Your IP : 216.73.216.40


Current Path : /var/www/html/ajay/
Upload File :
Current File : /var/www/html/ajay/server

#! /bin/sh
#set -v 
#set -x 
PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin
#cat * | grep "|*parameter1*|" | grep "|*parameter2*|" | cut -f 8,11,12,15,21,23,34 -d "|" | wc -l
Decision=${1-text}
if [[ -z "$1" ]]
then
if [ -f ./variables ]; then
	. ./variables
else
	touch variables
fi
echo -n "please provide domain name Default is :iiita.ac.in:"
read default_DomainName 
if [ $default_DomainName ]
then
DomainName=${default_DomainName:=iiita.ac.in}
else
 DomainName=${DomainName:=iiita.ac.in} 
fi
echo "DomainName="$DomainName > variables_temp && mv variables_temp variables
echo -n "please provide Ldap Server name Default is :ldap.iiita.ac.in:"
read default_LdapServer 
if [ $default_LdapServer ]
 then	
LdapServer=${default_LdapServer:=ldap.iiita.ac.in} 
else 	
LdapServer=${LdapServer:=ldap.iiita.ac.in} 
fi
echo "LdapServer="$LdapServer >> variables
echo -n "please provide Organization short name default is  :iiita:"
read default_Org
if [ $default_Org ]
 then
Org=${default_Org:=iiita}
else
Org=${Org:=iiita}
fi
echo "Org="$Org >> variables
echo -n "please provide Ldap Server base dn Default is :dc=iiita,dc=ac,dc=in:  "
read default_LdapServerDn 
if [ $default_LdapServerDn ] 
then
	LdapServerDn=${default_LdapServerDn:=dc=iiita,dc=ac,dc=in} 
else 
	LdapServerDn=${LdapServerDn:=dc=iiita,dc=ac,dc=in}
 fi
echo "LdapServerDn="$LdapServerDn >> variables
echo -n "please provide Ldap Server Manager Cn Default is :cn=Manager,dc=iiita,dc=ac,dc=in:  "
read default_LdapServerCn 
if
 [ $default_LdapServerCn  ] 
then
	LdapServerCn=${default_LdapServerCn:=cn=Manager,dc=iiita,dc=ac,dc=in}
 else
 	LdapServerCn=${LdapServerCn:=cn=Manager,dc=iiita,dc=ac,dc=in}
 fi
echo "LdapServerCn="$LdapServerCn >> variables
echo -n "please provide User to Email Default is:indem@iiita.ac.in: "
read default_person_to_email
if
 [ $default_person_to_email ] 
then	
person_to_email=${default_person_to_email:=indem@iiita.ac.in}
 else 
	person_to_email=${person_to_email:=indem@iiita.ac.in} 
fi
echo "person_to_email="$person_to_email >> variables
echo -n "please provide normal user name: iiita: "
read default_NormalUser
if
 [ $default_NormalUser ]
 then	
NormalUser=${default_NormalUser:=iiita}
 else 
	NormalUser=${NormalUser:=iiita}
 fi
echo "NormalUser="$NormalUser >> variables
echo -n "please provide vqadmin password Default is:iiita123:  "
read default_Password
if
 [ $default_Password ]
 then	
Password=${default_Password:=iiita123}
 else 
	Password=${Password:=iiita123} 
fi
echo "Password="$Password >> variables
echo -n "please provide host name Default is:studentzone: "
read default_Host
if
 [ $default_Host ] 
then	
Host=${default_Host:=studentzone} 
else 
	Host=${Host:=studentzone} 
fi
echo "Host="$Host >> variables
echo -n "please provide Webserver host name Default is:studentzone.iiita.ac.in: "
read default_WebHost
if
 [ $default_WebHost ]
 then	
WebHost=${default_WebHost:=studentzone.iiita.ac.in} 
else 
	WebHost=${WebHost:=studentzone.iiita.ac.in}
 fi
echo "WebHost="$WebHost >> variables
echo -n "please provide host ip Default is:172.31.1.103: "
read default_HostIp
if 
[ $default_HostIp ] 
then	
HostIp=${default_HostIp:=172.31.1.103} 
else
 	HostIp=${HostIp:=172.31.1.103}
 fi
