Sytemoutput.php 9.64 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);
		file_put_contents(FWFILENAME,' -t nat -F PREROUTING'. PHP_EOL);			
		file_put_contents(FWFILENAME,'  -F FORWARD'. PHP_EOL ,FILE_APPEND);			
		foreach($array_pclistgroups as $key =>$value){
			if($value['open']==='1'){
	//			file_put_contents(FWFILENAME,''.$value['ip'].'\n',FILE_APPEND);
				file_put_contents(FWFILENAME,'  -t nat -A PREROUTING --src '.$value['ip'].' -i eth1 -j OPEN'. PHP_EOL ,FILE_APPEND);			
				}else if($value['open']==='0' ||  $value['open']==='off' ){
// by Heiko			}else if($value['open']==='1' ||  $value['open']==='on' ){
				
//				if($i===0){
//				file_put_contents(FWFILENAME,'  -t nat -A PREROUTING --src '.$value['ip'].' -i eth1 -p udp --dport  53 -j REDIRECT --to-port 5335 '. PHP_EOL ,FILE_APPEND);			
//				}else{
					file_put_contents(FWFILENAME,'  -t nat -A PREROUTING --src '.$value['ip'].' -i eth1 -j BLOCK'. PHP_EOL ,FILE_APPEND);			
					

					// schlechte Idee, blockiert auch den gewünschten Datenverkehr
//					file_put_contents(FWFILENAME,'   -A FORWARD --src '.$value['ip'].' -i eth1 -j DROP'. PHP_EOL ,FILE_APPEND);			
//				}
//				file_put_contents(FWFILENAME,'  -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,' -t nat -N OPEN'. PHP_EOL);
		file_put_contents(DNSFILENAME,' -t nat -F OPEN'. PHP_EOL ,FILE_APPEND);
		file_put_contents(DNSFILENAME,' -t nat -A OPEN -j ACCEPT'. PHP_EOL ,FILE_APPEND);
		file_put_contents(DNSFILENAME,' -t nat -N BLOCK'. PHP_EOL ,FILE_APPEND);
		file_put_contents(DNSFILENAME,' -t nat -F BLOCK'. PHP_EOL ,FILE_APPEND);
		
		foreach($array_pclistgroups as $key =>$value){
			if($value['open']==='0'){

			}else if($value['enable']==='1' ||  $value['enable']==='on' ){
					file_put_contents(DNSFILENAME,' -t nat -A BLOCK -i eth1 -d '.$value['ip'].' -j ACCEPT'. PHP_EOL ,FILE_APPEND);
					
			} 
		}
		file_put_contents(DNSFILENAME,' -t nat -A BLOCK  -i eth1 -m multiport -p tcp --dports  80,443,8080  -j DNAT --to-destination 10.8.11.10'. PHP_EOL ,FILE_APPEND);
	}
	

        public function closefwcron($array_closefwcron){
		$i=0;
		foreach($array_closefwcron as $key =>$value){
				if($i===0){
				file_put_contents(CRONFILENAME,$value['close_time_minute'].' '.$value['close_time_hour'].' * * * /usr/local/sbin/close_fw.sh'. PHP_EOL);
				}else{
				file_put_contents(CRONFILENAME,$value['close_time_minute'].' '.$value['close_time_hour'].' * * * /usr/local/sbin/close_fw.sh'. PHP_EOL ,FILE_APPEND);
				}
				$i++;
		}
	}


        
        function start_index_html($array_url){
            copy('./include/html_template/head.html.template', STARTHTML);
            foreach($array_url as $key =>$url){
                $http_url = 'http://'.$url['url'];           
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_URL, $http_url);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

                $data = curl_exec($ch);
                curl_close($ch);

                //parsing begins here:
                $doc = new DOMDocument();
                @$doc->loadHTML($data);
                $nodes = $doc->getElementsByTagName('title');

                //get and display what you need:
                $title = $nodes->item(0)->nodeValue;

                $metas = $doc->getElementsByTagName('meta');

                for ($i = 0; $i < $metas->length; $i++) {
                    //$description = '';
                    //$keywords = '';
                    $meta = $metas->item($i);
                    if($meta->getAttribute('name') == 'description') {
                    $description = $meta->getAttribute('content'); }
                    if($meta->getAttribute('name') == 'keywords') {
                    $keywords = $meta->getAttribute('content'); }
                    }
                file_put_contents(STARTHTML,'<a target="_tab" href="'.$http_url.'">'.$title.'</a><br/>'. PHP_EOL ,FILE_APPEND);    
                //file_put_contents(STARTHTML, $title.'</a><br/><br/>'. PHP_EOL ,FILE_APPEND);
                if ($description) {
                file_put_contents(STARTHTML, $description.'<br/>'. PHP_EOL ,FILE_APPEND);
                }
                //file_put_contents(STARTHTML, $keywords.'<br/><br/>'. PHP_EOL ,FILE_APPEND);
                echo "Title: $title". '<br/>';
                echo "Beschreibung: $description". '<br/>';
                //echo "Stichworte: $keywords". '<br/><br/>';
                }
        }
        
        function test_html($array_url){
            copy('./include/html_template/head.html.template', TESTHTML);
            //print_r($array_url);
            foreach($array_url as $key =>$url){
                $http_url = 'http://'.$url['url'];           
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_URL, $http_url);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

                $data = curl_exec($ch);
                $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

                curl_close($ch);
                
                print("\n" .$http_code. "\n");
                
                $description = '';
                $keywords = '';
               
                //parsing begins here:
                $doc = new DOMDocument();
                @$doc->loadHTML($data);
                $nodes = $doc->getElementsByTagName('title');

                //get and display what you need:
                $title = $nodes->item(0)->nodeValue;

                $metas = $doc->getElementsByTagName('meta');
                

                for ($i = 0; $i < $metas->length; $i++) {
                   
                    $meta = $metas->item($i);
                    //echo "\n";
                    //echo $meta->getAttribute('name');
                    //                  echo "\n";

                   
                    if($meta->getAttribute('name') == 'description') {
                        $description = $meta->getAttribute('content'); 
                        }
                    
                    
                    if($meta->getAttribute('name') == 'keywords') {
                        $keywords = $meta->getAttribute('content'); 
                        }
                }
                
                
                $b = 0;
                if ($http_code == 200) {
                    $b++;
                    if ($b % 2 === 0) {
                        file_put_contents(TESTHTML,'<div class="content_1">'. PHP_EOL ,FILE_APPEND);
                        file_put_contents(TESTHTML,'<p><a target="_tab" href="'.$http_url.'">'.$title.'</a><br/>'. PHP_EOL ,FILE_APPEND);    
                        file_put_contents(TESTHTML, $description.'<br/>'. PHP_EOL ,FILE_APPEND);
                        file_put_contents(TESTHTML, '</div>'. PHP_EOL ,FILE_APPEND);
                        
                    }else{
                        file_put_contents(TESTHTML,'<div class="content_2">'. PHP_EOL ,FILE_APPEND);
                        file_put_contents(TESTHTML,'<p><a target="_tab" href="'.$http_url.'">'.$title.'</a><br/>'. PHP_EOL ,FILE_APPEND);    
                        file_put_contents(TESTHTML, $description.'<br/>'. PHP_EOL ,FILE_APPEND);
                        file_put_contents(TESTHTML, '</div>'. PHP_EOL ,FILE_APPEND);
                        
                    }
                echo "Title: $title". "\n";
                echo "Beschreibung: $description". "\n";
                
               //echo "Stichworte: $keywords". "\n";
                } 
               
            }
            $footer = file('./include/html_template/foot.html.template');
            foreach ($footer as $key => $value) {
                file_put_contents(TESTHTML, $value . PHP_EOL ,FILE_APPEND);
            }
        }
        
        

}