X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Factions.php;h=5d73030e5a509b1381d8998c17b8844786025914;hb=350bb4d9c096b0cfb877fb67ab94ebac753a98a5;hp=437541aefd255d3c3eda1397c06134d3b98eaba4;hpb=34d41a3846da0721bc27d94ffe69ec4ee2cf9dec;p=plewww.git diff --git a/planetlab/actions.php b/planetlab/actions.php index 437541a..5d73030 100644 --- a/planetlab/actions.php +++ b/planetlab/actions.php @@ -18,6 +18,7 @@ $known_actions=array(); // interface : // (*) use POST // (*) set 'action' to one of the following +//////////////////////////////////////// persons $known_actions []= "add-person-to-site"; // expects: person_id & site_id $known_actions []= "remove-person-from-sites"; @@ -38,14 +39,27 @@ $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'] -$known_actions []= "update-tag-type"; -// expects: tag_type_id & name & description & category & min_role_id -$known_actions []= "add-tag-type"; -// expects: tag_type_id & name & description & category & min_role_id +$known_actions []= "update-person"; +// expects: person_id & first_name last_name title email phone url bio + [password1 password2] + +//////////////////////////////////////// nodes +$known_actions []= "node-boot-state"; +// expects: node_id boot_state +$known_actions []= "delete-node"; +// expects: node_id +$known_actions []= "update-node"; +// expects: node_id, hostname, model +//////////////////////////////////////// sites $known_actions []= "delete-site"; // expects: site_id $known_actions []= "expire-all-slices-in-site"; // expects: slice_ids + +//////////////////////////////////////// tags +$known_actions []= "update-tag-type"; +// expects: tag_type_id & name & description & category & min_role_id +$known_actions []= "add-tag-type"; +// expects: tag_type_id & name & description & category & min_role_id $known_actions []= "set-tag-on-node"; // expects: node_id tagname value @@ -77,8 +91,7 @@ switch ($action) { 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(); + plc_redirect (l_person($person_id)); } case 'remove-person-from-sites': { @@ -90,8 +103,7 @@ switch ($action) { foreach ( $site_ids as $site_id ) { $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) ); } - header( "location: " . l_person($person_id)); - exit(); + plc_redirect (l_person($person_id)); } case 'remove-roles-from-person' : { @@ -103,41 +115,35 @@ switch ($action) { foreach( $role_ids as $role_id) { $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ); } - header( "location: " . l_person($person_id)); - exit(); + plc_redirect (l_person($person_id)); } 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(); + plc_redirect (l_person($person_id)); } case 'enable-person' : { $fields = array( "enabled"=>true ); $api->UpdatePerson( intval( $person_id ), $fields ); - header( "location: " . l_person($person_id)); - exit(); + plc_redirect (l_person($person_id)); } case 'disable-person' : { $fields = array( "enabled"=>false ); $api->UpdatePerson( intval( $person_id ), $fields ); - header( "location: " . l_person($person_id)); - exit(); + plc_redirect (l_person($person_id)); } case 'become-person' : { $plc->BecomePerson (intval($person_id)); - header ("location: " . l_persons()); - exit(); + plc_redirect (l_persons()); } case 'delete-person' : { $api->DeletePerson( intval( $person_id ) ); - header( "location: " . l_persons() ); - exit(); + plc_redirect (l_persons()); } case 'delete-keys' : { @@ -149,10 +155,10 @@ switch ($action) { foreach( $key_ids as $key_id ) { $api->DeleteKey( intval( $key_id ) ); } - header( "location: " . l_person($person_id)); - exit(); + plc_redirect(l_person($person_id)); } + case 'upload-key' : { if ( ! isset( $_FILES['key'] ) ) { drupal_set_message ("action=$action, no key file set"); @@ -185,10 +191,124 @@ switch ($action) { plc_error("Please verify your SSH file content"); return; } - header( "location: " . l_person($person_id)); - exit(); + plc_redirect(l_person($person_id)); + } + + case 'update-person': { + $person_id=$_POST['person_id']; + // attempt to update this person + $first_name= $_POST['first_name']; + $last_name= $_POST['last_name']; + $title= $_POST['title']; + $email= $_POST['email']; + $phone= $_POST['phone']; + $url= $_POST['url']; + $bio= str_replace("\r", "", $_POST['bio']); + $password1= $_POST['password1']; + $password2= $_POST['password2']; + + if( $password1 != $password2 ) { + drupal_set_error ("The passwords do not match"); + plc_redirect(l_person($person_id)); + } + + $update_vals= array(); + $update_vals['first_name']= $first_name; + $update_vals['last_name']= $last_name; + $update_vals['title']= $title; + $update_vals['email']= $email; + $update_vals['phone']= $phone; + $update_vals['url']= $url; + $update_vals['bio']= $bio; + + if( $password1 != "" ) + $update_vals['password']= $password1; + + $rc= $api->UpdatePerson( intval( $person_id ), $update_vals); + + if ( $rc == 1 ) { + drupal_set_message("$first_name $last_name updated"); + } else { + drupal_set_error ("Could not update person $person_id" . $api->error()); + } + plc_redirect(l_person($person_id)); + break; + } + +//////////////////////////////////////////////////////////// nodes + case 'node-boot-state': { + $node_id=intval($_POST['node_id']); + $boot_state=$_POST['boot_state']; + $result=$api->UpdateNode( $node_id, array( "boot_state" => $boot_state ) ); + if ($result==1) { + drupal_set_message("boot state updated"); + plc_redirect (l_node($node_id)); + } else { + drupal_set_error("Could not set boot_state '$boot_state'"); + } + break; + } + + case 'delete-node': { + $node_id=intval($_POST['node_id']); + $result=$api->DeleteNode( intval( $node_id ) ); + if ($api==1) { + drupal_set_message("Node $node_id deleted"); + plc_redirect (l_nodes()); + } else { + drupal_set_error ("Could not delete node $node_id"); + } + break; + } + + case 'update-node': { + $hostname= $_POST['hostname']; + $model= $_POST['model']; + + $fields= array( "hostname"=>$hostname, "model"=>$model ); + $api->UpdateNode( intval( $node_id ), $fields ); + $error= $api->error(); + + if( empty( $error ) ) { + drupal_set_message("Update node $hostname"); + plc_redirect(l_node($node_id)); + } else { + drupal_set_error($error); + } + break; + } + +//////////////////////////////////////////////////////////// sites + case 'delete-site': { + $site_id = intval($_POST['site_id']); + if ($api->DeleteSite($site_id) ==1) + drupal_set_message ("Site $site_id deleted"); + else + drupal_set_error("Failed to delete site $site_id"); + plc_redirect (l_sites()); + } + + case 'expire-all-slices-in-site': { + // xxx todo + drupal_set_message("action $action not implemented in actions.php -- need tweaks and test"); + return; + + //// old code from sites/expire.php + $sites = $api->GetSites( array( intval( $site_id ))); + $site=$sites[0]; + // xxx why not 'now?' + $expiration= strtotime( $_POST['expires'] ); + // loop through all slices for site + foreach ($site['slice_ids'] as $slice_id) { + $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) ); + } + // update site to not allow slice creation or renewal + $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ; + plc_redirect (l_site($site_id)); } +//////////////////////////////////////////////////////////// tags + case 'update-tag-type': { // get post vars $tag_type_id= intval( $_POST['tag_type_id'] ); @@ -207,8 +327,7 @@ switch ($action) { // Update it! $api->UpdateTagType( $tag_type_id, $tag_type_fields ); - header( "location: " . l_tag($tag_type_id)); - exit(); + plc_redirect(l_tag($tag_type_id)); } case 'add-tag-type': { @@ -229,38 +348,7 @@ switch ($action) { $id=$api->AddTagType( $tag_type_fields ); drupal_set_message ("tag type $id created"); - header( "location: " . l_tag($id)); - exit(); - } - - case 'delete-site': { - $site_id = intval($_POST['site_id']); - if ($api->DeleteSite($site_id) ==1) - drupal_set_message ("Site $site_id deleted"); - else - drupal_set_error("Failed to delete site $site_id"); - header ("location: " . l_sites()); - exit(); - } - - case 'expire-all-slices-in-site': { - // xxx todo - drupal_set_message("action $action not implemented in actions.php -- need tweaks and test"); - return; - - //// old code from sites/expire.php - $sites = $api->GetSites( array( intval( $site_id ))); - $site=$sites[0]; - // xxx why not 'now?' - $expiration= strtotime( $_POST['expires'] ); - // loop through all slices for site - foreach ($site['slice_ids'] as $slice_id) { - $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) ); - } - // update site to not allow slice creation or renewal - $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ; - header ("location: " . l_site($site_id)); - exit(0); + plc_redirect( l_tag($id)); } case 'set-tag-on-node': { @@ -291,10 +379,10 @@ switch ($action) { } } - header ("location: " . l_node($node_id)); - exit(); + plc_redirect (l_node($node_id)); } +//////////////////////////////////////// case 'debug': { plc_debug('GET',$_GET);