hst-install-debian.sh 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  1. #!/bin/bash
  2. # ======================================================== #
  3. #
  4. # Hestia Control Panel Installer for Debian
  5. # https://www.hestiacp.com/
  6. #
  7. # Currently Supported Versions:
  8. # Debian 11 12
  9. #
  10. # ======================================================== #
  11. #----------------------------------------------------------#
  12. # Variables&Functions #
  13. #----------------------------------------------------------#
  14. export PATH=$PATH:/sbin
  15. export DEBIAN_FRONTEND=noninteractive
  16. RHOST='apt.hestiacp.com'
  17. VERSION='debian'
  18. HESTIA='/usr/local/hestia'
  19. LOG="/root/hst_install_backups/hst_install-$(date +%d%m%Y%H%M).log"
  20. memory=$(grep 'MemTotal' /proc/meminfo | tr ' ' '\n' | grep [0-9])
  21. hst_backups="/root/hst_install_backups/$(date +%d%m%Y%H%M)"
  22. spinner="/-\|"
  23. os='debian'
  24. release="$(cat /etc/debian_version | tr "." "\n" | head -n1)"
  25. codename="$(cat /etc/os-release | grep VERSION= | cut -f 2 -d \( | cut -f 1 -d \))"
  26. architecture="$(arch)"
  27. HESTIA_INSTALL_DIR="$HESTIA/install/deb"
  28. HESTIA_COMMON_DIR="$HESTIA/install/common"
  29. VERBOSE='no'
  30. # Define software versions
  31. HESTIA_INSTALL_VER='1.10.0~alpha'
  32. # Supported PHP versions
  33. multiphp_v=("5.6" "7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3" "8.4" "8.5")
  34. # One of the following PHP versions is required for Roundcube / phpmyadmin
  35. multiphp_required=("7.3" "7.4" "8.0" "8.1" "8.2" "8.3")
  36. # Default PHP version if none supplied
  37. fpm_v="8.3"
  38. # MariaDB version
  39. mariadb_v="11.4"
  40. # Node.js version
  41. node_v="20"
  42. # Defining software pack for all distros
  43. software="acl apache2 apache2-suexec-custom apache2-utils at awstats bc bind9 bsdmainutils bsdutils
  44. clamav-daemon cron curl dnsutils dovecot-imapd dovecot-managesieved dovecot-pop3d dovecot-sieve e2fslibs e2fsprogs
  45. exim4 exim4-daemon-heavy expect fail2ban flex ftp git hestia=${HESTIA_INSTALL_VER} hestia-nginx hestia-php hestia-web-terminal
  46. idn2 imagemagick ipset jq libapache2-mod-fcgid libapache2-mod-php$fpm_v libapache2-mpm-itk libmail-dkim-perl lsb-release
  47. lsof mariadb-client mariadb-common mariadb-server mc mysql-client mysql-common mysql-server net-tools nginx nodejs openssh-server
  48. php$fpm_v php$fpm_v-apcu php$fpm_v-bz2 php$fpm_v-cgi php$fpm_v-cli php$fpm_v-common php$fpm_v-curl php$fpm_v-gd
  49. php$fpm_v-imagick php$fpm_v-imap php$fpm_v-intl php$fpm_v-ldap php$fpm_v-mbstring php$fpm_v-mysql php$fpm_v-opcache
  50. php$fpm_v-pgsql php$fpm_v-pspell php$fpm_v-readline php$fpm_v-xml php$fpm_v-zip postgresql postgresql-contrib
  51. proftpd-basic quota rrdtool rsyslog spamd sysstat unrar-free unzip util-linux vim-common vsftpd xxd whois zip zstd bubblewrap restic"
  52. installer_dependencies="apt-transport-https ca-certificates curl dirmngr gnupg openssl wget sudo"
  53. # Defining help function
  54. help() {
  55. echo "Usage: $0 [OPTIONS]
  56. -a, --apache Install Apache [yes|no] default: yes
  57. -w, --phpfpm Install PHP-FPM [yes|no] default: yes
  58. -o, --multiphp Install MultiPHP [yes|no] default: no
  59. -v, --vsftpd Install VSFTPD [yes|no] default: yes
  60. -j, --proftpd Install ProFTPD [yes|no] default: no
  61. -k, --named Install BIND [yes|no] default: yes
  62. -m, --mysql Install MariaDB [yes|no] default: yes
  63. -M, --mysql8 Install MySQL 8 [yes|no] default: no
  64. -g, --postgresql Install PostgreSQL [yes|no] default: no
  65. -x, --exim Install Exim [yes|no] default: yes
  66. -z, --dovecot Install Dovecot [yes|no] default: yes
  67. -Z, --sieve Install Sieve [yes|no] default: no
  68. -c, --clamav Install ClamAV [yes|no] default: yes
  69. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  70. -i, --iptables Install iptables [yes|no] default: yes
  71. -b, --fail2ban Install Fail2Ban [yes|no] default: yes
  72. -q, --quota Filesystem Quota [yes|no] default: no
  73. -L, --resourcelimit Resource Limitation [yes|no] default: no
  74. -W, --webterminal Web Terminal [yes|no] default: no
  75. -d, --api Activate API [yes|no] default: yes
  76. -r, --port Change Backend Port default: 8083
  77. -l, --lang Default language default: en
  78. -y, --interactive Interactive install [yes|no] default: yes
  79. -s, --hostname Set hostname
  80. -e, --email Set admin email
  81. -u, --username Set admin user
  82. -p, --password Set admin password
  83. -D, --with-debs Path to Hestia debs
  84. -f, --force Force installation
  85. -h, --help Print this help
  86. Example: bash $0 -e demo@hestiacp.com -p p4ssw0rd --multiphp yes"
  87. exit 1
  88. }
  89. # Defining file download function
  90. download_file() {
  91. wget $1 -q --show-progress --progress=bar:force
  92. }
  93. # Defining password-gen function
  94. gen_pass() {
  95. matrix=$1
  96. length=$2
  97. if [ -z "$matrix" ]; then
  98. matrix="A-Za-z0-9"
  99. fi
  100. if [ -z "$length" ]; then
  101. length=16
  102. fi
  103. head /dev/urandom | tr -dc $matrix | head -c$length
  104. }
  105. # Defining return code check function
  106. check_result() {
  107. if [ $1 -ne 0 ]; then
  108. echo "Error: $2"
  109. exit $1
  110. fi
  111. }
  112. # Source conf in installer
  113. source_conf() {
  114. while IFS='= ' read -r lhs rhs; do
  115. if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
  116. rhs="${rhs%%^\#*}" # Del in line right comments
  117. rhs="${rhs%%*( )}" # Del trailing spaces
  118. rhs="${rhs%\'*}" # Del opening string quotes
  119. rhs="${rhs#\'*}" # Del closing string quotes
  120. declare -g $lhs="$rhs"
  121. fi
  122. done < $1
  123. }
  124. # Defining function to set default value
  125. set_default_value() {
  126. eval variable=\$$1
  127. if [ -z "$variable" ]; then
  128. eval $1=$2
  129. fi
  130. if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  131. eval $1=$2
  132. fi
  133. }
  134. # Defining function to set default language value
  135. set_default_lang() {
  136. if [ -z "$lang" ]; then
  137. eval lang=$1
  138. fi
  139. lang_list="ar az bg bn bs ca cs da de el en es fa fi fr hr hu id it ja ka ku ko nl no pl pt pt-br ro ru sk sq sr sv th tr uk ur vi zh-cn zh-tw"
  140. if ! (echo $lang_list | grep -w $lang > /dev/null 2>&1); then
  141. eval lang=$1
  142. fi
  143. }
  144. # Define the default backend port
  145. set_default_port() {
  146. if [ -z "$port" ]; then
  147. eval port=$1
  148. fi
  149. }
  150. # Write configuration KEY/VALUE pair to $HESTIA/conf/hestia.conf
  151. write_config_value() {
  152. local key="$1"
  153. local value="$2"
  154. echo "$key='$value'" >> $HESTIA/conf/hestia.conf
  155. }
  156. # Sort configuration file values
  157. # Write final copy to $HESTIA/conf/hestia.conf for active usage
  158. # Duplicate file to $HESTIA/conf/defaults/hestia.conf to restore known good installation values
  159. sort_config_file() {
  160. sort $HESTIA/conf/hestia.conf -o /tmp/updconf
  161. mv $HESTIA/conf/hestia.conf $HESTIA/conf/hestia.conf.bak
  162. mv /tmp/updconf $HESTIA/conf/hestia.conf
  163. rm -f $HESTIA/conf/hestia.conf.bak
  164. if [ ! -d "$HESTIA/conf/defaults/" ]; then
  165. mkdir -p "$HESTIA/conf/defaults/"
  166. fi
  167. cp $HESTIA/conf/hestia.conf $HESTIA/conf/defaults/hestia.conf
  168. }
  169. # todo add check for usernames that are blocked
  170. validate_username() {
  171. if [[ "$username" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
  172. if [ -n "$(grep ^$username: /etc/passwd /etc/group)" ]; then
  173. echo -e "\nUsername or Group allready exists please select a new user name or delete the user and / or group."
  174. else
  175. return 1
  176. fi
  177. else
  178. echo -e "\nPlease use a valid username (ex. user)."
  179. return 0
  180. fi
  181. }
  182. validate_password() {
  183. if [ -z "$vpass" ]; then
  184. return 0
  185. else
  186. return 1
  187. fi
  188. }
  189. # Validate hostname according to RFC1178
  190. validate_hostname() {
  191. # remove extra .
  192. servername=$(echo "$servername" | sed -e "s/[.]*$//g")
  193. servername=$(echo "$servername" | sed -e "s/^[.]*//")
  194. if [[ $(echo "$servername" | grep -o "\." | wc -l) -gt 1 ]] && [[ ! $servername =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  195. # Hostname valid
  196. return 1
  197. else
  198. # Hostname invalid
  199. return 0
  200. fi
  201. }
  202. validate_email() {
  203. if [[ ! "$email" =~ ^[A-Za-z0-9._%+-]+@[[:alnum:].-]+\.[A-Za-z]{2,63}$ ]]; then
  204. # Email invalid
  205. return 0
  206. else
  207. # Email valid
  208. return 1
  209. fi
  210. }
  211. version_ge() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o -n "$1" -a "$1" = "$2"; }
  212. #----------------------------------------------------------#
  213. # Verifications #
  214. #----------------------------------------------------------#
  215. # Creating temporary file
  216. tmpfile=$(mktemp -p /tmp)
  217. # Translating argument to --gnu-long-options
  218. for arg; do
  219. delim=""
  220. case "$arg" in
  221. --apache) args="${args}-a " ;;
  222. --phpfpm) args="${args}-w " ;;
  223. --vsftpd) args="${args}-v " ;;
  224. --proftpd) args="${args}-j " ;;
  225. --named) args="${args}-k " ;;
  226. --mysql) args="${args}-m " ;;
  227. --mariadb) args="${args}-m " ;;
  228. --mysql-classic) args="${args}-M " ;;
  229. --mysql8) args="${args}-M " ;;
  230. --postgresql) args="${args}-g " ;;
  231. --exim) args="${args}-x " ;;
  232. --dovecot) args="${args}-z " ;;
  233. --sieve) args="${args}-Z " ;;
  234. --clamav) args="${args}-c " ;;
  235. --spamassassin) args="${args}-t " ;;
  236. --iptables) args="${args}-i " ;;
  237. --fail2ban) args="${args}-b " ;;
  238. --multiphp) args="${args}-o " ;;
  239. --quota) args="${args}-q " ;;
  240. --resourcelimit) args="${args}-L " ;;
  241. --webterminal) args="${args}-W " ;;
  242. --port) args="${args}-r " ;;
  243. --lang) args="${args}-l " ;;
  244. --interactive) args="${args}-y " ;;
  245. --api) args="${args}-d " ;;
  246. --hostname) args="${args}-s " ;;
  247. --email) args="${args}-e " ;;
  248. --username) args="${args}-u " ;;
  249. --password) args="${args}-p " ;;
  250. --force) args="${args}-f " ;;
  251. --with-debs) args="${args}-D " ;;
  252. --help) args="${args}-h " ;;
  253. *)
  254. [[ "${arg:0:1}" == "-" ]] || delim="\""
  255. args="${args}${delim}${arg}${delim} "
  256. ;;
  257. esac
  258. done
  259. eval set -- "$args"
  260. # Parsing arguments
  261. while getopts "a:w:v:j:k:m:M:g:d:x:z:Z:c:t:i:b:r:o:q:L:l:y:s:u:e:p:W:D:fh" Option; do
  262. case $Option in
  263. a) apache=$OPTARG ;; # Apache
  264. w) phpfpm=$OPTARG ;; # PHP-FPM
  265. o) multiphp=$OPTARG ;; # Multi-PHP
  266. v) vsftpd=$OPTARG ;; # Vsftpd
  267. j) proftpd=$OPTARG ;; # Proftpd
  268. k) named=$OPTARG ;; # Named
  269. m) mysql=$OPTARG ;; # MariaDB
  270. M) mysql8=$OPTARG ;; # MySQL
  271. g) postgresql=$OPTARG ;; # PostgreSQL
  272. x) exim=$OPTARG ;; # Exim
  273. z) dovecot=$OPTARG ;; # Dovecot
  274. Z) sieve=$OPTARG ;; # Sieve
  275. c) clamd=$OPTARG ;; # ClamAV
  276. t) spamd=$OPTARG ;; # SpamAssassin
  277. i) iptables=$OPTARG ;; # Iptables
  278. b) fail2ban=$OPTARG ;; # Fail2ban
  279. q) quota=$OPTARG ;; # FS Quota
  280. L) resourcelimit=$OPTARG ;; # Resource Limitaiton
  281. W) webterminal=$OPTARG ;; # Web Terminal
  282. r) port=$OPTARG ;; # Backend Port
  283. l) lang=$OPTARG ;; # Language
  284. d) api=$OPTARG ;; # Activate API
  285. y) interactive=$OPTARG ;; # Interactive install
  286. s) servername=$OPTARG ;; # Hostname
  287. e) email=$OPTARG ;; # Admin email
  288. u) username=$OPTARG ;; # Admin username
  289. p) vpass=$OPTARG ;; # Admin password
  290. D) withdebs=$OPTARG ;; # Hestia debs path
  291. f) force='yes' ;; # Force install
  292. h) help ;; # Help
  293. *) help ;; # Print help (default)
  294. esac
  295. done
  296. if [ -n "$multiphp" ]; then
  297. if [ "$multiphp" != 'no' ] && [ "$multiphp" != 'yes' ]; then
  298. php_versions=$(echo $multiphp | tr ',' "\n")
  299. multiphp_version=()
  300. for php_version in "${php_versions[@]}"; do
  301. if [[ $(echo "${multiphp_v[@]}" | fgrep -w "$php_version") ]]; then
  302. multiphp_version=(${multiphp_version[@]} "$php_version")
  303. else
  304. echo "$php_version is not supported"
  305. exit 1
  306. fi
  307. done
  308. multiphp_v=()
  309. for version in "${multiphp_version[@]}"; do
  310. multiphp_v=(${multiphp_v[@]} $version)
  311. done
  312. fpm_old=$fpm_v
  313. multiphp="yes"
  314. fpm_v=$(printf "%s\n" "${multiphp_version[@]}" | sort -V | tail -n1)
  315. fpm_last=$(printf "%s\n" "${multiphp_required[@]}" | sort -V | tail -n1)
  316. # Allow Maintainer to set minimum fpm version to make sure phpmyadmin and roundcube keep working
  317. if [[ -z $(echo "${multiphp_required[@]}" | fgrep -w $fpm_v) ]]; then
  318. if version_ge $fpm_v $fpm_last; then
  319. multiphp_version=(${multiphp_version[@]} $fpm_last)
  320. fpm_v=$fpm_last
  321. else
  322. # Roundcube and PHPmyadmin doesn't support the version selected.
  323. echo "Selected PHP versions are not supported any more by Dependencies..."
  324. exit 1
  325. fi
  326. fi
  327. software=$(echo "$software" | sed -e "s/php$fpm_old/php$fpm_v/g")
  328. fi
  329. fi
  330. # Defining default software stack
  331. set_default_value 'nginx' 'yes'
  332. set_default_value 'apache' 'yes'
  333. set_default_value 'phpfpm' 'yes'
  334. set_default_value 'multiphp' 'no'
  335. set_default_value 'vsftpd' 'yes'
  336. set_default_value 'proftpd' 'no'
  337. set_default_value 'named' 'yes'
  338. set_default_value 'mysql' 'yes'
  339. set_default_value 'mysql8' 'no'
  340. set_default_value 'postgresql' 'no'
  341. set_default_value 'exim' 'yes'
  342. set_default_value 'dovecot' 'yes'
  343. set_default_value 'sieve' 'no'
  344. if [ $memory -lt 1500000 ]; then
  345. set_default_value 'clamd' 'no'
  346. set_default_value 'spamd' 'no'
  347. elif [ $memory -lt 3000000 ]; then
  348. set_default_value 'clamd' 'no'
  349. set_default_value 'spamd' 'yes'
  350. else
  351. set_default_value 'clamd' 'yes'
  352. set_default_value 'spamd' 'yes'
  353. fi
  354. set_default_value 'iptables' 'yes'
  355. set_default_value 'fail2ban' 'yes'
  356. set_default_value 'quota' 'no'
  357. set_default_value 'resourcelimit' 'no'
  358. set_default_value 'webterminal' 'no'
  359. set_default_value 'interactive' 'yes'
  360. set_default_value 'api' 'yes'
  361. set_default_port '8083'
  362. set_default_lang 'en'
  363. # Checking software conflicts
  364. if [ "$proftpd" = 'yes' ]; then
  365. vsftpd='no'
  366. fi
  367. if [ "$exim" = 'no' ]; then
  368. clamd='no'
  369. spamd='no'
  370. dovecot='no'
  371. fi
  372. if [ "$dovecot" = 'no' ]; then
  373. sieve='no'
  374. fi
  375. if [ "$iptables" = 'no' ]; then
  376. fail2ban='no'
  377. fi
  378. if [ "$apache" = 'no' ]; then
  379. phpfpm='yes'
  380. fi
  381. if [ "$mysql" = 'yes' ] && [ "$mysql8" = 'yes' ]; then
  382. mysql='no'
  383. fi
  384. if [ "$mysql8" = 'yes' ] && [ "$architecture" = 'aarch64' ]; then
  385. check_result 1 "Mysql 8 does not support ARM64 yet for Debian please use Ubuntu. Unable to continue"
  386. fi
  387. # Checking root permissions
  388. if [ "x$(id -u)" != 'x0' ]; then
  389. check_result 1 "Script can be run executed only by root"
  390. fi
  391. if [ -d "/usr/local/hestia" ]; then
  392. check_result 1 "Hestia install detected. Unable to continue"
  393. fi
  394. type=$(grep "^ID=" /etc/os-release | cut -f 2 -d '=')
  395. if [ "$type" = "ubuntu" ]; then
  396. check_result 1 "You are running the wrong installer for Ubuntu. Please run hst-install.sh or hst-install-ubuntu.sh instead."
  397. elif [ "$type" != "debian" ]; then
  398. check_result 1 "You are running an unsupported OS."
  399. fi
  400. # Clear the screen once launch permissions have been verified
  401. clear
  402. # Configure apt to retry downloading on error
  403. if [ ! -f /etc/apt/apt.conf.d/80-retries ]; then
  404. echo "APT::Acquire::Retries \"3\";" > /etc/apt/apt.conf.d/80-retries
  405. fi
  406. # Welcome message
  407. echo "Welcome to the Hestia Control Panel installer!"
  408. echo
  409. echo "Please wait, the installer is now checking for missing dependencies..."
  410. echo
  411. # Update apt repository
  412. apt-get -qq update
  413. # Creating backup directory
  414. mkdir -p "$hst_backups"
  415. # Pre-install packages
  416. echo "[ * ] Installing dependencies..."
  417. apt-get -y install $installer_dependencies >> $LOG
  418. check_result $? "Package installation failed, check log file for more details."
  419. # Check if apparmor is installed
  420. if [ $(dpkg-query -W -f='${Status}' apparmor 2> /dev/null | grep -c "ok installed") -eq 0 ]; then
  421. apparmor='no'
  422. else
  423. apparmor='yes'
  424. fi
  425. # Check repository availability
  426. wget --quiet "https://$RHOST" -O /dev/null
  427. check_result $? "Unable to connect to the Hestia APT repository"
  428. # Check installed packages
  429. tmpfile=$(mktemp -p /tmp)
  430. dpkg --get-selections > $tmpfile
  431. conflicts_pkg="exim4 mariadb-server apache2 nginx hestia postfix"
  432. # Drop postfix from the list if exim should not be installed
  433. if [ "$exim" = 'no' ]; then
  434. conflicts_pkg=$(echo $conflicts_pkg | sed 's/postfix//g' | xargs)
  435. fi
  436. for pkg in $conflicts_pkg; do
  437. if [ -n "$(grep $pkg $tmpfile)" ]; then
  438. conflicts="$pkg* $conflicts"
  439. fi
  440. done
  441. rm -f $tmpfile
  442. if [ -n "$conflicts" ] && [ -z "$force" ]; then
  443. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  444. echo
  445. echo 'WARNING: The following packages are already installed'
  446. echo "$conflicts"
  447. echo
  448. echo 'It is highly recommended that you remove them before proceeding.'
  449. echo
  450. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  451. echo
  452. read -p 'Would you like to remove the conflicting packages? [y/N] ' answer
  453. if [ "$answer" = 'y' ] || [ "$answer" = 'Y' ]; then
  454. apt-get -qq purge $conflicts -y
  455. check_result $? 'apt-get remove failed'
  456. unset $answer
  457. else
  458. check_result 1 "Hestia Control Panel should be installed on a clean server."
  459. fi
  460. fi
  461. # Check network configuration
  462. if [ -d /etc/netplan ] && [ -z "$force" ]; then
  463. if [ -z "$(ls -A /etc/netplan)" ]; then
  464. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  465. echo
  466. echo 'WARNING: Your network configuration may not be set up correctly.'
  467. echo 'Details: The netplan configuration directory is empty.'
  468. echo ''
  469. echo 'You may have a network configuration file that was created using'
  470. echo 'systemd-networkd.'
  471. echo ''
  472. echo 'It is strongly recommended to migrate to netplan, which is now the'
  473. echo 'default network configuration system in newer releases of Ubuntu.'
  474. echo ''
  475. echo 'While you can leave your configuration as-is, please note that you'
  476. echo 'will not be able to use additional IPs properly.'
  477. echo ''
  478. echo 'If you wish to continue and force the installation,'
  479. echo 'run this script with -f option:'
  480. echo "Example: bash $0 --force"
  481. echo
  482. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  483. echo
  484. check_result 1 "Unable to detect netplan configuration."
  485. fi
  486. fi
  487. # Validate whether installation script matches release version before continuing with install
  488. if [ -z "$withdebs" ] || [ ! -d "$withdebs" ]; then
  489. release_branch_ver=$(curl -s https://raw.githubusercontent.com/hestiacp/hestiacp/release/src/deb/hestia/control | grep "Version:" | awk '{print $2}')
  490. if [ "$HESTIA_INSTALL_VER" != "$release_branch_ver" ]; then
  491. echo
  492. echo -e "\e[91mInstallation aborted\e[0m"
  493. echo "===================================================================="
  494. echo -e "\e[33mERROR: Install script version does not match package version!\e[0m"
  495. echo -e "\e[33mPlease download the installer from the release branch in order to continue:\e[0m"
  496. echo ""
  497. echo -e "\e[33mhttps://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install.sh\e[0m"
  498. echo ""
  499. echo -e "\e[33mTo test pre-release versions, build the .deb packages and re-run the installer:\e[0m"
  500. echo -e " \e[33m./hst_autocompile.sh \e[1m--hestia branchname no\e[21m\e[0m"
  501. echo -e " \e[33m./hst-install.sh .. \e[1m--with-debs /tmp/hestiacp-src/debs\e[21m\e[0m"
  502. echo ""
  503. check_result 1 "Installation aborted"
  504. fi
  505. fi
  506. case $architecture in
  507. x86_64)
  508. ARCH="amd64"
  509. ;;
  510. aarch64)
  511. ARCH="arm64"
  512. ;;
  513. *)
  514. echo
  515. echo -e "\e[91mInstallation aborted\e[0m"
  516. echo "===================================================================="
  517. echo -e "\e[33mERROR: $architecture is currently not supported!\e[0m"
  518. echo -e "\e[33mPlease verify the achitecture used is currenlty supported\e[0m"
  519. echo ""
  520. echo -e "\e[33mhttps://github.com/hestiacp/hestiacp/blob/main/README.md\e[0m"
  521. echo ""
  522. check_result 1 "Installation aborted"
  523. ;;
  524. esac
  525. #----------------------------------------------------------#
  526. # Brief Info #
  527. #----------------------------------------------------------#
  528. install_welcome_message() {
  529. DISPLAY_VER=$(echo $HESTIA_INSTALL_VER | sed "s|~alpha||g" | sed "s|~beta||g")
  530. echo
  531. echo ' _ _ _ _ ____ ____ '
  532. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  533. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
  534. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  535. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  536. echo " "
  537. echo " Hestia Control Panel "
  538. if [[ "$HESTIA_INSTALL_VER" =~ "beta" ]]; then
  539. echo " BETA RELEASE "
  540. fi
  541. if [[ "$HESTIA_INSTALL_VER" =~ "alpha" ]]; then
  542. echo " DEVELOPMENT SNAPSHOT "
  543. echo " NOT INTENDED FOR PRODUCTION USE "
  544. echo " USE AT YOUR OWN RISK "
  545. fi
  546. echo " ${DISPLAY_VER} "
  547. echo " www.hestiacp.com "
  548. echo
  549. echo "========================================================================"
  550. echo
  551. echo "Thank you for downloading Hestia Control Panel! In a few moments,"
  552. echo "we will begin installing the following components on your server:"
  553. echo
  554. }
  555. # Printing nice ASCII logo
  556. clear
  557. install_welcome_message
  558. # Web stack
  559. echo ' - NGINX Web / Proxy Server'
  560. if [ "$apache" = 'yes' ]; then
  561. echo ' - Apache Web Server (as backend)'
  562. fi
  563. if [ "$phpfpm" = 'yes' ] && [ "$multiphp" = 'no' ]; then
  564. echo ' - PHP-FPM Application Server'
  565. fi
  566. if [ "$multiphp" = 'yes' ]; then
  567. phpfpm='yes'
  568. echo -n ' - Multi-PHP Environment: Version'
  569. for version in "${multiphp_v[@]}"; do
  570. echo -n " php$version"
  571. done
  572. echo ''
  573. fi
  574. # DNS stack
  575. if [ "$named" = 'yes' ]; then
  576. echo ' - Bind DNS Server'
  577. fi
  578. # Mail stack
  579. if [ "$exim" = 'yes' ]; then
  580. echo -n ' - Exim Mail Server'
  581. if [ "$clamd" = 'yes' ] || [ "$spamd" = 'yes' ]; then
  582. echo -n ' + '
  583. if [ "$clamd" = 'yes' ]; then
  584. echo -n 'ClamAV '
  585. fi
  586. if [ "$spamd" = 'yes' ]; then
  587. if [ "$clamd" = 'yes' ]; then
  588. echo -n '+ '
  589. fi
  590. echo -n 'SpamAssassin'
  591. fi
  592. fi
  593. echo
  594. if [ "$dovecot" = 'yes' ]; then
  595. echo -n ' - Dovecot POP3/IMAP Server'
  596. if [ "$sieve" = 'yes' ]; then
  597. echo -n '+ Sieve'
  598. fi
  599. fi
  600. fi
  601. echo
  602. # Database stack
  603. if [ "$mysql" = 'yes' ]; then
  604. echo ' - MariaDB Database Server'
  605. fi
  606. if [ "$mysql8" = 'yes' ]; then
  607. echo ' - MySQL8 Database Server'
  608. fi
  609. if [ "$postgresql" = 'yes' ]; then
  610. echo ' - PostgreSQL Database Server'
  611. fi
  612. # FTP stack
  613. if [ "$vsftpd" = 'yes' ]; then
  614. echo ' - Vsftpd FTP Server'
  615. fi
  616. if [ "$proftpd" = 'yes' ]; then
  617. echo ' - ProFTPD FTP Server'
  618. fi
  619. if [ "$webterminal" = 'yes' ]; then
  620. echo ' - Web terminal'
  621. fi
  622. # Firewall stack
  623. if [ "$iptables" = 'yes' ]; then
  624. echo -n ' - Firewall (iptables)'
  625. fi
  626. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  627. echo -n ' + Fail2Ban Access Monitor'
  628. fi
  629. echo -e "\n"
  630. echo "========================================================================"
  631. echo -e "\n"
  632. # Asking for confirmation to proceed
  633. if [ "$interactive" = 'yes' ]; then
  634. read -p 'Would you like to continue with the installation? [y/N]: ' answer
  635. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  636. echo 'Goodbye'
  637. exit 1
  638. fi
  639. fi
  640. # Validate Username / Password / Email / Hostname even when interactive = no
  641. if [ -z "$username" ]; then
  642. while validate_username; do
  643. read -p 'Please enter administrator username: ' username
  644. done
  645. else
  646. if validate_username; then
  647. exit 1
  648. fi
  649. fi
  650. # Ask for password
  651. if [ -z "$vpass" ]; then
  652. while validate_password; do
  653. read -p 'Please enter administrator password: ' vpass
  654. done
  655. else
  656. if validate_password; then
  657. echo "Please use a valid password"
  658. exit 1
  659. fi
  660. fi
  661. # Validate Email / Hostname even when interactive = no
  662. # Asking for contact email
  663. if [ -z "$email" ]; then
  664. while validate_email; do
  665. echo -e "\nPlease use a valid emailadress (ex. info@domain.tld)."
  666. read -p 'Please enter admin email address: ' email
  667. done
  668. else
  669. if validate_email; then
  670. echo "Please use a valid emailadress (ex. info@domain.tld)."
  671. exit 1
  672. fi
  673. fi
  674. # Asking to set FQDN hostname
  675. if [ -z "$servername" ]; then
  676. # Ask and validate FQDN hostname.
  677. read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
  678. # Set hostname if it wasn't set
  679. if [ -z "$servername" ]; then
  680. servername=$(hostname -f)
  681. fi
  682. # Validate Hostname, go to loop if the validation fails.
  683. while validate_hostname; do
  684. echo -e "\nPlease use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
  685. read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
  686. done
  687. else
  688. # Validate FQDN hostname if it is preset
  689. if validate_hostname; then
  690. echo "Please use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
  691. exit 1
  692. fi
  693. fi
  694. # Generating admin password if it wasn't set
  695. displaypass="The password you chose during installation."
  696. if [ -z "$vpass" ]; then
  697. vpass=$(gen_pass)
  698. displaypass=$vpass
  699. fi
  700. # Set FQDN if it wasn't set
  701. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  702. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  703. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  704. if [[ -n "$servername" ]]; then
  705. servername="$servername.example.com"
  706. else
  707. servername="example.com"
  708. fi
  709. echo "127.0.0.1 $servername" >> /etc/hosts
  710. fi
  711. if [[ -z $(grep -i "$servername" /etc/hosts) ]]; then
  712. echo "127.0.0.1 $servername" >> /etc/hosts
  713. fi
  714. # Set email if it wasn't set
  715. if [[ -z "$email" ]]; then
  716. email="admin@$servername"
  717. fi
  718. # Defining backup directory
  719. echo -e "Installation backup directory: $hst_backups"
  720. # Print Log File Path
  721. echo "Installation log file: $LOG"
  722. # Print new line
  723. echo
  724. #----------------------------------------------------------#
  725. # Checking swap #
  726. #----------------------------------------------------------#
  727. # Add swap for low memory servers
  728. if [ -z "$(swapon -s)" ] && [ "$memory" -lt 1000000 ]; then
  729. fallocate -l 1G /swapfile
  730. chmod 600 /swapfile
  731. mkswap /swapfile
  732. swapon /swapfile
  733. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  734. fi
  735. #----------------------------------------------------------#
  736. # Install repository #
  737. #----------------------------------------------------------#
  738. # Define apt conf location
  739. apt=/etc/apt/sources.list.d
  740. # Create new folder if it doesn't exist
  741. mkdir -p /root/.gnupg/ && chmod 700 /root/.gnupg/
  742. # Updating system
  743. echo "Adding required repositories to proceed with installation:"
  744. echo
  745. # Installing Nginx repo
  746. echo "[ * ] NGINX"
  747. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://nginx.org/packages/mainline/$VERSION/ $codename nginx" > $apt/nginx.list
  748. curl -s https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-keyring.gpg > /dev/null 2>&1
  749. # Installing sury PHP repo
  750. echo "[ * ] PHP"
  751. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/sury-keyring.gpg] https://packages.sury.org/php/ $codename main" > $apt/php.list
  752. curl -s https://packages.sury.org/php/apt.gpg | gpg --dearmor | tee /usr/share/keyrings/sury-keyring.gpg > /dev/null 2>&1
  753. # Installing sury Apache2 repo
  754. if [ "$apache" = 'yes' ]; then
  755. echo "[ * ] Apache2"
  756. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/apache2-keyring.gpg] https://packages.sury.org/apache2/ $codename main" > $apt/apache2.list
  757. curl -s https://packages.sury.org/apache2/apt.gpg | gpg --dearmor | tee /usr/share/keyrings/apache2-keyring.gpg > /dev/null 2>&1
  758. fi
  759. # Installing MariaDB repo
  760. if [ "$mysql" = 'yes' ]; then
  761. echo "[ * ] MariaDB $mariadb_v"
  762. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mariadb-keyring.gpg] https://dlm.mariadb.com/repo/mariadb-server/$mariadb_v/repo/$VERSION $codename main" > $apt/mariadb.list
  763. curl -s https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor | tee /usr/share/keyrings/mariadb-keyring.gpg > /dev/null 2>&1
  764. fi
  765. # Installing Mysql8 repo
  766. if [ "$mysql8" = 'yes' ]; then
  767. echo "[ * ] Mysql 8"
  768. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-apt-config" >> /etc/apt/sources.list.d/mysql.list
  769. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-8.0" >> /etc/apt/sources.list.d/mysql.list
  770. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-tools" >> /etc/apt/sources.list.d/mysql.list
  771. echo "#deb [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-tools-preview" >> /etc/apt/sources.list.d/mysql.list
  772. echo "deb-src [arch=$ARCH signed-by=/usr/share/keyrings/mysql-keyring.gpg] http://repo.mysql.com/apt/debian/ $codename mysql-8.0" >> /etc/apt/sources.list.d/mysql.list
  773. GNUPGHOME="$(mktemp -d)"
  774. export GNUPGHOME
  775. for keyserver in $(shuf -e ha.pool.sks-keyservers.net hkp://p80.pool.sks-keyservers.net:80 keyserver.ubuntu.com hkp://keyserver.ubuntu.com:80); do
  776. gpg --no-default-keyring --keyring /usr/share/keyrings/mysql-keyring.gpg --keyserver "${keyserver}" --recv-keys "B7B3B788A8D3785C" > /dev/null 2>&1 && break
  777. done
  778. fi
  779. # Installing HestiaCP repo
  780. echo "[ * ] Hestia Control Panel"
  781. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/hestia-keyring.gpg] https://$RHOST/ $codename main" > $apt/hestia.list
  782. gpg --no-default-keyring --keyring /usr/share/keyrings/hestia-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys A189E93654F0B0E5 > /dev/null 2>&1
  783. # Installing Node.js repo
  784. if [ "$webterminal" = 'yes' ]; then
  785. echo "[ * ] Node.js $node_v"
  786. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_$node_v.x nodistro main" > $apt/nodejs.list
  787. curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodejs.gpg > /dev/null 2>&1
  788. apt-get -y install nodejs >> $LOG
  789. fi
  790. # Installing PostgreSQL repo
  791. if [ "$postgresql" = 'yes' ]; then
  792. echo "[ * ] PostgreSQL"
  793. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/postgresql-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/ $codename-pgdg main" > $apt/postgresql.list
  794. curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/postgresql-keyring.gpg > /dev/null 2>&1
  795. fi
  796. # Echo for a new line
  797. echo
  798. # Updating system
  799. echo -ne "Updating currently installed packages, please wait... "
  800. apt-get -qq update
  801. apt-get -y upgrade >> $LOG &
  802. BACK_PID=$!
  803. # Check if package installation is done, print a spinner
  804. spin_i=1
  805. while kill -0 $BACK_PID > /dev/null 2>&1; do
  806. printf "\b${spinner:spin_i++%${#spinner}:1}"
  807. sleep 0.5
  808. done
  809. # Do a blank echo to get the \n back
  810. echo
  811. # Check Installation result
  812. wait $BACK_PID
  813. check_result $? 'apt-get upgrade failed'
  814. #----------------------------------------------------------#
  815. # Backup #
  816. #----------------------------------------------------------#
  817. # Creating backup directory tree
  818. mkdir -p $hst_backups
  819. cd $hst_backups
  820. mkdir nginx apache2 php vsftpd proftpd bind exim4 dovecot clamd
  821. mkdir spamassassin mysql postgresql openssl hestia
  822. # Backup OpenSSL configuration
  823. cp /etc/ssl/openssl.cnf $hst_backups/openssl > /dev/null 2>&1
  824. # Backup nginx configuration
  825. systemctl stop nginx > /dev/null 2>&1
  826. cp -r /etc/nginx/* $hst_backups/nginx > /dev/null 2>&1
  827. # Backup Apache configuration
  828. systemctl stop apache2 > /dev/null 2>&1
  829. cp -r /etc/apache2/* $hst_backups/apache2 > /dev/null 2>&1
  830. rm -f /etc/apache2/conf.d/* > /dev/null 2>&1
  831. # Backup PHP-FPM configuration
  832. systemctl stop php*-fpm > /dev/null 2>&1
  833. cp -r /etc/php/* $hst_backups/php > /dev/null 2>&1
  834. # Backup Bind configuration
  835. systemctl stop bind9 > /dev/null 2>&1
  836. cp -r /etc/bind/* $hst_backups/bind > /dev/null 2>&1
  837. # Backup Vsftpd configuration
  838. systemctl stop vsftpd > /dev/null 2>&1
  839. cp /etc/vsftpd.conf $hst_backups/vsftpd > /dev/null 2>&1
  840. # Backup ProFTPD configuration
  841. systemctl stop proftpd > /dev/null 2>&1
  842. cp /etc/proftpd/* $hst_backups/proftpd > /dev/null 2>&1
  843. # Backup Exim configuration
  844. systemctl stop exim4 > /dev/null 2>&1
  845. cp -r /etc/exim4/* $hst_backups/exim4 > /dev/null 2>&1
  846. # Backup ClamAV configuration
  847. systemctl stop clamav-daemon > /dev/null 2>&1
  848. cp -r /etc/clamav/* $hst_backups/clamav > /dev/null 2>&1
  849. # Backup SpamAssassin configuration
  850. systemctl stop spamassassin > /dev/null 2>&1
  851. cp -r /etc/spamassassin/* $hst_backups/spamassassin > /dev/null 2>&1
  852. # Backup Dovecot configuration
  853. systemctl stop dovecot > /dev/null 2>&1
  854. cp /etc/dovecot.conf $hst_backups/dovecot > /dev/null 2>&1
  855. cp -r /etc/dovecot/* $hst_backups/dovecot > /dev/null 2>&1
  856. # Backup MySQL/MariaDB configuration and data
  857. systemctl stop mysql > /dev/null 2>&1
  858. killall -9 mysqld > /dev/null 2>&1
  859. mv /var/lib/mysql $hst_backups/mysql/mysql_datadir > /dev/null 2>&1
  860. cp -r /etc/mysql/* $hst_backups/mysql > /dev/null 2>&1
  861. mv -f /root/.my.cnf $hst_backups/mysql > /dev/null 2>&1
  862. # Backup Hestia
  863. systemctl stop hestia > /dev/null 2>&1
  864. cp -r $HESTIA/* $hst_backups/hestia > /dev/null 2>&1
  865. apt-get -y purge hestia hestia-nginx hestia-php > /dev/null 2>&1
  866. rm -rf $HESTIA > /dev/null 2>&1
  867. #----------------------------------------------------------#
  868. # Package Includes #
  869. #----------------------------------------------------------#
  870. if [ "$phpfpm" = 'yes' ]; then
  871. fpm="php$fpm_v php$fpm_v-common php$fpm_v-bcmath php$fpm_v-cli
  872. php$fpm_v-curl php$fpm_v-fpm php$fpm_v-gd php$fpm_v-intl
  873. php$fpm_v-mysql php$fpm_v-soap php$fpm_v-xml php$fpm_v-zip
  874. php$fpm_v-mbstring php$fpm_v-bz2 php$fpm_v-pspell
  875. php$fpm_v-imagick"
  876. software="$software $fpm"
  877. fi
  878. #----------------------------------------------------------#
  879. # Package Excludes #
  880. #----------------------------------------------------------#
  881. # Excluding packages
  882. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  883. if [ $release -lt 12 ]; then
  884. software=$(echo "$software" | sed -e "s/spamd/spamassassin/g")
  885. fi
  886. if [ "$apache" = 'no' ]; then
  887. software=$(echo "$software" | sed -e "s/apache2 //")
  888. software=$(echo "$software" | sed -e "s/apache2-bin//")
  889. software=$(echo "$software" | sed -e "s/apache2-utils//")
  890. software=$(echo "$software" | sed -e "s/apache2-suexec-custom//")
  891. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  892. software=$(echo "$software" | sed -e "s/libapache2-mod-rpaf//")
  893. software=$(echo "$software" | sed -e "s/libapache2-mod-fcgid//")
  894. software=$(echo "$software" | sed -e "s/libapache2-mod-php$fpm_v//")
  895. fi
  896. if [ "$vsftpd" = 'no' ]; then
  897. software=$(echo "$software" | sed -e "s/vsftpd//")
  898. fi
  899. if [ "$proftpd" = 'no' ]; then
  900. software=$(echo "$software" | sed -e "s/proftpd-basic//")
  901. software=$(echo "$software" | sed -e "s/proftpd-mod-vroot//")
  902. fi
  903. if [ "$named" = 'no' ]; then
  904. software=$(echo "$software" | sed -e "s/bind9//")
  905. fi
  906. if [ "$exim" = 'no' ]; then
  907. software=$(echo "$software" | sed -e "s/exim4 //")
  908. software=$(echo "$software" | sed -e "s/exim4-daemon-heavy//")
  909. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  910. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  911. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  912. software=$(echo "$software" | sed -e "s/spamassassin//")
  913. software=$(echo "$software" | sed -e "s/dovecot-sieve//")
  914. software=$(echo "$software" | sed -e "s/dovecot-managesieved//")
  915. fi
  916. if [ "$clamd" = 'no' ]; then
  917. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  918. fi
  919. if [ "$spamd" = 'no' ]; then
  920. software=$(echo "$software" | sed -e "s/spamassassin//")
  921. software=$(echo "$software" | sed -e "s/spamd//")
  922. fi
  923. if [ "$dovecot" = 'no' ]; then
  924. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  925. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  926. fi
  927. if [ "$sieve" = 'no' ]; then
  928. software=$(echo "$software" | sed -e "s/dovecot-sieve//")
  929. software=$(echo "$software" | sed -e "s/dovecot-managesieved//")
  930. fi
  931. if [ "$mysql" = 'no' ]; then
  932. software=$(echo "$software" | sed -e "s/mariadb-server//")
  933. software=$(echo "$software" | sed -e "s/mariadb-client//")
  934. software=$(echo "$software" | sed -e "s/mariadb-common//")
  935. fi
  936. if [ "$mysql8" = 'no' ]; then
  937. software=$(echo "$software" | sed -e "s/mysql-server//")
  938. software=$(echo "$software" | sed -e "s/mysql-client//")
  939. software=$(echo "$software" | sed -e "s/mysql-common//")
  940. fi
  941. if [ "$mysql" = 'no' ] && [ "$mysql8" = 'no' ]; then
  942. software=$(echo "$software" | sed -e "s/php$fpm_v-mysql//")
  943. fi
  944. if [ "$postgresql" = 'no' ]; then
  945. software=$(echo "$software" | sed -e "s/postgresql-contrib//")
  946. software=$(echo "$software" | sed -e "s/postgresql//")
  947. software=$(echo "$software" | sed -e "s/php$fpm_v-pgsql//")
  948. fi
  949. if [ "$fail2ban" = 'no' ]; then
  950. software=$(echo "$software" | sed -e "s/fail2ban//")
  951. fi
  952. if [ "$iptables" = 'no' ]; then
  953. software=$(echo "$software" | sed -e "s/ipset//")
  954. software=$(echo "$software" | sed -e "s/fail2ban//")
  955. fi
  956. if [ "$webterminal" = 'no' ]; then
  957. software=$(echo "$software" | sed -e "s/nodejs//")
  958. software=$(echo "$software" | sed -e "s/hestia-web-terminal//")
  959. fi
  960. if [ "$phpfpm" = 'yes' ]; then
  961. software=$(echo "$software" | sed -e "s/php$fpm_v-cgi//")
  962. software=$(echo "$software" | sed -e "s/libapache2-mpm-itk//")
  963. software=$(echo "$software" | sed -e "s/libapache2-mod-ruid2//")
  964. software=$(echo "$software" | sed -e "s/libapache2-mod-php$fpm_v//")
  965. fi
  966. if [ -d "$withdebs" ]; then
  967. software=$(echo "$software" | sed -e "s/hestia-nginx//")
  968. software=$(echo "$software" | sed -e "s/hestia-php//")
  969. software=$(echo "$software" | sed -e "s/hestia-web-terminal//")
  970. software=$(echo "$software" | sed -e "s/hestia=${HESTIA_INSTALL_VER}//")
  971. fi
  972. #----------------------------------------------------------#
  973. # Install packages #
  974. #----------------------------------------------------------#
  975. # Enable en_US.UTF-8
  976. sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen
  977. locale-gen > /dev/null 2>&1
  978. # Disabling daemon autostart on apt-get install
  979. echo -e '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d
  980. chmod a+x /usr/sbin/policy-rc.d
  981. # Installing apt packages
  982. echo "The installer is now downloading and installing all required packages."
  983. echo -ne "NOTE: This process may take 10 to 15 minutes to complete, please wait... "
  984. echo
  985. apt-get -y install $software > $LOG
  986. BACK_PID=$!
  987. # Check if package installation is done, print a spinner
  988. spin_i=1
  989. while kill -0 $BACK_PID > /dev/null 2>&1; do
  990. printf "\b${spinner:spin_i++%${#spinner}:1}"
  991. sleep 0.5
  992. done
  993. # Do a blank echo to get the \n back
  994. echo
  995. # Check Installation result
  996. wait $BACK_PID
  997. check_result $? "apt-get install failed"
  998. echo
  999. echo "========================================================================"
  1000. echo
  1001. # Install Hestia packages from local folder
  1002. if [ -n "$withdebs" ] && [ -d "$withdebs" ]; then
  1003. echo "[ * ] Installing local package files..."
  1004. echo " - hestia core package"
  1005. dpkg -i $withdebs/hestia_*.deb > /dev/null 2>&1
  1006. if [ -z $(ls $withdebs/hestia-php_*.deb 2> /dev/null) ]; then
  1007. echo " - hestia-php backend package (from apt)"
  1008. apt-get -y install hestia-php > /dev/null 2>&1
  1009. else
  1010. echo " - hestia-php backend package"
  1011. dpkg -i $withdebs/hestia-php_*.deb > /dev/null 2>&1
  1012. fi
  1013. if [ -z $(ls $withdebs/hestia-nginx_*.deb 2> /dev/null) ]; then
  1014. echo " - hestia-nginx backend package (from apt)"
  1015. apt-get -y install hestia-nginx > /dev/null 2>&1
  1016. else
  1017. echo " - hestia-nginx backend package"
  1018. dpkg -i $withdebs/hestia-nginx_*.deb > /dev/null 2>&1
  1019. fi
  1020. if [ "$webterminal" = "yes" ]; then
  1021. if [ -z $(ls $withdebs/hestia-web-terminal_*.deb 2> /dev/null) ]; then
  1022. echo " - hestia-web-terminal package (from apt)"
  1023. apt-get -y install hestia-web-terminal > /dev/null 2>&1
  1024. else
  1025. echo " - hestia-web-terminal"
  1026. dpkg -i $withdebs/hestia-web-terminal_*.deb > /dev/null 2>&1
  1027. fi
  1028. fi
  1029. fi
  1030. # Restoring autostart policy
  1031. rm -f /usr/sbin/policy-rc.d
  1032. #----------------------------------------------------------#
  1033. # Configure system #
  1034. #----------------------------------------------------------#
  1035. echo "[ * ] Configuring system settings..."
  1036. # Generate a random password
  1037. random_password=$(gen_pass '32')
  1038. # Create the new hestiaweb user
  1039. /usr/sbin/useradd "hestiaweb" -c "$email" --no-create-home
  1040. # do not allow login into hestiaweb user
  1041. echo hestiaweb:$random_password | sudo chpasswd -e
  1042. # Add a general group for normal users created by Hestia
  1043. if [ -z "$(grep ^hestia-users: /etc/group)" ]; then
  1044. groupadd --system "hestia-users"
  1045. fi
  1046. # Create user for php-fpm configs
  1047. /usr/sbin/useradd "hestiamail" -c "$email" --no-create-home
  1048. # Ensures proper permissions for Hestia service interactions.
  1049. /usr/sbin/adduser hestiamail hestia-users
  1050. # Enable SFTP subsystem for SSH
  1051. sftp_subsys_enabled=$(grep -iE "^#?.*subsystem.+(sftp )?sftp-server" /etc/ssh/sshd_config)
  1052. if [ -n "$sftp_subsys_enabled" ]; then
  1053. sed -i -E "s/^#?.*Subsystem.+(sftp )?sftp-server/Subsystem sftp internal-sftp/g" /etc/ssh/sshd_config
  1054. fi
  1055. # Reduce SSH login grace time
  1056. sed -i "s/[#]LoginGraceTime [[:digit:]]m/LoginGraceTime 1m/g" /etc/ssh/sshd_config
  1057. # Disable SSH suffix broadcast
  1058. if [ -z "$(grep "^DebianBanner no" /etc/ssh/sshd_config)" ]; then
  1059. sed -i '/^[#]Banner .*/a DebianBanner no' /etc/ssh/sshd_config
  1060. if [ -z "$(grep "^DebianBanner no" /etc/ssh/sshd_config)" ]; then
  1061. # If first attempt fails just add it
  1062. echo '' >> /etc/ssh/sshd_config
  1063. echo 'DebianBanner no' >> /etc/ssh/sshd_config
  1064. fi
  1065. fi
  1066. # Restart SSH daemon
  1067. systemctl restart ssh
  1068. # Disable AWStats cron
  1069. rm -f /etc/cron.d/awstats
  1070. # Replace AWStats function
  1071. cp -f $HESTIA_INSTALL_DIR/logrotate/httpd-prerotate/* /etc/logrotate.d/httpd-prerotate/
  1072. # Set directory color
  1073. if [ -z "$(grep 'LS_COLORS="$LS_COLORS:di=00;33"' /etc/profile)" ]; then
  1074. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  1075. fi
  1076. # Register /sbin/nologin and /usr/sbin/nologin
  1077. if [ -z "$(grep ^/sbin/nologin /etc/shells)" ]; then
  1078. echo "/sbin/nologin" >> /etc/shells
  1079. fi
  1080. if [ -z "$(grep ^/usr/sbin/nologin /etc/shells)" ]; then
  1081. echo "/usr/sbin/nologin" >> /etc/shells
  1082. fi
  1083. # Configuring NTP
  1084. if [ ! -f "/etc/default/ntpsec-ntpdate" ]; then
  1085. if [ -f /etc/systemd/timesyncd.conf ]; then
  1086. # Not installed by default in debian 12, consider add systemd-timesyncd to
  1087. # package list for install
  1088. sed -i 's/#NTP=/NTP=pool.ntp.org/' /etc/systemd/timesyncd.conf
  1089. systemctl enable systemd-timesyncd
  1090. systemctl start systemd-timesyncd
  1091. fi
  1092. fi
  1093. # Restrict access to /proc fs
  1094. # Prevent unpriv users from seeing each other running processes
  1095. mount -o remount,defaults,hidepid=2 /proc > /dev/null 2>&1
  1096. if [ $? -ne 0 ]; then
  1097. echo "Info: Cannot remount /proc (LXC containers require additional perm added to host apparmor profile)"
  1098. else
  1099. echo "@reboot root sleep 5 && mount -o remount,defaults,hidepid=2 /proc" > /etc/cron.d/hestia-proc
  1100. fi
  1101. #----------------------------------------------------------#
  1102. # Configure Hestia #
  1103. #----------------------------------------------------------#
  1104. echo "[ * ] Configuring Hestia Control Panel..."
  1105. # Installing sudo configuration
  1106. mkdir -p /etc/sudoers.d
  1107. cp -f $HESTIA_COMMON_DIR/sudo/hestiaweb /etc/sudoers.d/
  1108. chmod 440 /etc/sudoers.d/hestiaweb
  1109. # Add Hestia global config
  1110. if [[ ! -e /etc/hestiacp/hestia.conf ]]; then
  1111. mkdir -p /etc/hestiacp
  1112. echo -e "# Do not edit this file, will get overwritten on next upgrade, use /etc/hestiacp/local.conf instead\n\nexport HESTIA='/usr/local/hestia'\n\n[[ -f /etc/hestiacp/local.conf ]] && source /etc/hestiacp/local.conf" > /etc/hestiacp/hestia.conf
  1113. fi
  1114. # Configuring system env
  1115. echo "export HESTIA='$HESTIA'" > /etc/profile.d/hestia.sh
  1116. echo 'PATH=$PATH:'$HESTIA'/bin' >> /etc/profile.d/hestia.sh
  1117. echo 'export PATH' >> /etc/profile.d/hestia.sh
  1118. chmod 755 /etc/profile.d/hestia.sh
  1119. source /etc/profile.d/hestia.sh
  1120. # Configuring logrotate for Hestia logs
  1121. cp -f $HESTIA_INSTALL_DIR/logrotate/hestia /etc/logrotate.d/hestia
  1122. # Create log path and symbolic link
  1123. rm -f /var/log/hestia
  1124. mkdir -p /var/log/hestia
  1125. ln -s /var/log/hestia $HESTIA/log
  1126. # Building directory tree and creating some blank files for Hestia
  1127. mkdir -p $HESTIA/conf $HESTIA/ssl $HESTIA/data/ips \
  1128. $HESTIA/data/queue $HESTIA/data/users $HESTIA/data/firewall \
  1129. $HESTIA/data/sessions
  1130. touch $HESTIA/data/queue/backup.pipe $HESTIA/data/queue/disk.pipe \
  1131. $HESTIA/data/queue/webstats.pipe $HESTIA/data/queue/restart.pipe \
  1132. $HESTIA/data/queue/traffic.pipe $HESTIA/data/queue/daily.pipe $HESTIA/log/system.log \
  1133. $HESTIA/log/nginx-error.log $HESTIA/log/auth.log $HESTIA/log/backup.log
  1134. chmod 750 $HESTIA/conf $HESTIA/data/users $HESTIA/data/ips $HESTIA/log
  1135. chmod -R 750 $HESTIA/data/queue
  1136. chmod 660 /var/log/hestia/*
  1137. chmod 770 $HESTIA/data/sessions
  1138. # Generating Hestia configuration
  1139. rm -f $HESTIA/conf/hestia.conf > /dev/null 2>&1
  1140. touch $HESTIA/conf/hestia.conf
  1141. chmod 660 $HESTIA/conf/hestia.conf
  1142. # Write default port value to hestia.conf
  1143. # If a custom port is specified it will be set at the end of the installation process
  1144. write_config_value "BACKEND_PORT" "8083"
  1145. # Web stack
  1146. if [ "$apache" = 'yes' ]; then
  1147. write_config_value "WEB_SYSTEM" "apache2"
  1148. write_config_value "WEB_RGROUPS" "www-data"
  1149. write_config_value "WEB_PORT" "8080"
  1150. write_config_value "WEB_SSL_PORT" "8443"
  1151. write_config_value "WEB_SSL" "mod_ssl"
  1152. write_config_value "PROXY_SYSTEM" "nginx"
  1153. write_config_value "PROXY_PORT" "80"
  1154. write_config_value "PROXY_SSL_PORT" "443"
  1155. write_config_value "STATS_SYSTEM" "awstats"
  1156. fi
  1157. if [ "$apache" = 'no' ]; then
  1158. write_config_value "WEB_SYSTEM" "nginx"
  1159. write_config_value "WEB_PORT" "80"
  1160. write_config_value "WEB_SSL_PORT" "443"
  1161. write_config_value "WEB_SSL" "openssl"
  1162. write_config_value "STATS_SYSTEM" "awstats"
  1163. fi
  1164. if [ "$phpfpm" = 'yes' ]; then
  1165. write_config_value "WEB_BACKEND" "php-fpm"
  1166. fi
  1167. # Database stack
  1168. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1169. installed_db_types='mysql'
  1170. fi
  1171. if [ "$postgresql" = 'yes' ]; then
  1172. installed_db_types="$installed_db_types,pgsql"
  1173. fi
  1174. if [ -n "$installed_db_types" ]; then
  1175. db=$(echo "$installed_db_types" \
  1176. | sed "s/,/\n/g" \
  1177. | sort -r -u \
  1178. | sed "/^$/d" \
  1179. | sed ':a;N;$!ba;s/\n/,/g')
  1180. write_config_value "DB_SYSTEM" "$db"
  1181. fi
  1182. # FTP stack
  1183. if [ "$vsftpd" = 'yes' ]; then
  1184. write_config_value "FTP_SYSTEM" "vsftpd"
  1185. fi
  1186. if [ "$proftpd" = 'yes' ]; then
  1187. write_config_value "FTP_SYSTEM" "proftpd"
  1188. fi
  1189. # DNS stack
  1190. if [ "$named" = 'yes' ]; then
  1191. write_config_value "DNS_SYSTEM" "bind9"
  1192. fi
  1193. # Mail stack
  1194. if [ "$exim" = 'yes' ]; then
  1195. write_config_value "MAIL_SYSTEM" "exim4"
  1196. if [ "$clamd" = 'yes' ]; then
  1197. write_config_value "ANTIVIRUS_SYSTEM" "clamav-daemon"
  1198. fi
  1199. if [ "$spamd" = 'yes' ]; then
  1200. if [ "$release" = '11' ]; then
  1201. write_config_value "ANTISPAM_SYSTEM" "spamassassin"
  1202. else
  1203. write_config_value "ANTISPAM_SYSTEM" "spamd"
  1204. fi
  1205. fi
  1206. if [ "$dovecot" = 'yes' ]; then
  1207. write_config_value "IMAP_SYSTEM" "dovecot"
  1208. fi
  1209. if [ "$sieve" = 'yes' ]; then
  1210. write_config_value "SIEVE_SYSTEM" "yes"
  1211. fi
  1212. fi
  1213. # Cron daemon
  1214. write_config_value "CRON_SYSTEM" "cron"
  1215. # Firewall stack
  1216. if [ "$iptables" = 'yes' ]; then
  1217. write_config_value "FIREWALL_SYSTEM" "iptables"
  1218. fi
  1219. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  1220. write_config_value "FIREWALL_EXTENSION" "fail2ban"
  1221. fi
  1222. # Disk quota
  1223. if [ "$quota" = 'yes' ]; then
  1224. write_config_value "DISK_QUOTA" "yes"
  1225. else
  1226. write_config_value "DISK_QUOTA" "no"
  1227. fi
  1228. # Resource limitation
  1229. if [ "$resourcelimit" = 'yes' ]; then
  1230. write_config_value "RESOURCES_LIMIT" "yes"
  1231. else
  1232. write_config_value "RESOURCES_LIMIT" "no"
  1233. fi
  1234. write_config_value "WEB_TERMINAL_PORT" "8085"
  1235. # Backups
  1236. write_config_value "BACKUP_SYSTEM" "local"
  1237. write_config_value "BACKUP_GZIP" "4"
  1238. write_config_value "BACKUP_MODE" "zstd"
  1239. # Language
  1240. write_config_value "LANGUAGE" "$lang"
  1241. # Login screen style
  1242. write_config_value "LOGIN_STYLE" "default"
  1243. # Theme
  1244. write_config_value "THEME" "dark"
  1245. # Inactive session timeout
  1246. write_config_value "INACTIVE_SESSION_TIMEOUT" "60"
  1247. # Version & Release Branch
  1248. write_config_value "VERSION" "${HESTIA_INSTALL_VER}"
  1249. write_config_value "RELEASE_BRANCH" "release"
  1250. # Email notifications after upgrade
  1251. write_config_value "UPGRADE_SEND_EMAIL" "true"
  1252. write_config_value "UPGRADE_SEND_EMAIL_LOG" "false"
  1253. # Set "root" user
  1254. write_config_value "ROOT_USER" "$username"
  1255. # Installing hosting packages
  1256. cp -rf $HESTIA_COMMON_DIR/packages $HESTIA/data/
  1257. # Update nameservers in hosting package
  1258. IFS='.' read -r -a domain_elements <<< "$servername"
  1259. if [ -n "${domain_elements[-2]}" ] && [ -n "${domain_elements[-1]}" ]; then
  1260. serverdomain="${domain_elements[-2]}.${domain_elements[-1]}"
  1261. sed -i s/"domain.tld"/"$serverdomain"/g $HESTIA/data/packages/*.pkg
  1262. fi
  1263. # Installing templates
  1264. cp -rf $HESTIA_INSTALL_DIR/templates $HESTIA/data/
  1265. cp -rf $HESTIA_COMMON_DIR/templates/web/ $HESTIA/data/templates
  1266. cp -rf $HESTIA_COMMON_DIR/templates/dns/ $HESTIA/data/templates
  1267. mkdir -p /var/www/html
  1268. mkdir -p /var/www/document_errors
  1269. # Install default success page
  1270. cp -rf $HESTIA_COMMON_DIR/templates/web/unassigned/index.html /var/www/html/
  1271. cp -rf $HESTIA_COMMON_DIR/templates/web/skel/document_errors/* /var/www/document_errors/
  1272. # Installing firewall rules
  1273. cp -rf $HESTIA_COMMON_DIR/firewall $HESTIA/data/
  1274. rm -f $HESTIA/data/firewall/ipset/blacklist.sh $HESTIA/data/firewall/ipset/blacklist.ipv6.sh
  1275. # Delete rules for services that are not installed
  1276. if [ "$vsftpd" = "no" ] && [ "$proftpd" = "no" ]; then
  1277. # Remove FTP
  1278. sed -i "/COMMENT='FTP'/d" $HESTIA/data/firewall/rules.conf
  1279. fi
  1280. if [ "$exim" = "no" ]; then
  1281. # Remove SMTP
  1282. sed -i "/COMMENT='SMTP'/d" $HESTIA/data/firewall/rules.conf
  1283. fi
  1284. if [ "$dovecot" = "no" ]; then
  1285. # Remove IMAP / Dovecot
  1286. sed -i "/COMMENT='IMAP'/d" $HESTIA/data/firewall/rules.conf
  1287. sed -i "/COMMENT='POP3'/d" $HESTIA/data/firewall/rules.conf
  1288. fi
  1289. if [ "$named" = "no" ]; then
  1290. # Remove IMAP / Dovecot
  1291. sed -i "/COMMENT='DNS'/d" $HESTIA/data/firewall/rules.conf
  1292. fi
  1293. # Installing API
  1294. cp -rf $HESTIA_COMMON_DIR/api $HESTIA/data/
  1295. # Configuring server hostname
  1296. $HESTIA/bin/v-change-sys-hostname $servername > /dev/null 2>&1
  1297. # Configuring global OpenSSL options
  1298. echo "[ * ] Configuring OpenSSL to improve TLS performance..."
  1299. tls13_ciphers="TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384"
  1300. if [ "$release" = "11" ]; then
  1301. sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
  1302. elif [ "$release" = "12" ]; then
  1303. if ! grep -qw "^ssl_conf = ssl_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
  1304. sed -i '/providers = provider_sect$/a ssl_conf = ssl_sect' /etc/ssl/openssl.cnf
  1305. fi
  1306. if ! grep -qw "^[ssl_sect]$" /etc/ssl/openssl.cnf 2> /dev/null; then
  1307. sed -i '$a \\n[ssl_sect]\nsystem_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
  1308. elif grep -qw "^system_default = system_default_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
  1309. sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
  1310. fi
  1311. fi
  1312. # Generating SSL certificate
  1313. echo "[ * ] Generating default self-signed SSL certificate..."
  1314. $HESTIA/bin/v-generate-ssl-cert $(hostname) '' 'US' 'California' \
  1315. 'San Francisco' 'Hestia Control Panel' 'IT' > /tmp/hst.pem
  1316. crt_end=$(grep -n "END CERTIFICATE-" /tmp/hst.pem | cut -f 1 -d:)
  1317. if [ "$release" = "12" ]; then
  1318. key_start=$(grep -n "BEGIN PRIVATE KEY" /tmp/hst.pem | cut -f 1 -d:)
  1319. key_end=$(grep -n "END PRIVATE KEY" /tmp/hst.pem | cut -f 1 -d:)
  1320. else
  1321. key_start=$(grep -n "BEGIN RSA" /tmp/hst.pem | cut -f 1 -d:)
  1322. key_end=$(grep -n "END RSA" /tmp/hst.pem | cut -f 1 -d:)
  1323. fi
  1324. # Adding SSL certificate
  1325. echo "[ * ] Adding SSL certificate to Hestia Control Panel..."
  1326. cd $HESTIA/ssl
  1327. sed -n "1,${crt_end}p" /tmp/hst.pem > certificate.crt
  1328. sed -n "$key_start,${key_end}p" /tmp/hst.pem > certificate.key
  1329. chown root:mail $HESTIA/ssl/*
  1330. chmod 660 $HESTIA/ssl/*
  1331. rm /tmp/hst.pem
  1332. # Install dhparam.pem
  1333. cp -f $HESTIA_INSTALL_DIR/ssl/dhparam.pem /etc/ssl
  1334. # Enable SFTP jail
  1335. echo "[ * ] Enabling SFTP jail..."
  1336. $HESTIA/bin/v-add-sys-sftp-jail > /dev/null 2>&1
  1337. check_result $? "can't enable sftp jail"
  1338. # Enable SSH jail
  1339. echo "[ * ] Enabling SSH jail..."
  1340. $HESTIA/bin/v-add-sys-ssh-jail > /dev/null 2>&1
  1341. check_result $? "can't enable ssh jail"
  1342. # Adding Hestia admin account
  1343. echo "[ * ] Creating default admin account..."
  1344. $HESTIA/bin/v-add-user "$username" "$vpass" "$email" "default" "System Administrator"
  1345. check_result $? "can't create admin user"
  1346. $HESTIA/bin/v-change-user-shell "$username" nologin
  1347. $HESTIA/bin/v-change-user-role "$username" admin
  1348. $HESTIA/bin/v-change-user-language "$username" "$lang"
  1349. $HESTIA/bin/v-change-sys-config-value 'POLICY_SYSTEM_PROTECTED_ADMIN' 'yes'
  1350. #----------------------------------------------------------#
  1351. # Configure Nginx #
  1352. #----------------------------------------------------------#
  1353. echo "[ * ] Configuring NGINX..."
  1354. rm -f /etc/nginx/conf.d/*.conf
  1355. cp -f $HESTIA_INSTALL_DIR/nginx/nginx.conf /etc/nginx/
  1356. cp -f $HESTIA_INSTALL_DIR/nginx/status.conf /etc/nginx/conf.d/
  1357. cp -f $HESTIA_INSTALL_DIR/nginx/0rtt-anti-replay.conf /etc/nginx/conf.d/
  1358. cp -f $HESTIA_INSTALL_DIR/nginx/agents.conf /etc/nginx/conf.d/
  1359. # Copy over cloudflare.inc incase in the next step there are connection issues with CF
  1360. cp -f $HESTIA_INSTALL_DIR/nginx/cloudflare.inc /etc/nginx/conf.d/
  1361. cp -f $HESTIA_INSTALL_DIR/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  1362. cp -f $HESTIA_INSTALL_DIR/nginx/phppgadmin.inc /etc/nginx/conf.d/
  1363. cp -f $HESTIA_INSTALL_DIR/logrotate/nginx /etc/logrotate.d/
  1364. mkdir -p /etc/nginx/conf.d/domains
  1365. mkdir -p /etc/nginx/conf.d/main
  1366. mkdir -p /etc/nginx/modules-enabled
  1367. mkdir -p /var/log/nginx/domains
  1368. # Update dns servers in nginx.conf
  1369. for nameserver in $(grep -is '^nameserver' /etc/resolv.conf | cut -d' ' -f2 | tr '\r\n' ' ' | xargs); do
  1370. if [[ "$nameserver" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
  1371. if [ -z "$resolver" ]; then
  1372. resolver="$nameserver"
  1373. else
  1374. resolver="$resolver $nameserver"
  1375. fi
  1376. fi
  1377. done
  1378. if [ -n "$resolver" ]; then
  1379. sed -i "s/1.0.0.1 8.8.4.4 1.1.1.1 8.8.8.8/$resolver/g" /etc/nginx/nginx.conf
  1380. fi
  1381. # https://github.com/ergin/nginx-cloudflare-real-ip/
  1382. cf_ips="$(curl -fsLm5 --retry 2 https://api.cloudflare.com/client/v4/ips)"
  1383. if [ -n "$cf_ips" ] && [ "$(echo "$cf_ips" | jq -r '.success//""')" = "true" ]; then
  1384. cf_inc="/etc/nginx/conf.d/cloudflare.inc"
  1385. echo "[ * ] Updating Cloudflare IP Ranges for Nginx..."
  1386. echo "# Cloudflare IP Ranges" > $cf_inc
  1387. echo "" >> $cf_inc
  1388. echo "# IPv4" >> $cf_inc
  1389. for ipv4 in $(echo "$cf_ips" | jq -r '.result.ipv4_cidrs[]//""' | sort); do
  1390. echo "set_real_ip_from $ipv4;" >> $cf_inc
  1391. done
  1392. echo "" >> $cf_inc
  1393. echo "# IPv6" >> $cf_inc
  1394. for ipv6 in $(echo "$cf_ips" | jq -r '.result.ipv6_cidrs[]//""' | sort); do
  1395. echo "set_real_ip_from $ipv6;" >> $cf_inc
  1396. done
  1397. echo "" >> $cf_inc
  1398. echo "real_ip_header CF-Connecting-IP;" >> $cf_inc
  1399. fi
  1400. update-rc.d nginx defaults > /dev/null 2>&1
  1401. systemctl start nginx >> $LOG
  1402. check_result $? "nginx start failed"
  1403. #----------------------------------------------------------#
  1404. # Configure Apache #
  1405. #----------------------------------------------------------#
  1406. if [ "$apache" = 'yes' ]; then
  1407. echo "[ * ] Configuring Apache Web Server..."
  1408. mkdir -p /etc/apache2/conf.d
  1409. mkdir -p /etc/apache2/conf.d/domains
  1410. # Copy configuration files
  1411. cp -f $HESTIA_INSTALL_DIR/apache2/apache2.conf /etc/apache2/
  1412. cp -f $HESTIA_INSTALL_DIR/apache2/status.conf /etc/apache2/mods-available/hestia-status.conf
  1413. cp -f /etc/apache2/mods-available/status.load /etc/apache2/mods-available/hestia-status.load
  1414. cp -f $HESTIA_INSTALL_DIR/logrotate/apache2 /etc/logrotate.d/
  1415. # Enable needed modules
  1416. a2enmod rewrite > /dev/null 2>&1
  1417. a2enmod suexec > /dev/null 2>&1
  1418. a2enmod ssl > /dev/null 2>&1
  1419. a2enmod actions > /dev/null 2>&1
  1420. a2enmod headers > /dev/null 2>&1
  1421. a2dismod --quiet status > /dev/null 2>&1
  1422. a2enmod --quiet hestia-status > /dev/null 2>&1
  1423. # Enable mod_ruid/mpm_itk or mpm_event
  1424. if [ "$phpfpm" = 'yes' ]; then
  1425. # Disable prefork and php, enable event
  1426. a2dismod php$fpm_v > /dev/null 2>&1
  1427. a2dismod mpm_prefork > /dev/null 2>&1
  1428. a2enmod mpm_event > /dev/null 2>&1
  1429. cp -f $HESTIA_INSTALL_DIR/apache2/hestia-event.conf /etc/apache2/conf.d/
  1430. else
  1431. a2enmod mpm_itk > /dev/null 2>&1
  1432. fi
  1433. echo "# Powered by hestia" > /etc/apache2/sites-available/default
  1434. echo "# Powered by hestia" > /etc/apache2/sites-available/default-ssl
  1435. echo "# Powered by hestia" > /etc/apache2/ports.conf
  1436. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  1437. touch /var/log/apache2/access.log /var/log/apache2/error.log
  1438. mkdir -p /var/log/apache2/domains
  1439. chmod a+x /var/log/apache2
  1440. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  1441. chmod 751 /var/log/apache2/domains
  1442. # Prevent remote access to server-status page
  1443. sed -i '/Allow from all/d' /etc/apache2/mods-available/hestia-status.conf
  1444. update-rc.d apache2 defaults > /dev/null 2>&1
  1445. systemctl start apache2 >> $LOG
  1446. check_result $? "apache2 start failed"
  1447. else
  1448. update-rc.d apache2 disable > /dev/null 2>&1
  1449. systemctl stop apache2 > /dev/null 2>&1
  1450. fi
  1451. #----------------------------------------------------------#
  1452. # Configure PHP-FPM #
  1453. #----------------------------------------------------------#
  1454. if [ "$phpfpm" = "yes" ]; then
  1455. if [ "$multiphp" = 'yes' ]; then
  1456. for v in "${multiphp_v[@]}"; do
  1457. echo "[ * ] Installing PHP $v..."
  1458. $HESTIA/bin/v-add-web-php "$v" > /dev/null 2>&1
  1459. done
  1460. else
  1461. echo "[ * ] Installing PHP $fpm_v..."
  1462. $HESTIA/bin/v-add-web-php "$fpm_v" > /dev/null 2>&1
  1463. fi
  1464. echo "[ * ] Configuring PHP-FPM $fpm_v..."
  1465. # Create www.conf for webmail and php(*)admin
  1466. cp -f $HESTIA_INSTALL_DIR/php-fpm/www.conf /etc/php/$fpm_v/fpm/pool.d/www.conf
  1467. update-rc.d php$fpm_v-fpm defaults > /dev/null 2>&1
  1468. systemctl start php$fpm_v-fpm >> $LOG
  1469. check_result $? "php-fpm start failed"
  1470. # Set default php version to $fpm_v
  1471. update-alternatives --set php /usr/bin/php$fpm_v > /dev/null 2>&1
  1472. fi
  1473. #----------------------------------------------------------#
  1474. # Configure PHP #
  1475. #----------------------------------------------------------#
  1476. echo "[ * ] Configuring PHP..."
  1477. ZONE=$(timedatectl > /dev/null 2>&1 | grep Timezone | awk '{print $2}')
  1478. if [ -z "$ZONE" ]; then
  1479. ZONE='UTC'
  1480. fi
  1481. for pconf in $(find /etc/php* -name php.ini); do
  1482. sed -i "s%;date.timezone =%date.timezone = $ZONE%g" $pconf
  1483. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  1484. done
  1485. # Cleanup php session files not changed in the last 7 days (60*24*7 minutes)
  1486. echo '#!/bin/sh' > /etc/cron.daily/php-session-cleanup
  1487. 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
  1488. 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
  1489. chmod 755 /etc/cron.daily/php-session-cleanup
  1490. #----------------------------------------------------------#
  1491. # Configure Vsftpd #
  1492. #----------------------------------------------------------#
  1493. if [ "$vsftpd" = 'yes' ]; then
  1494. echo "[ * ] Configuring Vsftpd server..."
  1495. cp -f $HESTIA_INSTALL_DIR/vsftpd/vsftpd.conf /etc/
  1496. touch /var/log/vsftpd.log
  1497. chown root:adm /var/log/vsftpd.log
  1498. chmod 640 /var/log/vsftpd.log
  1499. touch /var/log/xferlog
  1500. chown root:adm /var/log/xferlog
  1501. chmod 640 /var/log/xferlog
  1502. if [ -s /etc/logrotate.d/vsftpd ] && ! grep -Fq "/var/log/xferlog" /etc/logrotate.d/vsftpd; then
  1503. sed -i 's|/var/log/vsftpd.log|/var/log/vsftpd.log /var/log/xferlog|g' /etc/logrotate.d/vsftpd
  1504. fi
  1505. update-rc.d vsftpd defaults > /dev/null 2>&1
  1506. systemctl start vsftpd >> $LOG
  1507. check_result $? "vsftpd start failed"
  1508. fi
  1509. #----------------------------------------------------------#
  1510. # Configure ProFTPD #
  1511. #----------------------------------------------------------#
  1512. if [ "$proftpd" = 'yes' ]; then
  1513. echo "[ * ] Configuring ProFTPD server..."
  1514. echo "127.0.0.1 $servername" >> /etc/hosts
  1515. cp -f $HESTIA_INSTALL_DIR/proftpd/proftpd.conf /etc/proftpd/
  1516. cp -f $HESTIA_INSTALL_DIR/proftpd/tls.conf /etc/proftpd/
  1517. update-rc.d proftpd defaults > /dev/null 2>&1
  1518. systemctl start proftpd >> $LOG
  1519. check_result $? "proftpd start failed"
  1520. if [ "$release" -eq 11 ]; then
  1521. unit_files="$(systemctl list-unit-files | grep proftpd)"
  1522. if [[ "$unit_files" =~ "disabled" ]]; then
  1523. systemctl enable proftpd
  1524. fi
  1525. fi
  1526. if [ "$release" -eq 12 ]; then
  1527. systemctl disable --now proftpd.socket
  1528. systemctl enable --now proftpd.service
  1529. fi
  1530. fi
  1531. #----------------------------------------------------------#
  1532. # Configure MariaDB / MySQL #
  1533. #----------------------------------------------------------#
  1534. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1535. [ "$mysql" = 'yes' ] && mysql_type="MariaDB" || mysql_type="MySQL"
  1536. echo "[ * ] Configuring $mysql_type database server..."
  1537. mycnf="my-small.cnf"
  1538. if [ $memory -gt 1200000 ]; then
  1539. mycnf="my-medium.cnf"
  1540. fi
  1541. if [ $memory -gt 3900000 ]; then
  1542. mycnf="my-large.cnf"
  1543. fi
  1544. if [ "$mysql_type" = 'MariaDB' ]; then
  1545. # Run mariadb-install-db
  1546. mariadb-install-db >> $LOG
  1547. fi
  1548. # Remove symbolic link
  1549. rm -f /etc/mysql/my.cnf
  1550. # Configuring MariaDB
  1551. cp -f $HESTIA_INSTALL_DIR/mysql/$mycnf /etc/mysql/my.cnf
  1552. # Switch MariaDB inclusions to the MySQL
  1553. if [ "$mysql_type" = 'MySQL' ]; then
  1554. sed -i '/query_cache_size/d' /etc/mysql/my.cnf
  1555. sed -i 's|mariadb.conf.d|mysql.conf.d|g' /etc/mysql/my.cnf
  1556. fi
  1557. if [ "$mysql_type" = 'MariaDB' ]; then
  1558. sed -i 's|/usr/share/mysql|/usr/share/mariadb|g' /etc/mysql/my.cnf
  1559. update-rc.d mariadb defaults > /dev/null 2>&1
  1560. systemctl -q enable mariadb 2> /dev/null
  1561. systemctl start mariadb >> $LOG
  1562. check_result $? "${mysql_type,,} start failed"
  1563. fi
  1564. if [ "$mysql_type" = 'MySQL' ]; then
  1565. update-rc.d mysql defaults > /dev/null 2>&1
  1566. systemctl -q enable mysql 2> /dev/null
  1567. systemctl start mysql >> $LOG
  1568. check_result $? "${mysql_type,,} start failed"
  1569. fi
  1570. # Securing MariaDB/MySQL installation
  1571. mpass=$(gen_pass)
  1572. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  1573. chmod 600 /root/.my.cnf
  1574. if [ -f '/usr/bin/mariadb' ]; then
  1575. mysql_server="mariadb"
  1576. else
  1577. mysql_server="mysql"
  1578. fi
  1579. # Alter root password
  1580. $mysql_server -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$mpass'; FLUSH PRIVILEGES;"
  1581. if [ "$mysql_type" = 'MariaDB' ]; then
  1582. # Allow mysql access via socket for startup
  1583. $mysql_server -e "UPDATE mysql.global_priv SET priv=json_set(priv, '$.password_last_changed', UNIX_TIMESTAMP(), '$.plugin', 'mysql_native_password', '$.authentication_string', 'invalid', '$.auth_or', json_array(json_object(), json_object('plugin', 'unix_socket'))) WHERE User='root';"
  1584. # Disable anonymous users
  1585. $mysql_server -e "DELETE FROM mysql.global_priv WHERE User='';"
  1586. else
  1587. $mysql_server -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '$mpass';"
  1588. $mysql_server -e "DELETE FROM mysql.user WHERE User='';"
  1589. $mysql_server -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
  1590. fi
  1591. # Drop test database
  1592. $mysql_server -e "DROP DATABASE IF EXISTS test"
  1593. $mysql_server -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  1594. # Flush privileges
  1595. $mysql_server -e "FLUSH PRIVILEGES;"
  1596. fi
  1597. #----------------------------------------------------------#
  1598. # Configure phpMyAdmin #
  1599. #----------------------------------------------------------#
  1600. # Source upgrade.conf with phpmyadmin versions
  1601. # shellcheck source=/usr/local/hestia/install/upgrade/upgrade.conf
  1602. source $HESTIA/install/upgrade/upgrade.conf
  1603. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1604. # Display upgrade information
  1605. echo "[ * ] Installing phpMyAdmin version v$pma_v..."
  1606. # Download latest phpmyadmin release
  1607. wget --quiet --retry-connrefused https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  1608. # Unpack files
  1609. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  1610. # Create folders
  1611. mkdir -p /usr/share/phpmyadmin
  1612. mkdir -p /etc/phpmyadmin
  1613. mkdir -p /etc/phpmyadmin/conf.d/
  1614. mkdir /usr/share/phpmyadmin/tmp
  1615. # Configuring Apache2 for PHPMYADMIN
  1616. if [ "$apache" = 'yes' ]; then
  1617. touch /etc/apache2/conf.d/phpmyadmin.inc
  1618. fi
  1619. # Overwrite old files
  1620. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  1621. # Create copy of config file
  1622. cp -f $HESTIA_INSTALL_DIR/phpmyadmin/config.inc.php /etc/phpmyadmin/
  1623. # Set config and log directory
  1624. sed -i "s|'configFile' => ROOT_PATH . 'config.inc.php',|'configFile' => '/etc/phpmyadmin/config.inc.php',|g" /usr/share/phpmyadmin/libraries/vendor_config.php
  1625. # Create temporary folder and change permission
  1626. mkdir -p /var/lib/phpmyadmin/tmp
  1627. chmod 770 /var/lib/phpmyadmin/tmp
  1628. chown -R hestiamail:www-data /usr/share/phpmyadmin/tmp/
  1629. # Generate blow fish
  1630. blowfish=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
  1631. sed -i "s|%blowfish_secret%|$blowfish|" /etc/phpmyadmin/config.inc.php
  1632. # Clean Up
  1633. rm -fr phpMyAdmin-$pma_v-all-languages
  1634. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  1635. write_config_value "DB_PMA_ALIAS" "phpmyadmin"
  1636. $HESTIA/bin/v-change-sys-db-alias 'pma' "phpmyadmin"
  1637. # Special thanks to Pavel Galkin (https://skurudo.ru)
  1638. # https://github.com/skurudo/phpmyadmin-fixer
  1639. # shellcheck source=/usr/local/hestia/install/deb/phpmyadmin/pma.sh
  1640. source $HESTIA_INSTALL_DIR/phpmyadmin/pma.sh > /dev/null 2>&1
  1641. # Limit access to /etc/phpmyadmin/
  1642. chown -R root:hestiamail /etc/phpmyadmin/
  1643. chmod 640 /etc/phpmyadmin/config.inc.php
  1644. chmod 750 /etc/phpmyadmin/conf.d/
  1645. fi
  1646. #----------------------------------------------------------#
  1647. # Configure PostgreSQL #
  1648. #----------------------------------------------------------#
  1649. if [ "$postgresql" = 'yes' ]; then
  1650. echo "[ * ] Configuring PostgreSQL database server..."
  1651. ppass=$(gen_pass)
  1652. cp -f $HESTIA_INSTALL_DIR/postgresql/pg_hba.conf /etc/postgresql/*/main/
  1653. systemctl restart postgresql
  1654. sudo -iu postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'" > /dev/null 2>&1
  1655. mkdir -p /etc/phppgadmin/
  1656. mkdir -p /usr/share/phppgadmin/
  1657. wget --retry-connrefused --quiet https://github.com/hestiacp/phppgadmin/releases/download/v$pga_v/phppgadmin-v$pga_v.tar.gz
  1658. tar xzf phppgadmin-v$pga_v.tar.gz -C /usr/share/phppgadmin/
  1659. cp -f $HESTIA_INSTALL_DIR/pga/config.inc.php /etc/phppgadmin/
  1660. ln -s /etc/phppgadmin/config.inc.php /usr/share/phppgadmin/conf/
  1661. # Configuring phpPgAdmin
  1662. if [ "$apache" = 'yes' ]; then
  1663. cp -f $HESTIA_INSTALL_DIR/pga/phppgadmin.conf /etc/apache2/conf.d/phppgadmin.inc
  1664. fi
  1665. rm phppgadmin-v$pga_v.tar.gz
  1666. write_config_value "DB_PGA_ALIAS" "phppgadmin"
  1667. $HESTIA/bin/v-change-sys-db-alias 'pga' "phppgadmin"
  1668. # Limit access to /etc/phppgadmin/
  1669. chown -R root:hestiamail /etc/phppgadmin/
  1670. chmod 640 /etc/phppgadmin/config.inc.php
  1671. fi
  1672. #----------------------------------------------------------#
  1673. # Configure Bind #
  1674. #----------------------------------------------------------#
  1675. if [ "$named" = 'yes' ]; then
  1676. echo "[ * ] Configuring Bind DNS server..."
  1677. cp -f $HESTIA_INSTALL_DIR/bind/named.conf /etc/bind/
  1678. cp -f $HESTIA_INSTALL_DIR/bind/named.conf.options /etc/bind/
  1679. chown root:bind /etc/bind/named.conf
  1680. chown root:bind /etc/bind/named.conf.options
  1681. chown bind:bind /var/cache/bind
  1682. chmod 640 /etc/bind/named.conf
  1683. chmod 640 /etc/bind/named.conf.options
  1684. aa-complain /usr/sbin/named 2> /dev/null
  1685. if [ "$apparmor" = 'yes' ]; then
  1686. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2> /dev/null
  1687. systemctl status apparmor > /dev/null 2>&1
  1688. if [ $? -ne 0 ]; then
  1689. systemctl restart apparmor >> $LOG
  1690. fi
  1691. fi
  1692. update-rc.d bind9 defaults > /dev/null 2>&1
  1693. systemctl start bind9
  1694. check_result $? "bind9 start failed"
  1695. # Workaround for OpenVZ/Virtuozzo
  1696. if [ -e "/proc/vz/veinfo" ] && [ -e "/etc/rc.local" ]; then
  1697. sed -i "s/^exit 0/service bind9 restart\nexit 0/" /etc/rc.local
  1698. fi
  1699. fi
  1700. #----------------------------------------------------------#
  1701. # Configure Exim #
  1702. #----------------------------------------------------------#
  1703. if [ "$exim" = 'yes' ]; then
  1704. echo "[ * ] Configuring Exim mail server..."
  1705. gpasswd -a Debian-exim mail > /dev/null 2>&1
  1706. exim_version=$(exim4 --version | head -1 | awk '{print $3}' | cut -f -2 -d .)
  1707. # if Exim version > 4.9.4 or greater!
  1708. if ! version_ge "4.95" "$exim_version"; then
  1709. cp -f $HESTIA_INSTALL_DIR/exim/exim4.conf.4.95.template /etc/exim4/exim4.conf.template
  1710. else
  1711. if ! version_ge "4.93" "$exim_version"; then
  1712. cp -f $HESTIA_INSTALL_DIR/exim/exim4.conf.4.94.template /etc/exim4/exim4.conf.template
  1713. else
  1714. cp -f $HESTIA_INSTALL_DIR/exim/exim4.conf.template /etc/exim4/
  1715. fi
  1716. fi
  1717. cp -f $HESTIA_INSTALL_DIR/exim/dnsbl.conf /etc/exim4/
  1718. cp -f $HESTIA_INSTALL_DIR/exim/spam-blocks.conf /etc/exim4/
  1719. cp -f $HESTIA_INSTALL_DIR/exim/limit.conf /etc/exim4/
  1720. cp -f $HESTIA_INSTALL_DIR/exim/system.filter /etc/exim4/
  1721. touch /etc/exim4/white-blocks.conf
  1722. if [ "$spamd" = 'yes' ]; then
  1723. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  1724. fi
  1725. if [ "$clamd" = 'yes' ]; then
  1726. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  1727. fi
  1728. # Generate SRS KEY If not support just created it will get ignored anyway
  1729. srs=$(gen_pass)
  1730. echo $srs > /etc/exim4/srs.conf
  1731. chmod 640 /etc/exim4/srs.conf
  1732. chmod 640 /etc/exim4/exim4.conf.template
  1733. chown root:Debian-exim /etc/exim4/srs.conf
  1734. rm -rf /etc/exim4/domains
  1735. mkdir -p /etc/exim4/domains
  1736. rm -f /etc/alternatives/mta
  1737. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  1738. update-rc.d -f sendmail remove > /dev/null 2>&1
  1739. systemctl stop sendmail > /dev/null 2>&1
  1740. update-rc.d -f postfix remove > /dev/null 2>&1
  1741. systemctl stop postfix > /dev/null 2>&1
  1742. update-rc.d exim4 defaults
  1743. systemctl start exim4 >> $LOG
  1744. check_result $? "exim4 start failed"
  1745. fi
  1746. #----------------------------------------------------------#
  1747. # Configure Dovecot #
  1748. #----------------------------------------------------------#
  1749. if [ "$dovecot" = 'yes' ]; then
  1750. echo "[ * ] Configuring Dovecot POP/IMAP mail server..."
  1751. gpasswd -a dovecot mail > /dev/null 2>&1
  1752. cp -rf $HESTIA_COMMON_DIR/dovecot /etc/
  1753. cp -f $HESTIA_INSTALL_DIR/logrotate/dovecot /etc/logrotate.d/
  1754. rm -f /etc/dovecot/conf.d/15-mailboxes.conf
  1755. chown -R root:root /etc/dovecot*
  1756. touch /var/log/dovecot.log
  1757. chown -R dovecot:mail /var/log/dovecot.log
  1758. chmod 660 /var/log/dovecot.log
  1759. # Alter config for 2.2
  1760. version=$(dovecot --version | cut -f -2 -d .)
  1761. if [ "$version" = "2.2" ]; then
  1762. echo "[ * ] Downgrade dovecot config to sync with 2.2 settings"
  1763. sed -i 's|#ssl_dh_parameters_length = 4096|ssl_dh_parameters_length = 4096|g' /etc/dovecot/conf.d/10-ssl.conf
  1764. sed -i 's|ssl_dh = </etc/ssl/dhparam.pem|#ssl_dh = </etc/ssl/dhparam.pem|g' /etc/dovecot/conf.d/10-ssl.conf
  1765. sed -i 's|ssl_min_protocol = TLSv1.2|ssl_protocols = !SSLv3 !TLSv1 !TLSv1.1|g' /etc/dovecot/conf.d/10-ssl.conf
  1766. fi
  1767. update-rc.d dovecot defaults
  1768. systemctl start dovecot >> $LOG
  1769. check_result $? "dovecot start failed"
  1770. fi
  1771. #----------------------------------------------------------#
  1772. # Configure ClamAV #
  1773. #----------------------------------------------------------#
  1774. if [ "$clamd" = 'yes' ]; then
  1775. gpasswd -a clamav mail > /dev/null 2>&1
  1776. gpasswd -a clamav Debian-exim > /dev/null 2>&1
  1777. cp -f $HESTIA_INSTALL_DIR/clamav/clamd.conf /etc/clamav/
  1778. update-rc.d clamav-daemon defaults
  1779. if [ ! -d "/run/clamav" ]; then
  1780. mkdir /run/clamav
  1781. fi
  1782. chown -R clamav:clamav /run/clamav
  1783. if [ -e "/lib/systemd/system/clamav-daemon.service" ]; then
  1784. exec_pre1='ExecStartPre=-/bin/mkdir -p /run/clamav'
  1785. exec_pre2='ExecStartPre=-/bin/chown -R clamav:clamav /run/clamav'
  1786. sed -i "s|\[Service\]|[Service]\n$exec_pre1\n$exec_pre2|g" \
  1787. /lib/systemd/system/clamav-daemon.service
  1788. systemctl daemon-reload
  1789. fi
  1790. systemctl start clamav-daemon > /dev/null 2>&1
  1791. sleep 1
  1792. systemctl status clamav-daemon > /dev/null 2>&1
  1793. echo -ne "[ * ] Installing ClamAV anti-virus definitions... "
  1794. /usr/bin/freshclam >> $LOG > /dev/null 2>&1
  1795. BACK_PID=$!
  1796. spin_i=1
  1797. while kill -0 $BACK_PID > /dev/null 2>&1; do
  1798. printf "\b${spinner:spin_i++%${#spinner}:1}"
  1799. sleep 0.5
  1800. done
  1801. echo
  1802. systemctl start clamav-daemon >> $LOG
  1803. check_result $? "clamav-daemon start failed"
  1804. fi
  1805. #----------------------------------------------------------#
  1806. # Configure SpamAssassin #
  1807. #----------------------------------------------------------#
  1808. if [ "$spamd" = 'yes' ]; then
  1809. echo "[ * ] Configuring SpamAssassin..."
  1810. update-rc.d spamassassin defaults > /dev/null 2>&1
  1811. if [ "$release" = "11" ]; then
  1812. update-rc.d spamassassin enable > /dev/null 2>&1
  1813. systemctl start spamassassin >> $LOG
  1814. check_result $? "spamassassin start failed"
  1815. unit_files="$(systemctl list-unit-files | grep spamassassin)"
  1816. if [[ "$unit_files" =~ "disabled" ]]; then
  1817. systemctl enable spamassassin > /dev/null 2>&1
  1818. fi
  1819. sed -i "s/#CRON=1/CRON=1/" /etc/default/spamassassin
  1820. else
  1821. # Deb 12+ renamed to spamd
  1822. update-rc.d spamd enable > /dev/null 2>&1
  1823. systemctl start spamd >> $LOG
  1824. unit_files="$(systemctl list-unit-files | grep spamd)"
  1825. if [[ "$unit_files" =~ "disabled" ]]; then
  1826. systemctl enable spamd > /dev/null 2>&1
  1827. fi
  1828. fi
  1829. fi
  1830. #----------------------------------------------------------#
  1831. # Configure Fail2Ban #
  1832. #----------------------------------------------------------#
  1833. if [ "$fail2ban" = 'yes' ]; then
  1834. echo "[ * ] Configuring fail2ban access monitor..."
  1835. cp -rf $HESTIA_INSTALL_DIR/fail2ban /etc/
  1836. if [ "$dovecot" = 'no' ]; then
  1837. fline=$(cat /etc/fail2ban/jail.local | grep -n dovecot-iptables -A 2)
  1838. fline=$(echo "$fline" | grep enabled | tail -n1 | cut -f 1 -d -)
  1839. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1840. fi
  1841. if [ "$exim" = 'no' ]; then
  1842. fline=$(cat /etc/fail2ban/jail.local | grep -n exim-iptables -A 2)
  1843. fline=$(echo "$fline" | grep enabled | tail -n1 | cut -f 1 -d -)
  1844. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1845. fi
  1846. if [ "$vsftpd" = 'yes' ]; then
  1847. # Create vsftpd Log File
  1848. if [ ! -f "/var/log/vsftpd.log" ]; then
  1849. touch /var/log/vsftpd.log
  1850. fi
  1851. fline=$(cat /etc/fail2ban/jail.local | grep -n vsftpd-iptables -A 2)
  1852. fline=$(echo "$fline" | grep enabled | tail -n1 | cut -f 1 -d -)
  1853. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1854. fi
  1855. if [ ! -e /var/log/auth.log ]; then
  1856. # Debian workaround: auth logging was moved to systemd
  1857. touch /var/log/auth.log
  1858. chmod 640 /var/log/auth.log
  1859. chown root:adm /var/log/auth.log
  1860. fi
  1861. if [ -f /etc/fail2ban/jail.d/defaults-debian.conf ]; then
  1862. rm -f /etc/fail2ban/jail.d/defaults-debian.conf
  1863. fi
  1864. update-rc.d fail2ban defaults
  1865. systemctl start fail2ban >> $LOG
  1866. check_result $? "fail2ban start failed"
  1867. fi
  1868. # Configuring MariaDB/MySQL host
  1869. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1870. $HESTIA/bin/v-add-database-host mysql localhost root $mpass
  1871. fi
  1872. # Configuring PostgreSQL host
  1873. if [ "$postgresql" = 'yes' ]; then
  1874. $HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
  1875. fi
  1876. #----------------------------------------------------------#
  1877. # Install Roundcube #
  1878. #----------------------------------------------------------#
  1879. # Min requirements Dovecot + Exim + Mysql
  1880. if ([ "$mysql" == 'yes' ] || [ "$mysql8" == 'yes' ]) && [ "$dovecot" == "yes" ]; then
  1881. echo "[ * ] Installing Roundcube..."
  1882. $HESTIA/bin/v-add-sys-roundcube
  1883. write_config_value "WEBMAIL_ALIAS" "webmail"
  1884. else
  1885. write_config_value "WEBMAIL_ALIAS" ""
  1886. write_config_value "WEBMAIL_SYSTEM" ""
  1887. fi
  1888. #----------------------------------------------------------#
  1889. # Install Sieve #
  1890. #----------------------------------------------------------#
  1891. # Min requirements Dovecot + Exim + Mysql + Roundcube
  1892. if [ "$sieve" = 'yes' ]; then
  1893. # Folder paths
  1894. RC_INSTALL_DIR="/var/lib/roundcube"
  1895. RC_CONFIG_DIR="/etc/roundcube"
  1896. echo "[ * ] Installing Sieve Mail Filter..."
  1897. # dovecot.conf install
  1898. sed -i "s/namespace/service stats \{\n unix_listener stats-writer \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n\}\n\nnamespace/g" /etc/dovecot/dovecot.conf
  1899. # Dovecot conf files
  1900. # 10-master.conf
  1901. sed -i -E -z "s/ }\n user = dovecot\n}/ \}\n unix_listener auth-master \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n user = dovecot\n\}/g" /etc/dovecot/conf.d/10-master.conf
  1902. # 15-lda.conf
  1903. sed -i "s/\#mail_plugins = \\\$mail_plugins/mail_plugins = \$mail_plugins quota sieve\n auth_socket_path = \/var\/run\/dovecot\/auth-master/g" /etc/dovecot/conf.d/15-lda.conf
  1904. # 20-imap.conf
  1905. sed -i "s/mail_plugins = quota imap_quota/mail_plugins = quota imap_quota imap_sieve/g" /etc/dovecot/conf.d/20-imap.conf
  1906. # Replace dovecot-sieve config files
  1907. cp -f $HESTIA_COMMON_DIR/dovecot/sieve/* /etc/dovecot/conf.d
  1908. # Dovecot default file install
  1909. echo -e "require [\"fileinto\"];\n# rule:[SPAM]\nif header :contains \"X-Spam-Flag\" \"YES\" {\n fileinto \"INBOX.Spam\";\n}\n" > /etc/dovecot/sieve/default
  1910. # exim4 install
  1911. sed -i "s/\stransport = local_delivery/ transport = dovecot_virtual_delivery/" /etc/exim4/exim4.conf.template
  1912. sed -i "s/address_pipe:/dovecot_virtual_delivery:\n driver = pipe\n command = \/usr\/lib\/dovecot\/dovecot-lda -e -d \${extract{1}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\/accounts}}}}@\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\n delivery_date_add\n envelope_to_add\n return_path_add\n log_output = true\n log_defer_output = true\n user = \${extract{2}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\/passwd}}}}\n group = mail\n return_output\n\naddress_pipe:/g" /etc/exim4/exim4.conf.template
  1913. # Permission changes
  1914. touch /var/log/dovecot.log
  1915. chown -R dovecot:mail /var/log/dovecot.log
  1916. chmod 660 /var/log/dovecot.log
  1917. if [ -d "/var/lib/roundcube" ]; then
  1918. # Modify Roundcube config
  1919. mkdir -p $RC_CONFIG_DIR/plugins/managesieve
  1920. cp -f $HESTIA_COMMON_DIR/roundcube/plugins/config_managesieve.inc.php $RC_CONFIG_DIR/plugins/managesieve/config.inc.php
  1921. ln -s $RC_CONFIG_DIR/plugins/managesieve/config.inc.php $RC_INSTALL_DIR/plugins/managesieve/config.inc.php
  1922. chown -R hestiamail:www-data $RC_CONFIG_DIR/
  1923. chmod 751 -R $RC_CONFIG_DIR
  1924. chmod 644 $RC_CONFIG_DIR/*.php
  1925. chmod 644 $RC_CONFIG_DIR/plugins/managesieve/config.inc.php
  1926. sed -i "s/\"archive\"/\"archive\", \"managesieve\"/g" $RC_CONFIG_DIR/config.inc.php
  1927. chmod 640 $RC_CONFIG_DIR/config.inc.php
  1928. fi
  1929. # Restart Dovecot and Exim4
  1930. systemctl restart dovecot > /dev/null 2>&1
  1931. systemctl restart exim4 > /dev/null 2>&1
  1932. fi
  1933. #----------------------------------------------------------#
  1934. # Configure API #
  1935. #----------------------------------------------------------#
  1936. if [ "$api" = "yes" ]; then
  1937. # Keep legacy api enabled until transition is complete
  1938. write_config_value "API" "yes"
  1939. write_config_value "API_SYSTEM" "1"
  1940. write_config_value "API_ALLOWED_IP" ""
  1941. else
  1942. write_config_value "API" "no"
  1943. write_config_value "API_SYSTEM" "0"
  1944. write_config_value "API_ALLOWED_IP" ""
  1945. $HESTIA/bin/v-change-sys-api disable
  1946. fi
  1947. #----------------------------------------------------------#
  1948. # Configure Web terminal #
  1949. #----------------------------------------------------------#
  1950. # Web terminal
  1951. if [ "$webterminal" = 'yes' ]; then
  1952. write_config_value "WEB_TERMINAL" "true"
  1953. systemctl daemon-reload > /dev/null 2>&1
  1954. systemctl enable hestia-web-terminal > /dev/null 2>&1
  1955. systemctl restart hestia-web-terminal > /dev/null 2>&1
  1956. else
  1957. write_config_value "WEB_TERMINAL" "false"
  1958. fi
  1959. #----------------------------------------------------------#
  1960. # Configure File Manager #
  1961. #----------------------------------------------------------#
  1962. echo "[ * ] Configuring File Manager..."
  1963. $HESTIA/bin/v-add-sys-filemanager quiet
  1964. #----------------------------------------------------------#
  1965. # Configure dependencies #
  1966. #----------------------------------------------------------#
  1967. echo "[ * ] Configuring PHP dependencies..."
  1968. $HESTIA/bin/v-add-sys-dependencies quiet
  1969. echo "[ * ] Installing Rclone & Update Restic ..."
  1970. curl -s https://rclone.org/install.sh | bash > /dev/null 2>&1
  1971. restic self-update > /dev/null 2>&1
  1972. #----------------------------------------------------------#
  1973. # Configure IP #
  1974. #----------------------------------------------------------#
  1975. # Configuring system IPs
  1976. echo "[ * ] Configuring System IP..."
  1977. $HESTIA/bin/v-update-sys-ip > /dev/null 2>&1
  1978. # Get primary IP
  1979. default_nic="$(ip -d -j route show | jq -r '.[] | if .dst == "default" then .dev else empty end')"
  1980. # IPv4
  1981. primary_ipv4="$(ip -4 -d -j addr show "$default_nic" | jq -r '.[] | select(length > 0) | .addr_info[] | if .scope == "global" then .local else empty end' | head -n1)"
  1982. # IPv6
  1983. #primary_ipv6="$(ip -6 -d -j addr show "$default_nic" | jq -r '.[] | select(length > 0) | .addr_info[] | if .scope == "global" then .local else empty end' | head -n1)"
  1984. ip="$primary_ipv4"
  1985. local_ip="$primary_ipv4"
  1986. # Configuring firewall
  1987. if [ "$iptables" = 'yes' ]; then
  1988. $HESTIA/bin/v-update-firewall
  1989. fi
  1990. # Get public IP
  1991. pub_ipv4="$(curl -fsLm5 --retry 2 --ipv4 https://ip.hestiacp.com/)"
  1992. if [ -n "$pub_ipv4" ] && [ "$pub_ipv4" != "$ip" ]; then
  1993. if [ -e /etc/rc.local ]; then
  1994. sed -i '/exit 0/d' /etc/rc.local
  1995. else
  1996. touch /etc/rc.local
  1997. fi
  1998. check_rclocal=$(cat /etc/rc.local | grep "#!")
  1999. if [ -z "$check_rclocal" ]; then
  2000. echo "#!/bin/sh" >> /etc/rc.local
  2001. fi
  2002. # Fix for Proxmox VE containers where hostname is reset to non-FQDN format on reboot
  2003. check_pve=$(uname -r | grep pve)
  2004. if [ ! -z "$check_pve" ]; then
  2005. echo 'hostname=$(hostname --fqdn)' >> /etc/rc.local
  2006. echo ""$HESTIA/bin/v-change-sys-hostname" "'"$hostname"'"" >> /etc/rc.local
  2007. fi
  2008. echo "$HESTIA/bin/v-update-sys-ip" >> /etc/rc.local
  2009. echo "exit 0" >> /etc/rc.local
  2010. chmod +x /etc/rc.local
  2011. systemctl enable rc-local > /dev/null 2>&1
  2012. $HESTIA/bin/v-change-sys-ip-nat "$ip" "$pub_ipv4" > /dev/null 2>&1
  2013. ip="$pub_ipv4"
  2014. fi
  2015. # Configuring libapache2-mod-remoteip
  2016. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ]; then
  2017. cd /etc/apache2/mods-available
  2018. echo "<IfModule mod_remoteip.c>" > remoteip.conf
  2019. echo " RemoteIPHeader X-Real-IP" >> remoteip.conf
  2020. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ipv4" != "127.0.0.1" ]; then
  2021. echo " RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  2022. fi
  2023. if [ -n "$local_ip" ] && [ "$local_ip" != "$pub_ipv4" ]; then
  2024. echo " RemoteIPInternalProxy $local_ip" >> remoteip.conf
  2025. fi
  2026. if [ -n "$pub_ipv4" ]; then
  2027. echo " RemoteIPInternalProxy $pub_ipv4" >> remoteip.conf
  2028. fi
  2029. echo "</IfModule>" >> remoteip.conf
  2030. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  2031. a2enmod remoteip >> $LOG
  2032. systemctl restart apache2
  2033. fi
  2034. # Adding default domain
  2035. $HESTIA/bin/v-add-web-domain "$username" "$servername" "$ip"
  2036. check_result $? "can't create $servername domain"
  2037. # Adding cron jobs
  2038. export SCHEDULED_RESTART="yes"
  2039. min=$(gen_pass '012345' '2')
  2040. hour=$(gen_pass '1234567' '1')
  2041. echo "MAILTO=\"\"" > /var/spool/cron/crontabs/hestiaweb
  2042. echo "CONTENT_TYPE=\"text/plain; charset=utf-8\"" >> /var/spool/cron/crontabs/hestiaweb
  2043. echo "*/2 * * * * sudo /usr/local/hestia/bin/v-update-sys-queue restart" >> /var/spool/cron/crontabs/hestiaweb
  2044. echo "10 00 * * * sudo /usr/local/hestia/bin/v-update-sys-queue daily" >> /var/spool/cron/crontabs/hestiaweb
  2045. echo "15 02 * * * sudo /usr/local/hestia/bin/v-update-sys-queue disk" >> /var/spool/cron/crontabs/hestiaweb
  2046. echo "10 00 * * * sudo /usr/local/hestia/bin/v-update-sys-queue traffic" >> /var/spool/cron/crontabs/hestiaweb
  2047. echo "30 03 * * * sudo /usr/local/hestia/bin/v-update-sys-queue webstats" >> /var/spool/cron/crontabs/hestiaweb
  2048. echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-queue backup" >> /var/spool/cron/crontabs/hestiaweb
  2049. echo "10 05 * * * sudo /usr/local/hestia/bin/v-backup-users" >> /var/spool/cron/crontabs/hestiaweb
  2050. echo "20 00 * * * sudo /usr/local/hestia/bin/v-update-user-stats" >> /var/spool/cron/crontabs/hestiaweb
  2051. echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-rrd" >> /var/spool/cron/crontabs/hestiaweb
  2052. echo "$min $hour * * * sudo /usr/local/hestia/bin/v-update-letsencrypt-ssl" >> /var/spool/cron/crontabs/hestiaweb
  2053. echo "41 4 * * * sudo /usr/local/hestia/bin/v-update-sys-hestia-all" >> /var/spool/cron/crontabs/hestiaweb
  2054. chmod 600 /var/spool/cron/crontabs/hestiaweb
  2055. chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
  2056. # Enable automatic updates
  2057. $HESTIA/bin/v-add-cron-hestia-autoupdate apt
  2058. # Building initial rrd images
  2059. $HESTIA/bin/v-update-sys-rrd
  2060. # Enabling file system quota
  2061. if [ "$quota" = 'yes' ]; then
  2062. $HESTIA/bin/v-add-sys-quota
  2063. fi
  2064. # Set backend port
  2065. $HESTIA/bin/v-change-sys-port $port > /dev/null 2>&1
  2066. # Create default configuration files
  2067. $HESTIA/bin/v-update-sys-defaults
  2068. # Update remaining packages since repositories have changed
  2069. echo -ne "[ * ] Installing remaining software updates..."
  2070. apt-get -qq update
  2071. apt-get -y upgrade >> $LOG &
  2072. BACK_PID=$!
  2073. echo
  2074. # Starting Hestia service
  2075. update-rc.d hestia defaults
  2076. systemctl start hestia
  2077. check_result $? "hestia start failed"
  2078. chown hestiaweb:hestiaweb $HESTIA/data/sessions
  2079. # Create backup folder and set correct permission
  2080. mkdir -p /backup/
  2081. chmod 755 /backup/
  2082. # Create cronjob to generate ssl
  2083. echo "@reboot root sleep 10 && rm /etc/cron.d/hestia-ssl && PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:' && /usr/local/hestia/bin/v-add-letsencrypt-host" > /etc/cron.d/hestia-ssl
  2084. #----------------------------------------------------------#
  2085. # Set hestia.conf default values #
  2086. #----------------------------------------------------------#
  2087. echo "[ * ] Updating configuration files..."
  2088. BIN="$HESTIA/bin"
  2089. source $HESTIA/func/syshealth.sh
  2090. syshealth_repair_system_config
  2091. # Add /usr/local/hestia/bin/ to PATH variable in .bashrc if it exists
  2092. [[ -f /root/.bashrc ]] && echo 'if [ "${PATH#*/usr/local/hestia/bin*}" = "$PATH" ]; then
  2093. . /etc/profile.d/hestia.sh
  2094. fi' >> /root/.bashrc
  2095. # Add /usr/local/hestia/bin/ to PATH variable in .zshrc if it exists
  2096. [[ -f /root/.zshrc ]] && echo 'if [ "${PATH#*/usr/local/hestia/bin*}" = "$PATH" ]; then
  2097. . /etc/profile.d/hestia.sh
  2098. fi' >> /root/.zshrc
  2099. #----------------------------------------------------------#
  2100. # Hestia Access Info #
  2101. #----------------------------------------------------------#
  2102. # Comparing hostname and IP
  2103. host_ip=$(host $servername | head -n 1 | awk '{print $NF}')
  2104. if [ "$host_ip" = "$ip" ]; then
  2105. ip="$servername"
  2106. fi
  2107. echo -e "\n"
  2108. echo "===================================================================="
  2109. echo -e "\n"
  2110. # Sending notification to admin email
  2111. echo -e "Congratulations!
  2112. You have successfully installed Hestia Control Panel on your server.
  2113. Ready to get started? Log in using the following credentials:
  2114. Admin URL: https://$servername:$port" > $tmpfile
  2115. if [ "$host_ip" != "$ip" ]; then
  2116. echo " Backup URL: https://$ip:$port" >> $tmpfile
  2117. fi
  2118. echo -e -n " Username: $username
  2119. Password: $displaypass
  2120. Thank you for choosing Hestia Control Panel to power your full stack web server,
  2121. we hope that you enjoy using it as much as we do!
  2122. Please feel free to contact us at any time if you have any questions,
  2123. or if you encounter any bugs or problems:
  2124. Documentation: https://docs.hestiacp.com/
  2125. Forum: https://forum.hestiacp.com/
  2126. GitHub: https://www.github.com/hestiacp/hestiacp
  2127. Note: Automatic updates are enabled by default. If you would like to disable them,
  2128. please log in and navigate to Server > Updates to turn them off.
  2129. Help support the Hestia Control Panel project by donating via PayPal:
  2130. https://www.hestiacp.com/donate
  2131. --
  2132. Sincerely yours,
  2133. The Hestia Control Panel development team
  2134. Made with love & pride by the open-source community around the world.
  2135. " >> $tmpfile
  2136. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  2137. cat $tmpfile | $send_mail -s "Hestia Control Panel" $email
  2138. # Congrats
  2139. echo
  2140. cat $tmpfile
  2141. rm -f $tmpfile
  2142. # Add welcome message to notification panel
  2143. $HESTIA/bin/v-add-user-notification "$username" 'Welcome to Hestia Control Panel!' '<p>You are now ready to begin adding <a href="/add/user/">user accounts</a> and <a href="/add/web/">domains</a>. For help and assistance, <a href="https://hestiacp.com/docs/" target="_blank">view the documentation</a> or <a href="https://forum.hestiacp.com/" target="_blank">visit our forum</a>.</p><p>Please <a href="https://github.com/hestiacp/hestiacp/issues" target="_blank">report any issues via GitHub</a>.</p><p class="u-text-bold">Have a wonderful day!</p><p><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team</p>'
  2144. # Clean-up
  2145. # Sort final configuration file
  2146. sort_config_file
  2147. if [ "$interactive" = 'yes' ]; then
  2148. echo "[ ! ] IMPORTANT: The system will now reboot to complete the installation process."
  2149. read -n 1 -s -r -p "Press any key to continue"
  2150. reboot
  2151. else
  2152. echo "[ ! ] IMPORTANT: You must restart the system before continuing!"
  2153. fi
  2154. # EOF