main.go 602 B

123456789101112131415161718192021222324252627282930313233
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "io/ioutil"
  6. "math/rand"
  7. "path/filepath"
  8. "time"
  9. )
  10. func main() {
  11. rand.Seed(time.Now().UnixNano())
  12. pass := flag.String("p", "", "password")
  13. dataDir := flag.String("d", "/usr/share/website", "data directory")
  14. stateDir := flag.String("s", "/var/lib/website", "data directory")
  15. flag.Parse()
  16. if *pass != "" {
  17. hash, err := GenerateFromPassword(*pass)
  18. if err != nil {
  19. fmt.Println(err)
  20. return
  21. }
  22. ioutil.WriteFile(filepath.Join(*stateDir, "password"), []byte(hash), 0600)
  23. fmt.Println("Password updated")
  24. return
  25. }
  26. route(*dataDir, *stateDir)
  27. }