Difference between revisions of "SME Site Maker"

From SME Server
Jump to navigationJump to search
(Changed category to HowTo as this is not a contrib in being a package in RPM format.)
Line 24: Line 24:
 
   
 
   
 
  # Author: Normando Hall (PicsOne)
 
  # Author: Normando Hall (PicsOne)
  # Version: 1.0
+
  # Version: 1.1
  # 06/06/2007
+
  # 07/06/2007 (d/m/Y)
   
+
#
 +
#
 +
  # Changelog
 +
#
 +
# 1.1 (by Normando Hall)
 +
# Added php open_basedir restriction
 +
# Set debug variable
 +
#
 +
# 1.0 (by Normando Hall)
 +
# Initial release
 +
 
 
  clear
 
  clear
 
  echo "========================================================"
 
  echo "========================================================"
Line 44: Line 54:
 
  read x
 
  read x
 
  custom_httpd_dir=/etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
 
  custom_httpd_dir=/etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
 +
f_dbg=0      #Set to 1 to view the variabls content at the end.
 
  clear
 
  clear
 
  ######################### - Site ROOT - ##################################3
 
  ######################### - Site ROOT - ##################################3
Line 253: Line 264:
 
  esac
 
  esac
 
  fi
 
  fi
 +
 +
obd="$f_root"
 +
        clear
 +
        echo
 +
        echo "Do you want to modify open_basedir restriction?"
 +
        echo "Default give php access only to local siteroot (f_root)"
 +
        echo "Use with care, this is a security risk"
 +
        echo "(Y/N/Enter)"
 +
        echo ":"
 +
read YESNO
 +
case "$YESNO" in
 +
"Y" | "y" )
 +
f_obd="1";;
 +
"N" | "n" )
 +
f_obd="0";;
 +
*)
 +
f_obd="0";;
 +
esac
 +
 +
if [ "f_obd" = "1" ]
 +
then
 +
clear
 +
 +
ANSWER=1
 +
while [ $ANSWER = 1 ]
 +
do
 +
        clear
 +
        echo
 +
        echo "Please enter the directory you want to allow PHP can access."
 +
        echo "If you specify more than one, separate with \":\""
 +
        echo "Example: /dir_one:/dir_two"
 +
        echo ":"
 +
 +
read open_bd
 +
if [  "$open_bd"  != "" ]
 +
then
 +
obd=$open_bd
 +
ANSWER=0
 +
else
 +
    clear
 +
        echo
 +
        echo "You have not provide a directory name. Hit enter to try again"
 +
read x
 +
fi
 +
done
 +
fi
 +
 
  ###################### - CGI - #######################################
 
  ###################### - CGI - #######################################
 
  clear
 
  clear
Line 445: Line 503:
 
  echo 'php_admin_value eaccelerator.enable 1' >> $c_file
 
  echo 'php_admin_value eaccelerator.enable 1' >> $c_file
 
  fi
 
  fi
 +
 +
echo "php_admin_value open_basedir $obd" >> $c_file
 
   
 
   
 
  fi
 
  fi
Line 450: Line 510:
 
   
 
   
 
  clear
 
  clear
  # for debug only
+
  #################- DEBUG -############################
  # echo "$files_root"
+
  if [ "$dbg" = "1" ]
# echo "$f_root"
+
then
# echo "$alias_root"
+
echo "$files_root"
# echo "$a_root"
+
echo "$f_root"
# echo "$f_ssl"
+
echo "$alias_root"
# echo "$f_idx"
+
echo "$a_root"
# echo "$f_aov"
+
echo "$f_ssl"
# echo "$f_inc"
+
echo "$f_idx"
# echo "$php"
+
echo "$f_aov"
# echo "$f_fop"
+
echo "$f_inc"
# echo "$f_eac"
+
echo "$php"
# echo "$f_rgl"
+
echo "$f_fop"
# echo "$cgi"
+
echo "$f_eac"
# echo "$cgi_root"
+
echo "$f_rgl"
# echo "$c_root"
+
echo "$cgi"
# echo "$calias_root"
+
echo "$cgi_root"
# echo "$ca_root"
+
echo "$c_root"
# echo "$conf_name"
+
echo "$calias_root"
# echo "$c_name"
+
echo "$ca_root"
# echo "$custom_httpd_dir"
+
echo "$conf_name"
# echo "$c_file"
+
echo "$c_name"
# echo "$fopt"
+
echo "$custom_httpd_dir"
   
