summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiBa-NL <pba_2k3@yahoo.com>2016-09-06 02:36:45 +0200
committerPiBa-NL <pba_2k3@yahoo.com>2016-09-06 02:37:45 +0200
commita8620841be1ad5ecced36091cb8bc716df32789c (patch)
tree9c094e93470492bb36f5093aed5b376721614ecd
parent1c1f08f92e8841f7282280caeed7613edd810453 (diff)
downloadpfsense-a8620841be1ad5ecced36091cb8bc716df32789c.zip
pfsense-a8620841be1ad5ecced36091cb8bc716df32789c.tar.gz
XMLRPC, generic xmlrpc_client implementation + bugfixes in voucher sync
-rw-r--r--src/etc/inc/voucher.inc180
-rw-r--r--src/etc/inc/xmlrpc_client.inc116
-rwxr-xr-xsrc/etc/rc.filter_synchronize194
-rw-r--r--src/usr/local/www/services_captiveportal_vouchers.php60
4 files changed, 182 insertions, 368 deletions
diff --git a/src/etc/inc/voucher.inc b/src/etc/inc/voucher.inc
index 1ed3845..9144daa 100644
--- a/src/etc/inc/voucher.inc
+++ b/src/etc/inc/voucher.inc
@@ -30,22 +30,9 @@ if (!function_exists('captiveportal_syslog')) {
}
function xmlrpc_sync_voucher_expire($vouchers, $syncip, $port, $password, $username) {
- global $g, $config, $cpzone;
- require_once("XML/RPC2/Client.php");
-
- $protocol = "http";
- if (is_array($config['system']) &&
- is_array($config['system']['webgui']) &&
- !empty($config['system']['webgui']['protocol']) &&
- $config['system']['webgui']['protocol'] == "https") {
- $protocol = "https";
- }
- if ($protocol == "https" || $port == "443") {
- $url = "https://{$syncip}:{$port}";
- } else {
- $url = "http://{$syncip}:{$port}";
- }
-
+ global $cpzone;
+ require_once("xmlrpc_client.inc");
+
/* Construct code that is run on remote machine */
$execcmd = <<<EOF
global \$cpzone;
@@ -55,67 +42,19 @@ function xmlrpc_sync_voucher_expire($vouchers, $syncip, $port, $password, $usern
voucher_expire("$vouchers");
EOF;
-
- $options = array(
- 'prefix' => 'pfsense.',
- 'sslverify' => false,
- 'connectionTimeout' => 240
- );
-
- log_error(sprintf(gettext("Captive Portal Voucher XMLRPC sync data %s."), $url));
- $cli = XML_RPC2_Client::create($url, $options);
- if (!is_object($cli)) {
- $error = sprintf(gettext("A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with %s (pfsense.exec_php)."), $url);
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return false;
- }
-
- try {
- $resp = $cli->exec_php($username, $password, $execcmd);
- } catch (XML_RPC2_FaultException $e) {
- // The XMLRPC server returns a XMLRPC error
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getFaultCode() . ' : ' . $e->getFaultString();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", "");
- return false;
- } catch (Exception $e) {
- // Other errors (HTTP or networking problems...)
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getMessage();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, gettext("Error code received"), "");
- return false;
- }
-
- if (!is_array($resp) && trim($resp) == "Authentication failed") {
- $error = "An authentication failure occurred while trying to access {$url} (exec_php).";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
+ $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $resp = $rpc_client->xmlrpc_exec_php($execcmd);
+ if (empty($resp)) {
return false;
}
-
- log_error(sprintf(gettext("CaptivePortalVoucherSync XMLRPC reload data success with %s (pfsense.exec_php)."), $url));
-
return $resp;
}
function xmlrpc_sync_voucher_disconnect($dbent, $syncip, $port, $password, $username, $term_cause = 1, $stop_time = null) {
- global $g, $config, $cpzone;
- require_once("XML/RPC2/Client.php");
-
- $protocol = "http";
- if (is_array($config['system']) && is_array($config['system']['webgui']) && !empty($config['system']['webgui']['protocol']) &&
- $config['system']['webgui']['protocol'] == "https") {
- $protocol = "https";
- }
- if ($protocol == "https" || $port == "443") {
- $url = "https://{$syncip}:{$port}";
- } else {
- $url = "http://{$syncip}:{$port}";
- }
-
+ global $cpzone;
+ require_once("xmlrpc_client.inc");
/* Construct code that is run on remote machine */
- $dbent_str = serialize($dbent);
+ $dbent_str = addslashes(serialize($dbent));
$tmp_stop_time = (isset($stop_time)) ? $stop_time : "null";
$execcmd = <<<EOF
global \$cpzone;
@@ -127,64 +66,17 @@ function xmlrpc_sync_voucher_disconnect($dbent, $syncip, $port, $password, $user
captiveportal_disconnect(\$dbent, \$radiusservers, $term_cause, $tmp_stop_time);
EOF;
-
- $options = array(
- 'prefix' => 'pfsense.',
- 'sslverify' => false,
- 'connectionTimeout' => 240
- );
-
- log_error(sprintf(gettext("Captive Portal Voucher XMLRPC sync data %s."), $url));
- $cli = XML_RPC2_Client::create($url, $options);
- if (!is_object($cli)) {
- $error = sprintf(gettext("A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with %s (pfsense.exec_php)."), $url);
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
+ $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $resp = $rpc_client->xmlrpc_exec_php($execcmd);
+ if (empty($resp)) {
return false;
}
-
- try {
- $resp = $cli->exec_php($username, $password, $execcmd);
- } catch (XML_RPC2_FaultException $e) {
- // The XMLRPC server returns a XMLRPC error
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getFaultCode() . ' : ' . $e->getFaultString();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", "");
- return false;
- } catch (Exception $e) {
- // Other errors (HTTP or networking problems...)
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getMessage();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, gettext("Error code received"), "");
- return false;
- }
-
- if (!is_array($resp) && trim($resp) == "Authentication failed") {
- $error = "An authentication failure occurred while trying to access {$url} (exec_php).";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return false;
- }
-
- log_error(sprintf(gettext("CaptivePortalVoucherSync XMLRPC reload data success with %s (pfsense.exec_php)."), $url));
-
return $resp;
}
function xmlrpc_sync_used_voucher($voucher_received, $syncip, $port, $password, $username) {
- global $g, $config, $cpzone;
- require_once("XML/RPC2/Client.php");
-
- $protocol = "http";
- if (is_array($config['system']) && is_array($config['system']['webgui']) && !empty($config['system']['webgui']['protocol']) &&
- $config['system']['webgui']['protocol'] == "https") {
- $protocol = "https";
- }
- if ($protocol == "https" || $port == "443") {
- $url = "https://{$syncip}:{$port}";
- } else {
- $url = "http://{$syncip}:{$port}";
- }
+ global $config, $cpzone;
+ require_once("xmlrpc_client.inc");
/* Construct code that is run on remote machine */
$execcmd = <<<EOF
@@ -198,52 +90,16 @@ function xmlrpc_sync_used_voucher($voucher_received, $syncip, $port, $password,
\$toreturn['voucher']['roll'] = \$config['voucher'][\$cpzone]['roll'];
EOF;
-
- $options = array(
- 'prefix' => 'pfsense.',
- 'sslverify' => false,
- 'connectionTimeout' => 240
- );
-
- log_error(sprintf(gettext("Captive Portal Voucher XMLRPC sync data %s."), $url));
- $cli = XML_RPC2_Client::create($url, $options);
- if (!is_object($cli)) {
- $error = sprintf(gettext("A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with %s (pfsense.exec_php)."), $url);
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return null;
- }
-
- try {
- $resp = $cli->exec_php($username, $password, $execcmd);
- } catch (XML_RPC2_FaultException $e) {
- // The XMLRPC server returns a XMLRPC error
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getFaultCode() . ' : ' . $e->getFaultString();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", "");
- return null;
- } catch (Exception $e) {
- // Other errors (HTTP or networking problems...)
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getMessage();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, gettext("Error code received"), "");
- return null;
- }
-
- if (!is_array($resp) && trim($resp) == "Authentication failed") {
- $error = "An authentication failure occurred while trying to access {$url} (exec_php).";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return null;
- }
-
+ $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $resp = $rpc_client->xmlrpc_exec_php($execcmd);
+
if (!is_array($config['voucher'])) {
$config['voucher'] = array();
}
if (is_array($resp['voucher']['roll'])) {
$config['voucher'][$cpzone]['roll'] = $resp['voucher']['roll'];
- write_config(sprintf(gettext("Captive Portal Voucher database synchronized with %s"), $url));
+ write_config(sprintf(gettext("Captive Portal Voucher database synchronized with %s:%s"), $syncip, $port));
voucher_configure_zone(true);
unset($resp['voucher']);
} else if (!isset($resp['timeleft'])) {
diff --git a/src/etc/inc/xmlrpc_client.inc b/src/etc/inc/xmlrpc_client.inc
new file mode 100644
index 0000000..1ef3107
--- /dev/null
+++ b/src/etc/inc/xmlrpc_client.inc
@@ -0,0 +1,116 @@
+<?php
+/*
+ * xmlrpc_client.php
+ *
+ * part of pfSense (https://www.pfsense.org)
+ * Copyright (c) 2016 Electric Sheep Fencing, LLC
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+require_once("XML/RPC2/Client.php");
+
+class pfsense_xmlrpc_client {
+
+ private $username, $password, $url, $filenotice, $error;
+
+ public function __construct($syncip, $port, $username, $password) {
+ global $config;
+ $this->username = $username;
+ $this->password = $password;
+ $this->filenotice = "sync_settings";
+
+ $protocol = "http";
+ if (is_array($config['system']) &&
+ is_array($config['system']['webgui']) &&
+ !empty($config['system']['webgui']['protocol']) &&
+ $config['system']['webgui']['protocol'] == "https") {
+ $protocol = "https";
+ }
+ if (is_ipaddrv6($syncip)) {
+ $syncip = "[{$syncip}]";
+ }
+ //TODO: check if the url needs to end with?:
+ if ($protocol == "https" || $port == "443") {
+ $this->url = "https://{$syncip}:{$port}/xmlrpc.php";
+ } else {
+ $this->url = "http://{$syncip}:{$port}/xmlrpc.php";
+ }
+ }
+
+ function set_noticefile($noticefile) {
+ $this->filenotice = $noticefile;
+ }
+
+ function xmlrpc_internal($method, $parameter, $timeout = 240) {
+ $this->error = null;
+ $options = array(
+ 'prefix' => 'pfsense.',
+ 'sslverify' => false,
+ 'connectionTimeout' => $timeout
+ );
+
+ $numberofruns = 0;
+ while ($numberofruns < 2) {
+ $numberofruns++;
+
+ log_error(sprintf(gettext("Beginning XMLRPC sync data to %s."), $this->url));
+ $cli = XML_RPC2_Client::create($this->url, $options);
+ if (!is_object($cli)) {
+ $this->error = sprintf(gettext("A communications error occurred while attempting XMLRPC sync with %s (pfsense.%s)."), $this->url, $method);
+ log_error($this->error);
+ file_notice($this->filenotice, $this->error, "Settings Sync", "");
+ continue;
+ }
+ try {//restore_config_section
+ $resp = $cli->$method($this->username, $this->password, $parameter);
+ } catch (XML_RPC2_FaultException $e) {
+ // The XMLRPC server returns a XMLRPC error
+ $this->error = "Exception calling XMLRPC method1 {$method} #" . $e->getFaultCode() . ' : ' . $e->getFaultString();
+ log_error($this->error);
+ file_notice($this->filenotice, $this->error, "Communications error occurred", "");
+ continue;
+ } catch (Exception $e) {
+ // Other errors (HTTP or networking problems...)
+ $this->error = "Exception calling XMLRPC method2 {$method} # " . $e->getMessage() . htmlspecialchars(print_r(debug_backtrace(),true))."DUS";
+ log_error($this->error);
+ file_notice($this->filenotice, $this->error, gettext("Error code received"), "");
+ continue;
+ }
+
+ if (!is_array($resp) && trim($resp) == "Authentication failed") {
+ $this->error = "An authentication failure occurred while trying to access {$this->url} ({$method}).";
+ log_error($this->error);
+ file_notice($this->filenotice, $this->error, "Settings Sync", "");
+ continue;
+ }
+ log_error(sprintf(gettext("XMLRPC reload data success with %s (pfsense.{$method})."), $this->url));
+ return $resp;
+ }
+ return null;
+ }
+
+ function xmlrpc_exec_php($execcmd, $timeout = 240) {
+ $resp = $this->xmlrpc_internal("exec_php", $execcmd, $timeout);
+ return $resp;
+ }
+
+ function xmlrpc_method($method, $parameter = "", $timeout = 240) {
+ $resp = $this->xmlrpc_internal($method, $parameter, $timeout);
+ return $resp;
+ }
+ function get_error() {
+ return $this->error;
+ }
+}
diff --git a/src/etc/rc.filter_synchronize b/src/etc/rc.filter_synchronize
index 88bebab..a0e0277 100755
--- a/src/etc/rc.filter_synchronize
+++ b/src/etc/rc.filter_synchronize
@@ -31,8 +31,8 @@ require_once("config.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
-require_once("XML/RPC2/Client.php");
require_once("interfaces.inc");
+require_once("xmlrpc_client.inc");
/*
* backup_vip_config_section($section): returns as an xml file string of
@@ -85,75 +85,35 @@ function remove_special_characters($string) {
return $string;
}
-function carp_check_version($url, $username, $password, $method = 'host_firmware_version') {
+function carp_check_version($syncip, $port, $username, $password) {
global $config, $g;
if (file_exists("{$g['varrun_path']}/booting") || platform_booting()) {
return;
}
- $options = array(
- 'prefix' => 'pfsense.',
- 'sslverify' => false,
- 'connectionTimeout' => 240
- );
+ $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $resp = $rpc_client->xmlrpc_method('host_firmware_version');
- $numberofruns = 0;
- while ($numberofruns < 2) {
- $numberofruns++;
-
- $cli = XML_RPC2_Client::create($url, $options);
- if (!is_object($cli)) {
- $error = "A communications error occurred while attempting XMLRPC sync with username {$username} {$url}.";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- continue;
- }
-
- try {
- $resp = $cli->$method($username, $password);
- } catch (XML_RPC2_FaultException $e) {
- // The XMLRPC server returns a XMLRPC error
- $error = 'Exception calling XMLRPC method ' . $method . ' #' . $e->getFaultCode() . ' : ' . $e->getFaultString();
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- continue;
- } catch (Exception $e) {
- // Other errors (HTTP or networking problems...)
- $error = 'Exception calling XMLRPC method ' . $method . ' #' . $e->getMessage();
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- continue;
- }
-
- if (!is_array($resp)) {
- if (trim($resp) == "Authentication failed") {
- $error = "An authentication failure occurred while trying to access {$url} ({$method}).";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return false;
- }
- } elseif (!isset($resp['config_version']) ||
- ($resp['config_version'] != $config['version'])) {
- update_filter_reload_status("The other member is on a different configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
- log_error("The other member is on a different configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
- return false;
- } else {
- return true;
- }
+ log_error(sprintf(gettext("XMLRPC versioncheck:").$resp['config_version'] ." -- ". $config['version']));
+ if (!isset($resp['config_version']) ||
+ ($resp['config_version'] != $config['version'])) {
+ update_filter_reload_status("The other member is on a different configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
+ log_error("The other member is on a different configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
+ return false;
+ } else {
+ return true;
}
return false;
}
-function carp_sync_xml($url, $username, $password, $sections, $method = 'restore_config_section') {
+function carp_sync_xml($syncip, $port, $username, $password, $sections) {
global $config, $g;
if (file_exists("{$g['varrun_path']}/booting") || platform_booting()) {
return true;
}
- update_filter_reload_status("Syncing CARP data to {$url}");
-
/* make a copy of config */
$config_copy = $config;
@@ -243,58 +203,18 @@ function carp_sync_xml($url, $username, $password, $sections, $method = 'restore
break;
case 'authserver':
$xml['system'][$section] = $config_copy['system'][$section];
+ break;
default:
$xml[$section] = $config_copy[$section];
}
}
-
- $options = array(
- 'prefix' => 'pfsense.',
- 'sslverify' => false,
- 'connectionTimeout' => 240
- );
-
- $numberofruns = 0;
- while ($numberofruns < 2) {
- $numberofruns++;
-
- log_error("Beginning XMLRPC sync to {$url}.");
- $cli = XML_RPC2_Client::create($url, $options);
- if (!is_object($cli)) {
- $error = "A communications error occurred while attempting XMLRPC sync with username {$username} {$url}.";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- continue;
- }
-
- try {
- $resp = $cli->$method($username, $password, $xml);
- } catch (XML_RPC2_FaultException $e) {
- // The XMLRPC server returns a XMLRPC error
- $error = 'Exception calling XMLRPC method ' . $method . '#' . $e->getFaultCode() . ' : ' . $e->getFaultString();
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- continue;
- } catch (Exception $e) {
- // Other errors (HTTP or networking problems...)
- $error = 'Exception calling XMLRPC method ' . $method . ' #' . $e->getMessage();
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- continue;
- }
-
- if (!is_array($resp) && trim($resp) == "Authentication failed") {
- $error = "An authentication failure occurred while trying to access {$url} ($method).";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return false;
- } else {
- log_error("XMLRPC sync successfully completed with {$url}.");
- update_filter_reload_status("XMLRPC sync successfully completed with {$url}.");
- return true;
- }
+
+ $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $resp = $rpc_client->xmlrpc_method('restore_config_section', $xml);
+ if ($resp != null) {
+ update_filter_reload_status("XMLRPC sync successfully completed with {$syncip}:{$port}.");
+ return true;
}
-
return false;
}
@@ -311,29 +231,6 @@ if (is_array($config['hasync'])) {
return;
}
- /*
- * XXX: The way we're finding the port right now is really suboptimal -
- * we can't assume that the other machine is setup identically.
- */
- if (!empty($config['system']['webgui']['protocol'])) {
- $synchronizetoip = $config['system']['webgui']['protocol'];
- $synchronizetoip .= "://";
- }
-
- /* if port is empty lets rely on the protocol selection */
- $port = $config['system']['webgui']['port'];
- if (empty($port)) {
- if ($config['system']['webgui']['protocol'] == "http") {
- $port = "80";
- } else {
- $port = "443";
- }
- }
-
- if (is_ipaddrv6($hasync['synchronizetoip'])) {
- $hasync['synchronizetoip'] = "[{$hasync['synchronizetoip']}]";
- }
- $synchronizetoip .= $hasync['synchronizetoip'] . ":{$port}/xmlrpc.php";
if ($hasync['synchronizerules'] != "") {
if (!is_array($config['filter'])) {
$config['filter'] = array();
@@ -425,6 +322,9 @@ if (is_array($config['hasync'])) {
$sections[] = 'group';
}
if ($hasync['synchronizeauthservers'] != "") {
+ if (!is_array($config['system']['authserver'])) {
+ $config['system']['authserver'] = array();
+ }
$sections[] = 'authserver';
}
if ($hasync['synchronizednsforwarder'] != "") {
@@ -458,45 +358,25 @@ if (is_array($config['hasync'])) {
} else {
$username = $hasync['username'];
}
-
- if (!carp_check_version($synchronizetoip, $username, $hasync['password'])) {
+ /* if port is empty lets rely on the protocol selection */
+ $port = $config['system']['webgui']['port'];
+ if (empty($port)) {
+ if ($config['system']['webgui']['protocol'] == "http") {
+ $port = "80";
+ } else {
+ $port = "443";
+ }
+ }
+ if (!carp_check_version($hasync['synchronizetoip'], $port, $username, $hasync['password'])) {
return;
}
update_filter_reload_status("Signaling CARP reload signal...");
- if (!carp_sync_xml($synchronizetoip, $username, $hasync['password'], $sections)) {
+ if (!carp_sync_xml($hasync['synchronizetoip'], $port, $username, $hasync['password'], $sections)) {
return;
}
- $options = array(
- 'prefix' => 'pfsense.',
- 'sslverify' => false,
- 'connectionTimeout' => 900
- );
-
- $cli = XML_RPC2_Client::create($synchronizetoip, $options);
- if (!is_object($cli)) {
- $error = "A communications error occurred while attempting Filter sync with username {$username} {$synchronizetoip}.";
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- } else {
- try {
- $resp = $cli->filter_configure($username, $hasync['password']);
- } catch (XML_RPC2_FaultException $e) {
- // The XMLRPC server returns a XMLRPC error
- $error = 'Exception calling XMLRPC method filter_configure #' . $e->getFaultCode() . ' : ' . $e->getFaultString();
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return;
- } catch (Exception $e) {
- // Other errors (HTTP or networking problems...)
- $error = 'Exception calling XMLRPC method filter_configure #' . $e->getMessage();
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- return;
- }
- log_error("Filter sync successfully completed with {$synchronizetoip}.");
- }
+ $rpc_client = new pfsense_xmlrpc_client($hasync['synchronizetoip'], $port, $username, $hasync['password']);
+ $resp = $rpc_client->xmlrpc_method('filter_configure', "", 900);
+
}
-
-?>
diff --git a/src/usr/local/www/services_captiveportal_vouchers.php b/src/usr/local/www/services_captiveportal_vouchers.php
index b6cf157..80d49c1 100644
--- a/src/usr/local/www/services_captiveportal_vouchers.php
+++ b/src/usr/local/www/services_captiveportal_vouchers.php
@@ -290,65 +290,27 @@ if ($_POST) {
}
if ($newvoucher['vouchersyncpass'] && $newvoucher['vouchersyncusername'] &&
$newvoucher['vouchersyncport'] && $newvoucher['vouchersyncdbip']) {
- // Synchronize the voucher DB from the master node
- require_once("XML/RPC2/Client.php");
-
- $protocol = "http";
- if (is_array($config['system']) && is_array($config['system']['webgui']) && !empty($config['system']['webgui']['protocol']) &&
- $config['system']['webgui']['protocol'] == "https") {
- $protocol = "https";
- }
- if ($protocol == "https" || $newvoucher['vouchersyncport'] == "443") {
- $url = "https://{$newvoucher['vouchersyncdbip']}";
- } else {
- $url = "http://{$newvoucher['vouchersyncdbip']}";
- }
- $url .= ":{$newvoucher['vouchersyncport']}/xmlrpc.php";
+ // Synchronize the voucher DB from the master node
$execcmd = <<<EOF
+ global \$config;
\$toreturn = array();
\$toreturn['voucher'] = \$config['voucher']['$cpzone'];
unset(\$toreturn['vouchersyncport'], \$toreturn['vouchersyncpass'], \$toreturn['vouchersyncusername'], \$toreturn['vouchersyncdbip']);
EOF;
-
- $options = array(
- 'prefix' => 'pfsense.',
- 'sslverify' => false,
- 'connectionTimeout' => 240
- );
-
- log_error(sprintf(gettext("voucher XMLRPC sync data %s"), $url));
- $cli = XML_RPC2_Client::create($url, $options);
- if (!is_object($cli)) {
- $error = sprintf(gettext("A communications error occurred while attempting CaptivePortalVoucherSync XMLRPC sync with %s (pfsense.exec_php)."), $url);
- log_error($error);
- file_notice("sync_settings", $error, "Settings Sync", "");
- $input_errors[] = $error;
- } else {
- try {
- $resp = $cli->exec_php($newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass'], $execcmd);
- } catch (XML_RPC2_FaultException $e) {
- // The XMLRPC server returns a XMLRPC error
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getFaultCode() . ' : ' . $e->getFaultString();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, "Communications error occurred", "");
- $input_errors[] = $error;
- } catch (Exception $e) {
- // Other errors (HTTP or networking problems...)
- $error = 'Exception calling XMLRPC method exec_php #' . $e->getMessage();
- log_error($error);
- file_notice("CaptivePortalVoucherSync", $error, gettext("Error code received"), "");
- $input_errors[] = $error;
- }
+ require_once("xmlrpc_client.inc");
+ $rpc_client = new pfsense_xmlrpc_client(
+ $newvoucher['vouchersyncdbip'], $newvoucher['vouchersyncport'],
+ $newvoucher['vouchersyncusername'], $newvoucher['vouchersyncpass']);
+ $rpc_client->set_noticefile("CaptivePortalVoucherSync");
+ $resp = $rpc_client->xmlrpc_exec_php($execcmd);
+ if ($resp == null) {
+ $input_errors[] = $rpc_client->get_error();
}
if (!$input_errors) {
- if (!is_array($resp)) {
- if ($resp == "Authentication failed") {
- $input_errors[] = gettext("Could not synchronize the voucher database: Authentication Failed.");
- }
- } else {
+ if (is_array($resp)) {
log_error(sprintf(gettext("The Captive Portal voucher database has been synchronized with %s (pfsense.exec_php)."), $url));
// If we received back the voucher roll and other information then store it.
if ($resp['voucher']['roll']) {
OpenPOWER on IntegriCloud