54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"amnezia-share/internal/web"
|
|
)
|
|
|
|
type adminIndexView struct {
|
|
adminLayout
|
|
TotalLinks int
|
|
ActiveLinks int
|
|
ExpiredLinks int
|
|
CleanedLinks int
|
|
LimitLinks int
|
|
CodesCount int
|
|
PanelURL string
|
|
PanelOK bool
|
|
PanelErr string
|
|
Maintenance bool
|
|
}
|
|
|
|
// AdminIndex renders the admin dashboard (admin/index.php).
|
|
func AdminIndex(a *web.App) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
view := adminIndexView{adminLayout: newAdminLayout(a, r, "index")}
|
|
|
|
view.TotalLinks, _ = a.Share.CountLinks(ctx, "")
|
|
view.ActiveLinks, _ = a.Share.CountLinks(ctx, "active")
|
|
view.ExpiredLinks, _ = a.Share.CountLinks(ctx, "expired")
|
|
view.CleanedLinks, _ = a.Share.CountLinks(ctx, "cleaned")
|
|
view.LimitLinks, _ = a.Share.CountLinks(ctx, "limit")
|
|
if codes, err := a.Share.ListCodes(ctx); err == nil {
|
|
view.CodesCount = len(codes)
|
|
}
|
|
view.Maintenance = a.Settings.Maintenance(ctx)
|
|
|
|
view.PanelURL = a.Settings.PanelURL(ctx)
|
|
token := a.Settings.PanelToken(ctx)
|
|
if view.PanelURL != "" && token != "" {
|
|
servers, err := a.Panel.ListServers(ctx, view.PanelURL, token)
|
|
if err != nil {
|
|
view.PanelErr = err.Error()
|
|
} else {
|
|
view.PanelOK = true
|
|
_ = servers
|
|
}
|
|
}
|
|
|
|
a.Render(w, r, "page_admin_index", view)
|
|
}
|
|
}
|