+
echo "$c_file"
 +
echo "$fopt"
 +
echo "$f_obd"
 +
echo "$open_bd"
 +
echo "$obd"
 +
  fi
 
  expand-template /etc/httpd/conf/httpd.conf
 
  expand-template /etc/httpd/conf/httpd.conf
 
  /etc/init.d/httpd-e-smith restart
 
  /etc/init.d/httpd-e-smith restart

Revision as of 14:54, 7 April 2007

SME Site Maker

This script is designed to help you when create a new web site under /opt directory.

If you improve or add new functions, please update this wiki page.

Template:DrawBoxNote

Your can download from here: SMESiteMaker (It's possible to upload non image files to wiki?)

Please, use this thread in the forum to any dude or comments:

SME SM Forum thread

Untar and execute.

Enjoy.


Code:

#!/bin/bash

# Author: Normando Hall (PicsOne)
# Version: 1.1
# 07/06/2007  (d/m/Y)
#
#
# Changelog
#
# 1.1 (by Normando Hall)
# Added php open_basedir restriction
# Set debug variable
#
# 1.0 (by Normando Hall)
# Initial release
clear
echo "========================================================"
echo "=                SME Site Maker Script                 ="
echo "=                                                      ="
echo "= This script will configure your SME webserver, and   ="
echo "= make the necesary directory to hold your site.       ="
echo "=                                                      ="
echo "= No express or implied warranties are provided and its="
echo "= usage is at your own risk.                           ="
echo "=                                                      ="
echo "= If you feel confortable with the above then press    ="
echo "= enter if not press Ctrl+C to abort the configuration ="
echo "= script.                                              ="
echo "=                                                      ="
echo "========================================================"
read x
custom_httpd_dir=/etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
f_dbg=0       #Set to 1 to view the variabls content at the end.
clear
######################### - Site ROOT - ##################################3
f_root=""
ANSWER=1
while [ $ANSWER = 1 ]
do
        clear
        echo " Please enter a directory name where you put the site files."
	echo " The directory is created under /opt dir."
        echo " Example \"mySite\" without \" \". No include end or trailing slash"
        echo ":"
read files_root
if [  "$files_root"  != "" ]
then
f_root=/opt/$files_root
if [ -d $f_root ]
then
	clear
	echo " This directory already exist. If you want to remove and all contents"
	echo " hit Y, or N to continue without change"
	echo " (Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
YESNO=1
rm -rf $f_root;;
"N" | "n" )
YESNO=2;;
*)
YESNO=2;;
esac
fi
ANSWER=0  

if [ "$YESNO" != "2" ]
then
mkdir -p $f_root
chown root.www $f_root
chmod 644 $f_root
fi

else
	clear
        echo
        echo "You have not enter a directory name. Hit enter to try again"
read x
fi
done
#################### -ALIAS - ######################################
clear
a_root=""
ANSWER=1
while [ $ANSWER = 1 ]
do
        clear
        echo
        echo "Please enter an alias name to access your site."
        echo "Example \"wiki\" without \" \". No include end or trailing slash"
        echo ":" 

read alias_root
if [  "$alias_root"  != "" ]
then
a_root=/$alias_root
ANSWER=0
else
	clear
        echo
        echo "You have not provide an alias name. Hit enter to try again"
read x
fi
done
##################### - SSL - ####################################
clear
f_ssl=""
        clear
        echo
        echo "Do you want to force SSL?"
        echo "This is used to force to secure http (https)"
        echo "(Y/N/Enter)"
        echo ":"

read YESNO
case "$YESNO" in
"Y" | "y" )
f_ssl="1";;
"N" | "n" )
f_ssl="0";;
*)
f_ssl="0";;
esac
############################ - INDEX - ############################################
clear
f_idx=""
        clear
        echo
        echo "Do you want to allow directory index?"
        echo "This is used to index a directory if no index.htm/l or index.php file is available"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
