4 require_once 'plc_login.php';
6 // Get session and API handles
7 require_once 'plc_session.php';
11 require_once 'plc_drupal.php';
14 require_once 'plc_functions.php';
16 $known_actions=array();
17 ////////////////////////////////////////////////////////////
20 // (*) set 'action' to one of the following
21 $known_actions []= "add-person-to-site";
22 // expects: person_id & site_id
23 $known_actions []= "remove-person-from-sites";
24 // expects: person_id & site_ids
25 $known_actions []= "remove-roles-from-person";
26 // expects: person_id & role_ids
27 $known_actions []= "add-role-to-person";
28 // expects: role_person_id & id
29 $known_actions []= "enable-person";
31 $known_actions []= "disable-person";
33 $known_actions []= "become-person";
35 $known_actions []= "delete-person";
37 $known_actions []= "delete-keys";
38 // expects: key_ids & person_id (for redirecting to the person's page)
39 $known_actions []= "upload-key";
40 // expects: person_id & $_FILES['key']
41 $known_actions []= "update-tag-type";
42 // expects: tag_type_id & name & description & category & min_role_id
43 $known_actions []= "add-tag-type";
44 // expects: tag_type_id & name & description & category & min_role_id
45 $known_actions []= "expire-all-slices-in-site";
48 //////////////////////////////
49 // sometimes we don't set 'action', but use the submit button name instead
50 // so if 'action' not set, see if $_POST has one of the actions as a key
52 $action=$_POST['action'];
54 foreach ($known_actions as $known_action)
55 if ($_POST[$known_action]) {
56 $action=$known_action;
61 $person_id = $_POST['person_id']; // usually needed
64 drupal_set_message ("actions.php: action not set");
65 plc_debug('POST',$_POST);
71 case 'add-person-to-site': {
72 $site_id = $_POST['site_id'];
73 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
74 header( "location: " . l_person($person_id));
78 case 'remove-person-from-sites': {
79 $site_ids = $_POST['site_ids'];
81 drupal_set_message("action=$action - No site selected");
84 foreach ( $site_ids as $site_id ) {
85 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
87 header( "location: " . l_person($person_id));
91 case 'remove-roles-from-person' : {
92 $role_ids=$_POST['role_ids'];
94 drupal_set_message("action=$action - No role selected");
97 foreach( $role_ids as $role_id) {
98 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
100 header( "location: " . l_person($person_id));
104 case 'add-role-to-person' : {
105 $role_id=$_POST['role_id'];
106 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
107 header( "location: " . l_person($person_id));
111 case 'enable-person' : {
112 $fields = array( "enabled"=>true );
113 $api->UpdatePerson( intval( $person_id ), $fields );
114 header( "location: " . l_person($person_id));
118 case 'disable-person' : {
119 $fields = array( "enabled"=>false );
120 $api->UpdatePerson( intval( $person_id ), $fields );
121 header( "location: " . l_person($person_id));
125 case 'become-person' : {
126 $plc->BecomePerson (intval($person_id));
127 header ("location: " . l_persons());
131 case 'delete-person' : {
132 $api->DeletePerson( intval( $person_id ) );
133 header( "location: " . l_persons() );
137 case 'delete-keys' : {
138 $key_ids=$_POST['key_ids'];
140 drupal_set_message("action=$action - No key selected");
143 foreach( $key_ids as $key_id ) {
144 $api->DeleteKey( intval( $key_id ) );
146 header( "location: " . l_person($person_id));
150 case 'upload-key' : {
151 if ( ! isset( $_FILES['key'] ) ) {
152 drupal_set_message ("action=$action, no key file set");
156 $key_file= $_FILES['key']['tmp_name'];
158 plc_error("Please select a valid SSH key file to upload");
161 $fp = fopen( $key_file, "r" );
164 plc_error("Unable to open key file $key_file");
167 // opened the key file, read the one line of contents
168 // The POST operation always creates a file even if the filename
169 // the user specified was garbage. If there was some problem
170 // with the source file, we'll get a zero length read here.
171 $key = fread($fp, filesize($key_file));
174 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
177 $error= $api->error();
179 plc_error("Please verify your SSH file content");
182 header( "location: " . l_person($person_id));
186 case 'update-tag-type': {
188 $tag_type_id= intval( $_POST['tag_type_id'] );
189 $name = $_POST['name'];
190 $min_role_id= intval( $_POST['min_role_id'] );
191 $description= $_POST['description'];
192 $category= $_POST['category'];
194 // make tag_type_fields dict
195 $tag_type_fields= array( "min_role_id" => $min_role_id,
197 "description" => $description,
198 "category" => $category,
202 $api->UpdateTagType( $tag_type_id, $tag_type_fields );
204 header( "location: " . l_tag($tag_type_id));
208 case 'add-tag-type': {
210 $name = $_POST['name'];
211 $min_role_id= intval( $_POST['min_role_id'] );
212 $description= $_POST['description'];
213 $category= $_POST['category'];
215 // make tag_type_fields dict
216 $tag_type_fields= array( "min_role_id" => $min_role_id,
218 "description" => $description,
219 "category" => $category,
223 $id=$api->AddTagType( $tag_type_fields );
224 drupal_set_message ("tag type $id created");
226 header( "location: " . l_tag($id));
230 case 'expire-all-slices-in-site': {
231 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
234 //// old code from sites/expire.php
235 $sites = $api->GetSites( array( intval( $site_id )));
237 // xxx why not 'now?'
238 $expiration= strtotime( $_POST['expires'] );
239 // loop through all slices for site
240 foreach ($site['slice_ids'] as $slice_id) {
241 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
243 // update site to not allow slice creation or renewal
244 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
245 header ("location: " l_site($site_id));
250 plc_debug('GET',$_GET);
251 plc_debug('POST',$_POST);
252 plc_debug('FILES',$_FILES);
257 plc_error ("Unknown action $action in actions.php");