feat: support WEBUI_PASSWORD env var with default password

Set default WebUI password to "proxygo" and allow customization via
WEBUI_PASSWORD environment variable, eliminating the need to manually
compute SHA256 hashes and modify source code.
This commit is contained in:
jonasen1988
2026-03-27 19:48:36 +08:00
parent f678e2e016
commit f2c3fbac24
4 changed files with 36 additions and 10 deletions

View File

@@ -1,11 +1,15 @@
package config
import (
"crypto/sha256"
"encoding/json"
"fmt"
"os"
"sync"
)
const DefaultPassword = "proxygo"
func dataDir() string {
if d := os.Getenv("DATA_DIR"); d != "" {
os.MkdirAll(d, 0755)
@@ -63,10 +67,19 @@ var (
cfgMu sync.RWMutex
)
func passwordHash(plain string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(plain)))
}
func DefaultConfig() *Config {
// 优先从环境变量 WEBUI_PASSWORD 读取密码,未设置时使用默认密码
password := os.Getenv("WEBUI_PASSWORD")
if password == "" {
password = DefaultPassword
}
return &Config{
WebUIPort: ":7778",
WebUIPasswordHash: "64c2de42ff93286f5c7108867ffe3167a24f4c1abee648dea7bc7fa1d11e2b21",
WebUIPasswordHash: passwordHash(password),
ProxyPort: ":7777",
DBPath: dataDir() + "proxy.db",
ValidateConcurrency: 300,