#!/bin/sh
#   Copyright (C) 2002 TR-IRCD Development
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2, or (at your option)
#   any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


CONFIG=""
OUTDIR=""
OUTPUT=""

QLINES=qlines.conf
GLINES=glines.conf
KLINES=kline.conf
JLINES=jline.conf
UNDOCUMENTED=compat.conf

used_qlines=0
used_klines=0
used_glines=0
used_jlines=0

use_diepass=""
use_restartpass=""
use_displaypass=""

hashutil="${HASHPROG}"

if test "x$hashutil" == "x" ; then 
	hashutil="./ircpasswd"
fi

if test ! -x "$hashutil" ; then
	echo "No hash utility (ircpasswd) found in current directory"
	exit 255
fi 


connect_amount=0
listen_count=0
lcount=0
ultimate_count=0
hub_count=0
expanded=0

if [ ! "$2" ] ; then
	echo "Usage: converter [-info] source destination-dir"
	echo "  "
	echo "The \"-info\" parameter adds extra descriptive"
	echo "information to the output file"
	echo " TR-IRCD Development (c) 2002"
	exit 255
fi

if [ "x$1" == "x-info" ] ; then

	if [ ! "$3" ] ; then
		echo "Usage: converter [-info] source destination-dir"
		echo "  "
		echo "The \"-info\" parameter adds extra descriptive"
		echo "information to the output file"
		echo " TR-IRCD Development (c) 2002"
		exit 255	
	fi

 	expanded=1
	CONFIG="$2"
	OUTDIR="$3"
else
	expanded=0
	CONFIG="$1"
	OUTDIR="$2"
fi

OUTPUT="$OUTDIR/ircd.conf"
QLINES="$OUTDIR/qlines.conf"
GLINES="$OUTDIR/glines.conf"
KLINES="$OUTDIR/kline.conf"  
JLINES="$OUTDIR/jline.conf"
UNDOCUMENTED="$OUTDIR/compat.conf"

O=$OUTPUT
ELEMENT=file.name

while read LINE; do

   awk {'print $LINE'} | sed -e 's/\ / /g' | sed -e 's/::/:*:/g' \
	| sed -e 's/::/:*:/g' | sed -e 's/:/\ /g' > $ELEMENT

done < $CONFIG

rm -f $OUTPUT $GLINES $QLINES $KLINES $UNDOCUMENTED

while read FA FB FC FD; do

   case "$FA" in
        X)
                use_diepass="$FB"
                use_restartpass="$FC"
                use_displaypass="$FD"
                ;;
	*)
		;;
   esac

done < $ELEMENT

diepass="`$hashutil $use_diepass | sed -e 's/Encryption\ is\:\ //g'`"
restartpass="`$hashutil $use_restartpass | sed -e 's/Encryption\ is\:\ //g'`"
displaypass="`$hashutil $use_displaypass | sed -e 's/Encryption\ is\:\ //g'`"

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

#tr-ircd 5.0 configuration file example v0.3 nexus@develooper.net
#
#       The config file consists of directives and comments. A directive 
#       consists of either a direct value, or other directives. Each directive
#       HAS to end with a semicolon (;). A directive is ALWAYS in lowercase.
#       Comments are denoted with either one of #, // or /* */. While the first
#       two declare the rest of the line as comments, anything between /* and 
#       */ is considered a comment and gets ignored. Below are some examples of
#       correct directives.
#
#       directive1= value1;             
#       directive2 {                    
#               directive3=value3;
#               directive4=value4;
#       };
#
#       Below is a description of each directive and the values they expect. 
#       Unless noted otherwise in the comments to each directive, each 
#       directive accepts strings as values. Accepted units for time are:
#       seconds, minutes, hours, days, weeks, months, years, decades, centuries
#       and millenia.
#
#       If a directive is not listed below, it doesn't exist.

# PLEASE NOTE THAT EVERY PASSWORD ENTRY EXCEPT send_password FROM connect { }
# MUST BE ENCRYPTED WITH the ircpasswd utility.

/*  The serverinfo directive encompasses the following directives:
 *      name        : This is the name used throughout IRC to refer to this 
 *                    server. Although this name does not have to correspond to
 *                    an actual hostname of the server running the daemon, if 
 *                    this is to be leaf server, a resolvable address is 
 *                    recommended.
 *      aliasname   : This is an alias for the server. Every client connecting 
 *                    using this name will get servermessages from this 
 *                    servername.
 *      description : This is a description of the server as seen in whois and 
 *                    links requests.
 *      networkname : This is given to the clients as they connect. It is
 *                    prudent, but not mandatory that all linked servers have 
 *                    the same value set at this directive.
 *      networkdesc : This description appears instead of the description for a
 *                    request from a user on another server when either server 
 *                    employs the serverhide directive.
 *      address     : This is the IP address for the daemon to bind to.
 *                    This value has to be entered as a valid IP address.
 *      servermode  : This value determines whether this server will act with
 *                    full capacity or maintain only those features available in
 *                    tr-ircd version 4. Valid choices are:
 *                      native
 *                      trircd4_compatible
 *                      pelennor (compatibility with Bahamut 1.4 series)
 *                      halcyon  (compatibility with Bahamut 1.6 series)
 *                    Please note that this option will have no effect, if the
 *                    ircd is compiled with STATIC_MODULES enabled.
 *      restartpass : This is the password required to use the command restart.
 *                      This password, and the die password must be hashed with
 *                      MD5SUM.
 *      diepass     : This is the password required to use the command die.
 *      displaypass : This is the password required to use the command display.
 *      identity    : This is the unique identifier for the server, between
 *                    1 and 4095.
 */

/* The operator directive encompasses the following directives:
 *      name     : This is the userid of the operator.
 *      user     : This is the hostmask from which this operator can login.
 *      password : This is the password required to oper to this operator.
 *      class    : This is the connection class that this operator gets 
 *                 transferred to after entering above credentials.
 *      die      : This value determines whether the operator has access to the
 *                 die command. Enter yes or no.
 *      admin    : This value determines whether the operator is a Server Admin.
 *                 Enter yes or no.
 *      restart  : This value determines whether the operator has access to the 
 *                 restart command. Enter yes or no.
 *      sadmin   : This value determines whether the operator is a Services 
 *                 Admin. Enter yes or no.
 */

/* The class directive encompasses the following directives:
 *      number      : This is the number identifying this connection class.
 *      pingtime    : This the time after which the server will ping an inactive
 *                    user to determine whether the connection is still alive.
 *                    Enter a time unit.
 *      connectfreq : This is the time interval at which the server attempts to
 *                    establish a connection to servers bearing this class.
 *                    Enter 0 for client classes, a time unit for servers.
 *      max_links   : This is the maximum number of clients that will be allowed
 *                    to connect using this class.
 *      sendq       : This is the total bandwidth allocated to this class. The 
 *                    accepted format for this field is a number followed by 
 *                    either b, kb or mb.
 */

/* The auth directive encompasses the following directives:
 *      user         : The ident and hostmask that this auth directive applies
 *                     to.
 *      password     : If this directive is set this password has to be entered
 *                     via the PASS command to use this auth.
 *      spoof_notice : If this directive is set to yes, a notice will be sent
 *                     each time an operator uses hostmasking. Enter yes or no.
 *      spoof        : This is the address that is shown as the hostname of the
 *                     operator using hostmasking.
 *      exceed_limit : If this directive is set to yes, users connecting with 
 *                     this auth will be exempt from flood checks. Enter yes or
 *                     no.
 *      kline_exempt : If this directive is set to yes, users connecting with
 *                     this auth are unaffected by klines matching their hosts.
 *                     Enter yes or no.
 *      restricted   : If this directive is set to yes, users connecting with
 *                     this auth will not be oppable in channels. Enter yes or
 *                     no.
 *      redirserv    : If and when the class this auth uses is full, this server
 *                     is shown along with the port set in redirport.
 *      redirport    : If and when the class this auth uses is full, this port
 *                     is shown alongside redirserv.
 *      class        : This is the class this auth uses.
 */

/* The service directive encompasses the following directives:
 *      name       : This is the name of the service using this directive.
 *      host       : This is the hostname the service must have to be able to
 *                   connect through this service directive. Either one of host
 *                   or ip suffice for a service to connect.
 *      ip         : This is the IP address the service must have to be able to
 *                   connect through this service directive. Either one of IP or
 *                   host suffice for a service to connect.
 *      password   : This is the password the service must use during connection
 *                   to be allowed to connect.
 *      ultimate   : This determines whether the service is given U-line
 *                   privileges. Enter yes or no.
 *      send_akill : This determines whether the service can create Akills. 
 *                   Enter yes or no.
 *      class      : This determines the connection class this directive uses.
 */

EOC

fi

while read FA FB FC FD FE FF FG; do

   FB="`echo "$FB" | sed -e 's/ /\ /g'`"
   FC="`echo "$FC" | sed -e 's/ /\ /g'`"
   FD="`echo "$FD" | sed -e 's/ /\ /g'`"
   FE="`echo "$FE" | sed -e 's/ /\ /g'`"
   FF="`echo "$FF" | sed -e 's/ /\ /g'`"
   FG="`echo "$FG" | sed -e 's/ /\ /g'`"

   case "$FA" in

	M)
		echo "serverinfo {" >> $O
		echo "    name = \"$FB\";" >> $O
		echo "    description = \"$FD\";" >> $O
		echo "    networkname = \"TestNet\";" >> $O
		echo "    networkdesc = \"$FD\";" >> $O
		echo "    address = \"$FC\";" >> $O
		echo "     " >> $O
		echo "    /* address6 = \"::1\"; */" >> $O
		echo "     " >> $O
		echo "    restartpass = \"$restartpass\";" >> $O
                echo "    diepass = \"$diepass\";" >> $O
                echo "    displaypass = \"$displaypass\";" >> $O
		echo "    identity = $FE; /* This is not a port */" >> $O
		echo "    aliasname = \"$FB\";" >> $O
		echo "    servermode = native;" >> $O
		echo "};" >> $O
		echo "     " >> $O
		;;
	A)	echo "admin {" >> $O
		echo "    name = \"$FB\";" >> $O
		echo "    description = \"$FC\";" >> $O
		echo "    email = \"$FD\";" >> $O
		echo "};" >> $O
		echo "     " >> $O
		;;
	Y)
		echo "class {" >> $O
		echo "    class = $FB;" >> $O
		echo "    pingtime = $FC;" >> $O
		echo "    connectfreq = $FD;" >> $O
		echo "    max_links = $FE;" >> $O
		echo "    sendq = $FF bytes;" >> $O
		echo "};" >> $O
		echo "     " >> $O
		;;

	I)	
		echo "auth {" >> $O
		echo "    user = \"$FB\";" >> $O
		echo "    class = $FF;" >> $O

		if [ "x$FE" != "x*" ] ; then
			echo "    port = $FE;" >> $O
                	echo "     " >> $O
                	echo "    /* spoof = \"staff.trircd.net\";" >> $O
                	echo "     * spoof_notice = yes;" >> $O
                	echo "     *" >> $O
                	echo "     * restriced = no;" >> $O
                	echo "     * redirserv = \"other.trircd.net\";" >> $O
                	echo "     * redirport = 6667;" >> $O
                	echo "     */" >> $O
		fi
		if [ "x$FC" != "x*" ] ; then
		    if [ "y$FC" != "yoper." ] ; then
			echo "    password = \"`$hashutil $FC | sed -e 's/Encryption\ is\:\ //g'`\";" >> $O
		    else
                        echo "     " >> $O
                        echo "    /* password = \"testpass\"; Must use ircpasswd */" >> $O
		    fi
		fi
		echo "};" >> $O
		echo "     " >> $O
		;;
        E)
                echo "auth {" >> $O
                echo "    user = \"$FD@$FB\";" >> $O
                echo "    class = 1;" >> $O
		echo "    exceed_limit = yes;" >> $O
                echo "};" >> $O                      
                echo "     " >> $O
                ;;
        F)
                echo "auth {" >> $O
                echo "    user = \"$FD@$FB\";" >> $O
                echo "    class = 1;" >> $O   
                echo "    exceed_limit = yes;" >> $O
		echo "    kline_exempt = yes;" >> $O
                echo "};" >> $O                      
                echo "     " >> $O
                ;;
	O)
		echo "operator {" >> $O
		echo "    name = \"$FD\";" >> $O
		if [ "x$FB" != "x*" ] ; then
			echo "    user = \"$FB\";" >> $O
		else
			echo "    user = \"*@*\";" >> $O
		fi
		echo "    password = \"$FC\";" >> $O
		echo "    class = $FF;" >> $O
		if [ "x`echo $FE | sed -e s/.*a.*//g`" != "x" ] ; then
			echo "    sadmin = no;" >> $O
		else
			echo "    sadmin = yes;" >> $O
		fi
                if [ "x`echo $FE | sed -e s/.*A.*//g`" != "x" ] ; then
                        echo "    admin = no;" >> $O 
                else
                        echo "    admin = yes;" >> $O 
                fi
                if [ "x`echo $FE | sed -e s/.*R.*//g`" != "x" ] ; then
                        echo "    restart = no;" >> $O 
                else
                        echo "    restart = yes;" >> $O 
                fi
                if [ "x`echo $FE | sed -e s/.*D.*//g`" != "x" ] ; then
                        echo "    die = no;" >> $O 
                else
                        echo "    die = yes;" >> $O 
                fi
		echo "};" >> $O
		echo "     " >> $O
		;;
	Q)
		if [ "$used_qlines" == "0" ] ; then
			echo "# Q:Line (Quarantines) Configuration file" > $QLINES
			echo "  " >> $QLINES
			used_qlines=1
		fi
		echo "Q::$FC:$FD" | sed -e 's/_/\ /g' >> $QLINES
		;;
        J)
                if [ "$used_jlines" == "0" ] ; then
                        echo "# J:Line (Channel Quarantines) Configuration file" > $JLINES
                        echo "  " >> $JLINES
                        used_jlines=1
                fi
                echo "J::$FC:$FD" | sed -e 's/_/\ /g' >> $JLINES
                ;;
        G)
                if [ "$used_glines" == "0" ] ; then
                        echo "# G:Line (Real Name Ban) Configuration file" > $GLINES
                        echo "  " >> $GLINES
                        used_glines=1
                fi   
                echo "G::$FC:$FD" | sed -e 's/_/\ /g' >> $GLINES
                ;;
        K)
                if [ "$used_klines" == "0" ] ; then
                        echo "# K:Line (Kill Lines) Configuration file" > $KLINES
                        echo "  " >> $KLINES
                        used_klines=1
                fi   
                echo "K:$FB:$FC:$FD" | sed -e 's/_/\ /g' >> $KLINES
                ;;
        H)
		hub_elements[$hub_count]="$FD"
		hub_count=$((hub_count+1))
                echo "H:*::$FD" >> $UNDOCUMENTED
                ;;
        U)
                ultimate_elements[$ultimate_count]="$FB"
                ultimate_count=$((ultimate_count+1))
                echo "U:$FB:*:*" >> $UNDOCUMENTED
                ;;
	S)
		echo "service {" >> $O
		echo "    name = \"$FD\";" >> $O
		echo "    ip = \"$FB\";" >> $O
		echo "    password = \"`$hashutil $FC | sed -e 's/Encryption\ is\:\ //g'`\";" >> $O
		echo "    class = $FF;" >> $O
                if [ "x`echo $FE | sed -e s/.*U.*//g`" != "x" ] ; then
                        echo "    ultimate = no;" >> $O 
                else
                        echo "    ultimate = yes;" >> $O 
                fi
                if [ "x`echo $FE | sed -e s/.*A.*//g`" != "x" ] ; then
                        echo "    send_akill = no;" >> $O 
                else
                        echo "    send_akill = yes;" >> $O 
                fi
		echo "};" >> $O
		echo "     " >> $O
		;;
	P)
		listen_elements[$listen_count]="$FC"
		listen_count=$((listen_count+1))
		listen_elements[$listen_count]=$FE
		listen_count=$((listen_count+1))
		;;
	C)
		connect_name[$connect_amount]="$FD"
		connect_host[$connect_amount]="$FB"
		connect_sendpass[$connect_amount]="$FC"
		connect_port[$connect_amount]=$FE
		connect_class[$connect_amount]=$FF
		connect_amount=$((connect_amount+1))
		;;
	T)
		proxy_host="$FB"
		proxy_url="$FC"
		;;
	*)
		;;
   esac

done < $ELEMENT

while read FA FB FC FD; do        

   case "$FA" in
        N)
                tempvar=0
                while (($tempvar<$connect_amount)) ; do
                        if [ "${connect_name[$tempvar]}" == "$FD" ] ; then
                                connect_flags[$tempvar]="$FE"
                                connect_recvpass[$tempvar]="$FC"
                        fi
                        tempvar=$((tempvar+1))
                done
                ;;
        *)        
                ;;
   esac      

done < $ELEMENT

rm -f $ELEMENT 

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The serverhide directive encompasses the following directives:
 *      enable          : This enables whether server hiding is enabled. Enter
 *                        yes or no.
 *      flatten_links   : If this is set to yes all servers in a links request
 *                        will be shown as connected to this server. Enter yes
 *                        or no.
 *      links_from_file : If this is set to yes, the links information is read
 *                        from the etc/ircd.links file. Enter yes or no.
 *      links_oper_only : This directive restricts the links command to IRC
 *                        operators. Enter yes or no.
 *      links_delay     : The amount of time the event manager uses to write
 *                        down the links file.
 *      
 */

EOC

fi

cat >> $O << EOC

serverhide {
    enable = no;
    flatten_links = no;
    links_from_file = no;
    links_oper_only = no;
    links_delay = 2 hours;
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The serveropts directive encompasses the following directives:
 *      ts_warn_delta                : This is the maximum lag between two 
 *                                     servers before a warning is given. This 
 *                                     value should be in seconds.
 *      ts_max_delta                 : This is the maximum lag allowed between
 *                                     two servers that are to be linked. This
 *                                     value should be in seconds.
 *      language                     : This is the default language a user sees
 *                                     on connecting. Only language names
 *                                     defined in the language extension files
 *                                     and "english" are valid.
 *      save_maxclient_stats         : If this value is set to yes, the server
 *                                     retains the peak number of users. Enter
 *                                     yes or no.
 *      save_maxclient_stats_time    : If this value is set to yes, the server
 *                                     retains the date the peak number of
 *                                     users was reached. Enter yes or no.
 *      use_registerfilter           : If this value is set to yes, each user
 *                                     gets the mode +R upon login. Enter yes or
 *                                     no.
 *      use_short_motd               : This determines whether the shor form of
 *                                     the motd is shown to users on
 *                                     connection. Enter yes or no.
 *      hub                          : This determines whether this server
 *                                     should act as a hub in the network.
 *                                     Enter yes or no.
 */

EOC

fi

cat >> $O << EOC 

serveropts {
    ts_warn_delta = 12 minutes;
    ts_max_delta = 1 minute;
    save_maxclient_stats = yes;
    save_maxclient_stats_time =  1 hour;
    havent_read_conf = yes;
    use_registerfilter = no;
    use_short_motd = no;
    hub = yes;
#    language = "english";
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The connect_control directive encompasses the following directives:
 *      default_kline_time           : This value is used whenever a kline does
 *                                     not have the time attribute set. This
 *                                     value should be a time unit.
 *      server_kline_address         : This value will be shown to anyone who
 *                                     has been klined locally as the email
 *                                     address to apply to. Please enter a
 *                                     valid email address.
 *      network_kline_address        : This value will be shon to anyone who
 *                                     has been klined from the network. This
 *                                     value should correspond with the value
 *                                     used by every other server in the
 *                                     network and should be a valid email
 *                                     address.
 *      wingate_notice               : If this is set to yes, users get a 
 *                                     warning that they will be scanned by the
 *                                     address specified in monitor_host upon
 *                                     login. Enter yes or no.
 *      monitor_host                 : This value should correspond to your 
 *                                     proxy control host if wingate_notice is
 *                                     set to yes. 
 *      monitor_url                  : This value should point to an URL
 *                                     where you describe your networks policy
 *                                     about the usage of irc proxies.
 *      throttle_time                : This is the time that has to pass before
 *                                     the server will allow a second connection
 *                                     from the same host. Enter a time unit.
 *      throttle_count               : This is the maximum number of connections that
 *                                     will be allowed to connect before getting
 *                                     throttled.
 *      identd_use_tilde             : Setting this to yes uses the tilde ~ symbol for
 *                                     users without a proper identd reply.   
 *      identd_complain              : If this value is set to yes, users 
 *                                     without proper identd authentification
 *                                     get a message telling them to install 
 *                                     identd. Enter yes or no.
 *      identd_timeout               : This value determines how long the server should
 *                                     wait for an identd connection.
 *      havent_read_conf             : If this directive is encountered, the
 *                                     server does not start. Delete it.
 */

EOC

fi

cat >> $O << EOC

connect_control {
    default_kline_time = 30 seconds;
    server_kline_address = "kline@local.tile.net";
    network_kline_address = "kline@time.net";
    wingate_notice = yes;
    monitor_host = "`echo "$proxy_host"`";
    monitor_url = "`echo "$proxy_url"`";
    identd_use_tilde = no;
    identd_complain = no;
    identd_timeout = 30 seconds;
    throttle_time = 30 seconds;
    throttle_count = 10;
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The flood_control directive encompasses the following directives:
 *      floodcontrol                 : This value sets the max number of lines           
 *                                     per second a client can send to a channel
 *                                     or user user before the following lines 
 *                                     will be throttled due to flood. 
 *                                     It is a number.
 *      motd_wait                    : This value denotes the amount of time
 *                                     which has to pass before using the motd
 *                                     command more than the number set in 
 *                                     motd_max. This value should be in
 *                                     seconds.
 *      motd_max                     : This is the maximum number of motd
 *                                     attempts that will be answered by the 
 *                                     server in the time specified by
 *                                     motd_wait.
 *      client_flood                 : This is the number of bytes that a client
 *                                     may send in one second before it will
 *                                     be disconnected for flooding.
 *      no_oper_flood                : If this is set to no, opers are included
 *                                     in flood checks. Enter yes or no. 
 *      anti_nick_flood              : This determines whether rapid nick
 *                                     changes constitute a flood. Enter yes or
 *                                     no.
 *      max_nick_time                : If anti_nick_flood is set to yes, this
 *                                     value denotes the amount of time which
 *                                     has to pass before using the nick
 *                                     command more than the number set in
 *                                     max_nick_changes. This value should be
 *                                     in seconds.
 *      max_nick_changes             : If anti_nick_flood is set to yes, this
 *                                     is the maximum number of nick change
 *                                     attempts that will be allowed by the
 *                                     server in the time specified by
 *                                     max_nick_time.
 *      no_away_flood                : This determines whether rapid away 
 *                                     changes constitute a flood. Enter yes or
 *                                     no.
 *      max_away_time                : If no_away_flood is set to yes, this
 *                                     value denotes the amount of time which
 *                                     has to pass before using the away
 *                                     command more than the number set in
 *                                     max_away_count. This value should be
 *                                     in seconds.
 *      max_away_count               : If no_away_flood is set to yes, this  
 *                                     is the maximum number of away uses that
 *                                     will be allowed by the server in the     
 *                                     time specified by max_away_count.
 *      anti_spambot                 : This value determines whether join and 
 *                                     part floods should be detected. Enter yes
 *                                     or no.
 *      min_join_leave_time          : This is the amount of time in which a  
 *                                     client is evaluated for spambot
 *                                     candidacy. Enter a time unit.
 *      min_join_leave_count         : This is the number of join or part
 *                                     commands that are enough for a client to
 *                                     be considered a spambot if executed
 *                                     within the period set in
 *                                     min_join_leave_time. Enter a positive 
 *                                     number.
 *      join_leave_count_expire_time : This is the amount of time in which a
 *                                     spambot is ignored by the server after
 *                                     exceeding the limits set by prior   
 *                                     directives. Enter a time unit.
 *      oper_spam_countdown          : The number of join & part attempts the
 *                                     server allows before sending a message  
 *                                     to &SPAMBOTS about the client.
 *      havent_read_conf             : If this directive is encountered, the 
 *                                     server does not start. Delete it.   
 */

EOC

fi

cat >> $O << EOC

flood_control {
    floodcontrol = 10;
    motd_wait = 10 seconds;
    motd_max = 3;
    client_flood = 2560 ;
    no_oper_flood = yes;
    anti_nick_flood = yes ;
    max_nick_time = 20 seconds;
    max_nick_changes = 5 ;
    no_away_flood = yes;
    max_away_time = 3 minutes;
    havent_read_conf = yes;
    max_away_count = 5;
    anti_spambot = yes;
    min_join_leave_time = 1 minute;
    max_join_leave_count = 25;
    join_leave_count_expire_time = 2 minutes;
    oper_spam_countdown = 5;
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The operator_options directive encompasses the following directives:
 *      use_remoteconnect            : If this value is set to yes, operators
 *                                     can observe remote connections from the
 *                                     &CONNECTS channel. Enter yes or no.
 *      staffhide                    : This determines whether operators get
 *                                     fakehosts. Enter yes or no.
 *      staff_fakehost               : This is the fakehost that opers get if
 *                                     staffhide is set to yes.
 *      opers_can_choose_fakehost    : If this value is set to yes, operators
 *                                     can choose their own fakehosts upon
 *                                     login. Enter yes or no.
 *      dont_check_remote_qline      : If this value is set to yes, the server
 *                                     checks local qlines against remote
 *                                     connects and issues a warning if a 
 *                                     locally qlined nick is introduced
 *                                     remotely. Enter yes or no.
 *      no_oper_jupiter              : If this value is set to yes, operators
 *                                     cannot use the jupiter command directly.
 *                                     Enter yes or no.
 *      havent_read_conf             : If this directive is encountered, the
 *                                     server does not start. Delete it.
 */

EOC

fi

cat >> $O << EOC

operator_options {
    use_remoteconnect = yes;
    dont_check_remote_qline = no;
    staff_fakehost = "staff.time.net";
    staffhide = yes;
    opers_can_choose_fakehost = yes;
    no_oper_jupiter = yes;
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The servicesconf directive encompasses the following directives:
 *      operserv_other_host : If operserv is to have a different address than
 *                            the rest of services, enter it here.
 *      chanserv_name       : Set this to the nick of ChanServ in your network.
 *      nickserv_name       : Set this to the nick of NickServ in your network.
 *      operserv_name       : Set this to the nick of OperServ in your network.
 *      memoserv_name       : Set this to the nick of MemoServ in your network.
 *      statserv_name       : Set this to the nick of StatServ in your network.
 *	nickserv_name	    : Set this to the nick of HelpServ in your network.
 *      services_name       : Set this to the address of Services.
 *      hide_ulined_servers : Set this to yes to hide the server name of 
 *                            U-lined clients. Enter yes or no.
 */

EOC

fi

cat >> $O << EOC

servicesconf {
    operserv_other_host = "services.tr";
    chanserv_name = "ChanServ";
    nickserv_name = "NickServ";
    operserv_name = "Haydar";
    memoserv_name = "MemoServ";
    statserv_name = "StatServ";
    helpserv_name = "HelpServ";
    services_name = "services.tr";
    hide_ulined_servers = yes;
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The channelconf directive encompasses the following directives:
 *      moderated_hosts  : If this value is set to yes, the chanmode +M may be
 *                         used to impose host based moderating in channels.
 *                         Enter yes or no.
 *      channelname_bans : If this value is set to yes, users may be denied 
 *                         entry to a channel based on what other channels they
 *                         are on. Enter yes or no.
 *      halfops      : This enables or disables halfops. Enter yes or no.
 *      floodmode    : This enables or disables the flood mode +f.
 *                     Enter yes or no.
 *                     This is only functional, if floodcontrol directive
 *                     has also a positive value.
 *      max_channels_per_user    : The maximum amount of channels a user   
 *                     may join.
 *      default_quit_msg         : This is the message shown when a user
 *                     quits without message.
 */
 
EOC

fi

cat >> $O << EOC

channelconf {
    moderated_hosts = no;
    channelname_bans = no;
    halfops = yes;
    floodmode = no;
    max_channels_per_user = 10 ;
    default_quit_message = "timenet - where time stops";
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The modules directive encompasses the following directives:
 *      module : This directive facilitates the loading of additional modules,
 *           allowing additional functionality without having to go to 
 *           great lengths. Enter the name of the file containing the
 *           module.
 *      path   : Modules added with the module directive are searched for in
 *           MODPATH, LANGPATH and this directory.
 */

EOC

fi

cat >> $O << EOC
 
modules {
    path = "/home/ircd/lib/contrib";
    module = "m_locops.so";
};

EOC

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The connect directive encompasses the following directives:
 *      name        : This is the name expected of the connecting server.
 *      host        : This is the actual hostname of the server expected.
 *      send_password   : This is the password sent to the server as part of the
 *            handshake. This must correspond to the accept_password
 *            of the server to which the connection will be
 *            established.
 *      accept_password : This is the password the other server is expected to
 *            send as part of the handshake.
 *      encrypted       : This determines whether data transfer between the 
 *            servers is encrypted. Please note that encryption via
 *            RC4 is a CPU intensive operation. Enter yes or no.
 *      compressed      : This determines whether data transfer between the
 *            servers is compressed. Enter yes or no.
 *      autoconnect     : If this directive is set to yes, the server tries to
 *            automatically connect to this server as set in the 
 *            class directive. Enter yes or no.
 *      ishub       : This determines whether the other server is accepted
 *            as a hub by this server. Enter yes or no.
 *      aftype      : This determines if the connection is made with IPv4
 *            or IPv6 interfaces. Enter ipv6 or ipv4.
 *      class       : This is the class used by this connect directive.
 *      ultimate    : This determines whether the other server is accepted
 *            as a U-Lined server by this server. Enter yes or no.
 */

EOC

fi

while (($connect_amount>0)) ; do

	this_hub=0
	this_ultimate=0

	connect_amount=$((connect_amount-1))
	echo "    " >> $O
	echo "connect {" >> $O
	echo "     name = \"${connect_name[$connect_amount]}\";" >> $O
	echo "     host = \"${connect_host[$connect_amount]}\";" >> $O
	echo "     send_password = \"${connect_sendpass[$connect_amount]}\";" >> $O
	echo "     accept_password = \"`$hashutil ${connect_recvpass[$connect_amount]} | sed -e 's/Encryption\ is\:\ //g'`\";" >> $O
	if [ "x${connect_port[$connect_amount]}" != "x*" ] ; then
		echo "     port = ${connect_port[$connect_amount]};" >> $O
	fi
	echo "     class = ${connect_class[$connect_amount]};" >> $O
	echo "     aftype = ipv4;" >> $O     
	echo "     autoconnect = yes;" >> $O
	tempvar=0
	while (($tempvar<$hub_count)) ; do
		if [ "${connect_name[$connect_amount]}" == "${hub_elements[$tempvar]}" ] ; then
			echo "     ishub = yes;" >> $O
			this_hub=1
		fi
		tempvar=$((tempvar+1))
	done
	if [ "x$this_hub" == "x0" ] ; then
		echo "     ishub = no;" >> $O
	fi
    tempvar=0
    while (($tempvar<$ultimate_count)) ; do
        if [ "${connect_name[$connect_amount]}" == "${ultimate_elements[$tempvar]}" ] ; then
            echo "     ultimate = yes;" >> $O
			this_ultimate=1
        fi
        tempvar=$((tempvar+1))
    done
    if [ "x$this_ultimate" == "x0" ] ; then 
        echo "     ultimate = no;" >> $O
    fi
    if [ "x`echo ${connect_flags[$connect_amount]} | sed -e s/.*E.*//g`" != "x" ] ; then
    	echo "     encrypted = no;" >> $O       
    else
        echo "     encrypted = yes;" >> $O       
    fi	
    if [ "x`echo ${connect_flags[$connect_amount]} | sed -e s/.*Z.*//g`" != "x" ] ; then          
        echo "     compressed = no;" >> $O              
    else    
        echo "     compressed = yes;" >> $O          
    fi   
	echo "};" >> $O
	echo "    " >> $O
done

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The listen directive encompasses subsections, which include following directives:
 *      port : This directive lists the ports the server listens on.
 *         The format accepted by this directive is a list of port numbers
 *         or port ranges separated by commas (,). A port range consists of
 *         the lower port separated by two dots (..) from the higher port.
 *      ip   : This is the IP the server listens for the ports listed in the 
 *         subsection. If this and the next directive are not entered, the 
 *         ports listed
 *         are bound to all interfaces of the server.
 *      host : This is the hostname the server listens for the ports listed
 *         in the subsection. If this and the previous directive are not 
 *         entered, the ports listed are bound to all interfaces of the server.
 */

EOC

fi

echo "listen {" >> $O
while (($lcount<$listen_count)) ; do
	echo "    {" >> $O
	if [ "x${listen_elements[$lcount]}" != "x*" ] ; then
		echo "    ip = \"${listen_elements[$lcount]}\";" >> $O
	fi
	lcount=$((lcount+1))
	echo "    port = ${listen_elements[$lcount]};" >> $O
	echo "    };" >> $O
	lcount=$((lcount+1))
done
echo "};" >> $O
echo "    " >> $O

if [ "x$expanded" != "x0" ] ; then

cat >> $O << EOC

/* The files directive encompasses the following directive:
 *      load : This directive facilitates the loading of additional, old style
 *         configuration files. Such files are used to keep the main
 *         configuration file clean of repetitive lines such as the kline.
 */

EOC

fi

echo "files {" >> $O

# KLINE file is not added, since it is opened by the ircd itself.

if [ "x$used_qlines" != "x0" ] ; then
    echo "     load = \"$QLINES\";" >> $O
fi
if [ "x$used_glines" != "x0" ] ; then
    echo "     load = \"$GLINES\";" >> $O
fi
if [ "x$used_jlines" != "x0" ] ; then
    echo "     load = \"$JLINES\";" >> $O
fi
if [ "x$hub_count" != "x0" -o "x$ultimate_count" != "x0" ] ; then
    echo "     load = \"$UNDOCUMENTED\";" >> $O
fi
echo "};" >> $O
echo "     " >> $O

echo "# TR-IRCD 5.0 Configuration File" >> $O
echo "# Created automatically by converter.sh" >> $O
echo "# TR-IRCD 5.0 and converter.sh are Copyright (c) 2002" >> $O
echo "#  " >> $O
echo "# TR-IRCD Development Team" >> $O
echo "   " >> $O
