Skip to content

Commit 81f365e

Browse files
authored
Merge pull request hestiacp#2220 from jaapmarcus/fix/2139-http-auth
Fix hestiacp#1239 basic auth not working
2 parents ec32653 + 1dfcb35 commit 81f365e

File tree

3 files changed

+57
-36
lines changed

3 files changed

+57
-36
lines changed

bin/v-add-web-domain-httpauth

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ source $HESTIA/func/domain.sh
3030
source_conf "$HESTIA/conf/hestia.conf"
3131

3232
# Defining htpasswd file
33-
htaccess="$HOMEDIR/$user/conf/web/$domain/htaccess"
3433
htpasswd="$HOMEDIR/$user/conf/web/$domain/htpasswd"
35-
shtaccess="$htaccess"
36-
shtpasswd="$htpasswd"
3734
docroot="$HOMEDIR/$user/web/$domain/public_html"
3835

3936
# Perform verification if read-only mode is enabled
@@ -63,41 +60,47 @@ fi
6360
# Action #
6461
#----------------------------------------------------------#
6562

63+
6664
# Adding htaccess password protection
67-
if [ ! -e "$htaccess" ]; then
68-
if [ "$WEB_SYSTEM" != 'nginx' ]; then
69-
echo "<Directory $docroot>" > $htaccess
70-
echo " AuthUserFile $htpasswd" >> $htaccess
71-
echo " AuthName \"$domain access\"" >> $htaccess
72-
echo " AuthType Basic" >> $htaccess
73-
echo " Require valid-user" >> $htaccess
74-
echo "</Directory>" >> $htaccess
65+
if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
66+
htaccess="$HOMEDIR/$user/conf/web/$domain/nginx.conf_htaccess"
67+
shtaccess="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_htaccess"
68+
if [ ! -f "$htaccess" ]; then
69+
echo "auth_basic \"$domain password access\";" > $htaccess
70+
echo "auth_basic_user_file $htpasswd;" >> $htaccess
71+
ln -s $htaccess $shtaccess
72+
restart_required='yes'
73+
fi
7574
else
76-
echo "auth_basic \"$domain password access\";" > $htaccess
77-
echo "auth_basic_user_file $htpasswd;" >> $htaccess
75+
htaccess="$HOMEDIR/$user/conf/web/$domain/apache2.conf_htaccess"
76+
shtaccess="$HOMEDIR/$user/conf/web/$domain/apache2.ssl.conf_htaccess"
77+
if [ ! -f "$htaccess" ]; then
78+
echo "<Directory $docroot>" > $htaccess
79+
echo " AuthUserFile $htpasswd" >> $htaccess
80+
echo " AuthName \"$domain access\"" >> $htaccess
81+
echo " AuthType Basic" >> $htaccess
82+
echo " Require valid-user" >> $htaccess
83+
echo "</Directory>" >> $htaccess
84+
ln -s $htaccess $shtaccess
85+
restart_required='yes'
86+
fi
7887
fi
79-
restart_required='yes'
80-
fi
88+
8189

8290
# Adding httpasswd user
8391
auth_hash=$($BIN/v-generate-password-hash htpasswd htpasswd $password)
8492
touch $htpasswd
85-
chmod 640 $htpasswd $htaccess
93+
chmod 644 $htpasswd $htaccess
8694
chgrp $user $htpasswd $htaccess
8795
sed -i "/^$auth_user:/d" $htpasswd
8896
echo "$auth_user:$auth_hash" >> $htpasswd
8997

90-
# Symbolic link for secure web templates
91-
if [ ! -L "$shtpasswd" ]; then
92-
ln -s $htpasswd $shtpasswd
93-
fi
94-
if [ ! -L "$shtaccess" ]; then
95-
ln -s $htaccess $shtaccess
96-
fi
97-
9898
# Restarting web server
9999
if [ "$restart" != 'no' ] && [ "$restart_required" = 'yes' ]; then
100100
$BIN/v-restart-web
101+
if [ -n "$PROXY_SYSTEM" ]; then
102+
$BIN/v-restart-proxy
103+
fi
101104
fi
102105

103106
#----------------------------------------------------------#

