-
Notifications
You must be signed in to change notification settings - Fork 1
/
zm_fix_zpush_lets.sh
95 lines (65 loc) · 2.49 KB
/
zm_fix_zpush_lets.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#! /bin/bash
##################################################################################
# Creator: @anahuac kyahosting.com.br
# Maintainer: @ananiasfilho kmee.com.br
#
# Version: 0.1
# License: GNU General Public License v3.0
# https://github.com/ananiasfilho/zm-fix-zpush-lets/blob/master/LICENSE
##################################################################################
whereis_templates="/opt/zimbra/conf/nginx/templates"
files=`grep Microsoft-Server-ActiveSync $whereis_templates/* | cut -d: -f1 | sort | uniq`
for file in $files ; do
# Z-PUSH
l1=`grep -n Microsoft-Server-ActiveSync $file | cut -d: -f1`
if [ "$l1" != "" ] ; then
many_spaces=`grep Microsoft-Server-ActiveSync $file | awk -F'[^ \t]' '{print length($1)","NR}' | cut -d, -f1`
regexp=$(echo "}" | perl -pe "\$_=\" \"x$many_spaces .\$_")
li="$l1"
while [ true ] ; do
regtest=`sed "${li}q;d" $file | grep "^$regexp"`
if [ "$regtest" != "" ] ; then
l2=$li
break
fi
li=`expr $li + 1`
#echo "$regexp"
done
# Adiciona as configurações certas
head_n=`expr ${l1} - 1`
head -n $head_n $file >/tmp/file_tmp_nginx_zm
echo " location ^~ /Microsoft-Server-ActiveSync
{
set \$mailhostport \${web.http.uport};
set \$relhost \$host;
if (\$mailhostport != 80) {
set \$relhost \$host:\$mailhostport;
}
include /opt/z-push/nginx-php-fpm.conf;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
set \$virtual_host \$http_host;
if (\$virtual_host = '') {
set \$virtual_host $server_addr:$server_port;
}
proxy_set_header Host \$virtual_host;
proxy_redirect http://\$http_host/ https://\$http_host/;
proxy_redirect http://\$relhost/ https://\$http_host/;
}
" >> /tmp/file_tmp_nginx_zm
total_lines=`wc -l $file | cut -d" " -f1`
tail_n=`expr $total_lines - ${l2}`
tail -n $tail_n $file >>/tmp/file_tmp_nginx_zm
fi
# LET'S ENCRYPT
test_lets=`grep letsencrypt $file | grep acme-challenge`
if [ "$test_lets" = "" ] ; then
head_n=`expr $total_lines - 1`
head -n $head_n $file >/tmp/file_tmp_nginx_zm
echo "" >>/tmp/file_tmp_nginx_zm
echo " location ^~ /.well-known/acme-challenge { root /opt/zimbra/data/nginx/letsencrypt; }" >>/tmp/file_tmp_nginx_zm
echo "" >>/tmp/file_tmp_nginx_zm
echo "}" >>/tmp/file_tmp_nginx_zm
fi
# Copia o arquivo para o lugar certo
cp /tmp/file_tmp_nginx_zm $file
done