Skip to content

Commit 1e22c49

Browse files
authored
fix/use v-list-sys-sshd-port to check custom ssh port#3921 (hestiacp#3922)
1 parent 554b2ca commit 1e22c49

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

bin/v-add-firewall-chain

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ heal_iptables_links
5656

5757
# Checking known chains
5858
case $chain in
59-
SSH) # Get ssh port by reading ssh config file.
60-
sshport=$(grep '^Port ' /etc/ssh/sshd_config | head -1 | cut -d ' ' -f 2)
59+
SSH) # Get ssh port (or ports) using v-list-sys-sshd-port.
60+
sshport="$($BIN/v-list-sys-sshd-port plain | sed ':a;N;$!ba;s/\n/,/g')"
6161
if [ -z "$sshport" ]; then
6262
sshport=22
6363
fi

bin/v-update-firewall

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ if [ $? -ne 0 ]; then
6060
conntrack_ftp='no'
6161
fi
6262

63-
# Checking custom OpenSSH port
64-
sshport=$(grep '^Port ' /etc/ssh/sshd_config | head -1 | cut -d ' ' -f 2)
65-
if [[ "$sshport" =~ ^[0-9]+$ ]] && [ "$sshport" -ne "22" ]; then
66-
sed -i "s/PORT='22'/PORT=\'$sshport\'/" $rules
63+
# Checking custom OpenSSH port (or ports)
64+
sshport="$($BIN/v-list-sys-sshd-port plain | sed ':a;N;$!ba;s/\n/,/g')"
65+
if echo "$sshport" | grep -E '^[0-9]+(,[0-9]+)*$' &>/dev/null; then
66+
sed -i -E "s/(PORT=')[0-9]+(,[0-9]+)*('.*COMMENT='SSH')/\1$sshport\3/" $rules
67+
sed -i "/CHAIN='SSH'/c\CHAIN='SSH' PORT='$sshport' PROTOCOL='TCP'" "$HESTIA/data/firewall/chains.conf"
6768
fi
6869

6970
# Load ipset lists before adding Hestia iptables rules

0 commit comments

Comments
 (0)