4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_functions.php';
12 require_once 'plc_sorts.php';
15 $_person= $plc->person;
16 $_roles= $_person['role_ids'];
18 // if not a admin, pi, or tech then redirect to node index
19 if( !(in_array( 10, $plc->person['role_ids'] ) || in_array( 20, $plc->person['role_ids'] ) || in_array( 40, $plc->person['role_ids'] )) ) {
20 header( "index.php" );
24 // this sets up which box is to be checked the first time the page is loaded
25 $method= $_POST['method'];
29 $model= $_POST['model'];
36 // if submitted validate and add
37 if( $_POST['submitted'] )
43 $method = trim($_POST['method']);
44 $ip = trim($_POST['ip']);
45 $netmask = trim($_POST['netmask']);
46 $network = trim($_POST['network']);
47 $gateway = trim($_POST['gateway']);
48 $broadcast = trim($_POST['broadcast']);
49 $dns1 = trim($_POST['dns1']);
50 $dns2 = trim($_POST['dns2']);
51 $hostname = trim($_POST['hostname']);
52 $model= trim($_POST['model']);
54 // used to generate error strings for static fields only
55 $static_fields= array();
56 $static_fields['netmask']= "Netmask address";
57 $static_fields['network']= "Network address";
58 $static_fields['gateway']= "Gateway address";
59 $static_fields['broadcast']= "Broadcast address";
60 $static_fields['dns1']= "Primary DNS address";
62 if( $method == 'static' )
64 foreach( $static_fields as $field => $desc )
66 if( trim($_POST[$field]) == "" )
68 $errors[] = "$desc is required";
70 elseif( !is_valid_ip(trim($_POST[$field])) )
72 $errors[] = "$desc is not a valid address";
76 if( !is_valid_network_addr($network,$netmask) )
78 $errors[] = "The network address does not coorespond to the netmask";
84 $errors[] = "Hostname is required";
89 $errors[] = "IP is required";
92 if( count($errors) == 0 )
96 // add new node and its network
97 $optional_vals= array( "hostname"=>$hostname, "model"=>$model );
99 $site_id= $_person['site_ids'][0];
101 $node_id= $api->AddNode( intval( $site_id ), $optional_vals );
103 if ( $api->error() ) {
104 $errors[] = "Hostname already present or not valid";
109 // now, try to add the network.
110 $optional_vals= array();
111 $optional_vals['is_primary']= true;
112 $optional_vals['ip']= $ip;
113 $optional_vals['type']= 'ipv4';
114 $optional_vals['method']= $method;
116 if( $method == 'static' )
119 $optional_vals['gateway']= $gateway;
120 $optional_vals['network']= $network;
121 $optional_vals['broadcast']= $broadcast;
122 $optional_vals['netmask']= $netmask;
123 $optional_vals['dns1']= $dns1;
125 $optional_vals['dns2']= $dns2;
129 $interface_id= $api->AddInterface( $node_id, $optional_vals);
130 // if AddInterface fails, we have the node created,
131 // but no primary interface is present.
132 // The primary interface can be added later,
133 // but take a look at the possible Methods,
134 // if we specify TUN/TAP Method we will have
135 // an error on download of the configuration file
143 require_once 'plc_drupal.php';
144 drupal_set_title('Nodes');
145 include 'plc_header.php';
150 <script language="javascript">
151 function updateStaticFields()
153 var is_dhcp= document.fm.method[0].checked;
155 document.fm.netmask.disabled= is_dhcp;
156 document.fm.network.disabled= is_dhcp;
157 document.fm.gateway.disabled= is_dhcp;
158 document.fm.broadcast.disabled= is_dhcp;
159 document.fm.dns1.disabled= is_dhcp;
160 document.fm.dns2.disabled= is_dhcp;
169 <h2>Node Created</h2>
171 <p>The node has been successfully added.
173 <p>View node details and download a configuration
174 file <a href="/db/nodes/index.php?id=<?php echo $node_id ?>">here</a>.
182 <h2>Add A New Node</h2>
184 <p>This page will allow you to add a new machine to your site. This must
185 be done before the machine is turned on, as it will allow you to download
186 a configuration file when complete for this node.
188 <p>Even for DHCP, you must enter the IP address of the node.
191 if( count($errors) > 0 )
193 print( "<p><strong>The following errors occured:</strong>" );
194 print( "<font color='red' size='-1'><ul>\n" );
195 foreach( $errors as $err )
197 print( "<li>$err\n" );
199 print( "</ul></font>\n" );
202 $self = $_SERVER['PHP_SELF'];
203 if (!empty($_SERVER['QUERY_STRING'])) {
204 $self .= "?" . $_SERVER['QUERY_STRING'];
209 <form name="fm" method="post" action="<?php echo $self; ?>">
210 <input type="hidden" name="submitted" value="1">
212 <h3>Node Details</h3>
215 <input type="hidden" name="submitted" value="1">
217 <table width="100%" cellspacing="0" cellpadding="4" border="0">
220 <td width=250>Hostname:</td>
221 <td><input type="text" name="hostname"
222 value="<?php print($hostname); ?>" size="40" maxlength="256"></td>
227 <td><input type="text" name="model"
228 value="<?php print($model); ?>" size="40" maxlength="256"></td>
234 <h3>Network Settings</h3>
236 <table width="100%" cellspacing="0" cellpadding="4" border="0">
239 <td valign='top' width="250">Addressing Method</td>
241 <input type="radio" name="method" value="dhcp" onChange='updateStaticFields()'
242 <?php if($method == 'dhcp') { echo "checked"; } ?>>DHCP
243 <input type="radio" name="method" value="static" onChange='updateStaticFields()'
244 <?php if($method == 'static') { echo "checked"; } ?>>Static
249 <td valign='top'>IP Address</td>
250 <td><input type="text" name="ip" value="<?php print($ip); ?>"></td>
254 <td valign='top'>Netmask</font></td>
255 <td><input type="text" name="netmask" value="<?php print($netmask); ?>"></td>
259 <td valign='top'>Network address</td>
260 <td><input type="text" name="network" value="<?php print($network); ?>">
265 <td valign='top'>Gateway Address</td>
266 <td><input type="text" name="gateway" value="<?php print($gateway); ?>"></td>
270 <td valign='top'>Broadcast address</td>
271 <td><input type="text" name="broadcast" value="<?php print($broadcast); ?>">
276 <td valign='top'>Primary DNS</td>
277 <td><input type="text" name="dns1" value="<?php print($dns1); ?>">
282 <td valign='top'>Secondary DNS (optional)</td>
283 <td><input type="text" name="dns2" value="<?php print($dns2); ?>">
289 <td><input type="submit" name="Submit" value="Add"></td>
301 include 'plc_footer.php';