60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
#!/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'];
|
|
printf("Description from VIP WAN: %s \n", $description);
|
|
# VIP WAN (GW: $gatewayIP)
|
|
$gatewayIP = trim(substr(explode(":", $description)[1], 0, -1));
|
|
printf("CARP Gateway IP from Description: %s \n", $gatewayIP );
|
|
if (filter_var($gatewayIP, FILTER_VALIDATE_IP)) {
|
|
foreach ($config['gateways']['gateway_item'] as $i => $gateway) {
|
|
if ($gateway['name'] == $gatewayName) {
|
|
printf("Current Gateway IP: %s \n", $gateway['gateway']);
|
|
if ($gateway['gateway'] != $gatewayIP) {
|
|
printf("Updating Gateway IPs. \n");
|
|
$config['gateways']['gateway_item'][$i]['gateway'] = $gatewayIP;
|
|
write_config_and_restart_services($wanInterface);
|
|
} else {
|
|
printf("Gateway IPs are the same, not updating. \n");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |