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.2 $
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.2 2007-01-11 13:44:29 arjen
31 Manually edit parameters.
32 View logs from abusing IP addresses.
34 Revision 1.1 2005/06/04 07:24:38 arjen
37 ******************************/
39 // RCSID = "$Id: abuse.php,v 1.2 2007-01-11 13:44:29 arjen Exp $";
41 ini_set('include_path', '.:./classes:../phpclasses');
43 require_once('page.class.php');
46 class abuse_list extends page
51 if (!empty($_GET['oid']))
53 $res = pg_exec($this->database, "SELECT objectname FROM object
54 WHERE objectid=CAST('" . $_GET['oid']."' AS BIGINT)");
55 $obj = pg_fetch_object($res, 0);
56 echo "<h1>Abuse List for " . $obj->objectname . "</h1><hr>";
58 if (!empty($_POST['ACTION']) && ($_POST['ACTION'] == 'Abuse'))
61 $Source_IP = $_POST['source'];
62 echo "Reporting " . $_POST['ACTION'] . " for " . $_POST['source'] . "<br>\n";
63 $res = pg_exec($this->database, "SELECT * FROM object_abuse
64 WHERE objectid='". $_GET['oid'] ."' AND source='$Source_IP'");
65 if (pg_numrows($res) == 0)
67 echo "$Source_IP is new.<br>";
68 pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
69 "', '$Source_IP', '$abuse_points')");
73 $abuse = pg_fetch_object($res, 0);
74 $abuse_points += $abuse->nr_abuses;
75 echo $Source_IP . " will get " . $abuse_points . " abuse points.<br>";
76 echo "Status was " . $abuse->status . "<br>";
77 pg_exec($this->database, "UPDATE object_abuse SET nr_abuses='$abuse_points'" .
78 " WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
80 if ($abuse_points >= 6)
82 echo "<h2 class='error'>Block IP adrress $Source_IP on the firewall.</h2>";
83 pg_exec($this->database, "UPDATE object_abuse SET status='dropped'" .
84 " WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
87 //select rawdata from log where logid in (select logid from log_abuse where source='');
90 else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Investigate')
92 // Present a list of abuse addresses in one subnet
94 $Subnet = $_POST['subnet'];
95 $res = pg_exec($this->database, "SELECT * FROM object_abuse
96 WHERE objectid='". $_GET['oid'] ."' AND source << '$Subnet'");
98 echo pg_numrows($res) . " records found.<br>";
101 echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th></tr>\n";
103 for ($ip = 0; $ip < pg_numrows($res); $ip++)
105 $abuse = pg_fetch_object($res, $ip);
109 echo $abuse->nr_abuses;
117 else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Block')
119 // Block an entire subnet and remove the addresses from the list
121 $Subnet = $_POST['subnet'];
122 pg_exec($this->database, "DELETE FROM object_abuse WHERE objectid = '" . $_GET['oid']
123 . "' AND source << '$Subnet'");
125 pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
126 "', '$Subnet', '$abuse_points', 'dropped')");
129 if (!empty($_GET['src']))
133 $res = pg_exec($this->database, "SELECT logid FROM log_abuse WHERE objectid=$oid AND source <<= '$src'");
135 echo "<tr><th>Abused log entry</th></tr>";
136 for ($row = 0; $row < pg_numrows($res); $row++)
138 $logid = pg_fetch_object($res, $row);
139 //$log = pg_fetch_object(pg_exec($this->database, "SELECT rawdata FROM log WHERE logid=" . $logid->logid), 0);
141 //echo $log->rawdata;
149 echo "<form method='post'>";
150 echo "Report <input type='submit' name='ACTION' value='Abuse'>";
151 echo " for IP address <input type='text' name='source'>";
154 echo "<form method='post'>";
155 echo "<input type='submit' name='ACTION' value='Investigate'>";
156 echo " or <input type='submit' name='ACTION' value='Block'>";
157 echo " this subnet: <input type='text' name='subnet'>";
160 $res = pg_exec($this->database, "SELECT * FROM object_abuse
161 WHERE objectid='". $_GET['oid'] ."' ORDER BY source");
163 echo pg_numrows($res) . " records found.<br>";
166 echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th><th>Last Changed</th></tr>\n";
168 for ($ip = 0; $ip < pg_numrows($res); $ip++)
170 $abuse = pg_fetch_object($res, $ip);
174 echo "<a href='abuse.php?oid=" . $_GET['oid'] . "&src=" . $abuse->source . "'>" . $abuse->nr_abuses . "</a>";
178 echo $abuse->last_changed;
187 $page = new abuse_list("Gnucomo Abuse List");