File "apacheadmin.sh"
Full path: /www/wwwroot/fabriciovc.eti.br/downloads/windows/apt/iproute/apacheadmin.sh
File size: 7.45 KiB (7633 bytes)
MIME-type: text/x-shellscript
Charset: utf-8
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Nota de Copyright #
# Copyright C 2008 Fabricio Vaccari Constanski #
# fabriciovc[em]fabriciovc.eti.br - 26/11/2008 #
# Ultima atualizacao em : 26/01/2009 - fabriciovc #
# #
# Este trabalho esta licenciado sob uma Licenca Creative Commons Atribuicao- #
# Compartilhamento pela mesma Licenca 2.5 Brasil. Para ver uma copia desta #
# licenca, visite http://creativecommons.org/licenses/by-sa/2.5/br/ #
# ou envie uma carta para Creative Commons, 171 Second Street, Suite 300, #
# San Francisco, California 94105, USA. #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#- PATHS DE COMANDOS ----------------------------------------------------------
A2ENSITE=`which a2ensite`
A2DISSITE=`which a2dissite`
CAT=`which cat`
CHMOD=`which chmod`
CHOWN=`which chown`
CP=`which cp`
CUT=`which cut`
DATE=`which date`
LS=`which ls`
MKDIR=`which mkdir`
MYSQL=`which mysql`
MV=`which mv`
RM=`which rm`
SED=`which sed`
#- USUARIOS E GRUPOS PARA DEFINICAO DE PERMISSOES -----------------------------
WWW_USER='www-data'
WWW_GROUP='www-data'
#- PATHS DE ARQUIVOS E DIRETORIOS ---------------------------------------------
WWW_DIR="/srv/www" # DocumentRoot do Apache2
WEBSITE_DIR="$WWW_DIR/website" # DocumentRoot dos sites Apache2
SITES_AVAILABLE="/etc/apache2/sites-available" # Arquivos de hosts virtuais
#- FUNCAO _CHECKOK - VERIFICACAO DE COMANDOS EXECUTADOS -----------------------
_CHECKOK () {
if [ $? -eq 0 ]; then
echo -e " \\033[1;32mOK\\033[0;39m"
else
echo -e " \\033[1;31mFALHOU\\033[0;39m"
fi
}
#------------------------------------------------------------------------------
#- FUNCAO _GET_DOMAIN - OBTEM O DOMINIO A SE UTILIZADO ------------------------
_GET_DOMAIN () {
echo -n "Digite o nome do dominio: "
read DOMAIN
if [ -z $DOMAIN ]; then
echo -e "\\033[1;31mDominio nao informado!!!\\033[0;39m"
_MENU
fi
DOM=$(echo $DOMAIN | egrep '([^\.])+([0-9A-Za-z-]+)\.([A-Za-z]{3,})+(\.([A-Za-z]{2}))?$');
if [ -z $DOM ]; then
echo -e "\\033[1;31mFormato do dominio invalido!!!\\033[0;39m"
echo -e "O formato correto e: \\033[1;33mdominio.com(.br)\\033[0;39m"
_MENU
fi
#echo -n "Digite o IP do endereço www.${DOMAIN}: "
#read IP_WWW
#if [ -z $IP_WWW ]; then
# echo -e "\\033[1;31mFormato de IP invalido!!!\\033[0;39m"
# echo -e "O formato correto e: \\033[1;33mx.y.w.z\\033[0;39m"
# _MENU
#fi
#echo -n "Digite o IP do endereço mail.${DOMAIN}: "
#read IP_MAIL
#if [ -z $IP_MAIL ]; then
# echo -e "\\033[1;31mFormato de IP invalido!!!\\033[0;39m"
# echo -e "O formato correto e: \\033[1;33mx.y.w.z\\033[0;39m"
# _MENU
#fi
}
#------------------------------------------------------------------------------
#- FUNCAO _APACHE -------------------------------------------------------------
_APACHE () {
if [ "$OPT" = "Criar Dominio" ]; then
echo
echo -n "Adicionando entrada www.${DOMAIN} no apache..."
$CAT << EOF > $SITES_AVAILABLE/www.$DOMAIN
<VirtualHost www.$DOMAIN:80>
ServerAdmin webmaster@$DOMAIN
ServerName www.$DOMAIN
ServerAlias $DOMAIN
ServerAlias ns1.$DOMAIN
ServerAlias ns2.$DOMAIN
DocumentRoot $WEBSITE_DIR/$DOMAIN
<Directory $WEBSITE_DIR/$DOMAIN>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ "$WEBSITE_DIR/$DOMAIN/cgi-bin/"
<Directory "$WEBSITE_DIR/$DOMAIN/cgi-bin/">
AllowOverride All
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ServerSignature Off
</VirtualHost>
EOF
_CHECKOK
echo -n "Adicionando entrada mail.${DOMAIN} no apache..."
$CAT << EOF > $SITES_AVAILABLE/mail.$DOMAIN
<VirtualHost mail.$DOMAIN:80>
ServerAdmin webmaster@$DOMAIN
ServerName mail.$DOMAIN
ServerAlias imap.$DOMAIN
ServerAlias pop.$DOMAIN
ServerAlias pop3.$DOMAIN
ServerAlias smtp.$DOMAIN
ServerAlias webmail.$DOMAIN
DocumentRoot $WWW_DIR/webmail/
<Directory $WWW_DIR/webmail/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerSignature Off
</VirtualHost>
EOF
_CHECKOK
echo -n "Criando diretorio $WEBSITE_DIR/$DOMAIN..."
$MKDIR -p $WEBSITE_DIR/$DOMAIN
_CHECKOK
echo -n "Copiando pagina de construcao para $WEBSITE_DIR/$DOMAIN..."
$CP $WWW_DIR/construcao/* $WEBSITE_DIR/$DOMAIN/
_CHECKOK
echo -n "Ativando o dominio $DOMAIN no apache..."
$A2ENSITE "*.${DOMAIN}" 2>&1 > /dev/null
_CHECKOK
elif [ "$OPT" = "Excluir Dominio" ]; then
echo -n "Removendo diretorio $WEBSITE_DIR/$DOMAIN..."
$RM -rf $WEBSITE_DIR/$DOMAIN
_CHECKOK
echo -n "Desativando o dominio $DOMAIN no apache..."
$A2DISSITE "*.${DOMAIN}" 2>&1 > /dev/null
_CHECKOK
echo -n "Removendo entradas do dominio ${DOMAIN} do apache2..."
$RM -f $SITES_AVAILABLE/*.${DOMAIN}
_CHECKOK
fi
echo -n "Relendo as configuracoes do apache2..."
/etc/init.d/apache2 reload 2>&1 > /dev/null
_CHECKOK
}
#------------------------------------------------------------------------------
#- FUNCAO _CREATE_DOMAIN ------------------------------------------------------
_CREATE_DOMAIN () {
_GET_DOMAIN
if [ -d $WEBSITE_DIR/$DOMAIN ]; then
echo -e "\\033[1;33mDominio ja existe!!!\\033[0;39m"
else
_APACHE
fi
}
#------------------------------------------------------------------------------
#- FUNCAO _LIST_DOMAIN --------------------------------------------------------
_LIST_DOMAIN () {
echo
echo -e "\\033[1;33mLista de dominios cadastrados no apache:\\033[0;39m"
for WWW_LIST in `$LS ${WEBSITE_DIR} 2> /dev/null`
do
echo -e "-> \\033[1;34m$WWW_LIST\\033[0;39m"
done
}
#------------------------------------------------------------------------------
#- FUNCAO _DELETE_DOMAIN ------------------------------------------------------
_DELETE_DOMAIN () {
_LIST_DOMAIN
_GET_DOMAIN
if [ ! -d $WEBSITE_DIR/$DOMAIN ]; then
echo -e "\\033[1;31mDominio nao removido!!!\\033[0;39m"
echo -e "\\033[1;33mDominio inexistente!!!\\033[0;39m"
else
echo -n "Deseja remover o dominio? (s/n): "
read SN
if [ -z $SN ] || [ $SN != s ]; then
echo -e "\\033[1;31mDominio nao removido!!!\\033[0;39m"
else
_APACHE
fi
fi
}
#------------------------------------------------------------------------------
#- FUNCAO _MENU ---------------------------------------------------------------
_MENU () {
unset DOMAIN
echo
echo "Escolha uma opcao a seguir:"
select OPT in "Criar Dominio" "Listar Dominios" "Excluir Dominio" "Sair";
do
case $OPT in
"Criar Dominio") _CREATE_DOMAIN; _MENU ;;
"Listar Dominios") _LIST_DOMAIN; _MENU ;;
"Excluir Dominio") _DELETE_DOMAIN; _MENU ;;
"Sair") exit 0;;
*) echo -e "\\033[1;33mForneca uma opcao valida.\\033[0;39m" ;;
esac
done
}
#------------------------------------------------------------------------------
#- EXEC -----------------------------------------------------------------------
clear
echo -e "\\033[1;33m-------------------------------------------------------------\\033[0;39m"
echo -e "\\033[1;33m SISTEMA DE GERENCIAMENTO DO APACHE \\033[0;39m"
echo -e "\\033[1;33m-------------------------------------------------------------\\033[0;39m"
_MENU
#------------------------------------------------------------------------------