script to add additional FTP user to a domain

This script does the following
 
ths scritp will only add additional FTP user to a domain
 
#!/bin/bash

#format
#script domain.com username foldername password sizeinMB

domain_system_user=`cat /etc/passwd | sed 's/:/ /g' |awk '{print $1  $5 }' |sed 's/\// /g' |awk '{print $3" "  }' |sed -n "/${1}/P" |sed 's/\./ /g' |awk '{print $1}' `

echo -e  "Chking if domin name exist "
if [ -d /websites/"$1" ]; then
echo -e "the domin exist"
echo -e "chking to see if user exist"
     if [ "`cat /usr/local/pureftpd/etc/pureftpd.passwd  | sed 's/:/ /g' |awk '{print $1  $5 }' |sed 's/\// /g' |awk '{print $3" " $1 }' |sed -n "/${1} ${2}/P"`" != "$1 $2"  ]; then

echo -e "chking to see if dir exist"
          if [ -d /websites/"$1"/"$3"  ]; then
echo -e "the dir $3 exist"
      echo -e "adding ftp user"
(echo $4; echo $4 ) | /usr/local/pureftpd/bin/pure-pw useradd "$2" -f /usr/local/pureftpd/etc/pureftpd.passwd  -u "$domain_system_user" -d /websites/"$1"/"$3"  -m

      else
echo -e "the dir $3 does not exist ===> the ftp user is not created"
           fi
    else
echo -e  "the user is all read present"
fi
else
echo -e "the domin does not exist"
fi



--

shell script to delete directory protection /htaccess



Following  is  what the script does
 
1. chks if the domin exist
2. chks if there is alreaady a protected folder
3. if both are true then it removes the content frm the httpd_vhost.conf file
 
 
#!/bin/bash

read -p "Enter your domain: " d
read -p "Enter the directory that you want to delete: " f

