Przeglądaj źródła

Populate logging functions

Bob Mottram 8 lat temu
rodzic
commit
21822c6e75

+ 18
- 2
src/freedombone-app-matrix Wyświetl plik

63
                   MATRIX_CODE)
63
                   MATRIX_CODE)
64
 
64
 
65
 function logging_on_matrix {
65
 function logging_on_matrix {
66
-    echo -n ''
66
+    if [ -f /var/lib/matrix/homeserver.yaml ]; then
67
+        sed -i 's|log_file:.*|log_file: /etc/matrix/homeserver.log|g' /var/lib/matrix/homeserver.yaml
68
+        if ! grep -q "#log_config:" /var/lib/matrix/homeserver.yaml; then
69
+            sed -i 's|log_config:|#log_config:|g' /var/lib/matrix/homeserver.yaml
70
+        fi
71
+    fi
67
 }
72
 }
68
 
73
 
69
 function logging_off_matrix {
74
 function logging_off_matrix {
70
-    echo -n ''
75
+    if [ -f /var/lib/matrix/homeserver.yaml ]; then
76
+        sed -i 's|log_file:.*|log_file: /dev/null|g' /var/lib/matrix/homeserver.yaml
77
+        if ! grep -q "#log_config:" /var/lib/matrix/homeserver.yaml; then
78
+            sed -i 's|log_config:|#log_config:|g' /var/lib/matrix/homeserver.yaml
79
+        fi
80
+        if [ -f /etc/matrix/homeserver.log ]; then
81
+            $REMOVE_FILES_COMMAND /etc/matrix/homeserver.log
82
+        fi
83
+        if [ -f /etc/matrix/homeserver.log.1 ]; then
84
+            $REMOVE_FILES_COMMAND /etc/matrix/homeserver.log.1
85
+        fi
86
+    fi
71
 }
87
 }
72
 
88
 
73
 function matrix_nginx {
89
 function matrix_nginx {

+ 10
- 2
src/freedombone-app-mumble Wyświetl plik

48
                   ADMIN_USERNAME)
48
                   ADMIN_USERNAME)
49
 
49
 
50
 function logging_on_mumble {
50
 function logging_on_mumble {
51
-    echo -n ''
51
+    if [ -f /etc/mumble-server.ini ]; then
52
+        sed -i 's|logfile=.*|logfile=/var/log/mumble-server.log|g' /etc/mumble-server.ini
53
+    fi
52
 }
54
 }
53
 
55
 
