Лови
#!/usr/bin/perl -w
use CGI::Carp qw (fatalsToBrowser);
use CGI::Session;
use DBI;
use CGI qw/:standard/;
my $cgi = new CGI;
sub redir_url {
print $cgi->redirect(-uri=>"auth.pl?auth=Error");
}
################################################
#
# Session
#
################################################
my $sid = $cgi->param(sess) || undef;
my $session = new CGI::Session("driver:File", $sid , {Directory=>\'/tmp\'}) || undef;
#my $sid = $session->param(_SESSION_ID) || undef;
#my $session = new CGI::Session("driver:File", undef, {Directory=>\'/tmp\'}) || undef;
$login=param(name);
$login="\'$login\'";
$table_log="squid_log_";
$operator="operator";
$oper_pass="secret";
$res = "0";
$table_auth="pass_rule";
$passwd=param(pass);
#################################################
# #
# Open config file #
# #
#################################################
open (mylog_conf, "/usr/local/script/traff_db/etc/my_log/my_log.conf");
while (<mylog_conf>){
($section,$param)=split(":",$_);
if ($section eq "table") {
chomp $param;
$table=$param;
}
if($section eq "operator"){
chomp $param;
$operator=$param;
}
if($section eq "pass"){
chomp $param;
$oper_pass=$param;
}
if($section eq "pass_rule"){
chomp $param;
$table_auth=$param;
}
}
close(mylog_conf);
$table_log="$table_log$table";
#################################################
# #
# Check authentificated #
# #
#################################################
my ($dbh,$sth,$count);
$dbh = DBI->connect("DBI:mysql:host=freebsd;database=squid","$operator","$oper_pass")
or die "cann\'t open db";
$sth = $dbh->prepare("SELECT user_pass FROM $table_auth where user_login=$login"
)
or die "cann\'t execute select from db table $!";
$sth->execute ();
my $user_pass;
$user_pass = $sth->fetchrow_array();
$sth->finish();
$dbh->disconnect();
$auth="Error";
if((crypt($passwd,$user_pass) ne $user_pass)){
$auth="Error"
}
else {
$auth="ok";
}
if ($auth eq "Error") {
&redir_url;
}
else {
############################################################################
$name_stat=param(name);
$headpage="уФБФЙУФЙЛБ Й МЙЮОЩЕ БРБТФБНЕОФЩ РПМШЪПЧБФЕМС $name_stat";
print $cgi->header(-expires=>\'no cache\');
print $cgi->start_html(-title=>$headpage);
#print "$operator - $oper_pass - $login - $auth - $passwd - $user_pass
";
#################################################
# #
# Database connect and select column #
# #
#################################################
print "$operator - $oper_pass - $login - $table_log - $sid";
my ($dbh,$sth,$count);
$dbh = DBI->connect
("DBI:mysql:host=freebsd;database=squid","$operator","$oper_pass")
or die "cann\'t open db table $!";
$sth = $dbh->prepare("SELECT sum(size) FROM $table_log where шdent=$login")
or die "cann\'t execute select from db table $!";
$sth->execute ();
#################################################
# #
# Calculate size of traf #
# #
#################################################
my $size;
$size = $sth->fetchrow_array();
print "<center>";
print "<table cellspacing=0 cellpadding=0 border=0>";
print "<tr>";
print "<td><img src=\\"/image/car.gif\\" width=\\"180\\" height=\\"120\\" border
=\\"0\\" alt=\\"\\"></td>";
print "<td><img src=\\"/image/main.gif\\" width=\\"600\\" height=\\"120\\" borde
r=\\"0\\" alt=\\"\\"></td>";
print "</tr>";
print "</table>";
print "<table width=\\"800\\" cellspacing=\\"0\\" cellpadding=\\"0\\">";
print "<tr leftMargin=0> ";
print "<td width=\\"180\\" bgcolor=\\"red\\" background=\\"/image/bg3.gif\\" valign=\\
"top\\">";
print " <DIV align=left>";
print " <OBJECT >";
print " <EMBED src=\\"/image/menu.swf\\" WIDTH=180 HEIGHT=399 TYPE=\\"ap
plication/x-shockwave-flash\\"></EMBED>";
print "</OBJECT></DIV>";
print " </td>";
print " <td width=\\"440\\" bgcolor=\\"white\\" valign=top>";
print "<table>";
print "<tr>";
print " <td><img src=\\"/image/apart.jpg\\" width=\\"440\\" height=\\"80\\" border=
\\"0\\" align=\\"left\\" alt=\\"\\">";
print "</p></td>";
print " </tr></table>";
print "<font color=navy><i>";
print $cgi->h2(\'уФБФЙУФЙЛБ:\');
print "</i></font>";
print table({-align=>CENTER,valign=>CENTER,-cellpadding=>2, -border=>2,
-bordercolordark=>navy, -bordercolorlight=>"#719BF2", -width=>300},caption(\'
\'),
Tr({-align=>CENTER,-valign=>TOP},
td ("йНС РПМШЪПЧБФЕМС"),td("тБЪНЕТ ФТБЖЙЛБ, ВБКФ")),
Tr({-align=>CENTER,-valign=>TOP},
td ("$name_stat"),td("$size")));
print " </td>";
print " <td width=\\"180\\" bgcolor=\\"white\\" valign=\\"top\\">
<d
iv align=\\"justify\\">
<img src=\\"/image/banner.jpg\\" width=\\"180\\"
height=\\"250\\" border=\\"0\\" alt=\\"\\">";
print " </td>";
print " </tr>";
print " </table>";
print " </center>";
$sth->finish();
$dbh->disconnect();
print $cgi->end_html;
}
exit(0);