-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfirewall.php
359 lines (330 loc) · 15.5 KB
/
firewall.php
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?php
/*
* firewall.php
*
* Copyright (C) 2013-2014 by Erland Hedman <erland@hedmanshome.se>
*
* This program 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
* 2 of the License, or (at your option) any later version.
*/
include 'cgi-bin/common.php';
//if (count($_POST)) {echo "<pre>"; print_r($_POST); echo "</pre>";exit;}
if (count($_POST) && $_POST["POST_ACTION"] == "OK") {
if ($_POST["ACTION_DO_FWS"] == 1 || $_POST["activate"] == "Stop") {
if (do_firewall_pw($_POST["SUPER_PASSWD"]) == false) {
header('Location: http://'. $_SERVER["SERVER_ADDR"]. $_SERVER['SCRIPT_NAME'].'?msg=noauth');
die();
}
}
if (! function_exists('pcntl_fork')) die('PCNTL functions not available on this PHP installation');
$pid = pcntl_fork();
if ($pid == -1) {
echo("<pre>pcntl_fork: failed - check the extension for pcntl.so\n");
print_r(error_get_last());
echo "</pre>\n"; exit;
} else if (!$pid) {
// We are the child
if ($_POST["activate"] == "Activate") {
do_firewall_masqif(g_wan()." ".g_lan()." ".g_srvlan()." ".g_srvip());
if ($_POST["ACTION_DO_TS"] == 1)
do_firewall_ts($_POST['ts_enabled']." ".$_POST['dl_speed']." ".$_POST['ul_speed']." ".g_wan());
if ($_POST["ACTION_DO_FWS"] == 1)
do_firewall_fws($_POST['ssh_enabled']." ".$_POST['nfs_enabled']." ".$_POST['vpn_enabled']);
do_firewall_mgm("restart");
} else if ($_POST["activate"] == "Stop") {
do_firewall_mgm("stop");
}
} else {
header('Location: http://'. $_SERVER["SERVER_ADDR"]. '/wait.php?seconds=14&loc='.$_SERVER['SCRIPT_NAME']);
exit;
}
}
$nfssts="";
$vpnsts="";
$sshsts="";
$ret=exec("grep -m1 'SSH(ACCEPT)' /etc/shorewall/rules | awk '{printf \"%s%s\",\$2,\$3}'");
if ($ret == 'loc$FW') $sshsts="checked ";
$ret=exec("grep -m1 portmap /etc/shorewall/rules | awk '{printf \"%s%s%s\", \$1,\$2,\$3}'");
if ($ret == 'ACCEPTloc$FW') $nfssts="checked ";
if (file_exists ("/etc/shorewall/tunnels") == true)
$vpnsts="checked ";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/css/bridge.css">
<title><?php p_title(); ?></title>
<script>
<?php setTimeout(); ?>
<?php include 'inc/general.js.php' ?>
function initPage()
{
var f=getObj("form");
f.ts_enable.checked = <?php echo @stat("/etc/shorewall/tcinterfaces")==false? "false":"true" ?>;
<?php if (file_exists("/etc/shorewall/tcinterfaces")) {?>
f.dl_speed.value="<?php echo exec ("cat /etc/shorewall/tcinterfaces | awk 'NR>5{gsub(".'"mbit",""); printf "%s"'.", $3}'"); ?>";
f.ul_speed.value="<?php echo exec ("cat /etc/shorewall/tcinterfaces | awk 'NR>5{gsub(".'"mbit",""); printf "%s"'.", $4}'"); ?>";
<?php } if (g_srvstat("shorewall") == true) { echo 'f.activate.value = "Activate";'; } ?>
f.PASSWD.value == "00000000";
return true;
}
function checkPage()
{
var f=getObj("form");
if (getObj("ts_enable").checked == true) {
if (isFieldBlank(f.dl_speed.value) == true) {
f.dl_speed.select();
alert("Blank Download speed field");
return false;
}
if (isFieldBlank(f.ul_speed.value) == true) {
f.ul_speed.select();
alert("Blank Upload speed field");
return false;
}
if (isDecimal(f.dl_speed.value) == false) {
f.dl_speed.select();
alert("Not a valid number");
return false;
}
if (isDecimal(f.ul_speed.value) == false) {
f.ul_speed.select();
alert("Not a valid number");
return false;
}
if (isInRange(f.dl_speed.value, 1, 1000) == false) {
f.dl_speed.select();
alert("Not in range (1-1000");
return false;
}
if (isInRange(f.ul_speed.value, 1, 1000) == false) {
f.ul_speed.select();
alert("Not in range (1-1000");
return false;
}
}
var pw=getObj("PASSWD");
if (f.ACTION_DO_FWS.value==1) {
if (pw.value == "00000000" || isFieldBlank(pw.value) == true ) {
pw.select();
alert("A Super Admin Password is required to set <?php p_mode(); ?> Accessibility");
return false;
}
}
f.ts_enabled.value=(getObj("ts_enable").checked? "1":"0");
f.SUPER_PASSWD.value = pw.value;
var f=getObj("form");
f.POST_ACTION.value = "OK";
f.submit();
}
function do_stop()
{
var f=getObj("form");
var pw=getObj("PASSWD");
if (pw.value == "00000000" || isFieldBlank(pw.value) == true ) {
pw.select();
alert("A Super Admin Password is required");
return false;
}
f.activate.value = "Stop";
f.SUPER_PASSWD.value = pw.value;
f.POST_ACTION.value = "OK";
f.submit();
}
function do_activate()
{
var f=getObj("form");
f.activate.value = "Activate";
f.POST_ACTION.value = "OK";
f.submit();
}
function onenable_ts(objs)
{
var f=getObj("form");
f.ts_enabled.value=(objs.checked? "1":"0");
return true;
}
function onenable_fws()
{
var f=getObj("form");
f.ssh_enabled.value=(getObj("ssh_enable").checked? "1":"0");
f.nfs_enabled.value=(getObj("nfs_enable").checked? "1":"0");
f.vpn_enabled.value=(getObj("vpn_enable").checked? "1":"0");
f.ACTION_DO_FWS.value = "1";
return true;
}
function do_ts()
{
var f=getObj("form");
f.ACTION_DO_TS.value = "1";
}
</script>
</head>
<body onload="initPage();"><script>onbody();</script>
<form name="form" id="form" method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" onsubmit="return checkPage();">
<input name="POST_ACTION" value="" type="hidden">
<input name="ts_enabled" value="0" id="ts_enabled" type="hidden">
<input name="ACTION_DO_FWS" value="0" type="hidden">
<input name="ACTION_DO_TS" value="0" type="hidden" >
<input name="ssh_enabled" value="0" id="ssh_enabled" type="hidden">
<input name="nfs_enabled" value="0" id="nfs_enabled" type="hidden">
<input name="vpn_enabled" value="0" id="vpn_enabled" type="hidden">
<input name="activate" value="" id="activate" type="hidden">
<input name="SUPER_PASSWD" value="00000000" id="SUPER_PASSWD" type="hidden">
<table id="topContainer">
<tr>
<td class="laCN">Project Page : <a href="<?php p_productHome(); ?>" target=_blank><?php p_serverName(); ?></a></td>
<td class="raCN">Version : <?php p_firmware("-ro");?> </td>
</tr>
</table>
<table id="topTable">
<tr>
<td id="topBarLeft"><a id="logo" href="<?php p_productHome(); ?>"></a></td>
<td id="topBarRight"></td>
</tr>
</table>
<table id="topMenuTable">
<tr>
<td class="ledPanel">
<img class="led" alt="fwstat" title="Firewall" src="/img/<?php echo g_srvstat("shorewall")? "on":"off" ?>.png">
<img class="led" alt="dnsstat" title="DNS" src="/img/<?php echo g_srvstat("named")? "on":"off" ?>.png">
<img class="led" alt="dhcpstat" title="DHCP" src="/img/<?php echo g_srvstat("dhcpd")? "on":"off" ?>.png">
</td>
<td class="topMenuLink"><a href="/network.php">Setup</a></td>
<td class="topMenuThis"><a href="/advanced.php">Advanced</a></td>
<td class="topMenuLink"><a href="/admin.php">MAINTENANCE</a></td>
<td class="topMenuLink"><a href="/status.php">Status</a></td>
<td class="topMenuLink"><a href="/logout.php"><span id="timer"></span></a></td>
</tr>
</table>
<table id="mainContentTable">
<tr style="vertical-align: top;">
<td class="leftMenyContatiner">
<div class="leftNavLink">
<ul style="width: 100%">
<li><div id="left" class="navThis">Security</div></li>
<li><div class="leftnavLink"><a href="/virtual.php">Virtual Server</a></div></li>
<li><div class="leftnavLink"><a href="/vpn.php">Inbound Access</a></div></li>
<li><div class="leftnavLink"><a href="/blacklist.php">URL Blacklist</a></div></li>
<li><div class="leftnavLink"><a href="/logfw.php">Firewall Log</a></div></li>
</ul>
</div>
</td>
<td id="contentHeading">
<div id="contentBox">
<h1>Firewall</h1>
<?php if (g_srvstat("shorewall") || file_exists("/tmp/shwlog") == true) { ?>
<br>
<input value="Save Settings" type="submit">
<input value="Don't Save Settings" onclick="cancelSettings()" type="button">
<?php }?>
<table><tr><td style="text-align:right">
<?php
if (g_srvstat("shorewall") == false) {
echo '<b style="color:#f00;">Firewall: stopped</b> ';
if (($_SERVER["SERVER_ADDR"] == g_srvip()&& g_srvlan() == g_wan()) || $_SERVER["SERVER_ADDR"] == g_ip(g_wan())) {
echo ' <br><b>The firewall cannot be started since you are administer this pages from the WAN side.</b> ';
echo '<br>Start using the public LAN (address='.g_ip(g_lan()).'/interface='.g_lan().') instead. ';
if (g_srvip() != "0")
echo '<br>Also disable the Fixed Static Address in the <b>SETUP=>Network</b> menu. ';
}
$dis = file_exists("/tmp/shwlog") == true? ' disabled' : '';
echo '<input type="button"'.$dis.' onclick="return do_activate();" value="Activate">';
} else {
echo '<b style="color:#090;">Firewall: active</b> ';
echo '<input type="button" onclick="do_stop()" value="Stop">';
}
if (@stat("/tmp/shwlog") != false) {
echo "<pre>\n";
@system("grep -i error /tmp/shwlog;");
echo "</pre>\n";
}
?>
</td></tr></table>
<?php if (count($_GET)>0 && $_GET["msg"] == "noauth") { ?>
<b>Super Admin Authorization failed</b>
<?php }?>
</div><div class="vbr"></div>
<div class="actionBox" id="showTs" onclick="do_ts();" style="display:<?php echo g_srvstat("shorewall")? "block":"none"; ?>">
<h2 class="actionHeader">WAN Traffic Shaping</h2>
<table>
<tbody>
<tr>
<td colspan="2" class="raCB" style="width:40%; height:25px">Enable Traffic Shaping :</td>
<td colspan="3" class="laCB">
<input type="checkbox" id="ts_enable" onChange="onenable_ts(this)">
</td>
</tr>
<tr>
<td class="raCB" style="height:25px">Download speed :</td>
<td class="laCB">
<input size="6" maxlength="4" type="text" name="dl_speed" id="dl_speed" value="0"> mbit
</td><td></td>
<td class="raCB" style="height:25px">Upload speed :</td>
<td class="laCB" style="width:40%">
<input size="6" maxlength="4" type="text" name="ul_speed" id="ul_speed" value="0"> mbit
</td>
</tr>
</tbody>
</table>
</div><div class="vbr"></div>
<div class="actionBox" id="showAcc" style="display:<?php echo g_srvstat("shorewall")? "block":"none"; ?>">
<h2 class="actionHeader">Accessibility for the <?php p_mode(); ?></h2>
<table>
<tbody>
<tr>
<td class="raCB" style="vertical-align:bottom;width:40%" >Super Admin Password :</td>
<td colspan="2" class="laCB"> <input type="password" autocomplete="off" id="PASSWD" value="00000000"></td>
<tr>
<td class="raCB" style="height:25px">Enable VPN :</td>
<td class="laCB">
<input type="checkbox" <?php echo $vpnsts; ?>id="vpn_enable" onChange="onenable_fws();">
</td>
<td>Allow this <?php p_mode(); ?> to be the VPN Server for the LAN</td>
</tr>
<tr>
<td class="raCB" style="height:25px">Enable SSH :</td>
<td class="laCB">
<input type="checkbox" <?php echo $sshsts; ?>id="ssh_enable" onChange="onenable_fws();">
</td>
<td>Login permission to the <?php p_mode(); ?> from the LAN</td>
</tr>
<tr>
<td class="raCB" style="height:25px">LAN NFS access of these pages :</td>
<td class="laCB">
<input type="checkbox" <?php echo $nfssts; ?>id="nfs_enable" onChange="onenable_fws();">
</td>
<td>Mainly for system development</td>
</tr>
</tbody>
</table>
</div>
</td>
<td id="quickHelpContent"><strong>Help...</strong><br>
<br>
Here you can start and stop the firewall for your LAN.<br>To stop the firewall, a Super Admin password is required.
<br><br>
You can shape incoming and outgoing network traffic.
Simple Traffic Shaping allows you to set a limit on the total bandwidth allowed in or out of the <?php p_mode(); ?>.
<br><br>
To complete the VPN service running on this <?php p_mode(); ?> you have to go to the "Inbound Access" page.<br><br>
If you have a VPN service running on a server inside your LAN, go to the "Virtual Server" page to allow a VPN service for that server.<br>
</td>
</tr>
<tr>
<td colspan="3" id="footer">
Copyright © <?php p_copyRight(); ?>
</td>
</tr>
</table>
</form>
<?php
if (@stat("/tmp/shwlog") != false) {
echo '<script>getObj("showTs").style.display = "block"; getObj("showAcc").style.display = "block";</script>';
unlink("/tmp/shwlog"); }
?>
</body>
</html>