#!/usr/bin/perl use CGI::Cookie; use CGI qw(:standard); ############### CONFIG ############### $cname = "cooke.site"; $csite = "192.168.200.13"; $dblogin = "user"; $dbpasswd = "password"; $title = "Заголовок авторизации"; $message = "Введите имя пользователя и пароль"; $link = "how-to-use.cgi"; $logfile = "file.log"; $secr = "secret"; ###################################### $authl = $ARGV[0]; $authp = $ARGV[1]; $logout = param("logout"); if ($logout eq "1") { my $cooke = cookie($cname); if ($cooke eq "") {print "Content-type: text/html\n\n

Error


You are not logged on!"; exit (0);} $auth="0"; my $cook = cookie( -name => $cname, -value => '0', -expires => '1', -domain => $csite, -path => '/', ); $cook = sprintf header(-cookie=>$cook); ($cook) = split("charset=", $cook); $cook = sprintf ("%s charset=KOI8-R\n\n", $cook); print "$cook"; print ""; exit (0); } $rip = $ENV{'REMOTE_ADDR'}; my $cooke = cookie($cname); if ($cooke eq $secr) {print "Content-type: text/html\n\n"; exit(1);} if ($authl ne "" or $authp ne "") {$ok = "2";} if ($authl eq "" and $authp eq "") { $ok = "0"; print "Content-type: text/html\n\n"; print " $title

$message


Имя пользователя
Пароль
"; exit(2); } if ($authl ne "") { if ($authl eq $dblogin and $authp eq $dbpasswd) {$ok = "1";} } if ($ok eq "1") { my $cook = cookie( -name => $cname, -value => $secr, -expires => '0', -domain => $csite, -path => '/', ); $cook = sprintf header(-cookie=>$cook); ($cook) = split("charset=", $cook); $cook = sprintf ("%s charset=UTF8\n\n", $cook); print "$cook"; exit(1); } if ($ok eq "2") { print "Content-type: text/html\n\n
Доступ запрещён!"; if ($logfile ne "") { system ("echo \"Authentication error\nLogin: $authl\nPassword: $authp\nIP Address: $rip\n\" >> $logfile"); } exit(2); } if ($ok eq "0") { print "Content-type: text/html\n\n

Access denyed


"; }