Use getJailFromArray so we can handle same name jails

This commit is contained in:
yo 2022-07-10 14:17:12 +02:00
parent e13437b79e
commit 9b90f9c812

View File

@ -10,13 +10,18 @@ import (
func GetJailProperties(args []string) {
var props []string
var jail Jail
var jail *Jail
var err error
if len(args) > 0 {
for i, a := range args {
// Last arg is the jail name
if i == len(args)-1 {
jail.Name = a
jail, err = getJailFromArray(a, gJails)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
} else {
props = append(props, a)
}
@ -31,12 +36,12 @@ func GetJailProperties(args []string) {
if isStringInArray(props, "all") {
var result []string
result = getStructFieldNames(jail, result, "")
result = getStructFieldNames(*jail, result, "")
props = result
}
for _, p := range props {
v, err := getJailProperty(&jail, p)
v, err := getJailProperty(jail, p)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
@ -47,9 +52,7 @@ func GetJailProperties(args []string) {
}
func getJailProperty(jail *Jail, propName string) (string, error) {
for i, j := range gJails {
if j.Name == jail.Name {
val, _, err := getStructFieldValue(&gJails[i], propName)
val, _, err := getStructFieldValue(jail, propName)
if err != nil {
return "", err
}
@ -64,10 +67,8 @@ func getJailProperty(jail *Jail, propName string) (string, error) {
default:
return "", errors.New(fmt.Sprintf("Error: Unknown type for property %s: %s\n", propName, val.Kind()))
}
}
}
return "", errors.New(fmt.Sprintf("Jail not found: %s", jail.Name))
return "", errors.New("Unknown error in getJailProperty")
}
func SetJailProperties(args []string) {