Add VPS-aware VPN IP allocation

This commit is contained in:
litoral05
2026-05-07 14:17:40 +01:00
parent a09587950e
commit c88ef29449
16 changed files with 592 additions and 1 deletions
@@ -0,0 +1,47 @@
package com.litoralregas.vpnprovisioner.vps;
import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service
public class WireGuardVpsService {
private static final Pattern VPN_IP_PATTERN =
Pattern.compile("\\b198\\.19\\.\\d{1,3}\\.\\d{1,3}\\b");
private final SshService sshService;
public WireGuardVpsService(SshService sshService) {
this.sshService = sshService;
}
public Set<String> findUsedVpnIps() {
SshCommandResult result = sshService.executeOnConfiguredVps(
"sudo wg show wg0 allowed-ips"
);
if (result.exitCode() != 0) {
throw new SshCommandException(
"Failed to query WireGuard allowed IPs: " + result.stderr()
);
}
return parseVpnIps(result.stdout());
}
Set<String> parseVpnIps(String output) {
Set<String> ips = new HashSet<>();
Matcher matcher = VPN_IP_PATTERN.matcher(output);
while (matcher.find()) {
ips.add(matcher.group());
}
return ips;
}
}