mktime() is no longer allowed, used time() instead
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 29 Apr 2022 18:32:46 +0000 (20:32 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 29 Apr 2022 18:32:46 +0000 (20:32 +0200)
planetlab/common/actions.php
planetlab/sirius/index.php
planetlab/sirius/sirius_func.php

index aced135..c33c68f 100644 (file)
@@ -14,1168 +14,1298 @@ require_once 'plc_drupal.php';
 // Common functions
 require_once 'plc_functions.php';
 
 // Common functions
 require_once 'plc_functions.php';
 
-$known_actions=array();
+$known_actions = array();
 ////////////////////////////////////////////////////////////
 // interface :
 ////////////////////////////////////////////////////////////
 // interface :
-// (*) use POST 
+// (*) use POST
 // (*) set 'action' to one of the following
 //////////////////////////////////////// persons
 // (*) 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";
-//     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']
-$known_actions []= "update-person";
-//     expects:        person_id & first_name last_name title email phone url bio + [password1 password2]
+$known_actions[] = "add-person-to-site";
+//    expects:    person_id & site_id
+$known_actions[] = "remove-person-from-sites";
+//    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']
+$known_actions[] = "update-person";
+//    expects:    person_id & first_name last_name title email phone url bio + [password1 password2]
 
 //////////////////////////////////////// nodes
 
 //////////////////////////////////////// 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, node_type
-$known_actions []= "attach-pcu";
-//     expects:        node_id, pcu_id, port (pcu_id <0 means detach)
-$known_actions []= "reboot-node-with-pcu";
-//     expects:        node_id
+$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, node_type
+$known_actions[] = "attach-pcu";
+//    expects:    node_id, pcu_id, port (pcu_id <0 means detach)
+$known_actions[] = "reboot-node-with-pcu";
+//    expects:    node_id
 
 //////////////////////////////////////// interfaces
 
 //////////////////////////////////////// interfaces
-$known_actions []= "delete-interfaces";        
-//     expects:        interface_ids
-$known_actions []="add-interface";
-//     expects:        node_id & interface details
-$known_actions []="new-interface";
-//     expects:        node_id 
-$known_actions []="update-interface";
-//     expects:        interface_id & interface details
+$known_actions[] = "delete-interfaces";
+//    expects:    interface_ids
+$known_actions[] = "add-interface";
+//    expects:    node_id & interface details
+$known_actions[] = "new-interface";
+//    expects:    node_id
+$known_actions[] = "update-interface";
+//    expects:    interface_id & interface details
 
 //////////////////////////////////////// sites
 
 //////////////////////////////////////// sites
-$known_actions []= "delete-site";      
-//     expects:        site_id
-$known_actions []= "expire-all-slices-in-site";
-//     expects:        slice_ids
-$known_actions []= "update-site";
-//     expects:        site_id & name abbreviated_name url latitude longitude [login_base max_slices]
+$known_actions[] = "delete-site";
+//    expects:    site_id
+$known_actions[] = "expire-all-slices-in-site";
+//    expects:    slice_ids
+$known_actions[] = "update-site";
+//    expects:    site_id & name abbreviated_name url latitude longitude [login_base max_slices]
 
 //////////////////////////////////////// slices
 
 //////////////////////////////////////// slices
-$known_actions []= "delete-slice";
+$known_actions[] = "delete-slice";
 //      expects:        slice_id
 //      expects:        slice_id
-$known_actions []= "update-slice";     
-//     expects:        slice_id, name, description, url
-$known_actions []= "renew-slice";
-//     expects:        slice_id & expires
-$known_actions []= 'remove-persons-from-slice';
-//     expects:        slice_id & person_ids
-$known_actions []= 'add-persons-in-slice';
-//     expects:        slice_id & person_ids
-$known_actions []= 'remove-nodes-from-slice';
-//     expects:        slice_id & node_ids
-$known_actions []= 'add-nodes-in-slice';
-//     expects:        slice_id & node_ids
-$known_actions []= 'update-initscripts';
-//     expects:        slice_id & name & previous-initscript & previous-initscript-code 
-//                     & initscript & initscript-code
-$known_actions []= 'delete-slice-tags';
+$known_actions[] = "update-slice";
+//    expects:    slice_id, name, description, url
+$known_actions[] = "renew-slice";
+//    expects:    slice_id & expires
+$known_actions[] = 'remove-persons-from-slice';
+//    expects:    slice_id & person_ids
+$known_actions[] = 'add-persons-in-slice';
+//    expects:    slice_id & person_ids
+$known_actions[] = 'remove-nodes-from-slice';
+//    expects:    slice_id & node_ids
+$known_actions[] = 'add-nodes-in-slice';
+//    expects:    slice_id & node_ids
+$known_actions[] = 'update-initscripts';
+//    expects:    slice_id & name & previous-initscript & previous-initscript-code
+//            & initscript & initscript-code
+$known_actions[] = 'delete-slice-tags';
 //      expects:        slice_tag_id
 //      expects:        slice_tag_id
-$known_actions []= 'add-slice-tag';
+$known_actions[] = 'add-slice-tag';
 //      expects:        slice_id & tag_type_id & node_id & nodegroup_id
 
 //////////////////////////////////////// tag types
 //      expects:        slice_id & tag_type_id & node_id & nodegroup_id
 
 //////////////////////////////////////// tag types
-$known_actions []= "update-tag-type";
-//     expects:        tag_type_id & name & description & category & min_role_id  
-$known_actions []= "add-tag-type";
-//     expects:        tag_type_id & tagname & description & category & min_role_id  
-$known_actions []= "delete-tag-types";
-//     expects:        tag_type_ids
-$known_actions []= "remove-roles-from-tag-type";
-//     expects:        tag_type_id & role_ids
-$known_actions []= "add-role-to-tag-type";
-//     expects:        tag_type_id_id & id
+$known_actions[] = "update-tag-type";
+//    expects:    tag_type_id & name & description & category & min_role_id
+$known_actions[] = "add-tag-type";
+//    expects:    tag_type_id & tagname & description & category & min_role_id
+$known_actions[] = "delete-tag-types";
+//    expects:    tag_type_ids
+$known_actions[] = "remove-roles-from-tag-type";
+//    expects:    tag_type_id & role_ids
+$known_actions[] = "add-role-to-tag-type";
+//    expects:    tag_type_id_id & id
 
 //////////////////////////////////////// tags
 
 //////////////////////////////////////// tags
-$known_actions []= "set-tag-on-node";
-//     expects:        node_id tagname value
-$known_actions []= "set-tag-on-site";
-//     expects:        site_id tagname value
-$known_actions []= "set-tag-on-person";
-//     expects:        person_id tagname value
-$known_actions []= "set-tag-on-interface";
-//     expects:        interface_id tagname value
-$known_actions []= "delete-node-tags";
-//     expects:        node_id & node_tag_ids
-$known_actions []= "delete-site-tags";
-//     expects:        site_id & site_tag_ids
-$known_actions []= "delete-person-tags";
-//     expects:        person_id & person_tag_ids
-$known_actions []= "delete-interface-tags";
-//     expects:        interface_id & interface_tag_ids
+$known_actions[] = "set-tag-on-node";
+//    expects:    node_id tagname value
+$known_actions[] = "set-tag-on-site";
+//    expects:    site_id tagname value
+$known_actions[] = "set-tag-on-person";
+//    expects:    person_id tagname value
+$known_actions[] = "set-tag-on-interface";
+//    expects:    interface_id tagname value
+$known_actions[] = "delete-node-tags";
+//    expects:    node_id & node_tag_ids
+$known_actions[] = "delete-site-tags";
+//    expects:    site_id & site_tag_ids
+$known_actions[] = "delete-person-tags";
+//    expects:    person_id & person_tag_ids
+$known_actions[] = "delete-interface-tags";
+//    expects:    interface_id & interface_tag_ids
 
 //////////////////////////////////////// nodegroups
 
 //////////////////////////////////////// nodegroups
-$known_actions []= "update-nodegroup";
-//     expects nodegroup_id groupname value
-$known_actions []= "add-nodegroup";
-//     expects groupname, tag_type_id, value
-$known_actions []= 'delete-nodegroups';
-//     expects nodegroup_ids
+$known_actions[] = "update-nodegroup";
+//    expects nodegroup_id groupname value
+$known_actions[] = "add-nodegroup";
+//    expects groupname, tag_type_id, value
+$known_actions[] = 'delete-nodegroups';
+//    expects nodegroup_ids
 
 //////////////////////////////////////// leases
 
 //////////////////////////////////////// leases
-$known_actions []= "manage-leases";
-//     expects as 'actions' a list of 'action' of the form
+$known_actions[] = "manage-leases";
+//    expects as 'actions' a list of 'action' of the form
 //      either [ 'add-leases', [nodenames], slicename, t_from, t_until ]
 //      or     [ 'delete-leases', lease_id ]
 
 ////////////////////////////////////////////////////////////
 //      either [ 'add-leases', [nodenames], slicename, t_from, t_until ]
 //      or     [ 'delete-leases', lease_id ]
 
 ////////////////////////////////////////////////////////////
-$interface_details= array ('method','type', 'ip', 'gateway', 'network', 
-                          'broadcast', 'netmask', 'dns1', 'dns2', 
-                          'hostname', 'mac', 'bwlimit' );
+$interface_details = array('method', 'type', 'ip', 'gateway', 'network',
+    'broadcast', 'netmask', 'dns1', 'dns2',
+    'hostname', 'mac', 'bwlimit');
 
 //////////////////////////////
 // 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
 
 //////////////////////////////
 // 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;
+if ($_POST['action']) {
+    $action = $_POST['action'];
+} else {
+    foreach ($known_actions as $known_action) {
+        if ($_POST[$known_action]) {
+            $action = $known_action;
+            break;
+        }
     }
     }
+}
 
 //uncomment for debugging incoming data
 //$action='debug';
 
 
 //uncomment for debugging incoming data
 //$action='debug';
 
