From 138ef6c7b0e90371bc8852d5bd468aa03ebe2c19 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Tue, 5 Feb 2013 22:58:40 +0200 Subject: [PATCH] support for NATed networks --- bin/v-add-sys-ip | 8 +++-- bin/v-add-web-domain | 18 +++++------ bin/v-add-web-domain-alias | 1 + bin/v-add-web-domain-nginx | 2 ++ bin/v-add-web-domain-ssl | 1 + bin/v-change-sys-ip-name | 5 ++- bin/v-change-sys-ip-nat | 54 +++++++++++++++++++++++++++++++ bin/v-change-web-domain-ip | 7 ++-- bin/v-change-web-domain-nginx-tpl | 1 + bin/v-change-web-domain-tpl | 8 +---- bin/v-delete-web-domain | 3 +- bin/v-delete-web-domain-alias | 1 + bin/v-list-sys-ip | 2 +- bin/v-list-sys-ips | 16 ++++++--- bin/v-list-user-ips | 22 ++++++++++--- bin/v-list-web-domain | 4 +-- bin/v-list-web-domains | 4 +-- bin/v-rebuild-web-domains | 17 +++++----- bin/v-suspend-web-domain | 1 + bin/v-unsuspend-web-domain | 1 + func/domain.sh | 7 ++-- func/ip.sh | 25 +++++++++++--- func/main.sh | 1 + web/add/ip/index.php | 4 ++- web/delete/ip/index.php | 3 +- web/edit/ip/index.php | 13 ++++++++ web/inc/i18n/en.php | 4 ++- web/inc/i18n/ru.php | 2 ++ web/templates/admin/add_ip.html | 12 +++++++ web/templates/admin/add_web.html | 8 +++-- web/templates/admin/edit_ip.html | 11 +++++++ web/templates/admin/edit_web.html | 10 +++--- web/templates/admin/list_ip.html | 29 ++++++++++++++++- web/templates/admin/panel.html | 14 ++++---- web/templates/user/add_web.html | 8 +++-- web/templates/user/edit_web.html | 10 +++--- web/templates/user/panel.html | 28 ++++++++-------- 37 files changed, 271 insertions(+), 94 deletions(-) create mode 100755 bin/v-change-sys-ip-nat diff --git a/bin/v-add-sys-ip b/bin/v-add-sys-ip index 90315382..74884a48 100755 --- a/bin/v-add-sys-ip +++ b/bin/v-add-sys-ip @@ -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 #----------------------------------------------------------# diff --git a/bin/v-add-web-domain b/bin/v-add-web-domain index 47397899..f8071c2b 100755 --- a/bin/v-add-web-domain +++ b/bin/v-add-web-domain @@ -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'" diff --git a/bin/v-add-web-domain-alias b/bin/v-add-web-domain-alias index a14ac8ae..9305c04b 100755 --- a/bin/v-add-web-domain-alias +++ b/bin/v-add-web-domain-alias @@ -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 diff --git a/bin/v-add-web-domain-nginx b/bin/v-add-web-domain-nginx index f1509862..ae7d54ad 100755 --- a/bin/v-add-web-domain-nginx +++ b/bin/v-add-web-domain-nginx @@ -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 diff --git a/bin/v-add-web-domain-ssl b/bin/v-add-web-domain-ssl index a741d355..5fc272ec 100755 --- a/bin/v-add-web-domain-ssl +++ b/bin/v-add-web-domain-ssl @@ -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 diff --git a/bin/v-change-sys-ip-name b/bin/v-change-sys-ip-name index eae3c7ee..f96b96a0 100755 --- a/bin/v-change-sys-ip-name +++ b/bin/v-change-sys-ip-name @@ -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 diff --git a/bin/v-change-sys-ip-nat b/bin/v-change-sys-ip-nat new file mode 100755 index 00000000..813b90e2 --- /dev/null +++ b/bin/v-change-sys-ip-nat @@ -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 diff --git a/bin/v-change-web-domain-ip b/bin/v-change-web-domain-ip index 5032f3b2..6d6c6d63 100755 --- a/bin/v-change-web-domain-ip +++ b/bin/v-change-web-domain-ip @@ -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 diff --git a/bin/v-change-web-domain-nginx-tpl b/bin/v-change-web-domain-nginx-tpl index 61bd2bca..e9d1e282 100755 --- a/bin/v-change-web-domain-nginx-tpl +++ b/bin/v-change-web-domain-nginx-tpl @@ -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 diff --git a/bin/v-change-web-domain-tpl b/bin/v-change-web-domain-tpl index b812910a..90f9dbfd 100755 --- a/bin/v-change-web-domain-tpl +++ b/bin/v-change-web-domain-tpl @@ -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 diff --git a/bin/v-delete-web-domain b/bin/v-delete-web-domain index 68c9f2ac..f2ba2f14 100755 --- a/bin/v-delete-web-domain +++ b/bin/v-delete-web-domain @@ -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 diff --git a/bin/v-delete-web-domain-alias b/bin/v-delete-web-domain-alias index 55b94ef1..f5359fa0 100755 --- a/bin/v-delete-web-domain-alias +++ b/bin/v-delete-web-domain-alias @@ -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" diff --git a/bin/v-list-sys-ip b/bin/v-list-sys-ip index 0ba7f7c0..fac7d358 100755 --- a/bin/v-list-sys-ip +++ b/bin/v-list-sys-ip @@ -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 diff --git a/bin/v-list-sys-ips b/bin/v-list-sys-ips index a757019c..85b5635e 100755 --- a/bin/v-list-sys-ips +++ b/bin/v-list-sys-ips @@ -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 diff --git a/bin/v-list-user-ips b/bin/v-list-user-ips index 945556a8..ec29f00b 100755 --- a/bin/v-list-user-ips +++ b/bin/v-list-user-ips @@ -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 ;; diff --git a/bin/v-list-web-domain b/bin/v-list-web-domain index d74d1c68..480c9d83 100755 --- a/bin/v-list-web-domain +++ b/bin/v-list-web-domain @@ -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 diff --git a/bin/v-list-web-domains b/bin/v-list-web-domains index 17eeef03..ea5fac3a 100755 --- a/bin/v-list-web-domains +++ b/bin/v-list-web-domains @@ -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 diff --git a/bin/v-rebuild-web-domains b/bin/v-rebuild-web-domains index c8b6a9cc..713c952b 100755 --- a/bin/v-rebuild-web-domains +++ b/bin/v-rebuild-web-domains @@ -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)) diff --git a/bin/v-suspend-web-domain b/bin/v-suspend-web-domain index de707089..dfb4de68 100755 --- a/bin/v-suspend-web-domain +++ b/bin/v-suspend-web-domain @@ -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 diff --git a/bin/v-unsuspend-web-domain b/bin/v-unsuspend-web-domain index b62fa1ae..7820fed4 100755 --- a/bin/v-unsuspend-web-domain +++ b/bin/v-unsuspend-web-domain @@ -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 diff --git a/func/domain.sh b/func/domain.sh index b3cf4186..d7a478d5 100644 --- a/func/domain.sh +++ b/func/domain.sh @@ -256,9 +256,9 @@ add_web_config() { -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%/$elog/g" \ - -e "s/%cgi%/$cgi/g" \ - -e "s/%cgi_option%/$cgi_option/g" \ + -e "s/%elog%//g" \ + -e "s/%cgi%//g" \ + -e "s/%cgi_option%/+ExecCGI/g" \ >> $conf } @@ -464,7 +464,6 @@ namehost_ip_disable() { # Update web domain values upd_web_domain_values() { - ip=$IP group="$user" email="$user@$domain" docroot="$HOMEDIR/$user/web/$domain/public_html" diff --git a/func/ip.sh b/func/ip.sh index a42a5e57..0ac2409d 100644 --- a/func/ip.sh +++ b/func/ip.sh @@ -1,8 +1,7 @@ # Validationg ip address is_ip_valid() { - #check_ifc=$(/sbin/ifconfig |grep "inet addr:$ip") - #if [ ! -e "$VESTA/data/ips/$ip" ] || [ -z "$check_ifc" ]; then - if [ ! -e "$VESTA/data/ips/$ip" ] ; then + check_nat=$(grep "^NAT='$ip'" $VESTA/data/ips/* 2>/dev/null) + if [ ! -e "$VESTA/data/ips/$ip" ] && [ -z "$check_nat" ] ; then echo "Error: IP $ip not exist" log_event "$E_NOTEXIST" "$EVENT" exit $E_NOTEXIST @@ -11,7 +10,13 @@ is_ip_valid() { # Check if ip availabile for user is_ip_avalable() { - ip_data=$(cat $VESTA/data/ips/$ip) + if [ -e "$VESTA/data/ips/$ip" ]; then + ip_data=$(cat $VESTA/data/ips/$ip) + else + nated_ip=$(grep "^NAT='$ip'" $VESTA/data/ips/*) + nated_ip=$(echo "$nated_ip" | cut -f 1 -d : | cut -f 7 -d /) + ip_data=$(cat $VESTA/data/ips/$nated_ip) + fi owner=$(echo "$ip_data"|grep OWNER= | cut -f 2 -d \') status=$(echo "$ip_data"|grep STATUS= | cut -f 2 -d \') shared=no @@ -90,7 +95,7 @@ update_ip_value() { # Get ip name get_ip_name() { - grep "NAME=" $VESTA/data/ips/$ip |cut -f 2 -d \' + grep "NAME=" $VESTA/data/ips/$ip | cut -f 2 -d \' } # Increase ip value @@ -192,6 +197,7 @@ create_vesta_ip() { 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 @@ -205,3 +211,12 @@ create_ip_startup() { ip_data="$ip_data\nNETMASK=$mask" echo -e "$ip_data" > $iconf-$iface } + +get_real_ip() { + if [ -e "$VESTA/data/ips/$1" ]; then + echo $1 + else + nated_ip=$(grep "^NAT='$1'" $VESTA/data/ips/*) + echo "$nated_ip" | cut -f 1 -d : | cut -f 7 -d / + fi +} \ No newline at end of file diff --git a/func/main.sh b/func/main.sh index b7335418..23a7541f 100644 --- a/func/main.sh +++ b/func/main.sh @@ -752,6 +752,7 @@ validate_format(){ max_db) validate_format_int "$arg" ;; min) validate_format_mhdmw "$arg" $arg_name ;; month) validate_format_mhdmw "$arg" $arg_name ;; + nat_ip) validate_format_ip "$arg" ;; ns1) validate_format_domain "$arg" ;; ns2) validate_format_domain "$arg" ;; ns3) validate_format_domain "$arg" ;; diff --git a/web/add/ip/index.php b/web/add/ip/index.php index 000601df..ba163066 100644 --- a/web/add/ip/index.php +++ b/web/add/ip/index.php @@ -25,6 +25,7 @@ if ($_SESSION['user'] == 'admin') { $v_ip = escapeshellarg($_POST['v_ip']); $v_netmask = escapeshellarg($_POST['v_netmask']); $v_name = escapeshellarg($_POST['v_name']); + $v_nat = escapeshellarg($_POST['v_nat']); $v_interface = $_POST['v_interface']; $v_shared = $_POST['v_shared']; @@ -51,7 +52,7 @@ if ($_SESSION['user'] == 'admin') { // Add IP $v_interface = escapeshellarg($_POST['v_interface']); $v_owner = $_POST['v_owner']; - exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name, $output, $return_var); + exec (VESTA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface." ".$v_owner." '".$ip_status."' ".$v_name." ".$v_nat, $output, $return_var); $v_owner = $_POST['v_owner']; $v_interface = $_POST['v_interface']; if ($return_var != 0) { @@ -65,6 +66,7 @@ if ($_SESSION['user'] == 'admin') { unset($v_ip); unset($v_netmask); unset($v_name); + unset($v_nat); unset($output); } } diff --git a/web/delete/ip/index.php b/web/delete/ip/index.php index 9ddd03c4..15b5e6bc 100644 --- a/web/delete/ip/index.php +++ b/web/delete/ip/index.php @@ -13,7 +13,8 @@ if ($_SESSION['user'] == 'admin') { if ($return_var != 0) { $error = implode('
', $output); if (empty($error)) $error = _('Error: vesta did not return any output.'); - $_SESSION['error_msg'] = $error; + if ($return_var == 4) $error = _('IP address is in use'); + $_SESSION['error_msg'] = $error; } unset($output); diff --git a/web/edit/ip/index.php b/web/edit/ip/index.php index ebef99f1..f29438f8 100644 --- a/web/edit/ip/index.php +++ b/web/edit/ip/index.php @@ -36,6 +36,7 @@ if ($_SESSION['user'] == 'admin') { $v_netmask = $data[$v_ip]['NETMASK']; $v_interace = $data[$v_ip]['INTERFACE']; $v_name = $data[$v_ip]['NAME']; + $v_nat = $data[$v_ip]['NAT']; $v_ipstatus = $data[$v_ip]['STATUS']; if ($v_ipstatus == 'dedicated') $v_dedicated = 'yes'; $v_owner = $data[$v_ip]['OWNER']; @@ -104,6 +105,18 @@ if ($_SESSION['user'] == 'admin') { unset($output); } + // Change Nat + if (($v_nat != $_POST['v_nat']) && (empty($_SESSION['error_msg']))) { + $v_nat = escapeshellarg($_POST['v_nat']); + exec (VESTA_CMD."v-change-sys-ip-nat ".$v_ip." ".$v_nat, $output, $return_var); + if ($return_var != 0) { + $error = implode('
', $output); + if (empty($error)) $error = _('Error code:',$return_var); + $_SESSION['error_msg'] = $error; + } + unset($output); + } + if (empty($_SESSION['error_msg'])) { $_SESSION['ok_msg'] = _('Changes has been saved.'); } diff --git a/web/inc/i18n/en.php b/web/inc/i18n/en.php index 6ed2cf61..e61f332e 100644 --- a/web/inc/i18n/en.php +++ b/web/inc/i18n/en.php @@ -258,6 +258,7 @@ $LANG['en'] = array( 'Shared' => 'Shared', 'Assigned user' => 'Assigned user', 'Assigned domain' => 'Assigned domain', + 'NAT IP association' => 'NAT IP association', 'shell' => 'shell', 'web domains' => 'web domains', 'web aliases' => 'web aliases', @@ -356,8 +357,9 @@ $LANG['en'] = array( 'Passwords not match' => 'Passwords not match', 'Please enter valid email address.' => 'Please enter valid email address.', 'Field "%s" can not be blank.' => 'Field "%s" can not be blank.', - 'Error code:' => 'Error code:', + 'Error code:' => 'Error code: %s', 'SERVICE_ACTION_FAILED' => '"%s" "%s" failed', + 'IP address is in use' => 'IP address is in use', 'Welcome to Vesta Control Panel' => 'Welcome to Vesta Control Panel', 'MAIL_FROM' => 'Vesta Control Panel ', diff --git a/web/inc/i18n/ru.php b/web/inc/i18n/ru.php index 1f20aa5f..1670e44f 100644 --- a/web/inc/i18n/ru.php +++ b/web/inc/i18n/ru.php @@ -259,6 +259,7 @@ $LANG['ru'] = array( 'Shared' => 'Общий', 'Assigned user' => 'Назначить пользователю', 'Assigned domain' => 'Домен', + 'NAT IP association' => 'Ассоциированный NAT IP', 'shell' => 'ssh доступ', 'web domains' => 'веб домены', 'web aliases' => 'алиасы хостов', @@ -359,6 +360,7 @@ $LANG['ru'] = array( 'Field "%s" can not be blank.' => 'Поле "%s" не может быть пустым.', 'Error code:' => 'Код ошибки: %s', 'SERVICE_ACTION_FAILED' => 'Не удалось "%s" "%s"', + 'IP address is in use' => 'IP адрес используется', 'Welcome to Vesta Control Panel' => 'Добро пожаловать в панель управления Vesta', 'MAIL_FROM' => 'Vesta Control Panel ', diff --git a/web/templates/admin/add_ip.html b/web/templates/admin/add_ip.html index fb59949a..74b674e8 100644 --- a/web/templates/admin/add_ip.html +++ b/web/templates/admin/add_ip.html @@ -135,6 +135,18 @@ + () + + + + + diff --git a/web/templates/admin/add_web.html b/web/templates/admin/add_web.html index c46b466e..98b5ad01 100644 --- a/web/templates/admin/add_web.html +++ b/web/templates/admin/add_web.html @@ -103,11 +103,13 @@ diff --git a/web/templates/admin/edit_ip.html b/web/templates/admin/edit_ip.html index f161a002..50ac6ba5 100644 --- a/web/templates/admin/edit_ip.html +++ b/web/templates/admin/edit_ip.html @@ -123,6 +123,17 @@ + () + + + + + diff --git a/web/templates/admin/edit_web.html b/web/templates/admin/edit_web.html index 227f3204..9798aff1 100644 --- a/web/templates/admin/edit_web.html +++ b/web/templates/admin/edit_web.html @@ -95,12 +95,14 @@ diff --git a/web/templates/admin/list_ip.html b/web/templates/admin/list_ip.html index 9f445853..84c33c64 100644 --- a/web/templates/admin/list_ip.html +++ b/web/templates/admin/list_ip.html @@ -20,6 +20,31 @@ + +
+ +
+

