/** * Re-inflates and unserializes a blob of compressed data * @param string $data * @return mixed false if an error occurred */ public static function unserialize($data) { if (Audit::current()->compressData) { $data = gzuncompress($data); } return unserialize($data); }
public function publish($assetManager) { $module = \bedezign\yii2\audit\Audit::current(); if ($module && $module->entry) { // We can't be sure that the actual logger was loaded already, so we fallback on the window object // to store the associated audit entry id \Yii::$app->view->registerJs("window.auditEntry = {$module->entry->id};", \yii\web\View::POS_HEAD); } return parent::publish($assetManager); }
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); } } } } }
public function record() { $dataMap = ['_GET' => $_GET, '_POST' => $_POST, '_COOKIE' => $_COOKIE, '_SERVER' => $_SERVER, '_FILES' => $_FILES]; if (Yii::$app->request instanceof \yii\web\Request) { if (!empty($_SESSION)) { $dataMap['_SESSION'] = $_SESSION; } } else { if (Yii::$app->request instanceof \yii\console\Request) { $dataMap['_PARAMS'] = Yii::$app->request->params; } } $entry = Audit::current()->getEntry(); if ($entry) { $batchData = []; foreach ($this->logVars as $type) { $data = ArrayHelper::getValue($dataMap, $type); if ($data) { $batchData[$type] = $data; } } $entry->addBatchData($batchData); } }
<?php use bedezign\yii2\audit\Audit; use yii\helpers\Html; use Yii; /** @var yii\web\View $this */ /** @var bedezign\yii2\audit\models\AuditEntry $entry */ if ($auditEntry = Audit::current()->getEntry()) { $style = YII_DEBUG ? '' : 'color:transparent;'; if (Yii::$app->audit->checkAccess()) { echo Html::a('audit-' . $auditEntry->id, ['/audit/default/view', 'id' => $auditEntry->id], ['style' => $style]); } else { echo Html::tag('span', 'audit-' . $auditEntry->id, ['style' => $style]); } }
<?php use bedezign\yii2\audit\Audit; use yii\helpers\Html; use yii\grid\GridView; use yii\web\View; use bedezign\yii2\audit\models\AuditTrailSearch; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('audit', 'Trails'); $this->params['breadcrumbs'][] = ['label' => Yii::t('audit', 'Audit'), 'url' => ['default/index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="audit-trail"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}'], 'id', ['attribute' => 'entry_id', 'class' => 'yii\\grid\\DataColumn', 'value' => function ($data) { return $data->entry_id ? Html::a($data->entry_id, ['default/view', 'id' => $data->entry_id]) : ''; }, 'format' => 'raw'], ['attribute' => 'user_id', 'label' => Yii::t('audit', 'User ID'), 'class' => 'yii\\grid\\DataColumn', 'value' => function ($data) { return Audit::current()->getUsername($data->user_id); }], ['attribute' => 'action', 'filter' => AuditTrailSearch::actionFilter()], 'model', 'model_id', 'field', ['label' => Yii::t('audit', 'Diff'), 'value' => function ($model) { return $model->getDiffHtml(); }, 'format' => 'raw'], 'stamp']]); ?> </div>
<?php /** @var yii\web\View $this */ /** @var bedezign\yii2\audit\models\AuditTrail $model */ use bedezign\yii2\audit\Audit; use yii\helpers\Html; use yii\widgets\DetailView; $this->title = Yii::t('audit', 'Trail #{id}', ['id' => $model->id]); $this->params['breadcrumbs'][] = ['label' => Yii::t('audit', 'Audit'), 'url' => ['default/index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('audit', 'Trails'), 'url' => ['trail/index']]; $this->params['breadcrumbs'][] = '#' . $model->id; echo Html::tag('h1', $this->title); echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['label' => $model->getAttributeLabel('user_id'), 'value' => Audit::current()->getUsername($model->user_id)], 'action', 'model', 'model_id', 'field', 'stamp']]); echo Html::tag('h2', Yii::t('audit', 'Difference')); echo $model->getDiffHtml();
public static function getDb() { return Audit::current() ? Audit::current()->getDb() : parent::getDb(); }
use bedezign\yii2\audit\models\AuditTrail; $this->title = Yii::t('audit', 'Entry #{id}', ['id' => $model->id]); $this->params['breadcrumbs'][] = ['label' => Yii::t('audit', 'Audit'), 'url' => ['default/index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('audit', 'Entries'), 'url' => ['index']]; $this->params['breadcrumbs'][] = '#' . $model->id; ?> <?php echo Html::tag('h1', $this->title); ?> <div class="row"> <div class="col-md-10"> <?php echo Html::tag('h2', Yii::t('audit', 'Request'), ['id' => 'entry', 'class' => 'hashtag']); echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['label' => $model->getAttributeLabel('user_id'), 'value' => Audit::current()->getUsername($model->user_id)], 'ip', 'created', ['attribute' => 'start_time', 'format' => 'datetime'], ['attribute' => 'end_time', 'format' => 'datetime'], ['attribute' => 'duration', 'format' => 'decimal'], 'referrer', 'redirect', 'url', 'route', ['attribute' => 'memory', 'format' => 'shortsize'], ['attribute' => 'memory_max', 'format' => 'shortsize']]]); foreach ($model->extraData as $data) { $attributes = []; foreach ($data->data as $name => $value) { $attributes[] = ['label' => $name, 'value' => Helper::formatValue($value), 'format' => 'raw']; } echo Html::tag('h2', $data->type . ' (' . count($attributes) . ')', ['id' => $data->type, 'class' => 'hashtag']); echo DetailView::widget(['model' => $data, 'attributes' => $attributes, 'template' => '<tr><th>{label}</th><td style="word-break:break-word;">{value}</td></tr>']); } if (count($model->trail)) { $dataProvider = new ActiveDataProvider(['query' => AuditTrail::find()->where(['entry_id' => $model->id]), 'pagination' => ['pageSize' => 1000]]); echo Html::tag('h2', Yii::t('audit', 'Trail ({i})', ['i' => count($model->trail)]), ['id' => 'trail', 'class' => 'hashtag']); echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', 'action', 'model', 'model_id', 'field', ['label' => Yii::t('audit', 'Diff'), 'value' => function ($model) { /** @var AuditTrail $model */ return $model->getDiffHtml(); }, 'format' => 'raw'], 'stamp', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}', 'buttons' => ['view' => function ($url, $model, $key) {