-
Notifications
You must be signed in to change notification settings - Fork 0
/
arpwatch_reports.php
147 lines (135 loc) · 5.33 KB
/
arpwatch_reports.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
#!/usr/local/bin/php
<?php
/*
$Id$
arpwatch_reports.php
Copyright (C) 2005 Colin Smith
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("service-utils.inc");
//if for some reason it is not passed an interface...
if(!isset($_GET['interface']) || $_GET['interface']=="default") {
$interface = convert_friendly_interface_to_real_interface_name($config['installedpackages']['arpwatch']['config'][0]['interface_array'][0]);
}
else {
$interface = $_GET['interface'];
}
$logfile = "/var/log/arp." . $interface . ".dat";
if ($_POST['clear']) {
stop_service("arpwatch");
unlink_if_exists($logfile);
touch($logfile);
start_service("arpwatch");
}
if(file_exists($logfile)) {
$rawrep = file($logfile);
foreach($rawrep as $line) {
$todo = preg_split('/\s/', $line);
$rawmac = explode(":", trim($todo[0]));
foreach($rawmac as $set) $mac[] = str_pad($set, 2, "0", STR_PAD_LEFT);
$newmac = implode(":", $mac);
$report[$todo[1]][] = array(
"mac" => $newmac,
"timestamp" => trim($todo[2]),
"hostname" => trim($todo[3]) ? trim($todo[3]) : "Unknown"
);
unset($mac);
}
}
$pgtitle = "Arpwatch: Reports";
include("head.inc");
?>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td class="tabnavtbl">
<?php
$tab_array = array();
$tab_array[] = array("Settings", false, "pkg_edit.php?xml=arpwatch.xml&id=0");
$tab_array[] = array("Reports", true, "arpwatch_reports.php");
display_top_tabs($tab_array);
?>
</td></tr>
<tr><td class="tabnavtbl">
<?php
$tab_array = array();
foreach($config['installedpackages']['arpwatch']['config'][0]['interface_array'] as $iface) {
$if = convert_friendly_interface_to_real_interface_name($iface);
if($if) {
$tab_array[] = array(gettext($iface),
(($interface == $if)),
"/arpwatch_reports.php?interface={$if}");
}
}
display_top_tabs($tab_array);
?>
</td></tr>
<tr>
<td>
<div id="mainarea">
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="4" class="listtopic"><?php echo convert_real_interface_to_friendly_interface_name($interface); ?> entries</td>
</tr>
<tr>
<td width="15%" class="listhdrr">IP</td>
<td width="25%" class="listhdrr">Timestamp</td>
<td width="15%" class="listhdrr">MAC</td>
<td width="45%" class="listhdrr">Hostname</td>
</tr>
<?php
if($report)
foreach($report as $ip => $rawentries) {
$printip = true;
$entries = $rawentries;
sort($entries);
foreach($entries as $entry) {
echo '<tr>';
if($printip) {
echo '<td class="listlr">' . $ip . '</td>';
$stampclass = "listr";
$printip = false;
} else {
$stampclass = "listlr";
echo '<td></td>';
}
echo '<td class="' . $stampclass . '">' .
date("D M j G:i:s", $entry['timestamp']) .
'</td>';
echo '<td class="listr">' . $entry['mac'] . '</td>';
echo '<td class="listr">' . $entry['hostname'] . '</td>';
echo '</tr>';
}
}
?>
<tr>
<td>
<br>
<form action="arpwatch_reports.php?interface=<?php echo $interface;?>" method="post">
<input name="clear" type="submit" class="formbtn" value="Clear log">
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>