Possibility to check certificate
with available --no-cert-check option to disable it. Auto disable if connecting on localhost
This commit is contained in:
parent
b2076e496f
commit
10660aedf6
|
@ -6,20 +6,22 @@ use JSON;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use HTTP::Cookies;
|
use HTTP::Cookies;
|
||||||
|
use URI;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
umask 077;
|
umask 077;
|
||||||
|
|
||||||
my $user = 'zabbix';
|
my $user = 'zabbix';
|
||||||
my $pass = 'secret';
|
my $pass = 'secret';
|
||||||
my $site = 'default';
|
my $site = 'default';
|
||||||
my $url = 'https://localhost:8443';
|
my $url = 'https://localhost:8443';
|
||||||
|
my $certcheck = 1;
|
||||||
my $unifi;
|
my $unifi;
|
||||||
my $dev;
|
my $dev;
|
||||||
my $station;
|
my $station;
|
||||||
my $net;
|
my $net;
|
||||||
my $wlan;
|
my $wlan;
|
||||||
my $pretty = 0;
|
my $pretty = 0;
|
||||||
|
|
||||||
my $json = {};
|
my $json = {};
|
||||||
my $site_id;
|
my $site_id;
|
||||||
|
@ -29,6 +31,7 @@ GetOptions (
|
||||||
'password|p=s' => \$pass,
|
'password|p=s' => \$pass,
|
||||||
'site=s' => \$site,
|
'site=s' => \$site,
|
||||||
'url=s' => \$url,
|
'url=s' => \$url,
|
||||||
|
'cert-check!' => \$certcheck,
|
||||||
'unifi' => \$unifi,
|
'unifi' => \$unifi,
|
||||||
'dev=s' => \$dev,
|
'dev=s' => \$dev,
|
||||||
'station=s' => \$station,
|
'station=s' => \$station,
|
||||||
|
@ -37,6 +40,12 @@ GetOptions (
|
||||||
'pretty' => \$pretty
|
'pretty' => \$pretty
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# If connecting to localhost, no need to check certificate
|
||||||
|
my $uri = URI->new($url);
|
||||||
|
if ($uri->host =~ m/^localhost|127\.0\.0/){
|
||||||
|
$certcheck = 0;
|
||||||
|
}
|
||||||
|
|
||||||
my @radio_proto = qw/a b g na ng ac/;
|
my @radio_proto = qw/a b g na ng ac/;
|
||||||
my $resp;
|
my $resp;
|
||||||
my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
|
my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
|
||||||
|
@ -45,8 +54,13 @@ my $cj = HTTP::Cookies->new(
|
||||||
autosave => 1,
|
autosave => 1,
|
||||||
ignore_discard => 1
|
ignore_discard => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $sslopts = {};
|
||||||
|
if (not $certcheck){
|
||||||
|
$sslopts = { verify_hostname => 0, SSL_verify_mode => 0 }
|
||||||
|
}
|
||||||
my $ua = LWP::UserAgent->new(
|
my $ua = LWP::UserAgent->new(
|
||||||
ssl_opts => { verify_hostname => 0 },
|
ssl_opts => $sslopts,
|
||||||
cookie_jar => $cj
|
cookie_jar => $cj
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -6,17 +6,19 @@ use JSON;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use HTTP::Cookies;
|
use HTTP::Cookies;
|
||||||
|
use URI;
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
umask 077;
|
umask 077;
|
||||||
|
|
||||||
my $user = 'zabbix';
|
my $user = 'zabbix';
|
||||||
my $pass = 'secret';
|
my $pass = 'secret';
|
||||||
my $site = 'default';
|
my $site = 'default';
|
||||||
my $url = 'https://localhost:8443';
|
my $url = 'https://localhost:8443';
|
||||||
my $what = 'devices';
|
my $certcheck = 1;
|
||||||
my $type = 'all';
|
my $what = 'devices';
|
||||||
my $pretty = 0;
|
my $type = 'all';
|
||||||
|
my $pretty = 0;
|
||||||
|
|
||||||
my $json = {};
|
my $json = {};
|
||||||
@{$json->{data}} = ();
|
@{$json->{data}} = ();
|
||||||
|
@ -26,6 +28,7 @@ GetOptions (
|
||||||
'password|p=s' => \$pass,
|
'password|p=s' => \$pass,
|
||||||
'site=s' => \$site,
|
'site=s' => \$site,
|
||||||
'url=s' => \$url,
|
'url=s' => \$url,
|
||||||
|
'cert-check!' => \$certcheck,
|
||||||
'what=s' => \$what,
|
'what=s' => \$what,
|
||||||
'type:s' => \$type,
|
'type:s' => \$type,
|
||||||
'pretty' => \$pretty
|
'pretty' => \$pretty
|
||||||
|
@ -33,6 +36,13 @@ GetOptions (
|
||||||
|
|
||||||
# An empty type is the same as all
|
# An empty type is the same as all
|
||||||
$type = 'all' if ($type eq '');
|
$type = 'all' if ($type eq '');
|
||||||
|
|
||||||
|
# If connecting to localhost, no need to check certificate
|
||||||
|
my $uri = URI->new($url);
|
||||||
|
if ($uri->host =~ m/^localhost|127\.0\.0/){
|
||||||
|
$certcheck = 0;
|
||||||
|
}
|
||||||
|
|
||||||
my $site_id;
|
my $site_id;
|
||||||
my $resp;
|
my $resp;
|
||||||
my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
|
my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
|
||||||
|
@ -41,8 +51,14 @@ my $cj = HTTP::Cookies->new(
|
||||||
autosave => 1,
|
autosave => 1,
|
||||||
ignore_discard => 1
|
ignore_discard => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $sslopts = {};
|
||||||
|
if (not $certcheck){
|
||||||
|
$sslopts = { verify_hostname => 0, SSL_verify_mode => 0 }
|
||||||
|
}
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new(
|
my $ua = LWP::UserAgent->new(
|
||||||
ssl_opts => { verify_hostname => 0 },
|
ssl_opts => $sslopts,
|
||||||
cookie_jar => $cj
|
cookie_jar => $cj
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user