hst-install-centos.sh 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. #!/bin/bash
  2. # Hestia RHEL/CentOS installer v1.0
  3. #----------------------------------------------------------#
  4. # Variables&Functions #
  5. #----------------------------------------------------------#
  6. export PATH=$PATH:/sbin
  7. #export DEBIAN_FRONTEND=noninteractive
  8. RHOST='rhel.hestiacp.com'
  9. GPG='gpg.hestiacp.com'
  10. VERSION='rhel'
  11. HESTIA='/usr/local/hestia'
  12. LOG="/root/hst_install_backups/hst_install-$(date +%d%m%Y%H%M).log"
  13. memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])
  14. hst_backups="/root/hst_install_backups/$(date +%d%m%Y%H%M)"
  15. arch=$(uname -i)
  16. spinner="/-\|"
  17. os='rhel'
  18. release=$(grep -o "[0-9]" /etc/redhat-release |head -n1)
  19. codename="${os}_$release"
  20. HESTIA_INSTALL_DIR="$HESTIA/install/rhel"
  21. VERBOSE='no'
  22. # Define software versions
  23. HESTIA_INSTALL_VER='1.2.0'
  24. pma_v='5.0.2'
  25. multiphp_v=("5.6" "7.0" "7.1" "7.2" "7.3" "7.4")
  26. fpm_v="73"
  27. mariadb_v="10.3"
  28. # Defining software pack for all distros
  29. software=" nginx awstats bc bind bind-libs bind-utils clamav clamav-update
  30. curl dovecot e2fsprogs exim expect fail2ban flex freetype ftp GeoIP httpd
  31. ImageMagick iptables-services lsof mailx mariadb mariadb-server mc
  32. mod_fcgid mod_ssl net-tools openssh-clients pcre php
  33. php-bcmath php-cli php-common php-fpm php-gd php-imap php-mbstring
  34. php-mcrypt phpMyAdmin php-mysql php-pdo phpPgAdmin php-pgsql php-soap
  35. php-tidy php-xml php-xmlrpc postgresql postgresql-contrib
  36. postgresql-server proftpd roundcubemail rrdtool rsyslog screen
  37. spamassassin sqlite sudo tar telnet unzip hestia hestia-nginx
  38. hestia-php vim-common vsftpd webalizer which zip wget tar langpacks-en glibc-all-langpacks
  39. ipset oniguruma5php libzip zstd"
  40. # Defining help function
  41. help() {
  42. echo "Usage: $0 [OPTIONS]
  43. -a, --apache Install Apache [yes|no] default: yes
  44. -n, --nginx Install Nginx [yes|no] default: yes
  45. -w, --phpfpm Install PHP-FPM [yes|no] default: no
  46. -o, --multiphp Install Multi-PHP [yes|no] default: no
  47. -v, --vsftpd Install Vsftpd [yes|no] default: yes
  48. -j, --proftpd Install ProFTPD [yes|no] default: no
  49. -k, --named Install Bind [yes|no] default: yes
  50. -m, --mysql Install MariaDB [yes|no] default: yes
  51. -g, --postgresql Install PostgreSQL [yes|no] default: no
  52. -x, --exim Install Exim [yes|no] default: yes
  53. -z, --dovecot Install Dovecot [yes|no] default: yes
  54. -c, --clamav Install ClamAV [yes|no] default: yes
  55. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  56. -i, --iptables Install Iptables [yes|no] default: yes
  57. -b, --fail2ban Install Fail2ban [yes|no] default: yes
  58. -q, --quota Filesystem Quota [yes|no] default: no
  59. -d, --api Activate API [yes|no] default: yes
  60. -r, --port Change Backend Port default: 8083
  61. -l, --lang Default language default: en
  62. -y, --interactive Interactive install [yes|no] default: yes
  63. -s, --hostname Set hostname
  64. -e, --email Set admin email
  65. -p, --password Set admin password
  66. -D, --with-rpms Path to Hestia rpms
  67. -f, --force Force installation
  68. -h, --help Print this help
  69. Example: bash $0 -e demo@hestiacp.com -p p4ssw0rd --apache no --phpfpm yes"
  70. exit 1
  71. }
  72. # Defining file download function
  73. download_file() {
  74. wget $1 -q --show-progress --progress=bar:force
  75. }
  76. # Defining password-gen function
  77. gen_pass() {
  78. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  79. LENGTH=16
  80. while [ ${n:=1} -le $LENGTH ]; do
  81. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  82. let n+=1
  83. done
  84. echo "$PASS"
  85. }
  86. # Defining return code check function
  87. check_result() {
  88. if [ $1 -ne 0 ]; then
  89. echo "Error: $2"
  90. exit $1
  91. fi
  92. }
  93. # Defining function to set default value
  94. set_default_value() {
  95. eval variable=\$$1
  96. if [ -z "$variable" ]; then
  97. eval $1=$2
  98. fi
  99. if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  100. eval $1=$2
  101. fi
  102. }
  103. # Defining function to set default language value
  104. set_default_lang() {
  105. if [ -z "$lang" ]; then
  106. eval lang=$1
  107. fi
  108. lang_list="
  109. ar cz el fa hu ja no pt se ua
  110. bs da en fi id ka pl ro tr vi
  111. cn de es fr it nl pt-BR ru tw
  112. bg ko sr th ur"
  113. if !(echo $lang_list |grep -w $lang > /dev/null 2>&1); then
  114. eval lang=$1
  115. fi
  116. }
  117. # Define the default backend port
  118. set_default_port() {
  119. if [ -z "$port" ]; then
  120. eval port=$1
  121. fi
  122. }
  123. #----------------------------------------------------------#
  124. # Verifications #
  125. #----------------------------------------------------------#
  126. # Creating temporary file
  127. tmpfile=$(mktemp -p /tmp)
  128. # Translating argument to --gnu-long-options
  129. for arg; do
  130. delim=""
  131. case "$arg" in
  132. --apache) args="${args}-a " ;;
  133. --nginx) args="${args}-n " ;;
  134. --phpfpm) args="${args}-w " ;;
  135. --vsftpd) args="${args}-v " ;;
  136. --proftpd) args="${args}-j " ;;
  137. --named) args="${args}-k " ;;
  138. --mysql) args="${args}-m " ;;
  139. --postgresql) args="${args}-g " ;;
  140. --exim) args="${args}-x " ;;
  141. --dovecot) args="${args}-z " ;;
  142. --clamav) args="${args}-c " ;;
  143. --spamassassin) args="${args}-t " ;;
  144. --iptables) args="${args}-i " ;;
  145. --fail2ban) args="${args}-b " ;;
  146. --multiphp) args="${args}-o " ;;
  147. --quota) args="${args}-q " ;;
  148. --port) args="${args}-r " ;;
  149. --lang) args="${args}-l " ;;
  150. --interactive) args="${args}-y " ;;
  151. --api) args="${args}-d " ;;
  152. --hostname) args="${args}-s " ;;
  153. --email) args="${args}-e " ;;
  154. --password) args="${args}-p " ;;
  155. --force) args="${args}-f " ;;
  156. --with-rpms) args="${args}-D " ;;
  157. --help) args="${args}-h " ;;
  158. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  159. args="${args}${delim}${arg}${delim} ";;
  160. esac
  161. done
  162. eval set -- "$args"
  163. # Parsing arguments
  164. while getopts "a:n:w:v:j:k:m:g:d:x:z:c:t:i:b:r:o:q:l:y:s:e:p:D:fh" Option; do
  165. case $Option in
  166. a) apache=$OPTARG ;; # Apache
  167. n) nginx=$OPTARG ;; # Nginx
  168. w) phpfpm=$OPTARG ;; # PHP-FPM
  169. o) multiphp=$OPTARG ;; # Multi-PHP
  170. v) vsftpd=$OPTARG ;; # Vsftpd
  171. j) proftpd=$OPTARG ;; # Proftpd
  172. k) named=$OPTARG ;; # Named
  173. m) mysql=$OPTARG ;; # MySQL
  174. g) postgresql=$OPTARG ;; # PostgreSQL
  175. x) exim=$OPTARG ;; # Exim
  176. z) dovecot=$OPTARG ;; # Dovecot
  177. c) clamd=$OPTARG ;; # ClamAV
  178. t) spamd=$OPTARG ;; # SpamAssassin
  179. i) iptables=$OPTARG ;; # Iptables
  180. b) fail2ban=$OPTARG ;; # Fail2ban
  181. q) quota=$OPTARG ;; # FS Quota
  182. r) port=$OPTARG ;; # Backend Port
  183. l) lang=$OPTARG ;; # Language
  184. d) api=$OPTARG ;; # Activate API
  185. y) interactive=$OPTARG ;; # Interactive install
  186. s) servername=$OPTARG ;; # Hostname
  187. e) email=$OPTARG ;; # Admin email
  188. p) vpass=$OPTARG ;; # Admin password
  189. D) withrpms=$OPTARG ;; # Hestia rpms path
  190. f) force='yes' ;; # Force install
  191. h) help ;; # Help
  192. *) help ;; # Print help (default)
  193. esac
  194. done
  195. # Defining default software stack
  196. set_default_value 'nginx' 'yes'
  197. set_default_value 'apache' 'yes'
  198. set_default_value 'phpfpm' 'yes'
  199. set_default_value 'multiphp' 'no'
  200. set_default_value 'vsftpd' 'yes'
  201. set_default_value 'proftpd' 'no'
  202. set_default_value 'named' 'yes'
  203. set_default_value 'mysql' 'yes'
  204. set_default_value 'postgresql' 'no'
  205. set_default_value 'exim' 'yes'
  206. set_default_value 'dovecot' 'yes'
  207. if [ $memory -lt 1500000 ]; then
  208. set_default_value 'clamd' 'no'
  209. set_default_value 'spamd' 'no'
  210. else
  211. set_default_value 'clamd' 'yes'
  212. set_default_value 'spamd' 'yes'
  213. fi
  214. set_default_value 'iptables' 'yes'
  215. set_default_value 'fail2ban' 'yes'
  216. set_default_value 'quota' 'no'
  217. set_default_value 'interactive' 'yes'
  218. set_default_value 'api' 'yes'
  219. set_default_port '8083'
  220. set_default_lang 'en'
  221. # Checking software conflicts
  222. if [ "$multiphp" = 'yes' ]; then
  223. phpfpm='yes'
  224. fi
  225. if [ "$proftpd" = 'yes' ]; then
  226. vsftpd='no'
  227. fi
  228. if [ "$exim" = 'no' ]; then
  229. clamd='no'
  230. spamd='no'
  231. dovecot='no'
  232. fi
  233. if [ "$iptables" = 'no' ]; then
  234. fail2ban='no'
  235. fi
  236. # Checking root permissions
  237. if [ "x$(id -u)" != 'x0' ]; then
  238. check_result 1 "Script can be run executed only by root"
  239. fi
  240. # Checking admin user account
  241. if [ ! -z "$(grep ^admin: /etc/passwd /etc/group)" ] && [ -z "$force" ]; then
  242. echo 'Please remove admin user account before proceeding.'
  243. echo 'If you want to do it automatically run installer with -f option:'
  244. echo -e "Example: bash $0 --force\n"
  245. check_result 1 "User admin exists"
  246. fi
  247. # Check if a default webserver was set
  248. if [ $apache = 'no' ] && [ $nginx = 'no' ]; then
  249. check_result 1 "No web server was selected"
  250. fi
  251. # Clear the screen once launch permissions have been verified
  252. clear
  253. # Welcome message
  254. echo "Welcome to the Hestia Control Panel installer!"
  255. echo
  256. echo "Please wait a moment while we update your system's repositories and"
  257. echo "install any necessary dependencies required to proceed with the installation..."
  258. echo
  259. # Creating backup directory
  260. mkdir -p $hst_backups
  261. # Checking ntpdate
  262. if [ "$release" -eq '7' ]; then
  263. if [ ! -e '/usr/sbin/ntpdate' ]; then
  264. echo "(*) Installing ntpdate..."
  265. yum -y install ntpdate >> $LOG
  266. check_result $? "Can't install ntpdate"
  267. fi
  268. else
  269. # 8 and up
  270. if [ ! -e '/usr/sbin/chronyd' ]; then
  271. echo "(*) Installing chrony..."
  272. yum -y install chrony >> $LOG
  273. check_result $? "Can't install chrony"
  274. fi
  275. fi
  276. # Checking wget
  277. if [ ! -e '/usr/bin/wget' ]; then
  278. echo "(*) Installing wget..."
  279. yum -y install wget >> $LOG
  280. check_result $? "Can't install wget"
  281. fi
  282. # Checking installed packages
  283. tmpfile=$(mktemp -p /tmp)
  284. rpm -qa > $tmpfile
  285. for pkg in exim mariadb-server MariaDB-server mysql-server httpd nginx hestia postfix; do
  286. if [ ! -z "$(grep $pkg $tmpfile)" ]; then
  287. conflicts="$pkg* $conflicts"
  288. fi
  289. done
  290. rm -f $tmpfile
  291. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  292. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  293. echo
  294. echo 'WARNING: The following packages are already installed'
  295. echo "$conflicts"
  296. echo
  297. echo 'It is highly recommended that you remove them before proceeding.'
  298. echo
  299. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  300. echo
  301. read -p 'Would you like to remove the conflicting packages? [y/n] ' answer
  302. if [ "$answer" = 'y' ] || [ "$answer" = 'Y' ]; then
  303. yum remove $conflicts -y
  304. check_result $? 'yum remove failed'
  305. unset $answer
  306. else
  307. check_result 1 "Hestia Control Panel should be installed on a clean server."
  308. fi
  309. fi
  310. #----------------------------------------------------------#
  311. # Brief Info #
  312. #----------------------------------------------------------#
  313. # Printing nice ASCII logo
  314. clear
  315. echo
  316. echo ' _ _ _ _ ____ ____ '
  317. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  318. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) |'
  319. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  320. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  321. echo
  322. echo ' Hestia Control Panel'
  323. echo " v${HESTIA_INSTALL_VER}"
  324. echo -e "\n"
  325. echo "===================================================================="
  326. echo -e "\n"
  327. echo 'The following server components will be installed on your system:'
  328. echo
  329. # Web stack
  330. if [ "$nginx" = 'yes' ]; then
  331. echo ' - NGINX Web / Proxy Server'
  332. fi
  333. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  334. echo ' - Apache Web Server'
  335. fi
  336. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  337. echo ' - Apache Web Server (as backend)'
  338. fi
  339. if [ "$phpfpm" = 'yes' ] && [ "$multiphp" = 'no' ]; then
  340. echo ' - PHP-FPM Application Server'
  341. fi
  342. if [ "$multiphp" = 'yes' ]; then
  343. echo ' - Multi-PHP Environment'
  344. fi
  345. # DNS stack
  346. if [ "$named" = 'yes' ]; then
  347. echo ' - Bind DNS Server'
  348. fi
  349. # Mail stack
  350. if [ "$exim" = 'yes' ]; then
  351. echo -n ' - Exim Mail Server'
  352. if [ "$clamd" = 'yes' ] || [ "$spamd" = 'yes' ] ; then
  353. echo -n ' + '
  354. if [ "$clamd" = 'yes' ]; then
  355. echo -n 'ClamAV '
  356. fi
  357. if [ "$spamd" = 'yes' ]; then
  358. if [ "$clamd" = 'yes' ]; then
  359. echo -n '+ '
  360. fi
  361. echo -n 'SpamAssassin'
  362. fi
  363. fi
  364. echo
  365. if [ "$dovecot" = 'yes' ]; then
  366. echo ' - Dovecot POP3/IMAP Server'
  367. fi
  368. fi
  369. # Database stack
  370. if [ "$mysql" = 'yes' ]; then
  371. echo ' - MariaDB Database Server'
  372. fi
  373. if [ "$postgresql" = 'yes' ]; then
  374. echo ' - PostgreSQL Database Server'
  375. fi
  376. # FTP stack
  377. if [ "$vsftpd" = 'yes' ]; then
  378. echo ' - Vsftpd FTP Server'
  379. fi
  380. if [ "$proftpd" = 'yes' ]; then
  381. echo ' - ProFTPD FTP Server'
  382. fi
  383. # Firewall stack
  384. if [ "$iptables" = 'yes' ]; then
  385. echo -n ' - Firewall (Iptables)'
  386. fi
  387. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  388. echo -n ' + Fail2Ban Access Monitor'
  389. fi
  390. echo -e "\n"
  391. echo "===================================================================="
  392. echo -e "\n"
  393. # Asking for confirmation to proceed
  394. if [ "$interactive" = 'yes' ]; then
  395. read -p 'Would you like to continue with the installation? [Y/N]: ' answer
  396. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  397. echo 'Goodbye'
  398. exit 1
  399. fi
  400. # Asking for contact email
  401. if [ -z "$email" ]; then
  402. read -p 'Please enter admin email address: ' email
  403. fi
  404. # Asking to set FQDN hostname
  405. if [ -z "$servername" ]; then
  406. read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
  407. fi
  408. fi
  409. # Generating admin password if it wasn't set
  410. if [ -z "$vpass" ]; then
  411. vpass=$(gen_pass)
  412. fi
  413. # Set hostname if it wasn't set
  414. if [ -z "$servername" ]; then
  415. servername=$(hostname -f)
  416. fi
  417. # Set FQDN if it wasn't set
  418. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  419. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  420. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  421. if [ ! -z "$servername" ]; then
  422. servername="$servername.example.com"
  423. else
  424. servername="example.com"
  425. fi
  426. echo "127.0.0.1 $servername" >> /etc/hosts
  427. fi
  428. # Set email if it wasn't set
  429. if [ -z "$email" ]; then
  430. email="admin@$servername"
  431. fi
  432. # Defining backup directory
  433. echo -e "Installation backup directory: $hst_backups"
  434. # Print Log File Path
  435. echo "Installation log file: $LOG"
  436. # Print new line
  437. echo
  438. #----------------------------------------------------------#
  439. # Checking swap #
  440. #----------------------------------------------------------#
  441. # Checking swap on small instances
  442. if [ -z "$(swapon -s)" ] && [ $memory -lt 1000000 ]; then
  443. fallocate -l 1G /swapfile
  444. chmod 600 /swapfile
  445. mkswap /swapfile
  446. swapon /swapfile
  447. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  448. fi
  449. #----------------------------------------------------------#
  450. # Install repository #
  451. #----------------------------------------------------------#
  452. # Updating system
  453. echo "Adding required repositories to proceed with installation:"
  454. echo
  455. # Installing EPEL repository
  456. yum install epel-release -y
  457. check_result $? "Can't install EPEL repository"
  458. # Installing Remi repository
  459. yum -y install http://rpms.remirepo.net/enterprise/remi-release-$release.rpm
  460. check_result $? "Can't install REMI repository"
  461. sed -i "s/enabled=0/enabled=1/g" /etc/yum.repos.d/remi.repo
  462. # Installing Nginx repository
  463. nrepo="/etc/yum.repos.d/nginx.repo"
  464. echo "[nginx]" > $nrepo
  465. echo "name=nginx repo" >> $nrepo
  466. echo "baseurl=https://nginx.org/packages/centos/$release/\$basearch/" >> $nrepo
  467. echo "gpgcheck=0" >> $nrepo
  468. echo "enabled=1" >> $nrepo
  469. #----------------------------------------------------------#
  470. # Backup #
  471. #----------------------------------------------------------#
  472. # Creating backup directory tree
  473. mkdir -p $hst_backups
  474. cd $hst_backups
  475. mkdir nginx httpd php vsftpd proftpd bind exim4 dovecot clamd
  476. mkdir spamassassin mysql postgresql hestia
  477. # Backup nginx configuration
  478. systemctl stop nginx > /dev/null 2>&1
  479. cp -r /etc/nginx/* $hst_backups/nginx > /dev/null 2>&1
  480. # Backup Apache configuration
  481. systemctl stop httpd > /dev/null 2>&1
  482. cp -r /etc/httpd/* $hst_backups/httpd > /dev/null 2>&1
  483. # Backup PHP-FPM configuration
  484. systemctl stop php-fpm >/dev/null 2>&1
  485. cp /etc/php.ini $hst_backups/php > /dev/null 2>&1
  486. cp -r /etc/php.d $hst_backups/php > /dev/null 2>&1
  487. cp /etc/php-fpm.conf $hst_backups/php-fpm > /dev/null 2>&1
  488. mv -f /etc/php-fpm.d/* $hst_backups/php-fpm/ > /dev/null 2>&1
  489. # Backup Bind configuration
  490. yum remove bind-chroot > /dev/null 2>&1
  491. systemctl stop named > /dev/null 2>&1
  492. cp /etc/named.conf $hst_backups/named >/dev/null 2>&1
  493. # Backup Vsftpd configuration
  494. systemctl stop vsftpd > /dev/null 2>&1
  495. cp /etc/vsftpd/vsftpd.conf $hst_backups/vsftpd >/dev/null 2>&1
  496. # Backup ProFTPD configuration
  497. systemctl stop proftpd > /dev/null 2>&1
  498. cp /etc/proftpd.conf $hst_backups/proftpd >/dev/null 2>&1
  499. # Backup Exim configuration
  500. systemctl stop exim > /dev/null 2>&1
  501. cp -r /etc/exim/* $hst_backups/exim >/dev/null 2>&1
  502. # Backup ClamAV configuration
  503. systemctl stop clamd > /dev/null 2>&1
  504. cp /etc/clamd.conf $hst_backups/clamd >/dev/null 2>&1
  505. cp -r /etc/clamd.d $hst_backups/clamd >/dev/null 2>&1
  506. # Backup SpamAssassin configuration
  507. systemctl stop spamassassin > /dev/null 2>&1
  508. cp -r /etc/mail/spamassassin/* $hst_backups/spamassassin >/dev/null 2>&1
  509. # Backup Dovecot configuration
  510. systemctl stop dovecot > /dev/null 2>&1
  511. cp /etc/dovecot.conf $hst_backups/dovecot > /dev/null 2>&1
  512. cp -r /etc/dovecot/* $hst_backups/dovecot > /dev/null 2>&1
  513. # Backup MySQL/MariaDB configuration and data
  514. systemctl stop mysql > /dev/null 2>&1
  515. systemctl stop mysqld > /dev/null 2>&1
  516. systemctl stop mariadb > /dev/null 2>&1
  517. mv /var/lib/mysql $hst_backups/mysql/mysql_datadir >/dev/null 2>&1
  518. cp /etc/my.cnf $hst_backups/mysql > /dev/null 2>&1
  519. cp /etc/my.cnf.d $hst_backups/mysql > /dev/null 2>&1
  520. mv /root/.my.cnf $hst_backups/mysql > /dev/null 2>&1
  521. # Backup PostgreSQL configuration and data
  522. systemctl stop postgresql > /dev/null 2>&1
  523. mv /var/lib/pgsql/data $hst_backups/postgresql/ >/dev/null 2>&1
  524. # Backup Hestia
  525. systemctl stop hestia-nginx > /dev/null 2>&1
  526. systemctl stop hestia-php > /dev/null 2>&1
  527. cp -r $HESTIA* $hst_backups/hestia > /dev/null 2>&1
  528. yum -y remove hestia hestia-nginx hestia-php > /dev/null 2>&1
  529. rm -rf $HESTIA > /dev/null 2>&1
  530. #----------------------------------------------------------#
  531. # Package Includes #
  532. #----------------------------------------------------------#
  533. if [ "$phpfpm" = 'yes' ]; then
  534. phpfpm_prefix="$fpm_v-php" # phpfpm_prefix="$fpm_v" for Debian
  535. fpm="php$phpfpm_prefix php$phpfpm_prefix-common php$phpfpm_prefix-bcmath php$phpfpm_prefix-cli
  536. php$phpfpm_prefix-curl php$phpfpm_prefix-fpm php$phpfpm_prefix-gd php$phpfpm_prefix-intl
  537. php$phpfpm_prefix-mysql php$phpfpm_prefix-soap php$phpfpm_prefix-xml php$phpfpm_prefix-zip
  538. php$phpfpm_prefix-mbstring php$phpfpm_prefix-json php$phpfpm_prefix-bz2 php$phpfpm_prefix-pspell
  539. php$phpfpm_prefix-imagick"
  540. software="$software $fpm "
  541. fi
  542. #----------------------------------------------------------#
  543. # Package Excludes #
  544. #----------------------------------------------------------#
  545. # Excluding packages
  546. if [ "$nginx" = 'no' ]; then
  547. software=$(echo "$software" | sed -e "s/\bnginx\b/ /")
  548. fi
  549. if [ "$apache" = 'no' ]; then
  550. software=$(echo "$software" | sed -e "s/\bhttpd\b/ /")
  551. software=$(echo "$software" | sed -e "s/\bm\od_ssl\b/ /")
  552. software=$(echo "$software" | sed -e "s/\bmod_fcgid\b/ /")
  553. fi
  554. if [ "$phpfpm" = 'no' ]; then
  555. software=$(echo "$software" | sed -e "s/\bphp-fpm\b/ /")
  556. fi
  557. if [ "$vsftpd" = 'no' ]; then
  558. software=$(echo "$software" | sed -e "s/\bvsftpd\b/ /")
  559. fi
  560. if [ "$proftpd" = 'no' ]; then
  561. software=$(echo "$software" | sed -e "s/\bproftpd\b/ /")
  562. fi
  563. if [ "$named" = 'no' ]; then
  564. software=$(echo "$software" | sed -e "s/\bbind\b/ /")
  565. fi
  566. if [ "$exim" = 'no' ]; then
  567. software=$(echo "$software" | sed -e "s/\bexim\b/ /")
  568. software=$(echo "$software" | sed -e "s/\bdovecot\b/ /")
  569. software=$(echo "$software" | sed -e "s/\bclamd\b/ /")
  570. software=$(echo "$software" | sed -e "s/\bclamav\b/ /")
  571. software=$(echo "$software" | sed -e "s/\bclamav-update\b/ /")
  572. software=$(echo "$software" | sed -e "s/\bspamassassin\b/ /")
  573. software=$(echo "$software" | sed -e "s/\broundcube-core\b/ /")
  574. software=$(echo "$software" | sed -e "s/\broundcube-mysql\b/ /")
  575. software=$(echo "$software" | sed -e "s/\broundcube-plugins\b/ /")
  576. fi
  577. if [ "$clamd" = 'no' ]; then
  578. software=$(echo "$software" | sed -e "s/\bclamd\b/ /")
  579. software=$(echo "$software" | sed -e "s/\bclamav\b/ /")
  580. software=$(echo "$software" | sed -e "s/\bclamav-update\b/ /")
  581. fi
  582. if [ "$spamd" = 'no' ]; then
  583. software=$(echo "$software" | sed -e 's/\bspamassassin\b/ /')
  584. fi
  585. if [ "$dovecot" = 'no' ]; then
  586. software=$(echo "$software" | sed -e "s/\bdovecot-imapd\b/ /")
  587. software=$(echo "$software" | sed -e "s/\bdovecot-pop3d\b/ /")
  588. software=$(echo "$software" | sed -e "s/\broundcube-core\b/ /")
  589. software=$(echo "$software" | sed -e "s/\broundcube-mysql\b/ /")
  590. software=$(echo "$software" | sed -e "s/\broundcube-plugins\b/ /")
  591. fi
  592. if [ "$mysql" = 'no' ]; then
  593. software=$(echo "$software" | sed -e "s/\bmariadb-server\b/ /")
  594. software=$(echo "$software" | sed -e "s/\bmariadb-client\b/ /")
  595. software=$(echo "$software" | sed -e "s/\bmariadb-common\b/ /")
  596. software=$(echo "$software" | sed -e "s/\bphp$phpfpm_prefix-mysql\b/ /")
  597. if [ "$multiphp" = 'yes' ]; then
  598. for v in "${multiphp_v[@]}"; do
  599. software=$(echo "$software" | sed -e "s/\bphp$v-mysql\b/ /")
  600. software=$(echo "$software" | sed -e "s/\bphp$v-bz2\b/ /")
  601. done
  602. fi
  603. software=$(echo "$software" | sed -e "s/\bphpmyadmin\b/ /")
  604. fi
  605. if [ "$postgresql" = 'no' ]; then
  606. software=$(echo "$software" | sed -e "s/\bpostgresql-contrib\b/ /")
  607. software=$(echo "$software" | sed -e "s/\bpostgresql-server\b/ /")
  608. software=$(echo "$software" | sed -e "s/\bphp$phpfpm_prefix-pgsql\b/ /")
  609. if [ "$multiphp" = 'yes' ]; then
  610. for v in "${multiphp_v[@]}"; do
  611. software=$(echo "$software" | sed -e "s/\bphp$v-pgsql\b/ /")
  612. done
  613. fi
  614. software=$(echo "$software" | sed -e "s/\bphppgadmin\b/ /")
  615. fi
  616. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  617. software=$(echo "$software" | sed -e "s/\bfail2ban\b/ /")
  618. fi
  619. if [ "$phpfpm" = 'yes' ]; then
  620. software=$(echo "$software" | sed -e "s/\bphp$phpfpm_prefix-cgi\b/ /")
  621. fi
  622. if [ -d "$withrpms" ]; then
  623. software=$(echo "$software" | sed -e "s/\bhestia-nginx\b/ /")
  624. software=$(echo "$software" | sed -e "s/\bhestia-php\b/ /")
  625. software=$(echo "$software" | sed -e "s/\bhestia\b/ /")
  626. fi
  627. #----------------------------------------------------------#
  628. # Install packages #
  629. #----------------------------------------------------------#
  630. if [ "$codename" = "rhel_7" ]; then
  631. enabled_repos="*base *updates,nginx,epel,hestia,remi*"
  632. elif [ "$codename" = "rhel_8" ]; then
  633. # Enable Remi PHP stream
  634. dnf module disable -y php:*
  635. dnf module enable -y php:remi-7.4
  636. # Enable Perl 5.26
  637. dnf module disable -y perl:*
  638. dnf module enable -y perl:5.26
  639. dnf config-manager --set-enabled BaseOS
  640. dnf config-manager --set-enabled epel
  641. dnf config-manager --set-enabled epel-modular
  642. dnf config-manager --set-enabled extras
  643. dnf config-manager --set-enabled nginx
  644. dnf config-manager --set-enabled remi
  645. dnf config-manager --set-enabled remi-modular
  646. dnf config-manager --set-enabled PowerTools
  647. # No webalizer, phpPgAdmin on CentOS 8 yet
  648. software=$(echo "$software" | sed -e "s/\bwebalizer\b/ /")
  649. software=$(echo "$software" | sed -e "s/\bphpPgAdmin\b/ /")
  650. enabled_repos="BaseOS AppStream \
  651. epel epel-modular extras nginx PowerTools \
  652. raven raven-extras remi remi-modular"
  653. fi
  654. # Installing rpm packages
  655. yum install -y $software
  656. if [ $? -ne 0 ]; then
  657. echo yum -y --disablerepo=\* \
  658. --enablerepo="$enabled_repos" \
  659. install $software
  660. yum -y --disablerepo=\* \
  661. --enablerepo="$enabled_repos" \
  662. install $software
  663. fi
  664. check_result $? "yum install failed"
  665. if [ -d "$withrpms" ]; then
  666. yum install -y $withrpms/hestia-*.rpm
  667. else
  668. # Check repository availability
  669. wget --quiet "https://$GPG/rhel_signing.key" -O /dev/null
  670. check_result $? "Unable to connect to the Hestia RHEL repository"
  671. # Installing Hestia repository
  672. vrepo='/etc/yum.repos.d/hestia.repo'
  673. echo "[hestia]" > $vrepo
  674. echo "name=Hestia - $REPO" >> $vrepo
  675. echo "baseurl=http://$RHOST/$REPO/$release/\$basearch/" >> $vrepo
  676. echo "enabled=1" >> $vrepo
  677. echo "gpgcheck=1" >> $vrepo
  678. echo "gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-HESTIA" >> $vrepo
  679. wget c.hestiacp.com/GPG.txt -O /etc/pki/rpm-gpg/RPM-GPG-KEY-HESTIA
  680. yum install -y hestia hestia-nginx hestia-php
  681. fi
  682. #----------------------------------------------------------#
  683. # Configure system #
  684. #----------------------------------------------------------#
  685. echo "(*) Configuring system settings..."
  686. # Restarting rsyslog
  687. systemctl restart rsyslog > /dev/null 2>&1
  688. # Checking ipv6 on loopback interface
  689. check_lo_ipv6=$(/sbin/ip addr | grep 'inet6')
  690. check_rc_ipv6=$(grep 'scope global dev lo' /etc/rc.local)
  691. if [ ! -z "$check_lo_ipv6)" ] && [ -z "$check_rc_ipv6" ]; then
  692. ip addr add ::2/128 scope global dev lo
  693. echo "# Hestia: Workraround for openssl validation func" >> /etc/rc.local
  694. echo "ip addr add ::2/128 scope global dev lo" >> /etc/rc.local
  695. chmod a+x /etc/rc.local
  696. fi
  697. # Disabling SELinux
  698. if [ -e '/etc/sysconfig/selinux' ]; then
  699. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  700. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  701. setenforce 0 2>/dev/null
  702. fi
  703. # Disabling iptables
  704. systemctl stop iptables
  705. systemctl stop firewalld >/dev/null 2>&1
  706. # Configuring NTP synchronization
  707. if [ "$codename" = "rhel_7" ]; then
  708. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  709. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  710. chmod 775 /etc/cron.daily/ntpdate
  711. ntpdate -s pool.ntp.org
  712. elif [ "$codename" = "rhel_7" ]; then
  713. systemctl enable --now chronyd
  714. fi
  715. # Disabling webalizer routine
  716. rm -f /etc/cron.daily/00webalizer
  717. # Adding backup user
  718. adduser backup 2>/dev/null
  719. ln -sf /home/backup /backup
  720. chmod a+x /backup
  721. # Fix for nonexistent Debian-style "nogroup" on RHEL-based systems
  722. groupadd -o -g $(id -g nobody) nogroup
  723. # Set directory color
  724. if [ -z "$(grep 'LS_COLORS="$LS_COLORS:di=00;33"' /etc/profile)" ]; then
  725. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  726. fi
  727. # Register /sbin/nologin and /usr/sbin/nologin
  728. if [ -z "$(grep ^/sbin/nologin /etc/shells)" ]; then
  729. echo "/sbin/nologin" >> /etc/shells
  730. fi
  731. if [ -z "$(grep ^/usr/sbin/nologin /etc/shells)" ]; then
  732. echo "/usr/sbin/nologin" >> /etc/shells
  733. fi
  734. # Changing default systemd interval
  735. if [ "$release" -eq '7' ]; then
  736. # Hi Lennart
  737. echo "DefaultStartLimitInterval=1s" >> /etc/systemd/system.conf
  738. echo "DefaultStartLimitBurst=60" >> /etc/systemd/system.conf
  739. systemctl daemon-reexec
  740. fi
  741. #----------------------------------------------------------#
  742. # Configure Hestia #
  743. #----------------------------------------------------------#
  744. echo "(*) Configuring Hestia Control Panel..."
  745. # Installing sudo configuration
  746. mkdir -p /etc/sudoers.d
  747. cp -f $HESTIA_INSTALL_DIR/sudo/admin /etc/sudoers.d/
  748. chmod 440 /etc/sudoers.d/admin
  749. # Configuring system env
  750. echo "export HESTIA='$HESTIA'" > /etc/profile.d/hestia.sh
  751. echo 'PATH=$PATH:'$HESTIA'/bin' >> /etc/profile.d/hestia.sh
  752. echo 'export PATH' >> /etc/profile.d/hestia.sh
  753. chmod 755 /etc/profile.d/hestia.sh
  754. source /etc/profile.d/hestia.sh
  755. # Configuring logrotate for hestia logs
  756. cp -f $HESTIA_INSTALL_DIR/logrotate/hestia /etc/logrotate.d/
  757. # Building directory tree and creating some blank files for Hestia
  758. mkdir -p $HESTIA/conf $HESTIA/log $HESTIA/ssl $HESTIA/data/ips \
  759. $HESTIA/data/queue $HESTIA/data/users $HESTIA/data/firewall \
  760. $HESTIA/data/sessions
  761. touch $HESTIA/data/queue/backup.pipe $HESTIA/data/queue/disk.pipe \
  762. $HESTIA/data/queue/webstats.pipe $HESTIA/data/queue/restart.pipe \
  763. $HESTIA/data/queue/traffic.pipe $HESTIA/log/system.log \
  764. $HESTIA/log/nginx-error.log $HESTIA/log/auth.log
  765. chmod 750 $HESTIA/conf $HESTIA/data/users $HESTIA/data/ips $HESTIA/log
  766. chmod -R 750 $HESTIA/data/queue
  767. chmod 660 $HESTIA/log/*
  768. rm -f /var/log/hestia
  769. ln -s $HESTIA/log /var/log/hestia
  770. chmod 770 $HESTIA/data/sessions
  771. # Fixes for some Debian-only scripts
  772. ln -s /usr/local/hestia/data/templates/web/httpd /usr/local/hestia/data/templates/web/apache2
  773. ln -s /usr/sbin/ip /bin/ip
  774. # Generating Hestia configuration
  775. rm -f $HESTIA/conf/hestia.conf > /dev/null 2>&1
  776. touch $HESTIA/conf/hestia.conf
  777. chmod 660 $HESTIA/conf/hestia.conf
  778. # Web stack
  779. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  780. echo "WEB_SYSTEM='httpd'" >> $HESTIA/conf/hestia.conf
  781. echo "WEB_RGROUPS='apache'" >> $HESTIA/conf/hestia.conf
  782. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  783. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  784. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  785. echo "STATS_SYSTEM='awstats'" >> $HESTIA/conf/hestia.conf
  786. fi
  787. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  788. echo "WEB_SYSTEM='httpd'" >> $HESTIA/conf/hestia.conf
  789. echo "WEB_RGROUPS='apache'" >> $HESTIA/conf/hestia.conf
  790. echo "WEB_PORT='8080'" >> $HESTIA/conf/hestia.conf
  791. echo "WEB_SSL_PORT='8443'" >> $HESTIA/conf/hestia.conf
  792. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  793. echo "PROXY_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  794. echo "PROXY_PORT='80'" >> $HESTIA/conf/hestia.conf
  795. echo "PROXY_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  796. echo "STATS_SYSTEM='awstats'" >> $HESTIA/conf/hestia.conf
  797. fi
  798. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  799. echo "WEB_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  800. echo "WEB_RGROUPS='apache'" >> $HESTIA/conf/hestia.conf
  801. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  802. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  803. echo "WEB_SSL='openssl'" >> $HESTIA/conf/hestia.conf
  804. echo "STATS_SYSTEM='awstats'" >> $HESTIA/conf/hestia.conf
  805. fi
  806. if [ "$phpfpm" = 'yes' ] || [ "$multiphp" = 'yes' ]; then
  807. echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
  808. fi
  809. # Database stack
  810. if [ "$mysql" = 'yes' ]; then
  811. installed_db_types='mysql'
  812. fi
  813. if [ "$pgsql" = 'yes' ]; then
  814. installed_db_types="$installed_db_type,pgsql"
  815. fi
  816. if [ ! -z "$installed_db_types" ]; then
  817. db=$(echo "$installed_db_types" |\
  818. sed "s/,/\n/g"|\
  819. sort -r -u |\
  820. sed "/^$/d"|\
  821. sed ':a;N;$!ba;s/\n/,/g')
  822. echo "DB_SYSTEM='$db'" >> $HESTIA/conf/hestia.conf
  823. fi
  824. # FTP stack
  825. if [ "$vsftpd" = 'yes' ]; then
  826. echo "FTP_SYSTEM='vsftpd'" >> $HESTIA/conf/hestia.conf
  827. fi
  828. if [ "$proftpd" = 'yes' ]; then
  829. echo "FTP_SYSTEM='proftpd'" >> $HESTIA/conf/hestia.conf
  830. fi
  831. # DNS stack
  832. if [ "$named" = 'yes' ]; then
  833. echo "DNS_SYSTEM='named'" >> $HESTIA/conf/hestia.conf
  834. fi
  835. # Mail stack
  836. if [ "$exim" = 'yes' ]; then
  837. echo "MAIL_SYSTEM='exim'" >> $HESTIA/conf/hestia.conf
  838. if [ "$clamd" = 'yes' ]; then
  839. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $HESTIA/conf/hestia.conf
  840. fi
  841. if [ "$spamd" = 'yes' ]; then
  842. echo "ANTISPAM_SYSTEM='spamassassin'" >> $HESTIA/conf/hestia.conf
  843. fi
  844. if [ "$dovecot" = 'yes' ]; then
  845. echo "IMAP_SYSTEM='dovecot'" >> $HESTIA/conf/hestia.conf
  846. fi
  847. fi
  848. # Cron daemon
  849. echo "CRON_SYSTEM='crond'" >> $HESTIA/conf/hestia.conf
  850. # Firewall stack
  851. if [ "$iptables" = 'yes' ]; then
  852. echo "FIREWALL_SYSTEM='iptables'" >> $HESTIA/conf/hestia.conf
  853. fi
  854. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  855. echo "FIREWALL_EXTENSION='fail2ban'" >> $HESTIA/conf/hestia.conf
  856. fi
  857. # Disk quota
  858. if [ "$quota" = 'yes' ]; then
  859. echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
  860. fi
  861. # Backups
  862. echo "BACKUP_SYSTEM='local'" >> $HESTIA/conf/hestia.conf
  863. # Language
  864. echo "LANGUAGE='$lang'" >> $HESTIA/conf/hestia.conf
  865. # Version & Release Branch
  866. echo "VERSION='${HESTIA_INSTALL_VER}'" >> $HESTIA/conf/hestia.conf
  867. echo "RELEASE_BRANCH='release'" >> $HESTIA/conf/hestia.conf
  868. # Installing hosting packages
  869. cp -rf $HESTIA_INSTALL_DIR/packages $HESTIA/data/
  870. # Update nameservers in hosting package
  871. IFS='.' read -r -a domain_elements <<< "$servername"
  872. if [ ! -z "${domain_elements[-2]}" ] && [ ! -z "${domain_elements[-1]}" ]; then
  873. serverdomain="${domain_elements[-2]}.${domain_elements[-1]}"
  874. sed -i s/"domain.tld"/"$serverdomain"/g $HESTIA/data/packages/*.pkg
  875. fi
  876. # Installing templates
  877. cp -rf $HESTIA_INSTALL_DIR/templates $HESTIA/data/
  878. mkdir -p /var/www/html
  879. mkdir -p /var/www/document_errors
  880. # Install default success page
  881. cp -rf $HESTIA_INSTALL_DIR/templates/web/unassigned/index.html /var/www/html/
  882. cp -rf $HESTIA_INSTALL_DIR/templates/web/skel/document_errors/* /var/www/document_errors/
  883. # Installing firewall rules
  884. cp -rf $HESTIA_INSTALL_DIR/firewall $HESTIA/data/
  885. # Configuring server hostname
  886. $HESTIA/bin/v-change-sys-hostname $servername > /dev/null 2>&1
  887. # Generating SSL certificate
  888. echo "(*) Generating default self-signed SSL certificate..."
  889. $HESTIA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  890. 'San Francisco' 'Hestia Control Panel' 'IT' > /tmp/hst.pem
  891. # Parsing certificate file
  892. crt_end=$(grep -n "END CERTIFICATE-" /tmp/hst.pem |cut -f 1 -d:)
  893. key_start=$(grep -n "BEGIN RSA" /tmp/hst.pem |cut -f 1 -d:)
  894. key_end=$(grep -n "END RSA" /tmp/hst.pem |cut -f 1 -d:)
  895. # Adding SSL certificate
  896. echo "(*) Adding SSL certificate to Hestia Control Panel..."
  897. cd $HESTIA/ssl
  898. sed -n "1,${crt_end}p" /tmp/hst.pem > certificate.crt
  899. sed -n "$key_start,${key_end}p" /tmp/hst.pem > certificate.key
  900. chown root:mail $HESTIA/ssl/*
  901. chmod 660 $HESTIA/ssl/*
  902. rm /tmp/hst.pem
  903. # Adding nologin as a valid system shell
  904. if [ -z "$(grep nologin /etc/shells)" ]; then
  905. echo "/usr/sbin/nologin" >> /etc/shells
  906. fi
  907. # Install dhparam.pem
  908. cp -f $HESTIA_INSTALL_DIR/ssl/dhparam.pem /etc/ssl
  909. #----------------------------------------------------------#
  910. # Configure Nginx #
  911. #----------------------------------------------------------#
  912. if [ "$nginx" = 'yes' ]; then
  913. echo "(*) Configuring NGINX..."
  914. rm -f /etc/nginx/conf.d/*.conf
  915. cp -f $HESTIA_INSTALL_DIR/nginx/nginx.conf /etc/nginx/
  916. cp -f $HESTIA_INSTALL_DIR/nginx/status.conf /etc/nginx/conf.d/
  917. cp -f $HESTIA_INSTALL_DIR/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  918. cp -f $HESTIA_INSTALL_DIR/nginx/phppgadmin.inc /etc/nginx/conf.d/
  919. cp -f $HESTIA_INSTALL_DIR/logrotate/nginx /etc/logrotate.d/
  920. mkdir -p /etc/nginx/conf.d/domains
  921. mkdir -p /var/log/nginx/domains
  922. mkdir -p /etc/systemd/system/nginx.service.d
  923. cd /etc/systemd/system/nginx.service.d
  924. echo "[Service]" > limits.conf
  925. echo "LimitNOFILE=500000" >> limits.conf
  926. # Update dns servers in nginx.conf
  927. dns_resolver=$(cat /etc/resolv.conf | grep -i '^nameserver' | cut -d ' ' -f2 | tr '\r\n' ' ' | xargs)
  928. for ip in $dns_resolver; do
  929. if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  930. resolver="$ip $resolver"
  931. fi
  932. done
  933. if [ ! -z "$resolver" ]; then
  934. sed -i "s/1.0.0.1 1.1.1.1/$resolver/g" /etc/nginx/nginx.conf
  935. sed -i "s/1.0.0.1 1.1.1.1/$resolver/g" /usr/local/hestia/nginx/conf/nginx.conf
  936. fi
  937. systemctl enable nginx
  938. systemctl start nginx >> $LOG
  939. check_result $? "nginx start failed"
  940. fi
  941. #----------------------------------------------------------#
  942. # Configure Apache #
  943. #----------------------------------------------------------#
  944. if [ "$apache" = 'yes' ]; then
  945. echo "(*) Configuring Apache Web Server..."
  946. mkdir -p /etc/httpd/conf.d/domains
  947. # Copy configuration files
  948. cp -f $HESTIA_INSTALL_DIR/httpd/httpd.conf /etc/httpd/conf/
  949. cp -f $HESTIA_INSTALL_DIR/httpd/status.conf /etc/httpd/conf.d/
  950. cp -f $HESTIA_INSTALL_DIR/httpd/hestia-event.conf /etc/httpd/conf.modules.d/
  951. cp -f $HESTIA_INSTALL_DIR/logrotate/httpd /etc/logrotate.d/
  952. # Disable modules
  953. if [ -e "/etc/httpd/conf.modules.d/00-dav.conf" ]; then
  954. cd /etc/httpd/conf.modules.d
  955. sed -i "s/^/#/" 00-dav.conf
  956. fi
  957. if [ -e "/etc/httpd/conf.modules.d/00-lua.conf" ]; then
  958. cd /etc/httpd/conf.modules.d
  959. sed -i "s/^/#/" 00-lua.conf 00-proxy.conf
  960. fi
  961. if [ -e "/etc/httpd/conf.modules.d/00-proxy.conf" ]; then
  962. cd /etc/httpd/conf.modules.d
  963. sed -i "s/^/#/" 00-proxy.conf
  964. fi
  965. if [ "$phpfpm" = 'yes' ]; then
  966. # Disable prefork and php, enable event
  967. # apache_module_disable 'php5'
  968. sed -i "/LoadModule php5_module/ s/^/#/" /etc/httpd/conf.modules.d/*.conf
  969. # apache_module_disable 'php7'
  970. sed -i "/LoadModule php7_module/ s/^/#/" /etc/httpd/conf.modules.d/*.conf
  971. # apache_module_disable 'mpm_prefork'
  972. sed -i "/LoadModule mpm_prefork_module/ s/^/#/" /etc/httpd/conf.modules.d/*.conf
  973. # apache_module_enable 'mpm_event'
  974. sed -i "/LoadModule mpm_event_module/ s/#*//" /etc/httpd/conf.modules.d/*.conf
  975. fi
  976. sed -i "/LoadModule proxy_http2_module/ s/^/#/" /etc/httpd/conf.modules.d/*.conf
  977. echo "# Powered by hestia" > /etc/httpd/conf.d/welcome.conf
  978. mkdir -p /var/log/httpd/domains
  979. chmod a+x /var/log/httpd
  980. chmod 640 /var/log/httpd/access.log /var/log/httpd/error.log
  981. chmod 751 /var/log/httpd/domains
  982. chmod -f 777 /var/lib/php/session
  983. # Not needed. status.conf is fixed.
  984. # sed -i '/Allow from all/d' /etc/apache2/mods-enabled/status.conf
  985. systemctl enable httpd
  986. systemctl start httpd >> $LOG
  987. check_result $? "httpd start failed"
  988. else
  989. systemctl disable httpd > /dev/null 2>&1
  990. systemctl stop httpd > /dev/null 2>&1
  991. fi
  992. #----------------------------------------------------------#
  993. # Configure PHP-FPM #
  994. #----------------------------------------------------------#
  995. if [ "$multiphp" = 'yes' ] ; then
  996. for v in "${multiphp_v[@]}"; do
  997. cp -r /etc/php/$v/ /root/hst_install_backups/php$v/
  998. rm -f /etc/php/$v/fpm/pool.d/*
  999. echo "(*) Install PHP version $v..."
  1000. $HESTIA/bin/v-add-web-php "$v" > /dev/null 2>&1
  1001. done
  1002. fi
  1003. if [ "$phpfpm" = 'yes' ]; then
  1004. echo "(*) Configuring PHP-FPM..."
  1005. $HESTIA/bin/v-add-web-php "$fpm_v" > /dev/null 2>&1
  1006. cp -f $HESTIA_INSTALL_DIR/php-fpm/www.conf /etc/php/$fpm_v/fpm/pool.d/www.conf
  1007. systemctl enable php$phpfpm_prefix-fpm > /dev/null 2>&1
  1008. systemctl start php$phpfpm_prefix-fpm >> $LOG
  1009. check_result $? "php-fpm start failed"
  1010. update-alternatives --set php /usr/bin/php$fpm_v > /dev/null 2>&1
  1011. fi
  1012. #----------------------------------------------------------#
  1013. # Configure PHP #
  1014. #----------------------------------------------------------#
  1015. echo "(*) Configuring PHP..."
  1016. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  1017. if [ -z "$ZONE" ]; then
  1018. ZONE='UTC'
  1019. fi
  1020. for pconf in $(find /etc/php* -name php.ini); do
  1021. sed -i "s|;date.timezone =|date.timezone = $ZONE|g" $pconf
  1022. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  1023. done
  1024. # Cleanup php session files not changed in the last 7 days (60*24*7 minutes)
  1025. echo '#!/bin/sh' > /etc/cron.daily/php-session-cleanup
  1026. echo "find -O3 /home/*/tmp/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
  1027. echo "find -O3 $HESTIA/data/sessions/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
  1028. chmod 755 /etc/cron.daily/php-session-cleanup
  1029. #----------------------------------------------------------#
  1030. # Configure Vsftpd #
  1031. #----------------------------------------------------------#
  1032. if [ "$vsftpd" = 'yes' ]; then
  1033. echo "(*) Configuring Vsftpd server..."
  1034. cp -f $HESTIA_INSTALL_DIR/vsftpd/vsftpd.conf /etc/
  1035. touch /var/log/vsftpd.log
  1036. chown root:adm /var/log/vsftpd.log
  1037. chmod 640 /var/log/vsftpd.log
  1038. touch /var/log/xferlog
  1039. chown root:adm /var/log/xferlog
  1040. chmod 640 /var/log/xferlog
  1041. systemctl enable vsftpd
  1042. systemctl start vsftpd
  1043. check_result $? "vsftpd start failed"
  1044. fi
  1045. #----------------------------------------------------------#
  1046. # Configure ProFTPD #
  1047. #----------------------------------------------------------#
  1048. if [ "$proftpd" = 'yes' ]; then
  1049. echo "(*) Configuring ProFTPD server..."
  1050. echo "127.0.0.1 $servername" >> /etc/hosts
  1051. cp -f $HESTIA_INSTALL_DIR/proftpd/proftpd.conf /etc/proftpd/
  1052. systemctl enable proftpd > /dev/null 2>&1
  1053. systemctl start proftpd >> $LOG
  1054. check_result $? "proftpd start failed"
  1055. fi
  1056. #----------------------------------------------------------#
  1057. # Configure MySQL/MariaDB #
  1058. #----------------------------------------------------------#
  1059. if [ "$mysql" = 'yes' ]; then
  1060. echo "(*) Configuring MariaDB database server..."
  1061. mycnf="my-small.cnf"
  1062. if [ $memory -gt 1200000 ]; then
  1063. mycnf="my-medium.cnf"
  1064. fi
  1065. if [ $memory -gt 3900000 ]; then
  1066. mycnf="my-large.cnf"
  1067. fi
  1068. # Configuring MariaDB
  1069. cp -f $HESTIA_INSTALL_DIR/mysql/$mycnf /etc/my.cnf
  1070. rm -f /etc/my.cnf.d/*.cnf
  1071. mysql_install_db >> $LOG
  1072. systemctl enable mariadb > /dev/null 2>&1
  1073. systemctl start mariadb >> $LOG
  1074. check_result $? "mariadb start failed"
  1075. # Securing MySQL installation
  1076. mpass=$(gen_pass)
  1077. mysqladmin -u root password $mpass
  1078. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  1079. chmod 600 /root/.my.cnf
  1080. # Clear MariaDB Test Users and Databases
  1081. mysql -e "DELETE FROM mysql.user WHERE User=''"
  1082. mysql -e "DROP DATABASE test" > /dev/null 2>&1
  1083. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  1084. mysql -e "DELETE FROM mysql.user WHERE user='';"
  1085. mysql -e "DELETE FROM mysql.user WHERE password='' AND authentication_string='';"
  1086. fi
  1087. #----------------------------------------------------------#
  1088. # Configure phpMyAdmin #
  1089. #----------------------------------------------------------#
  1090. if [ "$mysql" = 'yes' ]; then
  1091. # Display upgrade information
  1092. echo "(*) Installing phpMyAdmin version v$pma_v..."
  1093. # Download latest phpmyadmin release
  1094. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  1095. # Unpack files
  1096. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  1097. # Delete file to prevent error
  1098. rm -fr /usr/share/phpMyAdmin/doc/html
  1099. # Overwrite old files
  1100. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpMyAdmin
  1101. # Set config and log directory
  1102. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpMyAdmin/');|" /usr/share/phpMyAdmin/libraries/vendor_config.php
  1103. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpMyAdmin/temp/');|" /usr/share/phpMyAdmin/libraries/vendor_config.php
  1104. # Create temporary folder and change permission
  1105. mkdir -p /var/lib/phpMyAdmin/temp
  1106. chmod 777 /var/lib/phpMyAdmin/temp
  1107. # Configuring phpMyAdmin
  1108. if [ "$apache" = 'yes' ]; then
  1109. cp -f $HESTIA_INSTALL_DIR/pma/apache.conf /etc/phpMyAdmin/
  1110. rm -f /etc/httpd/conf.d/phpMyAdmin.conf
  1111. ln -s /etc/phpMyAdmin/apache.conf /etc/httpd/conf.d/phpMyAdmin.conf
  1112. fi
  1113. cp -f $HESTIA_INSTALL_DIR/pma/config.inc.php /etc/phpMyAdmin/
  1114. # Clear Up
  1115. rm -fr phpMyAdmin-$pma_v-all-languages
  1116. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  1117. fi
  1118. #----------------------------------------------------------#
  1119. # Configure PostgreSQL #
  1120. #----------------------------------------------------------#
  1121. if [ "$postgresql" = 'yes' ]; then
  1122. echo "(*) Configuring PostgreSQL database server..."
  1123. ppass=$(gen_pass)
  1124. cp -f $HESTIA_INSTALL_DIR/postgresql/pg_hba.conf /var/lib/pgsql/data/
  1125. systemctl restart postgresql
  1126. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  1127. # Configuring phpPgAdmin
  1128. if [ "$apache" = 'yes' ]; then
  1129. cp -f $HESTIA_INSTALL_DIR/pga/phpPgAdmin.conf /etc/httpd/conf.d/
  1130. fi
  1131. cp -f $HESTIA_INSTALL_DIR/pga/config.inc.php /etc/phpPgAdmin/
  1132. fi
  1133. #----------------------------------------------------------#
  1134. # Configure Bind #
  1135. #----------------------------------------------------------#
  1136. if [ "$named" = 'yes' ]; then
  1137. echo "(*) Configuring Bind DNS server..."
  1138. cp -f $HESTIA_INSTALL_DIR/bind/named.conf /etc/
  1139. cp -f $HESTIA_INSTALL_DIR/bind/named.conf.options /etc/
  1140. chown root:named /etc/named.conf
  1141. chown root:named /etc/named.conf.options
  1142. chown named:named /var/named
  1143. chmod 640 /etc/named.conf
  1144. chmod 640 /etc/named.conf.options
  1145. systemctl enable named
  1146. systemctl restart named
  1147. check_result $? "named start failed"
  1148. fi
  1149. #----------------------------------------------------------#
  1150. # Configure Exim #
  1151. #----------------------------------------------------------#
  1152. if [ "$exim" = 'yes' ]; then
  1153. echo "(*) Configuring Exim mail server..."
  1154. gpasswd -a exim mail > /dev/null 2>&1
  1155. cp -f $HESTIA_INSTALL_DIR/exim/exim.conf.template /etc/exim/exim.conf
  1156. cp -f $HESTIA_INSTALL_DIR/exim/dnsbl.conf /etc/exim/
  1157. cp -f $HESTIA_INSTALL_DIR/exim/spam-blocks.conf /etc/exim/
  1158. touch /etc/exim/white-blocks.conf
  1159. if [ "$spamd" = 'yes' ]; then
  1160. sed -i "s/#SPAM/SPAM/g" /etc/exim/exim.conf
  1161. fi
  1162. if [ "$clamd" = 'yes' ]; then
  1163. sed -i "s/#CLAMD/CLAMD/g" /etc/exim/exim.conf
  1164. fi
  1165. chmod 640 /etc/exim/exim.conf
  1166. rm -rf /etc/exim/domains
  1167. mkdir -p /etc/exim/domains
  1168. rm -f /etc/alternatives/mta
  1169. ln -s /usr/sbin/sendmail.exim /etc/alternatives/mta
  1170. systemctl disable sendmail 2>/dev/null
  1171. systemctl stop sendmail 2>/dev/null
  1172. systemctl disable postfix 2>/dev/null
  1173. systemctl stop postfix 2>/dev/null
  1174. systemctl enable exim
  1175. systemctl start exim
  1176. check_result $? "exim start failed"
  1177. fi
  1178. #----------------------------------------------------------#
  1179. # Configure Dovecot #
  1180. #----------------------------------------------------------#
  1181. if [ "$dovecot" = 'yes' ]; then
  1182. echo "(*) Configuring Dovecot POP/IMAP mail server..."
  1183. gpasswd -a dovecot mail > /dev/null 2>&1
  1184. cp -rf $HESTIA_INSTALL_DIR/dovecot /etc/
  1185. cp -f $HESTIA_INSTALL_DIR/logrotate/dovecot /etc/logrotate.d/
  1186. chown -R root:root /etc/dovecot*
  1187. if [ "$release" -eq 7 ]; then
  1188. sed -i "s#namespace inbox {#namespace inbox {\n inbox = yes#" /etc/dovecot/conf.d/15-mailboxes.conf
  1189. fi
  1190. systemctl enable dovecot
  1191. systemctl start dovecot
  1192. check_result $? "dovecot start failed"
  1193. fi
  1194. #----------------------------------------------------------#
  1195. # Configure ClamAV #
  1196. #----------------------------------------------------------#
  1197. if [ "$clamd" = 'yes' ]; then
  1198. useradd clamav -g clamupdate -s /sbin/nologin -d /var/lib/clamav 2>/dev/null
  1199. gpasswd -a clamupdate exim
  1200. gpasswd -a clamupdate mail
  1201. cp -f $HESTIA_INSTALL_DIR/clamav/clamd.conf /etc/
  1202. cp -f $HESTIA_INSTALL_DIR/clamav/freshclam.conf /etc/
  1203. mkdir -p /var/log/clamav /var/run/clamav
  1204. chown clamav:clamupdate /var/log/clamav /var/run/clamav
  1205. chown -R clamav:clamupdate /var/lib/clamav
  1206. chmod 0775 /var/lib/clamav /var/log/clamav
  1207. cp -f $HESTIA_INSTALL_DIR/clamav/clamd.service /usr/lib/systemd/system/
  1208. systemctl daemon-reload
  1209. systemctl enable clamd
  1210. echo -ne "(*) Installing ClamAV anti-virus definitions... "
  1211. /usr/bin/freshclam >> $LOG &
  1212. BACK_PID=$!
  1213. spin_i=1
  1214. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  1215. printf "\b${spinner:spin_i++%${#spinner}:1}"
  1216. sleep 0.5
  1217. done
  1218. echo
  1219. systemctl start clamd
  1220. check_result $? "clamav-daemon start failed"
  1221. fi
  1222. #----------------------------------------------------------#
  1223. # Configure SpamAssassin #
  1224. #----------------------------------------------------------#
  1225. if [ "$spamd" = 'yes' ]; then
  1226. echo "(*) Configuring SpamAssassin..."
  1227. systemctl enable spamassassin
  1228. systemctl start spamassassin
  1229. check_result $? "spamassassin start failed"
  1230. fi
  1231. #----------------------------------------------------------#
  1232. # Configure RoundCube #
  1233. #----------------------------------------------------------#
  1234. if [ "$dovecot" = 'yes' ] && [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1235. echo "(*) Configuring Roundcube webmail client..."
  1236. cp -f $HESTIA_INSTALL_DIR/roundcube/main.inc.php /etc/roundcubemail/config.inc.php
  1237. cp -f $HESTIA_INSTALL_DIR/roundcube/db.inc.php /etc/roundcubemail/db.inc.php
  1238. cp -f $HESTIA_INSTALL_DIR/roundcube/config.inc.php /etc/roundcubemail/plugins/password/
  1239. cp -f $HESTIA_INSTALL_DIR/roundcube/hestia.php /usr/share/roundcubemail/plugins/password/drivers/
  1240. touch /var/log/roundcubemail/errors
  1241. chmod 640 /etc/roundcubemail/config.inc.php
  1242. chown root:apache /etc/roundcubemail/config.inc.php
  1243. chmod 640 /etc/roundcubemail/db.inc.php
  1244. chown root:apache /etc/roundcubemail/db.inc.php
  1245. chmod 640 /var/log/roundcubemail/errors
  1246. chown apache:adm /var/log/roundcubemail/errors
  1247. r="$(gen_pass)"
  1248. rcDesKey="$(openssl rand -base64 30 | tr -d "/" | cut -c1-24)"
  1249. mysql -e "CREATE DATABASE roundcube"
  1250. mysql -e "GRANT ALL ON roundcube.*
  1251. TO roundcube@localhost IDENTIFIED BY '$r'"
  1252. sed -i "s/%password%/$r/g" /etc/roundcubemail/db.inc.php
  1253. sed -i "s/%des_key%/$rcDesKey/g" /etc/roundcubemail/config.inc.php
  1254. sed -i "s/localhost/$servername/g" /usr/share/roundcubemail/plugins/password/config.inc.php
  1255. mysql roundcube < /usr/share/roundcubemail/SQL/mysql
  1256. # Enable Roundcube plugins
  1257. cp -f $HESTIA_INSTALL_DIR/roundcube/plugins/config_newmail_notifier.inc.php /etc/roundcubemail/plugins/newmail_notifier/config.inc.php
  1258. cp -f $HESTIA_INSTALL_DIR/roundcube/plugins/config_zipdownload.inc.php /etc/roundcubemail/plugins/zipdownload/config.inc.php
  1259. # Fixes for PHP 7.4 compatibility
  1260. sed -i 's/$identities, "\\n"/"\\n", $identities/g' /usr/share/roundcubemail/plugins/enigma/lib/enigma_ui.php
  1261. sed -i 's/(array_keys($post_search), \x27|\x27)/(\x27|\x27, array_keys($post_search))/g' /usr/share/roundcubemail/program/lib/Roundcube/rcube_contacts.php
  1262. sed -i 's/implode($name, \x27.\x27)/implode(\x27.\x27, $name)/g' /usr/share/roundcubemail/program/lib/Roundcube/rcube_db.php
  1263. sed -i 's/$fields, \x27,\x27/\x27,\x27, $fields/g' /usr/share/roundcubemail/program/steps/addressbook/search.inc
  1264. sed -i 's/implode($fields, \x27,\x27)/implode(\x27,\x27, $fields)/g' /usr/share/roundcubemail/program/steps/addressbook/search.inc
  1265. sed -i 's/implode($bstyle, \x27; \x27)/implode(\x27; \x27, $bstyle)/g' /usr/share/roundcubemail/program/steps/mail/sendmail.inc
  1266. # Configure webmail alias
  1267. echo "WEBMAIL_ALIAS='webmail'" >> $HESTIA/conf/hestia.conf
  1268. # Add robots.txt
  1269. echo "User-agent: *" > /var/lib/roundcubemail/robots.txt
  1270. echo "Disallow: /" >> /var/lib/roundcubemail/robots.txt
  1271. # Restart services
  1272. if [ "$apache" = 'yes' ]; then
  1273. systemctl restart httpd
  1274. fi
  1275. if [ "$nginx" = 'yes' ]; then
  1276. systemctl restart nginx
  1277. fi
  1278. fi
  1279. #----------------------------------------------------------#
  1280. # Configure Fail2Ban #
  1281. #----------------------------------------------------------#
  1282. if [ "$fail2ban" = 'yes' ]; then
  1283. echo "(*) Configuring fail2ban access monitor..."
  1284. cp -rf $HESTIA_INSTALL_DIR/fail2ban /etc/
  1285. if [ "$dovecot" = 'no' ]; then
  1286. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1287. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1288. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1289. fi
  1290. if [ "$exim" = 'no' ]; then
  1291. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1292. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1293. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1294. fi
  1295. if [ "$vsftpd" = 'yes' ]; then
  1296. #Create vsftpd Log File
  1297. if [ ! -f "/var/log/vsftpd.log" ]; then
  1298. touch /var/log/vsftpd.log
  1299. fi
  1300. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1301. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1302. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1303. fi
  1304. systemctl enable fail2ban
  1305. systemctl start fail2ban
  1306. check_result $? "fail2ban start failed"
  1307. fi
  1308. #----------------------------------------------------------#
  1309. # Configure API #
  1310. #----------------------------------------------------------#
  1311. if [ "$api" = 'yes' ]; then
  1312. echo "API='yes'" >> $HESTIA/conf/hestia.conf
  1313. else
  1314. rm -r $HESTIA/web/api
  1315. echo "API='no'" >> $HESTIA/conf/hestia.conf
  1316. fi
  1317. #----------------------------------------------------------#
  1318. # Fix phpmyadmin #
  1319. #----------------------------------------------------------#
  1320. # Special thanks to Pavel Galkin (https://skurudo.ru)
  1321. # https://github.com/skurudo/phpmyadmin-fixer
  1322. if [ "$mysql" = 'yes' ]; then
  1323. source $HESTIA_INSTALL_DIR/phpmyadmin/pma.sh > /dev/null 2>&1
  1324. fi
  1325. #----------------------------------------------------------#
  1326. # Configure Admin User #
  1327. #----------------------------------------------------------#
  1328. # Deleting old admin user
  1329. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1330. chattr -i /home/admin/conf > /dev/null 2>&1
  1331. userdel -f admin > /dev/null 2>&1
  1332. chattr -i /home/admin/conf > /dev/null 2>&1
  1333. mv -f /home/admin $hst_backups/home/ > /dev/null 2>&1
  1334. rm -f /tmp/sess_* > /dev/null 2>&1
  1335. fi
  1336. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1337. groupdel admin > /dev/null 2>&1
  1338. fi
  1339. # Enable sftp jail
  1340. $HESTIA/bin/v-add-sys-sftp-jail > /dev/null 2>&1
  1341. check_result $? "can't enable sftp jail"
  1342. # Adding Hestia admin account
  1343. $HESTIA/bin/v-add-user admin $vpass $email default System Administrator
  1344. check_result $? "can't create admin user"
  1345. $HESTIA/bin/v-change-user-shell admin nologin
  1346. $HESTIA/bin/v-change-user-language admin $lang
  1347. chown admin:admin $HESTIA/data/sessions
  1348. chown admin:admin $HESTIA/php/var/log
  1349. chown admin:admin $HESTIA/php/var/run
  1350. # Roundcube permissions fix
  1351. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1352. if [ ! -d "/var/log/roundcube" ]; then
  1353. mkdir /var/log/roundcube
  1354. fi
  1355. chown admin:admin /var/log/roundcube
  1356. fi
  1357. # Configuring system IPs
  1358. $HESTIA/bin/v-update-sys-ip > /dev/null 2>&1
  1359. # Get main IP
  1360. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1361. # Configuring firewall
  1362. if [ "$iptables" = 'yes' ]; then
  1363. $HESTIA/bin/v-update-firewall
  1364. fi
  1365. # Get public IP
  1366. pub_ip=$(curl --ipv4 -s https://ip.hestiacp.com/)
  1367. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1368. $HESTIA/bin/v-change-sys-ip-nat $ip $pub_ip > /dev/null 2>&1
  1369. ip=$pub_ip
  1370. fi
  1371. # Configuring libapache2-mod-remoteip
  1372. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  1373. cd /etc/httpd/conf.modules.d
  1374. echo "<IfModule mod_remoteip.c>" > remoteip.conf
  1375. echo " RemoteIPHeader X-Real-IP" >> remoteip.conf
  1376. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ip" != "127.0.0.1" ]; then
  1377. echo " RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  1378. fi
  1379. if [ ! -z "$local_ip" ] && [ "$local_ip" != "$pub_ip" ]; then
  1380. echo " RemoteIPInternalProxy $local_ip" >> remoteip.conf
  1381. fi
  1382. if [ ! -z "$pub_ip" ]; then
  1383. echo " RemoteIPInternalProxy $pub_ip" >> remoteip.conf
  1384. fi
  1385. echo "</IfModule>" >> remoteip.conf
  1386. #sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  1387. #a2enmod remoteip >> $LOG
  1388. systemctl restart httpd
  1389. fi
  1390. # Configuring MySQL/MariaDB host
  1391. if [ "$mysql" = 'yes' ]; then
  1392. $HESTIA/bin/v-add-database-host mysql localhost root $mpass
  1393. fi
  1394. # Configuring PostgreSQL host
  1395. if [ "$postgresql" = 'yes' ]; then
  1396. $HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
  1397. fi
  1398. # Adding default domain
  1399. $HESTIA/bin/v-add-web-domain admin $servername
  1400. check_result $? "can't create $servername domain"
  1401. # Adding cron jobs
  1402. export SCHEDULED_RESTART="yes"
  1403. command="sudo $HESTIA/bin/v-update-sys-queue restart"
  1404. $HESTIA/bin/v-add-cron-job 'admin' '*/2' '*' '*' '*' '*' "$command"
  1405. systemctl restart crond
  1406. command="sudo $HESTIA/bin/v-update-sys-queue daily"
  1407. $HESTIA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1408. command="sudo $HESTIA/bin/v-update-sys-queue disk"
  1409. $HESTIA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1410. command="sudo $HESTIA/bin/v-update-sys-queue traffic"
  1411. $HESTIA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1412. command="sudo $HESTIA/bin/v-update-sys-queue webstats"
  1413. $HESTIA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1414. command="sudo $HESTIA/bin/v-update-sys-queue backup"
  1415. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1416. command="sudo $HESTIA/bin/v-backup-users"
  1417. $HESTIA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1418. command="sudo $HESTIA/bin/v-update-user-stats"
  1419. $HESTIA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1420. command="sudo $HESTIA/bin/v-update-sys-rrd"
  1421. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1422. # Enable automatic updates
  1423. $HESTIA/bin/v-add-cron-hestia-autoupdate
  1424. # Building initital rrd images
  1425. $HESTIA/bin/v-update-sys-rrd
  1426. # Enabling file system quota
  1427. if [ "$quota" = 'yes' ]; then
  1428. $HESTIA/bin/v-add-sys-quota
  1429. fi
  1430. # Set backend port
  1431. $HESTIA/bin/v-change-sys-port $port
  1432. # Set default theme
  1433. $HESTIA/bin/v-change-sys-theme 'default'
  1434. # Starting Hestia service
  1435. systemctl enable hestia
  1436. systemctl start hestia
  1437. check_result $? "hestia start failed"
  1438. #----------------------------------------------------------#
  1439. # Configure FileManager #
  1440. #----------------------------------------------------------#
  1441. echo "(*) Configuring Filegator FileManager..."
  1442. source $HESTIA_INSTALL_DIR/filemanager/install-fm.sh > /dev/null 2>&1
  1443. #----------------------------------------------------------#
  1444. # Hestia Access Info #
  1445. #----------------------------------------------------------#
  1446. # Comparing hostname and IP
  1447. host_ip=$(host $servername| head -n 1 |awk '{print $NF}')
  1448. if [ "$host_ip" = "$ip" ]; then
  1449. ip="$servername"
  1450. fi
  1451. echo -e "\n"
  1452. echo "===================================================================="
  1453. echo -e "\n"
  1454. # Sending notification to admin email
  1455. echo -e "Congratulations!
  1456. You have successfully installed Hestia Control Panel on your server.
  1457. Ready to get started? Log in using the following credentials:
  1458. Admin URL: https://$ip:$port
  1459. Username: admin
  1460. Password: $vpass
  1461. Thank you for choosing Hestia Control Panel to power your full stack web server,
  1462. we hope that you enjoy using it as much as we do!
  1463. Please feel free to contact us at any time if you have any questions,
  1464. or if you encounter any bugs or problems:
  1465. E-mail: info@hestiacp.com
  1466. Web: https://www.hestiacp.com/
  1467. Forum: https://forum.hestiacp.com/
  1468. GitHub: https://www.github.com/hestiacp/hestiacp
  1469. Note: Automatic updates are enabled by default. If you would like to disable them,
  1470. please log in and navigate to Server > Updates to turn them off.
  1471. Help support the Hestia Contol Panel project by donating via PayPal:
  1472. https://www.hestiacp.com/donate
  1473. --
  1474. Sincerely yours,
  1475. The Hestia Control Panel development team
  1476. Made with love & pride by the open-source community around the world.
  1477. " > $tmpfile
  1478. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  1479. cat $tmpfile | $send_mail -s "Hestia Control Panel" $email
  1480. # Congrats
  1481. echo
  1482. cat $tmpfile
  1483. rm -f $tmpfile
  1484. # Add welcome message to notification panel
  1485. $HESTIA/bin/v-add-user-notification admin 'Welcome!' 'For more information on how to use Hestia Control Panel, click on the Help icon in the top right corner of the toolbar.<br><br>Please report any bugs or issues on GitHub at<br>https://github.com/hestiacp/hestiacp/issues<br><br>Have a great day!'
  1486. echo "(!) IMPORTANT: You must logout or restart the server before continuing."
  1487. echo ""
  1488. if [ "$interactive" = 'yes' ]; then
  1489. echo -n " Do you want to reboot now? [Y/N] "
  1490. read reboot
  1491. if [ "$reboot" = "Y" ] || [ "$reboot" = "y" ]; then
  1492. reboot
  1493. fi
  1494. fi
  1495. # EOF