-
-
Save taoso/1b04e3730b4dc1632707879c0fa6abc7 to your computer and use it in GitHub Desktop.
manually set openvpn route by script for Tunnelblick on macOS
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
#!/usr/bin/env php | |
# you should add the following two line in you ovpn.conf | |
# route-noexec # donot let openvpn set local route | |
# route-up a.sh # run a.sh under ~/Library/Application Support/Tunnelblick/Configurations/bilibili.tblk/Contents/Resources | |
<?php | |
$env = $_ENV; | |
$route = []; | |
foreach ($env as $key => $value) { | |
if (preg_match('/route_(netmask|network|gateway)_(\d+)/', $key, $matches)) { | |
$id = $matches[2]; | |
$key = $matches[1]; | |
$route[$id][$key] = $value; | |
} | |
} | |
foreach ($route as $id => $info) { | |
$cmd = "/sbin/route add ${info['network']} ${info['gateway']} -netmask ${info['netmask']}"; | |
system($cmd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment