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 'details.php';
13 require_once 'form.php';
15 // if not a admin, pi, or tech then redirect to node index
16 // xxx does not take site into account
17 $has_privileges=plc_is_admin() || plc_is_pi() || plc_is_tech();
18 if( ! $has_privileges) {
19 drupal_set_error ("Unsufficient provileges to add a node");
20 header( "index.php" );
23 //plc_debug('POST',$_POST);
25 // this sets up which box is to be checked the first time the page is loaded
26 // start with static; starting with dhcp does not disable the useless fields
27 $method= $_POST['method'];
28 if( $method == "" ) $method= "static";
30 $model= $_POST['model'];
31 if( $model == "" ) $model= "Custom";
33 // if submitted validate and add
34 // could go in actions.php but OTOH when things fail it's more convenient
35 // to show the current values again
36 if ( $_POST['add-node'] ) {
40 $hostname = trim($_POST['hostname']);
41 $model= trim($_POST['model']);
42 $ip = trim($_POST['ip']);
43 $method = trim($_POST['method']);
44 $netmask = trim($_POST['netmask']);
45 $network = trim($_POST['network']);
46 $broadcast = trim($_POST['broadcast']);
47 $gateway = trim($_POST['gateway']);
48 $dns1 = trim($_POST['dns1']);
49 $dns2 = trim($_POST['dns2']);
50 $bwlimit = trim($_POST['bwlimit']);
52 // used to generate error strings for static fields only
53 $static_fields= array();
54 $static_fields['netmask']= "Netmask address";
55 $static_fields['network']= "Network address";
56 $static_fields['gateway']= "Gateway address";
57 $static_fields['broadcast']= "Broadcast address";
58 $static_fields['dns1']= "Primary DNS address";
60 if( $method == 'static' ) {
61 foreach( $static_fields as $field => $desc ) {
62 if( trim($_POST[$field]) == "" ) {
63 $errors[] = "$desc is required";
64 } elseif( !is_valid_ip(trim($_POST[$field])) ) {
65 $errors[] = "$desc is not a valid address";
69 if( !is_valid_network_addr($network,$netmask) ) {
70 $errors[] = "The network address does not match the netmask";
74 if( $hostname == "" ) {
75 $errors[] = "Hostname is required";
78 $errors[] = "IP is required";
79 } else if ( ! is_valid_ip ($ip)) {
80 $errors []= "Invalid IP $ip";
83 if( !empty($errors) ) {
84 drupal_set_error(plc_itemize($errors));
86 // add new node and its interface
87 $node_fields= array( "hostname"=>$hostname, "model"=>$model );
88 $site_id= plc_my_site_id();
89 $node_id= $api->AddNode( intval( $site_id ), $node_fields );
91 if ( empty($node_id) || ($node_id < 0) ) {
92 drupal_set_error ("AddNode failed - hostname already present, or not valid ?");
94 // now, try to add the network.
95 $interface_fields= array();
96 $interface_fields['is_primary']= true;
97 $interface_fields['ip']= $ip;
98 $interface_fields['type']= $_POST['type'];
99 $interface_fields['method']= $method;
100 if (!empty($bwlimit))
101 $interface_fields['bwlimit']=$bwlimit;
103 if ( $method == 'static' ) {
104 $interface_fields['netmask']= $netmask;
105 $interface_fields['network']= $network;
106 $interface_fields['broadcast']= $broadcast;
107 $interface_fields['gateway']= $gateway;
108 $interface_fields['dns1']= $dns1;
110 $interface_fields['dns2']= $dns2;
113 $interface_id= $api->AddInterface( $node_id, $interface_fields);
114 if ($interface_id > 0) {
115 drupal_set_message ("Node successfully created");
116 drupal_set_message ("Download a boot image in the 'Download' drop down below");
117 plc_redirect (l_node($node_id));
119 // if AddInterface fails, we have the node created,
120 // but no primary interface is present.
121 // The primary interface can be added later,
122 // but take a look at the possible Methods,
123 // if we specify TUN/TAP Method we will have
124 // an error on download of the configuration file
125 drupal_set_message ("Node created");
126 drupal_set_error ("But without an interface");
127 drupal_set_error ("Please review manually");
128 plc_redirect (l_node($node_id));
135 require_once 'plc_drupal.php';
136 include 'plc_header.php';
138 // include javacsript helpers
139 require_once 'prototype.php';
140 drupal_set_html_head ('
141 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
144 $sites=$api->GetSites(array(plc_my_site_id()));
145 $sitename=$sites[0]['name'];
147 drupal_set_title('Add a new node in site "' . $sitename . '"');
151 This page lets you declare a new machine in your site.
152 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.
154 You must enter an IP address even if you use DHCP.
158 $details=new PlekitDetails($has_privileges);
160 // xxx hardwire network type for now
161 $form_variables = array('type'=>"ipv4");
162 //$form=$details->form_start(l_actions(),$form_variables);
163 $form=$details->form_start('/db/nodes/node_add.php',$form_variables);
167 $details->th_td("Hostname",$hostname,"hostname");
168 $details->th_td("Model",$model,"model");
169 $method_select = $form->select_html ("method",
170 interface_method_selectors($api,$method,true),
171 array('id'=>'method',
172 'onChange'=>'updateMethodFields()'));
173 $details->th_td("Method",$method_select,"method",
174 array('input_type'=>'select','value'=>$interface['method']));
176 // dont display the 'type' selector as it contains only ipv4
177 //>>> GetNetworkTypes()
180 $details->th_td("IP address",$ip,"ip",array('width'=>15,
181 'onKeyup'=>'networkHelper()',
182 'onChange'=>'networkHelper()'));
183 $details->th_td("Netmask",$netmask,"netmask",array('width'=>15,
184 'onKeyup'=>'networkHelper()',
185 'onChange'=>'networkHelper()'));
186 $details->th_td("Network",$network,"network",array('width'=>15));
187 $details->th_td("Broadcast",$broadcast,"broadcast",array('width'=>15));
188 $details->th_td("Gateway",$gateway,"gateway",array('width'=>15,
189 'onChange'=>'subnetChecker("gateway",false)'));
190 $details->th_td("DNS 1",$dns1,"dns1",array('width'=>15,
191 'onChange'=>'subnetChecker("dns1",false)'));
192 $details->th_td("DNS 2",$dns2,"dns2",array('width'=>15,
193 'onChange'=>'subnetChecker("dns2",true)'));
195 $details->th_td("BW limit (bps)",$bwlimit,"bwlimit",array('width'=>11));
198 $add_button = $form->submit_html ("add-node","Add New Node",
199 array('onSubmit'=>'interfaceSubmit()'));
200 $details->tr($add_button,"right");
206 include 'plc_footer.php';