mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 04:07:52 +00:00
har-to-portal: able to print out data for requests in reasonable perl format
This commit is contained in:
@@ -16,9 +16,16 @@ use Data::Dumper;
|
|||||||
$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
|
$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
|
||||||
$SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
|
$SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
|
||||||
#use constant NA => "NA";
|
#use constant NA => "NA";
|
||||||
use constant NL => "\n";
|
use constant NL => "\n";
|
||||||
#use constant Q => '"';
|
use constant Q => q(");
|
||||||
#use constant q => "'";
|
use constant a => q(');
|
||||||
|
use constant qQ => qq('");
|
||||||
|
use constant CS => q(: );
|
||||||
|
use constant c => q(,);
|
||||||
|
use constant dQH => q( ." -H ');
|
||||||
|
use constant CA => q(=>$::curl_args);
|
||||||
|
use constant MP => q( 'method'=>'POST',);
|
||||||
|
use constant PD => q( 'post_data'=>);
|
||||||
#use constant nbsp => " ";
|
#use constant nbsp => " ";
|
||||||
$| = 1;
|
$| = 1;
|
||||||
|
|
||||||
@@ -83,44 +90,67 @@ our $Decoder = JSON->new->utf8;
|
|||||||
my $json = $::Decoder->decode($har_txt);
|
my $json = $::Decoder->decode($har_txt);
|
||||||
$::Decoder->canonical(1);
|
$::Decoder->canonical(1);
|
||||||
$::Decoder->allow_blessed(1);
|
$::Decoder->allow_blessed(1);
|
||||||
#print Dumper(\$json);
|
|
||||||
|
|
||||||
my %ordered_entries = ();
|
my %ordered_entries = ();
|
||||||
print "I see ".(length($json->{log}->{entries}))." entries\n";
|
print "I see ".(length($json->{log}->{entries}))." entries\n";
|
||||||
|
|
||||||
foreach my $entry (@{$json->{log}->{entries}}) {
|
foreach my $entry (@{$json->{log}->{entries}}) {
|
||||||
my $request_start = $entry->{startedDateTime};
|
my $request_start = $entry->{startedDateTime};
|
||||||
$ordered_entries{$request_start} = \$entry;
|
$ordered_entries{$request_start} = \$entry;
|
||||||
#print Dumper(\$entry);
|
|
||||||
#print "------------------------------------------------------------------------------------\n";
|
|
||||||
}
|
}
|
||||||
print "------------------------------------------------------------------------------------\n";
|
print "------------------------------------------------------------------------------------\n";
|
||||||
print "------------------------------------------------------------------------------------\n";
|
my $found_redirect = 0;
|
||||||
print "------------------------------------------------------------------------------------\n";
|
my $found_login_post = 0;
|
||||||
print "------------------------------------------------------------------------------------\n";
|
die("unable to open $::outfile: $!") unless open($fh, ">", $::outfile);
|
||||||
for my $request_start ( sort keys %ordered_entries ) {
|
for my $request_start ( sort keys %ordered_entries ) {
|
||||||
print "Start: $request_start\n";
|
print "Start: $request_start\n";
|
||||||
my $entry = $ordered_entries{$request_start};
|
my $entry = $ordered_entries{$request_start};
|
||||||
#print Dumper($entry);
|
my $request = $$entry->{request};
|
||||||
#print "REF: ".ref($entry);
|
my $response = $$entry->{response};
|
||||||
my $request = $$entry->{request};
|
|
||||||
#print Dumper($request);
|
|
||||||
my $ra_headers = $request->{headers};
|
|
||||||
|
|
||||||
my $url = $request->{url};
|
my $req_headers = $request->{headers};
|
||||||
my $method = $request->{method};
|
my $res_headers = $response->{headers};
|
||||||
print "$method: $url\n";
|
|
||||||
#print Dumper($request) if ($method eq "POST");
|
|
||||||
|
|
||||||
for my $header_e (@$ra_headers) {
|
my $req_cookies = $request->{cookies} if (defined $request->{cookies}) || [];
|
||||||
print " H: ".$header_e->{name} .": ".$header_e->{value} .NL;
|
my $res_cookies = $response->{cookies} if (defined $response->{cookies}) || [];
|
||||||
|
|
||||||
|
my $url = $request->{url};
|
||||||
|
my $method = $request->{method};
|
||||||
|
print $fh "------------------------------------------------------------------------------------\n";
|
||||||
|
print $fh "$method: $url\n";
|
||||||
|
print $fh "------------------------------------------------------------------------------------\n";
|
||||||
|
print $fh "request({'curl_args'".CA;
|
||||||
|
|
||||||
|
for my $header_e (@$req_headers) {
|
||||||
|
print $fh NL.dQH. $header_e->{name} .CS. $header_e->{value} .qQ;
|
||||||
}
|
}
|
||||||
|
print $fh c.NL;
|
||||||
if ($method eq "POST") {
|
if ($method eq "POST") {
|
||||||
print " D: ".$request->{'postData'}->{text} .NL;
|
$found_login_post++;
|
||||||
|
print $fh MP.NL;
|
||||||
|
print $fh PD.a. $request->{'postData'}->{text} .a.c.NL;
|
||||||
}
|
}
|
||||||
}
|
print $fh q( 'url'=>).Q. $url .Q.c.NL;
|
||||||
|
print $fh q( 'print'=>1).NL;
|
||||||
|
print $fh q[}, \@response);].NL.NL;
|
||||||
|
for my $req_cookie(@$req_cookies) {
|
||||||
|
print $fh " request_cookie ";
|
||||||
|
print $fh "{'".$req_cookie->{name}."'} = '".$req_cookie->{value}."';\n";
|
||||||
|
}
|
||||||
|
print $fh NL;
|
||||||
|
if ($response->{status} == 301 || $response->{status} == 302) {
|
||||||
|
$found_redirect++;
|
||||||
|
print $fh "Expect redirect: ".$response->{status}.NL;
|
||||||
|
}
|
||||||
|
for my $header_e (@$res_headers) {
|
||||||
|
print $fh " response_header: ".$header_e->{name} .": ".$header_e->{value} .NL;
|
||||||
|
}
|
||||||
|
for my $res_cookie(@$res_cookies) {
|
||||||
|
print $fh " response_cookie";
|
||||||
|
print $fh "{'".$res_cookie->{name}."'} = '".$res_cookie->{value}."';\n";
|
||||||
|
}
|
||||||
|
} # ~for each request sorted by time
|
||||||
|
|
||||||
#die("unable to open $::outfile: $!") unless open($fh, ">", $::outfile);
|
#
|
||||||
# create find_redirect_url()
|
# create find_redirect_url()
|
||||||
|
|
||||||
# create submit_login()
|
# create submit_login()
|
||||||
|
|||||||
Reference in New Issue
Block a user