Esempio n. 1
0
 public function log()
 {
     // auth
     Auth::isAdminAuthorized($this->signedUser, 'admin.tools.log', true, '/tools');
     $delete = Converter::bool('delete');
     $code = Converter::int('code');
     $id = Converter::int('id', 'get');
     $deleteUrl = $code != 0 ? '?code=' . $code . '&delete=true' : '?delete=true';
     if ($delete) {
         Auth::isAdminAuthorized($this->signedUser, 'admin.tools.log.edit', true, '/tools');
         \Rebond\Core\Log\Data::clear($code);
         Session::adminSuccess('logClear', '/tools/log');
     }
     if ($id != 0) {
         $log = \Rebond\Core\Log\Data::loadById($id);
         if (isset($log)) {
             // view
             $this->setTpl();
             $formLog = new \Rebond\Core\Log\Form($log);
             // main
             $tplMain = new Template(Template::MODULE, ['core', 'log']);
             $tplMain->set('item', $formLog);
             // layout
             $this->tplLayout->set('column1', $tplMain->render('view'));
             // master
             $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
             return $this->tplMaster->render('tpl-default');
         }
     }
     $options = [];
     $options['order'][] = 'log.modified_date DESC';
     if ($code != 0) {
         $options['where'][] = ['log.code = ?', $code];
     }
     $options['limit'][] = 200;
     $logs = \Rebond\Core\Log\Data::loadAll($options);
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Template(Template::MODULE, ['core', 'log']);
     $tplFilter->set('count', count($logs));
     $tplFilter->set('list', \Rebond\Util\Error::errorCodes());
     $tplFilter->set('code', $code);
     $tplFilter->set('deleteUrl', '/tools/log/' . $deleteUrl);
     // main
     $tplMain = new Template(Template::MODULE, ['core', 'log']);
     $tplMain->set('items', $logs);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('filter'));
     $this->tplLayout->set('column2', $tplMain->render('listing'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-2-row'));
     $this->tplMaster->set('jsLauncher', 'toolsLog');
     return $this->tplMaster->render('tpl-default');
 }
Esempio n. 2
0
 public static function log($code, $message, $file, $line)
 {
     $app = \Rebond\App::instance();
     $d = new \DateTime();
     $message = self::textify($message);
     if ($app->step() != \Rebond\Config::STEP_RUNNING) {
         $log = \Rebond\Config::getPath('log') . 'log.txt';
         $file = str_replace(FULL_PATH, '/', str_replace('\\', '/', $file));
         $trace = stripos($file, 'SplClassLoader') !== false ? self::textify(debug_backtrace()) : '';
         // date # code # message # trace # file # line
         $message = $d->format('Y-m-d H:i:s') . '#' . Error::value($code) . '#' . str_replace(FULL_PATH, '/', $message) . '#' . $trace . '#' . $file . '#' . $line . PHP_EOL;
         \Rebond\Util\File::save($log, 'a', $message);
     } else {
         if (!in_array($code, [Error::LANG_NOT_FOUND, Error::PAGE_NOT_FOUND]) && $app->env() == \Rebond\Config::ENV_PROD && $app->site()->getSendMailOnError()) {
             $emails = $app->site()->getMailListOnError();
             if ($emails != '') {
                 $emails = explode(',', $emails);
                 \Rebond\App\Error\Mail::error($app->site()->getTitle(), $emails, $code, $message, $file, $line);
             }
         }
         $log = null;
         if ($code == Error::LANG_NOT_FOUND) {
             $options = [];
             $options['where'][] = ['log.request_uri = ?', $_SERVER['REQUEST_URI']];
             $options['where'][] = ['log.message = ?', $message];
             $log = \Rebond\Core\Log\Data::load($options);
         }
         if (!isset($log)) {
             $log = new \Rebond\Core\Log\Model();
             $log->setCode($code);
             $log->setMessage($message);
             $log->setRequestUri($_SERVER['REQUEST_URI']);
         }
         $log->setUserId($app->userId());
         $log->setFile($file);
         $log->setLine($line);
         $log->setTrace(self::textify(debug_backtrace()));
         $log->setIp($_SERVER['REMOTE_ADDR']);
         $log->setReferer(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
         return $log->save();
     }
     return 0;
 }
Esempio n. 3
0
 public function detail()
 {
     if (!$this->app->isDebug()) {
         return self::generic();
     }
     $logId = Util\Converter::toInt('id');
     if ($logId == 0) {
         return self::generic();
     }
     $log = \Rebond\Core\Log\Data::loadById($logId);
     if (!isset($log)) {
         return self::generic();
     }
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
     // main
     $tpl = new Util\Template(Util\Template::MODULE, ['app', 'error']);
     $tpl->set('log', $log);
     $tpl->set('referer', $referer);
     $tpl->set('adminUrl', \Rebond\Config::getPath('adminUrl'));
     return $tpl->render('detail');
 }
Esempio n. 4
0
 public function detail()
 {
     $this->setBaseTpl();
     // auth
     Auth::isAdminAuthorized($this->signedUser, null, true, '/profile/sign-in');
     $logId = Converter::int('id');
     if ($logId == 0) {
         return $this->generic();
     }
     if ($this->app->logLevel() == 1) {
         return $this->generic();
     }
     $log = \Rebond\Core\Log\Data::loadById($logId);
     if (!isset($log)) {
         return $this->generic();
     }
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
     // main
     $this->tplMain->set('log', $log);
     $this->tplMain->set('referer', $referer);
     // layout
     $this->tplLayout->set('column1', $this->tplMain->render('detail'));
     // master
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-1-col'));
     return $this->tplMaster->render('tpl-error');
 }