2595e0bf6afaf84dc60cff81ff6056cd9fb18336
[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.1 $
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.1  2005-06-04 07:24:38  arjen
31    New page: Abuse list
32
33 ******************************/
34
35 // RCSID = "$Id: abuse.php,v 1.1 2005-06-04 07:24:38 arjen Exp $";
36
37 ini_set('include_path', '.:./classes:../phpclasses');
38
39 require_once('page.class.php');
40
41
42 class abuse_list extends page
43 {
44
45    function Body()
46    {
47       if (!empty($_GET['oid']))
48       {
49          $res = pg_exec($this->database, "SELECT objectname FROM object
50                                           WHERE objectid=CAST('" . $_GET['oid']."' AS BIGINT)");
51          $obj = pg_fetch_object($res, 0);
52          echo "<h1>Abuse List for " . $obj->objectname . "</h1><hr>";
53
54          if (!empty($_POST['ACTION']) && ($_POST['ACTION'] == 'Abuse'))
55          {
56             $abuse_points = 2;
57             $Source_IP = $_POST['source'];
58             echo "Reporting " . $_POST['ACTION'] . " for " . $_POST['source'] . "<br>\n";
59             $res = pg_exec($this->database, "SELECT * FROM object_abuse
60                                   WHERE objectid='". $_GET['oid'] ."' AND source='$Source_IP'");
61             if (pg_numrows($res) == 0)
62             {
63                echo "$Source_IP is new.<br>";
64                pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
65                                   "', '$Source_IP', '$abuse_points')");
66             }
67             else
68             {
69                $abuse = pg_fetch_object($res, 0);
70                $abuse_points += $abuse->nr_abuses;
71                echo $Source_IP . " will get " . $abuse_points . " abuse points.<br>";
72                echo "Status was " . $abuse->status . "<br>";
73                pg_exec($this->database, "UPDATE object_abuse SET nr_abuses='$abuse_points'" .
74                            " WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
75
76                if ($abuse_points >= 6)
77                {
78                   echo "<h2 class='error'>Block IP adrress $Source_IP on the firewall.</h2>";
79                   pg_exec($this->database, "UPDATE object_abuse SET status='dropped'" .
80                            " WHERE objectid='" . $_GET['oid'] . "' AND source='$Source_IP'");
81                }
82             }
83 //select rawdata from log where logid in (select logid from log_abuse where source='');
84
85          }
86          else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Investigate')
87          {
88             //  Present a list of abuse addresses in one subnet
89
90             $Subnet = $_POST['subnet'];
91             $res = pg_exec($this->database, "SELECT * FROM object_abuse
92                                   WHERE objectid='". $_GET['oid'] ."' AND source << '$Subnet'");
93
94             echo pg_numrows($res) . " records found.<br>";
95
96             echo "<table>";
97             echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th></tr>\n";
98
99             for ($ip = 0; $ip < pg_numrows($res); $ip++)
100             {
101                $abuse = pg_fetch_object($res, $ip);
102                echo "<tr><td>";
103                echo $abuse->source;
104                echo "</td><td>";
105                echo $abuse->nr_abuses;
106                echo "</td><td>";
107                echo $abuse->status;
108                echo "</td></tr>";
109             }
110             echo "</table>";
111
112          }
113          else if (!empty($_POST['ACTION']) && $_POST['ACTION'] == 'Block')
114          {
115             //  Block an entire subnet and remove the addresses from the list
116
117             $Subnet = $_POST['subnet'];
118             pg_exec($this->database, "DELETE FROM object_abuse WHERE objectid = '" . $_GET['oid']
119                                          . "' AND source << '$Subnet'");
120             $abuse_points = 8;
121             pg_exec($this->database, "INSERT INTO object_abuse VALUES ('" . $_GET['oid'] .
122                                   "', '$Subnet', '$abuse_points', 'dropped')");
123          }
124
125          echo "<form method='post'>";
126          echo "Report <input type='submit' name='ACTION' value='Abuse'>";
127          echo " for IP address <input type='text' name='source'>";
128          echo "</form>"; 
129
130          echo "<form method='post'>";
131          echo "<input type='submit' name='ACTION' value='Investigate'>";
132          echo " or <input type='submit' name='ACTION' value='Block'>";
133          echo " this subnet: <input type='text' name='subnet'>";
134          echo "</form>"; 
135
136          $res = pg_exec($this->database, "SELECT * FROM object_abuse
137                                   WHERE objectid='". $_GET['oid'] ."' ORDER BY source");
138
139          echo pg_numrows($res) . " records found.<br>";
140
141          echo "<table>";
142          echo "<tr><th>IP address</th><th>Abuses</th><th>Status</th></tr>\n";
143
144          for ($ip = 0; $ip < pg_numrows($res); $ip++)
145          {
146             $abuse = pg_fetch_object($res, $ip);
147             echo "<tr><td>";
148             echo $abuse->source;
149             echo "</td><td>";
150             echo $abuse->nr_abuses;
151             echo "</td><td>";
152             echo $abuse->status;
153             echo "</td></tr>";
154          }
155          echo "</table>";
156       }
157    }
158 }
159
160 $page = new abuse_list("Gnucomo Abuse List");
161
162 $page->Showpage();
163
164 ?>