Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds VPN IP partial matching feature #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ named `$HOME/.routes.json`
The above example will route all the traffic for the class C block `9.8.7.*` to your VPN
server whose IP is `1.2.3.4`

### Remote VPN IP partial matching

```json
{ "remotes": {
"1.2.3": [
"9.8.7"
]
} }
```

The above example will route all the traffic for the class C block `9.8.7.*` to your VPN
server whose IP partially matches `1.2.3`, for example: `1.2.3.4`, `9.1.2.3`

### Configuring your VPN

Expand Down
15 changes: 12 additions & 3 deletions ip-up.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,20 @@ function main() {
$remoteIp = $_SERVER['argv'][5];
$remoteIpConfigs = expectObjectGetArray($routes['remotes'], "Invalid remotes value in routes.json");

// If we have a list of networks to send to this remote IP, set them
if(isset($remoteIpConfigs[$remoteIp])) {
$matchedRemoteIpConfig = false;

// If any of the config remote IP partially matches the actual remote IP, use the config.
// If multiple matches occur, the final one will be applied
foreach ($remoteIpConfigs as $ip => $config) {
if (strpos($remoteIp, $ip) !== false) {
$matchedRemoteIpConfig = $remoteIpConfigs[$ip];
}
}

if($matchedRemoteIpConfig) {

logMessage("Configuring routes for $remoteIp");
setRoutes($remoteIpConfigs[$remoteIp]);
setRoutes($matchedRemoteIpConfig);
}
else { // this remote IP is not known by the config

Expand Down