| Current Path : /var/www/html/mmishra/ |
| Current File : /var/www/html/mmishra/server.txt |
#! /bin/sh
#set -v
#set -x
PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin
if [ -f variables ]; then
. variables
else
touch variables
fi
echo $DomainName;
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
#DomainName=${default_DomainName:=$DomainName}
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
LdapServer=${default_LdapServer:=$LdapServer}
echo "LdapServer="$LdapServer >> variables
echo -n "please provide Ldap Server base dn Default is :dc=iiita,dc=ac,dc=in: "
read default_LdapServerDn
LdapServerDn=${default_LdapServerDn:=$LdapServerDn}
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
LdapServerCn=${default_LdapServerCn:=$LdapServerCn}
echo "LdapServerCn="$LdapServerCn >> variables
echo -n "please provide User to Email Default is:indem@iiita.ac.in: "
read default_person_to_email
person_to_email=${default_person_to_email:=$person_to_email}
echo "person_to_email="$person_to_email >> variables
echo -n "please provide normal user name: iiita: "
read default_NormalUser
NormalUser=${default_NormalUser:=$NormalUser}
echo "NormalUser="$NormalUser >> variables
echo -n "please provide vqadmin password Default is:iiita123: "
read default_Password
Password=${default_Password:=$Password}
echo "Password="$Password >> variables
echo -n "please provide host name Default is:studentzone: "
read default_Host
Host=${default_Host:=$Host}
echo "Host="$Host >> variables
echo -n "please provide Webserver host name Default is:studentzone.iiita.ac.in: "
read default_WebHost
WebHost=${default_WebHost:=$WebHost}
echo "WebHost="$WebHost >> variables
echo -n "please provide host ip Default is:172.31.1.102: "
read default_HostIp
HostIp=${default_HostIp:=$HostIp}
echo "HostIp="$HostIp >> variables
echo -n "please provide host Default Default is:172.31.1.1: "
read default_DefaultGateway
DefaultGateway=${default_DefaultGateway:=$DefaultGateway}
echo "DefaultGateway="$DefaultGateway >> variables
echo -n "please provide host Dns:172.31.1.21: "
read default_DefaultDns
Dns=${default_Dns:=$Dns}
echo "Dns="$Dns >> variables
echo -n "please provide Allowed Network Default is:172.0.0.0/8: "
read default_IiitaNetwork
IiitaNetwork=${default_IiitaNetwork:=$IiitaNetwork}
echo "IiitaNetwork="$IiitaNetwork >> variables
echo -n "please provide your apache webroot Directory path Default is:/var/www/html: "
read default_Webroot
Webroot=${default_Webroot:=$Webroot}
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
case $Decision in
n)
break
;;
1)
########################################################################
########################################################################
########Stop Firewall and Disable Selinux Configure Internet############
########################################################################
########################################################################
mkdir /downloads/
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
setenforce 0
sed 's|FORCELEGACY=no|FORCELEGACY=yes|g' /etc/sysconfig/authconfig > /etc/sysconfig/authconfig_tmp && mv /etc/sysconfig/authconfig_tmp /etc/sysconfig/authconfig
hostnamectl set-hostname $Host
read
nmcli d
nmcli c modify enp2s0f0 ipv4.addresses "$HostIp/24 $DefaultGateway"
nmcli c modify enp2s0f0 ipv4.dns $Dns
nmcli c modify enp2s0f0 ipv4.method manual
nmcli c down enp2s0f0
nmcli c up enp2s0f0
nmcli d show enp2s0f0
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 "Please Reboot the system and start second step..."
read
;;
2)
########################################################################
##### Add a few packages, make a directory, stop some stuff,############
##### start some stuff and remove that SUID bit :-D ####################
########################################################################
yum -y install yum-plugin-fastestmirror
yum -y update
yum -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 " Start Step 3"
;;
3)
yum -y install openssh-clients
yum -y install openldap-servers openldap-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
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: iiita" >> /downloads/frontend.ldif
echo "dc: iiita" >> /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
yum -y install openldap-clients nss-pam-ldapd
authconfig --enableldap --enableldapauth --ldapserver=$LdapServer --ldapbasedn=\"$LdapServerDn\" --enablemkhomedir --disableldaptls --update
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
systemctl restart sssd
;;
################################################################
################ Add Qmail Users and Directories ###############
################################################################
4)
yum -y install httpd
rm -f /etc/httpd/conf.d/welcome.conf
sed 's|ServerAdmin root@localhost|ServerAdmin courses@iiita.ac.in|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 courses.iiita.ac.in: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
;;
########### Qmail Installation ###############
##################################
###### Installing Net Qmail ######
###### Working 1 ######
##################################
5)
systemctl restart httpd
yum -y install php-ldap
systemctl restart httpd
yum -y install perl perl-CGI php-xmlrpc php-soap php-intl php-opcache php-opcache.enable
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
yum -y install php php-mbstring php-pear
sed '889s/.*/date.timezone = \"Asia/Tokyo\"/' /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> " >> ~/public_html/virtual.php
echo " <body> " >> ~/public_html/virtual.php
echo " <div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\"> " >> ~/public_html/virtual.php
echo " Virtual Host Test Page " >> ~/public_html/virtual.php
echo " </div> " >> ~/public_html/virtual.php
echo " </body> " >> ~/public_html/virtual.php
echo " </html> " >> ~/public_html/virtual.php
;;
##################################################
############### Installing Ucspi-TCP 2 ###########
##################################################
6)
yum -y install mariadb-server
sed -i'13i character-set-server=utf8 ' /etc/my.cnf.d/server.cnf > /etc/my.cnf.d/server.cnf_tmp && mv /etc/my.cnf.d/server.cnf_tmp /etc/my.cnf.d/server.cnf
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation
yum -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
##################################################
################ Install Deamontools 3 ###########
##################################################
;;
7)
cd /var/www/html/
wget https://download.moodle.org/download.php/direct/stable28/moodle-latest-28.tgz
tar xvzf moodle-latest-28.tgz
mv moodle courses
mkdir /var/www/moodledata
chmod 777 /var/www/moodledata
;;
esac