1
0

vhost.sh 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  15. # For more information please visit https://oneinstack.com #
  16. #######################################################################
  17. "
  18. # Check if user is root
  19. [ $(id -u) != '0' ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  20. oneinstack_dir=$(dirname "`readlink -f $0`")
  21. pushd ${oneinstack_dir} > /dev/null
  22. . ./options.conf
  23. . ./include/color.sh
  24. . ./include/check_dir.sh
  25. . ./include/check_os.sh
  26. . ./include/get_char.sh
  27. Show_Help() {
  28. echo
  29. echo "Usage: $0 command ...[parameters]....
  30. --help, -h Show this help message
  31. --quiet, -q quiet operation
  32. --list, -l List Virtualhost
  33. --mphp_ver [53~73] Use another PHP version (PATH: /usr/local/php${mphp_ver})
  34. --add Add Virtualhost
  35. --delete, --del Delete Virtualhost
  36. --httponly Use HTTP Only
  37. --selfsigned Use your own SSL Certificate and Key
  38. --letsencrypt Use Let's Encrypt to Create SSL Certificate and Key
  39. --dnsapi Use dns API to automatically issue Let's Encrypt Cert
  40. "
  41. }
  42. ARG_NUM=$#
  43. TEMP=`getopt -o hql --long help,quiet,list,mphp_ver:,add,delete,del,httponly,selfsigned,letsencrypt,dnsapi -- "$@" 2>/dev/null`
  44. [ $? != 0 ] && echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  45. eval set -- "${TEMP}"
  46. while :; do
  47. [ -z "$1" ] && break;
  48. case "$1" in
  49. -h|--help)
  50. Show_Help; exit 0
  51. ;;
  52. -q|--quiet)
  53. quiet_flag=y; shift 1
  54. ;;
  55. -l|--list)
  56. list_flag=y; shift 1
  57. ;;
  58. --mphp_ver)
  59. mphp_ver=$2; mphp_flag=y; shift 2
  60. [[ ! "${mphp_ver}" =~ ^5[3-6]$|^7[0-3]$ ]] && { echo "${CWARNING}mphp_ver input error! Please only input number 53~73${CEND}"; unset mphp_ver mphp_flag; }
  61. ;;
  62. --add)
  63. add_flag=y; shift 1
  64. ;;
  65. --delete|--del)
  66. delete_flag=y; shift 1
  67. ;;
  68. --httponly)
  69. sslquiet_flag=y
  70. httponly_flag=y
  71. Domian_Mode=1
  72. shift 1
  73. ;;
  74. --selfsigned)
  75. sslquiet_flag=y
  76. selfsigned_flag=y
  77. Domian_Mode=2
  78. shift 1
  79. ;;
  80. --letsencrypt)
  81. sslquiet_flag=y
  82. letsencrypt_flag=y
  83. Domian_Mode=3
  84. shift 1
  85. ;;
  86. --dnsapi)
  87. sslquiet_flag=y
  88. dnsapi_flag=y
  89. letsencrypt_flag=y
  90. shift 1
  91. ;;
  92. --)
  93. shift
  94. ;;
  95. *)
  96. echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
  97. ;;
  98. esac
  99. done
  100. Choose_ENV() {
  101. if [ -e "${apache_install_dir}/bin/apachectl" ];then
  102. [ "$(${apache_install_dir}/bin/apachectl -v | awk -F'.' /version/'{print $2}')" == '4' ] && { Apache_main_ver=24; Apache_grant='Require all granted'; }
  103. [ "$(${apache_install_dir}/bin/apachectl -v | awk -F'.' /version/'{print $2}')" == '2' ] && Apache_main_ver=22
  104. fi
  105. if [ -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  106. Number=111
  107. while :; do echo
  108. echo "Please choose to use environment:"
  109. echo -e "\t${CMSG}1${CEND}. Use php"
  110. echo -e "\t${CMSG}2${CEND}. Use java"
  111. echo -e "\t${CMSG}3${CEND}. Use hhvm"
  112. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  113. ENV_FLAG=${ENV_FLAG:-1}
  114. if [[ ! ${ENV_FLAG} =~ ^[1-3]$ ]]; then
  115. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  116. else
  117. break
  118. fi
  119. done
  120. case "${ENV_FLAG}" in
  121. 1)
  122. NGX_FLAG=php
  123. ;;
  124. 2)
  125. NGX_FLAG=java
  126. ;;
  127. 3)
  128. NGX_FLAG=hhvm
  129. ;;
  130. esac
  131. elif [ -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a ! -e "/usr/bin/hhvm" ]; then
  132. Number=110
  133. while :; do echo
  134. echo "Please choose to use environment:"
  135. echo -e "\t${CMSG}1${CEND}. Use php"
  136. echo -e "\t${CMSG}2${CEND}. Use java"
  137. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  138. ENV_FLAG=${ENV_FLAG:-1}
  139. if [[ ! ${ENV_FLAG} =~ ^[1-2]$ ]]; then
  140. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  141. else
  142. break
  143. fi
  144. done
  145. [ "${ENV_FLAG}" == '1' ] && NGX_FLAG=php
  146. [ "${ENV_FLAG}" == '2' ] && NGX_FLAG=java
  147. elif [ -e "${php_install_dir}/bin/phpize" -a ! -e "${tomcat_install_dir}/conf/server.xml" -a ! -e "/usr/bin/hhvm" ]; then
  148. Number=100
  149. NGX_FLAG=php
  150. elif [ -e "${php_install_dir}/bin/phpize" -a ! -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  151. Number=101
  152. while :; do echo
  153. echo "Please choose to use environment:"
  154. echo -e "\t${CMSG}1${CEND}. Use php"
  155. echo -e "\t${CMSG}2${CEND}. Use hhvm"
  156. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  157. ENV_FLAG=${ENV_FLAG:-1}
  158. if [[ ! ${ENV_FLAG} =~ ^[1-2]$ ]]; then
  159. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  160. else
  161. break
  162. fi
  163. done
  164. [ "${ENV_FLAG}" == '1' ] && NGX_FLAG=php
  165. [ "${ENV_FLAG}" == '2' ] && NGX_FLAG=hhvm
  166. elif [ ! -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  167. Number=011
  168. while :; do echo
  169. echo "Please choose to use environment:"
  170. echo -e "\t${CMSG}1${CEND}. Use java"
  171. echo -e "\t${CMSG}2${CEND}. Use hhvm"
  172. read -e -p "Please input a number:(Default 1 press Enter) " ENV_FLAG
  173. ENV_FLAG=${ENV_FLAG:-1}
  174. if [[ ! ${ENV_FLAG} =~ ^[1-2]$ ]]; then
  175. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  176. else
  177. break
  178. fi
  179. done
  180. [ "${ENV_FLAG}" == '1' ] && NGX_FLAG=java
  181. [ "${ENV_FLAG}" == '2' ] && NGX_FLAG=hhvm
  182. elif [ ! -e "${php_install_dir}/bin/phpize" -a -e "${tomcat_install_dir}/conf/server.xml" -a ! -e "/usr/bin/hhvm" ]; then
  183. Number=010
  184. NGX_FLAG=java
  185. elif [ ! -e "${php_install_dir}/bin/phpize" -a ! -e "${tomcat_install_dir}/conf/server.xml" -a -e "/usr/bin/hhvm" ]; then
  186. Number=001
  187. NGX_FLAG=hhvm
  188. else
  189. Number=000
  190. NGX_FLAG=php
  191. fi
  192. }
  193. Create_SSL() {
  194. if [ "${Domian_Mode}" == '2' ]; then
  195. printf "
  196. You are about to be asked to enter information that will be incorporated
  197. into your certificate request.
  198. What you are about to enter is what is called a Distinguished Name or a DN.
  199. There are quite a few fields but you can leave some blank
  200. For some fields there will be a default value,
  201. If you enter '.', the field will be left blank.
  202. "
  203. echo
  204. read -e -p "Country Name (2 letter code) [CN]: " SELFSIGNEDSSL_C
  205. SELFSIGNEDSSL_C=${SELFSIGNEDSSL_C:-CN}
  206. [ ${#SELFSIGNEDSSL_C} != 2 ] && { echo "${CWARNING}input error, You must input 2 letter code country name${CEND}"; continue; }
  207. echo
  208. read -e -p "State or Province Name (full name) [Shanghai]: " SELFSIGNEDSSL_ST
  209. SELFSIGNEDSSL_ST=${SELFSIGNEDSSL_ST:-Shanghai}
  210. echo
  211. read -e -p "Locality Name (eg, city) [Shanghai]: " SELFSIGNEDSSL_L
  212. SELFSIGNEDSSL_L=${SELFSIGNEDSSL_L:-Shanghai}
  213. echo
  214. read -e -p "Organization Name (eg, company) [Example Inc.]: " SELFSIGNEDSSL_O
  215. SELFSIGNEDSSL_O=${SELFSIGNEDSSL_O:-"Example Inc."}
  216. echo
  217. read -e -p "Organizational Unit Name (eg, section) [IT Dept.]: " SELFSIGNEDSSL_OU
  218. SELFSIGNEDSSL_OU=${SELFSIGNEDSSL_OU:-"IT Dept."}
  219. openssl req -utf8 -new -newkey rsa:2048 -sha256 -nodes -out ${PATH_SSL}/${domain}.csr -keyout ${PATH_SSL}/${domain}.key -subj "/C=${SELFSIGNEDSSL_C}/ST=${SELFSIGNEDSSL_ST}/L=${SELFSIGNEDSSL_L}/O=${SELFSIGNEDSSL_O}/OU=${SELFSIGNEDSSL_OU}/CN=${domain}" > /dev/null 2>&1
  220. openssl x509 -req -days 36500 -sha256 -in ${PATH_SSL}/${domain}.csr -signkey ${PATH_SSL}/${domain}.key -out ${PATH_SSL}/${domain}.crt > /dev/null 2>&1
  221. elif [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ]; then
  222. if [ "${moredomain}" == "*.${domain}" -o "${dnsapi_flag}" == 'y' ]; then
  223. while :; do echo
  224. echo 'Please select DNS provider:'
  225. echo "${CMSG}dp${CEND},${CMSG}cx${CEND},${CMSG}ali${CEND},${CMSG}cf${CEND},${CMSG}aws${CEND},${CMSG}linode${CEND},${CMSG}he${CEND},${CMSG}namesilo${CEND},${CMSG}dgon${CEND},${CMSG}freedns${CEND},${CMSG}gd${CEND},${CMSG}namecom${CEND} and so on."
  226. echo "${CMSG}More: https://oneinstack.com/faq/letsencrypt${CEND}"
  227. read -e -p "Please enter your DNS provider: " DNS_PRO
  228. if [ -e ~/.acme.sh/dnsapi/dns_${DNS_PRO}.sh ]; then
  229. break
  230. else
  231. echo "${CWARNING}You DNS api mode is not supported${CEND}"
  232. fi
  233. done
  234. while :; do echo
  235. echo "Syntax: export Key1=Value1 ; export Key2=Value1"
  236. read -e -p "Please enter your dnsapi parameters: " DNS_PAR
  237. echo
  238. eval ${DNS_PAR}
  239. if [ $? == 0 ]; then
  240. break
  241. else
  242. echo "${CWARNING}Syntax error! PS: export Ali_Key=LTq ; export Ali_Secret=0q5E${CEND}"
  243. fi
  244. done
  245. [ "${moredomainame_flag}" == 'y' ] && moredomainame_D="$(for D in ${moredomainame}; do echo -d ${D}; done)"
  246. ~/.acme.sh/acme.sh --force --issue --dns dns_${DNS_PRO} -d ${domain} ${moredomainame_D}
  247. else
  248. if [ "${nginx_ssl_flag}" == 'y' ]; then
  249. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  250. echo "server { server_name ${domain}${moredomainame}; root ${vhostdir}; access_log off; }" > ${web_install_dir}/conf/vhost/${domain}.conf
  251. ${web_install_dir}/sbin/nginx -s reload
  252. fi
  253. if [ "${apache_ssl_flag}" == 'y' ]; then
  254. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  255. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  256. <VirtualHost *:80>
  257. ServerAdmin admin@example.com
  258. DocumentRoot "${vhostdir}"
  259. ServerName ${domain}
  260. ${Apache_Domain_alias}
  261. <Directory "${vhostdir}">
  262. SetOutputFilter DEFLATE
  263. Options FollowSymLinks ExecCGI
  264. ${Apache_grant}
  265. AllowOverride All
  266. Order allow,deny
  267. Allow from all
  268. DirectoryIndex index.html index.php
  269. </Directory>
  270. </VirtualHost>
  271. EOF
  272. ${apache_install_dir}/bin/apachectl -k graceful
  273. fi
  274. auth_file="`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`".html
  275. auth_str='oneinstack'; echo ${auth_str} > ${vhostdir}/${auth_file}
  276. for D in ${domain} ${moredomainame}
  277. do
  278. curl_str=`curl --connect-timeout 30 -4 -s $D/${auth_file} 2>&1`
  279. [ "${curl_str}" != "${auth_str}" ] && { echo; echo "${CFAILURE}Let's Encrypt Verify error! DNS problem: NXDOMAIN looking up A for ${D}${CEND}"; }
  280. done
  281. rm -f ${vhostdir}/${auth_file}
  282. [ "${moredomainame_flag}" == 'y' ] && moredomainame_D="$(for D in ${moredomainame}; do echo -d ${D}; done)"
  283. ~/.acme.sh/acme.sh --force --issue -d ${domain} ${moredomainame_D} -w ${vhostdir}
  284. fi
  285. if [ -s ~/.acme.sh/${domain}/fullchain.cer ]; then
  286. [ -e "${PATH_SSL}/${domain}.crt" ] && rm -f ${PATH_SSL}/${domain}.{crt,key}
  287. [ -e /bin/systemctl -a -e /lib/systemd/system/nginx.service ] && Nginx_cmd='/bin/systemctl restart nginx' || Nginx_cmd='/etc/init.d/nginx force-reload'
  288. Apache_cmd="${apache_install_dir}/bin/apachectl -k graceful"
  289. if [ -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  290. Command="${Nginx_cmd};${Apache_cmd}"
  291. elif [ -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" ]; then
  292. Command="${Nginx_cmd}"
  293. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  294. Command="${Apache_cmd}"
  295. fi
  296. ~/.acme.sh/acme.sh --force --install-cert -d ${domain} --fullchain-file ${PATH_SSL}/${domain}.crt --key-file ${PATH_SSL}/${domain}.key --reloadcmd "${Command}" > /dev/null
  297. else
  298. echo "${CFAILURE}Error: Create Let's Encrypt SSL Certificate failed! ${CEND}"
  299. [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ] && rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  300. [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ] && rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  301. exit 1
  302. fi
  303. fi
  304. }
  305. Print_SSL() {
  306. if [ "${Domian_Mode}" == '2' ]; then
  307. echo "$(printf "%-30s" "Self-signed SSL Certificate:")${CMSG}${PATH_SSL}/${domain}.crt${CEND}"
  308. echo "$(printf "%-30s" "SSL Private Key:")${CMSG}${PATH_SSL}/${domain}.key${CEND}"
  309. echo "$(printf "%-30s" "SSL CSR File:")${CMSG}${PATH_SSL}/${domain}.csr${CEND}"
  310. elif [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ]; then
  311. echo "$(printf "%-30s" "Let's Encrypt SSL Certificate:")${CMSG}${PATH_SSL}/${domain}.crt${CEND}"
  312. echo "$(printf "%-30s" "SSL Private Key:")${CMSG}${PATH_SSL}/${domain}.key${CEND}"
  313. fi
  314. }
  315. Input_Add_domain() {
  316. if [ "${sslquiet_flag}" != 'y' ]; then
  317. while :;do
  318. printf "
  319. What Are You Doing?
  320. \t${CMSG}1${CEND}. Use HTTP Only
  321. \t${CMSG}2${CEND}. Use your own SSL Certificate and Key
  322. \t${CMSG}3${CEND}. Use Let's Encrypt to Create SSL Certificate and Key
  323. \t${CMSG}q${CEND}. Exit
  324. "
  325. read -e -p "Please input the correct option: " Domian_Mode
  326. if [[ ! "${Domian_Mode}" =~ ^[1-3,q]$ ]]; then
  327. echo "${CFAILURE}input error! Please only input 1~3 and q${CEND}"
  328. else
  329. break
  330. fi
  331. done
  332. fi
  333. #Multiple_PHP
  334. if [ $(ls /dev/shm/php*-cgi.sock 2> /dev/null | wc -l) -ge 2 ]; then
  335. if [ "${mphp_flag}" != 'y' ]; then
  336. PHP_detail_ver=`${php_install_dir}/bin/php-config --version`
  337. PHP_main_ver=${PHP_detail_ver%.*}
  338. while :; do echo
  339. echo 'Please select a version of the PHP:'
  340. echo -e "\t${CMSG}1${CEND}. PHP ${PHP_main_ver} (default)"
  341. [ -e "/dev/shm/php53-cgi.sock" ] && echo -e "\t${CMSG}2${CEND}. PHP 5.3"
  342. [ -e "/dev/shm/php54-cgi.sock" ] && echo -e "\t${CMSG}3${CEND}. PHP 5.4"
  343. [ -e "/dev/shm/php55-cgi.sock" ] && echo -e "\t${CMSG}4${CEND}. PHP 5.5"
  344. [ -e "/dev/shm/php56-cgi.sock" ] && echo -e "\t${CMSG}5${CEND}. PHP 5.6"
  345. [ -e "/dev/shm/php70-cgi.sock" ] && echo -e "\t${CMSG}6${CEND}. PHP 7.0"
  346. [ -e "/dev/shm/php71-cgi.sock" ] && echo -e "\t${CMSG}7${CEND}. PHP 7.1"
  347. [ -e "/dev/shm/php72-cgi.sock" ] && echo -e "\t${CMSG}8${CEND}. PHP 7.2"
  348. [ -e "/dev/shm/php73-cgi.sock" ] && echo -e "\t${CMSG}9${CEND}. PHP 7.3"
  349. read -e -p "Please input a number:(Default 1 press Enter) " php_option
  350. php_option=${php_option:-1}
  351. if [[ ! ${php_option} =~ ^[1-9]$ ]]; then
  352. echo "${CWARNING}input error! Please only input number 1~9${CEND}"
  353. else
  354. break
  355. fi
  356. done
  357. fi
  358. [ "${php_option}" == '2' ] && mphp_ver=53
  359. [ "${php_option}" == '3' ] && mphp_ver=54
  360. [ "${php_option}" == '4' ] && mphp_ver=55
  361. [ "${php_option}" == '5' ] && mphp_ver=56
  362. [ "${php_option}" == '6' ] && mphp_ver=70
  363. [ "${php_option}" == '7' ] && mphp_ver=71
  364. [ "${php_option}" == '8' ] && mphp_ver=72
  365. [ "${php_option}" == '9' ] && mphp_ver=73
  366. [ ! -e "/dev/shm/php${mphp_ver}-cgi.sock" ] && unset mphp_ver
  367. fi
  368. case "${NGX_FLAG}" in
  369. "php")
  370. NGX_CONF=$(echo -e "location ~ [^/]\.php(/|$) {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n }")
  371. ;;
  372. "java")
  373. NGX_CONF=$(echo -e "location ~ {\n proxy_pass http://127.0.0.1:8080;\n include proxy.conf;\n }")
  374. ;;
  375. "hhvm")
  376. NGX_CONF=$(echo -e "location ~ .*\.(php|php5)?$ {\n fastcgi_pass unix:/var/log/hhvm/sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;\n include fastcgi_params;\n }")
  377. ;;
  378. esac
  379. if [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ] && [ ! -e ~/.acme.sh/acme.sh ]; then
  380. pushd ${oneinstack_dir}/src > /dev/null
  381. [ ! -e acme.sh-master.tar.gz ] && wget -qc http://mirrors.linuxeye.com/oneinstack/src/acme.sh-master.tar.gz
  382. tar xzf acme.sh-master.tar.gz
  383. pushd acme.sh-master > /dev/null
  384. ./acme.sh --install > /dev/null 2>&1
  385. popd > /dev/null
  386. popd > /dev/null
  387. fi
  388. [ -e ~/.acme.sh/account.conf ] && sed -i '/^CERT_HOME=/d' ~/.acme.sh/account.conf
  389. if [[ "${Domian_Mode}" =~ ^[2-3]$ ]] || [ "${dnsapi_flag}" == 'y' ]; then
  390. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  391. nginx_ssl_flag=y
  392. PATH_SSL=${web_install_dir}/conf/ssl
  393. [ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
  394. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  395. apache_ssl_flag=y
  396. PATH_SSL=${apache_install_dir}/conf/ssl
  397. [ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
  398. fi
  399. elif [ "${Domian_Mode}" == 'q' ]; then
  400. exit 1
  401. fi
  402. while :; do echo
  403. read -e -p "Please input domain(example: www.example.com): " domain
  404. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  405. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  406. else
  407. break
  408. fi
  409. done
  410. if [ -e "${web_install_dir}/conf/vhost/${domain}.conf" -o -e "${apache_install_dir}/conf/vhost/${domain}.conf" -o -e "${tomcat_install_dir}/conf/vhost/${domain}.xml" ]; then
  411. [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ] && echo -e "${domain} in the Nginx/Tengine/OpenResty already exist! \nYou can delete ${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND} and re-create"
  412. [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ] && echo -e "${domain} in the Apache already exist! \nYou can delete ${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND} and re-create"
  413. [ -e "${tomcat_install_dir}/conf/vhost/${domain}.xml" ] && echo -e "${domain} in the Tomcat already exist! \nYou can delete ${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND} and re-create"
  414. exit
  415. else
  416. echo "domain=${domain}"
  417. fi
  418. while :; do echo
  419. echo "Please input the directory for the domain:${domain} :"
  420. read -e -p "(Default directory: ${wwwroot_dir}/${domain}): " vhostdir
  421. if [ -n "${vhostdir}" -a -z "$(echo ${vhostdir} | grep '^/')" ]; then
  422. echo "${CWARNING}input error! Press Enter to continue...${CEND}"
  423. else
  424. if [ -z "${vhostdir}" ]; then
  425. vhostdir="${wwwroot_dir}/${domain}"
  426. echo "Virtual Host Directory=${CMSG}${vhostdir}${CEND}"
  427. fi
  428. echo
  429. echo "Create Virtul Host directory......"
  430. mkdir -p ${vhostdir}
  431. echo "set permissions of Virtual Host directory......"
  432. chown -R ${run_user}.${run_user} ${vhostdir}
  433. break
  434. fi
  435. done
  436. while :; do echo
  437. read -e -p "Do you want to add more domain name? [y/n]: " moredomainame_flag
  438. if [[ ! ${moredomainame_flag} =~ ^[y,n]$ ]]; then
  439. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  440. else
  441. break
  442. fi
  443. done
  444. if [ "${moredomainame_flag}" == 'y' ]; then
  445. while :; do echo
  446. read -e -p "Type domainname or IP(example: example.com other.example.com): " moredomain
  447. if [ -z "$(echo ${moredomain} | grep '.*\..*')" ]; then
  448. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  449. else
  450. [ "${moredomain}" == "${domain}" ] && echo "${CWARNING}Domain name already exists! ${CND}" && continue
  451. echo domain list="$moredomain"
  452. moredomainame=" $moredomain"
  453. break
  454. fi
  455. done
  456. Apache_Domain_alias=ServerAlias${moredomainame}
  457. Tomcat_Domain_alias=$(for D in $(echo ${moredomainame}); do echo "<Alias>${D}</Alias>"; done)
  458. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  459. while :; do echo
  460. read -e -p "Do you want to redirect from ${moredomain} to ${domain}? [y/n]: " redirect_flag
  461. if [[ ! ${redirect_flag} =~ ^[y,n]$ ]]; then
  462. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  463. else
  464. break
  465. fi
  466. done
  467. [ "${redirect_flag}" == 'y' ] && Nginx_redirect="if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }"
  468. fi
  469. fi
  470. if [ "${nginx_ssl_flag}" == 'y' ]; then
  471. while :; do echo
  472. read -e -p "Do you want to redirect all HTTP requests to HTTPS? [y/n]: " https_flag
  473. if [[ ! ${https_flag} =~ ^[y,n]$ ]]; then
  474. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  475. else
  476. break
  477. fi
  478. done
  479. if [[ "$(${web_install_dir}/sbin/nginx -V 2>&1 | grep -Eo 'with-http_v2_module')" = 'with-http_v2_module' ]]; then
  480. LISTENOPT="443 ssl http2"
  481. else
  482. LISTENOPT="443 ssl spdy"
  483. fi
  484. Create_SSL
  485. Nginx_conf=$(echo -e "listen 80;\n listen ${LISTENOPT};\n ssl_certificate ${PATH_SSL}/${domain}.crt;\n ssl_certificate_key ${PATH_SSL}/${domain}.key;\n ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;\n ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;\n ssl_prefer_server_ciphers on;\n ssl_session_timeout 10m;\n ssl_session_cache builtin:1000 shared:SSL:10m;\n ssl_buffer_size 1400;\n add_header Strict-Transport-Security max-age=15768000;\n ssl_stapling on;\n ssl_stapling_verify on;\n")
  486. Apache_SSL=$(echo -e "SSLEngine on\n SSLCertificateFile \"${PATH_SSL}/${domain}.crt\"\n SSLCertificateKeyFile \"${PATH_SSL}/${domain}.key\"")
  487. elif [ "$apache_ssl_flag" == 'y' ]; then
  488. Create_SSL
  489. Apache_SSL=$(echo -e "SSLEngine on\n SSLCertificateFile \"${PATH_SSL}/${domain}.crt\"\n SSLCertificateKeyFile \"${PATH_SSL}/${domain}.key\"")
  490. [ -z "$(grep 'Listen 443' ${apache_install_dir}/conf/httpd.conf)" ] && sed -i "s@Listen 80@&\nListen 443@" ${apache_install_dir}/conf/httpd.conf
  491. [ -z "$(grep 'ServerName 0.0.0.0:443' ${apache_install_dir}/conf/httpd.conf)" ] && sed -i "s@ServerName 0.0.0.0:80@&\nServerName 0.0.0.0:443@" ${apache_install_dir}/conf/httpd.conf
  492. else
  493. Nginx_conf="listen 80;"
  494. fi
  495. }
  496. Nginx_anti_hotlinking() {
  497. while :; do echo
  498. read -e -p "Do you want to add hotlink protection? [y/n]: " anti_hotlinking_flag
  499. if [[ ! ${anti_hotlinking_flag} =~ ^[y,n]$ ]]; then
  500. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  501. else
  502. break
  503. fi
  504. done
  505. if [ -n "$(echo ${domain} | grep '.*\..*\..*')" ]; then
  506. domain_allow="*.${domain#*.} ${domain}"
  507. else
  508. domain_allow="*.${domain} ${domain}"
  509. fi
  510. if [ "${anti_hotlinking_flag}" == 'y' ]; then
  511. if [ "${moredomainame_flag}" == 'y' -a "${moredomain}" != "*.${domain}" ]; then
  512. domain_allow_all=${domain_allow}${moredomainame}
  513. else
  514. domain_allow_all=${domain_allow}
  515. fi
  516. domain_allow_all=`echo ${domain_allow_all} | tr ' ' '\n' | awk '!a[$1]++' | xargs`
  517. anti_hotlinking=$(echo -e "location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {\n valid_referers none blocked ${domain_allow_all};\n if (\$invalid_referer) {\n return 403;\n }\n }")
  518. fi
  519. }
  520. Nginx_rewrite() {
  521. [ ! -d "${web_install_dir}/conf/rewrite" ] && mkdir ${web_install_dir}/conf/rewrite
  522. while :; do echo
  523. read -e -p "Allow Rewrite rule? [y/n]: " rewrite_flag
  524. if [[ ! "${rewrite_flag}" =~ ^[y,n]$ ]]; then
  525. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  526. else
  527. break
  528. fi
  529. done
  530. if [ "${rewrite_flag}" == 'n' ]; then
  531. rewrite="none"
  532. touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
  533. else
  534. echo
  535. echo "Please input the rewrite of programme :"
  536. echo "${CMSG}wordpress${CEND},${CMSG}opencart${CEND},${CMSG}magento2${CEND},${CMSG}drupal${CEND},${CMSG}joomla${CEND},${CMSG}codeigniter${CEND},${CMSG}laravel${CEND}"
  537. echo "${CMSG}thinkphp${CEND},${CMSG}pathinfo${CEND},${CMSG}discuz${CEND},${CMSG}typecho${CEND},${CMSG}ecshop${CEND},${CMSG}nextcloud${CEND},${CMSG}zblog${CEND} rewrite was exist."
  538. read -e -p "(Default rewrite: other): " rewrite
  539. if [ "${rewrite}" == "" ]; then
  540. rewrite="other"
  541. fi
  542. echo "You choose rewrite=${CMSG}$rewrite${CEND}"
  543. [ "${NGX_FLAG}" == 'php' -a "${rewrite}" == "joomla" ] && NGX_CONF=$(echo -e "location ~ \\.php\$ {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n }")
  544. #[ "${NGX_FLAG}" == 'php' ] && [[ "${rewrite}" =~ ^codeigniter$|^thinkphp$|^pathinfo$ ]] && NGX_CONF=$(echo -e "location ~ [^/]\.php(/|\$) {\n try_files \$uri =404;\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n set \$real_script_name \$fastcgi_script_name;\n if (\$fastcgi_script_name ~ \"^(.+?\.php)(/.+)\$\") {\n set \$real_script_name \$1;\n set \$path_info \$2;\n }\n fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;\n fastcgi_param SCRIPT_NAME \$real_script_name;\n fastcgi_param PATH_INFO \$path_info;\n }")
  545. [ "${NGX_FLAG}" == 'php' ] && [[ "${rewrite}" =~ ^codeigniter$|^thinkphp$|^pathinfo$ ]] && NGX_CONF=$(echo -e "location ~ [^/]\.php(/|\$) {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n fastcgi_split_path_info ^(.+?\.php)(/.*)\$;\n set \$path_info \$fastcgi_path_info;\n fastcgi_param PATH_INFO \$path_info;\n try_files \$fastcgi_script_name =404; \n }")
  546. [ "${NGX_FLAG}" == 'php' -a "${rewrite}" == "typecho" ] && NGX_CONF=$(echo -e "location ~ .*\.php(\/.*)*\$ {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n set \$path_info \"\";\n set \$real_script_name \$fastcgi_script_name;\n if (\$fastcgi_script_name ~ \"^(.+?\.php)(/.+)\$\") {\n set \$real_script_name \$1;\n set \$path_info \$2;\n }\n fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;\n fastcgi_param SCRIPT_NAME \$real_script_name;\n fastcgi_param PATH_INFO \$path_info;\n }")
  547. if [[ ! "${rewrite}" =~ ^magento2$|^pathinfo$ ]]; then
  548. if [ -e "config/${rewrite}.conf" ]; then
  549. /bin/cp config/${rewrite}.conf ${web_install_dir}/conf/rewrite/${rewrite}.conf
  550. else
  551. touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
  552. fi
  553. fi
  554. fi
  555. }
  556. Nginx_log() {
  557. while :; do echo
  558. read -e -p "Allow Nginx/Tengine/OpenResty access_log? [y/n]: " access_flag
  559. if [[ ! "${access_flag}" =~ ^[y,n]$ ]]; then
  560. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  561. else
  562. break
  563. fi
  564. done
  565. if [ "${access_flag}" == 'n' ]; then
  566. Nginx_log="access_log off;"
  567. else
  568. Nginx_log="access_log ${wwwlogs_dir}/${domain}_nginx.log combined;"
  569. echo "You access log file=${CMSG}${wwwlogs_dir}/${domain}_nginx.log${CEND}"
  570. fi
  571. }
  572. Create_nginx_tomcat_conf() {
  573. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  574. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  575. server {
  576. ${Nginx_conf}
  577. server_name ${domain}${moredomainame};
  578. ${Nginx_log}
  579. index index.html index.htm index.jsp;
  580. root ${vhostdir};
  581. ${Nginx_redirect}
  582. #error_page 404 /404.html;
  583. #error_page 502 /502.html;
  584. ${anti_hotlinking}
  585. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  586. expires 30d;
  587. access_log off;
  588. }
  589. location ~ .*\.(js|css)?$ {
  590. expires 7d;
  591. access_log off;
  592. }
  593. location ~ /\.ht {
  594. deny all;
  595. }
  596. ${NGX_CONF}
  597. }
  598. EOF
  599. [ "${https_flag}" == 'y' ] && sed -i "s@^root.*;@&\nif (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  600. cat > ${tomcat_install_dir}/conf/vhost/${domain}.xml << EOF
  601. <Host name="${domain}" appBase="${vhostdir}" unpackWARs="true" autoDeploy="true"> ${Tomcat_Domain_alias}
  602. <Context path="" docBase="${vhostdir}" reloadable="false" crossContext="true"/>
  603. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  604. prefix="${domain}_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  605. <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For"
  606. protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/>
  607. </Host>
  608. EOF
  609. [ -z "$(grep -o "vhost-${domain} SYSTEM" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "/vhost-localhost SYSTEM/a<\!ENTITY vhost-${domain} SYSTEM \"file://${tomcat_install_dir}/conf/vhost/${domain}.xml\">" ${tomcat_install_dir}/conf/server.xml
  610. [ -z "$(grep -o "vhost-${domain};" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "s@vhost-localhost;@&\n \&vhost-${domain};@" ${tomcat_install_dir}/conf/server.xml
  611. echo
  612. ${web_install_dir}/sbin/nginx -t
  613. if [ $? == 0 ]; then
  614. echo "Reload Nginx......"
  615. ${web_install_dir}/sbin/nginx -s reload
  616. service tomcat restart
  617. else
  618. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  619. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  620. exit 1
  621. fi
  622. printf "
  623. #######################################################################
  624. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  625. # For more information please visit https://oneinstack.com #
  626. #######################################################################
  627. "
  628. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  629. echo "$(printf "%-30s" "Nginx Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  630. echo "$(printf "%-30s" "Tomcat Virtualhost conf:")${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND}"
  631. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  632. Print_SSL
  633. }
  634. Create_tomcat_conf() {
  635. cat > ${tomcat_install_dir}/conf/vhost/${domain}.xml << EOF
  636. <Host name="${domain}" appBase="webapps" unpackWARs="true" autoDeploy="true"> ${Tomcat_Domain_alias}
  637. <Context path="" docBase="${vhostdir}" reloadable="false" crossContext="true"/>
  638. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  639. prefix="${domain}_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  640. </Host>
  641. EOF
  642. [ -z "$(grep -o "vhost-${domain} SYSTEM" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "/vhost-localhost SYSTEM/a<\!ENTITY vhost-${domain} SYSTEM \"file://${tomcat_install_dir}/conf/vhost/${domain}.xml\">" ${tomcat_install_dir}/conf/server.xml
  643. [ -z "$(grep -o "vhost-${domain};" ${tomcat_install_dir}/conf/server.xml)" ] && sed -i "s@vhost-localhost;@&\n \&vhost-${domain};@" ${tomcat_install_dir}/conf/server.xml
  644. echo
  645. service tomcat restart
  646. printf "
  647. #######################################################################
  648. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  649. # For more information please visit https://oneinstack.com #
  650. #######################################################################
  651. "
  652. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  653. echo "$(printf "%-30s" "Tomcat Virtualhost conf:")${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND}"
  654. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  655. echo "$(printf "%-30s" "index url:")${CMSG}http://${domain}:8080/${CEND}"
  656. }
  657. Create_nginx_phpfpm_hhvm_conf() {
  658. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  659. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  660. server {
  661. ${Nginx_conf}
  662. server_name ${domain}${moredomainame};
  663. ${Nginx_log}
  664. index index.html index.htm index.php;
  665. root ${vhostdir};
  666. ${Nginx_redirect}
  667. include ${web_install_dir}/conf/rewrite/${rewrite}.conf;
  668. #error_page 404 /404.html;
  669. #error_page 502 /502.html;
  670. ${anti_hotlinking}
  671. ${NGX_CONF}
  672. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  673. expires 30d;
  674. access_log off;
  675. }
  676. location ~ .*\.(js|css)?$ {
  677. expires 7d;
  678. access_log off;
  679. }
  680. location ~ /\.ht {
  681. deny all;
  682. }
  683. }
  684. EOF
  685. [ "${rewrite}" == 'pathinfo' ] && sed -i '/pathinfo.conf;$/d' ${web_install_dir}/conf/vhost/${domain}.conf
  686. if [ "${rewrite}" == 'magento2' -a -e "config/${rewrite}.conf" ]; then
  687. /bin/cp config/${rewrite}.conf ${web_install_dir}/conf/vhost/${domain}.conf
  688. sed -i "s@/dev/shm/php-cgi.sock@/dev/shm/php${mphp_ver}-cgi.sock@g" ${web_install_dir}/conf/vhost/${domain}.conf
  689. sed -i "s@^ set \$MAGE_ROOT.*;@ set \$MAGE_ROOT ${vhostdir};@" ${web_install_dir}/conf/vhost/${domain}.conf
  690. sed -i "s@^ server_name.*;@ server_name ${domain}${moredomainame};@" ${web_install_dir}/conf/vhost/${domain}.conf
  691. sed -i "s@^ server_name.*;@&\n ${Nginx_log}@" ${web_install_dir}/conf/vhost/${domain}.conf
  692. [ "${NGX_FLAG}" == 'hhvm' ] && sed -i 's@fastcgi_pass unix:.*;@fastcgi_pass unix:/var/log/hhvm/sock;@g' ${web_install_dir}/conf/vhost/${domain}.conf
  693. if [ "${anti_hotlinking_flag}" == 'y' ]; then
  694. sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
  695. sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
  696. sed -i "s@^ root.*;@&\n return 403;@" ${web_install_dir}/conf/vhost/${domain}.conf
  697. sed -i "s@^ root.*;@&\n rewrite ^/ http://www.linuxeye.com/403.html;@" ${web_install_dir}/conf/vhost/${domain}.conf
  698. sed -i "s@^ root.*;@&\n if (\$invalid_referer) {@" ${web_install_dir}/conf/vhost/${domain}.conf
  699. sed -i "s@^ root.*;@&\n valid_referers none blocked ${domain_allow_all};@" ${web_install_dir}/conf/vhost/${domain}.conf
  700. sed -i "s@^ root.*;@&\n location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)\$ {@" ${web_install_dir}/conf/vhost/${domain}.conf
  701. fi
  702. [ "${redirect_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  703. if [ "${nginx_ssl_flag}" == 'y' ]; then
  704. sed -i "s@^ listen 80;@&\n listen ${LISTENOPT};@" ${web_install_dir}/conf/vhost/${domain}.conf
  705. sed -i "s@^ server_name.*;@&\n ssl_stapling_verify on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  706. sed -i "s@^ server_name.*;@&\n ssl_stapling on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  707. sed -i "s@^ server_name.*;@&\n add_header Strict-Transport-Security max-age=15768000;@" ${web_install_dir}/conf/vhost/${domain}.conf
  708. sed -i "s@^ server_name.*;@&\n ssl_buffer_size 1400;@" ${web_install_dir}/conf/vhost/${domain}.conf
  709. sed -i "s@^ server_name.*;@&\n ssl_session_cache builtin:1000 shared:SSL:10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
  710. sed -i "s@^ server_name.*;@&\n ssl_session_timeout 10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
  711. sed -i "s@^ server_name.*;@&\n ssl_prefer_server_ciphers on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  712. sed -i "s@^ server_name.*;@&\n ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:\!MD5;@" ${web_install_dir}/conf/vhost/${domain}.conf
  713. sed -i "s@^ server_name.*;@&\n ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;@" ${web_install_dir}/conf/vhost/${domain}.conf
  714. sed -i "s@^ server_name.*;@&\n ssl_certificate_key ${PATH_SSL}/${domain}.key;@" ${web_install_dir}/conf/vhost/${domain}.conf
  715. sed -i "s@^ server_name.*;@&\n ssl_certificate ${PATH_SSL}/${domain}.crt;@" ${web_install_dir}/conf/vhost/${domain}.conf
  716. fi
  717. fi
  718. [ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  719. echo
  720. ${web_install_dir}/sbin/nginx -t
  721. if [ $? == 0 ]; then
  722. echo "Reload Nginx......"
  723. ${web_install_dir}/sbin/nginx -s reload
  724. else
  725. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  726. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  727. exit 1
  728. fi
  729. printf "
  730. #######################################################################
  731. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  732. # For more information please visit https://oneinstack.com #
  733. #######################################################################
  734. "
  735. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  736. echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  737. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  738. [ "${rewrite_flag}" == 'y' -a "${rewrite}" != 'magento2' -a "${rewrite}" != 'pathinfo' ] && echo "$(printf "%-30s" "Rewrite rule:")${CMSG}${web_install_dir}/conf/rewrite/${rewrite}.conf${CEND}"
  739. Print_SSL
  740. }
  741. Apache_log() {
  742. while :; do echo
  743. read -e -p "Allow Apache access_log? [y/n]: " access_flag
  744. if [[ ! "${access_flag}" =~ ^[y,n]$ ]]; then
  745. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  746. else
  747. break
  748. fi
  749. done
  750. if [ "${access_flag}" == 'n' ]; then
  751. Apache_log='CustomLog "/dev/null" common'
  752. else
  753. Apache_log="CustomLog \"${wwwlogs_dir}/${domain}_apache.log\" common"
  754. echo "You access log file=${wwwlogs_dir}/${domain}_apache.log"
  755. fi
  756. }
  757. Create_apache_conf() {
  758. if [ "${Apache_main_ver}" == '24' ]; then
  759. if [ -e "${php_install_dir}/sbin/php-fpm" ] && [ -n "`grep -E ^LoadModule.*mod_proxy_fcgi.so ${apache_install_dir}/conf/httpd.conf`" ]; then
  760. Apache_fcgi=$(echo -e "<Files ~ (\\.user.ini|\\.htaccess|\\.git|\\.svn|\\.project|LICENSE|README.md)\$>\n Order allow,deny\n Deny from all\n </Files>\n <FilesMatch \\.php\$>\n SetHandler \"proxy:unix:/dev/shm/php${mphp_ver}-cgi.sock|fcgi://localhost\"\n </FilesMatch>")
  761. fi
  762. fi
  763. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  764. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  765. <VirtualHost *:80>
  766. ServerAdmin admin@example.com
  767. DocumentRoot "${vhostdir}"
  768. ServerName ${domain}
  769. ${Apache_Domain_alias}
  770. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  771. ${Apache_log}
  772. ${Apache_fcgi}
  773. <Directory "${vhostdir}">
  774. SetOutputFilter DEFLATE
  775. Options FollowSymLinks ExecCGI
  776. ${Apache_grant}
  777. AllowOverride All
  778. Order allow,deny
  779. Allow from all
  780. DirectoryIndex index.html index.php
  781. </Directory>
  782. </VirtualHost>
  783. EOF
  784. [ "$apache_ssl_flag" == 'y' ] && cat >> ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  785. <VirtualHost *:443>
  786. ServerAdmin admin@example.com
  787. DocumentRoot "${vhostdir}"
  788. ServerName ${domain}
  789. ${Apache_Domain_alias}
  790. ${Apache_SSL}
  791. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  792. ${Apache_log}
  793. ${Apache_fcgi}
  794. <Directory "${vhostdir}">
  795. SetOutputFilter DEFLATE
  796. Options FollowSymLinks ExecCGI
  797. ${Apache_grant}
  798. AllowOverride All
  799. Order allow,deny
  800. Allow from all
  801. DirectoryIndex index.html index.php
  802. </Directory>
  803. </VirtualHost>
  804. EOF
  805. echo
  806. ${apache_install_dir}/bin/apachectl -t
  807. if [ $? == 0 ]; then
  808. echo "Restart Apache......"
  809. ${apache_install_dir}/bin/apachectl -k graceful
  810. else
  811. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  812. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  813. exit 1
  814. fi
  815. printf "
  816. #######################################################################
  817. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  818. # For more information please visit https://oneinstack.com #
  819. #######################################################################
  820. "
  821. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  822. echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND}"
  823. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  824. Print_SSL
  825. }
  826. Create_nginx_apache_modphp_conf() {
  827. # Nginx/Tengine/OpenResty
  828. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  829. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  830. server {
  831. ${Nginx_conf}
  832. server_name ${domain}${moredomainame};
  833. ${Nginx_log}
  834. index index.html index.htm index.php;
  835. root ${vhostdir};
  836. ${Nginx_redirect}
  837. ${anti_hotlinking}
  838. location / {
  839. try_files \$uri @apache;
  840. }
  841. location @apache {
  842. proxy_pass http://127.0.0.1:88;
  843. include proxy.conf;
  844. }
  845. location ~ .*\.(php|php5|cgi|pl)?$ {
  846. proxy_pass http://127.0.0.1:88;
  847. include proxy.conf;
  848. }
  849. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  850. expires 30d;
  851. access_log off;
  852. }
  853. location ~ .*\.(js|css)?$ {
  854. expires 7d;
  855. access_log off;
  856. }
  857. location ~ /\.ht {
  858. deny all;
  859. }
  860. }
  861. EOF
  862. [ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  863. echo
  864. ${web_install_dir}/sbin/nginx -t
  865. if [ $? == 0 ]; then
  866. echo "Reload Nginx......"
  867. ${web_install_dir}/sbin/nginx -s reload
  868. else
  869. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  870. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  871. fi
  872. # Apache
  873. if [ "${Apache_main_ver}" == '24' ]; then
  874. if [ -e "${php_install_dir}/sbin/php-fpm" ] && [ -n "`grep -E ^LoadModule.*mod_proxy_fcgi.so ${apache_install_dir}/conf/httpd.conf`" ]; then
  875. Apache_fcgi=$(echo -e "<Files ~ (\\.user.ini|\\.htaccess|\\.git|\\.svn|\\.project|LICENSE|README.md)\$>\n Order allow,deny\n Deny from all\n </Files>\n <FilesMatch \\.php\$>\n SetHandler \"proxy:unix:/dev/shm/php${mphp_ver}-cgi.sock|fcgi://localhost\"\n </FilesMatch>")
  876. fi
  877. fi
  878. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  879. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  880. <VirtualHost *:88>
  881. ServerAdmin admin@example.com
  882. DocumentRoot "${vhostdir}"
  883. ServerName ${domain}
  884. ${Apache_Domain_alias}
  885. ${Apache_SSL}
  886. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  887. ${Apache_log}
  888. ${Apache_fcgi}
  889. <Directory "${vhostdir}">
  890. SetOutputFilter DEFLATE
  891. Options FollowSymLinks ExecCGI
  892. ${Apache_grant}
  893. AllowOverride All
  894. Order allow,deny
  895. Allow from all
  896. DirectoryIndex index.html index.php
  897. </Directory>
  898. </VirtualHost>
  899. EOF
  900. echo
  901. ${apache_install_dir}/bin/apachectl -t
  902. if [ $? == 0 ]; then
  903. echo "Restart Apache......"
  904. ${apache_install_dir}/bin/apachectl -k graceful
  905. else
  906. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  907. exit 1
  908. fi
  909. printf "
  910. #######################################################################
  911. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  912. # For more information please visit https://oneinstack.com #
  913. #######################################################################
  914. "
  915. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  916. echo "$(printf "%-30s" "Nginx Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  917. echo "$(printf "%-30s" "Apache Virtualhost conf:")${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND}"
  918. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  919. Print_SSL
  920. }
  921. Add_Vhost() {
  922. if [ -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" ]; then
  923. Choose_ENV
  924. Input_Add_domain
  925. Nginx_anti_hotlinking
  926. if [ "${NGX_FLAG}" == "java" ]; then
  927. Nginx_log
  928. Create_nginx_tomcat_conf
  929. else
  930. Nginx_rewrite
  931. Nginx_log
  932. Create_nginx_phpfpm_hhvm_conf
  933. fi
  934. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  935. Choose_ENV
  936. Input_Add_domain
  937. Apache_log
  938. Create_apache_conf
  939. elif [ ! -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" -a -e "${tomcat_install_dir}/conf/server.xml" ]; then
  940. Choose_ENV
  941. Input_Add_domain
  942. Create_tomcat_conf
  943. elif [ -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  944. Choose_ENV
  945. Input_Add_domain
  946. Nginx_anti_hotlinking
  947. if [ "${NGX_FLAG}" == "java" ]; then
  948. Nginx_log
  949. Create_nginx_tomcat_conf
  950. elif [ "${NGX_FLAG}" == "hhvm" ]; then
  951. Nginx_rewrite
  952. Nginx_log
  953. Create_nginx_phpfpm_hhvm_conf
  954. elif [ "${NGX_FLAG}" == "php" ]; then
  955. Nginx_log
  956. Apache_log
  957. Create_nginx_apache_modphp_conf
  958. fi
  959. else
  960. echo "Error! ${CFAILURE}Web server${CEND} not found!"
  961. fi
  962. }
  963. Del_NGX_Vhost() {
  964. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  965. [ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
  966. if [ -n "${Domain_List}" ]; then
  967. echo
  968. echo "Virtualhost list:"
  969. echo ${CMSG}${Domain_List}${CEND}
  970. while :; do echo
  971. read -e -p "Please input a domain you want to delete: " domain
  972. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  973. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  974. else
  975. if [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ]; then
  976. Directory=$(grep '^ root' ${web_install_dir}/conf/vhost/${domain}.conf | head -1 | awk -F'[ ;]' '{print $(NF-1)}')
  977. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  978. [ -e "${web_install_dir}/conf/ssl/${domain}.crt" ] && rm -f ${web_install_dir}/conf/ssl/${domain}.{crt,key}
  979. ${web_install_dir}/sbin/nginx -s reload
  980. while :; do echo
  981. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  982. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  983. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  984. else
  985. break
  986. fi
  987. done
  988. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  989. if [ "${quiet_flag}" != 'y' ]; then
  990. echo "Press Ctrl+c to cancel or Press any key to continue..."
  991. char=$(get_char)
  992. fi
  993. rm -rf ${Directory}
  994. fi
  995. echo
  996. [ -d ~/.acme.sh/${domain} ] && ~/.acme.sh/acme.sh --force --remove -d ${domain} > /dev/null 2>&1
  997. echo "${CMSG}Domain: ${domain} has been deleted.${CEND}"
  998. echo
  999. else
  1000. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1001. fi
  1002. break
  1003. fi
  1004. done
  1005. else
  1006. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1007. fi
  1008. fi
  1009. }
  1010. Del_Apache_Vhost() {
  1011. if [ -e "${apache_install_dir}/bin/httpd" ]; then
  1012. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  1013. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  1014. ${apache_install_dir}/bin/apachectl -k graceful
  1015. else
  1016. Domain_List=$(ls ${apache_install_dir}/conf/vhost | grep -v '0.conf' | sed "s@.conf@@g")
  1017. if [ -n "${Domain_List}" ]; then
  1018. echo
  1019. echo "Virtualhost list:"
  1020. echo ${CMSG}${Domain_List}${CEND}
  1021. while :; do echo
  1022. read -e -p "Please input a domain you want to delete: " domain
  1023. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  1024. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  1025. else
  1026. if [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ]; then
  1027. Directory=$(grep '^<Directory ' ${apache_install_dir}/conf/vhost/${domain}.conf | head -1 | awk -F'"' '{print $2}')
  1028. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  1029. [ -e "${apache_install_dir}/conf/ssl/${domain}.crt" ] && rm -f ${apache_install_dir}/conf/ssl/${domain}.{crt,key}
  1030. ${apache_install_dir}/bin/apachectl -k graceful
  1031. while :; do echo
  1032. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  1033. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  1034. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  1035. else
  1036. break
  1037. fi
  1038. done
  1039. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  1040. if [ "${quiet_flag}" != 'y' ]; then
  1041. echo "Press Ctrl+c to cancel or Press any key to continue..."
  1042. char=$(get_char)
  1043. fi
  1044. rm -rf ${Directory}
  1045. fi
  1046. [ -d ~/.acme.sh/${domain} ] && ~/.acme.sh/acme.sh --force --remove -d ${domain} > /dev/null 2>&1
  1047. echo "${CSUCCESS}Domain: ${domain} has been deleted.${CEND}"
  1048. else
  1049. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1050. fi
  1051. break
  1052. fi
  1053. done
  1054. else
  1055. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1056. fi
  1057. fi
  1058. fi
  1059. }
  1060. Del_Tomcat_Vhost() {
  1061. if [ -e "${tomcat_install_dir}/conf/server.xml" ]; then
  1062. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  1063. if [ -n "$(echo ${domain} | grep '.*\..*')" ] && [ -n "$(grep vhost-${domain} ${tomcat_install_dir}/conf/server.xml)" ]; then
  1064. sed -i /vhost-${domain}/d ${tomcat_install_dir}/conf/server.xml
  1065. rm -f ${tomcat_install_dir}/conf/vhost/${domain}.xml
  1066. service tomcat restart
  1067. fi
  1068. else
  1069. Domain_List=$(ls ${tomcat_install_dir}/conf/vhost | grep -v 'localhost.xml' | sed "s@.xml@@g")
  1070. if [ -n "${Domain_List}" ]; then
  1071. echo
  1072. echo "Virtualhost list:"
  1073. echo ${CMSG}${Domain_List}${CEND}
  1074. while :; do echo
  1075. read -e -p "Please input a domain you want to delete: " domain
  1076. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  1077. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  1078. else
  1079. if [ -n "$(grep vhost-${domain} ${tomcat_install_dir}/conf/server.xml)" ]; then
  1080. sed -i /vhost-${domain}/d ${tomcat_install_dir}/conf/server.xml
  1081. rm -f ${tomcat_install_dir}/conf/vhost/${domain}.xml
  1082. service tomcat restart
  1083. while :; do echo
  1084. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  1085. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  1086. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  1087. else
  1088. break
  1089. fi
  1090. done
  1091. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  1092. if [ "${quiet_flag}" != 'y' ]; then
  1093. echo "Press Ctrl+c to cancel or Press any key to continue..."
  1094. char=$(get_char)
  1095. fi
  1096. rm -rf ${Directory}
  1097. fi
  1098. echo "${CSUCCESS}Domain: ${domain} has been deleted.${CEND}"
  1099. else
  1100. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1101. fi
  1102. break
  1103. fi
  1104. done
  1105. else
  1106. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1107. fi
  1108. fi
  1109. fi
  1110. }
  1111. List_Vhost() {
  1112. [ -e "${tomcat_install_dir}/conf/server.xml" -a ! -d "${web_install_dir}/sbin/nginx" ] && Domain_List=$(ls ${tomcat_install_dir}/conf/vhost | grep -v 'localhost.xml' | sed "s@.xml@@g")
  1113. [ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
  1114. [ -e "${apache_install_dir}/bin/httpd" -a ! -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${apache_install_dir}/conf/vhost | grep -v '0.conf' | sed "s@.conf@@g")
  1115. if [ -n "${Domain_List}" ]; then
  1116. echo
  1117. echo "Virtualhost list:"
  1118. for D in ${Domain_List}; do echo ${CMSG}${D}${CEND}; done
  1119. else
  1120. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1121. fi
  1122. }
  1123. if [ ${ARG_NUM} == 0 ]; then
  1124. Add_Vhost
  1125. else
  1126. [ "${add_flag}" == 'y' -o "${sslquiet_flag}" == 'y' ] && Add_Vhost
  1127. [ "${list_flag}" == 'y' ] && List_Vhost
  1128. [ "${delete_flag}" == 'y' ] && { Del_NGX_Vhost; Del_Apache_Vhost; Del_Tomcat_Vhost; }
  1129. fi