Example #1
0
 /**
  * 
  * @param boolean $cacheConjuncts
  * @return void
  */
 public static function checkProcessRules($cacheConjuncts = true)
 {
     $logger = Logger::getLogger('FW');
     $session = Session::singleton();
     $logger->debug("Checking process rules for active roles: " . implode(', ', array_column($session->getActiveRoles(), 'label')));
     foreach ($session->rulesToMaintain as $rule) {
         $violations = $rule->getViolations($cacheConjuncts);
         foreach ($violations as $violation) {
             Notifications::addSignal($violation);
         }
     }
 }
 protected function write(array $record)
 {
     Notifications::addNotification($record['level'], $record['message']);
 }
Example #3
0
        }
    }
    foreach ((array) $allLinks as $rel => $links) {
        if (!empty($links)) {
            $relation = Relation::getRelation($rel);
        }
        foreach ($links as $link) {
            if (is_null($link['src']) || is_null($link['tgt'])) {
                continue;
            }
            // skip
            $relation->addLink(new Atom($link['src'], $relation->srcConcept), new Atom($link['tgt'], $relation->tgtConcept));
        }
    }
    $database->closeTransaction("Imported successfully", true);
    $content = Notifications::getAll();
    // Return all notifications
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->get('/admin/performance/conjuncts', function () use($app) {
    if (Config::get('productionEnv')) {
        throw new Exception("Performance tests are not allowed in production environment", 403);
    }
    // Defaults
    $groupBy = $app->request->params('groupBy');
    if (is_null($groupBy)) {
        $groupBy = 'conjuncts';
    }
    $from = $app->request->params('from');
    if (is_null($from)) {
        $from = 0;
Example #4
0
    $result = array('patches' => $app->request->getBody(), 'content' => $content, 'notifications' => Notifications::getAll(), 'invariantRulesHold' => $session->database->getInvariantRulesHold(), 'requestType' => $session->database->getRequestType(), 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->post('/resources/:resourceType/:resourceId/:ifcPath+', function ($resourceType, $resourceId, $ifcPath) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    $options = $app->request->params();
    $ifcPath = implode('/', $ifcPath);
    $atom = new Atom($resourceId, Concept::getConcept($resourceType));
    $atomOrIfc = $atom->walkIfcPath($ifcPath);
    // Perform create
    $content = $atomOrIfc->create($app->request->getBody(), $options);
    // Return result
    $result = array('content' => $content, 'notifications' => Notifications::getAll(), 'invariantRulesHold' => $session->database->getInvariantRulesHold(), 'requestType' => $session->database->getRequestType(), 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
$app->delete('/resources/:resourceType/:resourceId/:ifcPath+', function ($resourceType, $resourceId, $ifcPath) use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    $options = $app->request->params();
    $ifcPath = implode('/', $ifcPath);
    $atom = new Atom($resourceId, Concept::getConcept($resourceType));
    $atomOrIfc = $atom->walkIfcPath($ifcPath);
    // Perform delete
    $atomOrIfc->delete($options);
    // Return result
    $result = array('notifications' => Notifications::getAll(), 'invariantRulesHold' => $session->database->getInvariantRulesHold(), 'requestType' => $session->database->getRequestType(), 'sessionRefreshAdvice' => $session->getSessionRefreshAdvice());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
Example #5
0
    public static function addResponseCode($code, $message)
    {
        parent::$messages[$code] = "{$code} {$message}";
    }
}
NewResponse::addResponseCode(440, "Login Timeout");
// Create and configure Slim app (version 2.x)
$app = new \Slim\Slim(array('debug' => Config::get('debugMode')));
$app->add(new \Slim\Middleware\ContentTypes());
$app->response->headers->set('Content-Type', 'application/json');
// Error handler
$app->error(function (Exception $e) use($app) {
    $app->response->setStatus($e->getCode());
    try {
        Logger::getLogger("API")->error($e->getMessage());
        $notifications = Notifications::getAll();
        print json_encode(array('error' => $e->getCode(), 'msg' => $e->getMessage(), 'notifications' => $notifications));
    } catch (Exception $b) {
        Logger::getLogger("API")->error($b->getMessage());
        print json_encode(array('error' => $b->getCode(), 'msg' => $b->getMessage(), 'notifications' => array()));
    }
});
// Not found handler
$app->notFound(function () use($app) {
    $app->response->setStatus(404);
    print json_encode(array('error' => 404, 'msg' => "API call not found: {$app->request->getMethod()} {$app->request->getUrl()}{$app->request->getPath()}"));
});
include __DIR__ . '/resources.php';
// API calls starting with '/resources/'
include __DIR__ . '/admin.php';
// API calls starting with '/admin/'
Example #6
0
    }
    foreach ($identityProviders as $idpSettings) {
        $auth_url = array('auth_base' => $idpSettings['authBase'], 'arguments' => array('client_id' => $idpSettings['clientId'], 'response_type' => 'code', 'redirect_uri' => $idpSettings['redirectUrl'], 'scope' => $idpSettings['scope'], 'state' => $idpSettings['state']));
        $url = $auth_url['auth_base'] . '?' . http_build_query($auth_url['arguments']);
        $idps[] = array('name' => $idpSettings['name'], 'loginUrl' => $url, 'logo' => $idpSettings['logoUrl']);
    }
    // Return
    $result = array('identityProviders' => $idps, 'notifications' => Notifications::getAll());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
// Path to API is 'api/v1/oauthlogin/logout'
$app->get('/oauthlogin/logout', function () use($app) {
    $session = Session::singleton();
    $session->sessionAtom->deleteAtom();
    $session->database->closeTransaction('Logout successfull', true);
    $result = array('notifications' => Notifications::getAll());
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
// Path to API is 'api/v1/oauthlogin/callback/google'
$app->get('/oauthlogin/callback/google', function () use($app) {
    $code = $app->request->params('code');
    OAuthLoginController::callback($code, 'google');
});
// Path to API is 'api/v1/oauthlogin/callback/linkedin'
$app->get('/oauthlogin/callback/linkedin', function () use($app) {
    // TODO: add check $state variable, to prevent CSPF attack
    $code = $app->request->params('code');
    OAuthLoginController::callback($code, 'linkedin');
});
// Path to API is 'api/v1/oauthlogin/callback/github'
$app->get('/oauthlogin/callback/github', function () use($app) {
Example #7
0
global $app;
// Path to API is 'api/v1/excelimport/import'
$app->post('/excelimport/import', function () use($app) {
    $session = Session::singleton();
    $roleIds = $app->request->params('roleIds');
    $session->activateRoles($roleIds);
    // Check sessionRoles if allowedRolesForExcelImport is specified
    $allowedRoles = Config::get('allowedRolesForExcelImport', 'excelImport');
    if (!is_null($allowedRoles)) {
        $ok = false;
        foreach ($session->getSessionRoles() as $role) {
            if (in_array($role->label, $allowedRoles)) {
                $ok = true;
            }
        }
        if (!$ok) {
            throw new Exception("You do not have access to import excel files", 401);
        }
    }
    if (is_uploaded_file($_FILES['file']['tmp_name'])) {
        // Parse:
        $parser = new ExcelImport();
        $parser->ParseFile($_FILES['file']['tmp_name']);
        Database::singleton()->closeTransaction("File {$_FILES['file']['tmp_name']} imported successfully", true);
        unlink($_FILES['file']['tmp_name']);
    } else {
        Logger::getUserLogger()->error("No file uploaded");
    }
    $result = array('notifications' => Notifications::getAll(), 'files' => $_FILES);
    print json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});
Example #8
0
    $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());
    print json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
});