| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package LaBrea::Tarpit::tz_test_adj; | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | #use diagnostics; | ||||||||||||||||||||
| 7 | 3 | ▶ | use Time::Local; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | $VERSION = do { my @r = (q$Revision: 0.01 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | LaBrea::Tarpit::tz_test_adj | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | Used only by the test suite. | ||||||||||||||||||||
| 19 | From t/xxx.t | ||||||||||||||||||||
| 20 | use lib qw( ./ ); | ||||||||||||||||||||
| 21 | require tz_test_adj.pl | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | $expect = new LaBrea::Tarpit::tz_test_adj; | ||||||||||||||||||||
| 24 | $realtime = $expect->{sometime}; | ||||||||||||||||||||
| 25 | ... | ||||||||||||||||||||
| 26 | ... | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | $max = $expect->{max}; # max of times above | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 3 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.1
| |||||||||||||||||||||
| 33 | 3 | my ($proto) = @_; | |||||||||||||||||||
| 34 | 3 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 35 | 3 | my $expect = {}; | |||||||||||||||||||
| 36 | # time zone and year must be adjusted | ||||||||||||||||||||
| 37 | # | ||||||||||||||||||||
| 38 | 3 | my $test_no_year = <<EOF; | |||||||||||||||||||
| 39 | # mon dy hr mn sc yyy timestamp | ||||||||||||||||||||
| 40 | Nov 10 30 14 31 36 101 1007159496 | ||||||||||||||||||||
| 41 | Nov 10 30 14 31 39 101 1007159499 | ||||||||||||||||||||
| 42 | Nov 10 30 14 31 40 101 1007159500 | ||||||||||||||||||||
| 43 | Nov 10 30 14 31 41 101 1007159501 | ||||||||||||||||||||
| 44 | Nov 10 30 14 31 50 101 1007159510 | ||||||||||||||||||||
| 45 | Nov 10 30 14 31 59 101 1007159519 | ||||||||||||||||||||
| 46 | Nov 10 30 15 31 39 101 1007163099 | ||||||||||||||||||||
| 47 | EOF | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | # time zone only must be adjusted | ||||||||||||||||||||
| 50 | 3 | my $test_absolute = <<EOF; | |||||||||||||||||||
| 51 | Dec 11 1 13 11 07 101 1007241067 | ||||||||||||||||||||
| 52 | Dec 11 1 13 12 03 101 1007241123 | ||||||||||||||||||||
| 53 | Dec 11 1 13 12 05 101 1007241125 | ||||||||||||||||||||
| 54 | Dec 11 1 13 12 06 101 1007241126 | ||||||||||||||||||||
| 55 | Dec 11 1 13 12 07 101 1007241127 | ||||||||||||||||||||
| 56 | EOF | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 3 | foreach(split('\n', $test_no_year)) { | |||||||||||||||||||
| 59 | 24 | ▶ | next if $_ =~ /^\s*#/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 21 | my ($mon,$day,$hr,$min,$sec,$yr,$ts) = &parse_date($_); | |||||||||||||||||||
| 61 | # year is relative, get it now | ||||||||||||||||||||
| 62 | 21 | my ($nowmo,$nowyr) = (localtime(time))[4,5]; | |||||||||||||||||||
| 63 | 21 | ▶ | $yr = ($mon > $nowmo) # roll over to new year?? | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | ? $nowyr -1 | ||||||||||||||||||||
| 65 | : $nowyr; | ||||||||||||||||||||
| 66 | 21 | $expect->{$ts} = timelocal($sec,$min,$hr,$day,$mon,$yr); | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 3 | foreach(split('\n', $test_absolute)) { | |||||||||||||||||||
| 70 | 15 | ▶ | next if $_ =~ /^\s*#/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 15 | my ($mon,$day,$hr,$min,$sec,$yr,$ts) = &parse_date($_); | |||||||||||||||||||
| 72 | 15 | $expect->{$ts} = timelocal($sec,$min,$hr,$day,$mon,$yr); | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 3 | my $max = 0; | |||||||||||||||||||
| 76 | 3 | foreach(values %{$expect}) { | |||||||||||||||||||
| 77 | 36 | ▶ | $max = $_ if $max < $_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | 3 | $expect->{max} = $max; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 3 | bless ($expect, $class); | |||||||||||||||||||
| 82 | 3 | return $expect; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 36 | ▶ | sub parse_date { | ||||||||||||||||||
|
Subroutine
parse_date: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 86 | 36 | my ($s) = @_; | |||||||||||||||||||
| 87 | # mon dy hr mn sc yy ts | ||||||||||||||||||||
| 88 | 36 | $s =~ /(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)$/; | |||||||||||||||||||
| 89 | 36 | return ($1,$2,$3,$4,$5,$6,$7); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | ########################################################### | ||||||||||||||||||||
| 93 | # BELOW IS SETUP STUFF FOR ABOVE | ||||||||||||||||||||
| 94 | ########################################################### | ||||||||||||||||||||
| 95 | # | ||||||||||||||||||||
| 96 | # call &LaBrea::Tarpit::tz_test_adj::print_tvals | ||||||||||||||||||||
| 97 | # to print the test date values at the top of this file. | ||||||||||||||||||||
| 98 | # | ||||||||||||||||||||
| 99 | # If you need to update the test values, modify the foreach | ||||||||||||||||||||
| 100 | # statement to add / edit values the run &print_tvals to | ||||||||||||||||||||
| 101 | # print the new array for insertion into the new adjustment | ||||||||||||||||||||
| 102 | # strings. YOU MAY HAVE TO CONVERT 'h174' TO YEAR 2001 OR | ||||||||||||||||||||
| 103 | # WHATEVER THE NEW TEST STRING YEAR IS TO GET THIS TO WORK. | ||||||||||||||||||||
| 104 | # | ||||||||||||||||||||
| 105 | 0 | ▶ | sub print_tvals { | ||||||||||||||||||
|
Subroutine
print_tvals: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 106 | #Nov 10 30 14 31 36 101 1007159496 | ||||||||||||||||||||
| 107 | 0 | ||||||||||||||||||||
| 108 | "# mon\tdy hr mn sc yyy timestamp | ||||||||||||||||||||
| 109 | "; | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | foreach ( | |||||||||||||||||||
| 112 | 'Nov 30 14:31:36 h174 /usr/local/bin/LaBrea: Persist Activity: 67.97.64.173 61623 -> 63.77.172.50 80', | ||||||||||||||||||||
| 113 | 'Nov 30 14:31:39 h174 /usr/local/bin/LaBrea: Initial Connect (tarpitting): 63.204.44.126 2014 -> 63.77.172.39 80', | ||||||||||||||||||||
| 114 | 'Nov 30 14:31:40 h174 /usr/local/bin/LaBrea: Additional Activity: 63.204.44.126 2014 -> 63.77.172.39 80', | ||||||||||||||||||||
| 115 | 'Nov 30 14:31:41 h174 /usr/local/bin/LaBrea: Persist Trapping: 63.204.44.126 2014 -> 63.77.172.39 80 *', | ||||||||||||||||||||
| 116 | 'Nov 30 14:31:50 h174 /usr/local/bin/LaBrea: Persist Trapping: 63.204.44.126 2014 -> 63.77.172.39 80 *', | ||||||||||||||||||||
| 117 | 'Nov 30 14:31:59 h174 /usr/local/bin/LaBrea: Current average bw: 145 (bytes/sec)', | ||||||||||||||||||||
| 118 | 'Nov 30 15:31:39 h174 /usr/local/bin/LaBrea: Initial Connect (tarpitting): 222.205.44.126 2014 -> 63.77.172.49 123', | ||||||||||||||||||||
| 119 | 'Sat Dec 1 13:11:07 2001 2001 Persist Activity: 63.227.234.71 4628 -> 63.77.172.57 81 *', | ||||||||||||||||||||
| 120 | 'Sat Dec 1 13:12:03 2001 Persist Activity: 63.87.135.216 3204 -> 63.77.172.35 80', | ||||||||||||||||||||
| 121 | 'Sat Dec 1 13:12:05 2001 Initial Connect (tarpitting): 63.222.243.6 2710 -> 63.77.172.16 81', | ||||||||||||||||||||
| 122 | 'Sat Dec 1 13:12:06 2001 Additional Activity: 63.222.243.6 2710 -> 63.77.172.16 81 *', | ||||||||||||||||||||
| 123 | 'Sat Dec 1 13:12:07 2001 Persist Trapping: 63.222.243.6 2710 -> 63.77.172.16 81', | ||||||||||||||||||||
| 124 | ) { | ||||||||||||||||||||
| 125 | 0 | my $time =&make_time($_); | |||||||||||||||||||
| 126 | 0 | print $time,"\n"; | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | # used by above to print and make values | ||||||||||||||||||||
| 131 | # | ||||||||||||||||||||
| 132 | 0 | ▶ | sub make_time { | ||||||||||||||||||
|
Subroutine
make_time: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 133 | 0 | my ($line) = @_; | |||||||||||||||||||
| 134 | 0 | require Time::Local; | |||||||||||||||||||
| 135 | 0 | ▶ | return undef unless $line =~ /(.+)\s+(\d+):(\d+):(\d+)\s+(\w+)\s+/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 136 | 0 | @_ = split(/\s+/,$1); | |||||||||||||||||||
| 137 | 0 | my $day = pop @_; | |||||||||||||||||||
| 138 | 0 | my $mon = pop @_; | |||||||||||||||||||
| 139 | 0 | print $mon; | |||||||||||||||||||
| 140 | 0 | $mon = ${&mon}->{"\L$mon"}; | |||||||||||||||||||
| 141 | 0 | my ($hr,$min,$sec,$yr) = ($2,$3,$4,$5); | |||||||||||||||||||
| 142 | 0 | ▶ | if ($yr =~ /[^\d]/) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 143 | 0 | my ($nowmo,$nowyr) = (localtime(time))[4,5]; | |||||||||||||||||||
| 144 | 0 | ▶ | $yr = ($mon > $nowmo) # roll over to new year?? | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 145 | ? $nowyr -1 | ||||||||||||||||||||
| 146 | : $nowyr; | ||||||||||||||||||||
| 147 | } elsif ( $yr > 1900 ) { # most likely | ||||||||||||||||||||
| 148 | 0 | $yr -= 1900; | |||||||||||||||||||
| 149 | } elsif ( $yr < 70 ) { # yr 2000 or more | ||||||||||||||||||||
| 150 | 0 | $yr += 100; | |||||||||||||||||||
| 151 | } # else leave as-is, 70 - 99 | ||||||||||||||||||||
| 152 | 0 | print " $mon $day $hr $min $sec $yr "; | |||||||||||||||||||
| 153 | 0 | return &Time::Local::timelocal($sec,$min,$hr,$day,$mon,$yr); | |||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | # used by above to look up month value | ||||||||||||||||||||
| 157 | # | ||||||||||||||||||||
| 158 | 0 | ▶ | sub mon { | ||||||||||||||||||
|
Subroutine
mon: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 159 | 0 | return {qw(jan 0 feb 1 mar 2 apr 3 may 4 jun 5 jul 6 aug 7 sep 8 oct 9 nov 10 dec 11)}; | |||||||||||||||||||
| 160 | } | ||||||||||||||||||||
| 161 | 3 | 1; | |||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||