freedombone-app-dokuwiki 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Dokuwiki application
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 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. VARIANTS='full full-vim writer'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. DOKUWIKI_DOMAIN_NAME=
  34. DOKUWIKI_ADMIN_PASSWORD=
  35. DOKUWIKI_TITLE="${PROJECT_NAME} Dokuwiki"
  36. DOKUWIKI_CODE=
  37. DOKUWIKI_ONION_PORT=8089
  38. dokuwiki_variables=(ONION_ONLY
  39. MY_USERNAME
  40. DOKUWIKI_TITLE
  41. DOKUWIKI_DOMAIN_NAME
  42. DOKUWIKI_CODE
  43. DDNS_PROVIDER)
  44. function install_interactive_dokuwiki {
  45. if [[ $ONION_ONLY != "no" ]]; then
  46. DOKUWIKI_TITLE=$'My Dokuwiki'
  47. DOKUWIKI_DOMAIN_NAME='dokuwiki.local'
  48. write_config_param "DOKUWIKI_TITLE" "$DOKUWIKI_TITLE"
  49. write_config_param "DOKUWIKI_DOMAIN_NAME" "$DOKUWIKI_DOMAIN_NAME"
  50. else
  51. function_check interactive_site_details_with_title
  52. interactive_site_details_with_title "dokuwiki" "DOKUWIKI_TITLE" "DOKUWIKI_DOMAIN_NAME" "DOKUWIKI_CODE"
  53. fi
  54. APP_INSTALLED=1
  55. }
  56. function change_password_dokuwiki {
  57. curr_username="$1"
  58. new_user_password="$2"
  59. if grep "$curr_username:" /var/lib/dokuwiki/acl/users.auth.php; then
  60. HASHED_DOKUWIKI_PASSWORD=$(echo -n "$new_user_password" | md5sum | awk -F ' ' '{print $1}')
  61. existing_user=$(cat /var/lib/dokuwiki/acl/users.auth.php | grep "$curr_username:" | hean -n 1)
  62. if [[ "$existing_user" == *":admin,"* ]]; then
  63. sed -i "s|$curr_username:.*|$curr_username:$HASHED_DOKUWIKI_PASSWORD:$curr_username:$curr_username@$HOSTNAME:admin,user,upload|g" /var/lib/dokuwiki/acl/users.auth.php
  64. else
  65. sed -i "s|$curr_username:.*|$curr_username:$HASHED_DOKUWIKI_PASSWORD:$curr_username:$curr_username@$HOSTNAME:user,upload|g" /var/lib/dokuwiki/acl/users.auth.php
  66. fi
  67. chmod 640 /var/lib/dokuwiki/acl/users.auth.php
  68. ${PROJECT_NAME}-pass -u $curr_username -a dokuwiki -p "$new_user_password"
  69. fi
  70. }
  71. function add_user_dokuwiki {
  72. new_username="$1"
  73. new_user_password="$2"
  74. HASHED_DOKUWIKI_PASSWORD=$(echo -n "$new_user_password" | md5sum | awk -F ' ' '{print $1}')
  75. echo "$new_username:$HASHED_DOKUWIKI_PASSWORD:$new_username:$new_username@$HOSTNAME:user,upload" >> /var/lib/dokuwiki/acl/users.auth.php
  76. chmod 640 /var/lib/dokuwiki/acl/users.auth.php
  77. ${PROJECT_NAME}-pass -u "$new_username" -a dokuwiki -p "$new_user_password"
  78. }
  79. function remove_user_dokuwiki {
  80. remove_username="$1"
  81. if grep "$remove_username:" /var/lib/dokuwiki/acl/users.auth.php; then
  82. sed -i "/$remove_username:/d" /var/lib/dokuwiki/acl/users.auth.php
  83. ${PROJECT_NAME}-pass -u "$remove_username" --rmapp dokuwiki
  84. fi
  85. }
  86. function reconfigure_dokuwiki {
  87. echo -n ''
  88. }
  89. function upgrade_dokuwiki {
  90. echo -n ''
  91. }
  92. function backup_local_dokuwiki {
  93. source_directory=/var/lib/dokuwiki
  94. if [ -d $source_directory ]; then
  95. dest_directory=dokuwiki
  96. function_check backup_directory_to_usb
  97. backup_directory_to_usb $source_directory $dest_directory
  98. backup_directory_to_usb /etc/dokuwiki dokuwiki2
  99. fi
  100. }
  101. function restore_local_dokuwiki {
  102. if [ -d /var/lib/dokuwiki ]; then
  103. echo $"Restoring Dokuwiki installation"
  104. function_check get_completion_param
  105. DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
  106. temp_restore_dir=/root/tempdokuwiki
  107. function_check restore_directory_from_usb
  108. if [ -d ${USB_MOUNT}/backup/dokuwiki ]; then
  109. restore_directory_from_usb ${temp_restore_dir} dokuwiki
  110. else
  111. restore_directory_from_usb ${temp_restore_dir} wiki
  112. fi
  113. cp -r ${temp_restore_dir}/var/lib/dokuwiki/* /var/lib/dokuwiki/
  114. if [ ! "$?" = "0" ]; then
  115. function_check restore_directory_from_usb
  116. set_user_permissions
  117. function_check backup_unmount_drive
  118. backup_unmount_drive
  119. exit 868
  120. fi
  121. if [ -d ${USB_MOUNT}/backup/wiki2 ]; then
  122. restore_directory_from_usb ${temp_restore_dir}2 wiki2
  123. else
  124. restore_directory_from_usb ${temp_restore_dir}2 dokuwiki2
  125. fi
  126. cp -r ${temp_restore_dir}2/etc/dokuwiki/* /etc/dokuwiki/
  127. if [ ! "$?" = "0" ]; then
  128. function_check set_user_permissions
  129. set_user_permissions
  130. function_check backup_unmount_drive
  131. backup_unmount_drive
  132. exit 869
  133. fi
  134. rm -rf ${temp_restore_dir}
  135. rm -rf ${temp_restore_dir}2
  136. #rm -rf /var/lib/dokuwiki/data/cache/*
  137. #rm -rf /var/lib/dokuwiki/data/meta/*
  138. chmod -R 755 /var/lib/dokuwiki/data
  139. chown -R www-data:www-data /var/lib/dokuwiki/data
  140. chown -R www-data:www-data /var/lib/dokuwiki/*
  141. # Ensure that the bundled SSL cert is being used
  142. if [ -f /etc/ssl/certs/${DOKUWIKI_DOMAIN_NAME}.bundle.crt ]; then
  143. sed -i "s|${DOKUWIKI_DOMAIN_NAME}.crt|${DOKUWIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${DOKUWIKI_DOMAIN_NAME}
  144. fi
  145. if [ -d /etc/letsencrypt/live/${DOKUWIKI_DOMAIN_NAME} ]; then
  146. ln -s /etc/letsencrypt/live/${DOKUWIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${DOKUWIKI_DOMAIN_NAME}.key
  147. ln -s /etc/letsencrypt/live/${DOKUWIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${DOKUWIKI_DOMAIN_NAME}.pem
  148. fi
  149. echo $"Restore of Dokuwiki complete"
  150. fi
  151. }
  152. function backup_remote_dokuwiki {
  153. if [ -d /etc/dokuwiki ]; then
  154. echo $"Backing up dokuwiki"
  155. backup_directory_to_friend /var/lib/dokuwiki dokuwiki
  156. backup_directory_to_friend /etc/dokuwiki dokuwiki2
  157. fi
  158. }
  159. function restore_remote_dokuwiki {
  160. if [ -d $SERVER_DIRECTORY/backup/dokuwiki ]; then
  161. function_check get_completion_param
  162. DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
  163. echo $"Restoring Dokuwiki installation $DOKUWIKI_DOMAIN_NAME"
  164. function_check restore_directory_from_friend
  165. restore_directory_from_friend /root/tempdokuwiki dokuwiki
  166. cp -r /root/tempdokuwiki/var/lib/dokuwiki/* /var/lib/dokuwiki/
  167. if [ ! "$?" = "0" ]; then
  168. exit 868
  169. fi
  170. restore_directory_from_friend /root/tempdokuwiki2 dokuwiki2
  171. cp -r /root/tempdokuwiki2/etc/dokuwiki/* /etc/dokuwiki/
  172. if [ ! "$?" = "0" ]; then
  173. exit 869
  174. fi
  175. rm -rf /root/tempdokuwiki
  176. rm -rf /root/tempdokuwiki2
  177. #rm -rf /var/lib/dokuwiki/data/cache/*
  178. #rm -rf /var/lib/dokuwiki/data/meta/*
  179. chmod -R 755 /var/lib/dokuwiki/data
  180. chown -R www-data:www-data /var/lib/dokuwiki/data
  181. chown -R www-data:www-data /var/lib/dokuwiki/*
  182. # Ensure that the bundled SSL cert is being used
  183. if [ -f /etc/ssl/certs/${DOKUWIKI_DOMAIN_NAME}.bundle.crt ]; then
  184. sed -i "s|${DOKUWIKI_DOMAIN_NAME}.crt|${DOKUWIKI_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${DOKUWIKI_DOMAIN_NAME}
  185. fi
  186. if [ -d /etc/letsencrypt/live/${DOKUWIKI_DOMAIN_NAME} ]; then
  187. ln -s /etc/letsencrypt/live/${DOKUWIKI_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${DOKUWIKI_DOMAIN_NAME}.key
  188. ln -s /etc/letsencrypt/live/${DOKUWIKI_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${DOKUWIKI_DOMAIN_NAME}.pem
  189. fi
  190. echo $"Restore of Dokuwiki complete"
  191. fi
  192. }
  193. function remove_dokuwiki {
  194. if [ ${#DOKUWIKI_DOMAIN_NAME} -eq 0 ]; then
  195. return
  196. fi
  197. function_check remove_onion_service
  198. remove_onion_service dokuwiki ${DOKUWIKI_ONION_PORT}
  199. nginx_dissite $DOKUWIKI_DOMAIN_NAME
  200. remove_certs $DOKUWIKI_DOMAIN_NAME
  201. if [ -f /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME ]; then
  202. rm /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  203. fi
  204. apt-get -yq remove --purge dokuwiki
  205. if [ ! -d /var/www/$DOKUWIKI_DOMAIN_NAME ]; then
  206. rm -rf /var/www/$DOKUWIKI_DOMAIN_NAME
  207. fi
  208. if [ -d /var/lib/dokuwiki ]; then
  209. rm -rf /var/lib/dokuwiki
  210. fi
  211. if [ -d /etc/dokuwiki ]; then
  212. rm -rf /etc/dokuwiki
  213. fi
  214. if [ -d /usr/share/dokuwiki ]; then
  215. rm -rf /usr/share/dokuwiki
  216. fi
  217. remove_completion_param "install_dokuwiki"
  218. remove_completion_param "dokuwiki domain"
  219. sed -i '/dokuwiki/d' $COMPLETION_FILE
  220. function_check remove_ddns_domain
  221. remove_ddns_domain $DOKUWIKI_DOMAIN_NAME
  222. }
  223. function install_dokuwiki {
  224. if [ ! $DOKUWIKI_DOMAIN_NAME ]; then
  225. return
  226. fi
  227. apt-get -yq install dokuwiki
  228. apt-get -yq remove --purge apache*
  229. if [ -d /etc/apache2 ]; then
  230. rm -rf /etc/apache2
  231. echo $'Removed Apache installation after Dokuwiki install'
  232. fi
  233. if [ ! -d /var/www/$DOKUWIKI_DOMAIN_NAME ]; then
  234. mkdir /var/www/$DOKUWIKI_DOMAIN_NAME
  235. fi
  236. if [ -d /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs ]; then
  237. rm -rf /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
  238. fi
  239. ln -s /usr/share/dokuwiki /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
  240. if [ ! -d /var/lib/dokuwiki/custom ]; then
  241. mkdir /var/lib/dokuwiki/custom
  242. fi
  243. cp /etc/dokuwiki/local.php.dist /var/lib/dokuwiki/custom/local.php
  244. if [ ! -f /etc/dokuwiki/local.php ]; then
  245. ln -s /var/lib/dokuwiki/custom/local.php /etc/dokuwiki/local.php
  246. fi
  247. chown www-data /var/lib/dokuwiki/custom
  248. chown www-data /var/lib/dokuwiki/custom/local.php
  249. chown -R www-data /etc/dokuwiki
  250. chown -R www-data /usr/share/dokuwiki/lib/
  251. chmod 600 /var/lib/dokuwiki/custom/local.php
  252. chmod -R 755 /usr/share/dokuwiki/lib
  253. sed -i 's|//$conf|$conf|g' /var/lib/dokuwiki/custom/local.php
  254. sed -i "s|joe|$MY_USERNAME|g" /var/lib/dokuwiki/custom/local.php
  255. sed -i "s|Debian Dokuwiki|$DOKUWIKI_TITLE|g" /etc/dokuwiki/local.php
  256. sed -i "s|Debian DokuWiki|$DOKUWIKI_TITLE|g" /etc/dokuwiki/local.php
  257. # set the admin user
  258. sed -i "s/@admin/$MY_USERNAME/g" /etc/dokuwiki/local.php
  259. # disallow registration of new users
  260. if ! grep -q "disableactions" /etc/dokuwiki/local.php; then
  261. echo "\$conf['disableactions'] = 'register';" >> /etc/dokuwiki/local.php
  262. fi
  263. if ! grep -q "disableactions" /var/lib/dokuwiki/custom/local.php; then
  264. echo "\$conf['disableactions'] = 'register';" >> /var/lib/dokuwiki/custom/local.php
  265. fi
  266. if ! grep -q "authtype" /var/lib/dokuwiki/custom/local.php; then
  267. echo "\$conf['authtype'] = 'authplain';" >> /var/lib/dokuwiki/custom/local.php
  268. fi
  269. if ! grep -q "authtype" /etc/dokuwiki/local.php; then
  270. echo "\$conf['authtype'] = 'authplain';" >> /etc/dokuwiki/local.php
  271. fi
  272. if [ -f $IMAGE_PASSWORD_FILE ]; then
  273. DOKUWIKI_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  274. else
  275. if [ ! $DOKUWIKI_ADMIN_PASSWORD ]; then
  276. DOKUWIKI_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  277. fi
  278. fi
  279. HASHED_DOKUWIKI_PASSWORD=$(echo -n "$DOKUWIKI_ADMIN_PASSWORD" | md5sum | awk -F ' ' '{print $1}')
  280. echo -n "$MY_USERNAME:$HASHED_DOKUWIKI_PASSWORD:$MY_NAME:$MY_EMAIL:admin,user,upload" > /var/lib/dokuwiki/acl/users.auth.php
  281. chmod 640 /var/lib/dokuwiki/acl/users.auth.php
  282. if ! grep -q "video/ogg" /etc/dokuwiki/mime.conf; then
  283. echo 'ogv video/ogg' >> /etc/dokuwiki/mime.conf
  284. fi
  285. if ! grep -q "video/mp4" /etc/dokuwiki/mime.conf; then
  286. echo 'mp4 video/mp4' >> /etc/dokuwiki/mime.conf
  287. fi
  288. if ! grep -q "video/webm" /etc/dokuwiki/mime.conf; then
  289. echo 'webm video/webm' >> /etc/dokuwiki/mime.conf
  290. fi
  291. DOKUWIKI_ONION_HOSTNAME=$(add_onion_service dokuwiki 80 ${DOKUWIKI_ONION_PORT})
  292. set_completion_param "dokuwiki domain" "${DOKUWIKI_DOMAIN_NAME}"
  293. if [[ $ONION_ONLY == "no" ]]; then
  294. function_check nginx_http_redirect
  295. nginx_http_redirect $DOKUWIKI_DOMAIN_NAME
  296. echo 'server {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  297. echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  298. echo ' listen [::]:443 ssl;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  299. echo " root /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  300. echo " server_name $DOKUWIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  301. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  302. echo " error_log /dev/null;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  303. echo ' index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  304. echo ' charset utf-8;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  305. echo ' proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  306. function_check nginx_ssl
  307. nginx_ssl $DOKUWIKI_DOMAIN_NAME
  308. function_check nginx_disable_sniffing
  309. nginx_disable_sniffing $DOKUWIKI_DOMAIN_NAME
  310. echo ' add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  311. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  312. echo ' # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  313. echo ' location / {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  314. function_check nginx_limits
  315. nginx_limits $DOKUWIKI_DOMAIN_NAME
  316. echo ' rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  317. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  318. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  319. nginx_keybase $DOKUWIKI_DOMAIN_NAME
  320. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  321. echo ' # statically serve these file types when possible' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  322. echo ' # otherwise fall back to front controller' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  323. echo ' # allow browser to cache them' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  324. echo ' # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  325. echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  326. echo ' expires 30d;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  327. echo ' try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  328. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  329. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  330. echo ' # block these file types' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  331. echo ' location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  332. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  333. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  334. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  335. echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  336. echo ' # or a unix socket' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  337. echo ' location ~* \.php$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  338. function_check nginx_limits
  339. nginx_limits $DOKUWIKI_DOMAIN_NAME
  340. echo ' # Zero-day exploit defense.' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  341. echo ' # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  342. echo " # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  343. echo " # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  344. echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  345. echo " # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  346. echo ' try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  347. echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  348. echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  349. echo ' # With php5-cgi alone:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  350. echo ' # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  351. echo ' # With php5-fpm:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  352. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  353. echo ' include fastcgi_params;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  354. echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  355. echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  356. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  357. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  358. echo ' # deny access to all dot files' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  359. echo ' location ~ /\. {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  360. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  361. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  362. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  363. echo ' #deny access to store' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  364. echo ' location ~ /store {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  365. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  366. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  367. echo ' location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  368. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  369. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  370. echo ' location ~ /\.ht {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  371. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  372. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  373. echo '}' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  374. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  375. else
  376. echo -n '' > /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  377. fi
  378. echo 'server {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  379. echo " listen 127.0.0.1:${DOKUWIKI_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  380. echo " root /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  381. echo " server_name $DOKUWIKI_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  382. echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  383. echo " error_log /dev/null;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  384. echo ' index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  385. echo ' charset utf-8;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  386. echo ' proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  387. function_check nginx_disable_sniffing
  388. nginx_disable_sniffing $DOKUWIKI_DOMAIN_NAME
  389. echo ' add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  390. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  391. echo ' # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  392. echo ' location / {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  393. function_check nginx_limits
  394. nginx_limits $DOKUWIKI_DOMAIN_NAME
  395. echo ' rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  396. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  397. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  398. nginx_keybase $DOKUWIKI_DOMAIN_NAME
  399. echo ' # statically serve these file types when possible' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  400. echo ' # otherwise fall back to front controller' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  401. echo ' # allow browser to cache them' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  402. echo ' # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  403. echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  404. echo ' expires 30d;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  405. echo ' try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  406. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  407. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  408. echo ' # block these file types' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  409. echo ' location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  410. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  411. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  412. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  413. echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  414. echo ' # or a unix socket' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  415. echo ' location ~* \.php$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  416. function_check nginx_limits
  417. nginx_limits $DOKUWIKI_DOMAIN_NAME
  418. echo ' # Zero-day exploit defense.' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  419. echo ' # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  420. echo " # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  421. echo " # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  422. echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  423. echo " # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  424. echo ' try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  425. echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  426. echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  427. echo ' # With php5-cgi alone:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  428. echo ' # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  429. echo ' # With php5-fpm:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  430. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  431. echo ' include fastcgi_params;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  432. echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  433. echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  434. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  435. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  436. echo ' # deny access to all dot files' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  437. echo ' location ~ /\. {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  438. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  439. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  440. echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  441. echo ' #deny access to store' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  442. echo ' location ~ /store {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  443. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  444. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  445. echo ' location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  446. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  447. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  448. echo ' location ~ /\.ht {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  449. echo ' deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  450. echo ' }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  451. echo '}' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
  452. function_check create_site_certificate
  453. create_site_certificate $DOKUWIKI_DOMAIN_NAME
  454. function_check configure_php
  455. configure_php
  456. nginx_ensite $DOKUWIKI_DOMAIN_NAME
  457. systemctl restart php5-fpm
  458. systemctl restart nginx
  459. function_check add_ddns_domain
  460. add_ddns_domain $DOKUWIKI_DOMAIN_NAME
  461. ${PROJECT_NAME}-pass -u $MY_USERNAME -a dokuwiki -p "$DOKUWIKI_ADMIN_PASSWORD"
  462. APP_INSTALLED=1
  463. }
  464. # NOTE: deliberately no exit 0