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_peers.php';
19 require_once 'linetabs.php';
20 require_once 'table.php';
21 require_once 'details.php';
22 require_once 'form.php';
23 require_once 'toggle.php';
24 require_once 'plc_objects.php';
26 // --------------------
27 // recognized URL arguments
28 $node_id=intval($_GET['id']);
29 if ( ! $node_id ) { plc_error('Malformed URL - id not set'); return; }
32 // Get all columns as we focus on only one entry
33 $nodes= $api->GetNodes( array($node_id));
36 drupal_set_message ("Node " . $node_id . " not found");
42 $hostname= $node['hostname'];
43 $boot_state= $node['boot_state'];
44 $site_id= $node['site_id'];
45 $model= $node['model'];
46 $version= $node['version'];
47 $node_type = $node['node_type'];
49 // arrays of ids of node info
50 $slice_ids= $node['slice_ids'];
51 $conf_file_ids= $node['conf_file_ids'];
52 $interface_ids= $node['interface_ids'];
53 $nodegroup_ids= $node['nodegroup_ids'];
54 $pcu_ids= $node['pcu_ids'];
57 $peer_id = $node['peer_id'];
58 $peers=new Peers ($api);
61 $sites= $api->GetSites( array( $site_id ) );
63 $site_name= $site['name'];
64 $site_node_ids= $site['node_ids'];
66 // hash node_id=>hostname for this site's nodes
67 $site_node_hash=array();
68 if( !empty( $site_node_ids ) ) {
69 // get site node info basics
70 $site_nodes= $api->GetNodes( $site_node_ids );
72 foreach( $site_nodes as $site_node ) {
73 $site_node_hash[$site_node['node_id']]= $site_node['hostname'];
77 // gets slice info for each slice
78 if( !empty( $slice_ids ) )
79 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) );
82 if( !empty( $interface_ids ) )
83 $interfaces= $api->GetInterfaces( $interface_ids );
85 // gets nodegroup info
86 if( !empty( $nodegroup_ids ) )
87 $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value"));
89 // xxx Thierry : remaining stuff
90 // (*) events: should display the latest events relating to that node.
91 // disabling call to GetEvents, that gets the session deleted in the DB
92 // (*) conf_files: is fetched but not displayed
93 if( !empty( $conf_file_ids ) )
94 $conf_files= $api->GetConfFiles( $conf_file_ids );
96 // gets pcu and port info key to both is $pcu_id
97 // turning this off: GetPCUs is not allowed to users, and we don't show PCUs yet anyway
98 //if( !empty( $pcu_ids ) )
99 // $PCUs= $api->GetPCUs( $pcu_ids );
101 //////////////////// display node info
103 drupal_set_title("Details for node " . $hostname);
104 $local_peer= ! $peer_id;
107 // extra privileges to admins, and (pi||tech) on this site
108 $privileges = (plc_is_admin () && $local_peer) || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
112 $tabs [] = tab_nodes_site($site_id);
113 $tabs [] = tab_site($site_id);
114 //$tabs [] = tab_nodes();
116 if ( $local_peer && $privileges ) {
118 $tabs["Add Interface"]=array('url'=>l_interface_add($node_id),
119 'bubble'=>"Define new network interface on $hostname");
120 $tabs['Delete'] = array ('url'=>l_actions(),
122 'values'=>array('action'=>'delete-node','node_id'=>$node_id),
123 'bubble'=>"Delete node $hostname",
124 'confirm'=>'Are you sure to delete ' . $hostname);
125 $tabs["Events"]=array_merge(tablook_event(),
126 array('url'=>l_event("Node","node",$node_id),
127 'bubble'=>"Events for node $hostname"));
128 $tabs["Comon"]=array_merge(tablook_comon(),
129 array('url'=>l_comon("node_id",$node_id),
130 'bubble'=>"Comon page about node $hostname"));
133 plekit_linetabs($tabs);
135 // show gray background on foreign objects : start a <div> with proper class
136 $peers->block_start ($peer_id);
138 $toggle = new PlekitToggle ('node',"Details",
139 array('trigger-bubble'=>'Display and modify details for that node'));
142 $details=new PlekitDetails($privileges);
144 if ( ! $local_peer) {
145 $details->th_td("Peer",$peers->peer_link($peer_id));
149 $details->form_start(l_actions(),array("action"=>"update-node", "node_id"=>$node_id));
150 $details->th_td("Hostname",$hostname,"hostname");
151 $details->th_td("Model",$model,"model");
152 $details->tr_submit("submit","Update Node");
153 $details->form_end();
154 if ($privileges) $details->space();
156 $details->th_td("Type",$node_type);
157 $details->th_td("Version",$version);
158 // let's use plc_objects
159 $Node = new Node($node);
160 $details->th_td("Date created",$Node->dateCreated());
161 $details->th_td("Last contact",$Node->lastContact());
162 $details->th_td("Last update",$Node->lastUpdated());
166 if ( ! ($local_peer && $privileges)) {
168 $boot_value=$boot_state;
171 $boot_form = new PlekitForm (l_actions(), array("node_id"=>$node_id,
172 "action"=>"node-boot-state"));
173 $boot_value .= $boot_form->start_html();
174 $states = array( 'boot'=>'Boot', 'safeboot'=>'SafeBoot', 'failboot'=>'FailBoot',
175 'disabled' => 'Disabled', 'install'=>'Install', 'reinstall'=>'Reinstall');
177 foreach ($states as $dbname=>$displayname) {
178 $selector=array("display"=>$displayname, "value"=>$dbname);
179 if ($dbname == $boot_state) $selector['selected']=true;
180 $selectors []= $selector;
182 $boot_value .= $boot_form->select_html("boot_state",$selectors,array('autosubmit'=>true));
183 $boot_value .= $boot_form->end_html();
185 $details->th_td ("Boot state",$boot_value);
187 // same here for the download area
188 if ( $local_peer && $privileges) {
191 $download_form = new PlekitForm (l_actions_download(),array("node_id"=>$node_id));
192 $download_value .= $download_form->start_html();
194 array("display"=>"-- All in one images --","disabled"=>true),
195 array("value"=>"download-node-iso","display"=>"Download ISO image for $hostname"),
196 array("value"=>"download-node-usb","display"=>"Download USB image for $hostname<"),
197 array("display"=>"-- Floppy + generic image --","disabled"=>true),
198 array("value"=>"download-node-floppy","display"=>"Download Floppy file for $hostname"),
199 array("value"=>"download-generic-iso","display"=>"Download generic ISO image (requires floppy)"),
200 array("value"=>"download-generic-usb","display"=>"Download generic USB image (requires floppy)"));
201 $download_value .= $download_form->select_html("action",$selectors,
202 array('label'=>"Download mode",'autosubmit'=>true));
203 $download_value .= $download_form->end_html();
204 $details->th_td ("Download",$download_value);
207 // site info and all site nodes
209 $details->th_td("Site",l_site_t($site_id,$site_name));
211 // build list of node links
213 foreach ($site_node_hash as $hash_node_id => $hash_hostname) {
214 $nodes_area []= l_node_t($hash_node_id,$hash_hostname);
216 $details->th_tds ("All site nodes",$nodes_area);
221 $form=new PlekitForm (l_actions(), array('node_id'=>$node_id));
224 //////////////////////////////////////////////////////////// Tags
226 $show_tags = (plc_is_admin());
229 $tags=$api->GetNodeTags (array('node_id'=>$node_id));
230 function get_tagname ($tag) { return $tag['tagname'];}
231 $tagnames = array_map ("get_tagname",$tags);
232 $nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames);
234 $toggle = new PlekitToggle ('tags',"Tags",
235 array('trigger-bubble'=>'Inspect and set tags on that node',
236 'start-visible'=>$show_tags));
239 $headers=array("Name"=>"string",
241 "Nodegroup"=>"string",
243 if (plc_is_admin()) $headers[plc_delete_icon()]="none";
245 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
246 $table=new PlekitTable("node_tags",$headers,0,$table_options);
248 if ($tags) foreach ($tags as $tag) {
249 // does this match a nodegroup ?
250 $nodegroup_name="n/a";
251 $nodegroup_key=$tag['tagname'] . "=" . $tag['value'];
252 $nodegroup=$nodegroups_hash[$nodegroup_key];
253 if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']);
255 $table->cell(l_tag_obj($tag));
256 $table->cell($tag['value']);
257 $table->cell($nodegroup_name);
258 // the remove checkbox
259 if (plc_is_admin()) $table->cell ($form->checkbox_html('node_tag_ids[]',$tag['node_tag_id']));
264 $table->tfoot_start();
268 $table->cell($form->submit_html("delete-node-tags","Remove Tags"),
269 // use the whole columns and right adjust
270 $table->columns(), "right");
275 // get list of tag names in the node/* category
276 $all_tags= $api->GetTagTypes( array ("category"=>"node*"), array("tagname","tag_type_id"));
277 // xxx cannot use onchange=submit() - would need to somehow pass action name
278 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
279 $selector=array_map("tag_selector",$all_tags);
280 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
281 $table->cell($form->text_html("value","",array('width'=>8)));
282 $table->cell($form->submit_html("set-tag-on-node","Set Tag"),2,"left");
290 //////////////////////////////////////////////////////////// interfaces
292 $toggle=new PlekitToggle ('interfaces',"Interfaces",
293 array('trigger-bubble'=>'Inspect and tune interfaces on that node',
294 'start-hidden'=>true));
296 // display interfaces
297 if( ! $interfaces ) {
299 plc_warning_html("This node has no interface");
300 echo "Please add an interface to make this a usable PLC node.</p>\n";
304 $headers["IP"]="IPAddress";
305 $headers["Method"]="string";
306 $headers["Type"]="string";
307 $headers["MAC"]="string";
308 $headers["bw limit"]="FileSize";
309 // a single symbol, marking 'p' for primary and a delete button for non-primary
310 if ( $privileges ) $headers[plc_delete_icon()]='string';
312 $table_options=array('search_area'=>false,"pagesize_area"=>false,'notes_area'=>false);
313 $table=new PlekitTable("node_interfaces",$headers,2,$table_options);
316 foreach ( $interfaces as $interface ) {
317 $interface_id= $interface['interface_id'];
318 $interface_ip= $interface['ip'];
319 $interface_broad= $interface['broadcast'];
320 $interface_primary= $interface['is_primary'];
321 $interface_network= $interface['network'];
322 $interface_dns1= $interface['dns1'];
323 $interface_dns2= $interface['dns2'];
324 $interface_hostname= $interface['hostname'];
325 $interface_netmaks= $interface['netmask'];
326 $interface_gatewary= $interface['gateway'];
327 $interface_mac= $interface['mac'];
328 $interface_bwlimit= $interface['bwlimit'];
329 $interface_type= $interface['type'];
330 $interface_method= $interface['method'];
333 $table->cell(l_interface_t($interface_id,$interface_ip));
334 $table->cell($interface_method);
335 $table->cell($interface_type);
336 $table->cell($interface_mac);
337 $table->cell($interface_bwlimit);
339 if ($interface_primary) {
340 $table->cell(plc_bubble("p","Cannot delete a primary interface"));
342 $table->cell ($form->checkbox_html('interface_ids[]',$interface_id));
348 $table->tfoot_start();
350 $add_button=new PlekitFormButton (l_interface_add($node_id),"add_interface","Add interface","GET");
351 // we should have 6 cols, use 3 for the left (new) and the rest for the right (remove)
352 $table->cell($add_button->html(), 3,"left");
353 $table->cell($form->submit_html("delete-interfaces","Remove Interfaces"), $table->columns()-3,"right");
361 //////////////////////////////////////////////////////////// slices
365 $toggle=new PlekitToggle ('slices',"Slices",
366 array('trigger-bubble'=>'Review slices running on that node',
367 'start-hidden'=>true));
370 plc_warning ("This node is not associated to any slice");
373 $headers['Peer']="string";
374 $headers['Name']="string";
375 $headers['Slivers']="string";
377 $table_options = array('notes_area'=>false,"search_width"=>10,'pagesize'=>$reasonable_page);
378 if (count ($slices) <= $reasonable_page) {
379 $table_options['search_area']=false;
380 $table_options['pagesize_area']=false;
382 $table=new PlekitTable("node_slices",$headers,1,$table_options);
385 foreach ($slices as $slice) {
387 $table->cell ($peers->shortname($peer_id));
388 $table->cell (l_slice_t ($slice['slice_id'],$slice['name']));
389 $table->cell (l_sliver_t ($node_id,$slice['slice_id'],'view'));
399 ////////////////////////////////////////////////////////////
400 $peers->block_end($peer_id);
402 //plekit_linetabs ($tabs,"bottom");
405 include 'plc_footer.php';