new improved template scheme

This commit is contained in:
Serghey Rodin
2013-05-10 11:04:40 +03:00
parent 14687f170a
commit fd4e68bb8c
96 changed files with 1395 additions and 1425 deletions

View File

@@ -1,46 +1,32 @@
# Web template check
is_apache_template_valid() {
t="$WEBTPL/apache/$template.tpl"
s="$WEBTPL/apache/$template.stpl"
is_web_template_valid() {
t="$WEBTPL/$WEB_SYSTEM/$template.tpl"
s="$WEBTPL/$WEB_SYSTEM/$template.stpl"
if [ ! -e $t ] || [ ! -e $s ]; then
template='default'
t="$WEBTPL/apache/$template.tpl"
s="$WEBTPL/apache/$template.stpl"
if [ ! -e $t ] || [ ! -e $s ]; then
echo "Error: template $template not found"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
echo "Error: web template $template not found"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
}
# Nginx template check
is_nginx_template_valid() {
t="$WEBTPL/nginx/$template.tpl"
s="$WEBTPL/nginx/$template.stpl"
# Proxy template check
is_proxy_template_valid() {
t="$WEBTPL/$PROXY_SYSTEM/$template.tpl"
s="$WEBTPL/$PROXY_SYSTEM/$template.stpl"
if [ ! -e $t ] || [ ! -e $s ]; then
template='default'
t="$WEBTPL/nginx/$template.tpl"
s="$WEBTPL/nginx/$template.stpl"
if [ ! -e $t ] || [ ! -e $s ]; then
echo "Error: nginx $template not found"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
echo "Error: proxy template $template not found"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
}
# DNS template check
is_dns_template_valid() {
tpl="$DNSTPL/$template.tpl"
if [ ! -e $tpl ]; then
template='default'
tpl="$DNSTPL/$template.tpl"
if [ ! -e $tpl ]; then
echo "Error: template not found"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
t="$DNSTPL/$template.tpl"
if [ ! -e $t ]; then
echo "Error: dns template $template not found"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
}
@@ -239,6 +225,7 @@ add_web_config() {
-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/%proxy_extentions%/${PROXY_EXT//,/|}/g" \
-e "s/%domain_idn%/$domain_idn/g" \
-e "s/%domain%/$domain/g" \
-e "s/%user%/$user/g" \
@@ -255,10 +242,6 @@ add_web_config() {
-e "s/%ssl_pem%/${ssl_pem////\/}/g" \
-e "s/%ssl_ca_str%/${ssl_ca_str////\/}/g" \
-e "s/%ssl_ca%/${ssl_ca////\/}/g" \
-e "s/%nginx_extentions%/${NGINX_EXT//,/|}/g" \
-e "s/%elog%//g" \
-e "s/%cgi%//g" \
-e "s/%cgi_option%/+ExecCGI/g" \
>> $conf
}
@@ -397,71 +380,6 @@ del_web_config() {
sed -i "$top_line,$bottom_line d" $conf
}
# Add ip virtual hosting support
namehost_ip_support() {
if [ "$WEB_SYSTEM" = 'apache' ]; then
conf_line=$(grep -n "NameVirtual" $conf|tail -n 1|cut -f 1 -d ':')
if [ ! -z "$conf_line" ]; then
conf_ins=$((conf_line + 1))
else
conf_ins='1'
fi
if [ "$WEB_SSL" = 'mod_ssl' ]; then
sed -i "$conf_ins i NameVirtualHost $ip:$WEB_SSL_PORT" $conf
sed -i "$conf_ins i Listen $ip:$WEB_SSL_PORT" $conf
fi
sed -i "$conf_ins i NameVirtualHost $ip:$WEB_PORT" $conf
sed -i "$conf_ins i Listen $ip:$WEB_PORT" $conf
if [ "$PROXY_SYSTEM" = 'nginx' ]; then
cat $WEBTPL/nginx/ip.tpl | sed -e "s/%ip%/$ip/g" \
-e "s/%web_port%/$WEB_PORT/g" \
-e "s/%proxy_port%/$PROXY_PORT/g" >>$nconf
ips=$(grep 'MEFaccept ' $rconf |grep -v '#'| head -n1)
sed -i "s/$ips/$ips $ip/g" $rconf
fi
web_restart='yes'
fi
}
# Disable virtual ip hosting support
namehost_ip_disable() {
if [ "$WEB_SYSTEM" = 'apache' ]; then
sed -i "/NameVirtualHost $ip:/d" $conf
sed -i "/Listen $ip:/d" $conf
if [ "$PROXY_SYSTEM" = 'nginx' ]; then
tpl_ln=$(wc -l $WEBTPL/nginx/ip.tpl | cut -f 1 -d ' ')
ip_line=$(grep -n "%ip%" $WEBTPL/nginx/ip.tpl |head -n1 |\
cut -f 1 -d :)
conf_line=$(grep -n -w $ip $nconf|head -n1|cut -f 1 -d :)
if [ -z "$tpl_ln" ] || [ -z "$ip_line" ] || [ -z "$conf_line" ]
then
echo "Error: nginx config paring error"
log_event "$E_PARSING" "$EVENT"
exit $E_PARSING
fi
up_line=$((ip_line - 1))
first_line=$((conf_line - up_line))
last_line=$((conf_line - ip_line + tpl_ln))
if [ -z "$first_line" ] || [ -z "$last_line" ]; then
echo "Error: nginx config paring error"
log_event "$E_PARSING" "$EVENT"
exit $E_PARSING
fi
sed -i "$first_line,$last_line d" $nconf
ips=$(grep 'RPAFproxy_ips' $rconf)
new_ips=$(echo "$ips"|sed -e "s/$ip//")
sed -i "s/$ips/$new_ips/g" $rconf
fi
web_restart='yes'
fi
}
# Update web domain values
upd_web_domain_values() {
group="$user"

View File

@@ -45,9 +45,7 @@ is_ip_owner() {
# Check if ip address is free
is_ip_free() {
list=$(/sbin/ifconfig |grep 'inet addr:' |cut -f 2 -d : |cut -f 1 -d ' ')
ip_check=$(echo "$list" |grep -w "$ip")
if [ -n "$ip_check" ] || [ -e "$VESTA/data/ips/$ip" ]; then
if [ -e "$VESTA/data/ips/$ip" ]; then
echo "Error: IP exist"
log_event "$E_EXISTS" "$EVENT"
exit $E_EXISTS
@@ -174,30 +172,6 @@ get_ip_value() {
echo "$value"
}
# Create ip vesta configuration
create_vesta_ip() {
ip_data="OWNER='$user'"
ip_data="$ip_data\nSTATUS='$ip_status'"
ip_data="$ip_data\nNAME='$ip_name'"
ip_data="$ip_data\nU_SYS_USERS=''"
ip_data="$ip_data\nU_WEB_DOMAINS='0'"
ip_data="$ip_data\nINTERFACE='$interface'"
ip_data="$ip_data\nNETMASK='$mask'"
ip_data="$ip_data\nNAT='$nat_ip'"
ip_data="$ip_data\nTIME='$TIME'"
ip_data="$ip_data\nDATE='$DATE'"
echo -e "$ip_data" >$VESTA/data/ips/$ip
chmod 660 $VESTA/data/ips/$ip
}
# Create ip address startup configuration
create_ip_startup() {
ip_data="# Added by vesta $SCRIPT\nDEVICE=$iface"
ip_data="$ip_data\nBOOTPROTO=static\nONBOOT=yes\nIPADDR=$ip"
ip_data="$ip_data\nNETMASK=$mask"
echo -e "$ip_data" > $iconf-$iface
}
# Get real ip address
get_real_ip() {
if [ -e "$VESTA/data/ips/$1" ]; then

View File

@@ -209,7 +209,7 @@ is_object_valid() {
fi
fi
if [ -z "$sobject" ]; then
echo "Error: $3 not exist"
echo "Error: $2 $3 not exist"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
@@ -684,7 +684,7 @@ validate_format_mhdmw() {
fi
}
# Nginx static extention or DNS record
# proxy extention or DNS record
validate_format_common() {
exclude="[!|#|$|^|&|(|)|+|=|{|}|:|<|>|?|/|\|\"|'|;|%|\`| ]"
if [[ "$1" =~ $exclude ]] || [ 200 -le ${#1} ]; then

View File

@@ -156,14 +156,14 @@ rebuild_web_domain_conf() {
$HOMEDIR/$user/web/$domain/logs
# Create domain logs
touch /var/log/httpd/domains/$domain.bytes \
/var/log/httpd/domains/$domain.log \
/var/log/httpd/domains/$domain.error.log
touch /var/log/$WEB_SYSTEM/domains/$domain.bytes \
/var/log/$WEB_SYSTEM/domains/$domain.log \
/var/log/$WEB_SYSTEM/domains/$domain.error.log
# Create symlinks
cd $HOMEDIR/$user/web/$domain/logs/
ln -f -s /var/log/httpd/domains/$domain.log .
ln -f -s /var/log/httpd/domains/$domain.error.log .
ln -f -s /var/log/$WEB_SYSTEM/domains/$domain.log .
ln -f -s /var/log/$WEB_SYSTEM/domains/$domain.error.log .
cd - > /dev/null
# Propagate html skeleton
@@ -180,7 +180,7 @@ rebuild_web_domain_conf() {
chmod 751 $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.*
chmod 640 /var/log/$WEB_SYSTEM/domains/$domain.*
# Set ownership
chown $user:$user $HOMEDIR/$user/web/$domain
@@ -189,19 +189,18 @@ rebuild_web_domain_conf() {
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:$user /var/log/$WEB_SYSTEM/domains/$domain.*
# Adding tmp_httpd.conf
tpl_file="$WEBTPL/apache/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/tmp_httpd.conf"
# Adding tmp conf
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/tmp_$WEB_SYSTEM.conf"
add_web_config
chown root:apache $conf
chown root:$user $conf
chmod 640 $conf
# Running template trigger
if [ -x $WEBTPL/apache/$TPL.sh ]; then
$WEBTPL/apache/$TPL.sh $user $domain $ip $HOMEDIR $docroot
if [ -x $WEBTPL/$WEB_SYSTEM/$TPL.sh ]; then
$WEBTPL/$WEB_SYSTEM/$TPL.sh $user $domain $ip $HOMEDIR $docroot
fi
# Checking aliases
@@ -253,13 +252,13 @@ rebuild_web_domain_conf() {
fi
fi
# Checking ssl
# 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"
# Adding domain to the web conf
conf="$HOMEDIR/$user/conf/web/tmp_s$WEB_SYSTEM.conf"
tpl_file="$WEBTPL/$WEB_SYSTEM/$TPL.stpl"
add_web_config
chown root:apache $conf
chown root:$user $conf
chmod 640 $conf
cp -f $USER_DATA/ssl/$domain.crt \
@@ -274,30 +273,30 @@ rebuild_web_domain_conf() {
fi
# Running template trigger
if [ -x $WEBTPL/apache/$TPL.sh ]; then
$WEBTPL/apache/$TPL.sh $user $domain $ip $HOMEDIR $sdocroot
if [ -x $WEBTPL/$WEB_SYSTEM/$TPL.sh ]; then
$WEBTPL/$WEB_SYSTEM/$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"
# Checking proxy
if [ ! -z "$PROXY" ]; then
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.tpl"
conf="$HOMEDIR/$user/conf/web/tmp_$PROXY_SYSTEM.conf"
add_web_config
chown root:nginx $conf
chown root:$user $conf
chmod 640 $conf
if [ "$SSL" = 'yes' ]; then
tpl_file="$WEBTPL/nginx/$NGINX.stpl"
conf="$HOMEDIR/$user/conf/web/tmp_snginx.conf"
tpl_file="$WEBTPL/$PROXY_SYSTEM/$PROXY.stpl"
conf="$HOMEDIR/$user/conf/web/tmp_s$PROXY_SYSTEM.conf"
add_web_config
chown root:nginx $conf
chown root:$user $conf
chmod 640 $conf
fi
ngix_change='yes'
proxy_change='yes'
fi
if [ "$SUSPENDED" = 'yes' ]; then
suspended_web=$((suspended_web + 1))