changed to master and backup files
This commit is contained in:
52
opnsense-carp-dhcp-backup.php
Normal file
52
opnsense-carp-dhcp-backup.php
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
require_once("config.inc");
|
||||
require_once("interfaces.inc");
|
||||
require_once("util.inc");
|
||||
require_once("filter.inc");
|
||||
require_once("util.inc");
|
||||
require_once("system.inc");
|
||||
require_once('rrd.inc');
|
||||
require_once('plugins.inc.d/webgui.inc');
|
||||
|
||||
#############
|
||||
# Variables #
|
||||
#############
|
||||
|
||||
$wanInterface = 'wan';
|
||||
$gatewayName = 'WAN_GW';
|
||||
|
||||
###################
|
||||
# Start of Script #
|
||||
###################
|
||||
|
||||
|
||||
function write_config_and_restart_services ($interface) {
|
||||
write_config();
|
||||
system_hosts_generate(true);
|
||||
system_resolvconf_generate(true);
|
||||
interface_bring_down($interface);
|
||||
interface_configure(true, $interface, true);
|
||||
plugins_configure('monitor', true);
|
||||
filter_configure_sync(true);
|
||||
webgui_configure_do(true);
|
||||
rrd_configure(true);
|
||||
}
|
||||
|
||||
# loop through carp addresses and update the wan ip address
|
||||
foreach ($config['virtualip']['vip'] as $i => $vip) {
|
||||
if ($vip['interface'] == $wanInterface) {
|
||||
$description = $config['virtualip']['vip'][$i]['descr'];
|
||||
# VIP WAN (GW: $gatewayIP)
|
||||
$gatewayIP = substr(explode(":", $description), 0, -1)
|
||||
if (filter_var($gatewayIP, FILTER_VALIDATE_IP)) {
|
||||
foreach ($config['gateways']['gateway_item'] as $i => $gateway) {
|
||||
if ($gateway['name'] == $gatewayName) {
|
||||
$config['gateways']['gateway_item'][$i]['gateway'] = $gatewayIP;
|
||||
write_config_and_restart_services($wanInterface);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user