summaryrefslogtreecommitdiffstats
path: root/src/etc
diff options
context:
space:
mode:
authorPiBa-NL <pba_2k3@yahoo.com>2016-09-08 01:09:44 +0200
committerPiBa-NL <pba_2k3@yahoo.com>2016-09-08 01:09:44 +0200
commit4d7522bfc56cfd18f6d0df9fcea73715516b56d0 (patch)
tree2c69055c2d0c6e6602ad8a3334131054bcf8ac60 /src/etc
parenta8620841be1ad5ecced36091cb8bc716df32789c (diff)
downloadpfsense-4d7522bfc56cfd18f6d0df9fcea73715516b56d0.zip
pfsense-4d7522bfc56cfd18f6d0df9fcea73715516b56d0.tar.gz
XMLRPC, xmlrpc_client simplify construction parameters where possible + cleanup
Diffstat (limited to 'src/etc')
-rw-r--r--src/etc/inc/voucher.inc6
-rw-r--r--src/etc/inc/xmlrpc_client.inc31
-rwxr-xr-xsrc/etc/rc.filter_synchronize30
3 files changed, 39 insertions, 28 deletions
diff --git a/src/etc/inc/voucher.inc b/src/etc/inc/voucher.inc
index 9144daa..94fcd66 100644
--- a/src/etc/inc/voucher.inc
+++ b/src/etc/inc/voucher.inc
@@ -42,7 +42,7 @@ function xmlrpc_sync_voucher_expire($vouchers, $syncip, $port, $password, $usern
voucher_expire("$vouchers");
EOF;
- $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $rpc_client = new pfsense_xmlrpc_client_extended($syncip, $port, $username, $password);
$resp = $rpc_client->xmlrpc_exec_php($execcmd);
if (empty($resp)) {
return false;
@@ -66,7 +66,7 @@ function xmlrpc_sync_voucher_disconnect($dbent, $syncip, $port, $password, $user
captiveportal_disconnect(\$dbent, \$radiusservers, $term_cause, $tmp_stop_time);
EOF;
- $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $rpc_client = new pfsense_xmlrpc_client_extended($syncip, $port, $username, $password);
$resp = $rpc_client->xmlrpc_exec_php($execcmd);
if (empty($resp)) {
return false;
@@ -90,7 +90,7 @@ function xmlrpc_sync_used_voucher($voucher_received, $syncip, $port, $password,
\$toreturn['voucher']['roll'] = \$config['voucher'][\$cpzone]['roll'];
EOF;
- $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $rpc_client = new pfsense_xmlrpc_client_extended($syncip, $port, $username, $password);
$resp = $rpc_client->xmlrpc_exec_php($execcmd);
if (!is_array($config['voucher'])) {
diff --git a/src/etc/inc/xmlrpc_client.inc b/src/etc/inc/xmlrpc_client.inc
index 1ef3107..92b48da 100644
--- a/src/etc/inc/xmlrpc_client.inc
+++ b/src/etc/inc/xmlrpc_client.inc
@@ -21,7 +21,7 @@
require_once("XML/RPC2/Client.php");
-class pfsense_xmlrpc_client {
+class pfsense_xmlrpc_client_extended {
private $username, $password, $url, $filenotice, $error;
@@ -77,13 +77,13 @@ class pfsense_xmlrpc_client {
$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();
+ $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 method2 {$method} # " . $e->getMessage() . htmlspecialchars(print_r(debug_backtrace(),true))."DUS";
+ $this->error = "Exception calling XMLRPC method {$method} # " . $e->getMessage();
log_error($this->error);
file_notice($this->filenotice, $this->error, gettext("Error code received"), "");
continue;
@@ -114,3 +114,28 @@ class pfsense_xmlrpc_client {
return $this->error;
}
}
+
+class pfsense_xmlrpc_client extends pfsense_xmlrpc_client_extended {
+ /* Default sync class */
+ 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";
+ }
+ }
+ parent::__construct($hasync['synchronizetoip'], $port, $username, $hasync['password']);
+ }
+
+} \ No newline at end of file
diff --git a/src/etc/rc.filter_synchronize b/src/etc/rc.filter_synchronize
index a0e0277..8d108aa 100755
--- a/src/etc/rc.filter_synchronize
+++ b/src/etc/rc.filter_synchronize
@@ -85,14 +85,14 @@ function remove_special_characters($string) {
return $string;
}
-function carp_check_version($syncip, $port, $username, $password) {
+function carp_check_version() {
global $config, $g;
if (file_exists("{$g['varrun_path']}/booting") || platform_booting()) {
return;
}
- $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $rpc_client = new pfsense_xmlrpc_client();
$resp = $rpc_client->xmlrpc_method('host_firmware_version');
log_error(sprintf(gettext("XMLRPC versioncheck:").$resp['config_version'] ." -- ". $config['version']));
@@ -107,7 +107,7 @@ function carp_check_version($syncip, $port, $username, $password) {
return false;
}
-function carp_sync_xml($syncip, $port, $username, $password, $sections) {
+function carp_sync_xml($sections) {
global $config, $g;
if (file_exists("{$g['varrun_path']}/booting") || platform_booting()) {
@@ -209,7 +209,7 @@ function carp_sync_xml($syncip, $port, $username, $password, $sections) {
}
}
- $rpc_client = new pfsense_xmlrpc_client($syncip, $port, $username, $password);
+ $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}.");
@@ -352,31 +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 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'])) {
+
+ if (!carp_check_version()) {
return;
}
update_filter_reload_status("Signaling CARP reload signal...");
- if (!carp_sync_xml($hasync['synchronizetoip'], $port, $username, $hasync['password'], $sections)) {
+ if (!carp_sync_xml($sections)) {
return;
}
- $rpc_client = new pfsense_xmlrpc_client($hasync['synchronizetoip'], $port, $username, $hasync['password']);
+ $rpc_client = new pfsense_xmlrpc_client();
$resp = $rpc_client->xmlrpc_method('filter_configure', "", 900);
}
OpenPOWER on IntegriCloud