2022-05-31 05:38:51 +00:00
|
|
|
package archetype
|
2022-05-29 04:45:44 +00:00
|
|
|
|
|
|
|
import (
|
2022-05-29 06:26:36 +00:00
|
|
|
"fmt"
|
2023-01-31 04:23:56 +00:00
|
|
|
"hacklab.nilfm.cc/quartzgun/auth"
|
2022-05-29 06:26:36 +00:00
|
|
|
"strings"
|
2022-05-29 04:45:44 +00:00
|
|
|
)
|
|
|
|
|
2022-05-31 05:38:51 +00:00
|
|
|
func ProcessCmd(args []string, userStore auth.UserStore, cfg *Config) bool {
|
2022-05-29 06:26:36 +00:00
|
|
|
if len(args) == 1 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
switch args[1] {
|
|
|
|
case "adduser":
|
|
|
|
if len(args) < 4 {
|
|
|
|
return help()
|
|
|
|
}
|
|
|
|
userStore.AddUser(args[2], args[3])
|
|
|
|
case "rmuser":
|
|
|
|
if len(args) < 3 {
|
|
|
|
return help()
|
|
|
|
}
|
|
|
|
userStore.DeleteUser(args[2])
|
|
|
|
case "passwd":
|
|
|
|
if len(args) < 5 {
|
|
|
|
return help()
|
|
|
|
}
|
|
|
|
userStore.ChangePassword(args[2], args[3], args[4])
|
|
|
|
case "configure":
|
|
|
|
fmt.Printf("configuring\n")
|
|
|
|
for _, token := range args[2:] {
|
|
|
|
kvp := strings.Split(token, "=")
|
|
|
|
k := kvp[0]
|
|
|
|
v := kvp[1]
|
|
|
|
fmt.Printf("%s = %s\n", k, v)
|
|
|
|
switch k {
|
|
|
|
case "adapter":
|
2022-05-31 05:38:51 +00:00
|
|
|
cfg.SetAdapter(v)
|
2022-05-29 06:26:36 +00:00
|
|
|
case "root":
|
|
|
|
cfg.Root = v
|
|
|
|
case "assetRoot":
|
|
|
|
cfg.AssetRoot = v
|
|
|
|
case "staticRoot":
|
|
|
|
cfg.StaticRoot = v
|
|
|
|
case "plugins":
|
|
|
|
// handle plugins later
|
|
|
|
default:
|
|
|
|
panic("unknown configuration option: " + v)
|
|
|
|
}
|
|
|
|
}
|
2022-05-31 05:38:51 +00:00
|
|
|
cfg.Write()
|
2022-05-29 06:26:36 +00:00
|
|
|
default:
|
|
|
|
help()
|
|
|
|
}
|
|
|
|
return true
|
2022-05-29 04:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func help() bool {
|
2022-05-29 06:26:36 +00:00
|
|
|
return true
|
2022-05-29 04:45:44 +00:00
|
|
|
}
|