diff options
author | PiBa-NL <pba_2k3@yahoo.com> | 2016-09-22 20:00:51 +0200 |
---|---|---|
committer | PiBa-NL <pba_2k3@yahoo.com> | 2016-10-06 20:12:55 +0200 |
commit | dfbd0052d224bb65bc706cfed9e1a9266386b51a (patch) | |
tree | b18bf16a920b244b6dab5b42b6778fbded046e11 | |
parent | 05100687b3300f44423a2009c25d810a05fe9b26 (diff) | |
download | pfsense-dfbd0052d224bb65bc706cfed9e1a9266386b51a.zip pfsense-dfbd0052d224bb65bc706cfed9e1a9266386b51a.tar.gz |
XMLRPC, xmlrpc_client, add new scheme parameter in setConnectionData(syncip,port,user,pass,schema), for use by packages that sync to custom locations, set public/private on all functions
-rw-r--r-- | src/etc/inc/xmlrpc_client.inc | 66 | ||||
-rwxr-xr-x | src/etc/rc.filter_synchronize | 3 |
2 files changed, 47 insertions, 22 deletions
diff --git a/src/etc/inc/xmlrpc_client.inc b/src/etc/inc/xmlrpc_client.inc index 45c4910..3db6bfe 100644 --- a/src/etc/inc/xmlrpc_client.inc +++ b/src/etc/inc/xmlrpc_client.inc @@ -21,6 +21,8 @@ require_once("XML/RPC2/Client.php"); +define('PEAR_IGNORE_BACKTRACE', 1); + class pfsense_xmlrpc_client { private $username, $password, $url, $filenotice, $error; @@ -45,35 +47,34 @@ class pfsense_xmlrpc_client { } $this->setConnectionData($hasync['synchronizetoip'], $port, $username, $hasync['password']); } - - public function setConnectionData($syncip, $port, $username, $password) { + + public function setConnectionData($syncip, $port, $username, $password, $scheme = "") { 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 (empty($scheme)) { + $scheme = "http"; + if ($port == "443") { + $scheme = "https"; + } else if (is_array($config['system']) && + is_array($config['system']['webgui']) && + !empty($config['system']['webgui']['protocol']) && + $config['system']['webgui']['protocol'] == "https") { + $scheme = "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"; - } + $this->url = "{$scheme}://{$syncip}:{$port}/xmlrpc.php"; } - - function set_noticefile($noticefile) { + + public function set_noticefile($noticefile) { $this->filenotice = $noticefile; } - - function xmlrpc_internal($method, $parameter, $timeout = 240) { + + private function xmlrpc_internal($method, $parameter, $timeout = 240) { $this->error = null; $options = array( 'prefix' => 'pfsense.', @@ -94,6 +95,8 @@ class pfsense_xmlrpc_client { continue; } try {//restore_config_section + $REQUEST_URI = $_SERVER['REQUEST_URI']; + unset($_SERVER['REQUEST_URI']); // force use of 'toText()' when setting XML_RPC2_CurlException message $resp = $cli->$method($this->username, $this->password, $parameter); } catch (XML_RPC2_FaultException $e) { // The XMLRPC server returns a XMLRPC error @@ -101,12 +104,29 @@ class pfsense_xmlrpc_client { log_error($this->error); file_notice($this->filenotice, $this->error, "Communications error occurred", ""); continue; + } catch (XML_RPC2_CurlException $e) { + $previouserror = $e->getPrevious();// HTTP_Request2_ConnectionException + if ($previouserror == null) { + // CurlException doesnt get filled with PreviousError, + // however we dont want to show the stacktrace included in the 'message' to non sysadmin users + $this->error = "CurlException calling XMLRPC method {$method} #" . strtok($e->getMessage(), "\n"); + } else { + $this->error = "CurlException calling XMLRPC method {$method} #" . $previouserror->getMessage(); + } + 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; + } finally { + if (isset($REQUEST_URI)) { + // restore the unset variable to its previous state. + $_SERVER['REQUEST_URI'] = $REQUEST_URI; + } } if (!is_array($resp) && trim($resp) == "Authentication failed") { @@ -121,17 +141,21 @@ class pfsense_xmlrpc_client { return null; } - function xmlrpc_exec_php($execcmd, $timeout = 240) { + public function xmlrpc_exec_php($execcmd, $timeout = 240) { $resp = $this->xmlrpc_internal("exec_php", $execcmd, $timeout); return $resp; } - function xmlrpc_method($method, $parameter = "", $timeout = 240) { + public function xmlrpc_method($method, $parameter = "", $timeout = 240) { $resp = $this->xmlrpc_internal($method, $parameter, $timeout); return $resp; } - function get_error() { + public function get_error() { return $this->error; } + + public function getUrl() { + return $this->url; + } }
\ No newline at end of file diff --git a/src/etc/rc.filter_synchronize b/src/etc/rc.filter_synchronize index c363ff2..a6f6aa7 100755 --- a/src/etc/rc.filter_synchronize +++ b/src/etc/rc.filter_synchronize @@ -212,7 +212,8 @@ function carp_sync_xml($sections) { $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}."); + $url = $rpc_client->getUrl(); + update_filter_reload_status("XMLRPC sync successfully completed with {$url}."); return true; } return false; |