miniwol/main.go

38 lines
654 B
Go
Raw Normal View History

2022-02-11 15:06:06 +00:00
package main
import (
"fmt"
2022-02-17 12:31:01 +00:00
"log"
"os"
2022-02-18 14:34:33 +00:00
"git.ulra.eu/adro/miniwol/config"
"git.ulra.eu/adro/miniwol/web"
2022-02-17 12:31:01 +00:00
"golang.org/x/crypto/bcrypt"
2022-02-11 15:06:06 +00:00
)
func main() {
2022-02-17 12:31:01 +00:00
if len(os.Args) < 2 {
os.Args = append(os.Args, "")
2022-02-11 15:06:06 +00:00
}
2022-02-17 12:31:01 +00:00
switch os.Args[1] {
case "setpass":
passHash, err := bcrypt.GenerateFromPassword([]byte(os.Args[2]), bcrypt.DefaultCost)
if err != nil {
log.Fatal(err)
2022-02-11 15:06:06 +00:00
}
2022-02-17 12:31:01 +00:00
config.Config.PassHash = string(passHash)
err = config.Save()
if err != nil {
log.Fatal(err)
}
fmt.Println("Successfully set password")
case "web":
fallthrough
case "":
log.Fatal(web.Run())
default:
fmt.Println("Unknown subcommand", os.Args[1])
2022-02-11 15:06:06 +00:00
}
}