網頁託管--建議之解決與替代方案


緣起


構想


實驗站台


虛擬站台網頁內容

<html>
<head>
<meta http-equiv="refresh" content="0; url=chk_host.pl?server=www.dnes.mlc.edu.tw&school=苗栗縣大湖鄉大南國民小學&addr=[36441]苗栗縣大湖鄉大南村七鄰大南勢十五號&tel=037-992813&fax=037-994337">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>苗栗縣大湖鄉大南國民小學</title>
</head>
<body bgcolor="blue">
</body>
</html>


由虛擬站台偵測各校網路線路正常否的 CGI

#!/usr/bin/sperl5

# 接收傳遞過來的參數
# 將輸入的參數 one by one 取出來
$| = 1;  #flush on

if ($ENV{'REQUEST_METHOD'} eq "POST") {
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'REQUEST_METHOD'} eq "GET") {
        $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;
    $value =~ s///g;

    $A_hash{$name} = $value;
}

$server=$A_hash{"server"};
$school=$A_hash{"school"};
$addr=$A_hash{"addr"};
$tel=$A_hash{"tel"};
$fax=$A_hash{"fax"};

# 檢查主機網路是否正常
use Net::Ping ;
$p=Net::Ping->new("icmp",1) ;
$chk_server = $p->ping($server) ;

if ( $chk_server ) { # 如果線路檢查正常,進而以此網頁再去檢查 port 80
   print qq~
   <html>
   <head>
   <meta http-equiv="content-type" content="text/html; charset=big5">
   <meta http-equiv="refresh" content="0; url=chk_port80.pl?server=$server&school=$school&addr=$addr&tel=$tel&fax=$fax">
   </head>
   <body bgcolor="lime">
   </body>
   </html>
   ~;

} else { # 線路檢查結果不通,顯示網站維修的訊息。
   do "under_construction.pl";
}

$p->close() ;


由虛擬站台偵測各校主機 port 80 的 CGI

#!/usr/bin/perl

#接收命令行輸入
# 將輸入的參數 one by one 取出來
$| = 1;  #flush on

if ($ENV{'REQUEST_METHOD'} eq "POST") {
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'REQUEST_METHOD'} eq "GET") {
        $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;
    $value =~ s///g;

    $A_hash{$name} = $value;
}

$server=$A_hash{"server"};
$school=$A_hash{"school"};
$addr=$A_hash{"addr"};
$tel=$A_hash{"tel"};
$fax=$A_hash{"fax"};

use IO::Socket;
my ($line, $port, $sock, @servers);

#掃描通訊埠
$port = 80 ;

# 開始掃描 port 80
$sock = IO::Socket::INET->new(
   PeerAddr => $server,
   PeerPort => $port,
   Proto => 'tcp');

if ($sock)  { # 如果 port 80 正常,整個網站轉址過去
	print qq~
	<html>
	<head>
	<meta http-equiv="content-type" content="text/html; charset=big5">
	<meta http-equiv="refresh" content="0; url=http://$server/">
	</head>
	<body bgcolor="magenta">
	線路檢查正常,網站轉換中,請稍候......
	</body>
	</html>
	~;

} else { # port 80 不通時,顯示施工中的訊息
   do "under_construction.pl";

} 


網站維修通告的樣板網頁

under_construction.htm,此頁的資料、圖片,均抓取自網路上的資源。