wok view dropbear/stuff/init.d/dropbear @ rev 20257

Add giflossy
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Mar 13 23:27:32 2018 +0100 (2018-03-13)
parents 367fbda7855b
children 9096d6788292
line source
1 #!/bin/sh
2 # /etc/init.d/dropbear : Start, stop and restart SSH server on SliTaz, at
3 # boot time or with the command line.
4 #
5 # To start SSH server at boot time, just put dropbear in the $RUN_DAEMONS
6 # variable of /etc/rcS.conf and configure options with /etc/daemons.conf
7 #
8 . /etc/init.d/rc.functions
9 . /etc/daemons.conf
11 NAME=Dropbear
12 DESC="$(_ '%s server' SSH)"
13 DAEMON=/usr/sbin/dropbear
14 OPTIONS=$DROPBEAR_OPTIONS
15 PIDFILE=/var/run/dropbear.pid
17 case "$1" in
18 start)
19 # We need rsa and dss host key file to start dropbear.
20 for type in rsa dss ecdsa ; do
21 [ -s /etc/dropbear/dropbear_${type}_host_key ] && continue
22 action 'Generating Dropbear %s key... ' $type
23 # Need to delete key before creating it.
24 rm -f /etc/dropbear/dropbear_${type}_host_key
25 dropbearkey -t $type -f /etc/dropbear/dropbear_${type}_host_key >/dev/null 2>&1
26 status
27 done
28 if active_pidfile $PIDFILE dropbear ; then
29 _ '%s is already running.' $NAME
30 exit 1
31 fi
32 if [ -n "$(which iptables)" ] && ! iptables -L | grep 'tcp dpt:ssh ' ; then
33 tcp22new='iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent'
34 $tcp22new --set --name DEFAULT --rsource
35 limit='--seconds 300 --hitcount 5 --name DEFAULT --rsource'
36 $tcp22new --update $limit -j LOG --log-prefix "SSH-Bruteforce : "
37 $tcp22new --update $limit -j DROP
38 fi
39 action 'Starting %s: %s...' "$DESC" $NAME
40 $DAEMON $OPTIONS
41 status
42 ;;
43 stop)
44 if ! active_pidfile $PIDFILE dropbear ; then
45 _ '%s is not running.' $NAME
46 exit 1
47 fi
48 action 'Stopping %s: %s...' "$DESC" $NAME
49 kill $(cat $PIDFILE)
50 status
51 ;;
52 restart)
53 if ! active_pidfile $PIDFILE dropbear ; then
54 _ '%s is not running.' $NAME
55 exit 1
56 fi
57 action 'Restarting %s: %s...' "$DESC" $NAME
58 kill $(cat $PIDFILE)
59 sleep 2
60 $DAEMON $OPTIONS
61 status
62 ;;
63 *)
64 emsg "<n><b>$(_ 'Usage:')</b> $0 [start|stop|restart]"
65 newline
66 exit 1
67 ;;
68 esac
70 exit 0