feat: add web ui and dynamic private users

This commit is contained in:
OpenClaw Agent
2026-09-22 01:14:15 +08:00
parent 035c3600bf
commit 77572e610b
7 changed files with 418 additions and 7 deletions
+11 -1
View File
@@ -1,6 +1,8 @@
package auth
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"strings"
"time"
@@ -43,8 +45,11 @@ type PathRule struct {
}
type Account struct {
Username, Password string
PasswordHash string
Mask PermMask
Rules []PathRule
Home string
Admin bool
}
type Manager struct {
Accounts map[string]*Account
@@ -80,7 +85,7 @@ func ParseRules(values []string) (*Manager, error) {
}
func (m *Manager) Authenticate(user, pwd string) *Account {
if a, ok := m.Accounts[user]; ok && a.Password == pwd {
if a, ok := m.Accounts[user]; ok && (a.Password == pwd || a.PasswordHash == PasswordHash(pwd)) {
return a
}
if user == "" && pwd == "" {
@@ -88,6 +93,11 @@ func (m *Manager) Authenticate(user, pwd string) *Account {
}
return nil
}
func PasswordHash(password string) string {
h := sha256.Sum256([]byte(password))
return hex.EncodeToString(h[:])
}
func (a *Account) MaskFor(path string) PermMask {
return a.maskFor(path, false)
}