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