feat: add web ui and dynamic private users
This commit is contained in:
@@ -65,7 +65,12 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, ac := range cfg.Accounts {
|
||||
a := &auth.Account{Username: ac.Username, Password: ac.Password, Mask: auth.ParseMask(ac.Default)}
|
||||
admin := ac.Role == "admin" || strings.EqualFold(ac.Username, "admin")
|
||||
mask := auth.ParseMask(ac.Default)
|
||||
if admin && ac.Default == "" {
|
||||
mask = auth.Read | auth.Write | auth.Delete
|
||||
}
|
||||
a := &auth.Account{Username: ac.Username, Password: ac.Password, Mask: mask, Admin: admin}
|
||||
for _, d := range ac.None {
|
||||
a.Rules = append(a.Rules, auth.PathRule{Dir: accountRulePath(d, cfg.Path), Deny: true})
|
||||
}
|
||||
@@ -84,12 +89,41 @@ func main() {
|
||||
mgr.Accounts[ac.Username] = a
|
||||
}
|
||||
}
|
||||
if cfg.UserHome == "" {
|
||||
cfg.UserHome = "users"
|
||||
}
|
||||
multi := storage.NewMulti(cfg.Path)
|
||||
if len(cfg.Path) > 1 {
|
||||
if _, _, ok := multi.FindRoot(cfg.UserHome); !ok {
|
||||
cfg.UserHome = multi.Names[0] + "/" + strings.Trim(cfg.UserHome, "/")
|
||||
}
|
||||
}
|
||||
store := storage.Storage(multi)
|
||||
if len(cfg.Path) == 1 {
|
||||
store = storage.Local{Root: root}
|
||||
}
|
||||
srv := &api.Server{Store: store, Auth: mgr, Sessions: map[string]*auth.Account{}, SessionExpiry: map[string]time.Time{}, SessionTimeout: cfg.SessionTimeout, WebDAVRoot: root, Allow: cfg.Allow, MultiRoot: len(cfg.Path) > 1, RemoveMode: cfg.FileRemove, ImagePreview: cfg.ImagePreview, FolderDownload: cfg.FolderDownload, HTMLTitle: cfg.HTMLTitle, HTMLNotice: cfg.HTMLNotice, Log: opslog.New(cfg.Log)}
|
||||
userFile := cfg.UserFile
|
||||
if userFile == "" {
|
||||
if dir, e := os.UserConfigDir(); e == nil {
|
||||
userFile = filepath.Join(dir, "chfs-ng", "users.json")
|
||||
} else {
|
||||
userFile = filepath.Join(root, ".chfs-users.json")
|
||||
}
|
||||
} else if !filepath.IsAbs(userFile) {
|
||||
userFile = filepath.Join(root, userFile)
|
||||
}
|
||||
users := &auth.UserStore{Path: userFile}
|
||||
if err := users.Load(mgr, cfg.UserHome); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, a := range mgr.Accounts {
|
||||
if a.Home != "" {
|
||||
if err := store.MkdirAll(a.Home); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
srv := &api.Server{Store: store, Auth: mgr, Sessions: map[string]*auth.Account{}, SessionExpiry: map[string]time.Time{}, SessionTimeout: cfg.SessionTimeout, WebDAVRoot: root, Allow: cfg.Allow, MultiRoot: len(cfg.Path) > 1, RemoveMode: cfg.FileRemove, ImagePreview: cfg.ImagePreview, FolderDownload: cfg.FolderDownload, HTMLTitle: cfg.HTMLTitle, HTMLNotice: cfg.HTMLNotice, Log: opslog.New(cfg.Log), UserStore: users, UserHome: cfg.UserHome}
|
||||
addr := ":" + itoa(cfg.Port)
|
||||
log.Printf("chfs-ng listening on %s root=%s removeMode=%d", addr, filepath.Clean(root), cfg.FileRemove)
|
||||
if cfg.SSLCert != "" && cfg.SSLKey != "" {
|
||||
|
||||
Reference in New Issue
Block a user