From 0fce8c16f197599d3ec33f54494b00d085f8e4ae Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Mon, 2 Sep 2019 15:25:21 +0200
Subject: [PATCH] Fixed #5351 Remote API function dns_templatezone_add issue
 Added test script for dns_templatezone_add remote API function

---
 interface/lib/classes/remote.d/aps.inc.php    |  3 ++
 interface/lib/classes/remote.d/dns.inc.php    |  4 +-
 .../examples/dns_templatezone_add.php         | 50 +++++++++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 remoting_client/examples/dns_templatezone_add.php

diff --git a/interface/lib/classes/remote.d/aps.inc.php b/interface/lib/classes/remote.d/aps.inc.php
index 50dda48255..4cca7fb8b6 100644
--- a/interface/lib/classes/remote.d/aps.inc.php
+++ b/interface/lib/classes/remote.d/aps.inc.php
@@ -238,6 +238,9 @@ class remoting_aps extends remoting {
 			throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.');
 			return false;
 		}
+		
+		$app->uses('remoting_lib');
+		$app->remoting_lib->loadUserProfile(0);
 	
 		$app->load('aps_guicontroller');
 		$gui = new ApsGUIController($app);
diff --git a/interface/lib/classes/remote.d/dns.inc.php b/interface/lib/classes/remote.d/dns.inc.php
index 7e0b230d7f..434af6a983 100644
--- a/interface/lib/classes/remote.d/dns.inc.php
+++ b/interface/lib/classes/remote.d/dns.inc.php
@@ -56,7 +56,9 @@ class remoting_dns extends remoting {
 		$tform_def_file = "../../web/dns/form/dns_soa.tform.php";
 		$app->uses('tform');
 		$app->tform->loadFormDef($tform_def_file);
-		$app->uses('tpl,validate_dns');
+		$app->uses('tpl,validate_dns,remoting_lib');
+		
+		$app->remoting_lib->loadUserProfile($client_id);
 
 		//* replace template placeholders
 		$tpl_content = $template_record['template'];
diff --git a/remoting_client/examples/dns_templatezone_add.php b/remoting_client/examples/dns_templatezone_add.php
new file mode 100644
index 0000000000..aedfc61f5d
--- /dev/null
+++ b/remoting_client/examples/dns_templatezone_add.php
@@ -0,0 +1,50 @@
+<?php
+
+require 'soap_config.php';
+
+// Disable SSL verification for this test script
+$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.
+        $client_id = 1;
+        $template_id = 1;
+        $domain = 'test.tld';
+        $ip = '192.168.0.100';
+        $ns1 = 'ns1.testhoster.tld';
+        $ns2 = 'ns2.testhoster.tld';
+        $email = 'email.test.tld';
+
+        $id = $client->dns_templatezone_add($session_id, $client_id, $template_id, $domain, $ip, $ns1, $ns2, $email);
+
+        echo "ID: ".$id."<br>";
+
+        if($client->logout($session_id)) {
+                echo 'Logged out.<br />';
+        }
+
+
+} catch (SoapFault $e) {
+        echo $client->__getLastResponse();
+        die('SOAP Error: '.$e->getMessage());
+}
+
+?>
\ No newline at end of file
-- 
GitLab