person;
$_roles= $_person['role_ids'];
////////////////////
// The set of columns to fetch
// and the filter applied for fetching sites
$columns = array( "node_id", "hostname", "boot_state", "peer_id" ) ;
$filter = array("node_type"=>"regular");
if ( in_array( '10', $_roles ) || in_array('20', $_roles) || in_array('40',$_roles)) {
// admins, PIs and techs can see interface details
$columns [] = "interface_ids";
}
//////////////////
// perform post-processing on objects as returned by GetNodes
// performs sanity check and summarize the result in a single column
// performs in-place replacement, so passes a reference
function layout_node ($node) {
// we need the 'interface_ids' field to do this
// so regular users wont run this
if ( ! array_key_exists ('interface_ids', $node))
return $node;
$messages=array();
// do all this stuff on local nodes only
if ( ! $node['peer_id'] ) {
// check that the node has keys
if (count($node['interface_ids']) == 0)
$messages [] = "No interface";
}
// but always cleanup $node columns
unset ($node['interface_ids']);
$node['status'] = plc_make_table('plc-warning',$messages);
$node['comon'] = plc_comon_button("node_id",$node['node_id']);
return $node;
}
// if nodepattern is set then set id to that node's id.
// we use GET rather than POST so paginate can display the right contents on subsequent pages
// can be useful for writing bookmarkable URL's as well
if( $_GET['nodepattern'] || $_GET['peerscope']) {
// nodepattern
$nodepattern= $_GET['nodepattern'];
// need to use a hash filter for patterns to be properly handled
if (empty($nodepattern)) {
$nodepattern="*";
}
$filter = array_merge (array( "hostname"=>$nodepattern ), $filter);
// peerscope
list ( $peer_filter, $peer_label) = plc_peer_info($api,$_GET['peerscope']);
$filter=array_merge($filter,$peer_filter);
$nodes= $api->GetNodes($filter, $columns);
$nodes_count = count ($nodes);
if ( $nodes_count == 1) {
header( "location: index.php?id=". $nodes[0]['node_id'] );
exit();
} else if ( $nodes_count == 0) {
echo " No node matching $nodepattern ";
} else {
drupal_set_title ("Nodes matching $nodepattern on". $peer_label);
$nodes = array_map(layout_node,$nodes);
sort_nodes ($nodes);
echo paginate( $nodes, "node_id", "Nodes", 25, "hostname");
}
}
// if a site_id is given, display the site nodes only
else if( $_GET['site_id'] ) {
$site_id= $_GET['site_id'];
// Get site info
$site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "node_ids" ) );
drupal_set_title("Nodes on site " . $site_info[0]['name']);
// Get site nodes
$nodes= $api->GetNodes( array_merge(array('node_id'=>$site_info[0]['node_ids']),$filter), $columns);
if ( empty ($nodes) ) {
echo "No node to display";
} else {
$nodes = array_map(layout_node,$nodes);
sort_nodes( $nodes );
echo paginate( $nodes, "node_id", "Nodes", 25, "hostname");
}
}
// if a slice_id is given, display only the nodes related to this slice
else if( $_GET['slice_id'] ) {
$slice_id= $_GET['slice_id'];
// Get slice infos
$slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name", "node_ids" ) );
drupal_set_title($slice_info[0]['name']."run on");
// Get slice nodes
$nodes= $api->GetNodes( array_merge(array('node_id'=>$slice_info[0]['node_ids']),$filter), $columns);
if ( empty ($nodes) ) {
echo "No node to display";
} else {
$nodes = array_map(layout_node,$nodes);
sort_nodes( $nodes );
echo paginate( $nodes, "node_id", "Nodes", 25, "hostname");
echo "
GetNodes( empty($filter) ? NULL : $filter, $columns );
if ( empty ($nodes) ) {
echo "No node to display";
} else {
$nodes = array_map(layout_node,$nodes);
sort_nodes( $nodes );
drupal_set_html_head('
');
echo " No interface. Please add an interface to make this a usable PLC node This node is not in any nodegroup. Select nodegroup to add this node to. This node is not associated to any slice. Back to nodes list";
}
// Print footer
include 'plc_footer.php';
?>
\n";
echo paginate( $nodes, "node_id", "Nodes", 25, "hostname" );
echo "\n";
}
}
if ( $_GET['id'] ) {
// get the node id from the URL
$node_id= intval( $_GET['id'] );
// make the api call to pull that nodes DATA
$node_info= $api->GetNodes( array( $node_id ) );
if (empty ($node_info)) {
echo "No such node.";
} else {
// node info
$hostname= $node_info[0]['hostname'];
$boot_state= $node_info[0]['boot_state'];
$site_id= $node_info[0]['site_id'];
$model= $node_info[0]['model'];
$version= $node_info[0]['version'];
// arrays of ids of node info
$slice_ids= $node_info[0]['slice_ids'];
$conf_file_ids= $node_info[0]['conf_file_ids'];
$interface_ids= $node_info[0]['interface_ids'];
$nodegroup_ids= $node_info[0]['nodegroup_ids'];
$pcu_ids= $node_info[0]['pcu_ids'];
$ports= $node_info[0]['ports'];
// get peer
$peer_id= $node_info[0]['peer_id'];
// gets site info
$site_info= $api->GetSites( array( $site_id ) );
$site_name= $site_info[0]['name'];
$site_nodes= $site_info[0]['node_ids'];
if( !empty( $site_nodes ) ) {
// get site node info basics
$site_node_list= $api->GetNodes( $site_nodes );
foreach( $site_node_list as $s_node ) {
$site_node[$s_node['node_id']]= $s_node['hostname'];
}
}
// gets slice info for each slice
if( !empty( $slice_ids ) )
$slice_info= $api->GetSlices( $slice_ids, array( "slice_id", "name" , "peer_id" ) );
// gets conf file info
if( !empty( $conf_file_ids ) )
$conf_files= $api->GetConfFiles( $conf_file_ids );
// get interface info
if( !empty( $interface_ids ) )
$interfaces= $api->GetInterfaces( $interface_ids );
// gets nodegroup info
if( !empty( $nodegroup_ids ) )
$node_groups= $api->GetNodeGroups( $nodegroup_ids );
// xxx Thierry : disabling call to GetEvents, that gets the session deleted in the DB
// gets events
// $filter= array( "object_type"=>"Node", "object_id"=>$node_id );
// $fields= array( "event_id", "person_id", "fault_code", "call_name", "call", "message", "time" );
//
// $event_info= $api->GetEvents( $filter, $fields );
// gets pcu and port info key to both is $pcu_id
if( !empty( $pcu_ids ) )
$PCUs= $api->GetPCUs( $pcu_ids );
// display node info
if ( $peer_id) {
echo "
";
}
echo "";
if ($is_admin) {
echo plc_event_button("Node","node",$node_id);
echo " ";
}
echo plc_comon_button("node_id",$node_id);
echo " ";
echo "\n";
echo "
";
echo "\n";
echo "
\n";
echo "Hostname: $hostname \n";
echo "Model: $model \n";
echo "Version: $version \n";
if ( ! $peer_id && ( $is_admin || ( ($is_pi||$is_tech) && $in_site ) ) ) {
// handle legacy API
if ( ! method_exists ($api,"GetBootMedium")) {
$new_api_only=" disabled='disabled' ";
}
echo "Boot State: ";
if ($peer_id) {
echo $boot_state;
} else {
echo "";
}
echo " \n";
}
// site info and all site nodes
echo "Download ";
echo "";
echo " \n";
echo " \n";
echo "Site: $site_name \n";
echo "All site nodes: ";
if (empty($site_node)) {
echo "Site has no node";
} else {
foreach( $site_node as $key => $val ) {
echo "$val
";
}
}
echo "
\n";
if ( ! $peer_id ) {
echo "
\n";
// display interfaces
if( $interfaces ) {
echo "\n";
echo "
\n";
} else {
echo "";
// placeholder for the delete buttons
if ( $is_admin || ($is_pi && $in_site)) {
echo " \n";
foreach( $interfaces as $interface ) {
$nn_id= $interface['interface_id'];
$nn_ip= $interface['ip'];
$nn_broad= $interface['broadcast'];
$nn_primary= $interface['is_primary'];
$nn_network= $interface['network'];
$nn_dns1= $interface['dns1'];
$nn_dns2= $interface['dns2'];
$nn_hostname= $interface['hostname'];
$nn_netmaks= $interface['netmask'];
$nn_gatewary= $interface['gateway'];
$nn_mac= $interface['mac'];
$nn_bwlimit= $interface['bwlimit'];
$nn_type= $interface['type'];
$nn_method= $interface['method'];
echo "";
}
echo " IP Address Method Type MAC Bandwidth Limit ";
if ( $is_admin || ($is_pi && $in_site)) {
echo " \n";
}
echo "";
if (!$nn_primary) {
echo plc_delete_link_button('interfaces.php?id=' . $nn_id . '&delete=1&submitted=1', '\\nInterface ' . $nn_ip);
} else {
echo ' P ';
}
echo " ";
}
echo "";
if( $is_admin || $is_pi || $is_tech ) {
echo "$nn_ip";
} else {
echo " $nn_ip ";
}
echo "$nn_method $nn_type $nn_mac $nn_bwlimit
Add an interface.\n";
echo "
\n";
}
// display node group info
if( !empty( $node_groups ) ) {
echo "\n
\n";
foreach( $node_groups as $node_group ) {
echo "Name Description ";
if( in_array( 10, $_roles ) ) echo "";
echo " \n";
}
echo "". $node_group['name'] ." ". $node_group['description'] ." ";
if( in_array( '10', $_roles ) || ( in_array( 20, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) || ( in_array( 40, $_roles ) && in_array( $site_id, $_person['site_ids'] ) ) )
echo "Update remove ";
echo "
\n";
} else {
echo "
\n";
echo "\n";
}
// display slices
echo "
\n";
if( !empty( $slice_info ) ) {
sort_slices( $slice_info );
echo paginate( $slice_info, "slice_id", "Slices", 15, "name", "slivers", $node_id );
} else {
echo "
\n";
echo "\n
\n";
}
if ( $peer_id ) {
echo " \n";
// display event on rows of table
foreach( $event_info as $event ) {
echo "Call Name Call Message Time \n";
}
echo "". $event['call'] ." ". $event['message'] ." ". $event['time'] ."
";
echo "