add error handling for reading configuration #1
@ -75,7 +75,7 @@ func userData(username, usersonline, ops string) UserInfo {
|
||||
}
|
||||
crdstr := strings.TrimSuffix(string(crd), "\n")
|
||||
filename := "/home/" + username + "/meta-info.toml"
|
||||
_, error := os.Stat(filename)
|
||||
filestat, error := os.Stat(filename)
|
||||
if error != nil {
|
||||
if os.IsNotExist(error) {
|
||||
UserError("user doesn't have a meta-info.toml", username, error)
|
||||
@ -95,6 +95,23 @@ func userData(username, usersonline, ops string) UserInfo {
|
||||
return user
|
||||
}
|
||||
}
|
||||
// Check file size of meta-info.toml. If it's over 100 kB, bail
|
||||
if filestat.Size() > 100_000 {
|
||||
log.Error("user's meta-info.toml is above the 100 kB file size limit", "user", username)
|
||||
user := UserInfo{
|
||||
Name: username,
|
||||
Online: false,
|
||||
Op: false,
|
||||
}
|
||||
user.Created, _ = strconv.Atoi(crdstr)
|
||||
if isonline {
|
||||
user.Online = true
|
||||
}
|
||||
if isop {
|
||||
user.Op = true
|
||||
}
|
||||
return user
|
||||
}
|
||||
viper.SetConfigFile(filename)
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
log.Error("message", "couldn't read a users meta-info.toml file.", "error", log.Any("err", err), "user", username)
|
||||
|
Loading…
Reference in New Issue
Block a user