From d0301611abd503ee932c83012594fccc974e8aab Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Tue, 17 Nov 2009 18:55:45 -0500 Subject: Adding XML RPX Configuration synchronization capabilities --- config/haproxy/haproxy.inc | 74 +++++++++++++++++++++++++++++++++++++++ config/haproxy/haproxy_global.php | 69 +++++++++++++++++++++++++++++++----- 2 files changed, 134 insertions(+), 9 deletions(-) (limited to 'config') diff --git a/config/haproxy/haproxy.inc b/config/haproxy/haproxy.inc index e87e0817..6c226269 100644 --- a/config/haproxy/haproxy.inc +++ b/config/haproxy/haproxy.inc @@ -195,6 +195,20 @@ function haproxy_configure() { } fwrite ($fd, "\n"); } + if(isset($config['installedpackages']['haproxy']['enablesync'])) { + if($config['installedpackages']['haproxy']['synchost1']) { + haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost1'], + $config['installedpackages']['haproxy']['syncpassword']); + } + if($config['installedpackages']['haproxy']['synchost2']) { + haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost2'], + $config['installedpackages']['haproxy']['syncpassword']); + } + if($config['installedpackages']['haproxy']['synchost3']) { + haproxy_do_xmlrpc_sync($config['installedpackages']['haproxy']['synchost3'], + $config['installedpackages']['haproxy']['syncpassword']); + } + } } // create config file @@ -213,4 +227,64 @@ function haproxy_configure() { } } +function haproxy_do_xmlrpc_sync($sync_to_ip, $password) { + global $config, $g; + + if(!$password) + return; + + if(!$sync_to_ip) + return; + + $xmlrpc_sync_neighbor = $sync_to_ip; + if($config['system']['webgui']['protocol'] != "") { + $synchronizetoip = $config['system']['webgui']['protocol']; + $synchronizetoip .= "://"; + } + $port = $config['system']['webgui']['port']; + /* if port is empty lets rely on the protocol selection */ + if($port == "") { + if($config['system']['webgui']['protocol'] == "http") + $port = "80"; + else + $port = "443"; + } + $synchronizetoip .= $sync_to_ip; + + /* xml will hold the sections to sync */ + $xml = array(); + $xml['haproxy'] = $config['installedpackages']['haproxy']; + + /* assemble xmlrpc payload */ + $params = array( + XML_RPC_encode($password), + XML_RPC_encode($xml) + ); + + /* set a few variables needed for sync code borrowed from filter.inc */ + $url = $synchronizetoip; + log_error("Beginning HAProxy XMLRPC sync to {$url}:{$port}."); + $method = 'pfsense.merge_installedpackages_section_xmlrpc'; + $msg = new XML_RPC_Message($method, $params); + $cli = new XML_RPC_Client('/xmlrpc.php', $url, $port); + $cli->setCredentials('admin', $password); + if($g['debug']) + $cli->setDebug(1); + /* send our XMLRPC message and timeout after 250 seconds */ + $resp = $cli->send($msg, "250"); + if(!$resp) { + $error = "A communications error occurred while attempting HAProxy XMLRPC sync with {$url}:{$port}."; + log_error($error); + file_notice("sync_settings", $error, "HAProxy Settings Sync", ""); + } elseif($resp->faultCode()) { + $cli->setDebug(1); + $resp = $cli->send($msg, "250"); + $error = "An error code was received while attempting HAProxy XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString(); + log_error($error); + file_notice("sync_settings", $error, "HAProxy Settings Sync", ""); + } else { + log_error("HAProxy XMLRPC sync successfully completed with {$url}:{$port}."); + } +} + ?> \ No newline at end of file diff --git a/config/haproxy/haproxy_global.php b/config/haproxy/haproxy_global.php index 18a32954..af159f58 100755 --- a/config/haproxy/haproxy_global.php +++ b/config/haproxy/haproxy_global.php @@ -35,17 +35,20 @@ require_once("haproxy.inc"); $d_haproxyconfdirty_path = $g['varrun_path'] . "/haproxy.conf.dirty"; -if (!is_array($config['installedpackages']['haproxy'])) { +if (!is_array($config['installedpackages']['haproxy'])) $config['installedpackages']['haproxy'] = array(); -} $pconfig['enable'] = isset($config['installedpackages']['haproxy']['enable']); $pconfig['maxconn'] = $config['installedpackages']['haproxy']['maxconn']; +$pconfig['enablesync'] = isset($config['installedpackages']['haproxy']['enablesync']); +$pconfig['syncpassword'] = $config['installedpackages']['haproxy']['syncpassword']; +$pconfig['synchost1'] = $config['installedpackages']['haproxy']['synchost1']; +$pconfig['synchost2'] = $config['installedpackages']['haproxy']['synchost2']; +$pconfig['synchost3'] = $config['installedpackages']['haproxy']['synchost3']; if ($_POST) { unset($input_errors); $pconfig = $_POST; - if ($_POST['apply']) { $retval = 0; @@ -58,19 +61,27 @@ if ($_POST) { if ($_POST['enable']) { $reqdfields = explode(" ", "maxconn"); $reqdfieldsn = explode(",", "Maximum connections"); - } else { } do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - if ($_POST['maxconn'] && (!is_numeric($_POST['maxconn']))) { + if ($_POST['maxconn'] && (!is_numeric($_POST['maxconn']))) $input_errors[] = "The maximum number of connections should be numeric."; - } + + if($_POST['synchost1'] && !is_ipaddr($_POST['synchost1'])) + $input_errors[] = "Synchost1 needs to be an IPAddress."; + if($_POST['synchost2'] && !is_ipaddr($_POST['synchost2'])) + $input_errors[] = "Synchost2 needs to be an IPAddress."; + if($_POST['synchost3'] && !is_ipaddr($_POST['synchost3'])) + $input_errors[] = "Synchost3 needs to be an IPAddress."; if (!$input_errors) { $config['installedpackages']['haproxy']['enable'] = $_POST['enable'] ? true : false; $config['installedpackages']['haproxy']['maxconn'] = $_POST['maxconn'] ? $_POST['maxconn'] : false; - + $config['installedpackages']['haproxy']['enablesync'] = $_POST['enablesync'] ? true : false; + $config['installedpackages']['haproxy']['synchost1'] = $_POST['synchost1'] ? $_POST['synchost1'] : false; + $config['installedpackages']['haproxy']['synchost2'] = $_POST['synchost2'] ? $_POST['synchost2'] : false; + $config['installedpackages']['haproxy']['synchost2'] = $_POST['synchost3'] ? $_POST['synchost3'] : false; touch($d_haproxyconfdirty_path); write_config(); } @@ -142,11 +153,12 @@ function enable_change(enable_change) { Sets the maximum per-process number of concurrent connections to X.
NOTE: setting this value too high will result in haproxy not being able to allocate enough memory.
-Current memory usage {$hascpu}.

"; -?> + ?> + @@ -182,6 +194,45 @@ function enable_change(enable_change) {   + + + + + + + + + + + + + + + + + + + + + + +
Connections
  + > + Sync XMLRPC configuration to backup CARP members
Synchronization password + + Enter the password that will be used during configuration synchronization. This is generally the remote webConfigurator password. +
Sync host #1 + + Synchronize settings to this hosts IP address. +
Sync host #2 + + Synchronize settings to this hosts IP address. +
Sync host #3 + + Synchronize settings to this hosts IP address. +
+   +
  -- cgit v1.2.3