1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00

Add code for PPP and TUN devices

This commit is contained in:
Christian Zeitnitz 2021-03-28 16:35:19 +02:00
parent 6eb51a2d63
commit f7cef44b06

View File

@ -11,10 +11,23 @@ function getRouteInfo($checkAccess)
$rInfo = array();
// get all default routes
exec('ip route list | sed -rn "s/default via (([0-9]{1,3}\.){3}[0-9]{1,3}).*dev (\w*).*src (([0-9]{1,3}\.){3}[0-9]{1,3}).*/\3 \4 \1/p"', $routes);
exec('ip route list | sed -rn "s/default dev (\w*) scope link/\1/p"', $devs);
$devpat = array("tun", "ppp"); // routing in case of VPN and PPP connection are different
foreach ($devpat as $pat) {
exec('ip route list | grep -oP "'.$pat.'[0-9]" | sort -u', $devs);
}
if (!empty($devs)) {
foreach ($devs as $dev)
exec('ip route list | sed -rn "s/(([0-9]{1,3}\.){3}[0-9]{1,3}).*dev.*("' . $dev . '").*scope link src (([0-9]{1,3}\.){3}[0-9]{1,3}).*/\3 \4 \1/p"', $routes);
foreach ($devs as $dev) {
unset($gateway);
unset($ipadd);
exec('ip route list | sed -rn "s/^.*via (([0-9]{1,3}\.){3}[0-9]{1,3}) dev "' . $dev . '".*$/\1/p" | head -n 1', $gateway);
if (empty($gateway)) {
exec('ip route list | sed -rn "s/(([0-9]{1,3}\.){3}[0-9]{1,3}).*dev.*"' . $dev . '".*scope link src.*/\1/p"', $gateway);
}
exec('ifconfig -a | grep -i ' . $dev . ' -A 1 | grep -oP "(?<=inet )([0-9]{1,3}\.){3}[0-9]{1,3}"', $ipadd);
if (!empty($gateway) && !empty($ipadd)) {
$routes[]="$dev $ipadd[0] $gateway[0]";
}
}
}
if (!empty($routes)) {
foreach ($routes as $i => $route) {