Skip to content

Commit edcd549

Browse files
committed
permissions on htpasswd file
1 parent 3e3ecca commit edcd549

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

bin/v-add-web-domain-httpauth

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ fi
7474
# Adding httpasswd user
7575
auth_hash=$($BIN/v-generate-password-hash htpasswd htpasswd $password)
7676
touch $htpasswd
77+
chmod 640 $htpasswd $htaccess
7778
sed -i "/^$auth_user:/d" $htpasswd
7879
echo "$auth_user:$auth_hash" >> $htpasswd
7980

bin/v-delete-web-domain-httpauth

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sed -i "/^$auth_user:/d" $htpasswd
5454

5555
# Deleting password protection
5656
if [ "$(echo "$AUTH_USER" |tr : '\n' |wc -l)" -le 1 ]; then
57-
rm -f $htaccess
57+
rm -f $htaccess $htpasswd
5858
restart_required='yes'
5959
fi
6060

func/rebuild.sh

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,22 @@ rebuild_web_domain_conf() {
176176
fi
177177

178178
# Set folder permissions
179-
chmod 551 $HOMEDIR/$user/web/$domain
180-
chmod 751 $HOMEDIR/$user/web/$domain/private
181-
chmod 751 $HOMEDIR/$user/web/$domain/cgi-bin
182-
chmod 751 $HOMEDIR/$user/web/$domain/public_html
183-
chmod 751 $HOMEDIR/$user/web/$domain/public_shtml
184-
chmod 751 $HOMEDIR/$user/web/$domain/document_errors
185-
chmod 551 $HOMEDIR/$user/web/$domain/stats
186-
chmod 551 $HOMEDIR/$user/web/$domain/logs
179+
chmod 551 $HOMEDIR/$user/web/$domain \
180+
$HOMEDIR/$user/web/$domain/stats \
181+
$HOMEDIR/$user/web/$domain/logs
182+
chmod 751 $HOMEDIR/$user/web/$domain/private \
183+
$HOMEDIR/$user/web/$domain/cgi-bin \
184+
$HOMEDIR/$user/web/$domain/public_html \
185+
$HOMEDIR/$user/web/$domain/public_shtml \
186+
$HOMEDIR/$user/web/$domain/document_errors
187187
chmod 640 /var/log/$WEB_SYSTEM/domains/$domain.*
188188

189189
# Set ownership
190-
chown $user:$user $HOMEDIR/$user/web/$domain
191-
chown $user:$user $HOMEDIR/$user/web/$domain/private
192-
chown $user:$user $HOMEDIR/$user/web/$domain/cgi-bin
193-
chown $user:$user $HOMEDIR/$user/web/$domain/public_html
194-
chown $user:$user $HOMEDIR/$user/web/$domain/public_shtml
190+
chown $user:$user $HOMEDIR/$user/web/$domain \
191+
$HOMEDIR/$user/web/$domain/private \
192+
$HOMEDIR/$user/web/$domain/cgi-bin \
193+
$HOMEDIR/$user/web/$domain/public_html \
194+
$HOMEDIR/$user/web/$domain/public_shtml
195195
chown -R $user:$user $HOMEDIR/$user/web/$domain/document_errors
196196
chown root:$user /var/log/$WEB_SYSTEM/domains/$domain.*
197197

@@ -367,6 +367,39 @@ rebuild_web_domain_conf() {
367367
chmod u-w /etc/shadow
368368
fi
369369
done
370+
371+
# Adding http auth protection
372+
htaccess="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.conf_htaccess"
373+
htpasswd="$HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.htpasswd"
374+
docroot="$HOMEDIR/$user/web/$domain/public_html"
375+
for auth_user in ${AUTH_USER//:/ }; do
376+
# Parsing auth user variables
377+
position=$(echo $AUTH_USER | tr ':' '\n' | grep -n '' |\
378+
grep ":$auth_user$" | cut -f 1 -d:)
379+
auth_hash=$(echo $AUTH_HASH | tr ':' '\n' | grep -n '' |\
380+
grep "^$position:" | cut -f 2 -d :)
381+
382+
# Adding http auth user
383+
touch $htpasswd
384+
sed -i "/^$auth_user:/d" $htpasswd
385+
echo "$auth_user:$auth_hash" >> $htpasswd
386+
387+
# Checking web server include
388+
if [ ! -e "$htaccess" ]; then
389+
if [ "$WEB_SYSTEM" != 'nginx' ]; then
390+
echo "<Directory $docroot>" > $htaccess
391+
echo " AuthUserFile $htpasswd" >> $htaccess
392+
echo " AuthName \"$domain access\"" >> $htaccess
393+
echo " AuthType Basic" >> $htaccess
394+
echo " Require valid-user" >> $htaccess
395+
echo "</Directory>" >> $htaccess
396+
else
397+
echo "auth_basic \"$domain password access\";" > $htaccess
398+
echo "auth_basic_user_file $htpasswd;" >> $htaccess
399+
fi
400+
fi
401+
done
402+
chmod 640 $htpasswd $htaccess >/dev/null 2>&1
370403
}
371404

372405
# DNS domain rebuild

0 commit comments

Comments
 (0)