Created
December 18, 2009 03:52
-
-
Save taiyoh/259275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 他のポート番号を指定する際につけてください | |
#port = 3128 | |
# デバッグオプションを有効にしたいときにつけてください | |
#debug = 1 | |
# プロキシサーバへつなぐ為のパラメータ。ホスト名かIPを指定してください | |
#domain = hogehoge.local | |
[www.example.com] | |
/path/to/remote.js = /path/to/local.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# このファイルは3つともダウンロードしてください。 | |
# $ perl pac_manager.pl list.ini | |
# でproxy.pacが出力されます。 | |
use strict; | |
use warnings; | |
use FindBin; | |
use Text::MicroTemplate; | |
use Config::Tiny; | |
my $conf_file = shift(@ARGV); | |
die('no conf file') unless ($conf_file); | |
die("Config file passed on command line ($conf_file) could not be read.¥n") unless (-r $conf_file); | |
my %config = %{ Config::Tiny->read( $conf_file ) }; | |
my $root_config = delete $config{_}; | |
$root_config->{port} ||= 3128; | |
$root_config->{domain} ||= 'localhost'; | |
my $mt = Text::MicroTemplate->new( | |
template => do { | |
open my $fh, '<:utf8', "$FindBin::Bin/proxy.pac.mt"; | |
my $data = do { local $/; <$fh> }; | |
close $fh; | |
$data; | |
}, | |
); | |
my $code = $mt->code; | |
my $renderer = eval << "..." or die $@; | |
sub { | |
my ¥$root_config = shift; | |
my ¥$hosts = shift; | |
$code->(); | |
} | |
... | |
my $rendered = $renderer->($root_config, ¥%config); | |
print $rendered; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FindProxyForURL(url, host) { | |
var proxy = 'PROXY <?= $root_config->{domain} ?>:<?= $root_config->{port} ?>'; | |
? for my $h (keys %{$hosts}) { | |
? (my $_h = $h) =‾ s#¥.#¥¥.#g; | |
if (dnsDomainIs(host, '<?= $_h ?>')) { | |
<? my @p = map { | |
s{¥.}{¥¥.}g; | |
s{¥/}{¥¥/}g; | |
s{¥?}{¥¥?}g; | |
$_ | |
} keys %{$hosts->{$h}}; | |
?> | |
if(/(<?= join( '|', @p) ?>)/.test(url)) { | |
return proxy; | |
} | |
} | |
? } | |
return 'DIRECT'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment