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

use CGI;
$CGI::LIST_CONTEXT_WARN = 0;

$q = new CGI;
print $q->header(-charset=> "UTF-8",);
open(DvapFILE, "< /var/www/dvap.conf") or die("Error: $!");
my $match_pattern = '^\s*(#.*|)$';
while (my $line = <DvapFILE>) {
        chomp $line;
        if ($line !~ $match_pattern) {
		if (substr($line , 0, 14) eq "DVAP_FREQUENCY") {
			my @list = split (/=/, $line);
			$Freq = pop @list;
		}
		if (substr($line, 0, 12) eq "DVAP_SQUELCH") {
			my @list = split (/=/, $line);
			$Sque = pop @list;
		}
		if (substr($line, 0, 16) eq "DVAP_CALIBRATION") {
			my @list = split (/=/, $line);
			$Calib = pop @list;
		}
        }
    }
close (DvapFILE);
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">
<script>
function Store() {
if (((dvap_set.freq.value >= 144000000) && (dvap_set.freq.value <= 146000000))  || (( dvap_set.freq.value >= 430000000) && (dvap_set.freq.value <= 440000000))) {
document.dvap_set.action="/cgi-bin/DvapStore";
document.dvap_set.target="_top";
document.dvap_set.method="post";
document.dvap_set.submit();
} else {
alert ('周波数の値が間違っています');
}
}
</script>
<TITLE>Connect Rig Registoration</TITLE>
</HEAD>
<BODY>
<form name="dvap_set">
<br>DVAP設定</br>
EOF
print "周波数 <input type=\"text\" name=\"freq\" value=\"" . $Freq . "\" size=\"10\">Hz<br>\n";
print "スケルチ <input type=\"text\" name=\"sque\" value=\"" . $Sque . "\" size=\"3\"><br>\n";
print "キャリブレーション <input type=\"text\" name=\"calib\" value=\"" . $Calib . "\" size=\"6\"><br>\n";
print <<'EOF';
<button type="button" onclick="Store()">登録</button><br>
登録をクリックしますと設定を保存後、ラズベリーパイが再起動されます。
</form>
EOF
print $q->end_html;

