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_minitabs.php';
19 require_once 'plc_tables.php';
20 require_once 'plc_details.php';
21 require_once 'plc_forms.php';
23 // --------------------
24 // recognized URL arguments
25 $node_id=intval($_GET['id']);
26 if ( ! $node_id ) { plc_error('Malformed URL - id not set'); return; }
29 // Get all columns as we focus on only one entry
30 $nodes= $api->GetNodes( array($node_id));
33 drupal_set_message ("Node " . $node_id . " not found");
39 $hostname= $node['hostname'];
40 $boot_state= $node['boot_state'];
41 $site_id= $node['site_id'];
42 $model= $node['model'];
43 $version= $node['version'];
44 $node_type = $node['node_type'];
46 // arrays of ids of node info
47 $slice_ids= $node['slice_ids'];
48 $conf_file_ids= $node['conf_file_ids'];
49 $interface_ids= $node['interface_ids'];
50 $nodegroup_ids= $node['nodegroup_ids'];
51 $pcu_ids= $node['pcu_ids'];
54 $peer_id= $node['peer_id'];
57 $sites= $api->GetSites( array( $site_id ) );
59 $site_name= $site['name'];
60 $site_node_ids= $site['node_ids'];
62 // hash node_id=>hostname for this site's nodes
63 $site_node_hash=array();
64 if( !empty( $site_node_ids ) ) {
65 // get site node info basics
66 $site_nodes= $api->GetNodes( $site_node_ids );
68 foreach( $site_nodes as $site_node ) {
69 $site_node_hash[$site_node['node_id']]= $site_node['hostname'];
73 // gets slice info for each slice
74 if( !empty( $slice_ids ) )
75 $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) );
78 if( !empty( $interface_ids ) )
79 $interfaces= $api->GetInterfaces( $interface_ids );
81 // gets nodegroup info
82 if( !empty( $nodegroup_ids ) )
83 $nodegroups= $api->GetNodeGroups( $nodegroup_ids, array("groupname","tag_type_id","value"));
85 // xxx Thierry : remaining stuff
86 // (*) events: should display the latest events relating to that node.
87 // disabling call to GetEvents, that gets the session deleted in the DB
88 // (*) conf_files: is fetched but not displayed
89 if( !empty( $conf_file_ids ) )
90 $conf_files= $api->GetConfFiles( $conf_file_ids );
92 // gets pcu and port info key to both is $pcu_id
93 if( !empty( $pcu_ids ) )
94 $PCUs= $api->GetPCUs( $pcu_ids );
96 //////////////////// display node info
98 // fetches peers and initialize hash peer_id->peer
99 $peer_hash = plc_peer_global_hash ($api);
100 // show gray background on foreign objects : start a <div> with proper class
101 plc_peer_block_start ($peer_hash,$peer_id);
103 drupal_set_title("Details for node " . $hostname);
105 // extra privileges to admins, and (pi||tech) on this site
106 $privileges = plc_is_admin () || ( plc_in_site($site_id) && ( plc_is_pi() || plc_is_tech()));
110 if ( ! $peer_id && $privileges ) {
112 $tabs['Update'] = array ('url'=>"/db/nodes/node_actions.php",
114 'values'=>array('action'=>'prompt-update','node_id'=>$node_id),
115 'bubble'=>"Update details of $hostname");
116 $tabs['Delete'] = array ('url'=>"/db/nodes/node_actions.php",
118 'values'=>array('action'=>'delete','node_id'=>$node_id),
119 'bubble'=>"Delete $hostname",
120 'confirm'=>'Are you sure to delete ' . $hostname. ' ?');
121 // xxx subject to roles
122 $tabs["Add Interface"]=l_interface_add($node_id);
123 $tabs["Comon"]=array('url'=>l_comon("node_id",$node_id),
124 'buble'=>"Comon page for $hostname");
125 $tabs["Events"]=array('url'=>l_event("Node","node",$node_id),
126 'bubble'=>"Events for node $hostname");
129 $tabs["All nodes"]=l_nodes();
133 plc_details_start ();
134 plc_details_line("Hostname",$hostname);
135 plc_details_line("Type",$node_type);
136 plc_details_line("Model",$model);
137 plc_details_line("Version",$version);
139 // no tool to implement this multiple-choice setting yet
140 // xxx would need at least to use the proper class, like plc_details_class() or something
141 echo "<tr><th>Boot State: </th><td>";
145 echo "<form name='bootstate' action='/db/nodes/node_actions.php' method=post>\n";
146 echo "<input type=hidden name='node_id' value='$node_id'>\n";
147 echo "<input type=hidden name='action' value='boot-state'>\n";
148 echo "<select name='boot_state' onChange=\"submit();\">\n";
150 $states= array( 'boot'=>'Boot', 'dbg'=>'Debug', 'inst'=>'Install', 'rins'=>'Reinstall', 'rcnf'=>'Reconfigure', 'new'=>'New' );
152 foreach( $states as $key => $val ) {
153 echo "<option value='$key'";
155 if( $key == $boot_state )
158 echo ">$val</option>\n";
161 echo "</select></input></form>";
165 // same here for the download area
166 if ( ! $peer_id && $privileges) {
168 echo "<tr><th>Download </th><td>";
169 echo "<form name='download' action='/db/nodes/node_actions.php' method='post'>\n";
170 echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
171 echo "<select name='action' onChange='submit();'>\n";
172 echo "<option value='' selected='selected'> Download Mode </option>\n";
173 echo "<option value='' disabled='disabled'> -- All in one images -- </option>";
174 echo "<option value='download-node-iso' $new_api_only> Download ISO image for $hostname</option>\n";
175 echo "<option value='download-node-usb' $new_api_only> Download USB image for $hostname</option>\n";
176 echo "<option value='' disabled='disabled'> -- Floppy + generic image -- </option>";
177 echo "<option value='download-node-floppy'> Download Floppy file for $hostname</option>\n";
178 echo "<option value='download-generic-iso' $new_api_only> Download generic ISO image (requires floppy) </option>\n";
179 echo "<option value='download-generic-usb' $new_api_only> Download generic USB image (requires floppy) </option>\n";
180 echo "</select></form>";
185 // site info and all site nodes
186 plc_details_space_line ();
187 plc_details_line("Site",l_site_t($site_id,$site_name));
189 // build list of node links
191 foreach ($site_node_hash as $hash_node_id => $hash_hostname) {
192 $nodes_area []= l_node_t($hash_node_id,$hash_hostname);
194 plc_details_line_list ("All site nodes",$nodes_area);
198 //////////////////////////////////////////////////////////// Tags
200 $tags=$api->GetNodeTags (array('node_id'=>$node_id));
201 $tagnames = array_map ("get_tagname",$tags);
202 //plc_debug('tagnames',$tagnames);
203 $nodegroups_hash=plc_nodegroup_global_hash($api,$tagnames);
204 //plc_debug('hash',$nodegroups_hash);
207 $headers=array("Name"=>"string",
209 "Nodegroup"=>"string");
211 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
212 plc_table_start("node_tags",$headers,0,$table_options);
213 if ($tags) foreach ($tags as $tag) {
214 // does this match a nodegroup ?
215 $nodegroup_name="n/a";
216 $nodegroup_key=$tag['tagname'] . "=" . $tag['value'];
217 $nodegroup=$nodegroups_hash[$nodegroup_key];
218 if ($nodegroup) $nodegroup_name=l_nodegroup_t($nodegroup['nodegroup_id'],$nodegroup['groupname']);
219 plc_table_row_start();
220 plc_table_cell($tag['tagname']);
221 plc_table_cell($tag['value']);
222 plc_table_cell($nodegroup_name);
225 plc_table_end("node_tags");
227 //////////////////////////////////////////////////////////// slices
230 plc_section ("Slices");
232 echo "<p><span class='plc-warning'>This node is not associated to any slice.</span></p>\n";
235 $headers['Peer']="string";
236 $headers['Name']="string";
237 $headers['Slivers']="string";
238 $table_options = array('notes_area'=>false,"search_width"=>10);
239 plc_table_start ("node_slices",$headers,1,$table_options);
241 foreach ($slices as $slice) {
242 plc_table_row_start($slice['name']);
243 plc_table_cell (plc_peer_shortname($peer_hash,$slice['peer_id']));
244 plc_table_cell (l_slice_t ($slice['slice_id'],$slice['name']));
245 plc_table_cell (l_sliver_t ($node_id,$slice['slice_id'],'view'));
248 plc_table_end("node_slices");
251 //////////////////////////////////////////////////////////// interfaces
254 // display interfaces
255 if( ! $interfaces ) {
256 echo "<p><span class='plc-warning'>No interface</span>. Please add an interface to make this a usable PLC node</p>.\n";
260 // a single symbol, marking 'p' for primary and a delete button for non-primary
261 $headers[' ']='string';
264 $headers["IP"]="IPAddress";
265 $headers["Method"]="string";
266 $headers["Type"]="string";
267 $headers["MAC"]="string";
268 $headers["bw limit"]="FileSize";
270 plc_section('Interfaces');
271 $table_options=array('search_area'=>false,"pagesize_area"=>false,'notes_area'=>false);
272 plc_table_start("node_interfaces",$headers,2,$table_options);
274 foreach ( $interfaces as $interface ) {
275 $interface_id= $interface['interface_id'];
276 $interface_ip= $interface['ip'];
277 $interface_broad= $interface['broadcast'];
278 $interface_primary= $interface['is_primary'];
279 $interface_network= $interface['network'];
280 $interface_dns1= $interface['dns1'];
281 $interface_dns2= $interface['dns2'];
282 $interface_hostname= $interface['hostname'];
283 $interface_netmaks= $interface['netmask'];
284 $interface_gatewary= $interface['gateway'];
285 $interface_mac= $interface['mac'];
286 $interface_bwlimit= $interface['bwlimit'];
287 $interface_type= $interface['type'];
288 $interface_method= $interface['method'];
290 plc_table_row_start($interface['ip']);
292 if (!$interface_primary) {
294 plc_table_cell (plc_delete_link_button ('interfaces.php?id=' . $interface_id . '&delete=1&submitted=1',
295 '\\nInterface ' . $interface_ip));
300 plc_table_cell(l_interface_t($interface_id,$interface_ip));
301 plc_table_cell($interface_method);
302 plc_table_cell($interface_type);
303 plc_table_cell($interface_mac);
304 plc_table_cell($interface_bwlimit);
308 $button=plc_form_simple_button(l_interface_add($node_id),"Add interface","GET");
309 $footers=array(plc_table_td_text($button,6,"right"));
311 plc_table_end("node_interfaces",array("footers"=>$footers));
315 ////////////////////////////////////////////////////////////
316 plc_peer_block_end();
320 include 'plc_footer.php';