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 'linetabs.php';
15 require_once 'details.php';
16 require_once 'table.php';
17 require_once 'toggle.php';
19 require_once 'plc_drupal.php';
20 include 'plc_header.php';
22 // purpose : display, update or add an interface
25 // updating : _GET['id'] :
26 // if id is set: display the interface, allows to update/add a new if the user has privileges
27 // adding: _GET['node_id']:
28 // otherwise, node_id is needed and the form only allows to add
30 if ( isset ($_GET['id'])) {
32 $interface_id=intval($_GET['id']);
33 $interfaces=$api->GetInterfaces(array('interface_id'=>$interface_id));
34 $interface=$interfaces[0];
35 $node_id=$interface['node_id'];
36 $title=('Updating interface ' . $interface['ip']);
37 } else if (isset ($_GET['node_id'])) {
40 $node_id=$_GET['node_id'];
41 $title=('Adding interface');
45 drupal_set_error('Malformed URL in interface.php, need id or node_id');
46 plc_redirect(l_nodes());
51 $tabs[] = array('label'=>'Back to node', 'url'=>l_node($node_id),
52 'bubble'=>'Cancel pending changes');
53 plekit_linetabs($tabs);
55 $fields=array( 'method', 'type', 'ip', 'gateway', 'network', 'broadcast', 'netmask',
56 'dns1', 'dns2', 'hostname', 'mac', 'bwlimit', 'node_id' );
58 //////////////////////////////
59 $nodes= $api->GetNodes( array( intval($node_id) ), array( 'node_id', 'hostname', 'site_id' ) );
61 $site_id=$node['site_id'];
63 $can_update= plc_is_admin() || ( plc_in_site ($site_id) && ( plc_is_pi() || plc_is_tech()));
65 drupal_set_title($title . " on " . $node['hostname']);
67 // include javacsript helpers
68 require_once 'prototype.php';
69 drupal_set_html_head ('
70 <script type="text/javascript" src="/planetlab/nodes/interface.js"></script>
73 $details=new PlekitDetails($can_update);
75 // xxx hardwire network type for now
76 $form_variables = array('node_id'=>$node_id,'type'=>"ipv4");
77 if ($mode == "update") $form_variables['interface_id']=$interface_id;
78 $form=$details->form_start(l_actions(),$form_variables);
82 $method_select = $form->select_html ("method",
83 interface_method_selectors($api,$interface['method'],false),
84 array('id'=>'method','onChange'=>'updateMethodFields()'));
85 $details->th_td("Method",$method_select,"method",array('input_type'=>'select','value'=>$interface['method']));
87 // dont display the 'type' selector as it contains only ipv4
88 //>>> GetNetworkTypes()
91 $details->th_td("IP",$interface['ip'],"ip",array('width'=>15,
92 'onKeyup'=>'networkHelper()',
93 'onChange'=>'networkHelper()'));
94 $details->th_td("Netmask",$interface['netmask'],"netmask",array('width'=>15,
95 'onKeyup'=>'networkHelper()',
96 'onChange'=>'networkHelper()'));
97 $details->th_td("Network",$interface['network'],"network",array('width'=>15));
98 $details->th_td("Broadcast",$interface['broadcast'],"broadcast",array('width'=>15));
99 $details->th_td("Gateway",$interface['gateway'],"gateway",array('width'=>15,
100 'onChange'=>'subnetChecker("gateway",false)'));
101 $details->th_td("DNS 1",$interface['dns1'],"dns1",array('width'=>15,
102 'onChange'=>'subnetChecker("dns1",false)'));
103 $details->th_td("DNS 2",$interface['dns2'],"dns2",array('width'=>15,
104 'onChange'=>'subnetChecker("dns2",true)'));
106 $details->th_td("BW limit (bps)",$interface['bwlimit'],"bwlimit",array('width'=>11));
107 $details->th_td("Hostname",$interface['hostname'],"hostname");
108 # xxx should the user be allowed to change this ?
109 $mac=$interface['mac'];
110 if ($mac) $details->th_td("MAC address",$mac);
113 $update_button = $form->submit_html ("update-interface","Update",
114 array('onSubmit'=>'interfaceSubmit()'));
115 $add_button = $form->submit_html ("add-interface","Add as new",
116 array('onSubmit'=>'interfaceSubmit()'));
119 $details->tr($add_button,"right");
122 $details->tr($update_button . " " . $add_button,"right");
129 // no tags if the interface has not been created yet
130 if ($mode == 'add') return;
133 //////////////////////////////////////// tags
134 $toggle=new PlekitToggle ('tags','Tags',
135 array('visible'=>get_arg('show_tags',false)));
138 $form = new PlekitForm (l_actions(),array('interface_id'=>$interface_id));
141 $tags=$api->GetInterfaceTags (array('interface_id'=>$interface_id));
142 function get_tagname ($tag) { return $tag['tagname'];}
143 $tagnames = array_map ("get_tagname",$tags);
146 $headers=array("Name"=>"string",
149 if ($can_update) $headers[plc_delete_icon()]="none";
151 $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
152 $table=new PlekitTable("interface_tags",$headers,0,$table_options);
154 if ($tags) foreach ($tags as $tag) {
156 $table->cell(l_tag_obj($tag));
157 $table->cell($tag['value']);
158 // the remove checkbox
159 if ($can_update) $table->cell ($form->checkbox_html('interface_tag_ids[]',$tag['interface_tag_id']));
164 $table->tfoot_start();
168 $table->cell($form->submit_html("delete-interface-tags","Remove Tags"),
169 // use the whole columns and right adjust
170 array('hfill'=>true,'align'=>'right'));
175 // get list of tag names in the interface/* category
176 $all_tags= $api->GetTagTypes( array ("category"=>"interface*"), array("tagname","tag_type_id"));
177 // xxx cannot use onchange=submit() - would need to somehow pass action name
178 function tag_selector ($tag) { return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']); }
179 $selector=array_map("tag_selector",$all_tags);
180 $table->cell($form->select_html("tag_type_id",$selector,array('label'=>"Choose")));
181 $table->cell($form->text_html("value","",array('width'=>8)));
183 $table->cell($form->submit_html("set-tag-on-interface","Set Tag"),2,"left");
191 //plekit_linetabs ($tabs,"bottom");
194 include 'plc_footer.php';