package main import ( 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" "html/template" "net/http" "os" "path/filepath" ) func main() { cfg := core.ReadConfig() udb := indentalUserDB.CreateIndentalUserDB( filepath.Join( core.GetConfigLocation(), "user.db")) if core.ProcessCmd(os.Args, udb, cfg) { os.Exit(0) } if cfg.IsNull() { cfg.RunWizard() } cfg.Adapter.Init(cfg) fileManager := &core.SimpleFileManager{} fileManager.Init(cfg) pathConcat := filepath.Join templateRoot := pathConcat(cfg.AssetRoot, "templates") rtr := &router.Router{ StaticPaths: map[string]string{ "/static/": filepath.Join(cfg.AssetRoot, "static"), "/files/": cfg.StaticRoot, }, Fallback: *template.Must(template.ParseFiles( pathConcat(templateRoot, "error.html"), pathConcat(templateRoot, "header_err.html"), pathConcat(templateRoot, "footer.html"))), } rtr.Get("/login", renderer.Template( pathConcat(templateRoot, "login.html"))) rtr.Post("/login", Authorize("/", udb, "/login?tryagain=1", 84)) rtr.Get("/logout", Bunt("/", udb, "/login?tryagain=1")) rtr.Get( "/", Protected( WithAdapter( renderer.Template( pathConcat(templateRoot, "cms_list.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), http.MethodGet, udb, "/login")) rtr.Get( `/edit/(?P\S+)`, Fortify( Protected( WithAdapter( renderer.Template( pathConcat(templateRoot, "cms_edit.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), http.MethodGet, udb, "/login"))) rtr.Post( `/save/(?P\S+)`, Defend( Protected( WithAdapter( EnsurePageData( renderer.Template( pathConcat(templateRoot, "cms_save.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), cfg.Adapter), http.MethodGet, udb, "/login"), udb, "/")) rtr.Get( `/new`, Fortify( Protected( WithAdapter( renderer.Template( pathConcat(templateRoot, "cms_new.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), http.MethodGet, udb, "/login"))) rtr.Post( `/create`, Defend( Protected( WithAdapter( EnsurePageData( renderer.Template( pathConcat(templateRoot, "cms_create.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), cfg.Adapter), http.MethodGet, udb, "/login"), udb, "/")) rtr.Get( `/build`, Fortify( Protected( WithAdapter( renderer.Template( pathConcat(templateRoot, "build.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), http.MethodGet, udb, "/login"))) rtr.Post( `/build-run`, Defend( Protected( SanitizeFormMap( FormMapToBuildOptions( WithAdapter( renderer.Template( pathConcat(templateRoot, "build_run.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter))), http.MethodGet, udb, "/login"), udb, "/")) 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, "/")) rtr.Post( `/delete/(?P\S+)`, Defend( Protected( WithAdapter( renderer.Template( pathConcat(templateRoot, "delete.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), http.MethodGet, udb, "/login"), udb, "/")) rtr.Get( `/config`, Fortify( Protected( WithAdapter( renderer.Template( pathConcat(templateRoot, "config.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter), http.MethodGet, udb, "/login"))) rtr.Post( `/config-set`, Defend( Protected( SanitizeFormMap( FormMapToAdapterConfig( WithAdapter( renderer.Template( pathConcat(templateRoot, "config_set.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), cfg.Adapter))), http.MethodGet, udb, "/login"), udb, "/")) rtr.Get( `/file-mgr`, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { http.Redirect(w, req, "/file-mgr/", http.StatusSeeOther) })) rtr.Get( `/file-mgr/(?P.*)`, Fortify( Protected( WithFileManager( renderer.Template( pathConcat(templateRoot, "file_list.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), fileManager), http.MethodGet, udb, "/login"))) rtr.Get( `/file-actions/(?P.*)`, Fortify( Protected( WithFileManager( 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.*)`, Fortify( Protected( WithFileManager( renderer.Template( pathConcat(templateRoot, "file_move.html"), pathConcat(templateRoot, "header.html"), pathConcat(templateRoot, "footer.html")), fileManager), http.MethodGet, udb, "/login"))) rtr.Post( `/file-move-process/(?P.*)`, 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, "/")) rtr.Post( `/file-delete/(?P.*)`, 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.*)`, 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.*)`, 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, "/"), fileManager)) rtr.Get( `/mkdir/(?P.*)`, 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.*)`, 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, "/")) 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")) if cfg.ListenAddress == "" { cfg.ListenAddress = "127.0.0.1:8080" } http.ListenAndServe(cfg.ListenAddress, rtr) }