#!/bin/bash
function askPass {
	while true; do
		echo -n "Password:"
		read -s password
		echo ""
		echo -n "Confirm password:"
		read -s confirm
		echo ""
		if [ "$password" == "$confirm" ]; then
			oPass=$password
			break;
		fi
		echo "Error : Password and Confirm password are not same"
	done
}

function valid_ip {
    local  ip=$1
    local  stat=1

    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        OIFS=$IFS
        IFS='.'
        ip=($ip)
        IFS=$OIFS
        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
            && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
        stat=$?
    fi
    return $stat
}

function valid_mask {
   echo $1 | grep -w -E -o '^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)' > /dev/null
	return $?
}

function valid_mail {
   echo $1 | grep -w -E -o '^.+@[^\.]+\.+.*[^\.]+$' > /dev/null
   return $?
}

function valid_int {
	echo $1 | grep -w -E -o '^[[:digit:]]+$' > /dev/null
	return $?
}

function validate_ifaces {
	sysIfaces=$(ip -o link show|grep -v  LOOPBACK|cut -d':' -f2|tr -d " ")
        if [ -z "$oIface" ]; then
                sysIfaces=$(echo ${sysIfaces[*]}|tr ' ' ',')
                echo "-i, --iface param must be set to ($sysIfaces)"; print_net_usage; exit 1
        fi
        for iface in $sysIfaces
        do
                if [ "$iface" == "$oIface" ]; then
                        savingIface=$oIface
                fi
        done
        if [ -z "$savingIface" ]; then
                sysIfaces=$(echo ${sysIfaces[*]}|tr ' ' ',')
                echo "-i, --iface $oIface doesn't exist. Param must be set to ($sysIfaces)"; print_net_usage; exit 1
        fi
}

function netConf {
	oMode=$( echo $oMode | tr '[:upper:]' '[:lower:]' )
	rm -f /tmp/netif.new 2>&1 > /dev/null
	rm -f /tmp/resolv.conf 2>&1 > /dev/null

	if [ -z "$oMode" ]; then
		echo "-M, --Mode is empty. Must be set to (static or dhcp)"; print_net_usage; exit 1
	elif [ "$oMode" == "dhcp" -o "$oMode" == "auto" ]; then
		validate_ifaces
		generate-interfaces.pl -i $oIface > /tmp/netif.new
	elif [ "$oMode" == "static" ]; then
		netifChanges=false
		netifParams="-i $oIface"
	        if [ -n "$oAddress" ]; then
			validate_ifaces
			if [ -z "$oMask" ]; then
				echo "-m, --mask $oMask not set."; print_net_usage; exit 1
			fi

			valid_ip $oAddress
			if [[ $? -ne 0 ]]; then
				echo "-a, --address $oAddress isn't a correct IPv4 address"; exit 1
			fi

			netifParams="$netifParams -a $oAddress -m $oMask"
			netifChanges=true
                fi
                if [ -n "$oGateway" ]; then
			validate_ifaces
			valid_ip $oGateway
			if [[ $? -ne 0 ]]; then
				echo "-g, --gateway $oGateway isn't a correct IPv4 address"; exit 1
			fi
			netifParams="$netifParams -g $oGateway"
			netifChange=true
                fi
		if [ $netifChanges ]; then
			generate-interfaces.pl $netifParams > /tmp/netif.new
		fi
		if [ -n "$oNameservers" ]; then
			resolvconf=$(cat /etc/resolv.conf | egrep "domain|search"|tr "\n" "|")
			echo -n $resolvconf |tr "|" "\n" > /tmp/resolv.conf

			for ns in $(echo $oNameservers |tr ',' ' ')
			do
				valid_ip $ns
				if [[ $? -ne 0 ]]; then
					echo "-n, --nameservers $oNameservers invalid. $ns isn't a correct IPv4 address"; exit 1
				fi
				echo nameserver $ns >> /tmp/resolv.conf
			done
		fi
	else
		echo "-M, --Mode $oMode must be set to (static or dhcp)"; print_net_usage; exit 1
	fi

	if [ "$oYes" = false ]; then
		echo "#Generate configuration is :"
		if [ -f /tmp/netif.new ]; then
			echo "##For /etc/network/interfaces"
			cat /tmp/netif.new
		fi
		echo ""
		if [ -f /tmp/resolv.conf ]; then
                        echo "##For /etc/resolv.conf"
                        cat /tmp/resolv.conf
                fi
		echo
		while true; do
			echo "#If you apply, your ssh connection could be lost"
			read -p "#Do you wish to apply this ? (y,n) " yn
				case $yn in
				[Yy]* ) oYes=true; break;;
				[Nn]* ) break;;
				* ) echo "Please answer yes or no.";
			esac
		done
	fi

	if [ "$oYes" = true ]; then
		mv /tmp/netif.new /etc/network/interfaces 2>/dev/null
		mv /tmp/resolv.conf /etc/resolv.conf	  2>/dev/null
		service networking restart && exit 0
		exit 1
	else
		rm -f /tmp/netif.new 2>&1 > /dev/null
		rm -f /tmp/resolv.conf 2>&1 > /dev/null
	fi
}

