diff --git a/cmd/control/cli.go b/cmd/control/cli.go index 1f32933..625b678 100644 --- a/cmd/control/cli.go +++ b/cmd/control/cli.go @@ -7,6 +7,7 @@ import ( ) type CliArgs struct { + DBName string KeyFile string LogFile string PicsDir string @@ -21,6 +22,7 @@ func HandleCliArgs() (*CliArgs, error) { logFile := flag.String("log", "/var/log/cpolis.log", "log file") picsDir := flag.String("pics", "/var/www/cpolis/pics", "pictures directory") webDir := flag.String("web", "/var/www/cpolis/web", "web directory") + flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name") flag.Parse() cliArgs.KeyFile, err = filepath.Abs(*keyFile) diff --git a/cmd/main.go b/cmd/main.go index d173c99..2f33d62 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -16,67 +16,67 @@ func init() { } func main() { - cliArgs, err := control.HandleCliArgs() + args, err := control.HandleCliArgs() if err != nil { log.Fatalln(err) } - logFile, err := os.OpenFile(cliArgs.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) + logFile, err := os.OpenFile(args.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) if err != nil { log.Fatalln(err) } defer logFile.Close() log.SetOutput(logFile) - db, err := model.OpenDB("cpolis") + db, err := model.OpenDB(args.DBName) if err != nil { log.Fatalln(err) } defer db.Close() - key, err := control.LoadKey(cliArgs.KeyFile) + key, err := control.LoadKey(args.KeyFile) if err != nil { key, err = control.NewKey() if err != nil { log.Fatalln(err) } - control.SaveKey(key, cliArgs.KeyFile) + control.SaveKey(key, args.KeyFile) } store := control.NewCookieStore(key) mux := http.NewServeMux() mux.Handle("/web/static/", http.StripPrefix("/web/static/", - http.FileServer(http.Dir(cliArgs.WebDir+"/static/")))) - mux.HandleFunc("/", view.HomePage(cliArgs, db, store)) + http.FileServer(http.Dir(args.WebDir+"/static/")))) + mux.HandleFunc("/", view.HomePage(args, db, store)) - mux.HandleFunc("GET /create-tag/", view.CreateTag(cliArgs)) - mux.HandleFunc("GET /create-user/", view.CreateUser(cliArgs)) - mux.HandleFunc("GET /edit-user/", view.EditUser(cliArgs, db, store)) - mux.HandleFunc("GET /hub/", view.ShowHub(cliArgs, db, store)) - mux.HandleFunc("GET /logout/", view.Logout(cliArgs, store)) - mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(cliArgs, db, store)) - mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(cliArgs, db, store)) - mux.HandleFunc("GET /rss/", view.ShowRSS(cliArgs, + mux.HandleFunc("GET /create-tag/", view.CreateTag(args)) + mux.HandleFunc("GET /create-user/", view.CreateUser(args)) + mux.HandleFunc("GET /edit-user/", view.EditUser(args, db, store)) + mux.HandleFunc("GET /hub/", view.ShowHub(args, db, store)) + mux.HandleFunc("GET /logout/", view.Logout(args, store)) + mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(args, db, store)) + mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(args, db, store)) + mux.HandleFunc("GET /rss/", view.ShowRSS(args, db, "Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt", "https://distrikt-ni-st.de", "Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität", )) - mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(cliArgs, db)) - mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(cliArgs, db)) - mux.HandleFunc("GET /write-article/", view.WriteArticle(cliArgs, db)) + mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(args, db)) + mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(args, db)) + mux.HandleFunc("GET /write-article/", view.WriteArticle(args, db)) - mux.HandleFunc("POST /add-tag/", view.AddTag(cliArgs, db, store)) - mux.HandleFunc("POST /add-user/", view.AddUser(cliArgs, db, store)) - mux.HandleFunc("POST /login/", view.Login(cliArgs, db, store)) - mux.HandleFunc("POST /publish-article/", view.PublishArticle(cliArgs, db, store)) - mux.HandleFunc("POST /reject-article/", view.RejectArticle(cliArgs, db, store)) - mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(cliArgs, db, store)) - mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(cliArgs, db, store)) - mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(cliArgs, db, store)) - mux.HandleFunc("POST /submit-article/", view.SubmitArticle(cliArgs, db, store)) - mux.HandleFunc("POST /update-user/", view.UpdateUser(cliArgs, db, store)) - mux.HandleFunc("POST /upload-image/", view.UploadImage(cliArgs)) + mux.HandleFunc("POST /add-tag/", view.AddTag(args, db, store)) + mux.HandleFunc("POST /add-user/", view.AddUser(args, db, store)) + mux.HandleFunc("POST /login/", view.Login(args, db, store)) + mux.HandleFunc("POST /publish-article/", view.PublishArticle(args, db, store)) + mux.HandleFunc("POST /reject-article/", view.RejectArticle(args, db, store)) + mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(args, db, store)) + mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(args, db, store)) + mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(args, db, store)) + mux.HandleFunc("POST /submit-article/", view.SubmitArticle(args, db, store)) + mux.HandleFunc("POST /update-user/", view.UpdateUser(args, db, store)) + mux.HandleFunc("POST /upload-image/", view.UploadImage(args)) log.Fatalln(http.ListenAndServe(":8080", mux)) } diff --git a/cmd/view/articles.go b/cmd/view/articles.go index 6025246..f28d1c8 100644 --- a/cmd/view/articles.go +++ b/cmd/view/articles.go @@ -385,7 +385,7 @@ func UploadImage(c *control.CliArgs) http.HandlerFunc { } defer file.Close() - filename := fmt.Sprint("tmp/pics/", time.Now().Format("2006-01-02_15:04:05"), "-", header.Filename) + filename := fmt.Sprint(c.PicsDir, time.Now().Format("2006-01-02_15:04:05"), "-", header.Filename) img, err := os.Create(filename) if err != nil { log.Println(err)