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 $is_pi_or_tech=plc_is_pi() || plc_is_tech();
22 if( ! $has_privileges) {
23 if ( $is_pi_or_tech) {
24 drupal_goto(l_register_node());
27 drupal_set_error ("Insufficient provileges to add a node");
28 header( "index.php" );
32 //plc_debug('POST',$_POST);
34 // if submitted validate and add
35 // could go in actions.php but OTOH when things fail it's more convenient
36 // to show the current values again
37 if ( $_POST['add-node'] ) {
41 $site_id = trim($_POST['site_id']);
42 $hostname = trim($_POST['hostname']);
43 $model= trim($_POST['model']);
44 $ip = trim($_POST['ip']);
45 $method = trim($_POST['method']);
46 $netmask = trim($_POST['netmask']);
47 $network = trim($_POST['network']);
48 $broadcast = trim($_POST['broadcast']);
49 $gateway = trim($_POST['gateway']);
50 $dns1 = trim($_POST['dns1']);
51 $dns2 = trim($_POST['dns2']);
52 $bwlimit = trim($_POST['bwlimit']);
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' ) {
63 foreach( $static_fields as $field => $desc ) {
64 if( trim($_POST[$field]) == "" ) {
65 $errors[] = "$desc is required";
66 } elseif( !is_valid_ip(trim($_POST[$field])) ) {
67 $errors[] = "$desc is not a valid address";
71 if( !is_valid_network_addr($network,$netmask) ) {
72 $errors[] = "The network address does not match the netmask";
76 if( $hostname == "" ) {
77 $errors[] = "Hostname is required";
80 $errors[] = "IP is required";
81 } else if ( ! is_valid_ip ($ip)) {
82 $errors []= "Invalid IP $ip";
85 if( !empty($errors) ) {
86 drupal_set_error(plc_itemize($errors));
88 // add new node and its interface
89 $node_fields= array( "hostname"=>$hostname, "model"=>$model );
90 $node_id= $api->AddNode( intval( $site_id ), $node_fields );
92 if ( empty($node_id) || ($node_id < 0) ) {
93 drupal_set_error ("AddNode failed - hostname already present, or not valid ?");
95 // now, try to add the network.
96 $interface_fields= array();
97 $interface_fields['is_primary']= true;
98 $interface_fields['ip']= $ip;
99 $interface_fields['type']= $_POST['type'];
100 $interface_fields['method']= $method;
101 if (!empty($bwlimit))
102 $interface_fields['bwlimit']=$bwlimit;
104 if ( $method == 'static' ) {
105 $interface_fields['netmask']= $netmask;
106 $interface_fields['network']= $network;
107 $interface_fields['broadcast']= $broadcast;
108 $interface_fields['gateway']= $gateway;
109 $interface_fields['dns1']= $dns1;
111 $interface_fields['dns2']= $dns2;
114 $interface_id= $api->AddInterface( $node_id, $interface_fields);
115 if ($interface_id > 0) {
116 drupal_set_message ("Node successfully created");
117 drupal_set_message ("Download a boot image in the 'Download' drop down below");
118 plc_redirect (l_node($node_id));
120 // if AddInterface fails, we have the node created,
121 // but no primary interface is present.
122 // The primary interface can be added later,
123 // but take a look at the possible Methods,
124 // if we specify TUN/TAP Method we will have
125 // an error on download of the configuration file
126 drupal_set_message ("Node created");
127 drupal_set_error ("But without an interface");
128 drupal_set_error ("Please review manually");
129 plc_redirect (l_node($node_id));
136 require_once 'plc_drupal.php';
137 include 'plc_header.php';
139 // include javacsript helpers
140 require_once 'prototype.php';
141 drupal_set_html_head ('
142 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
145 drupal_set_title('Add a new node to site');
148 $method = $_POST['method'];
149 if( ! $method ) $method= "static";
151 $model = $_POST['model'];
152 if( ! $model ) $model= "Custom";
156 This page lets you declare a new machine to a site.
158 This must be done before the machine is turned on,
159 as it will allow you to download a boot image when complete for this node.
161 It is now reserved to admins, as regular users are supposed to use the register wizard, that among other things enforces PCU deployment.
163 An IP address is required even if you use DHCP.
167 $toggle = new PlekitToggle ('add-node',"Add Node",
168 array('bubble'=>'Add a node - does not enforce PCU - for admins only !',
169 'visible'=>get_arg('show_details',true)));
172 $details=new PlekitDetails($has_privileges);
174 // xxx hardwire network type for now
175 $form_variables = array('type'=>"ipv4");
176 //$form=$details->form_start(l_actions(),$form_variables);
177 $form=$details->form_start('/db/nodes/node_add.php',$form_variables,
178 array('onSubmit'=>'return interfaceSubmit()'));
182 $site_columns=array( "site_id", "name", "login_base" );
183 $local_sites= $api->GetSites( array("peer_id"=>NULL, '-SORT'=>'name'), $site_columns );
184 function site_selector($site) { return array('display'=>$site['name'],"value"=>$site['site_id']); }
185 $site_selector = array_map ("site_selector",$local_sites);
186 $site_select = $form->select_html("site_id", $site_selector, array('id'=>'site_id'));
187 $details->th_td("Site",
190 array('input_type'=>'select','value'=>$interface['site_id']));
192 $details->th_td("Hostname",$hostname,"hostname");
193 $details->th_td("Model",$model,"model");
194 $method_select = $form->select_html ("method",
195 interface_method_selectors($api,$method,true),
196 array('id'=>'method',
197 'onChange'=>'updateMethodFields()'));
198 $details->th_td("Method",$method_select,"method",
199 array('input_type'=>'select','value'=>$interface['method']));
201 // dont display the 'type' selector as it contains only ipv4
202 //>>> GetNetworkTypes()
205 $details->th_td("IP address",$ip,"ip",array('width'=>15,
206 'onKeyup'=>'networkHelper()',
207 'onChange'=>'networkHelper()'));
208 $details->th_td("Netmask",$netmask,"netmask",array('width'=>15,
209 'onKeyup'=>'networkHelper()',
210 'onChange'=>'networkHelper()'));
211 $details->th_td("Network",$network,"network",array('width'=>15));
212 $details->th_td("Broadcast",$broadcast,"broadcast",array('width'=>15));
213 $details->th_td("Gateway",$gateway,"gateway",array('width'=>15,
214 'onChange'=>'subnetChecker("gateway",false)'));
215 $details->th_td("DNS 1",$dns1,"dns1",array('width'=>15,
216 'onChange'=>'subnetChecker("dns1",false)'));
217 $details->th_td("DNS 2",$dns2,"dns2",array('width'=>15,
218 'onChange'=>'subnetChecker("dns2",true)'));
220 $details->th_td("BW limit (bps)",$bwlimit,"bwlimit",array('width'=>11));
223 $add_button = $form->submit_html ("add-node","Add New Node");
224 $details->tr($add_button,"right");
231 include 'plc_footer.php';