freedombone-logging 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Turn logging on or off
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU Affero General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. export TEXTDOMAIN=${PROJECT_NAME}-logging
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. WEBSERVER_LOG_LEVEL='warn'
  33. if [ ! "$1" ]; then
  34. exit 1
  35. fi
  36. if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
  37. if [ -f /etc/fail2ban/fail2ban.conf ]; then
  38. sed -i 's|loglevel.*|loglevel = 3|g' /etc/fail2ban/fail2ban.conf
  39. sed -i 's|logtarget.*|logtarget = /var/log/fail2ban.log|g' /etc/fail2ban/fail2ban.conf
  40. fi
  41. if [ -d /etc/tor ]; then
  42. sed -i 's|#Log notice file.*|Log notice file /var/log/tor.log|g' /etc/tor/torrc
  43. sed -i 's|Log notice file.*|Log notice file /var/log/tor.log|g' /etc/tor/torrc
  44. fi
  45. if [ -f /etc/mumble-server.ini ]; then
  46. sed -i 's|logfile=.*|logfile=/var/log/mumble-server.log|g' /etc/mumble-server.ini
  47. fi
  48. if [ -f /etc/php5/fpm/php-fpm.conf ]; then
  49. sed -i 's|error_log =.*|error_log = /var/log/php5-fpm.log|g' /etc/php5/fpm/php-fpm.conf
  50. fi
  51. if [ -d /etc/nginx ]; then
  52. if [ ! -d /var/log/nginx ]; then
  53. mkdir /var/log/nginx
  54. fi
  55. for filename in /etc/nginx/sites-available/* ; do
  56. filename_domain=$(echo "$filename" | awk -F '/' '{print $5}')
  57. sed -i "s|access_log.*|access_log /var/log/nginx/$filename_domain.access.log;|g" $filename
  58. sed -i "s|error_log.*|error_log /var/log/nginx/$filename_domain.err.log $WEBSERVER_LOG_LEVEL;|g" $filename
  59. done
  60. sed -i 's|access_log.*|access_log /var/log/nginx/access.log;|g' /etc/nginx/nginx.conf
  61. sed -i 's|error_log.*|error_log /var/log/nginx/error.log;|g' /etc/nginx/nginx.conf
  62. fi
  63. if [ -f /etc/init.d/spamassassin ]; then
  64. sed -i 's|DOPTIONS="-s null -d --pidfile=$PIDFILE"|DOPTIONS="-d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
  65. fi
  66. if [ -d /etc/prosody ]; then
  67. if [ ! -d /var/log/prosody ]; then
  68. mkdir /var/log/prosody
  69. chown root:adm /var/log/prosody
  70. fi
  71. sed -i 's|info = "/dev/null";|info = "/var/log/prosody/prosody.log";|g' /etc/prosody/prosody.cfg.lua
  72. sed -i 's|error = "/dev/null";|error = "/var/log/prosody/prosody.err";|g' /etc/prosody/prosody.cfg.lua
  73. sed -i 's|levels = { "error" }; to = "/dev/null";|levels = { "error" }; to = "syslog";|g' /etc/prosody/prosody.cfg.lua
  74. fi
  75. if [ -d /etc/exim4 ]; then
  76. if [ ! -d /var/log/exim4 ]; then
  77. mkdir /var/log/exim4
  78. fi
  79. sed -i 's|log_selector =.*|log_selector = MAIN_LOG_SELECTOR|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
  80. fi
  81. if [ -f /etc/dovecot/dovecot.conf ]; then
  82. sed -i 's|log_path =.*|log_path = /var/log/dovecot.log|g' /etc/dovecot/dovecot.conf
  83. sed -i 's|info_log_path =.*|info_log_path = /var/log/dovecot-info.log|g' /etc/dovecot/dovecot.conf
  84. sed -i 's|debug_log_path =.*|debug_log_path = /var/log/dovecot-debug.log|g' /etc/dovecot/dovecot.conf
  85. fi
  86. if [ -d /etc/mysql ]; then
  87. if [ ! -d /var/log/mysql ]; then
  88. mkdir /var/log/mysql
  89. fi
  90. sed -i 's|log_error =.*|log_error = /var/log/mysql/error.log|g' /etc/mysql/my.cnf
  91. fi
  92. sed -i 's|mail,news.none.*|mail,news.none -/var/log/messages|g' /etc/rsyslog.conf
  93. sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /var/log/auth.log|g' /etc/rsyslog.conf
  94. sed -i 's|mail.info.*|mail.info -/var/log/mail.info|g' /etc/rsyslog.conf
  95. sed -i 's|mail.warn.*|mail.warn -/var/log/mail.warn|g' /etc/rsyslog.conf
  96. sed -i 's|mail.err.*|mail.err /var/log/mail.err|g' /etc/rsyslog.conf
  97. sed -i 's|daemon.\*.*|daemon.\* -/var/log/daemon.log|g' /etc/rsyslog.conf
  98. sed -i 's|mail.\*.*|mail.\* -/var/log/mail.log|g' /etc/rsyslog.conf
  99. sed -i 's|user.\*.*|user.\* -/var/log/user.log|g' /etc/rsyslog.conf
  100. sed -i 's|news.none;mail.none.*|news.none;mail.none -/var/log/debug|g' /etc/rsyslog.conf
  101. else
  102. if [ -d /etc/tor ]; then
  103. sed -i 's|#Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
  104. sed -i 's|Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
  105. if [ -d /var/log/tor ]; then
  106. shred -zu /var/log/tor/*
  107. rm -rf /var/log/tor
  108. fi
  109. fi
  110. if [ -f /etc/mumble-server.ini ]; then
  111. sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
  112. if [ -d /var/log/mumble-server ]; then
  113. shred -zu /var/log/mumble-server/*
  114. rm -rf /var/log/mumble-server
  115. fi
  116. fi
  117. if [ -d /var/log/radicale ]; then
  118. shred -zu /var/log/radicale/*
  119. rm -rf /var/log/radicale
  120. fi
  121. if [ -f /etc/php5/fpm/php-fpm.conf ]; then
  122. sed -i 's|error_log =.*|error_log = /dev/null|g' /etc/php5/fpm/php-fpm.conf
  123. shred -zu /var/log/php5-fpm.*
  124. fi
  125. if [ -d /etc/nginx ]; then
  126. for filename in /etc/nginx/sites-available/* ; do
  127. sed -i 's|access_log.*|access_log /dev/null;|g' $filename
  128. sed -i 's|warn_log.*|warn_log /dev/null;|g' $filename
  129. sed -i 's|error_log.*|error_log /dev/null;|g' $filename
  130. done
  131. sed -i 's|access_log.*|access_log /dev/null;|g' /etc/nginx/nginx.conf
  132. sed -i 's|error_log.*|error_log /dev/null;|g' /etc/nginx/nginx.conf
  133. shred -zu /var/log/nginx/*
  134. fi
  135. if [ -f /etc/init.d/spamassassin ]; then
  136. sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
  137. fi
  138. if [ -d /etc/prosody ]; then
  139. sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  140. sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  141. sed -i 's|levels = { "error" }; to = "syslog";|levels = { "error" }; to = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  142. shred -zu /var/log/prosody/*
  143. rm -rf /var/log/prosody
  144. fi
  145. if [ -d /etc/exim4 ]; then
  146. sed -i 's|log_selector =.*|log_selector = -all|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
  147. shred -zu /var/log/exim4/*
  148. fi
  149. if [ -f /etc/dovecot/dovecot.conf ]; then
  150. sed -i 's|log_path =.*|log_path = /dev/null|g' /etc/dovecot/dovecot.conf
  151. sed -i 's|info_log_path =.*|info_log_path = /dev/null|g' /etc/dovecot/dovecot.conf
  152. sed -i 's|debug_log_path =.*|debug_log_path = /dev/null|g' /etc/dovecot/dovecot.conf
  153. shred -zu /var/log/mail.*
  154. shred -zu /var/log/dovecot*
  155. fi
  156. if [ -d /etc/mysql ]; then
  157. if [ -d /var/log/mysql ]; then
  158. shred -zu /var/log/mysql/*
  159. fi
  160. if [ -f /var/log/mysql.err ]; then
  161. shred -zu /var/log/mysql.err
  162. fi
  163. if [ -f /var/log/mysql.log ]; then
  164. shred -zu /var/log/mysql.log
  165. fi
  166. sed -i 's|log_error =.*|log_error = /dev/null|g' /etc/mysql/my.cnf
  167. fi
  168. if [ -f /etc/fail2ban/fail2ban.conf ]; then
  169. sed -i 's|loglevel.*|loglevel = 1|g' /etc/fail2ban/fail2ban.conf
  170. sed -i 's|logtarget.*|logtarget = /dev/null|g' /etc/fail2ban/fail2ban.conf
  171. shred -zu /var/log/fail2ban.*
  172. fi
  173. sed -i 's|mail,news.none.*|mail,news.none /dev/null|g' /etc/rsyslog.conf
  174. sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /dev/null|g' /etc/rsyslog.conf
  175. sed -i 's|mail.info.*|mail.info /dev/null|g' /etc/rsyslog.conf
  176. sed -i 's|mail.warn.*|mail.warn /dev/null|g' /etc/rsyslog.conf
  177. sed -i 's|mail.err.*|mail.err /dev/null|g' /etc/rsyslog.conf
  178. sed -i 's|daemon.\*.*|daemon.\* /dev/null|g' /etc/rsyslog.conf
  179. sed -i 's|mail.\*.*|mail.\* /dev/null|g' /etc/rsyslog.conf
  180. sed -i 's|user.\*.*|user.\* /dev/null|g' /etc/rsyslog.conf
  181. sed -i 's|news.none;mail.none.*|news.none;mail.none /dev/null|g' /etc/rsyslog.conf
  182. shred -zu /var/log/debug*
  183. shred -zu /var/log/auth.*
  184. shred -zu /var/log/mail.*
  185. shred -zu /var/log/daemon.*
  186. shred -zu /var/log/user.*
  187. shred -zu /var/log/messages*
  188. fi
  189. systemctl restart syslog
  190. if [ -d /etc/nginx ]; then
  191. systemctl restart php5-fpm
  192. systemctl restart nginx
  193. fi
  194. if [ -f /etc/init.d/spamassassin ]; then
  195. systemctl restart spamassassin
  196. fi
  197. if [ -d /etc/prosody ]; then
  198. systemctl restart prosody
  199. fi
  200. if [ -d /etc/exim4 ]; then
  201. systemctl restart exim4
  202. fi
  203. if [ -d /etc/dovecot ]; then
  204. systemctl restart dovecot
  205. fi
  206. if [ -d /etc/tor ]; then
  207. systemctl reload tor
  208. fi
  209. if [ -f /etc/mumble-server.ini ]; then
  210. systemctl restart mumble-server
  211. fi
  212. if [ -d /var/www/radicale ]; then
  213. systemctl restart radicale
  214. fi
  215. if [ -d /etc/fail2ban ]; then
  216. systemctl restart fail2ban
  217. fi
  218. exit 0