-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchmail--extract_fingerprints.pl
More file actions
executable file
·152 lines (112 loc) · 4.28 KB
/
fetchmail--extract_fingerprints.pl
File metadata and controls
executable file
·152 lines (112 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#! /usr/bin/perl -w
# git-servers/github.com/JochenHayek/misc/fetchmail--extract_fingerprints.pl
################################################################################
# how to call the script:
# $ ~/git-servers/github.com/JochenHayek/misc/fetchmail--extract_fingerprints.pl ~/var/log/fetchmail.log
# actually we call it like this:
# $ ssh -n ... bin/fetchmail--extract_fingerprints.pl var/log/fetchmail.log
################################################################################
# 2014-12-15 :
# the script also extracts from fetchmail's log file and then tells you,
# whether a specific server's fingerprints still match.
# 2014-11-05 :
# eventually created this script,
# because it appeared to me, as if I had done this job already a couple of times,
# and it also appeared to me as tedious and errorprone,
# so I made this a tiny little programming challenge.
################################################################################
{
use Carp;
use POSIX qw(strftime);
our $std_formatting_options = { 'separator' => ',', 'assign' => '=>', 'quoteLeft' => '{', 'quoteRight' => '}' };
$main::options{debug} = 0;
my($package,$filename,$line,$proc_name) = caller(0);
$proc_name = '(-)' if !defined($proc_name);
$now_string = strftime "%Y-%m-%d-%H-%M-%S", localtime;
my(%month_name2no) =
( 'Jan' => 1,
'Feb' => 2,
'Mar' => 3,
'Apr' => 4,
'May' => 5,
'Jun' => 6,
'Jul' => 7,
'Aug' => 8,
'Sep' => 9,
'Oct' => 10,
'Nov' => 11,
'Dec' => 12);
my($exit_value) = 0;
while(<>)
{
# $+{time}=>{Sat Dec 13 11:20:23 2014}
if( m/^ fetchmail: \s+ (?<version> \S+) \s+ querying \s+ (?<host> \S+) \s+ (?<z> .+) \s+ at \s+ (?<time> .+) : \s+ poll \s+ started $/x )
{
my($time) = $+{time};
# get to the pieces of this date+time string:
# (actually we would rather prefer the month as a 2-digit-string over the 3-letter-shortname)
if ( $time =~ m/^ (?<wday>\S+) \s+ (?<month>\S+) \s+ (?<day>\d+) \s+ (?<HHMMSS>\S+) \s+ (?<year>\d+) $/x )
{
##$now_string = "$+{year}-$+{month}-$+{day} $+{HHMMSS}";
$now_string = sprintf "%s-%02.2d-%02.2d %s",
$+{year},
$month_name2no{ $+{month} },
$+{day},
$+{HHMMSS};
printf STDOUT " # {%s}\n",$now_string
if 0;
}
}
# fetchmail: jh-gapps.gmail.com key fingerprint: 3E:D4:0B:B3:DE:CB:2D:4E:D3:FC:36:7D:A9:8E:B7:10
elsif( m/^ fetchmail: \s+ (?<host> \S+) \s+ key \s+ fingerprint: \s+ (?<fingerprint> \S+) $/x )
{
printf STDERR "=%s,%d,%s: %s // %s\n",__FILE__,__LINE__,$proc_name
, &main::format_key_value_list($main::std_formatting_options,
'$+{host}' => $+{host} ,
'$+{fingerprint}' => $+{fingerprint} ,
)
,'...'
if 1 && $main::options{debug};
printf STDOUT " poll %s\n sslfingerprint \"%s\"\t# >= %s\n",$+{host},$+{fingerprint},$now_string
if 1;
}
# this regexp will get refined, so that it will also tell us, if and when they will NOT match
# fetchmail: jh60.gmx.net fingerprints match.
# fetchmail: t-online.de fingerprints match.
# fetchmail: jh-gapps.gmail.com fingerprints do not match!
# fetchmail: jh.gmail.com fingerprints do not match!
elsif( m/^ fetchmail: \s+ (?<all> (?<host> \S+) \s+ fingerprints \s+ (?<middle> .* \s+ | ) match. ) $/x )
{
my(%plus) = %+;
printf STDOUT " # {%s}%s\n",
$plus{all},
( $plus{middle} eq '' ) ? '' : '# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
if 1;
$exit_value = 1
if $plus{middle} ne '';
}
}
exit($exit_value);
}
#
sub format_key_value_list
{
my $refOptions = shift(@_);
my $buf;
confess '!defined($refOptions)' unless defined($refOptions); # -> use Carp
my %options = %{$refOptions};
foreach my $i ('separator', 'assign', 'quoteLeft', 'quoteRight') {
$options{$i} = '' unless defined($options{$i});
}
my ($name,$value);
while($#_ >=0) {
($name,$value) = splice(@_,0,2);
my $chunk = "$name$options{assign}$options{quoteLeft}$value$options{quoteRight}";
if (defined($buf)) {
$buf .= "$options{separator}$chunk";
} else {
$buf = $chunk;
}
}
return $buf;
}