aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcello Coutinho <marcellocoutinho@gmail.com>2013-04-25 02:01:07 -0300
committerMarcello Coutinho <marcellocoutinho@gmail.com>2013-04-25 02:01:07 -0300
commit2091092ce056338746a23b342b75921112922ccd (patch)
tree9eec5714df582077eaad918cd02211ae80337275
parent64671ccfc12ac87839540de3cb011d7cfcf03401 (diff)
downloadpfsense-packages-2091092ce056338746a23b342b75921112922ccd.tar.gz
pfsense-packages-2091092ce056338746a23b342b75921112922ccd.tar.bz2
pfsense-packages-2091092ce056338746a23b342b75921112922ccd.zip
squid3 - change sync gui to accept system sync
-rw-r--r--config/squid-reverse/squid.inc81
-rwxr-xr-xconfig/squid-reverse/squid_reverse_sync.xml30
-rwxr-xr-xconfig/squid-reverse/squid_sync.xml28
3 files changed, 107 insertions, 32 deletions
diff --git a/config/squid-reverse/squid.inc b/config/squid-reverse/squid.inc
index 55d4a372..c8a803cc 100644
--- a/config/squid-reverse/squid.inc
+++ b/config/squid-reverse/squid.inc
@@ -5,7 +5,7 @@
Copyright (C) 2006-2009 Scott Ullrich
Copyright (C) 2006 Fernando Lemos
Copyright (C) 2012 Martin Fuchs
- Copyright (C) 2012 Marcello Coutinho
+ Copyright (C) 2012-2013 Marcello Coutinho
Copyright (C) 2013 Gekkenhuis
All rights reserved.
@@ -1851,27 +1851,55 @@ EOD;
/* Uses XMLRPC to synchronize the changes to a remote node */
function squid_sync_on_changes() {
global $config, $g;
-
- log_error("[squid] xmlrpc sync is starting.");
- $synconchanges = $config['installedpackages']['squidsync']['config'][0]['synconchanges'];
- if(!$synconchanges)
- return;
- foreach ($config['installedpackages']['squidsync']['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)
- squid_do_xmlrpc_sync($sync_to_ip, $username, $password);
+ print"<PRE>";
+ if (is_array($config['installedpackages']['squidsync']['config'])){
+ $squid_sync=$config['installedpackages']['squidsync']['config'][0];
+ $synconchanges = $squid_sync['synconchanges'];
+ $synctimeout = $squid_sync['synctimeout'];
+ switch ($synconchanges){
+ case "manual":
+ if (is_array($squid_sync[row])){
+ $rs=$squid_sync[row];
+ }
+ else{
+ log_error("[squid] xmlrpc sync is enabled but there is no hosts to push on squid 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'];
+ }
+ else{
+ log_error("[squid] xmlrpc sync is enabled but there is no system backup hosts to push squid config.");
+ return;
+ }
+ break;
+ default:
+ return;
+ break;
+ }
+ if (is_array($rs)){
+ log_error("[squid] 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)
+ squid_do_xmlrpc_sync($sync_to_ip, $username, $password,$synctimeout);
+ }
+ log_error("[squid] xmlrpc sync is ending.");
}
- }
- log_error("[squid] xmlrpc sync is ending.");
+ }
}
/* Do the actual XMLRPC sync */
-function squid_do_xmlrpc_sync($sync_to_ip, $username, $password) {
+function squid_do_xmlrpc_sync($sync_to_ip, $username, $password, $synctimeout) {
global $config, $g;
if(!$username)
@@ -1883,6 +1911,10 @@ function squid_do_xmlrpc_sync($sync_to_ip, $username, $password) {
if(!$sync_to_ip)
return;
+ if(!$synctimeout)
+ $synctimeout=250;
+
+
$xmlrpc_sync_neighbor = $sync_to_ip;
if($config['system']['webgui']['protocol'] != "") {
$synchronizetoip = $config['system']['webgui']['protocol'];
@@ -1925,15 +1957,15 @@ function squid_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 defined sync timeout value*/
+ $resp = $cli->send($msg, $synctimeout);
if(!$resp) {
$error = "A communications error occurred while attempting squid XMLRPC sync with {$url}:{$port}.";
log_error($error);
file_notice("sync_settings", $error, "squid 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 squid XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
log_error($error);
file_notice("sync_settings", $error, "squid Settings Sync", "");
@@ -1955,14 +1987,14 @@ function squid_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 squid XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
log_error($error);
file_notice("sync_settings", $error, "squid 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 squid XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
log_error($error);
file_notice("sync_settings", $error, "squid Settings Sync", "");
@@ -1971,5 +2003,4 @@ function squid_do_xmlrpc_sync($sync_to_ip, $username, $password) {
}
}
-
?>
diff --git a/config/squid-reverse/squid_reverse_sync.xml b/config/squid-reverse/squid_reverse_sync.xml
index db5e6145..041576b8 100755
--- a/config/squid-reverse/squid_reverse_sync.xml
+++ b/config/squid-reverse/squid_reverse_sync.xml
@@ -9,7 +9,7 @@
/*
squid_sync.xml
part of the sarg package for pfSense
- Copyright (C) 2012 Marcello Coutinho
+ Copyright (C) 2012-2013 Marcello Coutinho
All rights reserved.
*/
/* ========================================================================== */
@@ -17,7 +17,7 @@
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- 1. Redistributions of source code must retain the above copyright notice,
+ 1. Redistributions of source code MUST retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
@@ -80,8 +80,30 @@
<field>
<fielddescr>Automatically sync squid configuration changes</fielddescr>
<fieldname>synconchanges</fieldname>
- <description>Automatically sync squid(normal and reverse) changes to the hosts defined below.</description>
- <type>checkbox</type>
+ <description>Select a sync method for squid.</description>
+ <type>select</type>
+ <required/>
+ <default_value>auto</default_value>
+ <options>
+ <option><name>Sync to configured system backup server</name><value>auto</value></option>
+ <option><name>Sync to host(s) defined below</name><value>manual</value></option>
+ <option><name>Do not sync this package configuration</name><value>disabled</value></option>
+ </options>
+ </field>
+ <field>
+ <fielddescr>Sync timeout</fielddescr>
+ <fieldname>synctimeout</fieldname>
+ <description>Select sync max wait time</description>
+ <type>select</type>
+ <required/>
+ <default_value>250</default_value>
+ <options>
+ <option><name>250 seconds(Default)</name><value>250</value></option>
+ <option><name>120 seconds</name><value>120</value></option>
+ <option><name>90 seconds</name><value>90</value></option>
+ <option><name>60 seconds</name><value>60</value></option>
+ <option><name>30 seconds</name><value>30</value></option>
+ </options>
</field>
<field>
<fielddescr>Remote Server</fielddescr>
diff --git a/config/squid-reverse/squid_sync.xml b/config/squid-reverse/squid_sync.xml
index 62a726f4..cdd91e78 100755
--- a/config/squid-reverse/squid_sync.xml
+++ b/config/squid-reverse/squid_sync.xml
@@ -9,7 +9,7 @@
/*
squid_sync.xml
part of the sarg package for pfSense
- Copyright (C) 2012 Marcello Coutinho
+ Copyright (C) 2012-2013 Marcello Coutinho
All rights reserved.
*/
/* ========================================================================== */
@@ -92,8 +92,30 @@
<field>
<fielddescr>Automatically sync squid configuration changes</fielddescr>
<fieldname>synconchanges</fieldname>
- <description>Automatically sync squid(normal and reverse) changes to the hosts defined below.</description>
- <type>checkbox</type>
+ <description>Select a sync method for squid.</description>
+ <type>select</type>
+ <required/>
+ <default_value>auto</default_value>
+ <options>
+ <option><name>Sync to configured system backup server</name><value>auto</value></option>
+ <option><name>Sync to host(s) defined below</name><value>manual</value></option>
+ <option><name>Do not sync this package configuration</name><value>disabled</value></option>
+ </options>
+ </field>
+ <field>
+ <fielddescr>Sync timeout</fielddescr>
+ <fieldname>synctimeout</fieldname>
+ <description>Select sync max wait time</description>
+ <type>select</type>
+ <required/>
+ <default_value>250</default_value>
+ <options>
+ <option><name>250 seconds(Default)</name><value>250</value></option>
+ <option><name>120 seconds</name><value>120</value></option>
+ <option><name>90 seconds</name><value>90</value></option>
+ <option><name>60 seconds</name><value>60</value></option>
+ <option><name>30 seconds</name><value>30</value></option>
+ </options>
</field>
<field>
<fielddescr>Remote Server</fielddescr>