diff --git a/func/db.sh b/func/db.sh index 983174e7..c7514eea 100644 --- a/func/db.sh +++ b/func/db.sh @@ -30,7 +30,7 @@ mysql_connect() { if [ '0' -ne "$?" ]; then if [ "$notify" != 'no' ]; then echo -e "Can't connect to MySQL $HOST\n$(cat $err)" |\ - $send_mail -s "$subj" $email + $SENDMAIL -s "$subj" $email fi echo "Error: Connection to $HOST failed" log_event "$E_CONNECT" "$ARGUMENTS" @@ -49,7 +49,7 @@ mysql_dump() { rm -rf $tmpdir if [ "$notify" != 'no' ]; then echo -e "Can't dump database $database\n$(cat $err)" |\ - $send_mail -s "$subj" $email + $SENDMAIL -s "$subj" $email fi echo "Error: dump $database failed" log_event "$E_DB" "$ARGUMENTS" @@ -72,7 +72,7 @@ psql_connect() { if [ '0' -ne "$?" ]; then if [ "$notify" != 'no' ]; then echo -e "Can't connect to PostgreSQL $HOST\n$(cat /tmp/e.psql)" |\ - $send_mail -s "$subj" $email + $SENDMAIL -s "$subj" $email fi echo "Error: Connection to $HOST failed" log_event "$E_CONNECT" "$ARGUMENTS" @@ -90,7 +90,7 @@ psql_dump() { rm -rf $tmpdir if [ "$notify" != 'no' ]; then echo -e "Can't dump database $database\n$(cat /tmp/e.psql)" |\ - $send_mail -s "$subj" $email + $SENDMAIL -s "$subj" $email fi echo "Error: dump $database failed" log_event "$E_DB" "$ARGUMENTS" @@ -243,8 +243,7 @@ is_dbhost_new() { # Get database values get_database_values() { - db_str=$(grep "DB='$database'" $USER_DATA/db.conf) - eval $db_str + eval $(grep "DB='$database'" $USER_DATA/db.conf) } # Change MySQL database password diff --git a/func/domain.sh b/func/domain.sh index 586a0bd2..eda517a0 100644 --- a/func/domain.sh +++ b/func/domain.sh @@ -5,17 +5,10 @@ # Web template check is_web_template_valid() { if [ ! -z "$WEB_SYSTEM" ]; then - template=$1 - if [ -z "$template" ]; then - template=$(grep WEB_TEMPLATE $USER_DATA/user.conf |cut -f2 -d \') - if [ -z "$template" ]; then - template="default" - fi - fi - tpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.tpl" - stpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$template.stpl" + tpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$1.tpl" + stpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$1.stpl" if [ ! -e "$tpl" ] || [ ! -e "$stpl" ]; then - check_result $E_NOTEXIST "$template web template doesn't exist" + check_result $E_NOTEXIST "$1 web template doesn't exist" fi fi } @@ -23,25 +16,20 @@ is_web_template_valid() { # Proxy template check is_proxy_template_valid() { if [ ! -z "$PROXY_SYSTEM" ]; then - proxy=$1 - if [ -z "$proxy" ]; then - proxy=$(grep PROXY_TEMPLATE $USER_DATA/user.conf |cut -f2 -d \') - if [ -z "$proxy" ]; then - proxy="default" - fi - fi - tpl="$WEBTPL/$PROXY_SYSTEM/$proxy.tpl" - stpl="$WEBTPL/$PROXY_SYSTEM/$proxy.stpl" + tpl="$WEBTPL/$PROXY_SYSTEM/$1.tpl" + stpl="$WEBTPL/$PROXY_SYSTEM/$1.stpl" if [ ! -e "$tpl" ] || [ ! -e "$stpl" ]; then - check_result $E_NOTEXIST "$proxy proxy template doesn't exist" + check_result $E_NOTEXIST "$1 proxy template doesn't exist" fi fi } # Backend template check is_backend_template_valid() { - if [ ! -e "$WEBTPL/$WEB_BACKEND/$1.tpl" ]; then - check_result $E_NOTEXIST "$backend backend template doesn't exist" + if [ ! -z "$WEB_BACKEND" ]; then + if [ ! -e "$WEBTPL/$WEB_BACKEND/$1.tpl" ]; then + check_result $E_NOTEXIST "$1 backend template doesn't exist" + fi fi } @@ -210,7 +198,7 @@ add_web_config() { -e "s|%proxy_ssl_port%|$PROXY_SSL_PORT|g" \ -e "s/%proxy_extentions%/${PROXY_EXT//,/|}/g" \ -e "s|%user%|$user|g" \ - -e "s|%group%|$group|g" \ + -e "s|%group%|$user|g" \ -e "s|%home%|$HOMEDIR|g" \ -e "s|%docroot%|$HOMEDIR/$user/web/$domain/public_html|g" \ -e "s|%sdocroot%|$HOMEDIR/$user/web/$domain/public_html|g" \ @@ -225,7 +213,7 @@ add_web_config() { chmod 640 $conf if [ -z "$(grep "$conf" /etc/$1/conf.d/vesta.conf)" ]; then - if [ "$WEB_SYSTEM" != 'nginx' ]; then + if [ "$1" != 'nginx' ]; then echo "Include $conf" >> /etc/$1/conf.d/vesta.conf else echo "include $conf;" >> /etc/$1/conf.d/vesta.conf @@ -265,6 +253,10 @@ get_web_config_lines() { # Replace web config replace_web_config() { + conf="$HOMEDIR/$user/conf/web/$1.conf" + if [[ "$2" =~ stpl$ ]]; then + conf="$HOMEDIR/$user/conf/web/s$1.conf" + fi get_web_config_lines $WEBTPL/$1/$WEB_BACKEND/$2 $conf sed -i "$top_line,$bottom_line s|$old|$new|g" $conf } @@ -355,9 +347,8 @@ is_web_domain_cert_valid() { # DNS template check is_dns_template_valid() { - t="$DNSTPL/$template.tpl" - if [ ! -e $t ]; then - check_result $E_NOTEXIST "dns template $template doesn't exist" + if [ ! -e "$DNSTPL/$1.tpl" ]; then + check_result $E_NOTEXIST "$1 dns template doesn't exist" fi } diff --git a/func/ip.sh b/func/ip.sh index e3d84c63..eb52a990 100644 --- a/func/ip.sh +++ b/func/ip.sh @@ -33,7 +33,8 @@ is_ip_key_empty() { eval $string eval value="$key" if [ ! -z "$value" ] && [ "$value" != '0' ]; then - check_result $E_EXISTS "$key is not empty = $value" + key="$(echo $key|sed -e "s/\$U_//")" + check_result $E_EXISTS "IP is in use / $key = $value" fi } @@ -133,7 +134,6 @@ get_ip_value() { } - # Get real ip address get_real_ip() { if [ -e "$VESTA/data/ips/$1" ]; then @@ -142,8 +142,6 @@ get_real_ip() { nat=$(grep -H "^NAT='$1'" $VESTA/data/ips/*) if [ ! -z "$nat" ]; then echo "$nat" |cut -f 1 -d : |cut -f 7 -d / - else - get_user_ip fi fi } @@ -222,17 +220,22 @@ get_user_ip() { # Validate ip address is_ip_valid() { - if [ ! -z $1 ]; then - if [ -e "$VESTA/data/ips/$1" ]; then - ip_data=$(cat $VESTA/data/ips/$1) - local_ip="$1" + local_ip="$1" + if [ ! -e "$VESTA/data/ips/$1" ]; then + nat=$(grep -H "^NAT='$1'" $VESTA/data/ips/*) + if [ -z "$nat" ]; then + check_result $E_NOTEXIST "IP $1 doesn't exist" else - nat=$(grep -H "^NAT='$1'" $VESTA/data/ips/*) - check_result $? "IP $1 doesn't exist" $E_NOTEXIST nat=$(echo "$nat" |cut -f1 -d: |cut -f7 -d/) - ip_data=$(cat $VESTA/data/ips/$nat) local_ip=$nat fi + fi + if [ ! -z $2 ]; then + if [ -z "$nat" ]; then + ip_data=$(cat $VESTA/data/ips/$1) + else + ip_data=$(cat $VESTA/data/ips/$nat) + fi ip_owner=$(echo "$ip_data" |grep OWNER= |cut -f2 -d \') ip_status=$(echo "$ip_data" |grep STATUS= |cut -f2 -d \') if [ "$ip_owner" != "$user" ] && [ "$ip_status" = 'dedicated' ]; then @@ -242,7 +245,5 @@ is_ip_valid() { if [ "$ip_owner" != "$user" ] && [ "$ip_owner" != "$owner" ]; then check_result $E_FORBIDEN "$user user can't use IP $1" fi - else - get_user_ip fi } diff --git a/func/main.sh b/func/main.sh index d55faac8..633875d5 100644 --- a/func/main.sh +++ b/func/main.sh @@ -112,17 +112,18 @@ is_system_enabled() { # User package check is_package_full() { case "$1" in - WEB_DOMAINS) used=$(wc -l $USER_DATA/web.conf |cut -f1 -d \ );; + WEB_DOMAINS) used=$(wc -l $USER_DATA/web.conf);; WEB_ALIASES) used=$(echo $aliases |tr ',' '\n' |wc -l);; - DNS_DOMAINS) used=$(wc -l $USER_DATA/dns.conf |cut -f1 -d \ );; - DNS_RECORDS) used=$(wc -l $USER_DATA/dns/$domain.conf|cut -f1 -d \ );; - MAIL_DOMAINS) used=$(wc -l $USER_DATA/mail.conf |cut -f1 -d \ );; - MAIL_USER) used=$(wc -l $USER_DATA/mail/$domain.conf |cut -f1 -d \ );; - DATABASES) used=$(wc -l $USER_DATA/db.conf |cut -f1 -d \ );; - CRON_JOBS) used=$(wc -l $USER_DATA/cron.conf |cut -f1 -d \ );; + DNS_DOMAINS) used=$(wc -l $USER_DATA/dns.conf);; + DNS_RECORDS) used=$(wc -l $USER_DATA/dns/$domain.conf);; + MAIL_DOMAINS) used=$(wc -l $USER_DATA/mail.conf);; + MAIL_ACCOUNTS) used=$(wc -l $USER_DATA/mail/$domain.conf);; + DATABASES) used=$(wc -l $USER_DATA/db.conf);; + CRON_JOBS) used=$(wc -l $USER_DATA/cron.conf);; esac + used=$(echo "$used"| cut -f 1 -d \ ) limit=$(grep "^$1=" $USER_DATA/user.conf |cut -f 2 -d \') - if [ "$limit" != 'unlimited' ] && [ "$used" -ge "$limit" ]; then + if [ "$limit" != 'unlimited' ] && [[ "$used" -ge "$limit" ]]; then check_result $E_LIMIT "$1 limit is reached :: upgrade user package" fi } @@ -140,14 +141,19 @@ get_user_owner() { } # Random password generator -gen_password() { - PW_MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' - PW_LENGHT='10' - pw_matrix=${1-$PW_MATRIX} - pw_lenght=${2-$PW_LENGHT} - while [ ${n:=1} -le $pw_lenght ]; do - pass="$pass${pw_matrix:$(($RANDOM%${#pw_matrix})):1}" - let n+=1 +generate_password() { + matrix=$1 + lenght=$2 + if [ -z "$matrix" ]; then + matrix=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz + fi + if [ -z "$lenght" ]; then + lenght=10 + fi + i=1 + while [ $i -le $lenght ]; do + pass="$pass${matrix:$(($RANDOM%${#matrix})):1}" + ((i++)) done echo "$pass" } @@ -169,15 +175,6 @@ is_type_valid() { fi } -# Check if backup is available for user -is_backup_available() { - b_owner=$(echo $user |\ - sed -e "s/\.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].tar//") - if [ "$user" != "$b_owner" ]; then - check_result $E_FORBIDEN "permission denied" - fi -} - # Check user backup settings is_backup_enabled() { BACKUPS=$(grep "^BACKUPS=" $USER_DATA/user.conf | cut -f2 -d \') @@ -450,7 +447,7 @@ sync_cron_jobs() { fi rm -f $crontab if [ "$CRON_REPORTS" = 'yes' ]; then - echo "MAILTO=$CONTACT" > $sys_cron + echo "MAILTO=$CONTACT" > $crontab fi while read line; do eval $line @@ -467,15 +464,16 @@ sync_cron_jobs() { # User format validator is_user_format_valid() { if ! [[ "$1" =~ ^[a-zA-Z0-9][-|\.|_|a-zA-Z0-9]{0,28}[a-zA-Z0-9]$ ]]; then - check_result $E_INVALID "invalid user format :: $1" + check_result $E_INVALID "invalid $2 format :: $1" fi } # Domain format validator is_domain_format_valid() { + object_name=${2-domain} exclude="[!|@|#|$|^|&|*|(|)|+|=|{|}|:|,|<|>|?|_|/|\|\"|'|;|%|\`| ]" if [[ "$1" =~ $exclude ]]; then - check_result $E_INVALID "invalid domain format :: $1" + check_result $E_INVALID "invalid $object_name format :: $1" fi } @@ -494,9 +492,10 @@ is_alias_format_valid() { # IP format validator is_ip_format_valid() { + object_name=${2-ip} ip_regex='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' if ! [[ $1 =~ ^$ip_regex\.$ip_regex\.$ip_regex\.$ip_regex$ ]]; then - check_result $E_INVALID "invalid IP format :: $1" + check_result $E_INVALID "invalid $object_name format :: $1" fi } @@ -512,7 +511,203 @@ is_extention_format_valid() { is_number_format_valid() { object_name=${2-number} if ! [[ "$1" =~ ^[0-9]+$ ]] ; then - check_result $E_INVALID "invalid $object_name format :: $1" + check_result $E_INVALID "invalid $object_name format :: $1" + fi +} + +# Autoreply format validator +is_autoreply_format_valid() { + if [[ "$1" =~ [$|\`] ]] || [ 10240 -le ${#1} ]; then + check_result $E_INVALID "invalid autoreply format :: $1" + fi +} + +# Boolean format validator +is_boolean_format_valid() { + if [ "$1" != 'yes' ] && [ "$1" != 'no' ]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi +} + +# Common format validator +is_common_format_valid() { + exclude="[!|#|$|^|&|(|)|+|=|{|}|:|<|>|?|/|\|\"|'|;|%|\`| ]" + if [[ "$1" =~ $exclude ]]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi + if [ 400 -le ${#1} ]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi + if [[ "$1" =~ @ ]] && [ ${#1} -gt 1 ] ; then + check_result $E_INVALID "invalid $2 format :: $1" + fi + if [[ $1 =~ \* ]]; then + if [ "$(echo $1 | grep -o '*'|wc -l)" -gt 1 ]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi + fi +} + +# Database format validator +is_database_format_valid() { + exclude="[!|@|#|$|^|&|*|(|)|+|=|{|}|:|,|<|>|?|/|\|\"|'|;|%|\`| ]" + if [[ "$1" =~ $exclude ]] || [ 65 -le ${#1} ]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi +} + +# Date format validator +is_date_format_valid() { + if ! [[ "$1" =~ ^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$ ]]; then + check_result $E_INVALID "invalid date format :: $1" + fi +} + +# Database user validator +is_dbuser_format_valid() { + exclude="[!|@|#|$|^|&|*|(|)|+|=|{|}|:|,|<|>|?|/|\|\"|'|;|%|\`| ]" + if [[ "$1" =~ $exclude ]] || [ 17 -le ${#1} ]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi +} + +# DNS record type validator +is_dns_type_format_valid() { + known_dnstype='A,AAAA,NS,CNAME,MX,TXT,SRV,DNSKEY,KEY,IPSECKEY,PTR,SPF' + if [ -z "$(echo $known_dnstype |grep -w $1)" ]; then + check_result $E_INVALID "invalid dns record type format :: $1" + fi +} + +# DNS record validator +is_dns_record_format_valid() { + if [ "$rtype" = 'A' ]; then + is_ip_format_valid "$1" + fi + if [ "$rtype" = 'NS' ]; then + is_domain_format_valid "$1" 'ns_record' + fi + if [ "$rtype" = 'MX' ]; then + is_domain_format_valid "$1" 'mx_record' + is_int_format_valid "$priority" 'priority_record' + fi + +} + +# Email format validator +is_email_format_valid() { + if [[ ! "$1" =~ "@" ]] ; then + check_result $E_INVALID "invalid email format :: $1" + fi +} + +# Firewall action validator +is_fw_action_format_valid() { + if [ "$1" != "ACCEPT" ] && [ "$1" != 'DROP' ] ; then + check_result $E_INVALID "invalid action format :: $1" + fi +} + +# Firewall protocol validator +is_fw_protocol_format_valid() { + if [ "$1" != "ICMP" ] && [ "$1" != 'UDP' ] && [ "$1" != 'TCP' ] ; then + check_result $E_INVALID "invalid protocol format :: $1" + fi +} + +# Firewall port validator +is_fw_port_format_valid() { + if [ "${#1}" -eq 1 ]; then + if ! [[ "$1" =~ [0-9] ]]; then + check_result $E_INVALID "invalid port format :: $1" + fi + else + if ! [[ "$1" =~ ^[0-9][-|,|:|0-9]{0,30}[0-9]$ ]] + then + check_result $E_INVALID "invalid port format :: $1" + fi + fi +} + +# Integer validator +is_int_format_valid() { + if ! [[ "$1" =~ ^[0-9]+$ ]] ; then + check_result $E_INVALID "invalid $2 format :: $1" + fi +} + +# Interface validator +is_interface_format_valid() { + netdevices=$(cat /proc/net/dev |grep : |cut -f 1 -d : |tr -d ' ') + if [ -z $(echo "$netdevices" |grep -x $1) ]; then + check_result $E_INVALID "invalid interface format :: $1" + fi +} + +# IP status validator +is_ip_status_format_valid() { + if [ -z "$(echo shared,dedicated | grep -w $1 )" ]; then + check_result $E_INVALID "invalid status format :: $1" + fi +} + +# Cron validator +is_cron_format_valid() { + limit=60 + check_format='' + if [ "$2" = 'day' ]; then + limit=31 + fi + if [ "$2" = 'month' ]; then + limit=12 + fi + if [ "$2" = 'wday' ]; then + limit=7 + fi + if [ "$1" = '*' ]; then + check_format='ok' + fi + if [[ "$1" =~ ^[\*]+[/]+[0-9] ]]; then + if [ "$(echo $1 |cut -f 2 -d /)" -lt $limit ]; then + check_format='ok' + fi + fi + if [[ "$1" =~ ^[0-9][-|,|0-9]{0,28}[0-9]$ ]]; then + check_format='ok' + crn_values=${1//,/ } + crn_values=${crn_values//-/ } + for crn_vl in $crn_values; do + if [ "$crn_vl" -gt $limit ]; then + check_format='invalid' + fi + done + fi + if [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -lt $limit ]; then + check_format='ok' + fi + if [ "$check_format" != 'ok' ]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi +} + +# Name validator +is_name_format_valid() { + if ! [[ "$1" =~ ^[[:alnum:]][-|\ |\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi +} + +# Object validator +is_object_format_valid() { + if ! [[ "$1" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then + check_result $E_INVALID "invalid $2 format :: $1" + fi +} + +# Password validator +is_password_format_valid() { + if [ "${#1}" -lt '6' ]; then + check_result $E_INVALID "invalid password format :: $1" fi } @@ -522,11 +717,73 @@ is_format_valid() { eval arg=\$$arg_name if [ ! -z "$arg" ]; then case $arg_name in - aliases) is_alias_format_valid "$arg" ;; - domain) is_domain_format_valid "$arg" ;; - proxy_ext) is_extention_format_valid "$arg" ;; - ip) is_ip_format_valid "$arg" ;; - user) is_user_format_valid "$arg" ;; + account) is_user_format_valid "$arg" "$arg_name";; + action) is_fw_action_format_valid "$arg";; + aliases) is_alias_format_valid "$arg" ;; + antispam) is_boolean_format_valid "$arg" 'antispam' ;; + antivirus) is_boolean_format_valid "$arg" 'antivirus' ;; + autoreply) is_autoreply_format_valid "$arg" ;; + backup) is_user_format_valid "$arg" 'backup' ;; + charset) is_object_format_valid "$arg" "$arg_name" ;; + charsets) is_common_format_valid "$arg" 'charsets' ;; + comment) is_object_format_valid "$arg" 'comment' ;; + database) is_database_format_valid "$arg" 'database';; + day) is_cron_format_valid "$arg" $arg_name ;; + dbpass) is_password_format_valid "$arg" ;; + dbuser) is_dbuser_format_valid "$arg" 'dbuser';; + dkim) is_boolean_format_valid "$arg" 'dkim' ;; + dkim_size) is_int_format_valid "$arg" ;; + domain) is_domain_format_valid "$arg" ;; + dvalue) is_dns_record_format_valid "$arg";; + email) is_email_format_valid "$arg" ;; + exp) is_date_format_valid "$arg" ;; + extentions) is_common_format_valid "$arg" 'extentions' ;; + fname) is_name_format_valid "$arg" "first name" ;; + ftp_password) is_password_format_valid "$arg" ;; + ftp_user) is_user_format_valid "$arg" "$arg_name" ;; + host) is_domain_format_valid "$arg" "$arg_name" ;; + hour) is_cron_format_valid "$arg" $arg_name ;; + id) is_int_format_valid "$arg" 'id' ;; + ip) is_ip_format_valid "$arg" ;; + ip_name) is_domain_format_valid "$arg" 'IP name';; + ip_status) is_ip_status_format_valid "$arg" ;; + job) is_int_format_valid "$arg" 'job' ;; + key) is_user_format_valid "$arg" "$arg_name" ;; + lname) is_name_format_valid "$arg" "last name" ;; + malias) is_user_format_valid "$arg" "$arg_name" ;; + max_db) is_int_format_valid "$arg" 'max db';; + min) is_cron_format_valid "$arg" $arg_name ;; + month) is_cron_format_valid "$arg" $arg_name ;; + nat_ip) is_ip_format_valid "$arg" ;; + netmask) is_ip_format_valid "$arg" 'netmask' ;; + newid) is_int_format_valid "$arg" 'id' ;; + ns1) is_domain_format_valid "$arg" 'ns1' ;; + ns2) is_domain_format_valid "$arg" 'ns2' ;; + ns3) is_domain_format_valid "$arg" 'ns3' ;; + ns4) is_domain_format_valid "$arg" 'ns4' ;; + ns5) is_domain_format_valid "$arg" 'ns5' ;; + ns6) is_domain_format_valid "$arg" 'ns6' ;; + ns7) is_domain_format_valid "$arg" 'ns7' ;; + ns8) is_domain_format_valid "$arg" 'ns8' ;; + object) is_name_format_valid "$arg" 'object';; + package) is_object_format_valid "$arg" "$arg_name" ;; + password) is_password_format_valid "$arg" ;; + port) is_int_format_valid "$arg" 'port' ;; + port_ext) is_fw_protocol_format_valid "$arg";; + protocol) is_fw_port_format_valid "$arg" ;; + proxy_ext) is_extention_format_valid "$arg" ;; + quota) is_int_format_valid "$arg" 'quota' ;; + record) is_common_format_valid "$arg" 'record';; + restart) is_boolean_format_valid "$arg" 'restart' ;; + rtype) is_dns_type_format_valid "$arg" ;; + rule) is_int_format_valid "$arg" "rule id" ;; + soa) is_domain_format_valid "$arg" 'SOA' ;; + stats_pass) is_password_format_valid "$arg" ;; + stats_user) is_user_format_valid "$arg" "$arg_name" ;; + template) is_object_format_valid "$arg" "$arg_name" ;; + ttl) is_int_format_valid "$arg" 'ttl';; + user) is_user_format_valid "$arg" $arg_name;; + wday) is_cron_format_valid "$arg" $arg_name ;; esac fi done diff --git a/func/rebuild.sh b/func/rebuild.sh index 3f41360d..72cd7002 100644 --- a/func/rebuild.sh +++ b/func/rebuild.sh @@ -406,10 +406,14 @@ rebuild_dns_domain_conf() { # MAIL domain rebuild rebuild_mail_domain_conf() { - # Get domain values - domain_idn=$(idn -t --quiet -a "$domain") get_domain_values 'mail' + if [[ "$domain" = *[![:ascii:]]* ]]; then + domain_idn=$(idn -t --quiet -a $domain) + else + domain_idn=$domain + fi + if [ "$SUSPENDED" = 'yes' ]; then SUSPENDED_MAIL=$((SUSPENDED_MAIL +1)) fi @@ -526,8 +530,8 @@ rebuild_mysql_database() { eval $host_str if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ]; then echo "Error: mysql config parsing failed" - if [ ! -z "$send_mail" ]; then - echo "Can't parse MySQL DB config" | $send_mail -s "$subj" $email + if [ ! -z "$SENDMAIL" ]; then + echo "Can't parse MySQL DB config" | $SENDMAIL -s "$subj" $email fi log_event "$E_PARSING" "$ARGUMENTS" exit $E_PARSING @@ -537,9 +541,9 @@ rebuild_mysql_database() { mysql -h $HOST -u $USER -p$PASSWORD -e "$query" > /dev/null 2>&1 if [ '0' -ne "$?" ]; then echo "Error: Database connection to $HOST failed" - if [ ! -z "$send_mail" ]; then + if [ ! -z "$SENDMAIL" ]; then echo "Database connection to MySQL host $HOST failed" |\ - $send_mail -s "$subj" $email + $SENDMAIL -s "$subj" $email fi log_event "$E_CONNECT" "$ARGUMENTS" exit $E_CONNECT @@ -569,8 +573,8 @@ rebuild_pgsql_database() { export PGPASSWORD="$PASSWORD" if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $TPL ]; then echo "Error: postgresql config parsing failed" - if [ ! -z "$send_mail" ]; then - echo "Can't parse PostgreSQL config" | $send_mail -s "$subj" $email + if [ ! -z "$SENDMAIL" ]; then + echo "Can't parse PostgreSQL config" | $SENDMAIL -s "$subj" $email fi log_event "$E_PARSING" "$ARGUMENTS" exit $E_PARSING @@ -580,9 +584,9 @@ rebuild_pgsql_database() { psql -h $HOST -U $USER -c "$query" > /dev/null 2>&1 if [ '0' -ne "$?" ]; then echo "Error: Connection failed" - if [ ! -z "$send_mail" ]; then + if [ ! -z "$SENDMAIL" ]; then echo "Database connection to PostgreSQL host $HOST failed" |\ - $send_mail -s "$subj" $email + $SENDMAIL -s "$subj" $email fi log_event "$E_CONNECT" "$ARGUMENTS" exit $E_CONNECT diff --git a/func/remote.sh b/func/remote.sh index ba93f448..1f2d49d3 100644 --- a/func/remote.sh +++ b/func/remote.sh @@ -106,7 +106,7 @@ remote_dns_health_check() { else subj="DNS sync failed" email=$($BIN/v-get-user-value admin CONTACT) - cat $tmpfile |$send_mail -s "$subj" $email + cat $tmpfile |$SENDMAIL -s "$subj" $email fi # Deleting tmp file