Sytemoutput.php 2.95 KB
<?php
/**
 * 	This file is part of ncfilters by netz.coop eG.
 * 
 *  Ncfilters is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  Ncfilters is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Ncfilters.  If not, see <http://www.gnu.org/licenses/>.
 *  
 *  Diese Datei ist Teil von ncfilters by netz.coop eG.
 *  
 *  Ncfilters ist Freie Software: Sie können es unter den Bedingungen
 *  der GNU General Public License, wie von der Free Software Foundation,
 *  Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
 *  veröffentlichten Version, weiterverbreiten und/oder modifizieren.
 *  
 *  Ncfilters wird in der Hoffnung, dass es nützlich sein wird, aber
 *  OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
 *  Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
 *  Siehe die GNU General Public License für weitere Details.
 *  
 *  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
 *  Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
 * 
 */

/**
 * Sytemoutput
 * Output to files or System calls
 * 
 * @author kontakt@nc
 */

class Sytemoutput {
	
	public function createfw($array_pclistgroups){
		$i=0;
		file_put_contents(FWFILENAME, PHP_EOL);
		foreach($array_pclistgroups as $key =>$value){
			if($value['open']==='0'){
	//			file_put_contents(FWFILENAME,''.$value['ip'].'\n',FILE_APPEND);
			}else if($value['open']==='1' ||  $value['open']==='on' ){
				
				if($i===0){
					
					file_put_contents(FWFILENAME,'iptables  -t nat -A PREROUTING --src '.$value['ip'].' -i eth1 -p udp --dport  53 -j REDIRECT --to-port 5335 '. PHP_EOL);			
				}else{
					file_put_contents(FWFILENAME,'iptables  -t nat -A PREROUTING --src '.$value['ip'].' -i eth1 -p udp --dport  53 -j REDIRECT --to-port 5335 '. PHP_EOL ,FILE_APPEND);			
				}
				file_put_contents(FWFILENAME,'iptables  -t nat -A PREROUTING --src '.$value['ip'].' -i eth1 -p tcp --dport  53 -j REDIRECT --to-port 5335 '. PHP_EOL ,FILE_APPEND);			
			} 
			$i++;
		}
	}
	
	public function createhosts($array_pclistgroups){
		file_put_contents(DNSFILENAME, PHP_EOL);
		$i=0;
		
		foreach($array_pclistgroups as $key =>$value){
			if($value['open']==='0'){

			}else if($value['enable']==='1' ||  $value['enable']==='on' ){
				if($i===0){
					file_put_contents(DNSFILENAME,'address=/'.$value['url'].'/'.$value['ip'] .PHP_EOL );
				}else{
					file_put_contents(DNSFILENAME,'address=/'.$value['url'].'/'.$value['ip'] .PHP_EOL ,FILE_APPEND);
				}
					
			} 
			$i++;
		}
	}
	
}