#!/usr/bin/perl
##
##

use CGI;
$CGI::LIST_CONTEXT_WARN = 0;

$q = new CGI;

open my $rs , "hostname -I 2>&1 |";
my @ip = <$rs>;
close $rs;
my $result = join '' , @ip;
my $num = index ($result, ' ');
$result = substr($result, 0, $num);
$result =~ s/\s+//g;
$result =~ s/[[:cntrl:]]//g;
$useragent = $ENV{"HTTP_USER_AGENT"};
$browser   = get_browser_name();
sub get_browser_name
{
        local $name;

        $_ = $ENV{"HTTP_USER_AGENT"};

        if    (/Opera/i)                { $name = "Opera";}
        elsif (/Surf/i)                 { $name = "Surf"; }
        elsif (/MSIE 6/i)               { $name = "Internet Explorer Ver. 6"; }
        elsif (/Mozilla\/2/i)           { $name = "Netscape Navigator Ver. 2"; }
        elsif (/Mozilla\/3/i)           { $name = "Netscape Navigator Ver. 3"; }
        elsif (/Mozilla\/4/i    )       { $name = "Netscape Navigator Ver. 4"; }
        elsif (/Mozilla\/5|Netscape6/i) { $name = "Netscape Navigator Ver. 6"; }
        elsif (/Netscape\/7/i)          { $name = "Netscape Navigator Ver. 7"; }
        else                                    { $name = "分かりません"; }

        return $name;
}
print $q->header(-charset=> "UTF-8",);
print <<'EOF';
<HTML lang="ja">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>dmonitor reboot</TITLE>
<script>
var	watch1 = 60;
function disp(){
	document.form1.field1.value = watch1
	watch1 = watch1 - 1;
	if (watch1 >= 0)
	{
		setTimeout("disp()", 1000);
	}
	else
	{
EOF
print 'top.location.href="http://' . $result . '/index.html";';
print <<'EOF';
	}
}
</script>
</HEAD>
<BODY onLoad="disp()">
<form action="#" name="form1">
再起動完了まであと
<input type="text" name="field1" size="4">
秒
</form>
EOF
print $q->end_html;
