diff --git a/opnsense-carp-dhcp-backup-gateway.php b/opnsense-carp-dhcp-backup-gateway.php new file mode 100644 index 0000000..c77da6b --- /dev/null +++ b/opnsense-carp-dhcp-backup-gateway.php @@ -0,0 +1,78 @@ +#!/usr/local/bin/php + $vip) { + if ($vip['interface'] == $wanInterface) { + $carpStatus = $intf_details[$intf]['carp'][$vip['vhid']]['status']; + if ($carpStatus == "BACKUP") { + $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"); + } + } + } + } + } else { + printf("Router is currenty carp master, not updating"); + } + } +} \ No newline at end of file diff --git a/opnsense-carp-dhcp-backup.php b/opnsense-carp-dhcp-backup.php deleted file mode 100644 index 230438c..0000000 --- a/opnsense-carp-dhcp-backup.php +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/local/bin/php - $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"); - } - } - } - } - } -} \ No newline at end of file