$desc ) { if( trim($_POST[$field]) == "" ) { $errors[] = "$desc is required"; } elseif( !is_valid_ip(trim($_POST[$field])) ) { $errors[] = "$desc is not a valid address"; } } if( !is_valid_network_addr($network,$netmask) ) { $errors[] = "The network address does not match the netmask"; } } if( $hostname == "" ) { $errors[] = "Hostname is required"; } if( $ip == "" ) { $errors[] = "IP is required"; } else if ( ! is_valid_ip ($ip)) { $errors []= "Invalid IP $ip"; } if( !empty($errors) ) { drupal_set_error(plc_itemize($errors)); } else { // add new node and its interface $node_fields= array( "hostname"=>$hostname, "model"=>$model ); $site_id= plc_my_site_id(); $node_id= $api->AddNode( intval( $site_id ), $node_fields ); if ( empty($node_id) || ($node_id < 0) ) { drupal_set_error ("AddNode failed - hostname already present, or not valid ?"); } else { // now, try to add the network. $interface_fields= array(); $interface_fields['is_primary']= true; $interface_fields['ip']= $ip; $interface_fields['type']= $_POST['type']; $interface_fields['method']= $method; if (!empty($bwlimit)) $interface_fields['bwlimit']=$bwlimit; if ( $method == 'static' ) { $interface_fields['netmask']= $netmask; $interface_fields['network']= $network; $interface_fields['broadcast']= $broadcast; $interface_fields['gateway']= $gateway; $interface_fields['dns1']= $dns1; if (!empty($dns2)) $interface_fields['dns2']= $dns2; } $interface_id= $api->AddInterface( $node_id, $interface_fields); if ($interface_id > 0) { drupal_set_message ("Node successfully created"); drupal_set_message ("Download a boot image in the 'Download' drop down below"); plc_redirect (l_node($node_id)); } else { // if AddInterface fails, we have the node created, // but no primary interface is present. // The primary interface can be added later, // but take a look at the possible Methods, // if we specify TUN/TAP Method we will have // an error on download of the configuration file drupal_set_message ("Node created"); drupal_set_error ("But without an interface"); drupal_set_error ("Please review manually"); plc_redirect (l_node($node_id)); } } } } // Print header require_once 'plc_drupal.php'; include 'plc_header.php'; // include javacsript helpers require_once 'prototype.php'; drupal_set_html_head (' '); $sites=$api->GetSites(array(plc_my_site_id())); $site=$sites[0]; $sitename=$site['name']; drupal_set_title('Add a new node in site "' . $sitename . '"'); // defaults $method = $_POST['method']; if( ! $method ) $method= "static"; $model = $_POST['model']; if( ! $model ) $model= "Custom"; print <<< EOF
This page lets you declare a new machine in your site.
This must be done before the machine is turned on, as it will allow you to download a boot image when complete for this node.
You must enter an IP address even if you use DHCP.