function search()
{
    $t = $_GET["t"];
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_mailarchive_builder();
    $sock = new sockets();
    $search = '%';
    $table = "`" . date("Ymd") . "`";
    $page = 1;
    $FORCE_FILTER = "";
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, $database));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $results = $q->QUERY_SQL($sql, $database);
    if (mysql_num_rows($results) == 0) {
        json_error_show("{$table} no data", 1);
    }
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error);
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $zDate = $ligne["zDate"];
        $mailfrom = $ligne["mailfrom"];
        $mailto = $ligne["mailto"];
        $subject = utf8_encode($ligne["subject"]);
        $MessageID = $ligne["MessageID"];
        $data['rows'][] = array('id' => "{$MessageID}", 'cell' => array("<span style='font-size:14px;color:{$color}'>{$zDate}</a></span>", "<span style='font-size:14px;color:{$color}'>{$mailfrom}</a></span>", "<span style='font-size:14px;color:{$color}'>{$mailto}</a></span>", "<span style='font-size:14px;color:{$color}'>{$subject}</a></span>"));
    }
    echo json_encode($data);
}
예제 #2
0
function MessageID_resend_popup()
{
    $tpl = new templates();
    $q = new mysql_mailarchive_builder();
    $sql = "SELECT mailto,mailfrom,message_size,original_messageid,zDate FROM `{$_GET["table"]}` WHERE MessageID='{$_GET["MessageID-resend-popup"]}'";
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql));
    $subkect = mime_decode($ligne["subject"]);
    $page = CurrentPageName();
    $t = time();
    $tpl = new templates();
    $ligne["zDate"] = date('{l} d {F} H:i:s', strtotime($ligne["zDate"]));
    $html = "\n\t<div class=BodyContent>\n\t<table style='width:100%'>\n\t<tr>\n\t\t<td class=legend style='font-size:16px'>{zDate}:</td>\n\t\t<td style='font-size:16px'>{$ligne["zDate"]}</td>\n\t</tr>\t\t\n\t<tr>\n\t\t<td class=legend style='font-size:16px'>{message_id}:</td>\n\t\t<td style='font-size:16px'>{$ligne["original_messageid"]}</td>\n\t</tr>\t\n\t<tr>\n\t\t<td class=legend style='font-size:16px'>{sender}:</td>\n\t\t<td>" . Field_text("mailfrom-{$t}", $ligne["mailfrom"], "font-size:16px;width:240px") . "</td>\n\t</tr>\n\t<tr>\n\t\t<td class=legend style='font-size:16px'>{recipient}:</td>\n\t\t<td>" . Field_text("mailto-{$t}", $ligne["mailto"], "font-size:16px;width:240px") . "</td>\n\t</tr>\n\t<tr>\n\t\t<td class=legend style='font-size:16px'>{size}:</td>\n\t\t<td style='font-size:16px'>" . FormatBytes($ligne["message_size"] / 1024) . "</td>\n\t</tr>\n\t<tr>\n\t\t<td colspan=2 align=right><hr>" . button("{resend}", "Resend{$t}()", "18px") . "</td>\n\t</tr>\n\t</table>\t\n\t</div>\n\t<span id='{$t}-div'></span>\n<script>\n\tvar x_Resend{$t}= function (obj) {\n\t\tvar results=obj.responseText;\n\t\tdocument.getElementById('{$t}-div').innerHTML=results;\n\t}\t\t\n\t\n\t\t\n\tfunction  Resend{$t}(){\n\t\t\n\t\t\n\t\tAnimateDiv('{$t}-div');\n\t\tvar mailfrom=document.getElementById('mailfrom-{$t}').value;\n\t\tvar mailto=document.getElementById('mailto-{$t}').value;\n\t\t\n\t\tvar XHR = new XHRConnection();\n\t\tXHR.appendData('mailfrom',mailfrom);\n\t\tXHR.appendData('mailto',mailto);\n\t\tXHR.appendData('MessageID-send','{$_GET["MessageID-resend-popup"]}');\n\t\tXHR.appendData('table','{$_GET["table"]}');\n\t\tXHR.sendAndLoad('{$page}', 'POST',x_Resend{$t});\n\t\t}\n</script>\t\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
