Sytemoutput.php
9.64 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
<?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);
}
}
}