diff --git a/data/hooks/conf_regen/52-fail2ban b/data/hooks/conf_regen/52-fail2ban index 3cb499db7..e696df6c8 100755 --- a/data/hooks/conf_regen/52-fail2ban +++ b/data/hooks/conf_regen/52-fail2ban @@ -2,6 +2,8 @@ set -e +. /usr/share/yunohost/helpers + do_pre_regen() { pending_dir=$1 @@ -13,7 +15,9 @@ do_pre_regen() { cp yunohost.conf "${fail2ban_dir}/filter.d/yunohost.conf" cp jail.conf "${fail2ban_dir}/jail.conf" - cp yunohost-jails.conf "${fail2ban_dir}/jail.d/" + + export ssh_port="$(yunohost settings get 'security.ssh.port')" + ynh_render_template "yunohost-jails.conf" "${fail2ban_dir}/jail.d/yunohost-jails.conf" } do_post_regen() { diff --git a/data/templates/fail2ban/yunohost-jails.conf b/data/templates/fail2ban/yunohost-jails.conf index f3aea7fb1..1cf1a1966 100644 --- a/data/templates/fail2ban/yunohost-jails.conf +++ b/data/templates/fail2ban/yunohost-jails.conf @@ -1,4 +1,5 @@ [sshd] +port = {{ssh_port}} enabled = true [nginx-http-auth] diff --git a/src/yunohost/settings.py b/src/yunohost/settings.py index f44178f07..dd43c4787 100644 --- a/src/yunohost/settings.py +++ b/src/yunohost/settings.py @@ -387,13 +387,18 @@ def reconfigure_nginx(setting_name, old_value, new_value): regen_conf(names=["nginx"]) -@post_change_hook("security.ssh.port") @post_change_hook("security.ssh.compatibility") def reconfigure_ssh(setting_name, old_value, new_value): if old_value != new_value: regen_conf(names=["ssh"]) +@post_change_hook("security.ssh.port") +def reconfigure_ssh_and_fail2ban(setting_name, old_value, new_value): + if old_value != new_value: + regen_conf(names=["ssh", "fail2ban"]) + + @post_change_hook("smtp.allow_ipv6") @post_change_hook("smtp.relay.host") @post_change_hook("smtp.relay.port")