From 3c13cefa519ab8bd765ab569672fc6a7aedbdf73 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob.mottram@codethink.co.uk>
Date: Mon, 25 Apr 2016 17:48:10 +0100
Subject: [PATCH] Beginning of webmail

---
 src/freedombone              | 590 ++++++++++++++++++++---------------
 src/freedombone-controlpanel |  10 +-
 2 files changed, 353 insertions(+), 247 deletions(-)

diff --git a/src/freedombone b/src/freedombone
index c2ac8af1..e0280bb5 100755
--- a/src/freedombone
+++ b/src/freedombone
@@ -217,6 +217,13 @@ HUBZILLA_ADMIN_PASSWORD=
 HUBZILLA_COMMIT='b6ae2bff01f8a4dfc057ef2971b3d988b1028b3e'
 HUBZILLA_ADDONS_COMMIT='48725235777e2088fe109b722a5fc9141b6840ec'
 
+# roundcube webmail
+WEBMAIL_REPO="https://github.com/roundcube/roundcubemail"
+WEBMAIL_COMMIT='78cf9c2e5cff2d78cd8beb647d60570f195a2a9c'
+WEBMAIL_ONION_HOSTNAME=
+WEBMAIL_ONION_PORT=8097
+WEBMAIL_ADMIN_PASSWORD=
+
 # Domain name for git hosting installation
 GIT_DOMAIN_NAME=
 GIT_CODE=
