Commit 82546f3b authored by Ad Schellevis's avatar Ad Schellevis

(legacy) cleanup spaces and add curly braces in rc.filter_synchronize before...

(legacy) cleanup spaces and add curly braces in rc.filter_synchronize before changing things there...
parent 32d82fd5
...@@ -2,33 +2,33 @@ ...@@ -2,33 +2,33 @@
<?php <?php
/* /*
Copyright (C) 2004-2006 Scott Ullrich Copyright (C) 2004-2006 Scott Ullrich
Copyright (C) 2005 Bill Marquette Copyright (C) 2005 Bill Marquette
Copyright (C) 2006 Peter Allgeyer Copyright (C) 2006 Peter Allgeyer
Copyright (C) 2008 Ermal Luci Copyright (C) 2008 Ermal Luci
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: 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. this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("config.inc"); require_once("config.inc");
...@@ -43,363 +43,389 @@ require_once("util.inc"); ...@@ -43,363 +43,389 @@ require_once("util.inc");
* the configuration section * the configuration section
*/ */
function backup_vip_config_section() { function backup_vip_config_section() {
global $config; global $config;
if (!is_array($config['virtualip']['vip'])) if (!is_array($config['virtualip']['vip'])) {
return; return;
$temp = array(); }
$temp['vip'] = array(); $temp = array();
foreach($config['virtualip']['vip'] as $section) { $temp['vip'] = array();
if ($section['mode'] != "carp") foreach($config['virtualip']['vip'] as $section) {
continue; if ($section['mode'] != "carp") {
if ($section['advskew'] <> "") { continue;
$section_val = intval($section['advskew']); }
$section_val=$section_val+100; if ($section['advskew'] <> "") {
if ($section_val > 254) $section_val = intval($section['advskew']);
$section_val = 254; $section_val=$section_val+100;
$section['advskew'] = $section_val; if ($section_val > 254) {
} $section_val = 254;
if ($section['advbase'] <> "") { }
$section_val = intval($section['advbase']); $section['advskew'] = $section_val;
if ($section_val > 254) }
$section_val = 254; if ($section['advbase'] <> "") {
$section['advbase'] = $section_val; $section_val = intval($section['advbase']);
} if ($section_val > 254) {
$temp['vip'][] = $section; $section_val = 254;
} }
return $temp; $section['advbase'] = $section_val;
}
$temp['vip'][] = $section;
}
return $temp;
} }
function remove_special_characters($string) { function remove_special_characters($string) {
$match_array = ""; $match_array = "";
preg_match_all("/[a-zA-Z0-9\_\-]+/",$string,$match_array); preg_match_all("/[a-zA-Z0-9\_\-]+/",$string,$match_array);
$string = ""; $string = "";
foreach ($match_array[0] as $ma) { foreach ($match_array[0] as $ma) {
if ($string <> "") if ($string <> "") {
$string .= " "; $string .= " ";
$string .= $ma; }
} $string .= $ma;
return $string; }
return $string;
} }
function carp_check_version($url, $username, $password, $method = 'opnsense.firmware_version') { function carp_check_version($url, $username, $password, $method = 'opnsense.firmware_version') {
global $config, $g; global $config, $g;
if (file_exists('/var/run/booting')) {
return;
}
$client = new SimpleXMLRPC_Client($url,240);
$client->setCredentials($username, $password);
if ($client->query($method)) {
$remote_version = $client->getResponse();
} else {
// propagate error to log
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ;
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
// print communication details on failure
echo $client->getDetails();
return false ;
}
if (!is_array($remote_version) && trim($remote_version) == "Authentication failed") {
$error = "An authentication failure occurred while trying to access {$url} ({$method}).";
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
exit;
}
if (!isset($remote_version['config_version']) ||
$remote_version['config_version'] < $config['version']) {
update_filter_reload_status("The other member is on older configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
log_error("The other member is on older configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
return false;
} else {
return true;
}
if (file_exists('/var/run/booting')) {
return;
}
$client = new SimpleXMLRPC_Client($url,240);
$client->setCredentials($username, $password);
if ($client->query($method)) {
$remote_version = $client->getResponse();
} else {
// propagate error to log
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ;
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
// print communication details on failure
echo $client->getDetails();
return false ;
}
if (!is_array($remote_version) && trim($remote_version) == "Authentication failed") {
$error = "An authentication failure occurred while trying to access {$url} ({$method}).";
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
exit;
}
if (!isset($remote_version['config_version']) ||
$remote_version['config_version'] < $config['version']) {
update_filter_reload_status("The other member is on older configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
log_error("The other member is on older configuration version of {$g['product_name']}. Sync will not be done to prevent problems!");
return false;
} else {
return true;
}
} }
function carp_sync_xml($url, $username, $password, $sections, $method = 'opnsense.restore_config_section') { function carp_sync_xml($url, $username, $password, $sections, $method = 'opnsense.restore_config_section') {
global $config, $g; global $config, $g;
if (file_exists('/var/run/booting')) { if (file_exists('/var/run/booting')) {
return; return;
} }
update_filter_reload_status("Syncing CARP data to {$url}"); update_filter_reload_status("Syncing CARP data to {$url}");
/* make a copy of config */ /* make a copy of config */
$config_copy = $config; $config_copy = $config;
/* strip out nosync items */ /* strip out nosync items */
if (is_array($config_copy['nat']) && is_array($config_copy['nat']['outbound']['rule'])) { if (is_array($config_copy['nat']) && is_array($config_copy['nat']['outbound']['rule'])) {
$rulescnt = count($config_copy['nat']['outbound']['rule']); $rulescnt = count($config_copy['nat']['outbound']['rule']);
for ($x = 0; $x < $rulescnt; $x++) { for ($x = 0; $x < $rulescnt; $x++) {
$config_copy['nat']['outbound']['rule'][$x]['descr'] = remove_special_characters($config_copy['nat']['outbound']['rule'][$x]['descr']); $config_copy['nat']['outbound']['rule'][$x]['descr'] = remove_special_characters($config_copy['nat']['outbound']['rule'][$x]['descr']);
if (isset ($config_copy['nat']['outbound']['rule'][$x]['nosync'])) if (isset ($config_copy['nat']['outbound']['rule'][$x]['nosync'])) {
unset ($config_copy['nat']['outbound']['rule'][$x]); unset ($config_copy['nat']['outbound']['rule'][$x]);
} }
} }
if (is_array($config_copy['nat']) && is_array($config_copy['nat']['rule'])) { }
$natcnt = count($config_copy['nat']['rule']); if (is_array($config_copy['nat']) && is_array($config_copy['nat']['rule'])) {
for ($x = 0; $x < $natcnt; $x++) { $natcnt = count($config_copy['nat']['rule']);
$config_copy['nat']['rule'][$x]['descr'] = remove_special_characters($config_copy['nat']['rule'][$x]['descr']); for ($x = 0; $x < $natcnt; $x++) {
if (isset ($config_copy['nat']['rule'][$x]['nosync'])) $config_copy['nat']['rule'][$x]['descr'] = remove_special_characters($config_copy['nat']['rule'][$x]['descr']);
unset ($config_copy['nat']['rule'][$x]); if (isset ($config_copy['nat']['rule'][$x]['nosync'])) {
} unset ($config_copy['nat']['rule'][$x]);
} }
if (is_array($config_copy['filter']) && is_array($config_copy['filter']['rule'])) { }
$filtercnt = count($config_copy['filter']['rule']); }
for ($x = 0; $x < $filtercnt; $x++) { if (is_array($config_copy['filter']) && is_array($config_copy['filter']['rule'])) {
$config_copy['filter']['rule'][$x]['descr'] = remove_special_characters($config_copy['filter']['rule'][$x]['descr']); $filtercnt = count($config_copy['filter']['rule']);
if (isset ($config_copy['filter']['rule'][$x]['nosync'])) for ($x = 0; $x < $filtercnt; $x++) {
unset ($config_copy['filter']['rule'][$x]); $config_copy['filter']['rule'][$x]['descr'] = remove_special_characters($config_copy['filter']['rule'][$x]['descr']);
} if (isset ($config_copy['filter']['rule'][$x]['nosync'])) {
} unset ($config_copy['filter']['rule'][$x]);
if (isset($config_copy['aliases']) && is_array($config_copy['aliases']) && is_array($config_copy['aliases']['alias'])) { }
$aliascnt = count($config_copy['aliases']['alias']); }
for ($x = 0; $x < $aliascnt; $x++) { }
$config_copy['aliases']['alias'][$x]['descr'] = remove_special_characters($config_copy['aliases']['alias'][$x]['descr']); if (isset($config_copy['aliases']) && is_array($config_copy['aliases']) && is_array($config_copy['aliases']['alias'])) {
if (isset ($config_copy['aliases']['alias'][$x]['nosync'])) $aliascnt = count($config_copy['aliases']['alias']);
unset ($config_copy['aliases']['alias'][$x]); for ($x = 0; $x < $aliascnt; $x++) {
} $config_copy['aliases']['alias'][$x]['descr'] = remove_special_characters($config_copy['aliases']['alias'][$x]['descr']);
} if (isset ($config_copy['aliases']['alias'][$x]['nosync'])) {
if (is_array($config_copy['dnsmasq']) && is_array($config_copy['dnsmasq']['hosts'])) { unset ($config_copy['aliases']['alias'][$x]);
$dnscnt = count($config_copy['dnsmasq']['hosts']); }
for ($x = 0; $x < $dnscnt; $x++) { }
$config_copy['dnsmasq']['hosts'][$x]['descr'] = remove_special_characters($config_copy['dnsmasq']['hosts'][$x]['descr']); }
if (isset ($config_copy['dnsmasq']['hosts'][$x]['nosync'])) if (is_array($config_copy['dnsmasq']) && is_array($config_copy['dnsmasq']['hosts'])) {
unset ($config_copy['dnsmasq']['hosts'][$x]); $dnscnt = count($config_copy['dnsmasq']['hosts']);
} for ($x = 0; $x < $dnscnt; $x++) {
} $config_copy['dnsmasq']['hosts'][$x]['descr'] = remove_special_characters($config_copy['dnsmasq']['hosts'][$x]['descr']);
if (isset($config_copy['ipsec']) && is_array($config_copy['ipsec']) && is_array($config_copy['ipsec']['tunnel'])) { if (isset ($config_copy['dnsmasq']['hosts'][$x]['nosync'])) {
$ipseccnt = count($config_copy['ipsec']['tunnel']); unset ($config_copy['dnsmasq']['hosts'][$x]);
for ($x = 0; $x < $ipseccnt; $x++) { }
$config_copy['ipsec']['tunnel'][$x]['descr'] = remove_special_characters($config_copy['ipsec']['tunnel'][$x]['descr']); }
if (isset ($config_copy['ipsec']['tunnel'][$x]['nosync'])) }
unset ($config_copy['ipsec']['tunnel'][$x]); if (isset($config_copy['ipsec']) && is_array($config_copy['ipsec']) && is_array($config_copy['ipsec']['tunnel'])) {
} $ipseccnt = count($config_copy['ipsec']['tunnel']);
} for ($x = 0; $x < $ipseccnt; $x++) {
$config_copy['ipsec']['tunnel'][$x]['descr'] = remove_special_characters($config_copy['ipsec']['tunnel'][$x]['descr']);
if (is_array($config_copy['dhcpd'])) { if (isset ($config_copy['ipsec']['tunnel'][$x]['nosync'])) {
foreach($config_copy['dhcpd'] as $dhcpif => $dhcpifconf) { unset ($config_copy['ipsec']['tunnel'][$x]);
if($dhcpifconf['failover_peerip'] <> "") { }
$int = guess_interface_from_ip($dhcpifconf['failover_peerip']); }
$intip = find_interface_ip($int); }
$config_copy['dhcpd'][$dhcpif]['failover_peerip'] = $intip;
} if (is_array($config_copy['dhcpd'])) {
} foreach($config_copy['dhcpd'] as $dhcpif => $dhcpifconf) {
} if($dhcpifconf['failover_peerip'] <> "") {
$int = guess_interface_from_ip($dhcpifconf['failover_peerip']);
foreach ($sections as $section) { $intip = find_interface_ip($int);
/* we can't use array_intersect_key() $config_copy['dhcpd'][$dhcpif]['failover_peerip'] = $intip;
* due to the vip 'special case' }
*/ }
switch ($section) { }
case 'virtualip':
$xml[$section] = backup_vip_config_section(); foreach ($sections as $section) {
break; /* we can't use array_intersect_key()
case 'user': * due to the vip 'special case'
$xml['system'][$section] = $config_copy['system'][$section]; */
$xml['system']['nextuid'] = $config_copy['system']['nextuid']; switch ($section) {
break; case 'virtualip':
case 'group': $xml[$section] = backup_vip_config_section();
$xml['system'][$section] = $config_copy['system'][$section]; break;
$xml['system']['nextgid'] = $config_copy['system']['nextgid']; case 'user':
break; $xml['system'][$section] = $config_copy['system'][$section];
case 'authserver': $xml['system']['nextuid'] = $config_copy['system']['nextuid'];
$xml['system'][$section] = $config_copy['system'][$section]; break;
default: case 'group':
$xml[$section] = $config_copy[$section]; $xml['system'][$section] = $config_copy['system'][$section];
} $xml['system']['nextgid'] = $config_copy['system']['nextgid'];
} break;
case 'authserver':
$xml['system'][$section] = $config_copy['system'][$section];
$client = new SimpleXMLRPC_Client($url,240); default:
$client->setCredentials($username, $password); $xml[$section] = $config_copy[$section];
if ($client->query($method, $xml)) { }
$response = $client->getResponse(); }
} else {
// propagate error to log
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ; $client = new SimpleXMLRPC_Client($url,240);
log_error($error); $client->setCredentials($username, $password);
file_notice("sync_settings", $error, "Settings Sync", ""); if ($client->query($method, $xml)) {
// print communication details on failure $response = $client->getResponse();
echo $client->getDetails(); } else {
return false ; // propagate error to log
} $error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ;
log_error($error);
if (!is_array($response) && trim($response) == "Authentication failed") { file_notice("sync_settings", $error, "Settings Sync", "");
$error = "An authentication failure occurred while trying to access {$url} ({$method})."; // print communication details on failure
log_error($error); echo $client->getDetails();
file_notice("sync_settings", $error, "Settings Sync", ""); return false ;
exit; }
}
if (!is_array($response) && trim($response) == "Authentication failed") {
return true; $error = "An authentication failure occurred while trying to access {$url} ({$method}).";
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
exit;
}
return true;
} }
global $g; global $g;
if (file_exists('/var/run/booting')) { if (file_exists('/var/run/booting')) {
return; return;
} }
if (is_array($config['hasync'])) { if (is_array($config['hasync'])) {
$sections = array(); $sections = array();
update_filter_reload_status("Building high availability information"); update_filter_reload_status("Building high availability information");
$hasync = $config['hasync']; $hasync = $config['hasync'];
if (empty($hasync['synchronizetoip'])) { if (empty($hasync['synchronizetoip'])) {
log_error("Config sync not being done because of missing sync IP (this is normal on secondary systems)."); log_error("Config sync not being done because of missing sync IP (this is normal on secondary systems).");
exit; exit;
} }
if(is_ipaddrv6($hasync['synchronizetoip'])) if(is_ipaddrv6($hasync['synchronizetoip'])) {
$hasync['synchronizetoip'] = "[{$hasync['synchronizetoip']}]"; $hasync['synchronizetoip'] = "[{$hasync['synchronizetoip']}]";
}
/*
* XXX: The way we're finding the port right now is really suboptimal - /*
* we can't assume that the other machine is setup identically. * XXX: The way we're finding the port right now is really suboptimal -
*/ * we can't assume that the other machine is setup identically.
if (!empty($config['system']['webgui']['protocol'])) { */
$port = $config['system']['webgui']['port']; if (!empty($config['system']['webgui']['protocol'])) {
if (!empty($port)) { $port = $config['system']['webgui']['port'];
$synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip'].':'.$port."/xmlrpc.php"; if (!empty($port)) {
} else { $synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip'].':'.$port."/xmlrpc.php";
$synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip']."/xmlrpc.php" ; } else {
} $synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip']."/xmlrpc.php" ;
} }
}
if (isset($hasync['synchronizerules'])) {
if (!is_array($config['filter'])) if (isset($hasync['synchronizerules'])) {
$config['filter'] = array(); if (!is_array($config['filter'])) {
$sections[] = 'filter'; $config['filter'] = array();
} }
if (isset($hasync['synchronizenat'])) { $sections[] = 'filter';
if (!is_array($config['nat'])) }
$config['nat'] = array(); if (isset($hasync['synchronizenat'])) {
$sections[] = 'nat'; if (!is_array($config['nat'])) {
} $config['nat'] = array();
if (isset($hasync['synchronizealiases'])) { }
if (!isset($config['aliases']) || !is_array($config['aliases'])) { $sections[] = 'nat';
$config['aliases'] = array(); }
} if (isset($hasync['synchronizealiases'])) {
$sections[] = 'aliases'; if (!isset($config['aliases']) || !is_array($config['aliases'])) {
} $config['aliases'] = array();
if (isset($hasync['synchronizedhcpd']) && is_array($config['dhcpd'])) }
$sections[] = 'dhcpd'; $sections[] = 'aliases';
if (isset($hasync['synchronizewol'])) { }
if (!is_array($config['wol'])) if (isset($hasync['synchronizedhcpd']) && is_array($config['dhcpd'])) {
$config['wol'] = array(); $sections[] = 'dhcpd';
$sections[] = 'wol'; }
} if (isset($hasync['synchronizewol'])) {
if (isset($hasync['synchronizestaticroutes'])) { if (!is_array($config['wol'])) {
if (!is_array($config['staticroutes'])) $config['wol'] = array();
$config['staticroutes'] = array(); }
if (!isset($config['staticroutes']['route']) || !is_array($config['staticroutes']['route'])) $sections[] = 'wol';
$config['staticroutes']['route'] = array(); }
$sections[] = 'staticroutes'; if (isset($hasync['synchronizestaticroutes'])) {
if (!is_array($config['gateways'])) if (!is_array($config['staticroutes'])) {
$config['gateways'] = array(); $config['staticroutes'] = array();
$sections[] = 'gateways'; }
} if (!isset($config['staticroutes']['route']) || !is_array($config['staticroutes']['route'])) {
if (isset($hasync['synchronizevirtualip'])) { $config['staticroutes']['route'] = array();
if (!isset($config['virtualip']) || !is_array($config['virtualip'])) }
$config['virtualip'] = array(); $sections[] = 'staticroutes';
$sections[] = 'virtualip'; if (!is_array($config['gateways'])) {
} $config['gateways'] = array();
if (isset($hasync['synchronizelb'])) { }
if (!is_array($config['load_balancer'])) $sections[] = 'gateways';
$config['load_balancer'] = array(); }
$sections[] = 'load_balancer'; if (isset($hasync['synchronizevirtualip'])) {
} if (!isset($config['virtualip']) || !is_array($config['virtualip'])) {
if (isset($hasync['synchronizeipsec'])) { $config['virtualip'] = array();
if (!isset($config['ipsec']) || !is_array($config['ipsec'])) { }
$config['ipsec'] = array(); $sections[] = 'virtualip';
} }
$sections[] = 'ipsec'; if (isset($hasync['synchronizelb'])) {
} if (!is_array($config['load_balancer'])) {
if (isset($hasync['synchronizeopenvpn'])) { $config['load_balancer'] = array();
if (!isset($config['openvpn']) || !is_array($config['openvpn'])) }
$config['openvpn'] = array(); $sections[] = 'load_balancer';
$sections[] = 'openvpn'; }
} if (isset($hasync['synchronizeipsec'])) {
if (isset($hasync['synchronizecerts']) || isset($hasync['synchronizeopenvpn'])) { if (!isset($config['ipsec']) || !is_array($config['ipsec'])) {
if (!is_array($config['cert'])) $config['ipsec'] = array();
$config['cert'] = array(); }
$sections[] = 'cert'; $sections[] = 'ipsec';
}
if (!is_array($config['ca'])) if (isset($hasync['synchronizeopenvpn'])) {
$config['ca'] = array(); if (!isset($config['openvpn']) || !is_array($config['openvpn'])) {
$sections[] = 'ca'; $config['openvpn'] = array();
}
if (!isset($config['crl']) || !is_array($config['crl'])) $sections[] = 'openvpn';
$config['crl'] = array(); }
$sections[] = 'crl'; if (isset($hasync['synchronizecerts']) || isset($hasync['synchronizeopenvpn'])) {
} if (!is_array($config['cert'])) {
if (isset($hasync['synchronizeusers'])) { $config['cert'] = array();
$sections[] = 'user'; }
$sections[] = 'group'; $sections[] = 'cert';
}
if (isset($hasync['synchronizeauthservers'])) { if (!is_array($config['ca'])) {
$sections[] = 'authserver'; $config['ca'] = array();
} }
if (isset($hasync['synchronizednsforwarder']) && is_array($config['dnsmasq'])) $sections[] = 'ca';
$sections[] = 'dnsmasq';
if (isset($hasync['synchronizeschedules']) || isset($hasync['synchronizerules'])) { if (!isset($config['crl']) || !is_array($config['crl'])) {
if (!isset($config['schedules']) || !is_array($config['schedules'])) $config['crl'] = array();
$config['schedules'] = array(); }
$sections[] = 'schedules'; $sections[] = 'crl';
} }
if (isset($hasync['synchronizeusers'])) {
if (count($sections) <= 0) { $sections[] = 'user';
log_error("Nothing has been configured to be synched. Skipping...."); $sections[] = 'group';
exit; }
} if (isset($hasync['synchronizeauthservers'])) {
$sections[] = 'authserver';
if (empty($hasync['username'])) }
$username = "admin"; if (isset($hasync['synchronizednsforwarder']) && is_array($config['dnsmasq'])) {
else $sections[] = 'dnsmasq';
$username = $hasync['username']; }
if (isset($hasync['synchronizeschedules']) || isset($hasync['synchronizerules'])) {
if (!carp_check_version($synchronizeto, $username, $hasync['password'])) if (!isset($config['schedules']) || !is_array($config['schedules'])) {
exit; $config['schedules'] = array();
}
update_filter_reload_status("Signaling CARP reload signal..."); $sections[] = 'schedules';
carp_sync_xml($synchronizeto, $username, $hasync['password'], $sections); }
if (count($argv) <= 1 || $argv[1] != 'restart' ) { if (count($sections) <= 0) {
// only sync data, no reload log_error("Nothing has been configured to be synched. Skipping....");
// TODO: config sync probably needs more thinking, but when we always force a reload exit;
// TODO: the machine tends to get sloppy }
exit;
} if (empty($hasync['username'])) {
$client = new SimpleXMLRPC_Client($synchronizeto,240); $username = "admin";
$client->setCredentials($username, $hasync['password']); } else {
if ($client->query("opnsense.filter_configure")) { $username = $hasync['username'];
$response = $client->getResponse(); }
} else {
// propagate error to log if (!carp_check_version($synchronizeto, $username, $hasync['password'])) {
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ; exit;
log_error($error); }
file_notice("sync_settings", $error, "Settings Sync", "");
// print communication details on failure update_filter_reload_status("Signaling CARP reload signal...");
echo $client->getDetails(); carp_sync_xml($synchronizeto, $username, $hasync['password'], $sections);
return false ;
} if (count($argv) <= 1 || $argv[1] != 'restart' ) {
// only sync data, no reload
if (!is_array($response) && trim($response) == "Authentication failed") { // TODO: config sync probably needs more thinking, but when we always force a reload
$error = "An authentication failure occurred while trying to access {$url} ({$method})."; // TODO: the machine tends to get sloppy
log_error($error); exit;
file_notice("sync_settings", $error, "Settings Sync", ""); }
exit; $client = new SimpleXMLRPC_Client($synchronizeto,240);
} $client->setCredentials($username, $hasync['password']);
if ($client->query("opnsense.filter_configure")) {
$response = $client->getResponse();
} else {
log_error("Filter sync successfully completed with {$synchronizetoip}:{$port}."); // propagate error to log
$error = "An error occurred while attempting XMLRPC sync with username {$username} and {$url} " . $client->error ;
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
// print communication details on failure
echo $client->getDetails();
return false ;
}
if (!is_array($response) && trim($response) == "Authentication failed") {
$error = "An authentication failure occurred while trying to access {$url} ({$method}).";
log_error($error);
file_notice("sync_settings", $error, "Settings Sync", "");
exit;
}
log_error("Filter sync successfully completed with {$synchronizetoip}:{$port}.");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment