3 /**************************************************************************
4 ** (c) Copyright 2003, Andromeda Technology & Automation
5 ** This is free software; you can redistribute it and/or modify it under the
6 ** terms of the GNU General Public License, see the file COPYING.
7 ***************************************************************************
8 ** MODULE INFORMATION *
9 ***********************
10 ** FILE NAME : abuse.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.3 $
14 ** DESCRIPTION : Abuse list page
19 ***************************************************************************
20 ** ADMINISTRATIVE INFORMATION *
21 ********************************
22 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
23 ** CREATION DATE : Apr 13, 2004
24 ** LAST UPDATE : Apr 13, 2004
26 **************************************************************************/
28 /*****************************
30 Revision 1.3 2007-10-19 07:15:52 arjen
31 In the abuse list, IP addresses can be whitelisted.
33 Revision 1.2 2007/01/11 13:44:29 arjen
34 Manually edit parameters.
35 View logs from abusing IP addresses.
37 Revision 1.1 2005/06/04 07:24:38 arjen
40 ******************************/
42 // RCSID = "$Id: abuse.php,v 1.3 2007-10-19 07:15:52 arjen Exp $";
44 ini_set('include_path', '.:./classes:../phpclasses');
46 require_once('page.class.php');
49 class abuse_list extends page
54 if (!empty($_GET['oid']))
56 $res = pg_exec($this->database, "SELECT objectname FROM object
57 WHERE objectid=CAST('" . $_GET['oid']."' AS BIGINT)");
58 $obj = pg_fetch_object($res, 0);
59 echo "<h1>Abuse List for " . $obj->objectname . "</h1><hr>";
61 if (!empty($_POST['ACTION']) && ($_POST['ACTION'] == 'Abuse'))
64 $Source_IP = $_POST['source'];
65 echo "Reporting " . $_POST['ACTION'] . " for " . $_POST['source'] . "<br>\n";
66 $res = pg_exec($this->database, "SELECT * FROM object_abuse
67 WHERE objectid='". $_GET['oid'] ."' AND source='$Source_IP'");
68 if (pg_numrows($res) == 0)
70 echo "$Source_IP is new.<br>";
71 pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
72 "', '$Source_IP', '$abuse_points', '', NOW())");
76 $abuse = pg_fetch_object($res, 0);
77 $abuse_points += $abuse->nr_abuses;
78 echo $Source_IP . " will get " . $abuse_points . " abuse points.<br>";
79 echo "Status was " . $abuse->status . "<br>";
80 pg_exec($this->database, "UPDATE object_abuse SET nr_abuses='$abuse_points'" .
81 ", last_change=NOW() WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
83 if ($abuse_points >= 6)
85 echo "<h2 class='error'>Block IP adrress $Source_IP on the firewall.</h2>";
86 pg_exec($this->database, "UPDATE object_abuse SET status='dropped'" .
87 " WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
90 //select rawdata from log where logid in (select logid from log_abuse where source='');
93 else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Whitelist')
95 $Source_IP = $_POST['source'];
96 echo "Whitelisting " . $_POST['source'] . "<br>\n";
97 $res = pg_exec($this->database, "SELECT * FROM object_abuse
98 WHERE objectid='". $_GET['oid'] ."' AND source='$Source_IP'");
99 $Status = $_POST['status'];
100 if (pg_numrows($res) == 0)
102 echo "$Source_IP is new.<br>";
103 pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
104 "', '$Source_IP', 0, '$Status', NOW())");
108 $abuse = pg_fetch_object($res, 0);
109 echo $Source_IP . " will be whitelisted.<br>";
110 echo "Status was " . $abuse->status . "<br>";
111 pg_exec($this->database, "UPDATE object_abuse SET status='$Status'" .
112 ", last_change=NOW() WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
115 else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Investigate')
117 // Present a list of abuse addresses in one subnet
119 $Subnet = $_POST['subnet'];
120 $res = pg_exec($this->database, "SELECT * FROM object_abuse
121 WHERE objectid='". $_GET['oid'] ."' AND source << '$Subnet'");
123 echo pg_numrows($res) . " records found.<br>";
126 echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th></tr>\n";
128 for ($ip = 0; $ip < pg_numrows($res); $ip++)
130 $abuse = pg_fetch_object($res, $ip);
134 echo $abuse->nr_abuses;
142 else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Block')
144 // Block an entire subnet and remove the addresses from the list
146 $Subnet = $_POST['subnet'];
147 pg_exec($this->database, "DELETE FROM object_abuse WHERE objectid = '" . $_GET['oid']
148 . "' AND source << '$Subnet'");
150 pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
151 "', '$Subnet', '$abuse_points', 'dropped', NOW())");
154 if (!empty($_GET['src']))
158 $res = pg_exec($this->database, "SELECT * FROM log WHERE logid IN
159 (SELECT logid FROM log_abuse WHERE objectid=$oid AND source <<= '$src')
160 ORDER BY object_timestamp");
162 echo "<tr><th>Time</th><th>Service</th><th>Abused log entry</th></tr>";
163 for ($row = 0; $row < pg_numrows($res); $row++)
165 $log = pg_fetch_object($res, $row);
166 //$log = pg_fetch_object(pg_exec($this->database, "SELECT rawdata FROM log WHERE logid=" . $logid->logid), 0);
168 echo $log->object_timestamp;
170 echo $log->servicecode;
179 echo "<form method='post'>";
180 echo "Report <input type='submit' name='ACTION' value='Abuse'>";
181 echo " for IP address <input type='text' name='source'>";
182 echo " or <input type='submit' name='ACTION' value='Whitelist'>";
183 echo " with status <input type='text' name='status'>";
186 echo "<form method='post'>";
187 echo "<input type='submit' name='ACTION' value='Investigate'>";
188 echo " or <input type='submit' name='ACTION' value='Block'>";
189 echo " this subnet: <input type='text' name='subnet'>";
192 $res = pg_exec($this->database, "SELECT * FROM object_abuse
193 WHERE objectid='". $_GET['oid'] ."' ORDER BY source");
195 echo pg_numrows($res) . " records found.<br>";
198 echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th><th>Last Changed</th></tr>\n";
200 for ($ip = 0; $ip < pg_numrows($res); $ip++)
202 $abuse = pg_fetch_object($res, $ip);
206 echo "<a href='abuse.php?oid=" . $_GET['oid'] . "&src=" . $abuse->source . "'>" . $abuse->nr_abuses . "</a>";
210 echo $abuse->last_change;
219 $page = new abuse_list("Gnucomo Abuse List");