add user creation date to /users
This commit is contained in:
parent
381c6e94ba
commit
f37252e8ba
@ -26,6 +26,7 @@ type Userinfo struct {
|
|||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
Online bool `json:"online"`
|
Online bool `json:"online"`
|
||||||
Op bool `json:"op"`
|
Op bool `json:"op"`
|
||||||
|
Created string `json:"created"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Matrix string `json:"matrix"`
|
Matrix string `json:"matrix"`
|
||||||
Fediverse string `json:"fediverse"`
|
Fediverse string `json:"fediverse"`
|
||||||
@ -35,19 +36,29 @@ type Userinfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func userdata(username, usersonline, ops string) Userinfo {
|
func userdata(username, usersonline, ops string) Userinfo {
|
||||||
filename := "/home/" + username + "/meta-info.env"
|
|
||||||
_, error := os.Stat(filename)
|
|
||||||
regex := "(^| )" + username + "($| )"
|
regex := "(^| )" + username + "($| )"
|
||||||
isonline, err := regexp.MatchString(string(regex), string(usersonline))
|
isonline, err := regexp.MatchString(string(regex), string(usersonline))
|
||||||
isop, err := regexp.MatchString(string(regex), string(ops))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
isop, operr := regexp.MatchString(string(regex), string(ops))
|
||||||
|
if operr != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
cmd := "/usr/bin/stat -c %W /home/" + username
|
||||||
|
crd, crerr := exec.Command("bash", "-c", cmd).Output()
|
||||||
|
if crerr != nil {
|
||||||
|
log.Error(crerr)
|
||||||
|
}
|
||||||
|
crdstr := string(crd)
|
||||||
|
filename := "/home/" + username + "/meta-info.env"
|
||||||
|
_, error := os.Stat(filename)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
if os.IsNotExist(error) {
|
if os.IsNotExist(error) {
|
||||||
log.Error(username + " does not have a meta-info.env")
|
log.Error(username + " does not have a meta-info.env")
|
||||||
var user Userinfo
|
var user Userinfo
|
||||||
user.Name = username
|
user.Name = username
|
||||||
|
user.Created = strings.TrimSuffix(crdstr, "\n")
|
||||||
if isonline == true {
|
if isonline == true {
|
||||||
user.Online = true
|
user.Online = true
|
||||||
} else {
|
} else {
|
||||||
@ -65,6 +76,7 @@ func userdata(username, usersonline, ops string) Userinfo {
|
|||||||
viper.ReadInConfig()
|
viper.ReadInConfig()
|
||||||
var user Userinfo
|
var user Userinfo
|
||||||
user.Name = username
|
user.Name = username
|
||||||
|
user.Created = strings.TrimSuffix(crdstr, "\n")
|
||||||
user.FullName = viper.GetString("FULL_NAME")
|
user.FullName = viper.GetString("FULL_NAME")
|
||||||
user.Capsule = viper.GetString("GEMINI_CAPSULE")
|
user.Capsule = viper.GetString("GEMINI_CAPSULE")
|
||||||
user.Website = viper.GetString("WEBSITE")
|
user.Website = viper.GetString("WEBSITE")
|
||||||
|
Loading…
Reference in New Issue
Block a user