更新:请在发布新问题之前阅读此问题的答案!感谢。 的
这是为了工作。 (我在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天的价值(换句话说:一周的价值)滥用电子邮件,并在我们公司的Kayako安装中将其作为支持票提交。 Kayako API我已经拍了下来;问题是我如何仅阅读上周的滥用通知和不整个电子邮件帐户中的所有通知(我运行此脚本的最后2次,它像Energizer Bunny一样继续前进和前进,我必须在脚本及其进程所在的服务器上运行 kill -9 [进程ID] 命令。
顺便说一下,对于“email-functions.php”脚本,这个脚本提到:忽略它。它是由其他人写的,而不是我,所以我不能保证它的错误。
我只能承认自己编码中的错误......
如果有人知道如何解决我的问题,请留下回复或评论,谢谢!
答案 0 :(得分:0)
简单回答:
我所做的事情毫无意义。我的公司处理滥用门票的方式(实际上,根据电子邮件通知提交滥用票据)需要在任何这些PHP / Kayako REST API脚本变得方便之前修复。
长答案:
我们公司目前处理所有滥用通知,并使用人类作为转移方法将其提交给Kayako票务支持系统。然而,我们的人力提交票证(以及使用WHMCS的客户查询)存在缺陷,因为只有人类可以使用它;如果我们试图将机器人(自动化)系统集成(或自动化)到我们当前的方法中,它会像比尔盖茨(或其他人)曾经有名的说法那样“放大我们当前系统方法中的低效率”。 p>
因此,我认为剧本是一场闹剧。这不值得;我计划在明天早上午夜之前通知我的老板,并向他提出修复现行系统的计划。与此同时,我将编写该商业计划。