-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogfw.php
309 lines (278 loc) · 11.6 KB
/
logfw.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
<?php
/*
* logfw.php
*
* Copyright (C) 2013-2014 by Erland Hedman <[email protected]>
*
* 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 (! 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
do_fwlog(implode(" ", $_POST));
@system("/usr/sbin/service ulogd restart");
@system("/sbin/shorewall restart");
} else {
header('Location: http://'. $_SERVER["SERVER_ADDR"]. '/wait.php?seconds=10&loc='.$_SERVER['SCRIPT_NAME']);
exit;
}
}
@system("grep REJECT /etc/shorewall/policy | grep ".'"\$LOG" >/dev/null', $rej);
@system("grep DROP /etc/shorewall/policy | grep ".'"\$LOG" >/dev/null', $drp);
$rej=$rej==0? 1:0;
$drp=$drp==0? 1:0;
@exec('tail -n 300 /var/log/firewall | sed s/"Shorewall:*:"/" "/g | awk '."'".'{printf "%s,[%s] %s %s %s\n",$3,$5,$9,$17,$18}'."' >/tmp/fwlog");
$totlines=@exec("wc -l /tmp/fwlog | awk '{print $1}'");
$aPage=20;
$lastpage=ceil($totlines/$aPage <1? 1:$totlines/$aPage);
?>
<!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' ?>
var aPage=<?php echo $aPage ?>;
var curPage=1;
var curLine=1;
function doPage(from, to)
{
var i;
for (i=1; i< <?php echo $totlines ?>; i++) {
if (i >=from && i <= to)
getObj("item-"+i).style.display="";
else
getObj("item-"+i).style.display="none";
}
}
function doSearch(obj) //str.toLowerCase()
{
var i;
var f=0;
for (i=1; i< <?php echo $totlines ?>; i++) {
if (getObj("msg_"+i).value.toLowerCase().search(obj.value.toLowerCase())!=-1) {
getObj("item-"+i).style.display="";
f++;
} else
getObj("item-"+i).style.display="none";
}
if (f) {
getObj("Next").disabled=getObj("Prev").disabled=true;
getObj("First").disabled=getObj("Last").disabled=false;
getObj("show_pages").style.display="none";
}
}
function submitEnter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
doSearch(myfield);
return false;
} else
return true;
}
function nextPage()
{
var lastline=curLine+aPage > <?php echo $totlines ?>? <?php echo $totlines ?>:curLine+aPage;
if (lastline >= <?php echo $totlines ?>) {
getObj("Next").disabled=true;
}
doPage(curLine, --lastline);
curLine=lastline+1;
curPage++;
getObj("curPage").innerHTML=curPage;
getObj("Prev").disabled= false;
getObj("First").disabled=false;
}
function prevPage()
{
curLine=curLine-(aPage*2) <1? 1:curLine-(aPage*2);
curPage=curPage-1 <1? 1:curPage-1;
doPage(curLine, curLine+(aPage-1));
curLine+=aPage;
getObj("curPage").innerHTML=curPage;
if (curLine <=1)
getObj("Prev").disabled= true;
getObj("Next").disabled= false;
}
function initPage()
{
curLine=1;
curPage=1;
doPage(curLine, aPage);
curLine+=aPage;
document.getElementById("curPage").innerHTML=1;
if (<?php echo $totlines ?> < <?php echo $aPage ?>)
getObj("Last").disabled= getObj("Next").disabled= true;
else
getObj("Last").disabled= getObj("Next").disabled= getObj("Prev").disabled= false;
getObj("Prev").disabled=getObj("First").disabled= true;
getObj("show_pages").style.display="block";
return true;
}
function lastPage()
{
var f=<?php echo $totlines ?> < <?php echo $aPage ?>? 1:(<?php echo $totlines ?>-<?php echo $aPage ?>);
doPage(f, <?php echo $totlines ?>);
curLine=<?php echo $totlines ?>;
curPage=getObj("curPage").innerHTML=<?php echo $lastpage; ?>;
getObj("Prev").disabled=getObj("First").disabled=false;
getObj("Next").disabled=true;
getObj("show_pages").style.display="block";
}
function enable_rj(objs)
{
var f=getObj("form");
f.f_rj_enabled=(objs.checked? 1:0);
return true;
}
function enable_dr(objs)
{
var f=getObj("form");
f.f_dr_enabled=(objs.checked? 1:0);
return true;
}
function checkPage()
{
var f=getObj("form");
f.f_dr_enabled.value=(getObj("dr_enablecb").checked? 1:0);
f.f_rj_enabled.value=(getObj("rj_enablecb").checked? 1:0);
f.POST_ACTION.value = "OK";
f.submit();
return true;
}
</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="f_dr_enabled" value="<?php echo $drp ?>" type="hidden">
<input name="f_rj_enabled" value="<?php echo $rej ?>" 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 class="leftnavLink"><a href="/firewall.php">Security</a></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 id="left" class="navThis">Firewall Log</div></li>
</ul>
</div>
</td>
<td id="contentHeading">
<div id="contentBox">
<h1>View the firewall log.</h1>
<br>
<?php if (g_srvstat("shorewall")) { ?>
<input value="Save Settings" type="submit">
<input value="Don't Save Settings" onclick="cancelSettings()" type="button">
<?php }?>
<div style="text-align:right"><?php echo g_srvstat("shorewall")? '<b style="color:#090;">Firewall: active</b>':'<b style="color:#f00;">Firewall: stopped</b>' ?></div>
</div><div class="vbr"></div>
<div class="actionBox">
<h2 class="actionHeader">Log Options</h2>
<table>
<tr>
<td class="raCB" style="width:40%;height:25px">Log dropped packets :</td>
<td class="laCB">
<input <?php echo $drp==1? "checked ":""; ?>type="checkbox" id="dr_enablecb" onChange="enable_dr(this)">
</td>
</tr>
<tr>
<td class="raCB" style="height:25px">Log rejected packets :</td>
<td class="laCB">
<input <?php echo $rej==1? "checked ":""; ?>type="checkbox" id="rj_enablecb" onChange="enable_rj(this)">
</td>
</tr>
</table>
</div><div class="vbr"></div>
<div class="actionBox">
<h2 class="actionHeader">Log Details</h2>
<div style="padding: 6px;">
<input id="First" value="First Page" onclick="initPage()" type="button">
<input id="Last" value="Last Page" onclick="lastPage()" type="button">
<input id="Prev" value="Previous" onclick="prevPage()" type="button">
<input id="Next" value="Next" onclick="nextPage()" type="button">
<input value="Refresh" onclick="cancelSettings()" type="button">
Find :
<input title="Press return" id="search" size="16" maxlength="40" value="" onKeyPress="return submitEnter(this,event)" type="text">
<br><br><div id="show_pages">Page <span id="curPage"></span> of <?php echo $lastpage; ?></div>
</div>
<table class="logTable">
<tr><td style="width:60px"><b>Time</b></td><td><b>Message</b></td></tr>
<?php
$fd = fopen("/tmp/fwlog", "r");
$i=1;
while (!feof($fd)) {
$a=explode("," ,trim(fgets($fd)));
if (count($a) <2) continue;
echo " <tr id='item-".$i."' style='display:none'><td>".$a[0]."</td>";
echo "<td><input name='".$i."' id='msg_".$i."' value='".$a[1]."' type='hidden'>".$a[1]."</td></tr>\n";
$i++;
}
fclose($fd);
unlink("/tmp/fwlog");
?>
</table>
</div>
</td>
<td id="quickHelpContent"><strong>Help...</strong><br><br>
Check the log to view firewall activities.<br><br>
The log is resetted every 15 minutes.
</td>
</tr>
<tr>
<td colspan="3" id="footer">
Copyright © <?php p_copyRight(); ?>
</td>
</tr>
</table>
</form>
</body>
</html>