@@ -1066,6 +1073,12 @@ function read_configuration {
         if [[ $CONFIGURATION_FILE != "/root/${PROJECT_NAME}.cfg" ]]; then
             cp $CONFIGURATION_FILE /root/${PROJECT_NAME}.cfg
         fi
+        if grep -q "WEBMAIL_REPO" $CONFIGURATION_FILE; then
+            WEBMAIL_REPO=$(grep "WEBMAIL_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
+        fi
+        if grep -q "WEBMAIL_COMMIT" $CONFIGURATION_FILE; then
+            WEBMAIL_COMMIT=$(grep "WEBMAIL_COMMIT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
+        fi
         if grep -q "WIFI_INTERFACE" $CONFIGURATION_FILE; then
             WIFI_INTERFACE=$(grep "WIFI_INTERFACE" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
         fi
@@ -2009,60 +2022,60 @@ function backup_database_local {
     backup_databases_script=/usr/bin/backupdatabases
     echo '' >> $backup_databases_script
     echo "# Backup the ${database_name} database" >> $backup_databases_script
-    echo "TEMPFILE=/root/${database_name}.sql" >> $backup_databases_script
-    echo 'DAILYFILE=/var/backups/${database_name}_daily.sql' >> $backup_databases_script
-    echo "mysqldump --password=\"\$MYSQL_PASSWORD\" ${database_name} > \$TEMPFILE" >> $backup_databases_script
-    echo 'FILESIZE=$(stat -c%s $TEMPFILE)' >> $backup_databases_script
-    echo 'if [ "$FILESIZE" -eq "0" ]; then' >> $backup_databases_script
-    echo '    if [ -f $DAILYFILE ]; then' >> $backup_databases_script
-    echo '        cp $DAILYFILE $TEMPFILE' >> $backup_databases_script
-    echo '' >> $backup_databases_script
-    echo '        # try to restore yesterdays database' >> $backup_databases_script
-    echo "        mysql -u root --password=\"\$MYSQL_PASSWORD\" ${database_name} -o < \$DAILYFILE" >> $backup_databases_script
-    echo '' >> $backup_databases_script
-    echo '        # Send a warning email' >> $backup_databases_script
-    echo "        echo \"Unable to create a backup of the ${database_name} database. Attempted to restore from yesterdays backup\" | mail -s \"${database_name} backup\" \$EMAIL" >> $backup_databases_script
-    echo '    else' >> $backup_databases_script
-    echo '        # Send a warning email' >> $backup_databases_script
-    echo "        echo \"Unable to create a backup of the ${database_name} database.\" | mail -s \"${database_name} backup\" \$EMAIL" >> $backup_databases_script
-    echo '    fi' >> $backup_databases_script
-    echo 'else' >> $backup_databases_script
-    echo '    chmod 600 $TEMPFILE' >> $backup_databases_script
-    echo '    mv $TEMPFILE $DAILYFILE' >> $backup_databases_script
-    echo '' >> $backup_databases_script
-    echo '    # Make the backup readable only by root' >> $backup_databases_script
-    echo '    chmod 600 $DAILYFILE' >> $backup_databases_script
-    echo 'fi' >> $backup_databases_script
+		  echo "TEMPFILE=/root/${database_name}.sql" >> $backup_databases_script
+		  echo 'DAILYFILE=/var/backups/${database_name}_daily.sql' >> $backup_databases_script
+		  echo "mysqldump --password=\"\$MYSQL_PASSWORD\" ${database_name} > \$TEMPFILE" >> $backup_databases_script
+		  echo 'FILESIZE=$(stat -c%s $TEMPFILE)' >> $backup_databases_script
+		  echo 'if [ "$FILESIZE" -eq "0" ]; then' >> $backup_databases_script
+		  echo '    if [ -f $DAILYFILE ]; then' >> $backup_databases_script
+		  echo '        cp $DAILYFILE $TEMPFILE' >> $backup_databases_script
+		  echo '' >> $backup_databases_script
+		  echo '        # try to restore yesterdays database' >> $backup_databases_script
+		  echo "        mysql -u root --password=\"\$MYSQL_PASSWORD\" ${database_name} -o < \$DAILYFILE" >> $backup_databases_script
+		  echo '' >> $backup_databases_script
+		  echo '        # Send a warning email' >> $backup_databases_script
+		  echo "        echo \"Unable to create a backup of the ${database_name} database. Attempted to restore from yesterdays backup\" | mail -s \"${database_name} backup\" \$EMAIL" >> $backup_databases_script
+		  echo '    else' >> $backup_databases_script
+		  echo '        # Send a warning email' >> $backup_databases_script
+		  echo "        echo \"Unable to create a backup of the ${database_name} database.\" | mail -s \"${database_name} backup\" \$EMAIL" >> $backup_databases_script
+		  echo '    fi' >> $backup_databases_script
+		  echo 'else' >> $backup_databases_script
+		  echo '    chmod 600 $TEMPFILE' >> $backup_databases_script
+		  echo '    mv $TEMPFILE $DAILYFILE' >> $backup_databases_script
+		  echo '' >> $backup_databases_script
+		  echo '    # Make the backup readable only by root' >> $backup_databases_script
+		  echo '    chmod 600 $DAILYFILE' >> $backup_databases_script
+		  echo 'fi' >> $backup_databases_script
 
-    weekly_backup_script=/etc/cron.weekly/backupdatabasesweekly
-    if ! grep -q "${database_name}" ${weekly_backup_script}; then
-        echo '' >> ${weekly_backup_script}
-        echo "# ${database_name}" >> ${weekly_backup_script}
-        echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then" >> ${weekly_backup_script}
-        echo "  cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_2weekly.sql" >> ${weekly_backup_script}
-        echo 'fi' >> ${weekly_backup_script}
-        echo "if [ -f /var/backups/${database_name}_daily.sql ]; then" >> ${weekly_backup_script}
-        echo "  cp -f /var/backups/${database_name}_daily.sql /var/backups/${database_name}_weekly.sql" >> ${weekly_backup_script}
-        echo 'fi' >> ${weekly_backup_script}
-    fi
+		  weekly_backup_script=/etc/cron.weekly/backupdatabasesweekly
+		  if ! grep -q "${database_name}" ${weekly_backup_script}; then
+			  echo '' >> ${weekly_backup_script}
+			  echo "# ${database_name}" >> ${weekly_backup_script}
+			  echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then" >> ${weekly_backup_script}
+			  echo "  cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_2weekly.sql" >> ${weekly_backup_script}
+			  echo 'fi' >> ${weekly_backup_script}
+			  echo "if [ -f /var/backups/${database_name}_daily.sql ]; then" >> ${weekly_backup_script}
+			  echo "  cp -f /var/backups/${database_name}_daily.sql /var/backups/${database_name}_weekly.sql" >> ${weekly_backup_script}
+			  echo 'fi' >> ${weekly_backup_script}
+		  fi
 
-    monthly_backup_script=/etc/cron.monthly/backupdatabasesmonthly
-    if ! grep -q "${database_name}" ${monthly_backup_script}; then
-        echo '' >> ${monthly_backup_script}
-        echo "# ${database_name}" >> ${monthly_backup_script}
-        echo "if [ -f /var/backups/${database_name}_monthly.sql ]; then" >> ${monthly_backup_script}
-        echo "  cp -f /var/backups/${database_name}_monthly.sql /var/backups/${database_name}_2monthly.sql" >> ${monthly_backup_script}
-        echo 'fi' >> ${monthly_backup_script}
-        echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then" >> ${monthly_backup_script}
-        echo "  cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_monthly.sql" >> ${monthly_backup_script}
-        echo 'fi' >> ${monthly_backup_script}
-    fi
+		  monthly_backup_script=/etc/cron.monthly/backupdatabasesmonthly
+		  if ! grep -q "${database_name}" ${monthly_backup_script}; then
+			  echo '' >> ${monthly_backup_script}
+			  echo "# ${database_name}" >> ${monthly_backup_script}
+			  echo "if [ -f /var/backups/${database_name}_monthly.sql ]; then" >> ${monthly_backup_script}
+			  echo "  cp -f /var/backups/${database_name}_monthly.sql /var/backups/${database_name}_2monthly.sql" >> ${monthly_backup_script}
+			  echo 'fi' >> ${monthly_backup_script}
+			  echo "if [ -f /var/backups/${database_name}_weekly.sql ]; then" >> ${monthly_backup_script}
+			  echo "  cp -f /var/backups/${database_name}_weekly.sql /var/backups/${database_name}_monthly.sql" >> ${monthly_backup_script}
+			  echo 'fi' >> ${monthly_backup_script}
+		  fi
 
-    if ! grep -q "${database_name}" /etc/cron.hourly/repair; then
-        echo "${PROJECT_NAME}-repair-database ${database_name}" >> /etc/cron.hourly/repair
-        # remove legacy stuff
-        sed -i 's|/usr/bin/repairdatabase redmatrix||g' /etc/cron.hourly/repair
-    fi
+		  if ! grep -q "${database_name}" /etc/cron.hourly/repair; then
+			  echo "${PROJECT_NAME}-repair-database ${database_name}" >> /etc/cron.hourly/repair
+			  # remove legacy stuff
+			  sed -i 's|/usr/bin/repairdatabase redmatrix||g' /etc/cron.hourly/repair
+		  fi
 }
 
 function install_not_on_BBB {
@@ -4450,7 +4463,6 @@ function install_command_line_browser {
     echo 'install_command_line_browser' >> $COMPLETION_FILE
 }
 
-
 function configure_email {
     if [[ $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
         return
@@ -7287,6 +7299,12 @@ function install_wiki {
         nginx_disable_sniffing $WIKI_DOMAIN_NAME
         echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
         echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
+        echo '    # webmail' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
+        echo '    location /webmail {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
+        echo '        rewrite ^/(.*) /webmail/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
+        echo '        rewrite ^/(.*) /webmail/installer/index.php last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
+        echo '    }' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
+        echo '' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
         echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
         echo '    location / {' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
         echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$WIKI_DOMAIN_NAME
@@ -8815,30 +8833,23 @@ function install_search_engine {
     echo 'install_search_engine' >> $COMPLETION_FILE
 }
 
-function install_hubzilla {
-    if [[ $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
-        return
-    fi
-    if [ ! $HUBZILLA_DOMAIN_NAME ]; then
+function install_webmail {
+    if [[ $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
         return
     fi
 
-    HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
+    WEBMAIL_PATH=/var/www/webmail
 
     # update to a new commit if needed
-    set_repo_commit $HUBZILLA_PATH "Hubzilla commit" "$HUBZILLA_COMMIT" $HUBZILLA_REPO
-    set_repo_commit $HUBZILLA_PATH "Hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT" $HUBZILLA_ADDONS_REPO
-    if [ -d $HUBZILLA_PATH/redmatrix-themes1 ]; then
-        cd $HUBZILLA_PATH/redmatrix-themes1
-        git stash
-        git pull
-        cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
-        chown -R www-data:www-data $HUBZILLA_PATH
-    fi
+    set_repo_commit $WEBMAIL_PATH "Webmail commit" "$WEBMAIL_COMMIT" $WEBMAIL_REPO
 
-    if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
+    if grep -Fxq "install_webmail" $COMPLETION_FILE; then
         return
     fi
+    if [ -d /etc/apache2 ]; then
+        rm -rf /etc/apache2
+        echo $'Removed Apache installation after Dokuwiki install'
+    fi
 
     install_mariadb
     get_mariadb_password
@@ -8847,199 +8858,285 @@ function install_hubzilla {
     apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
     apt-get -y install php5-dev imagemagick php5-imagick
 
-    if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
-        mkdir /var/www/$HUBZILLA_DOMAIN_NAME
-    fi
-    if [ ! -d $HUBZILLA_PATH ]; then
-        mkdir $HUBZILLA_PATH
-    fi
-
-    if [ ! -f $HUBZILLA_PATH/index.php ]; then
-        cd $INSTALL_DIR
-        git_clone $HUBZILLA_REPO hubzilla
-        git checkout $HUBZILLA_COMMIT -b $HUBZILLA_COMMIT
-        if ! grep -q "Hubzilla commit" $COMPLETION_FILE; then
-            echo "Hubzilla commit:$HUBZILLA_COMMIT" >> $COMPLETION_FILE
+    if [ ! -f $WEBMAIL_PATH/index.php ]; then
+        git_clone $WEBMAIL_REPO webmail
+        git checkout $WEBMAIL_COMMIT -b $WEBMAIL_COMMIT
+        if ! grep -q "Webmail commit" $COMPLETION_FILE; then
+            echo "Webmail commit:$WEBMAIL_COMMIT" >> $COMPLETION_FILE
         else
-            sed -i "s/Hubzilla commit.*/Hubzilla commit:$HUBZILLA_COMMIT/g" $COMPLETION_FILE
+            sed -i "s/Webmail commit.*/Webmail commit:$WEBMAIL_COMMIT/g" $COMPLETION_FILE
         fi
-
-        rm -rf $HUBZILLA_PATH
-        mv hubzilla $HUBZILLA_PATH
-
-        git_clone $HUBZILLA_ADDONS_REPO $HUBZILLA_PATH/addon
-        cd $HUBZILLA_PATH/addon
-        git checkout $HUBZILLA_ADDONS_COMMIT -b $HUBZILLA_ADDONS_COMMIT
-        if ! grep -q "Hubzilla addons commit" $COMPLETION_FILE; then
-            echo "Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT" >> $COMPLETION_FILE
-        else
-            sed -i "s/Hubzilla addons commit.*/Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT/g" $COMPLETION_FILE
-        fi
-
-        # some extra themes
-        git_clone $HUBZILLA_THEMES_REPO $HUBZILLA_PATH/redmatrix-themes1
-        cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
-
-        chown -R www-data:www-data $HUBZILLA_PATH
+        chown -R www-data:www-data $WEBMAIL_PATH
     fi
 
-    HUBZILLA_ONION_HOSTNAME=
+    WEBMAIL_ONION_HOSTNAME=
     if [[ $ONION_ONLY != "no" ]]; then
-        HUBZILLA_ONION_HOSTNAME=$(add_onion_service hubzilla 80 ${HUBZILLA_ONION_PORT})
-        echo "Hubzilla onion domain:${HUBZILLA_ONION_HOSTNAME}" >> $COMPLETION_FILE
+        WEBMAIL_ONION_HOSTNAME=$(add_onion_service webmail 80 ${WEBMAIL_ONION_PORT})
+        echo "Webmail onion domain:${WEBMAIL_ONION_HOSTNAME}" >> $COMPLETION_FILE
     fi
 
-    get_mariadb_hubzilla_admin_password
-    if [ ! $HUBZILLA_ADMIN_PASSWORD ]; then
+    get_mariadb_webmail_admin_password  
+    if [ ! $WEBMAIL_ADMIN_PASSWORD ]; then
         if [ -f $IMAGE_PASSWORD_FILE ]; then
-            HUBZILLA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
+            WEBMAIL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
         else
-            HUBZILLA_ADMIN_PASSWORD="$(openssl rand -base64 32 | cut -c1-30)"
+            WEBMAIL_ADMIN_PASSWORD="$(openssl rand -base64 32 | cut -c1-30)"
         fi
-        echo '' >> /home/$MY_USERNAME/README
-        echo '' >> /home/$MY_USERNAME/README
-        echo 'Hubzilla' >> /home/$MY_USERNAME/README
-        echo '========' >> /home/$MY_USERNAME/README
-        if [[ $ONION_ONLY == 'no' ]]; then
-            echo $"Open https://$HUBZILLA_DOMAIN_NAME and register a new user" >> /home/$MY_USERNAME/README
-        else
-            echo $"Open http://$HUBZILLA_ONION_HOSTNAME and register a new user" >> /home/$MY_USERNAME/README
-        fi
-        echo $"Your MariaDB Hubzilla admin password is: $HUBZILLA_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
-        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
-        chmod 600 /home/$MY_USERNAME/README
     fi
+    create_database webmail "$WEBMAIL_ADMIN_PASSWORD"
 
-    create_database hubzilla "$HUBZILLA_ADMIN_PASSWORD"
+	if [ ! -d /var/www/$DEFAULT_DOMAIN_NAME/htdocs ]; then
+		mkdir -p /var/www/$DEFAULT_DOMAIN_NAME/htdocs
+	fi	
+	ln -s $WEBMAIL_PATH /var/www/$DEFAULT_DOMAIN_NAME/htdocs/webmail
+	
+	if ! grep -q "Webmail" /home/$MY_USERNAME/README; then
+		echo '' >> /home/$MY_USERNAME/README
+		echo '' >> /home/$MY_USERNAME/README
+		echo 'Webmail' >> /home/$MY_USERNAME/README
+		echo '=======' >> /home/$MY_USERNAME/README
+		if [[ $ONION_ONLY == 'no' ]]; then
+			echo $"Open https://$DEFAULT_DOMAIN_NAME/webmail/installer/index.php" >> /home/$MY_USERNAME/README
+		else
+			echo $"Open http://$WEBMAIL_ONION_HOSTNAME/installer/index.php" >> /home/$MY_USERNAME/README
+		fi
+		echo $"Database Type: MySQL" >> /home/$MY_USERNAME/README
+		echo $"Database name: webmail" >> /home/$MY_USERNAME/README
+		echo $"Database user name: webmailadmin" >> /home/$MY_USERNAME/README
+		echo $"Database password: $WEBMAIL_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
+		echo $"Enable the Enigma PGP plugin" >> /home/$MY_USERNAME/README
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
+		chmod 600 /home/$MY_USERNAME/README
+	fi
+    
+	echo 'install_webmail' >> $COMPLETION_FILE
+}
 
-    if ! grep -q "$HUBZILLA_PATH" /etc/crontab; then
-        echo "12,22,32,42,52 * *   *   *   root cd $HUBZILLA_PATH; /usr/bin/timeout 500 /usr/bin/php include/poller.php" >> /etc/crontab
-    fi
+function install_hubzilla {
+	if [[ $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CHAT" || $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" || $SYSTEM_TYPE == "$VARIANT_MESH" ]]; then
+		return
+	fi
+	if [ ! $HUBZILLA_DOMAIN_NAME ]; then
+		return
+	fi
 
-    add_ddns_domain $HUBZILLA_DOMAIN_NAME
+	HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
 
-    if [[ $ONION_ONLY == "no" ]]; then
-        nginx_http_redirect $HUBZILLA_DOMAIN_NAME
-        echo 'server {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    server_name $HUBZILLA_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        nginx_limits $HUBZILLA_DOMAIN_NAME
-        nginx_ssl $HUBZILLA_DOMAIN_NAME
-        nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
-        echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-    else
-        echo 'server {' > /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    listen 127.0.0.1:${HUBZILLA_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    server_name $HUBZILLA_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        nginx_limits $HUBZILLA_DOMAIN_NAME
-        nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
-        echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
-        echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+	# update to a new commit if needed
+	set_repo_commit $HUBZILLA_PATH "Hubzilla commit" "$HUBZILLA_COMMIT" $HUBZILLA_REPO
+	set_repo_commit $HUBZILLA_PATH "Hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT" $HUBZILLA_ADDONS_REPO
+	if [ -d $HUBZILLA_PATH/redmatrix-themes1 ]; then
+		cd $HUBZILLA_PATH/redmatrix-themes1
+		git stash
+		git pull
+		cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
+		chown -R www-data:www-data $HUBZILLA_PATH
+	fi
+
+	if grep -Fxq "install_hubzilla" $COMPLETION_FILE; then
+		return
+	fi
+
+	install_mariadb
+	get_mariadb_password
+	repair_databases_script
+
+	apt-get -y install php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt git
+	apt-get -y install php5-dev imagemagick php5-imagick
+
+	if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
+		mkdir /var/www/$HUBZILLA_DOMAIN_NAME
+	fi
+	if [ ! -d $HUBZILLA_PATH ]; then
+		mkdir $HUBZILLA_PATH
+	fi
+
+	if [ ! -f $HUBZILLA_PATH/index.php ]; then
+		cd $INSTALL_DIR
+		git_clone $HUBZILLA_REPO hubzilla
+		git checkout $HUBZILLA_COMMIT -b $HUBZILLA_COMMIT
+		if ! grep -q "Hubzilla commit" $COMPLETION_FILE; then
+			echo "Hubzilla commit:$HUBZILLA_COMMIT" >> $COMPLETION_FILE
+		else
+			sed -i "s/Hubzilla commit.*/Hubzilla commit:$HUBZILLA_COMMIT/g" $COMPLETION_FILE
+		fi
+
+		rm -rf $HUBZILLA_PATH
+		mv hubzilla $HUBZILLA_PATH
+
+		git_clone $HUBZILLA_ADDONS_REPO $HUBZILLA_PATH/addon
+		cd $HUBZILLA_PATH/addon
+		git checkout $HUBZILLA_ADDONS_COMMIT -b $HUBZILLA_ADDONS_COMMIT
+		if ! grep -q "Hubzilla addons commit" $COMPLETION_FILE; then
+			echo "Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT" >> $COMPLETION_FILE
+		else
+			sed -i "s/Hubzilla addons commit.*/Hubzilla addons commit:$HUBZILLA_ADDONS_COMMIT/g" $COMPLETION_FILE
+		fi
+
+		# some extra themes
+		git_clone $HUBZILLA_THEMES_REPO $HUBZILLA_PATH/redmatrix-themes1
+		cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
+
+		chown -R www-data:www-data $HUBZILLA_PATH
+	fi
+
+	HUBZILLA_ONION_HOSTNAME=
+	if [[ $ONION_ONLY != "no" ]]; then
+		HUBZILLA_ONION_HOSTNAME=$(add_onion_service hubzilla 80 ${HUBZILLA_ONION_PORT})
+		echo "Hubzilla onion domain:${HUBZILLA_ONION_HOSTNAME}" >> $COMPLETION_FILE
+	fi
+
+	get_mariadb_hubzilla_admin_password
+	if [ ! $HUBZILLA_ADMIN_PASSWORD ]; then
+		if [ -f $IMAGE_PASSWORD_FILE ]; then
+			HUBZILLA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
+		else
+			HUBZILLA_ADMIN_PASSWORD="$(openssl rand -base64 32 | cut -c1-30)"
+		fi
+		echo '' >> /home/$MY_USERNAME/README
+		echo '' >> /home/$MY_USERNAME/README
+		echo 'Hubzilla' >> /home/$MY_USERNAME/README
+		echo '========' >> /home/$MY_USERNAME/README
+		if [[ $ONION_ONLY == 'no' ]]; then
+			echo $"Open https://$HUBZILLA_DOMAIN_NAME and register a new user" >> /home/$MY_USERNAME/README
+		else
+			echo $"Open http://$HUBZILLA_ONION_HOSTNAME and register a new user" >> /home/$MY_USERNAME/README
+		fi
+		echo $"Your MariaDB Hubzilla admin password is: $HUBZILLA_ADMIN_PASSWORD" >> /home/$MY_USERNAME/README
+		chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
+		chmod 600 /home/$MY_USERNAME/README
+	fi
+
+	create_database hubzilla "$HUBZILLA_ADMIN_PASSWORD"
+
+	if ! grep -q "$HUBZILLA_PATH" /etc/crontab; then
+		echo "12,22,32,42,52 * *   *   *   root cd $HUBZILLA_PATH; /usr/bin/timeout 500 /usr/bin/php include/poller.php" >> /etc/crontab
+	fi
+
+	add_ddns_domain $HUBZILLA_DOMAIN_NAME
+
+	if [[ $ONION_ONLY == "no" ]]; then
+		nginx_http_redirect $HUBZILLA_DOMAIN_NAME
+		echo 'server {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    server_name $HUBZILLA_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		nginx_limits $HUBZILLA_DOMAIN_NAME
+		nginx_ssl $HUBZILLA_DOMAIN_NAME
+		nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
+		echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # With php5-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+	else
+		echo 'server {' > /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    listen 127.0.0.1:${HUBZILLA_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    server_name $HUBZILLA_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    error_log /var/log/nginx/${HUBZILLA_DOMAIN_NAME}_error_ssl.log $WEBSERVER_LOG_LEVEL;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    access_log off;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		nginx_limits $HUBZILLA_DOMAIN_NAME
+		nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
+		echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "    # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        allow all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
+		echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
         echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
         echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
         echo '        # With php5-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
@@ -10530,6 +10627,7 @@ install_rss_reader
 install_rss_reader_gnusocial
 install_rss_mobile_reader
 install_hubzilla
+#install_webmail
 #install_search_engine
 install_dlna_server
 configure_firewall_for_dlna
diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel
index a749b6cb..0bcdc0cf 100755
--- a/src/freedombone-controlpanel
+++ b/src/freedombone-controlpanel
@@ -395,7 +395,15 @@ function show_domains {
             echo ''
         fi
     fi
-
+    if grep -q "Webmail onion domain" $COMPLETION_FILE; then
+        echo -n -e "$(pad_string 'Webmail')"
+        WEBMAILDOM='-'
+        echo -n -e "$(pad_string ${WEBMAILDOM})"
+        if [ -d /var/lib/tor/hidden_service_webmail ]; then
+            echo -n "$(cat /var/lib/tor/hidden_service_webmail/hostname)"
+        fi
+        echo ''
+    fi
     if grep -q "Search engine onion domain" $COMPLETION_FILE; then
         echo -n -e "$(pad_string 'Search engine')"
         SEARCHDOM='-'