#!/bin/bash
# Copyright (c) 1995-2002 SUSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# Author: Stanislav Brabec, feedback to http://www.suse.de/feedback
#
### BEGIN INIT INFO
# Provides:          blocksshd
# Required-Start:    $network $remote_fs $local_fs 
# Required-Stop:     $null
# Default-Start:     3 5
# Default-Stop:
# Short-Description: blocksshd
# Description:       BlockSSHD is a Perl script based on BruteForceBlocker v1.2.3 that dynamically adds IPTables rules for Linux and pf firewall rules for BSD that block SSH brute force attacks.
### END INIT INFO

BLOCKSSHD_BIN=/usr/bin/blocksshd
test -x $BLOCKSSHD_BIN || { echo "$BLOCKSSHD_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0; else exit 5; fi; }
 
BLOCKSSHD_SYSCONFIG=/etc/sysconfig/blocksshd
test -e $BLOCKSSHD_SYSCONFIG || { echo "BLOCKSSHD_SYSCONFIG not installed";
        if [ "$1" = "stop" ]; then exit 0; else exit 5; fi; }

. $BLOCKSSHD_SYSCONFIG

. /etc/rc.status
rc_reset

case "$1" in
    start)
        echo -n "Starting blocksshd daemon"
        startproc $BLOCKSSHD_BIN --start
	$STARTCMD 
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down blocksshd daemon"
        killproc -TERM $BLOCKSSHD_BIN
	$STOPCMD
        rc_status -v
        ;;
    try-restart)
        $0 status >/dev/null &&  $0 restart
        rc_status
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    force-reload)
        echo -n "Reload service blocksshd"
        checkproc $BLOCKSSHD_BIN
        rc_status -v
        ;;
    reload)
        rc_status -v
        ;;
    status)
        echo -n "Checking for blocksshd: "
        checkproc $BLOCKSSHD_BIN
        rc_status -v
        ;;
    probe)
        ;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|\
restart|force-reload|reload|probe}"
        exit 1
        ;;
esac
rc_exit

