domain.func 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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_EXISTS $V_EVENT"
  20. exit $E_EXISTS
  21. fi
  22. return $E_EXISTS
  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_FORBIDEN $V_EVENT"
  39. exit $E_FORBIDEN
  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_EXISTS $V_EVENT"
  49. exit $E_EXISTS
  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_EXISTS $V_EVENT"
  66. exit $E_EXISTS
  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_NOTEXIST $V_EVENT"
  76. exit $E_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_NOTEXIST $V_EVENT"
  86. exit $E_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_SUSPENDED $V_EVENT"
  98. exit $E_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_UNSUSPENDED $V_EVENT"
  110. exit $E_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/dns/$domain
  165. }
  166. get_next_dns_record() {
  167. # Parsing config
  168. curr_str=$(grep "ID=" $V_USERS/$user/dns/$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/dns/$domain)
  176. if [ ! -z "$check_id" ]; then
  177. echo "Error: ID exist"
  178. log_event 'debug' "$E_EXISTS $V_EVENT"
  179. exit $E_EXISTS
  180. fi
  181. }
  182. sort_dns_records() {
  183. # Defining conf
  184. conf="$V_USERS/$user/dns/$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_crt%/${ssl_crt////\/}/g" \
  209. -e "s/%ssl_key%/${ssl_key////\/}/g" \
  210. -e "s/%ssl_pem%/${ssl_pem////\/}/g" \
  211. -e "s/%ssl_ca_str%/${ssl_ca_str////\/}/g" \
  212. -e "s/%nginx_extentions%/${NGINX_EXT//,/|}/g" \
  213. -e "s/%elog%/$elog/g" \
  214. -e "s/%cgi%/$cgi/g" \
  215. -e "s/%cgi_option%/$cgi_option/g" \
  216. >> $conf
  217. }
  218. get_web_config_brds() {
  219. # Defining template borders
  220. serv_line=$(grep -ni 'Name %domain_idn%' "$tpl_file" |cut -f 1 -d :)
  221. if [ -z "$serv_line" ]; then
  222. log_event 'debug' "$E_PARSING $V_EVENT"
  223. return $E_PARSING
  224. fi
  225. # Template lines
  226. last_line=$(wc -l $tpl_file|cut -f 1 -d ' ')
  227. bfr_line=$((serv_line - 1))
  228. aftr_line=$((last_line - serv_line - 1))
  229. # Config lines
  230. str=$(grep -ni "Name $domain_idn" $conf | cut -f 1 -d :)
  231. top_line=$((str - serv_line + 1))
  232. bottom_line=$((top_line + last_line -1))
  233. # Check for multialias (8k alias issue)
  234. multi=$(sed -n "$top_line,$bottom_line p" $conf |grep ServerAlias |wc -l)
  235. if [ "$multi" -ge 2 ]; then
  236. bottom_line=$((bottom_line + multi -1))
  237. fi
  238. }
  239. change_web_config() {
  240. # Get config borders
  241. get_web_config_brds || exit $?
  242. # Parsing config
  243. vhost=$(grep -A $aftr_line -B $bfr_line -ni "Name $domain_idn" $conf)
  244. str=$(echo "$vhost" | grep -F "$search_phrase" | head -n 1)
  245. # Parsing string position and content
  246. str_numb=$(echo "$str" | sed -e "s/-/=/" | cut -f 1 -d '=')
  247. str_cont=$(echo "$str" | sed -e "s/-/=/" | cut -f 2 -d '=')
  248. # Escaping chars
  249. str_repl=$(echo "$str_repl" | sed \
  250. -e 's/\\/\\\\/g' \
  251. -e 's/&/\\&/g' \
  252. -e 's/\//\\\//g')
  253. # Changing config
  254. if [ ! -z "$str" ]; then
  255. sed -i "$str_numb s/.*/$str_repl/" $conf
  256. fi
  257. }
  258. replace_web_config() {
  259. # Get config borders
  260. get_web_config_brds || exit $?
  261. # Escaping chars
  262. clean_new=$(echo "$new" | sed \
  263. -e 's/\\/\\\\/g' \
  264. -e 's/&/\\&/g' \
  265. -e 's/\//\\\//g')
  266. clean_old=$(echo "$old" | sed \
  267. -e 's/\\/\\\\/g' \
  268. -e 's/&/\\&/g' \
  269. -e 's/\//\\\//g')
  270. # Replacing string in config
  271. sed -i "$top_line,$bottom_line s/$clean_old/$clean_new/" $conf
  272. }
  273. get_web_domain_value() {
  274. key="$1"
  275. # Parsing domains
  276. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/web.conf )
  277. # Parsing key=value
  278. for keys in $string; do
  279. eval ${keys%%=*}=${keys#*=}
  280. done
  281. # Self reference
  282. eval value="$key"
  283. # Print value
  284. echo "$value"
  285. }
  286. get_web_domain_values() {
  287. # Defining domain parameters
  288. for line in $(grep "DOMAIN='$domain'" $V_USERS/$user/web.conf); do
  289. # Assing key=value
  290. for key in $line; do
  291. eval ${key%%=*}=${key#*=}
  292. done
  293. done
  294. }
  295. get_dns_domain_value() {
  296. key="$1"
  297. # Parsing domains
  298. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/dns.conf )
  299. # Parsing key=value
  300. for keys in $string; do
  301. eval ${keys%%=*}=${keys#*=}
  302. done
  303. # Self reference
  304. eval value="$key"
  305. # Print value
  306. echo "$value"
  307. }
  308. update_web_domain_value() {
  309. key="$1"
  310. value="$2"
  311. # Defining conf
  312. conf="$V_USERS/$user/web.conf"
  313. # Parsing conf
  314. domain_str=$(grep -n "DOMAIN='$domain'" $conf)
  315. str_number=$(echo $domain_str | cut -f 1 -d ':')
  316. str=$(echo $domain_str | cut -f 2 -d ':')
  317. # Reading key=values
  318. for keys in $str; do
  319. eval ${keys%%=*}=${keys#*=}
  320. done
  321. # Defining clean key
  322. c_key=$(echo "${key//$/}")
  323. eval old="${key}"
  324. # Escaping slashes
  325. old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  326. new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  327. # Updating conf
  328. sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\
  329. $conf
  330. }
  331. update_dns_domain_value() {
  332. key="$1"
  333. value="$2"
  334. # Defining conf
  335. conf="$V_USERS/$user/dns.conf"
  336. # Parsing conf
  337. domain_str=$(grep -n "DOMAIN='$domain'" $conf)
  338. str_number=$(echo $domain_str | cut -f 1 -d ':')
  339. str=$(echo $domain_str | cut -f 2 -d ':')
  340. # Reading key=values
  341. for keys in $str; do
  342. eval ${keys%%=*}=${keys#*=}
  343. done
  344. # Defining clean key
  345. c_key=$(echo "${key//$/}")
  346. eval old="${key}"
  347. # Escaping slashes
  348. old=$(echo "$old" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  349. new=$(echo "$value" | sed -e 's/\\/\\\\/g' -e 's/&/\\&/g' -e 's/\//\\\//g')
  350. # Updating conf
  351. sed -i "$str_number s/$c_key='${old//\*/\\*}'/$c_key='${new//\*/\\*}'/g"\
  352. $conf
  353. }
  354. is_web_domain_key_empty() {
  355. key="$1"
  356. # Parsing domains
  357. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/web.conf )
  358. # Parsing key=value
  359. for keys in $string; do
  360. eval ${keys%%=*}=${keys#*=}
  361. done
  362. # Self reference
  363. eval value="$key"
  364. # Checkng key
  365. if [ ! -z "$value" ] && [ "$value" != 'no' ]; then
  366. echo "Error: value is not empty = $value"
  367. log_event 'debug' "$E_EXISTS $V_EVENT"
  368. exit $E_EXISTS
  369. fi
  370. }
  371. is_web_domain_cert_valid() {
  372. # Checking file existance
  373. if [ ! -e "$ssl_dir/$domain.crt" ] || [ ! -e "$ssl_dir/$domain.key" ]; then
  374. echo "Error: ssl certificate not exist"
  375. log_event 'debug' "$E_NOTEXIST $V_EVENT"
  376. exit $E_NOTEXIST
  377. fi
  378. # Checking certificate
  379. crt=$(openssl verify $ssl_dir/$domain.crt 2>/dev/null |grep '/C=')
  380. if [ -z "$crt" ]; then
  381. echo "Error: ssl certificate invalid"
  382. log_event 'debug' "$E_INVALID $V_EVENT"
  383. exit $E_INVALID
  384. fi
  385. # Checking certificate key
  386. openssl rsa -in "$ssl_dir/$domain.key" -check >/dev/null 2>/dev/null
  387. if [ "$?" -ne 0 ]; then
  388. echo "Error: ssl key invalid"
  389. log_event 'debug' "$E_INVALID $V_EVENT"
  390. exit $E_INVALID
  391. fi
  392. # Checking certificate authority
  393. if [ -e "$ssl_dir/$domain.ca" ]; then
  394. ca=$(openssl verify $ssl_dir/$domain.ca 2>/dev/null |grep '/C=')
  395. if [ -z "$ca" ]; then
  396. echo "Error: ssl certificate invalid"
  397. log_event 'debug' "$E_INVALID $V_EVENT"
  398. exit $E_INVALID
  399. fi
  400. fi
  401. # Checking server
  402. openssl s_server -quiet \
  403. -cert $ssl_dir/$domain.crt -key $ssl_dir/$domain.key &
  404. pid=$!
  405. sleep 1
  406. disown > /dev/null 2>&1
  407. kill $pid > /dev/null 2>&1
  408. result=$?
  409. if [ "$result" -ne '0' ]; then
  410. echo "Error: ssl certificate key pair invalid"
  411. log_event 'debug' "$E_INVALID $V_EVENT"
  412. exit $E_INVALID
  413. fi
  414. }
  415. is_dns_record_valid() {
  416. # Checking record id
  417. check_id=$(grep "^ID='$id'" $V_USERS/$user/dns/$domain)
  418. if [ -z "$check_id" ]; then
  419. echo "Error: ID not exist"
  420. log_event 'debug' "$E_NOTEXIST $V_EVENT"
  421. exit $E_NOTEXIST
  422. fi
  423. }
  424. is_web_domain_value_exist() {
  425. key="$1"
  426. # Parsing domains
  427. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/web.conf )
  428. # Parsing key=value
  429. for keys in $string; do
  430. eval ${keys%%=*}=${keys#*=}
  431. done
  432. # Self reference
  433. eval value="$key"
  434. # Checking result
  435. if [ -z "$value" ] || [ "$value" = 'no' ]; then
  436. echo "Error: ${key//$/} is empty"
  437. log_event 'debug' "$E_NOTEXIST $V_EVENT"
  438. exit $E_NOTEXIST
  439. fi
  440. }
  441. is_dns_domain_value_exist() {
  442. key="$1"
  443. # Parsing domains
  444. string=$( grep "DOMAIN='$domain'" $V_USERS/$user/dns.conf )
  445. # Parsing key=value
  446. for keys in $string; do
  447. eval ${keys%%=*}=${keys#*=}
  448. done
  449. # Self reference
  450. eval value="$key"
  451. # Checking result
  452. if [ -z "$value" ] || [ "$value" = 'no' ]; then
  453. echo "Error: ${key//$/} is empty"
  454. log_event 'debug' "$E_NOTEXIST $V_EVENT"
  455. exit $E_EXISTS
  456. fi
  457. }
  458. del_web_config() {
  459. # Get config borders
  460. get_web_config_brds || exit $?
  461. # Deleting lines from config
  462. sed -i "$top_line,$bottom_line d" $conf
  463. }
  464. del_dns_domain() {
  465. conf="$V_USERS/$user/dns.conf"
  466. # Parsing domains
  467. string=$( grep -n "DOMAIN='$domain'" $conf | cut -f 1 -d : )
  468. if [ -z "$string" ]; then
  469. echo "Error: parse error"
  470. log_event 'debug' "$E_PARSING $V_EVENT"
  471. exit $E_PARSING
  472. fi
  473. sed -i "$string d" $conf
  474. rm -f $V_USERS/$user/dns/$domain
  475. }
  476. del_web_domain() {
  477. conf="$V_USERS/$user/web.conf"
  478. # Parsing domains
  479. string=$( grep -n "DOMAIN='$domain'" $conf | cut -f 1 -d : )
  480. if [ -z "$string" ]; then
  481. echo "Error: parse error"
  482. log_event 'debug' "$E_PARSING $V_EVENT"
  483. exit $E_PARSING
  484. fi
  485. sed -i "$string d" $conf
  486. }
  487. dom_clear_search(){
  488. # Defining delimeter
  489. IFS=$'\n'
  490. # Reading file line by line
  491. for line in $(grep $search_string $conf); do
  492. # Parsing key=val
  493. for key in $line; do
  494. eval ${key%%=*}=${key#*=}
  495. done
  496. # Print result line
  497. eval echo "$field"
  498. done
  499. }
  500. dom_clear_list() {
  501. # Reading file line by line
  502. while read line ; do
  503. # Parsing key=value
  504. for key in $line; do
  505. eval ${key%%=*}=${key#*=}
  506. done
  507. # Print result line
  508. eval echo "$field"
  509. done < $conf
  510. }
  511. namehost_ip_support() {
  512. #Checking web system
  513. if [ "$WEB_SYSTEM" = 'apache' ]; then
  514. # Checking httpd config for NameHost string number
  515. conf_line=$(grep -n "NameVirtual" $conf|tail -n 1|cut -f 1 -d ':')
  516. if [ ! -z "$conf_line" ]; then
  517. conf_ins=$((conf_line + 1)) # inster into next line
  518. else
  519. conf_ins='1' # insert into first line
  520. fi
  521. # Checking ssl support
  522. if [ "$WEB_SSL" = 'mod_ssl' ]; then
  523. web_ssl_port=$(get_config_value '$WEB_SSL_PORT')
  524. sed -i "$conf_ins i NameVirtualHost $ip:$web_ssl_port" $conf
  525. sed -i "$conf_ins i Listen $ip:$web_ssl_port" $conf
  526. fi
  527. web_port=$(get_config_value '$WEB_PORT')
  528. sed -i "$conf_ins i NameVirtualHost $ip:$web_port" $conf
  529. sed -i "$conf_ins i Listen $ip:$web_port" $conf
  530. # Checking proxy support
  531. if [ "$PROXY_SYSTEM" = 'nginx' ]; then
  532. proxy_port=$(get_config_value '$PROXY_PORT')
  533. cat $V_WEBTPL/ngingx_ip.tpl | sed -e "s/%ip%/$ip/g" \
  534. -e "s/%web_port%/$web_port/g" -e "s/%proxy_port%/$proxy_port/g" >>$nconf
  535. # Adding to rpaf ip pool as well
  536. ips=$(grep 'RPAFproxy_ips' $rconf)
  537. sed -i "s/$ips/$ips $ip/g" $rconf
  538. fi
  539. # Scheduling restart
  540. web_restart='yes'
  541. fi
  542. }
  543. namehost_ip_disable() {
  544. #Checking web system
  545. if [ "$WEB_SYSTEM" = 'apache' ]; then
  546. sed -i "/NameVirtualHost $ip:/d" $conf
  547. sed -i "/Listen $ip:/d" $conf
  548. # Checking proxy support
  549. if [ "$PROXY_SYSTEM" = 'nginx' ]; then
  550. tpl_ln=$(wc -l $V_WEBTPL/ngingx_ip.tpl | cut -f 1 -d ' ')
  551. ip_line=$(grep -n "%ip%" $V_WEBTPL/ngingx_ip.tpl |head -n1 |\
  552. cut -f 1 -d :)
  553. conf_line=$(grep -n -w $ip $nconf|head -n1|cut -f 1 -d :)
  554. # Checking parsed lines
  555. if [ -z "$tpl_ln" ] || [ -z "$ip_line" ] || [ -z "$conf_line" ]
  556. then
  557. echo "Error: nginx config paring error"
  558. log_event 'debug' "$E_PARSING $V_EVENT"
  559. exit $E_PARSING
  560. fi
  561. up_line=$((ip_line - 1))
  562. first_line=$((conf_line - up_line))
  563. last_line=$((conf_line - ip_line + tpl_ln))
  564. # Checking parsed lines
  565. if [ -z "$first_line" ] || [ -z "$last_line" ]; then
  566. echo "Error: nginx config paring error"
  567. log_event 'debug' "$E_PARSING $V_EVENT"
  568. exit $E_PARSING
  569. fi
  570. sed -i "$first_line,$last_line d" $nconf
  571. # Deleting from rpaf ip pool as well
  572. ips=$(grep 'RPAFproxy_ips' $rconf)
  573. new_ips=$(echo "$ips"|sed -e "s/$ip//")
  574. sed -i "s/$ips/$new_ips/g" $rconf
  575. fi
  576. # Scheduling restart
  577. web_restart='yes'
  578. fi
  579. }
  580. upd_web_domain_values() {
  581. ip=$IP
  582. group="$user"
  583. email="$user@$domain"
  584. docroot="$V_HOME/$user/web/$domain/public_html"
  585. docroot_string="DocumentRoot $docroot"
  586. proxy_string="proxy_pass http://$ip:$WEB_PORT;"
  587. # Parsing domain aliases
  588. i=1
  589. j=1
  590. OLD_IFS="$IFS"
  591. IFS=','
  592. server_alias=''
  593. alias_string=''
  594. for dalias in $ALIAS; do
  595. dalias=$(idn -t --quiet -a $dalias)
  596. # Spliting ServerAlias lines
  597. check_8k="$server_alias $dalias"
  598. if [ "${#check_8k}" -ge '8100' ]; then
  599. if [ "$j" -eq 1 ]; then
  600. alias_string="ServerAlias $server_alias"
  601. else
  602. alias_string="$alias_string\n ServerAlias $server_alias"
  603. fi
  604. j=2
  605. server_alias=''
  606. fi
  607. if [ "$i" -eq 1 ]; then
  608. aliases_idn="$dalias"
  609. server_alias="$dalias"
  610. alias_string="ServerAlias $server_alias"
  611. else
  612. aliases_idn="$aliases_idn,$dalias"
  613. server_alias="$server_alias $dalias"
  614. fi
  615. i=2
  616. done
  617. if [ $j -gt 1 ]; then
  618. alias_string="$alias_string\n ServerAlias $server_alias"
  619. else
  620. alias_string="ServerAlias $server_alias"
  621. fi
  622. IFS=$OLD_IFS
  623. # Checking error log status
  624. if [ "$ELOG" = 'no' ]; then
  625. elog='#'
  626. else
  627. elog=''
  628. fi
  629. # Checking cgi
  630. if [ "$CGI" != 'yes' ]; then
  631. cgi='#'
  632. cgi_option='-ExecCGI'
  633. else
  634. cgi=''
  635. cgi_option='+ExecCGI'
  636. fi
  637. # Checking suspend
  638. if [ "$SUSPEND" = 'yes' ]; then
  639. docroot_string="Redirect / http://$url"
  640. proxy_string="rewrite ^(.*)\$ http://$url;"
  641. fi
  642. # Defining SSL vars
  643. ssl_crt="$V_HOME/$user/conf/ssl.$domain.crt"
  644. ssl_key="$V_HOME/$user/conf/ssl.$domain.key"
  645. ssl_pem="$V_HOME/$user/conf/ssl.$domain.pem"
  646. ssl_ca="$V_HOME/$user/conf/ssl.$domain.ca"
  647. if [ ! -e "$V_USERS/$user/ssl/$domain.ca" ]; then
  648. ssl_ca_str='#'
  649. fi
  650. case $SSL_HOME in
  651. single) docroot="$V_HOME/$user/web/$domain/public_shtml" ;;
  652. same) docroot="$V_HOME/$user/web/$domain/public_html" ;;
  653. esac
  654. }