59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"forge.lightcrystal.systems/nilix/felt/register"
|
|
"forge.lightcrystal.systems/nilix/quartzgun/auth"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func ProcessCmd(args []string, userStore auth.UserStore, crypto register.SymmetricCrypto) bool {
|
|
if len(args) == 1 {
|
|
return false
|
|
}
|
|
switch args[1] {
|
|
case "invite":
|
|
now := time.Now().UnixMicro()
|
|
strNow := strconv.FormatInt(now, 10)
|
|
self, err := crypto.Encrypt(strNow)
|
|
if err == nil {
|
|
fmt.Print("This is the registration key: ")
|
|
fmt.Println(self)
|
|
} else {
|
|
fmt.Printf("%v\n", err)
|
|
}
|
|
case "adduser":
|
|
if len(args) < 4 {
|
|
return help(args[0])
|
|
}
|
|
userStore.AddUser(args[2], args[3])
|
|
case "rmuser":
|
|
if len(args) < 3 {
|
|
return help(args[0])
|
|
}
|
|
userStore.DeleteUser(args[2])
|
|
case "passwd":
|
|
if len(args) < 5 {
|
|
return help(args[0])
|
|
}
|
|
userStore.ChangePassword(args[2], args[3], args[4])
|
|
default:
|
|
return help(args[0])
|
|
}
|
|
return true
|
|
}
|
|
|
|
func help(prog string) bool {
|
|
fmt.Println("usage: " + prog + " [invite | adduser NAME PW | rmuser NAME | passwd NAME OLDPW NEWPW]")
|
|
fmt.Println(" commands:")
|
|
fmt.Println(" invite: generates a token to be appended to the /register/ endpoint to create an admin account")
|
|
fmt.Println(" adduser: adds a new admin user to the user.db")
|
|
fmt.Println(" rmuser: removes named user from the user.db")
|
|
fmt.Println(" passwd: change a user's password")
|
|
fmt.Println("")
|
|
fmt.Println(" adduser, rmuser, and passwd should be run while the server is offline")
|
|
fmt.Println(" This is because external changes to the user.db will be overwritten if the server is running")
|
|
fmt.Println(" Codes generated via the invite command are good for 15 minutes")
|
|
return true
|
|
}
|