Inheritance: extends yii\db\ActiveRecord
Esempio n. 1
0
 public function init()
 {
     if (\Yii::$app->user->isGuest) {
         $this->redirect('index.php?r=main/logout');
     }
     //echo Yii::app()->controller->action->id;
     $req = \Yii::$app->request;
     $audit = new Audit();
     $audit->method = $req->method;
     $audit->module = $this->route;
     $audit->action = \Yii::$app->controller->action->id;
     $audit->event_dt = date('Y-m-d H:i:s');
     $audit->user = !empty(\Yii::$app->user->name) ? \Yii::$app->user->name : 'Anonymous';
     $audit->ip_addr = $req->userIP;
     $audit->url = $req->scriptUrl;
     $audit->ref_url = $req->referrer;
     $data = '';
     if (count($_POST) > 0) {
         $data = json_encode($_POST);
     }
     if (count($_GET) > 1) {
         $arr = array();
         foreach ($_GET as $k => $v) {
             if ($k !== 'r') {
                 $arr[$k] = $v;
             }
         }
         $data .= json_encode($arr);
     }
     $audit->data = $data;
     $audit->save();
 }
Esempio n. 2
0
 public function actionList()
 {
     $where = '1';
     //comment here
     if (isset($_POST['tarikh'])) {
         $tarikh = $_POST['tarikh'];
         $module = $_POST['module'];
         if (!empty($module)) {
             $where .= " AND module = '{$module}'";
         }
         if (!empty($tarikh)) {
             $where .= " AND event_dt LIKE '" . MyDate::dateFormat('dmy', 'ymd', $tarikh, '-') . "%'";
         }
     } else {
         $module = '0';
         $event_dt = '';
     }
     $count = Audit::find()->where($where)->count();
     $pages = new Pagination(['totalCount' => $count]);
     $pages->pageSize = 10;
     $data['pages'] = $pages;
     $data['module'] = $module;
     $data['event_dt'] = $event_dt;
     $audits = Audit::find()->where($where)->offset($pages->offset)->limit($pages->limit)->all();
     $data['audits'] = $audits;
     $data['mod'] = Ref::getList('mod');
     return $this->render('list', $data);
 }
 /**
  *
  **/
 public static function log($user_id, $category, $message, array $attributes = null, $data_parser = null, $replay_route = null)
 {
     $audit_enabled = config('audit.enabled');
     $audit = false;
     $attJson = null;
     if ($audit_enabled) {
         // Remove from array attributes that we do not want to save.
         unset($attributes['_method']);
         unset($attributes['_token']);
         unset($attributes['password']);
         unset($attributes['password_confirmation']);
         if ($attributes) {
             $attJson = json_encode($attributes);
         }
         $audit = Audit::create(["user_id" => $user_id, "category" => $category, "message" => $message, "data" => $attJson, "data_parser" => $data_parser, "replay_route" => $replay_route]);
     }
     return $audit;
 }
 public static function ParseUpdateAuditLog($id)
 {
     $permsObj = [];
     $permsNoFound = [];
     $rolesObj = [];
     $rolesNotFound = [];
     $audit = \App\Models\Audit::find($id);
     $dataAtt = json_decode($audit->data, true);
     // Lookup and load the perms that we can still find, otherwise add to an separate array.
     if ($dataAtt['perms']) {
         foreach ($dataAtt['perms'] as $id) {
             $perm = \App\Models\Permission::find($id);
             if ($perm) {
                 $permsObj[] = $perm;
             } else {
                 $permsNoFound[] = trans('admin/users/general.error.perm_not_found', ['id' => $id]);
             }
         }
     }
     $dataAtt['permsObj'] = $permsObj;
     $dataAtt['permsNotFound'] = $permsNoFound;
     // Lookup and load the roles that we can still find, otherwise add to an separate array.
     if ($dataAtt['selected_roles']) {
         $aRolesIDs = explode(",", $dataAtt['selected_roles']);
         foreach ($aRolesIDs as $id) {
             $role = \App\Models\Role::find($id);
             if ($role) {
                 $rolesObj[] = $role;
             } else {
                 $rolesNotFound[] = trans('admin/users/general.error.perm_not_found', ['id' => $id]);
             }
         }
     }
     $dataAtt['rolesObj'] = $rolesObj;
     $dataAtt['rolesNotFound'] = $rolesNotFound;
     // Add the file name of the partial (blade) that will render this data.
     $dataAtt['show_partial'] = 'admin/users/_audit_log_data_viewer_update';
     return $dataAtt;
 }