예제 #3
0
function purge()
{
    $unix = new unix();
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["VERBOSE"]) {
        if (!$GLOBALS["FORCE"]) {
            $time = $unix->PROCCESS_TIME_MIN($pidTime);
            if ($time < 1440) {
                return;
            }
        }
    }
    $sock = new sockets();
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $MailArchiverToMySQLMaxDays = $sock->GET_INFO("MailArchiverToMySQLMaxDays");
    $MailArchiverToMySQLBackupPath = $sock->GET_INFO("MailArchiverToMySQLBackupPath");
    if (!is_numeric($MailArchiverToMySQLMaxDays)) {
        $MailArchiverToMySQLMaxDays = 60;
    }
    if ($MailArchiverToMySQLBackupPath == null) {
        $MailArchiverToMySQLBackupPath = "/home/artica/backup/mailsarchives";
    }
    $mysqldump = $unix->find_program("mysqldump");
    if (!is_file($mysqldump)) {
        system_admin_events("mysqldump no such binary", __FUNCTION__, __FILE__, __LINE__, "backup");
        return false;
    }
    $gzip = $unix->find_program("gzip");
    if (!is_file($gzip)) {
        system_admin_events("gzip no such binary", __FUNCTION__, __FILE__, __LINE__, "backup");
        return false;
    }
    $q = new mysql_mailarchive_builder();
    $params = $q->MYSQL_CMDLINES;
    $sql = "SELECT tablename FROM indextables WHERE xday<DATE_SUB(NOW(),INTERVAL {$MailArchiverToMySQLMaxDays} DAY)";
    @mkdir($MailArchiverToMySQLBackupPath, 0755, true);
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        system_admin_events("{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "backup");
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $tablename = $ligne["tablename"];
        $targetFilename = $MailArchiverToMySQLBackupPath . "/{$tablename}.gz";
        $targetLogsFilename = "{$MailArchiverToMySQLBackupPath}/{$tablename}.log";
        if (is_file($targetFilename)) {
            @unlink($targetFilename);
        }
        if (is_file($targetLogsFilename)) {
            @unlink($targetLogsFilename);
        }
        $cmdline = array();
        $cmdline[] = $mysqldump;
        $cmdline[] = $params;
        $cmdline[] = "--log-error={$targetLogsFilename}";
        $cmdline[] = "--skip-add-locks --insert-ignore --quote-names --skip-add-drop-table --verbose {$q->database} {$tablename}";
        $cmdline[] = " |{$gzip} -9 > {$targetFilename}";
        $cmd = @implode(" ", $cmdline);
        shell_exec($cmd);
        if ($unix->MYSQL_BIN_PARSE_ERROR(@file_get_contents($targetLogsFilename))) {
            system_admin_events("{$unix->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "backup");
            @unlink($targetFilename);
            @unlink($targetLogsFilename);
            continue;
        }
        @unlink($targetLogsFilename);
        $q->QUERY_SQL("DROP TABLE `{$tablename}`");
        if (!$q->ok) {
            system_admin_events("{$q->mysql_error}\nDROP TABLE `{$tablename}`", __FUNCTION__, __FILE__, __LINE__, "backup");
            continue;
        }
        $q->QUERY_SQL("DELETE FROM indextables WHERE tablename='{$tablename}'");
        if (!$q->ok) {
            system_admin_events("{$q->mysql_error}\nDELETE FROM indextables WHERE tablename='{$tablename}'", __FUNCTION__, __FILE__, __LINE__, "backup");
            continue;
        }
    }
}
예제 #4
0
function status2()
{
    $tpl = new templates();
    $page = CurrentPageName();
    $sock = new sockets();
    include_once dirname(__FILE__) . '/ressources/class.mysql.archive.builder.inc';
    $ini = new Bs_IniHandler();
    $ini->loadString(base64_decode($sock->getFrameWork("postfix.php?mailarchiver-status=yes")));
    $status = DAEMON_STATUS_ROUND("APP_MAILARCHIVER", $ini, null);
    $qArch = new mysql_mailarchive_builder();
    $qArchLigne = mysql_fetch_array($qArch->QUERY_SQL("SELECT SUM(rowsnum) as trows,SUM(size) as tsize FROM indextables"));
    $emailsNumber = numberFormat($qArchLigne["trows"], 0, '.', ' ');
    $emailsSize = FormatBytes($qArchLigne["tsize"] / 1024);
    $html = "\n\t\t\t\n\t<div style='font-size:16px' class=text-info>{backupemail_behavior_text}</div>\n\t<div style='width:98%' class=form>\n\t<table style='width:99%'>\n\t<tr>\n\t\t<td valign='top' width=50% valign='top'>{$status}</td>\n\t\t<td width=50% valign='middle' align='center'>" . imgtootltip("64-refresh.png", "{refresh}", "LoadAjax('mailarchiver-status','{$page}?status2=yes')") . "</td>\n\t</tr>\n\t<td valign='top'>\n\t\t<center>\n\t\t<table style='width:10%'>\n\t\t<tr>\n\t\t\t<td class=legend style='font-size:16px' nowrap>{backup}:</td>\n\t\t\t<td style='font-size:16px;font-weight:bold' nowrap>{$emailsNumber}&nbsp;emails&nbsp;({$emailsSize})</td>\n\t\t</tr>\n\t\t</table>\n\t\t</center>\n\t</td>\n\t</tr>\t\t\n\t</table>\n\t</div>\n\t";
    echo $tpl->_ENGINE_parse_body($html);
}
예제 #5
0
<?php

