function ufdb_smtp() { $unix = new unix(); $q = new mysql_squid_builder(); $sock = new sockets(); if (!$q->TABLE_EXISTS("ufdb_smtp")) { return; } if ($q->COUNT_ROWS("ufdb_smtp") == 0) { return; } $SquidGuardWebSMTP = unserialize(base64_decode($sock->GET_INFO("SquidGuardWebSMTP"))); if (!isset($SquidGuardWebSMTP["MaxError"])) { $SquidGuardWebSMTP["MaxError"] = 5; } if ($SquidGuardWebSMTP["MaxError"] == 0) { $SquidGuardWebSMTP["MaxError"] = 5; } $sql = "SELECT * FROM ufdb_smtp"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { return; } $sock = new sockets(); $SquidGuardWebSMTP = unserialize(base64_decode($sock->GET_INFO("SquidGuardWebSMTP"))); if ($SquidGuardWebSMTP["smtp_server_name"] == null) { return; } //`zDate`,`Subject`,`content`,`sender`,`URL`,`REASONGIVEN`,`retrytime`) VALUES while ($ligne = mysql_fetch_assoc($results)) { $zmd5 = $ligne["zmd5"]; $Subject = $ligne["Subject"]; $smtp_sender = $ligne["sender"]; $recipient = $SquidGuardWebSMTP["smtp_recipient"]; $smtp_senderTR = explode("@", $recipient); $instance = $smtp_senderTR[1]; $SquidGuardIPWeb = $ligne["SquidGuardIPWeb"]; $ticket = $ligne["ticket"]; $main_array = urlencode($ligne["main_array"]); if ($smtp_sender == null) { $smtp_sender = $SquidGuardWebSMTP["smtp_sender"]; } $body = array(); $body[] = "Return-Path: <{$smtp_sender}>"; $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)"; $body[] = "From: {$smtp_sender}"; $body[] = "Subject: {$Subject}"; $body[] = "To: {$recipient}"; $body[] = ""; $body[] = ""; $body[] = "Request time: {$ligne["zDate"]}"; $body[] = "URL: {$ligne["URL"]}"; $body[] = "Reason: {$ligne["REASONGIVEN"]}"; $body[] = "SMTP retry: {$ligne["retrytime"]}"; if ($ticket == 1) { $body[] = ""; $body[] = "****************** RELEASE THIS WEBSITE ******************"; $body[] = ""; $body[] = "If your are agree to release this website, click on the link bellow in order to create the rule."; $body[] = "{$SquidGuardIPWeb}?release-ticket=yes&serialize={$main_array}"; $body[] = ""; $body[] = "***********************************************************"; $body[] = ""; } $body[] = $ligne["content"]; $body[] = ""; $body[] = ""; $finalbody = @implode("\r\n", $body); ufdb_smtp_logs("Send to {$smtp_sender}", __FUNCTION__, __LINE__); $msmtp = new squidguard_msmtp($smtp_sender, $finalbody); $MaxError = $msmtp->MaxError; if ($msmtp->Send()) { ufdb_smtp_logs("Send Success, delete {$zmd5}", __FUNCTION__, __LINE__); $q->QUERY_SQL("DELETE FROM ufdb_smtp WHERE `zmd5`='{$zmd5}'"); if (!$q->ok) { ufdb_smtp_logs("{$q->mysql_error}", __FUNCTION__, __LINE__); } if ($q->COUNT_ROWS("ufdb_smtp") == 0) { break; } continue; } $retrytime = $ligne["retrytime"] + 1; ufdb_smtp_logs("{$zmd5}: Retry +1 = {$retrytime} Max:{$MaxError}", __FUNCTION__, __LINE__); if ($retrytime >= $MaxError) { squid_admin_mysql(1, "Timed out {$Subject} to {$SquidGuardWebSMTP["smtp_server_name"]} retry({$retrytime}/{$MaxError})", $msmtp->logs, __FILE__, __LINE__); $q->QUERY_SQL("DELETE FROM ufdb_smtp WHERE `zmd5`='{$zmd5}'"); continue; } squid_admin_mysql(1, "Unable to send {$Subject} to {$SquidGuardWebSMTP["smtp_server_name"]} retry({$retrytime}/{$MaxError})", $msmtp->logs, __FILE__, __LINE__); $q->QUERY_SQL("UPDATE ufdb_smtp SET `retrytime`='{$retrytime}' WHERE `zmd5`='{$zmd5}'"); if (!$q->ok) { ufdb_smtp_logs("{$q->mysql_error}", __FUNCTION__, __LINE__); } } $q->QUERY_SQL("DELETE FROM ufdb_smtp WHERE `retrytime`={$MaxError}"); $q->QUERY_SQL("DELETE FROM ufdb_smtp WHERE `retrytime`>" . $MaxError); }
function tests_smtp() { echo "<textarea style='width:100%;height:275px;font-size:14px !important;border:4px solid #CCCCCC;\n\tfont-family:\"Courier New\",\n\tCourier,monospace;color:black' id='subtitle'>"; include_once dirname(__FILE__) . '/ressources/smtp/smtp.php'; ini_set('display_errors', 1); ini_set('error_reporting', E_ALL); ini_set('error_prepend_string', null); ini_set('error_append_string', null); $tpl = new templates(); $sock = new sockets(); $SquidGuardWebSMTP = unserialize(base64_decode($sock->GET_INFO("SquidGuardWebSMTP"))); $GLOBALS["VERBOSE"] = true; $smtp_sender = $_GET["smtp_sendto"]; $recipient = $SquidGuardWebSMTP["smtp_recipient"]; $smtp_senderTR = explode("@", $_GET["smtp_sendto"]); $instance = $smtp_senderTR[1]; $random_hash = md5(date('r', time())); $body[] = "Return-Path: <{$smtp_sender}>"; $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)"; $body[] = "From: {$smtp_sender}"; $body[] = "To: {$recipient}"; $body[] = "Subject: Test notification from Web interface"; $body[] = ""; $body[] = ""; $body[] = "Here, the message from the robot..."; $body[] = ""; $body[] = ""; $finalbody = @implode("\r\n", $body); $msmtp = new squidguard_msmtp($smtp_sender, $finalbody); if ($msmtp->Send()) { echo $msmtp->logs; echo "</textarea><script>"; echo "alert('" . $tpl->javascript_parse_text("Test Message\nTo {$recipient}: {success}") . "');</script>"; return; } echo $msmtp->logs . "\n"; $smtp = new smtp(); $smtp->debug = true; if ($SquidGuardWebSMTP["smtp_auth_user"] != null) { $params["auth"] = true; $params["user"] = $SquidGuardWebSMTP["smtp_auth_user"]; $params["pass"] = $SquidGuardWebSMTP["smtp_auth_passwd"]; } $params["host"] = $SquidGuardWebSMTP["smtp_server_name"]; $params["port"] = $SquidGuardWebSMTP["smtp_server_port"]; if (!$smtp->connect($params)) { echo "</textarea><script>"; echo "alert('" . $tpl->javascript_parse_text("{error_while_sending_message} {error} {$smtp->error_number} {$smtp->error_text}") . "');</script>"; return; } if (!$smtp->send(array("from" => $smtp_sender, "recipients" => $recipient, "body" => $finalbody, "headers" => null))) { $smtp->quit(); echo "</textarea><script>"; echo "alert('" . $tpl->javascript_parse_text("{error_while_sending_message} {error}\\n {$smtp->error_number} {$smtp->error_text}") . "');</script>"; return; } echo "</textarea><script>"; echo "alert('" . $tpl->javascript_parse_text("Test Message\nTo {$recipient}: {success}") . "');</script>"; $smtp->quit(); }