示例#1
0
文件: Record.php 项目: gudwin/extasy
 public static function add($logName, $short, $full = null)
 {
     $log = Log::createIfNotExists($logName);
     if (!$log->enable_logging->getValue()) {
         return null;
     }
     if (empty($full)) {
         $full = $short;
     }
     if ($short instanceof \Exception) {
         $short = $short->getMessage();
     }
     if ($full instanceof \Exception) {
         $full = (string) $full;
     }
     //
     $result = new Record();
     $result->setLog($log);
     self::fillUserInfo($result);
     $result->short->setValue($short);
     $result->full->setValue($full);
     //
     $result->insert();
     return $result;
 }
示例#2
0
 public function getCurrentSession()
 {
     $helper = new FacebookJavaScriptLoginHelper();
     try {
         if (!empty($_SESSION[self::SessionKey])) {
             $accessToken = $_SESSION[self::SessionKey];
             $_SESSION[self::SessionKey] = null;
             $session = new \Facebook\FacebookSession($accessToken);
         } else {
             $session = $helper->getSession();
             $accessToken = $session->getAccessToken();
             $_SESSION[self::SessionKey] = (string) $accessToken;
         }
     } catch (\Exception $ex) {
         Record::add(__CLASS__, $ex->getMessage(), $ex);
         throw $ex;
     }
     if ($session) {
         try {
             $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
             return ['id' => $user_profile->getId(), 'name' => $user_profile->getName()];
         } catch (FacebookRequestException $e) {
             $error = "Exception occured, code: " . $e->getCode() . " with message: " . $e->getMessage();
             Record::add(__CLASS__, $error, $e);
             throw $e;
         }
     }
 }
示例#3
0
 protected static function postLogRecord($category, $message, $fullMessage)
 {
     try {
         Record::add($category, $message, $fullMessage);
     } catch (\Exception $e) {
     }
 }
示例#4
0
文件: Runner.php 项目: gudwin/extasy
 public function resolveJobs()
 {
     if ($this->noNeedToRun()) {
         return;
     }
     $timeLimit = $this->getTimeLimit();
     $startTime = time();
     do {
         try {
             $job = $this->getLastJob();
             if (is_object($job)) {
                 $job->run();
             }
         } catch (\Exception $e) {
             Record::add(self::LogName, $e);
             if (!empty($job)) {
                 $job->status = Job::ErrorStatus;
                 $job->update();
             }
         }
         $timeToStop = !empty($timeLimit) ? time() >= $startTime + $timeLimit : true;
         if (!$timeToStop) {
             sleep(1);
         }
     } while (!$timeToStop);
     $this->deleteOldRows();
 }
示例#5
0
function importMessages($log, $category)
{
    $data = selectMessages($category);
    foreach ($data as $record) {
        Record::add($log->name, $record['message'], $record['message']);
    }
}
示例#6
0
 protected function action()
 {
     // event should exists
     Log::getByName($this->GetParam('event'));
     Record::add($this->GetParam('event'), $this->GetParam('short'), $this->GetParam('full'));
     return true;
 }
示例#7
0
文件: Records.php 项目: gudwin/extasy
 protected function action()
 {
     $request = $this->buildRequest();
     $data = Record::select($request);
     $pagingInfo = Record::getPagingInfo();
     $result = array('list' => array(), 'total' => $pagingInfo['total'], 'page' => $pagingInfo['page']);
     foreach ($data as $row) {
         $result['list'][] = $this->packForResponse($row);
     }
     return $result;
 }
示例#8
0
 protected function action()
 {
     try {
         Cleaner::pack();
     } catch (\Exception $e) {
         \Extasy\Audit\Record::add(__CLASS__, $e->getMessage(), $e);
     }
     $job = new CleanerJob();
     $job->actionDate->setTime('+1 hour');
     $job->insert();
 }
示例#9
0
 protected function checkACL()
 {
     if (!empty($this->requiredACLRights)) {
         try {
             ACLUser::checkCurrentUserGrants($this->requiredACLRights);
         } catch (Exception $e) {
             $errorMsg = sprintf('Failed to execute operation:%s. Current user - ', self::MethodName, UsersLogin::isLogined() ? sprintf('%s:%d', UsersLogin::getCurrentSession()->login->getValue(), UsersLogin::getCurrentSession()->id->getValue()) : '');
             Record::add('api', $errorMsg);
             throw $e;
         }
     }
 }
示例#10
0
文件: Request.php 项目: gudwin/extasy
 protected function validateParameter($name, $value)
 {
     if (is_array($value)) {
         foreach ($value as $key => $row) {
             $this->validateParameter(sprintf('%s[%s]', $name, $key), $row);
         }
     } else {
         foreach ($this->patterns as $regExp) {
             if (preg_match($regExp, $value)) {
                 $short = sprintf('`%s` matches injection pattern "%s" ', htmlspecialchars($name), htmlspecialchars($regExp));
                 $full = sprintf('<b>%s</b><br>Page URL: %s<br>Matching Pattern: %s<br>Request:<br>%s<br>', htmlspecialchars($name), htmlspecialchars(print_r($this->uri(), true)), htmlspecialchars(print_r($regExp, true)), htmlspecialchars(print_r($this->data, true)));
                 \Extasy\Audit\Record::add(self::LogName, $short, $full);
             }
         }
     }
 }
示例#11
0
文件: ACLUser.php 项目: gudwin/extasy
 public static function checkCurrentUserGrants($aclActionList)
 {
     if (empty($aclActionList)) {
         return;
     }
     if (!is_array($aclActionList)) {
         throw new ACLException('Property `aclActionList` should be array type ');
     }
     $grantList = self::getCurrentUserGrants();
     $result = self::testGrants($aclActionList, $grantList);
     if (!$result) {
         $msg = "User not have enough rights to access requested action - " . self::$rightFailed;
         $fullMsg = sprintf("%s\r\nRequested grants:%s\r\nCurrent user:\r\n%s\r\n%s", $msg, print_r($aclActionList, true), print_r(UsersLogin::getCurrentSession(), true), \Faid\Debug\defaultDebugBackTrace(false));
         \Extasy\Audit\Record::add(__CLASS__, $msg, $fullMsg);
         throw new ForbiddenException($msg);
     }
 }
示例#12
0
文件: Login.php 项目: gudwin/extasy
 public function login($login, $password, $captchaCode = '', $remember = false)
 {
     // fix for cases with captcha
     if (!empty($_REQUEST['remember'])) {
         $remember = $_REQUEST['remember'] == 'true';
     }
     // проверяем код капчи
     /**
      * @todo Избавиться от этой зависимости
      */
     require_once APPLICATION_PATH . 'kcaptcha/helper.php';
     if (!kcaptchaHelper::check($captchaCode)) {
         $this->errorCode = self::kcaptchaFailed;
         return $this->main();
     }
     try {
         UsersLogin::login($login, $password, $remember);
         EventController::callEvent('users_registration_after_login', UsersLogin::getCurrentSession());
         $this->aParse['loginSuccess'] = true;
     } catch (\Extasy\Users\login\UserNotConfirmedException $e) {
         $this->jump('/signup/?code=');
     } catch (Exception $e) {
         \Extasy\Audit\Record::add(UsersLogin::LogName, $e->getMessage(), $e);
         $this->exception = $e;
         // Поддержка ajax-а
         if (empty($_REQUEST['ajaxRequest'])) {
             $this->main();
         }
     }
     // Если передавался параметр страниц
     if (!empty($this->pageId)) {
         $sitemap = Sitemap_Sample::get($this->pageId);
         if (!empty($sitemap)) {
             $this->jump($sitemap['full_url']);
         }
     } elseif (!empty($_POST['backUrl'])) {
         $backUrl = preg_replace("#\n.*#", "", $_POST['backUrl']);
         $this->jump($backUrl);
     }
     // Поддержка аякса
     if (!empty($_REQUEST['ajaxRequest'])) {
         $this->output('/users/login/form');
     }
     $this->jump('/');
 }
示例#13
0
文件: Login.php 项目: gudwin/extasy
 protected function action()
 {
     try {
         UsersLogin::testLoginAttempts();
     } catch (\Exception $e) {
         Record::add(__CLASS__, $e->getMessage(), $e);
         throw $e;
     }
     //
     $this->api = \Extasy\Users\Social\OdnoklassnikiApiFactory::getInstance();
     $userOdnoklassnikiProfile = $this->api->getCurrentSession();
     $uid = $userOdnoklassnikiProfile['id'];
     $user = \Extasy\Users\Columns\SocialNetworks::getByUID($uid, 'odnoklassniki');
     UsersLogin::testConfirmationCode($user);
     UsersLogin::forceLogin($user);
     $log = sprintf('Odnoklassniki login successfully finished. User ("%s", "%d") logged with uid ("%s" )', $user->login->getValue(), $user->id->getValue(), $userOdnoklassnikiProfile['id']);
     Record::add(__CLASS__, $log);
 }
示例#14
0
 public static function addMessage($category, $szMessage)
 {
     Record::add($category, $szMessage, $szMessage);
 }
示例#15
0
文件: login.php 项目: gudwin/extasy
 /**
  *
  */
 public static function logout()
 {
     if (self::isLogined()) {
         EventController::callEvent('users_after_logout');
         try {
             $user = self::getCurrentUser();
             CMSLog::addMessage(__CLASS__, sprintf('User `%s` logged out', $user->login->getValue()));
         } catch (\Exception $e) {
             $short = 'Failed to logout user. Probably, there is an issue inside User Sesison';
             $full = sprintf("%s\r\n%s", $short, $e);
             Record::add(__CLASS__, $short, $full);
         }
     }
     self::unsetSession();
     self::$currentUser = null;
 }
示例#16
0
 public function testSearchByText()
 {
     $request = new SearchRequest();
     $request->search_phrase = 'short';
     $result = Record::select($request);
     $this->assertEquals(3, sizeof($result));
     $request = new SearchRequest();
     $request->search_phrase = 'unknown';
     $result = Record::select($request);
     $this->assertEquals(0, sizeof($result));
 }
示例#17
0
}
Restorator::restore();
\SystemRegisterSample::createCache();
TestsHelper::dbFixture(ACL_TABLE, array());
ACL::create(ApiOperation::RightName);
// user record
TestsHelper::dbFixture(USERS_TABLE, array(array('login' => 'login', 'password' => passwordColumn::hash('testtest')), array('login' => 'guest', 'password' => passwordColumn::hash('testtest'))));
// grant user permission
$user = UserAccount::getByLogin('login');
ACL::grant(ApiOperation::RightName, $user->obj_rights->getEntity());
\UsersLogin::login('login', 'testtest');
// base logs
TestsHelper::dbFixture(Log::getTableName(), array(array('name' => 'Log1', 'critical' => 0, 'enable_logging' => 1), array('name' => 'Log2', 'critical' => 1, 'enable_logging' => 1)));
// base records
// - [different by user_id]
// - [different by date]
// - [different by content]
TestsHelper::dbFixture(Record::getTableName(), array(array('log_id' => 1, 'date' => '2001-01-01 00:00:00', 'short' => 'short log', 'full' => 'full_log', 'user_id' => 1, 'user_login' => 'login'), array('log_id' => 2, 'date' => '2001-01-02 00:00:00', 'short' => 'short log', 'full' => 'full_log', 'user_id' => 1, 'user_login' => 'login'), array('log_id' => 1, 'date' => '2001-01-03 00:00:00', 'short' => 'short log', 'full' => 'full_log')));
// Create custom config if it exists
$schemaName = 'Audit.CriticalEventName';
try {
    $config = \CConfig::getSchema($schemaName);
    $config->delete();
} catch (\Exception $e) {
} finally {
    $config = \CConfig::createSchema($schemaName);
    $config->addControl('to', 'inputfield', 'Получатели письма', array(), '*****@*****.**');
    $config->addControl('subject', 'inputfield', 'Тема письма', array(), 'Email Subject');
    $config->addControl('content', 'htmlfield', 'Шаблон письма', array(), 'Message body');
    $config->updateSchema($schemaName, 'Шаблон письма-оповещения о наступлении критического события аудита');
}
示例#18
0
 protected function action()
 {
     return Record::getNewCount();
 }
示例#19
0
 public function testEmailSentOnCriticalLogMessage()
 {
     Record::add('Log2', '', '');
     $this->assertTrue($this->mailer->isSent());
 }