From 100771a7ba16d3a384e71b9b4f8391e5a71146d9 Mon Sep 17 00:00:00 2001
From: Erik Brakkee
Date: Tue, 30 Jul 2024 19:59:13 +0200
Subject: [PATCH] restructuring
---
cmd/agent/agent.go | 18 +++++++++---------
cmd/converge/converge.go | 4 ++--
cmd/converge/pagehandler.go | 10 +++++-----
cmd/tcptows/tcptows.go | 4 ++--
cmd/templaterender/render.go | 10 +++++-----
cmd/wsproxy/wsproxy.go | 4 ++--
cmd/wstotcp/wstotcp.go | 4 ++--
go.mod | 2 +-
go.sum | 5 ++++-
pkg/agent/{ => session}/help.txt | 0
pkg/agent/{ => session}/session.go | 4 ++--
pkg/agent/{ => session}/ssh.go | 2 +-
pkg/{ => agent}/terminal/process.go | 0
pkg/{ => agent}/terminal/pty_linux.go | 0
pkg/{ => agent}/terminal/pty_windows.go | 0
pkg/comms/agentlistener.go | 2 +-
pkg/{ => server}/converge/admin.go | 14 +++++++-------
pkg/{ => server}/templates/about.templ | 0
pkg/{ => server}/templates/basepage.templ | 0
pkg/{ => server}/templates/constants.go | 0
pkg/{ => server}/templates/downloads.templ | 0
pkg/{ => server}/templates/index.templ | 0
pkg/{ => server}/templates/sessions.templ | 0
pkg/{ => server}/templates/usage.templ | 4 ++--
pkg/{ => support}/async/async.go | 0
pkg/{ => support}/concurrency/atomiccounter.go | 0
pkg/{ => support}/iowrappers/io.go | 0
pkg/{ => support}/iowrappers/sync.go | 0
pkg/{ => support}/websocketutil/connections.go | 0
pkg/{ => support}/websocketutil/services.go | 0
30 files changed, 45 insertions(+), 42 deletions(-)
rename pkg/agent/{ => session}/help.txt (100%)
rename pkg/agent/{ => session}/session.go (99%)
rename pkg/agent/{ => session}/ssh.go (97%)
rename pkg/{ => agent}/terminal/process.go (100%)
rename pkg/{ => agent}/terminal/pty_linux.go (100%)
rename pkg/{ => agent}/terminal/pty_windows.go (100%)
rename pkg/{ => server}/converge/admin.go (94%)
rename pkg/{ => server}/templates/about.templ (100%)
rename pkg/{ => server}/templates/basepage.templ (100%)
rename pkg/{ => server}/templates/constants.go (100%)
rename pkg/{ => server}/templates/downloads.templ (100%)
rename pkg/{ => server}/templates/index.templ (100%)
rename pkg/{ => server}/templates/sessions.templ (100%)
rename pkg/{ => server}/templates/usage.templ (97%)
rename pkg/{ => support}/async/async.go (100%)
rename pkg/{ => support}/concurrency/atomiccounter.go (100%)
rename pkg/{ => support}/iowrappers/io.go (100%)
rename pkg/{ => support}/iowrappers/sync.go (100%)
rename pkg/{ => support}/websocketutil/connections.go (100%)
rename pkg/{ => support}/websocketutil/services.go (100%)
diff --git a/cmd/agent/agent.go b/cmd/agent/agent.go
index eacdc88..e78b3a9 100755
--- a/cmd/agent/agent.go
+++ b/cmd/agent/agent.go
@@ -2,11 +2,11 @@ package main
import (
"bufio"
- "converge/pkg/agent"
+ "converge/pkg/agent/session"
+ "converge/pkg/agent/terminal"
"converge/pkg/comms"
- "converge/pkg/iowrappers"
- "converge/pkg/terminal"
- "converge/pkg/websocketutil"
+ "converge/pkg/support/iowrappers"
+ "converge/pkg/support/websocketutil"
"crypto/tls"
"fmt"
"github.com/gliderlabs/ssh"
@@ -37,8 +37,8 @@ func SftpHandler(sess ssh.Session) {
sess.LocalAddr().String(),
"sftp",
)
- agent.Login(sessionInfo, sess)
- defer agent.LogOut(sessionInfo.ClientId)
+ session.Login(sessionInfo, sess)
+ defer session.LogOut(sessionInfo.ClientId)
debugStream := io.Discard
serverOptions := []sftp.ServerOption{
@@ -73,9 +73,9 @@ func sshServer(hostKeyFile string, shellCommand string,
sessionInfo := comms.NewSessionInfo(
s.LocalAddr().String(), "ssh",
)
- agent.Login(sessionInfo, s)
+ session.Login(sessionInfo, s)
iowrappers.SynchronizeStreams(process.Pipe(), s)
- agent.LogOut(sessionInfo.ClientId)
+ session.LogOut(sessionInfo.ClientId)
// will cause addition goroutines to remmain alive when the SSH
// session is killed. For now acceptable since the agent is a short-lived
// process. Using Kill() here will create defunct processes and in normal
@@ -335,7 +335,7 @@ func main() {
"://"+urlObject.Host+"/static/wsproxy"+extension)
log.Println()
- agent.ConfigureAgent(commChannel, advanceWarningTime, agentExpriryTime, tickerInterval)
+ session.ConfigureAgent(commChannel, advanceWarningTime, agentExpriryTime, tickerInterval)
listener := comms.NewAgentListener(commChannel.Session)
diff --git a/cmd/converge/converge.go b/cmd/converge/converge.go
index 30346c8..4cc0592 100644
--- a/cmd/converge/converge.go
+++ b/cmd/converge/converge.go
@@ -2,8 +2,8 @@ package main
import (
"converge/pkg/comms"
- "converge/pkg/converge"
- "converge/pkg/websocketutil"
+ "converge/pkg/server/converge"
+ "converge/pkg/support/websocketutil"
"fmt"
"log"
"math/rand"
diff --git a/cmd/converge/pagehandler.go b/cmd/converge/pagehandler.go
index 40a16c5..8e6f154 100644
--- a/cmd/converge/pagehandler.go
+++ b/cmd/converge/pagehandler.go
@@ -1,7 +1,7 @@
package main
import (
- "converge/pkg/templates"
+ templates2 "converge/pkg/server/templates"
"net/http"
"os"
"strings"
@@ -30,13 +30,13 @@ func pageHandler(w http.ResponseWriter, r *http.Request) {
case "/":
fallthrough
case "index.html":
- templates.AboutTab().Render(r.Context(), w)
+ templates2.AboutTab().Render(r.Context(), w)
case "usage.html":
- templates.UsageTab(secure, r.Host, username).Render(r.Context(), w)
+ templates2.UsageTab(secure, r.Host, username).Render(r.Context(), w)
case "downloads.html":
- templates.DownloadsTab().Render(r.Context(), w)
+ templates2.DownloadsTab().Render(r.Context(), w)
case "sessions.html":
- templates.SessionsTab().Render(r.Context(), w)
+ templates2.SessionsTab().Render(r.Context(), w)
default:
http.NotFound(w, r)
}
diff --git a/cmd/tcptows/tcptows.go b/cmd/tcptows/tcptows.go
index 462f89a..9d95e35 100644
--- a/cmd/tcptows/tcptows.go
+++ b/cmd/tcptows/tcptows.go
@@ -1,8 +1,8 @@
package main
import (
- "converge/pkg/iowrappers"
- "converge/pkg/websocketutil"
+ "converge/pkg/support/iowrappers"
+ "converge/pkg/support/websocketutil"
"crypto/tls"
"fmt"
"github.com/gorilla/websocket"
diff --git a/cmd/templaterender/render.go b/cmd/templaterender/render.go
index 7c4ecfc..98c11bd 100644
--- a/cmd/templaterender/render.go
+++ b/cmd/templaterender/render.go
@@ -2,7 +2,7 @@ package main
import (
"context"
- "converge/pkg/templates"
+ templates2 "converge/pkg/server/templates"
"github.com/a-h/templ"
"log"
"os"
@@ -30,14 +30,14 @@ func main() {
dir := "html/docs"
fullindex := func() templ.Component {
- return templates.Index("s", "example.com", "converge")
+ return templates2.Index("s", "example.com", "converge")
}
usage := func() templ.Component {
- return templates.UsageTab("s", "example.com", "converge")
+ return templates2.UsageTab("s", "example.com", "converge")
}
render(dir, "fullindex.html", fullindex)
- render(dir, "index.html", templates.AboutTab)
+ render(dir, "index.html", templates2.AboutTab)
render(dir, "usage.html", usage)
- render(dir, "downloads.html", templates.Downloads)
+ render(dir, "downloads.html", templates2.Downloads)
}
diff --git a/cmd/wsproxy/wsproxy.go b/cmd/wsproxy/wsproxy.go
index a54c719..e574ed0 100644
--- a/cmd/wsproxy/wsproxy.go
+++ b/cmd/wsproxy/wsproxy.go
@@ -1,8 +1,8 @@
package main
import (
- "converge/pkg/iowrappers"
- "converge/pkg/websocketutil"
+ "converge/pkg/support/iowrappers"
+ "converge/pkg/support/websocketutil"
"crypto/tls"
"fmt"
"github.com/gorilla/websocket"
diff --git a/cmd/wstotcp/wstotcp.go b/cmd/wstotcp/wstotcp.go
index 99afe69..b586f7f 100644
--- a/cmd/wstotcp/wstotcp.go
+++ b/cmd/wstotcp/wstotcp.go
@@ -1,8 +1,8 @@
package main
import (
- "converge/pkg/iowrappers"
- "converge/pkg/websocketutil"
+ "converge/pkg/support/iowrappers"
+ "converge/pkg/support/websocketutil"
"fmt"
"github.com/gorilla/websocket"
"log"
diff --git a/go.mod b/go.mod
index fe53485..bcdb396 100755
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.21
require (
github.com/ActiveState/termtest/conpty v0.5.0
+ github.com/a-h/templ v0.2.747
github.com/creack/pty v1.1.21
github.com/fsnotify/fsnotify v1.7.0
github.com/gliderlabs/ssh v0.3.7
@@ -16,7 +17,6 @@ require (
require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
- github.com/a-h/templ v0.2.747 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/kr/fs v0.1.0 // indirect
golang.org/x/sys v0.22.0 // indirect
diff --git a/go.sum b/go.sum
index aceb5a6..f66c644 100755
--- a/go.sum
+++ b/go.sum
@@ -15,6 +15,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
+github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
+github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
@@ -28,8 +30,9 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
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.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
diff --git a/pkg/agent/help.txt b/pkg/agent/session/help.txt
similarity index 100%
rename from pkg/agent/help.txt
rename to pkg/agent/session/help.txt
diff --git a/pkg/agent/session.go b/pkg/agent/session/session.go
similarity index 99%
rename from pkg/agent/session.go
rename to pkg/agent/session/session.go
index 4c0ec03..0bc3582 100644
--- a/pkg/agent/session.go
+++ b/pkg/agent/session/session.go
@@ -1,9 +1,9 @@
-package agent
+package session
import (
"bytes"
- "converge/pkg/async"
"converge/pkg/comms"
+ "converge/pkg/support/async"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/gliderlabs/ssh"
diff --git a/pkg/agent/ssh.go b/pkg/agent/session/ssh.go
similarity index 97%
rename from pkg/agent/ssh.go
rename to pkg/agent/session/ssh.go
index 53f655f..46e4a29 100644
--- a/pkg/agent/ssh.go
+++ b/pkg/agent/session/ssh.go
@@ -1,4 +1,4 @@
-package agent
+package session
import (
"crypto/rand"
diff --git a/pkg/terminal/process.go b/pkg/agent/terminal/process.go
similarity index 100%
rename from pkg/terminal/process.go
rename to pkg/agent/terminal/process.go
diff --git a/pkg/terminal/pty_linux.go b/pkg/agent/terminal/pty_linux.go
similarity index 100%
rename from pkg/terminal/pty_linux.go
rename to pkg/agent/terminal/pty_linux.go
diff --git a/pkg/terminal/pty_windows.go b/pkg/agent/terminal/pty_windows.go
similarity index 100%
rename from pkg/terminal/pty_windows.go
rename to pkg/agent/terminal/pty_windows.go
diff --git a/pkg/comms/agentlistener.go b/pkg/comms/agentlistener.go
index 45ce80e..661c85a 100644
--- a/pkg/comms/agentlistener.go
+++ b/pkg/comms/agentlistener.go
@@ -1,7 +1,7 @@
package comms
import (
- "converge/pkg/websocketutil"
+ "converge/pkg/support/websocketutil"
"net"
"strconv"
)
diff --git a/pkg/converge/admin.go b/pkg/server/converge/admin.go
similarity index 94%
rename from pkg/converge/admin.go
rename to pkg/server/converge/admin.go
index c798cbd..df59903 100644
--- a/pkg/converge/admin.go
+++ b/pkg/server/converge/admin.go
@@ -2,9 +2,9 @@ package converge
import (
"converge/pkg/comms"
- "converge/pkg/concurrency"
- "converge/pkg/iowrappers"
"converge/pkg/models"
+ "converge/pkg/support/concurrency"
+ iowrappers2 "converge/pkg/support/iowrappers"
"fmt"
"io"
"log"
@@ -25,7 +25,7 @@ var clientIdGenerator = concurrency.NewAtomicCounter()
type ClientConnection struct {
models.Client
agent net.Conn
- client iowrappers.ReadWriteAddrCloser
+ client iowrappers2.ReadWriteAddrCloser
}
func NewAgent(commChannel comms.CommChannel, publicId string, agentInfo comms.AgentInfo) *AgentConnection {
@@ -39,7 +39,7 @@ func NewAgent(commChannel comms.CommChannel, publicId string, agentInfo comms.Ag
}
}
-func NewClient(publicId string, clientConn iowrappers.ReadWriteAddrCloser,
+func NewClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser,
agentConn net.Conn) *ClientConnection {
return &ClientConnection{
Client: models.Client{
@@ -152,7 +152,7 @@ func (admin *Admin) addAgent(publicId string, agentInfo comms.AgentInfo, conn io
return agent, nil
}
-func (admin *Admin) addClient(publicId string, clientConn iowrappers.ReadWriteAddrCloser) (*ClientConnection, error) {
+func (admin *Admin) addClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser) (*ClientConnection, error) {
admin.mutex.Lock()
defer admin.mutex.Unlock()
@@ -274,7 +274,7 @@ func (admin *Admin) Register(publicId string, conn io.ReadWriteCloser,
return nil
}
-func (admin *Admin) Connect(publicId string, conn iowrappers.ReadWriteAddrCloser) error {
+func (admin *Admin) Connect(publicId string, conn iowrappers2.ReadWriteAddrCloser) error {
defer conn.Close()
client, err := admin.addClient(publicId, conn)
if err != nil {
@@ -285,6 +285,6 @@ func (admin *Admin) Connect(publicId string, conn iowrappers.ReadWriteAddrCloser
}()
log.Printf("Connecting client and agent: '%s'\n", publicId)
- iowrappers.SynchronizeStreams(client.client, client.agent)
+ iowrappers2.SynchronizeStreams(client.client, client.agent)
return nil
}
diff --git a/pkg/templates/about.templ b/pkg/server/templates/about.templ
similarity index 100%
rename from pkg/templates/about.templ
rename to pkg/server/templates/about.templ
diff --git a/pkg/templates/basepage.templ b/pkg/server/templates/basepage.templ
similarity index 100%
rename from pkg/templates/basepage.templ
rename to pkg/server/templates/basepage.templ
diff --git a/pkg/templates/constants.go b/pkg/server/templates/constants.go
similarity index 100%
rename from pkg/templates/constants.go
rename to pkg/server/templates/constants.go
diff --git a/pkg/templates/downloads.templ b/pkg/server/templates/downloads.templ
similarity index 100%
rename from pkg/templates/downloads.templ
rename to pkg/server/templates/downloads.templ
diff --git a/pkg/templates/index.templ b/pkg/server/templates/index.templ
similarity index 100%
rename from pkg/templates/index.templ
rename to pkg/server/templates/index.templ
diff --git a/pkg/templates/sessions.templ b/pkg/server/templates/sessions.templ
similarity index 100%
rename from pkg/templates/sessions.templ
rename to pkg/server/templates/sessions.templ
diff --git a/pkg/templates/usage.templ b/pkg/server/templates/usage.templ
similarity index 97%
rename from pkg/templates/usage.templ
rename to pkg/server/templates/usage.templ
index 6100bff..e9e5abd 100644
--- a/pkg/templates/usage.templ
+++ b/pkg/server/templates/usage.templ
@@ -12,13 +12,13 @@ templ Usage(secure string, host string, username string) {
{`
# linux
- `}curl http{secure}://{host}/static/agent > agent{`
+ `}curl http{secure}://{host}/static/session > session{`
chmod 755 agent
`}./agent --id ID ws{secure}://{host}{`
rm -f agent
# windows
- `}curl http{secure}://{host}/static/agent.exe > agent.exe{`
+ `}curl http{secure}://{host}/static/session.exe > session.exe{`
`}agent --id ID ws{secure}://{host}{`
del agent.exe
`}
diff --git a/pkg/async/async.go b/pkg/support/async/async.go
similarity index 100%
rename from pkg/async/async.go
rename to pkg/support/async/async.go
diff --git a/pkg/concurrency/atomiccounter.go b/pkg/support/concurrency/atomiccounter.go
similarity index 100%
rename from pkg/concurrency/atomiccounter.go
rename to pkg/support/concurrency/atomiccounter.go
diff --git a/pkg/iowrappers/io.go b/pkg/support/iowrappers/io.go
similarity index 100%
rename from pkg/iowrappers/io.go
rename to pkg/support/iowrappers/io.go
diff --git a/pkg/iowrappers/sync.go b/pkg/support/iowrappers/sync.go
similarity index 100%
rename from pkg/iowrappers/sync.go
rename to pkg/support/iowrappers/sync.go
diff --git a/pkg/websocketutil/connections.go b/pkg/support/websocketutil/connections.go
similarity index 100%
rename from pkg/websocketutil/connections.go
rename to pkg/support/websocketutil/connections.go
diff --git a/pkg/websocketutil/services.go b/pkg/support/websocketutil/services.go
similarity index 100%
rename from pkg/websocketutil/services.go
rename to pkg/support/websocketutil/services.go