Add command "list properties" so we can get all internal properties to sort, filter, or set jail properties

This commit is contained in:
yo
2022-04-02 15:40:04 +02:00
parent 8d18bfe55d
commit f1c4fd960d
2 changed files with 49 additions and 2 deletions

View File

@ -296,6 +296,42 @@ func displayStructFields(jails []Jail, valsToDisplay []string) {
fmt.Printf("\n")
}
/*
* Display struct attributes name for a given struct.
* Recurse into struct attributes of type struct
* Used to show user jail properties
*/
func getStructFieldNames(parentStruct interface{}, result []string, prefix string) []string {
v := reflect.ValueOf(parentStruct)
for i := 0 ; i < v.NumField() ; i++ {
if v.Type().Field(i).Type.Kind() == reflect.Struct {
result = getStructFieldNames(v.Field(i).Interface(), result, v.Type().Field(i).Name)
} else {
if len(prefix) > 0 {
result = append(result, fmt.Sprintf("%s.%s", prefix, v.Type().Field(i).Name))
} else {
result = append(result, v.Type().Field(i).Name)
}
}
}
return result
}
func ListJailsProps(args []string) {
var conf Jail
var jailconf JailConfig
var result []string
conf.Config = jailconf
result = getStructFieldNames(conf, result, "")
for _, f := range result {
fmt.Printf("%s\n", f)
}
}
/* Get Jails from datastores. Store config and running metadata into gJails global var */
func ListJails(args []string, display bool) {