Go:Add build pipeline for go server and fix web login bug

This commit is contained in:
yuanyuanxiang
2026-05-27 08:47:21 +02:00
parent 620aaf6827
commit 268a427172
4 changed files with 160 additions and 15 deletions

View File

@@ -668,6 +668,15 @@ func main() {
log := logger.New(logCfg)
// Track env vars where we fell back to a built-in default. Printed once
// at the end of startup so the operator sees what's in effect — vars the
// operator explicitly set are NOT listed (they already know their value).
type defaultedEnv struct{ name, value string }
var defaultsUsed []defaultedEnv
rememberDefault := func(name, value string) {
defaultsUsed = append(defaultsUsed, defaultedEnv{name, value})
}
// Create auth config
authCfg := auth.DefaultConfig()
// PwdHash can be set from environment or config file
@@ -675,6 +684,7 @@ func main() {
if authCfg.PwdHash == "" {
// Default placeholder - should be configured in production
authCfg.PwdHash = "61f04dd637a74ee34493fc1025de2c131022536da751c29e3ff4e9024d8eec43"
rememberDefault("YAMA_PWDHASH", authCfg.PwdHash)
}
authCfg.SuperPass = os.Getenv("YAMA_PWD")
@@ -721,19 +731,23 @@ func main() {
// Web user authenticator. Bootstrap admin from env var YAMA_WEB_ADMIN_PASS;
// if unset, fall back to YAMA_PWD (same secret the TCP authorization uses)
// so a single password env var is enough to bring up the whole stack.
// If neither is set, no admin is registered and login will always fail —
// the user must define a password before browsers can log in.
// If neither is set we use a hard-coded "admin" default so the web UI is
// usable out of the box — the startup banner surfaces this so operators
// know to override it in any non-dev deployment.
const defaultWebAdminPass = "admin"
webAuth := wsauth.New()
adminPass := os.Getenv("YAMA_WEB_ADMIN_PASS")
if adminPass == "" {
adminPass = os.Getenv("YAMA_PWD")
}
if adminPass != "" {
webAuth.AddAdminFromPlainPassword("admin", adminPass)
log.Info("Web admin user configured")
} else {
log.Warn("Neither YAMA_WEB_ADMIN_PASS nor YAMA_PWD is set; web login will be unavailable")
usingDefaultWebPass := false
if adminPass == "" {
adminPass = defaultWebAdminPass
rememberDefault("YAMA_WEB_ADMIN_PASS", defaultWebAdminPass)
usingDefaultWebPass = true
}
webAuth.AddAdminFromPlainPassword("admin", adminPass)
log.Info("Web admin user configured")
// Persistent users live in users.json next to the binary's working dir
// — same default the C++ WebService uses (m_ConfigDir + "users.json").
@@ -741,6 +755,7 @@ func main() {
usersFile := os.Getenv("YAMA_USERS_FILE")
if usersFile == "" {
usersFile = "users.json"
rememberDefault("YAMA_USERS_FILE", usersFile)
}
if err := webAuth.SetUsersFile(usersFile); err != nil {
log.Warn("Failed to load %s: %v (continuing with admin only)", usersFile, err)
@@ -849,10 +864,21 @@ func main() {
fmt.Printf("Server started on port(s): %v\n", ports)
if *httpPort != 0 {
fmt.Printf("Web UI on http://localhost:%d/\n", *httpPort)
if usingDefaultWebPass {
fmt.Printf(" Default login: admin / %s (set YAMA_WEB_ADMIN_PASS to override)\n",
defaultWebAdminPass)
}
}
if licenseHTTP != nil {
fmt.Printf("License Server on http://%s/license/{sign,heartbeat}\n", licAddr)
}
if len(defaultsUsed) > 0 {
fmt.Println()
fmt.Println("[!] Using built-in defaults (set the env var to override):")
for _, d := range defaultsUsed {
fmt.Printf(" %s = %s\n", d.name, d.value)
}
}
fmt.Println("Logs are written to: logs/server.log")
fmt.Println("Press Ctrl+C to stop...")