#!/bin/sh

# part of pfSense by Scott Ullrich
# Copyright (C) 2004-2011 Scott Ullrich, All rights reserved.
# originally based on m0n0wall (http://neon1.net/m0n0wall)
# Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
# All rights reserved.

# make sure the user can't kill us by pressing Ctrl-C,
# ctrl-z, etc.
#trap : 2
#trap : 3
#trap : 4

# If recovery console shell option has been specified
if [ -f "/tmp/donotbootup" ]; then
	rm /tmp/donotbootup
	/bin/csh
	/usr/local/etc/rc.reboot
	# no coming back from here
fi

# endless loop
while : ; do

# Check to see if SSH is running.
if pgrep -q -a -F /var/run/sshd.pid sshd >/dev/null 2>&1; then
	sshd_option="14) Disable Secure Shell (sshd)";
else
	sshd_option="14) Enable Secure Shell (sshd)";
fi

# If we are on the LiveCD advertise the installer
if _tmpdir=$(mktemp -d -q /.diskless.XXXXXX); then
	rmdir ${_tmpdir}
else
	option99="99) Launch the installer"
fi

echo " 0) Logout                             8) Shell"
echo " 1) Assign Interfaces                  9) pfTop"
echo " 2) Set interface(s) IP address       10) Filter Logs"
echo " 3) Reset the root password           11) Restart web interface"
echo " 4) Reset to factory defaults         12) Developer Shell"
echo " 5) Reboot system                     13) Upgrade from console"
echo " 6) Halt system                       ${sshd_option}"
echo " 7) Ping host                         15) Restore a configuration"
if [ -n "${option99}" ]; then
# flat for alignment...
echo "                                      ${option99}"
fi

echo
read -p "Enter an option: " opmode
echo

# see what the user has chosen
case ${opmode} in
0)
        exit
        ;;
1)
        /usr/local/etc/rc.initial.setports
        ;;
2)
        /usr/local/etc/rc.initial.setlanip
        ;;
3)
        /usr/local/etc/rc.initial.password
        ;;
4)
        /usr/local/etc/rc.initial.defaults
        ;;
5)
        /usr/local/etc/rc.initial.reboot
        ;;
6)
        /usr/local/etc/rc.initial.halt
        ;;
7)
        /usr/local/etc/rc.initial.ping
        ;;
8)
        /bin/csh
        ;;
9)
        /usr/local/sbin/pftop
        ;;
10)
	/usr/sbin/tcpdump -s 256 -v -S -l -n -e -ttt -i pflog0
	;;
11)
	/usr/local/etc/rc.restart_webgui
	;;
12)
	/usr/local/sbin/pfSsh.php
	;;
13) 
	/usr/local/etc/rc.initial.firmware_update
	;;
14) 
	/usr/local/etc/rc.initial.toggle_sshd
	;;	
15)
	/usr/local/etc/rc.restore_config_backup
	;;
99)
	/usr/local/etc/rc.installer
	;;
*)
	;;
esac

/usr/local/etc/rc.initial.banner
echo

done