forked from msimerson/Mail-Toaster-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-squirrelmail.sh
executable file
·213 lines (171 loc) · 5.34 KB
/
provision-squirrelmail.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/sh
# shellcheck disable=1091
. mail-toaster.sh || exit
export JAIL_START_EXTRA=""
# shellcheck disable=2016
export JAIL_CONF_EXTRA=""
mt6-include 'php'
mt6-include nginx
SQ_DIR="$STAGE_MNT/usr/local/www/squirrelmail"
install_squirrelmail_mysql()
{
if [ "$TOASTER_MYSQL" != "1" ]; then return; fi
if [ "$SQUIRREL_SQL" != "1" ]; then return; fi
if ! mysql_db_exists squirrelmail; then
tell_status "creating squirrelmail database"
echo "CREATE DATABASE squirrelmail;" | jexec mysql /usr/local/bin/mysql || exit
echo "
CREATE TABLE address (
owner varchar(128) DEFAULT '' NOT NULL,
nickname varchar(16) DEFAULT '' NOT NULL,
firstname varchar(128) DEFAULT '' NOT NULL,
lastname varchar(128) DEFAULT '' NOT NULL,
email varchar(128) DEFAULT '' NOT NULL,
label varchar(255),
PRIMARY KEY (owner,nickname),
KEY firstname (firstname,lastname)
);
CREATE TABLE global_abook (
owner varchar(128) DEFAULT '' NOT NULL,
nickname varchar(16) DEFAULT '' NOT NULL,
firstname varchar(128) DEFAULT '' NOT NULL,
lastname varchar(128) DEFAULT '' NOT NULL,
email varchar(128) DEFAULT '' NOT NULL,
label varchar(255),
PRIMARY KEY (owner,nickname),
KEY firstname (firstname,lastname)
);
CREATE TABLE userprefs (
user varchar(128) DEFAULT '' NOT NULL,
prefkey varchar(64) DEFAULT '' NOT NULL,
prefval BLOB NOT NULL,
PRIMARY KEY (user,prefkey)
);" | jexec mysql /usr/local/bin/mysql squirrelmail || exit
fi
if [ -z "$sqpass" ]; then
echo "Oops, squirrelmail db password not set"
exit
fi
tee -a "$SQ_DIR/config/config_local.php" <<EO_SQUIRREL_SQL
\$prefs_dsn = 'mysql://squirrelmail:${sqpass}@$(get_jail_ip mysql)/squirrelmail';
\$addrbook_dsn = 'mysql://squirrelmail:${sqpass}@$(get_jail_ip mysql)/squirrelmail';
EO_SQUIRREL_SQL
local _grant='GRANT ALL PRIVILEGES ON squirrelmail.* to'
echo "$_grant 'squirrelmail'@'$(get_jail_ip squirrelmail)' IDENTIFIED BY '${sqpass}';" \
| jexec mysql /usr/local/bin/mysql || exit
echo "$_grant 'squirrelmail'@'$(get_jail_ip stage)' IDENTIFIED BY '${sqpass}';" \
| jexec mysql /usr/local/bin/mysql || exit
}
install_squirrelmail()
{
install_php 56 "fileinfo mcrypt exif openssl"
install_nginx || exit
tell_status "installing squirrelmail"
stage_pkg_install squirrelmail squirrelmail-sasql-plugin \
squirrelmail-quota_usage-plugin || exit
configure_squirrelmail_local
cp "$SQ_DIR/config/config_default.php" "$SQ_DIR/config/config.php"
cp "$SQ_DIR/plugins/sasql/sasql_conf.php.dist" \
"$SQ_DIR/plugins/sasql/sasql_conf.php"
cp "$SQ_DIR/plugins/quota_usage/config.php.sample" \
"$SQ_DIR/plugins/quota_usage/config.php"
mkdir -p "$STAGE_MNT/data/attach" "$STAGE_MNT/data/data"
cp "$SQ_DIR/data/default_pref" "$STAGE_MNT/data/data/"
chown -R www:www "$STAGE_MNT/data"
chmod 733 "$STAGE_MNT/data/attach"
install_squirrelmail_mysql
}
configure_nginx_server()
{
local _datadir="$ZFS_DATA_MNT/squirrelmail"
local _conf="etc/nginx-locations.conf"
if [ -f "$_datadir/$_conf" ]; then
tell_status "preservering /data/$_conf"
return
fi
tell_status "saving /data/$_conf"
tee "$_datadir/$_conf" <<'EO_NGINX_SERVER'
server_name squirrelmail;
root /usr/local/www;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_pass php;
}
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
}
EO_NGINX_SERVER
}
configure_squirrelmail_local()
{
local _active_cfg; _active_cfg="$SQ_DIR/config/config_local.php"
if [ -f "$_active_cfg" ]; then
sqpass=$(grep '//squirrelmail:' "$_active_cfg" | cut -f3 -d: | cut -f1 -d@)
fi
if [ ! -z "$sqpass" ]; then
tell_status "preserving squirrelmail mysql password: $sqpass"
else
sqpass=$(openssl rand -hex 18)
tell_status "generating squirremail mysql password: $sqpass"
fi
cp "$SQ_DIR/config/config_local.php.sample" "$SQ_DIR/config/config_local.php"
tee -a "$SQ_DIR/config/config_local.php" <<EO_SQUIRREL
\$signout_page = 'https://$TOASTER_HOSTNAME/';
\$domain = '$TOASTER_MAIL_DOMAIN';
\$smtpServerAddress = '$(get_jail_ip haraka)';
\$smtpPort = 465;
\$use_smtp_tls = true;
// PHP 5.6 enables verify_peer by default, which is good but in this context,
// unnecessary. Setting smtp_stream_options *should* disable that, but doesn't.
// Leave verify_peer disabled until squirrelmail gets this sorted out.
\$smtp_stream_options = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'verify_depth' => 3,
'cafile' => '/etc/ssl/cert.pem',
// 'allow_self_signed' => true,
],
];
\$smtp_auth_mech = 'login';
\$imapServerAddress = '$(get_jail_ip dovecot)';
\$imap_server_type = 'dovecot';
\$use_imap_tls = false;
\$data_dir = '/data/data';
\$attachment_dir = '/data/attach';
// \$check_referrer = '$TOASTER_MAIL_DOMAIN';
\$check_mail_mechanism = 'advanced';
EO_SQUIRREL
}
configure_squirrelmail()
{
configure_php squirrelmail
configure_nginx squirrelmail
configure_nginx_server
}
start_squirrelmail()
{
start_php_fpm
start_nginx
}
test_squirrelmail()
{
test_nginx
test_php_fpm
echo "it worked"
}
base_snapshot_exists || exit
create_staged_fs squirrelmail
start_staged_jail squirrelmail
install_squirrelmail
configure_squirrelmail
start_squirrelmail
test_squirrelmail
promote_staged_jail squirrelmail