@@ -6,25 +6,47 @@ function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1
66# Set new version number
77NEW_VERSION=" 1.0.1"
88
9- # Set phpMyAdmin version for upgrade
10- pma_v=' 4.9.0.1'
119
12- # Set backup folder
13- HESTIA_BACKUP=" /root/hst_upgrade/$( date +%d%m%Y%H%M) "
14-
15- # Set installation source folder
16- hestiacp=" $HESTIA /install/deb"
1710
1811# Load hestia.conf
1912source /usr/local/hestia/conf/hestia.conf
2013
21- # ###### Place additional commands below. #######
14+ # #######################################################################################################
15+ # ###### Place additional commands below. #######
16+ # #######################################################################################################
2217
23- # Back up old template files and install the latest versions
24- if [ -d $HESTIA /data/templates/ ]; then
25- echo " (*) Updating and rebuild web templates..."
26- cp -rf $HESTIA /data/templates $HESTIA_BACKUP /templates/
27- $HESTIA /bin/v-update-web-templates
18+ # Add amd64 to repositories to prevent notifications - https://goo.gl/hmsSV7
19+ if ! grep -q ' arch=amd64' /etc/apt/sources.list.d/nginx.list; then
20+ sed -i s/" deb " /" deb [arch=amd64] " /g /etc/apt/sources.list.d/nginx.list
21+ fi
22+ if ! grep -q ' arch=amd64' /etc/apt/sources.list.d/mariadb.list; then
23+ sed -i s/" deb " /" deb [arch=amd64] " /g /etc/apt/sources.list.d/mariadb.list
24+ fi
25+
26+ # Add a general group for normal users created by Hestia
27+ echo " (*) Verifying ACLs and hardening user permissions..."
28+ if [ -z " $( grep ^hestia-users: /etc/group) " ]; then
29+ groupadd --system " hestia-users"
30+ fi
31+
32+ # Make sure non-admin users belong to correct Hestia group
33+ for user in ` ls /usr/local/hestia/data/users/` ; do
34+ if [ " $user " != " admin" ]; then
35+ usermod -a -G " hestia-users" " $user "
36+ setfacl -m " u:$user :r-x" " $HOMEDIR /$user "
37+
38+ # Update FTP users groups membership
39+ uid=$( id -u $user )
40+ for ftp_user in $( cat /etc/passwd | grep -v " ^$user :" | grep " ^$user .*:$uid :$uid :" | cut -d " :" -f1) ; do
41+ usermod -a -G " hestia-users" " $ftp_user "
42+ done
43+ fi
44+ setfacl -m " g:hestia-users:---" " $HOMEDIR /$user "
45+ done
46+
47+ # Fix named rule for AppArmor - https://goo.gl/SPqHdq
48+ if [ " $DNS_SYSTEM " = ' bind9' ] && [ ! -f /etc/apparmor.d/local/usr.sbin.named ]; then
49+ echo " /home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2> /dev/null
2850fi
2951
3052# Update Apache and Nginx configuration to support new file structure
@@ -62,10 +84,250 @@ if [ ! -e /etc/ssl/dhparam.pem ]; then
6284 sed -i " /add_header X-Frame-Options SAMEORIGIN;/d" /etc/nginx/nginx.conf
6385 sed -i " /add_header X-Content-Type-Options nosniff;/d" /etc/nginx/nginx.conf
6486 fi
87+ fi
88+
89+ # Back up old template files and install the latest versions
90+ if [ -d $HESTIA /data/templates/ ]; then
91+ echo " (*) Updating default templates and packages..."
92+ cp -rf $HESTIA /data/templates $HESTIA_BACKUP /templates/
93+ $HESTIA /bin/v-update-web-templates
94+ $HESTIA /bin/v-update-dns-templates
95+ $HESTIA /bin/v-update-mail-templates
96+ fi
97+
98+ # Back up default package and install latest version
99+ if [ -d $HESTIA /data/packages/ ]; then
100+ cp -f $HESTIA /data/packages/default.pkg $HESTIA_BACKUP /packages/
101+ fi
102+
103+ # Remove old Office 365 template as there is a newer version with an updated name
104+ if [ -f $HESTIA /data/templates/dns/o365.tpl ]; then
105+ rm -f $HESTIA /data/templates/dns/o365.tpl
106+ fi
107+
108+ # Back up and remove default index.html if it exists
109+ if [ -f /var/www/html/index.html ]; then
110+ mv /var/www/html/index.html $HESTIA_BACKUP /templates/
111+ fi
112+
113+ # Configure default success page and set permissions on CSS, JavaScript, and Font dependencies for unassigned hosts
114+ if [ ! -d /var/www/html ]; then
115+ mkdir -p /var/www/html/
116+ fi
117+
118+ if [ ! -d /var/www/document_errors/ ]; then
119+ mkdir -p /var/www/document_errors/
120+ fi
121+
122+ cp -rf $HESTIA /install/deb/templates/web/unassigned/* /var/www/html/
123+ cp -rf $HESTIA /install/deb/templates/web/skel/document_errors/* /var/www/document_errors/
124+ chmod 644 /var/www/html/*
125+ chmod 644 /var/www/document_errors/*
126+
127+ # Remove old default asset files from existing domains based on checksum
128+ for user in ` ls /usr/local/hestia/data/users/` ; do
129+ USER_DATA=$HESTIA /data/users/$user
130+ for domain in $( $BIN /v-list-web-domains $user plain | cut -f 1) ; do
131+ WEBFOLDER=" /home/$user /web/$domain /public_html"
132+ folderchecksum=$( find " $WEBFOLDER /css" " $WEBFOLDER /js" " $WEBFOLDER /webfonts" -type f -print0 2> /dev/null | sort -z | xargs -r0 cat | md5sum | cut -d" " -f1)
133+ if [ " $folderchecksum " = " 926feacc51384fe13598631f9d1360c3" ]; then
134+ echo " (*) Removing old default asset files from: $domain ..."
135+ rm -rf " $WEBFOLDER /css" " $WEBFOLDER /js" " $WEBFOLDER /webfonts"
136+ fi
137+ unset folderchecksum
138+ unset WEBFOLDER
139+ done
140+ done
141+ folderchecksum=$( find /var/www/html/css /var/www/html/js /var/www/html/webfonts -type f -print0 2> /dev/null | sort -z | xargs -r0 cat | md5sum | cut -d" " -f1)
142+ if [ " $folderchecksum " = " d148d5173e5e4162d7af0a60585392cb" ]; then
143+ rm -rf /var/www/html/css /var/www/html/js /var/www/html/webfonts
144+ fi
145+ unset folderchecksum
146+
147+ # Correct permissions for DNS server cache
148+ if [ -d " /var/cache/bind" ]; then
149+ chown bind:bind /var/cache/bind
150+ fi
151+
152+ # Add unassigned hosts configuration to Nginx and Apache
153+ for ipaddr in $( ls /usr/local/hestia/data/ips/ 2> /dev/null) ; do
154+
155+ web_conf=" /etc/$WEB_SYSTEM /conf.d/$ipaddr .conf"
156+ rm -f $web_conf
157+
158+ if [ " $WEB_SYSTEM " = " apache2" ]; then
159+ echo " (*) Adding unassigned hosts configuration to Apache..."
160+ if [ -z " $( /usr/sbin/apache2 -v | grep Apache/2.4) " ]; then
161+ echo " NameVirtualHost $ipaddr :$WEB_PORT " > $web_conf
162+ fi
163+ echo " Listen $ipaddr :$WEB_PORT " >> $web_conf
164+ cat $HESTIA /install/deb/apache2/unassigned.conf >> $web_conf
165+ sed -i ' s/directIP/' $ipaddr ' /g' $web_conf
166+ sed -i ' s/directPORT/' $WEB_PORT ' /g' $web_conf
167+
168+ if [ " $WEB_SSL " = ' mod_ssl' ]; then
169+ if [ -z " $( /usr/sbin/apache2 -v | grep Apache/2.4) " ]; then
170+ sed -i " 1s/^/NameVirtualHost $ipaddr :$WEB_SSL_PORT \n/" $web_conf
171+ fi
172+ sed -i " 1s/^/Listen $ipaddr :$WEB_SSL_PORT \n/" $web_conf
173+ sed -i ' s/directSSLPORT/' $WEB_SSL_PORT ' /g' $web_conf
174+ fi
175+
176+ elif [ " $WEB_SYSTEM " = " nginx" ]; then
177+ cp -f $HESTIA /install/deb/nginx/unassigned.inc $web_conf
178+ sed -i ' s/directIP/' $ipaddr ' /g' $web_conf
179+ fi
65180
66- # Restart Nginx service
67- systemctl restart nginx > /dev/null 2>&1
181+ if [ " $PROXY_SYSTEM " = " nginx" ]; then
182+ echo " (*) Adding unassigned hosts configuration to Nginx..."
183+ cat $WEBTPL /$PROXY_SYSTEM /proxy_ip.tpl | \
184+ sed -e " s/%ip%/$ipaddr /g" \
185+ -e " s/%web_port%/$WEB_PORT /g" \
186+ -e " s/%proxy_port%/$PROXY_PORT /g" \
187+ > /etc/$PROXY_SYSTEM /conf.d/$ipaddr .conf
188+ fi
189+ done
190+
191+ # Cleanup php session files not changed in the last 7 days (60*24*7 minutes)
192+ if [ ! -f /etc/cron.daily/php-session-cleanup ]; then
193+ echo " (*) Configuring PHP session cleanup..."
194+ echo ' #!/bin/sh' > /etc/cron.daily/php-session-cleanup
195+ echo " find -O3 /home/*/tmp/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
196+ echo " find -O3 $HESTIA /data/sessions/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
68197fi
198+ chmod 755 /etc/cron.daily/php-session-cleanup
69199
200+ # Fix empty pool error message for MultiPHP
201+ php_versions=$( ls /etc/php/* /fpm -d 2> /dev/null | wc -l)
202+ if [ " $php_versions " -gt 1 ]; then
203+ for v in $( ls /etc/php/) ; do
204+ if [ ! -d " /etc/php/$v /fpm/pool.d/" ]; then
205+ continue
206+ fi
207+ echo " (*) Updating Multi-PHP configuration..."
208+ cp -f $hestiacp /php-fpm/dummy.conf /etc/php/$v /fpm/pool.d/
209+ v1=$( echo " $v " | sed -e ' s/[.]//' )
210+ sed -i " s/9999/99$v1 /g" /etc/php/$v /fpm/pool.d/dummy.conf
211+ done
212+ fi
70213
214+ # Remove obsolete firewall ports.conf file if it exists
215+ if [ -f /usr/local/hestia/data/firewall/ports.conf ]; then
216+ rm -f /usr/local/hestia/data/firewall/ports.conf
217+ fi
218+
219+ # Move ClamAV daemon settings page to correct location if necessary
220+ if [ ! -d /usr/local/hestia/web/edit/server/clamav-daemon ]; then
221+ mv /usr/local/hestia/web/edit/server/clamd /usr/local/web/edit/server/clamav-daemon
222+ fi
223+
224+ # Remove old OS-specific installation files if they exist to free up space
225+ if [ -d $HESTIA /install/ubuntu ]; then
226+ echo " (*) Removing old Hestia Control Panel installation files for Ubuntu..."
227+ rm -rf $HESTIA /install/ubuntu
228+ fi
229+ if [ -d $HESTIA /install/debian ]; then
230+ echo " (*) Removing old Hestia Control Panel installation files for Debian..."
231+ rm -rf $HESTIA /install/debian
232+ fi
233+
234+ # Update Dovecot configuration to support per-domain SSL
235+ echo " (*) Updating Dovecot IMAP/POP server configuration..."
236+ if [ -f /etc/dovecot/conf.d/15-mailboxes.conf ]; then
237+ mv /etc/dovecot/conf.d/15-mailboxes.conf $HESTIA_BACKUP /conf/
238+ fi
239+ if [ -f /etc/dovecot/dovecot.conf ]; then
240+ # Update Dovecot configuration and restart Dovecot service
241+ mv /etc/dovecot/dovecot.conf $HESTIA_BACKUP /conf/
242+ cp -f $HESTIA /install/deb/dovecot/dovecot.conf /etc/dovecot/dovecot.conf
243+ systemctl restart dovecot
244+ sleep 0.5
245+ fi
246+
247+ # Update Exim SMTP configuration to support per-domain SSL
248+ if [ -f /etc/exim4/exim4.conf.template ]; then
249+ echo " (*) Updating Exim SMTP server configuration..."
250+ mv /etc/exim4/exim4.conf.template $HESTIA_BACKUP /conf/
251+ cp -f $HESTIA /install/deb/exim/exim4.conf.template /etc/exim4/exim4.conf.template
252+ # Reconfigure spam filter and virus scanning
253+ if [ ! -z " $ANTISPAM_SYSTEM " ]; then
254+ sed -i " s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
255+ sed -i " s/#SPAM_SCORE/SPAM_SCORE/g" /etc/exim4/exim4.conf.template
256+ fi
257+ if [ ! -z " $ANTIVIRUS_SYSTEM " ]; then
258+ sed -i " s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
259+ fi
260+ fi
71261
262+ # Add IMAP system variable to configuration if Dovecot is installed
263+ if [ -z " $IMAP_SYSTEM " ]; then
264+ if [ -f /usr/bin/dovecot ]; then
265+ echo " (*) Adding missing IMAP_SYSTEM variable to hestia.conf..."
266+ echo " IMAP_SYSTEM = 'dovecot'" >> $HESTIA /conf/hestia.conf
267+ fi
268+ fi
269+
270+ # Add webmail alias variable to system configuration if non-existent
271+ imap_check=$( cat $HESTIA /conf/hestia.conf | grep IMAP_SYSTEM)
272+ if [ ! -z " $imap_check " ]; then
273+ WEBMAIL_ALIAS_CHECK=$( cat $HESTIA /conf/hestia.conf | grep WEBMAIL_ALIAS)
274+ if [ -z " $WEBMAIL_ALIAS_CHECK " ]; then
275+ echo " (*) Adding global webmail alias to system configuration..."
276+ sed -i " /WEBMAIL_ALIAS/d" $HESTIA /conf/hestia.conf
277+ echo " WEBMAIL_ALIAS='webmail'" >> $HESTIA /conf/hestia.conf
278+ fi
279+ fi
280+
281+ # Set Purge to false in Roundcube configuration - https://goo.gl/3Nja3u
282+ echo " (*) Updating Roundcube configuration..."
283+ if [ -f /etc/roundcube/config.inc.php ]; then
284+ sed -i " s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/config.inc.php
285+ fi
286+ if [ -f /etc/roundcube/defaults.inc.php ]; then
287+ sed -i " s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/defaults.inc.php
288+ fi
289+ if [ -f /etc/roundcube/main.inc.php ]; then
290+ sed -i " s/\['flag_for_deletion'] = 'Purge';/\['flag_for_deletion'] = false;/gI" /etc/roundcube/main.inc.php
291+ fi
292+ if [ -d " /etc/roundcube" ]; then
293+ chmod 640 /etc/roundcube/debian-db*
294+ chown root:www-data /etc/roundcube/debian-db*
295+ fi
296+
297+ # Remove Webalizer and set AWStats as default
298+ WEBALIAZER_CHECK=$( cat $HESTIA /conf/hestia.conf | grep webalizer)
299+ if [ ! -z " $WEBALIZER_CHECK " ]; then
300+ echo " (*) Removing Webalizer and setting AWStats as default web statistics backend..."
301+ apt purge webalizer -y > /dev/null 2>&1
302+ sed -i " s/STATS_SYSTEM='webalizer,awstats'/STATS_SYSTEM='awstats'/g" $HESTIA /conf/hestia.conf
303+ fi
304+
305+ # Enable SFTP chroot jail capabilities
306+ $HESTIA /bin/v-add-sys-sftp-jail no
307+
308+ # Enable SFTP subsystem for SSH
309+ sftp_subsys_enabled=$( grep -iE " ^#?.*subsystem.+(sftp )?sftp-server" /etc/ssh/sshd_config)
310+ if [ ! -z " $sftp_subsys_enabled " ]; then
311+ echo " (*) Updating SFTP subsystem configuration..."
312+ sed -i -E " s/^#?.*Subsystem.+(sftp )?sftp-server/Subsystem sftp internal-sftp/g" /etc/ssh/sshd_config
313+ fi
314+
315+ # Remove and migrate obsolete object keys
316+ for user in ` ls /usr/local/hestia/data/users/` ; do
317+ USER_DATA=$HESTIA /data/users/$user
318+
319+ # Web keys
320+ for domain in $( $BIN /v-list-web-domains $user plain | cut -f 1) ; do
321+ obskey=$( get_object_value ' web' ' DOMAIN' " $domain " ' $FORCESSL' )
322+ if [ ! -z " $obskey " ]; then
323+ echo " (*) Updating HTTP-to-HTTPS redirect configuration for $domain ..."
324+ update_object_value ' web' ' DOMAIN' " $domain " ' $FORCESSL' ' '
325+
326+ # copy value under new key name
327+ add_object_key " web" ' DOMAIN' " $domain " ' SSL_FORCE' ' SSL_HOME'
328+ update_object_value ' web' ' DOMAIN' " $domain " ' $SSL_FORCE' " $obskey "
329+ fi
330+ unset FORCESSL
331+ done
332+ sed -i " s/\sFORCESSL=''//g" $USER_DATA /web.conf
333+ done
0 commit comments