aboutsummaryrefslogtreecommitdiff
path: root/examples/inspect
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2020-02-26 15:48:20 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2020-02-27 17:40:57 +0200
commit3b2d57c14f1ed207c79362b7136e3da4054ad817 (patch)
tree8f97331e65e3d6cc0d483fc0c3d11a2e668e33be /examples/inspect
parenta9a6567bac8ab7729c243b555e7fb3c4bb2c6e51 (diff)
downloadping903-3b2d57c14f1ed207c79362b7136e3da4054ad817.tar.gz
ping903-3b2d57c14f1ed207c79362b7136e3da4054ad817.tar.bz2
Implememt client-side basic auth
* lib/Makefile.am: Add base64.c * lib/base64.c: New file. * lib/basicauth.c: Move base64 support to a separate source. * lib/basicauth.h (base64_encode,base64_decode): New protos. * src/strsplit.c: New file. * src/Makefile.am (libping903_a_SOURCES): Add strsplit.c * src/defs.h (CRED_FILE_NAME): New macro. (ecalloc,strsplit,argcv_free): New proto. * src/mem.c (ecalloc): New function. * src/ping903.c (strsplit): Remove. (cf_auth): Use modified strsplit. * src/ping903q.c (http_query): Attempt to authenticate if basic auth is required. * examples/lib/LWP/Ping903.pm: New file. * examples/dbload: Use LWP::Ping903 * examples/inspect: Likewise. * examples/ipadd: Likewise. * examples/ipdel: Likewise.
Diffstat (limited to 'examples/inspect')
-rwxr-xr-xexamples/inspect17
1 files changed, 13 insertions, 4 deletions
diff --git a/examples/inspect b/examples/inspect
index beebc17..6aacad4 100755
--- a/examples/inspect
+++ b/examples/inspect
@@ -57,13 +57,16 @@ L<DBI>.
use strict;
use warnings;
-use LWP::UserAgent;
+use LWP::Ping903;
+use HTTP::Status qw(:constants);
use JSON;
use Getopt::Long qw(:config gnu_getopt no_ignore_case);
use Pod::Usage;
use Pod::Man;
my $baseurl = 'http://localhost:8080';
+my $user;
+my $password;
GetOptions(
'U|url=s' => \$baseurl,
@@ -80,9 +83,17 @@ GetOptions(
) or exit(1);
die "too many arguments; try `$0 --help' for more info\n" if @ARGV;
-my $ua = new LWP::UserAgent;
+my $ua = new LWP::Ping903;
+
my $response = $ua->get("$baseurl/config");
unless ($response->is_success) {
+ if ($response->code eq HTTP_UNAUTHORIZED) {
+ my $s = $response->header('WWW-Authenticate');
+ $s =~ s/Basic realm=//;
+ $s =~ s/^"(.*)"$/$1/;
+ $s =~ s/\\([\\\"])/$1/g;
+ die "$s: not authorized";
+ }
die $response->status_line;
}
@@ -111,5 +122,3 @@ if (@{$resp->{'ip-list'}}) {
}
print "EOF\n";
}
-
-

Return to:

Send suggestions and report system problems to the System administrator.