function userConf {
	oAction=$( echo $oAction | tr '[:upper:]' '[:lower:]' )
	if [ -z "$oAction" ]; then
                echo "-A, --action is empty. Must be set to (list, show, update, delete or add)"; print_user_usage; exit 1
	fi

	if [ $oAction == "list" ]; then
		rootGroupID=$(psql -tA -h localhost -d esia -U esia -c "SELECT group_id from esia_groups WHERE group_name='root'";)
		rootUsers=$(psql -tA -h localhost -d esia -U esia -c "SELECT user_name FROM esia_users WHERE user_id IN(SELECT member_user_id FROM esia_memberof WHERE member_group_id=$rootGroupID)"|tr "\n" " ")
                noneRootUsers=$(psql -tA -h localhost -d esia -U esia -c "SELECT user_name FROM esia_users WHERE user_id NOT IN(SELECT member_user_id FROM esia_memberof WHERE member_group_id=$rootGroupID)"|tr "\n" " ")
                echo "root users : $rootUsers"
                echo "other users : $noneRootUsers"
                exit 0
	else
                user=$(psql -At -h localhost -d esia -U esia -c "SELECT user_id,user_name,user_inscription_time,user_email FROM esia_users WHERE user_name='$oUser'";)
                if [ -z "$user" -a $oAction != 'add' ]; then
                        echo "-u, --user '$oUser' not found"; exit 1
                fi
		if [ $oAction == "show" ]; then
                        echo -n "Login : "; echo $user|cut -d'|' -f2
                        echo -n "MakeTime : "; echo $user|cut -d'|' -f3
                        echo -n "Mail : "; echo $user|cut -d'|' -f4
                        exit 0
		elif [ $oAction == "add" ]; then
			if [ -z "$oMail" ]; then
				echo "-e, --mail is empty, must be set for adding user"; print_user_usage; exit 1
			fi
			if [ -z "$oPass" ]; then
				echo "-p, --pass is empty, must be set for adding user"; print_user_usage; exit 1
			fi
			datenow=$(psql -At -h localhost -d esia -U esia -c "SELECT now()"|cut -d'+' -f1);
			sha1=$(echo -nE "$oUser$oPass$datenow"|sha1sum |cut -d' ' -f1)
			rootGroupID=$(psql -tA -h localhost -d esia -U esia -c "SELECT group_id from esia_groups WHERE group_name='root'";)
			rootUserID="(SELECT user_id FROM esia_users WHERE user_name='$oUser')";
			sql="INSERT INTO esia_users (user_name,user_password,user_inscription_time,user_email) VALUES ('$oUser','$sha1','$datenow','$oMail')"
			sql="$sql;INSERT INTO esia_memberof (member_group_id,member_user_id) VALUES ($rootGroupID,$rootUserID)"
			confirm_msg="Do you want to add user $oUser,$oMail with root permissions"
		else
			userid=$(echo $user|cut -d'|' -f1)
			if [ $oAction == "delete" ]; then
				sql="DELETE FROM esia_users WHERE user_id=$userid"
				confirm_msg="Do you want to delete user '$user'"
			elif [ $oAction == "update" ]; then
				params=''
				confirm_msg="Do you want to update user '$user' with "
				if [ -n "$oPass" ]; then
					maketime=$(echo $user|cut -d'|' -f3)
					sha1=$(echo -nE "$oUser$oPass$maketime"|sha1sum |cut -d' ' -f1)
					params="user_password='$sha1'"
					confirm_msg="$confirm_msg new password"
				fi
				if [ -n "$oMail" ]; then
					if [ -n "$params" ]; then
						params="$params AND "
						confirm_msg="$confirm_msg and"
					fi
					params="$params user_email='$oMail'"
					confirm_msg="$confirm_msg $oMail"
				fi
				if [ -z "$params" ]; then
					echo "-A, --action '$oAction' must be used with mail and/or pass settings"; print_user_usage; exit 1
				fi
				sql="UPDATE esia_users SET $params WHERE user_id=$userid";
			else
				echo "-A, --action can't be set to '$oAction'. Must be set to (list, show, update, delete or add)"; print_user_usage; exit 1
			fi
		fi
	fi

	if [ "$oYes" = false ]; then
                while true; do
                        echo "$confirm_msg"
                        read -p "Do you wish to apply this ? (y,n) " yn
                                case $yn in
                                [Yy]* ) oYes=true; break;;
                                [Nn]* ) break;;
                                * ) echo "Please answer yes or no.";
                        esac
                done
        fi

        if [ "$oYes" = true ]; then
		files=$SCRIPT
		echo "$sql;" > /tmp/$files.sql
		psql -d esia -U esia -h localhost -f /tmp/$files.sql 1>/dev/null 2>/tmp/$files.err
		nb_errors=$(wc -l /tmp/$files.err|cut -d' ' -f1)
		if [ "$nb_errors" -ne 0 ]; then
			echo "Error to execute request. See /tmp/$files.sql and /tmp/$files.err for more details"; exit 1
		else
                        rm /tmp/$files.err 2> /dev/null
			rm /tmp/$files.sql 2> /dev/null
		fi
	fi
}

