From f37252e8ba10ea9c58a397ae4840e7dc6d01d614 Mon Sep 17 00:00:00 2001 From: Arya Kiran Date: Mon, 23 Jan 2023 20:23:05 +0530 Subject: [PATCH] add user creation date to /users --- pages/users.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pages/users.go b/pages/users.go index 6280fcc..590a6a7 100644 --- a/pages/users.go +++ b/pages/users.go @@ -26,6 +26,7 @@ type Userinfo struct { Desc string `json:"desc"` Online bool `json:"online"` Op bool `json:"op"` + Created string `json:"created"` Email string `json:"email"` Matrix string `json:"matrix"` Fediverse string `json:"fediverse"` @@ -35,19 +36,29 @@ type Userinfo struct { } func userdata(username, usersonline, ops string) Userinfo { - filename := "/home/" + username + "/meta-info.env" - _, error := os.Stat(filename) regex := "(^| )" + username + "($| )" isonline, err := regexp.MatchString(string(regex), string(usersonline)) - isop, err := regexp.MatchString(string(regex), string(ops)) if err != nil { 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 os.IsNotExist(error) { log.Error(username + " does not have a meta-info.env") var user Userinfo user.Name = username + user.Created = strings.TrimSuffix(crdstr, "\n") if isonline == true { user.Online = true } else { @@ -65,6 +76,7 @@ func userdata(username, usersonline, ops string) Userinfo { viper.ReadInConfig() var user Userinfo user.Name = username + user.Created = strings.TrimSuffix(crdstr, "\n") user.FullName = viper.GetString("FULL_NAME") user.Capsule = viper.GetString("GEMINI_CAPSULE") user.Website = viper.GetString("WEBSITE")