From a25fa66c1b97217940863317cce5d41d5568fdc4 Mon Sep 17 00:00:00 2001 From: Till Brehm Date: Mon, 11 Jun 2018 17:12:39 +0200 Subject: [PATCH] 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. --- interface/lib/classes/remote.d/admin.inc.php | 116 +++++++++++++++++++ interface/web/admin/lib/remote.conf.php | 2 +- 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/interface/lib/classes/remote.d/admin.inc.php b/interface/lib/classes/remote.d/admin.inc.php index 347f8520b..8b0c4730e 100644 --- a/interface/lib/classes/remote.d/admin.inc.php +++ b/interface/lib/classes/remote.d/admin.inc.php @@ -156,6 +156,122 @@ class remoting_admin extends remoting { return false; } } + + // config_value_* functions --------------------------------------------------------------------------------------- + + //* Get config_value details + public function config_value_get($session_id, $group, $name) + { + global $app; + + if(!$this->checkPerm($session_id, 'config_value_get')) { + throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + // validate fields + if($group == '' || $name == '') { + throw new SoapFault('field_empty_error', 'Group and name parameter may not be empty.'); + return false; + } + + return $app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name); + } + + //* Add a config_value record + public function config_value_add($session_id, $group, $name, $value) + { + global $app; + + if(!$this->checkPerm($session_id, 'config_value_add')) { + throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + // validate fields + if($group == '' || $name == '' || $value == '') { + throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.'); + return false; + } + + if(is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) { + throw new SoapFault('record_unique_error', 'Group plus name field combination is not unique.'); + return false; + } + + return $app->db->query('INSERT INTO sys_config (`group`,`name`,`value`) VALUES (?,?,?)',$group,$name,$value); + } + + //* Update config_value record + public function config_value_update($session_id, $group, $name, $value) + { + global $app; + + if(!$this->checkPerm($session_id, 'config_value_update')) { + throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + // validate fields + if($group == '' || $name == '' || $value == '') { + throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.'); + return false; + } + + if(!is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) { + throw new SoapFault('record_nonexist_error', 'There is no record with this group plus name field combination.'); + return false; + } + + return $app->db->query('UPDATE sys_config SET `value` = ? WHERE `group` = ? AND `name` = ?',$value,$group,$name); + } + + //* Replace config_value record + public function config_value_replace($session_id, $group, $name, $value) + { + global $app; + + if(!$this->checkPerm($session_id, 'config_value_replace')) { + throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + // validate fields + if($group == '' || $name == '' || $value == '') { + throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.'); + return false; + } + + if(is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) { + return $app->db->query('UPDATE sys_config SET `value` = ? WHERE `group` = ? AND `name` = ?',$value,$group,$name); + } else { + return $app->db->query('INSERT INTO sys_config (`group`,`name`,`value`) VALUES (?,?,?)',$group,$name,$value); + } + } + + //* Delete config_value record + public function config_value_delete($session_id, $group, $name) + { + global $app; + + if(!$this->checkPerm($session_id, 'config_value_delete')) { + throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + // validate fields + if($group == '' || $name == '') { + throw new SoapFault('field_empty_error', 'Group and name parameter may not be empty.'); + return false; + } + + if(!is_array($app->db->queryOneRecord('SELECT * FROM sys_config WHERE `group` = ? AND `name` = ?', $group, $name))) { + throw new SoapFault('record_nonexist_error', 'There is no record with this group plus name field combination.'); + return false; + } + + return $app->db->query('DELETE FROM sys_config WHERE `group` = ? AND `name` = ?',$group,$name); + } } diff --git a/interface/web/admin/lib/remote.conf.php b/interface/web/admin/lib/remote.conf.php index 01e03695f..a1067a992 100644 --- a/interface/web/admin/lib/remote.conf.php +++ b/interface/web/admin/lib/remote.conf.php @@ -1,6 +1,6 @@ -- GitLab