line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package LaBrea::Tarpit::tz_test_adj; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1769
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
118
|
|
6
|
|
|
|
|
|
|
#use diagnostics; |
7
|
3
|
|
|
3
|
|
1766
|
use Time::Local; |
|
3
|
|
|
|
|
4644
|
|
|
3
|
|
|
|
|
202
|
|
8
|
3
|
|
|
3
|
|
18
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
3006
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub new { |
33
|
3
|
|
|
3
|
|
602
|
my ($proto) = @_; |
34
|
3
|
|
33
|
|
|
27
|
my $class = ref($proto) || $proto; |
35
|
3
|
|
|
|
|
9
|
my $expect = {}; |
36
|
|
|
|
|
|
|
# time zone and year must be adjusted |
37
|
|
|
|
|
|
|
# |
38
|
3
|
|
|
|
|
7
|
my $test_no_year = <
|
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
|
|
|
|
|
16
|
my $test_absolute = <
|
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
|
|
|
|
|
24
|
foreach(split('\n', $test_no_year)) { |
59
|
24
|
100
|
|
|
|
935
|
next if $_ =~ /^\s*#/; |
60
|
21
|
|
|
|
|
75
|
my ($mon,$day,$hr,$min,$sec,$yr,$ts) = &parse_date($_); |
61
|
|
|
|
|
|
|
# year is relative, get it now |
62
|
21
|
|
|
|
|
435
|
my ($nowmo,$nowyr) = (localtime(time))[4,5]; |
63
|
21
|
50
|
|
|
|
66
|
$yr = ($mon > $nowmo) # roll over to new year?? |
64
|
|
|
|
|
|
|
? $nowyr -1 |
65
|
|
|
|
|
|
|
: $nowyr; |
66
|
21
|
|
|
|
|
62
|
$expect->{$ts} = timelocal($sec,$min,$hr,$day,$mon,$yr); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
3
|
|
|
|
|
147
|
foreach(split('\n', $test_absolute)) { |
70
|
15
|
50
|
|
|
|
581
|
next if $_ =~ /^\s*#/; |
71
|
15
|
|
|
|
|
29
|
my ($mon,$day,$hr,$min,$sec,$yr,$ts) = &parse_date($_); |
72
|
15
|
|
|
|
|
99
|
$expect->{$ts} = timelocal($sec,$min,$hr,$day,$mon,$yr); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
|
|
134
|
my $max = 0; |
76
|
3
|
|
|
|
|
7
|
foreach(values %{$expect}) { |
|
3
|
|
|
|
|
12
|
|
77
|
36
|
100
|
|
|
|
76
|
$max = $_ if $max < $_; |
78
|
|
|
|
|
|
|
} |
79
|
3
|
|
|
|
|
10
|
$expect->{max} = $max; |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
9
|
bless ($expect, $class); |
82
|
3
|
|
|
|
|
10
|
return $expect; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub parse_date { |
86
|
36
|
|
|
36
|
|
54
|
my ($s) = @_; |
87
|
|
|
|
|
|
|
# mon dy hr mn sc yy ts |
88
|
36
|
|
|
|
|
142
|
$s =~ /(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)$/; |
89
|
36
|
|
|
|
|
208
|
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
|
|
|
|
|
|
|
sub print_tvals { |
106
|
|
|
|
|
|
|
#Nov 10 30 14 31 36 101 1007159496 |
107
|
0
|
|
|
0
|
|
|
print |
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
|
|
|
|
|
|
|
sub make_time { |
133
|
0
|
|
|
0
|
|
|
my ($line) = @_; |
134
|
0
|
|
|
|
|
|
require Time::Local; |
135
|
0
|
0
|
|
|
|
|
return undef unless $line =~ /(.+)\s+(\d+):(\d+):(\d+)\s+(\w+)\s+/; |
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"}; |
|
0
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my ($hr,$min,$sec,$yr) = ($2,$3,$4,$5); |
142
|
0
|
0
|
|
|
|
|
if ($yr =~ /[^\d]/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my ($nowmo,$nowyr) = (localtime(time))[4,5]; |
144
|
0
|
0
|
|
|
|
|
$yr = ($mon > $nowmo) # roll over to new year?? |
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
|
|
|
|
|
|
|
sub mon { |
159
|
0
|
|
|
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
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
__END__ |