function mailConf {
	files=$SCRIPT
	CONFIG_KEYS="'MAIL_FROM','MAIL_SMTP','MAIL_SMTP_PORT','MAIL_USER','MAIL_PASSWORD'"
	sql="SELECT config_key,COALESCE(config_value,'NULL') FROM esia_configuration WHERE config_key IN ($CONFIG_KEYS)"
	db_result=$(psql -At -h localhost -d esia -U esia -c "$sql")

	db_from=$(echo $db_result|tr " " "\n"|grep "MAIL_FROM|"|cut -d'|' -f2)
	db_relayhost=$(echo $db_result|tr " " "\n"|grep "MAIL_SMTP|"|cut -d'|' -f2)
	db_relayport=$(echo $db_result|tr " " "\n"|grep "MAIL_SMTP_PORT|"|cut -d'|' -f2)
	db_user=$(echo $db_result|tr " " "\n"|grep "MAIL_USER|"|cut -d'|' -f2)
	db_pass=$(echo $db_result|tr " " "\n"|grep "MAIL_PASSWORD|"|cut -d'|' -f2)

	if [ "$oAction" = "show" ]; then
		if [ -n "$db_pass" ] && [ $db_pass != 'NULL' ]; then
			db_pass="****"
		fi
		echo "esia-configure -S mail -u $db_user -p $db_pass -r $db_relayhost:$db_relayport -f $db_from"
		exit 1
	fi

	changes=''
	echo -n "" > /tmp/$files.sql
	if [ -n "$oFrom" ]; then
                valid_mail $oFrom
                if [[ $? -ne 0 ]]; then
                         echo "-f, --form $oFrom isn't a correct mail format"; exit 1
                fi
                changes="$changes\nFrom $db_from changed => $oFrom"
		echo "UPDATE esia_configuration SET config_value='$oFrom' WHERE config_key='MAIL_FROM';" >> /tmp/$files.sql
        fi
	if [ -n "$oRelayhost" ]; then
		echo "$oRelayhost" |grep ':' > /dev/null
		if [ $? -eq 0 ]; then
			rh=$(echo "$oRelayhost"|cut -d':' -f1)
			rp=$(echo "$oRelayhost"|cut -d':' -f2)
		else
			rh=$oRelayhost
		fi

                echo "UPDATE esia_configuration SET config_value='$rh' WHERE config_key='MAIL_SMTP';" >> /tmp/$files.sql

		if [ -n "$rp" ]; then
			valid_int $rp
			if [[ $? -ne 0 ]]; then
				echo "-r, --relayhost $oRelayhost has not a correct port value $rp"; exit 1
			fi
			changes="$changes\nRelayhost $db_relayhost:$db_relayport => $rh:$rp"
			echo "UPDATE esia_configuration SET config_value=$rp WHERE config_key='MAIL_SMTP_PORT';" >> /tmp/$files.sql

		else
			if [ -z "$db_relayport" ]; then
				changes="$changes\nRelayhost $db_relayhost:$db_relayport => $rh:25"
				echo "UPDATE esia_configuration SET config_value=25 WHERE config_key='MAIL_SMTP_PORT';" >> /tmp/$files.sql

			else
				changes="$changes\nRelayhost $db_relayhost:$db_relayport => $rh:$db_relayport"
				#no changes into DB for port
			fi
		fi
	fi
	if [ -n "$oUser" ]; then
		changes="$changes\nUser $db_user changed => $oUser"
		if [ "$oUser" == "NULL" ]; then
                	echo "UPDATE esia_configuration SET config_value=NULL WHERE config_key='MAIL_USER';" >> /tmp/$files.sql
		else
			echo "UPDATE esia_configuration SET config_value='$oUser' WHERE config_key='MAIL_USER';" >> /tmp/$files.sql
		fi
	fi
	if [ -n "$oPass" ]; then
		changes="$changes\nPass changed"
                if [ "$oPass" == "NULL" ]; then
			echo "UPDATE esia_configuration SET config_value=NULL WHERE config_key='MAIL_PASSWORD';" >> /tmp/$files.sql
		else
			echo "UPDATE esia_configuration SET config_value='$oPass' WHERE config_key='MAIL_PASSWORD';" >> /tmp/$files.sql
		fi
	fi
	if [ -z "$changes" ]; then
		echo "You haven't specify changes for esia mailing system"; print_mail_usage; exit 1
	fi

	if [ "$oYes" = false ]; then
                while true; do
                        echo -e "This settings will be set :\n$changes\n"
                        read -p "Do you wish to apply this ? (y,n) " yn
                                case $yn in
                                [Yy]* ) oYes=true; break;;
                                [Nn]* ) break;;
                                * ) echo "Please answer yes or no.";
                        esac
                done
        fi

        if [ "$oYes" = true ]; then
                psql -d esia -U esia -h localhost -f /tmp/$files.sql 1>/dev/null 2>/tmp/$files.err
                nb_errors=$(wc -l /tmp/$files.err|cut -d' ' -f1)
                if [ "$nb_errors" -ne 0 ]; then
                        echo "Error to execute request. See /tmp/$files.sql and /tmp/$files.err for more details"; exit 1
                else
			rm /tmp/$files.err 2> /dev/null
                        rm /tmp/$files.sql 2> /dev/null
                fi
        fi
}

