2019-01-04 16:38:20 +01:00
|
|
|
#!/bin/sh
|
2019-01-07 14:47:05 +01:00
|
|
|
#
|
|
|
|
# Set or get ssh port of <jailname>
|
|
|
|
# Usage: port <jailname> [<port>|auto]
|
|
|
|
#
|
2019-01-04 16:38:20 +01:00
|
|
|
|
2020-04-01 11:23:35 +02:00
|
|
|
# shellcheck source=./config
|
2020-04-02 00:31:57 +02:00
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
2019-01-04 16:38:20 +01:00
|
|
|
|
|
|
|
jail="${1:-}"
|
|
|
|
port="${2:-}"
|
2019-01-07 14:47:05 +01:00
|
|
|
if [ ! -n "${jail}" ]; then
|
|
|
|
"${LIBDIR}/bkctld-help" && exit 1
|
|
|
|
fi
|
2019-01-07 16:41:29 +01:00
|
|
|
[ -d "${JAILDIR}/${jail}" ] || error "${jail} : inexistant jail'"
|
2019-01-04 16:38:20 +01:00
|
|
|
|
|
|
|
if [ -z "${port}" ]; then
|
|
|
|
grep -E "Port [0-9]+" "${JAILDIR}/${jail}/${SSHD_CONFIG}"|grep -oE "[0-9]+"
|
|
|
|
else
|
|
|
|
if [ "${port}" = "auto" ]; then
|
|
|
|
port=$(grep -h Port "${JAILDIR}"/*/"${SSHD_CONFIG}" 2>/dev/null | grep -Eo "[0-9]+" | sort -n | tail -1)
|
|
|
|
port=$((port+1))
|
|
|
|
[ "${port}" -le 1 ] && port=2222
|
|
|
|
fi
|
|
|
|
sed -i "s/^Port .*/Port ${port}/" "${JAILDIR}/$jail/${SSHD_CONFIG}"
|
|
|
|
notice "${jail} : update port => ${port}"
|
2020-02-05 14:58:15 +01:00
|
|
|
"${LIBDIR}/bkctld-reload" "${jail}"
|
2019-01-04 16:55:56 +01:00
|
|
|
"${LIBDIR}/bkctld-firewall" "${jail}"
|
2019-01-04 16:38:20 +01:00
|
|
|
fi
|