예제 #1
0
 /**
  * Download an AuditMail file as eml.
  * @param $id
  * @throws NotFoundHttpException
  */
 public function actionDownload($id)
 {
     $model = AuditMail::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException('The requested mail does not exist.');
     }
     Yii::$app->response->sendContentAsFile(Helper::uncompress($model->data), $model->id . '.eml');
 }
예제 #2
0
 public function recordMessage($message, $code = 0, $file = '', $line = 0, $trace = [])
 {
     $this->message = $message;
     $this->code = $code;
     $this->file = $file;
     $this->line = $line;
     $this->trace = Helper::cleanupTrace($trace);
 }
예제 #3
0
 public function beforeSave($insert)
 {
     // Only serialize complex values
     if (is_array($this->data) || is_object($this->data)) {
         $this->packed = true;
         $this->autoSerialize = true;
         $this->data = \bedezign\yii2\audit\components\Helper::compact($this->data);
     }
     return parent::beforeSave($insert);
 }
예제 #4
0
 /**
  *
  */
 public function afterFind()
 {
     parent::afterFind();
     if ($this->autoSerialize) {
         foreach ($this->serializeAttributes as $attribute) {
             if ($this->hasAttribute($attribute)) {
                 $this->{$attribute} = Helper::unserialize($this->{$attribute});
             }
         }
     }
 }
예제 #5
0
 /**
  * Log a regular error message
  *
  * @param int        $entry_id      Entry to associate the error with
  * @param string     $message
  * @param int        $code
  * @param string     $file
  * @param int        $line
  * @param array      $trace         Stack trace to include. Use `Helper::generateTrace()` to create it.
  * @return null|static
  */
 public function logMessage($entry_id, $message, $code = 0, $file = '', $line = 0, $trace = [])
 {
     $error = new AuditError();
     $error->entry_id = $entry_id;
     $error->message = $message;
     $error->code = $code;
     $error->file = $file;
     $error->line = $line;
     $error->trace = Helper::cleanupTrace($trace);
     $error->hash = Helper::hash($error->message . $error->file . $error->line);
     return $error->save(false) ? $error : null;
 }
예제 #6
0
 public function finalize()
 {
     if (in_array('response', $this->logVars)) {
         $entry = Audit::current()->getEntry();
         if ($entry) {
             if (Yii::$app->response instanceof \yii\web\Response) {
                 $data = Helper::compact(Yii::$app->response->headers, true);
                 if ($data) {
                     $entry->addData('response_headers', $data);
                 }
             }
         }
     }
 }
예제 #7
0
 public function finalize()
 {
     $this->end_time = microtime(true);
     $this->duration = $this->end_time - $this->start_time;
     $this->memory = memory_get_usage();
     $this->memory_max = memory_get_peak_usage();
     $response = \Yii::$app->response;
     if ($response instanceof \yii\web\Response) {
         $this->redirect = $response->headers->get('location');
         $this->addData('Response Headers', Helper::compact($response->headers, true), 'response_headers');
     }
     return $this->save(false, ['end_time', 'duration', 'memory', 'memory_max', 'redirect']);
 }
예제 #8
0
    }
}
if (count($entry->javascript)) {
    echo Html::tag('h2', Yii::t('audit', 'Javascript ({i})', ['i' => count($entry->javascript)]), ['id' => 'javascript', 'class' => 'hashtag']);
    foreach ($entry->javascript as $i => $javascript) {
        echo Html::tag('h3', Yii::t('audit', 'Entry #{i}', ['i' => $i + 1]));
        echo DetailView::widget(['model' => $javascript, 'attributes' => ['type', 'message', 'origin', ['attribute' => 'data', 'value' => Helper::formatValue($javascript->data), 'format' => 'raw']]]);
    }
}
$types = ['env' => '$_SERVER', 'session' => '$_SESSION', 'cookies' => '$_COOKIES', 'files' => '$_FILES', 'get' => '$_GET', 'post' => '$_POST'];
// display depricated data
if ($entry->data) {
    foreach ($entry->data as $type => $values) {
        $attributes = [];
        foreach ($values as $name => $value) {
            $attributes[] = ['label' => $name, 'value' => Helper::formatValue($value), 'format' => 'raw'];
        }
        echo Html::tag('h2', $types[$type], ['id' => $type, 'class' => 'hashtag']);
        echo DetailView::widget(['model' => $entry, 'attributes' => $attributes, 'template' => '<tr><th>{label}</th><td style="word-break:break-word;">{value}</td></tr>']);
    }
}
?>
    </div>
    <div class="col-md-2">
        <ul class="nav nav-pills nav-stacked affix">
          <li><a href="#entry"><?php 
echo Yii::t('audit', 'Request');
?>
</a></li>

          <?php 
예제 #9
0
 public function addBatchData($batchData)
 {
     $columns = ['entry_id', 'type', 'data', 'packed'];
     $rows = [];
     foreach ($batchData as $type => $data) {
         $rows[] = [$this->id, $type, Helper::serialize($data), 1];
     }
     Yii::$app->db->createCommand()->batchInsert(AuditData::tableName(), $columns, $rows)->execute();
 }
예제 #10
0
 public function addData($type, $data, $compact = true)
 {
     $record = ['entry_id' => $this->id, 'type' => $type, 'data' => Helper::serialize($data, $compact)];
     static::getDb()->createCommand()->insert(AuditData::tableName(), $record)->execute();
 }
예제 #11
0
 /**
  * @param $type
  * @param $data
  * @param bool|true $compact
  * @throws \yii\db\Exception
  */
 public function addData($type, $data, $compact = true)
 {
     // Make sure to mark data as a large object so it gets escaped
     $record = ['entry_id' => $this->id, 'type' => $type, 'data' => [Helper::serialize($data, $compact), \PDO::PARAM_LOB]];
     static::getDb()->createCommand()->insert(AuditData::tableName(), $record)->execute();
 }
예제 #12
0
<?php

/* @var $panel bedezign\yii2\audit\panels\SoapPanel */
use yii\bootstrap\Tabs;
use yii\helpers\Html;
use bedezign\yii2\audit\components\Helper;
use yii\helpers\ArrayHelper;
use yii\helpers\VarDumper;
$preformatted = ['class' => 'well', 'style' => 'overflow: auto; white-space: pre'];
$formatter = \Yii::$app->formatter;
//echo "<pre>" . ;
$tabs = [];
if (isset($request['result_object'])) {
    $tabs[] = ['label' => \Yii::t('audit', 'Result - Object'), 'content' => Html::tag('div', $formatter->asText(VarDumper::dumpAsString(ArrayHelper::toArray($request['result_object']))), $preformatted)];
    unset($request['result_object']);
}
if (isset($request['result'])) {
    $xml = Helper::formatAsXML($request['result']);
    if ($xml) {
        $tabs[] = ['label' => \Yii::t('audit', 'Result - XML'), 'content' => Html::tag('div', $xml, $preformatted)];
    }
    $tabs[] = ['label' => \Yii::t('audit', 'Result'), 'content' => Html::tag('div', $formatter->asText($request['result']), $preformatted)];
    unset($request['result']);
}
$tabs[] = ['label' => \Yii::t('audit', 'Info'), 'content' => $this->render('info_table', ['request' => $request]), 'active' => true];
echo Html::tag('h2', \Yii::t('audit', 'Request #{id}', ['id' => $index])), Tabs::widget(['items' => array_reverse($tabs)]);
예제 #13
0
 /**
  * @param Event $event
  * @return null|static
  */
 public static function record($event)
 {
     /* @var $message MessageInterface */
     $message = $event->message;
     $entry = Audit::getInstance()->getEntry(true);
     $mail = new static();
     $mail->entry_id = $entry->id;
     $mail->successful = $event->isSuccessful;
     $mail->from = self::convertParams($message->getFrom());
     $mail->to = self::convertParams($message->getTo());
     $mail->reply = self::convertParams($message->getReplyTo());
     $mail->cc = self::convertParams($message->getCc());
     $mail->bcc = self::convertParams($message->getBcc());
     $mail->subject = $message->getSubject();
     // add more information when message is a SwiftMailer message
     if ($message instanceof Message) {
         /* @var $swiftMessage Swift_Message */
         $swiftMessage = $message->getSwiftMessage();
         foreach ($swiftMessage->getChildren() as $part) {
             /* @var $part Swift_Mime_MimePart */
             if ($part instanceof Swift_Mime_Attachment) {
                 continue;
             }
             $contentType = $part->getContentType();
             if ($contentType == 'text/plain') {
                 $mail->text = Helper::compress($part->getBody());
             } elseif ($contentType == 'text/html') {
                 $mail->html = Helper::compress($part->getBody());
             }
         }
     }
     $mail->data = Helper::compress($message->toString());
     return $mail->save(false) ? $mail : null;
 }
예제 #14
0
<?php

/** @var View $this */
/** @var AuditMail $model */
use bedezign\yii2\audit\components\Helper;
use bedezign\yii2\audit\models\AuditMail;
use yii\helpers\Html;
use yii\web\View;
use yii\widgets\DetailView;
$this->title = Yii::t('audit', 'Mail #{id}', ['id' => $model->id]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('audit', 'Audit'), 'url' => ['default/index']];
$this->params['breadcrumbs'][] = ['label' => Yii::t('audit', 'Mails'), 'url' => ['index']];
$this->params['breadcrumbs'][] = '#' . $model->id;
echo Html::tag('h1', $this->title);
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['attribute' => 'entry_id', 'value' => $model->entry_id ? Html::a($model->entry_id, ['entry/view', 'id' => $model->entry_id]) : '', 'format' => 'raw'], 'successful', 'to', 'from', 'reply', 'cc', 'bcc', 'subject', ['label' => Yii::t('audit', 'Download'), 'value' => Html::a(Yii::t('audit', 'Download eml file'), ['mail/download', 'id' => $model->id]), 'format' => 'raw'], 'created']]);
echo Html::tag('h2', Yii::t('audit', 'Text'));
echo '<div class="well">';
echo Yii::$app->formatter->asNtext(Helper::uncompress($model->text));
echo '</div>';
echo Html::tag('h2', Yii::t('audit', 'HTML'));
echo '<div class="well">';
echo Helper::uncompress($model->html);
echo '</div>';
//echo Html::tag('h2', Yii::t('audit', 'Data'));
//echo '<div class="well">';
//echo Yii::$app->formatter->asNtext(Helper::uncompress($model->data));
//echo '</div>';