#!/bin/sh export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mod/sbin:/mod/bin:/mod/usr/sbin:/mod/usr/bin export LD_LIBRARY_PATH=/mod/lib DAEMON=dropbear case "$1" in ""|load|start|restart) if [ ! -r "/mod/etc/conf/$DAEMON.cfg" ]; then echo "Error[$DAEMON]: not configured" 1>&2 exit 1 fi . /mod/etc/conf/$DAEMON.cfg ;; esac start() { if [ ! -e "/tmp/flash/rsa_host_key" -o ! -e "/tmp/flash/dss_host_key" ]; then echo "Creating RSA and DSS host keys" rm -f /tmp/flash/rsa_host_key rm -f /tmp/flash/dss_host_key dropbearkey -t rsa -f /tmp/flash/rsa_host_key dropbearkey -t dss -f /tmp/flash/dss_host_key /usr/bin/modsave flash fi if [ ! -d "/mod/etc/ssh" ]; then mkdir -p /mod/etc/ssh ln -s /tmp/flash/rsa_host_key /mod/etc/ssh/rsa_host_key ln -s /tmp/flash/dss_host_key /mod/etc/ssh/dss_host_key fi [ -e "/mod/root/.ssh" ] || ln -s /tmp/flash/.ssh /mod/root/.ssh if [ "$DROPBEAR_PWDAUTH" = "yes" ]; then if cat /var/tmp/shadow | grep '^root:\*:' > /dev/null; then echo "Error[$DAEMON]: no root password set - run 'modpasswd root'" 1>&2 exit 1 fi else DROPBEAR_OPTIONS="-s $DROPBEAR_OPTIONS" fi echo -n 'Starting ssh server...' set -o noglob $DAEMON -p "$DROPBEAR_PORT" $DROPBEAR_OPTIONS exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n 'Stopping ssh server...' killall $DAEMON > /dev/null 2>&1 exitval=$? if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } case "$1" in ""|load) [ -d "/tmp/flash/.ssh" ] || mkdir /tmp/flash/.ssh modreg cgi 'dropbear' 'Dropbear' deffile='/mod/etc/default.dropbear/authorized_keys.def' [ -r "/tmp/flash/authorized_keys.def" ] && deffile='/tmp/flash/authorized_keys.def' modreg file 'authorized_keys' 'Authorized keys' 0 "$deffile" if [ "$DROPBEAR_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi start ;; unload) stop modunreg file 'authorized_keys' modunreg cgi 'dropbear' ;; start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) if [ -z "$(pidof "$DAEMON")" ]; then echo 'stopped' else echo 'running' fi ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0