2013-04-02 3 views
0

업데이트 됨 : 새로운 질문을 올리기 전에이 질문에 대한 답변을 읽어보십시오! 감사.POP3로 이메일을 읽은 후 PHP 내에서 Kayako Resolve API에 티켓을 제출하려면 어떻게해야합니까?

이것은 작업용입니다. (저는 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 = "[email protected]"; 
     $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를 가지고 있습니다. 나를위한 문제는 어떻게해야합니까? 지난 주 남용 알림을 읽고 NOT 전체 전자 메일 계정의 모든 고지 사항 (지난 2 일이 스크립트를 실행했을 때 계속 진행하고 Energizer Bunny와 & 프로세스가 위치한 서버에서 kill -9 [프로세스 ID] 명령을 서버에서 실행해야했습니다.

그런데 "email-functions.php"스크립트의 경우이 스크립트에 언급되어 있습니다. 무시하십시오. 그것은 나를 제외한 다른 사람들에 의해 작성되었으므로 나는 그 오류에 대해 보증 할 수 없습니다.

나는 단지 내 자신의 코딩의 오류를 인정 할 수 ...

사람이 내 문제를 해결하는 방법을 알고있는 경우, 응답 또는 코멘트를 남겨주세요, 감사합니다!

+0

미안 해요.이 일이 다소 힘이 센다고 들리지만 내 상사가이 프로젝트를 이번 수요일까지 진행할 것으로 기대합니다 ... 그래서 나는이 질문을 여기서하고 있습니다. –

+0

원래 코드 (두 가지 주요 부분 + 일부 사소한 부분)는 인터넷의 여러 위치에서 가져 왔습니다. 나는 회사의 요구에 맞추기 위해 무거운 수정을했다. –

+0

PHP를 통해 IMAP에 대해 언급 한 사람을위한 참고 자료 : 당사 서버는 PHP 5.2.17을 실행하며, PHP를 통해 IMAP를 지원하지 않습니다. –

답변

0

쉬운 답 :

내가 뭐하는 거지 무슨 일이 무의미하다. 저희 회사에서 악용 사례에 관한 티켓을 처리하는 방법 (실제로 전자 메일 통지를 기반으로 악의적 인 티켓을 제출하는 방법)은 이러한 PHP/Kayako REST API 스크립트를 사용하기 전에 해결해야합니다.

긴 답변 :

우리 회사는 현재 모든 학대 통지를 처리하고 전송 방법으로 인간을 사용하여 카야코 티켓 지원 시스템에 제출합니다. 그러나 인간 전용의 티켓 제출 (및 WHMCS를 사용한 클라이언트 조회)은 사람 만 사용할 수 있다는 단점이 있습니다. 우리가 현재의 방법으로 로봇 (자동화 된) 시스템을 통합 (또는 자동화)하려고 시도했을 때, 빌 게이츠 (Bill Gates) (또는 다른 사람)가 한때 유명한 방식으로 우리의 현재 시스템 방법론에서 "비효율을 확대"라고 말했을 것입니다.

따라서 스크립트는 극단이라고 판단했습니다. 그것은 가치가 없어; 나는 내일 아침 자정까지 내 상사에게이 사실을 알리고 현재 시스템을 고칠 계획을 제시 할 계획이다. 그 동안 나는 그 사업 계획서를 쓸 것이다.

+0

* "그 말로는 중재자 :이 질문의 스레드를 닫으십시오. 감사합니다. "* 당신은 당신의 대답을 받아 들여야합니다, 우리는 이런 이유로 질문을 닫지 않습니다. –

+0

나 자신의 대답을 어떻게 수락 할 수 있습니까? 그렇게하는 것이 합법적입니까 (즉, 나를 금지시키지 않겠습니까?). @WouterJ, 감사합니다. –

+0

체크 표시를 클릭하지만 마나 나까지 기다려야한다고 말합니다. –