Viewing file:
inbox.cgi (4.97 KB) -rwxr-xr-xSelect action/file-type:

(
+) |

(
+) |

(
+) |
Code (
+) |
Session (
+) |

(
+) |
SDB (
+) |

(
+) |

(
+) |

(
+) |

(
+) |

(
+) |
#!/usr/bin/perl
use DBI();
use CGI qw(:standard);
use IO::Socket;
use MIME::Base64();
use MIME::QuotedPrint();
use Encode;
use Encode qw/from_to/;
use CGI::Cookie;
$user = param("name");
$pass = param("pass");
$page = param("page");
$par1 = $ARGV[0];
if ($page eq "all") {$page = "0"; $page1 = "all";}
if ($user ne "")
{
### $pass = MIME::Base64::encode($pass);
$auth=sprintf("%s %s", $user, $pass);
my $cook = cookie(
-name => 'mn.mail.auth',
-value => $auth,
-expires => '0',
-domain => 'miranet.lan',
-path => '/',
);
$cook = sprintf header(-cookie=>$cook);
($cook) = split("charset=", $cook);
$cook = sprintf ("%s charset=KOI8-R\n\n", $cook);
print "$cook";
} else {
if ($par1 ne "quit") {print "Content-type: text/html\n\n";}
my $auth = cookie('mn.mail.auth');
($user, $pass) = split (" ", $auth);
### $pass = MIME::Base64::decode($pass);
}
if ($par1 ne "quit") {
open(patt,"<./patt_n1.html")||die "Pattern file 1 not found";
while(<patt>)
{
print;
}
close(patt);
}
$serv = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "localhost",
#PeerAddr => "pop.mail.ru",
PeerPort => "110",
);
$cnt = 0;
$stat1 = "";
$stat2 = "";
$c = 0;
$zv = "?";
$clr = "0060a0";
$clr = "005090";
$start = "0";
$mpp = "30";
$crnt = "0";
if ($page ne "") {$start = $page;}
if ($par1 eq "quit") {print $serv "QUIT\n";}
while ( <$serv> ) {
($q, $p) = split (" ");
($nl, $dt1) = split ("From:");
($nl, $dt2) = split ("Subject:");
($nl, $dt3) = split ("Return-Path:");
if ( $q eq "+OK" and $stat1 eq "" ) {$cnt=$cnt+1;}
if ( $cnt eq "1" ) { print $serv "USER $user\n";}
if ( $cnt eq "2" ) { print $serv "PASS $pass\n"; }
if ( $stat1 eq "list" )
{
$msg = $p;
$fs = $start * $mpp + 1;
$ls = $start * $mpp + $mpp;
if ($ls > $msg) {$ls=$msg;}
if ($page1 eq "all") {$ls = $msg;}
print "<center><h3><font color=#ffffff>Сообщений: $msg ( $fs - $ls )</font></h3></center><hr>\n"; $stat1="headq"; $stat2=$msg-($start*$mpp);
if ($page1 eq "all") {$stat2 = $msg;}
}
if ( $cnt eq "3" ) { $stat1 = "list"; print $serv "STAT\n"; $cnt="4"; print "<table border=0 cellspacing=0 width=100%>";}
if ( $stat1 eq "headw" )
{
if ( $q eq "From:" )
{
if (index ($dt1,"\=\?")<0) {from_to($dt1, "cp1251", "koi8-r") foreach $dt1; $from = $dt1;}
else {$from = autodec($dt1);}
}
if ( $q eq "Subject:" )
{
if (index ($dt2,"\=\?")<0) {from_to($dt2, "cp1251", "koi8-r") foreach $dt2; $subj = $dt2;}
else {$subj = autodec($dt2);}
}
if ( $q eq "Return-Path:" )
{
$ret = $dt3;
($nl, $ret) = split("<", $ret);
($ret) = split(">", $ret);
}
if ( $q eq "." ) {
# $cid=$start*$mpp+$crnt;
$cid=$stat2;
if ($subj eq "") {$subj = "[Нет темы]";}
print "<tr bgcolor=\#$clr><td width=30%><b><font size=2 face=\"arial\" color=#ffffff>$from ($ret)</font></td><td></td><td><b><a href=\"view.cgi?id=$cid\"><font size=2 face=\"arial\" color=#00ffff>$subj</font></a></b></td></tr>\n";
$stat2 = $stat2 - 1; $stat1 = "headq"; $subj = ""; $from = ""; $ret = ""; $crnt = $crnt + 1;
if ( $clr eq "0060a0" ) {$clr="005090"; $clr1="004080";} else {$clr="0060a0"; $clr1="005090";}
}
}
if ( $stat2 eq "0"or $crnt eq $mpp and $page1 ne "all")
{
$pgs = ($msg / $mpp);
if (int($pgs) ne $pgs) {$pgs = $pgs + 1;}
$pgs = int($pgs);
$pg = 0;
$pgstr = "<font face=\"arial\"><b>Страницы</b></font>";
while ( $pg ne $pgs )
{
if ($pg eq $start) {$clr = "#ffff00";} else {$clr = "#ffffff";}
$pg = $pg + 1;
$pgstr = sprintf ("%s<b> <font face=\"arial\"><a href=\"inbox.cgi?page=%s\">%s</a></font></b>", $pgstr, $pg-1, $pg);
}
$pgstr = sprintf ("%s<b> <font face=\"arial\"><a href=\"inbox.cgi?page=all\">Все</a></font></b>",$pgstr);
$stat1 = "end";
}
if ( $stat1 eq "headq" ) { $stat1 = "headw"; print $serv "TOP $stat2 0\n"; }
if ( $stat1 eq "end" )
{
print "</table><hr>\n";
print "<b>$pgstr</b><br>\n";
print "<b><a href=\"inbox.cgi?quit\">Выход</a><br>";
print $serv "QUIT\n";
exit 0;
}
if ( $par1 eq "quit" )
{
my $cook = cookie(
-name => 'mn.mail.auth',
-value => 'null',
-expires => '0',
-domain => 'miranet.lan',
-path => '/',
);
#print "Content-type: text/html\n\n";
print header(-cookie=>$cook);
print "<META HTTP-EQUIV=\"refresh\" content=\"0; URL=./login.cgi\">";
}
}
sub autodec {
my $dt2 = shift;
($edt1, $edt2) = split("=", $dt2);
($is, $cp, $t, $dat, $ie) = split (/\?/, $edt2);
if ( $t eq "B" or $t eq "b")
{
$t = "B";
$dt2 = MIME::Base64::decode($dat);
if ($cp ne "" ) {from_to($dt2, $cp, "koi8-r") foreach ($dt2);}
}
if ( $t eq "Q" or $t eq "q")
{
$t = "Q";
($nl, $nl, $nl, $dat, $nl) = split (/\?/, $dt2);
$dt2 = MIME::QuotedPrint::decode($dat);
if ($cp ne "") {from_to($dt2, $cp, "koi8-r") foreach ($dt2);}
}
if ( $t ne "B" and $t ne "Q" and $cp ne "") {from_to($dt2, $cp, "koi8-r") foreach ($dt2);}
return $dt2;
}