index.php 12.3 KB
<?php
session_start();
if($_POST['session']==='logout'){
	session_unset();
	session_destroy();
}
/**
 * 	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/>.
 * 
 */
/**
 * Index
 *
 * @author kontakt@nc
 */
require_once './include/configure.php';
require_once './include/classes/Connectdb.php';
require_once './include/classes/Output.php';
require_once './include/classes/Sytemoutput.php';


$db = new Connectdb();
$out = new Output();

echo $out->printhead();
echo $out->printstartbody();
echo $out->printlogo('NCFilters');
//echo '<pre>';
//print_r($_POST);
//echo '<pre>';


if(isset($_POST['username']) && $db->getUserpassword($_POST['username'],$_POST['password']) ){
	 $_SESSION['user_id'] = $_POST['username'];
}
	
if($_SESSION['user_id']){
	echo $out->printformstart('session','logout');
	echo $out->printbutton('Abmelden','danger btn-sm', 'Abmelden','right');
	echo $out->printformend();
	
}


if (!isset($_SESSION['user_id'])) {
	$out->printlogin();
	
	//$gehashtes_passwort = crypt('testpassword'); // Der Salt wird automatisch generiert

	/* Sie sollten das vollständige Ergebnis von crypt() als Salt zum
	  Passwort-Vergleich übergeben, um Problemen mit unterschiedlichen
	  Hash-Algorithmen vorzubeugen. (Wie bereits ausgeführt, verwendet
	  ein Standard-DES-Passwort-Hash einen 2-Zeichen-Salt, ein
	  MD5-basierter hingegen nutzt 12 Zeichen. */
	//echo'$gehashtes_passwort: '.$gehashtes_passwort;
	//if (crypt('testpassword', $gehashtes_passwort) == $gehashtes_passwort) {
	//   echo "Passwort stimmt überein!";
	//}
} else {

	
	/**
	 * Actions save delete insert update
	 */
	if (is_array($_POST) && key_exists('action', $_POST)) {
		$acttable = $_POST['table'];
		if ($_POST['action'] === 'fastinput') {
			$var_sql = true;
			if ($acttable === 'domains') {
				if (!$_POST['ip'] && $_POST['url']) {
					/**
					 * Get Ip for domain
					 */
					$test = dns_get_record($_POST['url'], DNS_A);
					$_POST['ip'] = $test[0]['ip'];
				}
				if (!$_POST['url'] || !$_POST['ip']) {
					$error = ' Bitte die Webseite eintragen';
					$var_sql = false;
				}
			} else if ($acttable === 'groups') {

				if (!$_POST['name'] || !$_POST['group_id'] || !$_POST['chldvlv']) {
					$error = ' Bitte alle Daten eintragen';
	//www.google.de/search?q=sqlite+sort+by+multiple+columns&ie=utf-8&oe=utf-8&gws_rd=cr&ei=S801WdjVNIOgsAG_85OYBQ				$var_sql = false;
				}
			}
			if ($var_sql) {
				$sqlstring = 'INSERT INTO ' . $_POST['table'] . ' (';
				unset($_POST['action']);
				unset($_POST['table']);

				foreach ($_POST as $key => $value) {
					$sqlstring .= $key . ',';
				}
				$sqlstring = substr($sqlstring, 0, -1);
				$sqlstring .= ') VALUES (';
				foreach ($_POST as $key => $value) {
					$sqlstring .= '"' . $value . '",';
					;
				}
				$sqlstring = substr($sqlstring, 0, -1);
				$sqlstring .= ') ';
				$db->exec($sqlstring);
				echo $out->printmsg(' Erfolgreich gespeichert', 'success');
			} else {
				echo $out->printmsg($error, 'danger');
			}
		} elseif ($_POST['action'] === 'delete') {
			if ($_POST['table'] === 'groups') {
				$sqlstring = 'DELETE FROM  ' . $_POST['table'] . ' WHERE GROUP_ID = ' . $_POST['group_id'];
			} else {
				$sqlstring = 'DELETE FROM  ' . $_POST['table'] . ' WHERE ID = ' . $_POST['id'];
			}
			$db->exec($sqlstring);
			echo $out->printmsg($acttable . ': Datensatz ' . $_POST['id'] . ' wurde gelöscht!', 'danger');
		} elseif ($_POST['action'] === 'activate') {
			if ($_POST['table'] === 'groups') {
				$sqlstring = 'UPDATE   ' . $_POST['table'] . ' SET  ' . $_POST['field'] . ' = 1  WHERE GROUP_ID = ' . $_POST['group_id'];
			} else {
				$sqlstring = 'UPDATE   ' . $_POST['table'] . ' SET  ' . $_POST['field'] . ' = 1  WHERE ID = ' . $_POST['id'];
			}


			$db->exec($sqlstring);
			echo $out->printmsg('Datensatz Aktiviert', 'success');
		} elseif ($_POST['action'] === 'deactivate') {
			if ($_POST['table'] === 'groups') {
				$sqlstring = 'UPDATE   ' . $_POST['table'] . ' SET  ' . $_POST['field'] . ' = 0  WHERE GROUP_ID = ' . $_POST['group_id'];
			} else {
				$sqlstring = 'UPDATE   ' . $_POST['table'] . ' SET  ' . $_POST['field'] . ' = 0  WHERE ID = ' . $_POST['id'];
			}
			$db->exec($sqlstring);
			echo $out->printmsg('Datensatz deaktiviert', 'danger');
		}

		$_POST[$acttable] = 'print';                     
                $sysout = new Sytemoutput();
		$array_pclistgroups = $db->getpclistgroupsarray();
		$sysout->createfw($array_pclistgroups);
		$domaingroupsarray = $db->getdomaingroupsarray();
		$sysout->createhosts($domaingroupsarray);

	}
	/**
	 * Create Controlls - Buttons
	 */
	$tablestring = $out->printmintablestart();
	$tablestringcontent = $out->printformstart('domains', 'print');
	$tablestringcontent .= $out->printbutton('Zeige Domains');
	$tablestringcontent .= $out->printformend();

	$tablestring .= $out->printmintablecell($tablestringcontent);
	$tablestringcontent = $out->printformstart('groups', 'print');
	$tablestringcontent .= $out->printbutton('Zeige Schulklassen');
	$tablestringcontent .= $out->printformend();
	$tablestring .= $out->printmintablecell($tablestringcontent);



	$stringadv .= $out->printformstart('pclist', 'print');
	$stringadv .= $out->printbutton('Zeige Pcs');
	$stringadv .= $out->printformend();

	$stringadv .= $out->printformstart('nclistsuser', 'print');
	$stringadv .= $out->printbutton('Zeige ncfilters Benutzer');
	$stringadv .= $out->printformend();

	$stringadv .= $out->printformstart('close_fw_cron', 'print');
	$stringadv .= $out->printbutton('Zeige Abschaltzeiten');
	$stringadv .= $out->printformend();

	$tablestringcontent = $out->printcollapsebtn('Erweitert', 'collapseId', 'warning btn-sm');
	$tablestring .= $out->printmintablecell($tablestringcontent);
	$tablestring .= $out->printmintableend();
	echo $tablestring;
	echo $out->printcollapsecontent($stringadv, 'Erweitert', 'collapseId', 'warning btn-sm');
/*
	if (is_array($_POST) && key_exists('insert', $_POST) && $_POST['insert'] === 'sample') {
		$db->exec("INSERT INTO domains (id,url,ip,priority,intern,enable,childlvl) VALUES ('0','antolin.de','217.13.73.6','0','0','1','1') ");
		$db->exec('INSERT INTO domains (id,url,ip,priority,intern,enable,childlvl) VALUES ("1","blindekuh.de/","217.160.231.96","0","0","1","1") ');
		$db->exec('INSERT INTO domains (id,url,ip,priority,intern,enable,childlvl) VALUES ("2","blinde-kuh.de","194.195.10.105","0","0","1","1") ');
		$db->exec('INSERT INTO domains (id,url,ip,priority,intern,enable,childlvl) VALUES ("3","#","192.168.1.123","0","0","1","1") ');

		$db->exec('INSERT INTO groups (group_id,name,chldvlv,open) VALUES ("0","Klasse 1a","1","0") ');
		$db->exec('INSERT INTO groups (group_id,name,chldvlv,open) VALUES ("2","Klasse 1b","1","0") ');
		$db->exec('INSERT INTO groups (group_id,name,chldvlv,open) VALUES ("3","Klasse 2a","2","0") ');
		$db->exec('INSERT INTO groups (group_id,name,chldvlv,open) VALUES ("4","Klasse 4a","4","0") ');

		$db->exec('INSERT INTO pclist (ip,group_id) VALUES (10.8.11.101","1") ');
		$db->exec('INSERT INTO pclist (id,ip,group_id) VALUES ("2","10.8.11.102","1") ');
		$db->exec('INSERT INTO pclist (id,ip,group_id) VALUES ("3","10.8.11.103","1") ');
		$db->exec('INSERT INTO pclist (id,ip,group_id) VALUES ("4","10.8.11.104","1") ');
		$db->exec('INSERT INTO pclist (id,ip,group_id) VALUES ("5","10.8.11.113","4") ');
		$db->exec('INSERT INTO pclist (id,ip,group_id) VALUES ("6","10.8.11.114","4") ');
//		echo 'INSERT INTO pclist (id,ip,group_id) VALUES ("6","10.8.11.114","4")';
	}
*/
	if (is_array($_POST) && key_exists('domains', $_POST) && $_POST['domains'] === 'print') {
		echo '<br> <h3>Domains:</h3> ';
		$resultndomains = $db->query('SELECT * FROM domains ' . SQLSORT);
		$i = 0;
		$ary_head_domains = array();
		$ary_content_domains = array();
		$ary_controll = array('fastinput' => true, 'delete' => true, 'table' => 'domains', 'fields' => array());
		while ($res = $resultndomains->fetchArray(SQLITE3_ASSOC)) {
			if ($i === 0) {
				foreach ($res as $key => $value) {
					$ary_head_domains[] .= $key;
				}
			}
			foreach ($res as $key => $value) {
				$ary_content_domains[$i][$key] .= $value;
			}
			$i++;
		}
		echo $out->printtable($ary_head_domains, $ary_content_domains, true, $ary_controll);
	}



	if (is_array($_POST) && key_exists('close_fw_cron', $_POST) && $_POST['close_fw_cron'] === 'print') {
		echo '<br> <h3>Abschaltzeiten:</h3> ';
		$resultclosefwcron = $db->query('SELECT * FROM close_fw_cron ORDER BY close_time_hour, close_time_minute');
		$i = 0;
		$ary_head_cron = array();
		$ary_content_cron = array();
		$ary_controll = array('fastinput' => true, 'delete' => true, 'table' => 'close_fw_cron', 'fields' => array());
		while ($res = $resultclosefwcron->fetchArray(SQLITE3_ASSOC)) {
			if ($i === 0) {
				foreach ($res as $key => $value) {
					$ary_head_cron[] .= $key;
				}
			}
			foreach ($res as $key => $value) {
				$ary_content_cron[$i][$key] .= $value;
			}
			$i++;
		}
		echo $out->printtable($ary_head_cron, $ary_content_cron, true, $ary_controll);
	}



	if (is_array($_POST) && key_exists('nclistsuser', $_POST) && $_POST['nclistsuser'] === 'print') {

		echo '<br> <h3>Users: </h3>';
		$resultnclistsuser = $db->query('SELECT * FROM nclistsuser ' . SQLSORT);
		$ary_head_nclistsuser = array();
		$ary_content_nclistsuser = array();
		$i = 0;
		while ($res = $resultnclistsuser->fetchArray(SQLITE3_ASSOC)) {
			//	 print_r($res);
			if ($i === 0) {
				foreach ($res as $key => $value) {
					$ary_head_nclistsuser[] .= $key;
				}
			}
			foreach ($res as $key => $value) {

				$ary_content_nclistsuser[$i][$key] .= $value;
			}
			$i++;
		}
		echo $out->printtable($ary_head_nclistsuser, $ary_content_nclistsuser);
	}

	if (is_array($_POST) && key_exists('groups', $_POST) && $_POST['groups'] === 'print') {
		$ary_controll = array('fastinput' => true, 'delete' => true, 'table' => 'groups', 'fields' => array());
		$resultgroups = $db->query('SELECT * FROM groups ' . SQLGRPSORT);
		echo '<br><h3> Groups: </h3>';
		$ary_head_groups = array();
		$ary_content_groups = array();
		$i = 0;
		while ($res = $resultgroups->fetchArray(SQLITE3_ASSOC)) {
			if ($i === 0) {
				foreach ($res as $key => $value) {
					$ary_head_groups[] .= $key;
				}
			}
			foreach ($res as $key => $value) {
				$ary_content_groups[$i][$key] .= $value;
			}
			$i++;
		}
		echo $out->printtable($ary_head_groups, $ary_content_groups, true, $ary_controll);
	}


	if (is_array($_POST) && key_exists('pclist', $_POST) && $_POST['pclist'] === 'print') {

		$resultpclist = $db->query('SELECT * FROM pclist ' . SQLSORT);
		echo '<br> <h3>PCs:</h3>';
		$ary_controll = array('fastinput' => true, 'delete' => true, 'table' => 'pclist', 'fields' => array());

		$ary_head_pclist = array();
		$ary_content_pclist = array();
		$i = 0;
		while ($res = $resultpclist->fetchArray(SQLITE3_ASSOC)) {
			if ($i === 0) {
				foreach ($res as $key => $value) {
					$ary_head_pclist[] .= $key;
				}
			}
			foreach ($res as $key => $value) {
				$ary_content_pclist[$i][$key] .= $value;
			}
			$i++;
		}
		echo $out->printtable($ary_head_pclist, $ary_content_pclist, true, $ary_controll);
	}





	
}
echo $out->printfoter();
echo $out->printendbody();