|
| 1 | +#!/bin/bash |
| 2 | +# info: enable/disable directory listing |
| 3 | +# options: USER DOMAIN MODE |
| 4 | +# |
| 5 | +# The call is used for changing the directory list mode. |
| 6 | + |
| 7 | + |
| 8 | +#----------------------------------------------------------# |
| 9 | +# Variable&Function # |
| 10 | +#----------------------------------------------------------# |
| 11 | + |
| 12 | +# Argument defenition |
| 13 | +user=$1 |
| 14 | +domain=$2 |
| 15 | +mode=$3 |
| 16 | + |
| 17 | +# Includes |
| 18 | +source $HESTIA/func/main.sh |
| 19 | +source $HESTIA/func/domain.sh |
| 20 | +source $HESTIA/conf/hestia.conf |
| 21 | + |
| 22 | +# Additional argument formatting |
| 23 | +format_domain |
| 24 | +format_domain_idn |
| 25 | + |
| 26 | + |
| 27 | +#----------------------------------------------------------# |
| 28 | +# Verifications # |
| 29 | +#----------------------------------------------------------# |
| 30 | + |
| 31 | +check_args '3' "$#" 'USER DOMAIN MODE' |
| 32 | +is_format_valid 'user' 'domain' |
| 33 | +is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM' |
| 34 | +is_object_valid 'user' 'USER' "$user" |
| 35 | +is_object_unsuspended 'user' 'USER' "$user" |
| 36 | +is_object_valid 'web' 'DOMAIN' "$domain" |
| 37 | +is_object_unsuspended 'web' 'DOMAIN' "$domain" |
| 38 | + |
| 39 | + |
| 40 | +#----------------------------------------------------------# |
| 41 | +# Action # |
| 42 | +#----------------------------------------------------------# |
| 43 | + |
| 44 | +# Fetching domain variables |
| 45 | +get_domain_values 'web' |
| 46 | + |
| 47 | +if [ "$mode" = "on" ]; then |
| 48 | + # Enable directory listing |
| 49 | + sed -i "s/-Index/+Index/g" $HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.conf |
| 50 | + if [ -e "$ssl_dir/$domain.ca" ]; then |
| 51 | + # Enable directory listing for SSL-enforced domains |
| 52 | + sed -i "s/-Index/+Index/g" $HOMEDIR/$user/conf/web/s$WEB_SYSTEM.$domain.conf |
| 53 | + fi |
| 54 | + echo "INFO: Enabled directory browsing for $domain." |
| 55 | +else |
| 56 | + # Disable directory listing |
| 57 | + sed -i "s/+Index/-Index/g" $HOMEDIR/$user/conf/web/$WEB_SYSTEM.$domain.conf |
| 58 | + if [ -e "$ssl_dir/$domain.ca" ]; then |
| 59 | + # Enable directory listing for SSL-enforced domains |
| 60 | + sed -i "s/+Index/-Index/g" $HOMEDIR/$user/conf/web/s$WEB_SYSTEM.$domain.conf |
| 61 | + fi |
| 62 | + echo "INFO: Disabled directory browsing for $domain." |
| 63 | +fi |
| 64 | + |
| 65 | + |
| 66 | +#----------------------------------------------------------# |
| 67 | +# Hestia # |
| 68 | +#----------------------------------------------------------# |
| 69 | + |
| 70 | +# Rebuilding vhosts |
| 71 | +$BIN/v-restart-web |
| 72 | + |
| 73 | +# Logging |
| 74 | +log_history "turned directory browsing $mode for $domain." |
| 75 | +log_event "$OK" "$EVENT" |
| 76 | + |
| 77 | +exit |
0 commit comments