Rev 5 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | #!/bin/bash |
2 | |||
3 | # |
||
11 | daniel-mar | 4 | # VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois) |
5 | daniel-mar | 5 | # Maintenance / Developer utilities |
2 | daniel-mar | 6 | # |
5 | daniel-mar | 7 | # (c) 2012-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de> |
2 | daniel-mar | 8 | # |
5 | daniel-mar | 9 | # License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2) |
2 | daniel-mar | 10 | # |
11 | |||
12 | DIR=$( dirname "$0" ) |
||
13 | |||
4 | daniel-mar | 14 | TESTCASES_LIST="$DIR/../../config/testcases.list" |
15 | |||
2 | daniel-mar | 16 | # --- |
17 | |||
18 | function FileAge() { |
||
19 | echo $((`date +%s` - `stat -c %Y $1`)) |
||
20 | } |
||
21 | |||
22 | function HumanReadableAge() { |
||
23 | local seconds=$1 |
||
24 | local days=$(($seconds/86400)) |
||
25 | seconds=$(($seconds-($days*86400) )) |
||
26 | local hours=$(($seconds/3600)) |
||
27 | seconds=$((seconds-($hours*3600) )) |
||
28 | local minutes=$(($seconds/60)) |
||
29 | seconds=$(( $seconds-($minutes*60) )) |
||
30 | |||
31 | # echo -n "${days}D ${hours}H ${minutes}M ${seconds}S" |
||
32 | if [ $days -gt 0 ]; then |
||
33 | if [ $hours -gt 12 ]; then |
||
34 | ((days++)); |
||
35 | fi |
||
36 | echo -n "${days} days ago" |
||
37 | elif [ $hours -gt 0 ]; then |
||
38 | if [ $minutes -gt 30 ]; then |
||
39 | ((hours++)); |
||
40 | fi |
||
41 | echo -n "${hours} hours ago" |
||
42 | elif [ $minutes -gt 0 ]; then |
||
43 | if [ $seconds -gt 30 ]; then |
||
44 | ((minutes++)); |
||
45 | fi |
||
46 | echo -n "${minutes} minutes ago" |
||
47 | else |
||
48 | echo -n "a few seconds ago" |
||
49 | fi |
||
50 | } |
||
51 | |||
52 | # --- |
||
53 | |||
54 | . "$DIR/../../config/testcases.conf" |
||
55 | |||
4 | daniel-mar | 56 | CACHE_DIR="$DIR/../../.cache" |
57 | |||
2 | daniel-mar | 58 | echo "Query Last activity Status" |
59 | echo "----------------------------------------------------------------------------------" |
||
60 | |||
61 | while read f; do |
||
62 | if [ -z "$f" ]; then |
||
63 | continue; |
||
64 | fi |
||
65 | |||
66 | # Check if the line begins with an '#' (leading spaces are permitted) |
||
67 | echo "$f" | grep -E "\s*^#" > /dev/null |
||
68 | if [ $? -eq 0 ]; then |
||
69 | continue; |
||
70 | fi |
||
71 | |||
72 | # Warum? "tld jp" wird dann zu "tld" |
||
73 | # query="$( basename $f )" |
||
74 | query="$f"; |
||
75 | |||
4 | daniel-mar | 76 | if [ ! -d "$CACHE_DIR/testcases/expected" ]; then |
77 | mkdir -p "$CACHE_DIR/testcases/expected" |
||
3 | daniel-mar | 78 | fi |
4 | daniel-mar | 79 | expfile="$CACHE_DIR/testcases/expected/$query" |
2 | daniel-mar | 80 | |
4 | daniel-mar | 81 | if [ ! -d "$CACHE_DIR/testcases/checktimestamps" ]; then |
82 | mkdir -p "$CACHE_DIR/testcases/checktimestamps" |
||
3 | daniel-mar | 83 | fi |
4 | daniel-mar | 84 | tsfile="$CACHE_DIR/testcases/checktimestamps/$query" |
2 | daniel-mar | 85 | if [ -f "$tsfile" ]; then |
86 | # lastcheck="$( date -r "$tsfile" )" |
||
87 | lastcheck=$( HumanReadableAge $( FileAge "$tsfile" )) |
||
88 | else |
||
89 | lastcheck="never" |
||
90 | fi |
||
91 | |||
4 | daniel-mar | 92 | if [ ! -d "$CACHE_DIR/testcases/problems" ]; then |
93 | mkdir -p "$CACHE_DIR/testcases/problems" |
||
3 | daniel-mar | 94 | fi |
4 | daniel-mar | 95 | errfile="$CACHE_DIR/testcases/problems/$query" |
2 | daniel-mar | 96 | if [ -f "$errfile" ]; then |
97 | cat "$errfile" | grep -E "at /(bin|usr|etc|var)/\S+ line" > /dev/null |
||
98 | PERLERR=$? |
||
99 | |||
100 | cat "$errfile" | head -n 1 | grep -E "^("$'\xEF\xBB\xBF'"){0,1}Process query: '$query'" > /dev/null |
||
101 | STARTEXP=$? |
||
102 | |||
11 | daniel-mar | 103 | cat "$errfile" | grep "vgwhois remarks: If this is a valid domainname or handle, please file a bug report." > /dev/null |
2 | daniel-mar | 104 | NOPATTERNMATCH=$? |
105 | |||
106 | if [ $PERLERR -eq 0 ]; then |
||
107 | status="Perl-Error!" |
||
108 | elif [ $STARTEXP -ne 0 ]; then |
||
109 | status="Unexpected head line" |
||
110 | elif [ $NOPATTERNMATCH -eq 0 ]; then |
||
111 | status="No pattern match" |
||
112 | elif [ -f "$expfile" ]; then |
||
113 | status="Different output" |
||
114 | else |
||
115 | status="No expected output defined" |
||
116 | fi |
||
117 | else |
||
118 | if [ -f "$expfile" ]; then |
||
119 | status="OK" |
||
120 | else |
||
121 | status="No expected output defined" |
||
122 | fi |
||
123 | fi |
||
124 | |||
125 | if [ ! -f "$tsfile" ] || [ $( stat --format=%Y "$tsfile" ) -le $(( $( date +%s ) - $recheck_time )) ]; then |
||
126 | if [ ! -f "$errfile" ] || [ $( stat --format=%Y "$errfile" ) -le $(( $( date +%s ) - $recheck_time )) ]; then |
||
127 | status="$status, outdated" |
||
128 | fi |
||
129 | fi |
||
130 | |||
131 | printf "%-30s %-20s %-20s\n" "$query" "$lastcheck" "$status" |
||
4 | daniel-mar | 132 | done < "$TESTCASES_LIST" |