Skip to content

Commit 4549a02

Browse files
author
Marius Cramer
committed
Implemented: FS#3240 - remote function to alter record permissions.
1 parent 89caa5a commit 4549a02

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

interface/lib/classes/remoting.inc.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,69 @@ public function server_get_functions($session_id, $server_id)
199199
}
200200
}
201201

202+
/**
203+
* set record permissions in any table
204+
* @param string session_id
205+
* @param string index_field
206+
* @param string index_value
207+
* @param array permissions
208+
* @author "ispcomm", improved by M. Cramer <m.cramer@pixcept.de>
209+
*/
210+
public function update_record_permissions($tablename, $index_field, $index_value, $permissions) {
211+
global $app;
212+
213+
if(!$this->checkPerm($session_id, 'admin_record_permissions')) {
214+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
215+
return false;
216+
}
217+
218+
foreach($permissions as $key => $value) { // make sure only sys_ fields are updated
219+
switch($key) {
220+
case 'sys_userid':
221+
// check if userid is valid
222+
$check = $app->db->queryOneRecord('SELECT userid FROM sys_user WHERE userid = ' . $app->functions->intval($value));
223+
if(!$check || !$check['userid']) {
224+
$this->server->fault('invalid parameters', $value . ' is no valid sys_userid.');
225+
return false;
226+
}
227+
$value = $app->functions->intval($value);
228+
break;
229+
case 'sys_groupid':
230+
// check if groupid is valid
231+
$check = $app->db->queryOneRecord('SELECT groupid FROM sys_group WHERE groupid = ' . $app->functions->intval($value));
232+
if(!$check || !$check['groupid']) {
233+
$this->server->fault('invalid parameters', $value . ' is no valid sys_groupid.');
234+
return false;
235+
}
236+
$value = $app->functions->intval($value);
237+
break;
238+
case 'sys_perm_user':
239+
case 'sys_perm_group':
240+
// check if permissions are valid
241+
$value = strtolower($value);
242+
if(!preg_match('/^[riud]+$/', $value)) {
243+
$this->server->fault('invalid parameters', $value . ' is no valid permission string.');
244+
return false;
245+
}
246+
247+
$newvalue = '';
248+
if(strpos($value, 'r') !== false) $newvalue .= 'r';
249+
if(strpos($value, 'i') !== false) $newvalue .= 'i';
250+
if(strpos($value, 'u') !== false) $newvalue .= 'u';
251+
if(strpos($value, 'd') !== false) $newvalue .= 'd';
252+
$value = $newvalue;
253+
unset($newvalue);
254+
255+
break;
256+
default:
257+
$this->server->fault('invalid parameters', 'Only sys_userid, sys_groupid, sys_perm_user and sys_perm_group parameters can be changed with this function.');
258+
break;
259+
}
260+
}
261+
262+
return $app->db->datalogUpdate( $tablename, $permissions, $index_field, $index_value ) ;
263+
}
264+
202265
/**
203266
Gets the ISPconfig version of the server
204267
@param int session_id
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

33
$function_list['server_get,get_function_list,client_templates_get_all,server_get_serverid_by_ip,server_ip_add,server_ip_update,server_ip_delete'] = 'Server functions';
4+
$function_list['admin_record_permissions'] = 'Record permission changes';
45

56
?>

0 commit comments

Comments
 (0)