From 8572592586c12fcf03f0e093d16f6a2a82d5dc0c Mon Sep 17 00:00:00 2001 From: Vittorio Parrella Date: Tue, 10 Sep 2024 23:24:16 +0200 Subject: [PATCH] fix tray merge --- qpep-tray/common/client_handler.go | 9 ++++----- qpep-tray/common/common.go | 3 --- qpep-tray/common/impl_linux.go | 26 +++++++++++++++++--------- qpep-tray/common/impl_windows.go | 30 ++++++++++++++++++++++++++++-- qpep-tray/common/server_handler.go | 6 +++--- qpep-tray/main.go | 2 -- 6 files changed, 52 insertions(+), 24 deletions(-) diff --git a/qpep-tray/common/client_handler.go b/qpep-tray/common/client_handler.go index 9a4b163..86ece86 100644 --- a/qpep-tray/common/client_handler.go +++ b/qpep-tray/common/client_handler.go @@ -3,11 +3,10 @@ package common import ( "errors" "github.com/parvit/qpep/qpep-tray/notify" - "github.com/parvit/qpep/shared" - "github.com/parvit/qpep/shared/logger" "github.com/parvit/qpep/shared/configuration" - "github.com/parvit/qpep/workers/gateway" stderr "github.com/parvit/qpep/shared/errors" + "github.com/parvit/qpep/shared/logger" + "github.com/parvit/qpep/workers/gateway" ) var clientActive bool = false @@ -18,7 +17,7 @@ func startClient() error { return stderr.ErrFailed } - outAddress := configuration2.QPepConfig.Client.LocalListeningAddress + outAddress := configuration.QPepConfig.Client.LocalListeningAddress addressList, _ := gateway.GetLanListeningAddresses() for idx, addr := range addressCheckBoxList { if addr.Checked() { @@ -62,7 +61,7 @@ func stopClient() error { clientActive = false gateway.SetSystemProxy(false) - InfoMsg("Client stopped") + notify.InfoMsg("Client stopped") return nil } diff --git a/qpep-tray/common/common.go b/qpep-tray/common/common.go index d256636..4ac8d68 100644 --- a/qpep-tray/common/common.go +++ b/qpep-tray/common/common.go @@ -15,11 +15,8 @@ import ( "github.com/parvit/qpep/api" "github.com/parvit/qpep/qpep-tray/icons" - "github.com/parvit/qpep/qpep-tray/toast" "github.com/parvit/qpep/qpep-tray/notify" "github.com/project-faster/systray" - - . "github.com/sqweek/dialog" ) const ( diff --git a/qpep-tray/common/impl_linux.go b/qpep-tray/common/impl_linux.go index 7070e19..6279d12 100644 --- a/qpep-tray/common/impl_linux.go +++ b/qpep-tray/common/impl_linux.go @@ -1,19 +1,15 @@ package common import ( - "github.com/parvit/qpep/shared/configuration" "github.com/parvit/qpep/qpep-tray/icons" + "github.com/parvit/qpep/qpep-tray/notify" + "github.com/parvit/qpep/shared/configuration" "os/exec" "path/filepath" - "syscall" - - "github.com/parvit/qpep/qpep-tray/notify" ) const ( EXENAME = "qpep" - - CMD_SERVICE = `%s -service %s %s %s` ) func getServiceCommand(start, client bool) *exec.Cmd { @@ -32,9 +28,7 @@ func getServiceCommand(start, client bool) *exec.Cmd { verboseFlag = "" } - attr := &syscall.SysProcAttr{} - - cmd := exec.Command(exeFile, serviceFlag, clientFlag, verboseFlag) + cmd := exec.Command(exeFile, "-service", serviceFlag, clientFlag, verboseFlag) if cmd == nil { notify.ErrorMsg("Could not create client command") return nil @@ -42,3 +36,17 @@ func getServiceCommand(start, client bool) *exec.Cmd { cmd.Dir, _ = filepath.Abs(ExeDir) return cmd } + +// fakeAPICallCheckProxy executes a "fake" api call to the local server to check for the connection running through +// the global proxy, this is checked by the client that adds the "X-QPEP-PROXY" header with value "true", a missing or +// "false" value means the proxy is not running correctly +func fakeAPICallCheckProxy() bool { + return true +} + +func getWaitingIcons() [][]byte { + return [][]byte{ + icons.MainIconWaiting, + icons.MainIconData, + } +} diff --git a/qpep-tray/common/impl_windows.go b/qpep-tray/common/impl_windows.go index 6a780b3..142658e 100644 --- a/qpep-tray/common/impl_windows.go +++ b/qpep-tray/common/impl_windows.go @@ -2,10 +2,10 @@ package common import ( "fmt" - "github.com/parvit/qpep/shared/configuration" - "github.com/parvit/qpep/shared/logger" "github.com/parvit/qpep/qpep-tray/icons" "github.com/parvit/qpep/qpep-tray/notify" + "github.com/parvit/qpep/shared/configuration" + "github.com/parvit/qpep/shared/logger" "os/exec" "path/filepath" "strings" @@ -54,3 +54,29 @@ func getServiceCommand(start, client bool) *exec.Cmd { cmd.SysProcAttr = attr return cmd } + +// fakeAPICallCheckProxy executes a "fake" api call to the local server to check for the connection running through +// the global proxy, this is checked by the client that adds the "X-QPEP-PROXY" header with value "true", a missing or +// "false" value means the proxy is not running correctly +func fakeAPICallCheckProxy() bool { + data, err, _ := shared.RunCommand("powershell.exe", "-ExecutionPolicy", "ByPass", "-Command", + "Invoke-WebRequest -Uri \"http://192.168.1.40:444/qpep-client-proxy-check\" -UseBasicParsing -TimeoutSec 1", + ) + logger.Info("proxy check data: %s", data) + logger.Info("proxy check error: %v", err) + if err != nil { + return false + } + if strings.Contains(string(data), "X-QPEP-PROXY, true") { + logger.Info("proxy is working") + return true + } + return false +} + +func getWaitingIcons() [][]byte { + return [][]byte{ + icons.MainIconWaiting, + icons.MainIconData, + } +} diff --git a/qpep-tray/common/server_handler.go b/qpep-tray/common/server_handler.go index 3b0d47a..43ae341 100644 --- a/qpep-tray/common/server_handler.go +++ b/qpep-tray/common/server_handler.go @@ -2,11 +2,11 @@ package common import ( "errors" + "github.com/parvit/qpep/qpep-tray/notify" "github.com/parvit/qpep/shared/configuration" - "github.com/parvit/qpep/shared/logger" stderr "github.com/parvit/qpep/shared/errors" + "github.com/parvit/qpep/shared/logger" "github.com/parvit/qpep/workers/gateway" - "github.com/parvit/qpep/qpep-tray/notify" ) var serverActive bool = false @@ -16,7 +16,7 @@ func startServer() error { return stderr.ErrFailed } - outAddress := configuration2.QPepConfig.Server.LocalListeningAddress + outAddress := configuration.QPepConfig.Server.LocalListeningAddress addressList, _ := gateway.GetLanListeningAddresses() for idx, addr := range addressCheckBoxList { if addr.Checked() { diff --git a/qpep-tray/main.go b/qpep-tray/main.go index 717f5ac..ac574d4 100644 --- a/qpep-tray/main.go +++ b/qpep-tray/main.go @@ -5,8 +5,6 @@ import ( "github.com/parvit/qpep/qpep-tray/notify" "github.com/parvit/qpep/shared/configuration" "github.com/parvit/qpep/workers/gateway" - "io" - "log" "os" "os/signal" "syscall"