2022-05-29 04:45:44 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-01-31 04:23:56 +00:00
|
|
|
core "hacklab.nilfm.cc/nirvash/archetype"
|
|
|
|
. "hacklab.nilfm.cc/nirvash/lfo"
|
|
|
|
"hacklab.nilfm.cc/quartzgun/indentalUserDB"
|
|
|
|
. "hacklab.nilfm.cc/quartzgun/middleware"
|
|
|
|
"hacklab.nilfm.cc/quartzgun/renderer"
|
|
|
|
"hacklab.nilfm.cc/quartzgun/router"
|
2023-10-21 04:46:37 +00:00
|
|
|
"html/template"
|
|
|
|
"net/http"
|
2022-05-29 06:26:36 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-05-29 04:45:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-05-31 05:38:51 +00:00
|
|
|
cfg := core.ReadConfig()
|
2022-05-29 06:26:36 +00:00
|
|
|
udb := indentalUserDB.CreateIndentalUserDB(
|
|
|
|
filepath.Join(
|
2022-05-31 05:38:51 +00:00
|
|
|
core.GetConfigLocation(),
|
2022-05-29 06:26:36 +00:00
|
|
|
"user.db"))
|
2022-05-31 05:38:51 +00:00
|
|
|
if core.ProcessCmd(os.Args, udb, cfg) {
|
2022-05-29 06:26:36 +00:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
if cfg.IsNull() {
|
|
|
|
cfg.RunWizard()
|
2022-05-29 06:26:36 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 05:38:51 +00:00
|
|
|
cfg.Adapter.Init(cfg)
|
|
|
|
|
2022-06-10 06:38:29 +00:00
|
|
|
fileManager := &core.SimpleFileManager{}
|
|
|
|
fileManager.Init(cfg)
|
|
|
|
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat := filepath.Join
|
2022-06-12 06:00:38 +00:00
|
|
|
templateRoot := pathConcat(cfg.AssetRoot, "templates")
|
2022-06-08 05:44:54 +00:00
|
|
|
|
2022-05-29 06:26:36 +00:00
|
|
|
rtr := &router.Router{
|
|
|
|
StaticPaths: map[string]string{
|
2022-06-10 06:38:29 +00:00
|
|
|
"/static/": filepath.Join(cfg.AssetRoot, "static"),
|
|
|
|
"/files/": cfg.StaticRoot,
|
2022-05-29 06:26:36 +00:00
|
|
|
},
|
2022-06-12 06:00:38 +00:00
|
|
|
Fallback: *template.Must(template.ParseFiles(
|
|
|
|
pathConcat(templateRoot, "error.html"),
|
2022-06-17 05:19:50 +00:00
|
|
|
pathConcat(templateRoot, "header_err.html"),
|
2022-06-12 06:00:38 +00:00
|
|
|
pathConcat(templateRoot, "footer.html"))),
|
2022-05-29 06:26:36 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 18:09:00 +00:00
|
|
|
rtr.Get("/login", renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "login.html")))
|
2022-05-29 06:26:36 +00:00
|
|
|
|
2022-08-05 01:01:28 +00:00
|
|
|
rtr.Post("/login", Authorize("/", udb, "/login?tryagain=1", 84))
|
2022-05-29 06:26:36 +00:00
|
|
|
|
2022-06-09 05:13:09 +00:00
|
|
|
rtr.Get("/logout", Bunt("/", udb, "/login?tryagain=1"))
|
2022-06-03 04:56:38 +00:00
|
|
|
|
2022-06-06 05:29:39 +00:00
|
|
|
rtr.Get(
|
|
|
|
"/",
|
2022-06-09 05:13:09 +00:00
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
2022-06-05 18:09:00 +00:00
|
|
|
renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "cms_list.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-06 05:29:39 +00:00
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"))
|
|
|
|
|
|
|
|
rtr.Get(
|
|
|
|
`/edit/(?P<Slug>\S+)`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
2022-06-06 05:29:39 +00:00
|
|
|
renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "cms_edit.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-06 05:29:39 +00:00
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Post(
|
|
|
|
`/save/(?P<Slug>\S+)`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
|
|
|
EnsurePageData(
|
2022-06-06 05:29:39 +00:00
|
|
|
renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "cms_save.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-06 05:29:39 +00:00
|
|
|
cfg.Adapter),
|
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
|
|
|
|
|
|
|
rtr.Get(
|
|
|
|
`/new`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
2022-06-06 05:29:39 +00:00
|
|
|
renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "cms_new.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-06 05:29:39 +00:00
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Post(
|
|
|
|
`/create`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
|
|
|
EnsurePageData(
|
2022-06-06 05:29:39 +00:00
|
|
|
renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "cms_create.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-06 05:29:39 +00:00
|
|
|
cfg.Adapter),
|
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
2022-05-29 06:26:36 +00:00
|
|
|
|
2022-06-07 06:59:41 +00:00
|
|
|
rtr.Get(
|
|
|
|
`/build`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
2022-06-07 06:59:41 +00:00
|
|
|
renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "build.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-07 06:59:41 +00:00
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Post(
|
|
|
|
`/build-run`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
SanitizeFormMap(
|
2022-06-18 06:17:08 +00:00
|
|
|
FormMapToBuildOptions(
|
|
|
|
WithAdapter(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "build_run.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
cfg.Adapter))),
|
2022-06-07 06:59:41 +00:00
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
|
|
|
|
2023-10-21 04:46:37 +00:00
|
|
|
rtr.Get(
|
|
|
|
`/deploy`,
|
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "deploy.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Post(
|
|
|
|
`/deploy`,
|
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "deployed.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
|
|
|
rtr.Post(
|
|
|
|
`/revert`,
|
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "reverted.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
2022-06-07 06:59:41 +00:00
|
|
|
rtr.Post(
|
|
|
|
`/delete/(?P<Slug>\S+)`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
2022-06-07 06:59:41 +00:00
|
|
|
renderer.Template(
|
2022-06-08 05:44:54 +00:00
|
|
|
pathConcat(templateRoot, "delete.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
|
|
|
|
|
|
|
rtr.Get(
|
|
|
|
`/config`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
2022-06-08 05:44:54 +00:00
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "config.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-07 06:59:41 +00:00
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
2022-06-08 05:44:54 +00:00
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Post(
|
|
|
|
`/config-set`,
|
2022-06-09 05:13:09 +00:00
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
SanitizeFormMap(
|
|
|
|
FormMapToAdapterConfig(
|
|
|
|
WithAdapter(
|
2022-06-08 05:44:54 +00:00
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "config_set.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-18 06:17:08 +00:00
|
|
|
cfg.Adapter))),
|
2022-06-08 05:44:54 +00:00
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
2022-06-07 06:59:41 +00:00
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
2022-06-08 05:44:54 +00:00
|
|
|
|
2022-06-12 06:00:38 +00:00
|
|
|
rtr.Get(
|
2022-06-15 07:33:56 +00:00
|
|
|
`/file-mgr`,
|
2022-06-12 06:00:38 +00:00
|
|
|
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
2022-06-15 07:33:56 +00:00
|
|
|
http.Redirect(w, req, "/file-mgr/", http.StatusSeeOther)
|
2022-06-12 06:00:38 +00:00
|
|
|
}))
|
|
|
|
|
2022-06-10 06:38:29 +00:00
|
|
|
rtr.Get(
|
2022-06-15 07:33:56 +00:00
|
|
|
`/file-mgr/(?P<Slug>.*)`,
|
2022-06-10 06:38:29 +00:00
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_list.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
2022-06-12 06:00:38 +00:00
|
|
|
rtr.Get(
|
|
|
|
`/file-actions/(?P<Slug>.*)`,
|
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
2022-06-15 07:33:56 +00:00
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_actions.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Get(
|
|
|
|
`/file-move/(?P<Slug>.*)`,
|
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_move.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
2022-06-12 06:00:38 +00:00
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
2022-06-13 06:32:14 +00:00
|
|
|
|
2022-06-15 07:33:56 +00:00
|
|
|
rtr.Post(
|
|
|
|
`/file-move-process/(?P<Slug>.*)`,
|
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_move_process.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
|
|
|
|
2022-06-13 06:32:14 +00:00
|
|
|
rtr.Post(
|
|
|
|
`/file-delete/(?P<Slug>.*)`,
|
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_delete.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
|
|
|
|
|
|
|
rtr.Get(
|
|
|
|
`/upload/(?P<Slug>.*)`,
|
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_upload.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Post(
|
|
|
|
`/upload-process/(?P<Slug>.*)`,
|
|
|
|
PrepareForUpload(
|
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_upload_process.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
2022-06-15 07:33:56 +00:00
|
|
|
"/"),
|
|
|
|
fileManager))
|
2022-06-13 06:32:14 +00:00
|
|
|
|
2022-06-14 04:03:34 +00:00
|
|
|
rtr.Get(
|
|
|
|
`/mkdir/(?P<Slug>.*)`,
|
|
|
|
Fortify(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_mkdir.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login")))
|
|
|
|
|
|
|
|
rtr.Post(
|
|
|
|
`/mkdir-process/(?P<Slug>.*)`,
|
|
|
|
Defend(
|
|
|
|
Protected(
|
|
|
|
WithFileManager(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "file_mkdir_process.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
fileManager),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"),
|
|
|
|
udb,
|
|
|
|
"/"))
|
2022-06-13 06:32:14 +00:00
|
|
|
|
2022-06-15 07:33:56 +00:00
|
|
|
rtr.Get(
|
|
|
|
`/fmt-help`,
|
|
|
|
Protected(
|
|
|
|
WithAdapter(
|
|
|
|
renderer.Template(
|
|
|
|
pathConcat(templateRoot, "format_help.html"),
|
|
|
|
pathConcat(templateRoot, "header.html"),
|
|
|
|
pathConcat(templateRoot, "footer.html")),
|
|
|
|
cfg.Adapter),
|
|
|
|
http.MethodGet,
|
|
|
|
udb,
|
|
|
|
"/login"))
|
2024-10-27 19:30:20 +00:00
|
|
|
|
|
|
|
if cfg.ListenAddress == "" {
|
|
|
|
cfg.ListenAddress = "127.0.0.1:8080"
|
|
|
|
}
|
|
|
|
http.ListenAndServe(cfg.ListenAddress, rtr)
|
2022-05-29 06:26:36 +00:00
|
|
|
}
|