#! /usr/local/bin/perl
#
# change.cgi for change.htm(パスワード変更CGI)
#
# (c)rescue.ne.jp
#
#
# 初期設定(あなたの環境に合わせて設定してください)
#
$an1_file = "/home/user/bin/.vip";
$htpasswd2 = "/home/user/bin/htpasswd2";
$title = "暫定パスワードの変更";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
$month = ($mon + 1);
print "Content-type: text/html\n\n";
$date_now = "$year年$month月$mday日 $hour時$min分$sec秒";
if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }
else { $buffer = $ENV{'QUERY_STRING'}; }
if ($buffer eq "") { &w2_html; &html_trailer1; }
else { &an_w; &html_trailer2; }
sub w2_html {
print "
$title\n";
print "\n";
print "$title
\n";
print "登録エラー
\n";
}
sub w_html {
print "$title\n";
print "\n";
print "$title
\n";
print "登録済み
\n";
print "このメールアドレスは既に登録されています。\n";
}
sub html_trailer1 {
print "\n";
print "\n";
exit;
}
sub html_trailer2 { #発行
print "
$title\n";
print "\n";
print "$title
\n";
print "パスワードを変更しました
\n";
print "\n";
}
sub an_w {
@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;
$value =~ s/>/>/g;
$value =~ s/"/"/g;
$FORM{$name} = $value;
}
$email = $FORM{'email'};
$email =~ s/\n//g;
$email =~ s/\r//g;
$password1 = $FORM{'password1'};
$password2 = $FORM{'password2'};
if ($password1 =~ /(\W)/) { &pass_err(1); }
if ($password2 =~ /(\W)/) { &pass_err(2); }
if ($password1 eq "" || $password2 eq "") { &pass_err(3); }
if ($password1 ne $password2) { &pass_err(4); }
$| = 1;
print "\n";
system("$htpasswd2 '$an1_file' '$email' '$password1'");
}
sub pass_err {
$error = $_[0];
print "$title\n";
print "\n";
print "$title
\n";
print "パスワードエラー($error)
\n";
print "確認の為に入力したパスワードが間違っています。または英数字以外の文字が使われています。\n";
&html_trailer1;
}