aboutsummaryrefslogtreecommitdiffstats
path: root/config/sarg/sarg.inc
diff options
context:
space:
mode:
Diffstat (limited to 'config/sarg/sarg.inc')
-rw-r--r--config/sarg/sarg.inc85
1 files changed, 60 insertions, 25 deletions
diff --git a/config/sarg/sarg.inc b/config/sarg/sarg.inc
index 5d0a91a5..32cca7ed 100644
--- a/config/sarg/sarg.inc
+++ b/config/sarg/sarg.inc
@@ -434,31 +434,63 @@ function sarg_validate_input($post, &$input_errors) {
}
}
-
/* Uses XMLRPC to synchronize the changes to a remote node */
function sarg_sync_on_changes() {
global $config, $g;
-
- log_error("[sarg] sarg_xmlrpc_sync.php is starting.");
- $synconchanges = $config['installedpackages']['sargsync']['config'][0]['synconchanges'];
- if(!$synconchanges)
- return;
- foreach ($config['installedpackages']['sargsync']['config'] as $rs ){
- foreach($rs['row'] as $sh){
- $sync_to_ip = $sh['ipaddress'];
- $password = $sh['password'];
- if($sh['username'])
- $username = $sh['username'];
- else
- $username = 'admin';
- if($password && $sync_to_ip)
- sarg_do_xmlrpc_sync($sync_to_ip, $username, $password);
+ if (is_array($config['installedpackages']['sargsync']['config'])){
+ $sarg_sync=$config['installedpackages']['sargsync']['config'][0];
+ $synconchanges = $sarg_sync['synconchanges'];
+ $synctimeout = $sarg_sync['synctimeout'];
+ switch ($synconchanges){
+ case "manual":
+ if (is_array($sarg_sync[row])){
+ $rs=$sarg_sync[row];
+ }
+ else{
+ log_error("[sarg] xmlrpc sync is enabled but there is no hosts to push on sarg config.");
+ return;
+ }
+ break;
+ case "auto":
+ if (is_array($config['installedpackages']['carpsettings']) && is_array($config['installedpackages']['carpsettings']['config'])){
+ $system_carp=$config['installedpackages']['carpsettings']['config'][0];
+ $rs[0]['ipaddress']=$system_carp['synchronizetoip'];
+ $rs[0]['username']=$system_carp['username'];
+ $rs[0]['password']=$system_carp['password'];
+ if ($system_carp['synchronizetoip'] =="" || $system_carp['username']==""){
+ log_error("[sarg] xmlrpc sync is enabled but there is no system backup hosts to push sarg config.");
+ return;
+ }
+
+ }
+ else{
+ log_error("[sarg] xmlrpc sync is enabled but there is no system backup hosts to push sarg config.");
+ return;
+ }
+ break;
+ default:
+ return;
+ break;
+ }
+ if (is_array($rs)){
+ log_error("[sarg] xmlrpc sync is starting.");
+ foreach($rs as $sh){
+ $sync_to_ip = $sh['ipaddress'];
+ $password = $sh['password'];
+ if($sh['username'])
+ $username = $sh['username'];
+ else
+ $username = 'admin';
+ if($password && $sync_to_ip)
+ sarg_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout);
+ }
+ log_error("[sarg] xmlrpc sync is ending.");
}
- }
- log_error("[sarg] sarg_xmlrpc_sync.php is ending.");
+ }
}
+
/* Do the actual XMLRPC sync */
-function sarg_do_xmlrpc_sync($sync_to_ip, $username, $password) {
+function sarg_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout) {
global $config, $g;
if(!$username)
@@ -469,7 +501,10 @@ function sarg_do_xmlrpc_sync($sync_to_ip, $username, $password) {
if(!$sync_to_ip)
return;
-
+
+ if(!$synctimeout)
+ $synctimeout="150";
+
$xmlrpc_sync_neighbor = $sync_to_ip;
if($config['system']['webgui']['protocol'] != "") {
$synchronizetoip = $config['system']['webgui']['protocol'];
@@ -504,15 +539,15 @@ function sarg_do_xmlrpc_sync($sync_to_ip, $username, $password) {
$cli->setCredentials($username, $password);
if($g['debug'])
$cli->setDebug(1);
- /* send our XMLRPC message and timeout after 250 seconds */
- $resp = $cli->send($msg, "250");
+ /* send our XMLRPC message and timeout after $synctimeout seconds */
+ $resp = $cli->send($msg, $synctimeout);
if(!$resp) {
$error = "A communications error occurred while attempting sarg XMLRPC sync with {$url}:{$port}.";
log_error($error);
file_notice("sync_settings", $error, "sarg Settings Sync", "");
} elseif($resp->faultCode()) {
$cli->setDebug(1);
- $resp = $cli->send($msg, "250");
+ $resp = $cli->send($msg, $synctimeout);
$error = "An error code was received while attempting sarg XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
log_error($error);
file_notice("sync_settings", $error, "sarg Settings Sync", "");
@@ -534,14 +569,14 @@ function sarg_do_xmlrpc_sync($sync_to_ip, $username, $password) {
$msg = new XML_RPC_Message($method, $params);
$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
$cli->setCredentials($username, $password);
- $resp = $cli->send($msg, "250");
+ $resp = $cli->send($msg, $synctimeout);
if(!$resp) {
$error = "A communications error occurred while attempting sarg XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
log_error($error);
file_notice("sync_settings", $error, "sarg Settings Sync", "");
} elseif($resp->faultCode()) {
$cli->setDebug(1);
- $resp = $cli->send($msg, "250");
+ $resp = $cli->send($msg, $synctimeout);
$error = "An error code was received while attempting sarg XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
log_error($error);
file_notice("sync_settings", $error, "sarg Settings Sync", "");