#!/bin/ash
#
#
#
 . /etc/server/daemon.conf
 adduser -D -H sshd 2>/dev/null
 mkdir /var/empty 2>/dev/null
 ln -s /etc/ssh/ssh-server.conf /etc/sshd_config 2>/dev/null
 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
   ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
 fi
 if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
   ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
 fi
 if [ ! -f /etc/ssh/ssh_host_ecdsa_key ]; then
   ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
 fi
#
#
#
 case "$1" in
 'dbkeys')
 if [ $SSHD = dropbear ]; then
   cd /etc/ssh
   dropbearconvert openssh dropbear ssh_host_rsa_key dropbear_rsa_host_key 2>/dev/null
   dropbearconvert openssh dropbear ssh_host_ecdsa_key dropbear_ecdsa_host_key 2>/dev/null
   mv dropbear* /etc/dropbear
 fi
 ;;
 'add')
 echo "22 stream tcp nowait root $SSHD $SSHD -i" > /etc/inetd/ssh.conf
 sed -i s/openssh/ssh-server/g /etc/inetd/ssh.conf
 ;;
 'start')
 sshd dbkeys
 sshd add
 inetd
 ;;
 'remove')
 rm /etc/inetd/ssh.conf 2>/dev/null
 ;;
 'stop')
 sshd remove
 inetd
 ;;
 'restart')
 sshd start
 ;;
 'test')
 if [ ! -e /etc/inetd/ssh.conf ]; then
   if [ ! -e /var/run/sshd.pid ]; then
     echo "Your SSH Server seems to be down."
     read -p "Do you wish to start it now (y/n)?: " CHOICE
     CHOICE=y$CHOICE
     if [ $CHOICE = yy ]; then
       sshd start
     fi
   fi
 fi
 clear
 echo "PuTTY Secure FTP Client will try to connect to your localhost:"
 echo ""
 psftp localhost
 ;;
 'help')
 echo "sshd start --> start SSH server"
 echo "sshd stop --> stop SSH server"
 echo "sshd restart --> restart SSH server"
 echo "sshd test --> test SSH server"
 ;;
 *)
 echo "Usage:"
 sshd help
 ;;
 esac