Manually edit parameters.
[gnucomo.git] / src / web / abuse.php
1 <?php
2
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 $
13 **
14 **  DESCRIPTION      : Abuse list page
15 **
16 **  EXPORTED OBJECTS : 
17 **  LOCAL    OBJECTS : 
18 **  MODULES  USED    :
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
25 **      MODIFICATIONS   : 
26 **************************************************************************/
27
28 /*****************************
29    $Log: abuse.php,v $
30    Revision 1.2  2007-01-11 13:44:29  arjen
31    Manually edit parameters.
32    View logs from abusing IP addresses.
33
34    Revision 1.1  2005/06/04 07:24:38  arjen
35    New page: Abuse list
36
37 ******************************/
38
39 // RCSID = "$Id: abuse.php,v 1.2 2007-01-11 13:44:29 arjen Exp $";
40
41 ini_set('include_path', '.:./classes:../phpclasses');
42
43 require_once('page.class.php');
44
45
46 class abuse_list extends page
47 {
48
49    function Body()
50    {
51       if (!empty($_GET['oid']))
52       {
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>";
57
58          if (!empty($_POST['ACTION']) && ($_POST['ACTION'] == 'Abuse'))
59          {
60             $abuse_points = 2;
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)
66             {
67                echo "$Source_IP is new.<br>";
68                pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
69                                   "', '$Source_IP', '$abuse_points')");
70             }
71             else
72             {
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'");
79
80                if ($abuse_points >= 6)
81                {
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'");
85                }
86             }
87 //select rawdata from log where logid in (select logid from log_abuse where source='');
88
89          }
90          else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Investigate')
91          {
92             //  Present a list of abuse addresses in one subnet
93
94             $Subnet = $_POST['subnet'];
95             $res = pg_exec($this->database, "SELECT * FROM object_abuse
96                                   WHERE objectid='". $_GET['oid'] ."' AND source << '$Subnet'");
97
98             echo pg_numrows($res) . " records found.<br>";
99
100             echo "<table>";
101             echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th></tr>\n";
102
103             for ($ip = 0; $ip < pg_numrows($res); $ip++)
104             {
105                $abuse = pg_fetch_object($res, $ip);
106                echo "<tr><td>";
107                echo $abuse->source;
108                echo "</td><td>";
109                echo $abuse->nr_abuses;
110                echo "</td><td>";
111                echo $abuse->status;
112                echo "</td></tr>";
113             }
114             echo "</table>";
115
116          }
117          else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Block')
118          {
119             //  Block an entire subnet and remove the addresses from the list
120
121             $Subnet = $_POST['subnet'];
122             pg_exec($this->database, "DELETE FROM object_abuse WHERE objectid = '" . $_GET['oid']
123                                          . "' AND source << '$Subnet'");
124             $abuse_points = 8;
125             pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
126                                   "', '$Subnet', '$abuse_points', 'dropped')");
127          }
128
129          if (!empty($_GET['src']))
130          {
131             $oid = $_GET['oid'];
132             $src = $_GET['src'];
133             $res = pg_exec($this->database, "SELECT logid FROM log_abuse WHERE objectid=$oid AND source <<= '$src'");
134             echo "<table>";
135             echo "<tr><th>Abused log entry</th></tr>";
136             for ($row = 0; $row < pg_numrows($res); $row++)
137             {
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);
140                echo "<tr><td>";
141                //echo $log->rawdata;
142                echo $logid->logid;
143                echo "</td></tr>";
144             }
145             echo "</table>";
146          }
147          else
148          {
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'>";
152             echo "</form>"; 
153    
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'>";
158             echo "</form>"; 
159    
160             $res = pg_exec($this->database, "SELECT * FROM object_abuse
161                                      WHERE objectid='". $_GET['oid'] ."' ORDER BY source");
162    
163             echo pg_numrows($res) . " records found.<br>";
164    
165             echo "<table>";
166             echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th><th>Last Changed</th></tr>\n";
167    
168             for ($ip = 0; $ip < pg_numrows($res); $ip++)
169             {
170                $abuse = pg_fetch_object($res, $ip);
171                echo "<tr><td>";
172                echo $abuse->source;
173                echo "</td><td>";
174                echo "<a href='abuse.php?oid=" . $_GET['oid'] . "&src=" . $abuse->source . "'>" .  $abuse->nr_abuses . "</a>";
175                echo "</td><td>";
176                echo $abuse->status;
177                echo "</td><td>";
178                echo $abuse->last_changed;
179                echo "</td></tr>";
180             }
181             echo "</table>";
182          }
183       }
184    }
185 }
186
187 $page = new abuse_list("Gnucomo Abuse List");
188
189 $page->Showpage();
190
191 ?>