Skip to content

Commit

Permalink
Remove old core openvpn3, use new library from upstream
Browse files Browse the repository at this point in the history
Since there is a bug with the connection for the win system,
it was decided to update the library Openvpn3.
Now there are problems building the project, due to the complex build system in GUI project:
github.com/therecipe/qt.
  • Loading branch information
Vai3soh committed Nov 12, 2022
1 parent a7003d2 commit 5cf65b0
Show file tree
Hide file tree
Showing 31 changed files with 846 additions and 2,376 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "third_party/go-openvpn"]
path = third_party/go-openvpn
url = https://github.com/Vai3soh/go-openvpn
11 changes: 7 additions & 4 deletions build/docker/linux/Dockerfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ GO=go$VERSION.linux-amd64.tar.gz && \
curl -sL --retry 10 --retry-delay 60 -O https://go.dev/dl/$GO && \
tar -xzf $GO -C /usr/local

WORKDIR /home/user/work/src/github.com/Vai3soh/
COPY . /home/user/work/src/github.com/Vai3soh/
WORKDIR /home/user/work/src/github.com/Vai3soh/goovpn
COPY . /home/user/work/src/github.com/Vai3soh/goovpn

RUN go get github.com/therecipe/qt/internal/binding/files/docs/[email protected]

ENV QT_MXE_ARCH=amd64
WORKDIR /home/user/work/src/github.com/Vai3soh/cmd/app/
WORKDIR /home/user/work/src/github.com/Vai3soh/goovpn/cmd/app/

RUN go mod vendor && qtdeploy build desktop
RUN go mod vendor && \
cd /home/user/work/src/github.com/Vai3soh/goovpn/vendor/github.com/Vai3soh/ && \
rm -rf ovpncli && git clone https://github.com/Vai3soh/ovpncli && cd - && \
qtdeploy build desktop
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type (
UseSystemd bool `yaml:"use_systemd" env:"USE_SYSTEMD"`
TunPersist bool `yaml:"tun_persist" env:"TUN_PERSIST"`
ClockTicks int `env-required:"true" yaml:"clock_ticks_time_ms" env:"CLOCK_TICKS_TIME_MS"`
CountReconn int `env-required:"true" yaml:"count_reconnection_attempt" env:"COUNT_RECCONECTION_ATTEMPT"`
VerbLogs bool `yaml:"verbose_logs" env:"VERB_LOGS"`
ConnectTimeout int `env-required:"true" yaml:"conn_timeout" env:"CONN_TIMEOUT"`
CompressionMode string `env-required:"true" yaml:"mode" env:"MODE"`
Expand Down
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ app:
disable_cert: false
mode: 'yes' #yes no
conn_timeout: 30
count_reconnection_attempt: 7

logger:
log_level: 'debug' #info
Expand Down
1 change: 1 addition & 0 deletions config/config_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ app:
disable_cert: false
mode: 'yes' #yes no
conn_timeout: 30
count_reconnection_attempt: 7

logger:
log_level: 'debug' #info
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/Vai3soh/goovpn
go 1.19

require (
github.com/Vai3soh/ovpncli v1.0.0
github.com/fangdingjun/go-log/v5 v5.0.0
github.com/golang/mock v1.6.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/ilyakaznacheev/cleanenv v1.3.0
github.com/ilyakaznacheev/cleanenv v1.4.0
github.com/rainu/go-command-chain v0.1.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d
github.com/xlab/closer v1.0.0
golang.org/x/sync v0.0.0-20220907140024-f12130a52804
github.com/xlab/closer v1.1.0
)

require (
Expand All @@ -26,6 +26,7 @@ require (
github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20200904063919-c0c124a5770d // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/tools v0.1.1 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
Expand Down
19 changes: 12 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Vai3soh/ovpncli v1.0.0 h1:rb65EUyfgU5Hi6W3EaeSVjsUNg3p9aBoq1bKy+CdXcw=
github.com/Vai3soh/ovpncli v1.0.0/go.mod h1:y6rerC0JEON6mQRtPMaQpzEu2vtXxpLhCPfMYbmqDRE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -11,8 +13,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e h1:XWcjeEtTFTOVA9Fs1w7n2XBftk5ib4oZrhzWk0B+3eA=
github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/ilyakaznacheev/cleanenv v1.3.0 h1:RapuLclPPUbmdd5Bi5UXScwMEZA6+ZNLU5OW9itPjj0=
github.com/ilyakaznacheev/cleanenv v1.3.0/go.mod h1:i0owW+HDxeGKE0/JPREJOdSCPIyOnmh6C0xhWAkF/xA=
github.com/ilyakaznacheev/cleanenv v1.4.0 h1:Gvwxt6wAPUo9OOxyp5Xz9eqhLsAey4AtbCF5zevDnvs=
github.com/ilyakaznacheev/cleanenv v1.4.0/go.mod h1:i0owW+HDxeGKE0/JPREJOdSCPIyOnmh6C0xhWAkF/xA=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand All @@ -28,20 +30,22 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d h1:T+d8FnaLSvM/1BdlDXhW4d5dr2F07bAbB+LpgzMxx+o=
github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d/go.mod h1:SUUR2j3aE1z6/g76SdD6NwACEpvCxb3fvG82eKbD6us=
github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20200904063919-c0c124a5770d h1:hAZyEG2swPRWjF0kqqdGERXUazYnRJdAk4a58f14z7Y=
github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20200904063919-c0c124a5770d/go.mod h1:7m8PDYDEtEVqfjoUQc2UrFqhG0CDmoVJjRlQxexndFc=
github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20200904063919-c0c124a5770d h1:AJRoBel/g9cDS+yE8BcN3E+TDD/xNAguG21aoR8DAIE=
github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20200904063919-c0c124a5770d/go.mod h1:mH55Ek7AZcdns5KPp99O0bg+78el64YCYWHiQKrOdt4=
github.com/xlab/closer v1.0.0 h1:2o9/LUpwFzBa1RsHkH+4RPUKLJI6acUW3Go+xi6pOeY=
github.com/xlab/closer v1.0.0/go.mod h1:Ff8YcUPbn5jju6nClrMCmJHQABM0S/obEK0za/1yVMk=
github.com/xlab/closer v1.1.0 h1:yrDiOXjd/B7pZ3lZkl/EZ1gWrR2M2N5XpBnixynm4mc=
github.com/xlab/closer v1.1.0/go.mod h1:Ff8YcUPbn5jju6nClrMCmJHQABM0S/obEK0za/1yVMk=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
Expand All @@ -54,10 +58,11 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220907140024-f12130a52804 h1:0SH2R3f1b1VmIMG7BXbEZCBUu2dKmHschSmjqGUrW8A=
golang.org/x/sync v0.0.0-20220907140024-f12130a52804/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
48 changes: 32 additions & 16 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (

"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"

"github.com/Vai3soh/ovpncli"
)

type fileEmbbed interface {
Expand Down Expand Up @@ -103,7 +105,6 @@ func Run(cfg *config.Config) {
command := cli.NewCmd()
cmdResolver := cli.NewResolver(cli.WithCliResolver(command))

logVpn := make(chan string)
app := widgets.NewQApplication(len(os.Args), os.Args)
mainWindown := widgets.NewQMainWindow(nil, 0)
centralwidget := widgets.NewQWidget(mainWindown, core.Qt__Widget)
Expand All @@ -130,7 +131,6 @@ func Run(cfg *config.Config) {
gui.WithPushButtonExit(pushButtonExit),
gui.WithTextEditReadOnly(textEditReadOnly),
gui.WithVerticalLayout(verticalLayout),
gui.WithChanVpnLog(&logVpn),
)
trayIcon := widgets.NewQSystemTrayIcon(nil)
menu := widgets.NewQMenu(nil)
Expand All @@ -145,15 +145,16 @@ func Run(cfg *config.Config) {
cl := &close.ShutdownApp{}

sessOvpn := session.NewOpenvpnClient(
session.WithCompressionMode(cfg.App.CompressionMode),
session.WithDisableClientCert(cfg.App.CheckDisableClientCert),
session.WithTimeout(cfg.App.ConnectTimeout),
session.WithVerboseLog(cfg.App.VerbLogs),
session.WithClockTicks(cfg.App.ClockTicks),
session.WithTunPersist(cfg.App.TunPersist),
session.WithUi(mainUiWindow),
ovpncli.WithCompressionMode(cfg.App.CompressionMode),
ovpncli.WithDisableClientCert(cfg.App.CheckDisableClientCert),
ovpncli.WithTunPersist(cfg.App.TunPersist),
ovpncli.WithLegacyAlgorithms(true),
ovpncli.WithNonPreferredDCAlgorithms(true),
)

ocl := sessOvpn.GetOverwriteClient()
ocl.ClientAPI_OpenVPNClient = sessOvpn.Client

memory := memory.NewDb(memory.WithMapMemory(
make(map[string]entity.Profile)),
)
Expand All @@ -174,7 +175,7 @@ func Run(cfg *config.Config) {

vpnUseCase, _ := usecase.NewVpnUseCase(
sessOvpn, sessOvpn, gl, gl, gl, gl, gl, gl,
mainUiWindow, mainUiWindow, mainUiWindow, mainUiWindow,
sessOvpn.GetOverwriteClient(), mainUiWindow, mainUiWindow, mainUiWindow,
stray, file, file, cmdResolver,
)

Expand All @@ -193,13 +194,13 @@ func Run(cfg *config.Config) {
if runtime.GOOS != "windows" {
tr = transport.New(
cfg.App.ConfigsPath, cfg.StopTimeout,
vpnUseCase, profileUseCase, names,
vpnUseCase, profileUseCase, names, l,
)
} else {
path := os.Getenv(`USERPROFILE`)
tr = transport.New(
path+"\\"+cfg.ConfigsPath, cfg.StopTimeout,
vpnUseCase, profileUseCase, names,
path+`\\`+cfg.ConfigsPath, cfg.StopTimeout,
vpnUseCase, profileUseCase, names, l,
)
}

Expand Down Expand Up @@ -250,21 +251,37 @@ func Run(cfg *config.Config) {
mainUiWindow.ClearLogForm()
})

flag := false
mainUiWindow.PushButtonConnect.ConnectClicked(func(_ bool) {

if flag {
ocl := session.NewOverwriteClient()
sessOvpn.OverwriteClient = *ocl
ocl.ClientAPI_OpenVPNClient = sessOvpn.Client
sessOvpn.SetClient(ovpncli.NewClient(ocl))
}

ctx, cancel := context.WithCancel(context.Background())

cl.SetBind(tr.Disconnect(cancel))
cl.Binder()

err := tr.Connect(ctx)()
go func() {
err = sessOvpn.CallbackError()
if err != nil {
l.Fatalf("session failed: [%w]\n", err)
}
}()

err := tr.Connect(ctx, cfg.CountReconn)()
if err != nil {
l.Fatalf("connect failed: [%w]\n", err)
}
flag = true

mainUiWindow.PushButtonDiscconnect.ConnectClicked(func(_ bool) {
mainUiWindow.ButtonDisconnectDisable()
cancel()
tr.Disconnect(cancel)()
})

exit.ConnectTriggered(func(bool) {
Expand All @@ -276,7 +293,6 @@ func Run(cfg *config.Config) {
tr.Disconnect(cancel)()
app.Exit(0)
})

})

exit.ConnectTriggered(func(bool) {
Expand Down
22 changes: 0 additions & 22 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ type uiMainWindow struct {
verticalLayout *widgets.QVBoxLayout
textEditReadOnly *widgets.QTextEdit
comboBox *widgets.QComboBox

vpnLog chan string
}

type Option func(*uiMainWindow)
Expand Down Expand Up @@ -106,12 +104,6 @@ func WithComboBox(comboBox *widgets.QComboBox) Option {
}
}

func WithChanVpnLog(vpnLog *chan string) Option {
return func(g *uiMainWindow) {
g.vpnLog = *vpnLog
}
}

type OptionTray func(*sysTray)

func NewSysTray(opts ...OptionTray) *sysTray {
Expand Down Expand Up @@ -239,20 +231,6 @@ func (s *sysTray) SearchKeyInMap(st string) (*string, error) {
return nil, fmt.Errorf("key in map not found")
}

func (g *uiMainWindow) ChanVpnLog() chan string {
return g.vpnLog
}

func (g *uiMainWindow) CloseChanVpnLog() {
close(g.vpnLog)
}

func (g *uiMainWindow) Log(text string) {
if text != "" {
g.vpnLog <- text
}
}

func (s *sysTray) SetIcon(path string) {
s.Tray.SetIcon(qtgui.NewQIcon5(path))
}
Expand Down
Loading

0 comments on commit 5cf65b0

Please sign in to comment.