freedombone-app-webmail 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Webmail application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  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. WEBMAIL_REPO="https://github.com/roundcube/roundcubemail"
  31. WEBMAIL_COMMIT='78cf9c2e5cff2d78cd8beb647d60570f195a2a9c'
  32. WEBMAIL_ONION_HOSTNAME=
  33. WEBMAIL_ONION_PORT=8097
  34. WEBMAIL_ADMIN_PASSWORD=
  35. WEB_PATH=/var/www
  36. WEBMAIL_PATH=$WEB_PATH/webmail
  37. function upgrade_webmail {
  38. echo ''
  39. }
  40. function backup_local_webmail {
  41. echo ''
  42. }
  43. function backup_remote_webmail {
  44. echo ''
  45. }
  46. function remove_webmail {
  47. if ! grep -Fxq "install_webmail" $COMPLETION_FILE; then
  48. return
  49. fi
  50. nginx_dissite webmail
  51. if [ -f /etc/nginx/sites-available/webmail ]; then
  52. rm /etc/nginx/sites-available/webmail
  53. fi
  54. function_check remove_onion_service
  55. remove_onion_service webmail ${WEBMAIL_ONION_PORT}
  56. function_check drop_database
  57. drop_database webmain
  58. if [ -d $WEB_PATH/webmail ]; then
  59. rm -rf $WEB_PATH/webmail
  60. fi
  61. sed -i '/Webmail /d' $COMPLETION_FILE
  62. sed -i '/install_webmail/d' $COMPLETION_FILE
  63. }
  64. function install_webmail {
  65. if [[ $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
  66. return
  67. fi
  68. # update to a new commit if needed
  69. function_check set_repo_commit
  70. set_repo_commit $WEBMAIL_PATH "Webmail commit" "$WEBMAIL_COMMIT" $WEBMAIL_REPO
  71. if grep -Fxq "install_webmail" $COMPLETION_FILE; then
  72. return
  73. fi
  74. if [ -d /etc/apache2 ]; then
  75. rm -rf /etc/apache2
  76. echo $'Removed Apache installation after Dokuwiki install'
  77. fi
  78. function_check install_mariadb
  79. install_mariadb
  80. function_check get_mariadb_password
  81. get_mariadb_password
  82. function_check repair_databases_script
  83. repair_databases_script
  84. apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
  85. apt-get -y install php5-dev imagemagick php5-imagick php5-sqlite php-auth-sasl php-net-smtp php-mime-type
  86. apt-get -y install php-mail-mime php-mail-mimedecode php-net-ldap3 php5-pspell
  87. pear install Net_IDNA2
  88. if [ ! -f $WEBMAIL_PATH/index.php ]; then
  89. cd $WEB_PATH
  90. git_clone $WEBMAIL_REPO webmail
  91. cd $WEBMAIL_PATH
  92. git checkout $WEBMAIL_COMMIT -b $WEBMAIL_COMMIT
  93. if ! grep -q "Webmail commit" $COMPLETION_FILE; then
  94. echo "Webmail commit:$WEBMAIL_COMMIT" >> $COMPLETION_FILE
  95. else
  96. sed -i "s/Webmail commit.*/Webmail commit:$WEBMAIL_COMMIT/g" $COMPLETION_FILE
  97. fi
  98. fi
  99. if [ ! -f $WEBMAIL_PATH/index.php ]; then
  100. echo $'Did not clone webmail repo'
  101. exit 52825
  102. fi
  103. WEBMAIL_ONION_HOSTNAME=$(add_onion_service webmail 80 ${WEBMAIL_ONION_PORT})
  104. echo "Webmail onion domain:${WEBMAIL_ONION_HOSTNAME}" >> $COMPLETION_FILE
  105. function_check get_mariadb_webmail_admin_password
  106. get_mariadb_webmail_admin_password
  107. if [ ! $WEBMAIL_ADMIN_PASSWORD ]; then
  108. if [ -f $IMAGE_PASSWORD_FILE ]; then
  109. WEBMAIL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  110. else
  111. WEBMAIL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  112. fi
  113. fi
  114. function_check create_database
  115. create_database webmail "$WEBMAIL_ADMIN_PASSWORD"
  116. mysql -u root --password="$MARIADB_PASSWORD" -D webmail < $WEBMAIL_PATH/SQL/mysql.initial.sql
  117. if [ ! -d /var/www/$DEFAULT_DOMAIN_NAME/htdocs ]; then
  118. mkdir -p /var/www/$DEFAULT_DOMAIN_NAME/htdocs
  119. fi
  120. ln -s $WEBMAIL_PATH /var/www/$DEFAULT_DOMAIN_NAME/htdocs/webmail
  121. if [ ! -f /var/www/webmail/config/config.inc.php ]; then
  122. # generate the configuration
  123. echo '<?php' > /var/www/webmail/config/config.inc.php
  124. echo "\$config['db_dsnw'] = 'mysql://root:${MARIADB_PASSWORD}@localhost/webmail';" >> /var/www/webmail/config/config.inc.php
  125. echo "\$config['default_host'] = 'localhost';" >> /var/www/webmail/config/config.inc.php
  126. echo "\$config['support_url'] = '';" >> /var/www/webmail/config/config.inc.php
  127. WEBMAIL_DES_KEY="$(create_password 25)"
  128. echo "\$config['des_key'] = '${WEBMAIL_DES_KEY}';" >> /var/www/webmail/config/config.inc.php
  129. echo "\$config['product_name'] = '${PROJECT_NAME}';" >> /var/www/webmail/config/config.inc.php
  130. echo "\$config['plugins'] = array('enigma');" >> /var/www/webmail/config/config.inc.php
  131. echo "\$config['mime_param_folding'] = 0;" >> /var/www/webmail/config/config.inc.php
  132. echo "\$config['enable_installer'] = false;" >> /var/www/webmail/config/config.inc.php
  133. fi
  134. chown -R www-data:www-data $WEBMAIL_PATH
  135. echo 'server {' > /etc/nginx/sites-available/webmail
  136. echo " listen 127.0.0.1:$WEBMAIL_ONION_PORT default_server;" >> /etc/nginx/sites-available/webmail
  137. echo " server_name $WEBMAIL_ONION_HOSTNAME;" >> /etc/nginx/sites-available/webmail
  138. echo " root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
  139. echo ' index index.php index.html index.htm;' >> /etc/nginx/sites-available/webmail
  140. echo ' access_log off;' >> /etc/nginx/sites-available/webmail
  141. echo ' error_log off;' >> /etc/nginx/sites-available/webmail
  142. echo ' location / {' >> /etc/nginx/sites-available/webmail
  143. echo ' try_files $uri $uri/ /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/webmail
  144. echo ' }' >> /etc/nginx/sites-available/webmail
  145. echo ' error_page 404 /404.html;' >> /etc/nginx/sites-available/webmail
  146. echo ' error_page 500 502 503 504 /50x.html;' >> /etc/nginx/sites-available/webmail
  147. echo ' location = /50x.html {' >> /etc/nginx/sites-available/webmail
  148. echo " root ${WEBMAIL_PATH};" >> /etc/nginx/sites-available/webmail
  149. echo ' }' >> /etc/nginx/sites-available/webmail
  150. echo ' location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {' >> /etc/nginx/sites-available/webmail
  151. echo ' deny all;' >> /etc/nginx/sites-available/webmail
  152. echo ' }' >> /etc/nginx/sites-available/webmail
  153. echo ' location ~ ^/(config|temp|logs)/ {' >> /etc/nginx/sites-available/webmail
  154. echo ' deny all;' >> /etc/nginx/sites-available/webmail
  155. echo ' }' >> /etc/nginx/sites-available/webmail
  156. echo ' location ~ /\. {' >> /etc/nginx/sites-available/webmail
  157. echo ' deny all;' >> /etc/nginx/sites-available/webmail
  158. echo ' access_log off;' >> /etc/nginx/sites-available/webmail
  159. echo ' log_not_found off;' >> /etc/nginx/sites-available/webmail
  160. echo ' }' >> /etc/nginx/sites-available/webmail
  161. echo ' location ~ \.php$ {' >> /etc/nginx/sites-available/webmail
  162. echo ' try_files $uri =404;' >> /etc/nginx/sites-available/webmail
  163. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/webmail
  164. echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/webmail
  165. echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/webmail
  166. echo ' include fastcgi_params;' >> /etc/nginx/sites-available/webmail
  167. echo ' }' >> /etc/nginx/sites-available/webmail
  168. echo ' add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/webmail
  169. echo ' add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/webmail
  170. echo ' client_max_body_size 15m;' >> /etc/nginx/sites-available/webmail
  171. echo '}' >> /etc/nginx/sites-available/webmail
  172. nginx_ensite webmail
  173. systemctl restart php5-fpm
  174. systemctl restart nginx
  175. if ! grep -q "Webmail" /home/$MY_USERNAME/README; then
  176. echo '' >> /home/$MY_USERNAME/README
  177. echo '' >> /home/$MY_USERNAME/README
  178. echo 'Webmail' >> /home/$MY_USERNAME/README
  179. echo '=======' >> /home/$MY_USERNAME/README
  180. if [[ $ONION_ONLY == 'no' ]]; then
  181. echo $"Open https://$DEFAULT_DOMAIN_NAME/webmail/index.php" >> /home/$MY_USERNAME/README
  182. else
  183. echo $"Open http://$WEBMAIL_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
  184. fi
  185. echo $"MariaDB webmail admin password: $WEBMAIL_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
  186. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  187. chmod 600 /home/$MY_USERNAME/README
  188. fi
  189. echo 'install_webmail' >> $COMPLETION_FILE
  190. }
  191. # NOTE: deliberately no exit 0