Diskussion:Ssh knock

Aus UUGRN
Version vom 15. Mai 2014, 18:38 Uhr von 10.253.1.13 (Diskussion) (pre/pre)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

What do you think of this script? (A thousand apologies, not a German-speaker.)

#!/bin/sh

dir=/var/knockdata

num=${0##*[.]}

function badknock { echo b > "$dir/$1"; } # hosts banned until lockfile removed

function ifnoknock { if [[ ! -f "$dir/$1" ]]; then badknock $REMOTE_HOST; fi }

case "$num" in
1)      if [[ -f "$dir/$REMOTE_HOST" ]] #reknock?
        then    if [[ "$(<$dir/$REMOTE_HOST)" = 'g' ]]
                then    echo 1 > "$dir/$REMOTE_HOST" #reknock!
                else    badknock "$REMOTE_HOST"
                fi
        else    echo 1 > "$dir/$REMOTE_HOST"
        fi ;;

2)      ifnoknock "$REMOTE_HOST"

        if [[ "$(<$dir/$REMOTE_HOST)" = '1' ]]
        then    echo 2 > "$dir/$REMOTE_HOST"
        else    badknock "$REMOTE_HOST"
        fi ;;

3)      ifnoknock "$REMOTE_HOST"

        if [[ "$(<$dir/$REMOTE_HOST)" = '2' ]]
        then    echo g > "$dir/$REMOTE_HOST"
        else    badknock "$REMOTE_HOST"
        fi ;;

t)      ifnoknock "$REMOTE_HOST"

        if [[ "$(<$dir/$REMOTE_HOST)" = 'g' ]]
        then    exec /usr/sbin/sshd -i # (https://wiki.uugrn.org/Ssh_knock)
        fi ;;
esac

echo '/*/'