f_idx="1";;
"N" | "n" )
f_idx="0";;
*)
f_idx="0";;
esac
#################### - AllowOverride - ######################################
clear
f_aov=""
        clear
        echo
        echo "Do you want to set AllowOverride All?"
        echo "This is used to allow process .htaccess files in your site dir"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
f_aov="1";;
"N" | "n" )
f_aov="0";;
*)
f_aov="0";;
esac
####################### - Includes - ###################################
clear
f_inc=""
        clear
        echo
        echo "Do you want to allow includes?"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
f_inc="1";;
"N" | "n" )
f_inc="0";;
*)
f_inc="0";;
esac
##################### - PHP - #####################################
clear
php=""
        clear
        echo
        echo "Do you want to execute PHP?"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
php="1";;
"N" | "n" )
php="0";;
*)
php="0";;
esac

if [ "$php" = "1" ]
then
        clear
        echo
        echo "Do you want to allow_url_fopen?"
        echo "This allow open and access remote files in your php scripts"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
f_fop="1";;
"N" | "n" )
f_fop="0";;
*)
f_fop="0";;
esac
        clear
        echo
        echo "If you have eaccelerator, want to enabled?"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
f_eac="1";;
"N" | "n" )
f_eac="0";;
*)
f_eac="0";;
esac
        clear
        echo
        echo "Do you want to allow register globals?"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
f_rgl="1";;
"N" | "n" )
f_rgl="0";;
*)
f_rgl="0";;
esac
fi

obd="$f_root"
        clear
        echo
        echo "Do you want to modify open_basedir restriction?"
        echo "Default give php access only to local siteroot (f_root)"
        echo "Use with care, this is a security risk"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
f_obd="1";;
"N" | "n" )
f_obd="0";;
*)
f_obd="0";;
esac

if [ "f_obd" = "1" ]
then
clear

ANSWER=1
while [ $ANSWER = 1 ]
do
        clear
        echo
        echo "Please enter the directory you want to allow PHP can access."
        echo "If you specify more than one, separate with \":\""
        echo "Example: /dir_one:/dir_two"
        echo ":"

read open_bd
if [  "$open_bd"  != "" ]
then
obd=$open_bd
ANSWER=0
else
    clear
        echo
        echo "You have not provide a directory name. Hit enter to try again"
read x
fi
done
fi

###################### - CGI - #######################################
clear
cgi=""
        clear
        echo
        echo "Do you want to execute CGI?"
        echo "(Y/N/Enter)"
        echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
cgi="1";;
"N" | "n" )
cgi="0";;
*)
cgi="0";;
esac

if [ "$cgi" = "1" ]
then
ANSWER=1
while [ $ANSWER = 1 ]
do
        clear
        echo
        echo "Please enter a directory name to hold your cgi scripts."
        echo "If you don't enter a directory, assume you want to allow cgi scripts in $f_root root directory."
        echo "If you provide a directory, this is created under $f_root/your_cgi_dir directory"
        echo ":"
read cgi_root
if [  "$cgi_root"  != "" ]
then
c_root=$f_root/$cgi_root
YESNO=1
if [ -d $c_root ]
then
	clear
	echo "This directory already exist. If you want to remove and all contents"
	echo "hit Y, or N to continue without change"
	echo "(Y/N/Enter)"
	echo ":"
read YESNO
case "$YESNO" in
"Y" | "y" )
YESNO=1
rm -rf $c_root;;
"N" | "n" )
YESNO=2;;
*)
YESNO=2;;
esac
fi
ANSWER=0

if [ "$YESNO" != "2" ]
then
mkdir -p $c_root
chown root.www $c_root
chmod 777 $c_root
fi
else
ANSWER=0
c_root=$f_root
fi
done

if [ "$c_root" = "$f_root" ]
then
ca_root=$a_root
chown root.www $ca_root
chmod 777 $ca_root
else
clear
###################### - CGI ALIAS -#########################################
ca_root=""
ANSWER=1
while [ $ANSWER = 1 ]
do
        clear
        echo
        echo "Please, provide a cgi alias."
        echo ":"
