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';
16 require_once 'plc_drupal.php';
17 include 'plc_header.php';
19 // purpose : display, update or add an interface
22 // updating : _GET['id'] :
23 // if id is set: display the interface, allows to update/add a new if the user has privileges
24 // adding: _GET['node_id']:
25 // otherwise, node_id is needed and the form only allows to add
27 if ( isset ($_GET['id'])) {
29 $interface_id=intval($_GET['id']);
30 $interfaces=$api->GetInterfaces(array('interface_id'=>$interface_id));
31 $interface=$interfaces[0];
32 $node_id=$interface['node_id'];
33 } else if (isset ($_GET['node_id'])) {
36 $node_id=$_GET['node_id'];
40 drupal_set_error('Malformed URL in interface.php, need id or node_id');
41 plc_redirect(l_nodes());
46 $tabs['Back to node']=array('url'=>l_node($node_id),
47 'bubble'=>'Cancel pending changes');
50 $fields=array( 'method', 'type', 'ip', 'gateway', 'network', 'broadcast', 'netmask',
51 'dns1', 'dns2', 'hostname', 'mac', 'bwlimit', 'node_id' );
53 //////////////////////////////
54 $nodes= $api->GetNodes( array( intval($node_id) ), array( 'node_id', 'hostname', 'site_id' ) );
56 $site_id=$node['site_id'];
58 $can_update= plc_is_admin() || ( plc_in_site ($site_id) && ( plc_is_pi() || plc_is_tech()));
60 drupal_set_title("Interface on " . $node['hostname']);
62 // include javacsript helpers
64 <script type="text/javascript" src="/planetlab/prototype/prototype.js"></script>
65 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
68 $details=new PlcDetails($can_update);
70 // hardwire network type
71 $form=$details->form_start(l_actions(),array('node_id'=>$node_id,'type'=>"ipv4"));
75 //>>> GetNetworkMethods()
76 //[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown']
77 function method_selectors ($api, $method) {
78 $builtin_methods=array("static"=>"Static", "dhcp"=>"DHCP", "proxy"=>"Proxy",
79 "tap"=>"TUN/TAP", "ipmi"=>"IPMI");
81 foreach ($builtin_methods as $value=>$display) {
82 $selector=array('display'=>$display, 'value'=>$value);
83 if ($value == $method) $selector['selected']=true;
84 $selectors []= $selector;
88 $method_select = $form->select_html ("method",method_selectors($api,$interface['method']),
89 array('id'=>'method','onChange'=>'updateMethodFields()'));
90 $details->th_td("Method",$method_select,"method",array('input_type'=>'select'));
92 // dont display the 'type' selector as it contains only ipv4
93 //>>> GetNetworkTypes()
96 $ip_options=array('width'=>15);
97 $ip_options_plus=array_merge($ip_options,array('onKeyup'=>'networkHelper()',
98 'onChange'=>'networkHelper()',
100 $ip_options_tmp=array_merge($ip_options,array('onKeyup'=>'subnetChecker("dns1")'));
102 $details->th_td("IP",$interface['ip'],"ip",$ip_options_plus);
103 $details->th_td("Netmask",$interface['netmask'],"netmask",$ip_options_plus);
104 $details->th_td("Network",$interface['network'],"network",$ip_options);
105 $details->th_td("Broadcast",$interface['broadcast'],"broadcast",$ip_options);
106 $details->th_td("Gateway",$interface['gateway'],"gateway",$ip_options);
107 $details->th_td("DNS 1",$interface['dns1'],"dns1",$ip_options_tmp);
108 $details->th_td("DNS 2",$interface['dns2'],"dns2",$ip_options);
110 $details->th_td("BW limit (bps)",$interface['bwlimit'],"bwlimit",array('width'=>11));
111 $details->th_td("Hostname",$interface['hostname'],"hostname");
112 # should the user be allowed to change this ?
113 $mac=$interface['mac'];
114 if ($mac) $details->th_td("MAC address",$mac);
117 $update_button = $form->submit_html ("update-interface","Update");
118 $add_button = $form->submit_html ("add-interface","Add as new");
119 $dbg="<input type=button onclick='formSubmit()' value='dbg'>";
122 $details->tr($add_button,"right");
125 $details->tr($update_button . $add_button . $dbg,"right");
132 // no tags if the interface has not been created yet
133 if ($mode == 'add') return;
136 //////////////////////////////////////// tags
137 $form = new PlcForm (l_actions(),array('interface_id'=>$interface_id));
140 $tags=$api->GetInterfaceTags (array('interface_id'=>$interface_id));
141 function get_tagname ($tag) { return $tag['tagname'];}
142 $tagnames = array_map ("get_tagname",$tags);
145 $headers=array("Name"=>"string",
148 if ($can_update) $headers[plc_delete_icon()]="none";
150 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
151 $table=new PlcTable("interface_tags",$headers,0,$table_options);
153 if ($tags) foreach ($tags as $tag) {
155 $table->cell(l_tag_obj($tag));
156 $table->cell($tag['value']);
157 // the remove checkbox
158 if ($can_update) $table->cell ($form->checkbox_html('interface_tag_ids[]',$tag['interface_tag_id']));
163 $table->tfoot_start();
167 $table->cell($form->submit_html("delete-interface-tags","Remove Tags"),
168 // use the whole columns and right adjust
169 $table->columns(), "right");
174 // get list of tag names in the interface/* category
175 $all_tags= $api->GetTagTypes( array ("category"=>"interface*"), array("tagname","tag_type_id"));
176 // xxx cannot use onchange=submit() - would need to somehow pass action name
177 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
178 $selector=array_map("tag_selector",$all_tags);
179 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
180 $table->cell($form->text_html("value","",array('width'=>8)));
181 $table->cell($form->submit_html("set-tag-on-interface","Set Tag"),2,"left");
189 include 'plc_footer.php';