Skip to content

Commit a25fa66

Browse files
author
Till Brehm
committed
Added remote functions config_value_get, config_value_add, config_value_update, config_value_replace and config_value_delete to access the sys_config key / value store in ISPConfig from remote api.
1 parent e15923a commit a25fa66

File tree

2 files changed

+117
-1
lines changed

2 files changed

+117
-1
lines changed

interface/lib/classes/remote.d/admin.inc.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,122 @@ public function system_config_get($session_id, $section, $key) {
156156
return false;
157157
}
158158
}
159+
160+
// config_value_* functions ---------------------------------------------------------------------------------------
161+
162+
//* Get config_value details
163+
public function config_value_get($session_id, $group, $name)
164+
{
165+
global $app;
166+
167+
if(!$this->checkPerm($session_id, 'config_value_get')) {
168+
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
169+
return false;
170+
}
171+
172+
// validate fields
173+
if($group == '' || $name == '') {
174+
throw new SoapFault('field_empty_error', 'Group and name parameter may not be empty.');
175+
return false;
176+
}
177+
178+
return $app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name);
179+
}
180+
181+
//* Add a config_value record
182+
public function config_value_add($session_id, $group, $name, $value)
183+
{
184+
global $app;
185+
186+
if(!$this->checkPerm($session_id, 'config_value_add')) {
187+
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
188+
return false;
189+
}
190+
191+
// validate fields
192+
if($group == '' || $name == '' || $value == '') {
193+
throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.');
194+
return false;
195+
}
196+
197+
if(is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) {
198+
throw new SoapFault('record_unique_error', 'Group plus name field combination is not unique.');
199+
return false;
200+
}
201+
202+
return $app->db->query('INSERT INTO sys_config (`group`,`name`,`value`) VALUES (?,?,?)',$group,$name,$value);
203+
}
204+
205+
//* Update config_value record
206+
public function config_value_update($session_id, $group, $name, $value)
207+
{
208+
global $app;
209+
210+
if(!$this->checkPerm($session_id, 'config_value_update')) {
211+
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
212+
return false;
213+
}
214+
215+
// validate fields
216+
if($group == '' || $name == '' || $value == '') {
217+
throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.');
218+
return false;
219+
}
220+
221+
if(!is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) {
222+
throw new SoapFault('record_nonexist_error', 'There is no record with this group plus name field combination.');
223+
return false;
224+
}
225+
226+
return $app->db->query('UPDATE sys_config SET `value` = ? WHERE `group` = ? AND `name` = ?',$value,$group,$name);
227+
}
228+
229+
//* Replace config_value record
230+
public function config_value_replace($session_id, $group, $name, $value)
231+
{
232+
global $app;
233+
234+
if(!$this->checkPerm($session_id, 'config_value_replace')) {
235+
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
236+
return false;
237+
}
238+
239+
// validate fields
240+
if($group == '' || $name == '' || $value == '') {
241+
throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.');
242+
return false;
243+
}
244+
245+
if(is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) {
246+
return $app->db->query('UPDATE sys_config SET `value` = ? WHERE `group` = ? AND `name` = ?',$value,$group,$name);
247+
} else {
248+
return $app->db->query('INSERT INTO sys_config (`group`,`name`,`value`) VALUES (?,?,?)',$group,$name,$value);
249+
}
250+
}
251+
252+
//* Delete config_value record
253+
public function config_value_delete($session_id, $group, $name)
254+
{
255+
global $app;
256+
257+
if(!$this->checkPerm($session_id, 'config_value_delete')) {
258+
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
259+
return false;
260+
}
261+
262+
// validate fields
263+
if($group == '' || $name == '') {
264+
throw new SoapFault('field_empty_error', 'Group and name parameter may not be empty.');
265+
return false;
266+
}
267+
268+
if(!is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) {
269+
throw new SoapFault('record_nonexist_error', 'There is no record with this group plus name field combination.');
270+
return false;
271+
}
272+
273+
return $app->db->query('DELETE FROM sys_config WHERE `group` = ? AND `name` = ?',$group,$name);
274+
}
159275

160276
}
161277

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
$function_list['server_get,server_config_set,get_function_list,client_templates_get_all,server_get_serverid_by_ip,server_ip_get,server_ip_add,server_ip_update,server_ip_delete,system_config_set,system_config_get'] = 'Server functions';
3+
$function_list['server_get,server_config_set,get_function_list,client_templates_get_all,server_get_serverid_by_ip,server_ip_get,server_ip_add,server_ip_update,server_ip_delete,system_config_set,system_config_get,config_value_get,config_value_add,config_value_update,config_value_replace,config_value_delete'] = 'Server functions';
44
$function_list['admin_record_permissions'] = 'Record permission changes';
55

66
?>

0 commit comments

Comments
 (0)