<?php
/*
Courieradmin V1, Administration of Courier Mailserver
Copyright (C) 2003 Daniel Heule
This file is part of Courieradmin.
Courieradmin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Courieradmin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Courieradmin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once "common.php";
if($_SESSION['user']['right_mailq'] != 1) exit;
if(!$CourierAdmin_MailQueue) exit;
if(!isset($_SESSION['mailq_refresh'])) $_SESSION['mailq_refresh'] = 0;
if(isset($_REQUEST['mailq_refresh']) && $_REQUEST['mailq_refresh'] != "") $_SESSION['mailq_refresh'] = $_REQUEST['mailq_refresh'];
elseif(!isset($_REQUEST['mailq_refresh']) && ($_REQUEST['mailq_act'] == "Mail aus Queue löschen .." || $_REQUEST['mailq_act'] == "Log zum Mail anzeigen .."))
{
$_SESSION['mailq_refresh'] = 0;
}
$mailq = "";
$mailq_messages = 0;
$mailq_logtext = "";
$mailq_canceltext = "";
exec("sudo -u ".$CourierAdmin_sh_root_user." ".$CourierAdmin_path."/bin/sudo_root.php mailq_show",$output);
//$output=file(mailq_save);
sscanf(end($output),'%d messages.', &$mailq_messages);
if($mailq_messages != 0)
{
$anzmessages = 0;
$mailq = "<table border=\"2\" cellspacing=\"0\" width=\"100%\"><tr><th> </th><th>Size</th><th>Mail-ID</th><th>Datum</th></tr><tr><th> </th><th>User</th><th>From</th><th> </th></tr><tr><th> </th><th>Status</th><th>Reciptient</th><th> </th></tr>\n";
foreach ($output as $key => $value)
{
if($key > 3 && $key < (count($output)-1))
{
if($value == "\n" || $value == "")
{
//var_dump($curmsg);
$anz_to_domain = 0;
$mailq_msg = "<tr><td width=\"100%\" colspan=\"4\"> </td></tr>\n";
$msg['size'] = trim(substr($curmsg[0],0,17));
$msg['id'] = trim(substr($curmsg[0],17,36));
$msg['time'] = trim(substr($curmsg[0],53));
$msg['type'] = trim(substr($curmsg[1],0,17));
$msg['from'] = trim(substr($curmsg[1],17));
if($msg['from'] == "") $msg['from'] = " ";
$mailq_msg .= "<tr><td><input type=checkbox name='mailq_msgsel[]' value='".$msg['id']."'></td><td>".$msg['size']."</td><td><b>".$msg['id']."</b></td><td>".$msg['time']."</td></tr>\n";
$mailq_msg .= "<tr><td> </td><td>".$msg['type']."</td><td>".$msg['from']."</td><td> </td></tr>\n";
for($i = 2;$i < count($curmsg);$i++)
{
$d = $i - 2;
$msg['stat'][$d] = trim(substr($curmsg[$i],0,17));
switch ($msg['stat'][$d])
{
case "Retry":
$msg['stat'][$d] = "<font color=\"blue\"><b>Retry</b></font>";
break;
case "Fail":
$msg['stat'][$d] = "<font color=\"red\"><b>Fail</b></font>";
break;
case "Done":
$msg['stat'][$d] = "<font color=\"green\"><b>Done</b></font>";
break;
default:
$msg['stat'][$d] = "<font color=\"black\"><b>Other</b></font>";
}
if($msg['stat'][$d] == "") $msg['stat'][$d] = " ";
$msg['to'][$d] = trim(substr($curmsg[$i],17));
if(stristr($msg['to'][$d],$_SESSION['user']['domain'])) $anz_to_domain++;
$mailq_msg .= "<tr><td> </td><td>".$msg['stat'][$d]."</td><td>".$msg['to'][$d]."</td><td> </td></tr>\n";
}
if($_SESSION['user']['domain'] == '*' || stristr($msg['from'],$_SESSION['user']['domain']) || $anz_to_domain > 0 )
{
$allowed_msg_ids[] = $msg['id'];
$mailq .= $mailq_msg;
}
unset($curmsg);
// var_dump($msg);
unset($msg);
//echo "Schlüssel: $key; Wert: $value<br>\n";
}
else
{
$curmsg[] = $value;
}
}
}
$mailq .= "</table>\n";
}
if($_REQUEST['mailq_act'] == "Log zum Mail anzeigen .." )
{
//var_dump($_REQUEST['mailq_msgsel']);
if(is_array($_REQUEST['mailq_msgsel']) && is_array($allowed_msg_ids))
{
$mailq_logids = array_intersect ($_REQUEST['mailq_msgsel'],$allowed_msg_ids);
if(is_array($mailq_logids) && count($mailq_logids))
{
$mailq_logtext = "<hr><h3>Log der Selektierten Mails:</h3><hr>";
foreach($mailq_logids as $logid)
{
$mailq_logtext .= "<h4>Log zu $logid:</h4><pre>";
unset($output_log);
exec("sudo -u ".$CourierAdmin_sh_root_user." ".$CourierAdmin_path."/bin/sudo_root.php maillog_grep ".$logid,$output_log);
foreach($output_log as $line)
{
$mailq_logtext .= htmlspecialchars($line."\n");
}
$mailq_logtext .= "</pre><hr>";
}
}
//$mailq_logtext
}
}
if($_REQUEST['mailq_act'] == "Mail aus Queue löschen .." && $_SESSION['user']['right_cancelmsg'] == 1)
{
if(is_array($_REQUEST['mailq_msgsel']) && is_array($allowed_msg_ids))
{
$mailq_logids = array_intersect ($_REQUEST['mailq_msgsel'],$allowed_msg_ids);
if(is_array($mailq_logids) && count($mailq_logids))
{
$mailq_canceltext = "<hr><h3>Folgende Mails wurden gecancelt:</h3><hr>";
foreach($mailq_logids as $logid)
{
$mailq_canceltext .= "<h4>Ausgabe zu $logid:</h4><pre>";
unset($output_cancelmsg);
exec("sudo -u ".$CourierAdmin_sh_root_user." ".$CourierAdmin_path."/bin/sudo_root.php mailq_cancelmsg ".$logid,$output_cancelmsg);
foreach($output_cancelmsg as $line)
{
$mailq_canceltext .= htmlspecialchars($line."\n");
}
$mailq_canceltext .= "</pre><hr>";
}
}
//$mailq_logtext
}
}
?>
<html>
<head>
<?php
if($_SESSION['mailq_refresh'] == 1)
{
echo"<meta http-equiv=\"refresh\" content=\"".$CourierAdmin_default_refresh_time."\">";
}
?>
<title>Mailq, Courieradmin (c) by Nerve</title>
</head>
<body>
<h1>Aktuelle Mail Queue von Courier</h1>
<h3>Queue umfasst Total <?php print($mailq_messages);?> Mails</h3>
<form name="Formular" method="post" action="<%=$self%>" target="_self">
<b>Automatisch auffrischen ? : </b> <input type="checkbox" name="mailq_refresh" value="1" <?php if($_SESSION['mailq_refresh'] > 0) echo "checked";?>><br><br>
<input type=submit name="mailq_act" value="Log zum Mail anzeigen .."><br><br>
<?php if($_SESSION['user']['right_cancelmsg'] == 1) print('<input type=submit name="mailq_act" value="Mail aus Queue löschen .."><br><br>');?><br>
<?php print($mailq); ?><br>
<input type=submit name="mailq_act" value="Log zum Mail anzeigen .."><br><br>
<?php if($_SESSION['user']['right_cancelmsg'] == 1) print('<input type=submit name="mailq_act" value="Mail aus Queue löschen .."><br><br>');?>
</form>
<h3>Queue umfasst Total <?php print($mailq_messages);?> Mails</h3>
<?php print($mailq_canceltext); ?><br>
<?php print($mailq_logtext); ?><br>
</body>
</html>
<?php