function view_stats() { if (!privs()) { die; } $ou = $_GET["ou"]; $users = new usersMenus(); sql_domain($ou); $sql = "SELECT COUNT( ID ) AS tcount, DATE_FORMAT( time_stamp, '%m-%d' ) AS tday\nFROM smtp_logs\nWHERE {$GLOBALS["SQL_DOMAINS"]}\nAND time_stamp > DATE_ADD( NOW( ) , INTERVAL -7\nDAY )\nGROUP BY DATE_FORMAT( time_stamp, '%m-%d' )"; $q = new mysql(); //echo $sql; $g = new artica_graphs($fileName, 60); $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $g->ydata[] = $ligne["tcount"]; $g->xdata[] = $ligne["tday"]; } //print_r($g->ydata); $fileName = "/usr/share/artica-postfix/ressources/logs/web/{$ou}-stats-7.png"; $g->title = "Inbound messages"; $g->x_title = "messages number"; $g->y_title = "days-month"; $g->width = 700; $g->filename = $fileName; $g->line_green(); echo "<img src='ressources/logs/web/{$ou}-stats-7.png'>"; }
function InsertMatch($week, $team1, $team2) { $league_id = $_POST['lid']; $conn = sql_domain(); $stmt = $conn->prepare('insert into matches_round_robin(league_id,week_id,team_1,team_2)VALUES(:l,:w,:t1,:t2)'); $stmt->bindParam(':l', $league_id); $stmt->bindParam(':w', $week); $stmt->bindParam(':t1', $team1); $stmt->bindParam(':t2', $team2); $stmt->execute(); }
<?php include $_SERVER['DOCUMENT_ROOT'] . '/functions.php'; $league_id = $_POST['lid']; $conn = sql_domain(); $stmt = $conn->prepare('select * from leagues_config where id = :i'); $stmt->bindParam(':i', $league_id); $stmt->execute(); $league = $stmt->fetchAll(); $league = $league[0]; ?> <div class="modal-dialog" style="width:1600px"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel"> <?php echo $league['name']; ?> - <?php echo GlobalGetLeagueType($league['type']); ?> </h4> </div> <div class="modal-body"> <div class="nav-tabs-custom"> <ul class="nav nav-tabs"> <li data-name="configuration" class="active tab_links"><a href="#tab_1" data-toggle="tab">Main configuration</a></li> <li data-name="brackets" class="tab_links"><a href="#tab_2" data-toggle="tab">Brackets</a></li> <li data-name="results" class="tab_links"><a href="#tab_2" data-toggle="tab">Match results</a></li> </ul>
function GeneratStats($ou) { $sql_domain = sql_domain($ou); if ($sql_domain == null) { return null; } $sql = "SELECT COUNT(ID) as tcount,bounce_error FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' )\nGROUP BY bounce_error"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $bounce_error = TransFormBounceError($ligne["bounce_error"]); if ($bounce_error == null) { $bounce_error = "Sended"; } $arr[] = "\"{$ligne["tcount"]}\"=>\"{$bounce_error}\""; } if (!is_array($arr)) { $day_camember = "array()"; } else { $day_camember = "array(" . implode(",\n", $arr) . ");"; } $sql = "SELECT COUNT(ID) as tcount,sender_domain FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) AND (\n\tSPAM=1 OR\n\tspammy=1 \n\tOR bounce_error='Discard' \n\tOR bounce_error='RBL'\n\tOR bounce_error='Greylisting'\n\tOR bounce_error='Domain not found'\n\tOR bounce_error='Relay access denied'\n\tOR bounce_error='Relaying denied'\n\t\n\t)\nGROUP BY sender_domain ORDER BY tcount DESC LIMIT 0,10"; $sql_log_1 = "{$sql}\n"; unset($arr); $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $arr1[] = "\"{$ligne["tcount"]}\"=>\"{$ligne["sender_domain"]}\""; } if (!is_array($arr1)) { $top_10_spammers = "array()"; } else { $top_10_spammers = "array(" . implode(",\n", $arr1) . ");"; } //-------------------------------------------------------------------------------------------------------------------------- $sql = "\n\nSELECT COUNT(ID) as tcount FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) AND (SPAM=1 OR bounce_error='Discard')"; $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_events")); $spams = $ligne["tcount"]; $sql = "SELECT COUNT(ID) as tcount FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) AND (whitelisted=1)"; $sql_log_3 = $sql; $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_events")); $whitelisted = $ligne["tcount"]; if ($whitelisted == null) { $whitelisted = 0; } if ($spams == null) { $spams = 0; } //-------------------------------------------------------------------------------------------------------------------------- $sql = "SELECT COUNT(ID) as tcount, DATE_FORMAT( time_sended, '%k' ) as th FROM smtp_logs \nWHERE {$sql_domain} AND DATE_FORMAT( time_connect, '%Y-%m-%d' ) = DATE_FORMAT( NOW( ) , '%Y-%m-%d' ) GROUP BY th ORDER BY th"; $sql_log_2 = "{$sql}\n"; $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $arr3[] = "\"{$ligne["tcount"]}\"=>\"{$ligne["th"]}\""; } if (!is_array($arr3)) { $flow_hour = "array()"; } else { $flow_hour = "array(" . implode(",\n", $arr3) . ");"; } $file = "<?php\n"; $file = $file . "/*\n{$sql_log_1}\n----------\n{$sql_log_3}\n----------\n{$sql_log_2}\n*/\n"; $file = $file . "\$today_cam_flow={$day_camember}\n"; $file = $file . "\$today_cam_top_ten_spammers={$top_10_spammers};\n"; $file = $file . "\$whitelisted=array('spam'=>{$spams},'whitelisted'=>{$whitelisted});\n"; $file = $file . "\$flow_hour={$flow_hour};\n"; $file = $file . "?>"; write_syslog("Generate mail statistics for {$num} \"" . dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}/", __FILE__); @mkdir(dirname(__FILE__) . "/ressources/logs"); @mkdir(dirname(__FILE__) . "/ressources/logs/ou-stats"); @mkdir(dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}"); @file_put_contents(dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}/day.inc", $file); chmod(dirname(__FILE__) . "/ressources/logs/ou-stats/{$ou}/day.inc", 0755); }
function InsertIntoMatch($round, $team_1, $team_2, $position) { $league_id = $_POST['lid']; $conn = sql_domain(); $stmt = $conn->prepare('insert into matches_single_ele(league_id,round_id,team_1,team_2,position)VALUES (:l,:r,:t1,:t2,:p)'); $stmt->bindParam(':r', $round); $stmt->bindParam(':l', $league_id); $stmt->bindParam(':t1', $team_1); $stmt->bindParam(':t2', $team_2); $stmt->bindParam(':p', $position); $stmt->execute(); }
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)); }
function RoundRobinInfoByColumn($column_a, $column_b, $value) { $conn = sql_domain(); $stmt = $conn->prepare('SELECT ' . $column_a . ' from leagues_config_round_robin where ' . $column_b . ' = :value'); $stmt->bindParam(':value', $value); $stmt->execute(); $result = $stmt->fetchAll(); if ($result) { return $result[0][$column_a]; } else { return ""; } }