2013-01-06 15:20:54 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2013-02-19 22:56:01 -08:00
|
|
|
"fmt"
|
2013-02-20 21:11:44 -08:00
|
|
|
"github.com/gorilla/sessions"
|
|
|
|
"html/template"
|
2013-01-06 15:20:54 -08:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2013-02-19 22:56:01 -08:00
|
|
|
var addr = flag.String("addr", ":8000", "address I'll listen on.")
|
2013-01-06 15:29:31 -08:00
|
|
|
var static_files = flag.String("static", "./static", "location of static files")
|
2013-02-26 22:30:23 -08:00
|
|
|
var passes_file = flag.String("passes", "passwds.json", "the password database")
|
2013-02-28 23:25:51 -08:00
|
|
|
var db_file = flag.String("children", "children.json", "the children database")
|
2013-02-20 21:11:44 -08:00
|
|
|
var template_dir = flag.String("templates", "templates", "template dir")
|
2013-02-19 22:56:01 -08:00
|
|
|
var add_pw = flag.String("passwd", "", "add this pass to the db")
|
2013-02-21 00:19:21 -08:00
|
|
|
var check_pw = flag.String("checkpw", "", "check if this pw is in db")
|
2013-01-06 15:20:54 -08:00
|
|
|
|
2013-03-08 22:28:24 -08:00
|
|
|
var addPath = "/add/"
|
|
|
|
|
2013-02-20 21:11:44 -08:00
|
|
|
var store = sessions.NewCookieStore([]byte("hello world"))
|
|
|
|
var templates *template.Template
|
|
|
|
|
2013-01-06 15:20:54 -08:00
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2013-02-19 22:56:01 -08:00
|
|
|
if *add_pw != "" {
|
2013-02-26 22:30:23 -08:00
|
|
|
add_password(*passes_file, *add_pw)
|
2013-02-21 00:19:21 -08:00
|
|
|
} else if *check_pw != "" {
|
2013-02-26 22:30:23 -08:00
|
|
|
fmt.Printf("valid password: %v\n",
|
|
|
|
check_password(*passes_file, *check_pw))
|
2013-02-19 22:56:01 -08:00
|
|
|
} else {
|
2013-02-20 21:11:44 -08:00
|
|
|
http.HandleFunc("/", homeHandler)
|
2013-02-20 21:27:09 -08:00
|
|
|
http.HandleFunc("/login", loginHandler)
|
2013-02-26 22:39:26 -08:00
|
|
|
http.HandleFunc("/logout", logoutHandler)
|
2013-03-08 22:28:24 -08:00
|
|
|
http.HandleFunc(addPath, addHandler)
|
2013-02-19 22:56:01 -08:00
|
|
|
http.Handle("/s/", http.StripPrefix("/s/",
|
|
|
|
http.FileServer(http.Dir(*static_files))))
|
|
|
|
if err := http.ListenAndServe(*addr, nil); err != nil {
|
|
|
|
log.Fatal("ListenAndServe:", err)
|
|
|
|
}
|
2013-01-06 15:20:54 -08:00
|
|
|
}
|
|
|
|
}
|