Compare commits

...

2 Commits

Author SHA1 Message Date
vasyahacker 6b29123275 man and readme fixes 2023-05-18 09:45:33 +04:00
vasyahacker f704996613 save/restore session token when users db reloading (if user unlocked);
tracking of when the points.txt file was last modified to detect changes
2023-05-18 08:56:43 +04:00
4 changed files with 40 additions and 11 deletions

View File

@ -128,6 +128,7 @@ For example:
```
./idecctl [-u pointfile] useradd <name> <e-mail> <password>
```
**Attention**: by default, a new user is added blocked, **set 'locked/no' in points.txt to unlock**
By default, pointfile is points.txt
@ -156,7 +157,10 @@ Where options are:
list.txt by default.
-host <string> Host string for node. For ex. http://hugeping.tk.
http://127.0.0.1:8080 by default
-noreg Disable new users registration
-style path Path to /style web-directory (css/images) (default "./style")
-sys "name" Node name. "openidec" by default
-tpl path Path to html templates (default "./tpl")
-u <points> Points file. "points.txt" by default.
-v Be verbose (for tracing)
```
@ -165,10 +169,12 @@ Where options are:
```
./idecctl fetch http://club.syscall.ru
wget http://club.syscall.ru/list.txt # for echo descriptions
./idecd -sys "newnode"
./idecd -sys "newnode" -tpl www/tpl -style www/style
```
And open http://127.0.0.1:8080 in your browser.
**Attention**: by default, a new user is added blocked, **set 'locked/no' in points.txt to unlock**
## Standarts supported
- u/e

View File

@ -875,6 +875,7 @@ type User struct {
}
// User database.
// ModTime: last modification time of points.txt to detect DB changes.
// FileSize - size of points.txt to detect DB changes.
// Names: holds User structure by user name
// ById: holds user name by user id
@ -887,6 +888,7 @@ type UDB struct {
Tokens map[string]string
List []string
Sync sync.RWMutex
ModTime int64
FileSize int64
}
@ -1088,15 +1090,16 @@ func (db *UDB) Edit(u *User) error {
if err := os.Rename(db.Path+".tmp", db.Path); err != nil {
return err
}
db.FileSize = 0 // force to reload
db.ModTime = 0 // force to reload
return nil
}
// Load user information in memory if it is needed (FileSize changed).
// Load user information in memory if it is needed (ModTime or FileSize changed).
// So, it is safe to call it on every request.
func (db *UDB) LoadUsers() error {
db.Sync.Lock()
defer db.Sync.Unlock()
var mtime int64
var fsize int64
file, err := os.Open(db.Path)
if err == nil {
@ -1106,16 +1109,22 @@ func (db *UDB) LoadUsers() error {
Error.Printf("Can not stat %s file: %s", db.Path, err)
return err
}
mtime = info.ModTime().Unix()
fsize = info.Size()
} else if os.IsNotExist(err) {
fsize = 0
mtime = 0
} else {
Error.Printf("Can not open %s file: %s", db.Path, err)
return err
}
if db.FileSize == fsize {
if db.ModTime == mtime && db.FileSize == fsize {
return nil
}
// save old tokens before reload
old_tokens := make(map[string]string)
for otoken, oname := range db.Tokens {
old_tokens[oname] = otoken
}
db.Names = make(map[string]User)
db.Tokens = make(map[string]string)
db.ById = make(map[int32]string)
@ -1137,8 +1146,15 @@ func (db *UDB) LoadUsers() error {
u.Mail = a[2]
u.Secret = a[3]
u.Tags = NewTags(a[4])
//u.Token = a[5]
//db.Tokens[u.Token] = u.Name
//restore token if user onlocked
token, ok := old_tokens[u.Name]
if ok {
locked, _ := u.Tags.Get("locked")
if locked != "" && locked == "no" {
u.Token = token
db.Tokens[token] = u.Name
}
}
db.ById[u.Id] = u.Name
db.Names[u.Name] = u
db.List = append(db.List, u.Name)
@ -1148,6 +1164,7 @@ func (db *UDB) LoadUsers() error {
Error.Printf("Can not read user DB: %s", err)
return errors.New(err.Error())
}
db.ModTime = mtime
db.FileSize = fsize
return nil
}

View File

@ -89,9 +89,12 @@ idecctl [-u pointfile] useradd <name> <e-mail> <password>
By default, pointfile is points.txt
.fi
.TP
.B ATTENTION!
by default, a new user is added blocked, set 'locked/no' in points.txt to unlock
.TP
.B BLACKLIST MSG
idecctl [-u pointfile] useradd <name> <e-mail> <password>
./ii-tool [-db db] blacklist <MsgId>
.nf
Blacklist is just new record with same id but spectial status.

View File

@ -77,10 +77,13 @@ http://127.0.0.1:8080/from/User/rss - From User
.SH EXAMPLES
Fetch db and start node:
.nf
idecctl fetch http://hugeping.tk # get database from remote node
ftp http://hugeping.tk/list.txt # for echo descriptions
idecd -sys "newnode" # run node with name "newnode"
idecctl fetch http://hugeping.tk # get database from remote node
ftp http://hugeping.tk/list.text # for echo descriptions
idecd -sys "newnode" -tpl www/tpl -style www/style # run node with name "newnode"
.fi
.SH
ATTENTION!
by default, a new user is added blocked, set 'locked/no' in points.txt to unlock
.SH SEE ALSO
idecctl(1), openidec(1), idecgmi(1)
.SH AUTHOR