EPFL-Net-SSLTest

 view release on metacpan or  search on metacpan

bin/epfl-net-ssl-test  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Getopt::Long;
use Pod::Usage;

use Carp qw/croak/;
use English qw/-no_match_vars/;
use LWP::UserAgent;
use Term::ANSIColor;
use WebService::SSLLabs;

=head1 NAME

epfl-net-ssl-test

=head1 DESCRIPTION

Check SSL connectivity from a Website with ssllabs.com

=head1 VERSION

Version 1.00

=head1 USAGE

  epfl-net-ssl-test --help

  epfl-net-ssl-test --domain=actu.epfl.ch

=cut

our $VERSION = '1.00';

my ( $help, $domain );

GetOptions(
  'domain=s' => \$domain,
  'help'     => \$help,
) || pod2usage(2);

if ( $help || !$domain ) {
  pod2usage(1);
  exit 0;
}

my $labs = WebService::SSLLabs->new();
my $host;

while ( not $host = $labs->analyze( host => $domain )->complete() ) {
  sleep $labs->previous_eta();
}

if ( $host->ready() ) {
  foreach my $endpoint ( $host->endpoints() ) {
    if ( $endpoint->ready() ) {
      print "\n", $endpoint->ip_address(), "\n"
        or croak "Couldn't write: $OS_ERROR";
      print color('green'), '✔ Diode', "\n", color('clear')
        or croak "Couldn't write: $OS_ERROR";
      print color('green'), '✔ SSL Certificate', "\n", color('clear')
        or croak "Couldn't write: $OS_ERROR";
      if ( $endpoint->grade() eq 'A' or $endpoint->grade() eq 'A+' ) {
        print color('green'), '✔ Grade ', $endpoint->grade(), "\n\n",
          color('clear')
          or croak "Couldn't write: $OS_ERROR";
      }
      else {
        print color('red'), '✘ Grade ', $endpoint->grade(), "\n\n",
          color('clear')
          or croak "Couldn't write: $OS_ERROR";
      }
    }
    else {
      print "\n", color('red'), '✘ Diode', "\n", color('clear')
        or croak "Couldn't write: $OS_ERROR";
      checkLocalCertificate($domain);
    }
  }
}
else {
  print "\n", color('red'), '✘ ', $host->status_message(), "\n\n",
    color('clear')
    or croak "Couldn't write: $OS_ERROR";
  exit 1;
}

sub checkLocalCertificate {
  my $dom = shift;

  my $url     = 'https://' . $dom;
  my $ua      = LWP::UserAgent->new;
  my $request = HTTP::Request->new( HEAD => $url );

  my $response = $ua->request($request);
  if ( $response->is_error ) {
    print color('red'), '✘ SSL Certificate', "\n\n", color('clear')
      or croak "Couldn't write: $OS_ERROR";
  }
  if ( $response->is_success ) {
    print color('green'), '✔ SSL Certificate', "\n\n", color('clear')
      or croak "Couldn't write: $OS_ERROR";
  }

  return;
}

=head1 AUTHOR

William Belle, C<< <william.belle at gmail.com> >>

=head1 BUGS AND LIMITATIONS

Please report any bugs or feature requests here
L<https://github.com/epfl-idevelop/epfl-net-sslTest/issues>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc EPFL::Net::SSLTest

You can also look for information at:

=over 4

=item * AnnoCPAN: Annotated CPAN documentation



( run in 1.356 second using v1.01-cache-2.11-cpan-524268b4103 )