#!/usr/bin/perl # INDEXO ver.2.00, (C)Copyright 2001 OGATA, Tetsuji. use strict; #========================================================================== # [ Note ] #========================================================================== my $scriptname = 'indexo'; my $version = 'ver.2.00'; my $copyright = '緒方哲治'; #-------------------------------------------------------------------------- # [ 著作権・使用上の注意 ] # # このソフトウェア(以下「INDEXO」と記述)は緒方哲治が作成しました。 # 著作権は緒方哲治に属します。 # 著作者の許可なく配布・販売することを禁止します。 # INDEXOはフリーソフトです。 # INDEXOを使用して発生したいかなる損害に対しても著作者はその責任を負いません。 # 改造は自由ですが、スクリプト内にある著作者情報は削除・変更しないでください。 # INDEXOを使用したことにより「すごい」とか「どうやったの?」とか言われたときは # CGIぽんを紹介するようにしてください。そのときのセリフは # 「なぁに、簡単なことさ。…CGIぽんのINDEXOを使えばね。」 # でお願いします。 # perlはversion5以上を使用してください。 # # CGIぽん http://specters.net/cgipon/ 緒方哲治 cgipon@specters.net #========================================================================== # [ 開始 ] #========================================================================== #-------------------------------------------------------------------------- # [ 変数設定 ] # 以下は書き換えない方がよい my $filename = 'indexo.txt'; my $countia = './countia.pl'; my %countia; my $config; my ($title,$background,$bgcolor,$textcolor,$linkcolor); my @lines; my %link; #-------------------------------------------------------------------------- # [ 設定ファイルの読み込み ] &READ_FILE; if ($config =~ /COUNTIA/) { &COUNTIA; } #-------------------------------------------------------------------------- # [ ブラウザの判別と出力 ] my $ua = $ENV{'HTTP_USER_AGENT'}; my @ua = split(/\//,$ua); if (($ua[0] eq 'PDXGW') || ($ua[0] eq 'Ginga')) { &PRINT_ONC; } elsif ($ua[0] eq 'UP.Browser') { &PRINT_HDML; } elsif ($ua[0] =~ /UP\.Browser|OPWV/) { &PRINT_XHTMLMP; } elsif ( ($ua[0] eq 'DoCoMo') || ($ua[0] eq 'J-PHONE') || ($ua[0] eq 'L-mode')|| ($ua[0] eq 'ASTEL')) { &PRINT_CHTML; } else { &PRINT_HTML; } exit; #-------------------------------------------------------------------------- # [ ONCの出力 ] sub PRINT_ONC { # 飛ばし処理 if ($link{'h'}) { if ($link{'h'} =~ /^http:/) { $link{'h'} =~ s/^http://g; print <<"_EOF_"; Content-type: text/plain From:$link{'h'} Subject:Jump! Content-Type:Text/X-PmailDX もう一度通話ボタンを押して下さい。 _EOF_ } elsif ($link{'h'} =~ /\.txt$/i) { print "Content-type: text/plain\n\n"; open(FILE,"<$link{'h'}"); foreach () { print; } close(FILE); } elsif ($link{'h'} =~ /\.html?$/i) { print "Content-type: text/html\n\n"; open(FILE,"<$link{'h'}"); foreach () { print; } close(FILE); } else { print "Content-type: text/html\n\n"; print "飛ばし文が不正です。"; } exit; } # 端末情報取得 my ($pdx,%pdx,$hr,$imgext); $ua[1] =~ s/ //g; ($ua[1],$pdx) = split(/\(/,$ua[1]); $pdx =~ s/\)$//; $pdx ||= q(TX=6;TY=3;GX=72;GY=36;C=G2;G=B2;GI=0); foreach (split(/;/,$pdx)) { my ($name,$value) = split(/=/,$_); $pdx{$name} = $value; } $hr = '−' x $pdx{'TX'}; $imgext = '.bmp'; # 出力準備 my ($add,$sel,$body,$ket); foreach (@lines) { my ($type,$serv,$posi,$text,$url,$key) = split(/<>/); if ($serv !~ /h/) { next; } $text =~ s/</</g; $text =~ s/&/&/g; if ($posi eq 'c') { $body .= $ket; if ($type eq 't') { $body .= ' ' x int($pdx{'TX'} - length($text) / 2); } $ket = "\n"; } elsif ($posi eq 'r') { $body .= $ket; if ($type eq 't') { $body .= ' ' x ($pdx{'TX'} * 2 - length($text)); } $ket = "\n"; } elsif ($posi eq 's') { $body .= $ket; $ket = "\n"; } elsif (($posi ne '^') && ($type ne 'h')) { $body .= $ket; $ket = "\n"; } if ($type eq 'c') { $type = 't'; $text =~ s/\[([\w]+)\]/$countia{$1}/g; } if ($type eq 't') { $url ||= $textcolor; $url =~ s/^#//; if ($url && ($pdx{'GI'} >= 2)) { $body .= qq($text); } else { $body .= qq($text); } } elsif ($type eq 'i') { $url =~ s/\.[^\.]+$//; $add .= qq(X-PmailDX-CTRL-Append: Name="$url$imgext"\n); if ($pdx{'GI'} >= 2) { $body .= qq(); } else { $body .= qq(図[$text]); } } elsif ($type eq 'a') { $url =~ s/^http://; $sel .= qq(\n); $body =~ s/\n$//g; if ($linkcolor && ($pdx{'GI'} >= 2)) { $body .= qq(\n$key⇒$text); } else { $body .= qq(\n$key⇒$text); } } elsif ($type eq 'm') { $body .= qq($text(<#MAIL>$url)); } elsif ($type eq 'p') { $body .= qq($text(<#TELEPHONE>$url)); } elsif ($type eq 'h') { $body .= qq($ket$hr\n); $ket = ''; } } $body .= $ket; $body =~ s/\n+$//; # 出力 print qq(Content-Type: text/plain\n\n); print qq($add); print qq(From: //$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}\n); print qq(Subject: $title\n); print qq(Content-Type: Text/X-PmailDX\n\n); print qq($sel); if (($pdx{GI} >= 2) && ($bgcolor || $textcolor)) { print qq(\n); } print qq($body); } #-------------------------------------------------------------------------- # [ HDMLの出力 ] sub PRINT_HDML { # 飛ばし処理 if ($link{'e'}) { if ($link{'e'} =~ /^http:\/\//) { print "Location:$link{'e'}\n\n"; } elsif ($link{'e'} =~ /\.html?$/i) { print qq(Content-type: text/html\n\n); open (FILE,"<$link{'e'}"); foreach () { print; } close FILE; } elsif ($link{'e'} =~ /\.hdml$/i) { print qq(Content-type: text/x-hdml;charset=Shift_JIS\n\n); open (FILE,"<$link{'e'}"); foreach () { print; } close FILE; } else { print "Content-type: text/html\n\n"; print "飛ばし文が不正です。"; } exit; } # 端末情報取得 my ($hr,$imgext,$mailto); if ($ENV{'HTTP_X_UP_DEVCAP_SCREENCHARS'}) { $hr = '-' x (split(/,/,$ENV{'HTTP_X_UP_DEVCAP_SCREENCHARS'}))[0]; } else { $hr = q(------------); } if ($ENV{'HTTP_X_UP_DEVCAP_ISCOLOR'}) { $imgext = '.png'; } else { $imgext = '.bmp'; } if ($ENV{'HTTP_X_UP_FAX_LIMIT'}) { $mailto = q(device:home/goto?svc=Email&SUB=sendMsg" vars="TO=); } else { $mailto = q(mailto:); } # 出力準備 my ($body,$ket); foreach (@lines) { my ($type,$serv,$posi,$text,$url,$key) = split(/<>/); if ($serv !~ /e/) { next; } $text =~ s/\$/&dol;/g; if ($posi eq 'c') { $body .= $ket; $body .= qq(
); $ket = qq(
\n); } elsif ($posi eq 'r') { $body .= $ket; $body .= qq(); $ket = qq(
\n); } elsif ($posi eq 's') { $body .= $ket; $body .= qq(); $ket = qq(\n); } elsif (($posi ne '^') && ($type ne 'h')) { $body .= $ket; $ket = qq(
\n); } if ($type eq 'c') { $type = 't'; $text =~ s/\[([\w]+)\]/$countia{$1}/g; } if ($type eq 't') { $body .= qq($text); } elsif ($type eq 'i') { $text =~ s/"/"/g; $url =~ s/\.[^\.]+$//; $body .= qq($text); } elsif ($type eq 'a') { if ($key =~ /^\d$/) { $body .= qq($text); } else { $body .= qq($text); } } elsif ($type eq 'm') { if ($key =~ /^\d$/) { $body .= qq($text); } else { $body .= qq($text); } } elsif ($type eq 'p') { if ($key =~ /^\d$/) { $body .= qq(); $body .= qq($text); } else { $body .= qq($text); } } elsif ($type eq 'h') { $body .= qq($ket$hr
\n); $ket = ''; } } $body =~ s//
\n/g; $body .= $ket; $body =~ s/(?:
\n?)+\n?$//; $body =~ s/\n+$//; # 出力 print qq(Content-type: text/x-hdml;charset=Shift_JIS\n\n); print qq(\n); print qq(\n$body\n\n); } #-------------------------------------------------------------------------- # [ XHTML-MPの出力 ] sub PRINT_XHTMLMP { # 飛ばし処理 if ($link{'e'}) { if ($link{'e'} =~ /^http:\/\//) { print "Location:$link{'e'}\n\n"; } elsif ($link{'e'} =~ /\.html?$/i) { print qq(Content-type: text/html\n\n); open (FILE,"<$link{'e'}"); foreach () { print; } close FILE; } elsif ($link{'e'} =~ /\.hdml$/i) { print qq(Content-type: text/x-hdml;charset=Shift_JIS\n\n); open (FILE,"<$link{'e'}"); foreach () { print; } close FILE; } else { print "Content-type: text/html\n\n"; print "飛ばし文が不正です。"; } exit; } # 出力準備 my ($css,$body,$ket); if ($bgcolor || $textcolor) { $css .= qq(body {); if ($bgcolor) { $css .= qq( background-color:#$bgcolor;); } if ($textcolor) { $css .= qq( color:#$textcolor;); } $css .= qq( }\n) } if ($linkcolor) { $css .= qq(a { color:#$linkcolor }\n); } foreach (@lines) { my ($type,$serv,$posi,$text,$url,$key) = split(/<>/); if ($serv !~ /e/) { next; } $text =~ s/ / /g; $text =~ s/"/"/g; if ($posi eq 'c') { $body .= $ket; if (($type eq 't') && ($url)) { $body .= qq(); } else { $body .= qq(); } $ket = qq(
\n); } elsif ($posi eq 'r') { $body .= $ket; if (($type eq 't') && ($url)) { $body .= qq(); } else { $body .= qq(); } $ket = qq(
\n); } elsif (($posi ne '^') && ($type ne 'h')) { $body .= $ket; if (($type eq 't') && ($url)) { $body .= qq(); $ket = qq(
\n); } else { $ket = qq(
\n); } } if ($type eq 'c') { $type = 't'; $text =~ s/\[([\w]+)\]/$countia{$1}/g; } if ($type eq 't') { $body .= $text; } elsif ($type eq 'i') { $text =~ s/"/"/g; $body .= qq($text); } elsif ($type eq 'a') { if ($key =~ /^\d$/) { $body .= qq($text); } else { $body .= qq($text); } } elsif ($type eq 'm') { if ($key =~ /^\d$/) { $body .= qq($text); } else { $body .= qq($text); } } elsif ($type eq 'p') { if ($key =~ /^\d$/) { $body .= qq($text); } else { $body .= qq($text); } } elsif ($type eq 'h') { $body .= $ket; $body =~ s#
\n?$##; $body .= qq(\n
\n); $ket = ''; } } $body .= $ket; $body =~ s#(?:
\n?)+\n?$##; $body =~ s/\n+$//; # 出力 print qq(Content-type: text/html;\n\n); print qq(\n); print qq(\n); print qq(\n); print qq(\n); print qq($title\n); if ($css) { print qq(\n); } print qq(\n\n$body\n\n\n); } #-------------------------------------------------------------------------- # [ CHTMLの出力 ] sub PRINT_CHTML { # 端末の判別 my ($ia,$imgext,$adkey,@key,$nnm); if ($ua[0] eq 'DoCoMo') { $ia = 'i'; $imgext = '.gif'; $adkey = 'accesskey'; @key = ( "\xF9\x90", "\xF9\x87", "\xF9\x88", "\xF9\x89", "\xF9\x8A", "\xF9\x8B", "\xF9\x8C", "\xF9\x8D", "\xF9\x8E", "\xF9\x8F", ); } elsif ($ua[0] eq 'J-PHONE') { $ia = 'j'; $imgext = '.png'; $adkey = 'directkey'; if ($ua[1] >= 3) { @key = ( "\x1B\$FE\x0F", "\x1B\$F<\x0F", "\x1B\$F=\x0F", "\x1B\$F>\x0F", "\x1B\$F?\x0F", "\x1B\$F@\x0F", "\x1B\$FA\x0F", "\x1B\$FB\x0F", "\x1B\$FC\x0F", "\x1B\$FD\x0F", ); $nnm = qq( nonumber); } else { $title = ''; } } elsif ($ua[0] eq 'ASTEL') { $ia = 'd'; $imgext = '.gif'; $adkey = 'accesskey'; @key = ( "\xF0\x40", "\xF0\x41", "\xF0\x42", "\xF0\x43", "\xF0\x44", "\xF0\x45", "\xF0\x46", "\xF0\x47", "\xF0\x48", "\xF0\x49", ); } elsif ($ua[0] eq 'L-mode') { $ia = 'l'; $imgext = '.gif'; $adkey = 'accesskey'; @key = ( "\xF9\x90", "\xF9\x87", "\xF9\x88", "\xF9\x89", "\xF9\x8A", "\xF9\x8B", "\xF9\x8C", "\xF9\x8D", "\xF9\x8E", "\xF9\x8F", ); } # 飛ばし処理 if ($link{$ia}) { if ($link{$ia} =~ /^http:\/\//) { print "Location:$link{$ia}\n\n"; } elsif ($link{$ia} =~ /\.html?$/i) { print qq(Content-type: text/html\n\n); open (FILE,"<$link{$ia}"); foreach () { print; } close FILE; } else { print "Content-type: text/html\n\n"; print "飛ばし文が不正です。"; } exit; } # 出力準備 my ($body,$ket); foreach (@lines) { my ($type,$serv,$posi,$text,$url,$key) = split(/<>/); if ($serv !~ /$ia/) { next; } $text =~ s/ / /g; if ($posi eq 'c') { $body .= $ket; $body .= qq(
); $ket = qq(
\n); } elsif ($posi eq 'r') { $body .= $ket; $body =~ s/
\n?$//; $body .= qq(
); $ket = qq(
\n); } elsif ($posi eq 's') { $body .= $ket; $body .= qq(); $ket = qq(\n); } elsif (($posi ne '^') && ($type ne 'h')) { $body .= $ket; $ket = qq(
\n); } if ($type eq 'c') { $type = 't'; $text =~ s/\[([\w]+)\]/$countia{$1}/g; } if ($type eq 't') { if ($url) { $body .= qq($text); } else { $body .= $text; } } elsif ($type eq 'i') { $text =~ s/"/"/g; $url =~ s/\.[^\.]+$//; $body .= qq($text); } elsif ($type eq 'a') { if ($key =~ /^\d$/) { $body .= qq($key[$key]$text); } else { $body .= qq($text); } } elsif ($type eq 'm') { if ($key =~ /^\d$/) { $body .= qq($key[$key]$text); } else { $body .= qq($text); } } elsif ($type eq 'p') { if ($key =~ /^\d$/) { $body .= qq($key[$key]$text); } else { $body .= qq($text); } } elsif ($type eq 'h') { $body .= $ket; $body =~ s/
\n?$//; $body .= qq(
\n); $ket = ''; } } $body =~ s#
\n
#
\n#g; $body =~ s#\n
#
\n#g; $body =~ s#\n#
\n#g; $body .= $ket; $body =~ s/(?:
\n?)+\n?$//; $body =~ s/\n+$//; # 出力 print qq(Content-type: text/html\n\n); print qq(\n\n); if ($title) { print qq($title\n); } print qq(\n\n$body\n\n\n); } #-------------------------------------------------------------------------- # [ HTMLの出力 ] sub PRINT_HTML { # 端末判別 my $ia = 'p'; if ($ua =~ /PalmScape|sharp pda browser|Windows CE|WorldTALK/) { $ia = 'x'; } # 飛ばし処理 if ($link{$ia}) { if ($link{$ia} =~ /^http:\/\//) { print "Location:$link{$ia}\n\n"; } elsif ($link{$ia} =~ /\.html?$/i) { print qq(Content-type: text/html\n\n); open (FILE,"<$link{$ia}"); foreach () { print; } close FILE; } else { print "Content-type: text/html\n\n"; print "飛ばし文が不正です。"; } exit; } # 出力準備 my ($body,$ket); foreach (@lines) { my ($type,$serv,$posi,$text,$url,$key) = split(/<>/); if ($serv !~ /p/) { next; } $text =~ s/ / /g; if ($posi eq 'c') { $body .= $ket; $body .= qq(
); $ket = qq(
\n); } elsif ($posi eq 'r') { $body .= $ket; $body =~ s/
\n?$//; $body .= qq(
); $ket = qq(
\n); } elsif ($posi eq 's') { $body .= $ket; $body .= qq(); $ket = qq(\n); } elsif (($posi ne '^') && ($type ne 'h')) { $body .= $ket; $ket = qq(
\n); } if ($type eq 'c') { $type = 't'; $text =~ s/\[([\w]+)\]/$countia{$1}/g; } if ($type eq 't') { if ($url) { $body .= qq($text); } else { $body .= $text; } } elsif ($type eq 'i') { $text =~ s/"/"/g; $body .= qq($text); } elsif ($type eq 'a') { $body .= qq($text); } elsif ($type eq 'm') { $body .= qq($text); } elsif ($type eq 'p') { $body .= qq($text($url)); } elsif ($type eq 'h') { $body .= $ket; $body =~ s/
\n?$//; $body .= qq(
\n); $ket = ''; } } $body =~ s#\n
#
\n#g; $body =~ s#\n
#
\n#g; $body =~ s#
\n#
\n#g; $body =~ s#([^>])( )([^( )])#$1 $3#g; $body .= $ket; $body =~ s/(?:
\n?)+\n?$//; $body =~ s/\n+$//; # 出力 print qq(Content-type: text/html\n\n); print qq(\n\n); if ($title) { print qq($title\n); } print qq(\n\n$body\n\n\n); } #-------------------------------------------------------------------------- # [ データの読み込み ] sub READ_FILE { my $get = $ENV{'QUERY_STRING'}; my @pairs = split(/&/,$get); foreach (@pairs) { my ($name,$value) = split(/=/,$_); if ($name eq 'fn') { $filename = $value; } } open (FILE,"<$filename"); $config = ; if ($config !~ /^#INDEXO/) { print qq(Content-type: text/html\n\n); print qq(エラー); print qq(INDEXOの設定ファイルではありません。
); print qq(一行目に#INDEXOと書かれているかどうか確認してください。); print qq(); exit; } foreach () { chomp; if (/^ *#/) { next; } elsif (/<>/) { push(@lines,$_); } elsif (/^title=>/) { s/^title=>//; $title = $_; } elsif (/^background=>/) { s/^background=>//; $background = $_; } elsif (/^bgcolor=>/) { s/^bgcolor=>#//; $bgcolor = $_; } elsif (/^text=>/) { s/^text=>#//; $textcolor = $_; } elsif (/^link=>/) { s/^link=>#//; $linkcolor = $_; } elsif (/->/) { if (/e.*->/) { $link{e} = $_; $link{e} =~ s/.*->//; } if (/d.*->/) { $link{d} = $_; $link{d} =~ s/.*->//; } if (/h.*->/) { $link{h} = $_; $link{h} =~ s/.*->//; } if (/i.*->/) { $link{i} = $_; $link{i} =~ s/.*->//; } if (/j.*->/) { $link{j} = $_; $link{j} =~ s/.*->//; } if (/l.*->/) { $link{l} = $_; $link{l} =~ s/.*->//; } if (/p.*->/) { $link{p} = $_; $link{p} =~ s/.*->//; } if (/x.*->/) { $link{x} = $_; $link{x} =~ s/.*->//; } } } close (FILE); } #-------------------------------------------------------------------------- # [ COUNTIA ] sub COUNTIA { if (-r $countia) { require $countia; %countia = %{&countia::cia("./logs/cia_$filename",1)}; } }