X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fincludes%2Fplc_functions.php;h=d40de74ab558556ecb4fd7c94aa3aedc3f2eb152;hb=9d5da0d9968a075070eb8c5b75d8267d082bec31;hp=aa6cbd5566c5db2468200fe2283c1c59ecb41ff8;hpb=e2ada0ca96feb499ff7868f84e51d31ca9b218c3;p=plewww.git diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index aa6cbd5..d40de74 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -1,9 +1,14 @@ 'Site nodes', 'url'=>l 'bubble'=>'Display nodes on that site'); } function tab_nodes_slice($slice_id){ return array ('label'=>'Slice nodes', 'url'=>l_nodes_slice($slice_id), 'bubble'=>'Display nodes for that slice'); } -function tab_nodes_mysite () { return array ('label'=>'My nodes', 'url'=>l_nodes_site(plc_my_site_id()), +function tab_nodes_mysite () { return array ('label'=>'My site nodes', 'url'=>l_nodes_my_site(), 'bubble'=>'Display nodes on my site'); } +function tab_nodes_all_mysite (){ return array ('label'=>'All My site nodes', 'url'=>l_nodes_all_my_site(), + 'bubble'=>'Display nodes on all my sites'); } function tab_node($node) { return array ('label'=>'Node '.$node['hostname'], 'url'=>l_node($node['node_id']), 'bubble'=>'Details for ' . $node['hostname']); } ////////// @@ -170,20 +191,20 @@ function tab_sites_local () { return array ('label'=>'Local sites' , 'url'=>l_si ////////// function tab_slices() { return array ('label'=>'All slices', 'url'=>l_slices(), 'bubble' => 'Display all slices'); } -function tab_slices_mysite () { return array ('label'=>'My site slices', 'url'=>l_slices_site(plc_my_site_id()), - 'bubble'=>'Display all slices on my site'); } -function tab_slices_mine () { return array ('label'=>'My site slices', 'url'=>l_slices_site(plc_my_site_id()), +function tab_slices_person() { return array ('label'=>'My slices', 'url'=>l_slices_person(plc_my_person_id()), + 'bubble' => 'Display my all slices'); } +function tab_slices_mysite () { return array ('label'=>'My site slices', 'url'=>l_slices_my_site(), 'bubble'=>'Display all slices on my site'); } function tab_slices_local () { return array ('label'=>'Local slices', 'url'=>l_slices_local(), 'bubble'=>'Display all slices local to this peer'); } function tab_slice($slice) { return array ('label'=>'Slice '.$slice['name'], 'url'=>l_slice($slice['slice_id']), 'bubble' => 'Details for ' . $slice['name']); } ////////// -function tab_persons() { return array ('label'=>'All accounts', 'url'=>l_persons(), +function tab_persons() { return array ('label'=>'All Accounts', 'url'=>l_persons(), 'bubble'=>'Display users from all peers'); } -function tab_persons_local() { return array ('label'=>'Local accounts', 'url'=>l_persons_peer('local'), +function tab_persons_local() { return array ('label'=>'Local Accounts', 'url'=>l_persons_peer('local'), 'bubble'=>'Display all users local to this peer'); } -function tab_persons_mysite() { return array ('label'=>'My accounts' , 'url'=>l_persons_site(plc_my_site_id()), +function tab_persons_mysite() { return array ('label'=>'My site accounts' , 'url'=>l_persons_site(plc_my_site_id()), 'bubble'=>'Display accounts on site ' . plc_my_site_id()); } function tab_person($person) { return array ('label'=>'Account '.$person['email'], 'url'=>l_person($person['person_id']), 'bubble'=>'Details for ' . $person['email']); } @@ -197,7 +218,7 @@ function tab_nodegroups() { return array ('label'=>'Nodegroups', 'url'=>l_nodegr function tablook_event() { return array('image'=>'/planetlab/icons/event.png','height'=>18);} function tablook_comon() { return array('image'=>'/planetlab/icons/comon.png','height'=>18);} -//////////////////// + //////////////////////////////////////////////////////////// validation functions function topdomain ($hostname) { @@ -205,24 +226,27 @@ function topdomain ($hostname) { return $exploded[0]; } -function is_valid_email_addr ($email) { - if (ereg("^.+@.+\\..+$", $email) ) { - return true; - } else { - return false; - } -} - -function is_valid_url ($url) { - if (ereg("^(http|https)://.+\..+$", strtolower($url) ) ) { - return true; - } else { - return false; - } -} +//// with php-5.3 on f12, ereg is marked deprecated, using PCRE instead +//// looks unused +// function is_valid_email_addr ($email) { +// if (preg_match("/^.+@.+\\..+$/", $email) ) { +// return true; +// } else { +// return false; +// } +//} +// +//// looks unused +//function is_valid_url ($url) { +// if (preg_match("/^(http|https):\/\/.+\..+$/", strtolower($url) ) ) { +// return true; +// } else { +// return false; +// } +//} function is_valid_ip ($ip) { - if (ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $ip ) ) { + if (preg_match("/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/", $ip ) ) { // it's at least in the right format, now check to see if // each part is equal to less than 255 $parts= explode( '.', $ip ); @@ -290,6 +314,19 @@ function plc_role_global_hash ($api) { return $hash; } +// because GetRoles does not correctly support filters, it's really painful to do this +function sort_roles ($r1, $r2) { return $r2['role_id'] - $r1['role_id']; } +function roles_except ($roles, $exception_ids) { + $result=array(); + if ($roles) foreach ($roles as $role) { + if ( ! in_array ($role['role_id'],$exception_ids) ) { + $result[]=$role; + } + } + usort($result,sort_roles); + return $result; +} + //////////////////////////////////////////////////////////// nodegroups // hash by 'tagname=value' function plc_nodegroup_global_hash ($api,$tagnames=NULL) { @@ -337,12 +374,42 @@ function plc_itemize ($messages, $class="") { return $formatted; } -////////// +////////// just return a truncated text +function truncate ($text,$numb,$etc = "...") { + if (strlen($text) <= $numb) return $text; + return substr($text, 0, $numb).$etc; +} +// ditto but in case the text is too lare, returns a with its 'title' set to the full value +function truncate_and_popup ($text,$numb,$etc = "...") { + if (strlen($text) <= $numb) return $text; + $display=substr($text, 0, $numb).$etc; + return sprintf("%s",$text,$display); +} + +// generates <(atom) class=(class)> (text) +function html_atom ($atom,$text,$class="") { + $html="<$atom"; + if ($class) $html .= " class='$class'"; + $html .= ">$text"; + return $html; +} +function html_div ($text,$class="") { return html_atom ('div',$text,$class); } +function html_span ($text,$class="") { return html_atom ('span',$text,$class); } + // should use the same channel as the php errors.. -function plc_error_html ($text) { return "
" . $text . "
"; } +function plc_error_html ($text) { return html_div ($text,'plc-error'); } function plc_error ($text) { print plc_error_html ("Error " . $text); } -function plc_errors ($errors) { +function errors_init() { return array();} +function errors_record ($adm, $errors) { + if ($adm->error()) { + $tmp=$adm->error(); + $errors []= $tmp; + } + return $errors; +} + +function errors_display ($errors) { if ($errors) { print( "
" ); print( "

The following errors occured:

" ); @@ -353,30 +420,50 @@ function plc_errors ($errors) { } } -function plc_warning_html ($text) { return "" . $text . "";} +function plc_warning_html ($text) { return html_span($text,'plc-warning'); } function plc_warning ($text) { print plc_warning_html("Warning " . $text); } -function bold_html ($text) { return "$text"; } +function bold_html ($text) { return html_span($text,'bold'); } // shows a php variable verbatim with a heading message function plc_debug ($message,$object) { - print "
" . $message . "
";
+  print "
" . $message . "
";
   print_r ($object);
   print "
"; } -function truncate ($text,$numb,$etc = "...") { - if (strlen($text) > $numb) { - $text = substr($text, 0, $numb); - $text = $text.$etc; - } - return $text; +function plc_debug_txt ($message,$txt) { + print "
" . $message . "
";
+  $txt=str_replace(" ","<SPC>",$txt);
+  $txt=str_replace("\t","<TAB>",$txt);
+  $txt=str_replace("\n","<LF>",$txt);
+  $txt=str_replace("\r","<CR>",$txt);
+  print $txt . "<EOF>";
+  print "
"; } -function html_div ($text,$class="") { - $html=" "Regular/Shared", + "reservable" => "Reservable (requires to get leases)"); +function node_type_display ($api, $node_type) { + global $builtin_node_types; + $val=$builtin_node_types[$node_type]; + if ( ! $val) $val="??undefined??"; + return $val; +} + +function node_type_selectors ($api,$node_type) { + global $builtin_node_types; + foreach ($builtin_node_types as $value=>$display) { + $selector=array('display'=>$display, 'value'=>$value); + if ($value == $node_type) $selector['selected']=true; + $selectors []= $selector; + } + return $selectors; +} + //////////////////// the options for an interface - suitable for plekit/form //>>> GetNetworkMethods() //[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown'] @@ -446,6 +554,14 @@ function interface_method_selectors ($api, $method, $primary) { return $selectors; } +// displays bandwidth with kbps Mbps Gbps as needed +function pretty_bandwidth ($bw) { + if ($bw < 1000) return $bw; + if ($bw < 1000000) return strval($bw/1000) . " kbps"; + if ($bw < 1000000000) return strval($bw/1000000) . " Mbps"; + else return strval($bw/1000000000) . " Gbps"; +} + //////////////////// function instantiation_label ($slice) { $instantiation_labels = array ('not-instantiated'=>'NOT', @@ -478,4 +594,10 @@ function count_english_warning ($objs, $name) { if (count ($objs) == 0) $x=plc_warning_html($x . ' !!'); return $x; } + +//////////////////// outlining reservable nodes +function reservable_mark () { return "-R-";} +function reservable_legend () { return "reservable nodes are marked with " . reservable_mark (); } + + ?>