#!/usr/local/bin/perl # wwget # World Wide Getter(?) # by Yoshioka Tsuneo(ke3057yt@ex.ecip.osaka-u.ac.jp) # Copy, Edit, Distribute FREE !! # # support Proxy Server # support GET,POST method # Only Support HTTP Protocol # # You need client.pl $prog=__FILE__; $progdir=$prog; $progdir=~s|/[^/]*$||; push(@INC,"$progdir"); require 'client.pl'; # package wwget; local($default_proxy); local($default_limit_time,$default_limit_size); if(-e '/ECIP'){ $default_proxy="http://wwwproxy:8080/"; } # If you need proxy server,leave # and set server,port. # $default_proxy="http://server:port/"; local($public_delegate_server)="http://ringer.etl.go.jp/"; # please see /usr/include/sys/socket.h # or /usr/include/linux/socket.h and so on. # eval("require 'sys/socket.h'"); local($AF_INET,$SOCK_STREAM); if($ENV{'OSTYPE'} =~ m/(linux|next)/i){ $AF_INET=2;$SOCK_STREAM=1; }elsif($ENV{'OSTYPE'} =~ m#sun#i){ $AF_INET=2;$SOCK_STREAM=2; }elsif((-e '/NextApps') || (-e '/sbin/lilo')){ $AF_INET=2;$SOCK_STREAM=1; }elsif($ENV{'OSTYPE'} eq 'irix'){ $AF_INET=2;$SOCK_STREAM=2; }elsif(`uname -s` eq 'osf1'){ $AF_INET=2;$SOCK_STREAM=1; }else{ $AF_INET=2;$SOCK_STREAM=2; $AF_INET=2;$SOCK_STREAM=1; } sub purse_URL { local($URL)=@_; local($proto,$server,$port,$path); # print "URL is [$URL]\n"; if(! ($URL =~ m|^(\w+):|)){ print "

URL [$URL] isn't correct

\n"; exit 1; } local($post) = $'; $proto=$1;$proto =~ tr/A-Z/a-z/; if($proto eq "http"){ if(! ($post=~ m|^//([^/:]+)(:\d+)?(/.*)?$|)){ print "

URL [$URL] isn't correct

\n";exit 1; } $server=$1; $port=$2;if($port ne ""){$port =~ s/^://;}else{$port=80;} $path=$3;if($path eq ""){$path="/";} }elsif($proto eq "ftp"){ if(! ($post=~ m&^//([^/:]+|.*:.*\@[^/:]+)(:\d+)?(/.*)?$&)){ #|.*:.*\@[^/:]+ print "

URL [$URL] isn't correct

\n";exit 1; } $server=$1; $port=$2;if($port ne ""){$port =~ s/^://;}else{$port=80;} $path=$3;if($path eq ""){$path="/";} }elsif($proto eq "file"){ if(! ($post=~ m|^/+(.*)?$|)){ print "

URL [$URL] isn't correct

\n";exit 1; } $path=$1;if($path eq ""){$path="/";} }else{ # $port= ((getservbyname($proto,'tcp'))[2]); print "Protocol [$proto] not supported\n"; exit 1; } # print "proto=$proto,server=$server,port=$port,path=$path\n"; ($proto,$server,$port,$path); } sub getbody { # local($path)=@_; local(*S)=@_; local($i); $i=0;$|=1; while(read(S,$_,4096)>0){ $i+=4; if(($limit_size ne "") && ($i>$limit_size)){ print "

warning: " . "this file is over $limit_size lines.

\n"; return; } print $_; } } sub getbody2 { local(*S)=@_; while(){ s/\n//g;s/\r//g; if(/^$/){ last; } } &getbody(*S); } sub setheader { local($TAG,$level)=@_; local($header,$body); if($TAG eq 'GET' || $TAG eq 'HEAD'){ if($level eq ""){ $header="";$body=""; }else{ while(){ chop; $header.= $_ . "\n"; if(/^$/){last;} } $body=""; } }elsif($TAG eq 'POST'){ if($level eq ""){ while(){ $body.=$_; } $header.= "Content-length: " . length($body) . "\n"; }else{ local($len)=0; while(){ chop; if(/^$/){last;} $header.=$header . "\n"; if(/^Content-length: (\d+)/){$len=$1;} } if($len!=0){ read(STDIN,$body,$len); } } }else{ print "[wwget error]setheader($TAG,$level)\n"; } # print "setheader($TAG,$level) end\n"; ($header,$body); } #$default_limit_size=50; #$default_limit_time=60*5; sub wwget_usage { local($prog)=`basename $0`;chop($prog); print "usage: $prog [] [GET|POST|HEAD] [HTTP/]\n"; print " option: -s :Limit Size to get(KB)\n"; #(default $default_limit_size(kb))\n"; print " -t