Skip to content

Instantly share code, notes, and snippets.

@taoso
Last active March 5, 2020 22:19
Show Gist options
  • Save taoso/1b04e3730b4dc1632707879c0fa6abc7 to your computer and use it in GitHub Desktop.
Save taoso/1b04e3730b4dc1632707879c0fa6abc7 to your computer and use it in GitHub Desktop.
manually set openvpn route by script for Tunnelblick on macOS
#!/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