From 1fcdfa4e9bf0941afaa8fb7018246226c597a55c Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:49:36 -0700 Subject: [PATCH] add "ports" command to list jails and their published ports --- usr/local/share/bastille/list.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/usr/local/share/bastille/list.sh b/usr/local/share/bastille/list.sh index ebb28cc4..d2fd2f89 100644 --- a/usr/local/share/bastille/list.sh +++ b/usr/local/share/bastille/list.sh @@ -32,7 +32,7 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille list [-j|-a] [release [-p]|template|(jail|container)|log|limit|(import|export|backup)]" + error_exit "Usage: bastille list [-j|-a] [release [-p]|template|(jail|container)|log|limit|ports|(import|export|backup)]" } if [ "${1}" = help -o "${1}" = "-h" -o "${1}" = "--help" ]; then @@ -202,12 +202,28 @@ list_import(){ ls "${bastille_backupsdir}" | grep -v ".sha256$" } +list_ports(){ + if [ -d "${bastille_jailsdir}" ]; then + JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g") + for _JAIL in ${JAIL_LIST}; do + if [ -f "${bastille_jailsdir}/${_JAIL}/rdr.conf" ]; then + _PORTS="$(cat "${bastille_jailsdir}"/"${_JAIL}"/rdr.conf | awk '{print $1":"$4"//"$2":"$5" -> "$3":"$6}')" + info "[${_JAIL}]:" + echo "${_PORTS}" + fi + done + fi +} + if [ $# -gt 0 ]; then # Handle special-case commands first. case "${1}" in all|-a|--all) list_all ;; + port|ports) + list_ports + ;; release|releases) list_release ;;