-
-
Save matti/f7101a307a5fded4424661615192a1d4 to your computer and use it in GitHub Desktop.
Disable WAN Interface on CARP Backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/php | |
<?php | |
require_once("config.inc"); | |
require_once("system.inc"); | |
require_once("interfaces.inc"); | |
require_once("util.inc"); | |
$subsystem = !empty($argv[1]) ? $argv[1] : ''; | |
$type = !empty($argv[2]) ? $argv[2] : ''; | |
file_put_contents("/tmp/kekkonen","alku type: ".$type." subsystem: ".$subsystem."\n",FILE_APPEND); | |
if ($type != 'MASTER' && $type != 'BACKUP') { | |
log_error("Carp '$type' event unknown from source '{$subsystem}'"); | |
exit(1); | |
} | |
if (!strstr($subsystem, '@')) { | |
log_error("Carp '$type' event triggered from wrong source '{$subsystem}'"); | |
exit(1); | |
} | |
$interfaces = array('wan'); | |
if ($type === "MASTER") { | |
foreach ($interfaces as $ifkey) { | |
log_error("enable interface '$ifkey' due CARP event '$type'"); | |
$config['interfaces'][$ifkey]['enable'] = '1'; | |
interfaces_bring_up($ifkey); | |
interface_configure(false, $ifkey, true, true); | |
write_config("enable interface '$ifkey' due CARP event '$type'", false); | |
usleep(200 * 1000); | |
} | |
} else { | |
foreach ($interfaces as $ifkey) { | |
log_error("disable interface '$ifkey' due CARP event '$type'"); | |
interface_bring_down($ifkey); | |
unset($config['interfaces'][$ifkey]['enable']); | |
interface_configure(false, $ifkey, true, false); | |
exec('/sbin/ifconfig ' . escapeshellarg($ifkey) . 'down 2>&1', $ifc, $ret); | |
write_config("disable interface '$ifkey' due CARP event '$type'", false); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment