$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 coorespond to the netmask"; } } if( $hostname == "" ) { $errors[] = "Hostname is required"; } if( $ip == "" ) { $errors[] = "IP is required"; } if( count($errors) == 0 ) { $success= 1; // add new node and its interface $optional_vals= array( "hostname"=>$hostname, "model"=>$model ); $site_id= plc_my_site_id(); $node_id= $api->AddNode( intval( $site_id ), $optional_vals ); if ( $api->error() ) { $errors[] = "Hostname already present or not valid"; $success= 0; } else { // now, try to add the network. $optional_vals= array(); $optional_vals['is_primary']= true; $optional_vals['ip']= $ip; $optional_vals['type']= 'ipv4'; $optional_vals['method']= $method; if( $method == 'static' ) { $optional_vals['gateway']= $gateway; $optional_vals['network']= $network; $optional_vals['broadcast']= $broadcast; $optional_vals['netmask']= $netmask; $optional_vals['dns1']= $dns1; if (!empty($dns2)) { $optional_vals['dns2']= $dns2; } } $interface_id= $api->AddInterface( $node_id, $optional_vals); // 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 } } } // Print header require_once 'plc_drupal.php'; include 'plc_header.php'; ?> The node has been successfully added.

View node details and download a configuration file $link. EOF; } else { $sites=$api->GetSites(array(plc_my_site_id())); $sitename=$sites[0]['name']; drupal_set_title('Add a new node in site "' . $sitename . '"'); print <<< EOF

This page will allow you to add a new machine to your site. This must be done before the machine is turned on, as it will allow you to download a configuration file when complete for this node.

Even for DHCP, you must enter the IP address of the node. EOF; if( count($errors) > 0 ) { plc_errors ($errors); } $self = $_SERVER['PHP_SELF']; if (!empty($_SERVER['QUERY_STRING'])) { $self .= "?" . $_SERVER['QUERY_STRING']; } ?>

Node Details

Hostname:
Model:

Interface Settings

Addressing Method >DHCP >Static
IP Address
Netmask
Network address
Gateway Address
Broadcast address
Primary DNS
Secondary DNS (optional)