home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet 1996 World Exposition
/
park.org.s3.amazonaws.com.7z
/
park.org.s3.amazonaws.com
/
cgi-bin
/
Japan
/
WIDE
/
listup
< prev
next >
Wrap
Text File
|
2017-09-21
|
6KB
|
293 lines
#! /usr/local/bin/perl
require '/usr/local/lib/perl/chat2.pl';
$persondb = '~suna/db/members';
$companydb = '~suna/db/company';
# check the validity of the environment variables
#&checkvalid;
# obtain query argument
#if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# $query = $ENV{'QUERY_STRING'};
#} else {
# $query = <STDIN>;
#}
$query = $ENV{'QUERY_STRING'};
#$query = $ARGV[0];
## separate parameters
foreach $i (split(/\+/, $query)) {
foreach $hex ($i =~ /\%([0-9A-F][0-9A-F])/g) {
eval '$i =~ ' . "s/\\%$hex/\\x$hex/g";
}
$i =~ s:/:\\x2F:g;
$i =~ s/\`/\\x60/g;
$i =~ s/\</\<\;/g;
$i =~ s/\>/\>\;/g;
$i =~ s/\&/\&\;/g;
$i =~ s/\$/\\x24/g;
push(@keywords, $i);
}
$keywords[0] = $ARGV[0];
if ($ARGV[1]) {
$keywords[1] = $ARGV[1];
}
if (scalar(@keywords) == 0 || scalar(@keywords) > 2) {
exit 1;
}
$mailinglist = $keywords[0];
$japanese = 0;
if ($keywords[1] eq 'japanese') {
$japanese = 1;
}
&readdb;
$ok = 0;
if ($mailinglist eq 'board'
|| $mailinglist eq 'wide'
|| $mailinglist =~ /-?tf$/
|| $mailinglist =~ /-?wg$/) {
$ok = 1;
}
if (! $ok) {
exit 1;
}
@members = &expn($mailinglist, 'sh.wide.ad.jp');
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>WIDE mailing list $mailinglist@wide.ad.jp</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1>Member of $mailinglist@wide.ad.jp</H1>\n";
print "<UL>\n";
foreach $i (@members) {
$name = $mailaddr = $homepage = $companyaddr = $company = $companyhomepage = '';
if ($i =~ /<([^>]*)>/) {
$mailaddr = $1;
$i =~ s/<([^>]*)>//;
$i =~ s/\s+/ /g;
$i =~ s/^\s+//;
$i =~ s/\s+$//;
$name = $i;
} else {
$mailaddr = $i;
$name = '';
}
# special rule
next if ($mailaddr =~ /^\\wide/);
# search for the name
$tmp = $mailaddr;
nameloop:
while (&domainlen($tmp) >= 3) {
if ($name{$tmp}) {
$mailaddr = $tmp;
$name = $name{$mailaddr};
last nameloop;
}
$tmp = &shorten($tmp);
}
# search for the company
$tmp = $mailaddr;
companyloop:
while (&domainlen($tmp) >= 2) {
if ($company{&domainname($tmp)}) {
$companyaddr = &domainname($tmp);
$company = $company{$companyaddr};
last companyloop;
}
$tmp = &shorten($tmp);
}
if ($japanese && $jname{$mailaddr}) {
$name = $jname{$mailaddr};
}
if ($homepage{$mailaddr}) {
$homepage = $homepage{$mailaddr};
}
if ($japanese && $jcompany{$companyaddr}) {
$company = $jcompany{$companyaddr};
}
if ($companyhomepage{$companyaddr}) {
$companyhomepage = $companyhomepage{$companyaddr};
}
# pretty print
print "<LI> ";
if ($name) {
if ($homepage) {
print "<A HREF=$homepage>$name</A>: ";
} else {
print "$name: ";
}
}
print $mailaddr;
if ($company) {
if ($companyhomepage) {
print ", <A HREF=$companyhomepage>$company</A>\n";
} else {
print ", $company\n";
}
}
}
print "</UL>\n";
print "</BODY></HTML>\n";
exit 0;
#------------------------------------------------------------
sub shorten {
local($addr) = @_;
local($user, $domain, @tmp);
($user, $domain) = split('@', $addr);
@tmp = split(/\./, $domain);
shift(@tmp);
return $user . '@' . join('.', @tmp);
}
sub domainlen {
local($addr) = @_;
local($user, $domain, @tmp);
($user, $domain) = split('@', $addr);
@tmp = split(/\./, $domain);
return scalar(@tmp);
}
sub domainname {
local($addr) = @_;
local($user, $domain);
($user, $domain) = split('@', $addr);
return $domain;
}
#------------------------------------------------------------
sub readdb {
local($account);
undef %name;
undef %jname;
undef %homepage;
undef %company;
undef %jcompany;
undef %companyhomepage;
if (! open(DB, $persondb)) {
return;
}
while (<DB>) {
chop;
split(/\t+/);
next if (! ($_[0] && $_[0] ne '-'));
$account = $_[0];
if ($_[1] && $_[1] ne '-') {
$name{$account} = $_[1];
}
if ($_[2] && $_[2] ne '-') {
$jname{$account} = $_[2];
}
if ($_[3] && $_[3] ne '-') {
$homepage{$account} = $_[3];
}
}
close(DB);
if (! open(DB, $companydb)) {
return;
}
while (<DB>) {
chop;
split(/\t+/);
next if (! ($_[0] && $_[0] ne '-'));
if ($_[1] && $_[1] ne '-') {
$company{$_[0]} = $_[1];
}
if ($_[2] && $_[2] ne '-') {
$jcompany{$_[0]} = $_[2];
}
if ($_[3] && $_[3] ne '-') {
$companyhomepage{$_[0]} = $_[3];
}
}
close(DB);
}
#------------------------------------------------------------
sub expn {
local($list, $host) = @_;
local(@ret, @result);
&chat'open_port($host, 25);
&expectexpn('220');
&chat'print("helo\n");
&expectexpn('250');
&chat'print("expn $list\n");
@ret = &expectexpn('250');
@result = ();
foreach $i (@ret) {
$i =~ s/^250[- ]//;
push(@result, $i);
}
&finishexpn;
return @result;
}
sub expectexpn {
local($arg) = @_;
local(@result);
$timeout = 30;
@expectarg = ('TIMEOUT', 'exit 1;',
'EOF', 'exit 1;');
$pre = '^';
if( $arg =~ /^\d+$/ ){
$pre = "[.|\n]*^";
}
push(@expectarg, "$pre(" . $arg . "-.*)\\015\\012");
push(@expectarg, 'push(@result, $1); 10;');
push(@expectarg, "$pre(" . $arg . " .*)\\015\\012");
push(@expectarg, 'push(@result, $1); 0;');
push(@expectarg, "^(.*)\\015\\012");
push(@expectarg, 'print $1; 5;');
while (1) {
$ret = &chat'expect($timeout, @expectarg);
return @result if ($ret == 0);
&finishexpn if ($ret == 5);
next if ($ret == 10);
}
}
sub finishexpn {
&chat'print("quit\n");
&chat'close;
}
sub checkvalid {
if (! defined($ENV{'REQUEST_METHOD'})) {
exit 1;
}
if (! defined($ENV{'PATH_INFO'})) {
exit 1;
}
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
if (! defined($ENV{'QUERY_STRING'})) {
exit 1;
}
}
}