Merge branch 'custom-tunnels-path'

This commit is contained in:
Tien Tran 2024-10-19 12:41:57 +11:00
commit 1466c26b9f
8 changed files with 39 additions and 174 deletions

6
.gitignore vendored
View File

@ -16,4 +16,8 @@
./wireguird ./wireguird
./wireguird.glade~ ./wireguird.glade~
./wireguird.settings ./wireguird.settings
deb/
build/
static/*.go

View File

@ -15,10 +15,10 @@ import (
) )
const ( const (
Version = "1.1.0" Version = "1.1.0"
Repo = "https://github.com/UnnoTed/wireguird" Repo = "https://github.com/UnnoTed/wireguird"
TunnelsPath = "/etc/wireguard/" DefaultTunnelsPath = "/etc/wireguard/"
IconPath = "/opt/wireguird/Icon/" IconPath = "/opt/wireguird/Icon/"
) )
var ( var (
@ -31,6 +31,7 @@ var (
header *gtk.HeaderBar header *gtk.HeaderBar
wgc *wgctrl.Client wgc *wgctrl.Client
updateTicker *time.Ticker updateTicker *time.Ticker
TunnelsPath string
) )
func Create(app *gtk.Application, b *gtk.Builder, w *gtk.ApplicationWindow, ind *appindicator.Indicator) error { func Create(app *gtk.Application, b *gtk.Builder, w *gtk.ApplicationWindow, ind *appindicator.Indicator) error {

View File

@ -229,7 +229,7 @@ func (t *Tunnels) Create() error {
t.icons[d.Name].SetFromPixbuf(gray.GetPixbuf()) 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() output, err := c.Output()
if err != nil { if err != nil {
es := string(err.(*exec.ExitError).Stderr) es := string(err.(*exec.ExitError).Stderr)
@ -283,7 +283,7 @@ func (t *Tunnels) Create() error {
} }
// connect to a tunnel // connect to a tunnel
c := exec.Command("wg-quick", "up", name) c := exec.Command("wg-quick", "up", TunnelsPath+name+".conf")
output, err := c.Output() output, err := c.Output()
if err != nil { if err != nil {
es := string(err.(*exec.ExitError).Stderr) es := string(err.(*exec.ExitError).Stderr)

10
main.go
View File

@ -4,6 +4,7 @@ package main
import ( import (
"os" "os"
"strings"
"github.com/UnnoTed/go-appindicator" "github.com/UnnoTed/go-appindicator"
"github.com/UnnoTed/horizontal" "github.com/UnnoTed/horizontal"
@ -21,6 +22,15 @@ func main() {
log.Logger = log.Output(horizontal.ConsoleWriter{Out: os.Stderr}) 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") 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 { if err := gui.Settings.Load(); err != nil {
log.Error().Err(err).Msg("error initial settings load") log.Error().Err(err).Msg("error initial settings load")
} }

View File

@ -1,3 +1,5 @@
#!/usr/bin/env sh
echo "wireguird: cleaning..." echo "wireguird: cleaning..."
deb_file="./build/wireguird_amd64.deb" deb_file="./build/wireguird_amd64.deb"
@ -13,17 +15,15 @@ fi
mkdir -p "$opt_w_dir" mkdir -p "$opt_w_dir"
echo "wireguird: building go binary..." echo "wireguird: building go binary..."
time {
go generate go generate
go build -ldflags "-s -w" -trimpath -o "$opt_w_dir""wireguird" go build -ldflags "-s -w" -trimpath -o "$opt_w_dir""wireguird"
}
echo "wireguird: copying icons..." echo "wireguird: copying icons..."
cp -r ./Icon/ "$opt_w_dir" cp -r ./Icon/ "$opt_w_dir"
echo "wireguird: building deb package..." 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 if [ ! -d "./build/" ]; then
mkdir ./build/ mkdir ./build/

View File

@ -3,18 +3,19 @@ package settings
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"os"
"path/filepath"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/ungerik/go-dry" "github.com/ungerik/go-dry"
) )
const FilePath = "./wireguird.settings"
type Settings struct { type Settings struct {
MultipleTunnels bool MultipleTunnels bool
StartOnTray bool StartOnTray bool
CheckUpdates bool CheckUpdates bool
TunnelsPath string
Debug bool Debug bool
} }
@ -23,11 +24,19 @@ var (
checkUpdates *bool checkUpdates *bool
debug *bool debug *bool
tray *bool tray *bool
filePath string
) )
func (s *Settings) Init() error { func (s *Settings) Init() error {
log.Debug().Msg("Settings init") 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 { if err := s.Load(); err != nil {
return err return err
} }
@ -48,7 +57,7 @@ func (s *Settings) Save() error {
return err return err
} }
if err := ioutil.WriteFile(FilePath, data, 0660); err != nil { if err := ioutil.WriteFile(filePath, data, 0666); err != nil {
return err return err
} }
@ -58,12 +67,12 @@ func (s *Settings) Save() error {
func (s *Settings) Load() error { func (s *Settings) Load() error {
log.Debug().Msg("loading settings") log.Debug().Msg("loading settings")
if !dry.FileExists(FilePath) { if !dry.FileExists(filePath) {
log.Debug().Msg("settings file doesnt exist") log.Debug().Msg("settings file doesnt exist")
return nil return nil
} }
data, err := ioutil.ReadFile(FilePath) data, err := ioutil.ReadFile(filePath)
if err != nil { if err != nil {
return err return err
} }

0
static/.gitkeep Normal file
View File

File diff suppressed because one or more lines are too long