echo "HostIp="$HostIp >> variables
echo -n "please provide host Default Default is:172.31.1.1: "
read default_DefaultGateway
if
 [ $default_DefaultGateway ] 
then	
DefaultGateway=${default_DefaultGateway:=172.31.1.1}
 else
 	DefaultGateway=${DefaultGateway:=172.31.1.1}
 fi
echo "DefaultGateway="$DefaultGateway >> variables
echo -n "please provide host Dns:172.31.1.21: "
read default_Dns
if
 [ $default_Dns ] 
then
	Dns=${default_Dns:=172.31.1.21} 
else
 	Dns=${Dns:=172.31.1.21} 
fi
echo "Dns="$Dns >> variables
echo -n "please provide Allowed Network Default is:172.0.0.0/8: "
read default_IiitaNetwork
if
 [ $default_IiitaNetwork ] 
then	
IiitaNetwork=${default_IiitaNetwork:=172.0.0.0/8} 
else
 	IiitaNetwork=${IiitaNetwork:=172.0.0.0/8}
 fi
echo "IiitaNetwork="$IiitaNetwork >> variables
echo -n "please provide your apache webroot Directory path Default is:/var/www/html: "
read default_Webroot
if 
[ $default_Webroot ] 
then	
Webroot=${default_Webroot:=/var/www/html} 
else
 	Webroot=${Webroot:=/var/www/html}
 fi
echo "Webroot="$Webroot >> variables
########################################################################

echo "All the information provided by you is as follows.."
echo  "Domain name is $DomainName"
echo  "Ldap Sever name is $LdapServer"
echo  "Ldap Server Dn is $LdapServerDn"
echo  "Ldap Server Manager Cn is $LdapServerCn"
echo  "User to Email is $person_to_email"
echo  "Normal User Name is $NormalUser"
echo  "Password is $Password"
echo  "Host Name is $Host"
echo  "Host Ip is $HostIp"
echo  "Default Gateway is $DefaultGateway"
echo  "Default DNS is $Dns"
echo  "Default Allowed Network is  is $IiitaNetwork"
echo  "Default Web Host Name  is $WebHost"
echo  "so apache webroot Directory path is $Webroot"
echo "Press step Number to continue or n to cancle  .........."
read Decision
else
Decision=${1-text}
. ./variables
fi
while [  $Decision -gt 0 ]; do
case $Decision in
     n)
	 break
	 ;;
0)
exit
;;
Default)
echo "Press 1 to Configure Network and Disable Selinux"
echo "Press 2 to Update System"
echo "Press 3 to install Openldap"
echo "Press 4 to configure Openldap"
echo "Press 5 to Configuer LDAP Client"
echo "press 6 to Install HTTP Server"
echo "Press 7 to install PHP"
echo "Press 8 to install MariaDb"
echo "Press 9 to install Moodle"
echo "Press 0 to Exit"
read Decision
;;
	 1)
