support for NATed networks

This commit is contained in:
Serghey Rodin 2013-02-05 22:58:40 +02:00
commit 138ef6c7b0
37 changed files with 271 additions and 94 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add system ip address
# options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME]
# options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]
#
# The function adds ip address into a system. It also creates rc scripts. You
# can specify ip name which will be used as root domain for temporary aliases.
@ -21,6 +21,7 @@ interface="${3-eth0}"
user="${4-admin}"
ip_status="${5-shared}" # can be dedicated as well
ip_name=$6
nat_ip=$7
# Includes
source $VESTA/conf/vesta.conf
@ -33,7 +34,7 @@ source $VESTA/func/domain.sh
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME]'
check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]'
validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
is_ip_free
is_object_valid 'user' 'USER' "$user"
@ -41,6 +42,9 @@ is_object_unsuspended 'user' 'USER' "$user"
if [ ! -z "$ip_name" ] ; then
validate_format 'ip_name'
fi
if [ ! -z "$nat_ip" ] ; then
validate_format 'nat_ip'
fi
#----------------------------------------------------------#

View file

@ -57,8 +57,11 @@ fi
# Action #
#----------------------------------------------------------#
# Defining domain aliases
# Define real ip in case of NAT
IP=$ip
ip=$(get_real_ip $ip)
# Defining domain aliases
ip_name=$(get_ip_name)
ip_name_idn=$(idn -t --quiet -a "$ip_name")
domain_alias="www.$domain"
@ -81,15 +84,12 @@ email="$user@$domain"
docroot="$HOMEDIR/$user/web/$domain/public_html"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
tpl_file="$WEBTPL/apache_$template.tpl"
elog=''
cgi=''
cgi_option='+ExecCGI'
# Adding domain to the httpd.conf
add_web_config
# Building directory tree
mkdir $HOMEDIR/$user/web/$domain \
mkdir -p $HOMEDIR/$user/web/$domain \
$HOMEDIR/$user/web/$domain/public_html \
$HOMEDIR/$user/web/$domain/public_shtml \
$HOMEDIR/$user/web/$domain/document_errors \
@ -104,7 +104,7 @@ touch /var/log/httpd/domains/$domain.bytes \
/var/log/httpd/domains/$domain.error.log
# Adding symlink for logs
ln -s /var/log/httpd/domains/$domain.*log $HOMEDIR/$user/web/$domain/logs/
ln -f -s /var/log/httpd/domains/$domain.*log $HOMEDIR/$user/web/$domain/logs/
# Adding domain skeleton
if [ -e "$WEBTPL/skel/public_html/" ]; then
@ -168,9 +168,9 @@ increase_user_value "$user" '$U_WEB_DOMAINS'
increase_user_value "$user" '$U_WEB_ALIASES'
# Defining domain variables
str="DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$aliases' TPL='$template'"
str="$str CGI='yes' ELOG='yes' SSL='no' SSL_HOME='same' FTP_USER=''"
str="$str FTP_MD5='' NGINX='' NGINX_EXT='' STATS='' STATS_USER=''"
str="DOMAIN='$domain' IP='$IP' IP6='' ALIAS='$aliases' TPL='$template'"
str="$str SSL='no' SSL_HOME='same' FTP_USER='' FTP_MD5=''"
str="$str NGINX='' NGINX_EXT='' STATS='' STATS_USER=''"
str="$str STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0' SUSPENDED='no'"
str="$str TIME='$TIME' DATE='$DATE'"

View file

@ -50,6 +50,7 @@ is_package_full 'WEB_ALIASES'
get_domain_values 'web'
tpl_file="$WEBTPL/apache_$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
ip=$(get_real_ip $IP)
# Parsing domain aliases
if [ -z "$ALIAS" ]; then

View file

@ -24,6 +24,7 @@ restart="$5"
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/domain.sh
source $VESTA/func/ip.sh
#----------------------------------------------------------#
@ -57,6 +58,7 @@ NGINX="$template"
NGINX_EXT="$extentions"
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
conf="$HOMEDIR/$user/conf/web/nginx.conf"
ip=$(get_real_ip $IP)
# Preparing domain values for the template substitution
upd_web_domain_values

View file

@ -65,6 +65,7 @@ get_domain_values 'web'
conf="$HOMEDIR/$user/conf/web/shttpd.conf"
tpl_file="$WEBTPL/apache_$TPL.stpl"
SSL_HOME="$ssl_home"
ip=$(get_real_ip $IP)
# Preparing domain values for the template substitution
upd_web_domain_values

View file

@ -24,7 +24,10 @@ source $VESTA/func/ip.sh
#----------------------------------------------------------#
check_args '2' "$#" 'IP IP_NAME'
validate_format 'ip' 'ip_name'
validate_format 'ip'
if [ ! -z "$ip_name" ]; then
validate_format 'ip_name'
fi
is_ip_valid

