move templates path to -tpl option

pull/1/head
vasyahacker 2023-03-31 11:35:04 +04:00
parent 5c9b00bd73
commit a115ec5ce4
2 changed files with 15 additions and 17 deletions

View File

@ -10,6 +10,7 @@ import (
"os"
"strings"
"path/filepath"
"errors"
"golang.org/x/sys/unix"
)
@ -61,9 +62,11 @@ var sysname_opt *string = flag.String("sys", "OpenIDEC", "Node name")
var host_opt *string = flag.String("host", "http://127.0.0.1:8080", "Node address")
var verbose_opt *bool = flag.Bool("v", false, "Verbose")
var echo_opt *string = flag.String("e", "list.txt", "Echoes list")
var tpl_path_opt *string = flag.String("tpl", "./tpl", "Path to html templates")
type WWW struct {
Host string
tplp string // templates path
tpl *template.Template
db *ii.DB
edb *ii.EDB
@ -100,8 +103,12 @@ func main() {
flag.Parse()
unix.Unveil("./tpl", "r")
unix.Unveil("/var/openidec/tpl", "r")
if _, err := os.Stat(*tpl_path_opt); errors.Is(err, os.ErrNotExist) {
ii.Error.Printf("Templates dir %s not found", *tpl_path_opt)
os.Exit(1)
}
unix.Unveil(*tpl_path_opt, "r")
unix.Unveil(*echo_opt, "r")
unix.Unveil(*users_opt, "rwc")
unix.Unveil(filepath.Dir(*db_opt), "rwc")
@ -116,10 +123,11 @@ func main() {
ii.OpenLog(os.Stdout, os.Stdout, os.Stderr)
}
db.Name = *sysname_opt
www.db = db
www.edb = edb
www.udb = udb
db.Name = *sysname_opt
www.tplp = *tpl_path_opt
www.db = db
www.edb = edb
www.udb = udb
www.Host = *host_opt
WebInit(&www)

View File

@ -913,18 +913,8 @@ func WebInit(www *WWW) {
},
}
tpl_path := "tpl"
if _, err := os.Stat(tpl_path); errors.Is(err, os.ErrNotExist) {
ii.Info.Printf("./tpl not found, trying /var/openidec/tpl..")
tpl_path = "/var/openidec/tpl"
if _, err := os.Stat(tpl_path); errors.Is(err, os.ErrNotExist) {
ii.Error.Printf(" %s not found", tpl_path)
os.Exit(1)
}
}
www.tpl = template.Must(
template.New("main").Funcs(funcMap).ParseGlob(tpl_path + "/*.tpl"))
template.New("main").Funcs(funcMap).ParseGlob(www.tplp + "/*.tpl"))
}
func handleErr(ctx *WebContext, w http.ResponseWriter, err error) {