function updConf {
	PKG=esia-auto-updates
	PKGS="esia-auto-updates esia-updates-critic"
	oAction=$( echo $oAction | tr '[:upper:]' '[:lower:]' )
	if [ -z "$oAction" ]; then
                echo "-A, --action is empty. Must be set to (enable or disable)"; print_updauto_usage; exit 1
        fi

	case $oAction in
		dis* )
			dpkg -l|tr -s " "|grep "ii $PKG " > /dev/null
			if [ "$?" -eq 1 ]; then
				if [ "$oYes" = false ]; then
					echo "Autoupdates already disabled"
				fi
				exit 0
			fi

			if [ "$oYes" = false ]; then
				while true; do
					echo -e "Do you want to disable auto-updates ?"
					read -p "Do you wish to apply this ? (y,n) " yn
					case $yn in
						[Yy]* ) break;;
						[Nn]* ) exit 0; break;;
						* ) echo "Please answer yes or no.";
					esac
				done
			fi

			apt-get remove $PKGS -y -qq 2>&1 >/dev/null;;
		en* )
			dpkg -l|tr -s " "|grep "ii i$PKG " > /dev/null
			if [ "$?" -eq 0 ]; then
                                if [ "$oYes" = false ]; then
                                        echo "Autoupdates already enabled"
                                fi
                                exit 0
                        fi


			if [ "$oYes" = false ]; then
                                while true; do
                                 echo -e "Do you want to enable auto-updates ?"
                                        read -p "Do you wish to apply this ? (y,n) " yn
                                        case $yn in
                                                [Yy]* ) break;;
                                                [Nn]* ) exit 0; break;;
                                        * ) echo "Please answer yes or no.";
                                        esac
                                done
                        fi

			if [ "$oYes" = false ]; then echo "00% Progress - connect to repositories"; fi
			apt-get update -qq 2>&1 >/dev/null
			if [ "$?" -ne 0 ]; then
				echo "Unable to connect to repositories"
				echo "You must check internet connection or apt-source.list to enable auto-updates"; exit 1
			fi
			if [ "$oYes" = false ]; then echo "33% Progress - download autoupdates process"; fi
			cd /var/cache/apt/archives
			apt-get download $PKGS -qq -y 2>&1 > /dev/null
			if [ "$?" -ne 0 ]; then
				cd $OLDPWD
				echo "Unable to download autoupdates from esia repositories"
                                echo "You must check internet connection or apt-source.list to enable auto-updates";
exit 1
                        fi
			cd $OLDPWD
			if [ "$oYes" = false ]; then echo "66% Progress - configure autoupdates process"; fi
			apt-get install $PKGS -qq -y 2>&1 > /dev/null
			if [ "$?" -ne 0 ]; then
				echo "Unable to setup autoupdates process"; exit 1:w

			fi
			if [ "$oYes" = false ]; then echo "Enable autoupdates terminated"; fi ;;
		* )
			echo "-A, --action Incorrect. Must be set to (enable or disable)";exit 1 ;;
	esac
}

function print_mail_usage {
	echo " usage: $SCRIPT -S mail [-u <user>] [-p <password] [-r <relayhost>:<port>] [-f <from>]"
	echo "        $SCRIPT -S mail -u NULL -p NULL [-r <relayhost>:<port>] [-f <from>]"
	echo "        $SCRIPT -S mail -A show"
}

function print_net_usage {
	echo " usage: $SCRIPT -S net -M [dhcp|static] [OPTIONS]"
	echo "        $SCRIPT --help"
	echo ""
	echo " exemples:"
	echo "        $SCRIPT -S net -M dhcp"
        echo "        $SCRIPT -S net -M static -i <iface> -a <address> -m <netmask>"
        echo "        $SCRIPT -S net -M static -g <gateway>"
        echo "        $SCRIPT -S net -M static -n <ns1>,<ns2>,..."
}

function print_user_usage {
	echo " usage: $SCRIPT -S user -A list"
	echo "        $SCRIPT -S user -A show -u <login>"
	echo "        $SCRIPT -S user -A delete -u <login>"
	echo "        $SCRIPT -S user -A update -u <login> [-e <email>] [-p <password>]"
	echo "        $SCRIPT -S user -A add -u <login> -e <email> -p <password>"
	echo ""
	echo " Note : New users are automatically added into rooti group. You can modify throught web interface"
}

function print_updauto_usage {
	echo " usage: $SCRIPT -S autoupdates -A enable"
	echo "        $SCRIPT -S autoupdates -A disable"
	echo " Note : Accept also another forms ([auto]update[s], en[able and (dis[able)"
}

function print_usage {
	echo "usage : $SCRIPT -S net [OPTIONS]"
	echo "        $SCRIPT -S user [OPTIONS]"
	echo "        $SCRIPT -S mail [OPTIONS]"
	echo "        $SCRIPT -S autoupdates [OPTIONS]"
	echo ""
	echo "        $SCRIPT --help for more help"
}

