Skip to content

Commit b1d8181

Browse files
author
Marius Burkard
committed
- get rid of SoapFault dependency when using json/rest remoting endpoint
1 parent 35869ae commit b1d8181

15 files changed

+357
-339
lines changed

interface/lib/classes/json_handler.inc.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,17 @@ public function run() {
115115

116116
try {
117117
$this->_return_json('ok', '', call_user_func_array(array($this->classes[$class_name], $method), $params));
118-
} catch(SoapFault $e) {
118+
} catch(ISPConfigRemoteException $e) {
119119
$this->_return_json('remote_fault', $e->getMessage());
120120
}
121121
}
122122

123123
}
124124

125-
?>
125+
if(!class_exists('ISPConfigRemoteException')) {
126+
class ISPConfigRemoteException extends Exception {
127+
public function __construct($code = '', $message = '') {
128+
parent::__construct($message . ' (' . $code . ')', 0);
129+
}
130+
}
131+
}

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function update_record_permissions($session_id, $tablename, $index_field,
5252
global $app;
5353

5454
if(!$this->checkPerm($session_id, 'admin_record_permissions')) {
55-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
55+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
5656
return false;
5757
}
5858

@@ -62,7 +62,7 @@ public function update_record_permissions($session_id, $tablename, $index_field,
6262
// check if userid is valid
6363
$check = $app->db->queryOneRecord('SELECT userid FROM sys_user WHERE userid = ?', $app->functions->intval($value));
6464
if(!$check || !$check['userid']) {
65-
throw new SoapFault('invalid parameters', $value . ' is no valid sys_userid.');
65+
throw new ISPConfigRemoteException('invalid parameters', $value . ' is no valid sys_userid.');
6666
return false;
6767
}
6868
$permissions[$key] = $app->functions->intval($value);
@@ -71,7 +71,7 @@ public function update_record_permissions($session_id, $tablename, $index_field,
7171
// check if groupid is valid
7272
$check = $app->db->queryOneRecord('SELECT groupid FROM sys_group WHERE groupid = ?', $app->functions->intval($value));
7373
if(!$check || !$check['groupid']) {
74-
throw new SoapFault('invalid parameters', $value . ' is no valid sys_groupid.');
74+
throw new ISPConfigRemoteException('invalid parameters', $value . ' is no valid sys_groupid.');
7575
return false;
7676
}
7777
$permissions[$key] = $app->functions->intval($value);
@@ -81,7 +81,7 @@ public function update_record_permissions($session_id, $tablename, $index_field,
8181
// check if permissions are valid
8282
$value = strtolower($value);
8383
if(!preg_match('/^[riud]+$/', $value)) {
84-
throw new SoapFault('invalid parameters', $value . ' is no valid permission string.');
84+
throw new ISPConfigRemoteException('invalid parameters', $value . ' is no valid permission string.');
8585
return false;
8686
}
8787

@@ -95,7 +95,7 @@ public function update_record_permissions($session_id, $tablename, $index_field,
9595

9696
break;
9797
default:
98-
throw new SoapFault('invalid parameters', 'Only sys_userid, sys_groupid, sys_perm_user and sys_perm_group parameters can be changed with this function.');
98+
throw new ISPConfigRemoteException('invalid parameters', 'Only sys_userid, sys_groupid, sys_perm_user and sys_perm_group parameters can be changed with this function.');
9999
break;
100100
}
101101
}
@@ -113,7 +113,7 @@ public function update_record_permissions($session_id, $tablename, $index_field,
113113
public function system_config_set($session_id, $section, $key, $value) {
114114
global $app;
115115
if(!$this->checkPerm($session_id, 'system_config_set')) {
116-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
116+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
117117
return false;
118118
}
119119
if ($section != '' && $key != '') {
@@ -123,7 +123,7 @@ public function system_config_set($session_id, $section, $key, $value) {
123123
$system_config_str = $app->ini_parser->get_ini_string($system_config_array);
124124
return $app->db->datalogUpdate('sys_ini', array("config" => $system_config_str), 'sysini_id', 1);
125125
} else {
126-
throw new SoapFault('invalid_function_parameter', 'Invalid function parameter.');
126+
throw new ISPConfigRemoteException('invalid_function_parameter', 'Invalid function parameter.');
127127
return false;
128128
}
129129
}
@@ -138,7 +138,7 @@ public function system_config_set($session_id, $section, $key, $value) {
138138
public function system_config_get($session_id, $section, $key) {
139139
global $app;
140140
if(!$this->checkPerm($session_id, 'system_config_get')) {
141-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
141+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
142142
return false;
143143
}
144144
if ($section != '') {
@@ -152,7 +152,7 @@ public function system_config_get($session_id, $section, $key) {
152152
else return false;
153153
}
154154
} else {
155-
throw new SoapFault('invalid_function_parameter', 'Invalid function parameter.');
155+
throw new ISPConfigRemoteException('invalid_function_parameter', 'Invalid function parameter.');
156156
return false;
157157
}
158158
}
@@ -165,13 +165,13 @@ public function config_value_get($session_id, $group, $name)
165165
global $app;
166166

167167
if(!$this->checkPerm($session_id, 'config_value_get')) {
168-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
168+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
169169
return false;
170170
}
171171

172172
// validate fields
173173
if($group == '' || $name == '') {
174-
throw new SoapFault('field_empty_error', 'Group and name parameter may not be empty.');
174+
throw new ISPConfigRemoteException('field_empty_error', 'Group and name parameter may not be empty.');
175175
return false;
176176
}
177177

@@ -184,18 +184,18 @@ public function config_value_add($session_id, $group, $name, $value)
184184
global $app;
185185

186186
if(!$this->checkPerm($session_id, 'config_value_add')) {
187-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
187+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
188188
return false;
189189
}
190190

191191
// validate fields
192192
if($group == '' || $name == '' || $value == '') {
193-
throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.');
193+
throw new ISPConfigRemoteException('field_empty_error', 'Group, name, and value parameter may not be empty.');
194194
return false;
195195
}
196196

197197
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.');
198+
throw new ISPConfigRemoteException('record_unique_error', 'Group plus name field combination is not unique.');
199199
return false;
200200
}
201201

@@ -208,18 +208,18 @@ public function config_value_update($session_id, $group, $name, $value)
208208
global $app;
209209

210210
if(!$this->checkPerm($session_id, 'config_value_update')) {
211-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
211+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
212212
return false;
213213
}
214214

215215
// validate fields
216216
if($group == '' || $name == '' || $value == '') {
217-
throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.');
217+
throw new ISPConfigRemoteException('field_empty_error', 'Group, name, and value parameter may not be empty.');
218218
return false;
219219
}
220220

221221
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.');
222+
throw new ISPConfigRemoteException('record_nonexist_error', 'There is no record with this group plus name field combination.');
223223
return false;
224224
}
225225

@@ -232,13 +232,13 @@ public function config_value_replace($session_id, $group, $name, $value)
232232
global $app;
233233

234234
if(!$this->checkPerm($session_id, 'config_value_replace')) {
235-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
235+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
236236
return false;
237237
}
238238

239239
// validate fields
240240
if($group == '' || $name == '' || $value == '') {
241-
throw new SoapFault('field_empty_error', 'Group, name, and value parameter may not be empty.');
241+
throw new ISPConfigRemoteException('field_empty_error', 'Group, name, and value parameter may not be empty.');
242242
return false;
243243
}
244244

@@ -255,18 +255,18 @@ public function config_value_delete($session_id, $group, $name)
255255
global $app;
256256

257257
if(!$this->checkPerm($session_id, 'config_value_delete')) {
258-
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
258+
throw new ISPConfigRemoteException('permission_denied', 'You do not have the permissions to access this function.');
259259
return false;
260260
}
261261

262262
// validate fields
263263
if($group == '' || $name == '') {
264-
throw new SoapFault('field_empty_error', 'Group and name parameter may not be empty.');
264+
throw new ISPConfigRemoteException('field_empty_error', 'Group and name parameter may not be empty.');
265265
return false;
266266
}
267267

268268
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.');
269+
throw new ISPConfigRemoteException('record_nonexist_error', 'There is no record with this group plus name field combination.');
270270
return false;
271271
}
272272

0 commit comments

Comments
 (0)