backwards compatibility with 4.2
[nodeconfig.git] / PlanetLabConf / proxies.php
1 #
2 # /etc/planetlab/proxies
3 #
4 # post: service vnet restart
5 #
6 # Proxy (a.k.a. network telescope a.k.a. honeypot) interface configuration
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 <?php
16 // Get admin API handle
17 require_once 'plc_api.php';
18 global $adm;
19
20 // Look up the node
21 // backwards compatibility with the old 4.2 API
22 global $__PLC_API_VERSION;
23 if ( ! method_exists ($adm,"GetInterfaces"))
24   $__PLC_API_VERSION = 4.2;
25 else
26   $__PLC_API_VERSION = 4.3;
27 if ($__PLC_API_VERSION==4.2)
28   $interfaces = $adm->GetNodeNetworks(array('ip' => $_SERVER['REMOTE_ADDR']));
29 else
30   $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
31
32 if (!empty($interfaces)) {
33   $nodes = $adm->GetNodes(array($interfaces[0]['node_id']));
34   if (!empty($nodes)) {
35     $node = $nodes[0];
36   }
37 }
38
39 if (!isset($node)) {
40   exit();
41 }
42
43 if ($__PLC_API_VERSION==4.2)
44   $interfaces = $adm->GetInterfaces($node['nodenetwork_ids']);
45 else
46   $interfaces = $adm->GetInterfaces($node['interface_ids']);
47
48 foreach ($interfaces as $interface) {
49   // XXX PL2896: need interfaces.device
50   switch ($interface['method']) {
51   case 'tap':
52     $dev = "tap0";
53     $types['taps'][$dev][0] = $interface['ip'] . "/" . $interface['gateway'];
54     break;
55   case 'proxy':
56     $dev = "proxy0";
57     $types['proxies'][$dev][] = $interface['ip'];
58     break;
59   }
60 }
61
62 // taps="tap0 tap1 ..."
63 // tap0="1.2.3.4/5.6.7.8"
64 // tap1="9.10.11.12/13.14.15.16"
65 // ...
66 // proxies="proxy0 proxy1 ..."
67 // proxy0="1.2.3.4 5.6.7.8 ..."
68 // proxy1="9.10.11.12 13.14.15.16 ..."
69 // ...
70 if (isset($types)) {
71   foreach ($types as $type => $devs) {
72     print("$type=\"" . implode(" ", array_keys($devs)) . "\"\n");
73     foreach ($devs as $dev => $ips) {
74       print("$dev=\"" . implode(" ", $ips) . "\"\n");
75     }
76   }
77 }
78
79 ?>