4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_functions.php';
14 // http://summer.cs.princeton.edu/
16 function plc_ip_to_int ($ip) {
17 $bytes=array_map("intval",explode(".",$ip));
19 foreach (range(0,3) as $i) {
20 $res=256*$res+$bytes[$i];
25 function plc_comon_address ($ip) {
26 return "address==".plc_ip_to_int($ip);
29 // builds the url to comon for the set of ips
30 function plc_comon_url_from_ips($comon_server_url, $ips) {
32 $select="select='" . join("||",array_map("plc_comon_address",$ips)) . "'";
34 $url=$comon_server_url .
35 "/status/tabulator.cgi?table=table_nodeviewshort&" . $select;
40 // we expect to GET either
45 // from that we get a set of nodes and compute a comon URL to gather them all
47 $fields=array("hostname","node_id","peer_id", "interface_ids");
49 if ($_GET['node_id']) {
50 $node_id=intval($_GET['node_id']);
51 $nodes=$api->GetNodes(array("node_id"=>array($node_id)),$fields);
52 } else if ($_GET['site_id']) {
53 $site_id=intval($_GET['site_id']);
54 $nodes=$api->GetNodes(array("node_type"=>"regular","site_id"=>array($site_id)),$fields);
55 } else if ($_GET['slice_id']) {
56 $slice_id=intval($_GET['slice_id']);
57 $return=$api->GetSlices(array("slice_id"=>array($slice_id)),array("node_ids"));
58 $node_ids=$return[0]['node_ids'];
59 $nodes=$api->GetNodes(array("node_type"=>"regular","node_id"=>$node_ids),$fields);
60 } else if (isset($_GET['peer_id'])) {
61 $peer_id=intval($_GET['peer_id']);
62 if ( ($peer_id == 0) || ($peer_id == "") )
64 $nodes=$api->GetNodes(array("node_type"=>"regular","peer_id"=>$peer_id),$fields);
66 echo "<div class='plc-warning'> Unexpected args in comon.php </div>\n";
71 // * gather interface_ids for local nodes
72 // * gather hostnames for foreign nodes
74 $interface_ids=array();
77 foreach ($nodes as $node) {
78 if (empty($node['peer_id'])) {
79 foreach ($node['interface_ids'] as $id=>$nnid) {
80 $interface_ids [] = $nnid;
83 $hostnames[] = $node['hostname'];
87 // Gather local ips from primary interfaces
88 // fetch primary interfaces
90 $nns = $api->GetInterfaces(array("is_primary"=>TRUE,"interface_id"=>$interface_ids),
92 foreach ($nns as $nn) {
93 $local_ips[] = $nn['ip'];
96 // for foreign hosts we're left with dns resolving them
98 foreach ($hostnames as $hostname) {
99 $resolved=gethostbyname($hostname);
100 // no way to notify this
101 if ($resolved == $hostname) {
103 $remote_ips[] = $resolved;
108 $all_ips=$local_ips+$remote_ips;
110 $url = plc_comon_url_from_ips("http://comon.cs.princeton.edu",$all_ips);