## Функция flock (1-да,0-нет)
$flock = "0";
## Хранение cookie у пользователя в днях.
$exp = "21";
## Путь к sendmail
$sema = "/usr/sbin/sendmail";
## Процент комиссионных при переводе кредитов 10%=0.1
$costtr = ".1";
$PH = "no";
sub getinput {
$meth = $ENV{'REQUEST_METHOD'};
if (!defined $meth || $meth eq '') {
$temp = "$ENV{'QUERY_STRING'}";
}
elsif ($meth eq "POST"){
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
}
elsif ($meth eq "GET") {
$temp = "$ENV{'QUERY_STRING'}";
}
else {
dienice("Unknown method: $meth");
}
@pairs=split(/&/,$temp);
$in{ip} = "$ENV{'REMOTE_ADDR'}";
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
chomp($content);
$in{$key}=$content;
}
}
sub sendmail {
local($to,$from,$subject,$message) = @_;
open (MESSAGE,"|$sema");
print MESSAGE "To: $to\n";
print MESSAGE "From: $from\n";
print MESSAGE "Subject: $subject\n\n";
print MESSAGE "$message\n\n";
close (MESSAGE);
}
sub dienice {
my($msg) = @_;
&printhead;
print "$Freead<P>\n";
print "<h2>Ошибка</h2><BR><HR><BR>\n";
print $msg;
exit;
}
sub getfile {
local($filename) = @_;
open(FILE, "$filename");
if ($flock eq "1") { flock(FILE, 2); }
@data = <FILE>;
close FILE;
$num = @data;
for ($i=0; $i<$num; $i++) {
chomp($data[$i]);
}
return @data;
}
sub appfile {
local($filename, @text) = @_;
open(FILE, ">>$filename");
if ($flock eq "1") { flock(FILE, 2); }
foreach $text(@text) {
print FILE "$text\n";
}
close FILE;
}
sub writefile {
local($filename, @text) = @_;
open(FILE, ">$filename");
if ($flock eq "1") { flock(FILE, 2); }
foreach $text(@text){
print FILE "$text\n";
}
close (FILE);
}
sub printhead {
if ($PH ne "y") {
print "Content-type: text/html\n\n";
$PH = "y";
}
}
sub getcookies {
if ($ENV{'HTTP_COOKIE'}) {
foreach (split(/; /,$ENV{'HTTP_COOKIE'})){
($cookie,$value) = split(/=/);
$Cookies{$cookie} = $value;
}
}
}
sub makecookies {
local(@cookies) = @_;
$expdate = mygmttime(time + (86400*$exp));
while( ($cookie,$value) = @cookies ) {
print "Set-Cookie:  $cookie=$value; expires=$expdate \n";
shift(@cookies); shift(@cookies);
}
}
sub cryptor {
local ($field, $pw) = @_;
$field = crypt($field,substr($pw,0,2));
return $field;
}
$der = "der";
1;
