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 []= "delete-site";
47 $known_actions []= "expire-all-slices-in-site";
50 //////////////////////////////
51 // sometimes we don't set 'action', but use the submit button name instead
52 // so if 'action' not set, see if $_POST has one of the actions as a key
54 $action=$_POST['action'];
56 foreach ($known_actions as $known_action)
57 if ($_POST[$known_action]) {
58 $action=$known_action;
65 $person_id = $_POST['person_id']; // usually needed
68 drupal_set_message ("actions.php: action not set");
69 plc_debug('POST',$_POST);
75 case 'add-person-to-site': {
76 $site_id = $_POST['site_id'];
77 $api->AddPersonToSite( intval( $person_id ), intval( $site_id ) );
78 header( "location: " . l_person($person_id));
82 case 'remove-person-from-sites': {
83 $site_ids = $_POST['site_ids'];
85 drupal_set_message("action=$action - No site selected");
88 foreach ( $site_ids as $site_id ) {
89 $api->DeletePersonFromSite( intval( $person_id ), intval( $site_id ) );
91 header( "location: " . l_person($person_id));
95 case 'remove-roles-from-person' : {
96 $role_ids=$_POST['role_ids'];
98 drupal_set_message("action=$action - No role selected");
101 foreach( $role_ids as $role_id) {
102 $api->DeleteRoleFromPerson( intval( $role_id ), intval( $person_id ) );
104 header( "location: " . l_person($person_id));
108 case 'add-role-to-person' : {
109 $role_id=$_POST['role_id'];
110 $api->AddRoleToPerson( intval( $role_id ), intval( $person_id ) );
111 header( "location: " . l_person($person_id));
115 case 'enable-person' : {
116 $fields = array( "enabled"=>true );
117 $api->UpdatePerson( intval( $person_id ), $fields );
118 header( "location: " . l_person($person_id));
122 case 'disable-person' : {
123 $fields = array( "enabled"=>false );
124 $api->UpdatePerson( intval( $person_id ), $fields );
125 header( "location: " . l_person($person_id));
129 case 'become-person' : {
130 $plc->BecomePerson (intval($person_id));
131 header ("location: " . l_persons());
135 case 'delete-person' : {
136 $api->DeletePerson( intval( $person_id ) );
137 header( "location: " . l_persons() );
141 case 'delete-keys' : {
142 $key_ids=$_POST['key_ids'];
144 drupal_set_message("action=$action - No key selected");
147 foreach( $key_ids as $key_id ) {
148 $api->DeleteKey( intval( $key_id ) );
150 header( "location: " . l_person($person_id));
154 case 'upload-key' : {
155 if ( ! isset( $_FILES['key'] ) ) {
156 drupal_set_message ("action=$action, no key file set");
160 $key_file= $_FILES['key']['tmp_name'];
162 plc_error("Please select a valid SSH key file to upload");
165 $fp = fopen( $key_file, "r" );
168 plc_error("Unable to open key file $key_file");
171 // opened the key file, read the one line of contents
172 // The POST operation always creates a file even if the filename
173 // the user specified was garbage. If there was some problem
174 // with the source file, we'll get a zero length read here.
175 $key = fread($fp, filesize($key_file));
178 $key_id= $api->AddPersonKey( intval( $person_id ), array( "key_type"=> 'ssh', "key"=> $key ) );
181 $error= $api->error();
183 plc_error("Please verify your SSH file content");
186 header( "location: " . l_person($person_id));
190 case 'update-tag-type': {
192 $tag_type_id= intval( $_POST['tag_type_id'] );
193 $name = $_POST['name'];
194 $min_role_id= intval( $_POST['min_role_id'] );
195 $description= $_POST['description'];
196 $category= $_POST['category'];
198 // make tag_type_fields dict
199 $tag_type_fields= array( "min_role_id" => $min_role_id,
201 "description" => $description,
202 "category" => $category,
206 $api->UpdateTagType( $tag_type_id, $tag_type_fields );
208 header( "location: " . l_tag($tag_type_id));
212 case 'add-tag-type': {
214 $name = $_POST['name'];
215 $min_role_id= intval( $_POST['min_role_id'] );
216 $description= $_POST['description'];
217 $category= $_POST['category'];
219 // make tag_type_fields dict
220 $tag_type_fields= array( "min_role_id" => $min_role_id,
222 "description" => $description,
223 "category" => $category,
227 $id=$api->AddTagType( $tag_type_fields );
228 drupal_set_message ("tag type $id created");
230 header( "location: " . l_tag($id));
234 case 'delete-site': {
235 $site_id = intval($_POST['site_id']);
236 if ($api->DeleteSite($site_id) ==1)
237 drupal_set_message ("Site $site_id deleted");
239 drupal_set_error("Failed to delete site $site_id");
240 header ("location: " . l_sites());
244 case 'expire-all-slices-in-site': {
245 drupal_set_message("action $action not implemented in actions.php -- need tweaks and test");
248 //// old code from sites/expire.php
249 $sites = $api->GetSites( array( intval( $site_id )));
251 // xxx why not 'now?'
252 $expiration= strtotime( $_POST['expires'] );
253 // loop through all slices for site
254 foreach ($site['slice_ids'] as $slice_id) {
255 $api->UpdateSlice( $slice_id, array( "expires" => $expiration ) );
257 // update site to not allow slice creation or renewal
258 $api->UpdateSite( $site_id, array( "max_slices" => 0 )) ;
259 header ("location: " . l_site($site_id));
264 plc_debug('GET',$_GET);
265 plc_debug('POST',$_POST);
266 plc_debug('FILES',$_FILES);
271 plc_error ("Unknown action $action in actions.php");