include_once dirname(__FILE__) . '/ressources/class.templates.inc';
include_once dirname(__FILE__) . '/ressources/class.ldap.inc';
include_once dirname(__FILE__) . '/ressources/class.users.menus.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.archive.builder.inc';
$q = new mysql_squid_builder();
$q = new mysql_mailarchive_builder();
$sql = "SELECT table_name as c FROM information_schema.tables WHERE table_schema = 'mailarchive'";
$results = $q->QUERY_SQL($sql, "mailarchive");
while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
    $tablename = $ligne["c"];
    if ($tablename == "indextables") {
        continue;
    }
    $Cyear = substr($tablename, 0, 4);
    $CMonth = substr($tablename, 4, 2);
    $CDay = substr($tablename, 6, 2);
    $CDay = str_replace("_", "", $CDay);
    $xtime = strtotime("{$Cyear}-{$CMonth}-{$CDay} 00:00:00");
    if (date("Y", $xtime) == date("Y")) {
        continue;
    }
    echo "Delete Table {$tablename}\n";
    $q->QUERY_SQL("DROP TABLE `{$tablename}`");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
    }
}
function MessageID_resend_perform()
{
    $workdir = dirname(__FILE__) . "/ressources/logs/web";
    $mailfrom = $_POST["mailfrom"];
    $MessageID = $_POST["MessageID-send"];
    $table = $_POST["table"];
    $mailto = $_POST["mailto"];
    $sql = "SELECT MessageBody,BinMessg FROM `{$table}` WHERE MessageID='{$MessageID}'";
    $tpl = new templates();
    $q = new mysql_mailarchive_builder();
    $user = new user($_SESSION["uid"]);
    writelogs($sql, __FUNCTION__, __FILE__, __LINE__);
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        echo $tpl->_ENGINE_parse_body("\n\t<div class=BodyContent>\n\t<div style='background-color:#D90000;border:1px solid #870000;padding:50px'>\n\t\t<center>\n\t\t\t<p style='color:white;font-size:18px;border:1px solid white;padding:10px;margin:10px'>{failed}<br>\n\t\t\t{$mailto}<hr><p style='color:white;font-size:18px;border:1px solid white;padding:10px;margin:10px'>{$q->mysql_error}</p><hr>\n\t\t\t</p>\n\t\t</center>\n\t</div></div>");
        exit;
    }
    $filename = md5($ligne["MessageBody"]);
    $lenght = strlen($ligne["BinMessg"]);
    if ($lenght == 0) {
        echo $tpl->_ENGINE_parse_body("\n\t<div class=BodyContent>\n\t<div style='background-color:#D90000;border:1px solid #870000;padding:50px'>\n\t\t<center>\n\t\t\t<p style='color:white;font-size:18px;border:1px solid white;padding:10px;margin:10px'>{failed}<br>\n\t\t\t{$mailto}<hr><p style='color:white;font-size:18px;border:1px solid white;padding:10px;margin:10px'>{this_message_contains_no_data}</p><hr>\n\t\t\t</p>\n\t\t</center>\n\t</div></div>");
        exit;
    }
    $lenghttext = FormatBytes($lenght / 1024);
    writelogs("Sending message {$workdir}/{$filename} from {$mailfrom} ({$lenght} bytes)", __FUNCTION__, __FILE__, __LINE__);
    file_put_contents("{$workdir}/{$filename}", $ligne["BinMessg"]);
    if (!is_file("{$workdir}/{$filename}")) {
        echo $tpl->_ENGINE_parse_body("\n\t<div class=BodyContent>\n\t<div style='background-color:#D90000;border:1px solid #870000;padding:50px'>\n\t\t<center>\n\t\t\t<p style='color:white;font-size:18px;border:1px solid white;padding:10px;margin:10px'>{failed}<br>\n\t\t\t{$mailto}<hr><p style='color:white;font-size:18px;border:1px solid white;padding:10px;margin:10px'>\n\t\t\t{$workdir}/{$filename} permission denied</p><hr>\n\t\t\t</p>\n\t\t</center>\n\t</div></div>");
        exit;
    }
    writelogs("Sending message {$workdir}/{$filename} from {$mailfrom}", __FUNCTION__, __FILE__, __LINE__);
    $cmd = "/usr/sbin/sendmail -bm -t -f {$mailfrom} <{$workdir}/{$filename} {$mailto} 2>&1";
    exec($cmd, $resultsMail);
    while (list($num, $tablez) = each($resultsMail)) {
        $resultsMail[$num] = "<div style='font-size:16px;color:#2E6E9E;font-weigth:bold'>" . htmlentities($resultsMail[$num]) . "</div>";
    }
    //@unlink("/tmp/$filename");
    $resultsMailTxt = @implode("<br>", $resultsMail);
    echo $tpl->_ENGINE_parse_body("\n\t<div class=BodyContent>\n\t\n\t\t<center>\n\t\t\t<p style='font-size:18px;border:1px solid white;padding:10px;margin:10px;color:#2E6E9E'>{success} {$lenghttext}</p>\n\t\t\t<div style='text-align:left'>{$resultsMailTxt}</div>\n\t\t</center>\n\t</div>\n\t</div>");
}
function database_search()
{
    $boot = new boostrap_form();
    $page = CurrentPageName();
    $tpl = new templates();
    $q = new mysql_mailarchive_builder();
    $search = string_to_flexquery("search-indextables");
    $sql = "SELECT * FROM indextables WHERE 1 {$search} ORDER BY xday DESC";
    $results = $q->QUERY_SQL($sql, "mailarchive");
    if (!$q->ok) {
        senderror($q->mysql_error);
    }
    if (mysql_num_rows($results) == 0) {
        senderrors("{this_request_contains_no_data}");
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $id = md5(serialize($ligne));
        $ligne["rowsnum"] = FormatNumber($ligne["rowsnum"]);
        $ligne["size"] = FormatBytes($ligne["size"] / 1024);
        $tr[] = "\n\t\t<tr id='{$id}'>\n\t\t<td width=1% nowrap><img src='img/table-show-48.png'></td>\n\t\t<td width=90% nowrap><div style='font-size:18px'>{$ligne["xday"]}</div></td>\n\t\t<td width=90% nowrap><div style='font-size:18px'><div style='font-size:18px'>{$ligne["rowsnum"]}</div></td>\n\t\t<td width=90% nowrap><div style='font-size:18px'><div style='font-size:18px'>{$ligne["size"]}</div></td>\n\t\t</tr>";
    }
    echo $tpl->_ENGINE_parse_body("\n\t\n\t\t\t<table class='table table-bordered'>\n\t\n\t\t\t<thead>\n\t\t\t\t<tr>\n\t\t\t\t\t<th colspan=2>{day}</th>\n\t\t\t\t\t<th >{rows}</th>\n\t\t\t\t\t<th >{size}</th>\n\t\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t <tbody>\n\t\t\t") . @implode("", $tr) . "</tbody></table>";
}