Explorar o código

IPV6: Mail and WebMail functionality

IPV6 WebMail templates
asmcc %!s(int64=3) %!d(string=hai) anos
pai
achega
689b78879d

+ 15 - 3
bin/v-add-mail-domain

@@ -84,11 +84,20 @@ check_hestia_demo_mode
 source_conf "$USER_DATA/user.conf"
 # Inherit web domain local ip address
 domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
-if [ ! -z "$domain_ip" ]; then
+domain_ipv6=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP6')
+if [ -n "$domain_ipv6" ]; then
+	local_ipv6=$(get_real_ipv6 "$domain_ipv6")
+	is_ipv6_valid "$local_ipv6" "$user"
+fi
+if [ -n "$domain_ip" ]; then
 	local_ip=$(get_real_ip "$domain_ip")
 	is_ip_valid "$local_ip" "$user"
-else
-	get_user_ip
+fi
+if [ -z "$local_ip" -a -z "$local_ipv6" ]; then
+	get_user_ipv6	#	get first available user ipv6 address as fallback, if none ip address was defined
+	if [ -z "$ipv6" ]; then
+		get_user_ip	#	get first available user ipv4 address as fallback, if none ipv6 user address available
+	fi
 fi
 
 # Generating timestamp
@@ -137,6 +146,9 @@ if [[ "$MAIL_SYSTEM" =~ exim ]]; then
 	if [ -n "$local_ip" ]; then
 		echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
 	fi
+	if [ -n "$local_ipv6" ]; then
+		echo "$local_ipv6" > $HOMEDIR/$user/conf/mail/$domain/ipv6
+	fi
 
 	if [ -n "$ANTISPAM_SYSTEM" ]; then
 		# Adding antispam protection

+ 12 - 2
bin/v-add-mail-domain-webmail

@@ -79,6 +79,12 @@ check_hestia_demo_mode
 
 # Inherit web domain local ip address
 domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
+domain_ipv6=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP6')
+if [ -n "$domain_ipv6" ]; then
+	local_ipv6=$(get_real_ipv6 "$domain_ipv6")
+	is_ipv6_valid "$local_ipv6" "$user"
+	ipv6=$local_ipv6
+fi
 if [ -n "$domain_ip" ]; then
 	local_ip=$(get_real_ip "$domain_ip")
 	is_ip_valid "$local_ip" "$user"
@@ -88,8 +94,12 @@ if [ -n "$domain_ip" ]; then
 	if [ -n "$nat_ip" ]; then
 		ip=$nat_ip
 	fi
-else
-	get_user_ip
+fi
+if [ -z "$ip" -a -z "$ipv6" ]; then
+	get_user_ipv6	#	get first available user ipv6 address as fallback, if none ip address was defined
+	if [ -z "$ipv6" ]; then
+		get_user_ip	#	get first available user ipv4 address as fallback, if none ipv6 user address available
+	fi
 fi
 
 # Verify that webmail alias variable exists and create it if it does not

+ 51 - 32
func/domain.sh

@@ -6,6 +6,44 @@
 #                                                                           #
 #===========================================================================#
 
+#----------------------------------------------------------#
+#                   COMMON FUNCTIONS                       #
+#----------------------------------------------------------#
+
+# Prepare IPV4 and IPV6 addresses for using in templates
+prepare_ips_for_template() {
+	if [ -z "$local_ip" ]; then
+		i4mark=""
+		ipv4=""
+		web_ipv4=""
+		web_ip="[$local_ipv6]"
+		proxy_ipv4=""
+		proxy_ip="[$local_ipv6]"
+		legacy_ip="[$local_ipv6]"
+	else
+		i4mark="\1"
+		ipv4="$local_ip"
+		web_ipv4="$local_ip"
+		web_ip="$local_ip"
+		proxy_ipv4="$local_ip"
+		proxy_ip="$local_ip"
+		legacy_ip="$local_ip"
+	fi
+	if [ -z "$local_ipv6" ]; then
+		i6mark=""
+		web_ipv6=""
+		web_ip="$local_ip"
+		proxy_ipv6=""
+		proxy_ip="$local_ip"
+	else
+		i6mark="\1"
+		web_ipv6="[$local_ipv6]"
+		web_ip="[$local_ipv6]"
+		proxy_ipv6="[$local_ipv6]"
+		proxy_ip="[$local_ipv6]"
+	fi
+}
+
 #----------------------------------------------------------#
 #                        WEB                               #
 #----------------------------------------------------------#