########################################################################
########################################################################
########Stop Firewall and Disable Selinux Configure Internet############
########################################################################
########################################################################
systemctl stop firewalld 
systemctl disable firewalld
sed 's|SELINUX=enforcing|SELINUX=disabled|g' /etc/selinux/config > /etc/selinux/config_tmp && mv /etc/selinux/config_tmp /etc/selinux/config
chmod 644 /etc/selinux/config
hostnamectl set-hostname $Host
device=`nmcli d | awk '{if ($3 =="connected") print $1}'`
echo $device
nmcli c modify $device ipv4.addresses "$HostIp/24"
nmcli c modify $device ipv4.gateway "$DefaultGateway" 
nmcli c modify $device ipv4.dns $Dns 
nmcli c modify $device ipv4.method manual
nmcli c down $device
nmcli c up $device
nmcli d show $device 
ip addr show 
sed 's|GRUB_CMDLINE_LINUX="|GRUB_CMDLINE_LINUX="ipv6.disable=1 |g' /etc/default/grub  > /etc/default/grub_tmp && mv /etc/default/grub_tmp /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg 
echo " Network is configured Please Reboot the system and start second step of system update..."
read Decision
#Decision = Default
;;
2)
########################################################################
##### Add a few packages, make a directory, stop some stuff,############
##### start some stuff and remove that SUID bit :-D ####################
########################################################################
dnf -y install dnf-plugin-fastestmirror 
dnf -y update
dnf -y install yum-allowdowngrade
dnf -y install vim-enhanced 
echo "alias vi='vim'" >> /etc/profile
source /etc/profile 
sed 's|#PermitRootLogin yes|PermitRootLogin yes|g' /etc/ssh/sshd_config  > /etc/ssh/sshd_config_tmp && mv /etc/ssh/sshd_config_tmp /etc/ssh/sshd_config
systemctl restart sshd 
echo "System is up to date now  Start Step 3 to install open ldap "
read Decision
;;
3)
dnf -y install openldap-servers openldap-clients nss-pam-ldapd openssh-clients 
echo "pidfile     /run/openldap/slapd.pid" > /etc/openldap/slapd.conf
echo "argsfile    /run/openldap/slapd.args" >> /etc/openldap/slapd.conf
rm -rf /etc/openldap/slapd.d/* 
slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d 
sed '6s/.*/olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * break/' /etc/openldap/slapd.d/cn=config/olcDatabase\={0}config.ldif  > /etc/openldap/slapd.d/cn=config/olcDatabase\={0}config.ldif_tmp && mv /etc/openldap/slapd.d/cn=config/olcDatabase\={0}config.ldif_tmp /etc/openldap/slapd.d/cn=config/olcDatabase\={0}config.ldif 
chown -R ldap. /etc/openldap/slapd.d 
chmod -R 700 /etc/openldap/slapd.d 
systemctl start slapd 
systemctl enable slapd
echo "LDAP Installed press 4 to Configure "
read Decision
;; 
4)
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/core.ldif 
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif 
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif 
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif 
echo "dn: cn=module,cn=config"  >	/downloads/backend.ldif
echo "objectClass: olcModuleList"  >>	/downloads/backend.ldif
echo "cn: module"  >>	/downloads/backend.ldif
echo "olcModulepath: /usr/lib64/openldap"  >>	/downloads/backend.ldif
echo "olcModuleload: back_hdb"  >>	/downloads/backend.ldif
echo ""  >>	/downloads/backend.ldif
echo "dn: olcDatabase=hdb,cn=config"  >>	/downloads/backend.ldif
echo "objectClass: olcDatabaseConfig"  >>	/downloads/backend.ldif
echo "objectClass: olcHdbConfig"  >>	/downloads/backend.ldif
echo "olcDatabase: {1}hdb"  >>	/downloads/backend.ldif
echo "olcSuffix: $LdapServerDn"  >>	/downloads/backend.ldif
echo "olcDbDirectory: /var/lib/ldap"  >>	/downloads/backend.ldif
echo "olcRootDN: $LdapServerCn"  >>	/downloads/backend.ldif
echo "olcRootPW: `slappasswd -s $Password`"  >>	/downloads/backend.ldif
echo "olcDbConfig: set_cachesize 0 2097152 0"  >>	/downloads/backend.ldif
echo "olcDbConfig: set_lk_max_objects 1500"  >>	/downloads/backend.ldif
echo "olcDbConfig: set_lk_max_locks 1500"  >>	/downloads/backend.ldif
echo "olcDbConfig: set_lk_max_lockers 1500"  >>	/downloads/backend.ldif
echo "olcDbIndex: objectClass eq"  >>	/downloads/backend.ldif
echo "olcLastMod: TRUE"  >>	/downloads/backend.ldif
echo "olcMonitoring: TRUE"  >>	/downloads/backend.ldif
echo "olcDbCheckpoint: 512 30"  >>	/downloads/backend.ldif
echo "olcAccess: to attrs=userPassword by dn=\"$LdapServerCn\" write by anonymous auth by self write by * none"  >>	/downloads/backend.ldif
echo "olcAccess: to attrs=shadowLastChange by self write by * read"  >>	/downloads/backend.ldif
echo "olcAccess: to dn.base=\"\" by * read"  >>	/downloads/backend.ldif
echo "olcAccess: to * by dn=\"$LdapServerCn\" write by * read"  >>	/downloads/backend.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /downloads/backend.ldif 
echo "dn: $LdapServerDn" > /downloads/frontend.ldif
echo "objectClass: top" >> /downloads/frontend.ldif
echo "objectClass: dcObject" >> /downloads/frontend.ldif
echo "objectclass: organization" >> /downloads/frontend.ldif
echo "o: $Org" >> /downloads/frontend.ldif
echo "dc: $Org" >> /downloads/frontend.ldif
echo "" >> /downloads/frontend.ldif
echo "dn: $LdapServerCn" >> /downloads/frontend.ldif
echo "objectClass: simpleSecurityObject" >> /downloads/frontend.ldif
echo "objectClass: organizationalRole" >> /downloads/frontend.ldif
echo "cn: admin" >> /downloads/frontend.ldif
echo "userPassword: `slappasswd -s $Password`" >> /downloads/frontend.ldif
ldapadd -x -H ldapi:/// -D cn=$LdapServerCn -W -f /downloads/frontend.ldif 
cd /etc/pki/tls/certs 
make server.key 
openssl rsa -in server.key -out server.key 
make server.csr 
openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 3650
cp /etc/pki/tls/certs/server.key /etc/pki/tls/certs/server.crt /etc/pki/tls/certs/ca-bundle.crt /etc/openldap/certs/ 
chown ldap. /etc/openldap/certs/server.key /etc/openldap/certs/server.crt /etc/openldap/certs/ca-bundle.crt 
echo "dn: cn=config " >> /downloads/modessl.ldif
echo "changetype: modify " >> /downloads/modessl.ldif
echo "add: olcTLSCACertificateFile " >> /downloads/modessl.ldif
echo "olcTLSCACertificateFile: /etc/openldap/certs/ca-bundle.crt " >> /downloads/modessl.ldif
echo "- " >> /downloads/modessl.ldif
echo "add: olcTLSCertificateFile " >> /downloads/modessl.ldif
echo "olcTLSCertificateFile: /etc/openldap/certs/server.crt " >> /downloads/modessl.ldif
echo "- " >> /downloads/modessl.ldif
echo "add: olcTLSCertificateKeyFile " >> /downloads/modessl.ldif
echo "olcTLSCertificateKeyFile: /etc/openldap/certs/server.key " >> /downloads/modessl.ldif
ldapmodify -Y EXTERNAL -H ldapi:/// -f /downloads/modessl.ldif
systemctl restart slapd
echo "ldap Configured Press 5 to confiture Ldap Client"
read Decision
;;
5)
dnf -y install openldap-servers openldap-clients nss-pam-ldapd openssh-clients
authconfig --enableldap --enableldapauth --ldapserver=$LdapServer --ldapbasedn=$LdapServerDn --enablemkhomedir --disableldaptls --update
systemctl restart sssd 
sed '3i ldap_auth_disable_tls_never_use_in_production = true' /etc/sssd/sssd.conf  > /etc/sssd/sssd.conf_tmp && mv /etc/sssd/sssd.conf_tmp /etc/sssd/sssd.conf
sed '2i ldap_tls_reqcert = never' /etc/sssd/sssd.conf  > /etc/sssd/sssd.conf_tmp && mv /etc/sssd/sssd.conf_tmp /etc/sssd/sssd.conf
chmod 500 /etc/sssd/sssd.conf 
systemctl restart sssd 
echo " Ldap Client Configured press 6 to install http server "
read Decision
;;
################################################################
################ Add Qmail Users and Directories ###############
################################################################
6)
dnf -y install httpd 
rm -f /etc/httpd/conf.d/welcome.conf
sed 's|ServerAdmin root@localhost|ServerAdmin `$person_to_email`|g' /etc/httpd/conf/httpd.conf  > /etc/httpd/conf/httpd.conf_tmp && mv /etc/httpd/conf/httpd.conf_tmp /etc/httpd/conf/httpd.conf
sed 's|#ServerName www.example.com:80|ServerName `$WebHost`:80|g' /etc/httpd/conf/httpd.conf  > /etc/httpd/conf/httpd.conf_tmp && mv /etc/httpd/conf/httpd.conf_tmp /etc/httpd/conf/httpd.conf
sed 's|AllowOverride None|AllowOverride None|g' /etc/httpd/conf/httpd.conf  > /etc/httpd/conf/httpd.conf_tmp && mv /etc/httpd/conf/httpd.conf_tmp /etc/httpd/conf/httpd.conf
sed 's|DirectoryIndex index.html|DirectoryIndex index.html index.php index.cgi|g' /etc/httpd/conf/httpd.conf  > /etc/httpd/conf/httpd.conf_tmp && mv /etc/httpd/conf/httpd.conf_tmp /etc/httpd/conf/httpd.conf
echo "ServerTokens Prod " >> /etc/httpd/conf/httpd.conf
echo "KeepAlive On" >> /etc/httpd/conf/httpd.conf 
systemctl start httpd 
systemctl enable httpd 
echo "<html>" >> /var/www/html/index.html
echo "<body>" >> /var/www/html/index.html
echo "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">" >> /var/www/html/index.html
echo "Test Page" >>/var/www/html/index.html
echo "</div>" >> /var/www/html/index.html
echo "</body>" >> /var/www/html/index.html
echo "</html>" >>/var/www/html/index.html
echo "HTPPD Installed press 7 to install php "
read Decision
;;
########### Qmail Installation ###############
##################################
###### Installing Net Qmail ######
###### Working     1        ######
##################################
7)
systemctl restart httpd 
dnf -y install php-ldap
systemctl restart httpd
dnf -y install perl perl-CGI php-xmlrpc php-soap php-intl php-opcache
sed '144s/.*/Options FollowSymLinks ExecCGI/' /etc/httpd/conf/httpd.conf  > /etc/httpd/conf/httpd.conf_tmp && mv /etc/httpd/conf/httpd.conf_tmp /etc/httpd/conf/httpd.conf 
sed '294s/.*/AddHandler cgi-script .cgi.pl/' /etc/httpd/conf/httpd.conf  > /etc/httpd/conf/httpd.conf_tmp && mv /etc/httpd/conf/httpd.conf_tmp /etc/httpd/conf/httpd.conf 
systemctl restart httpd 
dnf -y install php php-mbstring php-pear
sed '890s#.*#date.timezone = "Asia/Kolkata"#' /etc/php.ini  > /etc/php.ini_tmp && mv /etc/php.ini_tmp /etc/php.ini
sed 's|short_open_tag = Off|short_open_tag = On|g' /etc/php.ini  > /etc/php.ini_tmp && mv /etc/php.ini_tmp /etc/php.ini
sed 's|max_execution_time = 30|max_execution_time = 300|g' /etc/php.ini  > /etc/php.ini_tmp && mv /etc/php.ini_tmp /etc/php.ini
sed 's|memory_limit = 128M|memory_limit = 512M|g' /etc/php.ini  > /etc/php.ini_tmp && mv /etc/php.ini_tmp /etc/php.ini
sed 's|post_max_size = 8M|post_max_size = 20M|g' /etc/php.ini  > /etc/php.ini_tmp && mv /etc/php.ini_tmp /etc/php.ini
sed 's|upload_max_filesize = 2M|upload_max_filesize = 20M|g' /etc/php.ini  > /etc/php.ini_tmp && mv /etc/php.ini_tmp /etc/php.ini
systemctl restart httpd 
echo "<html>" >> $Webroot/index.php
echo "<body>" >> $Webroot/index.php
echo "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">" >> $Webroot/index.php
echo "<?php" >> $Webroot/index.php
echo "print Date(\"Y/m/d\");" >> $Webroot/index.php
echo "?>" >> $Webroot/index.php
echo "</div>" >> $Webroot/index.php
echo "</body>" >> $Webroot/index.php
echo "</html>" >> $Webroot/index.php
echo "# create new" > /etc/httpd/conf.d/vhost.conf
echo " 		" >> /etc/httpd/conf.d/vhost.conf
echo "# for original domain" >> /etc/httpd/conf.d/vhost.conf
echo " 		" >> /etc/httpd/conf.d/vhost.conf
echo "<VirtualHost *:80>" >> /etc/httpd/conf.d/vhost.conf
echo "DocumentRoot $Webroot" >> /etc/httpd/conf.d/vhost.conf
echo "ServerName $WebHost" >> /etc/httpd/conf.d/vhost.conf
echo "</VirtualHost>" >> /etc/httpd/conf.d/vhost.conf
echo " 		" >> /etc/httpd/conf.d/vhost.conf
echo "#for virtual domain" >> /etc/httpd/conf.d/vhost.conf
echo "" >> /etc/httpd/conf.d/vhost.conf
echo "<VirtualHost *:80>" >> /etc/httpd/conf.d/vhost.conf
echo "DocumentRoot $Webroot" >> /etc/httpd/conf.d/vhost.conf
echo "ServerName $WebHost" >> /etc/httpd/conf.d/vhost.conf
echo "ServerAdmin $person_to_email" >> /etc/httpd/conf.d/vhost.conf
echo "ErrorLog logs/virtual.host-error_log" >> /etc/httpd/conf.d/vhost.conf
echo "CustomLog logs/virtual.host-access_log combined" >> /etc/httpd/conf.d/vhost.conf
echo "</VirtualHost>" >> /etc/httpd/conf.d/vhost.conf
systemctl restart httpd 
echo " 	<html>	" >> $Webroot/virtual.php
echo " 	<body>	" >> $Webroot/virtual.php
echo " 	<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">	" >> $Webroot/virtual.php
echo " 	Virtual Host Test Page	" >> $Webroot/virtual.php
echo " 	</div>	" >> $Webroot/virtual.php
echo " 	</body>	" >> $Webroot/virtual.php
echo " 	</html>	" >> $Webroot/virtual.php
echo "PHP Installed press 8 to install mariadb.."
read Decision
;;
##################################################
############### Installing Ucspi-TCP 2 ###########
##################################################
8)
dnf -y install mariadb-server 
sed '21i character-set-server=utf8 ' /etc/my.cnf.d/mariadb-server.cnf   > /etc/my.cnf.d/mariadb-server.cnf_tmp && mv /etc/my.cnf.d/mariadb-server.cnf_tmp /etc/my.cnf.d/mariadb-server.cnf 
systemctl start mariadb 
systemctl enable mariadb 
mysql_secure_installation 
dnf -y install phpMyAdmin php-mysqlnd php-mcrypt 
sed '17i Require ip 127.0.0.1 172.0.0.0/8' /etc/httpd/conf.d/phpMyAdmin.conf   > /etc/httpd/conf.d/phpMyAdmin.conf_tmp && mv /etc/httpd/conf.d/phpMyAdmin.conf_tmp /etc/httpd/conf.d/phpMyAdmin.conf 
sed '34i Require ip 127.0.0.1 172.0.0.0/8' /etc/httpd/conf.d/phpMyAdmin.conf   > /etc/httpd/conf.d/phpMyAdmin.conf_tmp && mv /etc/httpd/conf.d/phpMyAdmin.conf_tmp /etc/httpd/conf.d/phpMyAdmin.conf 
systemctl restart httpd 
echo "mariadb and phpmyadmin installed press 9 to install moodle "
read Decision
##################################################
################ Install Deamontools 3 ###########
##################################################
;;
9)
cd /var/www/html/
wget https://download.moodle.org/download.php/direct/stable29/moodle-latest-29.tgz
tar xvzf moodle-latest-29.tgz
mv moodle courses
mkdir /var/www/moodledata
chmod 777 /var/www/moodledata
echo "Moodle Installed Select 0 to Exit"
read Decision
;;
esac
done