Provide a web interface for dropped IP addresses
[gnucomo.git] / src / web / dropped.php
1 <?php
2 /*
3  *  Provide a list of address to be blocked on the firewall
4  *  One GET parameter "object=hostname' will select dropped addresses for
5  *  that specific host. The default is to return dropped addresses for all hosts.
6  *
7  * A remote host can obtain the list of addresses with wget, for example:
8  *
9  * wget --quiet -O gnucomo-abuses --no-check-certificate https://www.andromeda.nl/gnucomo/dropped.php?object=chronon.soleus.nu
10  *
11  */
12
13 header('Content-Type: text/plain');
14 ini_set('include_path', '.:./classes:../phpclasses');
15
16 require_once('gnucomo_config.php');
17
18 //echo "client address = " . $_SERVER['REMOTE_ADDR'] . "\n";
19
20 $allowed_clients = array("82.161.249.49", "94.142.246.85");
21 //echo array_search($_SERVER['REMOTE_ADDR'], $allowed_clients);
22 //echo "\n";
23
24 if (array_search($_SERVER['REMOTE_ADDR'], $allowed_clients) !== FALSE)
25
26    $config = new gnucomo_config;
27    $config->read("gnucomo");
28
29    //  A special user for accessing dropped addresses
30
31    $name   = "firewall";
32    $passw  = "Gnuc0mo-Ab4se";
33
34    $database = pg_connect($config->Database($name, $passw));
35
36    $query = "select source from object_abuse where status='dropped' and family(source)=4";
37
38       if (!empty($_GET['object']))
39       {
40          $object_query = "SELECT objectid FROM object WHERE objectname='" . $_GET['object']."'";
41          $res = pg_exec($database, $object_query);
42          $obj = pg_fetch_object($res, 0);
43
44          $query .= " and objectid=" . $obj->objectid;
45       }
46
47    $query .= " order by source";
48
49
50    $res = pg_exec($database, $query);
51
52             for ($ip = 0; $ip < pg_num_rows($res); $ip++)
53             {
54                $abuse = pg_fetch_object($res, $ip);
55                echo $abuse->source;
56                echo "\n";
57             }
58 }
59 else
60 {
61    echo "Permission denied.\n";
62 }
63 ?>