#!/bin/bash

#    This file is part of EILiS.

#    EILiS 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 3 of the License, or
#    (at your option) any later version.

#    EILiS 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 EILiS.  If not, see <http://www.gnu.org/licenses/>.


# Main source code of EILiS - Easy Install Linux Servers
# E-mail Project: eilis.freesoftware@gmail.com

# Developed by Rafael de C. Farias - aka ENGEMEC"
# ----------------------------------------------"
# E-mails: engemec@gmail.com"
# 	   rafaelfarias@rafaelfarias.com"
# MSN: engemec.farias@homail.com"
# Gtalk: engemec@gmail.com"
# Skype: engemec.17081981"
# Web-site: www.rafaelfarias.com"

# Function from other files.
. /EILiS/SAMBA/smb.conf-01.sh
. /EILiS/SAMBA/user_definition_SAMBA.sh
. /EILiS/SAMBA/share_definition_SAMBA.sh
# SAMBA file: smb.conf-01.sh
# function_SAMBA()
# {
#   user_definition_SAMBA(){}
#   share_definition_SAMBA(){}
# }
. /EILiS/DHCP/dhcpd.conf-01.sh
. /EILiS/DHCP/function_ethernet_DHCP3.sh
# DHCP3 file: dhcpd.conf-01.sh
# function_DHCP3()
# {
#   function_authoritative_DHCP3(){}
#   function_subnet_DHCP(){}
#   function_ethernet_DHCP3(){}
# }
. /EILiS/SSH/sshd_config-01.sh
# OPENSSH file: sshd_config-01.sh
# function_OPENSSH()
# {
#   function_SSH_Port(){}
#   function_SSH_rootlogin(){}
# }
. /EILiS/FTP/vsftpd.conf-02.sh
# VSFTPD file: vsftpd.conf-02.sh
# function_VSFTPD()
# {
#   function_VSFTPD_anonymous(){}
#   function_VSFTPD_write(){}
#   function_VSFTPD_banner(){}
# }
. /EILiS/IPTABLES/iptables.firewall-03.sh
. /EILiS/IPTABLES/function_cleaning_IPTABLES.sh
# IPTABLES file: iptables.firewall-03.sh
# function_IPTABLES()
# {
#   function_cleaning_IPTABLES(){}
# }

restart_menu(){
echo ""
echo "     #      EEEEEEE   II   LL       II   SSSSSS      #"
echo "   ######## EE        II   LL            SS     ########"
echo " ########## EEEE      II   LL       II   SSSSSS ##########"
echo "   ######## EE        II   LL       II       SS ########"
echo "     #      EEEEEEE   II   LLLLLL   II   SSSSSS      #"
echo ""
echo "             EILiS - Easy Install Linux Server"
echo "                       Version 0.3"
echo ""
echo " The EILiS can help you with 5 services:"
echo " 0 - Information about EILiS."
echo " 1 - SAMBA (Share files and folders)"
echo " 2 - DHCP3 (DHCP server)"
echo " 3 - OPENSSH (Secure shell)"
echo " 4 - VSFTPD (FTP server)"
echo " 5 - BIND9 (DNS server)"
echo " 6 - IPTABLES (Firewall rules)"
echo ""
echo " 9 - >> EXIT <<"
echo ""
echo " Which service do you wnat to work now?"; read service_choice
echo ""
}
restart_menu;

