domain.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. #----------------------------------------------------------#
  2. # WEB #
  3. #----------------------------------------------------------#
  4. # Web template check
  5. is_web_template_valid() {
  6. if [ ! -z "$WEB_SYSTEM" ]; then
  7. tpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$1.tpl"
  8. stpl="$WEBTPL/$WEB_SYSTEM/$WEB_BACKEND/$1.stpl"
  9. if [ ! -e "$tpl" ] || [ ! -e "$stpl" ]; then
  10. check_result $E_NOTEXIST "$1 web template doesn't exist"
  11. fi
  12. fi
  13. }
  14. # Proxy template check
  15. is_proxy_template_valid() {
  16. if [ ! -z "$PROXY_SYSTEM" ]; then
  17. tpl="$WEBTPL/$PROXY_SYSTEM/$1.tpl"
  18. stpl="$WEBTPL/$PROXY_SYSTEM/$1.stpl"
  19. if [ ! -e "$tpl" ] || [ ! -e "$stpl" ]; then
  20. check_result $E_NOTEXIST "$1 proxy template doesn't exist"
  21. fi
  22. fi
  23. }
  24. # Backend template check
  25. is_backend_template_valid() {
  26. if [ ! -z "$WEB_BACKEND" ]; then
  27. if [ ! -e "$WEBTPL/$WEB_BACKEND/$1.tpl" ]; then
  28. check_result $E_NOTEXIST "$1 backend template doesn't exist"
  29. fi
  30. fi
  31. }
  32. # Web domain existence check
  33. is_web_domain_new() {
  34. web=$(grep -F -H "DOMAIN='$1'" $VESTA/data/users/*/web.conf)
  35. if [ ! -z "$web" ]; then
  36. if [ "$type" == 'web' ]; then
  37. check_result $E_EXISTS "Web domain $1 exist"
  38. fi
  39. web_user=$(echo "$web" |cut -f 7 -d /)
  40. if [ "$web_user" != "$user" ]; then
  41. check_result $E_EXISTS "Web domain $1 exist"
  42. fi
  43. fi
  44. }
  45. # Web alias existence check
  46. is_web_alias_new() {
  47. web_alias=$(grep -wH "$1" $VESTA/data/users/*/web.conf)
  48. if [ ! -z "$web_alias" ]; then
  49. a1=$(echo "$web_alias" |grep -F "'$1'" |cut -f 7 -d /)
  50. if [ ! -z "$a1" ] && [ "$2" == "web" ]; then
  51. check_result $E_EXISTS "Web alias $1 exists"
  52. fi
  53. if [ ! -z "$a1" ] && [ "$a1" != "$user" ]; then
  54. check_result $E_EXISTS "Web alias $1 exists"
  55. fi
  56. a2=$(echo "$web_alias" |grep -F "'$1," |cut -f 7 -d /)
  57. if [ ! -z "$a2" ] && [ "$2" == "web" ]; then
  58. check_result $E_EXISTS "Web alias $1 exists"
  59. fi
  60. if [ ! -z "$a2" ] && [ "$a2" != "$user" ]; then
  61. check_result $E_EXISTS "Web alias $1 exists"
  62. fi
  63. a3=$(echo "$web_alias" |grep -F ",$1," |cut -f 7 -d /)
  64. if [ ! -z "$a3" ] && [ "$2" == "web" ]; then
  65. check_result $E_EXISTS "Web alias $1 exists"
  66. fi
  67. if [ ! -z "$a3" ] && [ "$a3" != "$user" ]; then
  68. check_result $E_EXISTS "Web alias $1 exists"
  69. fi
  70. a4=$(echo "$web_alias" |grep -F ",$1'" |cut -f 7 -d /)
  71. if [ ! -z "$a4" ] && [ "$2" == "web" ]; then
  72. check_result $E_EXISTS "Web alias $1 exists"
  73. fi
  74. if [ ! -z "$a4" ] && [ "$a4" != "$user" ]; then
  75. check_result $E_EXISTS "Web alias $1 exists"
  76. fi
  77. fi
  78. }
  79. # Prepare web backend
  80. prepare_web_backend() {
  81. pool=$(find -L /etc/php* -type d \( -name "pool.d" -o -name "*fpm.d" \))
  82. if [ ! -e "$pool" ]; then
  83. check_result $E_NOTEXIST "php-fpm pool doesn't exist"
  84. fi
  85. backend_type="$domain"
  86. if [ "$WEB_BACKEND_POOL" = 'user' ]; then
  87. backend_type="$user"
  88. fi
  89. if [ -e "$pool/$backend_type.conf" ]; then
  90. backend_lsnr=$(grep "listen =" $pool/$backend_type.conf)
  91. backend_lsnr=$(echo "$backend_lsnr" |cut -f 2 -d = |sed "s/ //")
  92. if [ ! -z "$(echo $backend_lsnr |grep /)" ]; then
  93. backend_lsnr="unix:$backend_lsnr"
  94. fi
  95. fi
  96. }
  97. # Prepare web aliases
  98. prepare_web_aliases() {
  99. i=1
  100. for tmp_alias in ${1//,/ }; do
  101. tmp_alias_idn="$tmp_alias"
  102. if [[ "$tmp_alias" = *[![:ascii:]]* ]]; then
  103. tmp_alias_idn=$(idn -t --quiet -a $tmp_alias)
  104. fi
  105. if [[ $i -eq 1 ]]; then
  106. aliases="$tmp_alias"
  107. aliases_idn="$tmp_alias_idn"
  108. alias_string="ServerAlias $tmp_alias_idn"
  109. else
  110. aliases="$aliases,$tmp_alias"
  111. aliases_idn="$aliases_idn,$tmp_alias_idn"
  112. if (( $i % 100 == 0 )); then
  113. alias_string="$alias_string\n ServerAlias $tmp_alias_idn"
  114. else
  115. alias_string="$alias_string $tmp_alias_idn"
  116. fi
  117. fi
  118. alias_number=$i
  119. ((i++))
  120. done
  121. }
  122. # Update web domain values
  123. prepare_web_domain_values() {
  124. if [[ "$domain" = *[![:ascii:]]* ]]; then
  125. domain_idn=$(idn -t --quiet -a $domain)
  126. else
  127. domain_idn=$domain
  128. fi
  129. group="$user"
  130. email="info@$domain"
  131. docroot="$HOMEDIR/$user/web/$domain/public_html"
  132. sdocroot="$docroot"
  133. if [ "$SSL_HOME" = 'single' ]; then
  134. sdocroot="$HOMEDIR/$user/web/$domain/public_shtml" ;
  135. fi
  136. if [ ! -z "$WEB_BACKEND" ]; then
  137. prepare_web_backend
  138. fi
  139. server_alias=''
  140. alias_string=''
  141. aliases_idn=''
  142. prepare_web_aliases $ALIAS
  143. ssl_crt="$HOMEDIR/$user/conf/web/ssl.$domain.crt"
  144. ssl_key="$HOMEDIR/$user/conf/web/ssl.$domain.key"
  145. ssl_pem="$HOMEDIR/$user/conf/web/ssl.$domain.pem"
  146. ssl_ca="$HOMEDIR/$user/conf/web/ssl.$domain.ca"
  147. if [ ! -e "$USER_DATA/ssl/$domain.ca" ]; then
  148. ssl_ca_str='#'
  149. fi
  150. if [ "$SUSPENDED" = 'yes' ]; then
  151. docroot="$VESTA/data/templates/web/suspend"
  152. sdocroot="$VESTA/data/templates/web/suspend"
  153. fi
  154. }
  155. # Add web config
  156. add_web_config() {
  157. conf="$HOMEDIR/$user/conf/web/$domain.$1.conf"
  158. if [[ "$2" =~ stpl$ ]]; then
  159. conf="$HOMEDIR/$user/conf/web/$domain.$1.ssl.conf"
  160. fi
  161. domain_idn=$domain
  162. format_domain_idn
  163. cat $WEBTPL/$1/$WEB_BACKEND/$2 | \
  164. sed -e "s|%ip%|$local_ip|g" \
  165. -e "s|%domain%|$domain|g" \
  166. -e "s|%domain_idn%|$domain_idn|g" \
  167. -e "s|%alias%|${aliases//,/ }|g" \
  168. -e "s|%alias_idn%|${aliases_idn//,/ }|g" \
  169. -e "s|%alias_string%|$alias_string|g" \
  170. -e "s|%email%|info@$domain|g" \
  171. -e "s|%web_system%|$WEB_SYSTEM|g" \
  172. -e "s|%web_port%|$WEB_PORT|g" \
  173. -e "s|%web_ssl_port%|$WEB_SSL_PORT|g" \
  174. -e "s|%backend_lsnr%|$backend_lsnr|g" \
  175. -e "s|%rgroups%|$WEB_RGROUPS|g" \
  176. -e "s|%proxy_system%|$PROXY_SYSTEM|g" \
  177. -e "s|%proxy_port%|$PROXY_PORT|g" \
  178. -e "s|%proxy_ssl_port%|$PROXY_SSL_PORT|g" \
  179. -e "s/%proxy_extentions%/${PROXY_EXT//,/|}/g" \
  180. -e "s|%user%|$user|g" \
  181. -e "s|%group%|$user|g" \
  182. -e "s|%home%|$HOMEDIR|g" \
  183. -e "s|%docroot%|$docroot|g" \
  184. -e "s|%sdocroot%|$sdocroot|g" \
  185. -e "s|%ssl_crt%|$ssl_crt|g" \
  186. -e "s|%ssl_key%|$ssl_key|g" \
  187. -e "s|%ssl_pem%|$ssl_pem|g" \
  188. -e "s|%ssl_ca_str%|$ssl_ca_str|g" \
  189. -e "s|%ssl_ca%|$ssl_ca|g" \
  190. > $conf
  191. chown root:$user $conf
  192. chmod 640 $conf
  193. if [ -z "$(grep "$conf" /etc/$1/conf.d/vesta.conf)" ]; then
  194. if [ "$1" != 'nginx' ]; then
  195. echo "Include $conf" >> /etc/$1/conf.d/vesta.conf
  196. else
  197. echo "include $conf;" >> /etc/$1/conf.d/vesta.conf
  198. fi
  199. fi
  200. trigger="${2/%.tpl/.sh}"
  201. if [[ "$2" =~ stpl$ ]]; then
  202. trigger="${2/%.stpl/.sh}"
  203. fi
  204. if [ -x "$WEBTPL/$1/$WEB_BACKEND/$trigger" ]; then
  205. $WEBTPL/$1/$WEB_BACKEND/$trigger \
  206. $user $domain $local_ip $HOMEDIR \
  207. $HOMEDIR/$user/web/$domain/public_html
  208. fi
  209. }
  210. # Get config top and bottom line number
  211. get_web_config_lines() {
  212. tpl_lines=$(egrep -ni "name %domain_idn%" $1 |grep -w %domain_idn%)
  213. tpl_lines=$(echo "$tpl_lines" |cut -f 1 -d :)
  214. tpl_last_line=$(wc -l $1 |cut -f 1 -d ' ')
  215. if [ -z "$tpl_lines" ]; then
  216. check_result $E_PARSING "can't parse template $1"
  217. fi
  218. domain_idn=$domain
  219. format_domain_idn
  220. vhost_lines=$(grep -niF "name $domain_idn" $2)
  221. vhost_lines=$(echo "$vhost_lines" |egrep "$domain_idn($| |;)") #"
  222. vhost_lines=$(echo "$vhost_lines" |cut -f 1 -d :)
  223. if [ -z "$vhost_lines" ]; then
  224. check_result $E_PARSING "can't parse config $2"
  225. fi
  226. top_line=$((vhost_lines + 1 - tpl_lines))
  227. bottom_line=$((top_line - 1 + tpl_last_line))
  228. multi=$(sed -n "$top_line,$bottom_line p" $2 |grep ServerAlias |wc -l)
  229. if [ "$multi" -ge 2 ]; then
  230. bottom_line=$((bottom_line + multi -1))
  231. fi
  232. }
  233. # Replace web config
  234. replace_web_config() {
  235. conf="$HOMEDIR/$user/conf/web/$domain.$1.conf"
  236. if [[ "$2" =~ stpl$ ]]; then
  237. conf="$HOMEDIR/$user/conf/web/$domain.$1.ssl.conf"
  238. fi
  239. if [ -e "$conf" ]; then
  240. sed -i "s|$old|$new|g" $conf
  241. else
  242. # fallback to old style configs
  243. conf="$HOMEDIR/$user/conf/web/$1.conf"
  244. if [[ "$2" =~ stpl$ ]]; then
  245. conf="$HOMEDIR/$user/conf/web/s$1.conf"
  246. fi
  247. get_web_config_lines $WEBTPL/$1/$WEB_BACKEND/$2 $conf
  248. sed -i "$top_line,$bottom_line s|$old|$new|g" $conf
  249. fi
  250. }
  251. # Delete web configuration
  252. del_web_config() {
  253. conf="$HOMEDIR/$user/conf/web/$domain.$1.conf"
  254. if [[ "$2" =~ stpl$ ]]; then
  255. conf="$HOMEDIR/$user/conf/web/$domain.$1.ssl.conf"
  256. fi
  257. if [ -e "$conf" ]; then
  258. sed -i "\|$conf|d" /etc/$1/conf.d/vesta.conf
  259. rm -f $conf
  260. else
  261. # fallback to old style configs
  262. conf="$HOMEDIR/$user/conf/web/$1.conf"
  263. if [[ "$2" =~ stpl$ ]]; then
  264. conf="$HOMEDIR/$user/conf/web/s$1.conf"
  265. fi
  266. if [ -e "$conf" ]; then
  267. get_web_config_lines $WEBTPL/$1/$WEB_BACKEND/$2 $conf
  268. sed -i "$top_line,$bottom_line d" $conf
  269. fi
  270. fi
  271. # clean-up for both config styles if there is no more domains
  272. web_domain=$(grep DOMAIN $USER_DATA/web.conf |wc -l)
  273. if [ "$web_domain" -eq '0' ]; then
  274. sed -i "/.*\/$user\/conf\/web\//d" /etc/$1/conf.d/vesta.conf
  275. if [ -f "$conf" ]; then
  276. rm -f $conf
  277. fi
  278. fi
  279. }
  280. # SSL certificate verification
  281. is_web_domain_cert_valid() {
  282. if [ ! -e "$ssl_dir/$domain.crt" ]; then
  283. check_result $E_NOTEXIST "$ssl_dir/$domain.crt not found"
  284. fi
  285. if [ ! -e "$ssl_dir/$domain.key" ]; then
  286. check_result $E_NOTEXIST "$ssl_dir/$domain.key not found"
  287. fi
  288. crt_vrf=$(openssl verify $ssl_dir/$domain.crt 2>&1)
  289. if [ ! -z "$(echo $crt_vrf |grep 'unable to load')" ]; then
  290. check_result $E_INVALID "SSL Certificate is not valid"
  291. fi
  292. if [ ! -z "$(echo $crt_vrf |grep 'unable to get local issuer')" ]; then
  293. if [ ! -e "$ssl_dir/$domain.ca" ]; then
  294. check_result $E_NOTEXIST "Certificate Authority not found"
  295. fi
  296. fi
  297. if [ -e "$ssl_dir/$domain.ca" ]; then
  298. s1=$(openssl x509 -text -in $ssl_dir/$domain.crt 2>/dev/null)
  299. s1=$(echo "$s1" |grep Issuer |awk -F = '{print $6}' |head -n1)
  300. s2=$(openssl x509 -text -in $ssl_dir/$domain.ca 2>/dev/null)
  301. s2=$(echo "$s2" |grep Subject |awk -F = '{print $6}' |head -n1)
  302. if [ "$s1" != "$s2" ]; then
  303. check_result $E_NOTEXIST "SSL intermediate chain is not valid"
  304. fi
  305. fi
  306. key_vrf=$(grep 'PRIVATE KEY' $ssl_dir/$domain.key |wc -l)
  307. if [ "$key_vrf" -ne 2 ]; then
  308. check_result $E_INVALID "SSL Key is not valid"
  309. fi
  310. if [ ! -z "$(grep 'ENCRYPTED' $ssl_dir/$domain.key)" ]; then
  311. check_result $E_FORBIDEN "SSL Key is protected (remove pass_phrase)"
  312. fi
  313. openssl s_server -port 654321 -quiet -cert $ssl_dir/$domain.crt \
  314. -key $ssl_dir/$domain.key >> /dev/null 2>&1 &
  315. pid=$!
  316. sleep 0.5
  317. disown &> /dev/null
  318. kill $pid &> /dev/null
  319. check_result $? "ssl certificate key pair is not valid" $E_INVALID
  320. }
  321. #----------------------------------------------------------#
  322. # DNS #
  323. #----------------------------------------------------------#
  324. # DNS template check
  325. is_dns_template_valid() {
  326. if [ ! -e "$DNSTPL/$1.tpl" ]; then
  327. check_result $E_NOTEXIST "$1 dns template doesn't exist"
  328. fi
  329. }
  330. # DNS domain existence check
  331. is_dns_domain_new() {
  332. dns=$(ls $VESTA/data/users/*/dns/$1.conf 2>/dev/null)
  333. if [ ! -z "$dns" ]; then
  334. if [ "$2" == 'dns' ]; then
  335. check_result $E_EXISTS "DNS domain $1 exists"
  336. fi
  337. dns_user=$(echo "$dns" |cut -f 7 -d /)
  338. if [ "$dns_user" != "$user" ]; then
  339. check_result $E_EXISTS "DNS domain $1 exists"
  340. fi
  341. fi
  342. }
  343. # Update domain zone
  344. update_domain_zone() {
  345. domain_param=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
  346. eval $domain_param
  347. SOA=$(idn --quiet -a -t "$SOA")
  348. if [ -z "$SERIAL" ]; then
  349. SERIAL=$(date +'%Y%m%d01')
  350. fi
  351. if [[ "$domain" = *[![:ascii:]]* ]]; then
  352. domain_idn=$(idn -t --quiet -a $domain)
  353. else
  354. domain_idn=$domain
  355. fi
  356. zn_conf="$HOMEDIR/$user/conf/dns/$domain.db"
  357. echo "\$TTL $TTL
  358. @ IN SOA $SOA. root.$domain_idn. (
  359. $SERIAL
  360. 7200
  361. 3600
  362. 1209600
  363. 180 )
  364. " > $zn_conf
  365. fields='$RECORD\t$TTL\tIN\t$TYPE\t$PRIORITY\t$VALUE'
  366. while read line ; do
  367. IFS=$'\n'
  368. for key in $(echo $line|sed "s/' /'\n/g"); do
  369. eval ${key%%=*}="${key#*=}"
  370. done
  371. RECORD=$(idn --quiet -a -t "$RECORD")
  372. if [ "$TYPE" = 'CNAME' ] || [ "$TYPE" = 'MX' ]; then
  373. VALUE=$(idn --quiet -a -t "$VALUE")
  374. fi
  375. # Split long TXT entries into 255 chunks
  376. if [ "$TYPE" = 'TXT' ]; then
  377. txtlength=${#VALUE}
  378. if [ $txtlength -gt 255 ]; then
  379. already_chunked=0
  380. if [[ $VALUE == *"\" \""* ]] || [[ $VALUE == *"\"\""* ]]; then
  381. already_chunked=1
  382. fi
  383. if [ $already_chunked -eq 0 ]; then
  384. if [[ ${VALUE:0:1} = '"' ]]; then
  385. txtlength=$(( $txtlength - 2 ))
  386. VALUE=${VALUE:1:txtlength}
  387. fi
  388. VALUE=$(echo $VALUE | fold -w 255 | xargs -I '$' echo -n '"$"')
  389. fi
  390. fi
  391. fi
  392. if [ "$SUSPENDED" != 'yes' ]; then
  393. eval echo -e "\"$fields\""|sed "s/%quote%/'/g" >> $zn_conf
  394. fi
  395. done < $USER_DATA/dns/$domain.conf
  396. }
  397. # Update zone serial
  398. update_domain_serial() {
  399. zn_conf="$HOMEDIR/$user/conf/dns/$domain.db"
  400. if [ -e $zn_conf ]; then
  401. zn_serial=$(head $zn_conf |grep 'SOA' -A1 |tail -n 1 |sed "s/ //g")
  402. s_date=$(echo ${zn_serial:0:8})
  403. c_date=$(date +'%Y%m%d')
  404. if [ "$s_date" == "$c_date" ]; then
  405. cur_value=$(echo ${zn_serial:8} )
  406. new_value=$(expr $cur_value + 1 )
  407. len_value=$(expr length $new_value)
  408. if [ 1 -eq "$len_value" ]; then
  409. new_value='0'$new_value
  410. fi
  411. serial="$c_date""$new_value"
  412. else
  413. serial="$(date +'%Y%m%d01')"
  414. fi
  415. else
  416. serial="$(date +'%Y%m%d01')"
  417. fi
  418. add_object_key "dns" 'DOMAIN' "$domain" 'SERIAL' 'RECORDS'
  419. update_object_value 'dns' 'DOMAIN' "$domain" '$SERIAL' "$serial"
  420. }
  421. # Get next DNS record ID
  422. get_next_dnsrecord(){
  423. if [ -z "$id" ]; then
  424. curr_str=$(grep "ID=" $USER_DATA/dns/$domain.conf | cut -f 2 -d \' |\
  425. sort -n|tail -n1)
  426. id="$((curr_str +1))"
  427. fi
  428. }
  429. # Sort DNS records
  430. sort_dns_records() {
  431. conf="$USER_DATA/dns/$domain.conf"
  432. cat $conf |sort -n -k 2 -t \' >$conf.tmp
  433. mv -f $conf.tmp $conf
  434. }
  435. # Check if this is a last record
  436. is_dns_record_critical() {
  437. str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
  438. eval $str
  439. if [ "$TYPE" = 'A' ] || [ "$TYPE" = 'NS' ]; then
  440. records=$(grep "TYPE='$TYPE'" $USER_DATA/dns/$domain.conf| wc -l)
  441. if [ $records -le 1 ]; then
  442. echo "Error: at least one $TYPE record should remain active"
  443. log_event "$E_INVALID" "$ARGUMENTS"
  444. exit $E_INVALID
  445. fi
  446. fi
  447. }
  448. # Check if dns record is valid
  449. is_dns_fqnd() {
  450. t=$1
  451. r=$2
  452. fqdn_type=$(echo $t | grep "NS\|CNAME\|MX\|PTR\|SRV")
  453. tree_length=3
  454. if [ $t = 'CNAME' ]; then
  455. tree_length=2
  456. fi
  457. if [ ! -z "$fqdn_type" ]; then
  458. dots=$(echo $dvalue | grep -o "\." | wc -l)
  459. if [ "$dots" -lt "$tree_length" ]; then
  460. r=$(echo $r|sed -e "s/\.$//")
  461. msg="$t record $r should be a fully qualified domain name (FQDN)"
  462. echo "Error: $msg"
  463. log_event "$E_INVALID" "$ARGUMENTS"
  464. exit $E_INVALID
  465. fi
  466. fi
  467. }
  468. # Validate nameserver
  469. is_dns_nameserver_valid() {
  470. d=$1
  471. t=$2
  472. r=$3
  473. if [ "$t" = 'NS' ]; then
  474. remote=$(echo $r |grep ".$domain.$")
  475. if [ ! -z "$remote" ]; then
  476. zone=$USER_DATA/dns/$d.conf
  477. a_record=$(echo $r |cut -f 1 -d '.')
  478. n_record=$(grep "RECORD='$a_record'" $zone| grep "TYPE='A'")
  479. if [ -z "$n_record" ]; then
  480. check_result $E_NOTEXIST "IN A $a_record.$d does not exist"
  481. fi
  482. fi
  483. fi
  484. }
  485. #----------------------------------------------------------#
  486. # MAIL #
  487. #----------------------------------------------------------#
  488. # Mail domain existence check
  489. is_mail_domain_new() {
  490. mail=$(ls $VESTA/data/users/*/mail/$1.conf 2>/dev/null)
  491. if [ ! -z "$mail" ]; then
  492. if [ "$2" == 'mail' ]; then
  493. check_result $E_EXISTS "Mail domain $1 exists"
  494. fi
  495. mail_user=$(echo "$mail" |cut -f 7 -d /)
  496. if [ "$mail_user" != "$user" ]; then
  497. check_result $E_EXISTS "Mail domain $1 exists"
  498. fi
  499. fi
  500. }
  501. # Checking mail account existance
  502. is_mail_new() {
  503. check_acc=$(grep "ACCOUNT='$1'" $USER_DATA/mail/$domain.conf)
  504. if [ ! -z "$check_acc" ]; then
  505. check_result $E_EXISTS "mail account $1 is already exists"
  506. fi
  507. check_als=$(awk -F "ALIAS='" '{print $2}' $USER_DATA/mail/$domain.conf )
  508. check_als=$(echo "$check_als" | cut -f 1 -d "'" | grep -w $1)
  509. if [ ! -z "$check_als" ]; then
  510. check_result $E_EXISTS "mail alias $1 is already exists"
  511. fi
  512. }
  513. #----------------------------------------------------------#
  514. # CMN #
  515. #----------------------------------------------------------#
  516. # Checking domain existance
  517. is_domain_new() {
  518. type=$1
  519. for object in ${2//,/ }; do
  520. if [ ! -z "$WEB_SYSTEM" ]; then
  521. is_web_domain_new $object $type
  522. is_web_alias_new $object $type
  523. fi
  524. if [ ! -z "$DNS_SYSTEM" ]; then
  525. is_dns_domain_new $object $type
  526. fi
  527. if [ ! -z "$MAIL_SYSTEM" ]; then
  528. is_mail_domain_new $object $type
  529. fi
  530. done
  531. }
  532. # Get domain variables
  533. get_domain_values() {
  534. eval $(grep "DOMAIN='$domain'" $USER_DATA/$1.conf)
  535. }