Exemple #1
0
 /**
  * Public constructor, creates the timer object and calculates the execution
  * time limits.
  * 
  * @return  ATimer
  */
 public function __construct($max_exec_time = 5, $runtime_bias = 75)
 {
     ALog::_(ANGIE_LOG_DEBUG, __METHOD__ . '(' . $max_exec_time . ', ' . $runtime_bias . ')');
     // Initialize start time
     $this->start_time = $this->microtime_float();
     $this->max_exec_time = $max_exec_time * $runtime_bias / 100;
 }
 public function mux($logged)
 {
     $VIndex = new VIndex();
     switch ($VIndex->getController()) {
         case 'alog':
             $ALog = new ALog();
             return $ALog->mux();
         case 'arent':
             if ($logged >= 0) {
                 $ARent = new ARent();
                 return $ARent->mux();
             }
         case 'aadmin':
             if ($logged >= 1) {
                 $AAdmin = new AAdmin();
                 return $AAdmin->mux();
             }
     }
 }
Exemple #3
0
 static function display()
 {
     if (!self::isActive()) {
         return false;
     }
     $previous = array();
     $cummulative = array();
     $first = true;
     ob_start();
     switch (self::$debug_level) {
         case 0:
             //show only exceptions
             //shown in Abc_Exception::displayError
             break;
         case 1:
             //show errors and warnings
             self::display_errors();
             break;
         case 2:
             // #1 + mysql site load, php file execution time and page elements load time
             self::display_errors();
             //count php execution time
             foreach (self::$checkpoints as $name => $c) {
                 if ($c['type'] != 'checkpoint') {
                     continue;
                 }
                 if ($first == true) {
                     $first = false;
                     $cummulative = $c;
                 }
                 $time = sprintf("%01.4f", $c['time'] - $cummulative['time']);
             }
             echo '<div class="debug_info">';
             echo 'Queries - ' . count(self::$queries) . '<br />';
             echo 'Queries execution time - ' . sprintf('%01.5f', self::$queries_time) . '<br />';
             echo 'PHP Execution time - ' . $time . '<br />';
             echo '</div>';
             break;
         case 3:
         case 4:
         case 5:
             // #2 + basic logs and stack of execution
             // #3 + dump mysql statements
             // #4 + call stack
             echo '<table class="debug_info" cellpadding=5>
                 <tr>
                     <td><b>Name</b></td>
                     <td><b>Info</b></td>
                 </tr>';
             foreach (self::$checkpoints as $c) {
                 echo '<tr valign="top" class="debug_' . $c['type'] . '" ><td><b>' . $c['name'] . '</b><br /></td>';
                 echo '<td>';
                 if ($first == true && $c['type'] != 'variable') {
                     $previous = array('time' => $c['time'], 'memory' => 0, 'included_files' => 0, 'queries' => 0);
                     $first = false;
                     $cummulative = $c;
                 }
                 switch ($c['type']) {
                     case 'variable':
                         echo $c['msg'] . '<br />';
                         break;
                     case 'error':
                     case 'warning':
                         echo $c['msg'] . '<br />';
                     case 'checkpoint':
                         echo '- Memory: ' . number_format($c['memory'] - $previous['memory']) . ' (' . number_format($c['memory']) . ')' . '<br />';
                         echo '- Files: ' . ($c['included_files'] - $previous['included_files']) . ' (' . $c['included_files'] . ')' . '<br />';
                         echo '- Queries: ' . ($c['queries'] - $previous['queries']) . ' (' . $c['queries'] . ')' . '<br />';
                         echo '- Time: ' . sprintf("%01.4f", $c['time'] - $previous['time']) . ' (' . sprintf("%01.4f", $c['time'] - $cummulative['time']) . ')' . '<br />';
                         if (self::$debug_level > 3) {
                             self::display_queries($previous['queries'], $c['queries']);
                         }
                         if (self::$debug_level > 4) {
                             echo '<pre>' . $c['trace'] . '</pre>';
                         }
                         $previous = $c;
                         break;
                 }
                 echo '</td></tr>';
             }
             echo '</table>';
             break;
         default:
     }
     $debug = ob_get_clean();
     switch (self::$debug) {
         case 1:
             //show
             echo $debug;
             break;
         case 2:
             //log
             require_once DIR_CORE . 'lib/log.php';
             $registry = Registry::getInstance();
             if ($registry->has('log')) {
                 $log = $registry->get('log');
             } else {
                 $log = new ALog('error.txt');
             }
             $log->write(strip_tags(str_replace('<br />', "\r\n", $debug)));
             break;
         default:
     }
 }
 public function send()
 {
     if (defined('IS_DEMO') && IS_DEMO) {
         return null;
     }
     if (!$this->to) {
         $error = 'Error: E-Mail to required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->from) {
         $error = 'Error: E-Mail from required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->sender) {
         $error = 'Error: E-Mail sender required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->subject) {
         $error = 'Error: E-Mail subject required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->text && !$this->html) {
         $error = 'Error: E-Mail message required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (is_array($this->to)) {
         $to = implode(',', $this->to);
     } else {
         $to = $this->to;
     }
     $boundary = '----=_NextPart_' . md5(rand());
     $header = '';
     if ($this->protocol != 'mail') {
         $header .= 'To: ' . $to . $this->newline;
         $header .= 'Subject: ' . '=?UTF-8?B?' . base64_encode($this->subject) . '?=' . $this->newline;
     }
     $header .= 'Date: ' . date('D, d M Y H:i:s O') . $this->newline;
     $header .= 'From: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . '<' . $this->from . '>' . $this->newline;
     $header .= 'Reply-To: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . '<' . $this->from . '>' . $this->newline;
     $header .= 'Return-Path: ' . $this->from . $this->newline;
     $header .= 'X-Mailer: PHP/' . phpversion() . $this->newline;
     $header .= 'MIME-Version: 1.0' . $this->newline;
     $header .= 'Content-Type: multipart/related; boundary="' . $boundary . '"' . $this->newline . $this->newline;
     if (!$this->html) {
         $message = '--' . $boundary . $this->newline;
         $message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
         $message .= $this->text . $this->newline;
     } else {
         $message = '--' . $boundary . $this->newline;
         $message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . $this->newline . $this->newline;
         $message .= '--' . $boundary . '_alt' . $this->newline;
         $message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
         if ($this->text) {
             $message .= $this->text . $this->newline;
         } else {
             $message .= 'This is a HTML email and your email client software does not support HTML email!' . $this->newline;
         }
         $message .= '--' . $boundary . '_alt' . $this->newline;
         $message .= 'Content-Type: text/html; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: base64' . $this->newline . $this->newline;
         $message .= chunk_split(base64_encode($this->html)) . $this->newline;
         $message .= '--' . $boundary . '_alt--' . $this->newline;
     }
     foreach ($this->attachments as $attachment) {
         if (file_exists($attachment['file'])) {
             $handle = fopen($attachment['file'], 'r');
             $content = fread($handle, filesize($attachment['file']));
             fclose($handle);
             $message .= '--' . $boundary . $this->newline;
             $message .= 'Content-Type: application/octet-stream' . $this->newline;
             $message .= 'Content-Transfer-Encoding: base64' . $this->newline;
             $message .= 'Content-Disposition: attachment; filename="' . $attachment['filename'] . '"' . $this->newline;
             $message .= 'Content-ID: <' . basename(urlencode($attachment['filename'])) . '>' . $this->newline;
             $message .= 'X-Attachment-Id: ' . basename(urlencode($attachment['filename'])) . $this->newline . $this->newline;
             $message .= chunk_split(base64_encode($content));
         }
     }
     $message .= '--' . $boundary . '--' . $this->newline;
     if ($this->protocol == 'mail') {
         ini_set('sendmail_from', $this->from);
         if ($this->parameter) {
             mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header, $this->parameter);
         } else {
             mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header);
         }
     } elseif ($this->protocol == 'smtp') {
         $handle = fsockopen($this->hostname, (int) $this->port, $errno, $errstr, (int) $this->timeout);
         if (!$handle) {
             $error = 'Error: ' . $errstr . ' (' . $errno . ')';
             $this->log->write($error);
             $this->error[] = $error;
         } else {
             if (substr(PHP_OS, 0, 3) != 'WIN') {
                 socket_set_timeout($handle, $this->timeout, 0);
             }
             while ($line = fgets($handle, 515)) {
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($this->hostname, 0, 3) == 'tls') {
                 fputs($handle, 'STARTTLS' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 220) {
                     $error = 'Error: STARTTLS not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             }
             if (!empty($this->username) && !empty($this->password)) {
                 fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250) {
                     $error = 'Error: EHLO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, 'AUTH LOGIN' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 334) {
                     $error = 'Error: AUTH LOGIN not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, base64_encode($this->username) . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 334) {
                     $error = 'Error: Username not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, base64_encode($this->password) . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 235) {
                     $error = 'Error: Password not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             } else {
                 fputs($handle, 'HELO ' . getenv('SERVER_NAME') . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250) {
                     $error = 'Error: HELO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             }
             if ($this->verp) {
                 fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . $this->crlf);
             } else {
                 fputs($handle, 'MAIL FROM: <' . $this->from . '>' . $this->crlf);
             }
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 250) {
                 $error = 'Error: MAIL FROM not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             if (!is_array($this->to)) {
                 fputs($handle, 'RCPT TO: <' . $this->to . '>' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250 && substr($reply, 0, 3) != 251) {
                     $error = 'Error: RCPT TO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             } else {
                 foreach ($this->to as $recipient) {
                     fputs($handle, 'RCPT TO: <' . $recipient . '>' . $this->crlf);
                     $reply = '';
                     while ($line = fgets($handle, 515)) {
                         $reply .= $line;
                         if (substr($line, 3, 1) == ' ') {
                             break;
                         }
                     }
                     if (substr($reply, 0, 3) != 250 && substr($reply, 0, 3) != 251) {
                         $error = 'Error: RCPT TO not accepted from server!';
                         $this->log->write($error);
                         $this->error[] = $error;
                     }
                 }
             }
             fputs($handle, 'DATA' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 354) {
                 $error = 'Error: DATA not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fputs($handle, $header . $message . $this->crlf);
             fputs($handle, '.' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 250) {
                 $error = 'Error: DATA not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fputs($handle, 'QUIT' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 221) {
                 $error = 'Error: QUIT not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fclose($handle);
         }
     }
     if ($this->error) {
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
     }
 }