6 require_once 'plc_login.php';
8 // Get session and API handles
9 require_once 'plc_session.php';
13 require_once 'plc_functions.php';
14 require_once 'toggle.php';
15 require_once 'details.php';
16 require_once 'form.php';
18 // if not a admin, pi, or tech then redirect to node index
19 // xxx does not take site into account
20 $has_privileges=plc_is_admin();
21 if( ! $has_privileges) {
22 drupal_set_error ("Insufficient provileges to add a node");
23 header( "index.php" );
27 //plc_debug('POST',$_POST);
29 // if submitted validate and add
30 // could go in actions.php but OTOH when things fail it's more convenient
31 // to show the current values again
32 if ( $_POST['add-node'] ) {
36 $site_id = trim($_POST['site_id']);
37 $hostname = trim($_POST['hostname']);
38 $model= trim($_POST['model']);
39 $ip = trim($_POST['ip']);
40 $method = trim($_POST['method']);
41 $netmask = trim($_POST['netmask']);
42 $network = trim($_POST['network']);
43 $broadcast = trim($_POST['broadcast']);
44 $gateway = trim($_POST['gateway']);
45 $dns1 = trim($_POST['dns1']);
46 $dns2 = trim($_POST['dns2']);
47 $bwlimit = trim($_POST['bwlimit']);
49 // used to generate error strings for static fields only
50 $static_fields= array();
51 $static_fields['netmask']= "Netmask address";
52 $static_fields['network']= "Network address";
53 $static_fields['gateway']= "Gateway address";
54 $static_fields['broadcast']= "Broadcast address";
55 $static_fields['dns1']= "Primary DNS address";
57 if( $method == 'static' ) {
58 foreach( $static_fields as $field => $desc ) {
59 if( trim($_POST[$field]) == "" ) {
60 $errors[] = "$desc is required";
61 } elseif( !is_valid_ip(trim($_POST[$field])) ) {
62 $errors[] = "$desc is not a valid address";
66 if( !is_valid_network_addr($network,$netmask) ) {
67 $errors[] = "The network address does not match the netmask";
71 if( $hostname == "" ) {
72 $errors[] = "Hostname is required";
75 $errors[] = "IP is required";
76 } else if ( ! is_valid_ip ($ip)) {
77 $errors []= "Invalid IP $ip";
80 if( !empty($errors) ) {
81 drupal_set_error(plc_itemize($errors));
83 // add new node and its interface
84 $node_fields= array( "hostname"=>$hostname, "model"=>$model );
85 $node_id= $api->AddNode( intval( $site_id ), $node_fields );
87 if ( empty($node_id) || ($node_id < 0) ) {
88 drupal_set_error ("AddNode failed - hostname already present, or not valid ?");
90 // now, try to add the network.
91 $interface_fields= array();
92 $interface_fields['is_primary']= true;
93 $interface_fields['ip']= $ip;
94 $interface_fields['type']= $_POST['type'];
95 $interface_fields['method']= $method;
97 $interface_fields['bwlimit']=$bwlimit;
99 if ( $method == 'static' ) {
100 $interface_fields['netmask']= $netmask;
101 $interface_fields['network']= $network;
102 $interface_fields['broadcast']= $broadcast;
103 $interface_fields['gateway']= $gateway;
104 $interface_fields['dns1']= $dns1;
106 $interface_fields['dns2']= $dns2;
109 $interface_id= $api->AddInterface( $node_id, $interface_fields);
110 if ($interface_id > 0) {
111 drupal_set_message ("Node successfully created");
112 drupal_set_message ("Download a boot image in the 'Download' drop down below");
113 plc_redirect (l_node($node_id));
115 // if AddInterface fails, we have the node created,
116 // but no primary interface is present.
117 // The primary interface can be added later,
118 // but take a look at the possible Methods,
119 // if we specify TUN/TAP Method we will have
120 // an error on download of the configuration file
121 drupal_set_message ("Node created");
122 drupal_set_error ("But without an interface");
123 drupal_set_error ("Please review manually");
124 plc_redirect (l_node($node_id));
131 require_once 'plc_drupal.php';
132 include 'plc_header.php';
134 // include javacsript helpers
135 require_once 'prototype.php';
136 drupal_set_html_head ('
137 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
140 drupal_set_title('Add a new node to site');
143 $method = $_POST['method'];
144 if( ! $method ) $method= "static";
146 $model = $_POST['model'];
147 if( ! $model ) $model= "Custom";
151 This page lets you declare a new machine to a site.
153 This must be done before the machine is turned on,
154 as it will allow you to download a boot image when complete for this node.
156 It is now reserved to admins, as regular users are supposed to use the register wizard, that among other things enforces PCU deployment.
158 An IP address is required even if you use DHCP.
162 $toggle = new PlekitToggle ('add-node',"Add Node",
163 array('bubble'=>'Add a node - does not enforce PCU - for admins only !',
164 'visible'=>get_arg('show_details',true)));
167 $details=new PlekitDetails($has_privileges);
169 // xxx hardwire network type for now
170 $form_variables = array('type'=>"ipv4");
171 //$form=$details->form_start(l_actions(),$form_variables);
172 $form=$details->form_start('/db/nodes/node_add.php',$form_variables,
173 array('onSubmit'=>'return interfaceSubmit()'));
177 $site_columns=array( "site_id", "name", "login_base" );
178 $local_sites= $api->GetSites( array("peer_id"=>NULL, '-SORT'=>'name'), $site_columns );
179 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
180 $site_selector = array_map ("site_selector",$local_sites);
181 $site_select = $form->select_html("site_id", $site_selector, array('id'=>'site_id'));
182 $details->th_td("Site",
185 array('input_type'=>'select','value'=>$interface['site_id']));
187 $details->th_td("Hostname",$hostname,"hostname");
188 $details->th_td("Model",$model,"model");
189 $method_select = $form->select_html ("method",
190 interface_method_selectors($api,$method,true),
191 array('id'=>'method',
192 'onChange'=>'updateMethodFields()'));
193 $details->th_td("Method",$method_select,"method",
194 array('input_type'=>'select','value'=>$interface['method']));
196 // dont display the 'type' selector as it contains only ipv4
197 //>>> GetNetworkTypes()
200 $details->th_td("IP address",$ip,"ip",array('width'=>15,
201 'onKeyup'=>'networkHelper()',
202 'onChange'=>'networkHelper()'));
203 $details->th_td("Netmask",$netmask,"netmask",array('width'=>15,
204 'onKeyup'=>'networkHelper()',
205 'onChange'=>'networkHelper()'));
206 $details->th_td("Network",$network,"network",array('width'=>15));
207 $details->th_td("Broadcast",$broadcast,"broadcast",array('width'=>15));
208 $details->th_td("Gateway",$gateway,"gateway",array('width'=>15,
209 'onChange'=>'subnetChecker("gateway",false)'));
210 $details->th_td("DNS 1",$dns1,"dns1",array('width'=>15,
211 'onChange'=>'subnetChecker("dns1",false)'));
212 $details->th_td("DNS 2",$dns2,"dns2",array('width'=>15,
213 'onChange'=>'subnetChecker("dns2",true)'));
215 $details->th_td("BW limit (bps)",$bwlimit,"bwlimit",array('width'=>11));
218 $add_button = $form->submit_html ("add-node","Add New Node");
219 $details->tr($add_button,"right");
226 include 'plc_footer.php';