diff options
author | Renato Botelho <renato@netgate.com> | 2016-09-13 15:56:00 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-09-13 15:56:00 -0300 |
commit | 0ae266afd3a2130398855ec2a5eddb71631defd0 (patch) | |
tree | 8573f708ff13b4e25e6494687017930ca7c5ec48 | |
parent | 96ca183a728bd20a8f2453289a9590e2b5a04a1b (diff) | |
parent | eecfac71cfb1a27869a92b14314d5c2ecc1b9fa1 (diff) | |
download | pfsense-0ae266afd3a2130398855ec2a5eddb71631defd0.zip pfsense-0ae266afd3a2130398855ec2a5eddb71631defd0.tar.gz |
Merge pull request #3131 from PiBa-NL/20160906-generic-xmlrpc_client
-rw-r--r-- | src/etc/inc/voucher.inc | 183 | ||||
-rw-r--r-- | src/etc/inc/xmlrpc_client.inc | 137 | ||||
-rw-r--r-- | src/etc/pfSense.obsoletedfiles | 1 | ||||
-rwxr-xr-x | src/etc/rc.filter_synchronize | 192 | ||||
-rw-r--r-- | src/usr/local/www/services_captiveportal_vouchers.php | 61 |
5 files changed, 199 insertions, 375 deletions
diff --git a/src/etc/inc/voucher.inc b/src/etc/inc/voucher.inc index 073746e..4ceec0a 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,20 @@ 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(); + $rpc_client->setConnectionData($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 +67,18 @@ 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(); + $rpc_client->setConnectionData($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 +92,17 @@ 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(); + $rpc_client->setConnectionData($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..45c4910 --- /dev/null +++ b/src/etc/inc/xmlrpc_client.inc @@ -0,0 +1,137 @@ +<?php +/* + * xmlrpc_client.php + * + * part of pfSense (https://www.pfsense.org) + * Copyright (c) 2016 Rubicon Communications, LLC (Netgate) + * 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() { + global $config; + $hasync = $config['hasync']; + + if (empty($hasync['username'])) { + $username = "admin"; + } else { + $username = $hasync['username']; + } + /* 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"; + } + } + $this->setConnectionData($hasync['synchronizetoip'], $port, $username, $hasync['password']); + } + + public function setConnectionData($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}]"; + } + 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 method {$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 method {$method} # " . $e->getMessage(); + 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; + } +}
\ No newline at end of file diff --git a/src/etc/pfSense.obsoletedfiles b/src/etc/pfSense.obsoletedfiles index ff07481..ebee8ea 100644 --- a/src/etc/pfSense.obsoletedfiles +++ b/src/etc/pfSense.obsoletedfiles @@ -35,7 +35,6 @@ /etc/inc/sysctl.inc /etc/inc/uuid.php /etc/inc/xmlrpc.inc -/etc/inc/xmlrpc_client.inc /etc/inc/xmlrpc_server.inc /etc/inc/zeromq.inc /etc/inetd.conf diff --git a/src/etc/rc.filter_synchronize b/src/etc/rc.filter_synchronize index b39b269..c363ff2 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() { 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(); + $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($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(); + $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'] != "") { @@ -452,51 +352,17 @@ if (is_array($config['hasync'])) { log_error("Nothing has been configured to be synched. Skipping...."); return; } - - if (empty($hasync['username'])) { - $username = "admin"; - } else { - $username = $hasync['username']; - } - - if (!carp_check_version($synchronizetoip, $username, $hasync['password'])) { + + if (!carp_check_version()) { return; } update_filter_reload_status("Signaling CARP reload signal..."); - if (!carp_sync_xml($synchronizetoip, $username, $hasync['password'], $sections)) { + if (!carp_sync_xml($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(); + $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 4e76793..5bb2b3d 100644 --- a/src/usr/local/www/services_captiveportal_vouchers.php +++ b/src/usr/local/www/services_captiveportal_vouchers.php @@ -290,65 +290,28 @@ 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(); + $rpc_client->setConnectionData( + $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']) { |