2013-01-06 15:20:54 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-02-19 22:56:01 -08:00
|
|
|
"code.google.com/p/go.crypto/bcrypt"
|
2013-01-06 15:20:54 -08:00
|
|
|
"flag"
|
2013-02-19 22:56:01 -08:00
|
|
|
"fmt"
|
|
|
|
"github.com/kuroneko/gosqlite3"
|
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-19 22:56:01 -08:00
|
|
|
var db_file = flag.String("db", "./db.sqlite", "the database")
|
|
|
|
var add_pw = flag.String("passwd", "", "add this pass to the db")
|
2013-01-06 15:20:54 -08:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2013-02-19 22:56:01 -08:00
|
|
|
|
|
|
|
if *add_pw != "" {
|
|
|
|
hpass, err := bcrypt.GenerateFromPassword([]byte(*add_pw), bcrypt.DefaultCost)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
db, err := sqlite3.Open(*db_file)
|
|
|
|
defer db.Close()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
cmd := fmt.Sprintf("INSERT INTO passes ('id', 'hash') VALUES (null, '%v')",
|
|
|
|
string(hpass))
|
|
|
|
_, err = db.Execute(cmd)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Printf("%v\n", *add_pw)
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|