diff --git a/opnsense-carp-dhcp-master.php b/opnsense-carp-dhcp-master.php index b8b3515..7836307 100644 --- a/opnsense-carp-dhcp-master.php +++ b/opnsense-carp-dhcp-master.php @@ -9,6 +9,7 @@ require_once("util.inc"); require_once("system.inc"); require_once('rrd.inc'); require_once('plugins.inc.d/webgui.inc'); +require_once("XMLRPC_Client.inc"); /* @@ -101,6 +102,44 @@ function get_specialnets($only_enabled = false) { return $specialnets; } +function xmlrpc_exec($method, $params = [], $debug = false) { + global $config; + $synchronizeto = null; + $hasync = $config['hasync']; + if (is_ipaddrv6($hasync['synchronizetoip'])) { + $hasync['synchronizetoip'] = "[{$hasync['synchronizetoip']}]"; + } + + if (!empty($hasync['synchronizetoip'])) { + // determine target url + if (substr($hasync['synchronizetoip'],0, 4) == 'http') { + // URL provided + if (substr($hasync['synchronizetoip'], strlen($hasync['synchronizetoip'])-1, 1) == '/') { + $synchronizeto = $hasync['synchronizetoip']."xmlrpc.php"; + } else { + $synchronizeto = $hasync['synchronizetoip']."/xmlrpc.php"; + } + } elseif (!empty($config['system']['webgui']['protocol'])) { + // no url provided, assume the backup is using the same settings as our box. + $port = $config['system']['webgui']['port']; + if (!empty($port)) { + $synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip'].':'.$port."/xmlrpc.php"; + } else { + $synchronizeto = $config['system']['webgui']['protocol'] . '://'.$hasync['synchronizetoip']."/xmlrpc.php" ; + } + } + + $username = empty($hasync['username']) ? "root" : $hasync['username']; + $client = new SimpleXMLRPC_Client($synchronizeto,240); + $client->debug=$debug; + $client->setCredentials($username, $hasync['password']); + if ($client->query($method, $params)) { + return $client->getResponse(); + } + } + return false; +} + echo_write_log("Start of Script " . $argv[0]); @@ -290,8 +329,9 @@ if (filter_var($config['hasync']['synchronizetoip'], FILTER_VALIDATE_IP)) { } } while (true); - exec('configctl system ha_reconfigure_backup', $output, $result); - + configd_run('filter sync'); + xmlrpc_exec('opnsense.configd_reload_all_templates'); + echo_write_log("CARP Sync Status: " . $output); echo_write_log("finished the CARP Sync"); } else {