function print_help {
	echo "##Basic usage"
	print_usage
	echo ""
	echo "##Options"
	echo "-h, --help                        print this help"
	echo -e "\n#Common options"
	echo "-S, --section (net|user|mail)     section to configure"
	echo "-y, --yes                         ask confirm message before apply changes"
	echo -e "\n#Networking section"
	echo "-i, --iface IFACE                 network interface to configure (eth0,eth1,...)"
	echo "-M, --mode (static|dhcp)          static IP address or dhcp mode"
	echo "-a, --address IP                  IPv4 address for interface -i"
	echo "-m, --mask NETMASK                netmask for the IPv4 address"
	echo "-g, --gateway                     gateway|router IPv4 address"
	echo "-n, --nameservers NS_LIST         list of nameserver comma (,) separated"
	echo -e "\n#Common mail and user section"
	echo "-p, --pass PASSWORD               to set user password. It's advise to replace by -P"
	echo "-P, --askpass                     the user password will be prompted (for hidden this)"
	echo ""
	echo "-u, --user USER                   to set user login (for mail or user section)"
	echo -e "\n#Common user and autoupdates section"
	echo ""
	echo -e "\n#User section options"
	echo "-e, --email MAIL                  to set email for user"
	echo "-A, --action ACTION               to set the action to perform (list,show,delete,update or add) user(s)"
	echo -e "\n#Mail options"
	echo "-A, --action ACTION               to set another action to perform (show) mail(s)"
	echo "-f, --from MAIL                   to set from to email sended by server"
	echo "-r, --relayhost HOST:PORT         to set server that will relaying the mails"
	echo ""
	echo -e "\n#Common user and autoupdates section"
        echo "-A, --action ACTION               to set the action to perform (enable or disable) autoupdates(s)"
	echo ""
	echo "##Section net usage"
	print_net_usage
	echo ""
	echo "##Section user usage"
	print_user_usage
	echo ""
	echo "##Section mail usage"
	print_mail_usage
	echo ""
	echo "##Section autoupdates usage"
	print_updauto_usage
}

SCRIPT=$(basename $0)

mainLongOpt='section:,show,yes,interactive,help'
mainShortOpt='S:syIh'

commonLongOpt='action:,user:,pass:,askpass'
commonShortOpt='A:u:p:P'

netLongOpt='iface:,mode:,address:,masque:,gateway:,nameservers:'
netShortOpt='i:M:a:m:g:n:'

userLongOpt='email:'
userShortOpt='e:'

mailLongOpt='from:,relayhost:'
mailShortOpt='f:r:'

mergedLongOpt="$mainLongOpt,$commonLongOpt,$netLongOpt,$userLongOpt,$mailLongOpt"
mergedShortOpt="${mainShortOpt}${commonShortOpt}${netShortOpt}${userShortOpt}${mailShortOpt}"

if  [ -z "$1" ] ; then
        print_usage
        exit 1
fi
getopt -Q -o $mergedShortOpt --longoptions $mergedLongOpt -- "$@"
if [ $? -ne 0 ] ; then
	print_usage
	exit 1
fi

oYes=false
oAskPass=false

while true ; do
	case "$1" in
	-h | --help)		print_help; exit 0;;

	-S | --section)		oSection="$2"; shift 2;;
	-s | --show)		oShow=true; shift;;
	-y | --yes)		oYes=true; shift;;
	-I | --interactive)	oInteractive=true; shift;;

	-A | --action)		oAction="$2"; shift 2;;
	-u | --user)		oUser="$2"; shift 2;;
	-p | --pass)		oPass="$2"; shift 2;;
	-P | --askpass)		oAskPass=true; shift;;

	-i | --iface)		oIface="$2"; shift 2;;
	-M | --mode)		oMode="$2"; shift 2;;
	-a | --address)		oAddress="$2"; shift 2;;
	-m | --mask)		oMask="$2"; shift 2;;
	-g | --gateway)		oGateway="$2"; shift 2;;
	-n | --nameservers)	oNameservers="$2"; shift 2;;

	-e | --email)		oMail="$2"; shift 2;;

	-f | --from)		oFrom="$2"; shift 2;;
	-r | --relayhost)	oRelayhost="$2"; shift 2;;

	-- ) shift; break;;
	* ) break;;
	esac
done

if [ "$oAskPass" = true ]; then
	askPass
fi

if [ -n "$oSection" ]; then
	oSection=$( echo $oSection | tr '[:upper:]' '[:lower:]' )

	case $oSection in
	net ) netConf ;;
	user ) userConf ;;
	mail ) mailConf ;;
	*update*) updConf ;;
	* ) echo "-s, --section param must be set to (net, user or mail)"; print_usage; exit 1
	esac
fi
