#!/usr/bin/perl

print "Content-type: text/html;\n\n";
require "pvd-lib.pl";
getheader();
require "pvd-index.cfg";

if (!$in{killok} and !$in{kill_passw}) {
print qq~
<html><body>
<form method=post action="pvd-kill.pl">
Введите пароль для удаления записи № <b>$ENV{'QUERY_STRING'}</b><br>
<input type=password name=kill_passw>
<input type=checkbox name=kill_ip> добавить IP в BAN лист<br>
<input type=submit value=ok>
<input type=hidden name=killok value='$ENV{'QUERY_STRING'}'>
</form></body></html>
~;
}
elsif ($in{killok} and $in{kill_passw} eq $kill_passw) {
open LIST, "<$message{dbpath}/pvd-index.msg"; @GR=<LIST>; close LIST;
open LIST, ">$message{dbpath}/pvd-index.msg"; flock(LIST, 2); binmode LIST;
for($l=0;$l<=$#GR;$l++) {
   $GR[$l]=chdel($GR[$l]); @records = split(/\x01/, $GR[$l]);
   if ($in{killok} ne $records[0]) {push @ne_gr,$GR[$l]}
   else {$ban_ip=$records[$#records]}
}
for (0..$#ne_gr) {
    if ($_!=$#ne_gr) {print LIST $ne_gr[$_],"\x0A"}
    else {print LIST $ne_gr[$_]}
}
close(LIST);

if ($in{kill_ip}) {
    open LIST,">>$message{dbpath}/pvd-index.ban"; binmode LIST;
    print LIST "\x0A$ban_ip"; close LIST;
}
print "OK";
} else {print "ERR"}
