Feature #4928 ยป surftool_v0.01.patch
packages/config/surftool/check_and_activate.php 2015-08-08 18:42:44.000000000 +0200 | ||
---|---|---|
1 |
<?php |
|
2 |
/* |
|
3 |
check_and_activate.php |
|
4 |
Copyright (C) 2015 H-T Reimers <reimers@mail.de> |
|
5 |
All rights reserved. |
|
6 | ||
7 |
Redistribution and use in source and binary forms, with or without |
|
8 |
modification, are permitted provided that the following conditions are met: |
|
9 | ||
10 |
1. Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 | ||
13 |
2. Redistributions in binary form must reproduce the above copyright |
|
14 |
notice, this list of conditions and the following disclaimer in the |
|
15 |
documentation and/or other materials provided with the distribution. |
|
16 | ||
17 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
18 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
19 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
20 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
21 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 |
POSSIBILITY OF SUCH DAMAGE. |
|
27 |
*/ |
|
28 | ||
29 |
//Read configuration |
|
30 |
$config=parse_ini_file ("surftool.cfg"); |
|
31 | ||
32 |
$debug=0; |
|
33 |
$max_execution_time=5; |
|
34 | ||
35 |
$commandpath="/tmp/surftool"; |
|
36 |
|
|
37 |
|
|
38 | ||
39 |
$delay=2; |
|
40 |
if(isset($argv[1])){ |
|
41 |
if($argv[1]>=0 AND $argv[1]<600){ |
|
42 |
$delay=$argv[1]; |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
//check |
|
47 |
set_time_limit($max_execution_time); |
|
48 |
if (ini_get('max_execution_time') != $max_execution_time){ |
|
49 |
echo "Warning max_execution_time is ".ini_get('max_execution_time')."s should be ".$max_execution_time."s\n"; |
|
50 |
} |
|
51 | ||
52 |
include "surftool3.inc"; |
|
53 | ||
54 |
$sgcommands= new commandReader($commandpath); |
|
55 | ||
56 |
//Are there any changes? |
|
57 |
if($sgcommands->changes){ |
|
58 | ||
59 |
//read squidGuard.conf |
|
60 |
$sgconf = new surftoolSquidGuardConf($config); |
|
61 | ||
62 |
//activate domain changes |
|
63 |
$sgconf->setDomains("onplus",$sgcommands->domainsOnplusAdd,$sgcommands->domainsOnplusRemove); |
|
64 |
$sgconf->setDomains("only",$sgcommands->domainsOnlyAdd,$sgcommands->domainsOnlyRemove); |
|
65 | ||
66 |
$sgconf->write_squidGuardDomains(); |
|
67 |
|
|
68 |
//activate acl mode changes |
|
69 |
$sgconf->setAclMode($sgcommands->aclChangeMode); |
|
70 |
$sgconf->write_squidGuardConf(); |
|
71 | ||
72 |
//Reload Squid Configuration |
|
73 |
$sgconf->squidReload(); |
|
74 | ||
75 |
$sgcommands->deleteCommandFiles(); |
|
76 |
|
|
77 |
} |
|
78 | ||
79 |
?> |
packages/config/surftool/index.php 2015-08-08 18:42:51.000000000 +0200 | ||
---|---|---|
1 |
<?php |
|
2 |
/* |
|
3 |
index.php |
|
4 |
Copyright (C) 2015 H-T Reimers <reimers@mail.de> |
|
5 |
All rights reserved. |
|
6 | ||
7 |
Redistribution and use in source and binary forms, with or without |
|
8 |
modification, are permitted provided that the following conditions are met: |
|
9 | ||
10 |
1. Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 | ||
13 |
2. Redistributions in binary form must reproduce the above copyright |
|
14 |
notice, this list of conditions and the following disclaimer in the |
|
15 |
documentation and/or other materials provided with the distribution. |
|
16 | ||
17 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
18 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
19 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
20 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
21 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 |
POSSIBILITY OF SUCH DAMAGE. |
|
27 |
*/ |
|
28 | ||
29 |
session_start(); |
|
30 |
//Read configuration |
|
31 |
$config=parse_ini_file ("surftool.cfg"); |
|
32 | ||
33 | ||
34 |
if(isset($_POST["logout"])){ |
|
35 |
session_unset(); |
|
36 |
$logout=true; |
|
37 |
} |
|
38 |
if(isset($_SESSION["login"])) $login=$_SESSION["login"]; |
|
39 |
else $login=false; |
|
40 |
|
|
41 |
if( isset($_GET["secret"]) ){ |
|
42 |
if($_GET["secret"]==$config["redirect_secret"] ){ |
|
43 |
$login=true; |
|
44 |
$_SESSION["login"]=true; |
|
45 |
} |
|
46 |
} |
|
47 |
if( isset($_POST["loginname"]) AND isset($_POST["passwd"]) ){ |
|
48 |
$user=$_POST["loginname"]; |
|
49 |
$passwd=$_POST["passwd"]; |
|
50 |
if($user==$config["user_name"] AND $passwd==$config["user_password"]){ |
|
51 |
$login=true; |
|
52 |
$_SESSION["login"]=true; |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
if($logout){ |
|
57 |
header("Location: ".$config["logout_target"]); |
|
58 |
$meta="<meta http-equiv='refresh' content='0; URL=".$config["logout_target"]."'>"; //When redirect with header is not supported |
|
59 |
} |
|
60 |
else if($login){ |
|
61 |
header("Location: set.php"); |
|
62 |
$meta="<meta http-equiv='refresh' content='0; URL=set.php'>"; //When redirect with header is not supported |
|
63 |
} |
|
64 |
else $meta=""; |
|
65 |
echo "<!DOCTYPE html><html><head>$meta<title>Surftool</title></head><body>"; |
|
66 |
|
|
67 |
if($login){ |
|
68 |
echo "<a href='set.php'> weiter </a>"; //When redirect with header and meta is not supported |
|
69 |
echo "<form action='index.php' method='post'> |
|
70 |
<input type='submit' name='logout' value='logout'> |
|
71 |
</form> "; |
|
72 |
} |
|
73 |
else if(!$login){ |
|
74 |
echo " |
|
75 |
<form action='' method='post'> |
|
76 |
Loginname:<input type='text' name='loginname'><br> |
|
77 |
Password:<input type='password' name='passwd'><br> |
|
78 |
<input type='submit' value='login'> |
|
79 |
</form> "; |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
echo "</body></html>"; |
|
84 |
?> |
packages/config/surftool/set.php 2015-08-08 18:42:58.000000000 +0200 | ||
---|---|---|
1 |
<?php |
|
2 |
/* |
|
3 |
set.php |
|
4 |
Copyright (C) 2015 H-T Reimers <reimers@mail.de> |
|
5 |
All rights reserved. |
|
6 | ||
7 |
Redistribution and use in source and binary forms, with or without |
|
8 |
modification, are permitted provided that the following conditions are met: |
|
9 | ||
10 |
1. Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 | ||
13 |
2. Redistributions in binary form must reproduce the above copyright |
|
14 |
notice, this list of conditions and the following disclaimer in the |
|
15 |
documentation and/or other materials provided with the distribution. |
|
16 | ||
17 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
18 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
19 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
20 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
21 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 |
POSSIBILITY OF SUCH DAMAGE. |
|
27 |
*/ |
|
28 |
session_start(); |
|
29 |
$encoding="ISO-8859-1"; |
|
30 |
mb_internal_encoding("$encoding"); |
|
31 | ||
32 |
//Read configuration |
|
33 |
$config=parse_ini_file ("surftool.cfg"); |
|
34 | ||
35 |
function print_header($meta=""){ |
|
36 |
echo " |
|
37 |
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' |
|
38 |
'http://www.w3.org/TR/html4/loose.dtd'> |
|
39 |
<html> |
|
40 |
<head> |
|
41 |
$meta |
|
42 |
<title>Internet freischalten </title> |
|
43 |
<meta http-equiv='cache-control' content='max-age=0'> |
|
44 |
<meta http-equiv='cache-control' content='no-cache'> |
|
45 |
<meta http-equiv='expires' content='-1'> |
|
46 |
<meta http-equiv='Pragma' CONTENT='no-cache'> |
|
47 | ||
48 |
<style type='text/css'> |
|
49 |
.Color_on { |
|
50 |
background-color:darkgreen; |
|
51 |
color:black; |
|
52 |
} |
|
53 |
.Color_onplus { |
|
54 |
background-color:springgreen; |
|
55 |
color:black; |
|
56 |
} |
|
57 |
.Color_only { |
|
58 |
background-color:gold; |
|
59 |
color:black; |
|
60 |
} |
|
61 |
.Color_off { |
|
62 |
background-color:red; |
|
63 |
color:black; |
|
64 |
} |
|
65 |
.Color_adminfree { |
|
66 |
background-color:black; |
|
67 |
color:white; |
|
68 |
} |
|
69 |
.showMode{ |
|
70 |
width:100px; |
|
71 |
valign:middle; |
|
72 |
align:center; |
|
73 |
padding:0.3em; |
|
74 |
font-weight: bolder; |
|
75 |
font-size: 12pt; |
|
76 |
} |
|
77 |
.Button{ |
|
78 |
width:200px; |
|
79 |
height:60px; |
|
80 |
valign:middle; |
|
81 |
align:center; |
|
82 |
padding:1.5em; |
|
83 |
font-weight: bolder; |
|
84 |
font-size: 15pt; |
|
85 |
} |
|
86 |
</style> |
|
87 | ||
88 | ||
89 |
<script language='JavaScript'> |
|
90 |
<!-- |
|
91 | ||
92 |
function switch_2_expert(){ |
|
93 |
document.getElementById('ModusSimpleHeader').style.display = 'none'; //Link - ModusSimple verbergen |
|
94 |
document.getElementById('ModusSimpleLink').style.display = 'none'; //Link - ModusSimple verbergen |
|
95 |
document.getElementById('ModusExpertLink').style.display = 'block'; //Link - ModusExpert anzeigen |
|
96 |
document.getElementById('ModusExpertHeader').style.display = 'block'; //Link - ModusExpert anzeigen |
|
97 |
document.getElementById('ModusExpertSettings').style.display = 'block'; //ModusExpert anzeigen |
|
98 |
document.getElementById('ModusNormalRadio').checked = 'true'; |
|
99 | ||
100 |
} |
|
101 | ||
102 |
function switch_2_simple(){ |
|
103 |
document.getElementById('ModusSimpleHeader').style.display = 'block'; //ModusSimple anzeigen |
|
104 |
document.getElementById('ModusSimpleLink').style.display = 'block'; //ModusSimple anzeigen |
|
105 |
document.getElementById('ModusExpertHeader').style.display = 'none'; //ModusExpert verbergen |
|
106 |
document.getElementById('ModusExpertLink').style.display = 'none'; //ModusExpert verbergen |
|
107 |
document.getElementById('ModusExpertSettings').style.display = 'none'; //ModusExpert verbergen |
|
108 |
} |
|
109 | ||
110 | ||
111 |
function switch_mode(newmode){ |
|
112 | ||
113 |
if(newmode=='on'){ |
|
114 |
document.getElementById('showmodus').firstChild.nodeValue = 'gew?hlter Modus: Normale Freigabe'; |
|
115 |
document.getElementById('whitelist').style.display = 'none'; //Whitelist verbergen |
|
116 |
document.getElementById('onlylist').style.display = 'none'; //Onlylist verbergen |
|
117 |
} |
|
118 |
else if(newmode=='off'){ |
|
119 |
document.getElementById('showmodus').firstChild.nodeValue = 'gew?hlter Modus: Internetzugang ausschalten'; |
|
120 |
document.getElementById('whitelist').style.display = 'none'; //Whitelist verbergen |
|
121 |
document.getElementById('onlylist').style.display = 'none'; //Onlylist verbergen |
|
122 |
} |
|
123 |
else if(newmode=='onplus'){ |
|
124 |
document.getElementById('showmodus').firstChild.nodeValue = 'gew?hlter Modus: Erweiterte Freigabe mit zus?tzlichen Seiten'; |
|
125 |
document.getElementById('whitelist').style.display = 'block'; //Whitelist anzeigen |
|
126 |
document.getElementById('onlylist').style.display = 'none'; //Onlylist verbergen |
|
127 |
} |
|
128 |
else if(newmode=='only'){ |
|
129 |
document.getElementById('showmodus').firstChild.nodeValue = 'gew?hlter Modus: Nur bestimmte Seiten freigeben'; |
|
130 |
document.getElementById('whitelist').style.display = 'none'; //Whitelist verbergen |
|
131 |
document.getElementById('onlylist').style.display = 'block'; //Onlylist anzeigen |
|
132 |
} |
|
133 |
else if(newmode=='adminfree'){ |
|
134 |
document.getElementById('showmodus').firstChild.nodeValue = 'gew?hlter Modus: Administrative Freigabe'; |
|
135 |
document.getElementById('whitelist').style.display = 'none'; //Whitelist verbergen |
|
136 |
document.getElementById('onlylist').style.display = 'none'; //Onlylist verbergen |
|
137 |
} |
|
138 | ||
139 |
|
|
140 |
} |
|
141 |
//--> |
|
142 |
</script> |
|
143 |
|
|
144 |
<meta http-equiv='Content-Type' content='text/html; charset=<?php echo $encoding; ?>'> |
|
145 |
<link rel='stylesheet' title='Schulkonsole' href='surftoolstyle.css' type='text/css'> |
|
146 |
|
|
147 |
|
|
148 |
<meta name='copyright' content='Copyright 2012 H. Reimers, reimers@mail.de'> |
|
149 |
<meta name='description' content='Surftool'> |
|
150 |
<script language='JavaScript'> |
|
151 |
<!-- |
|
152 | ||
153 |
window.onload = function() { |
|
154 |
//alert('I am an alert box!'); |
|
155 |
//location.replace('index.php'); |
|
156 |
} |
|
157 |
//--> |
|
158 |
</script> |
|
159 |
</head> |
|
160 |
<body bgcolor= #fefae8>"; |
|
161 |
} |
|
162 | ||
163 | ||
164 | ||
165 |
$debug=1; |
|
166 |
if(isset($config["debuglevel"])) $debug=$config["debuglevel"]; |
|
167 |
|
|
168 |
$switchtime=2; |
|
169 |
if(isset($config["refresh_time"])) $switchtime=$config["refresh_time"]+1; |
|
170 |
|
|
171 |
include "surftool3.inc"; |
|
172 |
|
|
173 |
if(!isset($_SESSION["login"])){ |
|
174 |
$meta="<meta http-equiv='refresh' content='0; URL=index.php'>"; |
|
175 |
print_header($meta); |
|
176 |
echo "login first <a href='index.php'> weiter </a>"; |
|
177 |
exit(0); |
|
178 |
} |
|
179 |
else if(isset($_POST["mode"])){ |
|
180 |
$meta="<meta http-equiv='refresh' content='".$switchtime."' />"; |
|
181 |
print_header($meta); |
|
182 |
} |
|
183 |
else{ |
|
184 |
$meta=""; |
|
185 |
print_header($meta); |
|
186 |
} |
|
187 |
|
|
188 | ||
189 | ||
190 |
//Print logout button |
|
191 |
echo "<form action='index.php' method='post'> |
|
192 |
<input type='submit' name='logout' value='logout'> |
|
193 |
</form> "; |
|
194 | ||
195 | ||
196 |
function write_domains_command($mode,$add,$remove){ |
|
197 |
write_command("'set_domains','$mode','$add','$remove'"); |
|
198 |
} |
|
199 | ||
200 |
function write_acl_command($aclname, $newmode){ |
|
201 |
write_command("'set_acl_mode','$aclname','$newmode'"); |
|
202 |
} |
|
203 | ||
204 |
function write_command($command){ |
|
205 |
$i=0; |
|
206 |
$path="/tmp/surftool/"; |
|
207 |
$filename="/tmp/surftool/surftool-".date("Y-m-d-H-i")."-"; |
|
208 |
|
|
209 |
if(!file_exists($path)){ |
|
210 |
if (!mkdir($path, 0700, true)) { |
|
211 |
die('Failed to create folders...'); |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
215 |
//don't change existing files |
|
216 |
while( file_exists($filename.$i.".txt") ){ |
|
217 |
$i++; |
|
218 |
} |
|
219 | ||
220 |
$fp = fopen($filename.$i.".txt", "a"); |
|
221 |
fwrite($fp, "$command"); |
|
222 |
fclose($fp); |
|
223 |
} |
|
224 | ||
225 |
function print_switch_mode($squidGuardOnlyDomains, $squidGuardWhiteDomains,$admin=true){ |
|
226 |
$html = "<h2 id='ModusSimpleHeader'>Modus: normal</h2>"; |
|
227 |
$html.= "<h2 id='ModusExpertHeader' style='display:none;'>Modus: erweitert</h2>"; |
|
228 |
$html.= "<a href='#' id='ModusSimpleLink' onclick='switch_2_expert();return false'>(Hier klicken f?r den erweiterten Modus)</a>"; |
|
229 |
$html.= "<a href='#' id='ModusExpertLink' onclick='switch_2_simple();return false' style='display:none;'>(Hier klicken f?r den normalen Modus)</a>"; |
|
230 | ||
231 |
//=== Print Expert Modus |
|
232 |
$html.= "<table id='ModusExpertSettings' style='display:none;'>"; |
|
233 |
$html.= " <tr><td colspan='2'><h2>Erweiterter Modus</h2></td></tr>\n"; |
|
234 |
$html.= " <tr><td colspan='2' id='showmodus'>gew?hlter Modus: on</td></tr>\n |
|
235 |
<tr><td><input type='radio' name='mode' value='on' checked id='ModusNormalRadio' onclick='switch_mode(\"on\");' >Normale Freigabe</td> <td class='Color_on showMode'> Raum </td></tr>\n |
|
236 |
<tr><td><input type='radio' name='mode' value='onplus' onclick='switch_mode(\"onplus\");' >Erweiterte Freigabe mit zus?tzlichen Seiten</td><td class='Color_onplus showMode'> Raum </td></tr>\n |
|
237 |
<tr><td><input type='radio' name='mode' value='only' onclick='switch_mode(\"only\");' >Nur bestimmte Seiten freigeben</td> <td class='Color_only showMode'> Raum </td></tr>\n |
|
238 |
<tr><td><input type='radio' name='mode' value='off' onclick='switch_mode(\"off\");' >Internetzugang ausschalten</td> <td class='Color_off showMode'> Raum </td></tr>\n"; |
|
239 | ||
240 | ||
241 |
if($admin){ |
|
242 |
$html.= "<tr><td><input type='radio' name='mode' value='adminfree' onclick='switch_mode(\"adminfree\");' >Administrative Freigabe<br></td> <td class='Color_adminfree showMode'> Raum </td></tr>\n"; |
|
243 |
} |
|
244 | ||
245 |
// |
|
246 |
$html.= "</table>"; |
|
247 |
|
|
248 |
$html.= "<table border='0' id='whitelist' style='display:none;'> |
|
249 |
<tr> |
|
250 |
<td><h2>Liste der <u>zus?tzlich</u> freigegebenen Seiten</h2></td> |
|
251 |
</tr> |
|
252 |
<tr> |
|
253 |
<td><textarea name='domains_onplus' cols='80' rows='15' >$squidGuardWhiteDomains</textarea></td>\n |
|
254 |
</tr> |
|
255 |
<tr> |
|
256 |
<td>Hinweis: Diese Seiten/Domain erweitert die normale Freigabe. ?nderungen dieser Liste werden durch einen Klick auf den gew?nschten Raum ?bernommen. |
|
257 |
Diese Liste gilt f?r alle R?ume in diesem Modus. Aus diesem Grund sollten ?nderungen nicht leichtfertig erfolgen. |
|
258 |
?nderungen werden protokoliert. |
|
259 |
Erweiterungen der Freigaben sind nur f?r p?dagogisch unterrichtsrelevante Seiten zul?ssig. </td>\n |
|
260 |
</tr> |
|
261 |
</table>"; |
|
262 | ||
263 |
$html.= "<table border='0' id='onlylist' style='display:none;'> |
|
264 |
<tr> |
|
265 |
<td><h2>Liste der <u>einzigen</u> freigegebenen Seiten</h2></td> |
|
266 |
</tr> |
|
267 |
<tr> |
|
268 |
<td><textarea name='domains_only' cols='80' rows='15'>$squidGuardOnlyDomains</textarea></td>\n |
|
269 |
</tr> |
|
270 |
<tr> |
|
271 |
<td>Hinweis: Nur diese Seiten/Domain werden freigegeben. ?nderungen dieser Liste werden durch einen Klick auf den gew?nschten Raum ?bernommen. |
|
272 |
Diese Liste gilt f?r alle R?ume in diesem Modus. Aus diesem Grund sollten ?nderungen nicht leichtfertig erfolgen. |
|
273 |
?nderungen werden protokoliert. |
|
274 |
Freigaben sind nur f?r p?dagogisch unterrichtsrelevante Seiten zul?ssig. </td>\n |
|
275 |
</tr> |
|
276 |
</table>"; |
|
277 | ||
278 |
$html.= "</td></tr></table>"; |
|
279 |
return $html; |
|
280 |
|
|
281 |
} |
|
282 | ||
283 | ||
284 |
function preecho($data){ |
|
285 |
echo "<PRE>"; |
|
286 |
print_r($data); |
|
287 |
echo "</PRE>"; |
|
288 |
} |
|
289 | ||
290 | ||
291 |
function create_room_button($aclname,$mode){ |
|
292 |
echo " <td><input type='submit' name='group' value='$aclname' class='Color_$mode Button'></td>\n"; |
|
293 |
} |
|
294 | ||
295 |
function print_table($acls){ |
|
296 |
|
|
297 |
if(sizeof($acls)>0){ |
|
298 |
$spalten=4; |
|
299 |
$i=0; |
|
300 |
echo "<table border='0'>\n<tr>\n"; |
|
301 |
foreach($acls["acl"] AS $acl){ |
|
302 |
$i++; |
|
303 |
echo create_room_button($acl["acl-name"],$acl[mode]); |
|
304 | ||
305 |
if($i%$spalten==0){ |
|
306 |
echo "\n </tr>\n <tr>\n"; |
|
307 |
} |
|
308 |
} |
|
309 |
$rest=$spalten-$i%$spalten; |
|
310 |
if($rest>0){ |
|
311 |
echo " <td colspan=$rest> <td>\n</tr>\n"; |
|
312 |
} |
|
313 |
echo "</table>\n"; |
|
314 |
} |
|
315 |
else{ |
|
316 |
echo "keine<br>"; |
|
317 |
} |
|
318 |
} |
|
319 | ||
320 |
|
|
321 |
|
|
322 |
$sgconf = new surftoolSquidGuardConf($config); |
|
323 |
|
|
324 | ||
325 |
$changes=false; |
|
326 |
//preecho($_POST); |
|
327 |
//Check Post-Data |
|
328 |
if(isset($_POST["group"]) AND isset($_POST["mode"]) ){ |
|
329 |
$group=$_POST["group"]; |
|
330 |
$mode=$_POST["mode"]; |
|
331 |
if(isset($sgconf->squidGuardConf["acl"]["$group"])){ |
|
332 |
if($mode=="on" AND $sgconf->squidGuardConf["acl"]["$group"]["mode"]=="on") $mode="off"; |
|
333 |
write_acl_command($group, $mode); |
|
334 |
echo "Switch $group to $mode<br>\n"; |
|
335 |
$changes=true; |
|
336 |
} |
|
337 |
else{ |
|
338 |
echo "Error unknown group:'$group'<br>\n"; |
|
339 |
} |
|
340 |
|
|
341 |
} |
|
342 | ||
343 |
if(isset($_POST["mode"]) AND isset($_POST["domains_onplus"]) ){ |
|
344 |
if($_POST["mode"]=="onplus"){ |
|
345 |
//Any Changes? |
|
346 |
if($_POST["domains_onplus"] != $sgconf->squidGuardOnplusDomains){ |
|
347 |
//What Changes? |
|
348 |
$changes=$sgconf->compare_domains_onplus( $_POST["domains_onplus"] ); |
|
349 | ||
350 |
write_domains_command("onplus", $changes["add"],$changes["remove"] ); |
|
351 |
echo "<br>".$changes["msg"]; |
|
352 |
$changes=true; |
|
353 |
} |
|
354 |
else{ |
|
355 |
if($debug>2) echo "OnplusDomains: no changees<br>\n"; |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
|
|
360 |
if(isset($_POST["mode"]) AND isset($_POST["domains_only"]) ){ |
|
361 |
if($_POST["mode"]=="only"){ |
|
362 |
//Any Changes? |
|
363 |
if($_POST["domains_only"] != $sgconf->squidGuardOnlyDomains){ |
|
364 |
//What Changes? |
|
365 |
$changes=$sgconf->compare_domains_only( $_POST["domains_only"] ); |
|
366 |
|
|
367 |
write_domains_command("only", $changes["add"],$changes["remove"] ); |
|
368 |
echo "<br>".$changes["msg"]; |
|
369 |
$changes=true; |
|
370 |
} |
|
371 |
else{ |
|
372 |
if($debug>2) echo "OnlyDomains: no changees<br>\n"; |
|
373 |
} |
|
374 |
} |
|
375 |
} |
|
376 | ||
377 |
if($changes){ |
|
378 |
echo "<br>Please wait ".$switchtime."s<br>"; |
|
379 |
echo "<br><a href=''>Switch an other group</a><br>"; |
|
380 |
exit(0); |
|
381 |
} |
|
382 |
|
|
383 |
//=== |
|
384 |
echo "\n<form action='' method='post'>\n"; |
|
385 |
echo "<form accept-charset='$encoding'> "; |
|
386 |
echo print_switch_mode($sgconf->squidGuardOnlyDomains, $sgconf->squidGuardOnplusDomains); |
|
387 |
|
|
388 |
//Get groups/acls |
|
389 |
$groupsAll=$sgconf->squidGuardConf; |
|
390 | ||
391 |
//=== Find Groups with similar ip. |
|
392 |
// ip adresses ar in $groupsAll["src"]["NAME"] and acls are in => $groupsAll["acl"]["NAME"] |
|
393 |
$ip = $_SERVER["REMOTE_ADDR"]; |
|
394 |
$lastpoint=strripos($ip,'.'); |
|
395 |
$firstpart=substr($ip,0,$lastpoint); |
|
396 |
$groupsNear=array(); |
|
397 |
foreach($groupsAll["src"] AS $srcname => $src){ |
|
398 |
if(isset($src["ip"])){ |
|
399 |
foreach($src["ip"] AS $ip){ |
|
400 |
$pos = strpos($ip, $firstpart); |
|
401 |
if( $pos !== false){ |
|
402 |
if(isset($groupsAll["acl"]["$srcname"])){ |
|
403 |
$groupsNear["acl"]["$srcname"]=$groupsAll["acl"]["$srcname"]; |
|
404 |
} |
|
405 |
else{ |
|
406 |
echo "Warning: no acl:'$srcname'<br>\n "; |
|
407 |
} |
|
408 |
} |
|
409 |
} |
|
410 |
} |
|
411 |
else echo "no src<br>\n"; |
|
412 |
} |
|
413 | ||
414 | ||
415 |
echo "<pre>"; |
|
416 |
//print_r($sgconf); |
|
417 |
echo "</pre>"; |
|
418 |
|
|
419 |
echo "<h2>Vorschl?ge</h2>"; |
|
420 |
print_table($groupsNear); |
|
421 |
echo "<h2>Alle R?ume</h2>"; |
|
422 |
print_table($groupsAll); |
|
423 | ||
424 | ||
425 |
echo "\n</form>\n"; |
|
426 |
|
|
427 | ||
428 | ||
429 |
//if($debug>1) preecho($data); |
|
430 | ||
431 |
echo" |
|
432 |
<form action='index.php' method='post'> |
|
433 |
<input type='submit' name='logout' value='logout'> |
|
434 |
</form> "; |
|
435 | ||
436 | ||
437 | ||
438 |
?> |
packages/config/surftool/surftool.cfg 2015-07-13 17:36:42.000000000 +0200 | ||
---|---|---|
1 |
; Surftool configuration |
|
2 |
language = "eng" |
|
3 |
refresh_time = "1" |
|
4 |
squid_binary_path = "/usr/local/sbin/squid" |
|
5 |
squidGuard_binary_path = "/usr/local/bin/squidGuard" |
|
6 |
squidGuard_configfile = "/usr/pbi/squidguard-amd64/etc/squidGuard/squidGuard.conf" |
|
7 |
squidGuard_database = "/var/db/squidGuard/" |
|
8 |
group_onplus = "surftool_onplus" |
|
9 |
group_only = "surftool_only" |
|
10 |
command_path = "/tmp/surftool" |
|
11 |
user_name = "admin" |
|
12 |
user_password = "pfsense" |
|
13 |
logfile= "/var/log/surftool.log" |
|
14 |
logout_target= "http://10.12.0.10/index.php" |
|
15 |
redirect_secret = "geheim" |
packages/config/surftool/surftool.inc 2015-08-08 18:43:52.000000000 +0200 | ||
---|---|---|
1 |
<?php |
|
2 |
/* |
|
3 |
surftool.inc |
|
4 |
Copyright (C) 2015 H-T Reimers <reimers@mail.de> |
|
5 |
All rights reserved. |
|
6 | ||
7 |
Redistribution and use in source and binary forms, with or without |
|
8 |
modification, are permitted provided that the following conditions are met: |
|
9 | ||
10 |
1. Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 | ||
13 |
2. Redistributions in binary form must reproduce the above copyright |
|
14 |
notice, this list of conditions and the following disclaimer in the |
|
15 |
documentation and/or other materials provided with the distribution. |
|
16 | ||
17 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
18 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
19 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
20 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
21 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 |
POSSIBILITY OF SUCH DAMAGE. |
|
27 |
*/ |
|
28 | ||
29 |
require_once('globals.inc'); |
|
30 |
require_once('config.inc'); |
|
31 |
require_once('util.inc'); |
|
32 |
require_once('pfsense-utils.inc'); |
|
33 |
require_once('pkg-utils.inc'); |
|
34 |
require_once('filter.inc'); |
|
35 |
require_once('service-utils.inc'); |
|
36 | ||
37 |
if (file_exists('surftool.inc')) { |
|
38 |
require_once('surftool.inc'); |
|
39 |
} |
|
40 |
else update_log("File 'surftool.inc' not found."); |
|
41 | ||
42 |
global $pfs_version; |
|
43 |
$pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); |
|
44 |
switch ($pfs_version) { |
|
45 |
case "2.1": |
|
46 |
break; |
|
47 |
case "2.2": |
|
48 |
break; |
|
49 |
default: |
|
50 |
break; |
|
51 |
} |
|
52 | ||
53 |
define ('CMD_PKGDELETE', 'pkg_delete surftool-0.01'); |
|
54 | ||
55 |
// enable GUI debug |
|
56 |
define('SURFTOOL_GUI_DEBUG', 'on'); |
|
57 |
define('SURFTOOL_LOG_FILE', '/tmp/surftool_gui.log'); |
|
58 | ||
59 |
// configuration settings !-- CHECK THIS --! |
|
60 |
define('SURFTOOL_WWWPATH', '/usr/local/www/surftool/'); |
|
61 |
define('SURFTOOL_WWWCONFIGFILE', SURFTOOL_WWWPATH.'surftool.cfg'); |
|
62 |
define('SURFTOOL_STARTUP_SCRIPT', '/usr/local/etc/rc.d/surftooldaemon.sh'); |
|
63 | ||
64 |
// xml variables |
|
65 |
define('SURFTOOL_LANGUAGE', 'surftool_lang'); |
|
66 |
define('SURFTOOL_REFRESH_TIME', 'surftool_refresh_time'); |
|
67 |
define('SURFTOOL_SQUID_BINARY_PATH', 'surftool_squid_binary'); |
|
68 |
define('SURFTOOL_SQUIDGUARD_BINARY_PATH', 'surftool_sg_binary'); |
|
69 |
define('SURFTOOL_SQUIDGUARD_CONFIGFILE', 'surftool_sg_config_file'); |
|
70 |
define('SURFTOOL_SQUIDGUARD_DATABASE', 'surftool_sg_db'); |
|
71 |
define('SURFTOOL_GROUP_ONPLUS', 'surftool_group_onplus_name'); |
|
72 |
define('SURFTOOL_GROUP_ONLY', 'surftool_group_only_name'); |
|
73 |
define('SURFTOOL_DEBUGLEVEL', 'surftool_debuglevel'); |
|
74 |
define('SURFTOOL_LOGFILE', 'surftool_logfile'); |
|
75 |
define('SURFTOOL_CMD_PATH', 'surftool_command_path'); |
|
76 |
define('SURFTOOL_LOGOUT_TARGET', 'surftool_logout_target'); |
|
77 |
define('SURFTOOL_REDIRECT_SECRET', 'surftool_redirect_secret'); |
|
78 |
define('SURFTOOL_USER_NAME', 'surftool_user_name'); |
|
79 |
define('SURFTOOL_USER_PASSWORD', 'surftool_user_password'); |
|
80 | ||
81 | ||
82 |
|
|
83 | ||
84 |
function surftool_install() { |
|
85 |
global $pfs_version; |
|
86 |
global $g, $config; |
|
87 |
$SURFTOOL_STARTUP_SCRIPT=SURFTOOL_STARTUP_SCRIPT; |
|
88 |
update_log("surftool_install: started" ); |
|
89 |
//Write rc.d script |
|
90 |
surftool_write_rcfile(); |
|
91 |
//mwexec(SURFTOOL_STARTUP_SCRIPT." start"); |
|
92 |
//mwexec("/usr/local/etc/rc.d/surftool.sh start"); |
|
93 |
update_log("surftool_install: stopped"); |
|
94 |
|
|
95 |
} |
|
96 | ||
97 |
function surftool_deinstall() { |
|
98 |
global $g, $config; |
|
99 |
update_log("surftool_deinstall: started"); |
|
100 |
//exec(SURFTOOL_STARTUP_SCRIPT . " stop"); |
|
101 |
// delete cron task's |
|
102 |
//ls_setup_cron("lightsquid_squid_rotate", "", "", false); |
|
103 |
//ls_setup_cron("lightsquid_parser", "", "", false); |
|
104 | ||
105 | ||
106 |
update_log("surftool_deinstall: stopped"); |
|
107 |
} |
|
108 | ||
109 | ||
110 | ||
111 |
function surftool_resync() { |
|
112 |
global $config, $pfs_version; |
|
113 |
surftool_wirte_config_file(); |
|
114 |
surftool_write_rcfile(); |
|
115 |
} |
|
116 | ||
117 | ||
118 |
function surftool_validate(&$post, &$input_errors){ |
|
119 |
global $config; |
|
120 |
$cfg = $config['installedpackages']['surftool']['config'][0]; |
|
121 | ||
122 |
$surftool_refresh_time = trim($cfg[SURFTOOL_REFRESH_TIME]); |
|
123 |
$surftool_squid_binary = $cfg[SURFTOOL_SQUID_BINARY_PATH]; |
|
124 |
$surftool_sg_binary = $cfg[SURFTOOL_SQUIDGUARD_BINARY_PATH]; |
|
125 |
$surftool_sg_config_file = $cfg[SURFTOOL_SQUIDGUARD_CONFIGFILE]; |
|
126 |
$surftool_sg_db = $cfg[SURFTOOL_SQUIDGUARD_DATABASE]; |
|
127 |
$surftool_group_onplus_name = $cfg[SURFTOOL_GROUP_ONPLUS]; |
|
128 |
$surftool_group_only_name = $cfg[SURFTOOL_GROUP_ONLY]; |
|
129 |
$surftool_debuglevel = $cfg[SURFTOOL_DEBUGLEVEL]; |
|
130 |
$surftool_logfile = $cfg[SURFTOOL_LOGFILE]; |
|
131 |
$surftool_command_path = $cfg[SURFTOOL_CMD_PATH]; |
|
132 | ||
133 |
// if(!is_numeric($surftool_refresh_time)) $input_errors[] = "Refresh time: '$surftool_refresh_time' is not numeric"; |
|
134 |
// if(!file_exists($surftool_squid_binary)) $input_errors[] = "The file: '$surftool_squid_binary' do not exists"; |
|
135 |
} |
|
136 | ||
137 | ||
138 |
function surftool_wirte_config_file(){ |
|
139 |
global $config; |
|
140 |
$cfg = $config['installedpackages']['surftool']['config'][0]; |
|
141 | ||
142 | ||
143 |
$surftool_lang = $cfg[SURFTOOL_LANGUAGE]; |
|
144 |
$surftool_refresh_time = $cfg[SURFTOOL_REFRESH_TIME]; |
|
145 |
$surftool_squid_binary = $cfg[SURFTOOL_SQUID_BINARY_PATH]; |
|
146 |
$surftool_sg_binary = $cfg[SURFTOOL_SQUIDGUARD_BINARY_PATH]; |
|
147 |
$surftool_sg_config_file = $cfg[SURFTOOL_SQUIDGUARD_CONFIGFILE]; |
|
148 |
$surftool_sg_db = $cfg[SURFTOOL_SQUIDGUARD_DATABASE]; |
|
149 |
$surftool_group_onplus_name = $cfg[SURFTOOL_GROUP_ONPLUS]; |
|
150 |
$surftool_group_only_name = $cfg[SURFTOOL_GROUP_ONLY]; |
|
151 |
$surftool_debuglevel = $cfg[SURFTOOL_DEBUGLEVEL]; |
|
152 |
$surftool_logfile = $cfg[SURFTOOL_LOGFILE]; |
|
153 |
$surftool_command_path = $cfg[SURFTOOL_CMD_PATH]; |
|
154 |
$surftool_logout_target = $cfg[SURFTOOL_LOGOUT_TARGET]; |
|
155 |
$surftool_redirect_secret = $cfg[SURFTOOL_REDIRECT_SECRET]; |
|
156 |
$surftool_user_name = $cfg[SURFTOOL_USER_NAME]; |
|
157 |
$surftool_user_password = $cfg[SURFTOOL_USER_PASSWORD]; |
|
158 | ||
159 | ||
160 |
$stc="; Surftool configuration |
|
161 |
language = \"".$surftool_lang."\" |
|
162 |
refresh_time = \"".$surftool_refresh_time."\" |
|
163 |
squid_binary_path = \"".$surftool_squid_binary ."\" |
|
164 |
squidGuard_binary_path = \"".$surftool_sg_binary."\" |
|
165 |
squidGuard_configfile = \"".$surftool_sg_config_file."\" |
|
166 |
squidGuard_database = \"".$surftool_sg_db."\" |
|
167 |
group_onplus = \"".$surftool_group_onplus_name."\" |
|
168 |
group_only = \"".$surftool_group_only_name."\" |
|
169 |
command_path = \"".$surftool_command_path."\" |
|
170 |
user_name = \"".$surftool_user_name."\" |
|
171 |
user_password = \"".$surftool_user_password."\" |
|
172 |
logfile= \"".$surftool_logfile."\" |
|
173 |
logout_target= \"".$surftool_logout_target."\" |
|
174 |
redirect_secret = \"".$surftool_redirect_secret."\"\n"; |
|
175 | ||
176 |
file_put_contents(SURFTOOL_WWWCONFIGFILE,$stc); |
|
177 | ||
178 | ||
179 | ||
180 |
} |
|
181 | ||
182 | ||
183 |
// setup cron tasks |
|
184 |
// original source from '/etc/inc/pfsense-utils.inc' function 'tdr_install_cron' |
|
185 |
// this function safe for other tasks |
|
186 |
// ***************************************************************************** |
|
187 |
// - $task_name: cron task name (for config identification) /for searching my cron tasks/ |
|
188 |
// - $options: array=[0:minute][1:hour][2:mday][3:month][4:wday][5:who][6:cmd] |
|
189 |
// - $task_key: cron command key for searching |
|
190 |
// - $on_off: true-'on task', false-'off' task |
|
191 |
// required: $task_nameand $on_off |
|
192 |
// ***************************************************************************** |
|
193 | ||
194 | ||
195 |
/* |
|
196 |
define('FIELD_TASKNAME', 'task_name'); |
|
197 | ||
198 |
function ls_setup_cron($task_name, $options, $task_key, $on_off) { |
|
199 |
global $config; |
|
200 |
update_log("ls_setup_cron: start task_name=$task_name, task_key=$task_key, on_off=$on_off"); |
|
201 | ||
202 |
// check input params |
|
203 |
if(!$task_name) { |
|
204 |
update_log("ls_setup_cron: exit - uncomplete input params."); |
|
205 |
return; |
|
206 |
} |
|
207 | ||
208 |
// delete old task(s) |
|
209 |
if (is_array($config['cron']['item'])) { |
|
210 |
foreach ($config['cron']['item'] as $key => $item) { |
|
211 |
# unset crontask by name |
|
212 |
if (!empty($task_name) && ($item[FIELD_TASKNAME] == $task_name)) { |
|
213 |
unset($config['cron']['item'][$key]); |
|
214 |
} else |
|
215 |
# unset crontask by cmd |
|
216 |
if ($options[6] && (strpos($item['command'], $options[6]) !== false)) { |
|
217 |
unset($config['cron']['item'][$key]); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 | ||
222 |
# install cron task |
|
223 |
if ($on_off) { |
|
224 |
if ($task_key) { |
|
225 |
if (is_array($options)) { |
|
226 |
# add new |
|
227 |
$cron_item = array(); |
|
228 |
$cron_item[FIELD_TASKNAME] = $task_name; |
|
229 |
$cron_item['minute'] = $options[0]; |
|
230 |
$cron_item['hour'] = $options[1]; |
|
231 |
$cron_item['mday'] = $options[2]; |
|
232 |
$cron_item['month'] = $options[3]; |
|
233 |
$cron_item['wday'] = $options[4]; |
|
234 |
$cron_item['who'] = $options[5]; |
|
235 |
$cron_item['command'] = $options[6]; |
|
236 | ||
237 |
# check options |
|
238 |
if (!$cron_item['who']) $cron_item['who'] = "nobody"; |
|
239 | ||
240 |
$config['cron']['item'][] = $cron_item; |
|
241 |
update_log("ls_setup_cron: add cron task '{$task_name}'='{$cron_item['command']}'"); |
|
242 |
} |
|
243 |
} else |
|
244 |
// log |
|
245 |
update_log("ls_setup_cron: input prm 'task_key' not defined"); |
|
246 |
} |
|
247 | ||
248 |
write_config("Installed cron task '$task_name' for 'lightsquid' package"); |
|
249 |
configure_cron(); |
|
250 |
update_log("ls_setup_cron: Apply new cron settings."); |
|
251 |
} |
|
252 |
*/ |
|
253 |
|
|
254 |
function update_log($log) { |
|
255 |
if (SURFTOOL_GUI_DEBUG === 'on') { |
|
256 |
$t_st_log = ''; |
|
257 |
if (file_exists(SURFTOOL_LOG_FILE)) |
|
258 |
$t_st_log = file_get_contents(SURFTOOL_LOG_FILE); |
|
259 |
$t_st_log .= "\n$log"; |
|
260 |
file_put_contents(SURFTOOL_LOG_FILE, $t_st_log); |
|
261 |
} |
|
262 |
} |
|
263 | ||
264 |
function refresh_now() { |
|
265 |
// $cmd = CRONTAB_LS_TEMPLATE . " today"; |
|
266 |
update_log("surftool refresh_now: execute command '$cmd'"); |
|
267 |
// create lightsquid report catalog |
|
268 | ||
269 |
/* if (!file_exists(LS_REPORTPATH)) { |
|
270 |
update_log("lightsquid_install: Create report dir " . LS_REPORTPATH); |
|
271 |
mwexec("mkdir -p " . LS_REPORTPATH); |
|
272 |
} |
|
273 |
mwexec_bg($cmd); |
|
274 |
*/ |
|
275 |
} |
|
276 | ||
277 |
//check to see if the service is installed if it is return the id |
|
278 |
function get_service_id ($service_array, $fieldname, $fieldvalue) { |
|
279 |
$x = 0; |
|
280 |
$id = ''; |
|
281 |
foreach($service_array as $rowhelper) { |
|
282 |
if ($rowhelper[$fieldname] == $fieldvalue) { |
|
283 |
$id = $x; //return the id |
|
284 |
} |
|
285 |
$x++; |
|
286 |
} |
|
287 |
if (strlen($id) > 0) { |
|
288 |
return ($id); |
|
289 |
} |
|
290 |
else { |
|
291 |
return false; |
|
292 |
} |
|
293 |
} |
|
294 | ||
295 | ||
296 |
function surftool_write_rcfile() { |
|
297 |
global $config; |
|
298 |
$cfg = $config['installedpackages']['surftool']['config'][0]; |
|
299 |
$surftool_refresh_time = $cfg[SURFTOOL_REFRESH_TIME]; |
|
300 |
$surftool_logfile = $cfg[SURFTOOL_LOGFILE]; |
|
301 |
$surftool_command_path = $cfg[SURFTOOL_CMD_PATH]; |
|
302 |
$rc = array(); |
|
303 |
$SURFTOOL_LOCALBASE = "/usr/local/share/surftool/" ; //SURFTOOL_LOCALBASE; |
|
304 |
$rc['file'] = 'surftooldaemon.sh'; |
|
305 |
$rc['start'] = <<<EOD |
|
306 |
mkdir -p $surftool_command_path |
|
307 |
{$SURFTOOL_LOCALBASE}surftooldaemon.sh $surftool_refresh_time $surftool_logfile $surftool_command_path & |
|
308 |
EOD; |
|
309 |
$rc['stop'] = <<<EOD |
|
310 |
touch $surftool_command_path/stoppdaemon |
|
311 |
sleep 2 |
|
312 |
ps ax | grep surftooldaemon.sh | grep -v grep | awk '{print $1}' | xargs kill |
|
313 |
ps ax | grep surftool/check_and_activate.php | grep -v grep | awk '{print $1}' | xargs kill |
|
314 |
EOD; |
|
315 |
$rc['restart'] = <<<EOD |
|
316 |
rc_stop |
|
317 |
rc_start |
|
318 |
EOD; |
|
319 |
conf_mount_rw(); |
|
320 |
write_rcfile($rc); |
|
321 |
conf_mount_ro(); |
|
322 | ||
323 |
} |
|
324 | ||
325 | ||
326 |
?> |
packages/config/surftool/surftool.xml 2015-08-08 18:43:37.000000000 +0200 | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8" ?> |
|
2 |
<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd"> |
|
3 |
<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?> |
|
4 |
<packagegui> |
|
5 |
<copyright> |
|
6 |
<![CDATA[ |
|
7 |
/* $Id$ */ |
|
8 |
/* ========================================================================== */ |
|
9 |
/* |
|
10 |
surftool.xml |
|
11 |
part of pfSense (http://www.pfSense.com) |
|
12 |
Copyright (C) 2015 H. Reimers <reimers@mail.de>. |
|
13 |
All rights reserved. |
|
14 |
*/ |
|
15 |
/* ========================================================================== */ |
|
16 |
/* |
|
17 |
Redistribution and use in source and binary forms, with or without |
|
18 |
modification, are permitted provided that the following conditions are met: |
|
19 | ||
20 |
1. Redistributions of source code must retain the above copyright notice, |
|
21 |
this list of conditions and the following disclaimer. |
|
22 | ||
23 |
2. Redistributions in binary form must reproduce the above copyright |
|
24 |
notice, this list of conditions and the following disclaimer in the |
|
25 |
documentation and/or other materials provided with the distribution. |
|
26 | ||
27 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
28 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
29 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
30 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
31 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
32 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
33 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
34 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
35 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
36 |
POSSIBILITY OF SUCH DAMAGE. |
|
37 |
|
|
38 |
*/ |
|
39 |
/* ========================================================================== */ |
|
40 |
]]> |
|
41 |
</copyright> |
|
42 |
<description>Manage your squidguard groups. You can set every group very easily. The modes on/off/only/on plus and adminfree are available. This tool was made for schools.</description> |
|
43 |
<requirements>This package needs squidguard</requirements> |
|
44 |
<faq>Currently there are no FAQ items provided.</faq> |
|
45 |
<name>surftool</name> |
|
46 |
<version>0.01</version> |
|
47 |
<title>Services: Surftool -> Settings</title> |
|
48 |
<category>Services</category> |
|
49 |
<include_file>/usr/local/pkg/surftool.inc</include_file> |
|
50 |
<service> |
|
51 |
<name>surftool</name> |
|
52 |
<rcfile>surftooldaemon.sh</rcfile> |
|
53 |
<executable>/bin/sh /usr/local/share/surftool/surftooldaemon.sh</executable> |
|
54 |
<description>Surftool--Service</description> |
|
55 |
<custom_php_service_status_command>$surftool_ret = exec('/bin/pgrep -anf surftooldaemon.sh'); if($surftool_ret>0) {return true;} else {return false;};</custom_php_service_status_command> |
|
56 |
</service> |
|
57 |
<menu> |
|
58 |
<name>Surftool</name> |
|
59 |
<tooltiptext>Manage your squidguard groups</tooltiptext> |
|
60 |
<section>Services</section> |
|
61 |
<url>/pkg_edit.php?xml=surftool.xml&id=0</url> |
|
62 |
</menu> |
|
63 |
<tabs> |
|
64 |
<tab> |
|
65 |
<text>Settings</text> |
|
66 |
<url>/pkg_edit.php?xml=surftool.xml&id=0</url> |
|
67 |
<active/> |
|
68 |
</tab> |
|
69 |
<tab> |
|
70 |
<text>Switch groups</text> |
|
71 |
<url>/surftool/index.php</url> |
|
72 |
</tab> |
|
73 |
</tabs> |
|
74 |
<additional_files_needed> |
|
75 |
<prefix>/usr/local/pkg/</prefix> |
|
76 |
<chmod>0755</chmod> |
|
77 |
<item>http://10.12.0.3/packages/config/surftool/surftool.inc</item> |
|
78 |
</additional_files_needed> |
|
79 |
<additional_files_needed> |
|
80 |
<prefix>/usr/local/www/surftool/</prefix> |
|
81 |
<chmod>0644</chmod> |
|
82 |
<item>http://10.12.0.3/packages/config/surftool/index.php</item> |
|
83 |
</additional_files_needed> |
|
84 |
<additional_files_needed> |
|
85 |
<prefix>/usr/local/www/surftool/</prefix> |
|
86 |
<chmod>0644</chmod> |
|
87 |
<item>http://10.12.0.3/packages/config/surftool/surftool3.inc</item> |
|
88 |
</additional_files_needed> |
|
89 |
<additional_files_needed> |
|
90 |
<prefix>/usr/local/www/surftool/</prefix> |
|
91 |
<chmod>0644</chmod> |
|
92 |
<item>http://10.12.0.3/packages/config/surftool/check_and_activate.php</item> |
|
93 |
</additional_files_needed> |
|
94 |
<additional_files_needed> |
|
95 |
<prefix>/usr/local/www/surftool/</prefix> |
|
96 |
<chmod>0644</chmod> |
|
97 |
<item>http://10.12.0.3/packages/config/surftool/set.php</item> |
|
98 |
</additional_files_needed> |
|
99 |
<additional_files_needed> |
|
100 |
<prefix>/usr/local/share/surftool/</prefix> |
|
101 |
<chmod>0755</chmod> |
|
102 |
<item>http://10.12.0.3/packages/config/surftool/surftooldaemon.sh</item> |
|
103 |
</additional_files_needed> |
|
104 | ||
105 | ||
106 |
<fields> |
|
107 |
<field> |
|
108 |
<fielddescr>Language</fielddescr> |
|
109 |
<fieldname>surftool_lang</fieldname> |
|
110 |
<description>Select language</description> |
|
111 |
<type>select</type> |
|
112 |
<value>eng</value> |
|
113 |
<options> |
|
114 |
<option><name>English</name><value>eng</value></option> |
|
115 |
<option><name>German</name><value>deu</value></option> |
|
116 |
</options> |
|
117 |
</field> |
|
118 |
<field> |
|
119 |
<fielddescr>Refresh time</fielddescr> |
|
120 |
<fieldname>surftool_refresh_time</fieldname> |
|
121 |
<value>2</value> |
|
122 |
<type>input</type> |
|
123 |
<description> |
|
124 |
<![CDATA[Look every x seconds for changes <br> |
|
125 |
Default:<b>1</b>]]> |
|
126 |
</description> |
|
127 |
<size>4</size> |
|
128 |
</field> |
|
129 |
<field> |
|
130 |
<fielddescr>Path to the squid binary</fielddescr> |
|
131 |
<fieldname>surftool_squid_binary</fieldname> |
|
132 |
<value></value> |
|
133 |
<type>input</type> |
|
134 |
<description> |
|
135 |
<![CDATA[Enter the path to the squid binary. <br> |
|
136 |
Default for amd64:<b>/usr/pbi/squid-amd64/local/sbin/squid</b>]]> |
|
137 |
</description> |
|
138 |
<size>70</size> |
|
139 |
</field> |
|
140 |
<field> |
|
141 |
<fielddescr>Path to the squidGuard binary</fielddescr> |
|
142 |
<fieldname>surftool_sg_binary</fieldname> |
|
143 |
<value></value> |
|
144 |
<type>input</type> |
|
145 |
<description> |
|
146 |
<![CDATA[Enter the path to the squidGuard binary. <br> |
|
147 |
Default:<b>/usr/local/bin/squidGuard</b>]]> |
|
148 |
</description> |
|
149 |
<size>70</size> |
|
150 |
</field> |
|
151 |
<field> |
|
152 |
<fielddescr>Path to the squidGuard configuration file</fielddescr> |
|
153 |
<fieldname>surftool_sg_config_file</fieldname> |
|
154 |
<value></value> |
|
155 |
<type>input</type> |
|
156 |
<description> |
|
157 |
<![CDATA[Enter the path to the squidGuard configuration file. <br> |
|
158 |
Default for amd64:<b>/usr/pbi/squidguard-amd64/etc/squidGuard/squidGuard.conf</b>]]> |
|
159 |
</description> |
|
160 |
<size>70</size> |
|
161 |
</field> |
|
162 |
<field> |
|
163 |
<fielddescr>Path to the squidGuard database</fielddescr> |
|
164 |
<fieldname>surftool_sg_db</fieldname> |
|
165 |
<value></value> |
|
166 |
<type>input</type> |
|
167 |
<description> |
|
168 |
<![CDATA[Enter the path to the squidGuard database. <br> |
|
169 |
Default:<b>/var/db/squidGuard/</b>]]> |
|
170 |
</description> |
|
171 |
<size>70</size> |
|
172 |
</field> |
|
173 |
<field> |
|
174 |
<fielddescr>Name of the squidGuard group onplus</fielddescr> |
|
175 |
<fieldname>surftool_group_onplus_name</fieldname> |
|
176 |
<value></value> |
|
177 |
<type>input</type> |
|
178 |
<description> |
|
179 |
<![CDATA[Enter the name of the squidguard group onplus. <br> |
|
180 |
Default:<b>surftool_onplus</b>]]> |
|
181 |
</description> |
|
182 |
</field> |
|
183 |
<field> |
|
184 |
<fielddescr>Name of the squidGuard group only</fielddescr> |
|
185 |
<fieldname>surftool_group_only_name</fieldname> |
|
186 |
<value></value> |
|
187 |
<type>input</type> |
|
188 |
<description> |
|
189 |
<![CDATA[Enter the name of the squidguard group only. <br>Default:<b>surftool_only</b>]]> |
|
190 |
</description> |
|
191 |
</field> |
|
192 |
<field> |
|
193 |
<fielddescr>command path</fielddescr> |
|
194 |
<fieldname>surftool_command_path</fieldname> |
|
195 |
<value>/tmp/surftool</value> |
|
196 |
<type>input</type> |
|
197 |
<description> |
|
198 |
<![CDATA[Enter the path for the command files. <br>Default:<b>/tmp/surftool</b>]]> |
|
199 |
</description> |
|
200 |
</field> |
|
201 |
<field> |
|
202 |
<fielddescr>logfile</fielddescr> |
|
203 |
<fieldname>surftool_logfile</fieldname> |
|
204 |
<value></value> |
|
205 |
<type>input</type> |
|
206 |
<description> |
|
207 |
<![CDATA[Enter the path and name of the logfile. <br>Default:<b>/var/log/surftool.log</b>]]> |
|
208 |
</description> |
|
209 |
<size>70</size> |
|
210 |
</field> |
|
211 | ||
212 |
<field> |
|
213 |
<fielddescr>loglevel</fielddescr> |
|
214 |
<fieldname>surftool_debuglevel</fieldname> |
|
215 |
<value></value> |
|
216 |
<type>input</type> |
|
217 |
<description> |
|
218 |
<![CDATA[Enter the loglevel. <br>0 less<br>9 much<br>Default:<b>0</b>]]> |
|
219 |
</description> |
|
220 |
<size>3</size> |
|
221 |
</field> |
|
222 |
<field> |
|
223 |
<fielddescr>logout target</fielddescr> |
|
224 |
<fieldname>surftool_logout_target</fieldname> |
|
225 |
<value></value> |
|
226 |
<type>input</type> |
|
227 |
<description> |
|
228 |
<![CDATA[Enter a link for auto redirection after logout<br>Maybe:<b>http://10.12.0.10/index.php</b>]]> |
|
229 |
</description> |
|
230 |
<size>70</size> |
|
231 |
</field> |
|
232 |
<field> |
|
233 |
<fielddescr>Secret external link</fielddescr> |
|
234 |
<fieldname>surftool_redirect_secret</fieldname> |
|
235 |
<type>password</type> |
|
236 |
<description> |
|
237 |
<![CDATA[A secret for others system, which refer with a link to the surftool site<br>Default:<b>not set</b>]]> |
|
238 |
</description> |
|
239 |
</field> |
|
240 |
<field> |
|
241 |
<fielddescr>user name</fielddescr> |
|
242 |
<fieldname>surftool_user_name</fieldname> |
|
243 |
<value></value> |
|
244 |
<type>input</type> |
|
245 |
<description> |
|
246 |
<![CDATA[Username for the local user<br>Default:<b>admin</b>]]> |
|
247 |
</description> |
|
248 |
<size>20</size> |
|
249 |
</field> |
|
250 |
<field> |
|
251 |
<fielddescr>user password</fielddescr> |
|
252 |
<fieldname>surftool_user_password</fieldname> |
|
253 |
<type>password</type> |
|
254 |
<description> |
|
255 |
<![CDATA[Password for the local user<br>Default:<b>admin</b>]]> |
|
256 |
</description> |
|
257 |
</field> |
|
258 |
</fields> |
|
259 |
<custom_php_validation_command> |
|
260 |
surftool_validate($_POST, $input_errors); |
|
261 |
</custom_php_validation_command> |
|
262 |
<custom_php_resync_config_command> |
|
263 |
exec("/bin/rm -f /usr/local/etc/rc.d/surftool*"); |
|
264 |
surftool_resync(); |
|
265 |
</custom_php_resync_config_command> |
|
266 |
<custom_php_install_command> |
|
267 |
surftool_install(); |
|
268 |
surftool_resync(); |
|
269 |
</custom_php_install_command> |
|
270 |
<custom_php_deinstall_command> |
|
271 |
surftool_deinstall(); |
|
272 |
exec("/bin/rm -f /usr/local/etc/rc.d/surftool*"); |
|
273 |
exec("/bin/rm -f -r /usr/local/share/surftool/"); |
|
274 |
</custom_php_deinstall_command> |
|
275 |
</packagegui> |
packages/config/surftool/surftool3.inc 2015-08-08 18:43:16.000000000 +0200 | ||
---|---|---|
1 |
<?php |
|
2 |
/* |
|
3 |
surftool3.inc |
|
4 |
Copyright (C) 2015 H-T Reimers <reimers@mail.de> |
|
5 |
All rights reserved. |
|
6 | ||
7 |
Redistribution and use in source and binary forms, with or without |
|
8 |
modification, are permitted provided that the following conditions are met: |
|
9 | ||
10 |
1. Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 | ||
13 |
2. Redistributions in binary form must reproduce the above copyright |
|
14 |
notice, this list of conditions and the following disclaimer in the |
|
15 |
documentation and/or other materials provided with the distribution. |
|
16 | ||
17 |
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, |
|
18 |
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
|
19 |
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
20 |
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|
21 |
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
22 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
23 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
24 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
25 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
26 |
POSSIBILITY OF SUCH DAMAGE. |
|
27 |
*/ |
|
28 | ||
29 | ||
30 |
class surftoolSquidGuardConf{ |
|
31 | ||
32 |
var $debug=8; |
|
33 |
var $squidGuardConfPath="/usr/pbi/squidguard-amd64/etc/squidGuard/squidGuard.conf"; |
|
34 |
var $squidGuardOnlyName="surftool_only"; |
|
35 |
var $squidGuardOnlyPath="/var/db/squidGuard/surftool_only/domains"; |
|
36 |
var $squidGuardOnplusName="surftool_onplus"; |
|
37 |
var $squidGuardOnplusPath="/var/db/squidGuard/surftool_onplus/domains"; |
|
38 |
var $squidBinary = "/usr/local/bin/squid"; |
|
39 |
var $squidGuardBinary = "/usr/local/bin/squidGuard"; |
|
40 | ||
41 |
var $squidGuardConfText = ""; //Array: The hole Text of the config file - one line <=> one field |
|
42 |
var $squidGuardConf = array(); // |
|
43 | ||
44 |
//Onplus Domains |
|
45 |
var $OnplusChangesActiv=false; |
|
46 |
var $squidGuardOnplusDomains=""; //String, seperator: " " |
|
47 |
|
|
48 |
//Only Domains |
|
49 |
var $OnlyChangesActiv=false; |
|
50 |
var $squidGuardOnlyDomains=""; //String, seperator: " " |
|
51 | ||
52 |
//ACL-Modes changes |
|
53 |
var $aclChangeModeActiv=false; |
|
54 |
|
|
55 |
//Reload squid config |
|
56 |
var $squidReloadActiv=false; |
|
57 | ||
58 | ||
59 |
function __construct($config){ |
|
60 |
|
|
61 |
//$squidGuardConfPathNew, $squidGuardOnplusPathNew, $squidGuardOnlyPathNew) { |
|
62 | ||
63 |
$this->aclChangeModeActiv=false; //No changes at beginning |
|
64 |
$this->squidReloadActiv=false; //No changes at beginning |
|
65 |
|
|
66 |
//Get Systemconfiguration |
|
67 |
$this->squidGuardConfPath = $config["squidGuard_configfile"]; |
|
68 |
$this->squidGuardOnplusName = $config["group_onplus"]; |
|
69 |
$this->squidGuardOnplusPath = $config["squidGuard_database"].$config["group_onplus"]."/domains"; |
|
70 |
$this->squidGuardOnlyName = $config["group_only"]; |
|
71 |
$this->squidGuardOnlyPath = $config["squidGuard_database"].$config["group_only"]."/domains"; |
|
72 |
$this->squidBinary = $config["squid_binary_path"]; |
|
73 |
$this->squidGuardBinary = $config["squidGuard_binary_path"]; |
|
74 |
|
|
75 |
//Check data |
|
76 |
$this->check(); |
|
77 |
|
|
78 |
//Get Data from squidGuard.conf |
|
79 |
$this->parse_squidGuard(); |
|
80 |
//Get Group Mode (on,off,only,onplus,adminfree) |
|
81 |
$this->getAclMode(); |
|
82 | ||
83 |
//Get Array with domains for onplus mode |
|
84 |
$this->squidGuardOnplusDomains=$this->parse_squidGuardDomains($this->squidGuardOnplusPath); |
|
85 |
|
|
86 |
//Get Array with domains for only mode |
|
87 |
$this->squidGuardOnlyDomains=$this->parse_squidGuardDomains($this->squidGuardOnlyPath); |
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
//print_r($this->squidGuardOnplusDomains ); |
|
92 | ||
93 |
} |
|
94 |
|
|
95 |
function check(){ |
|
96 |
$error_msg=array(); |
|
97 |
if( !file_exists($this->squidBinary)){ |
|
98 |
$error_msg[]="Warning: squid binary '$this->squidBinary' do not exists\n"; |
|
99 |
} |
|
100 |
if( !file_exists($this->squidGuardBinary)){ |
|
101 |
$error_msg[]="Warning: squidGuard binary '$this->squidGuardBinary' do not exists\n"; |
|
102 |
} |
|
103 |
if( !file_exists($this->squidGuardConfPath)){ |
|
104 |
$error_msg[]="Warning: squidGuard configuration file '$this->squidGuardConfPath' do not exists\n"; |
|
105 |
} |
|
106 |
if( !file_exists($this->squidGuardOnplusPath)){ |
|
107 |
$error_msg[]="Warning: onplus group - file '$this->squidGuardOnplusPath' do not exists\n"; |
|
108 |
} |
|
109 |
if( !file_exists($this->squidGuardOnlyPath)){ |
|
110 |
$error_msg[]="Warning: only group - file '$this->squidGuardOnlyPath' do not exists\n"; |
|
111 |
} |
|
112 |
if(sizeof($error_msg)>0) print_r($error_msg); |
|
113 |
} |
|
114 |
|
|
115 |
function squidReload(){ |
|
116 |
if($this->squidReloadActiv){ |
|
117 |
$command=$this->squidBinary." -k reconfigure"; //#Squid/SquidGuard Config reload |
|
118 |
$output=array(); |
|
119 |
$return_var=""; |
|
120 |
exec ( $command, $output , $return_var ); |
|
121 |
if($return_var!=0 AND $this->debug>=2) echo "Error: squidReload: Can't exec '$command'!\n"; |
|
122 |
else if($this->debug>=3) echo "Info - squidReload: exec '$command' returns: '$return_var'!\n"; |
|
123 |
else if($this->debug>=6) print_r($output); |
|
124 |
} |
|
125 |
else{ |
|
126 |
if($this->debug>=3) echo "Info - squidReload: no reload\n"; |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
function write_squidGuardConf(){ |
|
131 |
if($this->aclChangeModeActiv==true){ |
|
132 |
// Array-->String (with End Of Line) |
|
133 |
$str = implode(PHP_EOL, $this->squidGuardConfText ); |
|
134 |
file_put_contents("$this->squidGuardConfPath", $str); |
|
135 |
$this->squidReloadActiv=true; |
|
136 |
} |
|
137 |
else{ |
|
138 |
if($this->debug>=2) echo "Info - write_squidGuardConf: no changes\n"; |
|
139 |
} |
|
140 |
|
|
141 |
} |
|
142 | ||
143 |
function parse_squidGuardDomains($file){ |
|
144 |
if(!file_exists($file)){ |
|
145 |
echo "parse_squidGuardDomains - Error: Can't access '$file'<br>\n"; |
|
146 |
} |
|
147 |
else{ |
|
148 |
$t = file_get_contents($file); |
|
149 |
$t = str_replace("\r\n", "\n", $t); |
|
150 |
$t = str_replace("\n", " ", $t); |
|
151 |
$domains=explode(" ",$t); |
|
152 |
$t=""; |
|
153 |
//Search wrong entries |
|
154 |
foreach($domains AS $domain){ |
|
155 |
$t.=" ".$this->clean_domain($domain); |
|
156 |
} |
|
157 |
return $t; |
|
158 |
} |
|
159 |
} |
|
160 | ||
161 |
function endsWith( $haystack, $needle,$debug=0){ |
|
162 |
$length = strlen($needle); |
|
163 |
if ($length == 0) { |
|
164 |
return true; |
|
165 |
} |
|
166 |
if($debug>=3) echo "endsWith".$length.substr($haystack, -$length)."\n"; |
|
167 |
return (substr($haystack, -$length) === $needle); |
|
168 |
} |
|
169 | ||
170 |
function setDomains($group,$add,$remove){ |
|
171 |
|
|
172 |
if( sizeof($remove)>0 OR sizeof($add)>0 ){ |
|
173 |
if($group=="onplus" ){ |
|
174 |
$this->OnplusChangesActiv=true; |
|
175 |
$target=&$this->squidGuardOnplusDomains; |
|
176 |
} |
|
177 |
else if($group=="only" ){ |
|
178 |
$this->OnlyChangesActiv=true; |
|
179 |
$target=&$this->squidGuardOnlyDomains; |
|
180 |
} |
|
181 |
else { |
|
182 |
echo "Error setDomains: unknown group: '$group'\n"; |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
//Search wrong entries |
|
187 |
$domains=explode(" ",$target); |
|
188 |
$target=""; |
|
189 |
foreach($domains AS $domain){ |
|
190 |
$target.=" ".$this->clean_domain($domain); |
|
191 |
} |
|
192 | ||
193 |
|
|
194 |
if(sizeof($remove)>0){ |
|
195 |
foreach($remove AS $domain){ |
|
196 |
if($this->debug>=2) echo "remove $domain from $group<br>\n"; |
|
197 |
$target=str_replace("$domain","",$target); |
|
198 |
} |
|
199 |
} |
|
200 |
if(sizeof($add)>0){ |
|
201 |
foreach($add AS $domain){ |
|
202 |
if($this->debug>=2) echo "add $domain to $group<br>\n"; |
|
203 |
//First replace -> no double entries |
|
204 |
$target=str_replace("$domain","",$target); |
|
205 |
$target.=" ".$domain; |
|
206 |
} |
|
207 |
} |
|
208 |
//Remove double blanks |
|
209 |
$target = preg_replace ('#\s+#' , ' ' , $target ); |
|
210 |
$target = trim($target ); |
|
211 |
} |
|
212 |
|
|
213 |
function write_squidGuardDomains(){ |
|
214 |
|
|
215 |
if($this->OnplusChangesActiv){ |
|
216 |
//echo $this->squidGuardOnplusDomains; //String, seperator: " " |
|
217 |
$str=trim($str); |
|
218 |
$str =str_replace(" ","\n",$this->squidGuardOnplusDomains); |
|
219 | ||
220 |
//file_put_contents("$this->squidGuardOnplusPath", $str); |
|
221 |
$fp = fopen("$this->squidGuardOnplusPath","w"); |
|
222 |
fwrite($fp, $str); |
|
223 |
fclose($fp); |
|
224 |
|
|
225 |
//Activate new domainlist |
|
226 |
$command=$this->squidGuardBinary." -C ".$this->squidGuardOnplusName."/domains -c ".$this->squidGuardConfPath; |
|
227 |
$return_var=""; |
|
228 |
system($command, $return_var ); |
|
229 | ||
230 |
//Activation ok? |
|
231 |
if($return_var!=0 AND $this->debug>=1) echo "error: write_squidGuardDomains: Can't exec '$command' returns retval:'$return_var'!\n"; |
|
232 |
if($this->debug>=3) echo "Info - write_squidGuardDomains: Exec '$command' with retval: $return_var !\n"; |
|
233 |
if($this->debug>=6) print_r($output); |
|
234 |
//Set flag to reload squid configuration |
|
235 |
$this->squidReloadActiv=true; |
|
236 |
} |
|
237 |
else{ |
|
238 |
if($this->debug>=6) echo "Info - write_squidGuardDomains: OnplusChangesActiv not activ !\n"; |
|
239 |
} |
|
240 | ||
241 |
if($this->OnlyChangesActiv){ |
|
242 |
//echo $this->squidGuardOnlyDomains; //String, seperator: " " |
|
243 |
$str=trim($str); |
|
244 |
$str =str_replace(" ","\n",$this->squidGuardOnlyDomains); |
|
245 |
//file_put_contents("$this->squidGuardOnlyPath", $str); |
|
246 |
$fp = fopen("$this->squidGuardOnlyPath","w"); |
|
247 |
fwrite($fp, $str); |
|
248 |
fclose($fp); |
|
249 |
|
|
250 |
//Activate new domainlist |
|
251 |
$command=$this->squidGuardBinary." -C ".$this->squidGuardOnlyName."/domains -c ".$this->squidGuardConfPath." > /dev/null 2>&1"; |
|
252 |
$return_var=""; |
|
253 |
system($command, $return_var ); |
|
254 | ||
255 |
//Activation ok? |