switch to gin, add basic server redering to login
This commit is contained in:
221
app/app.go
221
app/app.go
@@ -1,196 +1,123 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"proxmoxaas-dashboard/dist/web" // go will complain here until the first build
|
"proxmoxaas-dashboard/dist/web" // go will complain here until the first build
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/tdewolff/minify"
|
"github.com/tdewolff/minify"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseTemplates() map[string]*template.Template {
|
func ServeStatic(router *gin.Engine, m *minify.M) {
|
||||||
// create html map which stores html files to parsed templates
|
|
||||||
html := make(map[string]*template.Template)
|
|
||||||
fs.WalkDir(web.HTML, ".", func(path string, html_entry fs.DirEntry, err error) error { // walk the html directory
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !html_entry.IsDir() { // if it is an html file, parse with all the template files
|
|
||||||
v, err := fs.ReadFile(web.HTML, path)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error reading html file %s: %s", path, err.Error())
|
|
||||||
}
|
|
||||||
t := template.New(html_entry.Name()) // parse the html file
|
|
||||||
t, err = t.Parse(string(v))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error parsing html file %s: %s", path, err.Error())
|
|
||||||
}
|
|
||||||
// parse the html with every template file
|
|
||||||
fs.WalkDir(web.Templates, ".", func(path string, templates_entry fs.DirEntry, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !templates_entry.IsDir() { // if it is a template file, parse it
|
|
||||||
v, err = fs.ReadFile(web.Templates, path)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error reading template file %s: %s", path, err.Error())
|
|
||||||
}
|
|
||||||
t, err = t.Parse(string(v)) // parse the template file
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error parsing template file %s: %s", path, err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
html[html_entry.Name()] = t
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
return html
|
|
||||||
}
|
|
||||||
|
|
||||||
func ServeStatic(m *minify.M) {
|
|
||||||
css := MinifyStatic(m, web.CSS_fs)
|
css := MinifyStatic(m, web.CSS_fs)
|
||||||
http.HandleFunc("/css/", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/css/*css", func(c *gin.Context) {
|
||||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
path, _ := c.Params.Get("css")
|
||||||
data := css[path]
|
data := css[fmt.Sprintf("css%s", path)]
|
||||||
w.Header().Add("Content-Type", data.MimeType.Type)
|
c.Data(200, data.MimeType.Type, []byte(data.Data))
|
||||||
w.Write([]byte(data.Data))
|
|
||||||
})
|
})
|
||||||
images := MinifyStatic(m, web.Images_fs)
|
images := MinifyStatic(m, web.Images_fs)
|
||||||
http.HandleFunc("/images/", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/images/*image", func(c *gin.Context) {
|
||||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
path, _ := c.Params.Get("image")
|
||||||
data := images[path]
|
data := images[fmt.Sprintf("images%s", path)]
|
||||||
w.Header().Add("Content-Type", data.MimeType.Type)
|
c.Data(200, data.MimeType.Type, []byte(data.Data))
|
||||||
w.Write([]byte(data.Data))
|
|
||||||
})
|
})
|
||||||
modules := MinifyStatic(m, web.Modules_fs)
|
modules := MinifyStatic(m, web.Modules_fs)
|
||||||
http.HandleFunc("/modules/", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/modules/*module", func(c *gin.Context) {
|
||||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
path, _ := c.Params.Get("module")
|
||||||
data := modules[path]
|
data := modules[fmt.Sprintf("modules%s", path)]
|
||||||
w.Header().Add("Content-Type", data.MimeType.Type)
|
c.Data(200, data.MimeType.Type, []byte(data.Data))
|
||||||
w.Write([]byte(data.Data))
|
|
||||||
})
|
})
|
||||||
scripts := MinifyStatic(m, web.Scripts_fs)
|
scripts := MinifyStatic(m, web.Scripts_fs)
|
||||||
http.HandleFunc("/scripts/", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/scripts/*script", func(c *gin.Context) {
|
||||||
path := strings.TrimPrefix(r.URL.Path, "/")
|
path, _ := c.Params.Get("script")
|
||||||
data := scripts[path]
|
data := scripts[fmt.Sprintf("scripts%s", path)]
|
||||||
w.Header().Add("Content-Type", data.MimeType.Type)
|
c.Data(200, data.MimeType.Type, []byte(data.Data))
|
||||||
w.Write([]byte(data.Data))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
||||||
configPath := flag.String("config", "config.json", "path to config.json file")
|
configPath := flag.String("config", "config.json", "path to config.json file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
global := GetConfig(*configPath)
|
global := GetConfig(*configPath)
|
||||||
|
|
||||||
|
router := gin.Default()
|
||||||
m := InitMinify()
|
m := InitMinify()
|
||||||
|
|
||||||
ServeStatic(m)
|
ServeStatic(router, m)
|
||||||
|
|
||||||
html := ParseTemplates()
|
html := MinifyStatic(m, web.Templates)
|
||||||
|
LoadHTMLToGin(router, html)
|
||||||
|
|
||||||
http.HandleFunc("/account.html", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/account.html", func(c *gin.Context) {
|
||||||
global.Page = "account"
|
c.HTML(http.StatusOK, "html/account.html", gin.H{
|
||||||
page := bytes.Buffer{}
|
"global": global,
|
||||||
err := html["account.html"].Execute(&page, global)
|
"page": "account",
|
||||||
if err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
minified := bytes.Buffer{}
|
|
||||||
err = m.Minify("text/html", &minified, &page)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
w.Write(minified.Bytes())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/", func(c *gin.Context) {
|
||||||
global.Page = "index"
|
c.HTML(http.StatusOK, "html/index.html", gin.H{
|
||||||
page := bytes.Buffer{}
|
"global": global,
|
||||||
err := html["index.html"].Execute(&page, global)
|
"page": "index",
|
||||||
if err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
minified := bytes.Buffer{}
|
|
||||||
err = m.Minify("text/html", &minified, &page)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
w.Write(minified.Bytes())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/index.html", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/index.html", func(c *gin.Context) {
|
||||||
global.Page = "index"
|
c.HTML(http.StatusOK, "html/index.html", gin.H{
|
||||||
page := bytes.Buffer{}
|
"global": global,
|
||||||
err := html["index.html"].Execute(&page, global)
|
"page": "index",
|
||||||
if err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
minified := bytes.Buffer{}
|
|
||||||
err = m.Minify("text/html", &minified, &page)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
w.Write(minified.Bytes())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/instance.html", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/instance.html", func(c *gin.Context) {
|
||||||
global.Page = "instance"
|
c.HTML(http.StatusOK, "html/instance.html", gin.H{
|
||||||
page := bytes.Buffer{}
|
"global": global,
|
||||||
err := html["instance.html"].Execute(&page, global)
|
"page": "instance",
|
||||||
if err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
minified := bytes.Buffer{}
|
|
||||||
err = m.Minify("text/html", &minified, &page)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
w.Write(minified.Bytes())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/login.html", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/login.html", func(c *gin.Context) {
|
||||||
global.Page = "login"
|
response, err := http.Get(global.API + "/proxmox/access/domains")
|
||||||
page := bytes.Buffer{}
|
|
||||||
err := html["login.html"].Execute(&page, global)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
minified := bytes.Buffer{}
|
data, err := io.ReadAll(response.Body)
|
||||||
err = m.Minify("text/html", &minified, &page)
|
response.Body.Close()
|
||||||
if err != nil {
|
body := GetRealmsBody{}
|
||||||
log.Fatal(err.Error())
|
json.Unmarshal(data, &body)
|
||||||
|
realms := Select{
|
||||||
|
ID: "realm",
|
||||||
|
Name: "realm",
|
||||||
}
|
}
|
||||||
w.Write(minified.Bytes())
|
for _, realm := range body.Data {
|
||||||
|
realms.Options = append(realms.Options, Option{
|
||||||
|
Selected: realm.Default != 0,
|
||||||
|
Value: realm.Realm,
|
||||||
|
Display: realm.Comment,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
c.HTML(http.StatusOK, "html/login.html", gin.H{
|
||||||
|
"global": global,
|
||||||
|
"page": "login",
|
||||||
|
"realms": realms,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/settings.html", func(w http.ResponseWriter, r *http.Request) {
|
router.GET("/settings.html", func(c *gin.Context) {
|
||||||
global.Page = "settings"
|
c.HTML(http.StatusOK, "html/settings.html", gin.H{
|
||||||
page := bytes.Buffer{}
|
"global": global,
|
||||||
err := html["settings.html"].Execute(&page, global)
|
"page": "settings",
|
||||||
if err != nil {
|
})
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
minified := bytes.Buffer{}
|
|
||||||
err = m.Minify("text/html", &minified, &page)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
w.Write(minified.Bytes())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Printf("Starting HTTP server at port: %d\n", global.Port)
|
router.Run(fmt.Sprintf("0.0.0.0:%d", global.Port))
|
||||||
err := http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", global.Port), nil)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
73
app/types.go
Normal file
73
app/types.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/tdewolff/minify"
|
||||||
|
"github.com/tdewolff/minify/css"
|
||||||
|
"github.com/tdewolff/minify/html"
|
||||||
|
"github.com/tdewolff/minify/js"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MimeType struct {
|
||||||
|
Type string
|
||||||
|
Minifier func(m *minify.M, w io.Writer, r io.Reader, params map[string]string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
var PlainTextMimeType = MimeType{
|
||||||
|
Type: "text/plain",
|
||||||
|
Minifier: nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
var MimeTypes = map[string]MimeType{
|
||||||
|
"css": {
|
||||||
|
Type: "text/css",
|
||||||
|
Minifier: css.Minify,
|
||||||
|
},
|
||||||
|
"html": {
|
||||||
|
Type: "text/html",
|
||||||
|
Minifier: html.Minify,
|
||||||
|
},
|
||||||
|
"tmpl": {
|
||||||
|
Type: "text/plain",
|
||||||
|
Minifier: TemplateMinifier,
|
||||||
|
},
|
||||||
|
"svg": {
|
||||||
|
Type: "image/svg+xml",
|
||||||
|
Minifier: nil,
|
||||||
|
},
|
||||||
|
"js": {
|
||||||
|
Type: "application/javascript",
|
||||||
|
Minifier: js.Minify,
|
||||||
|
},
|
||||||
|
"wasm": {
|
||||||
|
Type: "application/wasm",
|
||||||
|
Minifier: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// used when requesting GET /access/domains
|
||||||
|
type GetRealmsBody struct {
|
||||||
|
Data []Realm `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// stores each realm's data
|
||||||
|
type Realm struct {
|
||||||
|
Default int `json:"default"`
|
||||||
|
Realm string `json:"realm"`
|
||||||
|
Comment string `json:"comment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// type used for templated <select>
|
||||||
|
type Select struct {
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
Options []Option
|
||||||
|
}
|
||||||
|
|
||||||
|
// type used for templated <option>
|
||||||
|
type Option struct {
|
||||||
|
Selected bool
|
||||||
|
Value string
|
||||||
|
Display string
|
||||||
|
}
|
80
app/utils.go
80
app/utils.go
@@ -1,18 +1,18 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"embed"
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/tdewolff/minify"
|
"github.com/tdewolff/minify"
|
||||||
"github.com/tdewolff/minify/css"
|
|
||||||
"github.com/tdewolff/minify/html"
|
|
||||||
"github.com/tdewolff/minify/js"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -20,7 +20,6 @@ type Config struct {
|
|||||||
Organization string `json:"organization"`
|
Organization string `json:"organization"`
|
||||||
PVE string `json:"pveurl"`
|
PVE string `json:"pveurl"`
|
||||||
API string `json:"apiurl"`
|
API string `json:"apiurl"`
|
||||||
Page string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfig(configPath string) Config {
|
func GetConfig(configPath string) Config {
|
||||||
@@ -36,39 +35,6 @@ func GetConfig(configPath string) Config {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
type MimeType struct {
|
|
||||||
Type string
|
|
||||||
Minifier func(m *minify.M, w io.Writer, r io.Reader, params map[string]string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
var PlainTextMimeType = MimeType{
|
|
||||||
Type: "text/plain",
|
|
||||||
Minifier: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
var MimeTypes = map[string]MimeType{
|
|
||||||
"css": {
|
|
||||||
Type: "text/css",
|
|
||||||
Minifier: css.Minify,
|
|
||||||
},
|
|
||||||
"html": {
|
|
||||||
Type: "text/html",
|
|
||||||
Minifier: html.Minify,
|
|
||||||
},
|
|
||||||
"svg": {
|
|
||||||
Type: "image/svg+xml",
|
|
||||||
Minifier: nil,
|
|
||||||
},
|
|
||||||
"js": {
|
|
||||||
Type: "application/javascript",
|
|
||||||
Minifier: js.Minify,
|
|
||||||
},
|
|
||||||
"wasm": {
|
|
||||||
Type: "application/wasm",
|
|
||||||
Minifier: nil,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitMinify() *minify.M {
|
func InitMinify() *minify.M {
|
||||||
m := minify.New()
|
m := minify.New()
|
||||||
for _, v := range MimeTypes {
|
for _, v := range MimeTypes {
|
||||||
@@ -119,8 +85,48 @@ func MinifyStatic(m *minify.M, files embed.FS) map[string]StaticFile {
|
|||||||
MimeType: PlainTextMimeType,
|
MimeType: PlainTextMimeType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("%s: %s \n\n", path, minified[path].Data)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return minified
|
return minified
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LoadHTMLToGin(engine *gin.Engine, html map[string]StaticFile) {
|
||||||
|
root := template.New("")
|
||||||
|
tmpl := template.Must(root, LoadAndAddToRoot(engine.FuncMap, root, html))
|
||||||
|
engine.SetHTMLTemplate(tmpl)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadAndAddToRoot(FuncMap template.FuncMap, root *template.Template, html map[string]StaticFile) error {
|
||||||
|
for name, file := range html {
|
||||||
|
t := root.New(name).Funcs(FuncMap)
|
||||||
|
_, err := t.Parse(file.Data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TemplateMinifier(m *minify.M, w io.Writer, r io.Reader, _ map[string]string) error {
|
||||||
|
// remove newlines and tabs
|
||||||
|
rb := bufio.NewReader(r)
|
||||||
|
for {
|
||||||
|
line, err := rb.ReadString('\n')
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
line = strings.Replace(line, "\n", "", -1)
|
||||||
|
line = strings.Replace(line, "\t", "", -1)
|
||||||
|
line = strings.Replace(line, " ", "", -1)
|
||||||
|
if _, errws := io.WriteString(w, line); errws != nil {
|
||||||
|
return errws
|
||||||
|
}
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
40
go.mod
40
go.mod
@@ -1,11 +1,39 @@
|
|||||||
module proxmoxaas-dashboard
|
module proxmoxaas-dashboard
|
||||||
|
|
||||||
go 1.23.2
|
go 1.24
|
||||||
|
|
||||||
require github.com/tdewolff/minify v2.3.6+incompatible
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/tdewolff/minify/v2 v2.21.3 // indirect
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/tdewolff/parse v2.3.4+incompatible // indirect
|
github.com/tdewolff/minify v2.3.6+incompatible
|
||||||
github.com/tdewolff/parse/v2 v2.7.20 // indirect
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/bytedance/sonic v1.12.10 // indirect
|
||||||
|
github.com/bytedance/sonic/loader v0.2.3 // indirect
|
||||||
|
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||||
|
github.com/foolin/goview v0.3.0 // indirect
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
||||||
|
github.com/gin-contrib/sse v1.0.0 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.25.0 // indirect
|
||||||
|
github.com/goccy/go-json v0.10.5 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||||
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
||||||
|
github.com/tdewolff/parse v2.3.4+incompatible // indirect
|
||||||
|
github.com/tdewolff/test v1.0.11-0.20240106005702-7de5f7df4739 // indirect
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
|
golang.org/x/arch v0.14.0 // indirect
|
||||||
|
golang.org/x/crypto v0.35.0 // indirect
|
||||||
|
golang.org/x/net v0.35.0 // indirect
|
||||||
|
golang.org/x/sys v0.30.0 // indirect
|
||||||
|
golang.org/x/text v0.22.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.36.5 // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
@@ -17,7 +17,5 @@ var Modules_fs embed.FS
|
|||||||
var Scripts_fs embed.FS
|
var Scripts_fs embed.FS
|
||||||
|
|
||||||
//go:embed html/*
|
//go:embed html/*
|
||||||
var HTML embed.FS
|
|
||||||
|
|
||||||
//go:embed templates/*
|
//go:embed templates/*
|
||||||
var Templates embed.FS
|
var Templates embed.FS
|
||||||
|
@@ -12,14 +12,14 @@
|
|||||||
</header>
|
</header>
|
||||||
<main class="flex" style="justify-content: center; align-items: center;">
|
<main class="flex" style="justify-content: center; align-items: center;">
|
||||||
<div class="w3-container w3-card w3-margin w3-padding" style="height: fit-content;">
|
<div class="w3-container w3-card w3-margin w3-padding" style="height: fit-content;">
|
||||||
<h2 class="w3-center">{{.Organization}} Login</h2>
|
<h2 class="w3-center">{{.global.Organization}} Login</h2>
|
||||||
<form>
|
<form>
|
||||||
<label for="username"><b>Username</b></label>
|
<label for="username"><b>Username</b></label>
|
||||||
<input class="w3-input w3-border" id="username" name="username" type="text" autocomplete="username">
|
<input class="w3-input w3-border" id="username" name="username" type="text" autocomplete="username">
|
||||||
<label for="password"><b>Password</b></label>
|
<label for="password"><b>Password</b></label>
|
||||||
<input class="w3-input w3-border" id="password" name="password" type="password" autocomplete="current-password">
|
<input class="w3-input w3-border" id="password" name="password" type="password" autocomplete="current-password">
|
||||||
<label for="realm">Realm</label>
|
<label for="realm">Realm</label>
|
||||||
<select class="w3-select w3-border" id="realm" name="realm"></select>
|
{{template "select" .realms}}
|
||||||
<div class="w3-center">
|
<div class="w3-center">
|
||||||
<button class="w3-button w3-margin" id="submit" type="submit">LOGIN</button>
|
<button class="w3-button w3-margin" id="submit" type="submit">LOGIN</button>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { goToPage, requestPVE, setAppearance, requestAPI } from "./utils.js";
|
import { goToPage, setAppearance, requestAPI } from "./utils.js";
|
||||||
import { alert } from "./dialog.js";
|
import { alert } from "./dialog.js";
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
@@ -7,14 +7,6 @@ async function init () {
|
|||||||
await deleteAllCookies();
|
await deleteAllCookies();
|
||||||
setAppearance();
|
setAppearance();
|
||||||
const formSubmitButton = document.querySelector("#submit");
|
const formSubmitButton = document.querySelector("#submit");
|
||||||
const realms = await requestPVE("/access/domains", "GET");
|
|
||||||
const realmSelect = document.querySelector("#realm");
|
|
||||||
realms.data.forEach((element) => {
|
|
||||||
realmSelect.add(new Option(element.comment, element.realm));
|
|
||||||
if ("default" in element && element.default === 1) {
|
|
||||||
realmSelect.value = element.realm;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
formSubmitButton.addEventListener("click", async (e) => {
|
formSubmitButton.addEventListener("click", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const form = document.querySelector("form");
|
const form = document.querySelector("form");
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
{{define "head"}}
|
{{define "head"}}
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>{{.Organization}} - dashboard</title>
|
<title>{{.global.Organization}} - dashboard</title>
|
||||||
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
|
||||||
<link rel="stylesheet" href="modules/w3.css">
|
<link rel="stylesheet" href="modules/w3.css">
|
||||||
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
<script>
|
<script>
|
||||||
window.PVE = "{{.PVE}}";
|
window.PVE = "{{.global.PVE}}";
|
||||||
window.API = "{{.API}}";
|
window.API = "{{.global.API}}";
|
||||||
</script>
|
</script>
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
<link rel="stylesheet" href="css/nav.css">
|
<link rel="stylesheet" href="css/nav.css">
|
||||||
@@ -15,16 +15,16 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "header"}}
|
{{define "header"}}
|
||||||
<h1>{{.Organization}}</h1>
|
<h1>{{.global.Organization}}</h1>
|
||||||
<label for="navtoggle">☰</label>
|
<label for="navtoggle">☰</label>
|
||||||
<input type="checkbox" id="navtoggle">
|
<input type="checkbox" id="navtoggle">
|
||||||
<nav id="navigation">
|
<nav id="navigation">
|
||||||
{{if eq .Page "login"}}
|
{{if eq .page "login"}}
|
||||||
<a href="login.html" aria-current="page">Login</a>
|
<a href="login.html" aria-current="page">Login</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="index.html" {{if eq .Page "index"}} aria-current="page" {{end}}>Instances</a>
|
<a href="index.html" {{if eq .page "index"}} aria-current="page" {{end}}>Instances</a>
|
||||||
<a href="account.html" {{if eq .Page "account"}} aria-current="page" {{end}}>Account</a>
|
<a href="account.html" {{if eq .page "account"}} aria-current="page" {{end}}>Account</a>
|
||||||
<a href="settings.html" {{if eq .Page "settings"}} aria-current="page" {{end}}>Settings</a>
|
<a href="settings.html" {{if eq .page "settings"}} aria-current="page" {{end}}>Settings</a>
|
||||||
<a href="login.html">Logout</a>
|
<a href="login.html">Logout</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</nav>
|
</nav>
|
11
web/templates/select.tmpl
Normal file
11
web/templates/select.tmpl
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{{define "select"}}
|
||||||
|
<select class="w3-select w3-border" id="{{.ID}}" name="{{.Name}}">
|
||||||
|
{{range .Options}}
|
||||||
|
{{if .Selected}}
|
||||||
|
<option value="{{.Value}}" selected>{{.Display}}</option>
|
||||||
|
{{else}}
|
||||||
|
<option value="{{.Value}}">{{.Display}}</option>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</select>
|
||||||
|
{{end}}
|
Reference in New Issue
Block a user