From ae60b77eece1cbdecd520d52ef3410032f07d41d Mon Sep 17 00:00:00 2001
From: Erik Brakkee <erik@brakkee.org>
Date: Tue, 6 Aug 2024 22:50:24 +0200
Subject: [PATCH] public id is now shown on the sessions page since authorized
 keys are used which is safer.

---
 cmd/templaterender/render.go        |  6 ++----
 pkg/models/agent.go                 |  5 ++---
 pkg/models/client.go                |  1 -
 pkg/server/converge/admin.go        | 12 +++++-------
 pkg/server/templates/sessions.templ |  8 ++++----
 5 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/cmd/templaterender/render.go b/cmd/templaterender/render.go
index a89e3b5..70fd8c6 100644
--- a/cmd/templaterender/render.go
+++ b/cmd/templaterender/render.go
@@ -79,9 +79,8 @@ func main() {
 
 		state := models.State{}
 		agent := models.Agent{
-			PublicId:    "id",
-			GeneratedId: "100",
-			StartTime:   time.Now().In(japan),
+			PublicId:  "id",
+			StartTime: time.Now().In(japan),
 			AgentInfo: comms.AgentInfo{
 				Username: "ci",
 				Hostname: "container123",
@@ -94,7 +93,6 @@ func main() {
 		state.Agents = append(state.Agents, agent)
 		client := models.Client{
 			PublicId:    "c1",
-			AgentId:     "100",
 			ClientId:    3,
 			StartTime:   time.Now().In(japan),
 			SessionType: "sftp",
diff --git a/pkg/models/agent.go b/pkg/models/agent.go
index 4fc2015..5660039 100644
--- a/pkg/models/agent.go
+++ b/pkg/models/agent.go
@@ -6,9 +6,8 @@ import (
 )
 
 type Agent struct {
-	PublicId    string
-	GeneratedId string
-	StartTime   time.Time
+	PublicId  string
+	StartTime time.Time
 
 	AgentInfo  comms.AgentInfo
 	ExpiryTime time.Time
diff --git a/pkg/models/client.go b/pkg/models/client.go
index a0b8fe3..17136ea 100644
--- a/pkg/models/client.go
+++ b/pkg/models/client.go
@@ -6,7 +6,6 @@ import (
 
 type Client struct {
 	PublicId    string
-	AgentId     string
 	ClientId    int
 	StartTime   time.Time
 	SessionType string
diff --git a/pkg/server/converge/admin.go b/pkg/server/converge/admin.go
index a88e75d..f9d5866 100644
--- a/pkg/server/converge/admin.go
+++ b/pkg/server/converge/admin.go
@@ -33,21 +33,19 @@ type ClientConnection struct {
 func NewAgent(commChannel comms.CommChannel, publicId string, agentInfo comms.AgentInfo) *AgentConnection {
 	return &AgentConnection{
 		Agent: models.Agent{
-			PublicId:    publicId,
-			GeneratedId: strconv.Itoa(agentIdGenerator.IncrementAndGet()),
-			StartTime:   time.Now(),
-			AgentInfo:   agentInfo,
+			PublicId:  publicId,
+			StartTime: time.Now(),
+			AgentInfo: agentInfo,
 		},
 		commChannel: commChannel,
 	}
 }
 
-func NewClient(publicId string, agentId string, clientConn iowrappers2.ReadWriteAddrCloser,
+func NewClient(publicId string, clientConn iowrappers2.ReadWriteAddrCloser,
 	agentConn net.Conn) *ClientConnection {
 	return &ClientConnection{
 		Client: models.Client{
 			PublicId:  publicId,
-			AgentId:   agentId,
 			ClientId:  clientIdGenerator.IncrementAndGet(),
 			StartTime: time.Now(),
 		},
@@ -200,7 +198,7 @@ func (admin *Admin) addClient(publicId string, clientConn iowrappers2.ReadWriteA
 
 	log.Println("Sending connection information to agent")
 
-	client := NewClient(publicId, agent.GeneratedId, clientConn, agentConn)
+	client := NewClient(publicId, clientConn, agentConn)
 
 	// Before using this connection for SSH we use it to send client metadata to the
 	// agent
diff --git a/pkg/server/templates/sessions.templ b/pkg/server/templates/sessions.templ
index f8ba748..20070ee 100644
--- a/pkg/server/templates/sessions.templ
+++ b/pkg/server/templates/sessions.templ
@@ -34,7 +34,7 @@ templ State(state *models.State, location *time.Location) {
         <table class="table">
            <thead>
            <tr>
-               <th>#</th>
+               <th>rendez-vous id</th>
                <th>start time</th>
                <th>expiry time</th>
                <th>username</th>
@@ -45,7 +45,7 @@ templ State(state *models.State, location *time.Location) {
            </thead>
    for _, agent := range state.Agents {
            <tr>
-               <td>{agent.GeneratedId}</td>
+               <td>{agent.PublicId}</td>
                <td>{agent.StartTime.In(location).Format(time.DateTime)}</td>
                <td>{agent.ExpiryTime.In(location).Format(time.DateTime)}</td>
                <td>{agent.AgentInfo.Username}</td>
@@ -67,18 +67,18 @@ templ State(state *models.State, location *time.Location) {
           <table class="table">
               <thead>
               <tr>
-                  <th>agent#</th>
                   <th>id</th>
                   <th>start time</th>
                   <th>session type</th>
+                  <th>rendez-vous id</th>
               </tr>
               </thead>
    for _, client := range state.Clients {
               <tr>
-                  <td>{client.AgentId}</td>
                   <td>{strconv.Itoa(client.ClientId)}</td>
                   <td>{client.StartTime.In(location).Format(time.DateTime)}</td>
                   <td>{client.SessionType}</td>
+                  <td>{client.PublicId}</td>
               </tr>
    }
           </table>