Skip to content

Commit 138ef6c

Browse files
committed
support for NATed networks
1 parent 5798156 commit 138ef6c

37 files changed

+271
-94
lines changed

bin/v-add-sys-ip

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add system ip address
3-
# options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME]
3+
# options: IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]
44
#
55
# The function adds ip address into a system. It also creates rc scripts. You
66
# can specify ip name which will be used as root domain for temporary aliases.
@@ -21,6 +21,7 @@ interface="${3-eth0}"
2121
user="${4-admin}"
2222
ip_status="${5-shared}" # can be dedicated as well
2323
ip_name=$6
24+
nat_ip=$7
2425

2526
# Includes
2627
source $VESTA/conf/vesta.conf
@@ -33,14 +34,17 @@ source $VESTA/func/domain.sh
3334
# Verifications #
3435
#----------------------------------------------------------#
3536

36-
check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME]'
37+
check_args '2' "$#" 'IP MASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]'
3738
validate_format 'ip' 'mask' 'interface' 'user' 'ip_status'
3839
is_ip_free
3940
is_object_valid 'user' 'USER' "$user"
4041
is_object_unsuspended 'user' 'USER' "$user"
4142
if [ ! -z "$ip_name" ] ; then
4243
validate_format 'ip_name'
4344
fi
45+
if [ ! -z "$nat_ip" ] ; then
46+
validate_format 'nat_ip'
47+
fi
4448

4549

4650
#----------------------------------------------------------#

bin/v-add-web-domain

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ fi
5757
# Action #
5858
#----------------------------------------------------------#
5959

60-
# Defining domain aliases
60+
# Define real ip in case of NAT
6161
IP=$ip
62+
ip=$(get_real_ip $ip)
63+
64+
# Defining domain aliases
6265
ip_name=$(get_ip_name)
6366
ip_name_idn=$(idn -t --quiet -a "$ip_name")
6467
domain_alias="www.$domain"
@@ -81,15 +84,12 @@ email="$user@$domain"
8184
docroot="$HOMEDIR/$user/web/$domain/public_html"
8285
conf="$HOMEDIR/$user/conf/web/httpd.conf"
8386
tpl_file="$WEBTPL/apache_$template.tpl"
84-
elog=''
85-
cgi=''
86-
cgi_option='+ExecCGI'
8787

8888
# Adding domain to the httpd.conf
8989
add_web_config
9090

9191
# Building directory tree
92-
mkdir $HOMEDIR/$user/web/$domain \
92+
mkdir -p $HOMEDIR/$user/web/$domain \
9393
$HOMEDIR/$user/web/$domain/public_html \
9494
$HOMEDIR/$user/web/$domain/public_shtml \
9595
$HOMEDIR/$user/web/$domain/document_errors \
@@ -104,7 +104,7 @@ touch /var/log/httpd/domains/$domain.bytes \
104104
/var/log/httpd/domains/$domain.error.log
105105

106106
# Adding symlink for logs
107-
ln -s /var/log/httpd/domains/$domain.*log $HOMEDIR/$user/web/$domain/logs/
107+
ln -f -s /var/log/httpd/domains/$domain.*log $HOMEDIR/$user/web/$domain/logs/
108108

109109
# Adding domain skeleton
110110
if [ -e "$WEBTPL/skel/public_html/" ]; then
@@ -168,9 +168,9 @@ increase_user_value "$user" '$U_WEB_DOMAINS'
168168
increase_user_value "$user" '$U_WEB_ALIASES'
169169

170170
# Defining domain variables
171-
str="DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$aliases' TPL='$template'"
172-
str="$str CGI='yes' ELOG='yes' SSL='no' SSL_HOME='same' FTP_USER=''"
173-
str="$str FTP_MD5='' NGINX='' NGINX_EXT='' STATS='' STATS_USER=''"
171+
str="DOMAIN='$domain' IP='$IP' IP6='' ALIAS='$aliases' TPL='$template'"
172+
str="$str SSL='no' SSL_HOME='same' FTP_USER='' FTP_MD5=''"
173+
str="$str NGINX='' NGINX_EXT='' STATS='' STATS_USER=''"
174174
str="$str STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0' SUSPENDED='no'"
175175
str="$str TIME='$TIME' DATE='$DATE'"
176176

bin/v-add-web-domain-alias

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ is_package_full 'WEB_ALIASES'
5050
get_domain_values 'web'
5151
tpl_file="$WEBTPL/apache_$TPL.tpl"
5252
conf="$HOMEDIR/$user/conf/web/httpd.conf"
53+
ip=$(get_real_ip $IP)
5354

5455
# Parsing domain aliases
5556
if [ -z "$ALIAS" ]; then

bin/v-add-web-domain-nginx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ restart="$5"
2424
source $VESTA/conf/vesta.conf
2525
source $VESTA/func/main.sh
2626
source $VESTA/func/domain.sh
27+
source $VESTA/func/ip.sh
2728

