/usr/share/perl5/LWP/Protocol/socks.pm is in liblwp-protocol-socks-perl 1.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | ##############################
package LWP::Protocol::http::socks;
require LWP::Protocol::http;
our @ISA = qw(LWP::Protocol::http);
our $VERSION = "1.5";
LWP::Protocol::implementor('http::socks' => 'LWP::Protocol::http::socks');
sub new {
my $self = shift->SUPER::new(@_);
$self->{scheme} =~ s/::socks$//;
$self;
}
sub _extra_sock_opts {
my $self = shift;
my($host, $port) = @_;
my @extra_sock_opts = $self->SUPER::_extra_sock_opts(@_);
#(@extra_sock_opts, SocksDebug =>1, @{$self->{proxy_sock_opts}});
(@extra_sock_opts, @{$self->{proxy_sock_opts}});
}
##############################
package LWP::Protocol::http::socks::Socket;
require LWP::Protocol::http;
require IO::Socket::Socks;
require Net::HTTP;
our @ISA = qw(LWP::Protocol::http::SocketMethods IO::Socket::Socks Net::HTTP);
sub configure {
my $self = shift;
my $args = shift;
my $connectAddr = $args->{ConnectAddr} = delete $args->{PeerAddr};
my $connectPort = $args->{ConnectPort} = delete $args->{PeerPort};
$self->SUPER::configure($args);
$self->http_configure($args);
}
# hack out the connect so it doesn't reconnect
sub http_connect {
1;
}
##############################
package LWP::Protocol::https::socks;
require LWP::Protocol::https;
our @ISA = qw(LWP::Protocol::https);
LWP::Protocol::implementor('https::socks' => 'LWP::Protocol::https::socks');
sub new {
my $self = shift->SUPER::new(@_);
$self->{scheme} =~ s/::socks$//;
$self;
}
sub _extra_sock_opts {
my $self = shift;
my($host, $port) = @_;
my @extra_sock_opts = $self->SUPER::_extra_sock_opts(@_);
(@extra_sock_opts, @{$self->{proxy_sock_opts}});
#(@extra_sock_opts, @{$self->{proxy_sock_opts}});
}
##############################
package LWP::Protocol::https::socks::Socket;
require LWP::Protocol::https;
require IO::Socket::Socks;
use IO::Socket::SSL;
require Net::HTTPS;
our @ISA = qw(IO::Socket::SSL LWP::Protocol::https::Socket);
sub new {
my $class = shift;
my %args = @_;
my $connectAddr = $args{ConnectAddr} = delete $args{PeerAddr};
my $connectPort = $args{ConnectPort} = delete $args{PeerPort};
my $socks = new IO::Socket::Socks(%args);
$args{PeerAddr} = $connectAddr;
$args{PeerPort} = $connectPort;
delete $args{ProxyAddr};
delete $args{ProxyPort};
delete $args{ConnectAddr};
delete $args{ConnectPort};
my $ssl = new_from_fd LWP::Protocol::https::socks::Socket($socks, %args);
$ssl->http_configure(\%args);
$ssl;
}
# hack out the connect so it doesn't reconnect
sub http_connect {
1;
}
##############################
package LWP::Protocol::socks;
require LWP::Protocol;
our @ISA = qw(LWP::Protocol);
sub request {
my($self, $request, $proxy, $arg, $size, $timeout) = @_;
my $url = $request->uri;
my $scheme = $url->scheme;
my $protocol = LWP::Protocol::create("$scheme\::socks", $self->{ua});
$protocol->{proxy_sock_opts} = [ProxyAddr => $proxy->host,
ProxyPort => $proxy->port,
];
# [RT 48172] Adding user/pass functionality
if ( $proxy->userinfo() ) {
push(@{$protocol->{proxy_sock_opts}},
AuthType => 'userpass',
Username => $proxy->user(),
Password => $proxy->pass(),
);
}
$protocol->request($request, undef, $arg, $size, $timeout);
}
1;
__END__
=head1 NAME
LWP::Protocol::socks - adds support for the socks protocol and proxy facility
=head1 SYNOPSIS
use LWP::Protocol::socks;
=head1 DESCRIPTION
Use this package when you wish to use a socks proxy for your
connections.
It provides some essential hooks into the LWP system to implement a
socks "scheme" similar to http for describing your socks connection,
and can be used to proxy either http or https connections.
The use case is to use LWP::UserAgent's proxy method to register your
socks proxy like so:
$ua->proxy([qw(http https)] => 'socks://socks.yahoo.com:1080');
Then just use your $ua object as usual!
=head1 EXAMPLES
#!/usr/local/bin/perl
use strict;
use LWP::UserAgent;
my $ua = new LWP::UserAgent(agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5');
# for socks5, use socks like so:
$ua->proxy([qw(http https)] => 'socks://socks.yahoo.com:1080');
# for socks4, use socks4 like so:
$ua->proxy([qw(http https)] => 'socks4://socks.yahoo.com:1080');
my $response = $ua->get("http://www.freebsd.org");
print $response->code,' ', $response->message,"\n";
my $response = $ua->get("https://www.microsoft.com");
print $response->code,' ', $response->message,"\n";
=head1 AUTHORS
Sheridan C Rawlins E<lt>F<sheridan.rawlins@yahoo.com>E<gt>
Oleg G E<lt>F<oleg@cpan.org>E<gt>
|