|
@@ -2,37 +2,31 @@ package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "html/template"
|
|
|
"net/http"
|
|
|
+ "os"
|
|
|
|
|
|
+ "github.com/namsral/flag"
|
|
|
+
|
|
|
+ "git.lattuga.net/boyska/feedpanel/panelui"
|
|
|
"github.com/urfave/negroni"
|
|
|
)
|
|
|
|
|
|
-var helloTmpl *template.Template
|
|
|
-
|
|
|
-func init() {
|
|
|
- helloTmpl = template.Must(template.New("hello").Parse(`
|
|
|
-<html><body>Hello, {{.User}}
|
|
|
-<p>Go to <a href="/tt-rss/">Feed Reader</a></p>
|
|
|
-</body></html>`))
|
|
|
-}
|
|
|
-
|
|
|
func main() {
|
|
|
- mux := http.NewServeMux()
|
|
|
- mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
- user := r.Context().Value(keyUser)
|
|
|
- if user == nil {
|
|
|
- panic("Authentication middleware failed!")
|
|
|
- }
|
|
|
- w.WriteHeader(200)
|
|
|
- w.Header().Set("Content-type", "text/html")
|
|
|
- helloTmpl.Execute(w, map[string]interface{}{"User": user})
|
|
|
- })
|
|
|
+ fs := flag.NewFlagSetWithEnvPrefix(os.Args[0], "PANEL", 0)
|
|
|
+ allowedName := fs.String("allowed-name", "", "Name allowed to forward auth")
|
|
|
+ addr := fs.String("listen-addr", ":8000", "Address to listen on")
|
|
|
+ fs.Parse(os.Args[1:])
|
|
|
+
|
|
|
+ var allowedNames []string
|
|
|
+ if *allowedName != "" {
|
|
|
+ allowedNames = []string{*allowedName}
|
|
|
+ } else {
|
|
|
+ allowedNames = []string{}
|
|
|
+ }
|
|
|
|
|
|
- ha := HeaderAuth{AllowedNames: []string{"feedati-fe"}, RequireUser: true}
|
|
|
+ ha := panelui.HeaderAuth{AllowedNames: allowedNames, RequireUser: true}
|
|
|
n := negroni.New(negroni.NewRecovery(), negroni.NewLogger(), ha)
|
|
|
- n.UseHandler(mux)
|
|
|
- addr := ":8000"
|
|
|
- fmt.Println("Listening on", addr)
|
|
|
- http.ListenAndServe(addr, n)
|
|
|
+ n.UseHandler(panelui.GetMux())
|
|
|
+ fmt.Println("Listening on", *addr)
|
|
|
+ http.ListenAndServe(*addr, n)
|
|
|
}
|