forked from ProjectSegfault/publapi
add /users json field for op
This commit is contained in:
parent
0834cb4ae2
commit
381c6e94ba
@ -25,6 +25,7 @@ type Userinfo struct {
|
|||||||
FullName string `json:"fullName"`
|
FullName string `json:"fullName"`
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
Online bool `json:"online"`
|
Online bool `json:"online"`
|
||||||
|
Op bool `json:"op"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Matrix string `json:"matrix"`
|
Matrix string `json:"matrix"`
|
||||||
Fediverse string `json:"fediverse"`
|
Fediverse string `json:"fediverse"`
|
||||||
@ -33,11 +34,12 @@ type Userinfo struct {
|
|||||||
Loc string `json:"loc"`
|
Loc string `json:"loc"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func userdata(username, usersonline string) Userinfo {
|
func userdata(username, usersonline, ops string) Userinfo {
|
||||||
filename := "/home/" + username + "/meta-info.env"
|
filename := "/home/" + username + "/meta-info.env"
|
||||||
_, error := os.Stat(filename)
|
_, 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)
|
||||||
}
|
}
|
||||||
@ -51,6 +53,11 @@ func userdata(username, usersonline string) Userinfo {
|
|||||||
} else {
|
} else {
|
||||||
user.Online = false
|
user.Online = false
|
||||||
}
|
}
|
||||||
|
if isop == true {
|
||||||
|
user.Op = true
|
||||||
|
} else {
|
||||||
|
user.Op = false
|
||||||
|
}
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,6 +73,11 @@ func userdata(username, usersonline string) Userinfo {
|
|||||||
user.Matrix = viper.GetString("MATRIX")
|
user.Matrix = viper.GetString("MATRIX")
|
||||||
user.Fediverse = viper.GetString("FEDIVERSE")
|
user.Fediverse = viper.GetString("FEDIVERSE")
|
||||||
user.Loc = viper.GetString("LOCATION")
|
user.Loc = viper.GetString("LOCATION")
|
||||||
|
if isop == true {
|
||||||
|
user.Op = true
|
||||||
|
} else {
|
||||||
|
user.Op = false
|
||||||
|
}
|
||||||
if isonline == true {
|
if isonline == true {
|
||||||
user.Online = true
|
user.Online = true
|
||||||
} else {
|
} else {
|
||||||
@ -98,6 +110,14 @@ func UsersPage(c *fiber.Ctx) error {
|
|||||||
} else {
|
} else {
|
||||||
output = 1
|
output = 1
|
||||||
}
|
}
|
||||||
|
// Get OPs
|
||||||
|
ops, opserr := exec.Command("bash", "-c", "/usr/bin/members sudo").Output()
|
||||||
|
if opserr != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return c.SendStatus(fiber.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
opstr := string(ops)
|
||||||
|
// Get all users
|
||||||
users, err2 := exec.Command("bash", "-c", "/usr/bin/ls /home").Output()
|
users, err2 := exec.Command("bash", "-c", "/usr/bin/ls /home").Output()
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
log.Error(err2)
|
log.Error(err2)
|
||||||
@ -106,10 +126,11 @@ func UsersPage(c *fiber.Ctx) error {
|
|||||||
userstr := string(users)
|
userstr := string(users)
|
||||||
userstr2 := strings.TrimSuffix(userstr, "\n")
|
userstr2 := strings.TrimSuffix(userstr, "\n")
|
||||||
usersarr := strings.Split(userstr2, "\n")
|
usersarr := strings.Split(userstr2, "\n")
|
||||||
|
// Fill user info
|
||||||
var userinfostruct []Userinfo
|
var userinfostruct []Userinfo
|
||||||
for i := 0; i < len(usersarr); i++ {
|
for i := 0; i < len(usersarr); i++ {
|
||||||
uname := string(usersarr[i])
|
uname := string(usersarr[i])
|
||||||
userinfostruct = append(userinfostruct, userdata(uname, strings.TrimSuffix(usersonlinededup, "\n")))
|
userinfostruct = append(userinfostruct, userdata(uname, strings.TrimSuffix(usersonlinededup, "\n"), strings.TrimSuffix(opstr, "\n")))
|
||||||
}
|
}
|
||||||
data := Userstruct{
|
data := Userstruct{
|
||||||
Status: c.Response().StatusCode(),
|
Status: c.Response().StatusCode(),
|
||||||
|
Loading…
Reference in New Issue
Block a user