#!/usr/bin/env bash
# filename: knock-install.sh


export logfile="/var/log/knockd.log"
export seq_timout=30
export cmd_timout=10


function install-for-debian() {
    apt-get -y install knockd iptables-persistent
}


function install-for-centos() {
    yum -y install http://li.nux.ro/download/nux/misc/el7/x86_64/knock-server-0.7-1.el7.nux.x86_64.rpm
}

function knock_conf() {
    \mv /etc/knock.conf /etc/knock.conf@origin

    cat >/etc/knock.conf <<EOF
[options]
        logfile = /var/log/knockd.log

[openSSH]
        sequence = 1989:tcp, 2016:tcp
        seq_timeout = 30
        tcpflags = syn
        start_command = /sbin/iptables -I INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
        cmd_timeout = 10
        stop_command = /sbin/iptables -D INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
EOF
}