bin/v-delete-web-domain-httpauth

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ source $HESTIA/func/domain.sh
2828
# load config file
2929
source_conf "$HESTIA/conf/hestia.conf"
3030

31-
# Defining htpasswd file
32-
htaccess="$HOMEDIR/$user/conf/web/$domain/htaccess"
33-
htpasswd="$HOMEDIR/$user/conf/web/$domain/htpasswd"
34-
3531
#----------------------------------------------------------#
3632
# Verifications #
3733
#----------------------------------------------------------#
@@ -57,18 +53,29 @@ check_hestia_demo_mode
5753
# Action #
5854
#----------------------------------------------------------#
5955

56+
htpasswd="$HOMEDIR/$user/conf/web/$domain/htpasswd"
6057
# Deleting auth user
6158
sed -i "/^$auth_user:/d" $htpasswd
6259

6360
# Deleting password protection
6461
if [ "$(echo "$AUTH_USER" |tr : '\n' |wc -l)" -le 1 ]; then
65-
rm -f $htaccess $htpasswd $shtaccess $shtpasswd
62+
if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
63+
htaccess="$HOMEDIR/$user/conf/web/$domain/nginx.conf_htaccess"
64+
shtaccess="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_htaccess"
65+
else
66+
htaccess="$HOMEDIR/$user/conf/web/$domain/apache2.conf_htaccess"
67+
shtaccess="$HOMEDIR/$user/conf/web/$domain/apache2.ssl.conf_htaccess"
68+
fi
69+
rm -f $htaccess $htpasswd $shtaccess
6670
restart_required='yes'
6771
fi
6872

6973
# Restarting web server
7074
if [ "$restart" != 'no' ] && [ "$restart_required" = 'yes' ]; then
7175
$BIN/v-restart-web
76+
if [ -n "$PROXY_SYSTEM" ]; then
77+
$BIN/v-restart-proxy
78+
fi
7279
fi
7380

7481

func/rebuild.sh

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,21 +413,32 @@ rebuild_web_domain_conf() {
413413
sed -i "/^$auth_user:/d" $htpasswd
414414
echo "$auth_user:$auth_hash" >> $htpasswd
415415

416-
# Checking web server include
417-
if [ ! -e "$htaccess" ]; then
418-
if [ "$WEB_SYSTEM" != 'nginx' ]; then
416+
# Adding htaccess password protection
417+
if [ "$WEB_SYSTEM" = "nginx" ] || [ "$PROXY_SYSTEM" = "nginx" ]; then
418+
htaccess="$HOMEDIR/$user/conf/web/$domain/nginx.conf_htaccess"
419+
shtaccess="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_htaccess"
420+
if [ ! -f "$htaccess" ]; then
421+
echo "auth_basic \"$domain password access\";" > $htaccess
422+
echo "auth_basic_user_file $htpasswd;" >> $htaccess
423+
ln -s $htaccess $shtaccess
424+
restart_required='yes'
425+
fi
426+
else
427+
htaccess="$HOMEDIR/$user/conf/web/$domain/apache2.conf_htaccess"
428+
shtaccess="$HOMEDIR/$user/conf/web/$domain/apache2.ssl.conf_htaccess"
429+
if [ ! -f "$htaccess" ]; then
419430
echo "<Directory $docroot>" > $htaccess
420431
echo " AuthUserFile $htpasswd" >> $htaccess
421432
echo " AuthName \"$domain access\"" >> $htaccess
422433
echo " AuthType Basic" >> $htaccess
423434
echo " Require valid-user" >> $htaccess
424435
echo "</Directory>" >> $htaccess
425-
else
426-
echo "auth_basic \"$domain password access\";" > $htaccess
427-
echo "auth_basic_user_file $htpasswd;" >> $htaccess
436+
ln -s $htaccess $shtaccess
437+
restart_required='yes'
428438
fi
429-
chmod 640 $htpasswd $htaccess >/dev/null 2>&1
430439
fi
440+
chmod 644 $htpasswd $htaccess
441+
chgrp $user $htpasswd $htaccess
431442
done
432443

433444
# Set folder permissions

0 commit comments

Comments
 (0)