54
bin/v-change-sys-ip-nat Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
# info: change ip nat address
# options: IP NAT_IP
#
# The function for changing nat ip associated with ip.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
ip=$1
nat_ip=$2
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/main.sh
source $VESTA/func/ip.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'IP NAT_IP'
validate_format 'ip'
if [ ! -z "$nat_ip" ]; then
validate_format 'nat_ip'
fi
is_ip_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Changing nat ip
if [ -z "$(grep NAT= $VESTA/data/ips/$ip)" ]; then
sed -i "s/^TIME/NAT='$nat_ip'\nTIME/g" $VESTA/data/ips/$ip
else
update_ip_value '$NAT' "$nat_ip"
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "changed associated nat address on $ip to $nat_ip" '' 'admin'
log_event "$OK" "$EVENT"
exit

View file

@ -45,9 +45,10 @@ is_ip_avalable
# Define variable for replace
get_domain_values 'web'
ip=$(get_real_ip $ip)
tpl_file="$WEBTPL/apache_$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
old=$IP
old=$(get_real_ip $IP)
new=$ip
replace_web_config
@ -82,7 +83,7 @@ increase_ip_value "$new"
decrease_ip_value "$old"
# Update config
update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$ip"
update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$3"
# Restart web server
if [ "$restart" != 'no' ]; then
@ -90,7 +91,7 @@ if [ "$restart" != 'no' ]; then
fi
# Logging
log_history "changed web domain $domain ip to $ip"
log_history "changed web domain $domain ip to $3"
log_event "$OK" "$EVENT"
exit

View file

@ -50,6 +50,7 @@ is_nginx_template_valid
get_domain_values 'web'
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
conf="$HOMEDIR/$user/conf/web/nginx.conf"
ip=$(get_real_ip $IP)
# Delete old vhost
del_web_config

View file

@ -43,6 +43,7 @@ is_apache_template_valid
# Parsing domain values
get_domain_values 'web'
ip=$(get_real_ip $IP)
# Deleting domain
tpl_file="$WEBTPL/apache_$TPL.tpl"
@ -61,13 +62,6 @@ fi
upd_web_domain_values
tpl_file="$WEBTPL/apache_$template.tpl"
# Checking error log
if [ "$ELOG" = 'no' ]; then
elog='#'
else
elog=''
fi
# Adding domain to the httpd.conf
add_web_config

View file

@ -46,6 +46,7 @@ is_object_unsuspended 'web' 'DOMAIN' "$domain"
get_domain_values 'web'
tpl_file="$WEBTPL/apache_$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
ip=$(get_real_ip $IP)
# Deleting domain
del_web_config
@ -146,7 +147,7 @@ if [ -z "$last_nginx" ]; then
fi
# Decrease counters
decrease_ip_value "$IP"
decrease_ip_value "$ip"
decrease_user_value "$user" '$U_WEB_DOMAINS'
decrease_user_value "$user" '$U_WEB_ALIASES' "$aliases"
if [ "$SSL" = 'yes' ]; then

View file

@ -36,6 +36,7 @@ is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'web' 'DOMAIN' "$domain"
is_object_unsuspended 'web' 'DOMAIN' "$domain"
get_domain_values 'web'
ip=$(get_real_ip $IP)
if [ -z "$(echo $ALIAS | tr ',' '\n' | grep ^$dom_alias$)" ]; then
echo "Error: alias $dom_alias not exist"
log_event "$E_NOTEXIST" "$EVENT"

View file

@ -74,7 +74,7 @@ conf=$VESTA/data/ips/$IP
# Defining fileds to select
fields='$IP $OWNER $STATUS $NAME $U_SYS_USERS $U_WEB_DOMAINS $INTERFACE
$NETMASK $TIME $DATE'
$NETMASK $NAT $TIME $DATE'
# Listing ip
case $format in

View file

