domain.func 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. # Checking domain existance
  2. is_domain_new() {
  3. output_mode="$1"
  4. search_dom=${2-$domain}
  5. # Parsing domain values
  6. check_domain=$(grep -F "DOMAIN='$search_dom'" $V_USERS/*/*.conf| \
  7. grep -v cron.conf)
  8. # Parsing alias values
  9. check_alias=$(grep -F 'ALIAS=' $V_USERS/*/*.conf | \
  10. grep -v cron.conf | \
  11. awk -F "ALIAS=" '{print $2}' | \
  12. cut -f 2 -d \' | \
  13. sed -e "s/,/\n/g" | \
  14. grep "^$search_dom$" )
  15. # Checking result
  16. if [ ! -z "$check_domain" ] || [ ! -z "$check_alias" ]; then
  17. if [ "$output_mode" != 'quiet' ]; then
  18. echo "Error: domain exist"
  19. log_event 'debug' "$E_DOM_EXIST $V_EVENT"
  20. exit $E_DOM_EXIST
  21. fi
  22. return $E_DOM_EXIST
  23. fi
  24. }
  25. is_domain_owner() {
  26. search_dom=${1-$domain}
  27. # Parsing domain values
  28. check_domain=$(grep "DOMAIN='$search_dom'" $V_USERS/$user/*.conf)
  29. # Parsing alias values
  30. check_alias=$(grep 'ALIAS=' $V_USERS/$user/*.conf | \
  31. awk -F "ALIAS=" '{print $2}' | \
  32. cut -f 2 -d \' | \
  33. sed -e "s/,/\n/g" | \
  34. grep "^$search_dom$" )
  35. # Checking result
  36. if [ -z "$check_domain" ] && [ -z "$check_alias" ]; then
  37. echo "Error: domain not owned"
  38. log_event 'debug' "$E_DOM_NOTOWNED $V_EVENT"
  39. exit $E_DOM_NOTOWNED
  40. fi
  41. }
  42. is_dns_domain_free() {
  43. # Parsing domain values
  44. check_domain=$(grep -F "DOMAIN='$domain'" $V_USERS/$user/dns.conf)
  45. # Checking result
  46. if [ ! -z "$check_domain" ]; then
  47. echo "Error: domain exist"
  48. log_event 'debug' "$E_DOM_EXIST $V_EVENT"
  49. exit $E_DOM_EXIST
  50. fi
  51. }
  52. is_web_domain_free() {
  53. search_dom=${1-$domain}
  54. # Parsing domain values
  55. check_domain=$(grep -F "DOMAIN='$search_dom'" $V_USERS/$user/web.conf)
  56. # Parsing alias values
  57. check_alias=$(grep -F 'ALIAS=' $V_USERS/$user/web.conf | \
  58. awk -F "ALIAS=" '{print $2}' | \
  59. cut -f 2 -d \' | \
  60. sed -e "s/,/\n/g" | \
  61. grep "^$search_dom$" )
  62. # Checking result
  63. if [ ! -z "$check_domain" ] || [ ! -z "$check_alias" ]; then
  64. echo "Error: domain exist"
  65. log_event 'debug' "$E_DOM_EXIST $V_EVENT"
  66. exit $E_DOM_EXIST
  67. fi
  68. }
  69. is_dns_domain_valid() {
  70. # Parsing domain values
  71. check_domain=$(grep -F "DOMAIN='$domain'" $V_USERS/$user/dns.conf)
  72. # Checking result
  73. if [ -z "$check_domain" ]; then
  74. echo "Error: domain not exist"
  75. log_event 'debug' "$E_DOM_NOTEXIST $V_EVENT"
  76. exit $E_DOM_NOTEXIST
  77. fi
  78. }
  79. is_web_domain_valid() {
  80. # Parsing domain values
  81. check_domain=$(grep -F "DOMAIN='$domain'" $V_USERS/$user/web.conf)
  82. # Checking result
  83. if [ -z "$check_domain" ]; then
  84. echo "Error: domain not exist"
  85. log_event 'debug' "$E_DOM_NOTEXIST $V_EVENT"
  86. exit $E_DOM_NOTEXIST
  87. fi
  88. }
  89. is_domain_suspended() {
  90. config_type="$1"
  91. # Parsing domain values
  92. check_domain=$(grep "DOMAIN='$domain'" $V_USERS/$user/$config_type.conf|\
  93. grep "SUSPEND='yes'")
  94. # Checking result
  95. if [ ! -z "$check_domain" ]; then
  96. echo "Error: domain suspended"
  97. log_event 'debug' "$E_DOM_SUSPENDED $V_EVENT"
  98. exit $E_DOM_SUSPENDED
  99. fi
  100. }
  101. is_domain_unsuspended() {
  102. config_type="$1"
  103. # Parsing domain values
  104. check_domain=$(grep "DOMAIN='$domain'" $V_USERS/$user/$config_type.conf|\
  105. grep "SUSPEND='no'")
  106. # Checking result
  107. if [ ! -z "$check_domain" ]; then
  108. echo "Error: domain unsuspended"
  109. log_event 'debug' "$E_DOM_UNSUSPENDED $V_EVENT"
  110. exit $E_DOM_UNSUSPENDED
  111. fi
  112. }
  113. update_domain_zone() {
  114. # Definigng variables
  115. line=$(grep "DOMAIN='$domain'" $V_USERS/$user/dns.conf)
  116. fields='$RECORD\t$TTL\tIN\t$TYPE\t$VALUE'
  117. conf="/etc/namedb/$domain.db"
  118. # Checking serial
  119. if [ -e $conf ]; then
  120. zn_serial=$(head $conf|grep 'SOA' -A1|tail -n 1|sed -e "s/ //g")
  121. s_date=$(echo ${zn_serial:0:8})
  122. c_date=$(date +'%Y%m%d')
  123. if [ "$s_date" == "$c_date" ]; then
  124. cur_value=$(echo ${zn_serial:8} )
  125. new_value=$(expr $cur_value + 1 )
  126. len_value=$(expr length $new_value)
  127. if [ 1 -eq "$len_value" ]; then
  128. new_value='0'$new_value
  129. fi
  130. serial="$c_date""$new_value"
  131. else
  132. serial="$(date +'%Y%m%d01')"
  133. fi
  134. else
  135. serial="$(date +'%Y%m%d01')"
  136. fi
  137. # Parsing dns domains conf
  138. for key in $line; do
  139. eval ${key%%=*}=${key#*=}
  140. done
  141. # Converting SOA to ascii
  142. SOA=$(idn --quiet -a -t "$SOA")
  143. # Adding zone header
  144. echo "\$TTL $TTL
  145. @ IN SOA $SOA. root.$domain_idn. (
  146. $serial
  147. 7200
  148. 3600
  149. 1209600
  150. 180 )
  151. " > $conf
  152. # Adding zone records
  153. while read line ; do
  154. # Defining new delimeter
  155. IFS=$'\n'
  156. # Parsing key=value
  157. for key in $(echo $line|sed -e "s/' /'\n/g"); do
  158. eval ${key%%=*}="${key#*=}"
  159. done
  160. # Converting utf records to ascii
  161. RECORD=$(idn --quiet -a -t "$RECORD")
  162. VALUE=$(idn --quiet -a -t "$VALUE")
  163. eval echo -e "\"$fields\""|sed -e "s/%quote%/'/g" >> $conf
  164. done < $V_USERS/$user/zones/$domain
  165. }
  166. get_next_dns_record() {
  167. # Parsing config
  168. curr_str=$(grep "ID=" $V_USERS/$user/zones/$domain|cut -f 2 -d \'|\
  169. sort -n|tail -n1)
  170. # Print result
  171. echo "$((curr_str +1))"
  172. }
  173. is_dns_record_free() {
  174. # Checking record id
  175. check_id=$(grep "ID='$id'" $V_USERS/$user/zones/$domain)
  176. if [ ! -z "$check_id" ]; then
  177. echo "Error: ID exist"
  178. log_event 'debug' "$E_ID_EXIST $V_EVENT"
  179. exit $E_ID_EXIST
  180. fi
  181. }
  182. sort_dns_records() {
  183. # Defining conf
  184. conf="$V_USERS/$user/zones/$domain"
  185. cat $conf |sort -n -k 2 -t \' >$conf.tmp
  186. mv -f $conf.tmp $conf
  187. }
  188. add_web_config() {
  189. # Adding template to config
  190. cat $tpl_file | \
  191. sed -e "s/%ip%/$ip/g" \
  192. -e "s/%web_port%/$WEB_PORT/g" \
  193. -e "s/%web_ssl_port%/$WEB_SSL_PORT/g" \
  194. -e "s/%proxy_string%/${proxy_string////\/}/g" \
  195. -e "s/%proxy_port%/$PROXY_PORT/g" \
  196. -e "s/%proxy_ssl_port%/$PROXY_SSL_PORT/g" \
  197. -e "s/%domain_idn%/$domain_idn/g" \
  198. -e "s/%domain%/$domain/g" \
  199. -e "s/%user%/$user/g" \
  200. -e "s/%group%/$group/g" \
  201. -e "s/%home%/${V_HOME////\/}/g" \
  202. -e "s/%docroot%/${docroot////\/}/g" \
  203. -e "s/%docroot_string%/${docroot_string////\/}/g" \
  204. -e "s/%email%/$email/g" \
  205. -e "s/%alias_string%/$alias_string/g" \
  206. -e "s/%alias_idn%/${aliases_idn//,/ }/g" \
  207. -e "s/%alias%/${aliases//,/ }/g" \
  208. -e "s/%ssl_cert%/${ssl_cert////\/}/g" \
  209. -e "s/%ssl_key%/${ssl_key////\/}/g" \
  210. -e "s/%nginx_extentions%/${NGINX_EXT//,/|}/g" \
  211. -e "s/%elog%/$elog/g" \
  212. -e "s/%cgi%/$cgi/g" \
  213. -e "s/%cgi_option%/$cgi_option/g" \
  214. >> $conf
  215. }
  216. get_web_config_brds() {
  217. # Defining template borders
  218. serv_line=$(grep -ni 'Name %domain_idn%' "$tpl_file" |cut -f 1 -d :)
  219. if [ -z "$serv_line" ]; then
  220. log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
  221. return $E_PARSE_ERROR
  222. fi
  223. # Template lines
  224. last_line=$(wc -l $tpl_file|cut -f 1 -d ' ')
  225. bfr_line=$((serv_line - 1))
  226. aftr_line=$((last_line - serv_line - 1))
  227. # Config lines
  228. str=$(grep -ni "Name $domain_idn" $conf | cut -f 1 -d :)
  229. top_line=$((str - serv_line + 1))
  230. bottom_line=$((top_line + last_line -1))
  231. # Check for multialias (8k alias issue)
  232. multi=$(sed -n "$top_line,$bottom_line p" $conf |grep ServerAlias |wc -l)
  233. if [ "$multi" -ge 2 ]; then
  234. bottom_line=$((bottom_line + multi -1))
  235. fi
  236. }
  237. change_web_config() {
  238. # Get config borders
  239. get_web_config_brds || exit $?
  240. # Parsing config
  241. vhost=$(grep -A $aftr_line -B $bfr_line -ni "Name $domain_idn" $conf)
  242. str=$(echo "$vhost" | grep -F "$search_phrase" | head -n 1)
  243. # Parsing string position and content
  244. str_numb=$(echo "$str" | sed -e "s/-/=/" | cut -f 1 -d '=')
  245. str_cont=$(echo "$str" | sed -e "s/-/=/" | cut -f 2 -d '=')
  246. # Escaping chars
  247. str_repl=$(echo "$str_repl" | sed \
  248. -e 's/\\/\\\\/g' \
  249. -e 's/&/\\&/g' \
  250. -e 's/\//\\\//g')
  251. # Changing config
  252. if [ ! -z "$str" ]; then
  253. sed -i "$str_numb s/.*/$str_repl/" $conf
  254. fi
  255. }
  256. replace_web_config() {
  257. # Get config borders
  258. get_web_config_brds || exit $?
  259. # Escaping chars
  260. clean_new=$(echo "$new" | sed \
  261. -e 's/\\/\\\\/g' \
  262. -e 's/&/\\&/g' \
  263. -e 's/\//\\\//g')
  264. clean_old=$(echo "$old" | sed \
  265. -e 's/\\/\\\\/g' \
  266. -e 's/&/\\&/g' \
  267. -e 's/\//\\\//g')
  268. # Replacing string in config
  269. sed -i "$top_line,$bottom_line s/$clean_old/$clean_new/" $conf
  270. }
  271. get_web_domain_value() {
  272. key="$1"
  273. # Parsing domains
  274. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/web.conf )
  275. # Parsing key=value
  276. for keys in $string; do
  277. eval ${keys%%=*}=${keys#*=}
  278. done
  279. # Self reference
  280. eval value="$key"
  281. # Print value
  282. echo "$value"
  283. }
  284. get_web_domain_values() {
  285. # Defining domain parameters
  286. for line in $(grep "DOMAIN='$domain'" $V_USERS/$user/web.conf); do
  287. # Assing key=value
  288. for key in $line; do
  289. eval ${key%%=*}=${key#*=}
  290. done
  291. done
  292. }
  293. get_dns_domain_value() {
  294. key="$1"
  295. # Parsing domains
  296. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/dns.conf )
  297. # Parsing key=value
  298. for keys in $string; do
  299. eval ${keys%%=*}=${keys#*=}
  300. done
  301. # Self reference
  302. eval value="$key"
  303. # Print value
  304. echo "$value"
  305. }
  306. update_web_domain_value() {
  307. key="$1"
  308. value="$2"
  309. # Defining conf
  310. conf="$V_USERS/$user/web.conf"
  311. # Parsing conf
  312. domain_str=$(grep -n "DOMAIN='$domain'" $conf)
  313. str_number=$(echo $domain_str | cut -f 1 -d ':')
  314. str=$(echo $domain_str | cut -f 2 -d ':')
  315. # Reading key=values
  316. for keys in $str; do
  317. eval ${keys%%=*}=${keys#*=}
  318. done
  319. # Defining clean key
  320. c_key=$(echo "${key//$/}")
  321. eval old="${key}"
  322. # Escaping slashes
  323. old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  324. new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  325. # Updating conf
  326. sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\
  327. $conf
  328. }
  329. update_dns_domain_value() {
  330. key="$1"
  331. value="$2"
  332. # Defining conf
  333. conf="$V_USERS/$user/dns.conf"
  334. # Parsing conf
  335. domain_str=$(grep -n "DOMAIN='$domain'" $conf)
  336. str_number=$(echo $domain_str | cut -f 1 -d ':')
  337. str=$(echo $domain_str | cut -f 2 -d ':')
  338. # Reading key=values
  339. for keys in $str; do
  340. eval ${keys%%=*}=${keys#*=}
  341. done
  342. # Defining clean key
  343. c_key=$(echo "${key//$/}")
  344. eval old="${key}"
  345. # Escaping slashes
  346. old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  347. new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  348. # Updating conf
  349. sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\
  350. $conf
  351. }
  352. is_web_domain_key_empty() {
  353. key="$1"
  354. # Parsing domains
  355. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/web.conf )
  356. # Parsing key=value
  357. for keys in $string; do
  358. eval ${keys%%=*}=${keys#*=}
  359. done
  360. # Self reference
  361. eval value="$key"
  362. # Checkng key
  363. if [ ! -z "$value" ] && [ "$value" != 'no' ]; then
  364. echo "Error: value is not empty = $value"
  365. log_event 'debug' "$E_VALUE_EXIST $V_EVENT"
  366. exit $E_VALUE_EXIST
  367. fi
  368. }
  369. is_web_domain_cert_valid() {
  370. # Checking file existance
  371. path="$V_USERS/$user/cert"
  372. if [ ! -e "$path/$ssl.crt" ] || [ ! -e "$path/$ssl.key" ]; then
  373. echo "Error: certificate not exist"
  374. log_event 'debug' "$E_CERT_NOTEXIST $V_EVENT"
  375. exit $E_CERT_NOTEXIST
  376. fi
  377. }
  378. is_dns_record_valid() {
  379. # Checking record id
  380. check_id=$(grep "^ID='$id'" $V_USERS/$user/zones/$domain)
  381. if [ -z "$check_id" ]; then
  382. echo "Error: ID not exist"
  383. log_event 'debug' "$E_ID_NOTEXIST $V_EVENT"
  384. exit $E_ID_NOTEXIST
  385. fi
  386. }
  387. is_web_domain_value_exist() {
  388. key="$1"
  389. # Parsing domains
  390. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/web.conf )
  391. # Parsing key=value
  392. for keys in $string; do
  393. eval ${keys%%=*}=${keys#*=}
  394. done
  395. # Self reference
  396. eval value="$key"
  397. # Checking result
  398. if [ -z "$value" ] || [ "$value" = 'no' ]; then
  399. echo "Error: ${key//$/} is empty"
  400. log_event 'debug' "$E_VALUE_EMPTY $V_EVENT"
  401. exit $E_VALUE_EMPTY
  402. fi
  403. }
  404. is_dns_domain_value_exist() {
  405. key="$1"
  406. # Parsing domains
  407. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/dns.conf )
  408. # Parsing key=value
  409. for keys in $string; do
  410. eval ${keys%%=*}=${keys#*=}
  411. done
  412. # Self reference
  413. eval value="$key"
  414. # Checking result
  415. if [ -z "$value" ] || [ "$value" = 'no' ]; then
  416. echo "Error: ${key//$/} is empty"
  417. log_event 'debug' "$E_VALUE_EMPTY $V_EVENT"
  418. exit $E_VALUE_EXIST
  419. fi
  420. }
  421. del_web_config() {
  422. # Get config borders
  423. get_web_config_brds || exit $?
  424. # Deleting lines from config
  425. sed -i "$top_line,$bottom_line d" $conf
  426. }
  427. del_dns_domain() {
  428. conf="$V_USERS/$user/dns.conf"
  429. # Parsing domains
  430. string=$( grep -n "DOMAIN='$domain'" $conf | cut -f 1 -d : )
  431. if [ -z "$string" ]; then
  432. echo "Error: parse error"
  433. log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
  434. exit $E_PARSE_ERROR
  435. fi
  436. sed -i "$string d" $conf
  437. rm -f $V_USERS/$user/zones/$domain
  438. }
  439. del_web_domain() {
  440. conf="$V_USERS/$user/web.conf"
  441. # Parsing domains
  442. string=$( grep -n "DOMAIN='$domain'" $conf | cut -f 1 -d : )
  443. if [ -z "$string" ]; then
  444. echo "Error: parse error"
  445. log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
  446. exit $E_PARSE_ERROR
  447. fi
  448. sed -i "$string d" $conf
  449. }
  450. dom_clear_search(){
  451. # Defining delimeter
  452. IFS=$'\n'
  453. # Reading file line by line
  454. for line in $(grep $search_string $conf); do
  455. # Parsing key=val
  456. for key in $line; do
  457. eval ${key%%=*}=${key#*=}
  458. done
  459. # Print result line
  460. eval echo "$field"
  461. done
  462. }
  463. dom_clear_list() {
  464. # Reading file line by line
  465. while read line ; do
  466. # Parsing key=value
  467. for key in $line; do
  468. eval ${key%%=*}=${key#*=}
  469. done
  470. # Print result line
  471. eval echo "$field"
  472. done < $conf
  473. }
  474. namehost_ip_support() {
  475. #Checking web system
  476. if [ "$WEB_SYSTEM" = 'apache' ]; then
  477. # Checking httpd config for NameHost string number
  478. conf_line=$(grep -n "NameVirtual" $conf|tail -n 1|cut -f 1 -d ':')
  479. if [ ! -z "$conf_line" ]; then
  480. conf_ins=$((conf_line + 1)) # inster into next line
  481. else
  482. conf_ins='1' # insert into first line
  483. fi
  484. # Checking ssl support
  485. if [ "$WEB_SSL" = 'mod_ssl' ]; then
  486. web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
  487. sed -i "$conf_ins i NameVirtualHost $ip:$web_ssl_port" $conf
  488. sed -i "$conf_ins i Listen $ip:$web_ssl_port" $conf
  489. fi
  490. web_port=$(get_config_value '$WEB_PORT')
  491. sed -i "$conf_ins i NameVirtualHost $ip:$web_port" $conf
  492. sed -i "$conf_ins i Listen $ip:$web_port" $conf
  493. # Checking proxy support
  494. if [ "$PROXY_SYSTEM" = 'nginx' ]; then
  495. proxy_port=$(get_config_value '$PROXY_PORT')
  496. cat $V_WEBTPL/ngingx_ip.tpl | sed -e "s/%ip%/$ip/g" \
  497. -e "s/%web_port%/$web_port/g" -e "s/%proxy_port%/$proxy_port/g" >>$nconf
  498. # Adding to rpaf ip pool as well
  499. ips=$(grep 'RPAFproxy_ips' $rconf)
  500. sed -i "s/$ips/$ips $ip/g" $rconf
  501. fi
  502. # Scheduling restart
  503. web_restart='yes'
  504. fi
  505. }
  506. namehost_ip_disable() {
  507. #Checking web system
  508. if [ "$WEB_SYSTEM" = 'apache' ]; then
  509. sed -i "/NameVirtualHost $ip:/d" $conf
  510. sed -i "/Listen $ip:/d" $conf
  511. # Checking proxy support
  512. if [ "$PROXY_SYSTEM" = 'nginx' ]; then
  513. tpl_ln=$(wc -l $V_WEBTPL/ngingx_ip.tpl | cut -f 1 -d ' ')
  514. ip_line=$(grep -n "%ip%" $V_WEBTPL/ngingx_ip.tpl |head -n1 |\
  515. cut -f 1 -d :)
  516. conf_line=$(grep -n -w $ip $nconf|head -n1|cut -f 1 -d :)
  517. # Checking parsed lines
  518. if [ -z "$tpl_ln" ] || [ -z "$ip_line" ] || [ -z "$conf_line" ]
  519. then
  520. echo "Error: nginx config paring error"
  521. log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
  522. exit $E_PARSE_ERROR
  523. fi
  524. up_line=$((ip_line - 1))
  525. first_line=$((conf_line - up_line))
  526. last_line=$((conf_line - ip_line + tpl_ln))
  527. # Checking parsed lines
  528. if [ -z "$first_line" ] || [ -z "$last_line" ]; then
  529. echo "Error: nginx config paring error"
  530. log_event 'debug' "$E_PARSE_ERROR $V_EVENT"
  531. exit $E_PARSE_ERROR
  532. fi
  533. sed -i "$first_line,$last_line d" $nconf
  534. # Deleting from rpaf ip pool as well
  535. ips=$(grep 'RPAFproxy_ips' $rconf)
  536. new_ips=$(echo "$ips"|sed -e "s/$ip//")
  537. sed -i "s/$ips/$new_ips/g" $rconf
  538. fi
  539. # Scheduling restart
  540. web_restart='yes'
  541. fi
  542. }
  543. upd_web_domain_values() {
  544. ip=$IP
  545. group="$user"
  546. email="$user@$domain"
  547. docroot="$V_HOME/$user/web/$domain/public_html"
  548. docroot_string="DocumentRoot $docroot"
  549. proxy_string="proxy_pass http://$ip:$WEB_PORT;"
  550. # Parsing domain aliases
  551. i=1
  552. j=1
  553. OLD_IFS="$IFS"
  554. IFS=','
  555. server_alias=''
  556. alias_string=''
  557. for dalias in $ALIAS; do
  558. dalias=$(idn -t --quiet -a $dalias)
  559. # Spliting ServerAlias lines
  560. check_8k="$server_alias $dalias"
  561. if [ "${#check_8k}" -ge '8100' ]; then
  562. if [ "$j" -eq 1 ]; then
  563. alias_string="ServerAlias $server_alias"
  564. else
  565. alias_string="$alias_string\n ServerAlias $server_alias"
  566. fi
  567. (( ++j))
  568. server_alias=''
  569. fi
  570. if [ "$i" -eq 1 ]; then
  571. aliases_idn="$dalias"
  572. server_alias="$dalias"
  573. alias_string="ServerAlias $server_alias"
  574. else
  575. aliases_idn="$aliases_idn,$dalias"
  576. server_alias="$server_alias $dalias"
  577. fi
  578. (( ++i))
  579. done
  580. if [ "$j" -gt 1 ]; then
  581. alias_string="$alias_string\n ServerAlias $server_alias"
  582. else
  583. alias_string="ServerAlias $server_alias"
  584. fi
  585. IFS=$OLD_IFS
  586. # Checking error log status
  587. if [ "$ELOG" = 'no' ]; then
  588. elog='#'
  589. else
  590. elog=''
  591. fi
  592. # Checking cgi
  593. if [ "$CGI" != 'yes' ]; then
  594. cgi='#'
  595. cgi_option='-ExecCGI'
  596. else
  597. cgi=''
  598. cgi_option='+ExecCGI'
  599. fi
  600. # Checking suspend
  601. if [ "$SUSPEND" = 'yes' ]; then
  602. docroot_string="Redirect / http://$url"
  603. proxy_string="rewrite ^(.*)\$ http://$url;"
  604. fi
  605. # Defining SSL vars
  606. ssl_cert="$V_HOME/$user/conf/$SSL_CERT.crt"
  607. ssl_key="$V_HOME/$user/conf/$SSL_CERT.key"
  608. case $SSL_HOME in
  609. single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
  610. same) docroot="$V_HOME/$user/web/$domain/public_html" ;;
  611. esac
  612. }