Description:

The following script will determine the shared user type I.E normal shared user, reseller or resold. In addition the script will also display the number of number of ModRails or Mongrel instances and the port used. While entering a reseller or resold account name the details of Mongrel / ModRails instances of all the users under the reseller will be displayed. The script will be very handy  while adding Vhost entries for either a reseller or a resold account. The script will create custom.conf file under the path /usr/local/apache/conf/userdata/std/2/USER_NAME/DOMAIN_NAME/ and add necessary content to this file. Finally, it will output the exact /scripts/ensure_vhost_includes command that needs to be executed to include the custom.conf file to the apache Vhost.

Working:

The script will take the account name as the input and it will check the user’s existence in the /etc/userdomains file. If the user is existing there then the user’s existence will be verified in the /var/cpanel/resellers file. If the result is positive then the Mongrel/ ModRails details of reseller account along with resold account will be displayed. If the username is not existing in the /var/cpanel/resellers file then the based on the owner of the user from the file /etc/trueuserowners the account type will be determined. Once the type of the username is determined, for a resold account the complete Mongrel / ModRails details of the other resold accounts along with reseller will be displayed. For the normal shared account the no: of mongrel (it’s port) and the ModRails will be displayed.

For adding vhost entry the script will take input from the following list of options.

Mongrel (M/m), Passenger (P/p), SVN (S/s) or Trac (T/t) ?

Usage:

Mongrel : We need to provide with the domain name, port on which mongrel is started and the number of instances.
Mod_rails : Requires only the domain name.
SVN : Requires only the domain name.
TRAC : We need to specify the domain name , CGI file and the trac_env.

————————————————————————

#!/bin/bash
echo -ne “enter the account name:”
read accname

if [ “$accname” == “” ]
then
echo “———————————————————————–”
echo ” Please enter an account name”
echo “———————————————————————–”
exit
fi

# Funtion to initialize parameters

initi () {
a=0
b=0
o=0
r=0
R=0
}

