4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_functions.php';
13 // if not a admin, pi, or tech then redirect to node index
14 // xxx does not take site into account
15 $has_privileges=plc_is_admin() || plc_is_pi() || plc_is_tech();
16 if( ! $has_privileges) {
17 header( "index.php" );
20 // this sets up which box is to be checked the first time the page is loaded
21 $method= $_POST['method'];
22 if( $method == "" ) $method= "static";
24 $model= $_POST['model'];
25 if( $model == "" ) $model= "Custom";
30 // if submitted validate and add
31 if ( $_POST['submitted'] ) {
36 $method = trim($_POST['method']);
37 $ip = trim($_POST['ip']);
38 $netmask = trim($_POST['netmask']);
39 $network = trim($_POST['network']);
40 $gateway = trim($_POST['gateway']);
41 $broadcast = trim($_POST['broadcast']);
42 $dns1 = trim($_POST['dns1']);
43 $dns2 = trim($_POST['dns2']);
44 $hostname = trim($_POST['hostname']);
45 $model= trim($_POST['model']);
47 // used to generate error strings for static fields only
48 $static_fields= array();
49 $static_fields['netmask']= "Netmask address";
50 $static_fields['network']= "Network address";
51 $static_fields['gateway']= "Gateway address";
52 $static_fields['broadcast']= "Broadcast address";
53 $static_fields['dns1']= "Primary DNS address";
55 if( $method == 'static' ) {
56 foreach( $static_fields as $field => $desc ) {
57 if( trim($_POST[$field]) == "" ) {
58 $errors[] = "$desc is required";
59 } elseif( !is_valid_ip(trim($_POST[$field])) ) {
60 $errors[] = "$desc is not a valid address";
64 if( !is_valid_network_addr($network,$netmask) ) {
65 $errors[] = "The network address does not coorespond to the netmask";
69 if( $hostname == "" ) {
70 $errors[] = "Hostname is required";
73 $errors[] = "IP is required";
75 if( count($errors) == 0 ) {
78 // add new node and its interface
79 $optional_vals= array( "hostname"=>$hostname, "model"=>$model );
80 $site_id= plc_my_site_id();
81 $node_id= $api->AddNode( intval( $site_id ), $optional_vals );
83 if ( $api->error() ) {
84 $errors[] = "Hostname already present or not valid";
87 // now, try to add the network.
88 $optional_vals= array();
89 $optional_vals['is_primary']= true;
90 $optional_vals['ip']= $ip;
91 $optional_vals['type']= 'ipv4';
92 $optional_vals['method']= $method;
94 if( $method == 'static' ) {
95 $optional_vals['gateway']= $gateway;
96 $optional_vals['network']= $network;
97 $optional_vals['broadcast']= $broadcast;
98 $optional_vals['netmask']= $netmask;
99 $optional_vals['dns1']= $dns1;
101 $optional_vals['dns2']= $dns2;
105 $interface_id= $api->AddInterface( $node_id, $optional_vals);
106 // if AddInterface fails, we have the node created,
107 // but no primary interface is present.
108 // The primary interface can be added later,
109 // but take a look at the possible Methods,
110 // if we specify TUN/TAP Method we will have
111 // an error on download of the configuration file
117 require_once 'plc_drupal.php';
118 include 'plc_header.php';
122 <script language="javascript">
123 function updateStaticFields() {
124 var is_dhcp= document.fm.method[0].checked;
126 document.fm.netmask.disabled= is_dhcp;
127 document.fm.network.disabled= is_dhcp;
128 document.fm.gateway.disabled= is_dhcp;
129 document.fm.broadcast.disabled= is_dhcp;
130 document.fm.dns1.disabled= is_dhcp;
131 document.fm.dns2.disabled= is_dhcp;
138 $link=l_node_t($node_id,"here");
139 drupal_set_title('Node created');
142 <p>The node has been successfully added.
144 <p>View node details and download a configuration
148 $sites=$api->GetSites(array(plc_my_site_id()));
149 $sitename=$sites[0]['name'];
151 drupal_set_title('Add a new node in site "' . $sitename . '"');
154 <p>This page will allow you to add a new machine to your site. This must
155 be done before the machine is turned on, as it will allow you to download
156 a configuration file when complete for this node.
158 <p>Even for DHCP, you must enter the IP address of the node.
161 if( count($errors) > 0 ) {
162 plc_errors ($errors);
165 $self = $_SERVER['PHP_SELF'];
166 if (!empty($_SERVER['QUERY_STRING'])) {
167 $self .= "?" . $_SERVER['QUERY_STRING'];
172 <form name="fm" method="post" action="<?php echo $self; ?>">
173 <input type="hidden" name="submitted" value="1">
175 <h3>Node Details</h3>
178 <input type="hidden" name="submitted" value="1">
180 <table width="100%" cellspacing="0" cellpadding="4" border="0">
183 <td width=250>Hostname:</td>
184 <td><input type="text" name="hostname"
185 value="<?php print($hostname); ?>" size="40" maxlength="256"></td>
190 <td><input type="text" name="model"
191 value="<?php print($model); ?>" size="40" maxlength="256"></td>
197 <h3>Interface Settings</h3>
199 <table width="100%" cellspacing="0" cellpadding="4" border="0">
202 <td valign='top' width="250">Addressing method</td>
204 <input type="radio" name="method" value="dhcp" onChange='updateStaticFields()'
205 <?php if($method == 'dhcp') { echo "checked"; } ?>>DHCP
206 <input type="radio" name="method" value="static" onChange='updateStaticFields()'
207 <?php if($method == 'static') { echo "checked"; } ?>>Static
212 <td valign='top'>IP address</td>
213 <td><input type="text" name="ip" value="<?php print($ip); ?>"></td>
217 <td valign='top'>Netmask</font></td>
218 <td><input type="text" name="netmask" value="<?php print($netmask); ?>"></td>
222 <td valign='top'>Network address</td>
223 <td><input type="text" name="network" value="<?php print($network); ?>">
228 <td valign='top'>Gateway address</td>
229 <td><input type="text" name="gateway" value="<?php print($gateway); ?>"></td>
233 <td valign='top'>Broadcast address</td>
234 <td><input type="text" name="broadcast" value="<?php print($broadcast); ?>">
239 <td valign='top'>Primary DNS</td>
240 <td><input type="text" name="dns1" value="<?php print($dns1); ?>">
245 <td valign='top'>Secondary DNS (optional)</td>
246 <td><input type="text" name="dns2" value="<?php print($dns2); ?>">
252 <td><input type="submit" name="Submit" value="Add"></td>
264 include 'plc_footer.php';