From d2ec087a2d0f476919f3413585efee6d21d68a7c Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Sun, 15 Mar 2009 16:45:26 +0000 Subject: [PATCH] admin db search rewritten + removed some obsolete action files --- planetlab/common/adminsearch.php | 747 ++++++++++------------------- planetlab/css/plc_style.css | 21 +- planetlab/includes/plc_session.php | 6 +- planetlab/nodes/setting_action.php | 118 ----- planetlab/nodes/sliver_action.php | 61 --- planetlab/slices/delete_slice.php | 60 --- planetlab/slices/slice.php | 12 +- planetlab/slices/slice_action.php | 60 --- planetlab/slices/slice_nodes.php | 264 ---------- planetlab/slices/slice_users.php | 207 -------- planetlab/slices/update_slice.php | 109 ----- plekit/php/toggle.php | 4 +- 12 files changed, 282 insertions(+), 1387 deletions(-) delete mode 100644 planetlab/nodes/setting_action.php delete mode 100644 planetlab/nodes/sliver_action.php delete mode 100644 planetlab/slices/delete_slice.php delete mode 100644 planetlab/slices/slice_action.php delete mode 100644 planetlab/slices/slice_nodes.php delete mode 100644 planetlab/slices/slice_users.php delete mode 100644 planetlab/slices/update_slice.php diff --git a/planetlab/common/adminsearch.php b/planetlab/common/adminsearch.php index 45a1c61..6ac2a02 100644 --- a/planetlab/common/adminsearch.php +++ b/planetlab/common/adminsearch.php @@ -1,6 +1,8 @@ = 2 ) { - return true; +$pattern=""; +if (isset($_GET['pattern'])) { $pattern=$_GET['pattern']; } +if (isset($_POST['pattern'])) { $pattern=$_POST['pattern']; } +$tokens=split(" ",$pattern); + +//////////////////// +// from a single search form, extract all tokens entered +// and then show all entities that match one of that tokens among +// nodes - persons - sites - slices +//////////////////// +function display_form ($pattern) { + if ($pattern) { + $title="Searching for $pattern"; + $visible=false; } else { - return false; + $title="Search for what"; + $visible=true; } + $toggle=new PlekitToggle("admin-search",$title,array('start-visible'=>$visible)); + $toggle->start(); + print <<< EOF +

This form searches for any entry in the database matching a name fragment, or token. Specifically it searches for persons, slices, nodes or slices. You can specify a space-separated list of tokens, entries matching any token would then get listed. +

+EOF; + print "
"; + $form=new PlekitForm ('/db/common/adminsearch.php',array()); + $form->start(); + print $form->label_html('pattern',"Enter space-separated tokens"); + print $form->text_html('pattern',$pattern); + print $form->submit_html('submit','Submit'); + $form->end(); + print "
\n"; + $toggle->end(); } -function get_and_print_site($site_array) { +// just look for *token* +function token_pattern ($token) { + return "*" . $token . "*"; +} + +// $type is e.g. 'Persons' -- $field is e.g. 'email' +function generic_search ($type,$field,$tokens) { global $api; - $sites = $api->GetSites( $site_array, array( "name", "site_id", - "url", "enabled", "node_ids", "person_ids", "date_created", - "slice_ids", "max_slivers", "max_slices", "login_base" ) ); - if ( count($sites) > 0 ) { - foreach( $sites as $site) { - $name = $site['name']; - $site_id = $site['site_id']; - $url = $site['url']; - $enabled = $site['enabled']; - $node_ids = $site['node_ids']; - $slice_ids_count = count($site['slice_ids']); - $person_ids = $site['person_ids']; - $date_created = date("M j G:i Y", $site['date_created']); - $max_slivers = $site['max_slivers']; - $max_slices = $site['max_slices']; - $login_base = $site['login_base']; - - echo "\n"; - - echo "$name\n"; - echo "(home)\n"; - echo "[ $slice_ids_count of $max_slices ]\n"; - - echo ""; - if (!$enabled) echo "Not Enabled
\n"; - //else echo "$date_created\n"; - echo "$date_created\n"; - - echo "Nodes: "; - foreach ($site['node_ids'] as $node_id) - { - echo " $node_id, "; - } - - echo "\n"; - } + $results=array(); + $methodname='Get'.$type; + if ( ! method_exists($api,$methodname)) { + plc_error("generic_search failed with methodname=$methodname"); + return $results; } + foreach ($tokens as $token) { + $filter=array($field=>token_pattern($token)); + $results = + array_merge ($results,$api->$methodname($filter)); + } + return $results; } -function get_and_print_hostname($host_array) { - global $api; - $nodes = $api->GetNodes( $host_array, array( "hostname", "node_id", - "site_id", "date_created", "last_contact", "boot_state" ) ); - if ( count ($nodes) > 0 ) { - foreach($nodes as $node) { - $hostname= $node['hostname']; - $node_id = $node['node_id']; - $boot_state= $node['boot_state']; - $last_contact = $node['last_contact']; - $date_created = date("M j G:i Y", $node['date_created']); - echo ""; - echo "$node_id "; - echo "$hostname"; - echo "$boot_state"; - if( $last_contact != NULL ) { - $last_contact_str = timeDiff($last_contact); +// $objects is e.g. a collection of persons +// then, e.g. on slice, $key='site_id' & $plural=false +// or, e.g. on person, $key='site_ids' & $plural=true +function generic_gather_related ($objects, $key, $plural) { + if ( empty ($objects)) + return array(); + // else, look for either 'site_id' or 'site_ids' in the first object + $sample=$objects[0]; + if ( array_key_exists($key,$sample)) { + $result=array(); + foreach ($objects as $object) { + if ($plural) { + $result = array_merge ($result, $object[$key]); } else { - $last_contact_str = "Never"; + $result []= $object[$key]; } - echo "$last_contact_str\n"; - echo "$date_created\n"; - echo "\n"; } + return $result; + } else { + plc_debug("gather_related failed with $key",$sample); + return array(); } - - return $nodes; } -function get_and_print_user ($user_array) { - global $api; - $persons= $api->GetPersons( $user_array, array( "person_id", "first_name", - "last_name", "email", "roles", "enabled", "date_created", - "site_ids" ) ); - - if ( count($persons) > 0 ) { - foreach($persons as $person) { - $first= $person['first_name']; - $last = $person['last_name']; - $person_id= $person['person_id']; - $email= $person['email']; - $enabled= $person['enabled']; - $roles = $person['roles']; - $role = $person['roles'][0]; - $date_created = date("M j G:i Y", $person['date_created']); - $site_ids= $person['site_ids']; - - echo "\n"; - - echo ""; - echo "$first $last"; - echo "($person_id) "; - echo "$email "; - - echo ""; - if (!$enabled) echo "Not Enabled
\n"; - //else echo "$date_created\n"; - echo "$date_created\n"; - //if (!$enabled) echo " Not Enabled "; - //else echo "$date"; - - echo " roles: "; - foreach ($person['roles'] as $role) { echo " $role, "; } - - echo "\n"; +////////// +// create link from an id, using the various global hashes +function plc_person_link ($person_id) {global $persons_hash; return l_person_obj($persons_hash[$person_id]);} +function plc_slice_link ($slice_id) {global $slices_hash; return l_slice_obj($slices_hash[$slice_id]);} +function plc_site_link ($site_id) {global $sites_hash; return l_site_obj($sites_hash[$site_id]);} +function plc_node_link ($node_id) {global $nodes_hash; return l_node_obj($nodes_hash[$node_id]);} + +function display_persons ($persons) { + if ( ! $persons) return; + + $toggle=new PlekitToggle('persons-area',"Persons"); + $toggle->start(); + + $headers=array('id'=>'int', + 'email'=>'string', + 'sites'=>'string', + 'slices'=>'string', + 'roles'=>'string'); + $table=new PlekitTable('persons',$headers,1); + $table->start(); + foreach ($persons as $person) { + $table->row_start(); + $table->cell($person['person_id']); + $table->cell(l_person_obj($person)); + $table->cell(plc_vertical_table(array_map("plc_site_link",$person['site_ids']))); + $table->cell(plc_vertical_table(array_map("plc_slice_link",$person['slice_ids']))); + $table->cell(plc_vertical_table($person['roles'])); + $table->row_end(); + } + $table->end(); + $toggle->end(); +} - } - +function display_slices ($slices) { + if ( ! $slices) return; + + $toggle=new PlekitToggle('slices-area',"Slices"); + $toggle->start(); + + $headers=array('id'=>'int', + 'name'=>'string', + 'site'=>'string', + 'persons'=>'string', + 'N'=>'string'); + $table=new PlekitTable('slices',$headers,1); + $table->start(); + foreach ($slices as $slice) { + $table->row_start(); + $table->cell($slice['slice_id']); + $table->cell(l_slice_obj($slice)); + global $sites_hash; + $site=$sites_hash[$slice['site_id']]; + $table->cell(l_site_obj($site)); + $table->cell(plc_vertical_table(array_map("plc_person_link",$slice['person_ids']))); + // this makes really long tables, use the slice link to see details + //$table->cell(plc_vertical_table(array_map("plc_node_link",$slice['node_ids']))); + $table->cell(count($slice['node_ids'])); + $table->row_end(); } - return $persons; + $table->end(); + $toggle->end(); } -// find person roles -$_person= $plc->person; -$_roles= $_person['role_ids']; - - -/////////////////////////////////////////////////////////////////////// -// Initially, we need a search form, and blank information after that. -// Based on the fields of the search form, we should be able to populate a lot -// of information, related to user, site, keys, -// -// from a simple domain name search, it would display the site, -// nodes -> pcu -// users grouped by role, -// from a user search, it would find, -// user info link, site, roles, etc. -// -// userquery will be one of these types: -// part of a user name, email, user_id -// part of a site name, site alias, site_id -// part of a node name, domain, node_id -// -// we should be able to return results based on these guesses. If they're -// good, we'll get hits, if nothing comes back, we won't display anything. - - -echo "
\n -
\n"; - -if( $_POST['userquery'] or $_GET['userquery']) { - if ( $_POST['userquery'] ) { - $query = $_POST['userquery']; - } else { - $query = $_GET['userquery']; +function display_sites ($sites) { + if ( ! $sites) return; + + $toggle=new PlekitToggle('sites-area',"Sites"); + $toggle->start(); + + $headers=array('id'=>'int', + 'name'=>'string', + 'url'=>'string', + 'persons'=>'string', + 'slices'=>'string', + 'nodes'=>'string'); + $table=new PlekitTable('sites',$headers,1); + $table->start(); + foreach ($sites as $site) { + $table->row_start(); + $table->cell($site['site_id']); + $table->cell(l_site_obj($site)); + $table->cell(href($site['url'],$site['url'])); + $table->cell(plc_vertical_table(array_map("plc_person_link",$site['person_ids']))); + $table->cell(plc_vertical_table(array_map("plc_slice_link",$site['slice_ids']))); + $table->cell(plc_vertical_table(array_map("plc_node_link",$site['node_ids']))); + $table->row_end(); } - } + $table->end(); + $toggle->end(); +} -echo "

(Separate with commas for multiple queries.)\n - \n - \n -

\n -
\n -
\n"; - -// if userquery then search based on string -if( $_POST['userquery'] or $_GET['userquery']) { - if ( $_POST['userquery'] ) { - $query = $_POST['userquery']; - } else { - $query = $_GET['userquery']; +function display_nodes ($nodes) { + if ( ! $nodes) return; + + $toggle=new PlekitToggle('nodes-area',"Nodes"); + $toggle->start(); + + $headers=array('id'=>'int', + 'hostname'=>'string', + 'site'=>'string', + 'slices'=>'string'); + $table=new PlekitTable('nodes',$headers,1); + $table->start(); + foreach ($nodes as $node) { + $table->row_start(); + $table->cell($node['node_id']); + $table->cell(l_node_obj($node)); + global $sites_hash; + $site=$sites_hash[$node['site_id']]; + $table->cell(l_site_obj($site)); + $table->cell(plc_vertical_table(array_map("plc_slice_link",$node['slice_ids']))); + $table->row_end(); } - echo "\n"; - - $f_commas = explode(",", $query); - // PHASE 1: query contains email, user_id, or part of a user name - foreach($f_commas as $tok) { - $tok = trim($tok); // strip white space. - - $e = false; - //find user by email - if ( is_valid_email_addr($tok) ){ - $u = get_and_print_user(array("email"=>$tok)); - $e = true; - if( count( $u ) == 0 ) $none = 1; - } - $n = false; - // find user by user_id - if ( is_numeric($tok) ){ - $u = get_and_print_user(array("person_id"=>intval($tok))); - $n = true; - if( count( $u ) == 0 ) $none = 1; - } - // neither of the above, - if (!$n && !$e) { - // split on spaces, and search each part. - // TODO: search upper and lower-case - $f_spaces = explode(" ", $tok); - foreach($f_spaces as $stok) { - // assume $tok is part of a name - // get_user - $a = get_and_print_user(array("first_name"=>$stok)); - $b = get_and_print_user(array("last_name"=>$stok)); - // c = intersect_users(a, b) - // if c - // print_user(c), - // else - // print_user(a,b) - } - if( count( $a ) == 0 && count( $b ) == 0 ) $none = 1; - } + $table->end(); + $toggle->end(); +} - // PHASE 2: query contains login_base, site_id, or part of a site name - // find site by login_base - $lb = false; - $s = get_and_print_site(array("login_base"=>strtolower($tok))); - if( count( $s ) == 0 ) $none = 1; - else $lb = true; +//////////////////////////////////////////////////////////// +display_form($pattern); - $n = false; - // find site by site_id - if ( is_numeric($tok) ){ - $s = get_and_print_site(array("site_id"=>intval($tok))); - $n = true; - if( count( $s ) == 0 ) $none = 1; - } +if ($pattern) { - if( !$lb && !$n ) { - $f_spaces = explode(" ", $tok); - foreach($f_spaces as $stok) { - $a = get_and_print_site(array("name"=>$stok)); - } - if( count($a) == 0 ) $none = 1; - } + ////////// search database + // search persons on email + $persons = array(); + $persons = array_merge ($persons, generic_search ('Persons','email',$tokens)); - // PHASE 3: query contains part of a node name, domain, node_id + // search slices on name + $slices=array(); + $slices = array_merge ($slices, generic_search ('Slices','name',$tokens)); - //if( $none == 1 ) echo "\n"; - if ( is_possible_domainname($tok) ) { - $n = get_and_print_hostname(array("hostname"=>$tok)); - } + // search sites on name and login_base + $sites=array(); + $sites = array_merge ($sites, generic_search('Sites','name',$tokens)); + $sites = array_merge ($sites, generic_search('Sites','login_base',$tokens)); + + // nodes on hostname + $nodes=array(); + $nodes = array_merge ($nodes, generic_search('Nodes','hostname',$tokens)); + + print "Search results for $pattern \n"; + if ( !$nodes && !$persons && !$slices && !$sites) { + plc_warning ("No result found"); + return; } - echo "
Search Results:
No Results.
\n"; - } -if (false) { - // if a site_id is given, display the site nodes only - if( $_GET['site_id'] ) { - $site_id= $_GET['site_id']; + ////////// collect all related objects + $rel_person_ids = array(); + $rel_person_ids = array_merge($rel_person_ids, generic_gather_related ($sites,'person_ids',true)); + $rel_person_ids = array_merge($rel_person_ids, generic_gather_related ($slices,'person_ids',true)); - // Get site info - $site_info= $api->GetSites( array( intval( $site_id ) ), array( "name", "person_ids" ) ); + $rel_slice_ids = array(); + $rel_slice_ids = array_merge($rel_slice_ids, generic_gather_related ($persons,'slice_ids',true)); + $rel_slice_ids = array_merge($rel_slice_ids, generic_gather_related ($sites,'slice_ids',true)); + $rel_slice_ids = array_merge($rel_slice_ids, generic_gather_related ($nodes,'slice_ids',true)); - // Get site nodes - $persons= $api->GetPersons( $site_info[0]['person_ids'], array( "person_id", "first_name", "last_name", "email", "roles", "peer_id", "enabled" ) ); - - drupal_set_title("People with " . $site_info[0]['name']); + $rel_site_ids = array(); + $rel_site_ids = array_merge ( $rel_site_ids, generic_gather_related ($persons,'site_ids',true)); + $rel_site_ids = array_merge ( $rel_site_ids, generic_gather_related ($slices,'site_id',false)); + $rel_site_ids = array_merge ( $rel_site_ids, generic_gather_related ($nodes,'site_id',false)); - sort_persons( $persons ); + $rel_node_ids = array(); + $rel_node_ids = array_merge($rel_node_ids, generic_gather_related ($sites,'node_ids',true)); + $rel_node_ids = array_merge($rel_node_ids, generic_gather_related ($slices,'node_ids',true)); - echo paginate_trash ( $persons, "person_id", "Persons", 25, "email" ); - } - // if no person id, display list of persons to choose - elseif( !$_GET['id'] ) { - - // GetPersons API call - $persons= $api->GetPersons( NULL, array( "person_id", "first_name", "last_name", "email", "roles" , "peer_id", "enabled" ) ); - - sort_persons( $persons ); - - echo "
\n -
\n"; - if( $pers_email ) echo "'$pers_email' is not a valid person email.\n"; - echo "

\n - \n - \n -

\n -
\n"; - } else { - // get the person_id from the URL - $person_id= intval( $_GET['id'] ); - - // GetPersons API call for this person - $person_info= $api->GetPersons( array( $person_id ) ); - - if( empty( $person_info ) ) { - echo "No such person."; - - } else { - // vars from api - $first_name= $person_info[0]['first_name']; - $last_name= $person_info[0]['last_name']; - $title= $person_info[0]['title']; - $url= $person_info[0]['url']; - $phone= $person_info[0]['phone']; - $email= $person_info[0]['email']; - $enabled= $person_info[0]['enabled']; - $peer_id=$person_info[0]['peer_id']; - - // arrays from api - $role_ids= $person_info[0]['role_ids']; - $roles= $person_info[0]['roles']; - $site_ids= $person_info[0]['site_ids']; - $slice_ids= $person_info[0]['slice_ids']; - $key_ids= $person_info[0]['key_ids']; - - // gets more data from API calls - $site_info= $api->GetSites( $site_ids, array( "site_id", "name" ) ); - $slice_info= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) ); - $key_info= $api->GetKeys( $key_ids ); - - drupal_set_title("$first_name $last_name Account Information"); - - // start form - if ( ! $peer_id ) { - echo "\n"; - } else { - echo "
"; - } - echo "\n"; - - if ( ! $peer_id ) { -# if ( Admin, PI, or user ) allow deletion - if( in_array( 10, $_roles ) || - ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) || - $_person['person_id'] == $person_id) { - - // list to take person action - echo "

\n"; - -# if ( Admin or PI ) check whether to allow # 'enabling/disabling'. - if( in_array( 10, $_roles ) || - ( in_array( 20, $_roles ) && in_array( $site_ids[0], $_person['site_ids'] ) ) ) { - - if( $enabled == true ) { - $actions['disable']= "Disable $first_name"; - } else { - $actions['enable']= "Enable $first_name"; - $select_end = $select_end . "   ". - "<- This user is not enabled. Choose here to enable or delete."; - } - if ( in_array( 10, $_roles )) { - $actions['su'] = "Become $first_name"; - } - } - -# for all cases, list each 'select' key - foreach( $actions as $key => $val ) { - echo "

\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
First Name: $first_name
Last Name: $last_name
Title: $title
Email: $email
Password: ***********
Phone: $phone
URL: $url
\n"; - - if( in_array( 10, $_roles ) || $_person['person_id'] == $person_id ) - echo "
Update account information\n"; - - echo "


\n"; - - // keys - $can_manage_keys = ( ( ! $peer_id ) && (in_array( "10", $_roles ) || $person_id == $_person['person_id'])); - echo "

Keys

\n"; - if( !empty( $key_ids ) ) { - echo "

\n"; - echo "\n"; - - foreach( $key_info as $key ) { - $key_type= $key['key_type']; - $key_id= $key['key_id']; - $key_html= wordwrap( $key['key'], 70, "
\n", 1 ); - echo "\n"; - } - - echo "
TypeKey
$key_type$key_html
\n"; - - - } else { - echo " This user has no known key"; - } - - if( $can_manage_keys ) - echo "

Manage Keys\n"; - echo "


"; - - - // sites - echo "

Sites

\n"; - if( !empty( $site_info ) ) { - echo "\n"; - - foreach( $site_info as $site ) { - $site_name= $site['name']; - $site_id= $site['site_id']; - - echo "\n"; - } - echo "
$site_name ( remove)
\n"; - echo "\n"; - - } else { - echo " This user is not affiliated with a site !!"; - } - - // diplay site select list to add another site for user - if( ! $peer_id && in_array( 10, $_roles ) ) { - // get site info - $full_site_info= $api->GetSites( NULL, array( "site_id", "name" ) ); - - if( $site_info ) - $person_site= arr_diff( $full_site_info, $site_info ); - else - $person_site= $full_site_info; - - sort_sites( $person_site ); - - echo "

Select a site to add this user to: "; - echo ""; - - } - echo "


\n"; - - // roles - echo "

Roles

\n"; - echo "

\n"; - echo ""; - if( in_array( "10", $_roles ) ) - echo ""; - echo "\n"; - - // construct role array - for( $n=0; $n$role_ids[$n], 'name'=>$roles[$n] ); - } - - - if ( !empty ($roles) ) { - foreach( $proles as $role ) { - $role_name= $role['name']; - $role_id= $role['role_id']; - - echo "\n"; - } - } else { - echo " This user has no known role !!"; - } - - echo "
RoleRemove
$role_name"; - - - if( in_array( 10, $_roles ) ) { - echo ""; - - } - - echo "
\n"; - - if ( in_array( 10, $_roles ) ) - echo "
\n"; - - - - // if admin show roles to add - if( in_array( 10, $_roles ) ) { - $all_roles= $api->GetRoles(); - $addable_roles= arr_diff( $all_roles, $proles ); - - if( !empty( $addable_roles ) ) { - echo "

Add role: \n"; - - } - } - - echo "


\n"; - - // slices - echo "

Slices

\n"; - if( !empty( $slice_info ) ) { - - foreach( $slice_info as $slice ) { - $slice_name= $slice['name']; - $slice_id= $slice['slice_id']; - - echo "$slice_name
\n"; - } - - } else { - echo "No slices found for that user"; - } + ////////// fetch related and store in a global hash + $rel_persons = $api->GetPersons ($rel_person_ids); + global $persons_hash; $persons_hash=array(); + foreach ($rel_persons as $person) $persons_hash[$person['person_id']]=$person; - if ( ! $peer_id ) { - echo "\n"; - } else { - echo "
\n"; - } + $rel_slices = $api->GetSlices ($rel_slice_ids); + global $slices_hash; $slices_hash=array(); + foreach ($rel_slices as $slice) $slices_hash[$slice['slice_id']]=$slice; - } - echo "

Back to person list"; + $rel_sites = $api->GetSites ($rel_site_ids); + global $sites_hash; $sites_hash=array(); + foreach ($rel_sites as $site) $sites_hash[$site['site_id']]=$site; - } - } + $rel_nodes = $api->GetNodes ($rel_node_ids); + global $nodes_hash; $nodes_hash=array(); + foreach ($rel_nodes as $node) $nodes_hash[$node['node_id']]=$node; + + ////////// show results + display_persons ($persons); + display_slices ($slices); + display_sites($sites); + display_nodes($nodes); + } // Print footer include 'plc_footer.php'; diff --git a/planetlab/css/plc_style.css b/planetlab/css/plc_style.css index f0238fc..40ccf29 100644 --- a/planetlab/css/plc_style.css +++ b/planetlab/css/plc_style.css @@ -20,6 +20,7 @@ a:hover.expandlink { color:#fff } +/* -------------------- general */ body { position: relative; } @@ -39,7 +40,7 @@ body { .plc-warning a:visited { text-decoration: none; color:white } .plc-warning a:hover { text-decoration: none; color:black } -/* styling the planetlab module area */ +/* -------------------- the planetlab module area */ div.block-planetlab a { font-weight:normal; font-style:italic; @@ -47,3 +48,21 @@ div.block-planetlab a { /* -------------------- sites */ .addresses { text-align: center; font-weight: bold; } +/* -------------------- admin search */ +#admin-search-form { + text-align: center; + padding: 10px; +} + +#admin-search-form input { + padding-left : 20 px; +} + +span.tokens { + font-weight: bold; + font-style: italic; +} + +#admin-search-message { + padding: 30px; +} diff --git a/planetlab/includes/plc_session.php b/planetlab/includes/plc_session.php index c0f9656..91fb247 100644 --- a/planetlab/includes/plc_session.php +++ b/planetlab/includes/plc_session.php @@ -142,8 +142,10 @@ if (!empty($_SESSION['plc'])) { if ($_SESSION['plc']['expires'] > time()) { $plc->person = $_SESSION['plc']['person']; $plc->api = new PLCAPI($_SESSION['plc']['auth']); - $plc->alt_person = $_SESSION['plc']['alt_person']; - $plc->alt_auth = $_SESSION['plc']['alt_auth']; + if (array_key_exists('alt_person',$_SESSION['plc'])) + $plc->alt_person = $_SESSION['plc']['alt_person']; + if (array_key_exists('alt_auth',$_SESSION['plc'])) + $plc->alt_auth = $_SESSION['plc']['alt_auth']; } else { // Destroy PHP session session_destroy(); diff --git a/planetlab/nodes/setting_action.php b/planetlab/nodes/setting_action.php deleted file mode 100644 index 1d04d10..0000000 --- a/planetlab/nodes/setting_action.php +++ /dev/null @@ -1,118 +0,0 @@ -person; -$_roles= $_person['role_ids']; - -//plc_debug('GET',$_GET); -//plc_debug('POST',$_POST); - -// tag type updates -if( $_POST['edit_type'] ) { - $setting_type_id= intval( $_POST['interface_tag_type_id'] ); - $setting_type = array ('category' => $_POST['category'], - 'name' => $_POST['name'], - 'min_role_id' => intval( $_POST['min_role_id'] ), - 'description' => $_POST['description']); - - // Update it! - $api->UpdateTagType( $setting_type_id, $setting_type ); - $api_error=$api->error(); - if (!empty($api_error)) { - print "

" . $api_error . "
"; - } - - // xxx check the destination page - plc_redirect ("settings.php"); -} - -// tag type adds -if( $_POST['add_type'] ) { - $setting_type = array ('category' => $_POST['category'], - 'name' => $_POST['name'], - 'min_role_id' => intval( $_POST['min_role_id'] ), - 'description' => $_POST['description']); - // add it!! - $api->AddTagType( $setting_type ); - - // xxx check the destination page - plc_redirect ("settings.php"); -} - - -// tag deletion -if( $_GET['rem_id'] ) { - // get the id of the tag to remove from GET - $setting_id= intval( $_GET['rem_id'] ); - - // get interface_id - $setting= $api->GetInterfaceTags( array( $setting_id ), array( "interface_id" ) ); - $interface_id= $setting[0]['interface_id']; - - // delete the tag - $api->DeleteInterfaceTag( $setting_id ); - - plc_redirect (l_interface($interface_id)); -} - -// tag adds -if( $_POST['add_setting'] ) { - // get the interface_id, tag_type_id, and value from POST - $interface_id= intval( $_POST['interface_id'] ); - $interface_tag_type_id= intval( $_POST['interface_tag_type_id'] ); - $value= $_POST['value']; - - // add it! - $api->AddInterfaceTag( $interface_id, $interface_tag_type_id, $value ); - - plc_redirect (l_interface($interface_id)); -} - -// tag updates -if( $_POST['edit_setting'] ) { - // get the id of the setting to update and the value from POST - $setting_id= intval( $_POST['setting_id'] ); - $value= $_POST['value']; - $interface_id= $_POST['interface_id']; - - // update it! - $api->UpdateInterfaceTag($setting_id, $value ); - - plc_redirect (l_interface($interface_id)); -} - -// Settings ------------------------------------------------- - -// TAG TYPES --------------------------------------------------- - -// delete tag types -if( $_GET['del_type'] ) { - // get vars - $type_id= intval( $_GET['del_type'] ); - - // delete it! - $api->DeleteTagType( $type_id ); - - // xxx check the destination page - plc_redirect ("settings.php" ); -} - -/* -// Print footer -include 'plc_footer.php'; -*/ - -?> diff --git a/planetlab/nodes/sliver_action.php b/planetlab/nodes/sliver_action.php deleted file mode 100644 index 77abdad..0000000 --- a/planetlab/nodes/sliver_action.php +++ /dev/null @@ -1,61 +0,0 @@ -person; -$_roles= $_person['role_ids']; - - -if( !empty( $_POST['add_sub'] ) ) { - $tag_type= $_POST['sliver']; - $value= $_POST['value']; - $node_id= $_POST['node_id']; - $slice_id= $_POST['slice_id']; - - $api->AddSliceTag( intval( $slice_id ), intval( $tag_type ), $value, intval( $node_id ) ); - - // xxx l_sliver ? - plc_redirect (l_sliver ($node_id,$slice_id)); - //header( "location: slivers.php?slice=$slice_id&node=$node_id" ); -} - - -// -if( $_GET['rem_id'] ) { - $tag_id= $_GET['rem_id']; - - // get the slivers for this node - $slivers= $api->GetSliceTags( array( "slice_tag_id"=>intval( $tag_id ) ), array( "slice_id", "node_id" ) ); - $sliver=$slivers[0]; - - $api->DeleteSliceTag( intval( $tag_id ) ); - - $node_id=$sliver['node_id']; - $slice_id=$sliver['slice_id']; - plc_redirect (l_sliver ($node_id,$slice_id)); -} - - -/* -// Print footer -include 'plc_footer.php'; -*/ - -?> diff --git a/planetlab/slices/delete_slice.php b/planetlab/slices/delete_slice.php deleted file mode 100644 index 75ff980..0000000 --- a/planetlab/slices/delete_slice.php +++ /dev/null @@ -1,60 +0,0 @@ -person; -$_roles= $_person['role_ids']; - -//print_r( $_person ); - -// if no id then go back to slice index -if( !$_GET['id'] ) - header( "index.php" ); - -// get slice id from get -$slice_id= $_GET['id']; - -// delete it! -if( $_POST['delete'] ) { - $api->DeleteSlice( intval( $slice_id ) ); - plc_redirect(l_slices()); -} - -// Print header -require_once 'plc_drupal.php'; -drupal_set_title('Slices'); -include 'plc_header.php'; - - -// get slice info from API call -$slice_info= $api->GetSlices( array( intval( $slice_id ) ), array( "name", "expires", "description" ) ); - -// start form -echo "
\n"; - -// show delete confirmation -echo "

Delete slice ". $slice_info[0]['name'] ."

\n"; -echo "

Are you sure you want to delete this slice?\n"; - -echo "\n"; -echo "\n"; -echo "\n"; -echo "\n"; -echo "
Name: ". $slice_info[0]['name'] ."
Description: ". $slice_info[0]['description'] ."
Expiration: ". gmstrftime( "%A %b-%d-%y %T %Z", $slice_info[0]['expires'] ) ."
\n"; -echo "\n"; -echo " diff --git a/planetlab/slices/slice.php b/planetlab/slices/slice.php index 24b12da..5797f04 100644 --- a/planetlab/slices/slice.php +++ b/planetlab/slices/slice.php @@ -273,8 +273,9 @@ $toggle->start(); // hide if both current+add are included // so user can chose which section is of interest // show otherwise +$count=count($persons); $toggle_persons = new PlekitToggle ('my-slice-persons-current', - "People currently in $name", + "$count people currently in $name", array('start-visible'=>!$privileges)); $toggle_persons->start(); @@ -314,8 +315,9 @@ $toggle_persons->end(); ////////// people to add if ($privileges) { + $count=count($potential_persons); $toggle_persons = new PlekitToggle ('my-slice-persons-add', - "People to add to $name", + "$count people may be added to $name", array('start-visible'=>false)); $toggle_persons->start(); if ( ! $potential_persons ) { @@ -375,8 +377,9 @@ $toggle=new PlekitToggle ('my-slice-nodes',"Nodes", $toggle->start(); ////////// nodes currently in +$count=count($nodes); $toggle_nodes=new PlekitToggle('my-slice-nodes-current', - "Nodes currently in $name", + "$count nodes currently in $name", array('start-visible'=>!$privileges)); $toggle_nodes->start(); @@ -412,8 +415,9 @@ $toggle_nodes->end(); ////////// nodes to add if ($privileges) { + $count=count($potential_nodes); $toggle_nodes=new PlekitToggle('my-slice-nodes-add', - "Nodes to add to $name", + "$count more nodes available", array('start-visible'=>false)); $toggle_nodes->start(); diff --git a/planetlab/slices/slice_action.php b/planetlab/slices/slice_action.php deleted file mode 100644 index 007c7f9..0000000 --- a/planetlab/slices/slice_action.php +++ /dev/null @@ -1,60 +0,0 @@ -person; -$_roles= $_person['role_ids']; - - - -// echo "

"; print_r( $_POST ); echo "
"; -// SLICES ------------------------------------------------------ - -// if action exists figure out what to do -if( $_POST['actions'] ) { - // get slice_id as int - $slice_id= intval( $_POST['slice_id'] ); - - // depending on action, run function - switch( $_POST['actions'] ) { - case "renew": - plc_redirect("renew_slice.php?id=$slice_id" ); - break; - case "delete": - plc_redirect( "delete_slice.php?id=$slice_id" ); - break; - case "nodes": - plc_redirect( "slice_nodes.php?id=$slice_id" ); - break; - case "users": - plc_redirect( "slice_users.php?id=$slice_id" ); - break; - - } - -} - - -/* -// Print footer -include 'plc_footer.php'; -*/ - -?> diff --git a/planetlab/slices/slice_nodes.php b/planetlab/slices/slice_nodes.php deleted file mode 100644 index 72f0ae7..0000000 --- a/planetlab/slices/slice_nodes.php +++ /dev/null @@ -1,264 +0,0 @@ -person; -$_roles= $_person['role_ids']; - -//print_r( $_person ); - -// if no id ... redirect to slice index -if( !$_GET['id'] && !$_POST['id'] ) { - plc_redirect( l_slices()); - } - - -// get slice id from GET or POST -if( $_GET['id'] ) - $slice_id= intval( $_GET['id'] ); -elseif ( $_POST['id'] ) - $slice_id= intval( $_POST['id'] ); -else - echo "no slice_id
\n"; - - -// if add node submitted add the nodes to slice -if( $_POST['add'] ) { - $add_nodes= $_POST['add_nodes']; - - foreach( $add_nodes as $nodes) { - $new_nodes[]= intval( $nodes ); - } - - // update it! - $api->AddSliceToNodes( $slice_id, $new_nodes ); - - $errors= $api->error(); - - if( empty( $errors ) ) - $added= "Nodes Added.

"; - else - $added= "Error: '$errors'

"; -} - -// if rem node submitted remove the nodes from slice -if( $_POST['remove'] ) { - $rem_nodes= $_POST['rem_nodes']; - - foreach( $rem_nodes as $nodes) { - $new_nodes[]= intval( $nodes ); - } - - // Delete them! - $api->DeleteSliceFromNodes( $slice_id, $new_nodes ); - - $errors= $api->error(); - - if( empty( $errors ) ) - $removed= "Nodes Removed.
"; - else - $removed= "Error: '$errors'

"; - -} - - -// get slice info -$slice_info= $adm->GetSlices( array( $slice_id ), array( "name", "node_ids", "peer_id" ) ); -$slice_readonly = $slice_info[0]['peer_id']; -drupal_set_title("Slice " . $slice_info[0]['name'] . " - Nodes"); - -// get node info -if( !empty( $slice_info[0]['node_ids'] ) ) - $node_info= $adm->GetNodes( $slice_info[0]['node_ids'], array( "hostname", "node_id", "site_id" , "peer_id") ); - -// get site names and ids -$site_info= $adm->GetSites( NULL, array( "site_id", "name", "peer_id" ) ); -sort_sites( $site_info ); - -// if site_id is in post use it, if not use the user's primary -if( $_POST['site_id'] ) - $site_id= $_POST['site_id']; -else - $site_id= $_person['site_ids'][0]; - - -// get site nodes for $site_id -if( $site_id == 'all_site' ) { - $full_node_info= $adm->GetNodes( array("node_type","regular"), - array( "hostname", "node_id" , "peer_id", "boot_state","last_updated") ); - - $snode_info= array(); - foreach( $full_node_info as $full_node ) { - if( !in_array( $full_node['node_id'], $slice_info[0]['node_ids'] ) ) - $snode_info[]= $full_node; - } -} -else { - $sid= intval( $site_id ); - $site_node_info= $adm->GetSites( array( $sid ), array( "node_ids" ) ); - $site_nodes= $site_node_info[0]['node_ids']; - - // gets all node_ids from site that arent already associated with the slice - foreach( $site_nodes as $snode) { - if( !in_array( $snode, $slice_info[0]['node_ids'] ) ) - $snodes[]= $snode; - } - - // Get node info from new list - if( !empty( $snodes ) ) - $snode_info= $adm->GetNodes( $snodes, array( "hostname", "node_id" , "peer_id", "boot_state","last_updated" ) ); - -} - -// start form -if ( $slice_readonly) - echo "
"; -else - echo "\n"; - -// section for adding nodes : for local slices only -if ( ! $slice_readonly ) { - echo "
"; - echo "
Select a site to add nodes from.
\n"; - echo "
"; - if ($site_id != 'all_site') { - echo plc_comon_button("site_id",$site_id,"_blank"); - echo ""; - } - echo "
\n"; - - // show all availible nodes at $site_id - //echo "
"; print_r( $snode_info ); echo "
"; - if( $snode_info ) { - echo $added; - echo "\n"; - echo " - "; - foreach( $snode_info as $snodes ) { - $class=""; - if ($snodes['peer_id']) { - $class="class='plc-foreign'"; - } - echo "\n"; - } - - echo "
check Hostname Boot State Last Update
"; - echo plc_comon_button("node_id",$snodes['node_id'],"_blank"); - echo ""; - echo ""; - echo ""; - echo $snodes['hostname']; - echo ""; - echo $snodes['boot_state']; - echo ""; - echo date('Y-m-d',$snodes['last_updated']); - echo "
\n"; - echo "

\n"; - } else { - echo "

No site nodes or all are already added.\n"; - } -} - -echo "


\n"; - -// show all nodes currently associated -echo $removed; -echo "
Nodes currently associated with slice
\n"; -if( $node_info ) { - if ( ! $slice_readonly) { - echo "Check boxes of nodes to remove:\n"; - echo "\n"; - echo " - "; - } else { - echo "
check Hostname Boot State Last Update
\n"; - echo " - "; - } - - foreach( $node_info as $node ) { - $class=""; - if ($node['peer_id']) { - $class="class='plc-foreign'"; - } - if ( ! $slice_readonly) { - echo "\n"; - } else { - echo ""; - } - - } - - echo "
check Hostname Boot State Last Update
"; - echo plc_comon_button("node_id",$node['node_id'],"_blank"); - echo ""; - echo ""; - echo "" ; - echo $node['hostname']; - echo ""; - echo $snodes['boot_state']; - echo ""; - echo date('Y-m-d',$snodes['last_updated']); - echo "
"; - echo plc_comon_button("node_id",$node['node_id'],"_blank"); - echo "" ; - echo $node['hostname']; - echo "
\n"; - if ( ! $slice_readonly) - echo "

\n"; - -} else { - echo "

No nodes associated with slice.\n"; -} - -if ($slice_readonly) - echo "

"; - else - echo "
"; - -echo "

Back to Slice\n"; - - -// Print footer -include 'plc_footer.php'; - -?> diff --git a/planetlab/slices/slice_users.php b/planetlab/slices/slice_users.php deleted file mode 100644 index a07c63a..0000000 --- a/planetlab/slices/slice_users.php +++ /dev/null @@ -1,207 +0,0 @@ -person; -$_roles= $_person['role_ids']; - -//print_r( $_person ); - -// if no id ... redirect to slice index -if( !$_GET['id'] && !$_POST['id'] ) { - plc_redirect(l_slices()); - } - - -// get slice id from GET or POST -if( $_GET['id'] ) - $slice_id= intval( $_GET['id'] ); -elseif ( $_POST['id'] ) - $slice_id= intval( $_POST['id'] ); -else - echo "no slice_id
\n"; - -// if add node submitted add the nodes to slice -if( $_POST['add'] ) { - $add_user= $_POST['add_user']; - - foreach( $add_user as $user) { - $api->AddPersonToSlice( intval( $user ), $slice_id ); - } - - $added= "People Added.
"; -} - -// if rem node submitted remove the nodes from slice -if( $_POST['remove'] ) { - $rem_user= $_POST['rem_user']; - - foreach( $rem_user as $user) { - $api->DeletePersonFromSlice( intval( $user ), $slice_id ); - } - - $removed= "People Removed.
"; -} - -// get slice info -$slice_info= $api->GetSlices( array( $slice_id ), array( "name", "person_ids" , "peer_id") ); -$slice_readonly = $slice_info[0]['peer_id']; -drupal_set_title("Slice " . $slice_info[0]['name'] . " - Users"); - -// get person info -if( !empty( $slice_info[0]['person_ids'] ) ) { - $person_info= $adm->GetPersons( $slice_info[0]['person_ids'], array( "first_name", "last_name", "email", "person_id","roles" ) ); - sort_persons( $person_info ); -} - -// if site_id is in post use it, if not use the user's primary -if( $_POST['site_id'] ) - $site_id= $_POST['site_id']; -else - $site_id= $_person['site_ids'][0]; - -// get site nodes for $site_id -$sid= intval( $site_id ); -$site_user_info= $adm->GetSites( array( $sid ), array( "person_ids" ) ); -$site_user= $site_user_info[0]['person_ids']; - - -// gets all person_ids from site that arent already associated with the slice -foreach( $site_user as $suser) { - if( !in_array( $suser, $slice_info[0]['person_ids'] ) ) - $susers[]= $suser; - -} - -// Get person info from new list -if( !empty( $susers ) ) { - $all_suser_info= $adm->GetPersons( $susers, array( "email", "first_name", "last_name", "person_id", "role_ids", 'roles' ) ); -//Filter the new list of user info to omit the tech user - foreach( $all_suser_info as $user_info) { - if ( (count($user_info["role_ids"])==1 ) && ( in_array(40, $user_info["role_ids"]) )) { - continue; - } - $suser_info[]= $user_info; - } - if ( ! empty($suser_info) ) { - sort_persons( $suser_info ); - } - } - - -// start form -if ( $slice_readonly) - echo "

"; -else - echo "
\n"; - -// section for adding people : for local slices only -if ( ! $slice_readonly ) { - echo "
"; - echo "
Select a site to add People from.
\n"; - echo "\n"; - - - if( $suser_info ) { - echo $added; - echo "\n"; - echo " - "; - $proles=""; - foreach( $suser_info as $susers ) { - foreach ( $susers['roles'] as $prole) - $proles.=" ".$prole; - echo "\n"; - unset($proles); - } - - echo "
Email First Name Last Name Roles
". $susers['email'] ." ". $susers['first_name'] ." ". $susers['last_name'] ." ".$proles."
\n"; - echo "

\n"; - } else { - echo "

All People on site already added.\n"; - } - } - - -echo "


\n"; - -// show all people currently associated -echo $removed; -echo "
People currently associated with slice
\n"; -if( $person_info ) { - if ( ! $slice_readonly ) { - echo "Check boxes of people to remove:\n"; - echo "\n"; - echo " - "; - } else { - echo "
Email First Name Last Name Roles
\n"; - echo ""; - } - - foreach( $person_info as $person ) { - foreach ( $person['roles'] as $prole) - $proles.=" ".$prole; - if ( ! $slice_readonly ) - echo "\n"; - else - echo ""; - unset($proles); - } - - echo "
E-mail First name Last name Roles
". $person['email'] ." ". $person['first_name']." ".$person['last_name'] ." ".$proles."
" . $person['email'] . "" . $person['first_name'] . "" . $person['last_name'] ." ".$proles."
\n"; - if ( ! $slice_readonly ) - echo "

\n"; - -} else { - echo "

No People associated with slice.\n"; -} - -if ($slice_readonly) - echo "

"; - else - echo ""; - -echo "

Back to Slice\n"; - -// Print footer -include 'plc_footer.php'; - -?> - diff --git a/planetlab/slices/update_slice.php b/planetlab/slices/update_slice.php deleted file mode 100644 index 59c3f6a..0000000 --- a/planetlab/slices/update_slice.php +++ /dev/null @@ -1,109 +0,0 @@ -person; -$_roles= $_person['role_ids']; - - -if( !empty( $_GET['id'] ) ) { - $slice_id= $_GET['id']; - // Fetch slice information - $slices= $api->GetSlices( array( intval( $slice_id ) ) ); - if( !empty( $slices ) ) { - $slice= $slices[0]; - } -} - -// Invalid slice name -if( !isset( $slice ) ) { - plc_redirect( l_slices()); -} - -// Defaults -$url_error = ""; -$description_error = ""; - -if( isset( $_POST['submitted'] ) ) { - if( !empty($_POST['url'] ) ) - $slice['url']= $_POST['url']; - else - $url_error= "Provide a link to a project website."; - - if( !empty($_POST['desc'] ) ) - $slice['description'] = $_POST['desc']; - else - $description_error= "Provide a short description of the slice."; - - if( empty( $url_error ) && empty( $description_error ) ) { - // Update the slice URL and description - $fields= array( "description"=>$slice['description'], "url"=>$slice['url'] ); - $api->UpdateSlice( intval( $slice_id ), $fields ); - plc_redirect(l_slice($slice_id)); - } -} - -// Print header -require_once 'plc_drupal.php'; -drupal_set_title('Slices'); -include 'plc_header.php'; - -$slice_name= $slice['name']; - -print "

Update Slice ". $slice['name'] ."

"; - -//echo "
"; print_r( $slice ); echo "
"; -$url = $slice['url'] ; -$description = $slice['description'] ; - -echo <<You must provide a short description as well as a -link to a project website. Do not provide -bogus information; if a complaint is lodged against your slice and -PlanetLab Operations is unable to determine what the normal behavior -of your slice is, your slice may be deleted to resolve the -complaint.

- -
- - - - - - - - - - - - - - - - - - - -
Name:$slice_name
URL:$url_error
Description:$description_error
- - - -
- -EOF; - -// Print footer -include 'plc_footer.php'; - -?> diff --git a/plekit/php/toggle.php b/plekit/php/toggle.php index c7ffc39..1796766 100644 --- a/plekit/php/toggle.php +++ b/plekit/php/toggle.php @@ -43,6 +43,7 @@ class PlekitToggle { $options['start-hidden'] = ! $options['start-visible']; unset ($options['start-visible']); } + if (!isset ($options['start-hidden'])) $options['start-hidden']=false; $this->options = $options; } @@ -84,8 +85,9 @@ class PlekitToggle { function trigger_html () { $trigger_id=$this->id_name('trigger'); if (array_key_exists ('trigger-tagname',$this->options)) $tagname=$this->options['trigger-tagname']; - if (array_key_exists ('trigger-bubble',$this->options)) $bubble=$this->options['trigger-bubble']; if (empty($tagname)) $tagname="span"; + $bubble=""; + if (array_key_exists ('trigger-bubble',$this->options)) $bubble=$this->options['trigger-bubble']; $html="<$tagname"; $html .= " id='$trigger_id'"; -- 2.43.0