更新: 新しい質問を投稿する前に、この質問に対する回答をお読みください。ありがとう。
これは仕事用です。(私は Web ホストである Acenet, Inc で働いているため、私のコードは重要なログインやその他の API データからサニタイズされます)。私が書いているスクリプトについて助けが必要です。
<?php
/* lothbrok.php - abuse notification email-reader & ticket-injector script for Acenet Inc */
/*
*
* "One script to rule them all,
* One script to find them.
* One script to bring them home,
* And in the darkness, bind them."
*
*/
if ($_GET['worms'] != "food") {
echo "Sorry, but you are not authorized to run LOTHBROK today! Goodbye!";
exit;
} else {
require("email_functions.php");
global $timeout, $error, $buffer;
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
ob_start();
//-----------------------------------------------------------------------------
// Declarations
//-----------------------------------------------------------------------------
$error = ""; // Error string.
$timeout = 90; // Default timeout before giving up on a network operation.
$Count = -1; // Mailbox msg count
$buffer = 512; // Socket buffer for socket fgets() calls, max per RFC 1939 the returned line a POP3 server can send is 512 bytes.
$server = "SANITIZED"; // Set this to hard code the server name
$RFC1939 = false; // Set by noop(). See rfc1939.txt
$msg_list_array = array(); // List of messages from server
$login = 'SANITIZED';
$pass = 'SANITIZED';
//-----------------------------------------------------------------------------
// The Code
//-----------------------------------------------------------------------------
echo "<h1>LOTHBROK</h1><h2>Starting Program</h2><br>";
set_time_limit($timeout);
$fp = connect ($server, $port = 110);
$Count = login($login,$pass, $fp);
if( (!$Count) or ($Count == -1) )
{
exit;
}// end if
if ($Count < 1)
{
die();
} else {
echo "Login OK: Inbox contains [$Count] messages<BR>\n";
$msg_list_array = uidl("", $fp);
set_time_limit($timeout);
}// end if
// loop thru the array to get each message
for ($i=1; $i <= $Count; $i++){
set_time_limit($timeout);
$MsgOne = top($i, empty($numLines), $fp);
if( (!$MsgOne) or (gettype($MsgOne) != "array") )
{
echo "oops, Message not returned by the server.<BR>\n";
exit;
}// end if
/*
call the function to read the message
returns true if access, breakdown and insertion
in to db are completed sucessfully
*/
/*
Function to read the message and extract :
a. subject
b. date
c. split the body line by line
*/
$body = ''; // get the body of the message into 1 variable
$subjects = ''; // get the subject of the email
$dates = ''; // get the date of the email
$body_start_key = false; // body starts at blank line, blank line is separator for from headers to body
$TIRSFlag = false; // flag for seeing if the email is really to be processed by the app
$base64Flag = false; // flag to handle base 64 encoding by email systems.
foreach ($MsgOne as $key => $value)
{
if (trim($value) == "Content-Transfer-Encoding: base64"){
$base64Flag = true;
}//end if
//get the subject line of the email
preg_match("/^(Subject\:) (.*)\r?\n$/i",$subjects,$subject);
//look for "FBL" in the subject to see if we need to attempt to process the email
if (strstr($subject,"FBL")) {
$TIRSFlag = true;
}// end if
}// end if
//get the date of the email
preg_match("/(Date\:) ^([A-Za-z]{3}), ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2})\:([0-9]{2})\:([0-9]{2}) \-?([0-9]{4})$\r?\n/i",$subjects,$dates);
// Grab the message body
$MsgOne = get($i, $fp);
//the body
if (strlen(trim($value))==0){
if ($body_start_key == false){ $body_start_key = true; } //set the start key for the body
}//end if
if ($body_start_key == true){
$body .= trim($value);
if ($base64Flag == false){ $body .="<br />"; }
}// end if
}// end foreach
// only create support ticket(s) if the subject line contains the acronym "FBL"
if ($TIRSFlag == false){
echo "<br>Nothing to read - finished.</b>";
exit;
}else{
//decode the message if its base64 encoded
if ($base64Flag == true) {
$body = base64_decode($body);
} //end if
}
//convert the body crlf to <br> tags if not done when the message was built
$body = nl2br($body);
$body = preg_replace("/^(Please investigate these FBL reports accordingly and create a ticket for the client if need be.)$/i"," ",$body);
$body = preg_replace("/^(Acenet) (AOL|Comcast|Yahoo!?|Hotmail) (FBL Bot)$/i"," ",$body);
/* Cordoned off in case something doesn't work and this is then neeeded.....
$dayn = substr($date,0,2);
$day = substr($date,6,7);
$monn = substr($date,9,11);
$monn = substr($date,9,11);
$year = substr($date,13,16);
$fhrd = substr($date,18,19);
$mind = substr($date,20,21);
$secd = substr($date,22,23);
$msed = substr($date,26,30);
End of Quarantine! :D .... */
while (preg_match("/(THIS IS AN AUTOMATED ABUSE ALERT - DO NOT REPLY)/i",$body) && $dates > strtotime($dates - 8)) {
// Here goes the part to actually make things work!
/* Yet another Quarantine section....
preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/", $subject, $ipaddy); // Client's first name in records (check WHMCS)
preg_match("/^(AOL|Hotmail|Yahoo|Comcast|Facebook|Google|Gmail)$/", $subject, $mailnet); // FBL Reporting Mailsys Network (Hotmail, Comcast, Yahoo!, Google, or AOL)
Hello, back to the news! */
$getArray["e"] = "/Tickets/Ticket";
$apiUrl = "SANITIZED" . $getArray["e"];
$apiKey = "SANITIZED";
$salt = mt_rand(1,99);
$secretKey = "SANITIZED";
$signature = base64_encode(hash_hmac('sha256',$salt,$secretKey,true));
$subject = "Abuse Email Ticket (TESTING - DO NOT RESPOND!)";
$fullname = "Ragnar Lothbrok";
$email = "burningjunk@mailinator.com";
$contents = "Hello anonymous Acenet user,\n\nWe have recently received an FBL (Feedback Loop) Report from an email provider indicating users have identified one or more messages originating from your account as spam. \n\nAcenet is setup to receive a notification any time email sent from our network arrives in the mailbox of another user at this provider and that email provider's user clicks \"This is Spam\" for that email. This is known as a Feedback Loop, we receive Feedback from external mail providers categorizing email which is sent from our network.\n\nThere are many reasons other users may be categorizing mail from your account as spam. The purpose of this notification is not to imply you are a spammer, but to factually inform you that a user has clicked \"This is Spam\" for email sent from your account. \n\nAlong with the FBL, we receive details about the email itself including the Sender, Subject, and Header information. Please note that the exact recipient of the email is often removed by the mail provider as part of their privacy policy. You will often see <redacted> in place of the true recipient's email address.\n\nThe relevant information related to this FBL Report is included below. \n\nIt's important to understand that we are not implying you are a spammer. But, it is our goal to assist you in determining why this report was generated for your emails. If these reports continue to generate, the aforementioned email provider may end up blacklisting your IP and prevent you from emailing those users. By working with our Technicians to address these FBL reports, we can help you to avoid such a situation.\n\nIf the email details provided below are unfamiliar to you, please update this ticket and our Technicians will be happy to review the contents and help interpret how this email may have originated from your account.\n\n\nIf you recognize the email details provided, you should review your mailing practices and attempt to identify why recipients are clicking \"This is Spam\" for these emails.\nFBL Reporting Information follows:\n-------------------------------------------------------------------------------------\n$body\n\n\n";
$departmentid = "9";
$ticketstatusid = "4";
$ticketpriorityid = "9";
$tickettypeid = "1";
$staffid = "27";
$post_data = array('subject' => $subject,
'fullname' => $fullname,
'email' => $email,
'contents' => $contents,
'departmentid' => $departmentid,
'ticketstatusid' => $ticketstatusid,
'ticketpriorityid' => $ticketpriorityid,
'tickettypeid' => $tickettypeid,
'staffid' => $staffid,
'apikey' => $apiKey,
'salt' => $salt,
'signature' => $signature);
$post_data = http_build_query($post_data, '', '&');
$curl = curl_init($apiUrl);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $apiUrl);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl);
curl_close($curl);
}// end for loop
//close the email box and delete all messages marked for deletion
quit($fp);
//close the application
echo "<br>Finished</b>";
exit;
}
/* Have a nice day! */
?>
とにかく、私の問題は、過去 7 日分 (つまり、1 週間分) の迷惑メール メッセージだけを読み、当社の Kayako インストール内でサポート チケットとして送信する必要があることです。Kayako API はダウン パットです。私にとっての問題は、メール アカウント全体のすべての通知ではなく、先週分の不正使用通知のみを読む方法です(このスクリプトを実行した最後の 2 回は、Energizer Bunny のように何度も何度も実行されました。スクリプトとそのプロセスが配置されているサーバーでkill -9 [プロセス ID]コマンドを実行する必要がありました)。
ところで、「email-functions.php」スクリプトに関しては、このスクリプトが言及しています: 無視してください。これは私ではなく他の人が書いたものなので、間違いを保証することはできません。
私は自分のコーディングの欠点を認めるしかありません...
誰かが私の問題を解決する方法を知っている場合は、返信またはコメントを残してください。