#!/bin/bash

# author : Nicolas Chipaux <aegiap@gandi.net> for GANDI
# all rights reserved.

[ -f /etc/gandi/plugins-lib ] && . /etc/gandi/plugins-lib || exit 1
load_config

# In case of deb based distribution, we create ssh key
if is_deb; then
    # We create ssh host key if not present.
    if [ -z "$(find /etc/ssh/ -name 'ssh_host_*_key' -print -quit)" ]; then
        LC_ALL=C LANG=C /usr/sbin/dpkg-reconfigure openssh-server -f noninteractive -p critical
    fi
fi

if [ $CONFIG_SSHD -eq 1 ]; then
    LC_ALL=C LANG=C perl -pi -e 's/^#?(PermitRootLogin ).*$/\1 without-password/ ; s/^#?(PermitEmptyPasswords ).*$/\1 no/ ; s/^#?(Compression ).*$/\1 delayed/' \
    /etc/ssh/sshd_config
    if ! grep -q '^ListenAddress[ ]*::' /etc/ssh/sshd_config; then
        echo -e "\nListenAddress ::\nListenAddress 0.0.0.0" >> /etc/ssh/sshd_config
    fi
fi

exit 0

#EOF
