示例#1
0
function buildpdf()
{
    @mkdir("/usr/share/artica-postfix/PDFs", 666, true);
    if ($GLOBALS["RCPT_TO"] == null) {
        echo "No recipient set...\n";
        return;
    }
    if ($GLOBALS["OU"] == null) {
        echo "No organization set...\n";
        return;
    }
    getSommaire();
    sql_domain();
    $date = date("Y-m-d");
    $pdf = new Cezpdf('a4', 'portrait');
    echo __FUNCTION__ . " Creating instance done...\n";
    $pdf->ezSetMargins(50, 70, 50, 50);
    $all = $pdf->openObject();
    $pdf->saveState();
    //$pdf->setStrokeColor(0,0,0,1);
    $pdf->line(20, 40, 578, 40);
    $pdf->line(20, 822, 578, 822);
    $pdf->addText(50, 34, 6, $date);
    $pdf->restoreState();
    $pdf->closeObject();
    $pdf->addObject($all, 'all');
    $mainFont = dirname(__FILE__) . "/ressources/fonts/Helvetica.afm";
    $codeFont = dirname(__FILE__) . "/ressources/fonts/Courier.afm";
    $pdf->selectFont($mainFont);
    $pdf->ezText("{$GLOBALS["OU"]}\n", 30, array('justification' => 'centre'));
    $pdf->ezText("Messaging report\n", 20, array('justification' => 'centre'));
    $pdf->ezText("{$date}", 18, array('justification' => 'centre'));
    $pdf->ezText(count($GLOBALS["OU-USERS"]) . " users", 18, array('justification' => 'centre'));
    $pdf->ezStartPageNumbers(100, 30, 12, "left", "Page {PAGENUM}/{TOTALPAGENUM}");
    $pdf->ezNewPage();
    $pdf->ezText("The report:", 28, array('justification' => 'left'));
    $pdf->ezText("");
    $pdf->ezText("The current report is based on " . count($GLOBALS["mydomains"]) . " domains", 12, array('justification' => 'left'));
    $pdf->ezText("Including " . @implode(", ", $GLOBALS["mydomains"]) . " for the last {$GLOBALS["LAST_DAYS"]} days", 12, array('justification' => 'left'));
    $sql = "SELECT COUNT(bounce_error) as tcount,bounce_error FROM smtp_logs WHERE {$GLOBALS["SQL_DOMAINS"]} AND time_stamp>DATE_ADD(NOW(), INTERVAL -{$GLOBALS["LAST_DAYS"]} DAY) GROUP BY bounce_error";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $data[] = array($ligne["tcount"], $ligne["bounce_error"]);
    }
    $pdf->ezText("");
    $title = "Global email status during the period";
    // 005447 = 0,0.32,0.278
    // CCCCCC = 0.8,0.8,0.8
    $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500);
    $pdf->ezTable($data, $cols, $title, $options);
    $file = FlowMessages();
    $pdf->ezNewPage();
    echo __FUNCTION__ . " image {$file}\n";
    $pdf->ezImage("/usr/share/artica-postfix/PDFs/graph1.png", 5, 500, "none", 'left', 1);
    $pdf->ezText("");
    $pdf->ezImage("/usr/share/artica-postfix/PDFs/graph2.png", 5, 500, "none", 'left', 1);
    $pdf->ezNewPage();
    //----------------------------------------------------------------------------------------------------------
    $sql = "SELECT COUNT( ID ) AS tcount,delivery_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY delivery_user ORDER BY tcount DESC LIMIT 0,10 ";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    echo $sql;
    unset($data);
    $data[] = array("nb", "recipients");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["delivery_user"] == null) {
            continue;
        }
        $data[] = array($ligne["tcount"], $ligne["delivery_user"]);
    }
    $title = "Most active users (recipients) during the period";
    $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500);
    $pdf->ezTable($data, $cols, $title, $options);
    //----------------------------------------------------------------------------------------------------------
    $pdf->ezText("\n");
    //----------------------------------------------------------------------------------------------------------
    $sql = "SELECT COUNT( ID ) AS tcount,sender_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_OUT_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY sender_user ORDER BY tcount DESC LIMIT 0,10 ";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    echo $sql;
    unset($data);
    $data[] = array("nb", "senders");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["sender_user"] == null) {
            continue;
        }
        $data[] = array($ligne["tcount"], $ligne["sender_user"]);
    }
    $title = "Most active users (senders) during the period";
    $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500);
    $pdf->ezTable($data, $cols, $title, $options);
    //----------------------------------------------------------------------------------------------------------
    $pdf->ezNewPage();
    //----------------------------------------------------------------------------------------------------------
    $sql = "SELECT COUNT( ID ) AS tcount,sender_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY sender_user ORDER BY tcount DESC LIMIT 0,32 ";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    echo $sql;
    unset($data);
    $data[] = array("nb", "Internet senders");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["sender_user"] == null) {
            continue;
        }
        $data[] = array($ligne["tcount"], $ligne["sender_user"]);
    }
    $title = "Most active sender internet users during the period";
    $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 10, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500);
    $pdf->ezTable($data, $cols, $title, $options);
    //----------------------------------------------------------------------------------------------------------
    $pdf->ezNewPage();
    //----------------------------------------------------------------------------------------------------------
    $sql = "SELECT COUNT( ID ) AS tcount,delivery_user\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_OUT_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -{$GLOBALS["LAST_DAYS"]}\nDAY )\nGROUP BY delivery_user ORDER BY tcount DESC LIMIT 0,32 ";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_events");
    echo $sql;
    unset($data);
    $data[] = array("nb", "Internet recipients");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        if ($ligne["delivery_user"] == null) {
            continue;
        }
        $data[] = array($ligne["tcount"], $ligne["delivery_user"]);
    }
    $title = "Most active internet recipients during the period";
    $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 10, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500);
    $pdf->ezTable($data, $cols, $title, $options);
    //----------------------------------------------------------------------------------------------------------
    $pdf->ezNewPage();
    //----------------------------------------------------------------------------------------------------------;
    $pdf->ezText("Per users report", 28, array('justification' => 'center'));
    $pdf->ezText("");
    $pdf->ezText(count($GLOBALS["OU-USERS"]) . " users detailed report", 18, array('justification' => 'center'));
    //----------------------------------------------------------------------------------------------------------
    $pdf->ezNewPage();
    //----------------------------------------------------------------------------------------------------------;
    while (list($uid) = each($GLOBALS["OU-USERS"])) {
        $u = new user($uid);
        $displayname = $u->DisplayName;
        echo "Generate report for {$u->uid}\n";
        $pdf->ezText("{$displayname}", 22, array('justification' => 'left'));
        $pdf->ezText("");
        $pdf->ezText("The current report is based on " . count($u->HASH_ALL_MAILS) . " email addresses", 10, array('justification' => 'left'));
        $pdf->ezText("Including " . @implode(", ", $u->HASH_ALL_MAILS) . " mails", 10, array('justification' => 'left'));
        $pdf->ezText("\n");
        FlowMessages_users($uid, $u->HASH_ALL_MAILS);
        if (is_file("/usr/share/artica-postfix/PDFs/{$uid}-inbound.png")) {
            $pdf->ezImage("/usr/share/artica-postfix/PDFs/{$uid}-inbound.png", 5, 500, "none", 'left', 1);
            $pdf->ezText("");
        }
        if (is_file("/usr/share/artica-postfix/PDFs/{$uid}-outbound.png")) {
            $pdf->ezImage("/usr/share/artica-postfix/PDFs/{$uid}-outbound.png", 5, 500, "none", 'left', 1);
            $pdf->ezText("");
        }
        if (is_array($GLOBALS[$uid]["RECEIVE"])) {
            $title = "Most Internet senders for  {$displayname} during the period";
            $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500);
            $pdf->ezTable($GLOBALS[$uid]["RECEIVE"], $cols, $title, $options);
        }
        if (is_array($GLOBALS[$uid]["SENT"])) {
            $title = "Most Internet recipients for  {$displayname} during the period";
            $options = array('showLines' => 2, 'showHeadings' => 0, 'shaded' => 2, 'shadeCol' => array(1, 1, 1), 'shadeCol2' => array(0.8, 0.8, 0.8), 'fontSize' => 11, 'textCol' => array(0, 0, 0), 'textCol2' => array(1, 1, 1), 'titleFontSize' => 16, 'titleGap' => 8, 'rowGap' => 5, 'colGap' => 10, 'lineCol' => array(1, 1, 1), 'xPos' => 'left', 'xOrientation' => 'right', 'width' => 500, 'maxWidth' => 500);
            $pdf->ezTable($GLOBALS[$uid]["SENT"], $cols, $title, $options);
        }
        $pdf->ezNewPage();
    }
    $pdfcode = $pdf->output();
    $fname = "/usr/share/artica-postfix/PDFs/report-director-{$GLOBALS["OU"]}.pdf";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pdf->messages}\nbuilding {$fname}\n";
    }
    @unlink($fname);
    if ($GLOBALS["VERBOSE"]) {
        echo "Building {$fname}\n";
    }
    $fp = fopen($fname, 'w');
    fwrite($fp, $pdfcode);
    fclose($fp);
    $users = new usersMenus();
    send_email_events("[ARTICA]: ({$users->hostname}) {$GLOBALS["OU"]}:: weekly report sended to {$GLOBALS["RCPT_TO"]}", "", "mailbox", date('Y-m-d H:i:s'), array($fname), $GLOBALS["RCPT_TO"]);
    if ($GLOBALS["VERBOSE"]) {
        echo "Sending mail\n";
    }
    SendMailNotif("you will find in attached file the weekly report of your {$users->hostname} mail server", "[ARTICA]: ({$users->hostname}) {$GLOBALS["OU"]}:: weekly messaging report", null, $GLOBALS["RCPT_TO"], $GLOBALS["VERBOSE"], array($fname));
}
    write_syslog("wants pflogsumm reporting but no recipients set", __FILE__);
    die;
}
while (list($num, $email) = each($rec)) {
    if (trim($email) == null) {
        continue;
    }
    $recipients[$email] = $email;
}
if (!is_array($recipients)) {
    write_syslog("wants pflogsumm reporting but no recipients set", __FILE__);
    die;
}
if (!is_file("{$maillog}")) {
    write_syslog("wants pflogsumm reporting but cannot stat maillog or mail.log", __FILE__);
    die;
}
system("/usr/sbin/pflogsumm -d today --verbose_msg_detail {$maillog} >/tmp/pflogsumm 2>&1");
$reporting = file_get_contents("/tmp/pflogsumm");
write_syslog("pflogsumm reporting generated for " . count($recipients) . " recipients with " . strlen($reporting) . " bytes length", __FILE__);
@unlink("/tmp/pflogsumm");
while (list($num, $email) = each($recipients)) {
    if (trim($email) == null) {
        continue;
    }
    if ($use_send_mail == 1) {
        SendMailNotifWithSendMail($reporting, $subject, $smtp_sender, $email, $debug);
    } else {
        SendMailNotif($reporting, $subject, $smtp_sender, $email, $debug);
    }
}