2016-02-11 07:24:15 +00:00
|
|
|
#!/bin/sh
|
2016-02-20 19:31:41 +00:00
|
|
|
# start/stop/startup/shutdown/backup/restore/restart shellinabox daemon:
|
2016-02-11 07:24:15 +00:00
|
|
|
|
|
|
|
PROG="shellinaboxd"
|
|
|
|
SHELLINABOXD="/usr/sbin/$PROG"
|
|
|
|
LOCKFILE="/var/lock/$PROG"
|
|
|
|
PIDFILE="/var/run/$PROG.pid"
|
|
|
|
PROFILE="/root/.bash_profile"
|
|
|
|
STYLES="/usr/local/emhttp/plugins/shellinabox-plugin/styles"
|
|
|
|
PLGPATH="/boot/config/plugins/shellinabox-plugin"
|
|
|
|
CONFIG="$PLGPATH/shellinabox-plugin.cfg"
|
|
|
|
USER_CSS="Color:+$STYLES/color.css,Monochrome:-$STYLES/monochrome.css;White:+$STYLES/white-on-black.css,Black:-$STYLES/black-on-white.css,Blue:-$STYLES/blue-on-black.css,Green:-$STYLES/green-on-black.css,Pink:-$STYLES/pink-on-black.css,Purple:-$STYLES/purple-on-black.css,Red:-$STYLES/red-on-black.css,Yellow:-$STYLES/yellow-on-black.css"
|
|
|
|
|
|
|
|
# read our configuration
|
|
|
|
[ -e "$CONFIG" ] && source $CONFIG
|
|
|
|
|
|
|
|
# add screenfetch to bash profile
|
|
|
|
if [ "$SCREEN" == "enable" ]; then
|
|
|
|
if ! grep "/usr/sbin/screenfetch" $PROFILE >/dev/null 2>&1
|
|
|
|
#append command to file
|
|
|
|
then echo -e "\n/usr/sbin/screenfetch" >> $PROFILE
|
|
|
|
else
|
|
|
|
#uncomment command
|
|
|
|
sed -e '/\/usr\/sbin\/screenfetch/s/^#//g' -i $PROFILE
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
#comment out command
|
|
|
|
sed -e '/\/usr\/sbin\/screenfetch/ s/^#*/#/' -i $PROFILE
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Start shellinaboxd:
|
|
|
|
shellinaboxd_start() {
|
|
|
|
# no-op if already running
|
|
|
|
if [[ "$SERVICE" == "enable" && ! -r "$PIDFILE" ]]; then
|
|
|
|
|
|
|
|
SSL_CONFIG=""
|
|
|
|
[ $SSL == "disable" ] && SSL_CONFIG="--disable-ssl"
|
|
|
|
|
|
|
|
echo "starting shellinaboxd..."
|
|
|
|
sleep 1
|
|
|
|
nohup /usr/sbin/$PROG --user=$RUNAS --background=$PIDFILE --port=$PORT --cert=$PLGPATH --user-css=$USER_CSS $SSL_CONFIG > /dev/null 2>&1 | logger -t$PROG &
|
|
|
|
touch $LOCKFILE
|
|
|
|
TIMER=0
|
|
|
|
while [ ! -e $PIDFILE ]; do
|
|
|
|
sleep 1
|
|
|
|
let TIMER=$TIMER+1
|
|
|
|
if [ $TIMER -gt 5 ]; then
|
|
|
|
echo -n "$PIDFILE not created"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "shellinaboxd is running"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Stop shellinaboxd:
|
|
|
|
shellinaboxd_stop() {
|
|
|
|
# no-op if not running
|
|
|
|
if [ -r "$PIDFILE" ]; then
|
|
|
|
echo "stopping shellinaboxd..."
|
|
|
|
|
|
|
|
TIMER=0
|
|
|
|
while `killall $PROG 2>/dev/null`; do
|
|
|
|
sleep 1
|
|
|
|
TIMER=$((TIMER+1))
|
|
|
|
if [ $TIMER -ge 30 ]; then
|
|
|
|
killall -9 $PROG
|
|
|
|
sleep 1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
rm -f $LOCKFILE && rm -f $PIDFILE
|
|
|
|
else
|
|
|
|
echo "shellinaboxd is stopped"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restart shellinaboxd:
|
|
|
|
shellinaboxd_restart() {
|
|
|
|
shellinaboxd_stop
|
|
|
|
sleep 1
|
|
|
|
shellinaboxd_start
|
|
|
|
}
|
|
|
|
|
2016-02-20 19:31:41 +00:00
|
|
|
# Restore home directory
|
2016-02-11 07:24:15 +00:00
|
|
|
shellinaboxd_restore() {
|
2016-02-20 19:31:41 +00:00
|
|
|
if [[ "$BACKUP" == "enable" && ! -e "/root/.bash_history" ]]; then
|
|
|
|
# restore home directory
|
2016-02-11 07:24:15 +00:00
|
|
|
echo "restoring home directory..."
|
|
|
|
sleep 1
|
2016-02-20 19:31:41 +00:00
|
|
|
tar -zxf $PLGPATH/home_directory.tar.gz -p -C / > /dev/null 2>&1
|
|
|
|
else
|
2016-02-20 19:37:09 +00:00
|
|
|
echo "Backup is not enabled or home directory is not new"
|
2016-02-11 07:24:15 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-02-20 19:31:41 +00:00
|
|
|
# Backup home directory:
|
|
|
|
shellinaboxd_backup() {
|
2016-02-11 07:24:15 +00:00
|
|
|
if [ "$BACKUP" == "enable" ]; then
|
|
|
|
# backup home directory
|
|
|
|
echo "saving home directory..."
|
|
|
|
sleep 1
|
2016-02-20 19:31:41 +00:00
|
|
|
tar -zcf $PLGPATH/home_directory.tar.gz -p -C / root > /dev/null 2>&1
|
|
|
|
else
|
|
|
|
echo "Backup is not enabled"
|
2016-02-11 07:24:15 +00:00
|
|
|
fi
|
2016-02-20 19:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Start and restore for system boot:
|
|
|
|
shellinaboxd_startup() {
|
|
|
|
shellinaboxd_restore
|
|
|
|
sleep 1
|
|
|
|
shellinaboxd_start
|
|
|
|
}
|
|
|
|
|
|
|
|
# Shutdown and backup for system shutdown or reboot:
|
|
|
|
shellinaboxd_shutdown() {
|
|
|
|
shellinaboxd_backup
|
|
|
|
sleep 1
|
2016-02-11 07:24:15 +00:00
|
|
|
shellinaboxd_stop
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
2016-02-20 19:31:41 +00:00
|
|
|
'backup')
|
|
|
|
shellinaboxd_backup
|
|
|
|
;;
|
2016-02-11 07:24:15 +00:00
|
|
|
'start')
|
|
|
|
shellinaboxd_start
|
|
|
|
;;
|
2016-02-20 19:31:41 +00:00
|
|
|
'startup')
|
|
|
|
shellinaboxd_startup
|
|
|
|
;;
|
2016-02-11 07:24:15 +00:00
|
|
|
'stop')
|
|
|
|
shellinaboxd_stop
|
|
|
|
;;
|
|
|
|
'shutdown')
|
|
|
|
shellinaboxd_shutdown
|
|
|
|
;;
|
|
|
|
'restore')
|
|
|
|
shellinaboxd_restore
|
|
|
|
;;
|
|
|
|
'restart')
|
|
|
|
shellinaboxd_restart
|
|
|
|
;;
|
|
|
|
*)
|
2016-02-20 19:31:41 +00:00
|
|
|
echo "usage rc.shellinaboxd: start|stop|startup|shutdown|backup|restore|restart"
|
2016-02-11 07:24:15 +00:00
|
|
|
esac
|