File manager - Edit - /var/www/payraty/helpdesk/public/storage/LWP.zip
Back
PK ! �lF Authen/Digest.pmnu �[��� package LWP::Authen::Digest; use strict; use parent 'LWP::Authen::Basic'; our $VERSION = '6.61'; require Digest::MD5; sub _reauth_requested { my ($class, $auth_param, $ua, $request, $auth_header) = @_; my $ret = defined($$auth_param{stale}) && lc($$auth_param{stale}) eq 'true'; if ($ret) { my $hdr = $request->header($auth_header); $hdr =~ tr/,/;/; # "," is used to separate auth-params!! ($hdr) = HTTP::Headers::Util::split_header_words($hdr); my $nonce = {@$hdr}->{nonce}; delete $$ua{authen_md5_nonce_count}{$nonce}; } return $ret; } sub auth_header { my($class, $user, $pass, $request, $ua, $h) = @_; my $auth_param = $h->{auth_param}; my $nc = sprintf "%08X", ++$ua->{authen_md5_nonce_count}{$auth_param->{nonce}}; my $cnonce = sprintf "%8x", time; my $uri = $request->uri->path_query; $uri = "/" unless length $uri; my $md5 = Digest::MD5->new; my(@digest); $md5->add(join(":", $user, $auth_param->{realm}, $pass)); push(@digest, $md5->hexdigest); $md5->reset; push(@digest, $auth_param->{nonce}); if ($auth_param->{qop}) { push(@digest, $nc, $cnonce, ($auth_param->{qop} =~ m|^auth[,;]auth-int$|) ? 'auth' : $auth_param->{qop}); } $md5->add(join(":", $request->method, $uri)); push(@digest, $md5->hexdigest); $md5->reset; $md5->add(join(":", @digest)); my($digest) = $md5->hexdigest; $md5->reset; my %resp = map { $_ => $auth_param->{$_} } qw(realm nonce opaque); @resp{qw(username uri response algorithm)} = ($user, $uri, $digest, "MD5"); if (($auth_param->{qop} || "") =~ m|^auth([,;]auth-int)?$|) { @resp{qw(qop cnonce nc)} = ("auth", $cnonce, $nc); } my(@order) = qw(username realm qop algorithm uri nonce nc cnonce response opaque); my @pairs; for (@order) { next unless defined $resp{$_}; # RFC2617 says that qop-value and nc-value should be unquoted. if ( $_ eq 'qop' || $_ eq 'nc' ) { push(@pairs, "$_=" . $resp{$_}); } else { push(@pairs, "$_=" . qq("$resp{$_}")); } } my $auth_value = "Digest " . join(", ", @pairs); return $auth_value; } 1; PK ! �uX Authen/Ntlm.pmnu �[��� package LWP::Authen::Ntlm; use strict; our $VERSION = '6.61'; use Authen::NTLM "1.02"; use MIME::Base64 "2.12"; sub authenticate { my($class, $ua, $proxy, $auth_param, $response, $request, $arg, $size) = @_; my($user, $pass) = $ua->get_basic_credentials($auth_param->{realm}, $request->uri, $proxy); unless(defined $user and defined $pass) { return $response; } if (!$ua->conn_cache()) { warn "The keep_alive option must be enabled for NTLM authentication to work. NTLM authentication aborted.\n"; return $response; } my($domain, $username) = split(/\\/, $user); ntlm_domain($domain); ntlm_user($username); ntlm_password($pass); my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization"; # my ($challenge) = $response->header('WWW-Authenticate'); my $challenge; foreach ($response->header('WWW-Authenticate')) { last if /^NTLM/ && ($challenge=$_); } if ($challenge eq 'NTLM') { # First phase, send handshake my $auth_value = "NTLM " . ntlm(); ntlm_reset(); # Need to check this isn't a repeated fail! my $r = $response; my $retry_count = 0; while ($r) { my $auth = $r->request->header($auth_header); ++$retry_count if ($auth && $auth eq $auth_value); if ($retry_count > 2) { # here we know this failed before $response->header("Client-Warning" => "Credentials for '$user' failed before"); return $response; } $r = $r->previous; } my $referral = $request->clone; $referral->header($auth_header => $auth_value); return $ua->request($referral, $arg, $size, $response); } else { # Second phase, use the response challenge (unless non-401 code # was returned, in which case, we just send back the response # object, as is my $auth_value; if ($response->code ne '401') { return $response; } else { my $challenge; foreach ($response->header('WWW-Authenticate')) { last if /^NTLM/ && ($challenge=$_); } $challenge =~ s/^NTLM //; ntlm(); $auth_value = "NTLM " . ntlm($challenge); ntlm_reset(); } my $referral = $request->clone; $referral->header($auth_header => $auth_value); my $response2 = $ua->request($referral, $arg, $size, $response); return $response2; } } 1; __END__ =pod =head1 NAME LWP::Authen::Ntlm - Library for enabling NTLM authentication (Microsoft) in LWP =head1 SYNOPSIS use LWP::UserAgent; use HTTP::Request::Common; my $url = 'http://www.company.com/protected_page.html'; # Set up the ntlm client and then the base64 encoded ntlm handshake message my $ua = LWP::UserAgent->new(keep_alive=>1); $ua->credentials('www.company.com:80', '', "MyDomain\\MyUserCode", 'MyPassword'); $request = GET $url; print "--Performing request now...-----------\n"; $response = $ua->request($request); print "--Done with request-------------------\n"; if ($response->is_success) {print "It worked!->" . $response->code . "\n"} else {print "It didn't work!->" . $response->code . "\n"} =head1 DESCRIPTION L<LWP::Authen::Ntlm> allows LWP to authenticate against servers that are using the NTLM authentication scheme popularized by Microsoft. This type of authentication is common on intranets of Microsoft-centric organizations. The module takes advantage of the Authen::NTLM module by Mark Bush. Since there is also another Authen::NTLM module available from CPAN by Yee Man Chan with an entirely different interface, it is necessary to ensure that you have the correct NTLM module. In addition, there have been problems with incompatibilities between different versions of L<Mime::Base64>, which Bush's L<Authen::NTLM> makes use of. Therefore, it is necessary to ensure that your Mime::Base64 module supports exporting of the C<encode_base64> and C<decode_base64> functions. =head1 USAGE The module is used indirectly through LWP, rather than including it directly in your code. The LWP system will invoke the NTLM authentication when it encounters the authentication scheme while attempting to retrieve a URL from a server. In order for the NTLM authentication to work, you must have a few things set up in your code prior to attempting to retrieve the URL: =over 4 =item * Enable persistent HTTP connections To do this, pass the C<< "keep_alive=>1" >> option to the L<LWP::UserAgent> when creating it, like this: my $ua = LWP::UserAgent->new(keep_alive=>1); =item * Set the credentials on the UserAgent object The credentials must be set like this: $ua->credentials('www.company.com:80', '', "MyDomain\\MyUserCode", 'MyPassword'); Note that you cannot use the L<HTTP::Request> object's C<authorization_basic()> method to set the credentials. Note, too, that the C<'www.company.com:80'> portion only sets credentials on the specified port AND it is case-sensitive (this is due to the way LWP is coded, and has nothing to do with LWP::Authen::Ntlm) =back =head1 AVAILABILITY General queries regarding LWP should be made to the LWP Mailing List. Questions specific to LWP::Authen::Ntlm can be forwarded to jtillman@bigfoot.com =head1 COPYRIGHT Copyright (c) 2002 James Tillman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L<LWP>, L<LWP::UserAgent>, L<lwpcook>. =cut PK ! �}�,< < Authen/Basic.pmnu �[��� package LWP::Authen::Basic; use strict; our $VERSION = '6.61'; require Encode; require MIME::Base64; sub auth_header { my($class, $user, $pass, $request, $ua, $h) = @_; my $userpass = "$user:$pass"; # https://tools.ietf.org/html/rfc7617#section-2.1 my $charset = uc($h->{auth_param}->{charset} || ""); $userpass = Encode::encode($charset, $userpass) if ($charset eq "UTF-8"); return "Basic " . MIME::Base64::encode($userpass, ""); } sub _reauth_requested { return 0; } sub authenticate { my($class, $ua, $proxy, $auth_param, $response, $request, $arg, $size) = @_; my $realm = $auth_param->{realm} || ""; my $url = $proxy ? $request->{proxy} : $request->uri_canonical; return $response unless $url; my $host_port = $url->host_port; my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization"; my @m = $proxy ? (m_proxy => $url) : (m_host_port => $host_port); push(@m, realm => $realm); my $h = $ua->get_my_handler("request_prepare", @m, sub { $_[0]{callback} = sub { my($req, $ua, $h) = @_; my($user, $pass) = $ua->credentials($host_port, $h->{realm}); if (defined $user) { my $auth_value = $class->auth_header($user, $pass, $req, $ua, $h); $req->header($auth_header => $auth_value); } }; }); $h->{auth_param} = $auth_param; my $reauth_requested = $class->_reauth_requested($auth_param, $ua, $request, $auth_header); if ( !$proxy && (!$request->header($auth_header) || $reauth_requested) && $ua->credentials($host_port, $realm)) { # we can make sure this handler applies and retry add_path($h, $url->path) unless $reauth_requested; # Do not clobber up path list for retries return $ua->request($request->clone, $arg, $size, $response); } my($user, $pass) = $ua->get_basic_credentials($realm, $url, $proxy); unless (defined $user and defined $pass) { $ua->set_my_handler("request_prepare", undef, @m); # delete handler return $response; } # check that the password has changed my ($olduser, $oldpass) = $ua->credentials($host_port, $realm); return $response if (defined $olduser and defined $oldpass and $user eq $olduser and $pass eq $oldpass); $ua->credentials($host_port, $realm, $user, $pass); add_path($h, $url->path) unless $proxy; return $ua->request($request->clone, $arg, $size, $response); } sub add_path { my($h, $path) = @_; $path =~ s,[^/]+\z,,; push(@{$h->{m_path_prefix}}, $path); } 1; PK ! m�� � MediaTypes.pmnu �[��� package LWP::MediaTypes; require Exporter; @ISA = qw(Exporter); @EXPORT = qw(guess_media_type media_suffix); @EXPORT_OK = qw(add_type add_encoding read_media_types); our $VERSION = '6.04'; use strict; use Scalar::Util qw(blessed); use Carp qw(croak); # note: These hashes will also be filled with the entries found in # the 'media.types' file. my %suffixType = ( 'txt' => 'text/plain', 'html' => 'text/html', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'xml' => 'text/xml', ); my %suffixExt = ( 'text/plain' => 'txt', 'text/html' => 'html', 'image/gif' => 'gif', 'image/jpeg' => 'jpg', 'text/xml' => 'xml', ); #XXX: there should be some way to define this in the media.types files. my %suffixEncoding = ( 'Z' => 'compress', 'gz' => 'gzip', 'hqx' => 'x-hqx', 'uu' => 'x-uuencode', 'z' => 'x-pack', 'bz2' => 'x-bzip2', ); read_media_types(); sub guess_media_type { my($file, $header) = @_; return undef unless defined $file; my $fullname; if (ref $file) { croak("Unable to determine filetype on unblessed refs") unless blessed($file); if ($file->can('path')) { $file = $file->path; } elsif ($file->can('filename')) { $fullname = $file->filename; } else { $fullname = "" . $file; } } else { $fullname = $file; # enable peek at actual file } my @encoding = (); my $ct = undef; for (file_exts($file)) { # first check this dot part as encoding spec if (exists $suffixEncoding{$_}) { unshift(@encoding, $suffixEncoding{$_}); next; } if (exists $suffixEncoding{lc $_}) { unshift(@encoding, $suffixEncoding{lc $_}); next; } # check content-type if (exists $suffixType{$_}) { $ct = $suffixType{$_}; last; } if (exists $suffixType{lc $_}) { $ct = $suffixType{lc $_}; last; } # don't know nothing about this dot part, bail out last; } unless (defined $ct) { # Take a look at the file if (defined $fullname) { $ct = (-T $fullname) ? "text/plain" : "application/octet-stream"; } else { $ct = "application/octet-stream"; } } if ($header) { $header->header('Content-Type' => $ct); $header->header('Content-Encoding' => \@encoding) if @encoding; } wantarray ? ($ct, @encoding) : $ct; } sub media_suffix { if (!wantarray && @_ == 1 && $_[0] !~ /\*/) { return $suffixExt{lc $_[0]}; } my(@type) = @_; my(@suffix, $ext, $type); foreach (@type) { if (s/\*/.*/) { while(($ext,$type) = each(%suffixType)) { push(@suffix, $ext) if $type =~ /^$_$/i; } } else { my $ltype = lc $_; while(($ext,$type) = each(%suffixType)) { push(@suffix, $ext) if lc $type eq $ltype; } } } wantarray ? @suffix : $suffix[0]; } sub file_exts { require File::Basename; my @parts = reverse split(/\./, File::Basename::basename($_[0])); pop(@parts); # never consider first part @parts; } sub add_type { my($type, @exts) = @_; for my $ext (@exts) { $ext =~ s/^\.//; $suffixType{$ext} = $type; } $suffixExt{lc $type} = $exts[0] if @exts; } sub add_encoding { my($type, @exts) = @_; for my $ext (@exts) { $ext =~ s/^\.//; $suffixEncoding{$ext} = $type; } } sub read_media_types { my(@files) = @_; local($/, $_) = ("\n", undef); # ensure correct $INPUT_RECORD_SEPARATOR my @priv_files = (); push(@priv_files, "$ENV{HOME}/.media.types", "$ENV{HOME}/.mime.types") if defined $ENV{HOME}; # Some doesn't have a home (for instance Win32) # Try to locate "media.types" file, and initialize %suffixType from it my $typefile; unless (@files) { @files = map {"$_/LWP/media.types"} @INC; push @files, @priv_files; } for $typefile (@files) { local(*TYPE); open(TYPE, $typefile) || next; while (<TYPE>) { next if /^\s*#/; # comment line next if /^\s*$/; # blank line s/#.*//; # remove end-of-line comments my($type, @exts) = split(' ', $_); add_type($type, @exts); } close(TYPE); } } 1; __END__ =head1 NAME LWP::MediaTypes - guess media type for a file or a URL =head1 SYNOPSIS use LWP::MediaTypes qw(guess_media_type); $type = guess_media_type("/tmp/foo.gif"); =head1 DESCRIPTION This module provides functions for handling media (also known as MIME) types and encodings. The mapping from file extensions to media types is defined by the F<media.types> file. If the F<~/.media.types> file exists it is used instead. For backwards compatibility we will also look for F<~/.mime.types>. The following functions are exported by default: =over 4 =item guess_media_type( $filename ) =item guess_media_type( $uri ) =item guess_media_type( $filename_or_object, $header_to_modify ) This function tries to guess media type and encoding for a file or objects that support the a C<path> or C<filename> method, eg, L<URI> or L<File::Temp> objects. When an object does not support either method, it will be stringified to determine the filename. It returns the content type, which is a string like C<"text/html">. In array context it also returns any content encodings applied (in the order used to encode the file). You can pass a URI object reference, instead of the file name. If the type can not be deduced from looking at the file name, then guess_media_type() will let the C<-T> Perl operator take a look. If this works (and C<-T> returns a TRUE value) then we return I<text/plain> as the type, otherwise we return I<application/octet-stream> as the type. The optional second argument should be a reference to a HTTP::Headers object or any object that implements the $obj->header method in a similar way. When it is present the values of the 'Content-Type' and 'Content-Encoding' will be set for this header. =item media_suffix( $type, ... ) This function will return all suffixes that can be used to denote the specified media type(s). Wildcard types can be used. In a scalar context it will return the first suffix found. Examples: @suffixes = media_suffix('image/*', 'audio/basic'); $suffix = media_suffix('text/html'); =back The following functions are only exported by explicit request: =over 4 =item add_type( $type, @exts ) Associate a list of file extensions with the given media type. Example: add_type("x-world/x-vrml" => qw(wrl vrml)); =item add_encoding( $type, @ext ) Associate a list of file extensions with an encoding type. Example: add_encoding("x-gzip" => "gz"); =item read_media_types( @files ) Parse media types files and add the type mappings found there. Example: read_media_types("conf/mime.types"); =back =head1 COPYRIGHT Copyright 1995-1999 Gisle Aas. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. PK ! >+�� � UserAgent.pmnu �[��� # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*- # vim: ts=4 sts=4 sw=4: package CPAN::LWP::UserAgent; use strict; use vars qw(@ISA $USER $PASSWD $SETUPDONE); use CPAN::HTTP::Credentials; # we delay requiring LWP::UserAgent and setting up inheritance until we need it $CPAN::LWP::UserAgent::VERSION = $CPAN::LWP::UserAgent::VERSION = "1.9601"; sub config { return if $SETUPDONE; if ($CPAN::META->has_usable('LWP::UserAgent')) { require LWP::UserAgent; @ISA = qw(Exporter LWP::UserAgent); ## no critic $SETUPDONE++; } else { $CPAN::Frontend->mywarn(" LWP::UserAgent not available\n"); } } sub get_basic_credentials { my($self, $realm, $uri, $proxy) = @_; if ( $proxy ) { return CPAN::HTTP::Credentials->get_proxy_credentials(); } else { return CPAN::HTTP::Credentials->get_non_proxy_credentials(); } } sub no_proxy { my ( $self, $no_proxy ) = @_; return $self->SUPER::no_proxy( split(',',$no_proxy) ); } # mirror(): Its purpose is to deal with proxy authentication. When we # call SUPER::mirror, we really call the mirror method in # LWP::UserAgent. LWP::UserAgent will then call # $self->get_basic_credentials or some equivalent and this will be # $self->dispatched to our own get_basic_credentials method. # Our own get_basic_credentials sets $USER and $PASSWD, two globals. # 407 stands for HTTP_PROXY_AUTHENTICATION_REQUIRED. Which means # although we have gone through our get_basic_credentials, the proxy # server refuses to connect. This could be a case where the username or # password has changed in the meantime, so I'm trying once again without # $USER and $PASSWD to give the get_basic_credentials routine another # chance to set $USER and $PASSWD. sub mirror { my($self,$url,$aslocal) = @_; my $result = $self->SUPER::mirror($url,$aslocal); if ($result->code == 407) { CPAN::HTTP::Credentials->clear_credentials; $result = $self->SUPER::mirror($url,$aslocal); } $result; } 1; PK ! ���Y Y Debug/TraceHTTP.pmnu �[��� package LWP::Debug::TraceHTTP; # Just call: # # require LWP::Debug::TraceHTTP; # LWP::Protocol::implementor('http', 'LWP::Debug::TraceHTTP'); # # to use this module to trace all calls to the HTTP socket object in # programs that use LWP. use strict; use parent 'LWP::Protocol::http'; our $VERSION = '6.61'; package # hide from PAUSE LWP::Debug::TraceHTTP::Socket; use Data::Dump 1.13; use Data::Dump::Trace qw(autowrap mcall); autowrap("LWP::Protocol::http::Socket" => "sock"); sub new { my $class = shift; return mcall("LWP::Protocol::http::Socket" => "new", undef, @_); } 1; PK ! �~�c/"