[sysadmin-bin] Drop tabs



commit adee2d649062ea0bb33e6aacdd89b21a20ea0a3a
Author: Andrea Veri <averi redhat com>
Date:   Wed Jun 13 10:36:14 2018 +0200

    Drop tabs

 gnomeweb/list-abusers | 282 +++++++++++++++++++++++++-------------------------
 1 file changed, 141 insertions(+), 141 deletions(-)
---
diff --git a/gnomeweb/list-abusers b/gnomeweb/list-abusers
index 6fb31ef..d6f5262 100755
--- a/gnomeweb/list-abusers
+++ b/gnomeweb/list-abusers
@@ -18,21 +18,21 @@
 FILE=""
 
 determine_file () {
-       FILE=""
+    FILE=""
 
-       # Change stuff like bugzilla-web to bugzilla
-       HN=${HOSTNAME%-*}
+    # Change stuff like bugzilla-web to bugzilla
+    HN=${HOSTNAME%-*}
 
-       if [ -z "$1" ]; then
-               # No arguments specified on the command line
-               FILES="\
+    if [ -z "$1" ]; then
+        # No arguments specified on the command line
+        FILES="\
 access_log
 /var/log/httpd/$HN/access_log
 /var/log/httpd/$HN.gnome.org/access_log
 /var/log/httpd/access_log"
-       else
-               # In case an argument was given
-               FILES="\
+    else
+        # In case an argument was given
+        FILES="\
 $1
 $1
 $1.gz
@@ -49,138 +49,138 @@ access_log$1.gz
 /var/log/httpd/$1/access_log
 /var/log/httpd/$1.gnome.org/access_log
 /var/log/httpd/$1"
-       fi
-
-       while read filetest; do
-               if [ -e "$filetest" ]; then
-                       FILE="$filetest"
-                        if [[ `head -n 1 $filetest | cut -d' ' -f1` =~ 
^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
-                            IS_UNPROXIED_SCRIPT='true'
-                        else
-                            IS_REVERSE_PROXY_SCRIPT='true'
-                        fi
-                       return 0
-               fi
-       done <<<"$FILES"
-
-       # Could not determine the file
-       return 1
+    fi
+
+    while read filetest; do
+        if [ -e "$filetest" ]; then
+            FILE="$filetest"
+            if [[ `head -n 1 $filetest | cut -d' ' -f1` =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ 
]]; then
+                IS_UNPROXIED_SCRIPT='true'
+            else
+                IS_REVERSE_PROXY_SCRIPT='true'
+            fi
+            return 0
+        fi
+    done <<<"$FILES"
+
+    # Could not determine the file
+    return 1
 }
 
 mode_report () {
-       # Report top 25 IP addresses by hits and optionally block them
-
-       # Variables used in awk script:
-       #   IP: hits per IP address
-       #   STOP: time of last hit (assumes logfile is sorted on time)
-       #   STOP: time of first hit (assumes logfile is sorted on time)
-       #   MINHITS: minimum number of hits that will be reported
-       #   IPS: total number of IPs found
-       #
-       # awk script will automatically set MINHITS when needed (makes the sort command quicker)
-       REVERSE_PROXY_SCRIPT='
+    # Report top 25 IP addresses by hits and optionally block them
+
+    # Variables used in awk script:
+    #   IP: hits per IP address
+    #   STOP: time of last hit (assumes logfile is sorted on time)
+    #   STOP: time of first hit (assumes logfile is sorted on time)
+    #   MINHITS: minimum number of hits that will be reported
+    #   IPS: total number of IPs found
+    #
+    # awk script will automatically set MINHITS when needed (makes the sort command quicker)
+    REVERSE_PROXY_SCRIPT='
 {
-       IP[$6]++;
-       STOP[$6]=$9 "/" $10;
-       if ( START[$9] == "" ) {
-               START[$6]=$9 "/" $10;
-               IPS++
-       }
+    IP[$6]++;
+    STOP[$6]=$9 "/" $10;
+    if ( START[$9] == "" ) {
+        START[$6]=$9 "/" $10;
+        IPS++
+    }
 }
 
 END {
-       if ( MINHITS == "" && NR > 100000 ) {
-               MINHITS=( (NR / IPS) + sqrt( ( NR / IPS ) ) )
-       }
-       for (i in IP) {
-               if ( MINHITS == "" || IP[i] >= MINHITS ) {
-                       print i "\t" IP[i] "\t-\t" START[i] "\t" STOP[i];
-               }
-       }
+    if ( MINHITS == "" && NR > 100000 ) {
+        MINHITS=( (NR / IPS) + sqrt( ( NR / IPS ) ) )
+    }
+    for (i in IP) {
+        if ( MINHITS == "" || IP[i] >= MINHITS ) {
+            print i "\t" IP[i] "\t-\t" START[i] "\t" STOP[i];
+        }
+    }
 }'
 
 
-       UNPROXIED_SCRIPT='
+    UNPROXIED_SCRIPT='
 {
-       IP[$1]++;
-       STOP[$1]=$4 "/" $5;
-       if ( START[$1] == "" ) {
-               START[$1]=$4 "/" $5;
-               IPS++
-       }
+    IP[$1]++;
+    STOP[$1]=$4 "/" $5;
+    if ( START[$1] == "" ) {
+        START[$1]=$4 "/" $5;
+        IPS++
+    }
 }
 
 END {
-       if ( MINHITS == "" && NR > 100000 ) {
-               MINHITS=( (NR / IPS) + sqrt( ( NR / IPS ) ) )
-       }
-       for (i in IP) {
-               if ( MINHITS == "" || IP[i] >= MINHITS ) {
-                       print i "\t" IP[i] "\t-\t" START[i] "\t" STOP[i];
-               }
-       }
+    if ( MINHITS == "" && NR > 100000 ) {
+        MINHITS=( (NR / IPS) + sqrt( ( NR / IPS ) ) )
+    }
+    for (i in IP) {
+        if ( MINHITS == "" || IP[i] >= MINHITS ) {
+            print i "\t" IP[i] "\t-\t" START[i] "\t" STOP[i];
+        }
+    }
 }'
 
 
-       # Show top 25 IP addresses for the determined logfile
-        if [ "$IS_UNPROXIED_SCRIPT" == 'true' ]; then
-            SCRIPT=$UNPROXIED_SCRIPT
-        elif [ "$IS_REVERSE_PROXY_SCRIPT" == 'true' ]; then
-            SCRIPT=$REVERSE_PROXY_SCRIPT
+    # Show top 25 IP addresses for the determined logfile
+    if [ "$IS_UNPROXIED_SCRIPT" == 'true' ]; then
+        SCRIPT=$UNPROXIED_SCRIPT
+    elif [ "$IS_REVERSE_PROXY_SCRIPT" == 'true' ]; then
+        SCRIPT=$REVERSE_PROXY_SCRIPT
+    fi
+    echo $FILE
+    $CAT $FILE | egrep -v '(172.31.1|10.8.0)' | egrep "(GET /buglist.cgi|(GET|POST) /wp-login.php)" | gawk 
-v MINHITS="$MINHITS" "$SCRIPT" | sort -rnk 2 | head -n25 | while read ipaddr hits perhour start stop bar; do
+        start=${start//\// }
+        start=${start/:/ }
+        start=${start//[]\[]/}
+        startstamp=`date -d "$start" +%s`
+
+        stop=${stop//\// }
+        stop=${stop/:/ }
+        stop=${stop//[]\[]/}
+        stopstamp=`date -d "$stop" +%s`
+
+        if [ "$startstamp" = "$stopstamp" ]; then
+            perhour=$[ $hits * 60 * 60 ]
+        else
+            perhour=$[ ($hits * 60 * 60 ) / ($stopstamp-$startstamp ) ]
         fi
-       echo $FILE
-       $CAT $FILE | egrep -v '(172.31.1|10.8.0)' | egrep "(GET /buglist.cgi|(GET|POST) /wp-login.php)" | 
gawk -v MINHITS="$MINHITS" "$SCRIPT" | sort -rnk 2 | head -n25 | while read ipaddr hits perhour start stop 
bar; do
-               start=${start//\// }
-               start=${start/:/ }
-               start=${start//[]\[]/}
-               startstamp=`date -d "$start" +%s`
-
-               stop=${stop//\// }
-               stop=${stop/:/ }
-               stop=${stop//[]\[]/}
-               stopstamp=`date -d "$stop" +%s`
-
-               if [ "$startstamp" = "$stopstamp" ]; then
-                       perhour=$[ $hits * 60 * 60 ]
-               else
-                       perhour=$[ ($hits * 60 * 60 ) / ($stopstamp-$startstamp ) ]
-               fi
-               baninfo=""
-
-               if [ -n "$BAN" ]; then
-                       ADD_TO_IPTABLES=""
-                       if [ $hits -gt $MINHITS -a $perhour -gt $MINHITSPERHOUR ]; then
-                               baninfo="\tShould be banned"
-                               # XXX - IP address is used as-is in the regexp
-                               # XXX - should escape characters like . ? [
-                               (/sbin/iptables -nL | grep -q -- "$ipaddr") || ADD_TO_IPTABLES=1
-                       fi
-                       if [ -n "$ADD_TO_IPTABLES" ]; then
+        baninfo=""
+
+        if [ -n "$BAN" ]; then
+            ADD_TO_IPTABLES=""
+            if [ $hits -gt $MINHITS -a $perhour -gt $MINHITSPERHOUR ]; then
+                baninfo="\tShould be banned"
+                # XXX - IP address is used as-is in the regexp
+                # XXX - should escape characters like . ? [
+                (/sbin/iptables -nL | grep -q -- "$ipaddr") || ADD_TO_IPTABLES=1
+            fi
+            if [ -n "$ADD_TO_IPTABLES" ]; then
                 echo "Blocked $ipaddr. hits: $hits, perhour: $perhour" >>/var/log/blocked
-                               baninfo="\tBanned"
-                               # XXX - add mail notification
+                baninfo="\tBanned"
+                # XXX - add mail notification
                 /sbin/iptables -A ABUSERS -s $ipaddr -j REJECT --reject-with icmp-admin-prohibited
-                       fi
-               fi
+            fi
+        fi
 
-               echo -e "$ipaddr\t$hits\t$perhour\t$start\t$stop$baninfo"
-       done
+        echo -e "$ipaddr\t$hits\t$perhour\t$start\t$stop$baninfo"
+    done
 }
 
 mode_grep () {
-       # Grep logfile for an IP address / regexp
-       $GREP "^$IP" "$FILE" | less
+    # Grep logfile for an IP address / regexp
+    $GREP "^$IP" "$FILE" | less
 }
 
 mode_tail () {
-       # Show changes to the logfile as they happen
-
-       if [ "$CAT" = "cat" ]; then
-               tail -f "$FILE"
-       else
-               # Logfile is archived. Just show the end
-               $CAT "$FILE" | tail
-       fi
+    # Show changes to the logfile as they happen
+
+    if [ "$CAT" = "cat" ]; then
+        tail -f "$FILE"
+    else
+        # Logfile is archived. Just show the end
+        $CAT "$FILE" | tail
+    fi
 }
 
 
@@ -189,7 +189,7 @@ mode_tail () {
 
 determine_file "$@" && shift
 if [ -z "$FILE" ]; then
-       determine_file "access_log"
+    determine_file "access_log"
 fi
 
 # MODE determines what the script will do:
@@ -197,40 +197,40 @@ fi
 #  ban: same as report
 MODE="report"
 if [ -z "$1" ]; then
-       :
+    :
 elif [[ "$1" =~ ^[0-9]+$ ]]; then
-       # numeric argument
-       MINHITS=$1
+    # numeric argument
+    MINHITS=$1
 elif [ "$1" = "-b" ]; then
-       # Ban IP address, requires MINHITS and HITPERHOUR argument
-       MODE="ban"
-       BAN=1
-       MINHITS=$2
-       MINHITSPERHOUR=$3
+    # Ban IP address, requires MINHITS and HITPERHOUR argument
+    MODE="ban"
+    BAN=1
+    MINHITS=$2
+    MINHITSPERHOUR=$3
 elif [ "$1" = "-f" ]; then
-       MODE="tail"
+    MODE="tail"
 else
-       MODE="grep"
-       IP="$1"
+    MODE="grep"
+    IP="$1"
 fi
 
 case "${FILE##*.}" in
-       gz)
-               CAT="zcat"
-               GREP="zgrep"
-       ;;
-       bz2)
-               CAT="bzcat"
-               GREP="bzgrep"
-       ;;
-       *)
-               CAT="cat"
-               GREP="grep"
-       ;;
+    gz)
+        CAT="zcat"
+        GREP="zgrep"
+    ;;
+    bz2)
+        CAT="bzcat"
+        GREP="bzgrep"
+    ;;
+    *)
+        CAT="cat"
+        GREP="grep"
+    ;;
 esac
 
 case "$MODE" in
-       report|ban)  mode_report "$@";;
-       grep)        mode_grep "$@";;
-       tail)        mode_tail "$@";;
+    report|ban)  mode_report "$@";;
+    grep)        mode_grep "$@";;
+    tail)        mode_tail "$@";;
 esac


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]