| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #!/bin/bash
- # info: adding web domain
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- user="$1"
- domain=$(idn -t --quiet -u "$2" )
- auth_user="$3"
- auth_pass="$4"
- # Importing variables
- source $VESTA/conf/vars.conf
- source $V_FUNC/shared_func.sh
- source $V_FUNC/domain_func.sh
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- # Checking arg number
- check_args '4' "$#" 'user domain auth_user auth_password'
- # Checking argument format
- format_validation 'user' 'domain' 'auth_user' 'auth_pass'
- # Checking web system is enabled
- is_system_enabled 'web'
- # Checking user
- is_user_valid
- # Checking user is active
- is_user_suspended
- # Checking domain exist
- is_web_domain_valid
- # Checking domain is not suspened
- is_domain_suspended 'web'
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Definining statistic dir
- stat_dir="$V_HOME/$user/web/$domain/stats"
- # Adding htaccess file
- if [ ! -e "$stat_dir/.htaccess" ]; then
- echo "AuthUserFile $stat_dir/.htpasswd" > $stat_dir/.htaccess
- echo "AuthName \"Only for admins\"" >> $stat_dir/.htaccess
- echo "AuthType Basic" >> $stat_dir/.htaccess
- echo "Require valid-user" >> $stat_dir/.htaccess
- echo "" >> $stat_dir/.htaccess
- fi
- # Generating htaccess user and password
- if [ ! -e "$stat_dir/.htpasswd" ]; then
- htpasswd -bc $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
- else
- htpasswd -b $stat_dir/.htpasswd "$auth_user" "$auth_pass" >/dev/null 2>&1
- fi
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- # Get current value
- curr_val=$(get_web_domain_value '$STATS_AUTH')
- check_uniq=$(echo "$curr_val" | grep -w "$auth_user")
- # Checking current users
- if [ -z "$curr_val" ] || [ "$curr_val" = 'no' ]; then
- a_users="$auth_user"
- else
- if [ -z "$check_uniq" ]; then
- a_users="$curr_val,$auth_user"
- else
- a_users="$curr_val"
- fi
- fi
- # Adding stats user in config
- update_web_domain_value '$STATS_AUTH' "$a_users"
- # Hiding password
- V_EVENT="$(date +%m-%d-%y" "%H:%m:%S) $V_SCRIPT $user $domain $auth_user *****"
- # Logging
- log_history "$V_EVENT" "v_del_web_domain_stat_auth $user $domain $auth_user"
- log_event 'system' "$V_EVENT"
- exit $OK
|