From e1205e67d6ddb33eb56e06b9c2a1d44d7eb2da32 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Wed, 28 Jan 2009 21:59:38 +0000 Subject: [PATCH 1/1] checkpoint --- planetlab/events/index.php | 15 +- planetlab/includes/plc_forms.php | 35 ++ planetlab/includes/plc_functions.php | 3 +- planetlab/includes/plc_tables.php | 28 +- planetlab/nodes/node.php | 6 +- .../nodes/{add_node.php => node_add.php} | 0 planetlab/nodes/nodes.php | 5 +- planetlab/peers/peers.php | 2 +- planetlab/persons/person.php | 469 +++++++++--------- planetlab/persons/person_actions.php | 348 ++++++------- planetlab/persons/persons.php | 8 +- planetlab/sites/index.php | 4 +- planetlab/sites/join_request.php | 2 +- 13 files changed, 475 insertions(+), 450 deletions(-) create mode 100644 planetlab/includes/plc_forms.php rename planetlab/nodes/{add_node.php => node_add.php} (100%) diff --git a/planetlab/events/index.php b/planetlab/events/index.php index 5c8db26..d076ca3 100644 --- a/planetlab/events/index.php +++ b/planetlab/events/index.php @@ -181,14 +181,14 @@ function e_event ($event_id) { return href(l_event("Event","event",$event_id),$event_id); } -function e_link ($type,$id) { +function e_subject ($type,$id) { $mess=$type . " " . $id; switch ($type) { case 'Node': return l_node_t ($id,$mess); case 'Site': return l_site_t ($id,$mess); case 'Person': return l_person_t ($id,$mess); case 'Slice': return l_slice_t ($id,$mess); - case 'Role': case 'Key': case 'PCU': case 'Interface': case 'NodeGroup': + case 'Role': case 'Key': case 'PCU': case 'Interface': case 'NodeGroup': case "Address": return "$mess"; default: return "Unknown $type" . "-" . $id; } @@ -199,12 +199,12 @@ function e_subjects ($param) { $types=$param['object_types']; $ids=$param['object_ids']; if ( ! $types) return ""; - return plc_vertical_table(array_map ("e_link",$types,$ids)); + return plc_vertical_table(array_map ("e_subject",$types,$ids)); } function e_issuer ($param) { - if ($param['node_id']) return e_link('Node',$param['node_id']); - if ($param['person_id']) return e_link('Person',$param['person_id']); + if ($param['node_id']) return e_subject('Node',$param['node_id']); + if ($param['person_id']) return e_subject('Person',$param['person_id']); return '???'; } @@ -358,8 +358,7 @@ if ( ! plc_is_admin()) { foreach ($messages as $line) drupal_set_message($line); - $columns=array( - "Id"=>"int", + $columns=array("Id"=>"int", "Time"=>"EnglishDateTime", "Method"=>"string", "Message"=>"string", @@ -403,7 +402,7 @@ if ( ! plc_is_admin()) { plc_table_cell($details); plc_table_row_end(); } - plc_table_end($table_options); + plc_table_end("events"); } diff --git a/planetlab/includes/plc_forms.php b/planetlab/includes/plc_forms.php new file mode 100644 index 0000000..44a9fa1 --- /dev/null +++ b/planetlab/includes/plc_forms.php @@ -0,0 +1,35 @@ +"; + foreach ($values as $key=>$value) { + print ""; + } +} + +function plc_form_end($options=array()) { + print ""; +} + +function plc_form_checkbox_text ($name,$value,$selected=false) { + return ""; +} + +function plc_form_submit_text ($name,$display) { + return ""; +} + +function plc_form_file_text ($name,$size) { + return ""; +} + +function plc_form_label_text ($label,$name) { + return ""; +} + +?> diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index fa28702..c93dc1c 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -45,7 +45,7 @@ function href ($url,$text) { return "" . $text . ""; function l_nodes () { return "/db/nodes/index.php"; } function l_node ($node_id) { return "/db/nodes/node.php?id=" . $node_id; } function l_node_t ($node_id,$text) { return href (l_node($node_id),$text); } -function l_node_add () { return "/db/nodes/add_node.php"; } +function l_node_add () { return "/db/nodes/node_add.php"; } function l_nodes_site ($site_id) { return "/db/nodes/index.php?site_id=" . $site_id; } function l_interface ($interface_id) { return "/db/nodes/interfaces.php?id=" . $interface_id; } @@ -70,6 +70,7 @@ function l_persons () { return "/db/persons/index.php"; } function l_person ($person_id) { return "/db/persons/index.php?id=" . $person_id; } function l_person_t ($person_id,$text) { return href (l_person($person_id),$text); } function l_persons_site ($site_id) { return "/db/persons/index.php?site_id=" . $site_id; } +function l_person_actions() { return "/db/persons/person_actions.php"; } function l_tags () { return "/db/tags/index.php"; } function l_tags_node () { return "/db/tags/index.php?type=node"; } diff --git a/planetlab/includes/plc_tables.php b/planetlab/includes/plc_tables.php index d41c15e..e2c08ce 100644 --- a/planetlab/includes/plc_tables.php +++ b/planetlab/includes/plc_tables.php @@ -9,6 +9,11 @@ drupal_set_html_head(' '); +//// hash to retrieve the columns and options as passed at table-creation time +// this means that table_id's need to be different across the page, +// which is required anyway for the search and pagesize areas to work properly +$plc_table_hash=array(); + //////////////////////////////////////// function plc_table_cell($cell) { printf (' %s ',$cell); @@ -25,7 +30,10 @@ function plc_table_cell($cell) { // - pagesize: the initial pagination size // - pagesize_def: the page size when one clicks the pagesize reset button // - max_pages: the max number of pages to display in the paginator -function plc_table_start ($table_id, $headers, $column_sort, $options) { +function plc_table_start ($table_id, $headers, $column_sort, $options=NULL) { + if ( ! $options ) $options = array(); + global $plc_table_hash; + $plc_table_hash[$table_id]=array($headers,$options); $search_area = array_key_exists('search_area',$options) ? $options['search_area'] : true; $max_pages = array_key_exists('max_pages',$options) ? $options['max_pages'] : 10; $pagesize = array_key_exists('pagesize',$options) ? $options['pagesize'] : 25; @@ -36,8 +44,11 @@ function plc_table_start ($table_id, $headers, $column_sort, $options) { plc_table_head($table_id,$headers,$column_sort,$max_pages,$pagesize); } -function plc_table_end ($options) { - plc_table_foot(); +function plc_table_end ($table_id) { + global $plc_table_hash; + list($headers,$options) = $plc_table_hash[$table_id]; + + plc_table_foot($options); $notes_area = array_key_exists('notes_area',$options) ? $options['notes_area'] : true; if ($notes_area) plc_table_notes($options); @@ -119,13 +130,10 @@ EOF; } //////////////////////////////////////// -function plc_table_foot () { - print <<< EOF - - - - -EOF; +function plc_table_foot ($options) { + print ""; + print $options['footer']; + print "\n"; } //////////////////////////////////////// diff --git a/planetlab/nodes/node.php b/planetlab/nodes/node.php index 825dd31..d8ad55a 100644 --- a/planetlab/nodes/node.php +++ b/planetlab/nodes/node.php @@ -212,7 +212,7 @@ if (empty($nodes)) { plc_table_cell (l_sliver_t ($node_id,$slice['slice_id'],'view')); plc_table_row_end(); } - plc_table_end($table_options); + plc_table_end("slivers"); } //////////////////////////////////////////////////////////// interfaces @@ -272,7 +272,7 @@ if (empty($nodes)) { plc_table_cell($interface_bwlimit); plc_table_row_end(); } - plc_table_end($table_options); + plc_table_end("interfaces"); } } @@ -300,7 +300,7 @@ if (empty($nodes)) { plc_table_cell($nodegroup['value']); plc_table_row_end(); } - plc_table_end($table_options); + plc_table_end("nodegroups"); } //////////////////////////////////////////////////////////// diff --git a/planetlab/nodes/add_node.php b/planetlab/nodes/node_add.php similarity index 100% rename from planetlab/nodes/add_node.php rename to planetlab/nodes/node_add.php diff --git a/planetlab/nodes/nodes.php b/planetlab/nodes/nodes.php index d03c7b5..6e1f501 100644 --- a/planetlab/nodes/nodes.php +++ b/planetlab/nodes/nodes.php @@ -138,8 +138,7 @@ $columns = array ("Peer"=>"string", "Float"=>"float"); # initial sort on hostnames -$table_options=array(); -plc_table_start("nodes",$columns,4,$table_options); +plc_table_start("nodes",$columns,4); $peer_hash = plc_peer_get_hash ($api); // write rows @@ -174,7 +173,7 @@ foreach ($nodes as $node) { $fake_i += 1; } -plc_table_end($table_options); +plc_table_end("nodes"); // Print footer include 'plc_footer.php'; diff --git a/planetlab/peers/peers.php b/planetlab/peers/peers.php index c547a19..a9af51a 100644 --- a/planetlab/peers/peers.php +++ b/planetlab/peers/peers.php @@ -49,7 +49,7 @@ if ( empty($peers)) { plc_table_cell (href(l_comon("peer_id",$peer['peer_id']),'Comon')); plc_table_row_end(); } - plc_table_end($table_options); + plc_table_end("peers"); } // Print footer diff --git a/planetlab/persons/person.php b/planetlab/persons/person.php index ce87e07..0fafa41 100644 --- a/planetlab/persons/person.php +++ b/planetlab/persons/person.php @@ -18,11 +18,15 @@ require_once 'plc_functions.php'; require_once 'plc_minitabs.php'; require_once 'plc_tables.php'; require_once 'plc_details.php'; +require_once 'plc_forms.php'; // -------------------- // recognized URL arguments $person_id=intval($_GET['id']); -if ( ! $person_id ) { plc_error('Malformed URL - id not set'); return; } +if ( ! $person_id ) { + plc_error('Malformed URL - id not set'); + return; + } //////////////////// // Get all columns as we focus on only one entry @@ -30,273 +34,294 @@ $persons= $api->GetPersons( array($person_id)); if (empty($persons)) { drupal_set_message ("Person " . $person_id . " not found"); - } else { - $person=$persons[0]; - - // vars from api - $first_name= $person['first_name']; - $last_name= $person['last_name']; - $title= $person['title']; - $url= $person['url']; - $phone= $person['phone']; - $email= $person['email']; - $enabled= $person['enabled']; - $peer_id=$person['peer_id']; - - // arrays from api - $role_ids= $person['role_ids']; - $roles= $person['roles']; - $site_ids= $person['site_ids']; - $slice_ids= $person['slice_ids']; - $key_ids= $person['key_ids']; - - // gets more data from API calls - $sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) ); - $slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) ); - $keys= $api->GetKeys( $key_ids ); + return; + } +$person=$persons[0]; - drupal_set_title("Details for account " . $first_name . " " . $last_name); +// vars from api +$enabled= $person['enabled']; +$first_name= $person['first_name']; +$last_name= $person['last_name']; +$email= $person['email']; +$url= $person['url']; +$phone= $person['phone']; +$title= $person['title']; +$bio= $person['bio']; +$peer_id=$person['peer_id']; - $plc_hash=plc_peer_get_hash($api); +// arrays from api +$role_ids= $person['role_ids']; +$roles= $person['roles']; +$site_ids= $person['site_ids']; +$slice_ids= $person['slice_ids']; +$key_ids= $person['key_ids']; - $local_peer = plc_peer_block_start ($peer_hash,$peer_id); - $is_my_account = plc_my_person_id() == $person_id; - $privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi()); +// gets more data from API calls +$sites= $api->GetSites( $site_ids, array( "site_id", "name", "login_base" ) ); +$slices= $api->GetSlices( $slice_ids, array( "slice_id", "name" ) ); +$keys= $api->GetKeys( $key_ids ); - $tabs=array(); +drupal_set_title("Details for account " . $first_name . " " . $last_name); - if ($local_peer && $privileges) { - if (plc_is_admin()) - $tabs['Events'] = array('url'=>l_events(), - 'values'=>array('type'=>'Person','person'=>$person_id), - 'bubble'=>'Related events', - 'image'=>'/planetlab/icons/event.png', - 'height'=>18); - if ($enabled) - $tabs['Disable'] = array ('method'=>'POST', - 'url'=>'/db/persons/person_actions.php', - 'values'=> array ('person_id'=>$person_id, - 'action'=>'disable'), - 'bubble'=>"Disable $first_name", - 'confirm'=>"Are you sure you want to disable $first_name $last_name"); - else - $tabs['Enable'] = array ('method'=>'POST', - 'url'=>'/db/persons/person_actions.php', - 'values'=> array ('person_id'=>$person_id, - 'action'=>'enable'), - 'bubble'=>"Enable $first_name"); - $tabs['Delete'] = array ('method'=>'POST', - 'url'=>'/db/persons/person_actions.php', - 'values'=> array ('person_id'=>$person_id, - 'action'=>'delete'), - 'bubble'=>"Delete $first_name", - 'confirm'=>"Are you sure to delete $first_name $last_name"); - } +$plc_hash=plc_peer_get_hash($api); - if ($privileges || $is_my_account) - $tabs['Update'] = array('url'=>'/db/persons/update.php', - 'values'=>array('id'=>$person_id), - 'bubble'=>"Update $first_name"); +$local_peer = plc_peer_block_start ($peer_hash,$peer_id); +$is_my_account = plc_my_person_id() == $person_id; +$privileges = plc_is_admin () || ( plc_in_site($site_id) && plc_is_pi()); - $tabs['All Users'] = array ('url'=>l_persons()); +$tabs=array(); - plc_tabs($tabs); - - if ($privileges && ! $enabled ) - drupal_set_message ("$first_name $last_name is not enabled yet, please use the 'Enable' button below"); +// update +if ($privileges || $is_my_account) + $tabs['Update'] = array('url'=>'/db/persons/update.php', + 'values'=>array('id'=>$person_id), + 'bubble'=>"Update $first_name $last_name"); + +// enable / disable +if ($local_peer && $privileges) + if ($enabled) + $tabs['Disable'] = array ('method'=>'POST', + 'url'=>l_person_actions(), + 'values'=> array ('person_id'=>$person_id, + 'action'=>'disable-person'), + 'bubble'=>"Disable $first_name $last_name", + 'confirm'=>"Are you sure you want to disable $first_name $last_name"); + else + $tabs['Enable'] = array ('method'=>'POST', + 'url'=>l_person_actions(), + 'values'=> array ('person_id'=>$person_id, + 'action'=>'enable-person'), + 'bubble'=>"Enable $first_name $last_name", + 'confirm'=>"Are you sure you want to enable $first_name $last_name"); - $enabled_text="Enabled"; - if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled"); +// become +if (plc_is_admin() && ! $is_my_account) + $tabs['Become'] = array('url'=>l_person_actions(), + 'values'=>array('action'=>'become-person', + 'person_id'=>$person_id), + 'bubble'=>"Become $first_name $last_name", + 'confirm'=>"Are you sure you want to su $first_name $last_name"); + +// delete +if ($local_peer && $privileges) + $tabs['Delete'] = array ('method'=>'POST', + 'url'=>l_person_actions(), + 'values'=> array ('person_id'=>$person_id, + 'action'=>'delete-person'), + 'bubble'=>"Delete $first_name $last_name", + 'confirm'=>"Are you sure to delete $first_name $last_name"); +// events for that person +if ( $privileges) + $tabs['Events'] = array('url'=>l_events(), + 'values'=>array('type'=>'Person','person'=>$person_id), + 'bubble'=>"Events about $first_name $last_name", + 'image'=>'/planetlab/icons/event.png', + 'height'=>18); - plc_details_start(); - plc_details_line("Enabled",$enabled_text); - plc_details_line("First Name",$first_name); - plc_details_line("Last Name",$last_name); - plc_details_line("Title",$title); - plc_details_line("Email",href("mailto:$email",$email)); - plc_details_line("Phone",$phone); - plc_details_line("URL",$url); - plc_details_end(); +// Back button +$tabs['All Users'] = array ('url'=>l_persons(), + 'bubble'=>'Back to the Users page'); - - echo "
\n"; - - // keys - $can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) ); - plc_table_title('Keys'); - if ( empty( $key_ids ) ) { - echo " This user has no known key"; - } else { - echo "

\n"; - echo ""; - if ( $can_manage_keys ) - echo ""; - echo "\n"; +plc_tabs($tabs); - foreach( $keys as $key ) { - $key_type= $key['key_type']; - $key_id= $key['key_id']; - $key_text= wordwrap( $key['key'], 70, "
\n", 1 ); - echo "\n"; - } - - echo "
TypeKeyRemove
$key_type$key_text"; - - if ( $can_manage_keys ) - echo ""; - - echo "
\n"; - if ($can_manage_keys) - echo "


\n"; +if ($local_peer && $privileges && ! $enabled ) + drupal_set_message ("$first_name $last_name is not enabled yet, you can enable her/him with the 'Enable' button below"); + +$enabled_text="Enabled"; +if ( ! $enabled ) $enabled_text = plc_warning_div("Disabled"); + +plc_details_start(); +plc_details_line("Enabled",$enabled_text); +plc_details_line("First Name",$first_name); +plc_details_line("Last Name",$last_name); +plc_details_line("Email",href("mailto:$email",$email)); +plc_details_line("URL",$url); +plc_details_line("Phone",$phone); +plc_details_line("Title",$title); +plc_details_line("Bio",wordwrap($bio,50,"
")); +plc_details_end(); + +//////////////////// slices +echo "


\n"; +plc_table_title('Slices'); + +if( empty( $slices ) ) { + drupal_set_message ("User has no slice"); + } else { + $columns=array('Slice name'=>'string'); + plc_table_start("person_slices",$columns,1,$table_options); + + foreach( $slices as $slice ) { + $slice_name= $slice['name']; + $slice_id= $slice['slice_id']; + plc_table_row_start(); + plc_table_cell(l_slice_t($slice_id,$slice_name)); + plc_table_row_end(); } + plc_table_end("person_slices"); + } + +////////// keys +echo "
\n"; +plc_table_title ("Keys"); - if( $can_manage_keys ){ - echo "
Upload new key: \n - \n -

\n"; +$can_manage_keys = ( $local_peer && ( plc_is_admin() || $is_my_account) ); +if ( empty( $key_ids ) ) { + plc_warning("This user has no known key"); + } else { + // we don't set 'action', but use the submit button name instead + plc_form_start(l_person_actions(), + array("person_id"=>$person_id)); + + // the headers + $columns=array("Type"=>"string", + "Key"=>"string"); + if ($can_manage_keys) $columns['Remove']="none"; + // table overall options + $table_options=array("search_area"=>false,"notes_area"=>false); + // add the 'remove site' button and key upload areas as the table footer + if ($can_manage_keys) { + $remove_keys_area=plc_form_submit_text ("delete-keys","Remove keys"); + $upload_key_left_area= plc_form_label_text("Upload new key","key") . plc_form_file_text("key",60); + $upload_key_right_area=plc_form_submit_text("upload-key","Upload key"); + $table_options['footer']=""; + $table_options['footer'].=" $remove_keys_area "; + $table_options['footer'].=" $upload_key_left_area ". + " $upload_key_right_area "; + } + plc_table_start("person_keys",$columns,"1",$table_options); + + foreach( $keys as $key ) { + $key_id=$key['key_id']; + plc_table_row_start($key_id); + plc_table_cell ($key['key_type']); + plc_table_cell(wordwrap( $key['key'], 60, "
\n", 1 )); + if ($can_manage_keys) + plc_table_cell (plc_form_checkbox_text('key_ids[]',$key_id)); + plc_table_row_end(); } + plc_table_end("person_keys"); + plc_form_end(); + } - // sites - plc_table_title('Sites'); +// sites +echo "
\n"; +plc_table_title('Sites'); - // sites - if (empty( $sites ) ) { - plc_warning('This user is not affiliated with a site !!'); - } else { - $columns=array(); - $columns['Name']="string"; - $columns['Login_base']="string"; - $columns['Remove']="string"; - $table_options = array('notes_area'=>false,'search_area'=>false); - plc_table_start ("person_slices",$columns,1,$table_options); - foreach( $sites as $site ) { - $site_name= $site['name']; - $site_id= $site['site_id']; - $login_base=$site['login_base']; - plc_table_row_start(); - plc_table_cell (l_site_t($site_id,$site_name)); - plc_table_cell ($login_base); - plc_table_cell (""); - plc_table_row_end (); - } - plc_table_end($table_options); +// sites +if (empty( $sites ) ) { + plc_warning('This user is not affiliated with a site !!'); + } else { + $columns=array(); + $columns['Name']="string"; + $columns['Login_base']="string"; + $columns['Remove']="string"; + $table_options = array('notes_area'=>false,'search_area'=>false); + plc_table_start ("person_sites",$columns,1,$table_options); + foreach( $sites as $site ) { + $site_name= $site['name']; + $site_id= $site['site_id']; + $login_base=$site['login_base']; + plc_table_row_start(); + plc_table_cell (l_site_t($site_id,$site_name)); + plc_table_cell ($login_base); + plc_table_cell (""); + plc_table_row_end (); } + plc_table_end("person_sites"); + } - echo "\n"; +echo "\n"; - // diplay site select list to add another site for user - if ($local_peer && plc_is_admin()) { - // get site info - $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) ); +// diplay site select list to add another site for user +if ($local_peer && plc_is_admin()) { + // get site info + $all_sites= $api->GetSites( NULL, array( "site_id", "name" ) ); - if( $sites ) - $person_site= arr_diff( $all_sites, $sites ); - else - $person_site= $all_sites; + if( $sites ) + $person_site= arr_diff( $all_sites, $sites ); + else + $person_site= $all_sites; - // sort_sites( $person_site ); + // sort_sites( $person_site ); - echo "

Select a site to add this user to: "; - echo "\n\n"; - foreach( $person_site as $site ) { - echo "\n"; + foreach( $person_site as $site ) { + echo "\n"; - } + } - echo ""; + echo ""; - } - echo "


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

Roles

\n"; - echo "

\n"; - echo ""; - if( plc_is_admin()) - echo ""; - echo "\n"; +// roles +echo "

Roles

\n"; +echo "

RoleRemove
\n"; +echo ""; +if( plc_is_admin()) + echo ""; +echo "\n"; - // construct role array - for( $n=0; $n$role_ids[$n], 'name'=>$roles[$n] ); - } +// construct role array +for( $n=0; $n$role_ids[$n], 'name'=>$roles[$n] ); + } - $button_shown=0; - if ( !empty ($roles) ) { - foreach( $proles as $role ) { - $role_name= $role['name']; - $role_id= $role['role_id']; +$button_shown=0; +if ( !empty ($roles) ) { + foreach( $proles as $role ) { + $role_name= $role['name']; + $role_id= $role['role_id']; - echo "\n"; - $button_shown=1; - } + if( plc_is_admin()) { + echo "\n"; + $button_shown=1; } - - echo "\n"; } - } else { - echo " This user has no known role !!"; + + echo "\n"; } - echo "
RoleRemove
$role_name"; + echo "
$role_name"; - if( plc_is_admin()) { - echo ""; - if ( ! $button_shown ) { - $rowspan=count($roles); - echo "
"; + if ( ! $button_shown ) { + $rowspan=count($roles); + echo "
\n"; + } else { + echo " This user has no known role !!"; + } +echo "\n"; - // if admin show roles to add - if( plc_is_admin()) { - $all_roles= $api->GetRoles(); - $addable_roles= arr_diff( $all_roles, $proles ); - ##when the proles array is empty strangely the method arr_diff($all_roles, $proles ) - ##return an empty array and the scrolling roles list is not displayed in this case - ##assign to addablerole all the roles - if (count($proles)==0) - $addable_roles=$all_roles; +// if admin show roles to add +if( plc_is_admin()) { + $all_roles= $api->GetRoles(); + $addable_roles= arr_diff( $all_roles, $proles ); + ##when the proles array is empty strangely the method arr_diff($all_roles, $proles ) + ##return an empty array and the scrolling roles list is not displayed in this case + ##assign to addablerole all the roles + if (count($proles)==0) + $addable_roles=$all_roles; - if( !empty( $addable_roles ) ) { - echo "

Add role: \n\n"; - foreach( $addable_roles as $arole ) { - echo "\n"; + foreach( $addable_roles as $arole ) { + echo "\n"; - } + } - echo "\n"; + echo "\n"; - } } + } - echo "


\n"; +plc_peer_block_end(); - // slices - plc_table_title('Slices'); - - if( empty( $slices ) ) { - drupal_set_message ("User has no slice"); - } else { - $columns=array('Slice name'=>'string'); - $table_options=array(); - plc_table_start("person_slices",$columns,1,$table_options); - - foreach( $slices as $slice ) { - $slice_name= $slice['name']; - $slice_id= $slice['slice_id']; - plc_table_row_start(); - plc_table_cell(l_slice_t($slice_id,$slice_name)); - plc_table_row_end(); - } - plc_table_end($table_options); - } - - plc_peer_block_end(); - - } - // Print footer include 'plc_footer.php'; diff --git a/planetlab/persons/person_actions.php b/planetlab/persons/person_actions.php index 9dbcd34..1905af6 100644 --- a/planetlab/persons/person_actions.php +++ b/planetlab/persons/person_actions.php @@ -9,225 +9,185 @@ global $plc, $api; //print header require_once 'plc_drupal.php'; -//set default -drupal_set_title('Persons'); -include 'plc_header.php'; // Common functions require_once 'plc_functions.php'; -require_once 'plc_sorts.php'; -// find person roles -$_person= $plc->person; -$_roles= $_person['role_ids']; +$known_actions=array(); +//////////////////////////////////////////////////////////// +// interface : +// (*) use POST +// (*) set 'action' to one of the following +$known_actions []= "add-person-to-site"; +// expects: person_id & site_id +$known_actions []= "remove-person-from-site"; +// expects: person_id & site_ids +$known_actions []= "remove-roles-from-person"; +// expects: person_id & role_ids +$known_actions []= "add-role-to-person"; +// expects: role_person_id & id +$known_actions []= "enable-person"; +// expects: person_id +$known_actions []= "disable-person"; +// expects: person_id +$known_actions []= "become-person"; +// expects: person_id +$known_actions []= "delete-person"; +// expects: person_id +$known_actions []= "delete-keys"; +// expects: key_ids & person_id (for redirecting to the person's page) +$known_actions []= "upload-key"; +// expects: person_id & $_FILES['key'] ////////////////////////////// -// get person id -if( $_POST['person_id'] ) - $person_id= $_POST['person_id']; - - -//////////////////// add in site -if( $_POST['site_add'] ) { - $site_id= $_POST['site_add']; - - $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) ); - header( "location: index.php?id=$person_id" ); - exit(); - -} - -//////////////////// remove from sites -if ( $_POST['Remove_Sites']){ - if( $_POST['rem_site'] ) { - foreach( $_POST['rem_site'] as $site_id ) { - $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) ); - } - header( "location: index.php?id=$person_id" ); - exit(); - }else{ - echo "

Please select one or more Sites to remove.

\n"; - echo "

Back to person page"; - return; - } -} - -//////////////////// remove roles -// remove role -if ( $_POST['Remove_Roles']){ - if($_POST['rem_role']) { - $rem_ids= $_POST['rem_role']; - foreach( $rem_ids as $role_id ) { - $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ); +// sometimes we don't set 'action', but use the submit button name instead +// so if 'action' not set, see if $_POST has one of the actions as a key +if ($_POST['action']) + $action=$_POST['action'] +else + foreach ($known_actions as $known_action) + if ($_POST[$known_action]) { + $action=$known_action; + break; } - header( "location: index.php?id=$person_id" ); - exit(); - }else{ - echo "

Please select one or more Roles to remove.

\n"; - echo "

Back to person page"; - } -} - -//////////////////// add roles -if( $_POST['add_role'] ) { - $role_id= $_POST['add_role']; - - $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ); - - header( "location: index.php?id=$person_id" ); - exit(); -} -//////////////////// enable -// enable person -if ( $_GET['enab_id'] ) { - $per_id= $_GET['enab_id']; +// +$person_id = $_POST['person_id']; // usually needed - $fields= array( "enabled"=>true ); - - $api->UpdatePerson( intval( $per_id ), $fields ); - - header( "location: index.php?id=$per_id" ); - exit(); - -} - -//////////////////// disable person -if( $_GET['dis_id'] ) { - $per_id= $_GET['dis_id']; - - $fields= array( "enabled"=>false ); +if ( ! $action ) { + drupal_set_message ("person_actions.php: action not set"); + return; + } - $api->UpdatePerson( intval( $per_id ), $fields ); +switch ($action) { - header( "location: index.php?id=$per_id" ); - exit(); - -} + case 'add-person-to-site': { + $site_id = $_POST['site_id']; + $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) ); + header( "location: " . l_person($person_id)); + exit(); + } -// if action exists figure out what to do -if( $_POST['action'] ) { + case 'remove-person-from-sites': { + $site_ids = $_POST['site_ids']; + if ( ! $site_ids) { + drupal_set_message("action=$action - No site selected"); + return; + } + foreach ( $site_ids as $site_id ) { + $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) ); + } + header( "location: " . l_person($person_id)); + exit(); + } - // depending on action, run function - switch( $_POST['action'] ) { - case "delete": - header( "location: person_actions.php?del_id=$person_id" ); - exit(); - break; - case "disable": - header( "location: person_actions.php?dis_id=$person_id" ); - exit(); - break; - case "enable": - header( "location: person_actions.php?enab_id=$person_id" ); - exit(); - break; - case "su": - plc_debug('plc',$plc); - $plc->BecomePerson (intval($person_id)); - header ( "location: index.php" ); - break; - } + case 'remove-roles-from-person' : { + $role_ids=$_POST['role_ids']; + if ( ! $role_ids) { + drupal_set_message("action=$action - No role selected"); + return; + } + foreach( $role_ids as $role_id) { + $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ); + } + header( "location: " . l_person($person_id)); + exit(); + } + + case 'add-role-to-person' : { + $role_id=$_POST['role_id']; + $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ); + header( "location: " . l_person($person_id)); + exit(); + } -} + case 'enable-person' : { + $fields = array( "enabled"=>true ); + $api->UpdatePerson( intval( $person_id ), $fields ); + header( "location: " . l_person($person_id)); + exit(); + } -//////////////////// delete person -if( $_GET['per_id'] ) { - $per_id= $_GET['per_id']; + case 'disable-person' : { + $fields = array( "enabled"=>false ); + $api->UpdatePerson( intval( $person_id ), $fields ); + header( "location: " . l_person($person_id)); + exit(); + } - $api->DeletePerson( intval( $per_id ) ); + case 'become-person' : { + $plc->BecomePerson (intval($person_id)); + header ("location: " . l_persons()); + exit(); + } - header( "location: index.php" ); + case 'delete-person' : { + $api->DeletePerson( intval( $person_id ) ); + header( "location: " . l_persons() ); exit(); } -//delete a key -if ( $_POST['Remove_keys'] ){ - if( $_POST['rem_key'] ) { - $key_ids= $_POST['rem_key']; - - foreach( $key_ids AS $key_id ) { - $api->DeleteKey( intval( $key_id ) ); - } - header( "location: index.php?id=$person_id" ); - exit(); - }else{ - echo "

Please select one or more keys to remove.

\n"; - echo "

Back to person page"; - } + case 'delete-keys' : { + $key_ids=$_POST['key_ids']; + if ( ! $key_ids) { + drupal_set_message("action=$action - No key selected"); + return; + } + foreach( $key_ids as $key_id ) { + $api->DeleteKey( intval( $key_id ) ); + } + header( "location: " . l_person($person_id)); + exit(); } -// upload a key if the user submitted one -if ( $_POST['Upload']){ - if( isset( $_FILES['key'] ) ) { - $key_file= $_FILES['key']['tmp_name']; - if( $key_file ){ - $fp = fopen( $key_file, "r" ); - $key = ""; - if( $fp ) { - // opened the key file, read the one line of contents - // The POST operation always creates a file even if the filename - // the user specified was garbage. If there was some problem - // with the source file, we'll get a zero length read here. - $key = fread($fp, filesize($key_file)); - fclose($fp); - - $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) ); - - if (!$key_id){ - $error= $api->error(); - echo "

Please verify your SSH file content.

\n"; - print '
' . $error . '
'; - echo "

Back to person page"; - } - else{ - header( "location: index.php?id=$person_id" ); - exit(); - } - }else { - $error= "Unable to open key file."; - print '

' . $error . '
'; - } - }else{ - echo "

Please select a valid SSH key file to upload.

\n"; - echo "

Back to person page"; - } - } + case 'upload-key' : { + if ( ! isset( $_FILES['key'] ) ) { + drupal_set_message ("action=$action, no key file set"); + return; + } + + $key_file= $_FILES['key']['tmp_name']; + if ( ! $key_file ) { + plc_error("Please select a valid SSH key file to upload"); + return; + } + $fp = fopen( $key_file, "r" ); + $key = ""; + if( ! $fp ) { + plc_error("Unable to open key file $key_file"); + return; + } + // opened the key file, read the one line of contents + // The POST operation always creates a file even if the filename + // the user specified was garbage. If there was some problem + // with the source file, we'll get a zero length read here. + $key = fread($fp, filesize($key_file)); + fclose($fp); + + $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) ); + + if ( ! $key_id ) { + $error= $api->error(); + plc_error("$error"); + plc_error("Please verify your SSH file content"); + return; + } + header( "location: " . l_person($person_id)); + exit(); } -// delete person confimation -if( $_GET['del_id'] ) { - $person_id= $_GET['del_id']; - - // get person info from API - $person_info= $api->GetPersons( array( intval( $person_id ) ), array( "first_name", "last_name", "email", "roles" ) ); - - // start form - echo "

\n"; - - // show delete confirmation - echo "

Delete ". $person_info[0]['first_name'] ." ". $person_info[0]['last_name'] ."

\n"; - echo "

Are you sure you want to delete this user?\n"; - - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
Email: ". $person_info[0]['email'] ."
Roles: "; - - foreach( $person_info[0]['roles'] as $role ) { - echo "$role
\n"; - } - - echo "
\n"; - echo "

\n"; - echo "

\n"; - - -} + case 'debug': { + plc_debug('GET',$_GET); + plc_debug('POST',$_POST); + plc_debug('FILES',$_FILES); + return; + } -// Print footer -include 'plc_footer.php'; + default: { + plc_error ("Unknown action $action in person_actions.php"); + return; + } + } ?> diff --git a/planetlab/persons/persons.php b/planetlab/persons/persons.php index 7197e01..d3fff78 100644 --- a/planetlab/persons/persons.php +++ b/planetlab/persons/persons.php @@ -31,10 +31,9 @@ $slice_id=intval($_GET['slice_id']); // --- decoration $title="Accounts"; $tabs=array(); -$mysite_id=plc_my_site_id(); $tabs['My accounts'] = array('url'=>l_persons(), 'values'=>array('site_id'=>plc_my_site_id()), - 'bubble'=>'Lists accounts on site ' . $mysite_id); + 'bubble'=>'Lists accounts on site ' . plc_my_site_id()); // -------------------- $peer_filter=array(); $person_filter=array(); @@ -141,8 +140,7 @@ $columns = array ("Peer"=>"string", ); // initial sort on email -$table_options=array(); -plc_table_start("persons",$columns,4,$table_options); +plc_table_start("persons",$columns,4); $peer_hash = plc_peer_get_hash ($api); // write rows @@ -169,7 +167,7 @@ foreach ($persons as $person) { } -plc_table_end($table_options); +plc_table_end("persons"); // Print footer include 'plc_footer.php'; diff --git a/planetlab/sites/index.php b/planetlab/sites/index.php index a4cf270..d92ce68 100644 --- a/planetlab/sites/index.php +++ b/planetlab/sites/index.php @@ -382,8 +382,8 @@ else { $right_role = in_array(30,$_roles) || in_array(40,$_roles); $can_add = $right_site && $right_role; if ($can_add) { - $href_add_node = "'/db/nodes/add_node.php'"; - printf ("0 Site has no node, please add one",$href_add_node); + $href_node_add = "'/db/nodes/node_add.php'"; + printf ("0 Site has no node, please add one",$href_node_add); } else { printf ("0 Site has no node",$href); } diff --git a/planetlab/sites/join_request.php b/planetlab/sites/join_request.php index cb70109..48dafd8 100644 --- a/planetlab/sites/join_request.php +++ b/planetlab/sites/join_request.php @@ -139,7 +139,7 @@ You can directly access your site information at https://%s:%d/db/sites/index.php?id=%d Please start with adding nodes for this site with -https://%s:%d/db/nodes/add_node.php +https://%s:%d/db/nodes/node_add.php Our support team will be glad to answer any question that you might have They are reachable at mailto:%s -- 2.43.0