Diskussion:Ssh knock: Unterschied zwischen den Versionen
Aus UUGRN
(Simple knock.) |
(kein Unterschied)
|
Version vom 13. Mai 2014, 17:25 Uhr
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 '/*/'