Identify/Ssh.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Hardware/Temperature.pm ↑ Summary Image/Convert.pm »
1 #
2 # $Id$
3 #
4 # identify::ssh Brik
5 #
6 package Metabrik::Identify::Ssh;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 banner => [ qw(string) ],
20 },
21 commands => {
22 parsebanner => [ qw(banner|OPTIONAL) ],
23 },
24 };
25 }
26  
27 sub parsebanner {
28 my $self = shift;
29 my ($banner) = @_;
30  
31 $banner ||= $self->banner;
32 $self->brik_help_run_undef_arg('parsebanner', $banner) or return;
33  
34 # From most specific to less specific
35 my $data = [
36 [
37 '^SSH-(\d+\.\d+)-OpenSSH_(\d+\.\d+\.\d+)(p\d+) Ubuntu-(2ubuntu2)$' => {
38 ssh_protocol_version => '$1',
39 ssh_product_version => '$2',
40 ssh_product_feature_portable => '$3',
41 ssh_os_distribution_version => '$4',
42 ssh_product => 'OpenSSH',
43 ssh_os => 'Linux',
44 ssh_os_distribution => 'Ubuntu',
45 },
46 ],
47 [
48 '^SSH-(\d+\.\d+)-OpenSSH_(\d+\.\d+)_(\S+) (\S+)$' => {
49 ssh_protocol_version => '$1',
50 ssh_product_version => '$2',
51 ssh_product_feature_portable => '$3',
52 ssh_product => 'OpenSSH',
53 ssh_extra => '$4',
54 },
55 ],
56 [
57 '^SSH-(\d+\.\d+)(.*)$' => {
58 ssh_protocol_version => '$1',
59 ssh_product => 'undef',
60 ssh_extra => '$2',
61 },
62 ],
63 ];
64  
65 my $result = {};
66 for my $elt (@$data) {
67 my $re = $elt->[0];
68 my $info = $elt->[1];
69 if ($banner =~ /$re/) {
70 for my $k (keys %$info) {
71 $result->{$k} = eval($info->{$k}) || $info->{$k};
72 }
73 last;
74 }
75 }
76  
77 return $result;
78 }
79  
80 1;
81  
82 __END__
« Hardware/Temperature.pm ↑ Summary Image/Convert.pm »