Procházet zdrojové kódy

Command to show Tor health status

Bob Mottram před 6 roky
rodič
revize
96540317a7
1 změnil soubory, kde provedl 62 přidání a 0 odebrání
  1. 62
    0
      src/freedombone-tor-health

+ 62
- 0
src/freedombone-tor-health Zobrazit soubor

@@ -0,0 +1,62 @@
1
+#!/bin/bash
2
+#  _____               _           _
3
+# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
4
+# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
5
+# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
6
+#
7
+#                              Freedom in the Cloud
8
+#
9
+# Returns a health status for Tor
10
+#
11
+# License
12
+# =======
13
+#
14
+# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
15
+#
16
+# This program is free software: you can redistribute it and/or modify
17
+# it under the terms of the GNU Affero General Public License as published by
18
+# the Free Software Foundation, either version 3 of the License, or
19
+# (at your option) any later version.
20
+#
21
+# This program is distributed in the hope that it will be useful,
22
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
+# GNU Affero General Public License for more details.
25
+#
26
+# You should have received a copy of the GNU Affero General Public License
27
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
+
29
+PROJECT_NAME='freedombone'
30
+
31
+export TEXTDOMAIN=${PROJECT_NAME}-tor-health
32
+export TEXTDOMAINDIR="/usr/share/locale"
33
+
34
+d1=$(date --date="-10 min" "+%b %d %H:%M"):00
35
+d2=$(date "+%b %d %H:%M"):00
36
+ctr=0
37
+echo -n '' > /var/log/tor/notices_new.log
38
+while read -r line; do
39
+    datestr=$(echo "$line" | awk -F '.' '{print $1}')
40
+    if [[ "$datestr" > "$d1" && "$datestr" < "$d2" || "$datestr" =~ $d2 ]]; then
41
+        if [[ "$line" == *'Retrying'* ]]; then
42
+            ctr=$((ctr+1))
43
+        fi
44
+        echo "$line" >> /var/log/tor/notices_new.log
45
+    fi
46
+done < /var/log/tor/notices.log
47
+
48
+mv /var/log/tor/notices_new.log /var/log/tor/notices.log
49
+chown -R debian-tor:adm /var/log/tor
50
+
51
+if [ $ctr -gt 5 ]; then
52
+    echo $'Failed'
53
+    exit 0
54
+fi
55
+
56
+if [ $ctr -gt 0 ]; then
57
+    echo $'Poor'
58
+    exit 0
59
+fi
60
+
61
+echo $'Good'
62
+exit 0