freedombone-logging 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none -/var/log/syslog|g' /etc/rsyslog.conf
  102. sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
  103. sed -i 's|cron.\*.*|cron.\* /var/log/cron.log|g' /etc/rsyslog.conf
  104. else
  105. if [ -d /etc/tor ]; then
  106. sed -i 's|#Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
  107. sed -i 's|Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
  108. if [ -d /var/log/tor ]; then
  109. shred -zu /var/log/tor/*
  110. rm -rf /var/log/tor
  111. fi
  112. fi
  113. if [ -f /etc/mumble-server.ini ]; then
  114. sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
  115. if [ -d /var/log/mumble-server ]; then
  116. shred -zu /var/log/mumble-server/*
  117. rm -rf /var/log/mumble-server
  118. fi
  119. fi
  120. if [ -d /var/log/radicale ]; then
  121. shred -zu /var/log/radicale/*
  122. rm -rf /var/log/radicale
  123. fi
  124. if [ -f /etc/php5/fpm/php-fpm.conf ]; then
  125. sed -i 's|error_log =.*|error_log = /dev/null|g' /etc/php5/fpm/php-fpm.conf
  126. shred -zu /var/log/php5-fpm.*
  127. fi
  128. if [ -d /etc/nginx ]; then
  129. for filename in /etc/nginx/sites-available/* ; do
  130. sed -i 's|access_log.*|access_log /dev/null;|g' $filename
  131. sed -i 's|warn_log.*|warn_log /dev/null;|g' $filename
  132. sed -i 's|error_log.*|error_log /dev/null;|g' $filename
  133. done
  134. sed -i 's|access_log.*|access_log /dev/null;|g' /etc/nginx/nginx.conf
  135. sed -i 's|error_log.*|error_log /dev/null;|g' /etc/nginx/nginx.conf
  136. shred -zu /var/log/nginx/*
  137. fi
  138. if [ -f /etc/init.d/spamassassin ]; then
  139. sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
  140. fi
  141. if [ -d /etc/prosody ]; then
  142. sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  143. sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  144. sed -i 's|levels = { "error" }; to = "syslog";|levels = { "error" }; to = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  145. shred -zu /var/log/prosody/*
  146. rm -rf /var/log/prosody
  147. fi
  148. if [ -d /etc/exim4 ]; then
  149. sed -i 's|log_selector =.*|log_selector = -all|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
  150. shred -zu /var/log/exim4/*
  151. fi
  152. if [ -f /etc/dovecot/dovecot.conf ]; then
  153. sed -i 's|log_path =.*|log_path = /dev/null|g' /etc/dovecot/dovecot.conf
  154. sed -i 's|info_log_path =.*|info_log_path = /dev/null|g' /etc/dovecot/dovecot.conf
  155. sed -i 's|debug_log_path =.*|debug_log_path = /dev/null|g' /etc/dovecot/dovecot.conf
  156. shred -zu /var/log/mail.*
  157. shred -zu /var/log/dovecot*
  158. fi
  159. if [ -d /etc/mysql ]; then
  160. if [ -d /var/log/mysql ]; then
  161. shred -zu /var/log/mysql/*
  162. fi
  163. if [ -f /var/log/mysql.err ]; then
  164. shred -zu /var/log/mysql.err
  165. fi
  166. if [ -f /var/log/mysql.log ]; then
  167. shred -zu /var/log/mysql.log
  168. fi
  169. sed -i 's|log_error =.*|log_error = /dev/null|g' /etc/mysql/my.cnf
  170. fi
  171. if [ -f /etc/fail2ban/fail2ban.conf ]; then
  172. sed -i 's|loglevel.*|loglevel = 1|g' /etc/fail2ban/fail2ban.conf
  173. sed -i 's|logtarget.*|logtarget = /dev/null|g' /etc/fail2ban/fail2ban.conf
  174. shred -zu /var/log/fail2ban.*
  175. fi
  176. sed -i 's|mail,news.none.*|mail,news.none /dev/null|g' /etc/rsyslog.conf
  177. sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /dev/null|g' /etc/rsyslog.conf
  178. sed -i 's|mail.info.*|mail.info /dev/null|g' /etc/rsyslog.conf
  179. sed -i 's|mail.warn.*|mail.warn /dev/null|g' /etc/rsyslog.conf
  180. sed -i 's|mail.err.*|mail.err /dev/null|g' /etc/rsyslog.conf
  181. sed -i 's|daemon.\*.*|daemon.\* /dev/null|g' /etc/rsyslog.conf
  182. sed -i 's|mail.\*.*|mail.\* /dev/null|g' /etc/rsyslog.conf
  183. sed -i 's|user.\*.*|user.\* /dev/null|g' /etc/rsyslog.conf
  184. sed -i 's|news.none;mail.none.*|news.none;mail.none /dev/null|g' /etc/rsyslog.conf
  185. sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none /dev/null|g' /etc/rsyslog.conf
  186. sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
  187. sed -i 's|cron.\*.*|cron.\* /dev/null|g' /etc/rsyslog.conf
  188. shred -zu /var/log/debug*
  189. shred -zu /var/log/cron.*
  190. shred -zu /var/log/auth.*
  191. shred -zu /var/log/mail.*
  192. shred -zu /var/log/daemon.*
  193. shred -zu /var/log/user.*
  194. shred -zu /var/log/messages*
  195. fi
  196. systemctl restart syslog
  197. if [ -d /etc/nginx ]; then
  198. systemctl restart php5-fpm
  199. systemctl restart nginx
  200. fi
  201. if [ -f /etc/init.d/spamassassin ]; then
  202. systemctl restart spamassassin
  203. fi
  204. if [ -d /etc/prosody ]; then
  205. systemctl restart prosody
  206. fi
  207. if [ -d /etc/exim4 ]; then
  208. systemctl restart exim4
  209. fi
  210. if [ -d /etc/dovecot ]; then
  211. systemctl restart dovecot
  212. fi
  213. if [ -d /etc/tor ]; then
  214. systemctl reload tor
  215. fi
  216. if [ -f /etc/mumble-server.ini ]; then
  217. systemctl restart mumble-server
  218. fi
  219. if [ -d /var/www/radicale ]; then
  220. systemctl restart radicale
  221. fi
  222. if [ -d /etc/fail2ban ]; then
  223. systemctl restart fail2ban
  224. fi
  225. exit 0