public function processRequest(MMapRequest $request, MMapResponse $response) { $oauth_verifier = null; $oauth_token = null; if ($request->issetGET('oauth_verifier')) { $oauth_verifier = $request->getGET('oauth_verifier'); } if ($request->issetGET('oauth_token')) { $oauth_token = $request->getGET('oauth_token'); } if ($oauth_verifier && $oauth_token) { $response->getHeaders()->append('Content-type: text/html'); $body = '<html> <div id="logo_eyeos" style="margin: 0 auto;width:350"> <img src="eyeos/extern/images/logo-eyeos.jpg"/></div> <div style="margin: 0 auto;width:350;text-align:center"><span style="font-family:Verdana;font-size:20px;">Successful authentication.<br>Back to Eyeos.</span></div> </html>'; $response->getHeaders()->append('Content-Length: ' . strlen($body)); $response->getHeaders()->append('Accept-Ranges: bytes'); $response->getHeaders()->append('X-Pad: avoid browser bug'); $response->getHeaders()->append('Cache-Control: '); $response->getHeaders()->append('pragma: '); $response->setBody($body); try { $userRoot = UMManager::getInstance()->getUserByName('root'); } catch (EyeNoSuchUserException $e) { throw new EyeFailedLoginException('Unknown user root"' . '". Cannot proceed to login.', 0, $e); } $subject = new Subject(); $loginContext = new LoginContext('eyeos-login', $subject); $cred = new EyeosPasswordCredential(); $cred->setUsername('root'); $cred->setPassword($userRoot->getPassword(), false); $subject->getPrivateCredentials()->append($cred); $loginContext->login(); Kernel::enterSystemMode(); $appProcess = new Process('stacksync'); $appProcess->setPid('31338'); $mem = MemoryManager::getInstance(); $processTable = $mem->get('processTable', array()); $processTable[31338] = $appProcess; $mem->set('processTable', $processTable); $appProcess->setLoginContext($loginContext); ProcManager::getInstance()->setCurrentProcess($appProcess); kernel::exitSystemMode(); $token = new stdClass(); $token->oauth_verifier = $oauth_verifier; $token->oauth_token = $oauth_token; $group = UMManager::getInstance()->getGroupByName('users'); $users = UMManager::getInstance()->getAllUsersFromGroup($group); foreach ($users as $user) { $NetSyncMessage = new NetSyncMessage('cloud', 'token', $user->getId(), $token); NetSyncController::getInstance()->send($NetSyncMessage); } } }
public function processRequest(MMapRequest $request, MMapResponse $response) { ob_start('mb_output_handler'); $return = null; $dataManager = DataManager::getInstance(); $POST = $request->getPOST(); $params = array(); if (isset($POST['params'])) { $params = $dataManager->doInput($POST['params']); } else { if ($request->issetGET('params')) { $params = $request->getGET('params'); } } //login in the system and get a valid login context $subject = new Subject(); $loginContext = new LoginContext('eyeos-login', $subject); $cred = new EyeosPasswordCredential(); $cred->setUsername($_REQUEST['username']); $cred->setPassword($_REQUEST['password'], true); $subject->getPrivateCredentials()->append($cred); $loginContext->login(); //now create fake process called api Kernel::enterSystemMode(); $appProcess = new Process('api'); $appProcess->setPid('31337'); $mem = MemoryManager::getInstance(); $processTable = $mem->get('processTable', array()); $processTable[31337] = $appProcess; $mem->set('processTable', $processTable); $appProcess->setLoginContext($loginContext); ProcManager::getInstance()->setCurrentProcess($appProcess); kernel::exitSystemMode(); $return = call_user_func_array(array('EyeosApplicationExecutable', '__callModule'), array($request->getPOST('module'), $request->getPOST('name'), $params)); //try to force mime type. If there is a previous mime type defined at application level //this have no effect if (!headers_sent()) { $response->getHeaders()->append('Content-type:text/plain'); } if ($response->getBodyRenderer() === null && $response->getBody() == '') { $response->setBodyRenderer(new DataManagerBodyRenderer($return)); } }