index.php
11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?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';
$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 Gruppen');
$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('insert', 'sample');
$stringadv .= $out->printbutton('Insert Sample Data');
$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('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();