Skip to content

Commit 813beb2

Browse files
author
Till Brehm
committed
Added remote api function to set system > server config values.
1 parent 4baefe2 commit 813beb2

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,34 @@ public function server_get($session_id, $server_id = null, $section ='') {
142142
}
143143
}
144144

145+
/**
146+
Set a value in the server configuration
147+
@param int session id
148+
@param int server id
149+
@param string section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
150+
@param string key of the option that you want to set
151+
@param string option value that you want to set
152+
*/
153+
154+
155+
public function server_config_set($session_id, $server_id, $section, $key, $value) {
156+
global $app;
157+
if(!$this->checkPerm($session_id, 'server_config_set')) {
158+
throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
159+
return false;
160+
}
161+
if (!empty($server_id) && $server_id > 0 && $section != '' && $key != '') {
162+
$app->uses('remoting_lib,getconf,ini_parser');
163+
$server_config_array = $app->getconf->get_server_config($server_id);
164+
$server_config_array[$section][$key] = $value;
165+
$server_config_str = $app->ini_parser->get_ini_string($server_config_array);
166+
$app->db->datalogUpdate('server', array("config" => $server_config_str), 'server_id', $server_id);
167+
} else {
168+
throw new SoapFault('invalid_function_parameter', 'Invalid function parameter.');
169+
return false;
170+
}
171+
}
172+
145173
/**
146174
Gets a list of all servers
147175
@param int session_id
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,get_function_list,client_templates_get_all,server_get_serverid_by_ip,server_ip_get,server_ip_add,server_ip_update,server_ip_delete'] = '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'] = 'Server functions';
44
$function_list['admin_record_permissions'] = 'Record permission changes';
55

66
?>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
require 'soap_config.php';
4+
5+
$context = stream_context_create([
6+
'ssl' => [
7+
// set some SSL/TLS specific options
8+
'verify_peer' => false,
9+
'verify_peer_name' => false,
10+
'allow_self_signed' => true
11+
]
12+
]);
13+
14+
15+
$client = new SoapClient(null, array('location' => $soap_location,
16+
'uri' => $soap_uri,
17+
'trace' => 1,
18+
'exceptions' => 1,
19+
'stream_context' => $context));
20+
21+
22+
try {
23+
if($session_id = $client->login($username, $password)) {
24+
echo 'Logged successfull. Session ID:'.$session_id.'<br />';
25+
}
26+
27+
//* Set the function parameters.
28+
$server_id = 1;
29+
30+
$result = $client->server_config_set($session_id, $server_id, 'server', 'migration_mode', 'y');
31+
32+
print_r($result);
33+
echo "<br>";
34+
35+
if($client->logout($session_id)) {
36+
echo 'Logged out.<br />';
37+
}
38+
39+
40+
} catch (SoapFault $e) {
41+
echo $client->__getLastResponse();
42+
die('SOAP Error: '.$e->getMessage());
43+
}
44+
45+
?>

0 commit comments

Comments
 (0)