@ -61,9 +61,15 @@ shell_list_ips() {
fi
for IP in $ip_list; do
ip_data=$(cat $VESTA/data/ips/$IP)
eval $ip_data
eval echo "$fields"
source $VESTA/data/ips/$IP
for field in $fields; do
eval value=$field
if [ -z "$value" ]; then
value='NULL'
fi
echo -n "$value "
done
echo
done
}
@ -75,13 +81,13 @@ shell_list_ips() {
# Defining fileds to select
conf=$VESTA/data/ips/*
fields="\$IP \$OWNER \$STATUS \$NAME \$U_SYS_USERS \$U_WEB_DOMAINS"
fields="$fields \$INTERFACE \$NETMASK \$TIME \$DATE"
fields="$fields \$INTERFACE \$NETMASK \$NAT \$TIME \$DATE"
# Listing ip addresses
case $format in
json) json_list_ips ;;
plain) nohead=1; shell_list_ips ;;
shell) fields='$IP $NETMASK $OWNER $STATUS $U_WEB_DOMAINS';
shell) fields='$IP $NETMASK $NAT $OWNER $U_WEB_DOMAINS';
shell_list_ips | column -t ;;
*) check_args '1' '0' '[FORMAT]'
esac

View file

@ -79,10 +79,24 @@ shell_list_user_ips() {
for IP in $(ls $VESTA/data/ips/); do
source $VESTA/data/ips/$IP
if [ "$OWNER" = "$user" ]; then
eval echo "$fields"
for field in $fields; do
eval value=$field
if [ -z "$value" ]; then
value='NULL'
fi
echo -n "$value "
done
echo
else
if [ "$OWNER" = 'admin' ] && [ "$STATUS" = 'shared' ]; then
eval echo "$fields"
for field in $fields; do
eval value=$field
if [ -z "$value" ]; then
value='NULL'
fi
echo -n "$value "
done
echo
fi
fi
done
@ -103,10 +117,10 @@ is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Defining fileds to select
fields='$IP $OWNER $STATUS $NAME'
fields='$IP $OWNER $STATUS $NAME $NAT'
# Listing ips
case $format in
case $format in
json) json_list_user_ips ;;
plain) nohead=1; shell_list_user_ips ;;
shell) shell_list_user_ips | column -t ;;

View file

@ -75,8 +75,8 @@ is_object_valid 'web' 'DOMAIN' "$domain"
conf=$USER_DATA/web.conf
# Defining fileds to select
fields='$DOMAIN $IP $IP6 $U_DISK $U_BANDWIDTH $TPL $ALIAS $CGI $ELOG $STATS
$STATS_USER $SSL $SSL_HOME $FTP_USER $NGINX $NGINX_EXT $SUSPENDED $TIME $DATE'
fields='$DOMAIN $IP $IP6 $U_DISK $U_BANDWIDTH $TPL $ALIAS $STATS $STATS_USER
$SSL $SSL_HOME $FTP_USER $NGINX $NGINX_EXT $SUSPENDED $TIME $DATE'
# Listing domains
case $format in

View file

@ -34,8 +34,8 @@ is_object_valid 'user' 'USER' "$user"
conf=$USER_DATA/web.conf
# Defining fileds to select
fields="\$DOMAIN \$IP \$IP6 \$U_DISK \$U_BANDWIDTH \$TPL \$ALIAS \$CGI"
fields="$fields \$ELOG \$STATS \$STATS_USER \$SSL \$SSL_HOME \$FTP_USER"
fields="\$DOMAIN \$IP \$IP6 \$U_DISK \$U_BANDWIDTH \$TPL \$ALIAS"
fields="$fields \$STATS \$STATS_USER \$SSL \$SSL_HOME \$FTP_USER"
fields="$fields \$NGINX \$NGINX_EXT \$SUSPENDED \$TIME \$DATE"
# Listing domains

View file

@ -60,14 +60,12 @@ for domain in $(shell_list) ; do
$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
ln -f -s /var/log/httpd/domains/$domain.log \
$HOMEDIR/$user/web/$domain/logs/$domain.log
ln -f -s /var/log/httpd/domains/$domain.error.log \
$HOMEDIR/$user/web/$domain/logs/$domain.error.log
if [ -e "$WEBTPL/skel/document_errors/" ]; then
cp -r $WEBTPL/skel/document_errors/ $HOMEDIR/$user/web/$domain/
fi
@ -98,6 +96,7 @@ for domain in $(shell_list) ; do
# Parsing domain values
domain_idn=$(idn -t --quiet -a "$domain")
get_domain_values 'web'
ip=$(get_real_ip $IP)
# Preparing domain values for the template substitution
upd_web_domain_values
@ -209,7 +208,7 @@ for domain in $(shell_list) ; do
chown root:nginx $conf
chmod 640 $conf
fi
ngix_change='yes'
ngix_change='yes'
fi
if [ "$SUSPENDED" = 'yes' ]; then
suspended_web=$((suspended_web + 1))

View file

@ -45,6 +45,7 @@ get_domain_values 'web'
tpl_file="$WEBTPL/apache_$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
SUSPENDED='yes'
ip=$(get_real_ip $IP)
# Preparing domain values for the template substitution
upd_web_domain_values

View file

@ -42,6 +42,7 @@ get_domain_values 'web'
tpl_file="$WEBTPL/apache_$TPL.tpl"
conf="$HOMEDIR/$user/conf/web/httpd.conf"
SUSPENDED='no'
ip=$(get_real_ip $IP)
# Preparing domain values for the template substitution
upd_web_domain_values