|
@@ -0,0 +1,675 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# .---. . .
|
|
4
|
+# | | |
|
|
5
|
+# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
+# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
+# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
+#
|
|
9
|
+# Freedom in the Cloud
|
|
10
|
+#
|
|
11
|
+# postactiv application
|
|
12
|
+#
|
|
13
|
+# License
|
|
14
|
+# =======
|
|
15
|
+#
|
|
16
|
+# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
|
|
17
|
+#
|
|
18
|
+# This program is free software: you can redistribute it and/or modify
|
|
19
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
20
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
21
|
+# (at your option) any later version.
|
|
22
|
+#
|
|
23
|
+# This program is distributed in the hope that it will be useful,
|
|
24
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26
|
+# GNU Affero General Public License for more details.
|
|
27
|
+#
|
|
28
|
+# You should have received a copy of the GNU Affero General Public License
|
|
29
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30
|
+
|
|
31
|
+VARIANTS='full full-vim media'
|
|
32
|
+
|
|
33
|
+IN_DEFAULT_INSTALL=0
|
|
34
|
+SHOW_ON_ABOUT=1
|
|
35
|
+
|
|
36
|
+POSTACTIV_DOMAIN_NAME=
|
|
37
|
+POSTACTIV_CODE=
|
|
38
|
+POSTACTIV_ONION_PORT=8100
|
|
39
|
+POSTACTIV_REPO="https://git.gnu.io/maiyannah/postActiv"
|
|
40
|
+POSTACTIV_COMMIT='a07d28888d97e207288c86b81905e42dae90aada'
|
|
41
|
+POSTACTIV_ADMIN_PASSWORD=
|
|
42
|
+
|
|
43
|
+# script which causes old posts to expire
|
|
44
|
+postactiv_expire_script=/usr/bin/postactiv-expire
|
|
45
|
+
|
|
46
|
+postactiv_variables=(POSTACTIV_COMMIT
|
|
47
|
+ ONION_ONLY
|
|
48
|
+ POSTACTIV_DOMAIN_NAME
|
|
49
|
+ POSTACTIV_CODE
|
|
50
|
+ DDNS_PROVIDER
|
|
51
|
+ MY_USERNAME)
|
|
52
|
+
|
|
53
|
+function remove_user_postactiv {
|
|
54
|
+ remove_username="$1"
|
|
55
|
+
|
|
56
|
+ function_check get_completion_param
|
|
57
|
+ POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
|
|
58
|
+ if [ -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
|
|
59
|
+ cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
|
|
60
|
+ php scripts/deleteprofile.php -n $remove_username -y
|
|
61
|
+ fi
|
|
62
|
+}
|
|
63
|
+
|
|
64
|
+function add_user_postactiv {
|
|
65
|
+ new_username="$1"
|
|
66
|
+ new_user_password="$2"
|
|
67
|
+
|
|
68
|
+ POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
|
|
69
|
+ if [ -d /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs ]; then
|
|
70
|
+ cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
|
|
71
|
+ php scripts/registeruser.php -n $new_username -w "$new_user_password" -e "$new_username@$HOSTNAME"
|
|
72
|
+ ${PROJECT_NAME}-addemail -u $new_username -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
|
|
73
|
+ echo '0'
|
|
74
|
+ else
|
|
75
|
+ echo '1'
|
|
76
|
+ fi
|
|
77
|
+}
|
|
78
|
+
|
|
79
|
+function install_interactive_postactiv {
|
|
80
|
+ if [ ! $ONION_ONLY ]; then
|
|
81
|
+ ONION_ONLY='no'
|
|
82
|
+ fi
|
|
83
|
+
|
|
84
|
+ if [[ $ONION_ONLY != "no" ]]; then
|
|
85
|
+ POSTACTIV_DOMAIN_NAME='postactiv.local'
|
|
86
|
+ else
|
|
87
|
+ POSTACTIV_DETAILS_COMPLETE=
|
|
88
|
+ while [ ! $POSTACTIV_DETAILS_COMPLETE ]
|
|
89
|
+ do
|
|
90
|
+ data=$(tempfile 2>/dev/null)
|
|
91
|
+ trap "rm -f $data" 0 1 2 5 15
|
|
92
|
+ if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
|
|
93
|
+ dialog --backtitle $"Freedombone Configuration" \
|
|
94
|
+ --title $"PostActiv Configuration" \
|
|
95
|
+ --form $"\nPlease enter your postactiv details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
|
|
96
|
+ $"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
|
|
97
|
+ $"Code:" 2 1 "$(grep 'POSTACTIV_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
|
|
98
|
+ 2> $data
|
|
99
|
+ else
|
|
100
|
+ dialog --backtitle $"Freedombone Configuration" \
|
|
101
|
+ --title $"PostActiv Configuration" \
|
|
102
|
+ --form $"\nPlease enter your postactiv details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
|
|
103
|
+ $"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
|
|
104
|
+ 2> $data
|
|
105
|
+ fi
|
|
106
|
+ sel=$?
|
|
107
|
+ case $sel in
|
|
108
|
+ 1) exit 1;;
|
|
109
|
+ 255) exit 1;;
|
|
110
|
+ esac
|
|
111
|
+ POSTACTIV_DOMAIN_NAME=$(cat $data | sed -n 1p)
|
|
112
|
+ img_url=$(cat $data | sed -n 3p)
|
|
113
|
+ if [ $POSTACTIV_DOMAIN_NAME ]; then
|
|
114
|
+ if [[ $POSTACTIV_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
|
|
115
|
+ POSTACTIV_DOMAIN_NAME=""
|
|
116
|
+ fi
|
|
117
|
+ TEST_DOMAIN_NAME=$POSTACTIV_DOMAIN_NAME
|
|
118
|
+ validate_domain_name
|
|
119
|
+ if [[ $TEST_DOMAIN_NAME != $POSTACTIV_DOMAIN_NAME ]]; then
|
|
120
|
+ POSTACTIV_DOMAIN_NAME=
|
|
121
|
+ dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
|
|
122
|
+ else
|
|
123
|
+ if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
|
|
124
|
+ POSTACTIV_CODE=$(cat $data | sed -n 4p)
|
|
125
|
+ validate_freedns_code "$POSTACTIV_CODE"
|
|
126
|
+ if [ ! $VALID_CODE ]; then
|
|
127
|
+ POSTACTIV_DOMAIN_NAME=
|
|
128
|
+ fi
|
|
129
|
+ fi
|
|
130
|
+ fi
|
|
131
|
+ fi
|
|
132
|
+ if [ $POSTACTIV_DOMAIN_NAME ]; then
|
|
133
|
+ POSTACTIV_DETAILS_COMPLETE="yes"
|
|
134
|
+ fi
|
|
135
|
+ done
|
|
136
|
+
|
|
137
|
+ # save the results in the config file
|
|
138
|
+ write_config_param "POSTACTIV_CODE" "$POSTACTIV_CODE"
|
|
139
|
+ fi
|
|
140
|
+ write_config_param "POSTACTIV_DOMAIN_NAME" "$POSTACTIV_DOMAIN_NAME"
|
|
141
|
+ APP_INSTALLED=1
|
|
142
|
+}
|
|
143
|
+
|
|
144
|
+function change_password_postactiv {
|
|
145
|
+ echo -n ''
|
|
146
|
+}
|
|
147
|
+
|
|
148
|
+function get_mariadb_postactiv_admin_password {
|
|
149
|
+ if [ -f /home/$MY_USERNAME/README ]; then
|
|
150
|
+ if grep -q "MariaDB postactiv admin password" /home/$MY_USERNAME/README; then
|
|
151
|
+ POSTACTIV_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "MariaDB postactiv admin password" | awk -F ':' '{print $2}' | sed 's/^ *//')
|
|
152
|
+ fi
|
|
153
|
+ if grep -q "postactiv administrator password" /home/$MY_USERNAME/README; then
|
|
154
|
+ POSTACTIV_ADMIN_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "postactiv administrator password" | awk -F ':' '{print $2}' | sed 's/^ *//')
|
|
155
|
+ fi
|
|
156
|
+ fi
|
|
157
|
+}
|
|
158
|
+
|
|
159
|
+function postactiv_create_database {
|
|
160
|
+ function_check get_mariadb_postactiv_admin_password
|
|
161
|
+ get_mariadb_postactiv_admin_password
|
|
162
|
+ if [ ! $POSTACTIV_ADMIN_PASSWORD ]; then
|
|
163
|
+ if [ -f $IMAGE_PASSWORD_FILE ]; then
|
|
164
|
+ POSTACTIV_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
|
|
165
|
+ else
|
|
166
|
+ POSTACTIV_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
|
167
|
+ fi
|
|
168
|
+ fi
|
|
169
|
+ if [ ! $POSTACTIV_ADMIN_PASSWORD ]; then
|
|
170
|
+ return
|
|
171
|
+ fi
|
|
172
|
+
|
|
173
|
+ function_check create_database
|
|
174
|
+ create_database postactiv "$POSTACTIV_ADMIN_PASSWORD" $MY_USERNAME
|
|
175
|
+}
|
|
176
|
+
|
|
177
|
+function postactiv_running_script {
|
|
178
|
+ # check that the daemon is running
|
|
179
|
+ echo '#!/bin/bash' > /etc/cron.hourly/postactiv-daemons
|
|
180
|
+ echo 'daemon_lines=$(ps aux | grep "scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/postactiv-daemons
|
|
181
|
+ echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/postactiv-daemons
|
|
182
|
+
|
|
183
|
+ echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/postactiv-daemons
|
|
184
|
+ echo ' MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/postactiv-daemons
|
|
185
|
+ echo ' echo "Restarting postactiv daemons" | mail -s "postactiv daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/postactiv-daemons
|
|
186
|
+ echo " cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs" >> /etc/cron.hourly/postactiv-daemons
|
|
187
|
+ echo ' scripts/startdaemons.sh' >> /etc/cron.hourly/postactiv-daemons
|
|
188
|
+ echo 'fi' >> /etc/cron.hourly/postactiv-daemons
|
|
189
|
+ chmod +x /etc/cron.hourly/postactiv-daemons
|
|
190
|
+}
|
|
191
|
+
|
|
192
|
+function reconfigure_postactiv {
|
|
193
|
+ echo -n ''
|
|
194
|
+}
|
|
195
|
+
|
|
196
|
+function upgrade_postactiv {
|
|
197
|
+ if grep -q "postactiv domain" $COMPLETION_FILE; then
|
|
198
|
+ POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
|
|
199
|
+ fi
|
|
200
|
+
|
|
201
|
+ # update to the next commit
|
|
202
|
+ function_check set_repo_commit
|
|
203
|
+ set_repo_commit /var/www/$POSTACTIV_DOMAIN_NAME/htdocs "postactiv commit" "$POSTACTIV_COMMIT" $POSTACTIV_REPO
|
|
204
|
+
|
|
205
|
+ function_check postactiv_running_script
|
|
206
|
+ postactiv_running_script
|
|
207
|
+}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+function backup_local_postactiv {
|
|
211
|
+ POSTACTIV_DOMAIN_NAME='postactiv'
|
|
212
|
+ if grep -q "postactiv domain" $COMPLETION_FILE; then
|
|
213
|
+ POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
|
|
214
|
+ fi
|
|
215
|
+
|
|
216
|
+ source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
|
|
217
|
+ if [ -d $source_directory ]; then
|
|
218
|
+ dest_directory=postactiv
|
|
219
|
+ function_check suspend_site
|
|
220
|
+ suspend_site ${POSTACTIV_DOMAIN_NAME}
|
|
221
|
+
|
|
222
|
+ function_check backup_directory_to_usb
|
|
223
|
+ backup_directory_to_usb $source_directory $dest_directory
|
|
224
|
+
|
|
225
|
+ function_check backup_database_to_usb
|
|
226
|
+ backup_database_to_usb postactiv
|
|
227
|
+
|
|
228
|
+ function_check restart_site
|
|
229
|
+ restart_site
|
|
230
|
+ fi
|
|
231
|
+}
|
|
232
|
+
|
|
233
|
+function restore_local_postactiv {
|
|
234
|
+ if ! grep -q "postactiv domain" $COMPLETION_FILE; then
|
|
235
|
+ return
|
|
236
|
+ fi
|
|
237
|
+ POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
|
|
238
|
+ if [ $POSTACTIV_DOMAIN_NAME ]; then
|
|
239
|
+ temp_restore_dir=/root/temppostactiv
|
|
240
|
+ postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
|
|
241
|
+ # stop the daemons
|
|
242
|
+ cd $postactiv_dir
|
|
243
|
+ scripts/stopdaemons.sh
|
|
244
|
+
|
|
245
|
+ function_check postactiv_create_database
|
|
246
|
+ postactiv_create_database
|
|
247
|
+
|
|
248
|
+ restore_database postactiv ${POSTACTIV_DOMAIN_NAME}
|
|
249
|
+ if [ -d $temp_restore_dir ]; then
|
|
250
|
+ rm -rf $temp_restore_dir
|
|
251
|
+ fi
|
|
252
|
+
|
|
253
|
+ # start the daemons
|
|
254
|
+ cd $postactiv_dir
|
|
255
|
+ scripts/startdaemons.sh
|
|
256
|
+ fi
|
|
257
|
+}
|
|
258
|
+
|
|
259
|
+function backup_remote_postactiv {
|
|
260
|
+ if grep -q "postactiv domain" $COMPLETION_FILE; then
|
|
261
|
+ POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
|
|
262
|
+ temp_backup_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
|
|
263
|
+ if [ -d $temp_backup_dir ]; then
|
|
264
|
+ function_check suspend_site
|
|
265
|
+ suspend_site ${POSTACTIV_DOMAIN_NAME}
|
|
266
|
+
|
|
267
|
+ function_check backup_database_to_friend
|
|
268
|
+ backup_database_to_friend postactiv
|
|
269
|
+
|
|
270
|
+ function_check backup_directory_to_friend
|
|
271
|
+ backup_directory_to_friend $temp_backup_dir postactiv
|
|
272
|
+
|
|
273
|
+ function_check restart_site
|
|
274
|
+ restart_site
|
|
275
|
+ else
|
|
276
|
+ echo $"postactiv domain specified but not found in ${temp_backup_dir}"
|
|
277
|
+ fi
|
|
278
|
+ fi
|
|
279
|
+}
|
|
280
|
+
|
|
281
|
+function restore_remote_postactiv {
|
|
282
|
+ if grep -q "postactiv domain" $COMPLETION_FILE; then
|
|
283
|
+ POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
|
|
284
|
+
|
|
285
|
+ # stop the daemons
|
|
286
|
+ cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
|
|
287
|
+ ./scripts/stopdaemons.sh
|
|
288
|
+
|
|
289
|
+ function_check postactiv_create_database
|
|
290
|
+ postactiv_create_database
|
|
291
|
+
|
|
292
|
+ function_check restore_database_from_friend
|
|
293
|
+ restore_database_from_friend postactiv ${POSTACTIV_DOMAIN_NAME}
|
|
294
|
+ if [ -d /root/temppostactiv ]; then
|
|
295
|
+ rm -rf /root/temppostactiv
|
|
296
|
+ fi
|
|
297
|
+
|
|
298
|
+ # start the daemons
|
|
299
|
+ cd /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
|
|
300
|
+ ./scripts/startdaemons.sh
|
|
301
|
+ fi
|
|
302
|
+}
|
|
303
|
+
|
|
304
|
+function remove_postactiv {
|
|
305
|
+ if [ ${#POSTACTIV_DOMAIN_NAME} -eq 0 ]; then
|
|
306
|
+ return
|
|
307
|
+ fi
|
|
308
|
+ read_config_param "POSTACTIV_DOMAIN_NAME"
|
|
309
|
+ read_config_param "MY_USERNAME"
|
|
310
|
+ echo "Removing $POSTACTIV_DOMAIN_NAME"
|
|
311
|
+ nginx_dissite $POSTACTIV_DOMAIN_NAME
|
|
312
|
+ remove_certs $POSTACTIV_DOMAIN_NAME
|
|
313
|
+ if [ -f /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh ]; then
|
|
314
|
+ cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts
|
|
315
|
+ ./scripts/stopdaemons.sh
|
|
316
|
+ fi
|
|
317
|
+ if [ -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
|
|
318
|
+ rm -rf /var/www/$POSTACTIV_DOMAIN_NAME
|
|
319
|
+ fi
|
|
320
|
+ if [ -f /etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME ]; then
|
|
321
|
+ rm /etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
|
|
322
|
+ fi
|
|
323
|
+ function_check drop_database
|
|
324
|
+ drop_database postactiv
|
|
325
|
+ function_check remove_onion_service
|
|
326
|
+ remove_onion_service postactiv ${POSTACTIV_ONION_PORT}
|
|
327
|
+ if grep -q "postactiv" /etc/crontab; then
|
|
328
|
+ sed -i "/postactiv/d" /etc/crontab
|
|
329
|
+ fi
|
|
330
|
+ remove_app postactiv
|
|
331
|
+ remove_completion_param install_postactiv
|
|
332
|
+ sed -i '/postactiv/d' $COMPLETION_FILE
|
|
333
|
+ if [ -f /etc/cron.hourly/postactiv-daemons ]; then
|
|
334
|
+ rm /etc/cron.hourly/postactiv-daemons
|
|
335
|
+ fi
|
|
336
|
+ sed -i '/Postactiv/d' /home/$MY_USERNAME/README
|
|
337
|
+}
|
|
338
|
+
|
|
339
|
+function install_postactiv_main {
|
|
340
|
+ if [ ! $POSTACTIV_DOMAIN_NAME ]; then
|
|
341
|
+ echo $'No domain name was given for postactiv'
|
|
342
|
+ exit 7359
|
|
343
|
+ fi
|
|
344
|
+
|
|
345
|
+ if [[ $(app_is_installed postactiv_main) == "1" ]]; then
|
|
346
|
+ return
|
|
347
|
+ fi
|
|
348
|
+
|
|
349
|
+ function_check postactiv_running_script
|
|
350
|
+ postactiv_running_script
|
|
351
|
+
|
|
352
|
+ function_check install_mariadb
|
|
353
|
+ install_mariadb
|
|
354
|
+
|
|
355
|
+ function_check get_mariadb_password
|
|
356
|
+ get_mariadb_password
|
|
357
|
+
|
|
358
|
+ function_check repair_databases_script
|
|
359
|
+ repair_databases_script
|
|
360
|
+
|
|
361
|
+ apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
|
|
362
|
+ apt-get -yq install php5-memcached php5-intl
|
|
363
|
+
|
|
364
|
+ if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME ]; then
|
|
365
|
+ mkdir /var/www/$POSTACTIV_DOMAIN_NAME
|
|
366
|
+ fi
|
|
367
|
+ if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
|
|
368
|
+ function_check git_clone
|
|
369
|
+ git_clone $POSTACTIV_REPO /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
|
|
370
|
+ if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
|
|
371
|
+ echo $'Unable to clone postactiv repo'
|
|
372
|
+ exit 87525
|
|
373
|
+ fi
|
|
374
|
+ fi
|
|
375
|
+
|
|
376
|
+ cd /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
|
|
377
|
+ git checkout $POSTACTIV_COMMIT -b $POSTACTIV_COMMIT
|
|
378
|
+ set_completion_param "postactiv commit" "$POSTACTIV_COMMIT"
|
|
379
|
+
|
|
380
|
+ chmod a+w /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
|
|
381
|
+ chown www-data:www-data /var/www/$POSTACTIV_DOMAIN_NAME/htdocs
|
|
382
|
+ chmod +x /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php
|
|
383
|
+
|
|
384
|
+ function_check postactiv_create_database
|
|
385
|
+ postactiv_create_database
|
|
386
|
+
|
|
387
|
+ if [ ! -f "/etc/aliases" ]; then
|
|
388
|
+ touch /etc/aliases
|
|
389
|
+ fi
|
|
390
|
+ if ! grep -q "www-data: root" /etc/aliases; then
|
|
391
|
+ echo 'www-data: root' >> /etc/aliases
|
|
392
|
+ fi
|
|
393
|
+ if ! grep -q "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
|
|
394
|
+ echo "*: /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
|
|
395
|
+ fi
|
|
396
|
+
|
|
397
|
+ function_check add_ddns_domain
|
|
398
|
+ add_ddns_domain $POSTACTIV_DOMAIN_NAME
|
|
399
|
+
|
|
400
|
+ postactiv_nginx_site=/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
|
|
401
|
+ if [[ $ONION_ONLY == "no" ]]; then
|
|
402
|
+ function_check nginx_http_redirect
|
|
403
|
+ nginx_http_redirect $POSTACTIV_DOMAIN_NAME
|
|
404
|
+ echo 'server {' >> $postactiv_nginx_site
|
|
405
|
+ echo ' listen 443 ssl;' >> $postactiv_nginx_site
|
|
406
|
+ echo " server_name $POSTACTIV_DOMAIN_NAME;" >> $postactiv_nginx_site
|
|
407
|
+ echo '' >> $postactiv_nginx_site
|
|
408
|
+ echo ' # Security' >> $postactiv_nginx_site
|
|
409
|
+ function_check nginx_ssl
|
|
410
|
+ nginx_ssl $POSTACTIV_DOMAIN_NAME
|
|
411
|
+
|
|
412
|
+ function_check nginx_disable_sniffing
|
|
413
|
+ nginx_disable_sniffing $POSTACTIV_DOMAIN_NAME
|
|
414
|
+
|
|
415
|
+ echo ' add_header Strict-Transport-Security max-age=15768000;' >> $postactiv_nginx_site
|
|
416
|
+ echo '' >> $postactiv_nginx_site
|
|
417
|
+ echo ' # Logs' >> $postactiv_nginx_site
|
|
418
|
+ echo ' access_log off;' >> $postactiv_nginx_site
|
|
419
|
+ echo ' error_log off;' >> $postactiv_nginx_site
|
|
420
|
+ echo '' >> $postactiv_nginx_site
|
|
421
|
+ echo ' # Root' >> $postactiv_nginx_site
|
|
422
|
+ echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;" >> $postactiv_nginx_site
|
|
423
|
+ echo '' >> $postactiv_nginx_site
|
|
424
|
+ echo ' # Index' >> $postactiv_nginx_site
|
|
425
|
+ echo ' index index.php;' >> $postactiv_nginx_site
|
|
426
|
+ echo '' >> $postactiv_nginx_site
|
|
427
|
+ echo ' # PHP' >> $postactiv_nginx_site
|
|
428
|
+ echo ' location ~ \.php {' >> $postactiv_nginx_site
|
|
429
|
+ echo ' include snippets/fastcgi-php.conf;' >> $postactiv_nginx_site
|
|
430
|
+ echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $postactiv_nginx_site
|
|
431
|
+ echo ' }' >> $postactiv_nginx_site
|
|
432
|
+ echo '' >> $postactiv_nginx_site
|
|
433
|
+ echo ' # Location' >> $postactiv_nginx_site
|
|
434
|
+ echo ' location / {' >> $postactiv_nginx_site
|
|
435
|
+ function_check nginx_limits
|
|
436
|
+ nginx_limits $POSTACTIV_DOMAIN_NAME '15m'
|
|
437
|
+ echo ' try_files $uri $uri/ @postactiv;' >> $postactiv_nginx_site
|
|
438
|
+ echo ' }' >> $postactiv_nginx_site
|
|
439
|
+ echo '' >> $postactiv_nginx_site
|
|
440
|
+ echo ' # Fancy URLs' >> $postactiv_nginx_site
|
|
441
|
+ echo ' location @postactiv {' >> $postactiv_nginx_site
|
|
442
|
+ echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $postactiv_nginx_site
|
|
443
|
+ echo ' }' >> $postactiv_nginx_site
|
|
444
|
+ echo '' >> $postactiv_nginx_site
|
|
445
|
+ echo ' # Restrict access that is unnecessary anyway' >> $postactiv_nginx_site
|
|
446
|
+ echo ' location ~ /\.(ht|git) {' >> $postactiv_nginx_site
|
|
447
|
+ echo ' deny all;' >> $postactiv_nginx_site
|
|
448
|
+ echo ' }' >> $postactiv_nginx_site
|
|
449
|
+ echo '}' >> $postactiv_nginx_site
|
|
450
|
+ else
|
|
451
|
+ echo -n '' > $postactiv_nginx_site
|
|
452
|
+ fi
|
|
453
|
+ echo 'server {' >> $postactiv_nginx_site
|
|
454
|
+ echo " listen 127.0.0.1:$POSTACTIV_ONION_PORT default_server;" >> $postactiv_nginx_site
|
|
455
|
+ echo " server_name $POSTACTIV_DOMAIN_NAME;" >> $postactiv_nginx_site
|
|
456
|
+ echo '' >> $postactiv_nginx_site
|
|
457
|
+ function_check nginx_disable_sniffing
|
|
458
|
+ nginx_disable_sniffing $POSTACTIV_DOMAIN_NAME
|
|
459
|
+ echo '' >> $postactiv_nginx_site
|
|
460
|
+ echo ' # Logs' >> $postactiv_nginx_site
|
|
461
|
+ echo ' access_log off;' >> $postactiv_nginx_site
|
|
462
|
+ echo ' error_log off;' >> $postactiv_nginx_site
|
|
463
|
+ echo '' >> $postactiv_nginx_site
|
|
464
|
+ echo ' # Root' >> $postactiv_nginx_site
|
|
465
|
+ echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;" >> $postactiv_nginx_site
|
|
466
|
+ echo '' >> $postactiv_nginx_site
|
|
467
|
+ echo ' # Index' >> $postactiv_nginx_site
|
|
468
|
+ echo ' index index.php;' >> $postactiv_nginx_site
|
|
469
|
+ echo '' >> $postactiv_nginx_site
|
|
470
|
+ echo ' # PHP' >> $postactiv_nginx_site
|
|
471
|
+ echo ' location ~ \.php {' >> $postactiv_nginx_site
|
|
472
|
+ echo ' include snippets/fastcgi-php.conf;' >> $postactiv_nginx_site
|
|
473
|
+ echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $postactiv_nginx_site
|
|
474
|
+ echo ' }' >> $postactiv_nginx_site
|
|
475
|
+ echo '' >> $postactiv_nginx_site
|
|
476
|
+ echo ' # Location' >> $postactiv_nginx_site
|
|
477
|
+ echo ' location / {' >> $postactiv_nginx_site
|
|
478
|
+ function_check nginx_limits
|
|
479
|
+ nginx_limits $POSTACTIV_DOMAIN_NAME '15m'
|
|
480
|
+ echo ' try_files $uri $uri/ @postactiv;' >> $postactiv_nginx_site
|
|
481
|
+ echo ' }' >> $postactiv_nginx_site
|
|
482
|
+ echo '' >> $postactiv_nginx_site
|
|
483
|
+ echo ' # Fancy URLs' >> $postactiv_nginx_site
|
|
484
|
+ echo ' location @postactiv {' >> $postactiv_nginx_site
|
|
485
|
+ echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $postactiv_nginx_site
|
|
486
|
+ echo ' }' >> $postactiv_nginx_site
|
|
487
|
+ echo '' >> $postactiv_nginx_site
|
|
488
|
+ echo ' # Restrict access that is unnecessary anyway' >> $postactiv_nginx_site
|
|
489
|
+ echo ' location ~ /\.(ht|git) {' >> $postactiv_nginx_site
|
|
490
|
+ echo ' deny all;' >> $postactiv_nginx_site
|
|
491
|
+ echo ' }' >> $postactiv_nginx_site
|
|
492
|
+ echo '}' >> $postactiv_nginx_site
|
|
493
|
+
|
|
494
|
+ function_check configure_php
|
|
495
|
+ configure_php
|
|
496
|
+
|
|
497
|
+ function_check create_site_certificate
|
|
498
|
+ create_site_certificate $POSTACTIV_DOMAIN_NAME 'yes'
|
|
499
|
+
|
|
500
|
+ # Ensure that the database gets backed up locally, if remote
|
|
501
|
+ # backups are not being used
|
|
502
|
+ function_check backup_databases_script_header
|
|
503
|
+ backup_databases_script_header
|
|
504
|
+
|
|
505
|
+ function_check backup_database_local
|
|
506
|
+ backup_database_local postactiv
|
|
507
|
+
|
|
508
|
+ function_check nginx_ensite
|
|
509
|
+ nginx_ensite $POSTACTIV_DOMAIN_NAME
|
|
510
|
+
|
|
511
|
+ # NOTE: For the typical case always enable SSL and only
|
|
512
|
+ # disable it if in onion only mode. This is due to complexities
|
|
513
|
+ # with the way URLs are generated by postactiv
|
|
514
|
+ postactiv_ssl='always'
|
|
515
|
+ if [[ $ONION_ONLY != 'no' ]]; then
|
|
516
|
+ postactiv_ssl='never'
|
|
517
|
+ fi
|
|
518
|
+
|
|
519
|
+ POSTACTIV_ONION_HOSTNAME=$(add_onion_service postactiv 80 ${POSTACTIV_ONION_PORT})
|
|
520
|
+
|
|
521
|
+ POSTACTIV_SERVER=${POSTACTIV_DOMAIN_NAME}
|
|
522
|
+ if [[ $ONION_ONLY != 'no' ]]; then
|
|
523
|
+ POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME}
|
|
524
|
+ fi
|
|
525
|
+
|
|
526
|
+ # Create the configuration
|
|
527
|
+ postactiv_installer=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts/install_cli.php
|
|
528
|
+ if [ ! -f $postactiv_installer ]; then
|
|
529
|
+ echo $'No postactiv commandline installer found'
|
|
530
|
+ exit 53026
|
|
531
|
+ fi
|
|
532
|
+ ${postactiv_installer} --server "${POSTACTIV_SERVER}" \
|
|
533
|
+ --host="localhost" --database="postactiv" \
|
|
534
|
+ --dbtype=mysql --username="root" -v \
|
|
535
|
+ --password="$MARIADB_PASSWORD" \
|
|
536
|
+ --sitename=$"postactiv" --fancy='yes' \
|
|
537
|
+ --admin-nick="$MY_USERNAME" \
|
|
538
|
+ --admin-pass="$POSTACTIV_ADMIN_PASSWORD" \
|
|
539
|
+ --site-profile="community" \
|
|
540
|
+ --ssl=${postactiv_ssl}
|
|
541
|
+ # There can be a lot of warnings here so the return value check is disabled
|
|
542
|
+ #if [ ! "$?" = "0" ]; then
|
|
543
|
+ # # failed to install
|
|
544
|
+ # echo $'Could not install postactiv'
|
|
545
|
+ # exit 72357
|
|
546
|
+ #fi
|
|
547
|
+
|
|
548
|
+ # check postactiv has a config file
|
|
549
|
+ postactiv_config_file=/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/config.php
|
|
550
|
+ if [ ! -f $postactiv_config_file ]; then
|
|
551
|
+ echo $'Postactiv config.php not found'
|
|
552
|
+ exit 87586
|
|
553
|
+ fi
|
|
554
|
+
|
|
555
|
+ # Some useful settings
|
|
556
|
+ if ! grep -q "Recommended postactiv settings" $postactiv_config_file; then
|
|
557
|
+ echo "" >> $postactiv_config_file
|
|
558
|
+ echo "// Recommended postactiv settings" >> $postactiv_config_file
|
|
559
|
+ echo "\$config['thumbnail']['maxsize'] = 3000;" >> $postactiv_config_file
|
|
560
|
+ echo "\$config['profile']['delete'] = true;" >> $postactiv_config_file
|
|
561
|
+ echo "\$config['profile']['changenick'] = true;" >> $postactiv_config_file
|
|
562
|
+ echo "\$config['public']['localonly'] = false;" >> $postactiv_config_file
|
|
563
|
+ echo "addPlugin('StoreRemoteMedia');" >> $postactiv_config_file
|
|
564
|
+ echo "\$config['queue']['enabled'] = true;" >> $postactiv_config_file
|
|
565
|
+ echo "\$config['queue']['daemon'] = true;" >> $postactiv_config_file
|
|
566
|
+ echo "\$config['ostatus']['hub_retries'] = 3;" >> $postactiv_config_file
|
|
567
|
+ fi
|
|
568
|
+
|
|
569
|
+ # This improves performance
|
|
570
|
+ sed -i "s|//\$config\['db'\]\['schemacheck'\].*|\$config\['db'\]\['schemacheck'\] = 'script';|g" $postactiv_config_file
|
|
571
|
+
|
|
572
|
+ systemctl restart php5-fpm
|
|
573
|
+ systemctl restart nginx
|
|
574
|
+
|
|
575
|
+ ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
|
|
576
|
+
|
|
577
|
+ # some post-install instructions for the user
|
|
578
|
+ if ! grep -q $"Postactiv administrator" /home/$MY_USERNAME/README; then
|
|
579
|
+ echo '' >> /home/$MY_USERNAME/README
|
|
580
|
+ echo '' >> /home/$MY_USERNAME/README
|
|
581
|
+ echo $'# Postactiv' >> /home/$MY_USERNAME/README
|
|
582
|
+ echo $"Postactiv administrator nickname: $MY_USERNAME" >> /home/$MY_USERNAME/README
|
|
583
|
+ echo $"Postactiv administrator password: $POSTACTIV_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
|
|
584
|
+ chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
|
|
585
|
+ chmod 600 /home/$MY_USERNAME/README
|
|
586
|
+ else
|
|
587
|
+ if [ -f /home/$MY_USERNAME/README ]; then
|
|
588
|
+ sed -i "s|Postactiv administrator password.*|Postactiv administrator password: $POSTACTIV_ADMIN_PASSWORD|g" /home/$MY_USERNAME/README
|
|
589
|
+ fi
|
|
590
|
+ fi
|
|
591
|
+
|
|
592
|
+ if ! grep -q "Postactiv onion domain" /home/$MY_USERNAME/README; then
|
|
593
|
+ echo $"Postactiv onion domain: ${POSTACTIV_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
|
|
594
|
+ echo '' >> /home/$MY_USERNAME/README
|
|
595
|
+ chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
|
|
596
|
+ chmod 600 /home/$MY_USERNAME/README
|
|
597
|
+ else
|
|
598
|
+ if [ -f /home/$MY_USERNAME/README ]; then
|
|
599
|
+ sed -i "s|Postactiv onion domain.*|Postactiv onion domain: ${POSTACTIV_ONION_HOSTNAME}|g" /home/$MY_USERNAME/README
|
|
600
|
+ fi
|
|
601
|
+ fi
|
|
602
|
+
|
|
603
|
+ set_completion_param "postactiv domain" "$POSTACTIV_DOMAIN_NAME"
|
|
604
|
+
|
|
605
|
+ install_completed postactiv_main
|
|
606
|
+}
|
|
607
|
+
|
|
608
|
+function expire_postactiv_posts {
|
|
609
|
+ # To prevent the database size from growing endlessly this script expires posts
|
|
610
|
+ # after a number of months
|
|
611
|
+ if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
|
|
612
|
+ return
|
|
613
|
+ fi
|
|
614
|
+
|
|
615
|
+ echo '<?php' > $postactiv_expire_script
|
|
616
|
+ echo '' >> $postactiv_expire_script
|
|
617
|
+ echo '// postactiv post expiry script, based on StatExpire by Tony Baldwin' >> $postactiv_expire_script
|
|
618
|
+ echo '// https://github.com/tonybaldwin/statexpire' >> $postactiv_expire_script
|
|
619
|
+ echo '' >> $postactiv_expire_script
|
|
620
|
+ echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $postactiv_expire_script
|
|
621
|
+ echo '$username="root";' >> $postactiv_expire_script
|
|
622
|
+ echo "\$password=trim(file_get_contents(\"$DATABASE_PASSWORD_FILE\"));" >> $postactiv_expire_script
|
|
623
|
+ echo '$database="postactiv";' >> $postactiv_expire_script
|
|
624
|
+ echo '' >> $postactiv_expire_script
|
|
625
|
+ echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $postactiv_expire_script
|
|
626
|
+ echo ' echo "Could not connect to mariadb";' >> $postactiv_expire_script
|
|
627
|
+ echo ' exit;' >> $postactiv_expire_script
|
|
628
|
+ echo '}' >> $postactiv_expire_script
|
|
629
|
+ echo '' >> $postactiv_expire_script
|
|
630
|
+ echo 'if (!mysql_select_db($database, $link)) {' >> $postactiv_expire_script
|
|
631
|
+ echo ' echo "Could not select postactiv database";' >> $postactiv_expire_script
|
|
632
|
+ echo ' exit;' >> $postactiv_expire_script
|
|
633
|
+ echo '}' >> $postactiv_expire_script
|
|
634
|
+ echo '' >> $postactiv_expire_script
|
|
635
|
+ echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $postactiv_expire_script
|
|
636
|
+ echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $postactiv_expire_script
|
|
637
|
+ echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $postactiv_expire_script
|
|
638
|
+ echo '' >> $postactiv_expire_script
|
|
639
|
+ echo 'mysql_query($notice_query);' >> $postactiv_expire_script
|
|
640
|
+ echo '$rowaff1=mysql_affected_rows();' >> $postactiv_expire_script
|
|
641
|
+ echo 'mysql_query($conversation_query);' >> $postactiv_expire_script
|
|
642
|
+ echo '$rowaff2=mysql_affected_rows();' >> $postactiv_expire_script
|
|
643
|
+ echo 'mysql_query($reply_query);' >> $postactiv_expire_script
|
|
644
|
+ echo '$rowaff3=mysql_affected_rows();' >> $postactiv_expire_script
|
|
645
|
+ echo 'mysql_close();' >> $postactiv_expire_script
|
|
646
|
+ echo '' >> $postactiv_expire_script
|
|
647
|
+ echo 'echo "Expire postactiv posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $postactiv_expire_script
|
|
648
|
+ chmod +x $postactiv_expire_script
|
|
649
|
+
|
|
650
|
+ # Add a cron job
|
|
651
|
+ if ! grep -q "$postactiv_expire_script" /etc/crontab; then
|
|
652
|
+ echo "10 3 5 * * root /usr/bin/timeout 500 /usr/bin/php $postactiv_expire_script" >> /etc/crontab
|
|
653
|
+ fi
|
|
654
|
+
|
|
655
|
+ # remove old expire script
|
|
656
|
+ if [ -f /etc/cron.weekly/clear-postactiv-database ]; then
|
|
657
|
+ rm /etc/cron.weekly/clear-postactiv-database
|
|
658
|
+ fi
|
|
659
|
+}
|
|
660
|
+
|
|
661
|
+function install_postactiv {
|
|
662
|
+ if [ ! $ONION_ONLY ]; then
|
|
663
|
+ ONION_ONLY='no'
|
|
664
|
+ fi
|
|
665
|
+
|
|
666
|
+ install_postactiv_main
|
|
667
|
+ expire_postactiv_posts
|
|
668
|
+
|
|
669
|
+ # unleash the daemons!
|
|
670
|
+ /etc/cron.hourly/postactiv-daemons
|
|
671
|
+
|
|
672
|
+ APP_INSTALLED=1
|
|
673
|
+}
|
|
674
|
+
|
|
675
|
+# NOTE: deliberately there is no "exit 0"
|