add option in UI to delete past sessions
This commit is contained in:
parent
653fc133ce
commit
3aef75a73e
3 changed files with 32 additions and 0 deletions
|
@ -88,6 +88,7 @@
|
||||||
<th style="width: 50%">Description</th>
|
<th style="width: 50%">Description</th>
|
||||||
<th style="width: 20%">Created at</th>
|
<th style="width: 20%">Created at</th>
|
||||||
<th style="width: 20%">Ended at</th>
|
<th style="width: 20%">Ended at</th>
|
||||||
|
<th style="width: 20%">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
@ -98,6 +99,12 @@
|
||||||
<td>{{ $session.Description }}</td>
|
<td>{{ $session.Description }}</td>
|
||||||
<td>{{ $session.CreatedAt.Format "02.01.2006 15:04:05" }}</td>
|
<td>{{ $session.CreatedAt.Format "02.01.2006 15:04:05" }}</td>
|
||||||
<td>{{ $session.EndedAt.Format "02.01.2006 15:04:05" }}</td>
|
<td>{{ $session.EndedAt.Format "02.01.2006 15:04:05" }}</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="/delete_session" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="session_id" value="{{ $session.Id }}">
|
||||||
|
<input type="submit" value="Delete" class="secondary">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
1
main.go
1
main.go
|
@ -48,6 +48,7 @@ func Run() error {
|
||||||
mux.Handle("GET /", routes.GetIndex(device, storage, tmpl))
|
mux.Handle("GET /", routes.GetIndex(device, storage, tmpl))
|
||||||
mux.Handle("POST /start_session", routes.StartSession(logger, storage))
|
mux.Handle("POST /start_session", routes.StartSession(logger, storage))
|
||||||
mux.Handle("POST /end_session", routes.EndSession(logger, storage))
|
mux.Handle("POST /end_session", routes.EndSession(logger, storage))
|
||||||
|
mux.Handle("POST /delete_session", routes.DeleteSession(logger, storage))
|
||||||
|
|
||||||
mux.Handle("POST /api/session", routes.APIStartSession(logger, storage))
|
mux.Handle("POST /api/session", routes.APIStartSession(logger, storage))
|
||||||
mux.Handle("DELETE /api/session/{session_id}", routes.APIEndSession(logger, storage))
|
mux.Handle("DELETE /api/session/{session_id}", routes.APIEndSession(logger, storage))
|
||||||
|
|
|
@ -83,3 +83,27 @@ func EndSession(logger *log.Logger, storage sessions.Storage) http.HandlerFunc {
|
||||||
logger.Printf("Ended session for %s via webpanel (id = %s)", req.RemoteAddr, sessionId)
|
logger.Printf("Ended session for %s via webpanel (id = %s)", req.RemoteAddr, sessionId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteSession(logger *log.Logger, storage sessions.Storage) http.HandlerFunc {
|
||||||
|
return func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
err := req.ParseMultipartForm(10 * 1024)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(res, "", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sessionId := req.FormValue("session_id")
|
||||||
|
err = storage.DeleteSession(sessionId)
|
||||||
|
switch {
|
||||||
|
case err == sessions.ErrUnknownSession:
|
||||||
|
http.Error(res, "", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
case err != nil:
|
||||||
|
http.Error(res, "", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.Redirect(res, req, "/", http.StatusFound)
|
||||||
|
logger.Printf("Deleted session for %s via webpanel (id = %s)", req.RemoteAddr, sessionId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue