Skip to content

Commit 6b2701d

Browse files
committed
Add: AddServerRoute client configuration parameter, which may implement #4
1 parent e7e6a48 commit 6b2701d

File tree

7 files changed

+37
-21
lines changed

7 files changed

+37
-21
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=0.1.3
1+
VERSION=0.1.4
22
BUILD=`git rev-parse --short=8 HEAD`
33
.PHONY: all fmt static precommit arm64 amd64 fmt static test release release_dir
44

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ Make sure you have WireGuard and iptables installed
2929
To download using curl run:
3030
```shell
3131
# for x86_64
32-
curl -SL https://github.com/andrianbdn/wg-cmd/releases/download/v0.1.3/wg-cmd-0.1.3-linux-amd64 -o /usr/local/bin/wg-cmd
32+
curl -SL https://github.com/andrianbdn/wg-cmd/releases/download/v0.1.4/wg-cmd-0.1.4-linux-amd64 -o /usr/local/bin/wg-cmd
3333

3434
# for arm64
35-
curl -SL https://github.com/andrianbdn/wg-cmd/releases/download/v0.1.3/wg-cmd-0.1.3-linux-arm64 -o /usr/local/bin/wg-cmd
35+
curl -SL https://github.com/andrianbdn/wg-cmd/releases/download/v0.1.4/wg-cmd-0.1.4-linux-arm64 -o /usr/local/bin/wg-cmd
3636
```
3737

3838
Set proper permissions and run the tool:
@@ -105,7 +105,10 @@ client configuration files.
105105

106106
#### client configuration (nnnn-%client%.toml)
107107

108-
Contains `ClientRoute` that overrides the one from server config.
108+
`ClientRoute` - completely overrides the `ClientRoute` from the server config
109+
110+
`AddServerRoute` - adds additional network to AllowedIPs for the client on the server side (useful
111+
when you want to route traffic to one client to another client's network through the server)
109112

110113
`MTU` - Override server MTU with a different value for this client. Set to -1 to omit MTU from this WireGuard client config.
111114

app/app.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ func (a *App) LoadInterface(ifName string) error {
8484
return err
8585
}
8686

87+
func (a *App) GenerateWireguardConfigLog() {
88+
_, err := a.GenerateWireguardConfig()
89+
if err != nil {
90+
// TODO: probably not the best way to handle this error
91+
log.Println("Error generating config", err)
92+
}
93+
}
94+
8795
func (a *App) GenerateWireguardConfig() (string, error) {
8896
configPath := filepath.Join(a.Settings.WireguardDir, a.State.Server.Interface) + ".conf"
8997
return configPath, a.State.GenerateWireguardFile(configPath, false)

backend/client.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import (
1414
)
1515

1616
type Client struct {
17-
ipNum int
18-
name string
19-
fileName string
20-
PublicKey string
21-
PrivateKey string
22-
ClientRoute string
23-
MTU int
24-
DNS string
17+
ipNum int
18+
name string
19+
fileName string
20+
PublicKey string
21+
PrivateKey string
22+
ClientRoute string
23+
AddServerRoute string
24+
MTU int
25+
DNS string
2526
}
2627

2728
func ReadClient(dir string, fileName string, ipNum int, name string) (*Client, error) {

backend/generator.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ func (s *Server) generateServerPeerConfig(client *Client, w io.Writer) error {
3131
_, _ = fmt.Fprintln(w, "PresharedKey =", s.PresharedKey)
3232
}
3333
_, _ = fmt.Fprintln(w, "PublicKey =", client.PublicKey)
34-
_, _ = fmt.Fprintln(w, "AllowedIPs =", client.AllowedIps(s))
34+
35+
allowedIps := client.AllowedIps(s)
36+
if client.AddServerRoute != "" {
37+
allowedIps = allowedIps + ", " + client.AddServerRoute
38+
}
39+
40+
_, _ = fmt.Fprintln(w, "AllowedIPs =", allowedIps)
3541

3642
return nil
3743
}

ext_editor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (m MainScreen) editorEvents(msg tea.Msg) (bool, tea.Model, tea.Cmd) {
5656
m.table = newAppDynamicTableList(m.app, &m.table)
5757
}
5858

59+
// Even if we edit peer, we may need to regenerate the server config
60+
// because of AddServerRoute client configuration option mainly
61+
m.app.GenerateWireguardConfigLog()
62+
5963
return true, m, nil
6064
}
6165

tui_main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ func (m MainScreen) ReallyAddPeer(name string) MainScreen {
218218
log.Println("Error adding peer", err)
219219
}
220220
if err == nil {
221-
_, err = m.app.GenerateWireguardConfig()
222-
if err != nil {
223-
log.Println("Error generating config", err)
224-
}
221+
m.app.GenerateWireguardConfigLog()
225222
}
226223
m.dialog = nil
227224
m.table = newAppDynamicTableList(m.app, &m.table)
@@ -241,10 +238,7 @@ func (m MainScreen) ReallyDeletePeer() MainScreen {
241238
log.Println("Error deleting peer", err)
242239
}
243240
if err == nil {
244-
_, err = m.app.GenerateWireguardConfig()
245-
if err != nil {
246-
log.Println("Error generating config", err)
247-
}
241+
m.app.GenerateWireguardConfigLog()
248242
}
249243

250244
m.table.DeleteSelectedRow()

0 commit comments

Comments
 (0)