freedombone-utils-web 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Web related functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. # default search engine for command line browser
  31. DEFAULT_SEARCH='https://searx.laquadrature.net'
  32. # onion port for the default domain
  33. DEFAULT_DOMAIN_ONION_PORT=8099
  34. # Whether Let's Encrypt is enabled for all sites
  35. LETSENCRYPT_ENABLED="yes"
  36. LETSENCRYPT_SERVER='https://acme-v01.api.letsencrypt.org/directory'
  37. # list of encryption protocols
  38. SSL_PROTOCOLS="TLSv1 TLSv1.1 TLSv1.2"
  39. # Mozilla recommended default ciphers. These work better on Android
  40. # See https://wiki.mozilla.org/Security/Server_Side_TLS
  41. SSL_CIPHERS="ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS"
  42. NGINX_ENSITE_REPO="https://github.com/perusio/nginx_ensite"
  43. NGINX_ENSITE_COMMIT='fa4d72ce1c0a490442c8474e9c8dc21ed52c93d0'
  44. # memory limit for php in MB
  45. MAX_PHP_MEMORY=64
  46. # logging level for Nginx
  47. WEBSERVER_LOG_LEVEL='warn'
  48. # test a domain name to see if it's valid
  49. function validate_domain_name {
  50. # count the number of dots in the domain name
  51. dots=${TEST_DOMAIN_NAME//[^.]}
  52. no_of_dots=${#dots}
  53. if (( $no_of_dots > 3 )); then
  54. TEST_DOMAIN_NAME=$"The domain $TEST_DOMAIN_NAME has too many subdomains. It should be of the type w.x.y.z, x.y.z or y.z"
  55. fi
  56. if (( $no_of_dots == 0 )); then
  57. TEST_DOMAIN_NAME=$"The domain $TEST_DOMAIN_NAME has no top level domain. It should be of the type w.x.y.z, x.y.z or y.z"
  58. fi
  59. }
  60. function nginx_disable_sniffing {
  61. domain_name=$1
  62. filename=/etc/nginx/sites-available/$domain_name
  63. echo ' add_header X-Frame-Options DENY;' >> $filename
  64. echo ' add_header X-Content-Type-Options nosniff;' >> $filename
  65. echo '' >> $filename
  66. }
  67. function nginx_limits {
  68. domain_name=$1
  69. max_body='20m'
  70. if [ $2 ]; then
  71. max_body=$2
  72. fi
  73. filename=/etc/nginx/sites-available/$domain_name
  74. echo " client_max_body_size ${max_body};" >> $filename
  75. echo ' client_body_buffer_size 128k;' >> $filename
  76. echo '' >> $filename
  77. echo ' limit_conn conn_limit_per_ip 10;' >> $filename
  78. echo ' limit_req zone=req_limit_per_ip burst=10 nodelay;' >> $filename
  79. echo '' >> $filename
  80. }
  81. function nginx_stapling {
  82. domain_name=$1
  83. filename=/etc/nginx/sites-available/$domain_name
  84. echo " ssl_stapling on;" >> $filename
  85. echo ' ssl_stapling_verify on;' >> $filename
  86. echo ' ssl_trusted_certificate /etc/ssl/certs/${domain_name}.pem;' >> $filename
  87. echo '' >> $filename
  88. }
  89. function nginx_http_redirect {
  90. # redirect port 80 to https
  91. domain_name=$1
  92. filename=/etc/nginx/sites-available/$domain_name
  93. echo 'server {' > $filename
  94. echo ' listen 80;' >> $filename
  95. echo ' listen [::]:80;' >> $filename
  96. echo " server_name ${domain_name};" >> $filename
  97. echo " root /var/www/${domain_name}/htdocs;" >> $filename
  98. echo ' access_log /dev/null;' >> $filename
  99. echo " error_log /dev/null;" >> $filename
  100. function_check nginx_limits
  101. nginx_limits $domain_name
  102. if [ ${#2} -gt 0 ]; then
  103. echo " $2;" >> $filename
  104. fi
  105. echo ' rewrite ^ https://$server_name$request_uri? permanent;' >> $filename
  106. echo '}' >> $filename
  107. echo '' >> $filename
  108. }
  109. function nginx_ssl {
  110. # creates the SSL/TLS section for a website
  111. domain_name=$1
  112. filename=/etc/nginx/sites-available/$domain_name
  113. echo ' ssl_stapling off;' >> $filename
  114. echo ' ssl_stapling_verify off;' >> $filename
  115. echo ' ssl on;' >> $filename
  116. echo " ssl_certificate /etc/letsencrypt/live/${domain_name}/fullchain.pem;" >> $filename
  117. echo " ssl_certificate_key /etc/letsencrypt/live/${domain_name}/privkey.pem;" >> $filename
  118. echo " ssl_dhparam /etc/ssl/certs/${domain_name}.dhparam;" >> $filename
  119. echo '' >> $filename
  120. echo ' ssl_session_cache builtin:1000 shared:SSL:10m;' >> $filename
  121. echo ' ssl_session_timeout 60m;' >> $filename
  122. echo ' ssl_prefer_server_ciphers on;' >> $filename
  123. echo " ssl_protocols $SSL_PROTOCOLS;" >> $filename
  124. echo " ssl_ciphers '$SSL_CIPHERS';" >> $filename
  125. echo " add_header Content-Security-Policy \"default-src https:; script-src https: 'unsafe-inline'; style-src https: 'unsafe-inline'\";" >> $filename
  126. echo ' add_header X-XSS-Protection "1; mode=block";' >> $filename
  127. echo ' add_header X-Robots-Tag none;' >> $filename
  128. echo ' add_header X-Download-Options noopen;' >> $filename
  129. echo ' add_header X-Permitted-Cross-Domain-Policies none;' >> $filename
  130. #nginx_stapling $1
  131. }
  132. function nginx_keybase {
  133. # creates files suitable for keybase.io verification
  134. domain_name=$1
  135. filename=/etc/nginx/sites-available/$domain_name
  136. echo '' >> $filename
  137. echo " # make sure webfinger and other well known services aren't blocked" >> $filename
  138. echo ' # by denying dot files and rewrite request to the front controller' >> $filename
  139. echo ' location ^~ /.well-known/ {' >> $filename
  140. echo ' allow all;' >> $filename
  141. echo ' }' >> $filename
  142. if [ ! -d /var/www/${domain_name}/htdocs/.well-known ]; then
  143. mkdir -p /var/www/${domain_name}/htdocs/.well-known
  144. fi
  145. if [ ! -f /var/www/${domain_name}/htdocs/keybase.txt ]; then
  146. touch /var/www/${domain_name}/htdocs/keybase.txt
  147. fi
  148. if [ ! -f /var/www/${domain_name}/htdocs/.well-known/keybase.txt ]; then
  149. touch /var/www/${domain_name}/htdocs/.well-known/keybase.txt
  150. fi
  151. }
  152. # check an individual domain name
  153. function test_domain_name {
  154. if [ $1 ]; then
  155. TEST_DOMAIN_NAME=$1
  156. if [[ $TEST_DOMAIN_NAME != 'ttrss' ]]; then
  157. function_check validate_domain_name
  158. validate_domain_name
  159. if [[ $TEST_DOMAIN_NAME != $1 ]]; then
  160. echo $"Invalid domain name $TEST_DOMAIN_NAME"
  161. exit 8528
  162. fi
  163. fi
  164. fi
  165. }
  166. # Checks whether certificates were generated for the given hostname
  167. function check_certificates {
  168. if [ ! $1 ]; then
  169. return
  170. fi
  171. USE_LETSENCRYPT='no'
  172. if [ $2 ]; then
  173. USE_LETSENCRYPT=$2
  174. fi
  175. if [[ $USE_LETSENCRYPT == 'no' ]]; then
  176. if [ ! -f /etc/ssl/private/${1}.key ]; then
  177. echo $"Private certificate for ${CHECK_HOSTNAME} was not created"
  178. exit 63959
  179. fi
  180. if [ ! -f /etc/ssl/certs/${1}.crt ]; then
  181. echo $"Public certificate for ${CHECK_HOSTNAME} was not created"
  182. exit 7679
  183. fi
  184. if grep -q "${1}.pem" /etc/nginx/sites-available/${1}; then
  185. sed -i "s|${1}.pem|${1}.crt|g" /etc/nginx/sites-available/${1}
  186. fi
  187. else
  188. if [ ! -f /etc/letsencrypt/live/${1}/privkey.pem ]; then
  189. echo $"Private certificate for ${CHECK_HOSTNAME} was not created"
  190. exit 6282
  191. fi
  192. if [ ! -f /etc/letsencrypt/live/${1}/fullchain.pem ]; then
  193. echo $"Public certificate for ${CHECK_HOSTNAME} was not created"
  194. exit 5328
  195. fi
  196. if grep -q "${1}.crt" /etc/nginx/sites-available/${1}; then
  197. sed -i "s|${1}.crt|${1}.pem|g" /etc/nginx/sites-available/${1}
  198. fi
  199. fi
  200. if [ ! -f /etc/ssl/certs/${1}.dhparam ]; then
  201. echo $"Diffie–Hellman parameters for ${CHECK_HOSTNAME} were not created"
  202. exit 5989
  203. fi
  204. }
  205. function cert_exists {
  206. cert_type='dhparam'
  207. if [ $2 ]; then
  208. cert_type="$2"
  209. fi
  210. if [ -f /etc/ssl/certs/${1}.${cert_type} ]; then
  211. echo "1"
  212. else
  213. if [ -f /etc/letsencrypt/live/${1}/fullchain.${cert_type} ]; then
  214. echo "1"
  215. else
  216. echo "0"
  217. fi
  218. fi
  219. }
  220. function create_self_signed_cert {
  221. ${PROJECT_NAME}-addcert -h ${SITE_DOMAIN_NAME} --dhkey ${DH_KEYLENGTH}
  222. function_check check_certificates
  223. check_certificates ${SITE_DOMAIN_NAME}
  224. }
  225. function create_letsencrypt_cert {
  226. ${PROJECT_NAME}-addcert -e ${SITE_DOMAIN_NAME} -s ${LETSENCRYPT_SERVER} --dhkey ${DH_KEYLENGTH} --email ${MY_EMAIL_ADDRESS}
  227. if [ ! "$?" = "0" ]; then
  228. if [[ ${NO_SELF_SIGNED} == 'no' ]]; then
  229. echo $"Lets Encrypt failed for ${SITE_DOMAIN_NAME}, so try making a self-signed cert"
  230. ${PROJECT_NAME}-addcert -h ${SITE_DOMAIN_NAME} --dhkey ${DH_KEYLENGTH}
  231. function_check check_certificates
  232. check_certificates ${SITE_DOMAIN_NAME}
  233. else
  234. echo $"Lets Encrypt failed for $SITE_DOMAIN_NAME"
  235. exit 682529
  236. fi
  237. return
  238. fi
  239. function_check check_certificates
  240. check_certificates ${SITE_DOMAIN_NAME} 'yes'
  241. }
  242. function create_site_certificate {
  243. SITE_DOMAIN_NAME="$1"
  244. # if yes then only "valid" certs are allowed, not self-signed
  245. NO_SELF_SIGNED='no'
  246. if [ $2 ]; then
  247. NO_SELF_SIGNED="$2"
  248. fi
  249. if [[ $ONION_ONLY == "no" ]]; then
  250. if [[ "$(cert_exists ${SITE_DOMAIN_NAME})" == "0" ]]; then
  251. if [[ $LETSENCRYPT_ENABLED != "yes" ]]; then
  252. create_self_signed_cert
  253. else
  254. create_letsencrypt_cert
  255. fi
  256. else
  257. if [[ $LETSENCRYPT_ENABLED == "yes" ]]; then
  258. if [[ "$(cert_exists ${SITE_DOMAIN_NAME} pem)" == "0" ]]; then
  259. create_letsencrypt_cert
  260. fi
  261. fi
  262. fi
  263. fi
  264. }
  265. # script to automatically renew any Let's Encrypt certificates
  266. function letsencrypt_renewals {
  267. if [[ $ONION_ONLY != "no" ]]; then
  268. return
  269. fi
  270. renewals_script=/etc/cron.monthly/letsencrypt
  271. renewals_retry_script=/etc/cron.daily/letsencrypt
  272. renewal_failure_msg=$'The certificate for $LETSENCRYPT_DOMAIN could not be renewed'
  273. renewal_email_title=$'${PROJECT_NAME} Lets Encrypt certificate renewal'
  274. # the main script tries to renew once per month
  275. echo '#!/bin/bash' > $renewals_script
  276. echo '' >> $renewals_script
  277. echo "PROJECT_NAME='${PROJECT_NAME}'" >> $renewals_script
  278. echo 'COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt' >> $renewals_script
  279. echo '' >> $renewals_script
  280. echo 'if [ -d /etc/letsencrypt ]; then' >> $renewals_script
  281. echo ' if [ -f ~/letsencrypt_failed ]; then' >> $renewals_script
  282. echo ' rm ~/letsencrypt_failed' >> $renewals_script
  283. echo ' fi' >> $renewals_script
  284. echo -n ' ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> $renewals_script
  285. echo -n "awk -F ':' '{print " >> $renewals_script
  286. echo -n '$2' >> $renewals_script
  287. echo "}')" >> $renewals_script
  288. echo ' ADMIN_EMAIL_ADDRESS=$ADMIN_USERNAME@$HOSTNAME' >> $renewals_script
  289. echo ' for d in /etc/letsencrypt/live/*/ ; do' >> $renewals_script
  290. echo -n ' LETSENCRYPT_DOMAIN=$(echo "$d" | ' >> $renewals_script
  291. echo -n "awk -F '/' '{print " >> $renewals_script
  292. echo -n '$5' >> $renewals_script
  293. echo "}')" >> $renewals_script
  294. echo ' if [ -f /etc/nginx/sites-available/$LETSENCRYPT_DOMAIN ]; then' >> $renewals_script
  295. echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt' >> $renewals_script
  296. echo ' if [ ! "$?" = "0" ]; then' >> $renewals_script
  297. echo " echo \"${renewal_failure_msg}\" > ~/temp_renewletsencrypt.txt" >> $renewals_script
  298. echo ' echo "" >> ~/temp_renewletsencrypt.txt' >> $renewals_script
  299. echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt 2>> ~/temp_renewletsencrypt.txt' >> $renewals_script
  300. echo -n " cat ~/temp_renewletsencrypt.txt | mail -s \"${renewal_email_title}\" " >> $renewals_script
  301. echo '$ADMIN_EMAIL_ADDRESS' >> $renewals_script
  302. echo ' rm ~/temp_renewletsencrypt.txt' >> $renewals_script
  303. echo ' if [ ! -f ~/letsencrypt_failed ]; then' >> $renewals_script
  304. echo ' touch ~/letsencrypt_failed' >> $renewals_script
  305. echo ' fi' >> $renewals_script
  306. echo ' fi' >> $renewals_script
  307. echo ' fi' >> $renewals_script
  308. echo ' done' >> $renewals_script
  309. echo 'fi' >> $renewals_script
  310. chmod +x $renewals_script
  311. # a secondary script keeps trying to renew after a failure
  312. echo '#!/bin/bash' > $renewals_retry_script
  313. echo '' >> $renewals_retry_script
  314. echo "PROJECT_NAME='${PROJECT_NAME}'" >> $renewals_retry_script
  315. echo 'COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt' >> $renewals_retry_script
  316. echo '' >> $renewals_retry_script
  317. echo 'if [ -d /etc/letsencrypt ]; then' >> $renewals_retry_script
  318. echo ' if [ -f ~/letsencrypt_failed ]; then' >> $renewals_retry_script
  319. echo ' rm ~/letsencrypt_failed' >> $renewals_retry_script
  320. echo -n ' ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | ' >> $renewals_retry_script
  321. echo -n "awk -F ':' '{print " >> $renewals_retry_script
  322. echo -n '$2' >> $renewals_retry_script
  323. echo "}')" >> $renewals_retry_script
  324. echo ' ADMIN_EMAIL_ADDRESS=$ADMIN_USERNAME@$HOSTNAME' >> $renewals_retry_script
  325. echo ' for d in /etc/letsencrypt/live/*/ ; do' >> $renewals_retry_script
  326. echo -n ' LETSENCRYPT_DOMAIN=$(echo "$d" | ' >> $renewals_retry_script
  327. echo -n "awk -F '/' '{print " >> $renewals_retry_script
  328. echo -n '$5' >> $renewals_retry_script
  329. echo "}')" >> $renewals_retry_script
  330. echo ' if [ -f /etc/nginx/sites-available/$LETSENCRYPT_DOMAIN ]; then' >> $renewals_retry_script
  331. echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt' >> $renewals_retry_script
  332. echo ' if [ ! "$?" = "0" ]; then' >> $renewals_retry_script
  333. echo " echo \"${renewal_failure_msg}\" > ~/temp_renewletsencrypt.txt" >> $renewals_retry_script
  334. echo ' echo "" >> ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
  335. echo ' ${PROJECT_NAME}-renew-cert -h $LETSENCRYPT_DOMAIN -p letsencrypt 2>> ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
  336. echo -n " cat ~/temp_renewletsencrypt.txt | mail -s \"${renewal_email_title}\" " >> $renewals_retry_script
  337. echo '$ADMIN_EMAIL_ADDRESS' >> $renewals_retry_script
  338. echo ' rm ~/temp_renewletsencrypt.txt' >> $renewals_retry_script
  339. echo ' if [ ! -f ~/letsencrypt_failed ]; then' >> $renewals_retry_script
  340. echo ' touch ~/letsencrypt_failed' >> $renewals_retry_script
  341. echo ' fi' >> $renewals_retry_script
  342. echo ' fi' >> $renewals_retry_script
  343. echo ' fi' >> $renewals_retry_script
  344. echo ' done' >> $renewals_retry_script
  345. echo ' fi' >> $renewals_retry_script
  346. echo 'fi' >> $renewals_retry_script
  347. chmod +x $renewals_retry_script
  348. }
  349. function configure_php {
  350. sed -i "s/memory_limit = 128M/memory_limit = ${MAX_PHP_MEMORY}M/g" /etc/php5/fpm/php.ini
  351. sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini
  352. sed -i "s/memory_limit = -1/memory_limit = ${MAX_PHP_MEMORY}M/g" /etc/php5/cli/php.ini
  353. sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 50M/g" /etc/php5/fpm/php.ini
  354. sed -i "s/post_max_size = 8M/post_max_size = 50M/g" /etc/php5/fpm/php.ini
  355. }
  356. function install_web_server_access_control {
  357. if [ ! -f /etc/pam.d/nginx ]; then
  358. echo '#%PAM-1.0' > /etc/pam.d/nginx
  359. echo '@include common-auth' >> /etc/pam.d/nginx
  360. echo '@include common-account' >> /etc/pam.d/nginx
  361. echo '@include common-session' >> /etc/pam.d/nginx
  362. fi
  363. }
  364. function install_dynamicdns {
  365. if [[ $SYSTEM_TYPE == "mesh"* ]]; then
  366. return
  367. fi
  368. if [[ $ONION_ONLY != "no" ]]; then
  369. return
  370. fi
  371. # update to the next commit
  372. function_check set_repo_commit
  373. set_repo_commit $INSTALL_DIR/inadyn "inadyn commit" "$INADYN_COMMIT" $INADYN_REPO
  374. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  375. return
  376. fi
  377. # Here we compile from source because the current package
  378. # doesn't support https, which could result in passwords
  379. # being leaked
  380. # Debian version 1.99.4-1
  381. # https version 1.99.8
  382. apt-get -yq install build-essential curl libgnutls28-dev automake1.11
  383. if [ ! -d $INSTALL_DIR/inadyn ]; then
  384. git_clone $INADYN_REPO $INSTALL_DIR/inadyn
  385. fi
  386. if [ ! -d $INSTALL_DIR/inadyn ]; then
  387. echo 'inadyn repo not cloned'
  388. echo -n | openssl s_client -showcerts -connect github.com:443 -CApath /etc/ssl/certs
  389. exit 6785
  390. fi
  391. cd $INSTALL_DIR/inadyn
  392. git checkout $INADYN_COMMIT -b $INADYN_COMMIT
  393. set_completion_param "inadyn commit" "$INADYN_COMMIT"
  394. ./configure
  395. if [ ! "$?" = "0" ]; then
  396. exit 74890
  397. fi
  398. USE_OPENSSL=1 make
  399. if [ ! "$?" = "0" ]; then
  400. exit 74858
  401. fi
  402. make install
  403. if [ ! "$?" = "0" ]; then
  404. exit 3785
  405. fi
  406. # create an unprivileged user
  407. #chmod 600 /etc/shadow
  408. #chmod 600 /etc/gshadow
  409. #useradd -r -s /bin/false debian-inadyn
  410. #chmod 0000 /etc/shadow
  411. #chmod 0000 /etc/gshadow
  412. # create a configuration file
  413. echo 'background' > /etc/inadyn.conf
  414. echo 'verbose 1' >> /etc/inadyn.conf
  415. echo 'period 300' >> /etc/inadyn.conf
  416. echo 'startup-delay 60' >> /etc/inadyn.conf
  417. echo 'cache-dir /run/inadyn' >> /etc/inadyn.conf
  418. echo 'logfile /dev/null' >> /etc/inadyn.conf
  419. chmod 600 /etc/inadyn.conf
  420. echo '[Unit]' > /etc/systemd/system/inadyn.service
  421. echo 'Description=inadyn (DynDNS updater)' >> /etc/systemd/system/inadyn.service
  422. echo 'After=network.target' >> /etc/systemd/system/inadyn.service
  423. echo '' >> /etc/systemd/system/inadyn.service
  424. echo '[Service]' >> /etc/systemd/system/inadyn.service
  425. echo 'ExecStart=/usr/local/sbin/inadyn --config /etc/inadyn.conf' >> /etc/systemd/system/inadyn.service
  426. echo 'Restart=always' >> /etc/systemd/system/inadyn.service
  427. echo 'Type=forking' >> /etc/systemd/system/inadyn.service
  428. echo '' >> /etc/systemd/system/inadyn.service
  429. echo '[Install]' >> /etc/systemd/system/inadyn.service
  430. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/inadyn.service
  431. systemctl enable inadyn
  432. systemctl start inadyn
  433. systemctl daemon-reload
  434. mark_completed $FUNCNAME
  435. }
  436. function install_command_line_browser {
  437. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  438. return
  439. fi
  440. apt-get -yq install elinks
  441. # set the home page
  442. if ! grep -q "WWW_HOME" /home/$MY_USERNAME/.bashrc; then
  443. if ! grep -q 'control' /home/$MY_USERNAME/.bashrc; then
  444. echo "export WWW_HOME=$DEFAULT_SEARCH" >> /home/$MY_USERNAME/.bashrc
  445. else
  446. sed -i "/control/i export WWW_HOME=$DEFAULT_SEARCH" /home/$MY_USERNAME/.bashrc
  447. fi
  448. fi
  449. mark_completed $FUNCNAME
  450. }
  451. function mesh_web_server {
  452. if [ -d /etc/apache2 ]; then
  453. chroot "$rootdir" apt-get -yq remove --purge apache2
  454. chroot "$rootdir" rm -rf /etc/apache2
  455. fi
  456. chroot "$rootdir" apt-get -yq install nginx
  457. if [ ! -d $rootdir/etc/nginx ]; then
  458. echo $'Unable to install web server'
  459. exit 346825
  460. fi
  461. }
  462. function install_web_server {
  463. if [ $INSTALLING_MESH ]; then
  464. mesh_web_server
  465. return
  466. fi
  467. # update to the next commit
  468. function_check set_repo_commit
  469. set_repo_commit $INSTALL_DIR/nginx_ensite "nginx-ensite commit" "$NGINX_ENSITE_COMMIT" $NGINX_ENSITE_REPO
  470. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  471. return
  472. fi
  473. # remove apache
  474. apt-get -yq remove --purge apache2
  475. if [ -d /etc/apache2 ]; then
  476. rm -rf /etc/apache2
  477. fi
  478. # install nginx
  479. apt-get -yq install nginx
  480. apt-get -yq install php5-fpm git
  481. # Turn off logs by default
  482. sed -i 's|access_log.*|access_log = /dev/null;|g' /etc/nginx/nginx.conf
  483. sed -i 's|error_log.*|error_log = /dev/null;|g' /etc/nginx/nginx.conf
  484. # limit the number of php processes
  485. sed -i 's/; process.max =.*/process.max = 32/g' /etc/php5/fpm/php-fpm.conf
  486. #sed -i 's/;process_control_timeout =.*/process_control_timeout = 300/g' /etc/php5/fpm/php-fpm.conf
  487. if ! grep -q "pm.max_children" /etc/php5/fpm/php-fpm.conf; then
  488. echo 'pm.max_children = 10' >> /etc/php5/fpm/php-fpm.conf
  489. echo 'pm.start_servers = 2' >> /etc/php5/fpm/php-fpm.conf
  490. echo 'pm.min_spare_servers = 2' >> /etc/php5/fpm/php-fpm.conf
  491. echo 'pm.max_spare_servers = 5' >> /etc/php5/fpm/php-fpm.conf
  492. echo 'pm.max_requests = 50' >> /etc/php5/fpm/php-fpm.conf
  493. fi
  494. if [ ! -d /etc/nginx ]; then
  495. echo $"ERROR: nginx does not appear to have installed. $CHECK_MESSAGE"
  496. exit 51
  497. fi
  498. # Nginx settings
  499. echo 'user www-data;' > /etc/nginx/nginx.conf
  500. #echo "worker_processes; $CPU_CORES" >> /etc/nginx/nginx.conf
  501. echo 'pid /run/nginx.pid;' >> /etc/nginx/nginx.conf
  502. echo '' >> /etc/nginx/nginx.conf
  503. echo 'events {' >> /etc/nginx/nginx.conf
  504. echo ' worker_connections 50;' >> /etc/nginx/nginx.conf
  505. echo ' # multi_accept on;' >> /etc/nginx/nginx.conf
  506. echo '}' >> /etc/nginx/nginx.conf
  507. echo '' >> /etc/nginx/nginx.conf
  508. echo 'http {' >> /etc/nginx/nginx.conf
  509. echo ' # limit the number of connections per single IP' >> /etc/nginx/nginx.conf
  510. echo ' limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;' >> /etc/nginx/nginx.conf
  511. echo '' >> /etc/nginx/nginx.conf
  512. echo ' # limit the number of requests for a given session' >> /etc/nginx/nginx.conf
  513. echo ' limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=140r/s;' >> /etc/nginx/nginx.conf
  514. echo '' >> /etc/nginx/nginx.conf
  515. echo ' # if the request body size is more than the buffer size, then the entire (or partial) request body is written into a temporary file' >> /etc/nginx/nginx.conf
  516. echo ' client_body_buffer_size 128k;' >> /etc/nginx/nginx.conf
  517. echo '' >> /etc/nginx/nginx.conf
  518. echo ' # headerbuffer size for the request header from client, its set for testing purpose' >> /etc/nginx/nginx.conf
  519. echo ' client_header_buffer_size 3m;' >> /etc/nginx/nginx.conf
  520. echo '' >> /etc/nginx/nginx.conf
  521. echo ' # maximum number and size of buffers for large headers to read from client request' >> /etc/nginx/nginx.conf
  522. echo ' large_client_header_buffers 4 256k;' >> /etc/nginx/nginx.conf
  523. echo '' >> /etc/nginx/nginx.conf
  524. echo ' # read timeout for the request body from client, its set for testing purpose' >> /etc/nginx/nginx.conf
  525. echo ' client_body_timeout 3m;' >> /etc/nginx/nginx.conf
  526. echo '' >> /etc/nginx/nginx.conf
  527. echo ' # how long to wait for the client to send a request header, its set for testing purpose' >> /etc/nginx/nginx.conf
  528. echo ' client_header_timeout 3m;' >> /etc/nginx/nginx.conf
  529. echo '' >> /etc/nginx/nginx.conf
  530. echo ' ##' >> /etc/nginx/nginx.conf
  531. echo ' # Basic Settings' >> /etc/nginx/nginx.conf
  532. echo ' ##' >> /etc/nginx/nginx.conf
  533. echo '' >> /etc/nginx/nginx.conf
  534. echo ' sendfile on;' >> /etc/nginx/nginx.conf
  535. echo ' tcp_nopush on;' >> /etc/nginx/nginx.conf
  536. echo ' tcp_nodelay on;' >> /etc/nginx/nginx.conf
  537. echo ' keepalive_timeout 65;' >> /etc/nginx/nginx.conf
  538. echo ' types_hash_max_size 2048;' >> /etc/nginx/nginx.conf
  539. echo ' server_tokens off;' >> /etc/nginx/nginx.conf
  540. echo '' >> /etc/nginx/nginx.conf
  541. echo ' # server_names_hash_bucket_size 64;' >> /etc/nginx/nginx.conf
  542. echo ' # server_name_in_redirect off;' >> /etc/nginx/nginx.conf
  543. echo '' >> /etc/nginx/nginx.conf
  544. echo ' include /etc/nginx/mime.types;' >> /etc/nginx/nginx.conf
  545. echo ' default_type application/octet-stream;' >> /etc/nginx/nginx.conf
  546. echo '' >> /etc/nginx/nginx.conf
  547. echo ' ##' >> /etc/nginx/nginx.conf
  548. echo ' # Logging Settings' >> /etc/nginx/nginx.conf
  549. echo ' ##' >> /etc/nginx/nginx.conf
  550. echo '' >> /etc/nginx/nginx.conf
  551. echo ' access_log /dev/null;' >> /etc/nginx/nginx.conf
  552. echo ' error_log /dev/null;' >> /etc/nginx/nginx.conf
  553. echo '' >> /etc/nginx/nginx.conf
  554. echo ' ###' >> /etc/nginx/nginx.conf
  555. echo ' # Gzip Settings' >> /etc/nginx/nginx.conf
  556. echo ' ##' >> /etc/nginx/nginx.conf
  557. echo ' gzip on;' >> /etc/nginx/nginx.conf
  558. echo ' gzip_disable "msie6";' >> /etc/nginx/nginx.conf
  559. echo '' >> /etc/nginx/nginx.conf
  560. echo ' # gzip_vary on;' >> /etc/nginx/nginx.conf
  561. echo ' # gzip_proxied any;' >> /etc/nginx/nginx.conf
  562. echo ' # gzip_comp_level 6;' >> /etc/nginx/nginx.conf
  563. echo ' # gzip_buffers 16 8k;' >> /etc/nginx/nginx.conf
  564. echo ' # gzip_http_version 1.1;' >> /etc/nginx/nginx.conf
  565. echo ' # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;' >> /etc/nginx/nginx.conf
  566. echo '' >> /etc/nginx/nginx.conf
  567. echo ' ##' >> /etc/nginx/nginx.conf
  568. echo ' # Virtual Host Configs' >> /etc/nginx/nginx.conf
  569. echo ' ##' >> /etc/nginx/nginx.conf
  570. echo '' >> /etc/nginx/nginx.conf
  571. echo ' include /etc/nginx/conf.d/*.conf;' >> /etc/nginx/nginx.conf
  572. echo ' include /etc/nginx/sites-enabled/*;' >> /etc/nginx/nginx.conf
  573. echo '}' >> /etc/nginx/nginx.conf
  574. # install a script to easily enable and disable nginx virtual hosts
  575. if [ ! -d $INSTALL_DIR ]; then
  576. mkdir $INSTALL_DIR
  577. fi
  578. cd $INSTALL_DIR
  579. function_check git_clone
  580. git_clone $NGINX_ENSITE_REPO $INSTALL_DIR/nginx_ensite
  581. cd $INSTALL_DIR/nginx_ensite
  582. git checkout $NGINX_ENSITE_COMMIT -b $NGINX_ENSITE_COMMIT
  583. set_completion_param "nginx-ensite commit" "$NGINX_ENSITE_COMMIT"
  584. make install
  585. nginx_dissite default
  586. function_check configure_firewall_for_web_access
  587. configure_firewall_for_web_access
  588. mark_completed $FUNCNAME
  589. }
  590. function remove_certs {
  591. domain_name=$1
  592. if [ ! $domain_name ]; then
  593. return
  594. fi
  595. if [ -f /etc/ssl/certs/${domain_name}.dhparam ]; then
  596. rm /etc/ssl/certs/${domain_name}.dhparam
  597. fi
  598. if [ -f /etc/ssl/certs/${domain_name}.pem ]; then
  599. rm /etc/ssl/certs/${domain_name}.pem
  600. fi
  601. if [ -f /etc/ssl/certs/${domain_name}.crt ]; then
  602. rm /etc/ssl/certs/${domain_name}.crt
  603. fi
  604. if [ -f /etc/ssl/private/${domain_name}.key ]; then
  605. rm /etc/ssl/private/${domain_name}.key
  606. fi
  607. }
  608. function configure_firewall_for_web_access {
  609. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  610. return
  611. fi
  612. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  613. # docker does its own firewalling
  614. return
  615. fi
  616. if [[ $ONION_ONLY != "no" ]]; then
  617. return
  618. fi
  619. firewall_add HTTP 80 tcp
  620. firewall_add HTTPS 443 tcp
  621. mark_completed $FUNCNAME
  622. }
  623. function update_default_domain {
  624. echo $'Updating default domain'
  625. if [[ $ONION_ONLY == 'no' ]]; then
  626. if [ -d /etc/prosody ]; then
  627. if [ -f /etc/mumble-server.ini ]; then
  628. if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  629. if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
  630. sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
  631. sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
  632. systemctl restart mumble
  633. fi
  634. else
  635. if ! grep -q "${DEFAULT_DOMAIN_NAME}.pem" /etc/mumble-server.ini; then
  636. usermod -a -G ssl-cert mumble-server
  637. sed -i "s|sslCert=.*|sslCert=/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/mumble-server.ini
  638. sed -i "s|sslKey=.*|sslKey=/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key|g" /etc/mumble-server.ini
  639. systemctl restart mumble
  640. fi
  641. fi
  642. fi
  643. if [ ! -d /etc/prosody/certs ]; then
  644. mkdir /etc/prosody/certs
  645. fi
  646. cp /etc/ssl/private/xmpp* /etc/prosody/certs
  647. cp /etc/ssl/certs/xmpp* /etc/prosody/certs
  648. if [ /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  649. usermod -a -G ssl-cert prosody
  650. sed -i "s|/etc/prosody/certs/xmpp.key|/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  651. sed -i "s|/etc/prosody/certs/xmpp.crt|/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  652. sed -i "s|/etc/prosody/certs/xmpp.key|/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key|g" /etc/prosody/prosody.cfg.lua
  653. sed -i "s|/etc/prosody/certs/xmpp.crt|/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/prosody/prosody.cfg.lua
  654. fi
  655. if grep -q "/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  656. sed -i "s|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key|/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  657. fi
  658. if grep -q "/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  659. sed -i "s|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem|/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  660. fi
  661. if grep -q "/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key" /etc/prosody/prosody.cfg.lua; then
  662. sed -i "s|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key|/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key|g" /etc/prosody/prosody.cfg.lua
  663. fi
  664. if grep -q "/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem" /etc/prosody/prosody.cfg.lua; then
  665. sed -i "s|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem|/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/prosody/prosody.cfg.lua
  666. fi
  667. chown -R prosody:default /etc/prosody
  668. chmod -R 700 /etc/prosody/certs/*
  669. chmod 600 /etc/prosody/prosody.cfg.lua
  670. systemctl reload prosody
  671. fi
  672. if [ -d /home/znc/.znc ]; then
  673. echo $'znc found'
  674. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "1" ]]; then
  675. pkill znc
  676. cat /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key > /home/znc/.znc/znc.pem
  677. chown znc:znc /home/znc/.znc/znc.pem
  678. chmod 700 /home/znc/.znc/znc.pem
  679. sed -i "s|CertFile =.*|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" /etc/ngircd/ngircd.conf
  680. sed -i "s|DHFile =.*|DHFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam" /etc/ngircd/ngircd.conf
  681. sed -i "s|KeyFile =.*|KeyFile = /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key" /etc/ngircd/ngircd.conf
  682. echo $'irc certificates updated'
  683. systemctl restart ngircd
  684. su -c 'znc' - znc
  685. fi
  686. fi
  687. if [ -d /etc/dovecot ]; then
  688. if [ ${#DEFAULT_DOMAIN_NAME} -gt 0 ]; then
  689. if ! grep -q "ssl_cert = </etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" /etc/dovecot/conf.d/10-ssl.conf; then
  690. sed -i "s|#ssl_cert =.*|ssl_cert = </etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/dovecot/conf.d/10-ssl.conf
  691. sed -i "s|ssl_cert =.*|ssl_cert = </etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/dovecot/conf.d/10-ssl.conf
  692. systemctl restart dovecot
  693. fi
  694. fi
  695. fi
  696. fi
  697. }
  698. function create_default_web_site {
  699. if [ ! -f /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME} ]; then
  700. # create a web site for the default domain
  701. if [ ! -d /var/www/${DEFAULT_DOMAIN_NAME}/htdocs ]; then
  702. mkdir -p /var/www/${DEFAULT_DOMAIN_NAME}/htdocs
  703. if [ -d /root/${PROJECT_NAME} ]; then
  704. cd /root/${PROJECT_NAME}/website
  705. ./deploy.sh EN /var/www/${DEFAULT_DOMAIN_NAME}/htdocs
  706. else
  707. if [ -d /home/${MY_USERNAME}/${PROJECT_NAME} ]; then
  708. cd /home/${MY_USERNAME}/${PROJECT_NAME}
  709. ./deploy.sh EN /var/www/${DEFAULT_DOMAIN_NAME}/htdocs
  710. fi
  711. fi
  712. fi
  713. # add a config for the default domain
  714. nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
  715. if [[ $ONION_ONLY == "no" ]]; then
  716. function_check nginx_http_redirect
  717. nginx_http_redirect $DEFAULT_DOMAIN_NAME
  718. echo 'server {' >> $nginx_site
  719. echo ' listen 443 ssl;' >> $nginx_site
  720. echo ' listen [::]:443 ssl;' >> $nginx_site
  721. echo " server_name $DEFAULT_DOMAIN_NAME;" >> $nginx_site
  722. echo '' >> $nginx_site
  723. echo ' # Security' >> $nginx_site
  724. function_check nginx_ssl
  725. nginx_ssl $DEFAULT_DOMAIN_NAME
  726. function_check nginx_disable_sniffing
  727. nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
  728. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $nginx_site
  729. echo '' >> $nginx_site
  730. echo ' # Logs' >> $nginx_site
  731. echo ' access_log /dev/null;' >> $nginx_site
  732. echo ' error_log /dev/null;' >> $nginx_site
  733. echo '' >> $nginx_site
  734. echo ' # Root' >> $nginx_site
  735. echo " root /var/www/$DEFAULT_DOMAIN_NAME/htdocs;" >> $nginx_site
  736. echo '' >> $nginx_site
  737. echo ' # Index' >> $nginx_site
  738. echo ' index index.html;' >> $nginx_site
  739. echo '' >> $nginx_site
  740. echo ' # Location' >> $nginx_site
  741. echo ' location / {' >> $nginx_site
  742. function_check nginx_limits
  743. nginx_limits $DEFAULT_DOMAIN_NAME '15m'
  744. echo ' }' >> $nginx_site
  745. echo '' >> $nginx_site
  746. echo ' # Restrict access that is unnecessary anyway' >> $nginx_site
  747. echo ' location ~ /\.(ht|git) {' >> $nginx_site
  748. echo ' deny all;' >> $nginx_site
  749. echo ' }' >> $nginx_site
  750. echo '}' >> $nginx_site
  751. else
  752. echo -n '' > $nginx_site
  753. fi
  754. echo 'server {' >> $nginx_site
  755. echo " listen 127.0.0.1:$DEFAULT_DOMAIN_ONION_PORT default_server;" >> $nginx_site
  756. echo " server_name $DEFAULT_DOMAIN_NAME;" >> $nginx_site
  757. echo '' >> $nginx_site
  758. function_check nginx_disable_sniffing
  759. nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
  760. echo '' >> $nginx_site
  761. echo ' # Logs' >> $nginx_site
  762. echo ' access_log /dev/null;' >> $nginx_site
  763. echo ' error_log /dev/null;' >> $nginx_site
  764. echo '' >> $nginx_site
  765. echo ' # Root' >> $nginx_site
  766. echo " root /var/www/$DEFAULT_DOMAIN_NAME/htdocs;" >> $nginx_site
  767. echo '' >> $nginx_site
  768. echo ' # Location' >> $nginx_site
  769. echo ' location / {' >> $nginx_site
  770. function_check nginx_limits
  771. nginx_limits $DEFAULT_DOMAIN_NAME '15m'
  772. echo ' }' >> $nginx_site
  773. echo '' >> $nginx_site
  774. echo ' # Restrict access that is unnecessary anyway' >> $nginx_site
  775. echo ' location ~ /\.(ht|git) {' >> $nginx_site
  776. echo ' deny all;' >> $nginx_site
  777. echo ' }' >> $nginx_site
  778. echo '}' >> $nginx_site
  779. if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  780. function_check create_site_certificate
  781. create_site_certificate $DEFAULT_DOMAIN_NAME 'yes'
  782. fi
  783. nginx_ensite $DEFAULT_DOMAIN_NAME
  784. fi
  785. }
  786. # NOTE: deliberately no exit 0