-$person_id = $_POST['person_id'];      // usually needed
+$person_id = $_POST['person_id']; // usually needed
 
 
-if ( ! $action ) {
-  drupal_set_message ("actions.php: action not set or not in known_actions");
-  plc_debug('POST',$_POST);
-  return;
- }
+if (!$action) {
+    drupal_set_message("actions.php: action not set or not in known_actions");
+    plc_debug('POST', $_POST);
+    return;
+}
 
 switch ($action) {
 
 
 switch ($action) {
 
- case 'add-person-to-site': {
-   $site_id = $_POST['site_id'];
-   $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
-   plc_redirect (l_person($person_id));
- }
-
- 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 ) );
-   }
-   plc_redirect (l_person($person_id));
- }
-
- case 'remove-roles-from-person' : {
-   $role_ids=$_POST['role_ids'];
-   if ( ! $role_ids) {
-     drupal_set_error("You have not selected role(s) to remove");
-   } else {
-     foreach( $role_ids as $role_id)  
-       if ( $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) ) != 1 ) 
-        drupal_set_error ("Could not remove role $role_id from person $person_id");
-   }
-   plc_redirect (l_person_roles($person_id));
- }
-     
- case 'add-role-to-person' : {
-   $role_id=$_POST['role_id'];
-   if ( ! $role_id) {
-     drupal_set_error ("You have not selected a role to add");
-   } else if ($api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) ) != 1) {
-     drupal_set_error("Could not add role $role_id to person $person_id");
-   }
-   plc_redirect (l_person_roles($person_id));
- }
-
- case 'enable-person' : {
-   $fields = array( "enabled"=>true );
-   $api->UpdatePerson( intval( $person_id ), $fields );
-   plc_redirect (l_person($person_id));
- }
-
- case 'disable-person' : {
-   $fields = array( "enabled"=>false );
-   $api->UpdatePerson( intval( $person_id ), $fields );
-   plc_redirect (l_person($person_id));
- }
-
- case 'become-person' : {
-   $plc->BecomePerson (intval($person_id));
-   plc_redirect (l_person(intval($person_id)));
- }
-
- case 'delete-person' : {
-  $api->DeletePerson( intval( $person_id ) );
-   plc_redirect (l_persons());
- }
-
- case 'delete-keys' : {
-   $key_ids=$_POST['key_ids'];
-   if ( ! $key_ids) {
-     drupal_set_message("action=$action - No key selected");
-     return;
-   }
-   $success=true;
-   $counter=0;
-   foreach( $key_ids as $key_id ) {
-     if ($api->DeleteKey( intval( $key_id )) != 1) 
-       $success=false;
-     else
-       $counter++;
-   }
-   if ($success) 
-     drupal_set_message ("Deleted $counter key(s)");
-   else
-     drupal_set_error ("Could not delete all selected keys, only $counter were removed");
-   plc_redirect(l_person($person_id));
- }
-
-
- 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 >= 1) 
-     drupal_set_message ("New key added");
-   else
-     drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error());
-   
-   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));
-  }
-
-   $fields= array();
-   $fields['first_name']= $first_name;
-   $fields['last_name']= $last_name;
-   $fields['title']= $title;
-   $fields['email']= $email;
-   $fields['phone']= $phone;
-   $fields['url']= $url;
-   $fields['bio']= $bio;
-               
-   if ( $password1 != "" )
-     $fields['password']= $password1;
-    
-    if ( $api->UpdatePerson( intval( $person_id ), $fields) == 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;
-  }
+    case 'add-person-to-site':{
+            $site_id = $_POST['site_id'];
+            $api->AddPersonToSite(intval($person_id), intval($site_id));
+            plc_redirect(l_person($person_id));
+        }
+
+    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));
+            }
+            plc_redirect(l_person($person_id));
+        }
+
+    case 'remove-roles-from-person':{
+            $role_ids = $_POST['role_ids'];
+            if (!$role_ids) {
+                drupal_set_error("You have not selected role(s) to remove");
+            } else {
+                foreach ($role_ids as $role_id) {
+                    if ($api->DeleteRoleFromPerson(intval($role_id), intval($person_id)) != 1) {
+                        drupal_set_error("Could not remove role $role_id from person $person_id");
+                    }
+                }
+
+            }
+            plc_redirect(l_person_roles($person_id));
+        }
+
+    case 'add-role-to-person':{
+            $role_id = $_POST['role_id'];
+            if (!$role_id) {
+                drupal_set_error("You have not selected a role to add");
+            } else if ($api->AddRoleToPerson(intval($role_id), intval($person_id)) != 1) {
+                drupal_set_error("Could not add role $role_id to person $person_id");
+            }
+            plc_redirect(l_person_roles($person_id));
+        }
+
+    case 'enable-person':{
+            $fields = array("enabled" => true);
+            $api->UpdatePerson(intval($person_id), $fields);
+            plc_redirect(l_person($person_id));
+        }
+
+    case 'disable-person':{
+            $fields = array("enabled" => false);
+            $api->UpdatePerson(intval($person_id), $fields);
+            plc_redirect(l_person($person_id));
+        }
+
+    case 'become-person':{
+            $plc->BecomePerson(intval($person_id));
+            plc_redirect(l_person(intval($person_id)));
+        }
+
+    case 'delete-person':{
+            $api->DeletePerson(intval($person_id));
+            plc_redirect(l_persons());
+        }
+
+    case 'delete-keys':{
+            $key_ids = $_POST['key_ids'];
+            if (!$key_ids) {
+                drupal_set_message("action=$action - No key selected");
+                return;
+            }
+            $success = true;
+            $counter = 0;
+            foreach ($key_ids as $key_id) {
+                if ($api->DeleteKey(intval($key_id)) != 1) {
+                    $success = false;
+                } else {
+                    $counter++;
+                }
+
+            }
+            if ($success) {
+                drupal_set_message("Deleted $counter key(s)");
+            } else {
+                drupal_set_error("Could not delete all selected keys, only $counter were removed");
+            }
+
+            plc_redirect(l_person($person_id));
+        }
+
+    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 >= 1) {
+                drupal_set_message("New key added");
+            } else {
+                drupal_set_error("Could not add key, please verify your SSH file content\n" . $api->error());
+            }
+
+            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));
+            }
+
+            $fields = array();
+            $fields['first_name'] = $first_name;
+            $fields['last_name'] = $last_name;
+            $fields['title'] = $title;
+            $fields['email'] = $email;
+            $fields['phone'] = $phone;
+            $fields['url'] = $url;
+            $fields['bio'] = $bio;
+
+            if ($password1 != "") {
+                $fields['password'] = $password1;
+            }
+
+            if ($api->UpdatePerson(intval($person_id), $fields) == 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
 
 //////////////////////////////////////////////////////////// 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': {
-   $node_id=intval($_POST['node_id']);
-   $hostname= $_POST['hostname'];
-   $model= $_POST['model'];
-   $node_type= $_POST['node_type'];
-
-   $fields= array( "hostname"=>$hostname, "model"=>$model, "node_type"=>$node_type );
-   $api->UpdateNode( $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;
- }
-
- // this code will ensure that at most one PCU gets attached to the node
- case 'attach-pcu': {
-   $node_id=intval($_POST['node_id']);
-   $pcu_id=intval($_POST['pcu_id']);
-   $port=intval($_POST['port']);
-   // always start with deleting former PCUs
-   $nodes = $api->GetNodes(array($node_id),array('pcu_ids'));
-   $former_pcu_ids = $nodes[0]['pcu_ids'];
-   if ($former_pcu_ids) foreach ($former_pcu_ids as $former_pcu_id) {
-       if ($api->DeleteNodeFromPCU($node_id,$former_pcu_id) == 1) 
-        drupal_set_message ('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
-       else 
-        drupal_set_error ('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
-     }
-   // re-attach only if provided pcu_id >=0
-   if ($pcu_id >= 0) {
-     if ($api->AddNodeToPCU($node_id,$pcu_id,$port) == 1)
-       drupal_set_message ('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
-     else
-       drupal_set_error ('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
-   } else {
-     drupal_set_message ('Detached node from all PCUs');
-   }
-   
-   plc_redirect(l_node($node_id));
-   break;
- }
-
- case 'reboot-node-with-pcu': {
-   $node_id=intval($_POST['node_id']);
-   $hostname= $_POST['hostname'];
-   $test = $_POST['test'];
-   settype($test, "boolean");
-
-   $ret = $api->RebootNodeWithPCU( $node_id, $test );
-   $error= $api->error();
-
-   if( empty( $error ) ) {
-     drupal_set_message("Reboot node $hostname: $ret");
-     plc_redirect(l_node($node_id));
-   } else {
-     drupal_set_error($error);
-   }
-   break;
- }
-   
+    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':{
+            $node_id = intval($_POST['node_id']);
+            $hostname = $_POST['hostname'];
+            $model = $_POST['model'];
+            $node_type = $_POST['node_type'];
+
+            $fields = array("hostname" => $hostname, "model" => $model, "node_type" => $node_type);
+            $api->UpdateNode($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;
+        }
+
+    // this code will ensure that at most one PCU gets attached to the node
+    case 'attach-pcu':{
+            $node_id = intval($_POST['node_id']);
+            $pcu_id = intval($_POST['pcu_id']);
+            $port = intval($_POST['port']);
+            // always start with deleting former PCUs
+            $nodes = $api->GetNodes(array($node_id), array('pcu_ids'));
+            $former_pcu_ids = $nodes[0]['pcu_ids'];
+            if ($former_pcu_ids) {
+                foreach ($former_pcu_ids as $former_pcu_id) {
+                    if ($api->DeleteNodeFromPCU($node_id, $former_pcu_id) == 1) {
+                        drupal_set_message('Detached node ' . $node_id . ' from PCU ' . $pcu_id);
+                    } else {
+                        drupal_set_error('Could not detach node ' . $node_id . ' from PCU ' . $pcu_id);
+                    }
+
+                }
+            }
+
+            // re-attach only if provided pcu_id >=0
+            if ($pcu_id >= 0) {
+                if ($api->AddNodeToPCU($node_id, $pcu_id, $port) == 1) {
+                    drupal_set_message('Attached node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+                } else {
+                    drupal_set_error('Failed to attach node ' . $node_id . ' to PCU ' . $pcu_id . ' on port ' . $port);
+                }
+
+            } else {
+                drupal_set_message('Detached node from all PCUs');
+            }
+
+            plc_redirect(l_node($node_id));
+            break;
+        }
+
+    case 'reboot-node-with-pcu':{
+            $node_id = intval($_POST['node_id']);
+            $hostname = $_POST['hostname'];
+            $test = $_POST['test'];
+            settype($test, "boolean");
+
+            $ret = $api->RebootNodeWithPCU($node_id, $test);
+            $error = $api->error();
+
+            if (empty($error)) {
+                drupal_set_message("Reboot node $hostname: $ret");
+                plc_redirect(l_node($node_id));
+            } else {
+                drupal_set_error($error);
+            }
+            break;
+        }
 
 //////////////////////////////////////////////////////////// interfaces
 
 //////////////////////////////////////////////////////////// interfaces
- case 'delete-interfaces' : {
-   $interface_ids=$_POST['interface_ids'];
-   if ( ! $interface_ids) {
-     drupal_set_message("action=$action - No interface selected");
-     return;
-   }
-   $success=true;
-   $counter=0;
-   foreach( $interface_ids as $interface_id ) {
-     if ($api->DeleteInterface( intval( $interface_id )) != 1) 
-       $success=false;
-     else
-       $counter++;
-   }
-   if ($success) 
-     drupal_set_message ("Deleted $counter interface(s)");
-   else
-     drupal_set_error ("Could not delete all selected interfaces, only $counter were removed");
-   plc_redirect(l_node($_POST['node_id']));
- }
-
- case 'new-interface': {
-   plc_redirect(l_interface_add($_POST['node_id']));
- }
-
- case 'add-interface': {
-   $node_id=intval($_POST['node_id']);
-   foreach ($interface_details as $field) {
-     $interface[$field]= $_POST[$field];
-     // these must be integers
-     if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
-       if ( empty ($interface[$field]) ) 
-        unset ($interface[$field]);
-       else 
-        $interface[$field]= intval( $interface[$field] );
-     }
-   }
-   $interface_id =$api->AddInterface( $node_id , $interface );
-   if ($interface_id <= 0 ) {
-     drupal_set_error ("Could not create interface");
-     drupal_set_error ($api->error());
-   } else {
-     $ip=$interface['ip'];
-     drupal_set_message ("Interface $ip added into node $node_id");
-     if ($_POST['is-virtual']) {
-       $ifname=$_POST['ifname'];
-       if ($api->AddInterfaceTag($interface_id,"ifname",$ifname) <= 0) 
-        drupal_set_error ("Could not set tag 'ifname'=$ifname");
-       else 
-        drupal_set_message ("Set tag 'ifname'=$ifname");
-       $alias=$_POST['alias'];
-       // deafult to interface_id
-       if ( ! $alias ) $alias=strval($interface_id);
-       if ($api->AddInterfaceTag($interface_id,"alias",$alias) <= 0) 
-        drupal_set_error ("Could not set tag 'alias'=$alias");
-       else 
-        drupal_set_message ("Set tag 'alias'=$alias");
-     }
-   }
-   plc_redirect (l_node_interfaces($node_id));
- }
-   
- case 'update-interface': {
-   $interface_id=$_POST['interface_id'];
-   foreach ($interface_details as $field) {
-     $interface[$field]= $_POST[$field];
-     if( in_array( $field, array( 'bwlimit', 'node_id' ) ) ) {
-       if ( intval($interface[$field]) != 0 ) {
-           $interface[$field]= intval( $interface[$field]);
-       } elseif ($field=='bwlimit' ) {
-           $interface[$field] = NULL;
-       }
-     }
-   }
-   $result=$api->UpdateInterface( intval( $interface_id ), $interface );
-   if ($result == 1 ) 
-     drupal_set_message ("Interface $interface_id updated");
-   else
-     drupal_set_error ("Could not update interface: " . $api->error());
-   plc_redirect (l_interface($interface_id));
- }
-   
+    case 'delete-interfaces':{
+            $interface_ids = $_POST['interface_ids'];
+            if (!$interface_ids) {
+                drupal_set_message("action=$action - No interface selected");
+                return;
+            }
+            $success = true;
+            $counter = 0;
+            foreach ($interface_ids as $interface_id) {
+                if ($api->DeleteInterface(intval($interface_id)) != 1) {
+                    $success = false;
+                } else {
+                    $counter++;
+                }
+
+            }
+            if ($success) {
+                drupal_set_message("Deleted $counter interface(s)");
+            } else {
+                drupal_set_error("Could not delete all selected interfaces, only $counter were removed");
+            }
+
+            plc_redirect(l_node($_POST['node_id']));
+        }
+
+    case 'new-interface':{
+            plc_redirect(l_interface_add($_POST['node_id']));
+        }
+
+    case 'add-interface':{
+            $node_id = intval($_POST['node_id']);
+            foreach ($interface_details as $field) {
+                $interface[$field] = $_POST[$field];
+                // these must be integers
+                if (in_array($field, array('bwlimit', 'node_id'))) {
+                    if (empty($interface[$field])) {
+                        unset($interface[$field]);
+                    } else {
+                        $interface[$field] = intval($interface[$field]);
+                    }
+
+                }
+            }
+            $interface_id = $api->AddInterface($node_id, $interface);
+            if ($interface_id <= 0) {
+                drupal_set_error("Could not create interface");
+                drupal_set_error($api->error());
+            } else {
+                $ip = $interface['ip'];
+                drupal_set_message("Interface $ip added into node $node_id");
+                if ($_POST['is-virtual']) {
+                    $ifname = $_POST['ifname'];
+                    if ($api->AddInterfaceTag($interface_id, "ifname", $ifname) <= 0) {
+                        drupal_set_error("Could not set tag 'ifname'=$ifname");
+                    } else {
+                        drupal_set_message("Set tag 'ifname'=$ifname");
+                    }
+
+                    $alias = $_POST['alias'];
+                    // deafult to interface_id
+                    if (!$alias) {
+                        $alias = strval($interface_id);
+                    }
+
+                    if ($api->AddInterfaceTag($interface_id, "alias", $alias) <= 0) {
+                        drupal_set_error("Could not set tag 'alias'=$alias");
+                    } else {
+                        drupal_set_message("Set tag 'alias'=$alias");
+                    }
+
+                }
+            }
+            plc_redirect(l_node_interfaces($node_id));
+        }
+
+    case 'update-interface':{
+            $interface_id = $_POST['interface_id'];
+            foreach ($interface_details as $field) {
+                $interface[$field] = $_POST[$field];
+                if (in_array($field, array('bwlimit', 'node_id'))) {
+                    if (intval($interface[$field]) != 0) {
+                        $interface[$field] = intval($interface[$field]);
+                    } elseif ($field == 'bwlimit') {
+                        $interface[$field] = null;
+                    }
+                }
+            }
+            $result = $api->UpdateInterface(intval($interface_id), $interface);
+            if ($result == 1) {
+                drupal_set_message("Interface $interface_id updated");
+            } else {
+                drupal_set_error("Could not update interface: " . $api->error());
+            }
+
+            plc_redirect(l_interface($interface_id));
+        }
+
 //////////////////////////////////////////////////////////// sites
 //////////////////////////////////////////////////////////// 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());
-   break;
- }
-
- 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));
-   break;
- }
-
- case 'update-site': {
-   $site_id=intval($_POST['site_id']);
-   $name= $_POST['name'];
-   $abbreviated_name= $_POST['abbreviated_name'];
-   $url= $_POST['url'];
-   $latitude= floatval($_POST['latitude']);
-   $longitude= floatval($_POST['longitude']);
-   //$max_slivers= $_POST['max_slivers'];
-   
-   $fields= array( "name" => $name, 
-                  "abbreviated_name" => $abbreviated_name, 
-                  "url" => $url, 
-                  "latitude" => floatval( $latitude ), 
-                  "longitude" => floatval( $longitude ));
-
-   if ($_POST['login_base']) 
-     $fields['login_base'] = $_POST['login_base'];
-   if (isset($_POST['max_slices']))
-     $fields['max_slices'] = intval($_POST['max_slices']);
-   if (isset($_POST['enabled'])) {
-     $fields['enabled'] = (bool)$_POST['enabled'];
-   }
-   
-   $retcod=$api->UpdateSite( intval( $site_id ), $fields );
-   if ($retcod == 1) 
-     drupal_set_message("Site $name updated");
-   else 
-     drupal_set_error ("Could not update site $site_id");
-     
-   plc_redirect(l_site($site_id));
-   break;
- }
+    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());
+            break;
+        }
+
+    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));
+            break;
+        }
+
+    case 'update-site':{
+            $site_id = intval($_POST['site_id']);
+            $name = $_POST['name'];
+            $abbreviated_name = $_POST['abbreviated_name'];
+            $url = $_POST['url'];
+            $latitude = floatval($_POST['latitude']);
+            $longitude = floatval($_POST['longitude']);
+            //$max_slivers= $_POST['max_slivers'];
+
+            $fields = array("name" => $name,
+                "abbreviated_name" => $abbreviated_name,
+                "url" => $url,
+                "latitude" => floatval($latitude),
+                "longitude" => floatval($longitude));
+
+            if ($_POST['login_base']) {
+                $fields['login_base'] = $_POST['login_base'];
+            }
+
+            if (isset($_POST['max_slices'])) {
+                $fields['max_slices'] = intval($_POST['max_slices']);
+            }
+
+            if (isset($_POST['enabled'])) {
+                $fields['enabled'] = (bool) $_POST['enabled'];
+            }
+
+            $retcod = $api->UpdateSite(intval($site_id), $fields);
+            if ($retcod == 1) {
+                drupal_set_message("Site $name updated");
+            } else {
+                drupal_set_error("Could not update site $site_id");
+            }
+
+            plc_redirect(l_site($site_id));
+            break;
+        }
 
 //////////////////////////////////////////////////////////// slices
 
 //////////////////////////////////////////////////////////// slices
- case 'delete-slice': {
-   $slice_id = $_POST['slice_id'];
-   if ($api->DeleteSlice( intval( $slice_id )) == 1 ) {
-     drupal_set_message("Slice $slice_id deleted");
-     plc_redirect(l_slices());
-   } else {
-     drupal_set_error("Could not delete slice $slice_id " . $api->error());
-   }
-   break;
- }
-     
- case 'update-slice': {
-   $slice_id = $_POST['slice_id'];
-   $name = $_POST['name'];
-   $description= $_POST['description'];
-   $url= $_POST['url'];
-
-   $fields= array( "description"=>$description, "url"=>$url );
-   $api->UpdateSlice( intval( $slice_id ), $fields );
-   $error= $api->error();
-
-   if( empty( $error ) ) {
-     drupal_set_message("Update slice $name");
-     plc_redirect(l_slice($slice_id));
-   } else {
-     drupal_set_error($error);
-   }
-   break;
- }
-
- case 'renew-slice': {
-   $slice_id = intval ($_POST['slice_id']);    
-   $expires = intval ($_POST['expires']);
-   // 8 weeks from now
-   // xxx
-   $now=mktime();
-   $WEEK=7*24*3600;
-   $WEEKS=8;
-   $MAX_FUTURE=$WEEKS*$WEEK;
-   if ( ($expires-$now) > $MAX_FUTURE) {
-     drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
-     plc_redirect(l_slice($slice_id));
-   }
-   if ($api->UpdateSlice ($slice_id, array('expires'=>$expires)) == 1)
-     drupal_set_message("Slice renewed");
-   else
-     drupal_set_error("Could not update slice $slice_id");
-   plc_redirect(l_slice($slice_id));
-   break;
- }
-
- case 'remove-persons-from-slice': {
-   $slice_id = intval ($_POST['slice_id']);    
-   $person_ids = $_POST['person_ids'];
-   $return_url = $_POST['return_url'];
-
-   if (!$return_url) {
-       $return_url = l_slice($slice_id) . "&show_persons=true" ;
-   }
-
-   $slice_name = "";
-   $tmp_slices = $api->GetSlices($slice_id, array("name"));
-   if (count($tmp_slices) > 0) {
-       $tmp_slice = $tmp_slices[0];
-       $slice_name = $tmp_slice["name"];
-   }
-   $notify_subject = "Removed from slice: " . $slice_name;
-   $notify_body = sprintf("You have been removed from the slice %s.
+    case 'delete-slice':{
+            $slice_id = $_POST['slice_id'];
+            if ($api->DeleteSlice(intval($slice_id)) == 1) {
+                drupal_set_message("Slice $slice_id deleted");
+                plc_redirect(l_slices());
+            } else {
+                drupal_set_error("Could not delete slice $slice_id " . $api->error());
+            }
+            break;
+        }
+
+    case 'update-slice':{
+            $slice_id = $_POST['slice_id'];
+            $name = $_POST['name'];
+            $description = $_POST['description'];
+            $url = $_POST['url'];
+
+            $fields = array("description" => $description, "url" => $url);
+            $api->UpdateSlice(intval($slice_id), $fields);
+            $error = $api->error();
+
+            if (empty($error)) {
+                drupal_set_message("Update slice $name");
+                plc_redirect(l_slice($slice_id));
+            } else {
+                drupal_set_error($error);
+            }
+            break;
+        }
+
+    case 'renew-slice': {
+            $slice_id = intval($_POST['slice_id']);
+            $expires = intval($_POST['expires']);
+            // 8 weeks from now
+            // xxx
+            $now = time();
+            $WEEK = 7 * 24 * 3600;
+            $WEEKS = 8;
+            $MAX_FUTURE = $WEEKS * $WEEK;
+            if (($expires - $now) > $MAX_FUTURE) {
+                drupal_set_error("Cannot renew slice that far in the future, max is $WEEKS weeks from now");
+                plc_redirect(l_slice($slice_id));
+            }
+            if ($api->UpdateSlice($slice_id, array('expires' => $expires)) == 1) {
+                drupal_set_message("Slice renewed");
+            } else {
+                drupal_set_error("Could not update slice $slice_id");
+            }
+
+            plc_redirect(l_slice($slice_id));
+            break;
+        }
+
+    case 'remove-persons-from-slice':{
+            $slice_id = intval($_POST['slice_id']);
+            $person_ids = $_POST['person_ids'];
+            $return_url = $_POST['return_url'];
+
+            if (!$return_url) {
+                $return_url = l_slice($slice_id) . "&show_persons=true";
+            }
+
+            $slice_name = "";
+            $tmp_slices = $api->GetSlices($slice_id, array("name"));
+            if (count($tmp_slices) > 0) {
+                $tmp_slice = $tmp_slices[0];
+                $slice_name = $tmp_slice["name"];
+            }
+            $notify_subject = "Removed from slice: " . $slice_name;
+            $notify_body = sprintf("You have been removed from the slice %s.
 
 Our support team will be glad to answer any question that you might have.
 
 Our support team will be glad to answer any question that you might have.
-",$slice_name);
-   $notify_person_ids = array();
-
-   $success=true;
-   $counter=0;
-   foreach( $person_ids as $person_id ) {
-     if ($api->DeletePersonFromSlice(intval($person_id),$slice_id) != 1)
-       $success=false;
-     else {
-         array_push($notify_person_ids, intval($person_id));
-       $counter++;
-     }
-   }
-   if ($success) {
-     $adm->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
-     drupal_set_message ("Deleted $counter person(s)");
-   }
-   else
-     drupal_set_error ("Could not delete all selected persons, only $counter were removed");
-   plc_redirect($return_url);
-   break;
- }
-
- case 'add-persons-in-slice': {
-   $slice_id = intval ($_POST['slice_id']);    
-   $person_ids = $_POST['person_ids'];
-   $return_url = $_POST['return_url'];
-
-   if (!$return_url) {
-       $return_url = l_slice($slice_id) . "&show_persons=true" ;
-   }
-
-   $slice_name = "";
-   $tmp_slices = $api->GetSlices($slice_id, array("name"));
-   if (count($tmp_slices) > 0) {
-     $tmp_slice = $tmp_slices[0];
-     $slice_name = $tmp_slice["name"];
-   }
-   $notify_subject = "Added to slice: " . $slice_name;
-   $notify_body = sprintf("You have been added to the slice %s as a user.
+", $slice_name);
+            $notify_person_ids = array();
+
+            $success = true;
+            $counter = 0;
+            foreach ($person_ids as $person_id) {
+                if ($api->DeletePersonFromSlice(intval($person_id), $slice_id) != 1) {
+                    $success = false;
+                } else {
+                    array_push($notify_person_ids, intval($person_id));
+                    $counter++;
+                }
+            }
+            if ($success) {
+                $adm->NotifyPersons($notify_person_ids, $notify_subject, $notify_body);
+                drupal_set_message("Deleted $counter person(s)");
+            } else {
+                drupal_set_error("Could not delete all selected persons, only $counter were removed");
+            }
+
+            plc_redirect($return_url);
+            break;
+        }
+
+    case 'add-persons-in-slice':{
+            $slice_id = intval($_POST['slice_id']);
+            $person_ids = $_POST['person_ids'];
+            $return_url = $_POST['return_url'];
+
+            if (!$return_url) {
+                $return_url = l_slice($slice_id) . "&show_persons=true";
+            }
+
+            $slice_name = "";
+            $tmp_slices = $api->GetSlices($slice_id, array("name"));
+            if (count($tmp_slices) > 0) {
+                $tmp_slice = $tmp_slices[0];
+                $slice_name = $tmp_slice["name"];
+            }
+            $notify_subject = "Added to slice: " . $slice_name;
+            $notify_body = sprintf("You have been added to the slice %s as a user.
 
 You can go to your slice page following the link below:
 https://%s:%d/db/slices/index.php?id=%d
 
 Our support team will be glad to answer any question that you might have.
 
 You can go to your slice page following the link below:
 https://%s:%d/db/slices/index.php?id=%d
 
 Our support team will be glad to answer any question that you might have.
-",$slice_name,PLC_WWW_HOST,PLC_WWW_SSL_PORT,$slice_id);
-   $notify_person_ids = array();
-
-   $success=true;
-   $counter=0;
-   foreach ($person_ids as $person_id) {
-     if ($api->AddPersonToSlice(intval($person_id),$slice_id) != 1)
-       $success=false;
-     else {
-       array_push($notify_person_ids, intval($person_id));
-       $counter++;
-     }
-   }
-   if ($success) {
-     $adm->NotifyPersons($notify_person_ids,$notify_subject,$notify_body);
-     drupal_set_message ("Added $counter person(s)");
-   }
-   else
-     drupal_set_error ("Could not add all selected persons, only $counter were added");
-   plc_redirect($return_url);
-   break;
- }
-
- case 'remove-nodes-from-slice': {
-   $slice_id = intval ($_POST['slice_id']);    
-   $node_ids = array_map("intval",$_POST['node_ids']);
-   $count=count($node_ids);
-   
-   if ($api->DeleteSliceFromNodes($slice_id,$node_ids) == 1) 
-     drupal_set_message ("Removed $count node(s)");
-   else
-     drupal_set_error ("Could not remove selected nodes");
-   plc_redirect(l_slice_nodes($slice_id));
-   break;
- }
-
- case 'add-nodes-in-slice': {
-   $slice_id = intval ($_POST['slice_id']);    
-   $node_ids = array_map("intval",$_POST['node_ids']);
-   $count=count($node_ids);
-   if ($api->AddSliceToNodes($slice_id,$node_ids) == 1) 
-     drupal_set_message ("Added $count node(s)");
-   else
-     drupal_set_error ("Could not add all selected nodes");
-   plc_redirect(l_slice_nodes($slice_id));
-   break;
- }
-
- case 'update-initscripts': {
-//     expects:        slice_id & name & previous-initscript & previous-initscript-code 
-//                     & initscript & initscript-code
-   $slice_id = intval ($_POST['slice_id']);    
-   $previous_initscript=$_POST['previous-initscript'];
-   $initscript=$_POST['initscript'];
-   $previous_initscript_code=html_entity_decode($_POST['previous-initscript-code']);
-   $initscript_code=$_POST['initscript-code'];
-
-   $changes=FALSE;
-   if (strcmp($initscript,$previous_initscript) != 0) {
-     $newvalue=$api->SetSliceInitscript($slice_id,$initscript);
-     $status = (strcmp($newvalue,$initscript)==0) ? "OK" : "failed";
-     if (! $initscript)                drupal_set_message("Removed shared initscript '" . $previous_initscript . "' " . $status);
-     else                      drupal_set_message("Replaced shared initscript with '" . $initscript . "' " . $status);
-     $changes=TRUE;
-   }
-
-   // somehow some \r chars make it here; just ignore them
-   $previous_initscript_code=str_replace("\r","",$previous_initscript_code);
-   //   plc_debug_txt('previous initscript_code after cr',$previous_initscript_code);
-
-   $initscript_code=str_replace("\r","",$initscript_code);
-   // make sure the script ends with a single \n 
-   $initscript_code=trim($initscript_code);
-   if (!empty($initscript_code) && $initscript_code[strlen($initscript_code)-1] != "\n")
-     $initscript_code.="\n";
-   // plc_debug_txt('initscript_code after cr & nl/eof',$initscript_code);
-
-   if (strcmp($initscript_code,$previous_initscript_code) != 0) {
-     $newvalue=$api->SetSliceInitscriptCode($slice_id,$initscript_code);
-     // plc_debug_txt('newvalue',$newvalue);
-     $status=(strcmp($newvalue,$initscript_code)==0) ? "OK" : "failed";
-     if (! $initscript_code)   drupal_set_message("Removed initscript code " . $status);
-     else                      drupal_set_message("Installed new initscript code " . $status);
-     $changes=TRUE;
-   }
-   if (!$changes) drupal_set_message("No changes required in initscript");
-   plc_redirect(l_slice($slice_id) . "&show_details=0&show_initscripts=1" );
-   break;
- }
-
-
- case 'delete-slice-tags': {
-   $slice_id = intval($_POST['slice_id']);
-   $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
-   $count = 0;
-   $success = true;
-   foreach($slice_tag_ids as $slice_tag_id) {
-     if ($api->DeleteSliceTag($slice_tag_id)) $count += 1;
-     else {
-       drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
-       $success = false;
-     }
-   }
-   if ($success)
-     drupal_set_message ("Deleted $count slice tag(s)");
-   plc_redirect(l_slice($slice_id) . "&show_tags=1" );
-   break;
- }
-  
- case 'add-slice-tag': {
-   $slice_id = intval($_POST['slice_id']);
-   $tag_type_id = intval($_POST['tag_type_id']);
-   $value = $_POST['value'];
-   $node_id = intval($_POST['node_id']);
-   $nodegroup_id = intval($_POST['nodegroup_id']);
-  
-   $result = null;
-   if ($node_id) {
-     $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
-   } elseif ($nodegroup_id) {
-     $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
-   } else {
-     $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
-   }
-   if ($result)
-     drupal_set_message ("Added slice tag.");
-   else 
-       drupal_set_error("Could not add slice tag");
-   if ($_POST['sliver_action'])
-       plc_redirect(l_sliver($node_id,$slice_id));
-   else
-       plc_redirect(l_slice($slice_id) . "&show_tags=true" );
-   break;
- }
+", $slice_name, PLC_WWW_HOST, PLC_WWW_SSL_PORT, $slice_id);
+            $notify_person_ids = array();
+
+            $success = true;
+            $counter = 0;
+            foreach ($person_ids as $person_id) {
+                if ($api->AddPersonToSlice(intval($person_id), $slice_id) != 1) {
+                    $success = false;
+                } else {
+                    array_push($notify_person_ids, intval($person_id));
+                    $counter++;
+                }
+            }
+            if ($success) {
+                $adm->NotifyPersons($notify_person_ids, $notify_subject, $notify_body);
+                drupal_set_message("Added $counter person(s)");
+            } else {
+                drupal_set_error("Could not add all selected persons, only $counter were added");
+            }
+
+            plc_redirect($return_url);
+            break;
+        }
+
+    case 'remove-nodes-from-slice':{
+            $slice_id = intval($_POST['slice_id']);
+            $node_ids = array_map("intval", $_POST['node_ids']);
+            $count = count($node_ids);
+
+            if ($api->DeleteSliceFromNodes($slice_id, $node_ids) == 1) {
+                drupal_set_message("Removed $count node(s)");
+            } else {
+                drupal_set_error("Could not remove selected nodes");
+            }
+
+            plc_redirect(l_slice_nodes($slice_id));
+            break;
+        }
+
+    case 'add-nodes-in-slice':{
+            $slice_id = intval($_POST['slice_id']);
+            $node_ids = array_map("intval", $_POST['node_ids']);
+            $count = count($node_ids);
+            if ($api->AddSliceToNodes($slice_id, $node_ids) == 1) {
+                drupal_set_message("Added $count node(s)");
+            } else {
+                drupal_set_error("Could not add all selected nodes");
+            }
+
+            plc_redirect(l_slice_nodes($slice_id));
+            break;
+        }
+
+    case 'update-initscripts':{
+//    expects:    slice_id & name & previous-initscript & previous-initscript-code
+            //            & initscript & initscript-code
+            $slice_id = intval($_POST['slice_id']);
+            $previous_initscript = $_POST['previous-initscript'];
+            $initscript = $_POST['initscript'];
+            $previous_initscript_code = html_entity_decode($_POST['previous-initscript-code']);
+            $initscript_code = $_POST['initscript-code'];
+
+            $changes = false;
+            if (strcmp($initscript, $previous_initscript) != 0) {
+                $newvalue = $api->SetSliceInitscript($slice_id, $initscript);
+                $status = (strcmp($newvalue, $initscript) == 0) ? "OK" : "failed";
+                if (!$initscript) {
+                    drupal_set_message("Removed shared initscript '" . $previous_initscript . "' " . $status);
+                } else {
+                    drupal_set_message("Replaced shared initscript with '" . $initscript . "' " . $status);
+                }
+
+                $changes = true;
+            }
+
+            // somehow some \r chars make it here; just ignore them
+            $previous_initscript_code = str_replace("\r", "", $previous_initscript_code);
+            //   plc_debug_txt('previous initscript_code after cr',$previous_initscript_code);
+
+            $initscript_code = str_replace("\r", "", $initscript_code);
+            // make sure the script ends with a single \n
+            $initscript_code = trim($initscript_code);
+            if (!empty($initscript_code) && $initscript_code[strlen($initscript_code) - 1] != "\n") {
+                $initscript_code .= "\n";
+            }
+
+            // plc_debug_txt('initscript_code after cr & nl/eof',$initscript_code);
+
+            if (strcmp($initscript_code, $previous_initscript_code) != 0) {
+                $newvalue = $api->SetSliceInitscriptCode($slice_id, $initscript_code);
+                // plc_debug_txt('newvalue',$newvalue);
+                $status = (strcmp($newvalue, $initscript_code) == 0) ? "OK" : "failed";
+                if (!$initscript_code) {
+                    drupal_set_message("Removed initscript code " . $status);
+                } else {
+                    drupal_set_message("Installed new initscript code " . $status);
+                }
+
+                $changes = true;
+            }
+            if (!$changes) {
+                drupal_set_message("No changes required in initscript");
+            }
+
+            plc_redirect(l_slice($slice_id) . "&show_details=0&show_initscripts=1");
+            break;
+        }
+
+    case 'delete-slice-tags':{
+            $slice_id = intval($_POST['slice_id']);
+            $slice_tag_ids = array_map("intval", $_POST['slice_tag_ids']);
+            $count = 0;
+            $success = true;
+            foreach ($slice_tag_ids as $slice_tag_id) {
+                if ($api->DeleteSliceTag($slice_tag_id)) {
+                    $count += 1;
+                } else {
+                    drupal_set_error("Could not delete slice tag: slice_tag_id = $slice_tag_id");
+                    $success = false;
+                }
+            }
+            if ($success) {
+                drupal_set_message("Deleted $count slice tag(s)");
+            }
+
+            plc_redirect(l_slice($slice_id) . "&show_tags=1");
+            break;
+        }
+
+    case 'add-slice-tag':{
+            $slice_id = intval($_POST['slice_id']);
+            $tag_type_id = intval($_POST['tag_type_id']);
+            $value = $_POST['value'];
+            $node_id = intval($_POST['node_id']);
+            $nodegroup_id = intval($_POST['nodegroup_id']);
+
+            $result = null;
+            if ($node_id) {
+                $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, $node_id);
+            } elseif ($nodegroup_id) {
+                $result = $api->AddSliceTag($slice_id, $tag_type_id, $value, null, $nodegroup_id);
+            } else {
+                $result = $api->AddSliceTag($slice_id, $tag_type_id, $value);
+            }
+            if ($result) {
+                drupal_set_message("Added slice tag.");
+            } else {
+                drupal_set_error("Could not add slice tag");
+            }
+
+            if ($_POST['sliver_action']) {
+                plc_redirect(l_sliver($node_id, $slice_id));
+            } else {
+                plc_redirect(l_slice($slice_id) . "&show_tags=true");
+            }
+
+            break;
+        }
 
 //////////////////////////////////////////////////////////// tag types
 
 
 //////////////////////////////////////////////////////////// tag types
 
- case 'update-tag-type': {
-  // get post vars 
-   $tag_type_id= intval( $_POST['tag_type_id'] );
-   $tagname = $_POST['tagname'];
-   $min_role_id= intval( $_POST['min_role_id'] );
-   $description= $_POST['description'];  
-   $category= $_POST['category'];
-  
-   // make tag_type_fields dict
-   $tag_type_fields= array( "min_role_id" => $min_role_id, 
-                           "tagname" => $tagname, 
-                           "description" => $description,
-                           "category" => $category,
-                           );
-
-   if ($api->UpdateTagType( $tag_type_id, $tag_type_fields ) == 1) 
-     drupal_set_message ("Tag type $tagname updated");
-   else 
-     drupal_set_error ("Could not update tag type $tag_type_id\n".$api->error());
-   plc_redirect(l_tag($tag_type_id));
-   break;
- }
-
- case 'add-tag-type': {
-  // get post vars 
-   $tagname = $_POST['tagname'];
-   $min_role_id= intval( $_POST['min_role_id'] );
-   $description= $_POST['description'];  
-   $category= $_POST['category'];  
-  
-   // make tag_type_fields dict
-   $tag_type_fields= array( "min_role_id" => $min_role_id, 
-                           "tagname" => $tagname, 
-                           "description" => $description,
-                           "category" => $category,
-                           );
-
-  // Add it!
-   $tag_type_id=$api->AddTagType( $tag_type_fields );
-   if ($tag_type_id > 0) 
-     drupal_set_message ("tag type $tag_type_id created");
-   else
-     drupal_set_error ("Could not create tag type $tagname");
-   plc_redirect( l_tags());
-   break;
- }
-
- case 'delete-tag-types': {
-   $tag_type_ids = $_POST['tag_type_ids'];
-   if ( ! $tag_type_ids) {
-     drupal_set_message("action=$action - No tag selected");
-     return;
-   }
-   $success=true;
-   $counter=0;
-   foreach ($tag_type_ids as $tag_type_id) 
-     if ($api->DeleteTagType(intval($tag_type_id)) != 1) 
-       $success=false;
-     else
-       $counter++;
-   if ($success) 
-     drupal_set_message ("Deleted $counter tag(s)");
-   else
-     drupal_set_error ("Could not delete all selected tags, only $counter were removed");
-   plc_redirect (l_tags());
-   break;
- }
-
- case 'remove-roles-from-tag-type' : {
-   $tag_type_id=$_POST['tag_type_id'];
-   $role_ids=$_POST['role_ids'];
-   if ( ! $role_ids) {
-     drupal_set_error("You have not selected role(s) to remove");
-   } else {
-     foreach( $role_ids as $role_id)  
-       if ( $api->DeleteRoleFromTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1 ) 
-        drupal_set_error ("Could not remove role $role_id from tag type $tag_type_id");
-   }
-   plc_redirect (l_tag_roles($tag_type_id));
- }
-     
- case 'add-role-to-tag-type' : {
-   $tag_type_id=$_POST['tag_type_id'];
-   $role_id=$_POST['role_id'];
-   if ( ! $role_id) {
-     drupal_set_error ("You have not selected a role to add");
-   } else if ($api->AddRoleToTagType( intval( $role_id ), intval( $tag_type_id ) ) != 1) {
-     drupal_set_error("Could not add role $role_id to tag $tag_type_id");
-   }
-   plc_redirect (l_tag_roles($tag_type_id));
- }
-
-//////////////////////////////////////// tags   
- case 'set-tag-on-node': 
- case 'set-tag-on-site': 
- case 'set-tag-on-person': 
- case 'set-tag-on-interface': 
-   {
-   
-   $mode = NULL;
-   if ($action == 'set-tag-on-node') $mode='node';
-   if ($action == 'set-tag-on-site') $mode='site';
-   if ($action == 'set-tag-on-person') $mode='person';
-   if ($action == 'set-tag-on-interface') $mode='interface';
-
-   if ($mode=='node') 
-     $id = intval($_POST['node_id']);
-   else if ($mode=='site')
-     $id = intval($_POST['site_id']);
-   else if ($mode=='person')
-     $id = intval($_POST['person_id']);
-   else 
-     $id = intval($_POST['interface_id']);
-   $tag_type_id = intval($_POST['tag_type_id']);
-   $value = $_POST['value'];
-
-   $tag_types=$api->GetTagTypes(array($tag_type_id));
-   if (count ($tag_types) != 1) {
-     drupal_set_error ("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
-   } else {
-     if ($mode=='node') 
-       $tags = $api->GetNodeTags (array('node_id'=>$id, 'tag_type_id'=> $tag_type_id));
-     else if ($mode=='site')
-       $tags = $api->GetSiteTags (array('site_id'=>$id, 'tag_type_id'=> $tag_type_id));
-     else if ($mode=='person')
-       $tags = $api->GetPersonTags (array('person_id'=>$id, 'tag_type_id'=> $tag_type_id));
-     else
-       $tags = $api->GetInterfaceTags (array('interface_id'=>$id, 'tag_type_id'=> $tag_type_id));
-
-     // already has a tag set
-     if ( count ($tags) == 1) {
-       $tag=$tags[0];
-       if ($mode=='node') 
-        $result=$api->UpdateNodeTag($tag['node_tag_id'],$value);
-       else if ($mode=='site') 
-        $result=$api->UpdateSiteTag($tag['site_tag_id'],$value);
-       else if ($mode=='person') 
-        $result=$api->UpdatePersonTag($tag['person_tag_id'],$value);
-       else 
-        $result=$api->UpdateInterfaceTag($tag['interface_tag_id'],$value);
-
-       if ($result == 1) 
-        drupal_set_message ("Updated tag, new value = $value");
-       else
-        drupal_set_error ("Could not update tag");
-
-     // no such tag set yet on that object
-     } else {
-       if ($mode=='node')
-        $tag_id = $api->AddNodeTag($id,$tag_type_id,$value);
-       else if ($mode=='site')
-        $tag_id = $api->AddSiteTag($id,$tag_type_id,$value);
-       else if ($mode=='person')
-        $tag_id = $api->AddPersonTag($id,$tag_type_id,$value);
-       else
-        $tag_id = $api->AddInterfaceTag($id,$tag_type_id,$value);
-       if ($tag_id) 
-        drupal_set_message ("Created tag, new value = $value");
-       else
-        drupal_set_error ("Could not create tag");
-     }
-   }
-   
-   if ($mode=='node')
-     plc_redirect (l_node_tags($id));
-   else if ($mode=='site')
-     plc_redirect (l_site_tags($id));
-   else if ($mode=='person')
-     plc_redirect (l_person_tags($id));
-   else
-     plc_redirect (l_interface_tags($id));
- }
-
- case 'delete-node-tags': 
- case 'delete-site-tags':
- case 'delete-person-tags':
- case 'delete-interface-tags': {
-
-   $mode = NULL;
-   if ($action == 'delete-node-tags') $mode='node';
-   if ($action == 'delete-site-tags') $mode='site';
-   if ($action == 'delete-person-tags') $mode='person';
-   if ($action == 'delete-interface-tags') $mode='interface';
-
-   if ($mode=='node') {
-     $id=$_POST['node_id'];
-     $tag_ids=$_POST['node_tag_ids'];
-   } else if ($mode=='site') {
-     $id=$_POST['site_id'];
-     $tag_ids=$_POST['site_tag_ids'];
-   } else if ($mode=='person') {
-     $id=$_POST['person_id'];
-     $tag_ids=$_POST['person_tag_ids'];
-   } else {
-     $id=$_POST['interface_id'];
-     $tag_ids=$_POST['interface_tag_ids'];
-   }
-
-   if ( ! $tag_ids) {
-     drupal_set_message("action=$action - No tag selected");
-     return;
-   }
-   $success=true;
-   $counter=0;
-   foreach( $tag_ids as $tag_id ) {
-     if ($mode=='node') 
-       $retcod = $api->DeleteNodeTag( intval( $tag_id ));
-     else if ($mode=='site')
-       $retcod = $api->DeleteSiteTag( intval( $tag_id ));
-     else if ($mode=='person')
-       $retcod = $api->DeletePersonTag( intval( $tag_id ));
-     else
-       $retcod = $api->DeleteInterfaceTag( intval( $tag_id ));
-     if ($retcod != 1) 
-       $success=false;
-     else
-       $counter++;
-   }
-   if ($success) 
-     drupal_set_message ("Deleted $counter tag(s)");
-   else
-     drupal_set_error ("Could not delete all selected tags, only $counter were removed");
-
-   if ($mode=='node')
-     plc_redirect (l_node_tags($id));
-   else if ($mode=='site')
-     plc_redirect (l_site_tags($id));
-   else if ($mode=='person')
-     plc_redirect (l_person_tags($id));
-   else
-     plc_redirect (l_interface_tags($id));
-
- }
+    case 'update-tag-type':{
+            // get post vars
+            $tag_type_id = intval($_POST['tag_type_id']);
+            $tagname = $_POST['tagname'];
+            $min_role_id = intval($_POST['min_role_id']);
+            $description = $_POST['description'];
+            $category = $_POST['category'];
+
+            // make tag_type_fields dict
+            $tag_type_fields = array("min_role_id" => $min_role_id,
+                "tagname" => $tagname,
+                "description" => $description,
+                "category" => $category,
+            );
+
+            if ($api->UpdateTagType($tag_type_id, $tag_type_fields) == 1) {
+                drupal_set_message("Tag type $tagname updated");
+            } else {
+                drupal_set_error("Could not update tag type $tag_type_id\n" . $api->error());
+            }
+
+            plc_redirect(l_tag($tag_type_id));
+            break;
+        }
+
+    case 'add-tag-type':{
+            // get post vars
+            $tagname = $_POST['tagname'];
+            $min_role_id = intval($_POST['min_role_id']);
+            $description = $_POST['description'];
+            $category = $_POST['category'];
+
+            // make tag_type_fields dict
+            $tag_type_fields = array("min_role_id" => $min_role_id,
+                "tagname" => $tagname,
+                "description" => $description,
+                "category" => $category,
+            );
+
+            // Add it!
+            $tag_type_id = $api->AddTagType($tag_type_fields);
+            if ($tag_type_id > 0) {
+                drupal_set_message("tag type $tag_type_id created");
+            } else {
+                drupal_set_error("Could not create tag type $tagname");
+            }
+
+            plc_redirect(l_tags());
+            break;
+        }
+
+    case 'delete-tag-types':{
+            $tag_type_ids = $_POST['tag_type_ids'];
+            if (!$tag_type_ids) {
+                drupal_set_message("action=$action - No tag selected");
+                return;
+            }
+            $success = true;
+            $counter = 0;
+            foreach ($tag_type_ids as $tag_type_id) {
+                if ($api->DeleteTagType(intval($tag_type_id)) != 1) {
+                    $success = false;
+                } else {
+                    $counter++;
+                }
+            }
+
+            if ($success) {
+                drupal_set_message("Deleted $counter tag(s)");
+            } else {
+                drupal_set_error("Could not delete all selected tags, only $counter were removed");
+            }
+
+            plc_redirect(l_tags());
+            break;
+        }
+
+    case 'remove-roles-from-tag-type':{
+            $tag_type_id = $_POST['tag_type_id'];
+            $role_ids = $_POST['role_ids'];
+            if (!$role_ids) {
+                drupal_set_error("You have not selected role(s) to remove");
+            } else {
+                foreach ($role_ids as $role_id) {
+                    if ($api->DeleteRoleFromTagType(intval($role_id), intval($tag_type_id)) != 1) {
+                        drupal_set_error("Could not remove role $role_id from tag type $tag_type_id");
+                    }
+                }
+
+            }
+            plc_redirect(l_tag_roles($tag_type_id));
+        }
+
+    case 'add-role-to-tag-type':{
+            $tag_type_id = $_POST['tag_type_id'];
+            $role_id = $_POST['role_id'];
+            if (!$role_id) {
+                drupal_set_error("You have not selected a role to add");
+            } else if ($api->AddRoleToTagType(intval($role_id), intval($tag_type_id)) != 1) {
+                drupal_set_error("Could not add role $role_id to tag $tag_type_id");
+            }
+            plc_redirect(l_tag_roles($tag_type_id));
+        }
+
+//////////////////////////////////////// tags
+    case 'set-tag-on-node':
+    case 'set-tag-on-site':
+    case 'set-tag-on-person':
+    case 'set-tag-on-interface':
+        {
+
+            $mode = null;
+            if ($action == 'set-tag-on-node') {
+                $mode = 'node';
+            }
+
+            if ($action == 'set-tag-on-site') {
+                $mode = 'site';
+            }
+
+            if ($action == 'set-tag-on-person') {
+                $mode = 'person';
+            }
+
+            if ($action == 'set-tag-on-interface') {
+                $mode = 'interface';
+            }
+
+            if ($mode == 'node') {
+                $id = intval($_POST['node_id']);
+            } else if ($mode == 'site') {
+                $id = intval($_POST['site_id']);
+            } else if ($mode == 'person') {
+                $id = intval($_POST['person_id']);
+            } else {
+                $id = intval($_POST['interface_id']);
+            }
+
+            $tag_type_id = intval($_POST['tag_type_id']);
+            $value = $_POST['value'];
+
+            $tag_types = $api->GetTagTypes(array($tag_type_id));
+            if (count($tag_types) != 1) {
+                drupal_set_error("Could not locate tag_type_id $tag_type_id </br> Tag not set.");
+            } else {
+                if ($mode == 'node') {
+                    $tags = $api->GetNodeTags(array('node_id' => $id, 'tag_type_id' => $tag_type_id));
+                } else if ($mode == 'site') {
+                    $tags = $api->GetSiteTags(array('site_id' => $id, 'tag_type_id' => $tag_type_id));
+                } else if ($mode == 'person') {
+                    $tags = $api->GetPersonTags(array('person_id' => $id, 'tag_type_id' => $tag_type_id));
+                } else {
+                    $tags = $api->GetInterfaceTags(array('interface_id' => $id, 'tag_type_id' => $tag_type_id));
+                }
+
+                // already has a tag set
+                if (count($tags) == 1) {
+                    $tag = $tags[0];
+                    if ($mode == 'node') {
+                        $result = $api->UpdateNodeTag($tag['node_tag_id'], $value);
+                    } else if ($mode == 'site') {
+                        $result = $api->UpdateSiteTag($tag['site_tag_id'], $value);
+                    } else if ($mode == 'person') {
+                        $result = $api->UpdatePersonTag($tag['person_tag_id'], $value);
+                    } else {
+                        $result = $api->UpdateInterfaceTag($tag['interface_tag_id'], $value);
+                    }
+
+                    if ($result == 1) {
+                        drupal_set_message("Updated tag, new value = $value");
+                    } else {
+                        drupal_set_error("Could not update tag");
+                    }
+
+                    // no such tag set yet on that object
+                } else {
+                    if ($mode == 'node') {
+                        $tag_id = $api->AddNodeTag($id, $tag_type_id, $value);
+                    } else if ($mode == 'site') {
+                        $tag_id = $api->AddSiteTag($id, $tag_type_id, $value);
+                    } else if ($mode == 'person') {
+                        $tag_id = $api->AddPersonTag($id, $tag_type_id, $value);
+                    } else {
+                        $tag_id = $api->AddInterfaceTag($id, $tag_type_id, $value);
+                    }
+
+                    if ($tag_id) {
+                        drupal_set_message("Created tag, new value = $value");
+                    } else {
+                        drupal_set_error("Could not create tag");
+                    }
+
+                }
+            }
+
+            if ($mode == 'node') {
+                plc_redirect(l_node_tags($id));
+            } else if ($mode == 'site') {
+                plc_redirect(l_site_tags($id));
+            } else if ($mode == 'person') {
+                plc_redirect(l_person_tags($id));
+            } else {
+                plc_redirect(l_interface_tags($id));
+            }
+
+        }
+
+    case 'delete-node-tags':
+    case 'delete-site-tags':
+    case 'delete-person-tags':
+    case 'delete-interface-tags':{
+
+            $mode = null;
+            if ($action == 'delete-node-tags') {
+                $mode = 'node';
+            }
+
+            if ($action == 'delete-site-tags') {
+                $mode = 'site';
+            }
+
+            if ($action == 'delete-person-tags') {
+                $mode = 'person';
+            }
+
+            if ($action == 'delete-interface-tags') {
+                $mode = 'interface';
+            }
+
+            if ($mode == 'node') {
+                $id = $_POST['node_id'];
+                $tag_ids = $_POST['node_tag_ids'];
+            } else if ($mode == 'site') {
+                $id = $_POST['site_id'];
+                $tag_ids = $_POST['site_tag_ids'];
+            } else if ($mode == 'person') {
+                $id = $_POST['person_id'];
+                $tag_ids = $_POST['person_tag_ids'];
+            } else {
+                $id = $_POST['interface_id'];
+                $tag_ids = $_POST['interface_tag_ids'];
+            }
+
+            if (!$tag_ids) {
+                drupal_set_message("action=$action - No tag selected");
+                return;
+            }
+            $success = true;
+            $counter = 0;
+            foreach ($tag_ids as $tag_id) {
+                if ($mode == 'node') {
+                    $retcod = $api->DeleteNodeTag(intval($tag_id));
+                } else if ($mode == 'site') {
+                    $retcod = $api->DeleteSiteTag(intval($tag_id));
+                } else if ($mode == 'person') {
+                    $retcod = $api->DeletePersonTag(intval($tag_id));
+                } else {
+                    $retcod = $api->DeleteInterfaceTag(intval($tag_id));
+                }
+
+                if ($retcod != 1) {
+                    $success = false;
+                } else {
+                    $counter++;
+                }
+
+            }
+            if ($success) {
+                drupal_set_message("Deleted $counter tag(s)");
+            } else {
+                drupal_set_error("Could not delete all selected tags, only $counter were removed");
+            }
+
+            if ($mode == 'node') {
+                plc_redirect(l_node_tags($id));
+            } else if ($mode == 'site') {
+                plc_redirect(l_site_tags($id));
+            } else if ($mode == 'person') {
+                plc_redirect(l_person_tags($id));
+            } else {
+                plc_redirect(l_interface_tags($id));
+            }
+
+        }
 
 //////////////////////////////////////// nodegroups
 
 //////////////////////////////////////// nodegroups
- case 'update-nodegroup': {
-   $nodegroup_id = $_POST['nodegroup_id'];
-   $groupname = $_POST['groupname'];
-   $value = $_POST['value'];
-
-   $fields=array();
-   $fields['groupname']=$groupname;
-   $fields['value']=$value;
-   if ( $api->UpdateNodeGroup($nodegroup_id,$fields) == 1) 
-     drupal_set_message ('Nodegroup updated');
-   else 
-     drupal_set_error ("Could not update nodegroup $groupname");
-   
-   plc_redirect(l_nodegroup($nodegroup_id));
-
- }
-
- case 'add-nodegroup': {
-   $groupname=$_POST['groupname'];
-   if ( ! $groupname ) {
-     drupal_set_error ('Empty groupname');
-     plc_redirect (l_nodegroups());
-   }
-   $tag_type_id=intval($_POST['tag_type_id']);
-   if ( ! $tag_type_id ) {
-     drupal_set_error ('You must select a tag in the dropdown list');
-     plc_redirect (l_nodegroups());
-   }
-   $value=$_POST['value'];
-   if ( ! $value ) {
-     drupal_set_message ("Empty value.. let's see ..");
-   }
-   if ( $api->AddNodeGroup ($groupname,$tag_type_id,$value) > 0) 
-     drupal_set_message ("Nodegroup $groupname created");
-   else
-     drupal_set_error ("Could not create nodegroup $groupname");
-
-   plc_redirect (l_nodegroups());
-   break;
- }
-
- case 'delete-nodegroups': {
-   $nodegroup_ids=$_POST['nodegroup_ids'];
-   if ( ! $nodegroup_ids ) {
-     drupal_set_message("action=delete-nodegroups - No group selected");
-     plc_redirect(l_nodegroups());
-   }
-   $success=true;
-   $counter=0;
-   foreach ($nodegroup_ids as $nodegroup_id) 
-     if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1) 
-       $success=false;
-     else
-       $counter++;
-   if ($success) 
-     drupal_set_message ("Deleted $counter group(s)");
-   else
-     drupal_set_error ("Could not delete all selected groups, only $counter were removed");
-   plc_redirect (l_nodegroups());
-   break;
- }
+    case 'update-nodegroup':{
+            $nodegroup_id = $_POST['nodegroup_id'];
+            $groupname = $_POST['groupname'];
+            $value = $_POST['value'];
+
+            $fields = array();
+            $fields['groupname'] = $groupname;
+            $fields['value'] = $value;
+            if ($api->UpdateNodeGroup($nodegroup_id, $fields) == 1) {
+                drupal_set_message('Nodegroup updated');
+            } else {
+                drupal_set_error("Could not update nodegroup $groupname");
+            }
+
+            plc_redirect(l_nodegroup($nodegroup_id));
+
+        }
+
+    case 'add-nodegroup':{
+            $groupname = $_POST['groupname'];
+            if (!$groupname) {
+                drupal_set_error('Empty groupname');
+                plc_redirect(l_nodegroups());
+            }
+            $tag_type_id = intval($_POST['tag_type_id']);
+            if (!$tag_type_id) {
+                drupal_set_error('You must select a tag in the dropdown list');
+                plc_redirect(l_nodegroups());
+            }
+            $value = $_POST['value'];
+            if (!$value) {
+                drupal_set_message("Empty value.. let's see ..");
+            }
+            if ($api->AddNodeGroup($groupname, $tag_type_id, $value) > 0) {
+                drupal_set_message("Nodegroup $groupname created");
+            } else {
+                drupal_set_error("Could not create nodegroup $groupname");
+            }
+
+            plc_redirect(l_nodegroups());
+            break;
+        }
+
+    case 'delete-nodegroups':{
+            $nodegroup_ids = $_POST['nodegroup_ids'];
+            if (!$nodegroup_ids) {
+                drupal_set_message("action=delete-nodegroups - No group selected");
+                plc_redirect(l_nodegroups());
+            }
+            $success = true;
+            $counter = 0;
+            foreach ($nodegroup_ids as $nodegroup_id) {
+                if ($api->DeleteNodeGroup(intval($nodegroup_id)) != 1) {
+                    $success = false;
+                } else {
+                    $counter++;
+                }
+            }
+
+            if ($success) {
+                drupal_set_message("Deleted $counter group(s)");
+            } else {
+                drupal_set_error("Could not delete all selected groups, only $counter were removed");
+            }
+
+            plc_redirect(l_nodegroups());
+            break;
+        }
 
 //////////////////////////////////////// leases
 
 //////////////////////////////////////// leases
- case 'manage-leases': {
-   $actions=json_decode($_POST['actions']);
-   $add_requested=0;
-   $add_done=0;
-   $del_requested=0;
-   $del_done=0;
-   $errors=array();
-   foreach ($actions as $action) {
-     if ($action[0] == 'add-leases') {
-       $nodenames=$action[1];
-       $add_requested += count($nodenames);
-       $slicename=$action[2];
-       $t_from=intval($action[3]);
-       $t_until=intval($action[4]);
-       $hash = $api->AddLeases($nodenames,$slicename,$t_from,$t_until);
-       // update number of added leases
-       $ids=$hash['new_ids'];
-       $add_done += count($ids);
-       // update global errors array
-       foreach ($api_errors=$hash['errors'] as $error) $errors[]=$error;
-     } else if ($action[0]=='delete-leases') {
-       $lease_id=intval($action[1]);
-       $del_requested += 1;
-       if ($api->DeleteLeases(array($lease_id)) == 1) {
-        $del_done += 1;
-       } else {
-        $errors []= "Could not delete lease " . $lease_id;
-       }
-     } else {
-       $errors []= "in actions.php, manage-leases, wrong action ". $action[0];
-     }
-   }
-   
-   if (count($errors)==0) {
-     echo("All leases updated (" . $add_done . " added and " . $del_done . " deleted)");
-   } else {
-     foreach ($errors as $error) echo($error. "\n");
-     echo("Leases updated only partially (" . 
-         $add_done . "/" . $add_requested . " added and " . 
-         $del_done . "/" . $del_requested . " deleted)");
-   }     
-
-   break;
- }
+    case 'manage-leases':{
+            $actions = json_decode($_POST['actions']);
+            $add_requested = 0;
+            $add_done = 0;
+            $del_requested = 0;
+            $del_done = 0;
+            $errors = array();
+            foreach ($actions as $action) {
+                if ($action[0] == 'add-leases') {
+                    $nodenames = $action[1];
+                    $add_requested += count($nodenames);
+                    $slicename = $action[2];
+                    $t_from = intval($action[3]);
+                    $t_until = intval($action[4]);
+                    $hash = $api->AddLeases($nodenames, $slicename, $t_from, $t_until);
+                    // update number of added leases
+                    $ids = $hash['new_ids'];
+                    $add_done += count($ids);
+                    // update global errors array
+                    foreach ($api_errors = $hash['errors'] as $error) {
+                        $errors[] = $error;
+                    }
+
+                } else if ($action[0] == 'delete-leases') {
+                    $lease_id = intval($action[1]);
+                    $del_requested += 1;
+                    if ($api->DeleteLeases(array($lease_id)) == 1) {
+                        $del_done += 1;
+                    } else {
+                        $errors[] = "Could not delete lease " . $lease_id;
+                    }
+                } else {
+                    $errors[] = "in actions.php, manage-leases, wrong action " . $action[0];
+                }
+            }
+
+            if (count($errors) == 0) {
+                echo ("All leases updated (" . $add_done . " added and " . $del_done . " deleted)");
+            } else {
+                foreach ($errors as $error) {
+                    echo ($error . "\n");
+                }
+
+                echo ("Leases updated only partially (" .
+                    $add_done . "/" . $add_requested . " added and " .
+                    $del_done . "/" . $del_requested . " deleted)");
+            }
+
+            break;
+        }
 
 ////////////////////////////////////////
 
 
 ////////////////////////////////////////
 
case 'debug': {
-   plc_debug('GET',$_GET);
-   plc_debug('POST',$_POST);
-   plc_debug('FILES',$_FILES);
-   return;
- }
   case 'debug':{
+            plc_debug('GET', $_GET);
+            plc_debug('POST', $_POST);
+            plc_debug('FILES', $_FILES);
+            return;
       }
 
 
default: {
-   plc_error ("Unknown action $action in actions.php");
-   return;
- }
   default:{
+            plc_error("Unknown action $action in actions.php");
+            return;
       }
 
 
- }
+}
 
 ?>
 
 ?>
index 37559f6..c260926 100644 (file)
@@ -28,12 +28,12 @@ include 'plc_header.php';
 You can choose to run your experiment at the earliest available
 time or give a specific time.  The number of repetitions has
 the following meaning: if you want your job re-inserted on the
 You can choose to run your experiment at the earliest available
 time or give a specific time.  The number of repetitions has
 the following meaning: if you want your job re-inserted on the
-schedule list (in the earliest slot available) directly after it 
-gets a priority increase, you can do so (up to 4 times).  Currently, 
-our admission control policy is that we 
+schedule list (in the earliest slot available) directly after it
+gets a priority increase, you can do so (up to 4 times).  Currently,
+our admission control policy is that we
 allow only one slice per time slot.  <p>
 
 allow only one slice per time slot.  <p>
 
-Currently, 
+Currently,
 time slots are only allocated on the granularity
 of an hour, and
 only CPU is increased.
 time slots are only allocated on the granularity
 of an hour, and
 only CPU is increased.
@@ -62,7 +62,7 @@ function authorizeSlice($sn) {
 
   $username = $_SESSION['username'];
   $password = $_SESSION['password'];
 
   $username = $_SESSION['username'];
   $password = $_SESSION['password'];
-  
+
   $_api->setDebug(0);
 
   $_api_auth = new xmlrpcval(array(
   $_api->setDebug(0);
 
   $_api_auth = new xmlrpcval(array(
@@ -70,7 +70,7 @@ function authorizeSlice($sn) {
                                   "Username" => new xmlrpcval($username),
                                   "AuthString" => new xmlrpcval($password),
                                   "Role" => new xmlrpcval("user")), "struct");
                                   "Username" => new xmlrpcval($username),
                                   "AuthString" => new xmlrpcval($password),
                                   "Role" => new xmlrpcval("user")), "struct");
-  
+
   $func = new xmlrpcmsg("SliceInfo");
   $func->addParam($_api_auth);
 
   $func = new xmlrpcmsg("SliceInfo");
   $func->addParam($_api_auth);
 
@@ -106,9 +106,9 @@ function authorizeSlice($sn) {
     }
   }
   */
     }
   }
   */
