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 'linetabs.php';
13 require_once 'details.php';
14 require_once 'table.php';
15 require_once 'toggle.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 $title=('Updating interface ' . $interface['ip']);
35 } else if (isset ($_GET['node_id'])) {
38 $node_id=$_GET['node_id'];
39 $title=('Adding interface');
43 drupal_set_error('Malformed URL in interface.php, need id or node_id');
44 plc_redirect(l_nodes());
49 $tabs[] = array('label'=>'Back to node', 'url'=>l_node($node_id),
50 'bubble'=>'Cancel pending changes');
51 plekit_linetabs($tabs);
53 $fields=array( 'method', 'type', 'ip', 'gateway', 'network', 'broadcast', 'netmask',
54 'dns1', 'dns2', 'hostname', 'mac', 'bwlimit', 'node_id' );
56 //////////////////////////////
57 $nodes= $api->GetNodes( array( intval($node_id) ), array( 'node_id', 'hostname', 'site_id' ) );
59 $site_id=$node['site_id'];
61 $can_update= plc_is_admin() || ( plc_in_site ($site_id) && ( plc_is_pi() || plc_is_tech()));
63 drupal_set_title($title . " on " . $node['hostname']);
65 // include javacsript helpers
66 require_once 'prototype.php';
67 drupal_set_html_head ('
68 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
71 $details=new PlekitDetails($can_update);
73 // xxx hardwire network type for now
74 $form_variables = array('node_id'=>$node_id,'type'=>"ipv4");
75 if ($mode == "update") $form_variables['interface_id']=$interface_id;
76 $form=$details->form_start(l_actions(),$form_variables);
80 $method_select = $form->select_html ("method",
81 interface_method_selectors($api,$interface['method'],false),
82 array('id'=>'method','onChange'=>'updateMethodFields()'));
83 $details->th_td("Method",$method_select,"method",array('input_type'=>'select','value'=>$interface['method']));
85 // dont display the 'type' selector as it contains only ipv4
86 //>>> GetNetworkTypes()
89 $details->th_td("IP",$interface['ip'],"ip",array('width'=>15,
90 'onKeyup'=>'networkHelper()',
91 'onChange'=>'networkHelper()'));
92 $details->th_td("Netmask",$interface['netmask'],"netmask",array('width'=>15,
93 'onKeyup'=>'networkHelper()',
94 'onChange'=>'networkHelper()'));
95 $details->th_td("Network",$interface['network'],"network",array('width'=>15));
96 $details->th_td("Broadcast",$interface['broadcast'],"broadcast",array('width'=>15));
97 $details->th_td("Gateway",$interface['gateway'],"gateway",array('width'=>15,
98 'onChange'=>'subnetChecker("gateway",false)'));
99 $details->th_td("DNS 1",$interface['dns1'],"dns1",array('width'=>15,
100 'onChange'=>'subnetChecker("dns1",false)'));
101 $details->th_td("DNS 2",$interface['dns2'],"dns2",array('width'=>15,
102 'onChange'=>'subnetChecker("dns2",true)'));
104 $details->th_td("BW limit (bps)",$interface['bwlimit'],"bwlimit",array('width'=>11));
105 $details->th_td("Hostname",$interface['hostname'],"hostname");
106 # xxx should the user be allowed to change this ?
107 $mac=$interface['mac'];
108 if ($mac) $details->th_td("MAC address",$mac);
111 $update_button = $form->submit_html ("update-interface","Update",
112 array('onSubmit'=>'interfaceSubmit()'));
113 $add_button = $form->submit_html ("add-interface","Add as new",
114 array('onSubmit'=>'interfaceSubmit()'));
117 $details->tr($add_button,"right");
120 $details->tr($update_button . " " . $add_button,"right");
127 // no tags if the interface has not been created yet
128 if ($mode == 'add') return;
131 //////////////////////////////////////// tags
132 $toggle=new PlekitToggle ('tags','Tags');
135 $form = new PlekitForm (l_actions(),array('interface_id'=>$interface_id));
138 $tags=$api->GetInterfaceTags (array('interface_id'=>$interface_id));
139 function get_tagname ($tag) { return $tag['tagname'];}
140 $tagnames = array_map ("get_tagname",$tags);
143 $headers=array("Name"=>"string",
146 if ($can_update) $headers[plc_delete_icon()]="none";
148 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
149 $table=new PlekitTable("interface_tags",$headers,0,$table_options);
151 if ($tags) foreach ($tags as $tag) {
153 $table->cell(l_tag_obj($tag));
154 $table->cell($tag['value']);
155 // the remove checkbox
156 if ($can_update) $table->cell ($form->checkbox_html('interface_tag_ids[]',$tag['interface_tag_id']));
161 $table->tfoot_start();
165 $table->cell($form->submit_html("delete-interface-tags","Remove Tags"),
166 // use the whole columns and right adjust
167 $table->columns(), "right");
172 // get list of tag names in the interface/* category
173 $all_tags= $api->GetTagTypes( array ("category"=>"interface*"), array("tagname","tag_type_id"));
174 // xxx cannot use onchange=submit() - would need to somehow pass action name
175 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
176 $selector=array_map("tag_selector",$all_tags);
177 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
178 $table->cell($form->text_html("value","",array('width'=>8)));
179 $table->cell($form->submit_html("set-tag-on-interface","Set Tag"),2,"left");
187 //plekit_linetabs ($tabs,"bottom");
190 include 'plc_footer.php';