vhost.sh 52 KB

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