mirror of
https://github.com/myvesta/vesta
synced 2025-07-06 04:51:54 -07:00
added httpd config rebuild api
This commit is contained in:
parent
e26cc8c043
commit
748546309f
2 changed files with 109 additions and 164 deletions
|
@ -1,164 +0,0 @@
|
|||
#!/bin/bash
|
||||
# info: rebuilding web domain
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user="$1"
|
||||
domain=$(idn -t --quiet -u "$2" )
|
||||
domain_idn=$(idn -t --quiet -a "$domain")
|
||||
ip="$3"
|
||||
template=$4
|
||||
|
||||
# Importing variables
|
||||
source $VESTA/conf/vars.conf
|
||||
source $V_FUNC/shared_func.sh
|
||||
source $V_FUNC/domain_func.sh
|
||||
source $V_FUNC/ip_func.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Checking arg number
|
||||
check_args '2' "$#" 'user domain [ip] [template]'
|
||||
|
||||
# Checking argument format
|
||||
format_validation 'user' 'domain'
|
||||
|
||||
# Checking web system is enabled
|
||||
is_system_enabled 'web'
|
||||
|
||||
# Checking user
|
||||
is_user_valid
|
||||
|
||||
# Checking user is active
|
||||
is_user_suspended
|
||||
|
||||
# Checking domain exist
|
||||
is_web_domain_valid
|
||||
|
||||
# Checking domain is not suspened
|
||||
is_domain_suspended 'web_domains'
|
||||
|
||||
# Checking ip
|
||||
if [ -n "$ip" ]; then
|
||||
format_validation 'ip'
|
||||
is_ip_avalable
|
||||
fi
|
||||
|
||||
# Checking template
|
||||
if [ -n "$template" ]; then
|
||||
format_validation 'template'
|
||||
templates=$(get_user_value '$TEMPLATES')
|
||||
is_template_valid "web"
|
||||
fi
|
||||
|
||||
exit
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Defining domain aliases
|
||||
ip_name=$(get_ip_name)
|
||||
ip_name_idn=$(idn -t --quiet -a "$ip_name")
|
||||
domain_alias="www.$domain"
|
||||
domain_alias_idn="www.$domain_idn"
|
||||
if [ ! -z "$ip_name" ]; then
|
||||
domain_alias_dash="${domain//./-}.$ip_name"
|
||||
domain_alias_dash_idn="${domain_idn//./-}.$ip_name_idn"
|
||||
aliases="$domain_alias,$domain_alias_dash"
|
||||
aliases_idn="$domain_alias_idn,$domain_alias_dash_idn"
|
||||
else
|
||||
aliases="$domain_alias"
|
||||
aliases_idn="$domain_alias_idn"
|
||||
fi
|
||||
|
||||
# Defining vars for httpd_add_config function
|
||||
port=$(get_web_port)
|
||||
group="$user"
|
||||
email="$user@$domain"
|
||||
docroot="$V_HOME/$user/domains/$domain/public_html"
|
||||
conf="$V_HOME/$user/conf/httpd.conf"
|
||||
tpl_file="$V_WEBTPL/apache_$template.tpl"
|
||||
|
||||
# Adding domain to the httpd.conf
|
||||
httpd_add_config
|
||||
|
||||
# Building directory tree
|
||||
if [ ! -e $V_HOME/$user/domains/$domain ]; then
|
||||
mkdir $V_HOME/$user/domains/$domain \
|
||||
$V_HOME/$user/domains/$domain/public_html \
|
||||
$V_HOME/$user/domains/$domain/public_shtml \
|
||||
$V_HOME/$user/domains/$domain/document_errors \
|
||||
$V_HOME/$user/domains/$domain/cgi-bin \
|
||||
$V_HOME/$user/domains/$domain/private \
|
||||
$V_HOME/$user/domains/$domain/stats \
|
||||
$V_HOME/$user/domains/$domain/logs
|
||||
|
||||
# Adding domain skeleton
|
||||
cp -r $V_WEBTPL/skel/public_html/ $V_HOME/$user/domains/$domain/
|
||||
cp -r $V_WEBTPL/skel/public_shtml/ $V_HOME/$user/domains/$domain/
|
||||
cp -r $V_WEBTPL/skel/document_errors/ $V_HOME/$user/domains/$domain/
|
||||
cp -r $V_WEBTPL/skel/cgi-bin/ $V_HOME/$user/domains/$domain/
|
||||
|
||||
# Changing tpl values
|
||||
for file in $(find "$V_HOME/$user/domains/$domain/" -type f); do
|
||||
sed -i "s/%domain%/$domain/g" $file
|
||||
done
|
||||
fi
|
||||
|
||||
# Adding domain logs
|
||||
touch /var/log/httpd/domains/$domain.bytes \
|
||||
/var/log/httpd/domains/$domain.log \
|
||||
/var/log/httpd/domains/$domain.error_log
|
||||
|
||||
# Adding symlink for logs
|
||||
ln -s /var/log/httpd/domains/$domain.*log $V_HOME/$user/domains/$domain/logs/
|
||||
|
||||
# Changing file owner
|
||||
chown -R $user:$user $V_HOME/$user/domains/$domain
|
||||
chown root:$user /var/log/httpd/domains/$domain.*
|
||||
|
||||
# Changing file permissions
|
||||
chmod 551 $V_HOME/$user/domains/$domain
|
||||
chmod 751 $V_HOME/$user/domains/$domain/private
|
||||
chmod 751 $V_HOME/$user/domains/$domain/cgi-bin
|
||||
chmod 751 $V_HOME/$user/domains/$domain/public_html
|
||||
chmod 751 $V_HOME/$user/domains/$domain/public_shtml
|
||||
chmod 751 $V_HOME/$user/domains/$domain/document_errors
|
||||
chmod -f -R 775 $V_HOME/$user/domains/$domain/cgi-bin/*
|
||||
chmod -f -R 775 $V_HOME/$user/domains/$domain/public_html/*
|
||||
chmod -f -R 775 $V_HOME/$user/domains/$domain/document_errors/*
|
||||
chmod 551 $V_HOME/$user/domains/$domain/stats
|
||||
chmod 551 $V_HOME/$user/domains/$domain/logs
|
||||
chmod 640 /var/log/httpd/domains/$domain.*
|
||||
|
||||
# Running template post setup file
|
||||
if [ -e $V_WEBTPL/apache_$template.sh ]; then
|
||||
$V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot $port
|
||||
fi
|
||||
|
||||
# Checking main vesta httpd config
|
||||
main_conf='/etc/httpd/conf.d/vesta.conf'
|
||||
main_conf_check=$(grep "$conf" $main_conf )
|
||||
if [ -z "$main_conf_check" ]; then
|
||||
echo "Include $conf" >>$main_conf
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Adding task to the vesta piped
|
||||
restart_schedule 'web'
|
||||
|
||||
# Logging
|
||||
log_event 'system' "$V_EVENT"
|
||||
|
||||
exit $OK
|
109
bin/v_rebuild_web_domains
Executable file
109
bin/v_rebuild_web_domains
Executable file
|
@ -0,0 +1,109 @@
|
|||
#!/bin/bash
|
||||
# info: rebuilding web domains
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user="$1"
|
||||
|
||||
# Importing variables
|
||||
source $VESTA/conf/vars.conf
|
||||
source $V_FUNC/shared_func.sh
|
||||
source $V_FUNC/domain_func.sh
|
||||
source $V_FUNC/ip_func.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Checking arg number
|
||||
check_args '1' "$#" 'user'
|
||||
|
||||
# Checking argument format
|
||||
format_validation 'user'
|
||||
|
||||
# Checking web system is enabled
|
||||
is_system_enabled 'web'
|
||||
|
||||
# Checking user
|
||||
is_user_valid
|
||||
|
||||
# Checking user is active
|
||||
is_user_suspended
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Defining config
|
||||
conf="$V_USERS/$user/web_domains.conf"
|
||||
|
||||
# Defining search string
|
||||
search_string="DOMAIN"
|
||||
|
||||
# Defining fileds to select
|
||||
field='$DOMAIN'
|
||||
|
||||
# Parsing unsuspeneded domains
|
||||
domains=$(dom_clear_search)
|
||||
|
||||
# Starting update disk loop
|
||||
for domain in $domains; do
|
||||
|
||||
# Defining domain parameters
|
||||
template=$(get_web_domain_value '$TPL')
|
||||
tpl_file="$V_WEBTPL/apache_$template.tpl"
|
||||
ip=$(get_web_domain_value '$IP')
|
||||
port=$(get_web_port)
|
||||
domain=$(get_web_domain_value '$DOMAIN')
|
||||
domain_idn=$(idn -t --quiet -a "$domain")
|
||||
group="$user"
|
||||
docroot="$V_HOME/$user/domains/$domain/public_html"
|
||||
email="$user@$domain"
|
||||
aliases=$(get_web_domain_value '$ALIAS')
|
||||
aliases_idn=$(idn -t --quiet -a "$aliases")
|
||||
|
||||
#ssl_cert=$()
|
||||
#ssl_key=$()
|
||||
|
||||
# Adding domain to the tmp_httpd.conf
|
||||
conf="$V_HOME/$user/conf/tmp_httpd.conf"
|
||||
httpd_add_config
|
||||
|
||||
# Running template trigger
|
||||
if [ -e $V_WEBTPL/apache_$template.sh ]; then
|
||||
$V_WEBTPL/apache_$template.sh $user $domain $ip $V_HOME $docroot $port
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
# Renaming tmp config
|
||||
tmp_conf="$conf"
|
||||
conf="$V_HOME/$user/conf/httpd.conf"
|
||||
mv $tmp_conf $conf
|
||||
|
||||
# Checking include in main httpd.conf
|
||||
main_conf='/etc/httpd/conf.d/vesta.conf'
|
||||
main_conf_check=$(grep "$conf" $main_conf )
|
||||
if [ -z "$main_conf_check" ]; then
|
||||
echo "Include $conf" >>$main_conf
|
||||
fi
|
||||
|
||||
exit
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Adding task to the vesta pipe
|
||||
restart_schedule 'web'
|
||||
|
||||
# Logging
|
||||
log_event 'system' "$V_EVENT"
|
||||
|
||||
exit $OK
|
Loading…
Add table
Add a link
Reference in a new issue