概要

  • CGIで環境変数を表示します。
  • 「HTTPS」を表示するように修正。(2012/04/29)
  • 「GeoIP」を表示するように修正。(2012/09/06)

動作サンプル

HTML版httphttps
Text版httphttps

ソースコード

HTML版

すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
-
|
!
!
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
!
 
 
-
|
!
 
 
#!/usr/bin/perl
 
use strict;
use warnings;
use utf8;
use Encode;
use CGI::Pretty qw( -no_xhtml *table );    # //HTML 4.01 Transitional//EN
 
my $charsetConsole    = 'UTF-8';
my $charsetFile        = 'UTF-8';
 
binmode( STDIN,  ":encoding($charsetConsole)" );
binmode( STDOUT, ":encoding($charsetConsole)" );
binmode( STDERR, ":encoding($charsetConsole)" );
 
my $q = new CGI;
$q->charset( $charsetFile );
 
my $cginame = 'PrintEnv';
 
printHeader();
 
print $q->start_table( { '-summary' => 'ENV', '-border' => 1 } );
print $q->Tr( $q->th( [ 'Key', 'Value' ] ) );
foreach ( sort( keys( %ENV ) ) ){
    if ( /^(GEOIP_|HTTPS|HTTP_|QUERY_|REMOTE_|REQUEST_|SERVER_(ADDR|NAME|PORT|PROTOCOL))/i ){
        print $q->Tr( $q->td( [ $_, $ENV{$_} ] ) );
    }
}
print $q->end_table();
 
printFooter();
 
exit;
 
sub printHeader
{
    print $q->header();
    print $q->start_html( 
        '-title'    => $cginame, 
        '-lang'        => 'ja-JP', 
        '-head'        => [ 
            $q->meta( { '-http_equiv' => 'Content-style-type', '-content' => 'text/css' } ), 
            $q->meta( { '-http_equiv' => 'Content-script-type', '-content' => 'text/javascript' } ), 
        ], 
        '-style'    => [ { 'src' => '/take.css' }, ], 
    );
    print $q->h1( $cginame );
}
 
sub printFooter
{
    print $q->end_html . "\n";
}
 
# EOF

Text版

すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 
 
 
 
 
 
 
 
 
-
-
|
!
!
 
 
#!/usr/bin/perl
# 環境変数の表示(テキスト版)
 
use strict;
use warnings;
use utf8;
 
print "Content-type: text/plain; charset=UTF-8\n\n";
 
foreach ( sort( keys( %ENV ) ) ){
    if ( /^(GEOIP_|HTTPS|HTTP_|QUERY_|REMOTE_|REQUEST_|SERVER_(ADDR|NAME|PORT|PROTOCOL))/i ){
        print $_ . "\t" . $ENV{ $_ } . "\n";
    }
}
 
# EOF

IIS8用

すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
 
 
 
 
 
 
 
-
-
|
!
!
 
 
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
 
-
|
|
|
|
!
 
 
#!/usr/bin/perl
# 環境変数の表示
 
use strict;
use warnings;
use utf8;
use Encode;
use CGI::Pretty qw( -no_xhtml *table );    # //HTML 4.01 Transitional//EN
 
my $charsetConsole    = 'UTF-8';
my $charsetFile        = 'UTF-8';
 
#binmode( STDIN,  ":encoding($charsetConsole)" );
#binmode( STDOUT, ":encoding($charsetConsole)" );
#binmode( STDERR, ":encoding($charsetConsole)" );
 
my $encoder = find_encoding( $charsetConsole );
if ( defined( $ENV{PERLXS} ) && $ENV{PERLXS} eq 'PerlIS' ){
    print $encoder->encode( "HTTP/1.0 200 OK\n" );
}
 
my $q = new CGI;
$q->charset( $charsetFile );
 
my $cginame = '環境変数の表示';
 
print $encoder->encode(makeHeader($q));
 
my $output = '';
$output .= $q->start_table( { '-summary' => 'ENV', '-border' => 1 } );
$output .= $q->Tr( $q->th( [ 'キー', '値' ] ) );
foreach ( sort( keys( %ENV ) ) ){
    if ( /^(GEOIP_|HTTPS|HTTP_|QUERY_|REMOTE_|REQUEST_|SERVER_(ADDR|NAME|PORT|PROTOCOL))/i ){
        $output .= $q->Tr( $q->td( [ $_, $ENV{$_} ] ) );
    }
}
$output .= $q->end_table();
print $encoder->encode($output);
 
print $encoder->encode(makeFooter($q));
 
exit;
 
sub makeHeader
{
    my $q = shift or return;
    my $ret = '';
    $ret .= $q->header();
    $ret .= $q->start_html(
        '-title'    => $cginame,
        '-lang'        => 'ja-JP',
        '-head'        => [
            $q->meta( { '-http_equiv' => 'Content-style-type', '-content' => 'text/css' } ),
            $q->meta( { '-http_equiv' => 'Content-script-type', '-content' => 'text/javascript' } ),
        ],
        '-style'    => [ { 'src' => '/take.css' }, ],
    );
    $ret .= $q->h1( $cginame );
    return $ret;
}
 
sub makeFooter
{
    my $q = shift or return;
    my $ret = '';
    $ret .= $q->end_html . "\n";
    return $ret;
}
 
# EOF

IIS6用

すべてを展開すべてを収束
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
 
 
 
 
 
 
 
 
-
-
|
!
!
-
|
!
 
 
 
 
 
 
 
 
 
 
#!/usr/bin/perl
# printEnv.pl
# Linuxの場合は、EUC-JP,LFで保存
 
print "Content-type: text/html\n\n";
 
print <<EOL;
<html>
<body>
%ENV
<table border="1">
<tr><th>key</th><th>value</th></tr>
EOL
 
foreach $key (sort keys(%ENV)){
    printf("<tr><td>%s</td><td>%s</td></tr>\n", $key, $ENV{$key});
}
 
print <<EOL;
</table>
<br>
%ALL_HTTP
<table border="1">
<tr><th>key</th><th>value</th></tr>
EOL
 
# IIS用
@ALL_HTTP = split( "\n", $ENV{ "ALL_HTTP" } );
%ALL_HTTP = ();
foreach $line ( @ALL_HTTP ){
    if ( $line =~ /([^:]+):(.*)\s*/){
        $ALL_HTTP{ $1 } = $2;
    }
}
foreach $key (sort keys(%ALL_HTTP)){
    printf("<tr><td>%s</td><td>%s</td></tr>\n", $key, $ALL_HTTP{$key});
}
 
print <<EOL;
</table>
</body>
</html>
EOL
 
exit();
 
# EOF

添付ファイル: filePrintEnv.zip 618件 [詳細]

リロード   新規 下位ページ作成 編集 凍結 差分 添付 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: Tue, 04 Mar 2014 14:23:59 JST (1631d)