backwards compatibility with 4.2
[nodeconfig.git] / PlanetLabConf / blacklist.php
1 #
2 # /etc/planetlab/blacklist
3 #
4 # post: iptables-restore --noflush < /etc/planetlab/blacklist
5 #
6 # PlanetLab per-node outbound blacklist
7
8 # Aaron Klingaman <alk@cs.princeton.edu>
9 # Mark Huang <mlhuang@cs.princeton.edu>
10 # Copyright (C) 2004 The Trustees of Princeton University
11 #
12 # $Id$
13 #
14
15 *filter
16 -F BLACKLIST
17
18 <?php
19
20 // Get admin API handle
21 require_once 'plc_api.php';
22 global $adm;
23
24 // backwards compatibility with the old 4.2 API
25 global $__PLC_API_VERSION;
26 if ( ! method_exists ($adm,"GetInterfaces"))
27   $__PLC_API_VERSION = 4.2;
28 else
29   $__PLC_API_VERSION = 4.3;
30
31 // Look up the node
32 if ($__PLC_API_VERSION==4.2)
33   $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
34 else
35   $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
36 if (!empty($interfaces)) {
37   $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
38   if (!empty($nodes)) {
39     $node = $nodes[0];
40   }
41 }
42
43 if (isset($node)) {
44   // XXX Implement generic "networks" table
45   // $networks = $adm->GetNetworks();
46   $networks = array();
47   foreach ($networks as $network) {
48     if ($network['blacklisted']) {
49       $dest = $network['ip'];
50       if ($network['netmask']) {
51         $dest .= "/" . $network['netmask'];
52       }
53       print "-A BLACKLIST -d $dest -j LOGDROP\n";
54     }
55   }
56 }
57
58 print "\n";
59
60 ?>
61
62 COMMIT