addons.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+
  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 7+ and Ubuntu 12+ #
  15. # Install/Uninstall Extensions #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. # Check if user is root
  20. [ $(id -u) != '0' ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  21. oneinstack_dir=$(dirname "`readlink -f $0`")
  22. pushd ${oneinstack_dir} > /dev/null
  23. # get the IP information
  24. PUBLIC_IPADDR=$(./include/get_public_ipaddr.py)
  25. IPADDR_COUNTRY=$(./include/get_ipaddr_state.py $PUBLIC_IPADDR)
  26. . ./versions.txt
  27. . ./options.conf
  28. . ./include/color.sh
  29. . ./include/memory.sh
  30. . ./include/check_os.sh
  31. . ./include/check_download.sh
  32. . ./include/download.sh
  33. . ./include/get_char.sh
  34. . ./include/zendopcache.sh
  35. . ./include/xcache.sh
  36. . ./include/apcu.sh
  37. . ./include/eaccelerator.sh
  38. . ./include/ZendGuardLoader.sh
  39. . ./include/ioncube.sh
  40. . ./include/sourceguardian.sh
  41. . ./include/ImageMagick.sh
  42. . ./include/GraphicsMagick.sh
  43. . ./include/pecl_mongodb.sh
  44. . ./include/memcached.sh
  45. . ./include/redis.sh
  46. . ./include/python.sh
  47. . ./include/ngx_lua_waf.sh
  48. . ./include/panel.sh
  49. # Check PHP
  50. if [ -e "${php_install_dir}/bin/phpize" ]; then
  51. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  52. PHP_detail_ver=$(${php_install_dir}/bin/php -r 'echo PHP_VERSION;')
  53. PHP_main_ver=${PHP_detail_ver%.*}
  54. case "${PHP_main_ver}" in
  55. 5.3)
  56. php_option=1
  57. ;;
  58. 5.4)
  59. php_option=2
  60. ;;
  61. 5.5)
  62. php_option=3
  63. ;;
  64. 5.6)
  65. php_option=4
  66. ;;
  67. 7.0)
  68. php_option=5
  69. ;;
  70. 7.1)
  71. php_option=6
  72. ;;
  73. 7.2)
  74. php_option=7
  75. ;;
  76. 7.3)
  77. php_option=8
  78. ;;
  79. esac
  80. fi
  81. # Check PHP Extensions
  82. Check_PHP_Extension() {
  83. [ ! -e "${php_install_dir}/bin/phpize" ] && { echo "${CWARNING}PHP was not exist! ${CEND}"; exit 1; }
  84. [ -e "`ls ${php_install_dir}/etc/php.d/0?-${PHP_extension}.ini 2> /dev/null`" ] && { echo "${CWARNING}PHP ${PHP_extension} module already installed! ${CEND}"; exit 1; }
  85. }
  86. # restart PHP
  87. Restart_PHP() {
  88. [ -e "${apache_install_dir}/conf/httpd.conf" ] && service httpd restart || service php-fpm restart
  89. }
  90. # Check succ
  91. Check_succ() {
  92. [ -f "${phpExtensionDir}/${PHP_extension}.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP ${PHP_extension} module installed successfully! ${CEND}"; }
  93. }
  94. # Uninstall succ
  95. Uninstall_succ() {
  96. [ -e "`ls ${php_install_dir}/etc/php.d/0?-${PHP_extension}.ini 2> /dev/null`" ] && { rm -rf ${php_install_dir}/etc/php.d/0?-${PHP_extension}.ini; Restart_PHP; echo; echo "${CMSG}PHP ${PHP_extension} module uninstall completed${CEND}"; } || { echo; echo "${CWARNING}${PHP_extension} module does not exist! ${CEND}"; }
  97. }
  98. Install_fail2ban() {
  99. [ ! -e "${python_install_dir}/bin/python" ] && Install_Python
  100. pushd ${oneinstack_dir}/src > /dev/null
  101. src_url=http://mirrors.linuxeye.com/oneinstack/src/fail2ban-${fail2ban_ver}.tar.gz && Download_src
  102. tar xzf fail2ban-${fail2ban_ver}.tar.gz
  103. pushd fail2ban-${fail2ban_ver}
  104. sed -i 's@for i in xrange(50)@for i in range(50)@' fail2ban/__init__.py
  105. ${python_install_dir}/bin/python setup.py install
  106. if [ "${PM}" == 'yum' ]; then
  107. LOGPATH=/var/log/secure
  108. /bin/cp files/redhat-initd /etc/init.d/fail2ban
  109. sed -i "s@^FAIL2BAN=.*@FAIL2BAN=${python_install_dir}/bin/fail2ban-client@" /etc/init.d/fail2ban
  110. sed -i 's@Starting fail2ban.*@&\n [ ! -e "/var/run/fail2ban" ] \&\& mkdir /var/run/fail2ban@' /etc/init.d/fail2ban
  111. chmod +x /etc/init.d/fail2ban
  112. chkconfig --add fail2ban
  113. chkconfig fail2ban on
  114. fi
  115. if [ "${PM}" == 'apt-get' ]; then
  116. LOGPATH=/var/log/auth.log
  117. /bin/cp files/debian-initd /etc/init.d/fail2ban
  118. sed -i 's@2 3 4 5@3 4 5@' /etc/init.d/fail2ban
  119. sed -i "s@^DAEMON=.*@DAEMON=${python_install_dir}/bin/\$NAME-client@" /etc/init.d/fail2ban
  120. chmod +x /etc/init.d/fail2ban
  121. update-rc.d fail2ban defaults
  122. fi
  123. [ -z "`grep ^Port /etc/ssh/sshd_config`" ] && now_ssh_port=22 || now_ssh_port=`grep ^Port /etc/ssh/sshd_config | awk '{print $2}' | head -1`
  124. cat > /etc/fail2ban/jail.local << EOF
  125. [DEFAULT]
  126. ignoreip = 127.0.0.1/8
  127. bantime = 86400
  128. findtime = 600
  129. maxretry = 5
  130. [ssh-iptables]
  131. enabled = true
  132. filter = sshd
  133. action = iptables[name=SSH, port=$now_ssh_port, protocol=tcp]
  134. logpath = $LOGPATH
  135. EOF
  136. cat > /etc/logrotate.d/fail2ban << EOF
  137. /var/log/fail2ban.log {
  138. missingok
  139. notifempty
  140. postrotate
  141. ${python_install_dir}/bin/fail2ban-client flushlogs >/dev/null || true
  142. endscript
  143. }
  144. EOF
  145. sed -i 's@^iptables = iptables.*@iptables = iptables@' /etc/fail2ban/action.d/iptables-common.conf
  146. kill -9 `ps -ef | grep fail2ban | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
  147. service fail2ban start
  148. popd > /dev/null
  149. if [ -e "${python_install_dir}/bin/fail2ban-python" ]; then
  150. echo; echo "${CSUCCESS}fail2ban installed successfully! ${CEND}"
  151. else
  152. echo; echo "${CFAILURE}fail2ban install failed, Please try again! ${CEND}"
  153. fi
  154. popd > /dev/null
  155. }
  156. Uninstall_fail2ban() {
  157. service fail2ban stop
  158. ${python_install_dir}/bin/pip uninstall -y fail2ban > /dev/null 2>&1
  159. rm -rf /etc/init.d/fail2ban /etc/fail2ban /etc/logrotate.d/fail2ban /var/log/fail2ban.* /var/run/fail2ban
  160. echo; echo "${CMSG}fail2ban uninstall completed${CEND}";
  161. }
  162. ACTION_FUN() {
  163. while :; do
  164. echo
  165. echo "Please select an action:"
  166. echo -e "\t${CMSG}1${CEND}. install"
  167. echo -e "\t${CMSG}2${CEND}. uninstall"
  168. read -e -p "Please input a number:(Default 1 press Enter) " ACTION
  169. ACTION=${ACTION:-1}
  170. if [[ ! "${ACTION}" =~ ^[1,2]$ ]]; then
  171. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  172. else
  173. break
  174. fi
  175. done
  176. }
  177. while :;do
  178. printf "
  179. What Are You Doing?
  180. \t${CMSG} 1${CEND}. Install/Uninstall PHP opcode cache
  181. \t${CMSG} 2${CEND}. Install/Uninstall ZendGuardLoader/ionCube/SourceGuardian PHP Extension
  182. \t${CMSG} 3${CEND}. Install/Uninstall ImageMagick/GraphicsMagick PHP Extension
  183. \t${CMSG} 4${CEND}. Install/Uninstall fileinfo/imap/phalcon/mongodb PHP Extension
  184. \t${CMSG} 5${CEND}. Install/Uninstall memcached/memcache
  185. \t${CMSG} 6${CEND}. Install/Uninstall Redis
  186. \t${CMSG} 7${CEND}. Install/Uninstall swoole PHP Extension
  187. \t${CMSG} 8${CEND}. Install/Uninstall xdebug PHP Extension
  188. \t${CMSG} 9${CEND}. Install/Uninstall PHP Composer
  189. \t${CMSG}10${CEND}. Install/Uninstall fail2ban
  190. \t${CMSG}11${CEND}. Install/Uninstall ngx_lua_waf
  191. \t${CMSG} q${CEND}. Exit
  192. "
  193. read -e -p "Please input the correct option: " Number
  194. if [[ ! "${Number}" =~ ^[1-9,q]$|^1[0-2]$ ]]; then
  195. echo "${CFAILURE}input error! Please only input 1~11 and q${CEND}"
  196. else
  197. case "${Number}" in
  198. 1)
  199. ACTION_FUN
  200. while :; do echo
  201. echo "Please select a opcode cache of the PHP:"
  202. echo -e "\t${CMSG}1${CEND}. Zend OPcache"
  203. echo -e "\t${CMSG}2${CEND}. XCache"
  204. echo -e "\t${CMSG}3${CEND}. APCU"
  205. echo -e "\t${CMSG}4${CEND}. eAccelerator"
  206. read -e -p "Please input a number:(Default 1 press Enter) " phpcache_option
  207. phpcache_option=${phpcache_option:-1}
  208. if [[ ! "${phpcache_option}" =~ ^[1-4]$ ]]; then
  209. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  210. else
  211. case "${phpcache_option}" in
  212. 1)
  213. PHP_extension=opcache
  214. ;;
  215. 2)
  216. PHP_extension=xcache
  217. ;;
  218. 3)
  219. PHP_extension=apcu
  220. ;;
  221. 4)
  222. PHP_extension=eaccelerator
  223. ;;
  224. esac
  225. break
  226. fi
  227. done
  228. if [ "${ACTION}" = '1' ]; then
  229. Check_PHP_Extension
  230. case "${phpcache_option}" in
  231. 1)
  232. pushd ${oneinstack_dir}/src > /dev/null
  233. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  234. src_url=https://pecl.php.net/get/zendopcache-${zendopcache_ver}.tgz && Download_src
  235. Install_ZendOPcache
  236. else
  237. src_url=http://www.php.net/distributions/php-${PHP_detail_ver}.tar.gz && Download_src
  238. Install_ZendOPcache
  239. fi
  240. popd > /dev/null
  241. Check_succ
  242. ;;
  243. 2)
  244. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$ ]]; then
  245. while :; do
  246. read -e -p "Please input xcache admin password: " xcachepwd
  247. (( ${#xcachepwd} >= 5 )) && { xcachepwd_md5=$(echo -n "${xcachepwd}" | md5sum | awk '{print $1}') ; break ; } || echo "${CFAILURE}xcache admin password least 5 characters! ${CEND}"
  248. done
  249. checkDownload
  250. Install_XCache
  251. Check_succ
  252. else
  253. echo "${CWARNING}Your php does not support XCache! ${CEND}"; exit 1
  254. fi
  255. ;;
  256. 3)
  257. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$|^7.[0-3]$ ]]; then
  258. checkDownload
  259. Install_APCU
  260. Check_succ
  261. else
  262. echo "${CWARNING}Your php does not support APCU! ${CEND}"; exit 1
  263. fi
  264. ;;
  265. 4)
  266. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  267. checkDownload
  268. Install_eAccelerator
  269. Check_succ
  270. else
  271. echo "${CWARNING}Your php does not support eAccelerator! ${CEND}"; exit 1
  272. fi
  273. ;;
  274. esac
  275. else
  276. Uninstall_succ
  277. fi
  278. ;;
  279. 2)
  280. ACTION_FUN
  281. while :; do echo
  282. echo "Please select ZendGuardLoader/ionCube/SourceGuardian:"
  283. echo -e "\t${CMSG}1${CEND}. ZendGuardLoader"
  284. echo -e "\t${CMSG}2${CEND}. ionCube Loader"
  285. echo -e "\t${CMSG}3${CEND}. SourceGuardian"
  286. read -e -p "Please input a number:(Default 1 press Enter) " Loader
  287. Loader=${Loader:-1}
  288. if [[ ! "${Loader}" =~ ^[1-3]$ ]]; then
  289. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  290. else
  291. [ "${Loader}" = '1' ] && PHP_extension=ZendGuardLoader
  292. [ "${Loader}" = '2' ] && PHP_extension=ioncube
  293. [ "${Loader}" = '3' ] && PHP_extension=sourceguardian
  294. break
  295. fi
  296. done
  297. if [ "${ACTION}" = '1' ]; then
  298. Check_PHP_Extension
  299. if [ "${Loader}" = '1' ]; then
  300. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$ ]] && [ "${armplatform}" != 'y' ]; then
  301. zendguardloader_yn='y' && checkDownload
  302. Install_ZendGuardLoader
  303. Check_succ
  304. else
  305. echo; echo "${CWARNING}Your php ${PHP_detail_ver} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  306. fi
  307. elif [ "${Loader}" = '2' ]; then
  308. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$|^7.[0-2]$ ]] || [ "${TARGET_ARCH}" != "arm64" ]; then
  309. ioncube_yn='y' && checkDownload
  310. Install_ionCube
  311. Restart_PHP; echo "${CSUCCESS}PHP ioncube module installed successfully! ${CEND}";
  312. else
  313. echo; echo "${CWARNING}Your php ${PHP_detail_ver} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  314. fi
  315. elif [ "${Loader}" = '3' ]; then
  316. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$|^7.[0-2]$ ]] || [ "${TARGET_ARCH}" != "armv8" ]; then
  317. sourceguardian_yn='y' && checkDownload
  318. Install_SourceGuardian
  319. Restart_PHP; echo "${CSUCCESS}PHP SourceGuardian module installed successfully! ${CEND}";
  320. else
  321. echo; echo "${CWARNING}Your php ${PHP_detail_ver} or platform ${TARGET_ARCH} does not support ${PHP_extension}! ${CEND}";
  322. fi
  323. fi
  324. else
  325. Uninstall_succ
  326. fi
  327. ;;
  328. 3)
  329. ACTION_FUN
  330. while :; do echo
  331. echo "Please select ImageMagick/GraphicsMagick:"
  332. echo -e "\t${CMSG}1${CEND}. ImageMagick"
  333. echo -e "\t${CMSG}2${CEND}. GraphicsMagick"
  334. read -e -p "Please input a number:(Default 1 press Enter) " magick_option
  335. magick_option=${magick_option:-1}
  336. if [[ ! "${magick_option}" =~ ^[1,2]$ ]]; then
  337. echo "${CWARNING}input error! Please only input number 1~2${CEND}"
  338. else
  339. [ "${magick_option}" = '1' ] && PHP_extension=imagick
  340. [ "${magick_option}" = '2' ] && PHP_extension=gmagick
  341. break
  342. fi
  343. done
  344. if [ "${ACTION}" = '1' ]; then
  345. Check_PHP_Extension
  346. magick_yn=y && checkDownload
  347. if [ "${magick_option}" = '1' ]; then
  348. [ ! -d "${imagick_install_dir}" ] && Install_ImageMagick
  349. Install_pecl-imagick
  350. Check_succ
  351. elif [ "${magick_option}" = '2' ]; then
  352. [ ! -d "${gmagick_install_dir}" ] && Install_GraphicsMagick
  353. Install_pecl-gmagick
  354. Check_succ
  355. fi
  356. else
  357. Uninstall_succ
  358. [ -d "${imagick_install_dir}" ] && rm -rf ${imagick_install_dir}
  359. [ -d "${gmagick_install_dir}" ] && rm -rf ${gmagick_install_dir}
  360. fi
  361. ;;
  362. 4)
  363. ACTION_FUN
  364. while :; do echo
  365. echo "Please select fileinfo/imap/phalcon/mongodb:"
  366. echo -e "\t${CMSG}1${CEND}. fileinfo"
  367. echo -e "\t${CMSG}2${CEND}. imap"
  368. echo -e "\t${CMSG}3${CEND}. phalcon"
  369. echo -e "\t${CMSG}4${CEND}. mongodb"
  370. read -e -p "Please input a number:(Default 1 press Enter) " phpext_option
  371. phpext_option=${phpext_option:-1}
  372. if [[ ! "${phpext_option}" =~ ^[1-4]$ ]]; then
  373. echo "${CWARNING}input error! Please only input number 1~4${CEND}"
  374. else
  375. if [ "${phpext_option}" = '1' ]; then
  376. PHP_extension=fileinfo
  377. elif [ "${phpext_option}" = '2' ]; then
  378. PHP_extension=imap
  379. IMAP_ARGS='--with-kerberos --with-imap --with-imap-ssl'
  380. if [ "${PM}" == 'yum' ]; then
  381. yum -y install libc-client-devel
  382. [ "${OS_BIT}" == '64' -a ! -e /usr/lib/libc-client.so ] && ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
  383. else
  384. apt-get -y install libc-client2007e-dev
  385. fi
  386. elif [ "${phpext_option}" = '3' ]; then
  387. PHP_extension=phalcon
  388. elif [ "${phpext_option}" = '4' ]; then
  389. if [[ "${PHP_main_ver}" =~ ^5.[3-4]$ ]]; then
  390. PHP_extension=mongo
  391. else
  392. PHP_extension=mongodb
  393. fi
  394. fi
  395. break
  396. fi
  397. done
  398. if [ "${ACTION}" = '1' ]; then
  399. Check_PHP_Extension
  400. pushd ${oneinstack_dir}/src > /dev/null
  401. if [[ "${phpext_option}" =~ ^[1-2]$ ]]; then
  402. src_url=http://www.php.net/distributions/php-${PHP_detail_ver}.tar.gz && Download_src
  403. tar xzf php-${PHP_detail_ver}.tar.gz
  404. pushd php-${PHP_detail_ver}/ext/${PHP_extension}
  405. ${php_install_dir}/bin/phpize
  406. ./configure --with-php-config=${php_install_dir}/bin/php-config ${IMAP_ARGS}
  407. make -j ${THREAD} && make install
  408. [ -f "${phpExtensionDir}/${PHP_extension}.so" ] && echo "extension=${PHP_extension}.so" > ${php_install_dir}/etc/php.d/04-${PHP_extension}.ini
  409. popd > /dev/null
  410. rm -rf php-${PHP_detail_ver}
  411. elif [ "${phpext_option}" = '3' ]; then
  412. if [[ "${PHP_main_ver}" =~ ^5.[5-6]$|^7.[0-2]$ ]]; then
  413. src_url=http://mirrors.linuxeye.com/oneinstack/src/cphalcon-${phalcon_ver}.tar.gz && Download_src
  414. tar xzf cphalcon-${phalcon_ver}.tar.gz
  415. pushd cphalcon-${phalcon_ver}/build
  416. ./install --phpize ${php_install_dir}/bin/phpize --php-config ${php_install_dir}/bin/php-config --arch ${OS_BIT}bits
  417. [ -f "${phpExtensionDir}/${PHP_extension}.so" ] && echo "extension=${PHP_extension}.so" > ${php_install_dir}/etc/php.d/04-${PHP_extension}.ini
  418. popd > /dev/null
  419. rm -rf cphalcon-${phalcon_ver}
  420. else
  421. echo; echo "${CWARNING}Your php ${PHP_detail_ver} does not support ${PHP_extension}! ${CEND}";
  422. fi
  423. elif [ "${phpext_option}" = '4' ]; then
  424. if [ "${PHP_extension}" == 'mongo' ]; then
  425. echo "Download pecl mongo for php..."
  426. src_url=https://pecl.php.net/get/mongo-${pecl_mongo_ver}.tgz && Download_src
  427. elif [ "${PHP_extension}" == 'mongo' ]; then
  428. echo "Download pecl mongodb for php..."
  429. src_url=https://pecl.php.net/get/mongodb-${pecl_mongodb_ver}.tgz && Download_src
  430. fi
  431. Install_pecl-mongodb
  432. fi
  433. popd > /dev/null
  434. Check_succ
  435. else
  436. Uninstall_succ
  437. fi
  438. ;;
  439. 5)
  440. ACTION_FUN
  441. while :; do echo
  442. echo "Please select memcache/memcached PHP Extension:"
  443. echo -e "\t${CMSG}1${CEND}. memcache PHP Extension"
  444. echo -e "\t${CMSG}2${CEND}. memcached PHP Extension"
  445. echo -e "\t${CMSG}3${CEND}. memcache/memcached PHP Extension"
  446. read -e -p "Please input a number:(Default 1 press Enter) " Memcache
  447. Memcache=${Memcache:-1}
  448. if [[ ! "${Memcache}" =~ ^[1-3]$ ]]; then
  449. echo "${CWARNING}input error! Please only input number 1~3${CEND}"
  450. else
  451. [ "${Memcache}" = '1' ] && PHP_extension=memcache
  452. [ "${Memcache}" = '2' ] && PHP_extension=memcached
  453. break
  454. fi
  455. done
  456. if [ "${ACTION}" = '1' ]; then
  457. memcached_yn=y && checkDownload
  458. case "${Memcache}" in
  459. 1)
  460. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  461. Check_PHP_Extension
  462. Install_pecl-memcache
  463. Check_succ
  464. ;;
  465. 2)
  466. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  467. Check_PHP_Extension
  468. Install_pecl-memcached
  469. Check_succ
  470. ;;
  471. 3)
  472. [ ! -d "${memcached_install_dir}/include/memcached" ] && Install_memcached
  473. PHP_extension=memcache && Check_PHP_Extension
  474. Install_pecl-memcache
  475. PHP_extension=memcached && Check_PHP_Extension
  476. Install_pecl-memcached
  477. [ -f "${phpExtensionDir}/memcache.so" -a "${phpExtensionDir}/memcached.so" ] && { Restart_PHP; echo;echo "${CSUCCESS}PHP memcache/memcached module installed successfully! ${CEND}"; }
  478. ;;
  479. esac
  480. else
  481. PHP_extension=memcache && Uninstall_succ
  482. PHP_extension=memcached && Uninstall_succ
  483. [ -e "${memcached_install_dir}" ] && { service memcached stop > /dev/null 2>&1; rm -rf ${memcached_install_dir} /etc/init.d/memcached /usr/bin/memcached; }
  484. fi
  485. ;;
  486. 6)
  487. ACTION_FUN
  488. PHP_extension=redis
  489. redis_yn=y && checkDownload
  490. if [ "${ACTION}" = '1' ]; then
  491. [ ! -d "${redis_install_dir}" ] && Install_redis-server
  492. Check_PHP_Extension
  493. Install_pecl-redis
  494. else
  495. Uninstall_succ
  496. [ -e "${redis_install_dir}" ] && { service redis-server stop > /dev/null 2>&1; rm -rf ${redis_install_dir} /etc/init.d/redis-server /usr/local/bin/redis-*; }
  497. fi
  498. ;;
  499. 7)
  500. ACTION_FUN
  501. PHP_extension=swoole
  502. if [ "${ACTION}" = '1' ]; then
  503. Check_PHP_Extension
  504. pushd ${oneinstack_dir}/src > /dev/null
  505. if [[ "${PHP_main_ver}" =~ ^5\.[3-6]$ ]]; then
  506. src_url=https://pecl.php.net/get/swoole-1.10.5.tgz && Download_src
  507. tar xzf swoole-1.10.5.tgz
  508. pushd swoole-1.10.5
  509. else
  510. src_url=https://pecl.php.net/get/swoole-${swoole_ver}.tgz && Download_src
  511. tar xzf swoole-${swoole_ver}.tgz
  512. pushd swoole-${swoole_ver}
  513. fi
  514. ${php_install_dir}/bin/phpize
  515. ./configure --with-php-config=${php_install_dir}/bin/php-config --enable-openssl --with-openssl-dir=${openssl_install_dir}
  516. make -j ${THREAD} && make install
  517. popd > /dev/null
  518. rm -rf swoole-${swoole_ver}
  519. popd > /dev/null
  520. echo 'extension=swoole.so' > ${php_install_dir}/etc/php.d/06-swoole.ini
  521. Check_succ
  522. else
  523. Uninstall_succ
  524. fi
  525. ;;
  526. 8)
  527. ACTION_FUN
  528. PHP_extension=xdebug
  529. if [ "${ACTION}" = '1' ]; then
  530. Check_PHP_Extension
  531. pushd ${oneinstack_dir}/src > /dev/null
  532. if [[ "${PHP_main_ver}" =~ ^7\.[0-3]$ ]]; then
  533. src_url=https://pecl.php.net/get/xdebug-${xdebug_ver}.tgz && Download_src
  534. src_url=http://mirrors.linuxeye.com/oneinstack/src/webgrind-master.zip && Download_src
  535. tar xzf xdebug-${xdebug_ver}.tgz
  536. unzip -q webgrind-master.zip
  537. /bin/mv webgrind-master ${wwwroot_dir}/default/webgrind
  538. pushd xdebug-${xdebug_ver}
  539. elif [[ "${PHP_main_ver}" =~ ^5\.[5-6]$ ]]; then
  540. src_url=https://pecl.php.net/get/xdebug-2.5.5.tgz && Download_src
  541. src_url=http://mirrors.linuxeye.com/oneinstack/src/webgrind-master.zip && Download_src
  542. tar xzf xdebug-2.5.5.tgz
  543. unzip -q webgrind-master.zip
  544. /bin/mv webgrind-master ${wwwroot_dir}/default/webgrind
  545. pushd xdebug-2.5.5
  546. else
  547. echo "${CWARNING}Need a PHP version >= 5.5.0 and <= 7.2.0${CEND}"
  548. exit 1
  549. fi
  550. ${php_install_dir}/bin/phpize
  551. ./configure --with-php-config=${php_install_dir}/bin/php-config
  552. make -j ${THREAD} && make install
  553. popd > /dev/null
  554. rm -rf xdebug-${xdebug_ver}
  555. popd > /dev/null
  556. [ ! -e /tmp/xdebug ] && { mkdir /tmp/xdebug; chown ${run_user}.${run_user} /tmp/xdebug; }
  557. [ ! -e /tmp/webgrind ] && { mkdir /tmp/webgrind; chown ${run_user}.${run_user} /tmp/webgrind; }
  558. chown -R ${run_user}.${run_user} ${wwwroot_dir}/default/webgrind
  559. sed -i 's@static $storageDir.*@static $storageDir = "/tmp/webgrind";@' ${wwwroot_dir}/default/webgrind/config.php
  560. sed -i 's@static $profilerDir.*@static $profilerDir = "/tmp/xdebug";@' ${wwwroot_dir}/default/webgrind/config.php
  561. cat > ${php_install_dir}/etc/php.d/08-xdebug.ini << EOF
  562. [xdebug]
  563. zend_extension=xdebug.so
  564. xdebug.trace_output_dir=/tmp/xdebug
  565. xdebug.profiler_output_dir = /tmp/xdebug
  566. xdebug.profiler_enable = On
  567. xdebug.profiler_enable_trigger = 1
  568. EOF
  569. Check_succ
  570. echo; echo "Webgrind URL: ${CMSG}http://{Public IP}/webgrind ${CEND}"
  571. else
  572. rm -rf /tmp/{xdebug,webgrind} ${wwwroot_dir}/default/webgrind
  573. Uninstall_succ
  574. fi
  575. ;;
  576. 9)
  577. ACTION_FUN
  578. if [ "${ACTION}" = '1' ]; then
  579. [ -e "/usr/local/bin/composer" ] && { echo "${CWARNING}PHP Composer already installed! ${CEND}"; exit 1; }
  580. if [ "$IPADDR_COUNTRY"x == "CN"x ]; then
  581. wget -c https://dl.laravel-china.org/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  582. ${php_install_dir}/bin/php /usr/local/bin/composer config -g repo.packagist composer https://packagist.phpcomposer.com
  583. else
  584. wget -c https://getcomposer.org/composer.phar -O /usr/local/bin/composer > /dev/null 2>&1
  585. fi
  586. chmod +x /usr/local/bin/composer
  587. if [ -e "/usr/local/bin/composer" ]; then
  588. echo; echo "${CSUCCESS}Composer installed successfully! ${CEND}"
  589. else
  590. echo; echo "${CFAILURE}Composer install failed, Please try again! ${CEND}"
  591. fi
  592. else
  593. rm -rf /usr/local/bin/composer
  594. echo; echo "${CMSG}composer uninstall completed${CEND}";
  595. fi
  596. ;;
  597. 10)
  598. ACTION_FUN
  599. if [ "${ACTION}" = '1' ]; then
  600. Install_fail2ban
  601. else
  602. Uninstall_fail2ban
  603. fi
  604. ;;
  605. 11)
  606. ACTION_FUN
  607. if [ "${ACTION}" = '1' ]; then
  608. [ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
  609. [ -e "${tengine_install_dir}/sbin/nginx" ] && Tengine_lua_waf
  610. enable_lua_waf
  611. else
  612. disable_lua_waf
  613. fi
  614. ;;
  615. 12)
  616. ACTION_FUN
  617. if [ "${ACTION}" = '1' ]; then
  618. [ ! -e "${python_install_dir}/bin/python" ] && Install_Python
  619. Install_Panel
  620. else
  621. Uninstall_Panel
  622. fi
  623. ;;
  624. q)
  625. exit
  626. ;;
  627. esac
  628. fi
  629. done