54
 function logging_off_mumble {
56
 function logging_off_mumble {
55
-    echo -n ''
57
+    if [ -f /etc/mumble-server.ini ]; then
58
+        sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
59
+        if [ -d /var/log/mumble-server ]; then
60
+            $REMOVE_FILES_COMMAND /var/log/mumble-server/*
61
+            rm -rf /var/log/mumble-server
62
+        fi
63
+    fi
56
 }
64
 }
57
 
65
 
58
 function install_interactive_mumble {
66
 function install_interactive_mumble {

+ 16
- 2
src/freedombone-app-xmpp Wyświetl plik

60
                 XMPP_DOMAIN_CODE)
60
                 XMPP_DOMAIN_CODE)
61
 
61
 
62
 function logging_on_xmpp {
62
 function logging_on_xmpp {
63
-    echo -n ''
63
+    if [ -d /etc/prosody ]; then
64
+        if [ ! -d /var/log/prosody ]; then
65
+            mkdir /var/log/prosody
66
+            chown root:adm /var/log/prosody
67
+        fi
68
+        sed -i 's|info = "/dev/null";|info = "/var/log/prosody/prosody.log";|g' /etc/prosody/prosody.cfg.lua
69
+        sed -i 's|error = "/dev/null";|error = "/var/log/prosody/prosody.err";|g' /etc/prosody/prosody.cfg.lua
70
+        sed -i 's|levels = { "error" }; to = "/dev/null";|levels = { "error" }; to = "syslog";|g' /etc/prosody/prosody.cfg.lua
71
+    fi
64
 }
72
 }
65
 
73
 
66
 function logging_off_xmpp {
74
 function logging_off_xmpp {
67
-    echo -n ''
75
+    if [ -d /etc/prosody ]; then
76
+        sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
77
+        sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
78
+        sed -i 's|levels = { "error" }; to = "syslog";|levels = { "error" }; to = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
79
+        $REMOVE_FILES_COMMAND /var/log/prosody/*
80
+        rm -rf /var/log/prosody
81
+    fi
68
 }
82
 }
69
 
83
 
70
 function xmpp_add_onion_address {
84
 function xmpp_add_onion_address {

+ 46
- 44
src/freedombone-logging Wyświetl plik

40
 # Also the shred command can be very slow on Beaglebone Black
40
 # Also the shred command can be very slow on Beaglebone Black
41
 REMOVE_FILES_COMMAND='rm -rf'
41
 REMOVE_FILES_COMMAND='rm -rf'
42
 
42
 
43
+APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
44
+for f in $APP_FILES
45
+do
46
+    source $f
47
+done
48
+
49
+APPS_AVAILABLE=()
50
+
51
+function logging_get_app_names {
52
+    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
53
+
54
+    for filename in $FILES
55
+    do
56
+        app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
57
+        if grep -q "logging_on_" ${filename}; then
58
+            if grep -q "logging_off_" ${filename}; then
59
+                APPS_AVAILABLE+=("${app_name}")
60
+            fi
61
+        fi
62
+    done
63
+}
64
+
65
+function turn_logging_on {
66
+    logging_get_app_names
67
+
68
+    for a in "${APPS_AVAILABLE[@]}"
69
+    do
70
+        echo $"Turning on logging for ${a}"
71
+        logging_on_${a}
72
+    done
73
+}
74
+
75
+function turn_logging_off {
76
+    logging_get_app_names
77
+
78
+    for a in "${APPS_AVAILABLE[@]}"
79
+    do
80
+        echo $"Turning off logging for ${a}"
81
+        logging_off_${a}
82
+    done
83
+}
84
+
43
 function turn_off_rsys_logging {
85
 function turn_off_rsys_logging {
44
     sed -i 's|mail,news.none.*|mail,news.none      /dev/null|g' /etc/rsyslog.conf
86
     sed -i 's|mail,news.none.*|mail,news.none      /dev/null|g' /etc/rsyslog.conf
45
     sed -i 's|auth,authpriv.\*.*|auth,authpriv.\*         /dev/null|g' /etc/rsyslog.conf
87
     sed -i 's|auth,authpriv.\*.*|auth,authpriv.\*         /dev/null|g' /etc/rsyslog.conf
83
 fi
125
 fi
84
 
126
 
85
 if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
127
 if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
86
-    if [ -f /var/lib/matrix/homeserver.yaml ]; then
87
-        sed -i 's|log_file:.*|log_file: /etc/matrix/homeserver.log|g' /var/lib/matrix/homeserver.yaml
88
-        if ! grep -q "#log_config:" /var/lib/matrix/homeserver.yaml; then
89
-            sed -i 's|log_config:|#log_config:|g' /var/lib/matrix/homeserver.yaml
90
-        fi
91
-    fi
128
+    turn_logging_on
129
+
92
     if [ -f /etc/fail2ban/fail2ban.conf ]; then
130
     if [ -f /etc/fail2ban/fail2ban.conf ]; then
93
         sed -i 's|loglevel.*|loglevel = 3|g' /etc/fail2ban/fail2ban.conf
131
         sed -i 's|loglevel.*|loglevel = 3|g' /etc/fail2ban/fail2ban.conf
94
         sed -i 's|logtarget.*|logtarget = /var/log/fail2ban.log|g' /etc/fail2ban/fail2ban.conf
132
         sed -i 's|logtarget.*|logtarget = /var/log/fail2ban.log|g' /etc/fail2ban/fail2ban.conf
105
         sed -i 's|#Log notice file.*|Log notice file /var/log/tor/notices.log|g' /etc/tor/torrc
143
         sed -i 's|#Log notice file.*|Log notice file /var/log/tor/notices.log|g' /etc/tor/torrc
106
         sed -i 's|Log notice file.*|Log notice file /var/log/tor/notices.log|g' /etc/tor/torrc
144
         sed -i 's|Log notice file.*|Log notice file /var/log/tor/notices.log|g' /etc/tor/torrc
107
     fi
145
     fi
108
-    if [ -f /etc/mumble-server.ini ]; then
109
-        sed -i 's|logfile=.*|logfile=/var/log/mumble-server.log|g' /etc/mumble-server.ini
110
-    fi
111
     if [ -f /etc/php/7.0/fpm/php-fpm.conf ]; then
146
     if [ -f /etc/php/7.0/fpm/php-fpm.conf ]; then
112
         sed -i 's|error_log =.*|error_log = /var/log/php-fpm.log|g' /etc/php/7.0/fpm/php-fpm.conf
147
         sed -i 's|error_log =.*|error_log = /var/log/php-fpm.log|g' /etc/php/7.0/fpm/php-fpm.conf
113
     fi
148
     fi
126
     if [ -f /etc/init.d/spamassassin ]; then
161
     if [ -f /etc/init.d/spamassassin ]; then
127
         sed -i 's|DOPTIONS="-s null -d --pidfile=$PIDFILE"|DOPTIONS="-d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
162
         sed -i 's|DOPTIONS="-s null -d --pidfile=$PIDFILE"|DOPTIONS="-d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
128
     fi
163
     fi
129
-    if [ -d /etc/prosody ]; then
130
-        if [ ! -d /var/log/prosody ]; then
131
-            mkdir /var/log/prosody
132
-            chown root:adm /var/log/prosody
133
-        fi
134
-        sed -i 's|info = "/dev/null";|info = "/var/log/prosody/prosody.log";|g' /etc/prosody/prosody.cfg.lua
135
-        sed -i 's|error = "/dev/null";|error = "/var/log/prosody/prosody.err";|g' /etc/prosody/prosody.cfg.lua
136
-        sed -i 's|levels = { "error" }; to = "/dev/null";|levels = { "error" }; to = "syslog";|g' /etc/prosody/prosody.cfg.lua
137
-    fi
138
     if [ -d /etc/exim4 ]; then
164
     if [ -d /etc/exim4 ]; then
139
         if [ ! -d /var/log/exim4 ]; then
165
         if [ ! -d /var/log/exim4 ]; then
140
             mkdir /var/log/exim4
166
             mkdir /var/log/exim4
158
     fi
184
     fi
159
     turn_on_rsys_logging
185
     turn_on_rsys_logging
160
 else
186
 else
161
-    if [ -f /var/lib/matrix/homeserver.yaml ]; then
162
-        sed -i 's|log_file:.*|log_file: /dev/null|g' /var/lib/matrix/homeserver.yaml
163
-        if ! grep -q "#log_config:" /var/lib/matrix/homeserver.yaml; then
164
-            sed -i 's|log_config:|#log_config:|g' /var/lib/matrix/homeserver.yaml
165
-        fi
166
-        if [ -f /etc/matrix/homeserver.log ]; then
167
-            $REMOVE_FILES_COMMAND /etc/matrix/homeserver.log
168
-        fi
169
-        if [ -f /etc/matrix/homeserver.log.1 ]; then
170
-            $REMOVE_FILES_COMMAND /etc/matrix/homeserver.log.1
171
-        fi
172
-    fi
187
+    rurn_logging_off
188
+
173
     if [ -d /etc/tor ]; then
189
     if [ -d /etc/tor ]; then
174
         sed -i 's|#Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
190
         sed -i 's|#Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
175
         sed -i 's|Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
191
         sed -i 's|Log notice file.*|Log notice file /dev/null|g' /etc/tor/torrc
176
     fi
192
     fi
177
-    if [ -f /etc/mumble-server.ini ]; then
178
-        sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
179
-        if [ -d /var/log/mumble-server ]; then
180
-            $REMOVE_FILES_COMMAND /var/log/mumble-server/*
181
-            rm -rf /var/log/mumble-server
182
-        fi
183
-    fi
184
     if [ -d /var/log/radicale ]; then
193
     if [ -d /var/log/radicale ]; then
185
         $REMOVE_FILES_COMMAND /var/log/radicale/*
194
         $REMOVE_FILES_COMMAND /var/log/radicale/*
186
         rm -rf /var/log/radicale
195
         rm -rf /var/log/radicale
202
     if [ -f /etc/init.d/spamassassin ]; then
211
     if [ -f /etc/init.d/spamassassin ]; then
203
         sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
212
         sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
204
     fi
213
     fi
205
-    if [ -d /etc/prosody ]; then
206
-        sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
207
-        sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
208
-        sed -i 's|levels = { "error" }; to = "syslog";|levels = { "error" }; to = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
209
-        $REMOVE_FILES_COMMAND /var/log/prosody/*
210
-        rm -rf /var/log/prosody
211
-    fi
212
     if [ -d /etc/exim4 ]; then
214
     if [ -d /etc/exim4 ]; then
213
         sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs
215
         sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs
214
         sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/exim4.conf.template
216
         sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/exim4.conf.template