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';
14 // if not a admin, pi, or tech then redirect to node index
15 // xxx does not take site into account
16 $has_privileges=plc_is_admin() || plc_is_pi() || plc_is_tech();
17 if( ! $has_privileges) {
18 header( "index.php" );
21 // this sets up which box is to be checked the first time the page is loaded
22 $method= $_POST['method'];
23 if( $method == "" ) $method= "static";
25 $model= $_POST['model'];
26 if( $model == "" ) $model= "Custom";
31 // if submitted validate and add
32 if ( $_POST['submitted'] ) {
37 $method = trim($_POST['method']);
38 $ip = trim($_POST['ip']);
39 $netmask = trim($_POST['netmask']);
40 $network = trim($_POST['network']);
41 $gateway = trim($_POST['gateway']);
42 $broadcast = trim($_POST['broadcast']);
43 $dns1 = trim($_POST['dns1']);
44 $dns2 = trim($_POST['dns2']);
45 $hostname = trim($_POST['hostname']);
46 $model= trim($_POST['model']);
48 // used to generate error strings for static fields only
49 $static_fields= array();
50 $static_fields['netmask']= "Netmask address";
51 $static_fields['network']= "Network address";
52 $static_fields['gateway']= "Gateway address";
53 $static_fields['broadcast']= "Broadcast address";
54 $static_fields['dns1']= "Primary DNS address";
56 if( $method == 'static' ) {
57 foreach( $static_fields as $field => $desc ) {
58 if( trim($_POST[$field]) == "" ) {
59 $errors[] = "$desc is required";
60 } elseif( !is_valid_ip(trim($_POST[$field])) ) {
61 $errors[] = "$desc is not a valid address";
65 if( !is_valid_network_addr($network,$netmask) ) {
66 $errors[] = "The network address does not coorespond to the netmask";
70 if( $hostname == "" ) {
71 $errors[] = "Hostname is required";
74 $errors[] = "IP is required";
76 if( count($errors) == 0 ) {
79 // add new node and its interface
80 $optional_vals= array( "hostname"=>$hostname, "model"=>$model );
81 $site_id= plc_my_site_id();
82 $node_id= $api->AddNode( intval( $site_id ), $optional_vals );
84 if ( $api->error() ) {
85 $errors[] = "Hostname already present or not valid";
88 // now, try to add the network.
89 $optional_vals= array();
90 $optional_vals['is_primary']= true;
91 $optional_vals['ip']= $ip;
92 $optional_vals['type']= 'ipv4';
93 $optional_vals['method']= $method;
95 if( $method == 'static' ) {
96 $optional_vals['gateway']= $gateway;
97 $optional_vals['network']= $network;
98 $optional_vals['broadcast']= $broadcast;
99 $optional_vals['netmask']= $netmask;
100 $optional_vals['dns1']= $dns1;
102 $optional_vals['dns2']= $dns2;
106 $interface_id= $api->AddInterface( $node_id, $optional_vals);
107 // if AddInterface fails, we have the node created,
108 // but no primary interface is present.
109 // The primary interface can be added later,
110 // but take a look at the possible Methods,
111 // if we specify TUN/TAP Method we will have
112 // an error on download of the configuration file
118 require_once 'plc_drupal.php';
119 drupal_set_title('Nodes');
120 include 'plc_header.php';
124 <script language="javascript">
125 function updateStaticFields() {
126 var is_dhcp= document.fm.method[0].checked;
128 document.fm.netmask.disabled= is_dhcp;
129 document.fm.network.disabled= is_dhcp;
130 document.fm.gateway.disabled= is_dhcp;
131 document.fm.broadcast.disabled= is_dhcp;
132 document.fm.dns1.disabled= is_dhcp;
133 document.fm.dns2.disabled= is_dhcp;
140 $link=l_node2($node_id,"here");
142 <h2>Node Created</h2>
144 <p>The node has been successfully added.
146 <p>View node details and download a configuration
151 <h2>Add A New Node</h2>
153 <p>This page will allow you to add a new machine to your site. This must
154 be done before the machine is turned on, as it will allow you to download
155 a configuration file when complete for this node.
157 <p>Even for DHCP, you must enter the IP address of the node.
160 if( count($errors) > 0 ) {
161 plc_errors ($errors);
164 $self = $_SERVER['PHP_SELF'];
165 if (!empty($_SERVER['QUERY_STRING'])) {
166 $self .= "?" . $_SERVER['QUERY_STRING'];
171 <form name="fm" method="post" action="<?php echo $self; ?>">
172 <input type="hidden" name="submitted" value="1">
174 <h3>Node Details</h3>
177 <input type="hidden" name="submitted" value="1">
179 <table width="100%" cellspacing="0" cellpadding="4" border="0">
182 <td width=250>Hostname:</td>
183 <td><input type="text" name="hostname"
184 value="<?php print($hostname); ?>" size="40" maxlength="256"></td>
189 <td><input type="text" name="model"
190 value="<?php print($model); ?>" size="40" maxlength="256"></td>
196 <h3>Interface Settings</h3>
198 <table width="100%" cellspacing="0" cellpadding="4" border="0">
201 <td valign='top' width="250">Addressing Method</td>
203 <input type="radio" name="method" value="dhcp" onChange='updateStaticFields()'
204 <?php if($method == 'dhcp') { echo "checked"; } ?>>DHCP
205 <input type="radio" name="method" value="static" onChange='updateStaticFields()'
206 <?php if($method == 'static') { echo "checked"; } ?>>Static
211 <td valign='top'>IP Address</td>
212 <td><input type="text" name="ip" value="<?php print($ip); ?>"></td>
216 <td valign='top'>Netmask</font></td>
217 <td><input type="text" name="netmask" value="<?php print($netmask); ?>"></td>
221 <td valign='top'>Network address</td>
222 <td><input type="text" name="network" value="<?php print($network); ?>">
227 <td valign='top'>Gateway Address</td>
228 <td><input type="text" name="gateway" value="<?php print($gateway); ?>"></td>
232 <td valign='top'>Broadcast address</td>
233 <td><input type="text" name="broadcast" value="<?php print($broadcast); ?>">
238 <td valign='top'>Primary DNS</td>
239 <td><input type="text" name="dns1" value="<?php print($dns1); ?>">
244 <td valign='top'>Secondary DNS (optional)</td>
245 <td><input type="text" name="dns2" value="<?php print($dns2); ?>">
251 <td><input type="submit" name="Submit" value="Add"></td>
263 include 'plc_footer.php';