-       
+
        global $api;
        global $api;
-  
+
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name" ) );
 
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name" ) );
 
@@ -116,16 +116,16 @@ function authorizeSlice($sn) {
   {
        if ( $slice["name"] == $sn )
                return 1;
   {
        if ( $slice["name"] == $sn )
                return 1;
-       
+
   }
   }
-  
+
   return 0;
   return 0;
-  
+
 }
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
 }
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
-//probably will need to change this.  
+//probably will need to change this.
 function validateRequest ($units, $timesOccupied, $requestedTime, $currentTime) {
   if ($units != 1)
     return TOO_MANY_UNITS;
 function validateRequest ($units, $timesOccupied, $requestedTime, $currentTime) {
   if ($units != 1)
     return TOO_MANY_UNITS;
@@ -144,7 +144,7 @@ function validateRequest ($units, $timesOccupied, $requestedTime, $currentTime)
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
-//probably will need to change this.  
+//probably will need to change this.
 function validateAndMarkRequest ($units, &$timesOccupied, $requestedTime, $currentTime, $sn, $jobArray) {
   // buffer so we aren't too close to deadline, if your request is late
   // OR if it's within 1 minute of deadline, it's too late
 function validateAndMarkRequest ($units, &$timesOccupied, $requestedTime, $currentTime, $sn, $jobArray) {
   // buffer so we aren't too close to deadline, if your request is late
   // OR if it's within 1 minute of deadline, it's too late
@@ -176,7 +176,7 @@ function findNextFreeSlot($units, $timesOccupied) {
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
-  $currentTime = gmmktime();
+  $currentTime = time();
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   while ($retVal != SUCCESS) {
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   while ($retVal != SUCCESS) {
@@ -198,7 +198,7 @@ function dumpToFile($fileName, $buffer, $which, $timesOccupied) {
 
   //lock in case of concurrent accesses
   flock($fileHandle, LOCK_EX);
 
   //lock in case of concurrent accesses
   flock($fileHandle, LOCK_EX);
-  
+
   if ($which == "schedule") {  // need to write timestamp in this case
     $s = gettimeofday();
     fwrite($fileHandle, $s[sec]);
   if ($which == "schedule") {  // need to write timestamp in this case
     $s = gettimeofday();
     fwrite($fileHandle, $s[sec]);
@@ -208,8 +208,8 @@ function dumpToFile($fileName, $buffer, $which, $timesOccupied) {
   //do the dump here
   foreach ($buffer as $value) {
     $t = "";
   //do the dump here
   foreach ($buffer as $value) {
     $t = "";
-    if ($which == "schedule") {  
-      if (strcmp($value["timestamp"], mktime()) > 0) {
+    if ($which == "schedule") {
+      if (strcmp($value["timestamp"], time()) > 0) {
        $numReps = $value["reps"];
        $ts = $value["timestamp"];
        $t = $value["sliceName"]." ".$value["id"]." ".$value["timestamp"]." ".$value["units"]." ".$value["reps"]." \n";
        $numReps = $value["reps"];
        $ts = $value["timestamp"];
        $t = $value["sliceName"]." ".$value["id"]." ".$value["timestamp"]." ".$value["units"]." ".$value["reps"]." \n";
@@ -243,13 +243,13 @@ function updateSliceFile($name, $units) {
 
   $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "rw");
   if (!$sliceFile) {
 
   $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "rw");
   if (!$sliceFile) {
-    echo "<p>Unable to open remote file.</p>"; 
-    
+    echo "<p>Unable to open remote file.</p>";
+
   }
 
   flock($sliceFile, LOCK_EX);
 
   }
 
   flock($sliceFile, LOCK_EX);
 
-  //we'll construct a new list here, will be current slice file except 
+  //we'll construct a new list here, will be current slice file except
   //the slice in question will have it's units decreased, if there are any...
   while (!feof($sliceFile)) {
     $num = fscanf($sliceFile, "%s %d\n", $sliceName, $unitsAvailable);
   //the slice in question will have it's units decreased, if there are any...
   while (!feof($sliceFile)) {
     $num = fscanf($sliceFile, "%s %d\n", $sliceName, $unitsAvailable);
@@ -280,13 +280,13 @@ function updateSliceFile($name, $units) {
 
 
 //pretty obvious what this does; basically, does the slice exist in
 
 
 //pretty obvious what this does; basically, does the slice exist in
-//the slice file yet?  (New user of calendar service user may not have 
+//the slice file yet?  (New user of calendar service user may not have
 //an entry)
 function isFirstSliceRequest($name) {
   $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "r");
   if (!$sliceFile) {
 //an entry)
 function isFirstSliceRequest($name) {
   $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "r");
   if (!$sliceFile) {
-    echo "<p>Unable to open remote file.</p>"; 
-    
+    echo "<p>Unable to open remote file.</p>";
+
   }
 
   flock($sliceFile, LOCK_EX);
   }
 
   flock($sliceFile, LOCK_EX);
@@ -347,8 +347,8 @@ function getCurrentSchedule (&$jobArray, &$timesOccupied, &$maxId) {
 
   $schedFile = fopen("/var/www/html/planetlab/sirius/schedule.txt", "r");
   if (!$schedFile) {
 
   $schedFile = fopen("/var/www/html/planetlab/sirius/schedule.txt", "r");
   if (!$schedFile) {
-    echo "<p>Unable to open remote file.</p>"; 
-    
+    echo "<p>Unable to open remote file.</p>";
+
   }
 
   flock($schedFile, LOCK_EX);
   }
 
   flock($schedFile, LOCK_EX);
@@ -393,7 +393,7 @@ function getCurrentSchedule (&$jobArray, &$timesOccupied, &$maxId) {
 }
 
 // Reid: after below function call, you have the current schedule.
 }
 
 // Reid: after below function call, you have the current schedule.
-// It is stored in $jobArray, which is an array of arrays.  
+// It is stored in $jobArray, which is an array of arrays.
 // Layout: each element of $jobArray is an array with
 //         the following fields.
 //   "sliceName": the name of the slice that occupies the slot
 // Layout: each element of $jobArray is an array with
 //         the following fields.
 //   "sliceName": the name of the slice that occupies the slot
@@ -434,14 +434,14 @@ if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
     if (array_key_exists($sname, $jobArray)) {
       $changeMade = 1;
       $ts = $jobArray[$sname]["timestamp"];
     if (array_key_exists($sname, $jobArray)) {
       $changeMade = 1;
       $ts = $jobArray[$sname]["timestamp"];
-      if ($ts - mktime() < DELETE_THRESHOLD)
+      if ($ts - time() < DELETE_THRESHOLD)
        $requestStatus = TOO_CLOSE_TO_DEADLINE;
       else {
        $timesOccupied[$ts]--;
        unset($jobArray[$sname]);
       }
     }
        $requestStatus = TOO_CLOSE_TO_DEADLINE;
       else {
        $timesOccupied[$ts]--;
        unset($jobArray[$sname]);
       }
     }
-    else 
+    else
       $requestStatus = NO_SUCH_SLICE;
   }
 
       $requestStatus = NO_SUCH_SLICE;
   }
 
@@ -453,8 +453,8 @@ if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
     $reps = $_POST['reps'];
     //  $u = $_POST['units'];
     $u = 1;
     $reps = $_POST['reps'];
     //  $u = $_POST['units'];
     $u = 1;
-    
-    $currentTime = mktime();
+
+    $currentTime = time();
 
     if ($_POST['whenToRun'] == "asap") {
       $requestedTime = findNextFreeSlot($u, $timesOccupied);
 
     if ($_POST['whenToRun'] == "asap") {
       $requestedTime = findNextFreeSlot($u, $timesOccupied);
@@ -481,20 +481,20 @@ if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
          $requestedTime = gmmktime($hour, 0, 0, $currMonth, $currDate, $currYear);
       }
     }
          $requestedTime = gmmktime($hour, 0, 0, $currMonth, $currDate, $currYear);
       }
     }
-    
+
     $id = $maxId + 1;
     $id = $maxId + 1;
-    
+
     $requestStatus = validateAndMarkRequest($u, $timesOccupied, $requestedTime, $currentTime, $sname, $jobArray);
     if ($requestStatus == SUCCESS) {
       // ignore below, it is for future work anyways.
       if (isFirstSliceRequest($sname)) {
        $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "a");
        if ($sliceFile == 0) {
     $requestStatus = validateAndMarkRequest($u, $timesOccupied, $requestedTime, $currentTime, $sname, $jobArray);
     if ($requestStatus == SUCCESS) {
       // ignore below, it is for future work anyways.
       if (isFirstSliceRequest($sname)) {
        $sliceFile = fopen("/var/www/html/planetlab/sirius/slices.txt", "a");
        if ($sliceFile == 0) {
-         echo "<p>Unable to open file.</p>"; 
-         
+         echo "<p>Unable to open file.</p>";
+
        }
        flock($sliceFile, LOCK_EX);
        }
        flock($sliceFile, LOCK_EX);
-       
+
        // should be max number of units, not 5
        // why is this 6?
        fwrite($sliceFile, $sname." "."6");
        // should be max number of units, not 5
        // why is this 6?
        fwrite($sliceFile, $sname." "."6");
@@ -504,9 +504,9 @@ if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
       // if (updateSliceFile($sname, 1) < 0)
       // temporarily not looking at units...
       if (0)
       // if (updateSliceFile($sname, 1) < 0)
       // temporarily not looking at units...
       if (0)
-       $requestStatus = NO_UNITS_LEFT;  
+       $requestStatus = NO_UNITS_LEFT;
       else {
       else {
-       // here, pretty simple, just stick all data into 
+       // here, pretty simple, just stick all data into
        // array element, then stick array into $jobArray.
        $newArray["sliceName"] = $sname;
        $newArray["id"] = $id;
        // array element, then stick array into $jobArray.
        $newArray["sliceName"] = $sname;
        $newArray["id"] = $id;
@@ -521,7 +521,7 @@ if (isset($_POST['action']) && $_POST['action'] == 'submitted') {
 }
 
 //sort job array by earliest time first ("cmp" function does this)
 }
 
 //sort job array by earliest time first ("cmp" function does this)
-usort($jobArray, "cmp");  
+usort($jobArray, "cmp");
 
 // Reid: after this above line, $jobArray holds a sorted list that
 //       you can output as the queue.
 
 // Reid: after this above line, $jobArray holds a sorted list that
 //       you can output as the queue.
@@ -549,7 +549,7 @@ $deletedExpiredJob = 0;
 $arr= array();
 $n= 0;
 foreach ($jobArray as $value) {
 $arr= array();
 $n= 0;
 foreach ($jobArray as $value) {
-  if (strcmp($value["timestamp"], mktime()) > 0) {
+  if (strcmp($value["timestamp"], time()) > 0) {
     printf("<tr>\n");
     printf("<td> %s </td><td align=center> %d </td><td> %s </td>\n", $value["sliceName"], $value["reps"], gmdate("r", $value["timestamp"]));
     $arr[$n]= $value["sliceName"];
     printf("<tr>\n");
     printf("<td> %s </td><td align=center> %d </td><td> %s </td>\n", $value["sliceName"], $value["reps"], gmdate("r", $value["timestamp"]));
     $arr[$n]= $value["sliceName"];
@@ -565,7 +565,7 @@ echo "<br>\n";
 // Reid: end of current printing of the schedule.
 
 // Reid: here is where we put the data back to the schedule file.
 // Reid: end of current printing of the schedule.
 
 // Reid: here is where we put the data back to the schedule file.
-//       It's already a function, 
+//       It's already a function,
 
 function findNextQueue($units, $timesOccupied, $arr) {
 
 
 function findNextQueue($units, $timesOccupied, $arr) {
 
@@ -573,16 +573,16 @@ function findNextQueue($units, $timesOccupied, $arr) {
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
-  $currentTime = gmmktime();
+  $currentTime = time();
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   $i = 0;
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   $i = 0;
-       
+
 
        // DAVE
        // outputting table to display the queue
        // green background will mean slot is open, and red will mean the slot is used
 
        // DAVE
        // outputting table to display the queue
        // green background will mean slot is open, and red will mean the slot is used
-       // 
+       //
   echo "<table cellspacing=\"2\" cellpadding=\"1\" border=\"0\" width=550>\n";
   echo "<tr><td colspan=\"3\"><span class='bold'>24 hour Queue:</span> Choose the GMT time slot you desire (<font color=\"#339933\">green</font> slots are open, <font color=\"#CC3333\">red</font> are taken) <p></td></tr>\n";
   echo "<tr><td width=\"47%\" align=\"right\"><table cellspacing=1 cellpadding=1 border=0 width=130>\n";
   echo "<table cellspacing=\"2\" cellpadding=\"1\" border=\"0\" width=550>\n";
   echo "<tr><td colspan=\"3\"><span class='bold'>24 hour Queue:</span> Choose the GMT time slot you desire (<font color=\"#339933\">green</font> slots are open, <font color=\"#CC3333\">red</font> are taken) <p></td></tr>\n";
   echo "<tr><td width=\"47%\" align=\"right\"><table cellspacing=1 cellpadding=1 border=0 width=130>\n";
@@ -595,7 +595,7 @@ function findNextQueue($units, $timesOccupied, $arr) {
   while ($i < 12) {
     $retVal = validateRequest($units, $timesOccupied, $reqTime, $currentTime);
     if ($retVal == SUCCESS) { // advance timestamp one hour (3600 seconds)
   while ($i < 12) {
     $retVal = validateRequest($units, $timesOccupied, $reqTime, $currentTime);
     if ($retVal == SUCCESS) { // advance timestamp one hour (3600 seconds)
-         
+
        echo "<tr bgcolor=\"#339933\"><td><input type=\"radio\" name=\"queue_time\" value=\"" . gmdate("H:i:s", $reqTime) . "\"> " . gmdate("H:i:s", $reqTime) . " &nbsp;  </td></tr>\n";
     }
     else {
        echo "<tr bgcolor=\"#339933\"><td><input type=\"radio\" name=\"queue_time\" value=\"" . gmdate("H:i:s", $reqTime) . "\"> " . gmdate("H:i:s", $reqTime) . " &nbsp;  </td></tr>\n";
     }
     else {
@@ -633,7 +633,7 @@ function sliceDropDown() {
 
   $username = $_SESSION['username'];
   $password = $_SESSION['password'];
 
   $username = $_SESSION['username'];
   $password = $_SESSION['password'];
-  
+
   $_api->setDebug(0);
 
   $_api_auth = new xmlrpcval(array(
   $_api->setDebug(0);
 
   $_api_auth = new xmlrpcval(array(
@@ -641,12 +641,12 @@ function sliceDropDown() {
                                   "Username" => new xmlrpcval($username),
                                   "AuthString" => new xmlrpcval($password),
                                   "Role" => new xmlrpcval("user")), "struct");
                                   "Username" => new xmlrpcval($username),
                                   "AuthString" => new xmlrpcval($password),
                                   "Role" => new xmlrpcval("user")), "struct");
-  
+
   $func = new xmlrpcmsg("SliceInfo");
   $func->addParam($_api_auth);
 
   $result = $_api->send($func, 15, 'https');
   $func = new xmlrpcmsg("SliceInfo");
   $func->addParam($_api_auth);
 
   $result = $_api->send($func, 15, 'https');
-  
+
   if( $result == 0 ) {
     //    printf("problem: %s\n", $_api->errstring);
     return 0;
   if( $result == 0 ) {
     //    printf("problem: %s\n", $_api->errstring);
     return 0;
@@ -670,7 +670,7 @@ function sliceDropDown() {
       $i = 0;
       while ($i < $numElements) {
                echo "<option value='" . $arr[$i][name] . "'>" . $arr[$i][name] . "</option>\n";
       $i = 0;
       while ($i < $numElements) {
                echo "<option value='" . $arr[$i][name] . "'>" . $arr[$i][name] . "</option>\n";
-               
+
                $i++;
       }
       return 0;
                $i++;
       }
       return 0;
@@ -678,7 +678,7 @@ function sliceDropDown() {
   }
   */
        global $api;
   }
   */
        global $api;
-  
+
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name" ) );
 
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name" ) );
 
@@ -691,9 +691,9 @@ function sliceDropDown() {
   foreach ( $result AS $slice )
   {
        echo "<option value='" . $slice["name"] . "'>" . $slice["name"] . "\n";
   foreach ( $result AS $slice )
   {
        echo "<option value='" . $slice["name"] . "'>" . $slice["name"] . "\n";
-       
+
   }
   }
-  
+
 }
 //reopen schedule file, and dump newly sorted job list into it
 //note that current timestamp is put in at beginning
 }
 //reopen schedule file, and dump newly sorted job list into it
 //note that current timestamp is put in at beginning
@@ -704,14 +704,14 @@ if ($deletedExpiredJob || ($changeMade && $requestStatus == SUCCESS)) {
 
   // hack here...the problem is that the file might not be sorted
   // when it should, because of the stupid way it was designed.  this
 
   // hack here...the problem is that the file might not be sorted
   // when it should, because of the stupid way it was designed.  this
-  // happens when reps is not 0, and the next entry should go after 
+  // happens when reps is not 0, and the next entry should go after
   // another entry.  what does happen is that it goes before, which is
   // fine for displaying, but the sirius service code expects it to
   // always be sorted, "it" being the schedule file
 
   $hackArray = array();
   getCurrentSchedule ($hackArray, $timesOccupied, $maxId);
   // another entry.  what does happen is that it goes before, which is
   // fine for displaying, but the sirius service code expects it to
   // always be sorted, "it" being the schedule file
 
   $hackArray = array();
   getCurrentSchedule ($hackArray, $timesOccupied, $maxId);
-  usort($hackArray, "cmp");  
+  usort($hackArray, "cmp");
   dumpToFile("/var/www/html/planetlab/sirius/schedule.txt", $hackArray, "schedule", $timesOccupied);
 }
 
   dumpToFile("/var/www/html/planetlab/sirius/schedule.txt", $hackArray, "schedule", $timesOccupied);
 }
 
@@ -754,10 +754,10 @@ Choose a number of times you need CPU priority:
 
 <p>
 Only enter a time/date here if your request is for a time more than 24 hours from now.<br>
 
 <p>
 Only enter a time/date here if your request is for a time more than 24 hours from now.<br>
-Year (two digits) <input type=text maxlength=2 size=2 name="year"/> 
-Month (1-12) <input type=text maxlength=2 size=2 name="month"/> 
-Date (1-31) <input type=text maxlength=2 size=2 name="date"/> 
-Hour (0-23) <input type=text maxlength=2 size=2 name="hour"/> 
+Year (two digits) <input type=text maxlength=2 size=2 name="year"/>
+Month (1-12) <input type=text maxlength=2 size=2 name="month"/>
+Date (1-31) <input type=text maxlength=2 size=2 name="date"/>
+Hour (0-23) <input type=text maxlength=2 size=2 name="hour"/>
 <p>
 <!--Units <input type=text maxlength=2 size=2 name="units"/>-->
 <!--<p>-->
 <p>
 <!--Units <input type=text maxlength=2 size=2 name="units"/>-->
 <!--<p>-->
index 3d9a161..a75fc20 100644 (file)
@@ -1,26 +1,26 @@
 <?php
 
 function authorizeSlice($sn) {
 <?php
 
 function authorizeSlice($sn) {
-       
+
        global $api;
        global $api;
-  
+
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name", "slice_id" ) );
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name", "slice_id" ) );
-  
+
   foreach ( $result AS $slice )
   {
        if ( $slice["name"] == $sn )
                return 1;
   foreach ( $result AS $slice )
   {
        if ( $slice["name"] == $sn )
                return 1;
-       
+
   }
   }
-  
+
   return 0;
   return 0;
-  
+
 }
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
 }
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
-//probably will need to change this.  
+//probably will need to change this.
 function validateRequest ($units, $timesOccupied, $requestedTime, $currentTime) {
   if ($units != 1)
     return TOO_MANY_UNITS;
 function validateRequest ($units, $timesOccupied, $requestedTime, $currentTime) {
   if ($units != 1)
     return TOO_MANY_UNITS;
@@ -39,7 +39,7 @@ function validateRequest ($units, $timesOccupied, $requestedTime, $currentTime)
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
 
 //can a request be satisfied?  Currently, answer is yes unless
 //either this time is taken or you asked for more than one unit
-//probably will need to change this.  
+//probably will need to change this.
 function validateAndMarkRequest ($units, &$timesOccupied, $requestedTime, $currentTime, $sn, $jobArray) {
   // buffer so we aren't too close to deadline, if your request is late
   // OR if it's within 1 minute of deadline, it's too late
 function validateAndMarkRequest ($units, &$timesOccupied, $requestedTime, $currentTime, $sn, $jobArray) {
   // buffer so we aren't too close to deadline, if your request is late
   // OR if it's within 1 minute of deadline, it's too late
@@ -71,7 +71,7 @@ function findNextFreeSlot($units, $timesOccupied) {
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
-  $currentTime = gmmktime();
+  $currentTime = time();
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   while ($retVal != SUCCESS) {
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   while ($retVal != SUCCESS) {
@@ -93,7 +93,7 @@ function dumpToFile($fileName, $buffer, $which, $timesOccupied) {
 
   //lock in case of concurrent accesses
   flock($fileHandle, LOCK_EX);
 
   //lock in case of concurrent accesses
   flock($fileHandle, LOCK_EX);
-  
+
   if ($which == "schedule") {  // need to write timestamp in this case
     $s = gettimeofday();
     fwrite($fileHandle, $s['sec']);
   if ($which == "schedule") {  // need to write timestamp in this case
     $s = gettimeofday();
     fwrite($fileHandle, $s['sec']);
@@ -103,8 +103,8 @@ function dumpToFile($fileName, $buffer, $which, $timesOccupied) {
   //do the dump here
   foreach ($buffer as $value) {
     $t = "";
   //do the dump here
   foreach ($buffer as $value) {
     $t = "";
-    if ($which == "schedule") {  
-      if (strcmp($value["timestamp"], mktime()) > 0) {
+    if ($which == "schedule") {
+      if (strcmp($value["timestamp"], time()) > 0) {
        $numReps = $value["reps"];
        $ts = $value["timestamp"];
        $t = $value["sliceName"]." ".$value["id"]." ".$value["timestamp"]." ".$value["units"]." ".$value["reps"]." \n";
        $numReps = $value["reps"];
        $ts = $value["timestamp"];
        $t = $value["sliceName"]." ".$value["id"]." ".$value["timestamp"]." ".$value["units"]." ".$value["reps"]." \n";
@@ -138,13 +138,13 @@ function updateSliceFile($name, $units) {
 
   $sliceFile = fopen("slices.txt", "rw");
   if (!$sliceFile) {
 
   $sliceFile = fopen("slices.txt", "rw");
   if (!$sliceFile) {
-    echo "<p>Unable to open remote file.</p>"; 
-    
+    echo "<p>Unable to open remote file.</p>";
+
   }
 
   flock($sliceFile, LOCK_EX);
 
   }
 
   flock($sliceFile, LOCK_EX);
 
-  //we'll construct a new list here, will be current slice file except 
+  //we'll construct a new list here, will be current slice file except
   //the slice in question will have it's units decreased, if there are any...
   while (!feof($sliceFile)) {
     $num = fscanf($sliceFile, "%s %d\n", $sliceName, $unitsAvailable);
   //the slice in question will have it's units decreased, if there are any...
   while (!feof($sliceFile)) {
     $num = fscanf($sliceFile, "%s %d\n", $sliceName, $unitsAvailable);
@@ -175,13 +175,13 @@ function updateSliceFile($name, $units) {
 
 
 //pretty obvious what this does; basically, does the slice exist in
 
 
 //pretty obvious what this does; basically, does the slice exist in
-//the slice file yet?  (New user of calendar service user may not have 
+//the slice file yet?  (New user of calendar service user may not have
 //an entry)
 function isFirstSliceRequest($name) {
   $sliceFile = fopen("slices.txt", "r");
   if (!$sliceFile) {
 //an entry)
 function isFirstSliceRequest($name) {
   $sliceFile = fopen("slices.txt", "r");
   if (!$sliceFile) {
-    echo "<p>Unable to open remote file.</p>"; 
-    
+    echo "<p>Unable to open remote file.</p>";
+
   }
 
   flock($sliceFile, LOCK_EX);
   }
 
   flock($sliceFile, LOCK_EX);
@@ -241,8 +241,8 @@ function getCurrentSchedule (&$jobArray, &$timesOccupied, &$maxId) {
 
   $schedFile = fopen("schedule.txt", "r");
   if (!$schedFile) {
 
   $schedFile = fopen("schedule.txt", "r");
   if (!$schedFile) {
-    echo "<p>Unable to open remote file.</p>"; 
-    
+    echo "<p>Unable to open remote file.</p>";
+
   }
 
   flock($schedFile, LOCK_EX);
   }
 
   flock($schedFile, LOCK_EX);
@@ -293,15 +293,15 @@ function findNextQueue($units, $timesOccupied) {
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
   $currMonth = gmdate("m");
   $currDate = gmdate("d");
   $currHour = gmdate("H") + 1;
-  $currentTime = gmmktime();
+  $currentTime = time();
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   $i = 0;
   $reqTime = gmmktime($currHour, 0, 0, $currMonth, $currDate, $currYear);
   $retVal = 1;
   $i = 0;
-       
+
        // DAVE
        // outputting table to display the queue
        // green background will mean slot is open, and red will mean the slot is used
        // DAVE
        // outputting table to display the queue
        // green background will mean slot is open, and red will mean the slot is used
-       // 
+       //
   echo "<table cellspacing=\"2\" cellpadding=\"1\" border=\"0\" width=550>\n";
   echo "<tr><td colspan=\"3\"><span class='bold'>24 hour Queue:</span> Choose the GMT time slot you desire (<font color=\"#339933\">green</font> slots are open, <font color=\"#CC3333\">red</font> are taken) <p></td></tr>\n";
   echo "<tr><td width=\"47%\" align=\"right\"><table cellspacing=1 cellpadding=1 border=0 width=130>\n";
   echo "<table cellspacing=\"2\" cellpadding=\"1\" border=\"0\" width=550>\n";
   echo "<tr><td colspan=\"3\"><span class='bold'>24 hour Queue:</span> Choose the GMT time slot you desire (<font color=\"#339933\">green</font> slots are open, <font color=\"#CC3333\">red</font> are taken) <p></td></tr>\n";
   echo "<tr><td width=\"47%\" align=\"right\"><table cellspacing=1 cellpadding=1 border=0 width=130>\n";
@@ -314,7 +314,7 @@ function findNextQueue($units, $timesOccupied) {
   while ($i < 12) {
     $retVal = validateRequest($units, $timesOccupied, $reqTime, $currentTime);
     if ($retVal == SUCCESS) { // advance timestamp one hour (3600 seconds)
   while ($i < 12) {
     $retVal = validateRequest($units, $timesOccupied, $reqTime, $currentTime);
     if ($retVal == SUCCESS) { // advance timestamp one hour (3600 seconds)
-         
+
        echo "<tr bgcolor=\"#339933\"><td><input type=\"radio\" name=\"queue_time\" value=\"" . gmdate("H:i:s", $reqTime) . "\"> " . gmdate("H:i:s", $reqTime) . " &nbsp;  </td></tr>\n";
     }
     else {
        echo "<tr bgcolor=\"#339933\"><td><input type=\"radio\" name=\"queue_time\" value=\"" . gmdate("H:i:s", $reqTime) . "\"> " . gmdate("H:i:s", $reqTime) . " &nbsp;  </td></tr>\n";
     }
     else {
@@ -350,7 +350,7 @@ function findNextQueue($units, $timesOccupied) {
 function sliceDropDown() {
 
        global $api;
 function sliceDropDown() {
 
        global $api;
-  
+
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name", "slice_id" ) );
   // sort_slices( $result ); --> slice sort on name
   $slice_list= array();
   $result= $api->GetSlices( Null, array( "name", "slice_id" ) );
   // sort_slices( $result ); --> slice sort on name
@@ -362,9 +362,9 @@ function sliceDropDown() {
   foreach ( $result AS $slice )
   {
        echo "<option value='" . $slice["name"] . "'>" . $slice["name"] . "\n";
   foreach ( $result AS $slice )
   {
        echo "<option value='" . $slice["name"] . "'>" . $slice["name"] . "\n";
-       
+
   }
   }
-  
+
 }
 
 
 }