converge/pkg/server/templates/sessions.templ
Erik Brakkee 1b1f8f2167 A lot of work in getting cut and paste from the UI to
work properly.

Wrote two web components. One for cut and paste in general, and another for code samples.
2024-09-08 11:16:49 +02:00

95 lines
2.1 KiB
Plaintext

package templates
import (
"converge/pkg/models"
"strconv"
"time"
_ "time/tzdata"
)
templ Sessions(state *models.State, loc *time.Location) {
<div hx-ext="ws" ws-connect="../ws/sessions">
<h1>sessions</h1>
<div id="status">
if state != nil {
@State(state, loc)
} else {
Loading...
}
</div>
</div>
}
templ State(state *models.State, location *time.Location) {
<div id="status">
<h3>agents</h3>
if len(state.Agents) == 0 {
<p>-</p>
} else {
<table class="table">
<thead>
<tr>
<th>#</th>
<th>start time</th>
<th>expiry time</th>
<th>username</th>
<th>host</th>
<th>OS</th>
<th>shell</th>
</tr>
</thead>
for _, agent := range state.Agents {
<tr>
<td>{agent.GeneratedId}</td>
<td>{agent.StartTime.In(location).Format(time.DateTime)}</td>
<td>{agent.ExpiryTime.In(location).Format(time.DateTime)}</td>
<td>{agent.AgentInfo.Username}</td>
<td>{agent.AgentInfo.Hostname}</td>
<td>{agent.AgentInfo.OS}</td>
<td>{agent.AgentInfo.Shell}</td>
</tr>
}
</table>
}
<h3>clients</h3>
if len(state.Clients) == 0 {
<p>-</p>
} else {
<table class="table">
<thead>
<tr>
<th>agent#</th>
<th>id</th>
<th>start time</th>
<th>session type</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>
</tr>
}
</table>
}
</div>
}
templ SessionsTab(state *models.State, loc *time.Location) {
@BasePage(4) {
@Sessions(state, loc)
}
}