replaced underscore with dash in api syscalls

This commit is contained in:
Serghey Rodin 2012-11-09 18:26:32 +02:00
commit b6b7eacadb
283 changed files with 438 additions and 412 deletions

306
bin/v-rebuild-web-domains Executable file
View file

@ -0,0 +1,306 @@
#!/bin/bash
# info: rebuild dns domains
# options: user [restart]
#
# The function rebuilds BIND configuration files for all dns domains.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
restart=$2
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'user [restart]'
validate_format 'user'
is_system_enabled "$WEB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
user_domains=0
user_ssl=0
user_aliases=0
suspended_web=0
# Clean up old config
rm -f $HOMEDIR/$user/conf/tmp_*.conf
# Defining config
conf=$USER_DATA/web.conf
fields='$DOMAIN'
nohead=1
# Starting loop
for domain in $(shell_list) ; do
# Rebuilding directories
mkdir -p $HOMEDIR/$user/web/$domain \
$HOMEDIR/$user/web/$domain/public_html \
$HOMEDIR/$user/web/$domain/public_shtml \
$HOMEDIR/$user/web/$domain/document_errors \
$HOMEDIR/$user/web/$domain/cgi-bin \
$HOMEDIR/$user/web/$domain/private \
$HOMEDIR/$user/web/$domain/stats \
$HOMEDIR/$user/web/$domain/logs
if [ ! -e "$HOMEDIR/$user/web/$domain/logs/$domain.log" ]; then
ln -s /var/log/httpd/domains/$domain.error.log \
$HOMEDIR/$user/web/$domain/logs/$domain.log
fi
if [ ! -e "$HOMEDIR/$user/web/$domain/logs/$domain.error.log" ]; then
ln -s /var/log/httpd/domains/$domain.error.log \
$HOMEDIR/$user/web/$domain/logs/$domain.error.log
fi
if [ -e "$WEBTPL/skel/document_errors/" ]; then
cp -r $WEBTPL/skel/document_errors/ $HOMEDIR/$user/web/$domain/
fi
touch /var/log/httpd/domains/$domain.bytes \
/var/log/httpd/domains/$domain.log \
/var/log/httpd/domains/$domain.error.log
chmod 551 $HOMEDIR/$user/web/$domain
chmod 771 $HOMEDIR/$user/web/$domain/private
chmod 771 $HOMEDIR/$user/web/$domain/cgi-bin
chmod 771 $HOMEDIR/$user/web/$domain/public_html
chmod 771 $HOMEDIR/$user/web/$domain/public_shtml
chmod 771 $HOMEDIR/$user/web/$domain/document_errors
chmod 551 $HOMEDIR/$user/web/$domain/stats
chmod 551 $HOMEDIR/$user/web/$domain/logs
chmod 640 /var/log/httpd/domains/$domain.*
chown $user:$user $HOMEDIR/$user/web/$domain
chown $user:$user $HOMEDIR/$user/web/$domain/private
chown $user:$user $HOMEDIR/$user/web/$domain/cgi-bin
chown $user:$user $HOMEDIR/$user/web/$domain/public_html
chown $user:$user $HOMEDIR/$user/web/$domain/public_shtml
chown -R $user:$user $HOMEDIR/$user/web/$domain/document_errors
chown root:$user /var/log/httpd/domains/$domain.*
chown root:apache $conf
# Parsing domain values
domain_idn=$(idn -t --quiet -a "$domain")
get_domain_values 'web'
# Preparing domain values for the template substitution
upd_web_domain_values
# Adding domain to the tmp_httpd.conf
tpl_file="$WEBTPL/apache_$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf"
add_web_config
chown root:apache $conf
chmod 640 $conf
# Running template trigger
if [ -x $WEBTPL/apache_$TPL.sh ]; then
$WEBTPL/apache_$TPL.sh $user $domain $ip $HOMEDIR $docroot
fi
# Checking aliases
if [ ! -z "$ALIAS" ]; then
aliases=$(echo "$ALIAS"|tr ',' '\n'| wc -l)
user_aliases=$((user_aliases + aliases))
fi
# Checking stats
if [ ! -z "$STATS" ]; then
cat $WEBTPL/$STATS.tpl |\
sed -e "s/%ip%/$ip/g" \
-e "s/%web_port%/$WEB_PORT/g" \
-e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \
-e "s/%proxy_port%/$PROXY_PORT/g" \
-e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
-e "s/%domain_idn%/$domain_idn/g" \
-e "s/%domain%/$domain/g" \
-e "s/%user%/$user/g" \
-e "s/%home%/${HOMEDIR////\/}/g" \
-e "s/%alias%/${aliases//,/ }/g" \
-e "s/%alias_idn%/${aliases_idn//,/ }/g" \
> $HOMEDIR/$user/conf/web/$STATS.$domain.conf
webstats="$BIN/v-update-web-domain-stat $user $domain"
check_webstats=$(grep "$webstats" $VESTA/data/queue/webstats.pipe)
if [ -z "$check_webstats" ]; then
echo "$webstats" >> $VESTA/data/queue/webstats.pipe
fi
if [ ! -z "$STATS_USER" ]; then
# Definining statistic dir
stats_dir="$HOMEDIR/$user/web/$domain/stats"
# Adding htaccess file
echo "AuthUserFile $stats_dir/.htpasswd" > $stats_dir/.htaccess
echo "AuthName \"Web Statistics\"" >> $stats_dir/.htaccess
echo "AuthType Basic" >> $stats_dir/.htaccess
echo "Require valid-user" >> $stats_dir/.htaccess
# Generating htaccess user and password
echo "$STATS_USER:$STATS_CRYPT" > $stats_dir/.htpasswd
fi
fi
# Checking ssl
if [ "$SSL" = 'yes' ]; then
# Adding domain to the shttpd.conf
conf="$HOMEDIR/$user/conf/web/tmp_shttpd.conf"
tpl_file="$WEBTPL/apache_$TPL.stpl"
add_web_config
chown root:apache $conf
chmod 640 $conf
cp -f $USER_DATA/ssl/$domain.crt \
$HOMEDIR/$user/conf/web/ssl.$domain.crt
cp -f $USER_DATA/ssl/$domain.key \
$HOMEDIR/$user/conf/web/ssl.$domain.key
cp -f $USER_DATA/ssl/$domain.pem \
$HOMEDIR/$user/conf/web/ssl.$domain.pem
if [ -e "$USER_DATA/ssl/$domain.ca" ]; then
cp -f $USER_DATA/ssl/$domain.ca \
$HOMEDIR/$user/conf/web/ssl.$domain.ca
fi
# Running template trigger
if [ -x $WEBTPL/apache_$TPL.sh ]; then
$WEBTPL/apache_$TPL.sh $user $domain $ip $HOMEDIR $sdocroot
fi
user_ssl=$((user_ssl + 1))
ssl_change='yes'
fi
# Checking nginx
if [ ! -z "$NGINX" ]; then
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
conf="$HOMEDIR/$user/conf/web/tmp_nginx.conf"
add_web_config
chown root:nginx $conf
chmod 640 $conf
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/nginx_$NGINX.stpl"
conf="$HOMEDIR/$user/conf/web/tmp_snginx.conf"
add_web_config
chown root:nginx $conf
chmod 640 $conf
fi
ngix_change='yes'
fi
if [ "$SUSPENDED" = 'yes' ]; then
suspended_web=$((suspended_web + 1))
fi
user_domains=$((user_domains + 1))
# Checking ftp
if [ ! -z "$FTP_USER" ]; then
if [ -z "$(grep ^$FTP_USER: /etc/passwd)" ]; then
/usr/sbin/adduser $FTP_USER -g $user -s /sbin/nologin -M \
-d "$HOMEDIR/$user/web/$domain" > /dev/null 2>&1
shadow='/etc/shadow'
shdw=$(grep "^$FTP_USER:" $shadow)
shdw3=$(echo "$shdw" | cut -f3 -d :)
shdw4=$(echo "$shdw" | cut -f4 -d :)
shdw5=$(echo "$shdw" | cut -f5 -d :)
shdw6=$(echo "$shdw" | cut -f6 -d :)
shdw7=$(echo "$shdw" | cut -f7 -d :)
shdw8=$(echo "$shdw" | cut -f8 -d :)
shdw9=$(echo "$shdw" | cut -f9 -d :)
chmod u+w $shadow
sed -i "/^$FTP_USER:*/d" $shadow
shdw_str="$FTP_USER:$FTP_MD5:$shdw3:$shdw4:$shdw5:$shdw6"
shdw_str="$shdw_str:$shdw7:$shdw8:$shdw9"
echo "$shdw_str" >> $shadow
chmod u-w $shadow
fi
fi
done
# Renaming tmp config
tmp_conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
if [ -e "$tmp_conf" ]; then
mv $tmp_conf $conf
fi
# Checking include in main httpd.conf
main_conf='/etc/httpd/conf.d/vesta.conf'
main_conf_check=$(grep "$conf" $main_conf )
if [ ! -z "$domain" ] && [ -z "$main_conf_check" ]; then
echo "Include $conf" >>$main_conf
fi
# Checking ssl
if [ "$ssl_change" = 'yes' ]; then
tmp_conf="$HOMEDIR/$user/conf/web/tmp_shttpd.conf"
conf="$HOMEDIR/$user/conf/web/shttpd.conf"
mv $tmp_conf $conf
# Checking include in main httpd.conf
main_conf_check=$(grep "$conf" $main_conf )
if [ -z "$main_conf_check" ]; then
echo "Include $conf" >>$main_conf
fi
fi
# Checking nginx
if [ "$ngix_change" = 'yes' ]; then
nginx_conf='/etc/nginx/conf.d/vesta_users.conf'
tmp_conf="$HOMEDIR/$user/conf/web/tmp_nginx.conf"
conf="$HOMEDIR/$user/conf/web/nginx.conf"
mv $tmp_conf $conf
nginx_conf_check=$(grep "$conf" $nginx_conf )
if [ -z "$nginx_conf_check" ]; then
echo "include $conf;" >>$nginx_conf
fi
# Checking ssl for nginx
if [ "$ssl_change" = 'yes' ]; then
tmp_conf="$HOMEDIR/$user/conf/web/tmp_snginx.conf"
conf="$HOMEDIR/$user/conf/web/snginx.conf"
mv $tmp_conf $conf
nginx_conf_check=$(grep "$conf" $nginx_conf )
if [ -z "$nginx_conf_check" ]; then
echo "include $conf;" >>$nginx_conf
fi
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating counters
update_user_value "$user" '$SUSPENDED_WEB' "$suspended_web"
update_user_value "$user" '$U_WEB_DOMAINS' "$user_domains"
update_user_value "$user" '$U_WEB_SSL' "$user_ssl"
update_user_value "$user" '$U_WEB_ALIASES' "$user_aliases"
# Restart web server
if [ "$restart" != 'no' ]; then
$BIN/v-restart-web "$EVENT"
fi
# Logging
log_event "$OK" "$EVENT"
exit