+
+
+ @@ -64,7 +89,9 @@ diff --git a/web/templates/admin/panel.html b/web/templates/admin/panel.html index bafdccd5..95ac487a 100644 --- a/web/templates/admin/panel.html +++ b/web/templates/admin/panel.html @@ -9,26 +9,26 @@ @@ -41,12 +41,12 @@ @@ -54,12 +54,12 @@ @@ -67,12 +67,12 @@ @@ -80,11 +80,11 @@ @@ -92,11 +92,11 @@ @@ -104,7 +104,7 @@
- + + ' . $data[$key]['NAT'] . ''; ?> +
- + - + - + - + - + - + - + diff --git a/web/templates/user/add_web.html b/web/templates/user/add_web.html index f2466cc9..e26f2ab3 100644 --- a/web/templates/user/add_web.html +++ b/web/templates/user/add_web.html @@ -103,11 +103,13 @@ diff --git a/web/templates/user/edit_web.html b/web/templates/user/edit_web.html index 600850f5..8f0cb8d9 100644 --- a/web/templates/user/edit_web.html +++ b/web/templates/user/edit_web.html @@ -95,12 +95,14 @@ diff --git a/web/templates/user/panel.html b/web/templates/user/panel.html index 806d95a7..97739dab 100644 --- a/web/templates/user/panel.html +++ b/web/templates/user/panel.html @@ -9,16 +9,16 @@
- + - + - +