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

Custom tunnels path #58

Open
wants to merge 2 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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@

./wireguird
./wireguird.glade~
./wireguird.settings
./wireguird.settings

deb/
build/
static/*.go
9 changes: 5 additions & 4 deletions gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
)

const (
Version = "1.1.0"
Repo = "https://github.com/UnnoTed/wireguird"
TunnelsPath = "/etc/wireguard/"
IconPath = "/opt/wireguird/Icon/"
Version = "1.1.0"
Repo = "https://github.com/UnnoTed/wireguird"
DefaultTunnelsPath = "/etc/wireguard/"
IconPath = "/opt/wireguird/Icon/"
)

var (
Expand All @@ -31,6 +31,7 @@ var (
header *gtk.HeaderBar
wgc *wgctrl.Client
updateTicker *time.Ticker
TunnelsPath string
)

func Create(app *gtk.Application, b *gtk.Builder, w *gtk.ApplicationWindow, ind *appindicator.Indicator) error {
Expand Down
4 changes: 2 additions & 2 deletions gui/tunnels.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (t *Tunnels) Create() error {
t.icons[d.Name].SetFromPixbuf(gray.GetPixbuf())
})

c := exec.Command("wg-quick", "down", d.Name)
c := exec.Command("wg-quick", "down", TunnelsPath+d.Name+".conf")
output, err := c.Output()
if err != nil {
es := string(err.(*exec.ExitError).Stderr)
Expand Down Expand Up @@ -283,7 +283,7 @@ func (t *Tunnels) Create() error {
}

// connect to a tunnel
c := exec.Command("wg-quick", "up", name)
c := exec.Command("wg-quick", "up", TunnelsPath+name+".conf")
output, err := c.Output()
if err != nil {
es := string(err.(*exec.ExitError).Stderr)
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"os"
"strings"

"github.com/UnnoTed/go-appindicator"
"github.com/UnnoTed/horizontal"
Expand All @@ -21,6 +22,15 @@ func main() {
log.Logger = log.Output(horizontal.ConsoleWriter{Out: os.Stderr})
log.Info().Uint("major", gtk.GetMajorVersion()).Uint("minor", gtk.GetMinorVersion()).Uint("micro", gtk.GetMicroVersion()).Msg("GTK Version")

if gui.Settings.TunnelsPath == "" {
gui.TunnelsPath = gui.DefaultTunnelsPath
} else {
gui.TunnelsPath = gui.Settings.TunnelsPath
}
if !strings.HasSuffix(gui.TunnelsPath, "/") {
gui.TunnelsPath += "/"
}

if err := gui.Settings.Load(); err != nil {
log.Error().Err(err).Msg("error initial settings load")
}
Expand Down
6 changes: 3 additions & 3 deletions package_deb.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env sh

echo "wireguird: cleaning..."

deb_file="./build/wireguird_amd64.deb"
Expand All @@ -13,17 +15,15 @@ fi
mkdir -p "$opt_w_dir"

echo "wireguird: building go binary..."
time {
go generate
go build -ldflags "-s -w" -trimpath -o "$opt_w_dir""wireguird"
}

echo "wireguird: copying icons..."
cp -r ./Icon/ "$opt_w_dir"

echo "wireguird: building deb package..."

touch "$opt_w_dir""wireguird.settings"
echo '{"MultipleTunnels":false,"StartOnTray":false,"CheckUpdates":false,"TunnelsPath":"/etc/wireguard","Debug":false}' > "$opt_w_dir""wireguird.settings"

if [ ! -d "./build/" ]; then
mkdir ./build/
Expand Down
19 changes: 14 additions & 5 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package settings
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/ungerik/go-dry"
)

const FilePath = "./wireguird.settings"

type Settings struct {
MultipleTunnels bool
StartOnTray bool
CheckUpdates bool
TunnelsPath string
Debug bool
}

Expand All @@ -23,11 +24,19 @@ var (
checkUpdates *bool
debug *bool
tray *bool
filePath string
)

func (s *Settings) Init() error {
log.Debug().Msg("Settings init")

exePath, err := os.Executable()
if err != nil {
return err
}

filePath = filepath.Join(filepath.Dir(exePath), "wireguird.settings")

if err := s.Load(); err != nil {
return err
}
Expand All @@ -48,7 +57,7 @@ func (s *Settings) Save() error {
return err
}

if err := ioutil.WriteFile(FilePath, data, 0660); err != nil {
if err := ioutil.WriteFile(filePath, data, 0666); err != nil {
return err
}

Expand All @@ -58,12 +67,12 @@ func (s *Settings) Save() error {

func (s *Settings) Load() error {
log.Debug().Msg("loading settings")
if !dry.FileExists(FilePath) {
if !dry.FileExists(filePath) {
log.Debug().Msg("settings file doesnt exist")
return nil
}

data, err := ioutil.ReadFile(FilePath)
data, err := ioutil.ReadFile(filePath)
if err != nil {
return err
}
Expand Down
Empty file added static/.gitkeep
Empty file.
159 changes: 0 additions & 159 deletions static/ab0x.go

This file was deleted.