<?php
- // $Id: node_actions.php 1184 2008-02-12 20:33:35Z thierry $
+ // $Id$
// This file was created when we decided to make the node page consistent with the other pages
// That is to say, we wanted the 'Update' and 'Delete' functions to appear in a drop-down
// menu like for the other objects
require_once 'plc_functions.php';
require_once 'plc_sorts.php';
-// find person roles
-$_person= $plc->person;
-$_roles= $_person['role_ids'];
-
// NOTE: this function exits() after it completes its job,
// simply returning leads to html decorations being added around the contents
function deliver_and_unlink ($filename) {
exit();
}
-function show_download_confirm_button($api, $node_id, $action, $can_gen_config, $show_details) {
+function show_download_confirm_button ($api, $node_id, $action, $can_gen_config, $show_details) {
if( $can_gen_config ) {
- if ($show_details && method_exists($api,"GetBootMedium")) {
+ if ($show_details) {
$preview=$api->GetBootMedium($node_id,"node-preview","");
print ("<hr /> <h3>Current node configuration contents</h3>");
print ("<pre>\n$preview</pre>\n");
echo "<form method=post action='node_actions.php'>\n";
echo "<input type=hidden name='node_id' value='$node_id'></input>\n";
echo "<input type=hidden name='action' value='update'></input>\n";
- if( $_POST['error'] ) echo "<font color=red>". unserialize( $_POST['error'] ."</font>\n" );
+ if( $_POST['error'] ) plc_error(unserialize( $_POST['error']));
echo "<p><table cellpadding=2><tbody>\n
<tr><th>Hostname: </th><td> <input type=text size=35 name='hostname' value='". $node_info[0]['hostname'] ."'></td></tr>\n
<tr><th>Model: </th><td> <input type=text size=35 name='model' value='". $node_info[0]['model'] ."'></td></tr>\n
case "download-generic-iso":
case "download-generic-usb":
- if ( ! method_exists($api,"GetBootMedium")) {
- print ("<span class='plc-warning'> API lacks support for GetBootMedium </span>");
- return;
- }
-
if ($action=="download-generic-iso") {
$boot_action="generic-iso";
} else {
$node_detail= $return[0];
// non-admin people need to be affiliated with the right site
- if( !in_array( 10, $_roles ) ) {
+ if( ! plc_is_admin() ) {
$node_site_id = $node_detail['site_id'];
- $in_site = in_array ($node_site_id,$_person['site_ids']);
+ $in_site = plc_in_site($node_site_id);
if( ! $in_site) {
$error= "Insufficient permission. You cannot create configuration files for this node.";
}
}
$hostname= $node_detail['hostname'];
- $return= $api->GetNodeNetworks( array( "node_id" => $node_id ), NULL );
+ $return= $api->GetInterfaces( array( "node_id" => $node_id ), NULL );
$can_gen_config= 1;
$has_primary= 0;
if( count($return) > 0 ) {
- foreach( $return as $node_network_detail ) {
- if( $node_network_detail['is_primary'] == true ) {
+ foreach( $return as $interface_detail ) {
+ if( $interface_detail['is_primary'] == true ) {
$has_primary= 1;
break;
}
$fields= array("method","ip");
foreach( $fields as $field ) {
- if( $node_network_detail[$field] == "" ) {
+ if( $interface_detail[$field] == "" ) {
$can_gen_config= 0;
- $node_network_detail[$field]= "<i>Missing</i>";
+ $interface_detail[$field]= "<i>Missing</i>";
}
}
- if( $node_network_detail['method'] == "static" ) {
+ if( $interface_detail['method'] == "static" ) {
$fields= array("gateway","netmask","network","broadcast","dns1");
foreach( $fields as $field ) {
- if( $node_network_detail[$field] == "" ) {
+ if( $interface_detail[$field] == "" ) {
$can_gen_config= 0;
- $node_network_detail[$field]= "<i>Missing</i>";
+ $interface_detail[$field]= "<i>Missing</i>";
}
}
}
- if( $node_network_detail['method'] != "static"
- && $node_network_detail['method'] != "dhcp" ) {
+ if( $interface_detail['method'] != "static"
+ && $interface_detail['method'] != "dhcp" ) {
$can_gen_config= 0;
- $node_network_detail['method']= "<i>Unknown method</i>";
+ $interface_detail['method']= "<i>Unknown method</i>";
}
}
$download= $_POST['download'];
if( $can_gen_config && !empty($download) ) {
- if (! method_exists ($api,"GetBootMedium")) {
- $file_contents= $api->AdmGenerateNodeConfFile( $node_id );
- header ("Content-Type: application/octet-stream");
- header ("Content-Transfer-Encoding: binary");
- header ("Content-Disposition: attachment; filename=plnode.txt" );
- header ("Content-Length: " . strlen(file_contents));
- header ("Pragma: hack");
- header ("Cache-Control: public, must-revalidate");
- print file_contents;
- exit();
+ switch ($action) {
+ case 'download-node-floppy':
+ $boot_action='node-floppy';
+ $location = "%d/%n-%v-rename-into-plnode%s";
+ break;
+ case 'download-node-iso':
+ $boot_action='node-iso';
+ $location = "%d/%n-%a-%v%s";
+ break;
+ case 'download-node-usb':
+ $boot_action='node-usb';
+ $location = "%d/%n-%a-%v%s";
+ break;
+ }
+
+ $filename=$api->GetBootMedium($node_id,$boot_action,$location);
+ $error=$api->error();
+ if (empty($error) && empty($filename)) {
+ $error="Unexpected error from GetBootMedium - probably wrong directory modes";
+ }
+ if (! empty($error)) {
+ print ("<div class='plc-error'> $error </div>\n");
+ print ("<p><a href='/db/nodes/index.php?id=$node_id'>Back to node </a>\n");
+ return ;
} else {
- switch ($action) {
- case 'download-node-floppy':
- $boot_action='node-floppy';
- $location = "%d/%n-%v-rename-into-plnode%s";
- break;
- case 'download-node-iso':
- $boot_action='node-iso';
- $location = "%d/%n-%a-%v%s";
- break;
- case 'download-node-usb':
- $boot_action='node-usb';
- $location = "%d/%n-%a-%v%s";
- break;
- }
-
- $filename=$api->GetBootMedium($node_id,$boot_action,$location);
- $error=$api->error();
- if (empty($error) && empty($filename)) {
- $error="Unexpected error from GetBootMedium - probably wrong directory modes";
- }
- if (! empty($error)) {
- print ("<div class='plc-error'> $error </div>\n");
- print ("<p><a href='/db/nodes/index.php?id=$node_id'>Back to node </a>\n");
- return ;
- } else {
- deliver_and_unlink ($filename);
- exit();
- }
+ deliver_and_unlink ($filename);
+ exit();
}
-
}
drupal_set_title("Download boot material for $hostname");
go into debug mode.
<p>In order to create a configuration file for this node using this page,
-all the node network settings must be up to date. Below is summary of these
+all the interface settings must be up to date. Below is summary of these
values. Any missing values must be entered before this can be used.
EOF;
show_download_confirm_button($api, $node_id, $action, $can_gen_config, false);
print ("<p>");
- print ("<h3>Current node network settings</h3>\n");
+ print ("<h3>Current interface settings</h3>\n");
if( $has_primary ) {
print( "<table border=\"0\" cellspacing=\"4\">\n" );
print( "<tr><th>Hostname:</th>" );
print( "<td>" . $node_detail['hostname'] . "</td></tr>\n" );
- $nn_id = $node_network_detail['nodenetwork_id'];
- print( "<tr><th colspan=2><a href='node_networks.php?id=$nn_id'>Node Network Details</a></th></tr>" );
+ $nn_id = $interface_detail['interface_id'];
+ print( "<tr><th colspan=2><a href='interfaces.php?id=$nn_id'>Interface Details</a></th></tr>" );
print( "<tr><th>Method:</th>" );
- print( "<td>" . $node_network_detail['method'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['method'] . "</td></tr>\n" );
print( "<tr><th>IP:</th>" );
- print( "<td>" . $node_network_detail['ip'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['ip'] . "</td></tr>\n" );
- if( $node_network_detail['method'] == "static" ) {
+ if( $interface_detail['method'] == "static" ) {
print( "<tr><th>Gateway:</th>" );
- print( "<td>" . $node_network_detail['gateway'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['gateway'] . "</td></tr>\n" );
print( "<tr><th>Network mask:</th>" );
- print( "<td>" . $node_network_detail['netmask'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['netmask'] . "</td></tr>\n" );
print( "<tr><th>Network address:</th>" );
- print( "<td>" . $node_network_detail['network'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['network'] . "</td></tr>\n" );
print( "<tr><th>Broadcast address:</th>" );
- print( "<td>" . $node_network_detail['broadcast'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['broadcast'] . "</td></tr>\n" );
print( "<tr><th>DNS 1:</th>" );
- print( "<td>" . $node_network_detail['dns1'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['dns1'] . "</td></tr>\n" );
print( "<tr><th>DNS 2:</th>" );
- if( $node_network_detail['dns2'] == "" ) {
+ if( $interface_detail['dns2'] == "" ) {
print( "<td><i>Optional, missing</i></td></tr>\n" );
} else {
- print( "<td>" . $node_network_detail['dns2'] . "</td></tr>\n" );
+ print( "<td>" . $interface_detail['dns2'] . "</td></tr>\n" );
}
}
- if (method_exists ($api,'GetNodeNetworkSettings')) {
- print ("<tr><th colspan=2><a href='node_networks.php?id=$nn_id'>Additional Settings</a></th></tr>\n");
- $nn_id = $node_network_detail['nodenetwork_id'];
- $settings=$api->GetNodeNetworkSettings(array("nodenetwork_id" => array($nn_id)));
- foreach ($settings as $setting) {
- $category=$setting['category'];
- $name=$setting['name'];
- $value=$setting['value'];
- print (" <tr><th> $category $name </th><td> $value </td></tr>\n");
- }
+ print ("<tr><th colspan=2><a href='interfaces.php?id=$nn_id'>Additional Settings</a></th></tr>\n");
+ $nn_id = $interface_detail['interface_id'];
+ $settings=$api->GetInterfaceTags(array("interface_id" => array($nn_id)));
+ foreach ($settings as $setting) {
+ $category=$setting['category'];
+ $name=$setting['tagname'];
+ $value=$setting['value'];
+ print (" <tr><th> $category $name </th><td> $value </td></tr>\n");
}
print( "</table>\n" );
} else {
- print( "<p class='plc-warning'>This node has no configured primary network.</p>\n" );
+ print( "<p class='plc-warning'>This node has no configured primary interface.</p>\n" );
}
show_download_confirm_button($api, $node_id, $action, $can_gen_config, true);