resellershow ()
{
initi
echo “========================================><==========================================”
echo -e ” The Reseller account – 33[1;38m $reseller 33[0m details ”
echo “========================================><==========================================”
for i in `grep -w $reseller /etc/trueuserowners | cut -f1 -d :`
do
if [ -d /usr/local/apache/conf/userdata/std/2/$i ] && [ $reseller != $i ]
then
a=`grep BalancerMember /usr/local/apache/conf/userdata/std/2/$i/* -R | wc -l`
b=`expr “$a” + “$b”`
p=`grep BalancerMember /usr/local/apache/conf/userdata/std/2/$i/* -R | cut -f4 -d :`
r=`grep RailsBaseURI /usr/local/apache/conf/userdata/std/2/$i/* -R | wc -l`
R=`expr “$r” + “$R”`
if [ $a -ne “0” ] || [ $r -ne “0” ]
then
echo ” Resold : ‘$i’ –> ‘$r’ModRails – $a mongrel (” $p “) ”
fi
elif [ -d /usr/local/apache/conf/userdata/std/2/$i ] && [ $reseller == $i ]
then
a=`grep BalancerMember /usr/local/apache/conf/userdata/std/2/$i/* -R | wc -l`
p=`grep BalancerMember /usr/local/apache/conf/userdata/std/2/$i/* -R | cut -f4 -d :`
b=`expr “$a” + “$b”`
r=`grep RailsBaseURI /usr/local/apache/conf/userdata/std/2/$i/* -R | wc -l`
R=`expr “$r” + “$R”`
if [ $a -ne “0” ] || [ $r -ne “0” ]
then
echo ” Reseller : ‘$i’ –> ‘$r’ModRails – $a mongrel (” $p “) ”
fi

fi

done

echo ” ”

echo “Reseller has a total of ‘$b’ mongrel instance(s) and ‘$R’ Modrails instance(s)”

echo ” ”
}
cut -f2 -d : /etc/userdomains | grep -w $accname > /dev/null 2>&1
if [ $? == 0 ]
then

grep -w $accname /var/cpanel/resellers > /dev/null 2>&1
if [ $? == 0 ]
then
echo “You have entered a reseller name”
reseller=$accname
resellershow
else
initi
if [ -d /usr/local/apache/conf/userdata/std/2/$accname ]
then
a=`grep BalancerMember /usr/local/apache/conf/userdata/std/2/$accname/* -R | wc -l`
b=`expr “$a” + “$b”`
p=`grep BalancerMember /usr/local/apache/conf/userdata/std/2/$accname/* -R | cut -f4 -d :`
r=`grep RailsBaseURI /usr/local/apache/conf/userdata/std/2/$accname/* -R | wc -l`
fi

reseller=`grep -w $accname /etc/trueuserowners | cut -f2 -d : | head -1`
if [ $reseller == “root” ]
then

TYPE=`grep PLAN /var/cpanel/users/$accname | cut -f2 -d =`
if [ $a -gt ‘0’ ] || [ $r -gt ‘0’ ]
then

echo ” ”

echo -e “33[1;38m $accname 33[0m is a $TYPE account and having ‘$r’ Modrails – ‘$a’ mongrel (” $p “) ”
echo ” ”
else
echo ” ”
echo -e “33[1;38m $accname 33[0m  is a $TYPE account”
echo ” ”
fi
else
echo “You have entered a resold account of the reseller: $reseller”
resellershow
fi
fi
else
echo ” ”
echo ” Please enter a valid account name :-(”
echo ” ”
exit 1
fi

echo -ne “Vhost entry type: Mongrel (M/m), Passenger (P/p), SVN (S/s), Trac (T/t) ? ”

read proxy
domaincheck () {
echo -ne “Enter the domain name–>”
read domain
grep $domain /etc/userdomains > /dev/null 2>&1
if [ $? == 0 ]
then
checkver=`grep $domain /etc/userdomains | cut -f2 -d : | head -1`
if [ $accname == $checkver ]
then
mkdir -p /usr/local/apache/conf/userdata/std/2/$accname/$domain
else
echo “The domain name entered is not matching with the account: please cross check it from /etc/userdomains and you are exiting from script”
exit 3
fi
else
echo “Invalid domain name: Sorry you are exiting from script”
exit 2
fi
}
case $proxy in

M | m )

domaincheck
echo -ne “Enter the port number:”
read port
echo ” RewriteEngine On” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” # Rewrite index to check for static” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” RewriteRule ^/$ /index.html [QSA] ” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” # Rewrite to check for Rails cached page” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” RewriteRule ^([^.]+)$ $”1″.html [QSA]” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” # Redirect all non-static requests to cluster” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” ” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf

recinstcheck () {
echo -ne ” enter the Mongrel instances –>”
read instance
if [ $instance -le “10” ] && [ $instance -gt “0” ]
then
for inst in `seq 1 $instance`
do
echo ” BalancerMember http://127.0.0.1:$port” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
port=`expr $port + 1`
done
else
echo “Sorry Maximum allowed is 10 and minimun is 1: Invalid Input and you are exiting from script”
recinstcheck
fi
}
recinstcheck

echo ” ” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “Now execute the command /scripts/ensure_vhost_includes –user=$accname ”

;;

P | p )
domaincheck
echo “RailsBaseURI /” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “Now execute the command /scripts/ensure_vhost_includes –user=$accname ”
;;

T | t )
domaincheck
echo -ne ” Enter the name of the CGI file: ”
read trac
echo -ne ” Enter the name of the trac_env: ”
read env
echo “ScriptAlias /trac “/home/$accname/public_html/cgi-bin/”” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” Options Indexes MultiViews” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AllowOverride None” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” Order allow,deny” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” Allow from all” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” SetEnv TRAC_ENV “/home/$accname/$env”” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AuthType basic” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AuthName trac” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AuthUserFile “/home/$accname/authfiles/svn-htpasswd”” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” Require valid-user” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “Now execute the command /scripts/ensure_vhost_includes –user=$accname ”
;;

S | s )
domaincheck
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “DAV svn” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” SVNParentPath /home/$accname/svn” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AuthType Basic ” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AuthName “Enter Login Info” ” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AuthUserFile /home/$accname/authfiles/svn-htpasswd” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” Require valid-user” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” AuthzSVNAccessFile /home/$accname/authfiles/svn-access.conf” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo ” Satisfy Any” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “” >> /usr/local/apache/conf/userdata/std/2/$accname/$domain/custom.conf
echo “Now execute the command /scripts/ensure_vhost_includes –user=$accname ”
;;

* )

echo “Invalid input, you are exiting from the script”
exit
;;

esac


Shares
Contact Us On WhatsApp