Ejemplo n.º 1
0
/**
 * write_log($response[, $logfile])
 *
 * Author(s): thanosb, ddonahue
 * Date: May 11, 2008
 * 
 * Writes the values of certain variables along with a message in a log file.
 *
 * Parameters:
 *  $message:   Message to be logged
 *  $logfile:   Path of log file to write to.  Optional.  Default is LOG_DEFAULT_FILE.
 *
 * Returns array:
 *  $result[status]:   True on success, false on failure
 *  $result[message]:  Error message
 */
function write_log($response, $logfile = '')
{
    // Determine log file
    if ($logfile == '') {
        // checking if the constant for the log file is defined
        if (defined(LOG_DEFAULT_FILE) == TRUE) {
            $logfile = LOG_DEFAULT_FILE;
        } else {
            error_log('No log file defined!', 0);
            return array(status => false, message => 'No log file defined!');
        }
    }
    // Get time of request
    if (($time = $_SERVER['REQUEST_TIME']) == '') {
        $time = time();
    }
    // Get IP address
    //if( ($remote_ip = $_SERVER['REMOTE_ADDR']) == '') {
    $remote_ip = get_client_ip();
    //"REMOTE_ADDR_UNKNOWN";
    //}
    // Get requested script
    if (($request_uri = $_SERVER['REQUEST_URI']) == '') {
        $request_uri = "REQUEST_URI_UNKNOWN";
    }
    // Get Request method
    if (requestMethod()) {
        $request_method = requestMethod();
    }
    // Format the date and time
    $date = date("Y-m-d H:i:s", $time);
    // log by date
    $logfile = date('Y-m-d_') . $logfile;
    $logfile = LOG_DIRECTORY . $logfile;
    // log all the fields
    $fields = '';
    foreach ($response['fields'] as $key => $value) {
        $fields .= "[" . $key . ":" . $value . "]";
    }
    // populate the content for logging
    if (is_array($response)) {
        $content = array($date, $response['user_id'], $remote_ip, $request_method, $request_uri, $fields, $response['content']);
    } else {
        $content = array($date, $remote_ip, $request_method, $request_uri, $response);
    }
    // Append to the log file
    if ($fd = @fopen($logfile, "a")) {
        $result = fputcsv($fd, $content);
        fclose($fd);
        if ($result > 0) {
            return array('status' => true);
        } else {
            error_log('Unable to write to ' . $logfile . '!', 0);
            return array('status' => false, 'message' => 'Unable to write to ' . $logfile . '!');
        }
    } else {
        error_log('Unable to open log ' . $logfile . '!', 0);
        return array('status' => false, 'message' => 'Unable to open log ' . $logfile . '!');
    }
}
Ejemplo n.º 2
0
 function report_to_dev($error_code)
 {
     $this->obj->loadHelper('phpmailer/phpmailer', 'mail');
     // $mailSettings = $this->common->dsp_mail_settings($this->tokenData);
     // if($this->debug) dbug('The $mailSettings',$mailSettings);
     define('EMAIL', 'bd90c28624b2e2e1496a40029b2c966f');
     define('SUPPORT_EMAIL', '*****@*****.**');
     define('PASSWORD', '2da6ee628941ba31684cffe8c13deaa8');
     define('PORT', 465);
     // 465 // 587
     define('ENCRYPTION', 'ssl');
     define('SERVER', 'in.mailjet.com');
     if ($this->obj->debug) {
         echo "email =>>" . EMAIL . "<br/>";
         echo "password =>>" . PASSWORD . "<br/>";
         echo "PORT =>>" . PORT . "<br/>";
         echo "SERVER =>>" . SERVER . "<br/>";
         echo "Encryption =>>" . ENCRYPTION . "<br/>";
         echo "support email =>>" . SUPPORT_EMAIL . "<br/><br/><br/>";
     }
     //SMTP needs accurate times, and the PHP time zone MUST be set
     //This should be done in your php.ini, but this is how to do it if you don't have access to that
     //date_default_timezone_set('Etc/UTC');
     //Tell PHPMailer to use SMTP
     $this->obj->mail->isSMTP();
     //Enable SMTP debugging
     // 0 = off (for production use)
     // 1 = client messages
     // 2 = client and server messages
     $this->obj->mail->SMTPDebug = 0;
     if ($this->obj->debug) {
         $this->obj->mail->SMTPDebug = 2;
     }
     //Ask for HTML-friendly debug output
     $this->obj->mail->Debugoutput = 'html';
     //Set the hostname of the mail server
     $this->obj->mail->Host = SERVER;
     //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
     // Or Set 465 for authenticated ssl
     $this->obj->mail->Port = PORT;
     //Set the encryption system to use - ssl (deprecated) or tls
     if (ENCRYPTION != NONE) {
         $this->obj->mail->SMTPSecure = ENCRYPTION;
     }
     //Whether to use SMTP authentication
     $this->obj->mail->SMTPAuth = true;
     //Username to use for SMTP authentication - use full email address for gmail
     $this->obj->mail->Username = EMAIL;
     //Password to use for SMTP authentication
     $this->obj->mail->Password = PASSWORD;
     //Set who the message is to be sent from
     $this->obj->mail->setFrom(SUPPORT_EMAIL, 'Support');
     //Set an alternative reply-to address
     //$this->obj->mail->addReplyTo(SUPPORT_EMAIL, 'Reply me');
     //Set who the message is to be sent to
     $this->obj->mail->addAddress('*****@*****.**', 'kanhai');
     //Set the subject line
     $this->obj->mail->Subject = 'Bidstalk Client Internal Error for apiToken [' . $this->obj->tokenData['api_token'] . '] and user_id [' . $this->obj->tokenData['api_user_id'] . '] ';
     //Read an HTML message body from an external file, convert referenced images to embedded,
     //convert HTML into a basic plain-text alternative body
     $this->obj->mail->msgHTML("\n\t\t\tInternal Error Details  <pre>" . "<br/> The Error Code : " . $error_code . "<br/> The Token : " . print_r($this->obj->tokenData, true) . "<br/> The Response : " . print_r($this->obj->response, true) . "<br/> The Request : " . print_r($_REQUEST, true) . "<br/> The Request Method : " . requestMethod() . "</pre>");
     //Replace the plain text body with one created manually
     $this->obj->mail->AltBody = 'This is a plain-text message body';
     if (!$this->obj->mail->send()) {
         if ($this->obj->debug) {
             echo "could not send error mail to dev";
         }
     } else {
         if ($this->obj->debug) {
             echo "sent mail successfully";
         }
     }
 }