#! /bin/sh
########################################################################
# Configuration script for IP-multiserv
#
# Christophe Blaess 2004
########################################################################

CONFIG_FILE="src/multiserv_config.h"
MAKEFILE="src/Makefile"
MAKEFILE_TMPL="src/Makefile.tmpl"



main ()
{
	if [ "$MULTISERV_VERSION" = "" ]; then
		echo "Please, do not call directly configuration script, but use"
		echo "  make config"
		exit 1
	fi
	read_old_config
	if which dialog > /dev/null 2>&2; then
		if ! dialog_config; then
			clear
			echo "Configuration NOT saved"
			exit 1
		fi
	else
		if ! text_mode_config; then
			clear
			echo "Configuration NOT saved"
			exit 1
		fi
	fi

	save_config
	clear
	echo "Configuration saved"
	echo "To continue installation you can run 'make'"
}


read_old_config()
{
	#--------------------  Disable all options
	MULTISERV_DEBUG="off"
	MULTISERV_STATIC="off"
	MULTISERV_LOG="off"
	MULTISERV_LOG_FILE=""
	MULTISERV_TELNET_TCP="off"
	MULTISERV_TFTP_UDP="off"
	MULTISERV_FTP_TCP="off"
	MULTISERV_FTP_VERBOSE="off"
	MULTISERV_FTP_ANONYMOUS="off"
	MULTISERV_FTP_ANONYMOUS_DIR="/tmp"
	MULTISERV_FTP_ANONYMOUS_UID="99"
	MULTISERV_FTP_ANONYMOUS_GID="99"
	MULTISERV_CHARGEN_TCP="off"
	MULTISERV_CHARGEN_UDP="off"
	MULTISERV_DAYTIME_TCP="off"
	MULTISERV_DAYTIME_UDP="off"
	MULTISERV_DISCARD_TCP="off"
	MULTISERV_DISCARD_UDP="off"
	MULTISERV_ECHO_TCP="off"
	MULTISERV_ECHO_UDP="off"
	MULTISERV_QOTD_TCP="off"
	MULTISERV_QOTD_UDP="off"
	MULTISERV_QOTD_FILE=""
	MULTISERV_TIME_TCP="off"
	MULTISERV_TIME_UDP="off"
	#--------------------  Config.h parsing 
	while read line; do
		case $line in
			"" | "//*" | "/\**" ) continue;;
			"#ifndef MULTISERV_CONFIG_H" ) continue;;
			"#define MULTISERV_CONFIG_H" ) continue;;
			"#endif" ) continue;;
			"#define MULTISERV_DEBUG" ) MULTISERV_DEBUG="on";;
			"#define MULTISERV_STATIC" ) MULTISERV_STATIC="on";;
			"#define MULTISERV_LOG" ) MULTISERV_LOG="on";;
			"#define MULTISERV_LOG_FILE"* ) MULTISERV_LOG_FILE=$(echo "$line"|sed -e 's/#define MULTISERV_LOG_FILE *//'|sed -e's/"//g');;
			"#define MULTISERV_TELNET_TCP" ) MULTISERV_TELNET_TCP="on";;
			"#define MULTISERV_FTP_TCP" ) MULTISERV_FTP_TCP="on";;
			"#define MULTISERV_FTP_VERBOSE" ) MULTISERV_FTP_VERBOSE="on";;
			"#define MULTISERV_FTP_ANONYMOUS" ) MULTISERV_FTP_ANONYMOUS="on";;
			"#define MULTISERV_FTP_ANONYMOUS_DIR"* ) MULTISERV_FTP_ANONYMOUS_DIR=$(echo "$line"|sed -e 's/#define MULTISERV_FTP_ANONYMOUS_DIR *//'|sed -e's/"//g');;
			"#define MULTISERV_FTP_ANONYMOUS_UID"* ) MULTISERV_FTP_ANONYMOUS_UID=$(echo "$line"|sed -e 's/#define MULTISERV_FTP_ANONYMOUS_UID *//'|sed -e's/"//g');;
			"#define MULTISERV_FTP_ANONYMOUS_GID"* ) MULTISERV_FTP_ANONYMOUS_GID=$(echo "$line"|sed -e 's/#define MULTISERV_FTP_ANONYMOUS_GID *//'|sed -e's/"//g');;
			"#define MULTISERV_TFTP_UDP" ) MULTISERV_TFTP_UDP="on";;
			"#define MULTISERV_TFTP_TCP" ) MULTISERV_TFTP_TCP="on";;
			"#define MULTISERV_CHARGEN_TCP" ) MULTISERV_CHARGEN_TCP="on";;
			"#define MULTISERV_CHARGEN_UDP" ) MULTISERV_CHARGEN_UDP="on";;
			"#define MULTISERV_DAYTIME_TCP" ) MULTISERV_DAYTIME_TCP="on";;
			"#define MULTISERV_DAYTIME_UDP" ) MULTISERV_DAYTIME_UDP="on";;
			"#define MULTISERV_DISCARD_TCP" ) MULTISERV_DISCARD_TCP="on";;
			"#define MULTISERV_DISCARD_UDP" ) MULTISERV_DISCARD_UDP="on";;
			"#define MULTISERV_ECHO_TCP" ) MULTISERV_ECHO_TCP="on";;
			"#define MULTISERV_ECHO_UDP" ) MULTISERV_ECHO_UDP="on";;
			"#define MULTISERV_QOTD_TCP" ) MULTISERV_QOTD_TCP="on";;
			"#define MULTISERV_QOTD_UDP" ) MULTISERV_QOTD_UDP="on";;
			"#define MULTISERV_QOTD_FILE"* ) MULTISERV_QOTD_FILE=$(echo "$line"|sed -e 's/#define MULTISERV_QOTD_FILE[	 ]*//'|sed -e's/"//g');;
			"#define MULTISERV_TIME_TCP" ) MULTISERV_TIME_TCP="on";;
			"#define MULTISERV_TIME_UDP" ) MULTISERV_TIME_UDP="on";;				
			"*" )
				echo "Unable to parse a line in $CONFIG_FILE :"
				echo "  " $line
				echo "--> ignored"
				continue;;
		esac
	done < "$CONFIG_FILE"
}

save_config()
{
	#--------------------  Config.h generation 
	
	echo "/* Do not edit this file! */" > "$CONFIG_FILE"
	echo "/* It is parsed and generated by the configuration script */"	>>  "$CONFIG_FILE"
	echo "#ifndef MULTISERV_CONFIG_H" >> "$CONFIG_FILE"
	echo "#define MULTISERV_CONFIG_H" >> "$CONFIG_FILE"
	# General Options
	if [ "$MULTISERV_DEBUG"  = "on" ]; then echo "#define MULTISERV_DEBUG" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_STATIC" = "on" ]; then echo "#define MULTISERV_STATIC" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_LOG"    = "on" ]; then echo "#define MULTISERV_LOG" >> $CONFIG_FILE; fi
	if [ -n "$MULTISERV_LOG_FILE" ]; then
		echo -n '#define MULTISERV_LOG_FILE "' >> $CONFIG_FILE;
		echo -n "$MULTISERV_LOG_FILE" >> $CONFIG_FILE
		echo '"' >> $CONFIG_FILE
	fi
	# Servers options
	if [ "$MULTISERV_TELNET_TCP" = "on" ]; then echo "#define MULTISERV_TELNET_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_FTP_TCP" = "on" ]; then echo "#define MULTISERV_FTP_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_FTP_VERBOSE" = "on" ]; then echo "#define MULTISERV_FTP_VERBOSE" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_FTP_ANONYMOUS" = "on" ]; then
		echo "#define MULTISERV_FTP_ANONYMOUS" >> $CONFIG_FILE
		echo -n '#define MULTISERV_FTP_ANONYMOUS_DIR "' >> $CONFIG_FILE
		echo -n "$MULTISERV_FTP_ANONYMOUS_DIR" >> $CONFIG_FILE
		echo '"' >> $CONFIG_FILE
		echo "#define MULTISERV_FTP_ANONYMOUS_UID $MULTISERV_FTP_ANONYMOUS_UID" >> $CONFIG_FILE
		echo "#define MULTISERV_FTP_ANONYMOUS_GID $MULTISERV_FTP_ANONYMOUS_GID" >> $CONFIG_FILE
	fi
	if [ "$MULTISERV_TFTP_UDP" = "on" ]; then echo "#define MULTISERV_TFTP_UDP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_TFTP_TCP" = "on" ]; then echo "#define MULTISERV_TFTP_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_CHARGEN_TCP" = "on" ]; then echo "#define MULTISERV_CHARGEN_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_CHARGEN_UDP" = "on" ]; then echo "#define MULTISERV_CHARGEN_UDP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_DAYTIME_TCP" = "on" ]; then echo "#define MULTISERV_DAYTIME_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_DAYTIME_UDP" = "on" ]; then echo "#define MULTISERV_DAYTIME_UDP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_DISCARD_TCP" = "on" ]; then echo "#define MULTISERV_DISCARD_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_DISCARD_UDP" = "on" ]; then echo "#define MULTISERV_DISCARD_UDP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_ECHO_TCP" = "on" ]; then echo "#define MULTISERV_ECHO_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_ECHO_UDP" = "on" ]; then echo "#define MULTISERV_ECHO_UDP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_QOTD_TCP" = "on" ]; then echo "#define MULTISERV_QOTD_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_QOTD_UDP" = "on" ]; then echo "#define MULTISERV_QOTD_UDP" >> $CONFIG_FILE; fi
	if [ -n "$MULTISERV_QOTD_FILE" ]; then
		echo -n '#define MULTISERV_QOTD_FILE "' >> $CONFIG_FILE;
		echo -n "$MULTISERV_QOTD_FILE" >> $CONFIG_FILE
		echo '"' >> $CONFIG_FILE
	fi
	if [ "$MULTISERV_TIME_TCP" = "on" ]; then echo "#define MULTISERV_TIME_TCP" >> $CONFIG_FILE; fi
	if [ "$MULTISERV_TIME_UDP" = "on" ]; then echo "#define MULTISERV_TIME_UDP" >> $CONFIG_FILE; fi
	echo "#endif"																		>> "$CONFIG_FILE"

	#----------------------- Makefile generation

	echo "# Do not edit this file!" > "$MAKEFILE"
	echo "# It is generated by the configuration script"	>>  "$MAKEFILE"
	echo "CC      =  gcc" >> "$MAKEFILE"
	echo "CFLAGS  =  -Wall -O2" >> "$MAKEFILE"
	echo -n "CPPFLAGS  = -DMULTISERV_VERSION='" >> "$MAKEFILE"
	echo -n '"' >> "$MAKEFILE"
	echo -n $MULTISERV_VERSION >> "$MAKEFILE"
	echo -n '"' >> "$MAKEFILE"
	echo "'" >> "$MAKEFILE"
	if [ "$MULTISERV_DEBUG" = "off" ]; then
		echo "CPPFLAGS += -DNDEBUG" >> $MAKEFILE
	fi
	if [ "$MULTISERV_STATIC" = "on" ]; then
		echo "LDFLAGS=-static" >> $MAKEFILE
	else
		echo "LDFLAGS=" >> $MAKEFILE
	fi
	cat $MAKEFILE_TMPL >> $MAKEFILE
}



dialog_config()
{
	local choice
	while true; do
		choice=$(dialog 										\
			--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
			--cancel-label "Exit"								\
			--ok-label "Select"									\
			--menu "IP-multiserv Configuration" 0 0 0			\
			"1" "General options"								\
			"2" "Servers configuration"							\
			2>&1)
		if [ $? -ne 0 ]; then break; fi
		case $choice in
			"1" )	dialog_general_config ;;
			"2" )	dialog_servers_config ;;
		esac
	done
	choice=$(dialog											\
		--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
		--yesno "Do you want to save the new configuration ?" 0 0 \
		2>&1)
}

dialog_general_config()
{
	local list
	local reply
	list=$(dialog 											\
		--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
		--cancel-label "Cancel"								\
		--ok-label "Ok"										\
		--checklist "General Configuration" 0 0 0			\
		"1" "Insert debug code" "$MULTISERV_DEBUG"			\
		"2" "Compile as static binary file" "$MULTISERV_STATIC"	\
		"3" "Insert logging routines" "$MULTISERV_LOG"			\
		2>&1)
	if [ $? -ne 0 ]; then return; fi
	if echo $list |grep "1" >/dev/null 2>&1 ; then MULTISERV_DEBUG="on"; else MULTISERV_DEBUG="off"; fi
	if echo $list |grep "2" >/dev/null 2>&1 ; then MULTISERV_STATIC="on"; else MULTISERV_STATIC="off"; fi
	if echo $list |grep "3" >/dev/null 2>&1 ; then MULTISERV_LOG="on"; else MULTISERV_LOG="off"; fi		
	if [ "$MULTISERV_LOG" = "on" ]; then
		reply=$(dialog											\
			--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
			--cancel-label "Cancel"								\
			--ok-label "Ok"										\
			--inputbox "IP-multiserv log file ?" 0 0 "$MULTISERV_LOG_FILE"	\
			2>&1)
		if [ $? -ne 0 ]; then return; fi
		MULTISERV_LOG_FILE=$reply
	fi
	
}

dialog_servers_config()
{
	local list
	local reply
	list=$(dialog 											\
		--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
		--cancel-label "Cancel"								\
		--ok-label "Ok"										\
		--checklist "Servers Configuration" 0 0 0			\
		"01" "Telnet server TCP/IP"							"$MULTISERV_TELNET_TCP"		\
		"02" "File Transfert - FTP - server TCP/IP"			"$MULTISERV_FTP_TCP"		\
		"03" "Trivial File Transfert - TFTP - server UDP/IP" "$MULTISERV_TFTP_UDP"		\
		"04" "Character Generator server TCP/IP"			"$MULTISERV_CHARGEN_TCP"	\
		"05" "Character Generator server UDP/IP"			"$MULTISERV_CHARGEN_UDP"	\
		"06" "Daytime server TCP/IP"						"$MULTISERV_DAYTIME_TCP"	\
		"07" "Daytime server UDP/IP"						"$MULTISERV_DAYTIME_UDP"	\
		"08" "Discard server TCP/IP"						"$MULTISERV_DISCARD_TCP"	\
		"09" "Discard server UDP/IP"						"$MULTISERV_DISCARD_UDP"	\
		"10" "Echo server TCP/IP"							"$MULTISERV_ECHO_TCP"		\
		"11" "Echo server UDP/IP"							"$MULTISERV_ECHO_UDP"		\
		"12" "Quote Of The Day server TCP/IP"				"$MULTISERV_QOTD_TCP"		\
		"13" "Quote Of The Day server UDP/IP"				"$MULTISERV_QOTD_UDP"		\
		"14" "Time server TCP/IP"							"$MULTISERV_TIME_TCP"		\
		"15" "Time server UDP/IP"							"$MULTISERV_TIME_UDP"		\
		2>&1)
	if [ $? -ne 0 ]; then return; fi
	if echo $list |grep "01" >/dev/null 2>&1 ; then MULTISERV_TELNET_TCP="on"; else MULTISERV_TELNET_TCP="off"; fi
	if echo $list |grep "02" >/dev/null 2>&1 ; then MULTISERV_FTP_TCP="on"; else MULTISERV_FTP_TCP="off"; fi
	if echo $list |grep "03" >/dev/null 2>&1 ; then MULTISERV_TFTP_UDP="on"; else MULTISERV_TFTP_UDP="off"; fi
	if echo $list |grep "04" >/dev/null 2>&1 ; then MULTISERV_CHARGEN_TCP="on"; else MULTISERV_CHARGEN_TCP="off"; fi
	if echo $list |grep "05" >/dev/null 2>&1 ; then MULTISERV_CHARGEN_UDP="on"; else MULTISERV_CHARGEN_UDP="off"; fi
	if echo $list |grep "06" >/dev/null 2>&1 ; then MULTISERV_DAYTIME_TCP="on"; else MULTISERV_DAYTIME_TCP="off"; fi
	if echo $list |grep "07" >/dev/null 2>&1 ; then MULTISERV_DAYTIME_UDP="on"; else MULTISERV_DAYTIME_UDP="off"; fi
	if echo $list |grep "08" >/dev/null 2>&1 ; then MULTISERV_DISCARD_TCP="on"; else MULTISERV_DISCARD_TCP="off"; fi
	if echo $list |grep "09" >/dev/null 2>&1 ; then MULTISERV_DISCARD_UDP="on"; else MULTISERV_DISCARD_UDP="off"; fi
	if echo $list |grep "10" >/dev/null 2>&1 ; then MULTISERV_ECHO_TCP="on"; else MULTISERV_ECHO_TCP="off"; fi
	if echo $list |grep "11" >/dev/null 2>&1 ; then MULTISERV_ECHO_UDP="on"; else MULTISERV_ECHO_UDP="off"; fi
	if echo $list |grep "12" >/dev/null 2>&1 ; then MULTISERV_QOTD_TCP="on"; else MULTISERV_QOTD_TCP="off"; fi
	if echo $list |grep "13" >/dev/null 2>&1 ; then MULTISERV_QOTD_UDP="on"; else MULTISERV_QOTD_UDP="off"; fi
	if echo $list |grep "14" >/dev/null 2>&1 ; then MULTISERV_TIME_TCP="on"; else MULTISERV_TIME_TCP="off"; fi
	if echo $list |grep "15" >/dev/null 2>&1 ; then MULTISERV_TIME_UDP="on"; else MULTISERV_TIME_UDP="off"; fi

	if [ "$MULTISERV_QOTD_TCP" = "on" ] || [ "$MULTISERV_QOTD_UDP" = "on" ]; then
		reply=$(dialog											\
			--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
			--cancel-label "Cancel"								\
			--ok-label "Ok"										\
			--inputbox "Quote Of The Day message file ?" 0 0 "$MULTISERV_QOTD_FILE"	\
			2>&1)
		if [ $? -ne 0 ]; then return; fi
		MULTISERV_QOTD_FILE=$reply
	fi

	if [ "$MULTISERV_FTP_TCP" = "on" ]; then
		if dialog											\
			--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
			--cancel-label "Cancel"								\
			--ok-label "Ok"										\
			--yesno "Verbose FTP reply messages (about 500 bytes)?" 0 0	\
			2>&1; then
			MULTISERV_FTP_VERBOSE="on"
		else
			MULTISERV_FTP_VERBOSE="off"
		fi
		if dialog											\
			--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
			--cancel-label "Cancel"								\
			--ok-label "Ok"										\
			--yesno "Allow anonymous FTP login ?" 0 0	\
			2>&1; then
			MULTISERV_FTP_ANONYMOUS="on"
			reply=$(dialog											\
				--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
				--cancel-label "Cancel"								\
				--ok-label "Ok"										\
				--inputbox "Anonymous FTP directory ? " 0 0 "$MULTISERV_FTP_ANONYMOUS_DIR"	\
				2>&1)
			if [ $? -ne 0 ]; then return; fi
			MULTISERV_FTP_ANONYMOUS_DIR=$reply
			reply=$(dialog											\
				--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
				--cancel-label "Cancel"								\
				--ok-label "Ok"										\
				--inputbox "Anonymous FTP User ID ? " 0 0 "$MULTISERV_FTP_ANONYMOUS_UID"	\
				2>&1)
			if [ $? -ne 0 ]; then return; fi
			MULTISERV_FTP_ANONYMOUS_GID=$reply
			reply=$(dialog											\
				--backtitle "IP-multiserv v.$MULTISERV_VERSION"		\
				--cancel-label "Cancel"								\
				--ok-label "Ok"										\
				--inputbox "Anonymous FTP Group ID ? " 0 0 "$MULTISERV_FTP_ANONYMOUS_GID"	\
				2>&1)
			if [ $? -ne 0 ]; then return; fi
			MULTISERV_FTP_ANONYMOUS_GID=$reply
		else
			MULTISERV_FTP_ANONYMOUS="off"
		fi
	fi
}