while [ $service_choice -le 9 ];
do
	if [ $service_choice = "0" ]; then
		information_EILiS(){
		echo ""
		echo "#    EILiS is free software: you can redistribute it and/or modify"
		echo "#    it under the terms of the GNU General Public License as published by"
		echo "#    the Free Software Foundation, either version 3 of the License, or"
		echo "#    (at your option) any later version."
		echo ""
		sleep 2;
		echo "#    EILiS is distributed in the hope that it will be useful,"
		echo "#    but WITHOUT ANY WARRANTY; without even the implied warranty of"
		echo "#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
		echo "#    GNU General Public License for more details."
		echo ""
		sleep 2;
		echo "#    You should have received a copy of the GNU General Public License"
		echo "#    along with EILiS.  If not, see <http://www.gnu.org/licenses/>."
		echo ""
		sleep 2;
		echo "#    EILiS is based on:"
		echo "#    - Debian 5.0.x"
		echo "#    - Ubuntu 10.04 LTS edition"
		echo "#    - Linux Mint 9 and others."
		echo ""
		sleep 2;
		echo "#    Main source code of EILiS - Easy Install Linux Servers"
		echo "#    E-mail Project: eilis.freesoftware@gmail.com"
		echo ""
		sleep 2;
		echo "#    Developed by Rafael de C. Farias - aka ENGEMEC"
		echo "#    ----------------------------------------------"
		echo "#    E-mails: engemec@gmail.com"
		echo "#             rafaelfarias@rafaelfarias.com"
		echo "#    MSN: engemec.farias@homail.com"
		echo "#    Gtalk: engemec@gmail.com"
		echo "#    Skype: engemec.17081981"
		echo "#    Web-site: www.rafaelfarias.com"
		echo ""
		sleep 2;
		}
		information_EILiS;
		restart_menu;		
	elif [ $service_choice = "1" ]; then
		apt-get install samba -y;
		samba_menu(){
		echo "";
		echo "Choose an option:";
		echo "";
		echo " 1 - Configure the service first time (SAMBA).";
		echo " 2 - Add user (SAMBA).";
		echo " 3 - Add share definition (SAMBA).";
		echo " 4 - Start/Restart Files and Folders server.";
		echo " 5 - Start/Restart Files and Folders server.";
		echo "";
		echo " 9 - Return to main menu."; read samba_option
		echo "";
		}
		samba_menu;
		if [ $samba_option = "1" ]; then
			function_SAMBA;
			samba_menu;
		elif [ $samba_option = "2" ]; then
			user_definition_SAMBA;
			samba_menu;
		elif [ $samba_option = "3" ]; then
			share_definition_SAMBA;
			samba_menu;
		elif [ $samba_option = "4" ]; then
			service smbd restart;
			samba_menu;
		elif [ $samba_option = "5" ]; then
			service smbd stop;
			samba_menu;
		elif [ $samba_option = "9" ]; then
			restart_menu;
		else
			exit 0;
		fi;
	elif [ $service_choice = "2" ]; then
		apt-get install dhcp3-server -y;
		dhcp3_menu(){
		echo "";
		echo "Choose an option:";
		echo "";
		echo " 1 - Configure the service first time (DHCP3).";
		echo " 2 - Define outlet interface (DHCP3).";
		echo " 3 - Start/Restart DHCP server.";
		echo " 4 - Stop DHCP server.";
		echo "";
		echo " 9 - Return to main menu."; read dhcp3_option
		echo "";
		}
		dhcp3_menu;
		if [ $dhcp3_option = "1" ]; then
			function_DHCP3;
			dhcp3_menu;
		elif [ $dhcp3_option = "2" ]; then
			function_ethernet_DHCP3;
			dhcp3_menu;
		elif [ $dhcp3_option = "3" ]; then
			/etc/init.d/dhcp3-server restart;
			dhcp3_menu;
		elif [ $dhcp3_option = "4" ]; then
			/etc/init.d/dhcp3-server stop;
			dhcp3_menu;
		elif [ $dhcp3_option = "9" ]; then
			restart_menu;
		else
			exit 0;
		fi;
	elif [ $service_choice = "3" ]; then
		apt-get install openssh-server -y;
		openssh_menu(){
		echo "";
		echo "Choose an option:";
		echo "";
		echo " 1 - Configure the service first time (OPENSSH).";
		echo " 2 - Start/Restart SSH server.";
		echo " 3 - Stop SSH server.";
		echo "";
		echo " 9 - Return to main menu."; read openssh_option
		echo "";
		}
		openssh_menu;
		if [ $openssh_option = "1" ]; then
			function_OPENSSH;
			function_SSH_Port;
			function_SSH_rootlogin;
			openssh_menu;
		elif [ $openssh_option = "2" ]; then
			/etc/init.d/ssh restart;
			openssh_menu;
		elif [ $openssh_option = "3" ]; then
			/etc/init.d/ssh stop;
			openssh_menu;
		elif [ $openssh_option = "9" ]; then
			restart_menu;
		else
			exit 0;
		fi;
	elif [ $service_choice = "4" ]; then
		apt-get install vsftpd -y;
		vsftpd_menu()
		{
		echo "";
		echo "Choose an option:";
		echo "";
		echo " 1 - Configure the service first time (VSFTPD).";
		echo " 2 - Start/Restart FTP server.";
		echo " 3 - Stop FTP server.";
		echo "";
		echo " 9 - Return to main menu."; read vsftpd_option
		echo "";
		}
		vsftpd_menu;
		if [ $vsftpd_option = "1" ]; then
			function_VSFTPD;
			function_VSFTPD_anonymous;
			function_VSFTPD_write;
			function_VSFTPD_banner;
			vsftpd_menu;
		elif [ $vsftpd_option = "2" ]; then
			/etc/init.d/vsftpd restart;
			vsftpd_menu;
		elif [ $vsftpd_option = "3" ]; then
			/etc/init.d/vsftpd stop;
			vsftpd_menu;
		elif [ $vsftpd_option = "9" ]; then
			restart_menu;
		else
			exit 0;
		fi;
	elif [ $service_choice = "5" ]; then
		bind9_menu()
		{
		echo "";
		echo "Choose an option:"
		echo "";
		echo " 1 - Install DNS Server (Bind 9).";
		echo " 2 - Start/Restart DNS server.";
		echo " 3 - Stop DNS server";
		echo "";
		echo " 9 - Return to main menu."; read bind9_option
		echo "";
		}
		bind9_menu;
		if [ $bind9_option = "1" ]; then
			apt-get install bind9 -y;
			bind9_menu;
		elif [ $bind9_option = "2" ]; then
			/etc/init.d/bind9 restart;
			bind9_menu;
		elif [ $bind9_option = "3" ]; then
			/etc/init.d/bind9 stop;
			bind9_menu;
		elif [ $bind9_option = "9" ]; then
			restart_menu;
		else
			exit 0;
		fi;
	elif [ $service_choice = "6" ]; then
		iptables_menu()
		{
			echo "";
			echo "Choose an option:"
			echo "";
			echo " 1 - Configure the service first time (IPTABLES).";
			echo " 2 - Start my firewall rules.";
			echo " 3 - Remove/Stop all rules.";
			echo "";
			echo " You can find IPTABLES's firewall rules on:";
			echo " user@localhost:/etc/IPTABLES# firewall.sh";
			echo "";
			echo " 9 - Return to main menu."; read iptables_option
			echo "";
		}
		iptables_menu;
		if [ $iptables_option = "1" ]; then
			function_IPTABLES;
			iptables_menu;
		elif [ $iptables_option = "2" ]; then
			sh /etc/IPTABLES/firewall.sh;
			iptables_menu;
		elif [ $iptables_option = "3" ]; then
			function_cleaning_IPTABLES_2;
			iptables_menu;
		elif [ $iptables_option = "9" ]; then
			restart_menu;
		else
			exit 0;
		fi;
	else
		exit 0;
	fi;
done

exit 0