2829

2930
#----------------------------------------------------------#
@@ -57,6 +58,7 @@ NGINX="$template"
5758
NGINX_EXT="$extentions"
5859
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
5960
conf="$HOMEDIR/$user/conf/web/nginx.conf"
61+
ip=$(get_real_ip $IP)
6062

6163
# Preparing domain values for the template substitution
6264
upd_web_domain_values

bin/v-add-web-domain-ssl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ get_domain_values 'web'
6565
conf="$HOMEDIR/$user/conf/web/shttpd.conf"
6666
tpl_file="$WEBTPL/apache_$TPL.stpl"
6767
SSL_HOME="$ssl_home"
68+
ip=$(get_real_ip $IP)
6869

6970
# Preparing domain values for the template substitution
7071
upd_web_domain_values

bin/v-change-sys-ip-name

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ source $VESTA/func/ip.sh
2424
#----------------------------------------------------------#
2525

2626
check_args '2' "$#" 'IP IP_NAME'
27-
validate_format 'ip' 'ip_name'
27+
validate_format 'ip'
28+
if [ ! -z "$ip_name" ]; then
29+
validate_format 'ip_name'
30+
fi
2831
is_ip_valid
2932

3033

bin/v-change-sys-ip-nat

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# info: change ip nat address
3+
# options: IP NAT_IP
4+
#
5+
# The function for changing nat ip associated with ip.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
ip=$1
14+
nat_ip=$2
15+
16+
# Includes
17+
source $VESTA/conf/vesta.conf
18+
source $VESTA/func/main.sh
19+
source $VESTA/func/ip.sh
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
check_args '2' "$#" 'IP NAT_IP'
27+
validate_format 'ip'
28+
if [ ! -z "$nat_ip" ]; then
29+
validate_format 'nat_ip'
30+
fi
31+
is_ip_valid
32+
33+
34+
#----------------------------------------------------------#
35+
# Action #
36+
#----------------------------------------------------------#
37+
38+
# Changing nat ip
39+
if [ -z "$(grep NAT= $VESTA/data/ips/$ip)" ]; then
40+
sed -i "s/^TIME/NAT='$nat_ip'\nTIME/g" $VESTA/data/ips/$ip
41+
else
42+
update_ip_value '$NAT' "$nat_ip"
43+
fi
44+
45+
46+
#----------------------------------------------------------#
47+
# Vesta #
48+
#----------------------------------------------------------#
49+
50+
# Logging
51+
log_history "changed associated nat address on $ip to $nat_ip" '' 'admin'
52+
log_event "$OK" "$EVENT"
53+
54+
exit

bin/v-change-web-domain-ip

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ is_ip_avalable
4545

4646
# Define variable for replace
4747
get_domain_values 'web'
48+
ip=$(get_real_ip $ip)
4849
tpl_file="$WEBTPL/apache_$TPL.tpl"
4950
conf="$HOMEDIR/$user/conf/web/httpd.conf"
50-
old=$IP
51+
old=$(get_real_ip $IP)
5152
new=$ip
5253
replace_web_config
5354

@@ -82,15 +83,15 @@ increase_ip_value "$new"
8283
decrease_ip_value "$old"
8384

8485
# Update config
85-
update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$ip"
86+
update_object_value 'web' 'DOMAIN' "$domain" '$IP' "$3"
8687

8788
# Restart web server
8889
if [ "$restart" != 'no' ]; then
8990
$BIN/v-restart-web "$EVENT"
9091
fi
9192

9293
# Logging
93-
log_history "changed web domain $domain ip to $ip"
94+
log_history "changed web domain $domain ip to $3"
9495
log_event "$OK" "$EVENT"
9596

9697
exit

bin/v-change-web-domain-nginx-tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ is_nginx_template_valid
5050
get_domain_values 'web'
5151
tpl_file="$WEBTPL/nginx_$NGINX.tpl"
5252
conf="$HOMEDIR/$user/conf/web/nginx.conf"
53+
ip=$(get_real_ip $IP)
5354

5455
# Delete old vhost
5556
del_web_config

bin/v-change-web-domain-tpl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ is_apache_template_valid
4343

4444
# Parsing domain values
4545
get_domain_values 'web'
46+
ip=$(get_real_ip $IP)
4647

4748
# Deleting domain
4849
tpl_file="$WEBTPL/apache_$TPL.tpl"
@@ -61,13 +62,6 @@ fi
6162
upd_web_domain_values
6263
tpl_file="$WEBTPL/apache_$template.tpl"
6364

64-
# Checking error log
65-
if [ "$ELOG" = 'no' ]; then
66-
elog='#'
67-
else
68-
elog=''
69-
fi
70-
7165
# Adding domain to the httpd.conf
7266
add_web_config
7367

0 commit comments

Comments
 (0)