6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_drupal.php';
14 include 'plc_header.php';
17 require_once 'plc_functions.php';
18 require_once 'plc_objects.php';
19 require_once 'plc_peers.php';
20 require_once 'plc_visibletags.php';
21 require_once 'linetabs.php';
22 require_once 'table.php';
23 require_once 'nifty.php';
25 ini_set("memory_limit","64M");
27 // --------------------
28 // recognized URL arguments
29 $peerscope=$_GET['peerscope'];
30 $pattern=$_GET['pattern'];
31 $site_id=intval($_GET['site_id']);
32 $slice_id=intval($_GET['slice_id']);
33 $person_id=intval($_GET['person_id']);
38 $tabs []= tab_nodes();
39 if (count (plc_my_site_ids()) == 1) {
40 $tabs []= tab_nodes_mysite();
42 $tabs []= tab_nodes_all_mysite();
44 $tabs []= tab_nodes_local();
46 // --------------------
50 // performs sanity check and summarize the result in a single column
51 function node_status ($node) {
54 if ($node['node_type'] != 'regular' && $node['node_type'] != 'reservable' )
55 $messages []= $node['node_type'];
57 // checks on local nodes only
58 if ( ( ! $node['peer_id']) ) {
59 // has it got interfaces
60 if (count($node['interface_ids']) == 0)
61 $messages []= "No interface";
63 return plc_vertical_table($messages,'plc-warning');
67 $node_fixed_columns=array('hostname','node_type','site_id','node_id','boot_state','run_level','last_contact',
68 'interface_ids','peer_id', 'slice_ids');
69 $visibletags = new VisibleTags ($api, 'node');
70 $visiblecolumns = $visibletags->column_names();
71 $node_columns=array_merge($node_fixed_columns,$visiblecolumns);
73 // server-side filtering - set pattern in $_GET for filtering on hostname
75 $node_filter['hostname']=$pattern;
76 $title .= " matching " . $pattern;
78 $node_filter['hostname']="*";
81 // server-side selection on peerscope
82 $peerscope=new PeerScope($api,$_GET['peerscope']);
83 $node_filter=array_merge($node_filter,$peerscope->filter());
84 $title .= ' - ' . $peerscope->label();
87 $sites=$api->GetSites(array($site_id));
90 $login_base=$site['login_base'];
91 $title .= t_site($site);
92 $tabs []= tab_site($site);
93 $node_filter['site_id']=array($site_id);
97 $slices=$api->GetSlices(array($slice_id),array('node_ids','name'));
99 $title .= t_slice($slice);
100 $tabs []= tab_slice($slice);
101 $node_filter['node_id'] = $slice['node_ids'];
104 // person_id is set : this is mostly oriented towards people managing several sites
106 // avoid doing a useless call to GetPersons if the person_id is already known though $plc,
107 // as this is mostly done for the 'all my sites nodes' link
108 if ($person_id == plc_my_person_id()) {
109 $person=plc_my_person();
110 $site_ids = plc_my_site_ids();
112 // fetch the person's site_ids
113 $persons = $api->GetPersons(array('person_id'=>$person_id),array('person_id','email','site_ids'));
115 $site_ids=$person['site_ids'];
117 $title .= t_person($person);
118 $node_filter['site_id']=$site_ids;
122 $nodes=$api->GetNodes($node_filter,$node_columns);
124 // build site_ids - interface_ids
126 $interface_ids=array();
127 if ($nodes) foreach ($nodes as $node) {
128 $site_ids []= $node['site_id'];
129 $interface_ids = array_merge ($interface_ids,$node['interface_ids']);
132 // fetch related interfaces
133 $interface_columns=array('ip','node_id','interface_id');
134 $interface_filter=array('is_primary'=>TRUE,'interface_id'=>$interface_ids);
135 $interfaces=$api->GetInterfaces($interface_filter,$interface_columns);
137 $interface_hash=array();
138 foreach ($interfaces as $interface) $interface_hash[$interface['node_id']]=$interface;
140 // fetch related sites
141 $site_columns=array('site_id','login_base');
142 $site_filter=array('site_id'=>$site_ids);
143 $sites=$api->GetSites($site_filter,$site_columns);
146 foreach ($sites as $site) $site_hash[$site['site_id']]=$site;
148 // --------------------
149 drupal_set_title($title);
151 plekit_linetabs($tabs);
154 drupal_set_message ('No node found');
158 $nifty=new PlekitNifty ('','objects-list','big');
160 $headers = array (); $offset=0;
164 if (plc_is_admin()) {
165 $short="I"; $long="node_id"; $type='int';
166 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
169 $short="P"; $long="Peer"; $type='string';
170 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
171 $short="D"; $long="toplevel domain name"; $type='string';
172 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
173 $headers["Site"]="string";
174 $headers["Hostname"]="string";
175 $short="IP"; $long="IP Address"; $type='sortIPAddress';
176 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
177 $short="ST"; $long=Node::status_footnote(); $type='string';
178 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
179 $short="SL"; $long="Number of slivers"; $type='int';
180 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
182 $headers=array_merge($headers,$visibletags->headers());
183 $notes=array_merge($notes,$visibletags->notes());
184 $short="?"; $long="extra status info"; $type='string';
185 $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
187 # initial sort on hostnames
188 $table=new PlekitTable ("nodes",$headers,3+$offset);
191 $peers = new Peers ($api);
193 foreach ($nodes as $node) {
194 //$node_obj = new Node ($node);
195 $hostname=$node['hostname'];
196 $node_id=$node['node_id'];
197 $site_id=$node['site_id'];
198 $site=$site_hash[$site_id];
199 $login_base = $site['login_base'];
200 $ip=$interface_hash[$node['node_id']]['ip'];
201 $interface_id=$interface_hash[$node['node_id']]['interface_id'];
202 $peer_id=$node['peer_id'];
205 if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id));
206 $peers->cell ($table,$peer_id);
207 $table->cell (topdomain($hostname));
208 $table->cell (l_site_t($site_id,$login_base));
209 $table->cell (l_node_t($node_id,$hostname));
210 $table->cell (l_interface_t($interface_id,$ip),array('only-if'=> !$peer_id));
211 list($label,$class) = Node::status_label_class_($node);
212 $table->cell ($label,array('class'=>$class));
213 $table->cell (count($node['slice_ids']));
214 foreach ($visiblecolumns as $tagname) $table->cell($node[$tagname]);
215 $table->cell (node_status($node));
220 $table->end(array('notes'=>$notes));
223 //plekit_linetabs ($tabs,"bottom");
226 include 'plc_footer.php';