@@ -250,37 +288,8 @@ add_web_config() {
 		fi
 	fi
 	
-	if [ -z "$local_ip" ]; then
-		i4mark=""
-		ipv4=""
-		web_ipv4=""
-		web_ip="[$local_ipv6]"
-		proxy_ipv4=""
-		proxy_ip="[$local_ipv6]"
-		legacy_ip="[$local_ipv6]"
-	else
-		i4mark="\1"
-		ipv4="$local_ip"
-		web_ipv4="$local_ip"
-		web_ip="$local_ip"
-		proxy_ipv4="$local_ip"
-		proxy_ip="$local_ip"
-		legacy_ip="$local_ip"
-	fi
-	if [ -z "$local_ipv6" ]; then
-		i6mark=""
-		web_ipv6=""
-		web_ip="$local_ip"
-		proxy_ipv6=""
-		proxy_ip="$local_ip"
-	else
-		i6mark="\1"
-		web_ipv6="[$local_ipv6]"
-		web_ip="[$local_ipv6]"
-		proxy_ipv6="[$local_ipv6]"
-		proxy_ip="[$local_ipv6]"
-	fi
-	
+	prepare_ips_for_template	#	prepare IPV4 and IPV6 variables for template substitution
+
 	# Note: Removing or renaming template variables will lead to broken custom templates.
 	#   -If possible custom templates should be automatically upgraded to use the new format
 	#   -Alternatively a depreciation period with proper notifications should be considered
@@ -848,12 +857,22 @@ add_webmail_config() {
 		override_alias_idn="mail.$domain_idn"
 	fi
 
+	prepare_ips_for_template	#	prepare IPV4 and IPV6 variables for template substitution
+
 	# Note: Removing or renaming template variables will lead to broken custom templates.
 	#   -If possible custom templates should be automatically upgraded to use the new format
 	#   -Alternatively a depreciation period with proper notifications should be considered
 
 	cat $MAILTPL/$1/$2 \
-		| sed -e "s|%ip%|$local_ip|g" \
+		| sed -e "s|%<i4\(.*\)i4>%|$i4mark|g" \
+			-e "s|%<i6\(.*\)i6>%|$i6mark|g" \
+			-e "s|%web_ipv4%|$web_ipv4|g" \
+			-e "s|%web_ipv6%|$web_ipv6|g" \
+			-e "s|%web_ip%|$web_ip|g" \
+			-e "s|%proxy_ipv4%|$proxy_ipv4|g" \
+			-e "s|%proxy_ipv6%|$proxy_ipv6|g" \
+			-e "s|%proxy_ip%|$proxy_ip|g" \
+			-e "s|%ip%|$legacy_ip|g" \
 			-e "s|%domain%|$WEBMAIL_ALIAS.$domain|g" \
 			-e "s|%domain_idn%|$WEBMAIL_ALIAS.$domain_idn|g" \
 			-e "s|%root_domain%|$domain|g" \

+ 1 - 4
func/ip.sh

@@ -435,10 +435,7 @@ get_real_ipv6() {
     if [ -e "$HESTIA/data/ips/$1" ]; then
         echo $1
     else
-        nat=$(grep -H "^NAT='$1'" $HESTIA/data/ips/*)
-        if [ ! -z "$nat" ]; then
-            echo "$nat" |cut -f 1 -d : |cut -f 7 -d /
-        fi
+        check_result $E_NOTEXIST "IPV6 $1 doesn't exist"
     fi
 }
 

+ 1 - 1
install/deb/templates/mail/apache2/default.stpl

@@ -1,4 +1,4 @@
-<VirtualHost %ip%:%web_ssl_port%>
+<VirtualHost%<i4 %web_ipv4%:%web_ssl_port%i4>%%<i6 %web_ipv6%:%web_ssl_port%i6>%>
     ServerName %domain_idn%
     ServerAlias %alias%
     Alias / /var/lib/roundcube/

+ 1 - 1
install/deb/templates/mail/apache2/default.tpl

@@ -1,4 +1,4 @@
-<VirtualHost %ip%:%web_port%>
+<VirtualHost%<i4 %web_ipv4%:%web_port%i4>%%<i6 %web_ipv6%:%web_port%i6>%>
     ServerName %domain_idn%
     ServerAlias %alias_idn%
     Alias / /var/lib/roundcube/

+ 1 - 1
install/deb/templates/mail/apache2/disabled.stpl

@@ -1,4 +1,4 @@
-<VirtualHost %ip%:%web_ssl_port%>
+<VirtualHost%<i4 %web_ipv4%:%web_ssl_port%i4>%%<i6 %web_ipv6%:%web_ssl_port%i6>%>
 ServerName %domain_idn%
 ServerAlias %alias_idn%
 DocumentRoot /var/www/html/

+ 1 - 1
install/deb/templates/mail/apache2/disabled.tpl

@@ -1,4 +1,4 @@
-<VirtualHost %ip%:%web_port%>
+<VirtualHost%<i4 %web_ipv4%:%web_port%i4>%%<i6 %web_ipv6%:%web_port%i6>%>
     ServerName %domain_idn%
     ServerAlias %alias_idn%
     DocumentRoot /var/www/html/

+ 1 - 1
install/deb/templates/mail/apache2/rainloop.stpl

@@ -1,4 +1,4 @@
-<VirtualHost %ip%:%web_ssl_port%>
+<VirtualHost%<i4 %web_ipv4%:%web_ssl_port%i4>%%<i6 %web_ipv6%:%web_ssl_port%i6>%>
 ServerName %domain_idn%
 ServerAlias %alias_idn%
 Alias / /var/lib/rainloop/

+ 1 - 1
install/deb/templates/mail/apache2/rainloop.tpl

@@ -1,4 +1,4 @@
-<VirtualHost %ip%:%web_port%>
+<VirtualHost%<i4 %web_ipv4%:%web_port%i4>%%<i6 %web_ipv6%:%web_port%i6>%>
     ServerName %domain_idn%
     ServerAlias %alias_idn%
     Alias / /var/lib/rainloop/

+ 6 - 5
install/deb/templates/mail/nginx/default.stpl

@@ -1,13 +1,14 @@
 server {
-    listen      %ip%:%proxy_ssl_port% ssl http2;
+%<i4    listen      %proxy_ipv4%:%proxy_ssl_port% ssl http2;i4>%
+%<i6    listen      %proxy_ipv6%:%proxy_ssl_port% ssl http2;i6>%
     server_name %domain_idn% %alias_idn%;
     root        /var/lib/roundcube;
     index       index.php index.html index.htm;
     access_log /var/log/nginx/domains/%domain%.log combined;
     error_log  /var/log/nginx/domains/%domain%.error.log error;
 
-    ssl_certificate     %ssl_pem%;
-    ssl_certificate_key %ssl_key%;
+    ssl_certificate      %ssl_pem%;
+    ssl_certificate_key  %ssl_key%;
     ssl_stapling on;
     ssl_stapling_verify on;
 
@@ -22,7 +23,7 @@ server {
     }
 
     location / {
-        proxy_pass https://%ip%:%web_ssl_port%;
+        proxy_pass      https://%web_ip%:%web_ssl_port%;
         try_files $uri $uri/ =404;
         alias /var/lib/roundcube/;
         location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
@@ -36,7 +37,7 @@ server {
     }
 
     location @fallback {
-        proxy_pass https://%ip%:%web_ssl_port%;
+        proxy_pass      https://%web_ip%:%web_ssl_port%;
     }
 
     proxy_hide_header Upgrade;

+ 5 - 4
install/deb/templates/mail/nginx/default.tpl

@@ -1,5 +1,6 @@
 server {
-    listen      %ip%:%proxy_port%;
+%<i4    listen      %proxy_ipv4%:%proxy_port%;i4>%
+%<i6    listen      %proxy_ipv6%:%proxy_port%;i6>%
     server_name %domain_idn% %alias_idn%;
     root        /var/lib/roundcube;
     index       index.php index.html index.htm;
@@ -19,7 +20,7 @@ server {
     }
 
     location / {
-        proxy_pass http://%ip%:%web_port%;
+        proxy_pass      http://%web_ip%:%web_port%;
         try_files $uri $uri/ =404;
         alias /var/lib/roundcube/;
         location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
@@ -29,11 +30,11 @@ server {
     }
 
     location /error/ {
-        alias /var/www/document_errors/;
+        alias   /var/www/document_errors/;
     }
 
     location @fallback {
-        proxy_pass http://%ip%:%web_port%;
+        proxy_pass      http://%web_ip%:%web_port%;
     }
 
     include %home%/%user%/conf/mail/%root_domain%/%proxy_system%.conf_*;

+ 3 - 2
install/deb/templates/mail/nginx/default_disabled.stpl

@@ -1,5 +1,6 @@
 server {
-    listen       %ip%:%proxy_ssl_port% ssl http2;
+%<i4    listen      %proxy_ipv4%:%proxy_ssl_port% ssl http2;i4>%
+%<i6    listen      %proxy_ipv6%:%proxy_ssl_port% ssl http2;i6>%
     server_name  %domain_idn% %alias_idn%;
     index       index.php index.html index.htm;
     access_log /var/log/nginx/domains/%domain%.log combined;
@@ -16,7 +17,7 @@ server {
     }
 
     location / {
-        proxy_pass  http://%ip%:%web_port%;
+        proxy_pass      http://%web_ip%:%web_port%;
     }
 
     proxy_hide_header Upgrade;

+ 3 - 2
install/deb/templates/mail/nginx/default_disabled.tpl

@@ -1,5 +1,6 @@
 server {
-listen       %ip%:%proxy_port%;
+%<i4    listen      %proxy_ipv4%:%proxy_port%;i4>%
+%<i6    listen      %proxy_ipv6%:%proxy_port%;i6>%
 server_name  %domain_idn% %alias_idn%;
 index       index.php index.html index.htm;
 access_log /var/log/nginx/domains/%domain%.log combined;
@@ -13,7 +14,7 @@ include %home%/%user%/conf/mail/%root_domain%/nginx.forcessl.conf*;
     }
 
     location / {
-        proxy_pass  http://%ip%:%web_port%;
+        proxy_pass      http://%web_ip%:%web_port%;
     }
 
     include %home%/%user%/conf/mail/%root_domain%/%proxy_system%.conf_*;

+ 4 - 3
install/deb/templates/mail/nginx/default_rainloop.stpl

@@ -1,5 +1,6 @@
 server {
-listen      %ip%:%proxy_ssl_port% ssl http2;
+%<i4    listen      %proxy_ipv4%:%proxy_ssl_port% ssl http2;i4>%
+%<i6    listen      %proxy_ipv6%:%proxy_ssl_port% ssl http2;i6>%
 server_name %domain_idn% %alias_idn%;
 root        /var/lib/rainloop;
 index       index.php index.html index.htm;
@@ -22,7 +23,7 @@ location ~ ^/(README.md|config|temp|logs|bin|SQL|INSTALL|LICENSE|CHANGELOG|UPGRA
 }
 
 location / {
-    proxy_pass https://%ip%:%web_ssl_port%;
+    proxy_pass https://%web_ip%:%web_ssl_port%;
     try_files $uri $uri/ =404;
     alias /var/lib/rainloop/;
     location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
@@ -36,7 +37,7 @@ location /error/ {
 }
 
 location @fallback {
-    proxy_pass https://%ip%:%web_ssl_port%;
+    proxy_pass https://%web_ip%:%web_ssl_port%;
 }
 
 proxy_hide_header Upgrade;

+ 4 - 3
install/deb/templates/mail/nginx/default_rainloop.tpl

@@ -1,5 +1,6 @@
 server {
-listen      %ip%:%proxy_port%;
+%<i4    listen      %proxy_ipv4%:%proxy_port%;i4>%
+%<i6    listen      %proxy_ipv6%:%proxy_port%;i6>%
 server_name %domain_idn% %alias_idn%;
 root        /var/lib/rainloop;
 index       index.php index.html index.htm;
@@ -24,7 +25,7 @@ location ~ ^/(README.md|config|temp|logs|bin|SQL|INSTALL|LICENSE|CHANGELOG|UPGRA
 }
 
 location / {
-    proxy_pass http://%ip%:%web_port%;
+    proxy_pass      http://%web_ip%:%web_port%;
     try_files $uri $uri/ =404;
     alias /var/lib/rainloop/;
     location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
@@ -38,7 +39,7 @@ location /error/ {
 }
 
 location @fallback {
-    proxy_pass http://%ip%:%web_port%;
+    proxy_pass      http://%web_ip%:%web_port%;
 }
 
 include %home%/%user%/conf/mail/%root_domain%/%proxy_system%.conf_*;

+ 2 - 1
install/deb/templates/mail/nginx/disabled.stpl

@@ -1,5 +1,6 @@
 server {
-    listen      %ip%:%web_ssl_port% ssl http2;
+%<i4    listen      %web_ipv4%:%web_ssl_port% ssl http2;i4>%
+%<i6    listen      %web_ipv6%:%web_ssl_port% ssl http2;i6>%
     server_name %domain_idn% %alias_idn%;
     root        /var/www/html;
     index       index.php index.html index.htm;

+ 2 - 1
install/deb/templates/mail/nginx/disabled.tpl

@@ -1,5 +1,6 @@
 server {
-    listen      %ip%:%web_port%;
+%<i4    listen      %web_ipv4%:%web_port%;i4>%
+%<i6    listen      %web_ipv6%:%web_port%;i6>%
     server_name %domain_idn% %alias_idn%;
     root        /var/www/html;
     index       index.php index.html index.htm;

+ 2 - 1
install/deb/templates/mail/nginx/rainloop.stpl

@@ -1,5 +1,6 @@
 server {
-listen      %ip%:%web_ssl_port% ssl http2;
+%<i4    listen      %web_ipv4%:%web_ssl_port% ssl http2;i4>%
+%<i6    listen      %web_ipv6%:%web_ssl_port% ssl http2;i6>%
 server_name %domain_idn% %alias_idn%;
 root        /var/lib/rainloop;
 index       index.php index.html index.htm;

+ 2 - 1
install/deb/templates/mail/nginx/rainloop.tpl

@@ -1,5 +1,6 @@
 server {
-listen      %ip%:%web_port%;
+%<i4    listen      %web_ipv4%:%web_port%;i4>%
+%<i6    listen      %web_ipv6%:%web_port%;i6>%
 server_name %domain_idn% %alias_idn%;
 root        /var/lib/rainloop;
 index       index.php index.html index.htm;

+ 2 - 1
install/deb/templates/mail/nginx/web_system.stpl

@@ -1,5 +1,6 @@
 server {
-    listen      %ip%:%web_ssl_port% ssl http2;
+%<i4    listen      %web_ipv4%:%web_ssl_port% ssl http2;i4>%
+%<i6    listen      %web_ipv6%:%web_ssl_port% ssl http2;i6>%
     server_name %domain_idn% %alias_idn%;
     root        /var/lib/roundcube;
     index       index.php index.html index.htm;

+ 2 - 1
install/deb/templates/mail/nginx/web_system.tpl

@@ -1,5 +1,6 @@
 server {
-    listen      %ip%:%web_port%;
+%<i4    listen      %web_ipv4%:%web_port%;i4>%
+%<i6    listen      %web_ipv6%:%web_port%;i6>%
     server_name %domain_idn% %alias_idn%;
     root        /var/lib/roundcube;
     index       index.php index.html index.htm;