line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LWP::UserAgent::ProxyAny; |
2
|
1
|
|
|
1
|
|
20418
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
4
|
|
|
|
|
|
|
our $VERSION = "1.01"; |
5
|
1
|
|
|
1
|
|
7
|
use base qw(LWP::UserAgent); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
1129
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub env_proxy { |
8
|
1
|
|
|
1
|
1
|
269
|
my ( $this ) = @_; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Call real env_proxy of LWP UserAgent |
11
|
1
|
|
|
|
|
11
|
$this->SUPER::env_proxy; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Try to get IE proxy setttings, return if not Win32 or not set |
14
|
1
|
|
|
|
|
18708
|
my $ie_proxy_no = ""; |
15
|
1
|
|
|
|
|
6
|
my $ie_proxy_server = $this->get_ie_proxy( $ie_proxy_no ); |
16
|
1
|
50
|
|
|
|
6
|
return if $ie_proxy_server eq ""; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Set LWP proxy |
19
|
0
|
0
|
|
|
|
0
|
if( $ie_proxy_server=~/;/ ) { |
20
|
|
|
|
|
|
|
#Multiple proxies, such as ftp=192.168.1.3:8080;...;https=192.168.1.3:8080 |
21
|
0
|
|
0
|
|
|
0
|
map /^(.*?)=(.*?)$/ && $this->proxy( $1, "http://$2/" ), split( /;/, $ie_proxy_server ); |
22
|
|
|
|
|
|
|
}else{ |
23
|
|
|
|
|
|
|
#Single proxy, such as 192.168.1.3:8080 |
24
|
0
|
|
|
|
|
0
|
$this->proxy( ['http','https','ftp','gopher'], "http://$ie_proxy_server/" ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Set LWP no_proxy |
28
|
0
|
0
|
|
|
|
0
|
$this->no_proxy( map( //i ? "localhost" : $_, split( /;/, $ie_proxy_no ) ) ) |
|
|
0
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if $ie_proxy_no ne ""; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_ie_proxy { |
33
|
2
|
50
|
|
2
|
1
|
4887
|
return "" unless $^O eq 'MSWin32'; |
34
|
0
|
|
|
|
|
0
|
my %RegHash; |
35
|
0
|
|
|
|
|
0
|
eval 'use Win32::TieRegistry(Delimiter=>"/", TiedHash=>\%RegHash);'; |
36
|
0
|
0
|
|
|
|
0
|
return get_ie_proxy_with_registry() if $@; |
37
|
0
|
0
|
|
|
|
0
|
my $iekey = $RegHash{"CUser/Software/Microsoft/Windows/CurrentVersion/Internet Settings/"} or return ""; |
38
|
0
|
0
|
|
|
|
0
|
my $ie_proxy_enable = $iekey->{"/ProxyEnable"} or return ""; |
39
|
0
|
0
|
|
|
|
0
|
my $ie_proxy_server = $iekey->{"/ProxyServer"} or return ""; |
40
|
0
|
|
|
|
|
0
|
my $ie_proxy_no = $iekey->{"/ProxyOverride"}; |
41
|
0
|
0
|
|
|
|
0
|
$_[1]=$ie_proxy_no if defined($ie_proxy_no); |
42
|
0
|
0
|
|
|
|
0
|
return $ie_proxy_enable=~/1$/ ? $ie_proxy_server : ""; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_ie_proxy_with_registry { |
46
|
0
|
0
|
|
0
|
0
|
0
|
return "" unless $^O eq 'MSWin32'; |
47
|
0
|
|
|
|
|
0
|
eval 'use Win32::Registry;'; |
48
|
0
|
0
|
|
|
|
0
|
return "" if $@; |
49
|
0
|
|
|
|
|
0
|
my ( $iekey, $type, $ie_proxy_enable, $ie_proxy_server, $ie_proxy_no ); |
50
|
1
|
|
|
1
|
|
67044
|
no warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
83
|
|
51
|
0
|
0
|
|
|
|
0
|
$::HKEY_CURRENT_USER->Open( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", $iekey ) or return ""; |
52
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
499
|
|
53
|
0
|
|
|
|
|
0
|
$iekey->QueryValueEx( "ProxyEnable", $type, $ie_proxy_enable ); |
54
|
0
|
|
|
|
|
0
|
$iekey->QueryValueEx( "ProxyServer", $type, $ie_proxy_server ); |
55
|
0
|
|
|
|
|
0
|
$iekey->QueryValueEx( "ProxyOverride", $type, $ie_proxy_no ); |
56
|
0
|
|
|
|
|
0
|
$iekey->Close; |
57
|
0
|
0
|
|
|
|
0
|
$_[1]=$ie_proxy_no if defined($ie_proxy_no); |
58
|
0
|
0
|
0
|
|
|
0
|
return defined($ie_proxy_enable) && $ie_proxy_enable=~/1$/ && defined($ie_proxy_server) |
59
|
|
|
|
|
|
|
? $ie_proxy_server : ""; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub set_proxy_by_name { |
63
|
1
|
|
|
1
|
1
|
439
|
my ( $this, $proxy_name ) = @_; |
64
|
1
|
|
|
|
|
3
|
$proxy_name=~s/ //g; # Remove spaces |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#Don't use proxy |
67
|
1
|
50
|
33
|
|
|
12
|
return if $proxy_name=~/^No$/i or $proxy_name eq ""; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Use default proxy |
70
|
1
|
50
|
|
|
|
6
|
if( $proxy_name=~/^(System|Default)/i ) { |
71
|
0
|
|
|
|
|
0
|
$this->env_proxy; |
72
|
0
|
|
|
|
|
0
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Set user-defined proxy |
76
|
1
|
|
|
|
|
4
|
$proxy_name =~ s/^http:\/\///i; |
77
|
1
|
|
|
|
|
15
|
$this->proxy( ['http','https','ftp','gopher'], "http://$proxy_name" ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |