#!/usr/local/bin/perl # # get.cgi by Take (http://www02.so-net.ne.jp/~shintan/) # httpでWebページを持ってきて表示する # # $lib_dir = '/~foo/libwww'; # libwwwを別のディレクトリに置く時に設定する # push(@INC,$lib_dir); require "www.pl"; require "wwwurl.pl"; require "wwwerror.pl"; $CGI_DIR = '/~foo/libwww/'; # 自分の環境に合わせて書き換えること $CGI_URL = 'http://www.***.jp/~foo/libwww/'; # 自分の環境に合わせて書き換えること $HTM_URL = 'http://www.***.jp/~foo/libwww/'; # 自分の環境に合わせて書き換えること # &set_proxy; # 外部アクセスにプロキシを経由する必要がある場合コメントを外す $method = 'GET'; # Method = GET $UserAgent = "get.cgi/0.00 ($HTM_URL)"; # Set up User-Agent: header &www'set_def_header('http', 'User-Agent', $UserAgent); $pwd = ( $ENV{'PWD'} || $ENV{'cwd'} || '' ); $Base = "file://localhost$pwd/"; # Set up initial Base URL $Tout = 60; # Time-out in seconds $Ims = ''; # If-Modified-Since header $home = $CGI_DIR; if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name,$value) = split(/=/,$pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } $url = $FORM{'URL'}; # WebページのURLを取得 $url =~ s///g; if ($url eq '' || $url eq 'http://' || !($url =~ m#^http\://#i)){ print "Location: " . $HTM_URL . "get.htm\n\n"; exit(0); } $url = &wwwurl'absolute($Base, $url); %headers = (); $headers = ''; $content = ''; $headers{'Referer'} = $ENV{'HTTP_REFERER'}; $headers{'Forwarded'} = 'by $HTM_URL for '.($ENV{'REMOTE_HOST'} || $ENV{'REMOTE_ADDR'}); if ($ENV{'HTTP_FORWARDED'} ne ''){ $headers{'Forwarded'} .= ', '.$ENV{'HTTP_FORWARDED'}; } $url =~ m#://([^/]+)/#; # virtual host対応 $host = $1; if ($host ne ''){ $headers{'Host'} = $host; } $response = &www'request($method, $url, *headers, *content, $Tout); if ($response == 200){ # 正常に取得出来た場合 print "Content-type: text/html\n\n"; print $content; } else { # 取得に失敗した場合 print "Content-type: text/html\n\n"; print $content; } exit; # プロキシの設定 # サーバー管理者に設定を確認すること sub set_proxy { $ENV{'http_proxy'} = "http://10.0.1.254:8080/"; $ENV{'https_proxy'} = "http://10.0.1.254:8080/"; $ENV{'ftp_proxy'} = "http://10.0.1.254:8080/"; }