text_mode_config()
{
	clear
	echo "--- IP-multiserv v.$MULTISERV_VERSION configuration ---"
	echo ""
	echo "The 'dialog' tool is not present on your system. We will go through"
	echo "a (boring) text-mode configuration. It would be easier to configure"
	echo "IP-multiserv with 'dialog'. See http://invisible-island.net/dialog/"
	echo ""
	echo "===== General Options ====="
	ask_question "Insert debug code into multiserv binary file" "MULTISERV_DEBUG"
	ask_question "Compile as static binary file" "MULTISERV_STATIC"
	ask_question "Insert logging routines" "MULTISERV_LOG"
	if [ "$MULTISERV_LOG" = "on" ]; then
		ask_string "IP-multiserv log file ?" "MULTISERV_LOG_FILE"
	fi
	echo ""
	echo "===== Servers Option ====="
	ask_question "Insert Telnet server TCP/IP"						MULTISERV_TELNET_TCP
	ask_question "Insert File Transfert Protocol - FTP - server TCP/IP"	MULTISERV_FTP_TCP
	ask_question "Insert Trivial File Transfert - TFTP - server UDP/IP"	MULTISERV_TFTP_UDP
	ask_question "Insert Character Generator server TCP/IP"			MULTISERV_CHARGEN_TCP
	ask_question "Insert Character Generator server UDP/IP"			MULTISERV_CHARGEN_UDP
	ask_question "Insert Daytime server TCP/IP"						MULTISERV_DAYTIME_TCP
	ask_question "Insert Daytime server UDP/IP"						MULTISERV_DAYTIME_UDP
	ask_question "Insert Discard server TCP/IP"						MULTISERV_DISCARD_TCP
	ask_question "Insert Discard server UDP/IP"						MULTISERV_DISCARD_UDP
	ask_question "Insert Echo server TCP/IP"						MULTISERV_ECHO_TCP
	ask_question "Insert Echo server UDP/IP"						MULTISERV_ECHO_UDP
	ask_question "Insert Quote Of The Day server TCP/IP"			MULTISERV_QOTD_TCP
	ask_question "Insert Quote Of The Day server UDP/IP"			MULTISERV_QOTD_UDP
	ask_question "Insert Time server TCP/IP"						MULTISERV_TIME_TCP
	ask_question "Insert Time server UDP/IP"						MULTISERV_TIME_UDP
	if [ "$MULTISERV_QOTD_TCP" = "on" ] || [ "$MULTISERV_QOTD_UDP" = "on" ]; then
		ask_string "Quote Of The Day message file ?" MULTISERV_QOTD_FILE
	fi
	if [ "$MULTISERV_FTP_TCP" = "on" ]; then
		ask_question "Verbose FTP reply messages (about 500 bytes)" MULTISERV_FTP_VERBOSE
	fi
	if [ "$MULTISERV_FTP_TCP" = "on" ]; then
		ask_question "Allow Anonymous FTP"				MULTISERV_FTP_ANONYMOUS
		if [ "$MULTISERV_FTP_ANONYMOUS" = "on" ]; then
			ask_string "Anonymous FTP directory ? "		MULTISERV_FTP_ANONYMOUS_DIR
			ask_string "Anonymous FTP User ID ? "		MULTISERV_FTP_ANONYMOUS_UID
			ask_string "Anonymous FTP Group ID ? "		MULTISERV_FTP_ANONYMOUS_GID
		fi
	fi
	clear
	while true; do
		echo -n "Do you want to save the new configuration ? [Y/N] "
		if ! read; then return 1; fi
		case $REPLY in
			[Yy]* ) break ;;
			[Nn]* ) return 1;;
		esac
	done
	return 0
}

ask_question()
{
	if [ $# -ne 2 ] ; then exit 1; fi
	local value=$(eval echo \$$2)
	while true ; do
		echo "$1 ?"
		if [ "$value" = "on" ]; then
			echo -n " -> [Y/n] "
		else
			echo -n " -> [y/N] "
		fi
		if ! read ; then exit ; fi
		case "$REPLY" in
			"" ) return ;;
			"Y"* | "y"* ) eval $2="on" ; return ;;
			"N"* | "n"* ) eval $2="off"; return ;;
		esac
	done
}

ask_string()
{
	if [ $# -ne 2 ] ; then exit 1; fi
	local value=$(eval echo \$$2)
	echo "$1 ?"
	echo -n " -> [$value] "
	if ! read ; then exit ; fi
	if  [ "$REPLY" = "" ]; then return; fi
	eval $2=$REPLY
}


	main 
