vhost.sh 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  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. [ -e "/dev/shm/php74-cgi.sock" ] && echo -e "\t${CMSG}10${CEND}. PHP 7.4"
  350. read -e -p "Please input a number:(Default 1 press Enter) " php_option
  351. php_option=${php_option:-1}
  352. if [[ ! ${php_option} =~ ^[1-9]$|^10$ ]]; then
  353. echo "${CWARNING}input error! Please only input number 1~10${CEND}"
  354. else
  355. break
  356. fi
  357. done
  358. fi
  359. [ "${php_option}" == '2' ] && mphp_ver=53
  360. [ "${php_option}" == '3' ] && mphp_ver=54
  361. [ "${php_option}" == '4' ] && mphp_ver=55
  362. [ "${php_option}" == '5' ] && mphp_ver=56
  363. [ "${php_option}" == '6' ] && mphp_ver=70
  364. [ "${php_option}" == '7' ] && mphp_ver=71
  365. [ "${php_option}" == '8' ] && mphp_ver=72
  366. [ "${php_option}" == '9' ] && mphp_ver=73
  367. [ "${php_option}" == '10' ] && mphp_ver=74
  368. [ ! -e "/dev/shm/php${mphp_ver}-cgi.sock" ] && unset mphp_ver
  369. fi
  370. case "${NGX_FLAG}" in
  371. "php")
  372. 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 }")
  373. ;;
  374. "java")
  375. NGX_CONF=$(echo -e "location ~ {\n proxy_pass http://127.0.0.1:8080;\n include proxy.conf;\n }")
  376. ;;
  377. "hhvm")
  378. 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 }")
  379. ;;
  380. esac
  381. if [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ] && [ ! -e ~/.acme.sh/acme.sh ]; then
  382. pushd ${oneinstack_dir}/src > /dev/null
  383. [ ! -e acme.sh-master.tar.gz ] && wget -qc http://mirrors.linuxeye.com/oneinstack/src/acme.sh-master.tar.gz
  384. tar xzf acme.sh-master.tar.gz
  385. pushd acme.sh-master > /dev/null
  386. ./acme.sh --install > /dev/null 2>&1
  387. popd > /dev/null
  388. popd > /dev/null
  389. fi
  390. [ -e ~/.acme.sh/account.conf ] && sed -i '/^CERT_HOME=/d' ~/.acme.sh/account.conf
  391. if [[ "${Domian_Mode}" =~ ^[2-3]$ ]] || [ "${dnsapi_flag}" == 'y' ]; then
  392. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  393. nginx_ssl_flag=y
  394. PATH_SSL=${web_install_dir}/conf/ssl
  395. [ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
  396. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  397. apache_ssl_flag=y
  398. PATH_SSL=${apache_install_dir}/conf/ssl
  399. [ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
  400. fi
  401. elif [ "${Domian_Mode}" == 'q' ]; then
  402. exit 1
  403. fi
  404. while :; do echo
  405. read -e -p "Please input domain(example: www.example.com): " domain
  406. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  407. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  408. else
  409. break
  410. fi
  411. done
  412. 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
  413. [ -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"
  414. [ -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"
  415. [ -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"
  416. exit
  417. else
  418. echo "domain=${domain}"
  419. fi
  420. while :; do echo
  421. echo "Please input the directory for the domain:${domain} :"
  422. read -e -p "(Default directory: ${wwwroot_dir}/${domain}): " vhostdir
  423. if [ -n "${vhostdir}" -a -z "$(echo ${vhostdir} | grep '^/')" ]; then
  424. echo "${CWARNING}input error! Press Enter to continue...${CEND}"
  425. else
  426. if [ -z "${vhostdir}" ]; then
  427. vhostdir="${wwwroot_dir}/${domain}"
  428. echo "Virtual Host Directory=${CMSG}${vhostdir}${CEND}"
  429. fi
  430. echo
  431. echo "Create Virtul Host directory......"
  432. mkdir -p ${vhostdir}
  433. echo "set permissions of Virtual Host directory......"
  434. chown -R ${run_user}.${run_user} ${vhostdir}
  435. break
  436. fi
  437. done
  438. while :; do echo
  439. read -e -p "Do you want to add more domain name? [y/n]: " moredomainame_flag
  440. if [[ ! ${moredomainame_flag} =~ ^[y,n]$ ]]; then
  441. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  442. else
  443. break
  444. fi
  445. done
  446. if [ "${moredomainame_flag}" == 'y' ]; then
  447. while :; do echo
  448. read -e -p "Type domainname or IP(example: example.com other.example.com): " moredomain
  449. if [ -z "$(echo ${moredomain} | grep '.*\..*')" ]; then
  450. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  451. else
  452. [ "${moredomain}" == "${domain}" ] && echo "${CWARNING}Domain name already exists! ${CND}" && continue
  453. echo domain list="$moredomain"
  454. moredomainame=" $moredomain"
  455. break
  456. fi
  457. done
  458. Apache_Domain_alias=ServerAlias${moredomainame}
  459. Tomcat_Domain_alias=$(for D in $(echo ${moredomainame}); do echo "<Alias>${D}</Alias>"; done)
  460. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  461. while :; do echo
  462. read -e -p "Do you want to redirect from ${moredomain} to ${domain}? [y/n]: " redirect_flag
  463. if [[ ! ${redirect_flag} =~ ^[y,n]$ ]]; then
  464. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  465. else
  466. break
  467. fi
  468. done
  469. [ "${redirect_flag}" == 'y' ] && Nginx_redirect="if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }"
  470. fi
  471. fi
  472. if [ "${nginx_ssl_flag}" == 'y' ]; then
  473. while :; do echo
  474. read -e -p "Do you want to redirect all HTTP requests to HTTPS? [y/n]: " https_flag
  475. if [[ ! ${https_flag} =~ ^[y,n]$ ]]; then
  476. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  477. else
  478. break
  479. fi
  480. done
  481. if [[ "$(${web_install_dir}/sbin/nginx -V 2>&1 | grep -Eo 'with-http_v2_module')" = 'with-http_v2_module' ]]; then
  482. LISTENOPT="443 ssl http2"
  483. else
  484. LISTENOPT="443 ssl spdy"
  485. fi
  486. Create_SSL
  487. 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")
  488. Apache_SSL=$(echo -e "SSLEngine on\n SSLCertificateFile \"${PATH_SSL}/${domain}.crt\"\n SSLCertificateKeyFile \"${PATH_SSL}/${domain}.key\"")
  489. elif [ "$apache_ssl_flag" == 'y' ]; then
  490. Create_SSL
  491. Apache_SSL=$(echo -e "SSLEngine on\n SSLCertificateFile \"${PATH_SSL}/${domain}.crt\"\n SSLCertificateKeyFile \"${PATH_SSL}/${domain}.key\"")
  492. [ -z "$(grep 'Listen 443' ${apache_install_dir}/conf/httpd.conf)" ] && sed -i "s@Listen 80@&\nListen 443@" ${apache_install_dir}/conf/httpd.conf
  493. [ -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
  494. else
  495. Nginx_conf="listen 80;"
  496. fi
  497. }
  498. Nginx_anti_hotlinking() {
  499. while :; do echo
  500. read -e -p "Do you want to add hotlink protection? [y/n]: " anti_hotlinking_flag
  501. if [[ ! ${anti_hotlinking_flag} =~ ^[y,n]$ ]]; then
  502. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  503. else
  504. break
  505. fi
  506. done
  507. if [ -n "$(echo ${domain} | grep '.*\..*\..*')" ]; then
  508. domain_allow="*.${domain#*.} ${domain}"
  509. else
  510. domain_allow="*.${domain} ${domain}"
  511. fi
  512. if [ "${anti_hotlinking_flag}" == 'y' ]; then
  513. if [ "${moredomainame_flag}" == 'y' -a "${moredomain}" != "*.${domain}" ]; then
  514. domain_allow_all=${domain_allow}${moredomainame}
  515. else
  516. domain_allow_all=${domain_allow}
  517. fi
  518. domain_allow_all=`echo ${domain_allow_all} | tr ' ' '\n' | awk '!a[$1]++' | xargs`
  519. 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 }")
  520. fi
  521. }
  522. Nginx_rewrite() {
  523. [ ! -d "${web_install_dir}/conf/rewrite" ] && mkdir ${web_install_dir}/conf/rewrite
  524. while :; do echo
  525. read -e -p "Allow Rewrite rule? [y/n]: " rewrite_flag
  526. if [[ ! "${rewrite_flag}" =~ ^[y,n]$ ]]; then
  527. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  528. else
  529. break
  530. fi
  531. done
  532. if [ "${rewrite_flag}" == 'n' ]; then
  533. rewrite="none"
  534. touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
  535. else
  536. echo
  537. echo "Please input the rewrite of programme :"
  538. echo "${CMSG}wordpress${CEND},${CMSG}opencart${CEND},${CMSG}magento2${CEND},${CMSG}drupal${CEND},${CMSG}joomla${CEND},${CMSG}codeigniter${CEND},${CMSG}laravel${CEND}"
  539. echo "${CMSG}thinkphp${CEND},${CMSG}pathinfo${CEND},${CMSG}discuz${CEND},${CMSG}typecho${CEND},${CMSG}ecshop${CEND},${CMSG}nextcloud${CEND},${CMSG}zblog${CEND},${CMSG}whmcs${CEND} rewrite was exist."
  540. read -e -p "(Default rewrite: other): " rewrite
  541. if [ "${rewrite}" == "" ]; then
  542. rewrite="other"
  543. fi
  544. echo "You choose rewrite=${CMSG}$rewrite${CEND}"
  545. [ "${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 }")
  546. #[ "${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 }")
  547. [ "${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 }")
  548. [ "${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 }")
  549. if [[ ! "${rewrite}" =~ ^magento2$|^pathinfo$ ]]; then
  550. if [ -e "config/${rewrite}.conf" ]; then
  551. /bin/cp config/${rewrite}.conf ${web_install_dir}/conf/rewrite/${rewrite}.conf
  552. else
  553. touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
  554. fi
  555. fi
  556. fi
  557. }
  558. Nginx_log() {
  559. while :; do echo
  560. read -e -p "Allow Nginx/Tengine/OpenResty access_log? [y/n]: " access_flag
  561. if [[ ! "${access_flag}" =~ ^[y,n]$ ]]; then
  562. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  563. else
  564. break
  565. fi
  566. done
  567. if [ "${access_flag}" == 'n' ]; then
  568. Nginx_log="access_log off;"
  569. else
  570. Nginx_log="access_log ${wwwlogs_dir}/${domain}_nginx.log combined;"
  571. echo "You access log file=${CMSG}${wwwlogs_dir}/${domain}_nginx.log${CEND}"
  572. fi
  573. }
  574. Create_nginx_tomcat_conf() {
  575. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  576. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  577. server {
  578. ${Nginx_conf}
  579. server_name ${domain}${moredomainame};
  580. ${Nginx_log}
  581. index index.html index.htm index.jsp;
  582. root ${vhostdir};
  583. ${Nginx_redirect}
  584. #error_page 404 /404.html;
  585. #error_page 502 /502.html;
  586. ${anti_hotlinking}
  587. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  588. expires 30d;
  589. access_log off;
  590. }
  591. location ~ .*\.(js|css)?$ {
  592. expires 7d;
  593. access_log off;
  594. }
  595. location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
  596. deny all;
  597. }
  598. ${NGX_CONF}
  599. }
  600. EOF
  601. [ "${https_flag}" == 'y' ] && sed -i "s@^root.*;@&\nif (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  602. cat > ${tomcat_install_dir}/conf/vhost/${domain}.xml << EOF
  603. <Host name="${domain}" appBase="${vhostdir}" unpackWARs="true" autoDeploy="true"> ${Tomcat_Domain_alias}
  604. <Context path="" docBase="${vhostdir}" reloadable="false" crossContext="true"/>
  605. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  606. prefix="${domain}_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  607. <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For"
  608. protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/>
  609. </Host>
  610. EOF
  611. [ -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
  612. [ -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
  613. echo
  614. ${web_install_dir}/sbin/nginx -t
  615. if [ $? == 0 ]; then
  616. echo "Reload Nginx......"
  617. ${web_install_dir}/sbin/nginx -s reload
  618. service tomcat restart
  619. else
  620. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  621. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  622. exit 1
  623. fi
  624. printf "
  625. #######################################################################
  626. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  627. # For more information please visit https://oneinstack.com #
  628. #######################################################################
  629. "
  630. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  631. echo "$(printf "%-30s" "Nginx Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  632. echo "$(printf "%-30s" "Tomcat Virtualhost conf:")${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND}"
  633. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  634. Print_SSL
  635. }
  636. Create_tomcat_conf() {
  637. cat > ${tomcat_install_dir}/conf/vhost/${domain}.xml << EOF
  638. <Host name="${domain}" appBase="webapps" unpackWARs="true" autoDeploy="true"> ${Tomcat_Domain_alias}
  639. <Context path="" docBase="${vhostdir}" reloadable="false" crossContext="true"/>
  640. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  641. prefix="${domain}_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  642. </Host>
  643. EOF
  644. [ -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
  645. [ -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
  646. echo
  647. service tomcat restart
  648. printf "
  649. #######################################################################
  650. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  651. # For more information please visit https://oneinstack.com #
  652. #######################################################################
  653. "
  654. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  655. echo "$(printf "%-30s" "Tomcat Virtualhost conf:")${CMSG}${tomcat_install_dir}/conf/vhost/${domain}.xml${CEND}"
  656. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  657. echo "$(printf "%-30s" "index url:")${CMSG}http://${domain}:8080/${CEND}"
  658. }
  659. Create_nginx_phpfpm_hhvm_conf() {
  660. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  661. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  662. server {
  663. ${Nginx_conf}
  664. server_name ${domain}${moredomainame};
  665. ${Nginx_log}
  666. index index.html index.htm index.php;
  667. root ${vhostdir};
  668. ${Nginx_redirect}
  669. include ${web_install_dir}/conf/rewrite/${rewrite}.conf;
  670. #error_page 404 /404.html;
  671. #error_page 502 /502.html;
  672. ${anti_hotlinking}
  673. ${NGX_CONF}
  674. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  675. expires 30d;
  676. access_log off;
  677. }
  678. location ~ .*\.(js|css)?$ {
  679. expires 7d;
  680. access_log off;
  681. }
  682. location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
  683. deny all;
  684. }
  685. }
  686. EOF
  687. [ "${rewrite}" == 'pathinfo' ] && sed -i '/pathinfo.conf;$/d' ${web_install_dir}/conf/vhost/${domain}.conf
  688. if [ "${rewrite}" == 'magento2' -a -e "config/${rewrite}.conf" ]; then
  689. /bin/cp config/${rewrite}.conf ${web_install_dir}/conf/vhost/${domain}.conf
  690. sed -i "s@/dev/shm/php-cgi.sock@/dev/shm/php${mphp_ver}-cgi.sock@g" ${web_install_dir}/conf/vhost/${domain}.conf
  691. sed -i "s@^ set \$MAGE_ROOT.*;@ set \$MAGE_ROOT ${vhostdir};@" ${web_install_dir}/conf/vhost/${domain}.conf
  692. sed -i "s@^ server_name.*;@ server_name ${domain}${moredomainame};@" ${web_install_dir}/conf/vhost/${domain}.conf
  693. sed -i "s@^ server_name.*;@&\n ${Nginx_log}@" ${web_install_dir}/conf/vhost/${domain}.conf
  694. [ "${NGX_FLAG}" == 'hhvm' ] && sed -i 's@fastcgi_pass unix:.*;@fastcgi_pass unix:/var/log/hhvm/sock;@g' ${web_install_dir}/conf/vhost/${domain}.conf
  695. if [ "${anti_hotlinking_flag}" == 'y' ]; then
  696. sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
  697. sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
  698. sed -i "s@^ root.*;@&\n return 403;@" ${web_install_dir}/conf/vhost/${domain}.conf
  699. sed -i "s@^ root.*;@&\n rewrite ^/ http://www.linuxeye.com/403.html;@" ${web_install_dir}/conf/vhost/${domain}.conf
  700. sed -i "s@^ root.*;@&\n if (\$invalid_referer) {@" ${web_install_dir}/conf/vhost/${domain}.conf
  701. sed -i "s@^ root.*;@&\n valid_referers none blocked ${domain_allow_all};@" ${web_install_dir}/conf/vhost/${domain}.conf
  702. 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
  703. fi
  704. [ "${redirect_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  705. if [ "${nginx_ssl_flag}" == 'y' ]; then
  706. sed -i "s@^ listen 80;@&\n listen ${LISTENOPT};@" ${web_install_dir}/conf/vhost/${domain}.conf
  707. sed -i "s@^ server_name.*;@&\n ssl_stapling_verify on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  708. sed -i "s@^ server_name.*;@&\n ssl_stapling on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  709. sed -i "s@^ server_name.*;@&\n add_header Strict-Transport-Security max-age=15768000;@" ${web_install_dir}/conf/vhost/${domain}.conf
  710. sed -i "s@^ server_name.*;@&\n ssl_buffer_size 1400;@" ${web_install_dir}/conf/vhost/${domain}.conf
  711. sed -i "s@^ server_name.*;@&\n ssl_session_cache builtin:1000 shared:SSL:10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
  712. sed -i "s@^ server_name.*;@&\n ssl_session_timeout 10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
  713. sed -i "s@^ server_name.*;@&\n ssl_prefer_server_ciphers on;@" ${web_install_dir}/conf/vhost/${domain}.conf
  714. 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
  715. sed -i "s@^ server_name.*;@&\n ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;@" ${web_install_dir}/conf/vhost/${domain}.conf
  716. sed -i "s@^ server_name.*;@&\n ssl_certificate_key ${PATH_SSL}/${domain}.key;@" ${web_install_dir}/conf/vhost/${domain}.conf
  717. sed -i "s@^ server_name.*;@&\n ssl_certificate ${PATH_SSL}/${domain}.crt;@" ${web_install_dir}/conf/vhost/${domain}.conf
  718. fi
  719. fi
  720. [ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  721. echo
  722. ${web_install_dir}/sbin/nginx -t
  723. if [ $? == 0 ]; then
  724. echo "Reload Nginx......"
  725. ${web_install_dir}/sbin/nginx -s reload
  726. else
  727. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  728. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  729. exit 1
  730. fi
  731. printf "
  732. #######################################################################
  733. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  734. # For more information please visit https://oneinstack.com #
  735. #######################################################################
  736. "
  737. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  738. echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  739. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  740. [ "${rewrite_flag}" == 'y' -a "${rewrite}" != 'magento2' -a "${rewrite}" != 'pathinfo' ] && echo "$(printf "%-30s" "Rewrite rule:")${CMSG}${web_install_dir}/conf/rewrite/${rewrite}.conf${CEND}"
  741. Print_SSL
  742. }
  743. Apache_log() {
  744. while :; do echo
  745. read -e -p "Allow Apache access_log? [y/n]: " access_flag
  746. if [[ ! "${access_flag}" =~ ^[y,n]$ ]]; then
  747. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  748. else
  749. break
  750. fi
  751. done
  752. if [ "${access_flag}" == 'n' ]; then
  753. Apache_log='CustomLog "/dev/null" common'
  754. else
  755. Apache_log="CustomLog \"${wwwlogs_dir}/${domain}_apache.log\" common"
  756. echo "You access log file=${wwwlogs_dir}/${domain}_apache.log"
  757. fi
  758. }
  759. Create_apache_conf() {
  760. if [ "${Apache_main_ver}" == '24' ]; then
  761. if [ -e "${php_install_dir}/sbin/php-fpm" ] && [ -n "`grep -E ^LoadModule.*mod_proxy_fcgi.so ${apache_install_dir}/conf/httpd.conf`" ]; then
  762. 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>")
  763. fi
  764. fi
  765. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  766. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  767. <VirtualHost *:80>
  768. ServerAdmin admin@example.com
  769. DocumentRoot "${vhostdir}"
  770. ServerName ${domain}
  771. ${Apache_Domain_alias}
  772. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  773. ${Apache_log}
  774. ${Apache_fcgi}
  775. <Directory "${vhostdir}">
  776. SetOutputFilter DEFLATE
  777. Options FollowSymLinks ExecCGI
  778. ${Apache_grant}
  779. AllowOverride All
  780. Order allow,deny
  781. Allow from all
  782. DirectoryIndex index.html index.php
  783. </Directory>
  784. </VirtualHost>
  785. EOF
  786. [ "$apache_ssl_flag" == 'y' ] && cat >> ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  787. <VirtualHost *:443>
  788. ServerAdmin admin@example.com
  789. DocumentRoot "${vhostdir}"
  790. ServerName ${domain}
  791. ${Apache_Domain_alias}
  792. ${Apache_SSL}
  793. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  794. ${Apache_log}
  795. ${Apache_fcgi}
  796. <Directory "${vhostdir}">
  797. SetOutputFilter DEFLATE
  798. Options FollowSymLinks ExecCGI
  799. ${Apache_grant}
  800. AllowOverride All
  801. Order allow,deny
  802. Allow from all
  803. DirectoryIndex index.html index.php
  804. </Directory>
  805. </VirtualHost>
  806. EOF
  807. echo
  808. ${apache_install_dir}/bin/apachectl -t
  809. if [ $? == 0 ]; then
  810. echo "Restart Apache......"
  811. ${apache_install_dir}/bin/apachectl -k graceful
  812. else
  813. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  814. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  815. exit 1
  816. fi
  817. printf "
  818. #######################################################################
  819. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  820. # For more information please visit https://oneinstack.com #
  821. #######################################################################
  822. "
  823. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  824. echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND}"
  825. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  826. Print_SSL
  827. }
  828. Create_nginx_apache_modphp_conf() {
  829. # Nginx/Tengine/OpenResty
  830. [ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
  831. cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
  832. server {
  833. ${Nginx_conf}
  834. server_name ${domain}${moredomainame};
  835. ${Nginx_log}
  836. index index.html index.htm index.php;
  837. root ${vhostdir};
  838. ${Nginx_redirect}
  839. ${anti_hotlinking}
  840. location / {
  841. try_files \$uri @apache;
  842. }
  843. location @apache {
  844. proxy_pass http://127.0.0.1:88;
  845. include proxy.conf;
  846. }
  847. location ~ .*\.(php|php5|cgi|pl)?$ {
  848. proxy_pass http://127.0.0.1:88;
  849. include proxy.conf;
  850. }
  851. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
  852. expires 30d;
  853. access_log off;
  854. }
  855. location ~ .*\.(js|css)?$ {
  856. expires 7d;
  857. access_log off;
  858. }
  859. location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
  860. deny all;
  861. }
  862. }
  863. EOF
  864. [ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
  865. echo
  866. ${web_install_dir}/sbin/nginx -t
  867. if [ $? == 0 ]; then
  868. echo "Reload Nginx......"
  869. ${web_install_dir}/sbin/nginx -s reload
  870. else
  871. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  872. echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
  873. fi
  874. # Apache
  875. if [ "${Apache_main_ver}" == '24' ]; then
  876. if [ -e "${php_install_dir}/sbin/php-fpm" ] && [ -n "`grep -E ^LoadModule.*mod_proxy_fcgi.so ${apache_install_dir}/conf/httpd.conf`" ]; then
  877. 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>")
  878. fi
  879. fi
  880. [ ! -d ${apache_install_dir}/conf/vhost ] && mkdir ${apache_install_dir}/conf/vhost
  881. cat > ${apache_install_dir}/conf/vhost/${domain}.conf << EOF
  882. <VirtualHost *:88>
  883. ServerAdmin admin@example.com
  884. DocumentRoot "${vhostdir}"
  885. ServerName ${domain}
  886. ${Apache_Domain_alias}
  887. ${Apache_SSL}
  888. ErrorLog "${wwwlogs_dir}/${domain}_error_apache.log"
  889. ${Apache_log}
  890. ${Apache_fcgi}
  891. <Directory "${vhostdir}">
  892. SetOutputFilter DEFLATE
  893. Options FollowSymLinks ExecCGI
  894. ${Apache_grant}
  895. AllowOverride All
  896. Order allow,deny
  897. Allow from all
  898. DirectoryIndex index.html index.php
  899. </Directory>
  900. </VirtualHost>
  901. EOF
  902. echo
  903. ${apache_install_dir}/bin/apachectl -t
  904. if [ $? == 0 ]; then
  905. echo "Restart Apache......"
  906. ${apache_install_dir}/bin/apachectl -k graceful
  907. else
  908. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  909. exit 1
  910. fi
  911. printf "
  912. #######################################################################
  913. # OneinStack for CentOS/RedHat 6+ Debian 8+ and Ubuntu 14+ #
  914. # For more information please visit https://oneinstack.com #
  915. #######################################################################
  916. "
  917. echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
  918. echo "$(printf "%-30s" "Nginx Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
  919. echo "$(printf "%-30s" "Apache Virtualhost conf:")${CMSG}${apache_install_dir}/conf/vhost/${domain}.conf${CEND}"
  920. echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
  921. Print_SSL
  922. }
  923. Add_Vhost() {
  924. if [ -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" ]; then
  925. Choose_ENV
  926. Input_Add_domain
  927. Nginx_anti_hotlinking
  928. if [ "${NGX_FLAG}" == "java" ]; then
  929. Nginx_log
  930. Create_nginx_tomcat_conf
  931. else
  932. Nginx_rewrite
  933. Nginx_log
  934. Create_nginx_phpfpm_hhvm_conf
  935. fi
  936. elif [ ! -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  937. Choose_ENV
  938. Input_Add_domain
  939. Apache_log
  940. Create_apache_conf
  941. elif [ ! -e "${web_install_dir}/sbin/nginx" -a ! -e "${apache_install_dir}/bin/httpd" -a -e "${tomcat_install_dir}/conf/server.xml" ]; then
  942. Choose_ENV
  943. Input_Add_domain
  944. Create_tomcat_conf
  945. elif [ -e "${web_install_dir}/sbin/nginx" -a -e "${apache_install_dir}/bin/httpd" ]; then
  946. Choose_ENV
  947. Input_Add_domain
  948. Nginx_anti_hotlinking
  949. if [ "${NGX_FLAG}" == "java" ]; then
  950. Nginx_log
  951. Create_nginx_tomcat_conf
  952. elif [ "${NGX_FLAG}" == "hhvm" ]; then
  953. Nginx_rewrite
  954. Nginx_log
  955. Create_nginx_phpfpm_hhvm_conf
  956. elif [ "${NGX_FLAG}" == "php" ]; then
  957. Nginx_log
  958. Apache_log
  959. Create_nginx_apache_modphp_conf
  960. fi
  961. else
  962. echo "Error! ${CFAILURE}Web server${CEND} not found!"
  963. fi
  964. }
  965. Del_NGX_Vhost() {
  966. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  967. [ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
  968. if [ -n "${Domain_List}" ]; then
  969. echo
  970. echo "Virtualhost list:"
  971. echo ${CMSG}${Domain_List}${CEND}
  972. while :; do echo
  973. read -e -p "Please input a domain you want to delete: " domain
  974. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  975. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  976. else
  977. if [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ]; then
  978. Directory=$(grep '^ root' ${web_install_dir}/conf/vhost/${domain}.conf | head -1 | awk -F'[ ;]' '{print $(NF-1)}')
  979. rm -f ${web_install_dir}/conf/vhost/${domain}.conf
  980. [ -e "${web_install_dir}/conf/ssl/${domain}.crt" ] && rm -f ${web_install_dir}/conf/ssl/${domain}.{crt,key}
  981. ${web_install_dir}/sbin/nginx -s reload
  982. while :; do echo
  983. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  984. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  985. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  986. else
  987. break
  988. fi
  989. done
  990. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  991. if [ "${quiet_flag}" != 'y' ]; then
  992. echo "Press Ctrl+c to cancel or Press any key to continue..."
  993. char=$(get_char)
  994. fi
  995. rm -rf ${Directory}
  996. fi
  997. echo
  998. [ -d ~/.acme.sh/${domain} ] && ~/.acme.sh/acme.sh --force --remove -d ${domain} > /dev/null 2>&1
  999. echo "${CMSG}Domain: ${domain} has been deleted.${CEND}"
  1000. echo
  1001. else
  1002. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1003. fi
  1004. break
  1005. fi
  1006. done
  1007. else
  1008. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1009. fi
  1010. fi
  1011. }
  1012. Del_Apache_Vhost() {
  1013. if [ -e "${apache_install_dir}/bin/httpd" ]; then
  1014. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  1015. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  1016. ${apache_install_dir}/bin/apachectl -k graceful
  1017. else
  1018. Domain_List=$(ls ${apache_install_dir}/conf/vhost | grep -v '0.conf' | sed "s@.conf@@g")
  1019. if [ -n "${Domain_List}" ]; then
  1020. echo
  1021. echo "Virtualhost list:"
  1022. echo ${CMSG}${Domain_List}${CEND}
  1023. while :; do echo
  1024. read -e -p "Please input a domain you want to delete: " domain
  1025. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  1026. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  1027. else
  1028. if [ -e "${apache_install_dir}/conf/vhost/${domain}.conf" ]; then
  1029. Directory=$(grep '^<Directory ' ${apache_install_dir}/conf/vhost/${domain}.conf | head -1 | awk -F'"' '{print $2}')
  1030. rm -f ${apache_install_dir}/conf/vhost/${domain}.conf
  1031. [ -e "${apache_install_dir}/conf/ssl/${domain}.crt" ] && rm -f ${apache_install_dir}/conf/ssl/${domain}.{crt,key}
  1032. ${apache_install_dir}/bin/apachectl -k graceful
  1033. while :; do echo
  1034. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  1035. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  1036. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  1037. else
  1038. break
  1039. fi
  1040. done
  1041. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  1042. if [ "${quiet_flag}" != 'y' ]; then
  1043. echo "Press Ctrl+c to cancel or Press any key to continue..."
  1044. char=$(get_char)
  1045. fi
  1046. rm -rf ${Directory}
  1047. fi
  1048. [ -d ~/.acme.sh/${domain} ] && ~/.acme.sh/acme.sh --force --remove -d ${domain} > /dev/null 2>&1
  1049. echo "${CSUCCESS}Domain: ${domain} has been deleted.${CEND}"
  1050. else
  1051. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1052. fi
  1053. break
  1054. fi
  1055. done
  1056. else
  1057. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1058. fi
  1059. fi
  1060. fi
  1061. }
  1062. Del_Tomcat_Vhost() {
  1063. if [ -e "${tomcat_install_dir}/conf/server.xml" ]; then
  1064. if [ -e "${web_install_dir}/sbin/nginx" ]; then
  1065. if [ -n "$(echo ${domain} | grep '.*\..*')" ] && [ -n "$(grep vhost-${domain} ${tomcat_install_dir}/conf/server.xml)" ]; then
  1066. sed -i /vhost-${domain}/d ${tomcat_install_dir}/conf/server.xml
  1067. rm -f ${tomcat_install_dir}/conf/vhost/${domain}.xml
  1068. service tomcat restart
  1069. fi
  1070. else
  1071. Domain_List=$(ls ${tomcat_install_dir}/conf/vhost | grep -v 'localhost.xml' | sed "s@.xml@@g")
  1072. if [ -n "${Domain_List}" ]; then
  1073. echo
  1074. echo "Virtualhost list:"
  1075. echo ${CMSG}${Domain_List}${CEND}
  1076. while :; do echo
  1077. read -e -p "Please input a domain you want to delete: " domain
  1078. if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
  1079. echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
  1080. else
  1081. if [ -n "$(grep vhost-${domain} ${tomcat_install_dir}/conf/server.xml)" ]; then
  1082. sed -i /vhost-${domain}/d ${tomcat_install_dir}/conf/server.xml
  1083. rm -f ${tomcat_install_dir}/conf/vhost/${domain}.xml
  1084. service tomcat restart
  1085. while :; do echo
  1086. read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
  1087. if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
  1088. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  1089. else
  1090. break
  1091. fi
  1092. done
  1093. if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
  1094. if [ "${quiet_flag}" != 'y' ]; then
  1095. echo "Press Ctrl+c to cancel or Press any key to continue..."
  1096. char=$(get_char)
  1097. fi
  1098. rm -rf ${Directory}
  1099. fi
  1100. echo "${CSUCCESS}Domain: ${domain} has been deleted.${CEND}"
  1101. else
  1102. echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
  1103. fi
  1104. break
  1105. fi
  1106. done
  1107. else
  1108. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1109. fi
  1110. fi
  1111. fi
  1112. }
  1113. List_Vhost() {
  1114. [ -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")
  1115. [ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
  1116. [ -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")
  1117. if [ -n "${Domain_List}" ]; then
  1118. echo
  1119. echo "Virtualhost list:"
  1120. for D in ${Domain_List}; do echo ${CMSG}${D}${CEND}; done
  1121. else
  1122. echo "${CWARNING}Virtualhost was not exist! ${CEND}"
  1123. fi
  1124. }
  1125. if [ ${ARG_NUM} == 0 ]; then
  1126. Add_Vhost
  1127. else
  1128. [ "${add_flag}" == 'y' -o "${sslquiet_flag}" == 'y' ] && Add_Vhost
  1129. [ "${list_flag}" == 'y' ] && List_Vhost
  1130. [ "${delete_flag}" == 'y' ] && { Del_NGX_Vhost; Del_Apache_Vhost; Del_Tomcat_Vhost; }
  1131. fi