Esempio n. 1
0
global $app;
$app->get('/sessions/:sessionId/navbar', function ($sessionId) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    foreach (RuleEngine::getSignalViolationsFromDB() as $violation) {
        Notifications::addSignal($violation);
    }
    $content = array('top' => AngularApp::getNavBarIfcs('top'), 'new' => AngularApp::getNavBarIfcs('new'), 'refreshMenu' => AngularApp::getMenuItems('refresh'), 'extMenu' => AngularApp::getMenuItems('ext'), 'roleMenu' => AngularApp::getMenuItems('role'), 'defaultSettings' => array('notifications' => Notifications::getDefaultSettings(), 'switchAutoCommit' => Config::get('interfaceAutoCommitChanges', 'transactions'), 'cacheGetCalls' => Config::get('interfaceCacheGetCalls', 'transactions'), 'switchAutoSave' => Config::get('interfaceAutoSaveChanges', 'transactions')), 'notifications' => Notifications::getAll(), 'session' => array('id' => $session->id, 'loggedIn' => $session->sessionUserLoggedIn()), 'sessionRoles' => array_values($session->getSessionRoles()), 'sessionVars' => $session->getSessionVars());
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->get('/sessions/:sessionId/notifications', function ($sessionId) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    foreach (RuleEngine::getSignalViolationsFromDB() as $violation) {
        Notifications::addSignal($violation);
    }
    $content = Notifications::getAll();
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->delete('/sessions/:sessionId', function ($sessionId) use($app) {
    $session = Session::singleton();
    // Checks
    if ($sessionId != $session->id) {
        throw new Exception("You can only destroy your own session", 403);
    }
    // Destroy session
    $session->destroySession();
    // Return result
    $content = array('notifications' => Notifications::getAll());
Esempio n. 2
0
 public static function run($allRules = false)
 {
     $database = Database::singleton();
     $logger = Logger::getLogger('EXECENGINE');
     $logger->info("ExecEngine run started");
     // Load the execEngine functions (security hazard :P)
     $files = getDirectoryList(__DIR__ . '/functions');
     foreach ($files as $file) {
         if (substr($file, -3) !== 'php') {
             continue;
         }
         require_once $path = __DIR__ . '/functions/' . $file;
         $logger->debug("Included file: {$path}");
     }
     self::$roleName = Config::get('execEngineRoleName', 'execEngine');
     try {
         $role = Role::getRoleByName(self::$roleName);
     } catch (Exception $e) {
         $logger->warning("ExecEngine extension included but role '" . self::$roleName . "' not used/defined in &-script.");
         self::$doRun = false;
         // prevent exec engine execution
     }
     $maxRunCount = Config::get('maxRunCount', 'execEngine');
     self::$runCount = 0;
     self::$autoRerun = Config::get('autoRerun', 'execEngine');
     // Get all rules that are maintained by the ExecEngine
     $rulesThatHaveViolations = array();
     while (self::$doRun) {
         self::$doRun = false;
         self::$runCount++;
         // Prevent infinite loop in ExecEngine reruns
         if (self::$runCount > $maxRunCount) {
             Logger::getUserLogger()->error('Maximum reruns exceeded for ExecEngine (rules with violations:' . implode(', ', $rulesThatHaveViolations) . ')');
             break;
         }
         $logger->notice("ExecEngine run #" . self::$runCount . " (auto rerun: " . var_export(self::$autoRerun, true) . ") for role '{$role->label}'");
         // Determine affected rules that must be checked by the exec engine
         $affectedConjuncts = RuleEngine::getAffectedConjuncts($database->getAffectedConcepts(), $database->getAffectedRelations(), 'sig');
         $affectedRules = array();
         foreach ($affectedConjuncts as $conjunct) {
             $affectedRules = array_merge($affectedRules, $conjunct->sigRuleNames);
         }
         // Check rules
         $rulesThatHaveViolations = array();
         foreach ($role->maintains() as $ruleName) {
             if (!in_array($ruleName, $affectedRules) && !$allRules) {
                 continue;
             }
             // skip this rule
             $rule = Rule::getRule($ruleName);
             $violations = $rule->getViolations(false);
             if (count($violations)) {
                 $rulesThatHaveViolations[] = $rule->id;
                 // Fix violations for every rule
                 $logger->notice("ExecEngine fixing " . count($violations) . " violations for rule '{$rule->id}'");
                 self::fixViolations($violations);
                 // Conjunct violations are not cached, because they are fixed by the ExecEngine
                 $logger->debug("Fixed " . count($violations) . " violations for rule '{$rule->__toString()}'");
                 // If $autoRerun, set $doRun to true because violations have been fixed (this may fire other execEngine rules)
                 if (self::$autoRerun) {
                     self::$doRun = true;
                 }
             }
         }
     }
     $logger->info("ExecEngine run completed");
 }
Esempio n. 3
0
 /**
  * Function to request closing the open database transaction
  * @param string $succesMessage specifies success/info message when invariants hold
  * @param boolean $databaseCommit specifies to commit (true) or rollback (false) when all invariants hold
  * @param Atom $atomStoreNewContent specifies to store the new content for the updated/created atom
  * @return boolean specifies if invariant rules hold (true) or not (false)
  */
 public function closeTransaction($succesMessage = 'Updated', $databaseCommit = null, &$atomStoreNewContent = null)
 {
     Hooks::callHooks('preDatabaseCloseTransaction', get_defined_vars());
     $this->logger->info("Closing database transaction");
     $this->logger->info("Checking all affected conjuncts");
     // Check invariant rules (we only have to check the affected invariant rules)
     $affectedConjuncts = RuleEngine::getAffectedConjuncts($this->affectedConcepts, $this->affectedRelations, 'inv');
     // Get affected invariant conjuncts
     $invariantRulesHold = RuleEngine::checkInvariantRules($affectedConjuncts, true);
     // Check all process rules that are relevant for the activate roles
     RuleEngine::checkProcessRules();
     unset($this->affectedConcepts, $this->affectedRelations);
     $this->affectedConcepts = array();
     $this->affectedRelations = array();
     if (!is_null($atomStoreNewContent)) {
         $atomStoreNewContent->setStoredContent();
     }
     // Determine if transaction should be committed or not when all invariant rules hold based on $requestType
     if (is_null($databaseCommit)) {
         $databaseCommit = $this->processRequestType();
     }
     if ($invariantRulesHold && $databaseCommit) {
         $this->commitTransaction();
         // commit database transaction
         Logger::getUserLogger()->notice($succesMessage);
     } elseif (Config::get('ignoreInvariantViolations', 'transactions') && $databaseCommit) {
         $this->commitTransaction();
         Logger::getUserLogger()->warning("Transaction committed with invariant violations");
     } elseif ($invariantRulesHold) {
         $this->logger->info("Invariant rules hold, but no database commit requested");
         $this->rollbackTransaction();
         // rollback database transaction
     } else {
         $this->logger->info("Invariant rules do not hold");
         $this->rollbackTransaction();
         // rollback database transaction
     }
     Hooks::callHooks('postDatabaseCloseTransaction', get_defined_vars());
     return $this->invariantRulesHold = $invariantRulesHold;
 }