Skip to content

Commit

Permalink
Add SUBSPACE_PERSISTENT_KEEPALIVE variable 🍵 (#213)
Browse files Browse the repository at this point in the history
* Add SUBSPACE_PERSISTENT_KEEPALIVE variable 🍵

* Remove manual Contributors 🍵
  • Loading branch information
mrnonz authored Jun 16, 2022
1 parent 7d12b87 commit 158a751
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ $ subspace --http-host subspace.example.com
| `SUBSPACE_THEME` | `green` | The theme to use, please refer to [semantic-ui](https://semantic-ui.com/usage/theming.html) for accepted colors |
| `SUBSPACE_BACKLINK` | `/` | The page to set the home button to |
| `SUBSPACE_DISABLE_DNS` | `false` | Whether to disable DNS so the client uses their own configured DNS server(s). Consider disabling DNS server, if supporting international VPN clients |
| `SUBSPACE_PERSISTENT_KEEPALIVE` | `0` | Whether PersistentKeepalive should be enabled for clients (seconds) |

### Run as a Docker container

Expand Down Expand Up @@ -211,6 +212,8 @@ docker create \
# Optional variable to disable DNS server. Enabled by default.
# consider disabling DNS server, if supporting international VPN clients
--env SUBSPACE_DISABLE_DNS=0 \
# Optional variable to change PersistentKeepalive
--env SUBSPACE_PERSISTENT_KEEPALIVE=20 \
subspacecommunity/subspace:latest

$ sudo docker start subspace
Expand Down Expand Up @@ -246,6 +249,7 @@ services:
- SUBSPACE_IPV6_GW=fd00::10:97:1
- SUBSPACE_IPV6_NAT_ENABLED=1
- SUBSPACE_DISABLE_DNS=0
- SUBSPACE_PERSISTENT_KEEPALIVE=20
cap_add:
- NET_ADMIN
network_mode: "host"
Expand Down
35 changes: 21 additions & 14 deletions cmd/subspace/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ func profileAddHandler(w *Web) {
if shouldDisableDNS := getEnv("SUBSPACE_DISABLE_DNS", "0"); shouldDisableDNS == "1" {
disableDNS = true
}
persistentKeepalive := "0"
if keepalive := getEnv("SUBSPACE_PERSISTENT_KEEPALIVE", "nil"); keepalive != "nil" {
persistentKeepalive = keepalive
}

script := `
cd {{$.Datadir}}/wireguard
Expand Down Expand Up @@ -489,23 +493,25 @@ PublicKey = $(cat server.public)
Endpoint = {{$.EndpointHost}}:{{$.Listenport}}
AllowedIPs = {{$.AllowedIPS}}
PersistentKeepalive = {{$.PersistentKeepalive}}
WGCLIENT
`
_, err = bash(script, struct {
Profile Profile
EndpointHost string
Datadir string
IPv4Gw string
IPv6Gw string
IPv4Pref string
IPv6Pref string
IPv4Cidr string
IPv6Cidr string
Listenport string
AllowedIPS string
Ipv4Enabled bool
Ipv6Enabled bool
DisableDNS bool
Profile Profile
EndpointHost string
Datadir string
IPv4Gw string
IPv6Gw string
IPv4Pref string
IPv6Pref string
IPv4Cidr string
IPv6Cidr string
Listenport string
AllowedIPS string
Ipv4Enabled bool
Ipv6Enabled bool
DisableDNS bool
PersistentKeepalive string
}{
profile,
endpointHost,
Expand All @@ -521,6 +527,7 @@ WGCLIENT
ipv4Enabled,
ipv6Enabled,
disableDNS,
persistentKeepalive,
})
if err != nil {
logger.Warn(err)
Expand Down

0 comments on commit 158a751

Please sign in to comment.