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_minitabs.php';
13 require_once 'plc_details.php';
14 require_once 'plc_tables.php';
15 require_once 'prototype.php';
17 require_once 'plc_drupal.php';
18 include 'plc_header.php';
20 // purpose : display, update or add an interface
23 // updating : _GET['id'] :
24 // if id is set: display the interface, allows to update/add a new if the user has privileges
25 // adding: _GET['node_id']:
26 // otherwise, node_id is needed and the form only allows to add
28 if ( isset ($_GET['id'])) {
30 $interface_id=intval($_GET['id']);
31 $interfaces=$api->GetInterfaces(array('interface_id'=>$interface_id));
32 $interface=$interfaces[0];
33 $node_id=$interface['node_id'];
34 } else if (isset ($_GET['node_id'])) {
37 $node_id=$_GET['node_id'];
41 drupal_set_error('Malformed URL in interface.php, need id or node_id');
42 plc_redirect(l_nodes());
47 $tabs[] = array('label'=>'Back to node', 'url'=>l_node($node_id),
48 'bubble'=>'Cancel pending changes');
51 $fields=array( 'method', 'type', 'ip', 'gateway', 'network', 'broadcast', 'netmask',
52 'dns1', 'dns2', 'hostname', 'mac', 'bwlimit', 'node_id' );
54 //////////////////////////////
55 $nodes= $api->GetNodes( array( intval($node_id) ), array( 'node_id', 'hostname', 'site_id' ) );
57 $site_id=$node['site_id'];
59 $can_update= plc_is_admin() || ( plc_in_site ($site_id) && ( plc_is_pi() || plc_is_tech()));
61 drupal_set_title("Interface on " . $node['hostname']);
63 // include javacsript helpers
65 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
68 $details=new PlcDetails($can_update);
70 // xxx hardwire network type for now
71 $form_variables = array('node_id'=>$node_id,'type'=>"ipv4");
72 if ($mode == "update") $form_variables['interface_id']=$interface_id;
73 $form=$details->form_start(l_actions(),$form_variables);
77 //>>> GetNetworkMethods()
78 //[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown']
79 function method_selectors ($api, $method) {
80 $builtin_methods=array("static"=>"Static", "dhcp"=>"DHCP", "proxy"=>"Proxy",
81 "tap"=>"TUN/TAP", "ipmi"=>"IPMI");
83 foreach ($builtin_methods as $value=>$display) {
84 $selector=array('display'=>$display, 'value'=>$value);
85 if ($value == $method) $selector['selected']=true;
86 $selectors []= $selector;
90 $method_select = $form->select_html ("method",method_selectors($api,$interface['method']),
91 array('id'=>'method','onChange'=>'updateMethodFields()'));
92 $details->th_td("Method",$method_select,"method",array('input_type'=>'select','value'=>$interface['method']));
94 // dont display the 'type' selector as it contains only ipv4
95 //>>> GetNetworkTypes()
98 $details->th_td("IP",$interface['ip'],"ip",array('width'=>15,
99 'onKeyup'=>'networkHelper()',
100 'onChange'=>'networkHelper()'));
101 $details->th_td("Netmask",$interface['netmask'],"netmask",array('width'=>15,
102 'onKeyup'=>'networkHelper()',
103 'onChange'=>'networkHelper()'));
104 $details->th_td("Network",$interface['network'],"network",array('width'=>15));
105 $details->th_td("Broadcast",$interface['broadcast'],"broadcast",array('width'=>15));
106 $details->th_td("Gateway",$interface['gateway'],"gateway",array('width'=>15,
107 'onChange'=>'subnetChecker("gateway",false)'));
108 $details->th_td("DNS 1",$interface['dns1'],"dns1",array('width'=>15,
109 'onChange'=>'subnetChecker("dns1",false)'));
110 $details->th_td("DNS 2",$interface['dns2'],"dns2",array('width'=>15,
111 'onChange'=>'subnetChecker("dns2",true)'));
113 $details->th_td("BW limit (bps)",$interface['bwlimit'],"bwlimit",array('width'=>11));
114 $details->th_td("Hostname",$interface['hostname'],"hostname");
115 # should the user be allowed to change this ?
116 $mac=$interface['mac'];
117 if ($mac) $details->th_td("MAC address",$mac);
120 $update_button = $form->submit_html ("update-interface","Update",
121 array('onSubmit'=>'interfaceSubmit()'));
122 $add_button = $form->submit_html ("add-interface","Add as new",
123 array('onSubmit'=>'interfaceSubmit()'));
126 $details->tr($add_button,"right");
129 $details->tr($update_button . " " . $add_button,"right");
136 // no tags if the interface has not been created yet
137 if ($mode == 'add') return;
140 //////////////////////////////////////// tags
141 $form = new PlcForm (l_actions(),array('interface_id'=>$interface_id));
144 $tags=$api->GetInterfaceTags (array('interface_id'=>$interface_id));
145 function get_tagname ($tag) { return $tag['tagname'];}
146 $tagnames = array_map ("get_tagname",$tags);
149 $headers=array("Name"=>"string",
152 if ($can_update) $headers[plc_delete_icon()]="none";
154 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
155 $table=new PlcTable("interface_tags",$headers,0,$table_options);
157 if ($tags) foreach ($tags as $tag) {
159 $table->cell(l_tag_obj($tag));
160 $table->cell($tag['value']);
161 // the remove checkbox
162 if ($can_update) $table->cell ($form->checkbox_html('interface_tag_ids[]',$tag['interface_tag_id']));
167 $table->tfoot_start();
171 $table->cell($form->submit_html("delete-interface-tags","Remove Tags"),
172 // use the whole columns and right adjust
173 $table->columns(), "right");
178 // get list of tag names in the interface/* category
179 $all_tags= $api->GetTagTypes( array ("category"=>"interface*"), array("tagname","tag_type_id"));
180 // xxx cannot use onchange=submit() - would need to somehow pass action name
181 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
182 $selector=array_map("tag_selector",$all_tags);
183 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
184 $table->cell($form->text_html("value","",array('width'=>8)));
185 $table->cell($form->submit_html("set-tag-on-interface","Set Tag"),2,"left");
192 plc_tabs ($tabs,"bottom");
195 include 'plc_footer.php';