Last active
July 18, 2023 22:58
-
-
Save luckman212/0fdea1cbdc0a561d781a52c7d34fb60d to your computer and use it in GitHub Desktop.
dpinger_static_routes.php - helper script related to https://github.com/pfsense/pfsense/pull/4591
This file contains 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
<?php | |
// includes | |
require_once("functions.inc"); | |
require_once("system.inc"); | |
require_once("util.inc"); | |
// global dpinger_dont_add_static_routes option | |
$dp_global_sr_disable = (isset($config['system']['dpinger_dont_add_static_routes']) ? 'ENABLED (checked)' : 'default (unchecked)'); | |
printf("==> global `dpinger_dont_add_static_routes` setting: %s\n", $dp_global_sr_disable); | |
// list each gateway and its monitor IP | |
if (is_array($config['gateways'])) { | |
printf("\n%-16s %-8s %-20s %-20s %s\n", "GATEWAYS", "IF", "GW IP", "MON IP", "STATIC ROUTE"); | |
echo "===================================================================================\n"; | |
$gateways = $config['gateways']['gateway_item']; | |
foreach ($gateways as $i => $gw) { | |
$if = (isset($gw['interface']) ? $gw['interface'] : '?'); | |
$gwip = (isset($gw['gateway']) ? $gw['gateway'] : '?'); | |
$name = (isset($gw['name']) ? $gw['name'] : '?'); | |
$sr = (isset($gw['dpinger_dont_add_static_route']) ? 'NO (checked)' : 'yes (unchecked)'); | |
$monip = (isset($gw['monitor']) ? $gw['monitor'] : '(blank)'); | |
printf("%-16s %-8s %-20s %-20s %s\n", $name, $if, $gwip, $monip, $sr); | |
} | |
} else { | |
echo "(no gateways found)\n"; | |
} | |
// print any static routes | |
$sroutes = get_staticroutes(); | |
if (is_array($sroutes)) { | |
printf("\n%-24s %-24s %s\n", "STATIC ROUTES", "GATEWAY", "DESC"); | |
echo "===================================================================================\n"; | |
foreach ($sroutes as $sr) { | |
printf("%-24s %-24s %s\n", $sr['network'], $sr['gateway'], $sr['descr']); | |
} | |
} | |
/* print routing table (IPv4) | |
$routes = shell_exec('/usr/bin/netstat -rnl -f inet'); | |
if (!empty($routes)) { | |
echo $routes; | |
} | |
*/ | |
$rt = route_table(); | |
if (is_array($rt)) { | |
printf("\nSTATIC ROUTES FROM ROUTING TABLE\n"); | |
echo "===================================================================================\n"; | |
$rt4 = $rt['inet']; | |
$rt6 = $rt['inet6']; | |
foreach ($rt4 as $r) { | |
if ($r['flags'] == 'UGHS') { | |
printf("%-24s %-30s %-6s %s\n", $r['destination'], $r['gateway'], $r['flags'], $r['interface-name']); | |
} | |
} | |
foreach ($rt6 as $r) { | |
if ($r['flags'] == 'UGHS') { | |
printf("%-24s %-30s %-6s %s\n", $r['destination'], $r['gateway'], $r['flags'], $r['interface-name']); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run:
or, if you don't want to install cmdwatch, you can use a simple while loop