From f14c9296cce8eb6e52ddb09961476469d3743118 Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Thu, 13 Jul 2017 11:41:52 +0200
Subject: [PATCH] Added remote api function 'system_config_set'.

---
 interface/lib/classes/remote.d/admin.inc.php  | 28 ++++++++++++
 interface/web/admin/lib/remote.conf.php       |  2 +-
 .../examples/system_config_set.php            | 45 +++++++++++++++++++
 3 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 remoting_client/examples/system_config_set.php

diff --git a/interface/lib/classes/remote.d/admin.inc.php b/interface/lib/classes/remote.d/admin.inc.php
index 33063d6542..a46c952a53 100644
--- a/interface/lib/classes/remote.d/admin.inc.php
+++ b/interface/lib/classes/remote.d/admin.inc.php
@@ -103,6 +103,34 @@ class remoting_admin extends remoting {
 		return $app->db->datalogUpdate( $tablename, $permissions, $index_field, $index_value ) ;
 	}
 	
+	/**
+	 Set a value in the system configuration
+	 @param int session id
+	 @param int server id
+	 @param string  section of the config field in the server table. Could be 'web', 'dns', 'mail', 'dns', 'cron', etc
+	 @param string key of the option that you want to set
+	 @param string option value that you want to set
+	 */
+
+
+	public function system_config_set($session_id, $section, $key, $value) {
+			global $app;
+			if(!$this->checkPerm($session_id, 'system_config_set')) {
+				throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
+				return false;
+			}
+			if ($section != '' && $key != '') {
+				$app->uses('remoting_lib,getconf,ini_parser');
+				$system_config_array = $app->getconf->get_global_config();
+				$system_config_array[$section][$key] = $value;
+				$system_config_str = $app->ini_parser->get_ini_string($system_config_array);
+				$app->db->datalogUpdate('sys_ini', array("config" => $system_config_str), 'sysini_id', 1);
+			} else {
+				throw new SoapFault('invalid_function_parameter', 'Invalid function parameter.');
+				return false;
+			}
+	}
+	
 
 }
 
diff --git a/interface/web/admin/lib/remote.conf.php b/interface/web/admin/lib/remote.conf.php
index bb9bba0d6c..5e711fac6b 100644
--- a/interface/web/admin/lib/remote.conf.php
+++ b/interface/web/admin/lib/remote.conf.php
@@ -1,6 +1,6 @@
 <?php
 
-$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';
+$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'] = 'Server functions';
 $function_list['admin_record_permissions'] = 'Record permission changes';
 
 ?>
diff --git a/remoting_client/examples/system_config_set.php b/remoting_client/examples/system_config_set.php
new file mode 100644
index 0000000000..a7a9d662c0
--- /dev/null
+++ b/remoting_client/examples/system_config_set.php
@@ -0,0 +1,45 @@
+<?php
+
+require 'soap_config.php';
+
+$context = stream_context_create([
+    'ssl' => [
+        // set some SSL/TLS specific options
+        'verify_peer' => false,
+        'verify_peer_name' => false,
+        'allow_self_signed' => true
+    ]
+]);
+
+
+$client = new SoapClient(null, array('location' => $soap_location,
+		'uri'      => $soap_uri,
+		'trace' => 1,
+		'exceptions' => 1,
+		'stream_context' => $context));
+
+
+try {
+	if($session_id = $client->login($username, $password)) {
+		echo 'Logged successfull. Session ID:'.$session_id.'<br />';
+	}
+
+	//* Set the function parameters.
+	$server_id = 1;
+
+	$result = $client->system_config_set($session_id, 'misc', 'company_name', 'ISPConfig');
+
+	print_r($result);
+	echo "<br>";
+
+	if($client->logout($session_id)) {
+		echo 'Logged out.<br />';
+	}
+
+
+} catch (SoapFault $e) {
+	echo $client->__getLastResponse();
+	die('SOAP Error: '.$e->getMessage());
+}
+
+?>
-- 
GitLab