#!/bin/sh
#
# (c) 2004-2013 Denora Team
# Contact us at info@denorastats.org
#
# This program is free but copyrighted software; see the file COPYING for
# details.
#
# Based on the original code of Anope by Anope Team.
# Based on the original code of Thales by Lucas.
#
# 

###############################################
# Set Variables
###############################################

# CONFIGURATION CACHE (e.g. ../config.log)
CACHEFILE="../../config.log"

# REGISTRATION INFORMATION CACHE FILE (no need to alter this)
REGCACHE="register.cache"

# SENDMAIL PATH
SENDMAIL="/usr/sbin/sendmail"

# SCRIPT VERSION NUMBER (DO NOT ALTER)
REGISTERVERSION="1.4"

# DO NOT CHANGE IF YOU WANT TO REGISTER WITH DENORA
REGISTRYADDRESS="register@denorastats.org"

################################################
# END OF CONFIGURATION
# YOU ARE NOT REQUIRED TO CHANGE ANYTHING BELOW
################################################

Show_Questions () {
	echo "Beginning registration..."
	echo "1. What is your network name? (e.g. Denora IRC Network)"
	read NETWORKNAME
	echo CONNECTADDRESS=\"$NETWORKNAME\" >> $REGCACHE
	echo "2. What is your network's connection address (e.g. irc.denorastats.org)"
	read CONNECTADDRESS
	echo CONNECTADDRESS=\"$CONNECTADDRESS\" >> $REGCACHE
	echo "3. Primary contact email address? (e.g. irc-admin@denorastats.org)"
	read CONTACTEMAIL
	echo CONTACTEMAIL=\"$CONTACTEMAIL\" >> $REGCACHE
	echo "4. What is your network's website address (e.g. http://www.denorastats.org/)"
	read WEBSITEADDRESS
	echo WEBSITEADDRESS=\"$WEBSITEADDRESS\" >> $REGCACHE
	echo "5. Would you like your network to be listed in a public database?"
	echo "[Please type YES if you would like to be listed]"
	read LISTED
	echo LISTED=\"$LISTED\" >> $REGCACHE
	echo "6. What IRCD do you intend to use Denora with?"
	read IRCD
	echo IRCD=\"$IRCD\" >> $REGCACHE
	echo >> $REGCACHE
	echo "Processing registration..."
	cat $CACHEFILE >> $REGCACHE
	$SENDMAIL "$REGISTRYADDRESS" < $REGCACHE 
		if [ -f $REGCACHE ] ; then
		echo "Cleaning up..."
		rm $REGCACHE
		fi
	echo "Registration Completed. Thank you for registering Denora."
}


if [ $0 != "./register" ] ; then
	cd src/bin/
fi

if [ ! -f $CACHEFILE ] ; then
        echo "Warning: Configuration cache file missing. Run ./Config"
        exit 1
fi

if [ ! -f $SENDMAIL ] ; then
	echo "Warning: Sendmail cannot be found. Please open this file and set variable correctly"
	exit 1;
fi

clear 

if [ -f $REGCACHE ] ; then
	echo "Previous registration cache file found. Removing..."
	rm $REGCACHE
fi

	echo "##################################################"
	echo "Denora registration script (v$REGISTERVERSION)"
	echo "##################################################"
	echo "This script allows you to register your network"
	echo "with the Denora central registry. This gives us"
	echo "an idea of how many networks use Denora and what options"
	echo "they compile with so we can spend more time developing"
	echo "options that are more widely used. Note: The options"
	echo "you selected in ./Config will be sent." 
	echo "You will be asked a series of questions, if you wish"
	echo "to be listed in the public network database all the"
	echo "information will be required."
	echo "NOTE: NO PRIVATE OR SENSITIVE INFORMATION WILL BE SENT"
	echo "##################################################"
	
ok=0
DEF=yes
while [ $ok -lt 1 ] ; do
        echo "Would you like to register? [Type YES to continue]"
        if read INPUT ; then : ; else echo "" ; exit 1 ; fi
        if [ ! "$INPUT" ] ; then
                INPUT=$DEF
        fi
        case $INPUT in
            n*|N*)
				echo "Registration Cancelled"
				ok=1
				;;
            y*|Y*)
				Show_Questions
				ok=1
				;;
            *)
	        	echo "Registration Cancelled"
				ok=1
                ;;
        esac
done
echo ""


