freedombone/src/freedombone-logging

282 lines
9.5 KiB
Plaintext
Raw Permalink Normal View History

2015-10-31 23:55:09 +01:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2015-10-31 23:55:09 +01:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2015-10-31 23:55:09 +01:00
#
# Turn logging on or off
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2015-2018 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
REMOVE_FILES_COMMAND='rm -rf'
source /usr/local/bin/${PROJECT_NAME}-vars
2018-03-02 20:17:02 +01:00
UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
for f in $UTILS_FILES
do
2018-03-02 20:17:02 +01:00
source "$f"
done
2018-03-02 20:17:02 +01:00
APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
2017-07-01 21:20:57 +02:00
for f in $APP_FILES
do
2018-03-02 20:17:02 +01:00
source "$f"
2017-07-01 21:20:57 +02:00
done
APPS_AVAILABLE=()
function logging_get_app_names {
2018-03-02 20:17:02 +01:00
FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
2017-07-01 21:20:57 +02:00
for filename in $FILES
do
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
2018-03-02 20:17:02 +01:00
if grep -q "logging_on_" "${filename}"; then
if grep -q "logging_off_" "${filename}"; then
2017-07-01 21:20:57 +02:00
APPS_AVAILABLE+=("${app_name}")
fi
fi
done
}
function turn_logging_on {
logging_get_app_names
2018-03-08 15:38:15 +01:00
# shellcheck disable=SC2068
for a in ${APPS_AVAILABLE[@]}
2017-07-01 21:20:57 +02:00
do
echo $"Turning on logging for ${a}"
2018-03-02 20:17:02 +01:00
"logging_on_${a}"
2017-07-01 21:20:57 +02:00
done
}
function turn_logging_off {
logging_get_app_names
2018-03-08 15:38:15 +01:00
# shellcheck disable=SC2068
for a in ${APPS_AVAILABLE[@]}
2017-07-01 21:20:57 +02:00
do
echo $"Turning off logging for ${a}"
2018-03-02 20:17:02 +01:00
"logging_off_${a}"
2017-07-01 21:20:57 +02:00
done
}
2016-11-18 19:08:18 +01:00
function turn_on_rsys_logging {
2018-04-21 21:57:36 +02:00
save_rsys_header
{ echo 'auth,authpriv.* /var/log/auth.log';
echo '*.*;auth,authpriv.none -/var/log/syslog';
echo 'cron.* /var/log/cron.log';
echo 'daemon.* -/var/log/daemon.log';
echo 'kern.* -/var/log/kern.log';
echo 'lpr.* -/var/log/lpr.log';
echo 'mail.* -/var/log/mail.log';
echo 'user.* -/var/log/user.log';
echo '';
echo 'mail.info -/var/log/mail.info';
echo 'mail.warn -/var/log/mail.warn';
echo 'mail.err /var/log/mail.err';
echo '';
echo "*.=debug;\\";
echo " auth,authpriv.none;\\";
echo ' news.none;mail.none -/var/log/debug';
echo "*.=info;*.=notice;*.=warn;\\";
echo " auth,authpriv.none;\\";
echo " cron,daemon.none;\\";
echo ' mail,news.none -/var/log/messages';
echo '';
echo '*.emerg :omusrmsg:*'; } >> /etc/rsyslog.conf
2016-11-18 19:08:18 +01:00
}
2015-10-31 23:55:09 +01:00
if [ ! "$1" ]; then
exit 1
fi
if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
2017-07-01 21:20:57 +02:00
turn_logging_on
2016-11-18 15:43:19 +01:00
if [ -d /etc/tor ]; then
if [ ! -d /var/log/tor ]; then
mkdir /var/log/tor
chown -R debian-tor:adm /var/log/tor
fi
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:adm /var/log/tor/notices.log
2016-11-20 23:02:46 +01:00
fi
echo 'Log notice file /var/log/tor/notices.log' > /etc/torrc.d/logging
2016-11-18 15:43:19 +01:00
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}')
2018-03-02 20:17:02 +01:00
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"
2016-11-18 15:43:19 +01:00
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
2018-03-02 20:17:02 +01:00
sed -i "s|DOPTIONS=\"-s null -d --pidfile=\$PIDFILE\"|DOPTIONS=\"-d --pidfile=\$PIDFILE\"|g" /etc/init.d/spamassassin
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
2018-04-19 12:07:11 +02:00
turn_on_postgresql_logging
2015-10-31 23:55:09 +01:00
else
2017-07-01 21:25:55 +02:00
turn_logging_off
2017-07-01 21:20:57 +02:00
if [ -d /etc/torrc.d ]; then
echo 'Log notice file /var/log/tor/notices.log' > /etc/torrc.d/logging
2016-11-18 15:43:19 +01:00
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
2018-03-02 20:17:02 +01:00
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"
2016-11-18 15:43:19 +01:00
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
2018-03-02 20:17:02 +01:00
sed -i "s|DOPTIONS=\"-d --pidfile=\$PIDFILE\"|DOPTIONS=\"-s null -d --pidfile=\$PIDFILE\"|g" /etc/init.d/spamassassin
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 19:08:18 +01:00
turn_off_rsys_logging
2018-04-19 12:07:11 +02:00
turn_off_postgresql_logging
2015-10-31 23:55:09 +01:00
fi
if [ -d /etc/exim4 ]; then
update-exim4.conf.template -r
update-exim4.conf
dpkg-reconfigure --frontend noninteractive exim4-config
fi
if [[ "$2" == "--reboot"* || "$2" == "--restart"* ]]; then
# if we are rebooting anyway then there is no need to
# restart the daemons
exit 0
fi
if [ -d /etc/exim4 ]; then
systemctl restart exim4
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
2016-11-18 15:43:19 +01:00
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
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
2018-04-19 12:07:11 +02:00
if [ -d /etc/postgresql ]; then
systemctl restart postgresql
fi
2015-10-31 23:55:09 +01:00
exit 0