if [ -d /websites/"$d" ]; then

   if [ -d /websites/"$d"/web/"$f" ]; then

      if [  -n "$(sed -n "/\#dir_protection_${d}_${f}#/,/&/p" /usr/local/apache2/conf/extra/httpd_vhost.conf)"  ]; then
sed -i "/\#dir_protection_${d}_${f}\#/,/\#dir_protection_${d}_${f}\#/d" /usr/local/apache2/conf/extra/httpd_vhost.conf
      else
echo -e "virtusl host doesnot exist"
      fi
  else
echo -e "  the folder /$f does not exist"
   fi
else
echo -e "the Domain $d does not exist"
fi
 


--

shell script to add directory protection or htaccess

This is a shell script to add directory protection or htaccess
the following is what the script does
 
1.it will read the domain nae and the folder name to be protected 
2. it will chk heatehr the domin dir exist 
3. it will chk if the htpasswd file exist .. if not it create 
4. if all the abel is true then it adds content in httpd_vhsot.conf file  
 
#!/bin/bash -x
#script to add directory protection

read -p "enter the domain name: " d
read -p "enter the dir that you want to protect: " f

var=`sed -n "/\#dir_protection_${d}_${f}\#/,/\#dir_protection_${d}_${f}\#/P" /usr/local/apache2/conf/extra/httpd_vhost.conf`

if [ -d /websites/"$d"/web/"$f" ]; then

    if [ -d /websites/privatefolderpasswd/"$d" -a -e /websites/privatefolderpasswd/"$d"/htpasswd  ]; then

         if [ -n "$var" ]; then
read -p "Enter user name for the folder you want to protect: " u
read -p "Enter  password for the user: " p
/usr/local/apache2/bin/htpasswd -bc /websites/privatefolderpasswd/"$d"/htpasswd "$u" "$p"

sed -i "/\#DIR_PROTECT_${d}2631\#/a\#################dir_protection_${d}_${f}#################\n<Directory \/websites\/${d}\/web\/awstats>\nAllowOverride  AuthConfig\nAuthName "MyPrivateStuff"\nAuthType Basic\nAuthGroupFile \/dev\/null\nAuthUserFile /websites\/privatefolderpasswd\/${d}/htpasswd\nAuthName Enterpassword\nRequire valid-user\n </Directory>\n#################dir_protection_${d}_${f}#################" /usr/local/apache2/conf/extra/httpd_vhost.conf

exit 1

         else
echo -e "this should not be here"
         fi
    else
echo -e "creating  dir structure to store htacess password file"

mkdir /websites/privatefolderpasswd/"$d"
touch /websites/privatefolderpasswd/"$d"/htpasswd

read -p "Enter user name for the folder you want to protect: " u
read -p "Enter  password for the user: " p
/usr/local/apache2/bin/htpasswd -bc /websites/privatefolderpasswd/"$d"/htpasswd "$u" "$p"

sed -i "/\#DIR_PROTECT_${d}2631\#/a\#################dir_protection_${d}_${f}#################\n<Directory \/websites\/${d}\/web\/awstats>\nAllowOverride  AuthConfig\nAuthName "MyPrivateStuff"\nAuthType Basic\nAuthGroupFile \/dev\/null\nAuthUserFile /websites\/privatefolderpasswd\/${d}/htpasswd\nAuthName Enterpassword\nRequire valid-user\n </Directory>\n#################dir_protection_${d}_${f}#################" /usr/local/apache2/conf/extra/httpd_vhost.conf
echo -e "The htaccess is created now"
    fi
else
echo -e "The domain does not exist"
exit 1
fi



--

ebooks for perl

http://www.costlowcorp.com/~erik/STY-Perl-24Hours.pdf

http://www.torrentreactor.net/torrents/632653/(Ebook-Pdf)-Teach-Yourself-Perl-In-21

--

ebook for perl

http://wwwacs.gantep.edu.tr/docs/perl-ebook/

--

Script to Add FTP user

This scipt i used ato the do the following
 
1. if the domain is present  then continue to 1.1  else the domin does not exist  
1.1. if  the FTP user is present then continutue to 1.1.1
1.1.1 if the directory exist ...execute command to add ftpuse to that particular dir
 
 
 
#!/bin/bash -x

#format
#script domain.com username foldername password sizeinMB

echo -e  "Chking if domin name exist "
if [ -d /websites/"$1" ]; then
echo -e "the domin exist"
echo -e "chking to see if user exist"
     if [ "`cat /usr/local/pureftpd/etc/pureftpd.passwd  | sed 's/:/ /g' |awk '{print $1}' |sed -n "/${2}/P"`" != "$2"  ]; then

echo -e "chking to see if dir exist"
          if [ -d /websites/"$1"/"$3"  ]; then
echo -e "the dir $3 exist"
      echo -e "adding ftp user"
(echo $4; echo $4 ) | /usr/local/pureftpd/bin/pure-pw useradd "$2" -f /usr/local/pureftpd/etc/pureftpd.passwd  -u "$2" -d /websites/"$1"/"$3"  -m

      else
echo -e "the dir $3 does not exist"
           fi
    else
echo -e  "the user is all read present"
fi
else
echo -e "the domin does not exist"
fi



--

script to add domain / ftp user account

Here is a script that does the following :

1. check if domain is present
2. if domain is present then it creates a system user
3. It creates the home directory structure
4 . within the home directory structure it creates  the various dir.
5. sets permission to those dir
6.  write the vhost directive in to the http.conf configuration file
7 . Restart apace ( gracefully )

#!/bin/bash
#steps to set up a website
echo -e " Enter you domain name "
read $1

domain_com=` echo $domain |sed s/\.com//g `
domain_in=`echo $domain |sed s/\.in//g`
domain_net=`echo $domain |sed s/\.net//g`
domain_co_in=`echo $domain |sed s/\.co.in//g`
domain_02=`cat /etc/passwd |grep $domain |sed s/:/\ /g |awk '{print $1}'`

if [ "$domain_com" =  "$domain_02" ]; then
echo -e " the domain exist "
exit 1
fi

echo -e "Please enter  user for for $domain  "
read user
if [ "$user" = "$domain_02" ]; then
echo -e " user exist quiting proces "
else
useradd -d /websites/"$domain" -s /sbin/nologin "$user"
echo -e " created domain $domain "


echo -e "adding ftp user "
echo  "$domain"
(echo $domain_com; echo $domain_com ) | /usr/local/pureftpd/bin/pure-pw useradd "$user" -f /usr/local/pureftpd/etc/pureftpd.passwd  -u "$user" -d /websites/"$domain" -m
echo -e " adding user sucessful "

echo -e "creating directory structure "
mkdir /websites/"$domain"/web /websites/"$domain"/logs /websites/"$domain"/private /websites/"$domain"/data /websites/"$domain"/cgi-bin
echo -e "sucessfully created directory structure   "


echo -e " we chang the permission for the the $user "
chmod 711 /websites/"$domain"/ && chmod 711 /websites/"$domain"/*

echo -e " we change the ownership   for  the $domain "
chown "$user":"$user" /websites/"$domain" && chown "$user":"$user" /websites/"$domain"/*
echo -e " changes for $user was sucessful "


echo -e "Creating the Vhost directive domain $domain "

echo -e "
######################"$domain"2631###################

<VirtualHost 192.168.0.244:80>
ServerAdmin admin@ashish.sys.qualiproj.com
ServerName "$user".sys.qualiproj.qualispace.com
ServerAlias www."$user".sys.qualiproj.qualispace.com
DocumentRoot /websites/"$domain"/web
##############MIME_TYPE_"$domain"2631##################
<Directory /websites/"$domain"/web>
    Options -MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    AllowOverride FileInfo AuthConfig Limit
    Order allow,deny
    Allow from all
</Directory>
ErrorLog /websites/"$domain"/logs/"$user".sys.qualiproj.error_log
CustomLog /websites/"$domain"/logs/$user.sys.qualiproj.access_log common
ScriptAlias /cgi-bin/ "/websites/"$domain"/cgi-bin/"
<Directory "/websites/"$domain"/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
       Order allow,deny
        Allow from all
</Directory>
</VirtualHost>
 " >>  /usr/local/apache2/conf/extra/httpd_vhost.conf

echo -e "Sucessfully created  the Vhost directive domain $domain "

echo -e " restarting httpd "
/etc/init.d/httpd graceful

echo -e "copying test html page to web folder "
cp -R /websites/agnello.com/web/bob.html /websites/"$domain"/web/index.html
echo -e "done "

echo -e " you can now log on to http://www."$user".sys.qualiproj.qualispace.com"

fi

 

--

A shell script to append MIME Type after a certain pattern

A shell script to append MIME Type after a certain pattern

in the bellow script

a ---> stands for append
\n ---> to next line

#!/bin/bash -x
#script to add mime type

add_mime_type_01 ()
{
echo -e enter domain name
if [ -d /websites/"$1" ]; then
sed -i "/MIME_TYPE_$12631/a\AddType application x-httpd-php .php
\nAddType application x-httpd-php-source .phps"
/usr/local/apache2/conf/extra/httpd_vhost.conf
echo -e " add mime type to $1 "
else
"the domin does not exist or has been deleted "
echo -e "execuiting this command "
fi
}

echo -e "Are you sure you want to add mime type for $1"
read answer
case $answer in
Y|yes|YES ) add_mime_type_01 $1
;;
N|No|NO|n ) echo " you have exited the progam "
;;
* ) echo " please type yes or no "
esac

Now aon you commany line jsut typme

script_command.sh yourdomain.com


--

adding passwod to ftpuser as one single command

If you want to add a ftp user the usual command is

pure-pw useradd nokia -f /usr/local/pureftpd/etc/pureftpd.passwd -u
nokia -d /home/website/nokia.com -m

it will prompt you to type and retype your password . Now if we want
to add the password on the same command line we can add

(echo name123; echo name123) | /usr/local/pureftpd/bin/pure-pw
passwd passsword -f /usr/local/pureftpd/etc/pureftpd.passwd -m

the -m creates a db file

--

steps to Installing mod_ssl for multiple domains

Apache : mod_ssl for virtual hosting

1. The apache server should be compiled with mod_ssl enabled,. You can check this in the httpd.conf file

LoadModule ssl_module modules/mod_ssl.so

2. Make the followin directory structure

mkdir /usr/local/apache2/conf/domains_ssl/

mkdir /usr/local/apache2/conf/domains_ssl/nokia.com/

3. once this is done create your self-signed ssl certificate and your ssl private key using the openssl toolkit. ( for production purpose you may want to purchase your certificate)

( in orde that apache should not ask fora passwork when it restart we do the following )

cd /usr/local/apache2/conf/domains_ssl/name1.com/ ------>

your location of the keys for domain name1

Step 1: Generate Private Key

openssl genrsa -des3 -out server.key 1024

(

N.B: make sure that that the CN matches that of the domain name )

Step 2: Generate CSR

openssl req -new -key server.key -out server.csr

Step 3: Remove Passphrase

cp server.key server.key.org

openssl rsa -in server.key.org -out server.key

Step 4: Sign the Certificate

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

you would have the follwing keys generated.

server.crt server.csr server.key server.key.org

 

Once this is done go to the very last line in the httpd.conf file

( addthe following if not already there )

<IfModule ssl_module>

Listen 443

SSLRandomSeed startup builtin

SSLRandomSeed connect builtin

</IfModule>

now in the httpd-vhost.conf file ( /usr/local/apache2/conf/extra/httpd-vhosts.conf ) add the following

NameVirtualHost 192.168.0.244:443

<VirtualHost 192.168.0.244:443>

ServerAdmin admin@name1.sys.qualiproj.com

ServerName name1.sys.qualiproj.qualispace.com

ServerAlias www.name1.sys.qualiproj.qualispace.com

DocumentRoot /websites/name1.com/web

SSLEngine on

SSLCertificateKeyFile /usr/local/apache2/conf/domains_ssl/name1.com/server.key

SSLCertificateFile /usr/local/apache2/conf/domains_ssl/name1.com/server.crt

ErrorLog /websites/name1.com/logs/name1.sys.qualiproj.error_log

CustomLog /websites/name1.com/logs/name1.sys.qualiproj.access_log common

</VirtualHost>

  

Now you can restart apache . it will not prompt you for a password .

Now view you site

https://domain.com

 

 

 

Other Articles

Enter your email address: