1.1.0.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/bin/sh
  2. # Hestia Control Panel upgrade script for target version 1.1.0
  3. #######################################################################################
  4. ####### Place additional commands below. #######
  5. #######################################################################################
  6. # Set default theme
  7. if [ -z $THEME ]; then
  8. echo "(*) Enabling support for themes..."
  9. $BIN/v-change-sys-theme 'default'
  10. fi
  11. # Reduce SSH login grace time
  12. if [ -e /etc/ssh/sshd_config ]; then
  13. echo "(*) Hardening SSH daemon configuration..."
  14. sed -i "s/LoginGraceTime 2m/LoginGraceTime 1m/g" /etc/ssh/sshd_config
  15. sed -i "s/#LoginGraceTime 2m/LoginGraceTime 1m/g" /etc/ssh/sshd_config
  16. fi
  17. # Implement recidive jail for fail2ban
  18. if [ ! -z "$FIREWALL_EXTENSION" ]; then
  19. if ! cat /etc/fail2ban/jail.local | grep -q "\[recidive\]"; then
  20. echo -e "\n\n[recidive]\nenabled = true\nfilter = recidive\naction = hestia[name=HESTIA]\nlogpath = /var/log/fail2ban.log\nmaxretry = 3\nfindtime = 86400\nbantime = 864000" >> /etc/fail2ban/jail.local
  21. fi
  22. fi
  23. # Enable OCSP SSL stapling and harden nginx configuration for roundcube
  24. if [ ! -z "$IMAP_SYSTEM" ]; then
  25. echo "(*) Hardening security of Roundcube webmail..."
  26. $BIN/v-update-mail-templates > /dev/null 2>&1
  27. if [ -e /etc/nginx/conf.d/webmail.inc ]; then
  28. cp -f /etc/nginx/conf.d/webmail.inc $HESTIA_BACKUP/conf/
  29. sed -i "s/config|temp|logs/README.md|config|temp|logs|bin|SQL|INSTALL|LICENSE|CHANGELOG|UPGRADING/g" /etc/nginx/conf.d/webmail.inc
  30. fi
  31. fi
  32. # Fix restart queue
  33. if [ -z "$($BIN/v-list-cron-jobs admin | grep 'v-update-sys-queue restart')" ]; then
  34. command="sudo $BIN/v-update-sys-queue restart"
  35. $BIN/v-add-cron-job 'admin' '*/2' '*' '*' '*' '*' "$command"
  36. fi
  37. # Remove deprecated line from ClamAV configuration file
  38. if [ -e "/etc/clamav/clamd.conf" ]; then
  39. clamd_conf_update_check=$(grep DetectBrokenExecutables /etc/clamav/clamd.conf)
  40. if [ ! -z "$clamd_conf_update_check" ]; then
  41. echo "(*) Updating ClamAV configuration..."
  42. sed -i '/DetectBrokenExecutables/d' /etc/clamav/clamd.conf
  43. fi
  44. fi
  45. # Remove errornous history.log file created by certain builds due to bug in v-restart-system
  46. if [ -e $HESTIA/data/users/history.log ]; then
  47. rm -f $HESTIA/data/users/history.log
  48. fi
  49. # Use exim4 server hostname instead of mail domain and remove hardcoded mail prefix
  50. if [ ! -z "$MAIL_SYSTEM" ]; then
  51. echo "(*) Updating exim configuration..."
  52. if cat /etc/exim4/exim4.conf.template | grep -q 'helo_data = mail.${sender_address_domain}'; then
  53. sed -i 's/helo_data = mail.${sender_address_domain}/helo_data = ${primary_hostname}/g' /etc/exim4/exim4.conf.template
  54. fi
  55. if ! grep -q '^OUTGOING_IP = /' /etc/exim4/exim4.conf.template; then
  56. sed -i '/^OUTGOING_IP/d' /etc/exim4/exim4.conf.template
  57. sed -i 's|^begin acl|OUTGOING_IP = /etc/exim4/domains/$sender_address_domain/ip\nbegin acl|' /etc/exim4/exim4.conf.template
  58. fi
  59. if ! grep -q 'interface =' /etc/exim4/exim4.conf.template; then
  60. sed -i '/interface =/d' /etc/exim4/exim4.conf.template
  61. sed -i 's|dkim_strict = 0|dkim_strict = 0\n interface = ${if exists{OUTGOING_IP}{${readfile{OUTGOING_IP}}}}|' /etc/exim4/exim4.conf.template
  62. fi
  63. fi
  64. # Members of admin group should be permitted to enter admin folder
  65. if [ -d /home/admin ]; then
  66. setfacl -m "g:admin:r-x" /home/admin
  67. fi
  68. # Fix sftp jail cronjob
  69. if [ -e "/etc/cron.d/hestia-sftp" ]; then
  70. if ! cat /etc/cron.d/hestia-sftp | grep -q 'root'; then
  71. echo "@reboot root /usr/local/hestia/bin/v-add-sys-sftp-jail" > /etc/cron.d/hestia-sftp
  72. fi
  73. fi
  74. # Create default writeable folders for all users
  75. echo "(*) Updating default writable folders for all users..."
  76. for user in $($HESTIA/bin/v-list-sys-users plain); do
  77. mkdir -p \
  78. $HOMEDIR/$user/.cache \
  79. $HOMEDIR/$user/.config \
  80. $HOMEDIR/$user/.local \
  81. $HOMEDIR/$user/.composer \
  82. $HOMEDIR/$user/.ssh
  83. chown $user:$user \
  84. $HOMEDIR/$user/.cache \
  85. $HOMEDIR/$user/.config \
  86. $HOMEDIR/$user/.local \
  87. $HOMEDIR/$user/.composer \
  88. $HOMEDIR/$user/.ssh
  89. done
  90. # Remove redundant fail2ban jail
  91. if fail2ban-client status sshd > /dev/null 2>&1 ; then
  92. fail2ban-client stop sshd >/dev/null 2>&1
  93. if [ -f /etc/fail2ban/jail.d/defaults-debian.conf ]; then
  94. mkdir -p $HESTIA_BACKUP/conf/fail2ban/jail.d
  95. mv /etc/fail2ban/jail.d/defaults-debian.conf $HESTIA_BACKUP/conf/fail2ban/jail.d/
  96. fi
  97. fi
  98. # Update Office 365/Microsoft 365 DNS template
  99. if [ -e "$HESTIA/data/templates/dns/office365.tpl" ]; then
  100. echo "(*) Updating DNS template for Office 365..."
  101. cp -f $HESTIA/install/deb/templates/dns/office365.tpl $HESTIA/data/templates/dns/office365.tpl
  102. fi
  103. # Ensure that backup compression level is correctly set
  104. GZIP_LVL_CHECK=$(cat $HESTIA/conf/hestia.conf | grep BACKUP_GZIP)
  105. if [ -z "$GZIP_LVL_CHECK" ]; then
  106. echo "(*) Updating backup compression level variable..."
  107. $BIN/v-change-sys-config-value "BACKUP_GZIP" '9'
  108. fi
  109. # Randomize Roundcube des_key for better security
  110. if [ -f "/etc/roundcube/config.inc.php" ]; then
  111. rcDesKey="$(openssl rand -base64 30 | tr -d "/" | cut -c1-24)"
  112. sed -i "s/vtIOjLZo9kffJoqzpSbm5r1r/$rcDesKey/g" /etc/roundcube/config.inc.php
  113. fi
  114. # Place robots.txt to prevent webmail crawling by search engine bots.
  115. if [ -e "/var/lib/roundcube/" ]; then
  116. if [ ! -f "/var/lib/roundcube/robots.txt" ]; then
  117. echo "User-agent: *" > /var/lib/roundcube/robots.txt
  118. echo "Disallow: /" >> /var/lib/roundcube/robots.txt
  119. fi
  120. fi
  121. # Installing postgresql repo
  122. if [ -e "/etc/postgresql" ]; then
  123. echo "(*) Enabling native PostgreSQL APT repository..."
  124. osname="$(cat /etc/os-release | grep "^ID\=" | sed "s/ID\=//g")"
  125. if [ "$osname" = "ubuntu" ]; then
  126. codename="$(lsb_release -s -c)"
  127. else
  128. codename="$(cat /etc/os-release |grep VERSION= |cut -f 2 -d \(|cut -f 1 -d \))"
  129. fi
  130. echo "deb http://apt.postgresql.org/pub/repos/apt/ $codename-pgdg main" > /etc/apt/sources.list.d/postgresql.list
  131. wget --quiet https://www.postgresql.org/media/keys/ACCC4CF8.asc -O /tmp/psql_signing.key
  132. APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key add /tmp/psql_signing.key > /dev/null 2>&1
  133. rm /tmp/psql_signing.key
  134. fi
  135. # Hardening MySQL configuration, prevent local infile.
  136. if [ -e "/etc/mysql/my.cnf" ]; then
  137. mysql_local_infile_check=$(grep local-infile /etc/mysql/my.cnf)
  138. if [ -z "$mysql_local_infile_check" ]; then
  139. echo "(*) Hardening MySQL configuration..."
  140. sed -i '/symbolic-links\=0/a\local-infile=0' /etc/mysql/my.cnf
  141. fi
  142. fi
  143. # Hardening nginx configuration, drop TLSv1.1 support.
  144. if [ -e "/etc/nginx/nginx.conf" ]; then
  145. nginx_tls_check=$(grep TLSv1.1 /etc/nginx/nginx.conf)
  146. if [ ! -z "$nginx_tls_check" ]; then
  147. echo "(*) Updating nginx security settings - disabling TLS v1.1..."
  148. sed -i 's/TLSv1.1 //g' /etc/nginx/nginx.conf
  149. fi
  150. fi
  151. # Fix logrotate permission bug for nginx
  152. if [ -e "/etc/logrotate/nginx" ]; then
  153. sed -i "s/create 640 nginx adm/create 640/g" /etc/logrotate.d/nginx
  154. fi
  155. # Fix logrotate permission bug for apache
  156. if [ -e "/etc/logrotate/apache2" ]; then
  157. sed -i "s/create 640 root adm/create 640/g" /etc/logrotate.d/apache2
  158. fi
  159. # Repair messed up user log permissions from the logrotate bug. Ignoring errors
  160. for user in $($HESTIA/bin/v-list-users plain | cut -f1); do
  161. for domain in $($HESTIA/bin/v-list-web-domains $user plain | cut -f1); do
  162. chown root:$user /var/log/$WEB_SYSTEM/domains/$domain.* > /dev/null 2>&1
  163. for sub_domain in $($HESTIA/bin/v-list-web-domain $user $domain plain | cut -f7 | tr ',' '\n'); do
  164. chown root:$user /var/log/$WEB_SYSTEM/domains/$sub_domain.* > /dev/null 2>&1
  165. done
  166. done
  167. done
  168. chown root:root /var/log/$WEB_SYSTEM/domains/$WEBMAIL_ALIAS* > /dev/null 2>&1
  169. # Enable IMAP/POP3 quota information
  170. if [ "$IMAP_SYSTEM" = "dovecot" ]; then
  171. echo "(*) Enabling IMAP quota information reporting..."
  172. if [ -e /etc/dovecot/conf.d/20-pop3.conf ]; then
  173. cp -f $HESTIA/install/deb/dovecot/conf.d/20-pop3.conf /etc/dovecot/conf.d/20-pop3.conf
  174. fi
  175. if [ -e /etc/dovecot/conf.d/20-imap.conf ]; then
  176. cp -f $HESTIA/install/deb/dovecot/conf.d/20-imap.conf /etc/dovecot/conf.d/20-imap.conf
  177. fi
  178. if [ -e /etc/dovecot/conf.d/90-quota.conf ]; then
  179. cp -f $HESTIA/install/deb/dovecot/conf.d/90-quota.conf /etc/dovecot/conf.d/90-quota.conf
  180. fi
  181. fi
  182. # Trigger multiphp legacy migration script
  183. num_php_versions=$(ls -d /etc/php/*/fpm/pool.d 2>/dev/null |wc -l)
  184. if [ "$num_php_versions" -gt 1 ] && [ -z "$WEB_BACKEND" ]; then
  185. echo "(*) Enabling modular Multi-PHP backend..."
  186. cp -rf $HESTIA/data/templates/web $HESTIA_BACKUP/templates/web
  187. bash $HESTIA/install/upgrade/manual/migrate_multiphp.sh > /dev/null 2>&1
  188. fi
  189. # Disable global subfolder alias for webmail in favor of subdomain
  190. if [ -e /etc/nginx/conf.d/webmail.inc ]; then
  191. rm -f /etc/nginx/conf.d/webmail.inc
  192. fi
  193. if [ -e /etc/apache2/conf.d/roundcube.conf ]; then
  194. rm -f /etc/apache2/conf.d/roundcube.conf
  195. fi