freedombone/src/freedombone-logging

286 lines
12 KiB
Plaintext
Raw Normal View History

2015-10-31 23:55:09 +01:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Turn logging on or off
# License
# =======
#
2016-10-31 17:24:49 +01:00
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
2015-10-31 23:55:09 +01:00
#
# This program is free software: you can redistribute it and/or modify
2016-02-13 23:09:27 +01:00
# it under the terms of the GNU Affero General Public License as published by
2015-10-31 23:55:09 +01:00
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2016-02-13 23:09:27 +01:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
2015-10-31 23:55:09 +01:00
#
2016-02-13 23:09:27 +01:00
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-10-31 23:55:09 +01:00
2015-11-27 12:42:16 +01:00
PROJECT_NAME='freedombone'
2015-11-27 17:52:23 +01:00
export TEXTDOMAIN=${PROJECT_NAME}-logging
2015-11-27 12:42:16 +01:00
export TEXTDOMAINDIR="/usr/share/locale"
2015-11-16 13:05:07 +01:00
WEBSERVER_LOG_LEVEL='warn'
2017-06-16 16:43:17 +02:00
# Shredding could be used here, but especially on microSD
# or SSD it's debatable how useful shredding really is.
# Also the shred command can be very slow on Beaglebone Black
REMOVE_FILES_COMMAND='rm -rf'
2016-11-18 19:08:18 +01:00
function turn_off_rsys_logging {
sed -i 's|mail,news.none.*|mail,news.none /dev/null|g' /etc/rsyslog.conf
sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.info.*|mail.info /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.warn.*|mail.warn /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.err.*|mail.err /dev/null|g' /etc/rsyslog.conf
sed -i 's|daemon.\*.*|daemon.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.\*.*|mail.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|user.\*.*|user.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|news.none;mail.none.*|news.none;mail.none /dev/null|g' /etc/rsyslog.conf
sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none /dev/null|g' /etc/rsyslog.conf
sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
sed -i 's|cron.\*.*|cron.\* /dev/null|g' /etc/rsyslog.conf
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/wtmp*
$REMOVE_FILES_COMMAND /var/log/debug*
$REMOVE_FILES_COMMAND /var/log/cron.*
$REMOVE_FILES_COMMAND /var/log/auth.*
$REMOVE_FILES_COMMAND /var/log/mail.*
$REMOVE_FILES_COMMAND /var/log/daemon.*
$REMOVE_FILES_COMMAND /var/log/user.*
$REMOVE_FILES_COMMAND /var/log/messages*
2016-11-18 19:08:18 +01:00
}
function turn_on_rsys_logging {
sed -i 's|mail,news.none.*|mail,news.none -/var/log/messages|g' /etc/rsyslog.conf
sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /var/log/auth.log|g' /etc/rsyslog.conf
sed -i 's|mail.info.*|mail.info -/var/log/mail.info|g' /etc/rsyslog.conf
sed -i 's|mail.warn.*|mail.warn -/var/log/mail.warn|g' /etc/rsyslog.conf
sed -i 's|mail.err.*|mail.err /var/log/mail.err|g' /etc/rsyslog.conf
sed -i 's|daemon.\*.*|daemon.\* -/var/log/daemon.log|g' /etc/rsyslog.conf
sed -i 's|mail.\*.*|mail.\* -/var/log/mail.log|g' /etc/rsyslog.conf
sed -i 's|user.\*.*|user.\* -/var/log/user.log|g' /etc/rsyslog.conf
sed -i 's|news.none;mail.none.*|news.none;mail.none -/var/log/debug|g' /etc/rsyslog.conf
sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none -/var/log/syslog|g' /etc/rsyslog.conf
sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
sed -i 's|cron.\*.*|cron.\* /var/log/cron.log|g' /etc/rsyslog.conf
}
2015-10-31 23:55:09 +01:00
if [ ! "$1" ]; then
exit 1
fi
if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
2017-05-13 11:12:16 +02:00
if [ -f /var/lib/matrix/homeserver.yaml ]; then
sed -i 's|log_file:.*|log_file: /etc/matrix/homeserver.log|g' /var/lib/matrix/homeserver.yaml
if ! grep -q "#log_config:" /var/lib/matrix/homeserver.yaml; then
sed -i 's|log_config:|#log_config:|g' /var/lib/matrix/homeserver.yaml
fi
fi
2016-11-18 15:52:53 +01:00
if [ -f /etc/fail2ban/fail2ban.conf ]; then
sed -i 's|loglevel.*|loglevel = 3|g' /etc/fail2ban/fail2ban.conf
sed -i 's|logtarget.*|logtarget = /var/log/fail2ban.log|g' /etc/fail2ban/fail2ban.conf
fi
2016-11-18 15:43:19 +01:00
if [ -d /etc/tor ]; then
2017-06-03 20:51:18 +02:00
if [ ! -f /var/log/tor/notices.log ]; then
touch /var/log/tor/notices.log
chown debian-tor:debian-tor /var/log/tor/notices.log
2016-11-20 23:02:46 +01:00
fi
2017-06-03 20:51:18 +02:00
sed -i 's|#Log notice file.*|Log notice file /var/log/tor/notices.log|g' /etc/tor/torrc
sed -i 's|Log notice file.*|Log notice file /var/log/tor/notices.log|g' /etc/tor/torrc
2016-11-18 15:43:19 +01:00
fi
if [ -f /etc/mumble-server.ini ]; then
sed -i 's|logfile=.*|logfile=/var/log/mumble-server.log|g' /etc/mumble-server.ini
fi
2017-06-03 13:43:06 +02:00
if [ -f /etc/php/7.0/fpm/php-fpm.conf ]; then
sed -i 's|error_log =.*|error_log = /var/log/php-fpm.log|g' /etc/php/7.0/fpm/php-fpm.conf
2016-11-18 15:43:19 +01:00
fi
if [ -d /etc/nginx ]; then
if [ ! -d /var/log/nginx ]; then
mkdir /var/log/nginx
fi
for filename in /etc/nginx/sites-available/* ; do
filename_domain=$(echo "$filename" | awk -F '/' '{print $5}')
sed -i "s|access_log.*|access_log /var/log/nginx/$filename_domain.access.log;|g" $filename
sed -i "s|error_log.*|error_log /var/log/nginx/$filename_domain.err.log $WEBSERVER_LOG_LEVEL;|g" $filename
done
2016-11-18 16:13:26 +01:00
sed -i 's|access_log.*|access_log /var/log/nginx/access.log;|g' /etc/nginx/nginx.conf
sed -i 's|error_log.*|error_log /var/log/nginx/error.log;|g' /etc/nginx/nginx.conf
2016-11-18 15:43:19 +01:00
fi
if [ -f /etc/init.d/spamassassin ]; then
sed -i 's|DOPTIONS="-s null -d --pidfile=$PIDFILE"|DOPTIONS="-d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
fi
if [ -d /etc/prosody ]; then
if [ ! -d /var/log/prosody ]; then
mkdir /var/log/prosody
2016-11-18 16:54:05 +01:00
chown root:adm /var/log/prosody
2016-11-18 15:43:19 +01:00
fi
sed -i 's|info = "/dev/null";|info = "/var/log/prosody/prosody.log";|g' /etc/prosody/prosody.cfg.lua
sed -i 's|error = "/dev/null";|error = "/var/log/prosody/prosody.err";|g' /etc/prosody/prosody.cfg.lua
2016-11-18 16:54:05 +01:00
sed -i 's|levels = { "error" }; to = "/dev/null";|levels = { "error" }; to = "syslog";|g' /etc/prosody/prosody.cfg.lua
2016-11-18 15:43:19 +01:00
fi
if [ -d /etc/exim4 ]; then
if [ ! -d /var/log/exim4 ]; then
mkdir /var/log/exim4
fi
2016-11-28 15:03:49 +01:00
sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = +tls_peerdn|g' /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs
2016-11-28 14:41:31 +01:00
sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = +tls_peerdn|g' /etc/exim4/exim4.conf.template
2016-11-18 15:43:19 +01:00
sed -i 's|log_selector =.*|log_selector = MAIN_LOG_SELECTOR|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
fi
if [ -f /etc/dovecot/dovecot.conf ]; then
sed -i 's|log_path =.*|log_path = /var/log/dovecot.log|g' /etc/dovecot/dovecot.conf
sed -i 's|info_log_path =.*|info_log_path = /var/log/dovecot-info.log|g' /etc/dovecot/dovecot.conf
sed -i 's|debug_log_path =.*|debug_log_path = /var/log/dovecot-debug.log|g' /etc/dovecot/dovecot.conf
fi
if [ -d /etc/mysql ]; then
if [ ! -d /var/log/mysql ]; then
mkdir /var/log/mysql
fi
2016-12-04 13:10:17 +01:00
if [ -f /etc/mysql/my.cnf ]; then
sed -i 's|log_error =.*|log_error = /var/log/mysql/error.log|g' /etc/mysql/my.cnf
fi
2016-11-18 15:43:19 +01:00
fi
2016-11-18 19:08:18 +01:00
turn_on_rsys_logging
2015-10-31 23:55:09 +01:00
else
2016-12-30 23:05:34 +01:00
if [ -f /var/lib/matrix/homeserver.yaml ]; then
sed -i 's|log_file:.*|log_file: /dev/null|g' /var/lib/matrix/homeserver.yaml
2017-05-13 11:12:16 +02:00
if ! grep -q "#log_config:" /var/lib/matrix/homeserver.yaml; then
sed -i 's|log_config:|#log_config:|g' /var/lib/matrix/homeserver.yaml
fi
if [ -f /etc/matrix/homeserver.log ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /etc/matrix/homeserver.log
2017-05-13 11:12:16 +02:00
fi
if [ -f /etc/matrix/homeserver.log.1 ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /etc/matrix/homeserver.log.1
2017-05-13 11:12:16 +02:00
fi
2016-12-30 23:05:34 +01:00
fi
2016-11-18 15:43:19 +01:00
if [ -d /etc/tor ]; then
sed -i 's|#Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
sed -i 's|Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
if [ -d /var/log/tor ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/tor/*
2016-11-18 15:43:19 +01:00
rm -rf /var/log/tor
fi
fi
if [ -f /etc/mumble-server.ini ]; then
sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
if [ -d /var/log/mumble-server ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/mumble-server/*
2016-11-18 15:43:19 +01:00
rm -rf /var/log/mumble-server
fi
fi
if [ -d /var/log/radicale ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/radicale/*
2016-11-18 15:43:19 +01:00
rm -rf /var/log/radicale
fi
2017-06-03 13:43:06 +02:00
if [ -f /etc/php/7.0/fpm/php-fpm.conf ]; then
sed -i 's|error_log =.*|error_log = /dev/null|g' /etc/php/7.0/fpm/php-fpm.conf
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/php-fpm.*
2016-11-18 15:43:19 +01:00
fi
if [ -d /etc/nginx ]; then
for filename in /etc/nginx/sites-available/* ; do
sed -i 's|access_log.*|access_log /dev/null;|g' $filename
sed -i 's|warn_log.*|warn_log /dev/null;|g' $filename
sed -i 's|error_log.*|error_log /dev/null;|g' $filename
done
2016-11-18 16:13:26 +01:00
sed -i 's|access_log.*|access_log /dev/null;|g' /etc/nginx/nginx.conf
sed -i 's|error_log.*|error_log /dev/null;|g' /etc/nginx/nginx.conf
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/nginx/*
2016-11-18 15:43:19 +01:00
fi
if [ -f /etc/init.d/spamassassin ]; then
sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
fi
if [ -d /etc/prosody ]; then
sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
2016-11-18 16:54:05 +01:00
sed -i 's|levels = { "error" }; to = "syslog";|levels = { "error" }; to = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/prosody/*
2016-11-18 16:54:05 +01:00
rm -rf /var/log/prosody
2016-11-18 15:43:19 +01:00
fi
if [ -d /etc/exim4 ]; then
2016-11-28 15:03:49 +01:00
sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs
2016-11-28 14:41:31 +01:00
sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/exim4.conf.template
2016-11-18 15:43:19 +01:00
sed -i 's|log_selector =.*|log_selector = -all|g' /etc/exim4/conf.d/main/90_exim4-config_log_selector
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/exim4/*
2016-11-18 15:43:19 +01:00
fi
if [ -f /etc/dovecot/dovecot.conf ]; then
sed -i 's|log_path =.*|log_path = /dev/null|g' /etc/dovecot/dovecot.conf
sed -i 's|info_log_path =.*|info_log_path = /dev/null|g' /etc/dovecot/dovecot.conf
sed -i 's|debug_log_path =.*|debug_log_path = /dev/null|g' /etc/dovecot/dovecot.conf
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/mail.*
$REMOVE_FILES_COMMAND /var/log/dovecot*
2016-11-18 15:43:19 +01:00
fi
if [ -d /etc/mysql ]; then
if [ -d /var/log/mysql ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/mysql/*
2016-11-18 15:43:19 +01:00
fi
if [ -f /var/log/mysql.err ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/mysql.err
2016-11-18 15:43:19 +01:00
fi
if [ -f /var/log/mysql.log ]; then
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/mysql.log
2016-11-18 15:43:19 +01:00
fi
2016-12-04 13:10:17 +01:00
if [ -f /etc/mysql/my.cnf ]; then
sed -i 's|log_error =.*|log_error = /dev/null|g' /etc/mysql/my.cnf
fi
2016-11-18 15:43:19 +01:00
fi
2016-11-18 15:52:53 +01:00
if [ -f /etc/fail2ban/fail2ban.conf ]; then
sed -i 's|loglevel.*|loglevel = 1|g' /etc/fail2ban/fail2ban.conf
sed -i 's|logtarget.*|logtarget = /dev/null|g' /etc/fail2ban/fail2ban.conf
2017-06-16 16:43:17 +02:00
$REMOVE_FILES_COMMAND /var/log/fail2ban.*
2016-11-18 15:52:53 +01:00
fi
2016-11-18 19:08:18 +01:00
turn_off_rsys_logging
2015-10-31 23:55:09 +01:00
fi
2016-11-18 17:27:41 +01:00
systemctl restart syslog
2016-11-20 22:42:42 +01:00
if [ -d /etc/tor ]; then
2016-11-20 22:55:38 +01:00
if [[ "$2" != "--onion" ]]; then
systemctl restart tor
fi
2016-11-20 22:42:42 +01:00
fi
2015-10-31 23:55:09 +01:00
if [ -d /etc/nginx ]; then
2017-06-01 20:05:15 +02:00
systemctl restart php7.0-fpm
2016-11-18 15:43:19 +01:00
systemctl restart nginx
2015-10-31 23:55:09 +01:00
fi
if [ -f /etc/init.d/spamassassin ]; then
2016-11-18 15:43:19 +01:00
systemctl restart spamassassin
2015-10-31 23:55:09 +01:00
fi
2015-11-01 00:14:28 +01:00
if [ -d /etc/prosody ]; then
2016-11-18 15:43:19 +01:00
systemctl restart prosody
2015-11-01 00:14:28 +01:00
fi
2015-11-01 00:20:41 +01:00
if [ -d /etc/exim4 ]; then
2016-11-28 15:38:52 +01:00
update-exim4.conf.template -r
update-exim4.conf
dpkg-reconfigure --frontend noninteractive exim4-config
2016-11-18 15:43:19 +01:00
systemctl restart exim4
fi
if [ -d /etc/dovecot ]; then
systemctl restart dovecot
fi
if [ -f /etc/mumble-server.ini ]; then
systemctl restart mumble-server
fi
if [ -d /var/www/radicale ]; then
systemctl restart radicale
2015-11-01 00:20:41 +01:00
fi
2016-11-18 15:52:53 +01:00
if [ -d /etc/fail2ban ]; then
systemctl restart fail2ban
fi
2017-05-13 11:12:16 +02:00
if [ -d /etc/matrix ]; then
2016-12-30 23:05:34 +01:00
systemctl restart matrix
fi
2015-10-31 23:55:09 +01:00
exit 0