Advertisement
Guest User

Untitled

a guest
May 6th, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 67.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. output(){
  4. echo -e '\e[36m'$1'\e[0m';
  5. }
  6.  
  7. warn(){
  8. echo -e '\e[31m'$1'\e[0m';
  9. }
  10.  
  11. preflight(){
  12. output "Pterodactyl Installation & Upgrade script v37.2"
  13. output "Copyright © 2018-2019 Thien Tran <thientran@securesrv.io>."
  14. output "Please report any issues or copyright violations to https://securesrv.io/discord"
  15. output ""
  16.  
  17. output "Thank you for your purchase. Please note that this script is meant to be installed on a fresh OS. Installing it on a non-fresh OS may cause problems."
  18. output "Automatic Operating System Detection initialized."
  19. if [ -r /etc/os-release ]; then
  20. lsb_dist="$(. /etc/os-release && echo "$ID")"
  21. dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
  22. else
  23. exit 1
  24. fi
  25. output "OS: $lsb_dist $dist_version detected."
  26. output ""
  27.  
  28. if [ "$lsb_dist" = "ubuntu" ]; then
  29. if [ "$dist_version" != "19.04" ] && [ "$dist_version" != "18.10" ] && [ "$dist_version" != "18.04" ] && [ "$dist_version" != "16.04" ]; then
  30. output "Unsupported Ubuntu version. Only Ubuntu 19.04, 18.10, 18.04, 16.04 are supported."
  31. exit 2
  32. fi
  33. elif [ "$lsb_dist" = "debian" ]; then
  34. if [ "$dist_version" != "9" ] && [ "$dist_version" != "8" ]; then
  35. output "Unsupported Debian version. Only Debian 9 and 8 are supported.."
  36. exit 2
  37. fi
  38. elif [ "$lsb_dist" = "fedora" ]; then
  39. if [ "$dist_version" != "29" ] && [ "$dist_version" != "28" ]; then
  40. output "Unsupported Fedora version. Only Fedora 29 and 28 is supported."
  41. exit 2
  42. fi
  43. elif [ "$lsb_dist" = "centos" ]; then
  44. if [ "$dist_version" != "7" ]; then
  45. output "Unsupported CentOS version. Only CentOS 7 is supported."
  46. exit 2
  47. fi
  48. elif [ "$lsb_dist" = "rhel" ]; then
  49. if [ "$dist_version" != "7" ]&&[ "$dist_version" != "7.1" ]&&[ "$dist_version" != "7.2" ]&&[ "$dist_version" != "7.3" ]&&[ "$dist_version" != "7.4" ]&&[ "$dist_version" != "7.5" ]&&[ "$dist_version" != "7.6" ]; then
  50. output "Unsupported RHEL version. Only RHEL 7 is supported."
  51. exit 2
  52. fi
  53. elif [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "debian" ] && [ "$lsb_dist" != "centos" ] && [ "$lsb_dist" != "rhel" ]; then
  54. output "Unsupported Operating System."
  55. output ""
  56. output "Supported OS:"
  57. output "Ubuntu: 19.04 18.10, 18.04, 16.04"
  58. output "Debian: 9, 8"
  59. output "Fedora: 29, 28"
  60. output "CentOS: 7"
  61. output "RHEL: 7"
  62. exit 2
  63. fi
  64.  
  65. if [ "$EUID" -ne 0 ]; then
  66. output "Please run as root"
  67. exit 3
  68. fi
  69.  
  70. output "Automatic Architecture Detection initialized."
  71. MACHINE_TYPE=`uname -m`
  72. if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  73. output "64-bit server detected! Good to go."
  74. output ""
  75. else
  76. output "Unsupported architecture detected! Please switch to 64-bit (x86_64)."
  77. exit 4
  78. fi
  79.  
  80. output "Automatic Virtualization Detection initialized."
  81. if [ "$lsb_dist" = "ubuntu" ]; then
  82. apt-get update --fix-missing
  83. apt-get -y install software-properties-common
  84. add-apt-repository -y universe
  85. apt-get -y install virt-what
  86. elif [ "$lsb_dist" = "debian" ]; then
  87. apt update --fix-missing
  88. apt-get -y install software-properties-common virt-what wget
  89. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  90. yum -y install virt-what wget
  91. fi
  92. virt_serv=$(echo $(virt-what))
  93. if [ "$virt_serv" = "" ]; then
  94. output "Virtualization: Bare Metal detected."
  95. elif [ "$virt_serv" = "openvz lxc" ]; then
  96. output "Virtualization: OpenVZ 7 detected."
  97. elif [ "$virt_serv" = "xen xen-hvm" ]; then
  98. output "Virtualization: Xen-HVM detected."
  99. elif [ "$virt_serv" = "xen xen-hvm aws" ]; then
  100. output "Virtualization: Xen-HVM on AWS detected."
  101. warn "When doing allocation for the node, please use the internal ip as Google Cloud uses NAT."
  102. warn "Resuming in 10 seconds."
  103. sleep 10
  104. else
  105. output "Virtualization: $virt_serv detected."
  106. fi
  107. output ""
  108. if [ "$virt_serv" != "" ] && [ "$virt_serv" != "kvm" ] && [ "$virt_serv" != "vmware" ] && [ "$virt_serv" != "hyperv" ] && [ "$virt_serv" != "openvz lxc" ] && [ "$virt_serv" != "xen xen-hvm" ] && [ "$virt_serv" != "xen xen-hvm aws" ]; then
  109. warn "Unsupported Virtualization method. Please consult with your provider whether your server can run Docker or not. Proceed at your own risk."
  110. warn "No support would be given if your server breaks at any point in the future."
  111. warn "Proceed?\n[1] Yes.\n[2] No."
  112. read choice
  113. case $choice in
  114. 1) output "Proceeding..."
  115. ;;
  116. 2) output "Cancelling installation..."
  117. exit 5
  118. ;;
  119. esac
  120. output ""
  121. fi
  122.  
  123. output "Kernel Detection Initialized."
  124. if echo $(uname -r) | grep -q xxxx; then
  125. output "OVH Kernel Detected. The script will not work. Please install your server with a generic/distribution kernel."
  126. output "When you are reinstalling your server, click on 'custom installation' and click on 'use distribution' kernel after that."
  127. output "You might also want to do custom partritioning, remove the /home partrition and give / all the remaining space."
  128. output "Please do not hesitate to contact us if you need help regarding this issue."
  129. exit 6
  130. elif echo $(uname -r) | grep -q pve; then
  131. output "Proxmox LXE Kernel Detected. You have chosen to continue in the last step, therefore we are proceeding at your own risk."
  132. output "Proceeding with a risky operation..."
  133. elif echo $(uname -r) | grep -q stab; then
  134. if echo $(uname -r) | grep -q 2.6; then
  135. output "OpenVZ 6 detected. This server will definitely not work with Docker, regardless of what your provider might say. Exiting to avoid further damages."
  136. exit 6
  137. fi
  138. elif echo $(uname -r) | grep -q lve; then
  139. output "CloudLinux Kernel detected. Docker is not supported on CloudLinux. The script will exit to avoid further damages."
  140. exit 6
  141. elif echo $(uname -r) | grep -q gcp; then
  142. output "Google Cloud Platform Detected."
  143. warn "Please make sure you have static ip setup, otherwise the system will not work after a reboot."
  144. warn "Please also make sure the google firewall allows the ports needed for the server to function normally."
  145. warn "When doing allocation for the node, please use the internal ip as Google Cloud uses NAT."
  146. warn "Resuming in 10 seconds."
  147. sleep 10
  148. else
  149. output "Did not detect any bad kernel. Moving forward."
  150. output ""
  151. fi
  152.  
  153.  
  154. bash -c 'cat > /etc/motd' <<-'EOF'
  155.  
  156. ___ ____ ___ __ __ ____ ____ ___ ____ _ _
  157. / __| ___) __| )( | _ ( ___) __| _ ( \/ )
  158. \__ \)__| (__ )(__)( ) /)__)\__ \) /\ /
  159. (___(____)___|______|_)\_|____|___(_)\_) \/
  160.  
  161. Pterodactyl Installation Script v37.2
  162. Copyright © 2018-2019 Thien Tran <thientran@securesrv.io>
  163. Download link: https://www.mc-market.org/resources/8070/
  164. Support: https://securesrv.io/discord
  165.  
  166. EOF
  167. ########ANTILEAK########
  168. if [ "$lsb_dist" = "ubuntu" ] || [ "$dist_version" = "19.04" ]; then
  169. apt -y install docker.io
  170. else
  171. curl -sSL https://get.docker.com/ | CHANNEL=stable bash
  172. fi
  173. systemctl enable docker
  174. systemctl start docker
  175.  
  176. ########CHECK IF THE VERSION IS LATEST########
  177. wget https://softauth.securesrv.io >/dev/null 2>&1
  178. if grep -q "llynGq6k97xPD0aumF3mDrPoat3tuTpvF25k0FxY" index.html; then
  179. output "Up to date, good to go!"
  180. output ""
  181. ########IF OUTDATED OR LEAKED########
  182. output "Outdated script, please use the latest version. If you believe this is an error, please contact us on Discord."
  183. output "If you happen to be using one of the pirated version of the script, please buy the resource to support the author. We accept both paypal and cryptocurrencies."
  184. output "Resource link: https://www.mc-market.org/resources/8070/"
  185. rm -rf index.html
  186. ########NO AUTOMATIC REMOVAL - REPORT BACK AS ONLINE##########
  187. exit 69
  188. ########IF USER IS LEGIT AND RERUN THE LATEST SCRIPT, IT WILL RUN docker swarm leave >/dev/null 2>&1 AND LEAVE########
  189. fi
  190. ########ANTILEAK########
  191.  
  192. output "Please select your installation option:"
  193. output "[1] Install the panel."
  194. output "[2] Install the daemon."
  195. output "[3] Install the panel and daemon."
  196. output "[4] Install the standalone SFTP server."
  197. output "[5] Upgrade 0.7.x panel to 0.7.13."
  198. output "[6] Upgrade 0.6.x daemon to 0.6.12."
  199. output "[7] Upgrade the panel to 0.7.13 and daemon to 0.6.12"
  200. output "[8] Upgrade the standalone SFTP server to 1.0.4."
  201. output "[9] Install or Update to phpMyAdmin 4.8.5 (Only use this after you have installed the panel.)"
  202. output "[10] Change Pterodactyl theme."
  203. output "[11] Emergency MariaDB root password reset."
  204. output "[12] Emergency Database host information reset."
  205. read choice
  206. case $choice in
  207. 1 ) installoption=1
  208. output "You have selected panel installation only."
  209. ;;
  210. 2 ) installoption=2
  211. output "You have selected daemon installation only."
  212. ;;
  213. 3 ) installoption=3
  214. output "You have selected panel and daemon installation."
  215. ;;
  216. 4 ) installoption=4
  217. output "You have selected to install the standalone SFTP server."
  218. ;;
  219. 5 ) installoption=5
  220. output "You have selected to upgrade the panel."
  221. ;;
  222. 6 ) installoption=6
  223. output "You have selected to upgrade the daemon."
  224. ;;
  225. 7 ) installoption=7
  226. output "You have selected to upgrade both the panel and daemon."
  227. ;;
  228. 8 ) installoption=8
  229. output "You have selected to upgrade the standalone SFTP."
  230. ;;
  231. 9 ) installoption=9
  232. output "You have selected to install or update phpMyAdmin."
  233. ;;
  234. 10 ) installoption=10
  235. output "You have selected to change Pterodactyl's theme."
  236. ;;
  237. 11 ) installoption=11
  238. output "You have selected MariaDB root password reset."
  239. ;;
  240. 12 ) installoption=12
  241. output "You have selected Database Host information reset."
  242. ;;
  243. esac
  244. }
  245.  
  246. webserver_options() {
  247. output "Please select which web server you would like to use:\n[1] Nginx (Recommended).\n[2] Apache2/Httpd."
  248. read choice
  249. case $choice in
  250. 1 ) webserver=1
  251. output "You have selected Nginx."
  252. output ""
  253. ;;
  254. 2 ) webserver=2
  255. output "You have selected Apache2 / Httpd."
  256. output ""
  257. ;;
  258. * ) output "You did not enter a valid selection."
  259. webserver_options
  260. esac
  261. }
  262.  
  263. theme_options() {
  264. output "Would you like to install Fonix's themes?"
  265. output "[1] No."
  266. output "[2] Tango Twist."
  267. output "[3] Blue Brick."
  268. output "[4] Minecraft Madness."
  269. output "[5] Lime Stitch."
  270. output "[6] Red Ape."
  271. output "[7] BlackEnd Space."
  272. output "[8] Nothing But Graphite."
  273. output ""
  274. output "You can find out about Fonix's themes here: https://github.com/TheFonix/Pterodactyl-Themes"
  275. read choice
  276. case $choice in
  277. 1 ) themeoption=1
  278. output "You have selected to install vanilla Pterodactyl theme."
  279. output ""
  280. ;;
  281. 2 ) themeoption=2
  282. output "You have selected to install Fonix's Tango Twist theme."
  283. output ""
  284. ;;
  285. 3 ) themeoption=3
  286. output "You have selected to install Fonix's Blue Brick theme."
  287. output ""
  288. ;;
  289. 4 ) themeoption=4
  290. output "You have selected to install Fonix's Minecraft Madness theme."
  291. output ""
  292. ;;
  293. 5 ) themeoption=5
  294. output "You have selected to install Fonix's Lime Stitch theme."
  295. output ""
  296. ;;
  297. 6 ) themeoption=6
  298. output "You have selected to install Fonix's Red Ape theme."
  299. output ""
  300. ;;
  301. 7 ) themeoption=7
  302. output "You have selected to install Fonix's BlackEnd Space theme."
  303. output ""
  304. ;;
  305. 8 ) themeoption=8
  306. output "You have selected to install Fonix's Nothing But Graphite theme."
  307. output ""
  308. ;;
  309. * ) output "You did not enter a a valid selection"
  310. theme_options
  311. esac
  312. }
  313.  
  314. required_infos() {
  315. output "Please enter the desired user email address:"
  316. read email
  317. dns_check
  318. }
  319.  
  320. ssl_option(){
  321. output "Do you want to use SSL? [Y/n]: "
  322. output "If you have a domain, please set it to 'yes' for maximum security."
  323. output "If you choose 'no', the server will be accessible via the IP without SSL. Please keep in mind this is HIGHLY INSECURE and is NOT RECOMMENDED!"
  324. output "If you panel has SSL, your daemon must have SSL as well."
  325. read RESPONSE
  326. USE_SSL=true
  327. if [[ "${RESPONSE}" =~ ^([nN][oO]|[nN])+$ ]]; then
  328. USE_SSL=false
  329. fi
  330.  
  331. if [ $USE_SSL = "true" ]; then
  332. dns_check
  333. fi
  334. }
  335.  
  336. dns_check(){
  337. output "Please enter your FQDN (panel.yourdomain.com):"
  338. read FQDN
  339.  
  340. output "Resolving DNS."
  341. SERVER_IP=$(curl -s http://checkip.amazonaws.com)
  342. DOMAIN_RECORD=$(dig +short ${FQDN})
  343. if [ "${SERVER_IP}" != "${DOMAIN_RECORD}" ]; then
  344. output ""
  345. output "The entered domain does not resolve to the primary public IP of this server."
  346. output "Please make an A record pointing to your server's ip. For example, if you make an A record called 'panel' pointing to your server's ip, your FQDN is panel.yourdomain.tld"
  347. output "If you are using Cloudflare, please disable the orange cloud."
  348. output "If you do not have a domain, you can get a free one at https://www.freenom.com/en/index.html?lang=en."
  349. dns_check
  350. else
  351. output "Domain resolved correctly. Good to go."
  352. fi
  353. }
  354.  
  355. theme() {
  356. output "Theme installation initialized."
  357. cd /var/www/pterodactyl
  358. if [ "$themeoption" = "1" ]; then
  359. output "Keeping Pterodactyl's vanilla theme."
  360. elif [ "$themeoption" = "2" ]; then
  361. curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/MasterThemes/TangoTwist/build.sh | sh
  362. elif [ "$themeoption" = "3" ]; then
  363. curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/MasterThemes/BlueBrick/build.sh | sh
  364. elif [ "$themeoption" = "4" ]; then
  365. curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/MasterThemes/MinecraftMadness/build.sh | sh
  366. elif [ "$themeoption" = "5" ]; then
  367. curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/MasterThemes/LimeStitch/build.sh | sh
  368. elif [ "$themeoption" = "6" ]; then
  369. curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/MasterThemes/RedApe/build.sh | sh
  370. elif [ "$themeoption" = "7" ]; then
  371. curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/MasterThemes/BlackEndSpace/build.sh | sh
  372. elif [ "$themeoption" = "8" ]; then
  373. curl https://raw.githubusercontent.com/TheFonix/Pterodactyl-Themes/master/MasterThemes/NothingButGraphite/build.sh | sh
  374. fi
  375. php artisan view:clear
  376. php artisan cache:clear
  377. }
  378.  
  379. repositories_setup(){
  380. output "Configuring your repositories."
  381. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  382. apt-get -y install sudo
  383. apt-get -y install software-properties-common
  384. echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
  385. apt-get -y update
  386. if [ "$lsb_dist" = "ubuntu" ]; then
  387. LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
  388. add-apt-repository -y ppa:chris-lea/redis-server
  389. add-apt-repository -y ppa:certbot/certbot
  390. add-apt-repository -y ppa:nginx/development
  391. if [ "$dist_version" = "18.10" ]; then
  392. apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
  393. add-apt-repository 'deb [arch=amd64] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu cosmic main'
  394. apt -y install tuned
  395. tuned-adm profile latency-performance
  396. elif [ "$dist_version" = "18.04" ]; then
  397. apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
  398. add-apt-repository -y 'deb [arch=amd64,arm64,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu bionic main'
  399. apt -y install tuned
  400. tuned-adm profile latency-performance
  401. elif [ "$dist_version" = "16.04" ]; then
  402. apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
  403. add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/ubuntu xenial main'
  404. apt -y install tuned
  405. tuned-adm profile latency-performance
  406. fi
  407. elif [ "$lsb_dist" = "debian" ]; then
  408. apt-get -y install ca-certificates apt-transport-https
  409. if [ "$dist_version" = "9" ]; then
  410. apt-get install -y software-properties-common dirmngr
  411. wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
  412. sudo echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
  413. sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
  414. sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/debian stretch main'
  415. apt -y install tuned
  416. tuned-adm profile latency-performance
  417. elif [ "$dist_version" = "8" ]; then
  418. wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
  419. echo "deb https://packages.sury.org/php/ jessie main" | sudo tee /etc/apt/sources.list.d/php.list
  420. apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
  421. add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.3/debian jessie main'
  422. fi
  423. fi
  424. apt-get -y update
  425. apt-get -y upgrade
  426. apt-get -y autoremove
  427. apt-get -y autoclean
  428. apt-get -y install dnsutils curl
  429. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  430. if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" = "29" ]; then
  431.  
  432. bash -c 'cat > /etc/yum.repos.d/mariadb.repo' <<-'EOF'
  433. [mariadb]
  434. name = MariaDB
  435. baseurl = http://yum.mariadb.org/10.3/fedora29-amd64
  436. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  437. gpgcheck=1
  438. EOF
  439.  
  440. bash -c 'cat > /etc/yum.repos.d/nginx.repo' <<-'EOF'
  441. [heffer-nginx-mainline]
  442. name=Copr repo for nginx-mainline owned by heffer
  443. baseurl=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/fedora-$releasever-$basearch/
  444. type=rpm-md
  445. skip_if_unavailable=True
  446. gpgcheck=1
  447. gpgkey=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/pubkey.gpg
  448. repo_gpgcheck=0
  449. enabled=1
  450. enabled_metadata=1
  451. EOF
  452.  
  453. dnf -y install http://rpms.remirepo.net/fedora/remi-release-29.rpm
  454. dnf -y install dnf-plugins-core
  455. dnf config-manager --set-enabled remi-php73
  456. dnf config-manager --set-enabled remi
  457.  
  458. elif [ "$lsb_dist" = "fedora" ] && [ "$dist_version" = "28" ]; then
  459.  
  460. bash -c 'cat > /etc/yum.repos.d/mariadb.repo' <<-'EOF'
  461. [mariadb]
  462. name = MariaDB
  463. baseurl = http://yum.mariadb.org/10.3/fedora28-amd64
  464. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  465. gpgcheck=1
  466. EOF
  467.  
  468. bash -c 'cat > /etc/yum.repos.d/nginx.repo' <<-'EOF'
  469. [heffer-nginx-mainline]
  470. name=Copr repo for nginx-mainline owned by heffer
  471. baseurl=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/fedora-$releasever-$basearch/
  472. type=rpm-md
  473. skip_if_unavailable=True
  474. gpgcheck=1
  475. gpgkey=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/pubkey.gpg
  476. repo_gpgcheck=0
  477. enabled=1
  478. enabled_metadata=1
  479. EOF
  480. dnf -y install http://rpms.remirepo.net/fedora/remi-release-28.rpm
  481. dnf -y install dnf-plugins-core
  482. dnf config-manager --set-enabled remi-php73
  483. dnf config-manager --set-enabled remi
  484.  
  485. elif [ "$lsb_dist" = "centos" ] && [ "$dist_version" = "7" ]; then
  486.  
  487. bash -c 'cat > /etc/yum.repos.d/mariadb.repo' <<-'EOF'
  488. [mariadb]
  489. name = MariaDB
  490. baseurl = http://yum.mariadb.org/10.3/centos7-amd64
  491. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  492. gpgcheck=1
  493. EOF
  494.  
  495. bash -c 'cat > /etc/yum.repos.d/nginx.repo' <<-'EOF'
  496. [heffer-nginx-mainline]
  497. name=Copr repo for nginx-mainline owned by heffer
  498. baseurl=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/epel-7-$basearch/
  499. type=rpm-md
  500. skip_if_unavailable=True
  501. gpgcheck=1
  502. gpgkey=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/pubkey.gpg
  503. repo_gpgcheck=0
  504. enabled=1
  505. enabled_metadata=1
  506. EOF
  507.  
  508. yum -y install epel-release
  509. yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  510. elif [ "$lsb_dist" = "rhel" ]; then
  511.  
  512. bash -c 'cat > /etc/yum.repos.d/mariadb.repo' <<-'EOF'
  513. [mariadb]
  514. name = MariaDB
  515. baseurl = http://yum.mariadb.org/10.3/rhel7-amd64
  516. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  517. gpgcheck=1
  518. EOF
  519.  
  520. bash -c 'cat > /etc/yum.repos.d/nginx.repo' <<-'EOF'
  521. [heffer-nginx-mainline]
  522. name=Copr repo for nginx-mainline owned by heffer
  523. baseurl=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/epel-7-$basearch/
  524. type=rpm-md
  525. skip_if_unavailable=True
  526. gpgcheck=1
  527. gpgkey=https://copr-be.cloud.fedoraproject.org/results/heffer/nginx-mainline/pubkey.gpg
  528. repo_gpgcheck=0
  529. enabled=1
  530. enabled_metadata=1
  531. EOF
  532. yum -y install epel-release
  533. yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  534. fi
  535. yum -y install yum-utils tuned
  536. tuned-adm profile latency-performance
  537. yum-config-manager --enable remi-php72
  538. yum -y upgrade
  539. yum -y autoremove
  540. yum -y clean packages
  541. yum -y install curl bind-utils
  542. fi
  543. }
  544.  
  545. install_dependencies(){
  546. output "Installing dependencies."
  547. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  548. if [ "$webserver" = "1" ]; then
  549. apt-get -y install php7.3 php7.3-cli php7.3-gd php7.3-mysql php7.3-pdo php7.3-mbstring php7.3-tokenizer php7.3-bcmath php7.3-xml php7.3-fpm php7.3-curl php7.3-zip curl tar unzip git redis-server nginx git wget expect jq
  550. elif [ "$webserver" = "2" ]; then
  551. apt-get -y install php7.3 php7.3-cli php7.3-gd php7.3-mysql php7.3-pdo php7.3-mbstring php7.3-tokenizer php7.3-bcmath php7.3-xml php7.3-fpm php7.3-curl php7.3-zip curl tar unzip git redis-server apache2 libapache2-mod-php7.3 redis-server git wget expect jq
  552. fi
  553. sh -c "DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server"
  554. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  555. if [ "$webserver" = "1" ]; then
  556. yum -y install php php-common php-fpm php-cli php-json php-mysqlnd php-mcrypt php-gd php-mbstring php-pdo php-zip php-bcmath php-dom php-opcache mariadb-server redis nginx git policycoreutils-python-utils libsemanage-devel unzip wget expect jq
  557. elif [ "$webserver" = "2" ]; then
  558. yum -y install php php-common php-fpm php-cli php-json php-mysqlnd php-mcrypt php-gd php-mbstring php-pdo php-zip php-bcmath php-dom php-opcache mariadb-server redis httpd git policycoreutils-python-utils libsemanage-devel mod_ssl unzip wget expect jq
  559. fi
  560. fi
  561.  
  562. output "Enabling Services."
  563. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  564. systemctl enable redis-server
  565. service redis-server start
  566. systemctl enable php7.3-fpm
  567. service php7.3-fpm start
  568. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  569. systemctl enable redis
  570. service redis start
  571. systemctl enable php-fpm
  572. service php-fpm start
  573. fi
  574.  
  575. systemctl enable cron
  576. systemctl enable mariadb
  577.  
  578. if [ "$webserver" = "1" ]; then
  579. systemctl enable nginx
  580. service nginx start
  581. elif [ "$webserver" = "2" ]; then
  582. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  583. systemctl enable apache2
  584. service apache2 start
  585. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  586. systemctl enable httpd
  587. service httpd start
  588. fi
  589. fi
  590. service cron start
  591. service mariadb start
  592. }
  593.  
  594. install_pterodactyl() {
  595. output "Creating the databases and setting root password."
  596. password=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  597. adminpassword=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  598. rootpassword=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  599. Q0="DROP DATABASE IF EXISTS test;"
  600. Q1="CREATE DATABASE IF NOT EXISTS panel;"
  601. Q2="GRANT ALL ON panel.* TO 'pterodactyl'@'127.0.0.1' IDENTIFIED BY '$password';"
  602. Q3="GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, EXECUTE, PROCESS, RELOAD, CREATE USER ON *.* TO 'admin'@'$SERVER_IP' IDENTIFIED BY '$adminpassword' WITH GRANT OPTION;"
  603. Q4="SET PASSWORD FOR 'root'@'localhost' = PASSWORD('$rootpassword');"
  604. Q5="SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('$rootpassword');"
  605. Q6="SET PASSWORD FOR 'root'@'::1' = PASSWORD('$rootpassword');"
  606. Q7="DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
  607. Q8="DELETE FROM mysql.user WHERE User='';"
  608. Q9="DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%';"
  609. Q10="FLUSH PRIVILEGES;"
  610. SQL="${Q0}${Q1}${Q2}${Q3}${Q4}${Q5}${Q6}${Q7}${Q8}${Q9}${Q10}"
  611. mysql -u root -e "$SQL"
  612.  
  613. output "Binding MariaDB to 0.0.0.0."
  614. if [ -f /etc/mysql/my.cnf ] ; then
  615. sed -i -- 's/bind-address/# bind-address/g' /etc/mysql/my.cnf
  616. sed -i '/\[mysqld\]/a bind-address = 0.0.0.0' /etc/mysql/my.cnf
  617. output 'Restarting MySQL process...'
  618. service mariadb restart
  619. elif [ -f /etc/my.cnf ] ; then
  620. sed -i -- 's/bind-address/# bind-address/g' /etc/my.cnf
  621. sed -i '/\[mysqld\]/a bind-address = 0.0.0.0' /etc/my.cnf
  622. output 'Restarting MySQL process...'
  623. service mariadb restart
  624. else
  625. output 'File my.cnf was not found! Please contact support.'
  626. fi
  627.  
  628. output "Downloading Pterodactyl."
  629. mkdir -p /var/www/pterodactyl
  630. cd /var/www/pterodactyl
  631. curl -Lo panel.tar.gz https://github.com/pterodactyl/panel/releases/download/v0.7.13/panel.tar.gz
  632. tar --strip-components=1 -xzvf panel.tar.gz
  633. chmod -R 755 storage/* bootstrap/cache/
  634.  
  635. output "Installing Pterodactyl."
  636. curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
  637. cp .env.example .env
  638. if [ "$lsb_dist" = "rhel" ]; then
  639. yum -y install composer
  640. composer update
  641. else
  642. composer install --no-dev --optimize-autoloader
  643. fi
  644. php artisan key:generate --force
  645. php artisan p:environment:setup -n --author=$email --url=https://$FQDN --timezone=America/New_York --cache=redis --session=database --queue=redis --redis-host=127.0.0.1 --redis-pass= --redis-port=6379
  646. php artisan p:environment:database --host=127.0.0.1 --port=3306 --database=panel --username=pterodactyl --password=$password
  647. output "To use PHP's internal mail sending, select [mail]. To use a custom SMTP server, select [smtp]. TLS Encryption is recommended."
  648. php artisan p:environment:mail
  649. php artisan migrate --seed --force
  650. php artisan p:user:make --email=$email --admin=1
  651. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  652. chown -R www-data:www-data * /var/www/pterodactyl
  653. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  654. if [ "$webserver" = "1" ]; then
  655. chown -R nginx:nginx * /var/www/pterodactyl
  656. elif [ "$webserver" = "2" ]; then
  657. chown -R apache:apache * /var/www/pterodactyl
  658. fi
  659. semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/pterodactyl/storage(/.*)?"
  660. restorecon -R /var/www/pterodactyl
  661. fi
  662.  
  663. output "Creating panel queue listeners"
  664. (crontab -l ; echo "* * * * * php /var/www/pterodactyl/artisan schedule:run >> /dev/null 2>&1")| crontab -
  665. service cron restart
  666.  
  667. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  668. cat > /etc/systemd/system/pteroq.service <<- 'EOF'
  669. [Unit]
  670. Description=Pterodactyl Queue Worker
  671. After=redis-server.service
  672.  
  673. [Service]
  674. User=www-data
  675. Group=www-data
  676. Restart=always
  677. ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
  678.  
  679. [Install]
  680. WantedBy=multi-user.target
  681. EOF
  682. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  683. if [ "$webserver" = "1" ]; then
  684. cat > /etc/systemd/system/pteroq.service <<- 'EOF'
  685. Description=Pterodactyl Queue Worker
  686. After=redis-server.service
  687.  
  688. [Service]
  689. User=nginx
  690. Group=nginx
  691. Restart=always
  692. ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
  693.  
  694. [Install]
  695. WantedBy=multi-user.target
  696. EOF
  697. elif [ "$webserver" = "2" ]; then
  698. cat > /etc/systemd/system/pteroq.service <<- 'EOF'
  699. [Unit]
  700. Description=Pterodactyl Queue Worker
  701. After=redis-server.service
  702.  
  703. [Service]
  704. User=apache
  705. Group=apache
  706. Restart=always
  707. ExecStart=/usr/bin/php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
  708.  
  709. [Install]
  710. WantedBy=multi-user.target
  711. EOF
  712. fi
  713. fi
  714. sudo systemctl daemon-reload
  715. systemctl enable pteroq.service
  716. systemctl start pteroq
  717. }
  718.  
  719. upgrade_pterodactyl(){
  720. cd /var/www/pterodactyl
  721. php artisan down
  722. curl -L https://github.com/pterodactyl/panel/releases/download/v0.7.13/panel.tar.gz | tar --strip-components=1 -xzv
  723. unzip panel
  724. chmod -R 755 storage/* bootstrap/cache
  725. composer install --no-dev --optimize-autoloader
  726. php artisan view:clear
  727. php artisan migrate --force
  728. php artisan db:seed --force
  729. chown -R www-data:www-data * /var/www/pterodactyl
  730. if [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  731. chown -R apache:apache * /var/www/pterodactyl
  732. chown -R nginx:nginx * /var/www/pterodactyl
  733. semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/pterodactyl/storage(/.*)?"
  734. restorecon -R /var/www/pterodactyl
  735. fi
  736. output "Your panel has been updated to version 0.7.13."
  737. php artisan up
  738. php artisan queue:restart
  739. }
  740.  
  741. nginx_config() {
  742. output "Disabling default configuration"
  743. rm -rf /etc/nginx/sites-enabled/default
  744. output "Configuring Nginx Webserver"
  745.  
  746. echo '
  747. server_tokens off;
  748.  
  749. set_real_ip_from 103.21.244.0/22;
  750. set_real_ip_from 103.22.200.0/22;
  751. set_real_ip_from 103.31.4.0/22;
  752. set_real_ip_from 104.16.0.0/12;
  753. set_real_ip_from 108.162.192.0/18;
  754. set_real_ip_from 131.0.72.0/22;
  755. set_real_ip_from 141.101.64.0/18;
  756. set_real_ip_from 162.158.0.0/15;
  757. set_real_ip_from 172.64.0.0/13;
  758. set_real_ip_from 173.245.48.0/20;
  759. set_real_ip_from 188.114.96.0/20;
  760. set_real_ip_from 190.93.240.0/20;
  761. set_real_ip_from 197.234.240.0/22;
  762. set_real_ip_from 198.41.128.0/17;
  763. set_real_ip_from 2400:cb00::/32;
  764. set_real_ip_from 2606:4700::/32;
  765. set_real_ip_from 2803:f800::/32;
  766. set_real_ip_from 2405:b500::/32;
  767. set_real_ip_from 2405:8100::/32;
  768. set_real_ip_from 2c0f:f248::/32;
  769. set_real_ip_from 2a06:98c0::/29;
  770.  
  771. real_ip_header X-Forwarded-For;
  772.  
  773. server {
  774. listen 80;
  775. server_name '"$FQDN"';
  776. return 301 https://$server_name$request_uri;
  777. }
  778.  
  779. server {
  780. listen 443 ssl http2;
  781. server_name '"$FQDN"';
  782.  
  783. root /var/www/pterodactyl/public;
  784. index index.php;
  785.  
  786. access_log /var/log/nginx/pterodactyl.app-access.log;
  787. error_log /var/log/nginx/pterodactyl.app-error.log error;
  788.  
  789. # allow larger file uploads and longer script runtimes
  790. client_max_body_size 100m;
  791. client_body_timeout 120s;
  792.  
  793. sendfile off;
  794.  
  795. # SSL Configuration
  796. ssl_certificate /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem;
  797. ssl_certificate_key /etc/letsencrypt/live/'"$FQDN"'/privkey.pem;
  798. ssl_session_cache shared:SSL:10m;
  799. ssl_protocols TLSv1.2;
  800. ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
  801. ssl_prefer_server_ciphers on;
  802.  
  803. # See https://hstspreload.org/ before uncommenting the line below.
  804. # add_header Strict-Transport-Security "max-age=15768000; preload;";
  805. add_header X-Content-Type-Options nosniff;
  806. add_header X-XSS-Protection "1; mode=block";
  807. add_header X-Robots-Tag none;
  808. add_header Content-Security-Policy "frame-ancestors 'self'";
  809. add_header X-Frame-Options DENY;
  810. add_header Referrer-Policy same-origin;
  811.  
  812. location / {
  813. try_files $uri $uri/ /index.php?$query_string;
  814. }
  815.  
  816. location ~ \.php$ {
  817. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  818. fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
  819. fastcgi_index index.php;
  820. include fastcgi_params;
  821. fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
  822. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  823. fastcgi_param HTTP_PROXY "";
  824. fastcgi_intercept_errors off;
  825. fastcgi_buffer_size 16k;
  826. fastcgi_buffers 4 16k;
  827. fastcgi_connect_timeout 300;
  828. fastcgi_send_timeout 300;
  829. fastcgi_read_timeout 300;
  830. include /etc/nginx/fastcgi_params;
  831. }
  832.  
  833. location ~ /\.ht {
  834. deny all;
  835. }
  836. }
  837. ' | sudo -E tee /etc/nginx/sites-available/pterodactyl.conf >/dev/null 2>&1
  838.  
  839. ln -s /etc/nginx/sites-available/pterodactyl.conf /etc/nginx/sites-enabled/pterodactyl.conf
  840. service nginx restart
  841. }
  842.  
  843. nginx_config_nossl() {
  844. output "Disabling default configuration"
  845. rm -rf /etc/nginx/sites-enabled/default
  846. output "Configuring Nginx Webserver"
  847.  
  848. echo '
  849. server_tokens off;
  850.  
  851. set_real_ip_from 103.21.244.0/22;
  852. set_real_ip_from 103.22.200.0/22;
  853. set_real_ip_from 103.31.4.0/22;
  854. set_real_ip_from 104.16.0.0/12;
  855. set_real_ip_from 108.162.192.0/18;
  856. set_real_ip_from 131.0.72.0/22;
  857. set_real_ip_from 141.101.64.0/18;
  858. set_real_ip_from 162.158.0.0/15;
  859. set_real_ip_from 172.64.0.0/13;
  860. set_real_ip_from 173.245.48.0/20;
  861. set_real_ip_from 188.114.96.0/20;
  862. set_real_ip_from 190.93.240.0/20;
  863. set_real_ip_from 197.234.240.0/22;
  864. set_real_ip_from 198.41.128.0/17;
  865. set_real_ip_from 2400:cb00::/32;
  866. set_real_ip_from 2606:4700::/32;
  867. set_real_ip_from 2803:f800::/32;
  868. set_real_ip_from 2405:b500::/32;
  869. set_real_ip_from 2405:8100::/32;
  870. set_real_ip_from 2c0f:f248::/32;
  871. set_real_ip_from 2a06:98c0::/29;
  872.  
  873. real_ip_header X-Forwarded-For;
  874.  
  875. server {
  876. listen 80 default_server;
  877. server_name _;
  878.  
  879. root /var/www/pterodactyl/public;
  880. index index.php;
  881.  
  882. access_log /var/log/nginx/pterodactyl.app-access.log;
  883. error_log /var/log/nginx/pterodactyl.app-error.log error;
  884.  
  885. # allow larger file uploads and longer script runtimes
  886. client_max_body_size 100m;
  887. client_body_timeout 120s;
  888.  
  889. sendfile off;
  890.  
  891. location / {
  892. try_files $uri $uri/ /index.php?$query_string;
  893. }
  894.  
  895. location ~ \.php$ {
  896. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  897. fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
  898. fastcgi_index index.php;
  899. include fastcgi_params;
  900. fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
  901. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  902. fastcgi_param HTTP_PROXY "";
  903. fastcgi_intercept_errors off;
  904. fastcgi_buffer_size 16k;
  905. fastcgi_buffers 4 16k;
  906. fastcgi_connect_timeout 300;
  907. fastcgi_send_timeout 300;
  908. fastcgi_read_timeout 300;
  909. include /etc/nginx/fastcgi_params;
  910. }
  911.  
  912. location ~ /\.ht {
  913. deny all;
  914. }
  915. }
  916. ' | sudo -E tee /etc/nginx/sites-available/pterodactyl.conf >/dev/null 2>&1
  917.  
  918. ln -s /etc/nginx/sites-available/pterodactyl.conf /etc/nginx/sites-enabled/pterodactyl.conf
  919. service nginx restart
  920. }
  921.  
  922. apache_config() {
  923. output "Disabling default configuration"
  924. rm -rf /etc/nginx/sites-enabled/default
  925. output "Configuring Apache2"
  926. echo '
  927. <VirtualHost *:80>
  928. ServerName '"$FQDN"'
  929. RewriteEngine On
  930. RewriteCond %{HTTPS} !=on
  931. RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
  932. </VirtualHost>
  933.  
  934. <VirtualHost *:443>
  935. ServerName '"$FQDN"'
  936. DocumentRoot "/var/www/pterodactyl/public"
  937. AllowEncodedSlashes On
  938. php_value upload_max_filesize 100M
  939. php_value post_max_size 100M
  940. <Directory "/var/www/pterodactyl/public">
  941. AllowOverride all
  942. </Directory>
  943. SSLEngine on
  944. SSLCertificateFile /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem
  945. SSLCertificateKeyFile /etc/letsencrypt/live/'"$FQDN"'/privkey.pem
  946. </VirtualHost>
  947.  
  948.  
  949. ' | sudo -E tee /etc/apache2/sites-available/pterodactyl.conf >/dev/null 2>&1
  950.  
  951. ln -s /etc/apache2/sites-available/pterodactyl.conf /etc/apache2/sites-enabled/pterodactyl.conf
  952. a2enmod ssl
  953. a2enmod rewrite
  954. service apache2 restart
  955. }
  956.  
  957. nginx_config_redhat(){
  958. output "Configuring Nginx Webserver"
  959.  
  960. echo '
  961. server_tokens off;
  962.  
  963. set_real_ip_from 103.21.244.0/22;
  964. set_real_ip_from 103.22.200.0/22;
  965. set_real_ip_from 103.31.4.0/22;
  966. set_real_ip_from 104.16.0.0/12;
  967. set_real_ip_from 108.162.192.0/18;
  968. set_real_ip_from 131.0.72.0/22;
  969. set_real_ip_from 141.101.64.0/18;
  970. set_real_ip_from 162.158.0.0/15;
  971. set_real_ip_from 172.64.0.0/13;
  972. set_real_ip_from 173.245.48.0/20;
  973. set_real_ip_from 188.114.96.0/20;
  974. set_real_ip_from 190.93.240.0/20;
  975. set_real_ip_from 197.234.240.0/22;
  976. set_real_ip_from 198.41.128.0/17;
  977. set_real_ip_from 2400:cb00::/32;
  978. set_real_ip_from 2606:4700::/32;
  979. set_real_ip_from 2803:f800::/32;
  980. set_real_ip_from 2405:b500::/32;
  981. set_real_ip_from 2405:8100::/32;
  982. set_real_ip_from 2c0f:f248::/32;
  983. set_real_ip_from 2a06:98c0::/29;
  984.  
  985. real_ip_header X-Forwarded-For;
  986. server {
  987. listen 80;
  988. server_name '"$FQDN"';
  989. return 301 https://$server_name$request_uri;
  990. }
  991.  
  992. server {
  993. listen 443 ssl http2;
  994. server_name '"$FQDN"';
  995.  
  996. root /var/www/pterodactyl/public;
  997. index index.php;
  998.  
  999. access_log /var/log/nginx/pterodactyl.app-access.log;
  1000. error_log /var/log/nginx/pterodactyl.app-error.log error;
  1001.  
  1002. # allow larger file uploads and longer script runtimes
  1003. client_max_body_size 100m;
  1004. client_body_timeout 120s;
  1005.  
  1006. sendfile off;
  1007.  
  1008. # strengthen ssl security
  1009. ssl_certificate /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem;
  1010. ssl_certificate_key /etc/letsencrypt/live/'"$FQDN"'/privkey.pem;
  1011. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  1012. ssl_prefer_server_ciphers on;
  1013. ssl_session_cache shared:SSL:10m;
  1014. ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
  1015.  
  1016. # See the link below for more SSL information:
  1017. # https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
  1018. #
  1019. # ssl_dhparam /etc/ssl/certs/dhparam.pem;
  1020.  
  1021. # Add headers to serve security related headers
  1022. add_header Strict-Transport-Security "max-age=15768000; preload;";
  1023. add_header X-Content-Type-Options nosniff;
  1024. add_header X-XSS-Protection "1; mode=block";
  1025. add_header X-Robots-Tag none;
  1026. add_header Content-Security-Policy "frame-ancestors 'self'";
  1027.  
  1028. location / {
  1029. try_files $uri $uri/ /index.php?$query_string;
  1030. }
  1031.  
  1032. location ~ \.php$ {
  1033. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  1034. fastcgi_pass unix:/var/run/php-fpm/pterodactyl.sock;
  1035. fastcgi_index index.php;
  1036. include fastcgi_params;
  1037. fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
  1038. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  1039. fastcgi_param HTTP_PROXY "";
  1040. fastcgi_intercept_errors off;
  1041. fastcgi_buffer_size 16k;
  1042. fastcgi_buffers 4 16k;
  1043. fastcgi_connect_timeout 300;
  1044. fastcgi_send_timeout 300;
  1045. fastcgi_read_timeout 300;
  1046. include /etc/nginx/fastcgi_params;
  1047. }
  1048.  
  1049. location ~ /\.ht {
  1050. deny all;
  1051. }
  1052. }
  1053. ' | sudo -E tee /etc/nginx/conf.d/pterodactyl.conf >/dev/null 2>&1
  1054.  
  1055. service nginx restart
  1056. chown -R nginx:nginx $(pwd)
  1057. semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/pterodactyl/storage(/.*)?"
  1058. restorecon -R /var/www/pterodactyl
  1059. }
  1060.  
  1061. nginx_config_redhat_nossl(){
  1062. output "Configuring Nginx Webserver"
  1063.  
  1064. echo '
  1065. server_tokens off;
  1066.  
  1067. set_real_ip_from 103.21.244.0/22;
  1068. set_real_ip_from 103.22.200.0/22;
  1069. set_real_ip_from 103.31.4.0/22;
  1070. set_real_ip_from 104.16.0.0/12;
  1071. set_real_ip_from 108.162.192.0/18;
  1072. set_real_ip_from 131.0.72.0/22;
  1073. set_real_ip_from 141.101.64.0/18;
  1074. set_real_ip_from 162.158.0.0/15;
  1075. set_real_ip_from 172.64.0.0/13;
  1076. set_real_ip_from 173.245.48.0/20;
  1077. set_real_ip_from 188.114.96.0/20;
  1078. set_real_ip_from 190.93.240.0/20;
  1079. set_real_ip_from 197.234.240.0/22;
  1080. set_real_ip_from 198.41.128.0/17;
  1081. set_real_ip_from 2400:cb00::/32;
  1082. set_real_ip_from 2606:4700::/32;
  1083. set_real_ip_from 2803:f800::/32;
  1084. set_real_ip_from 2405:b500::/32;
  1085. set_real_ip_from 2405:8100::/32;
  1086. set_real_ip_from 2c0f:f248::/32;
  1087. set_real_ip_from 2a06:98c0::/29;
  1088.  
  1089. real_ip_header X-Forwarded-For;
  1090.  
  1091. server {
  1092. listen 80 default_server;
  1093. server_name _;
  1094.  
  1095. root /var/www/pterodactyl/public;
  1096. index index.php;
  1097.  
  1098. access_log /var/log/nginx/pterodactyl.app-access.log;
  1099. error_log /var/log/nginx/pterodactyl.app-error.log error;
  1100.  
  1101. # allow larger file uploads and longer script runtimes
  1102. client_max_body_size 100m;
  1103. client_body_timeout 120s;
  1104.  
  1105. sendfile off;
  1106.  
  1107. location / {
  1108. try_files $uri $uri/ /index.php?$query_string;
  1109. }
  1110.  
  1111. location ~ \.php$ {
  1112. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  1113. fastcgi_pass unix:/var/run/php-fpm/pterodactyl.sock;
  1114. fastcgi_index index.php;
  1115. include fastcgi_params;
  1116. fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
  1117. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  1118. fastcgi_param HTTP_PROXY "";
  1119. fastcgi_intercept_errors off;
  1120. fastcgi_buffer_size 16k;
  1121. fastcgi_buffers 4 16k;
  1122. fastcgi_connect_timeout 300;
  1123. fastcgi_send_timeout 300;
  1124. fastcgi_read_timeout 300;
  1125. include /etc/nginx/fastcgi_params;
  1126. }
  1127.  
  1128. location ~ /\.ht {
  1129. deny all;
  1130. }
  1131. }
  1132. ' | sudo -E tee /etc/nginx/conf.d/pterodactyl.conf >/dev/null 2>&1
  1133.  
  1134. service nginx restart
  1135. chown -R nginx:nginx $(pwd)
  1136. semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/pterodactyl/storage(/.*)?"
  1137. restorecon -R /var/www/pterodactyl
  1138. }
  1139.  
  1140. apache_config_redhat() {
  1141. output "Configuring Apache2"
  1142. echo '
  1143. <VirtualHost *:80>
  1144. ServerName '"$FQDN"'
  1145. RewriteEngine On
  1146. RewriteCond %{HTTPS} !=on
  1147. RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
  1148. </VirtualHost>
  1149. <VirtualHost *:443>
  1150. ServerName '"$FQDN"'
  1151. DocumentRoot "/var/www/pterodactyl/public"
  1152. AllowEncodedSlashes On
  1153. <Directory "/var/www/pterodactyl/public">
  1154. AllowOverride all
  1155. </Directory>
  1156. SSLEngine on
  1157. SSLCertificateFile /etc/letsencrypt/live/'"$FQDN"'/fullchain.pem
  1158. SSLCertificateKeyFile /etc/letsencrypt/live/'"$FQDN"'/privkey.pem
  1159. </VirtualHost>
  1160.  
  1161. ' | sudo -E tee /etc/httpd/conf.d/pterodactyl.conf >/dev/null 2>&1
  1162. service httpd restart
  1163. }
  1164.  
  1165. php_config(){
  1166. output "Configuring PHP socket."
  1167. bash -c 'cat > /etc/php-fpm.d/www-pterodactyl.conf' <<-'EOF'
  1168. [pterodactyl]
  1169.  
  1170. user = nginx
  1171. group = nginx
  1172.  
  1173. listen = /var/run/php-fpm/pterodactyl.sock
  1174. listen.owner = nginx
  1175. listen.group = nginx
  1176. listen.mode = 0750
  1177.  
  1178. pm = ondemand
  1179. pm.max_children = 9
  1180. pm.process_idle_timeout = 10s
  1181. pm.max_requests = 200
  1182. EOF
  1183. systemctl restart php-fpm
  1184. }
  1185.  
  1186. webserver_config(){
  1187. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1188. if [ "$webserver" = "1" ]; then
  1189. nginx_config
  1190. elif [ "$webserver" = "2" ]; then
  1191. apache_config
  1192. fi
  1193. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1194. if [ "$webserver" = "1" ]; then
  1195. php_config
  1196. nginx_config_redhat
  1197. elif [ "$webserver" = "2" ]; then
  1198. apache_config_redhat
  1199. fi
  1200. fi
  1201. }
  1202.  
  1203. setup_pterodactyl(){
  1204. install_dependencies
  1205. install_pterodactyl
  1206. ssl_certs
  1207. webserver_config
  1208. theme
  1209. }
  1210.  
  1211. install_daemon() {
  1212. cd /root
  1213. output "Installing Pterodactyl Daemon dependencies."
  1214. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1215. apt-get -y install curl tar unzip
  1216. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1217. yum -y install curl tar unzip
  1218. fi
  1219. output "Enabling Swap support for Docker & Installing NodeJS."
  1220. sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="[^"]*/& swapaccount=1/' /etc/default/grub
  1221. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1222. sudo update-grub
  1223. curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
  1224. apt -y install nodejs make gcc g++ node-gyp
  1225. apt-get -y update
  1226. apt-get -y upgrade
  1227. apt-get -y autoremove
  1228. apt-get -y autoclean
  1229. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1230. grub2-mkconfig -o "$(readlink /etc/grub2.conf)"
  1231. curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
  1232. yum -y install nodejs gcc-c++ make
  1233. yum -y upgrade
  1234. yum -y autoremove
  1235. yum -y clean packages
  1236. fi
  1237. output "Installing the Pterodactyl Daemon."
  1238. mkdir -p /srv/daemon /srv/daemon-data
  1239. cd /srv/daemon
  1240. curl -L https://github.com/pterodactyl/daemon/releases/download/v0.6.12/daemon.tar.gz | tar --strip-components=1 -xzv
  1241. npm install --only=production
  1242. bash -c 'cat > /etc/systemd/system/wings.service' <<-'EOF'
  1243. [Unit]
  1244. Description=Pterodactyl Wings Daemon
  1245. After=docker.service
  1246.  
  1247. [Service]
  1248. User=root
  1249. #Group=some_group
  1250. WorkingDirectory=/srv/daemon
  1251. LimitNOFILE=4096
  1252. PIDFile=/var/run/wings/daemon.pid
  1253. ExecStart=/usr/bin/node /srv/daemon/src/index.js
  1254. Restart=on-failure
  1255. StartLimitInterval=600
  1256.  
  1257. [Install]
  1258. WantedBy=multi-user.target
  1259. EOF
  1260.  
  1261. systemctl daemon-reload
  1262. systemctl enable wings
  1263. if [ "$lsb_dist" = "debian" ] && [ "$dist_version" = "8" ]; then
  1264. kernel_modifications_d8
  1265. fi
  1266.  
  1267. output "Daemon installation is nearly complete, Please go to the panel and get your 'Auto deploy' command in the node configuration tab."
  1268. output "Paste your auto deploy command below: "
  1269. read AUTODEPLOY
  1270. ${AUTODEPLOY}
  1271. service wings start
  1272. }
  1273.  
  1274. upgrade_daemon(){
  1275. cd /srv/daemon
  1276. service wings stop
  1277. curl -L https://github.com/pterodactyl/daemon/releases/download/v0.6.12/daemon.tar.gz | tar --strip-components=1 -xzv
  1278. npm install -g npm
  1279. npm install --only=production
  1280. service wings restart
  1281. output "Your daemon has been updated to version 0.6.12."
  1282. output "npm has been updated to the latest version."
  1283. }
  1284.  
  1285. install_standalone_sftp(){
  1286. cd /srv/daemon
  1287. if [ $(cat /srv/daemon/config/core.json | jq -r '.sftp.enabled') == "null" ]; then
  1288. output "Updating config to enable sftp-server."
  1289. cat /srv/daemon/config/core.json | jq '.sftp.enabled |= false' > /tmp/core
  1290. cat /tmp/core > /srv/daemon/config/core.json
  1291. rm -rf /tmp/core
  1292. elif [ $(cat /srv/daemon/config/core.json | jq -r '.sftp.enabled') == "false" ]; then
  1293. output "Config already set up for golang sftp server."
  1294. else
  1295. output "You may have purposly set the sftp to true and that will fail."
  1296. fi
  1297. service wings restart
  1298. output "Installing standalone SFTP server."
  1299. curl -Lo sftp-server https://github.com/pterodactyl/sftp-server/releases/download/v1.0.4/sftp-server
  1300. chmod +x sftp-server
  1301. bash -c 'cat > /etc/systemd/system/pterosftp.service' <<-'EOF'
  1302. [Unit]
  1303. Description=Pterodactyl Standalone SFTP Server
  1304. After=wings.service
  1305.  
  1306. [Service]
  1307. User=root
  1308. WorkingDirectory=/srv/daemon
  1309. LimitNOFILE=4096
  1310. PIDFile=/var/run/wings/sftp.pid
  1311. ExecStart=/srv/daemon/sftp-server
  1312. Restart=on-failure
  1313. StartLimitInterval=600
  1314.  
  1315. [Install]
  1316. WantedBy=multi-user.target
  1317. EOF
  1318. systemctl enable pterosftp
  1319. service pterosftp restart
  1320. }
  1321.  
  1322. upgrade_standalone_sftp(){
  1323. output "Turning off the standalone SFTP server."
  1324. service pterosftp stop
  1325. curl -Lo sftp-server https://github.com/pterodactyl/sftp-server/releases/download/v1.0.4/sftp-server
  1326. chmod +x sftp-server
  1327. service pterosftp start
  1328. output "Your standalone SFTP server has been updated to v1.0.4"
  1329. }
  1330.  
  1331. install_phpmyadmin(){
  1332. output "Installing phpMyAdmin."
  1333. cd /var/www/pterodactyl/public
  1334. rm -rf phpmyadmin
  1335. wget https://files.phpmyadmin.net/phpMyAdmin/4.8.5/phpMyAdmin-4.8.5-all-languages.zip
  1336. unzip phpMyAdmin-4.8.5-all-languages
  1337. mv phpMyAdmin-4.8.5-all-languages phpmyadmin
  1338. rm -rf phpMyAdmin-4.8.5-all-languages.zip
  1339. cd /var/www/pterodactyl/public/phpmyadmin
  1340.  
  1341. SERVER_IP=$(curl -s http://checkip.amazonaws.com)
  1342. BOWFISH=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 34 | head -n 1`
  1343. bash -c 'cat > /var/www/pterodactyl/public/phpmyadmin/config.inc.php' <<EOF
  1344. <?php
  1345. /* Servers configuration */
  1346. \$i = 0;
  1347.  
  1348. /* Server: MariaDB [1] */
  1349. \$i++;
  1350. \$cfg['Servers'][\$i]['verbose'] = 'MariaDB';
  1351. \$cfg['Servers'][\$i]['host'] = '${SERVER_IP}';
  1352. \$cfg['Servers'][\$i]['port'] = '';
  1353. \$cfg['Servers'][\$i]['socket'] = '';
  1354. \$cfg['Servers'][\$i]['auth_type'] = 'cookie';
  1355. \$cfg['Servers'][\$i]['user'] = 'root';
  1356. \$cfg['Servers'][\$i]['password'] = '';
  1357.  
  1358. /* End of servers configuration */
  1359.  
  1360. \$cfg['blowfish_secret'] = '${BOWFISH}';
  1361. \$cfg['DefaultLang'] = 'en';
  1362. \$cfg['ServerDefault'] = 1;
  1363. \$cfg['UploadDir'] = '';
  1364. \$cfg['SaveDir'] = '';
  1365. \$cfg['CaptchaLoginPublicKey'] = '6LcJcjwUAAAAAO_Xqjrtj9wWufUpYRnK6BW8lnfn';
  1366. \$cfg['CaptchaLoginPrivateKey'] = '6LcJcjwUAAAAALOcDJqAEYKTDhwELCkzUkNDQ0J5'
  1367. ?>
  1368. EOF
  1369. output "Installation completed."
  1370. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1371. chown -R www-data:www-data * /var/www/pterodactyl
  1372. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1373. chown -R apache:apache * /var/www/pterodactyl
  1374. chown -R nginx:nginx * /var/www/pterodactyl
  1375. semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/pterodactyl/storage(/.*)?"
  1376. restorecon -R /var/www/pterodactyl
  1377. fi
  1378. }
  1379.  
  1380. kernel_modifications_d8(){
  1381. output "Modifying Grub."
  1382. sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="[^"]*/& cgroup_enable=memory/' /etc/default/grub
  1383. output "Adding backport repositories."
  1384. echo deb http://http.debian.net/debian jessie-backports main > /etc/apt/sources.list.d/jessie-backports.list
  1385. echo deb http://http.debian.net/debian jessie-backports main contrib non-free > /etc/apt/sources.list.d/jessie-backports.list
  1386. output "Updating Server Packages."
  1387. apt-get -y update
  1388. apt-get -y upgrade
  1389. apt-get -y autoremove
  1390. apt-get -y autoclean
  1391. output"Installing new kernel"
  1392. apt install -t jessie-backports linux-image-4.9.0-0.bpo.7-amd64
  1393. output "Modifying Docker."
  1394. sed -i 's,/usr/bin/dockerd,/usr/bin/dockerd --storage-driver=overlay2,g' /lib/systemd/system/docker.service
  1395. systemctl daemon-reload
  1396. service docker start
  1397. }
  1398.  
  1399. ssl_certs(){
  1400. output "Installing LetsEncrypt and creating an SSL certificate."
  1401. cd /root
  1402. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1403. if [ "$lsb_dist" = "debian" ] && [ "$dist_version" = "8" ]; then
  1404. wget https://dl.eff.org/certbot-auto
  1405. chmod a+x certbot-auto
  1406. else
  1407. apt-get -y install certbot
  1408. fi
  1409. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1410. yum -y install certbot
  1411. fi
  1412. if [ "$webserver" = "1" ]; then
  1413. service nginx stop
  1414. elif [ "$webserver" = "2" ]; then
  1415. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1416. service apache2 stop
  1417. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1418. service httpd stop
  1419. fi
  1420. fi
  1421.  
  1422. if [ "$lsb_dist" = "debian" ] && [ "$dist_version" = "8" ]; then
  1423. ./certbot-auto certonly --standalone --email "$email" --agree-tos -d "$FQDN" --non-interactive
  1424. else
  1425. certbot certonly --standalone --email "$email" --agree-tos -d "$FQDN" --non-interactive
  1426. fi
  1427. if [ "$installoption" = "2" ]; then
  1428. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1429. ufw deny 80
  1430. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1431. firewall-cmd --permanent --remove-port=80/tcp
  1432. firewall-cmd --reload
  1433. fi
  1434. else
  1435. if [ "$webserver" = "1" ]; then
  1436. service nginx restart
  1437. elif [ "$webserver" = "2" ]; then
  1438. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1439. service apache2 restart
  1440. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1441. service httpd restart
  1442. fi
  1443. fi
  1444. fi
  1445.  
  1446. if [ "$lsb_dist" = "debian" ] && [ "$dist_version" = "8" ]; then
  1447. apt -y install cronie
  1448. if [ "$installoption" = "1" ]; then
  1449. if [ "$webserver" = "1" ]; then
  1450. (crontab -l ; echo "0 0,12 * * * ./certbot-auto renew --pre-hook "service nginx stop" --post-hook "service nginx restart" >> /dev/null 2>&1")| crontab -
  1451. elif [ "$webserver" = "2" ]; then
  1452. (crontab -l ; echo "0 0,12 * * * ./certbot-auto renew --pre-hook "service apache2 stop" --post-hook "service apache2 restart" >> /dev/null 2>&1")| crontab -
  1453. fi
  1454. elif [ "$installoption" = "2" ]; then
  1455. (crontab -l ; echo "0 0,12 * * * ./certbot-auto renew --pre-hook "ufw allow 80" --pre-hook "service wings stop" --post-hook "ufw deny 80" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1456. elif [ "$installoption" = "3" ]; then
  1457. if [ "$webserver" = "1" ]; then
  1458. (crontab -l ; echo "0 0,12 * * * ./certbot-auto renew --pre-hook "service nginx stop" --pre-hook "service wings stop" --post-hook "service nginx restart" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1459. elif [ "$webserver" = "2" ]; then
  1460. (crontab -l ; echo "0 0,12 * * * ./certbot-auto renew --pre-hook "service apache2 stop" --pre-hook "service wings stop" --post-hook "service apache2 restart" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1461. fi
  1462. fi
  1463. elif [ "$lsb_dist" = "debian" ] || [ "$lsb_dist" = "ubuntu" ]; then
  1464. apt -y install cronie
  1465. if [ "$installoption" = "1" ]; then
  1466. if [ "$webserver" = "1" ]; then
  1467. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service nginx stop" --post-hook "service nginx restart" >> /dev/null 2>&1")| crontab -
  1468. elif [ "$webserver" = "2" ]; then
  1469. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service apache2 stop" --post-hook "service apache2 restart" >> /dev/null 2>&1")| crontab -
  1470. fi
  1471. elif [ "$installoption" = "2" ]; then
  1472. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "ufw allow 80" --pre-hook "service wings stop" --post-hook "ufw deny 80" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1473. elif [ "$installoption" = "3" ]; then
  1474. if [ "$webserver" = "1" ]; then
  1475. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service nginx stop" --pre-hook "service wings stop" --post-hook "service nginx restart" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1476. elif [ "$webserver" = "2" ]; then
  1477. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service apache2 stop" --pre-hook "service wings stop" --post-hook "service apache2 restart" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1478. fi
  1479. fi
  1480. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1481. yum -y install cronie
  1482. if [ "$installoption" = "1" ]; then
  1483. if [ "$webserver" = "1" ]; then
  1484. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service nginx stop" --post-hook "service nginx restart" >> /dev/null 2>&1")| crontab -
  1485. elif [ "$webserver" = "2" ]; then
  1486. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service httpd stop" --post-hook "service httpd restart" >> /dev/null 2>&1")| crontab -
  1487. fi
  1488. elif [ "$installoption" = "2" ]; then
  1489. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "firewall-cmd --add-port=80/tcp && firewall-cmd --reload" --pre-hook "service wings stop" --post-hook "firewall-cmd --remove-port=80/tcp && firewall-cmd --reload" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1490. elif [ "$installoption" = "3" ]; then
  1491. if [ "$webserver" = "1" ]; then
  1492. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service nginx stop" --pre-hook "service wings stop" --post-hook "service nginx restart" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1493. elif [ "$webserver" = "2" ]; then
  1494. (crontab -l ; echo "0 0,12 * * * certbot renew --pre-hook "service httpd stop" --pre-hook "service wings stop" --post-hook "service httpd restart" --post-hook "service wings restart" >> /dev/null 2>&1")| crontab -
  1495. fi
  1496. fi
  1497. fi
  1498. service cron restart
  1499. }
  1500.  
  1501. firewall(){
  1502. rm -rf /etc/rc.local
  1503. printf '%s\n' '#!/bin/bash' 'exit 0' | sudo tee -a /etc/rc.local
  1504. chmod +x /etc/rc.local
  1505.  
  1506. iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP
  1507. iptables -t mangle -A PREROUTING -p tcp ! --syn -m conntrack --ctstate NEW -j DROP
  1508. iptables -t mangle -A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP
  1509. iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP
  1510. iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP
  1511. iptables -t mangle -A PREROUTING -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
  1512. iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,RST FIN,RST -j DROP
  1513. iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,ACK FIN -j DROP
  1514. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,URG URG -j DROP
  1515. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,FIN FIN -j DROP
  1516. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,PSH PSH -j DROP
  1517. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL ALL -j DROP
  1518. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP
  1519. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
  1520. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,FIN,PSH,URG -j DROP
  1521. iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  1522. iptables -A INPUT -p tcp -m connlimit --connlimit-above 1000 --connlimit-mask 32 --connlimit-saddr -j REJECT --reject-with tcp-reset
  1523. iptables -t mangle -A PREROUTING -f -j DROP
  1524. /sbin/iptables -N port-scanning
  1525. /sbin/iptables -A port-scanning -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s --limit-burst 2 -j RETURN
  1526. /sbin/iptables -A port-scanning -j DROP
  1527. sh -c "iptables-save > /etc/iptables.conf"
  1528. sed -i -e '$i \iptables-restore < /etc/iptables.conf\n' /etc/rc.local
  1529.  
  1530. output "Setting up Fail2Ban"
  1531. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1532. apt -y install fail2ban
  1533. elif [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "rhel" ]; then
  1534. yum -y install fail2ban
  1535. fi
  1536. systemctl enable fail2ban
  1537. bash -c 'cat > /etc/fail2ban/jail.local' <<-'EOF'
  1538. [DEFAULT]
  1539. # Ban hosts for ten hours:
  1540. bantime = 36000
  1541.  
  1542. # Override /etc/fail2ban/jail.d/00-firewalld.conf:
  1543. banaction = iptables-multiport
  1544.  
  1545. [sshd]
  1546. enabled = true
  1547. EOF
  1548. service fail2ban restart
  1549.  
  1550. output "Configuring your firewall."
  1551. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1552. apt-get -y install ufw
  1553. ufw allow 22
  1554. if [ "$installoption" = "1" ]; then
  1555. ufw allow 80
  1556. ufw allow 443
  1557. ufw allow 3306
  1558. elif [ "$installoption" = "2" ]; then
  1559. ufw allow 80
  1560. ufw allow 8080
  1561. ufw allow 2022
  1562. elif [ "$installoption" = "3" ]; then
  1563. ufw allow 80
  1564. ufw allow 443
  1565. ufw allow 8080
  1566. ufw allow 2022
  1567. ufw allow 3306
  1568. fi
  1569. yes |ufw enable
  1570. elif [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "rhel" ]; then
  1571. yum -y install firewalld
  1572. systemctl enable firewalld
  1573. systemctl start firewalld
  1574. if [ "$installoption" = "1" ]; then
  1575. firewall-cmd --add-service=http --permanent
  1576. firewall-cmd --add-service=https --permanent
  1577. firewall-cmd --add-service=mysql --permanent
  1578. elif [ "$installoption" = "2" ]; then
  1579. firewall-cmd --permanent --add-port=80/tcp
  1580. firewall-cmd --permanent --add-port=2022/tcp
  1581. firewall-cmd --permanent --add-port=8080/tcp
  1582. elif [ "$installoption" = "3" ]; then
  1583. firewall-cmd --add-service=http --permanent
  1584. firewall-cmd --add-service=https --permanent
  1585. firewall-cmd --permanent --add-port=2022/tcp
  1586. firewall-cmd --permanent --add-port=8080/tcp
  1587. firewall-cmd --add-service=mysql --permanent
  1588. fi
  1589. firewall-cmd --reload
  1590. fi
  1591. }
  1592.  
  1593. mariadb_root_reset(){
  1594. service mariadb stop
  1595. mysqld_safe --skip-grant-tables >res 2>&1 &
  1596. sleep 5
  1597. rootpassword=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  1598. Q1="UPDATE user SET plugin='';"
  1599. Q2="UPDATE user SET password=PASSWORD('$rootpassword') WHERE user='root';"
  1600. Q3="FLUSH PRIVILEGES;"
  1601. SQL="${Q1}${Q2}${Q3}"
  1602. mysql mysql -e "$SQL"
  1603. pkill mysqld
  1604. service mariadb restart
  1605. output "Your MariaDB root password is $rootpassword"
  1606. }
  1607.  
  1608. database_host_reset(){
  1609. SERVER_IP=$(curl -s http://checkip.amazonaws.com)
  1610. service mariadb stop
  1611. mysqld_safe --skip-grant-tables >res 2>&1 &
  1612. sleep 5
  1613. adminpassword=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  1614. Q1="UPDATE user SET plugin='';"
  1615. Q2="UPDATE user SET password=PASSWORD('$adminpassword') WHERE user='admin';"
  1616. Q3="FLUSH PRIVILEGES;"
  1617. SQL="${Q1}${Q2}${Q3}"
  1618. mysql mysql -e "$SQL"
  1619. pkill mysqld
  1620. service mariadb restart
  1621. output "New database host information:"
  1622. output "Host: $SERVER_IP"
  1623. output "Port: 3306"
  1624. output "User: admin"
  1625. output "Password: $adminpassword"
  1626. }
  1627.  
  1628. broadcast(){
  1629. if [ "$installoption" = "1" ] || [ "$installoption" = "3" ]; then
  1630. output "###############################################################"
  1631. output "MARIADB INFORMATION"
  1632. output ""
  1633. output "Your MariaDB root password is $rootpassword"
  1634. output ""
  1635. output "Create your MariaDB host with the following information:"
  1636. output "Host: $SERVER_IP"
  1637. output "Port: 3306"
  1638. output "User: admin"
  1639. output "Password: $adminpassword"
  1640. output "###############################################################"
  1641. output ""
  1642. fi
  1643. output "###############################################################"
  1644. output "FIREWALL INFORMATION"
  1645. output ""
  1646. output "All unnecessary ports are blocked by default."
  1647. if [ "$lsb_dist" = "ubuntu" ] || [ "$lsb_dist" = "debian" ]; then
  1648. output "Use 'ufw allow <port>' to enable your desired ports"
  1649. elif [ "$lsb_dist" = "fedora" ] || [ "$lsb_dist" = "centos" ] || [ "$lsb_dist" = "rhel" ]; then
  1650. output "Use 'firewall-cmd --permanent --add-port=<port>/tcp' to enable your desired ports."
  1651. semanage permissive -a httpd_t
  1652. semanage permissive -a redis_t
  1653. fi
  1654. output "###############################################################"
  1655. output ""
  1656.  
  1657. if [ "$installoption" = "2" ] || [ "$installoption" = "3" ]; then
  1658. if [ "$lsb_dist" = "debian" ] && [ "$dist_version" = "8" ]; then
  1659. output "Please restart the server daemon to apply the necessary kernel changes on Debian 8."
  1660. fi
  1661. fi
  1662.  
  1663. }
  1664.  
  1665. #Execution
  1666. preflight
  1667. case $installoption in
  1668. 1) webserver_options
  1669. theme_options
  1670. repositories_setup
  1671. required_infos
  1672. firewall
  1673. setup_pterodactyl
  1674. broadcast
  1675. ;;
  1676. 2) repositories_setup
  1677. required_infos
  1678. firewall
  1679. ssl_certs
  1680. install_daemon
  1681. broadcast
  1682. ;;
  1683. 3) webserver_options
  1684. theme_options
  1685. repositories_setup
  1686. required_infos
  1687. firewall
  1688. setup_pterodactyl
  1689. install_daemon
  1690. broadcast
  1691. ;;
  1692. 4) install_standalone_sftp
  1693. ;;
  1694. 5) theme_options
  1695. upgrade_pterodactyl
  1696. theme
  1697. ;;
  1698. 6) upgrade_daemon
  1699. ;;
  1700. 7) theme_options
  1701. upgrade_pterodactyl
  1702. theme
  1703. upgrade_daemon
  1704. ;;
  1705. 8) upgrade_standalone_sftp
  1706. ;;
  1707. 9) install_phpmyadmin
  1708. ;;
  1709. 10) theme_options
  1710. if [ "$themeoption" = "1" ]; then
  1711. upgrade_pterodactyl
  1712. fi
  1713. theme
  1714. ;;
  1715. 11) mariadb_root_reset
  1716. ;;
  1717. 12) database_host_reset
  1718. ;;
  1719. esac
  1720. rm -rf install.sh.x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement