converge/pkg/server/templates/sessions.templ

94 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>id</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.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>
<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 id</th>
<th>id</th>
<th>start time</th>
<th>session type</th>
</tr>
</thead>
for _, client := range state.Clients {
<tr>
<td>{client.PublicId}</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)
}
}