read calias_root
if [  "$calias_root"  != "" ]
then
ca_root=/$calias_root
ANSWER=0
else
	clear
        echo
        echo "You have not enter a cgi alias name. Hit enter to try again"
read x
fi
done
fi
fi
#################### - Configuration NAME - ############################################
clear
c_name=""
ANSWER=1
while [ $ANSWER = 1 ]
do
        clear
        echo
        echo "Please enter a name for this configuration."
        echo ":"
read conf_name
if [  "$conf_name"  != "" ]
then
c_name=99SMESiteMaker_$conf_name
ANSWER=0
else
	clear
        echo
        echo "You have not provide a configuration name. Hit enter to try again"
read x
fi
done


################ - Final Step - ####################################
c_file=$custom_httpd_dir/$c_name
if [ -d $custom_httpd_dir ]
then
custom_httpd_dir=$custom_httpd_dir
#Anyone know a negate if for check? = if [directory NOT exist $dir]
else
mkdir -p $custom_httpd_dir
fi
fopt=""
touch $c_file
echo ' ' > $c_file
echo "Alias $a_root $f_root" >> $c_file
if [ "$cgi" = "1" ]
then
echo "ScriptAlias $ca_root $c_root" >> $c_file
fi
echo "<Directory $f_root>" >> $c_file
if [ "$f_ssl" = "1" ]
then
echo 'SSLRequireSSL on' >> $c_file
#echo 'RequireSSL on' >> $c_file #for SME6
fi
if [ "$php" = "1" ]
then
echo 'AddType application/x-httpd-php .php .php3 .phtml' >> $c_file
fi
if [ "$f_idx" = "1" ]||[ "$f_inc" = "1" ]||[ "$f_aov" = "1" ]
then
fopt="Options "
if [ "$f_idx" = "1" ]
then
fopt="$fopt Indexes "
fi
if [ "$f_inc" = "1" ]
then
fopt="$fopt +Includes "
fi
if [ "$f_aov" = "1" ]
then
fopt="$fopt FollowSymLinks "
fi
echo "$fopt" >> $c_file
if [ "$f_aov" = "1" ]
then
echo 'AllowOverride all' >> $c_file
fi
fi
echo 'order deny,allow' >> $c_file
echo 'deny from all' >> $c_file
echo 'allow from all' >> $c_file
if [ "$php" = "1" ]
then

if [ "$f_fop" = "1" ]
then
echo 'php_flag register_globals on' >> $c_file
else
echo 'php_flag register_globals off' >> $c_file
fi

if [ "$f_rgl" = "1" ]
then
echo 'php_admin_flag allow_url_fopen on' >> $c_file
else
echo 'php_admin_flag allow_url_fopen off' >> $c_file
fi

if [ "$f_eac" = "1" ]
then
echo 'php_admin_value eaccelerator.enable 1' >> $c_file
fi

echo "php_admin_value open_basedir $obd" >> $c_file

fi
echo '</Directory>' >> $c_file

clear
#################- DEBUG -############################
if [ "$dbg" = "1" ]
then
	echo "$files_root"
	echo "$f_root"
	echo "$alias_root"
	echo "$a_root"
	echo "$f_ssl"
	echo "$f_idx"
	echo "$f_aov"
	echo "$f_inc"
	echo "$php"
	echo "$f_fop"
	echo "$f_eac"
	echo "$f_rgl"
	echo "$cgi"
	echo "$cgi_root"
	echo "$c_root"
	echo "$calias_root"
	echo "$ca_root"
	echo "$conf_name"
	echo "$c_name"
	echo "$custom_httpd_dir"
	echo "$c_file"
	echo "$fopt"
	echo "$f_obd"
	echo "$open_bd"
	echo "$obd"
fi 
expand-template /etc/httpd/conf/httpd.conf
/etc/init.d/httpd-e-smith restart
# /sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf  # For SME6
# service httpd restart				    	    # For SME6
echo "====================================================="
echo "= Installation of you site is complete.             ="
echo "= Now you can copy your site files under $f_root.   ="
echo "= Access your site in http://your_domain/$alias_root="
echo "====================================================="