コード例 #1
0
 /**
  * Executed once before each test method.
  */
 public function setUp()
 {
     if (self::$InitProcessToRestore === null) {
         self::$InitProcessToRestore = ProcManager::getInstance()->getCurrentProcess();
     }
     $this->fixture_file1_path = USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeFile.ext';
     $this->fixture_metafile1_path = USERS_PATH . '/john/' . USERS_METAFILES_DIR . '/' . USERS_FILES_DIR . '/myHomeFile.ext.xml';
     $this->fixture_file2_path = EYEOS_TESTS_TMP_PATH . '/mySysFile.ext';
     $this->fixture_dir1_path = USERS_PATH . '/john/' . USERS_FILES_DIR . '/myHomeDir';
     $this->fixture_dir2_path = EYEOS_TESTS_TMP_PATH . '/mySysDir';
     $this->group = UMManager::getGroupByName(SERVICE_UM_DEFAULTUSERSGROUP);
     if (!self::$AliceCreated) {
         try {
             //create group "wonderland"
             $wonderland = UMManager::getInstance()->getNewGroupInstance();
             $wonderland->setName('wonderland');
             UMManager::getInstance()->createGroup($wonderland);
         } catch (EyeGroupAlreadyExistsException $e) {
         }
         try {
             //create user "alice"
             $alice = UMManager::getInstance()->getNewUserInstance();
             $alice->setName('alice');
             $alice->setPassword('alice', true);
             $alice->setPrimaryGroupId($wonderland->getId());
             UMManager::getInstance()->createUser($alice);
         } catch (EyeUserAlreadyExistsException $e) {
         }
         self::$AliceCreated = true;
     }
     AdvancedPathLib::rmdirs(USERS_PATH . '/john/' . USERS_FILES_DIR, true);
     AdvancedPathLib::rmdirs(USERS_PATH . '/john/' . USERS_METAFILES_DIR, true);
     if (!is_dir(EYEOS_TESTS_TMP_PATH)) {
         mkdir(EYEOS_TESTS_TMP_PATH, 0777, true);
     }
     AdvancedPathLib::rmdirs(EYEOS_TESTS_TMP_PATH, true);
     $this->fixture_file1 = FSI::getFile('home://~john/myHomeFile.ext');
     file_put_contents($this->fixture_file1_path, 'some content');
     $this->fixture_file2 = FSI::getFile('sys:///tests/tmp/mySysFile.ext');
     file_put_contents($this->fixture_file2_path, 'some other content');
     $this->fixture_dir1 = FSI::getFile('home://~john/myHomeDir');
     if (!is_dir($this->fixture_dir1_path)) {
         mkdir($this->fixture_dir1_path);
     }
     $this->fixture_dir2 = FSI::getFile('sys:///tests/tmp/mySysDir');
     if (!is_dir($this->fixture_dir2_path)) {
         mkdir($this->fixture_dir2_path);
     }
     $proc = new Process('example');
     $loginContext = new LoginContext('example', new Subject());
     $loginContext->getSubject()->getPrivateCredentials()->append(new EyeosPasswordCredential('john', 'john'));
     $loginContext->login();
     $proc->setLoginContext($loginContext);
     ProcManager::getInstance()->execute($proc);
     self::$MyProcPid = $proc->getPid();
 }
コード例 #2
0
 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);
         }
     }
 }
コード例 #3
0
ファイル: ProcessTest.php プロジェクト: DavidGarciaCat/eyeos
 public function setUp()
 {
     if (self::$InitProcessToRestore === null) {
         self::$InitProcessToRestore = ProcManager::getInstance()->getCurrentProcess();
     }
     $this->config = new XMLAuthConfiguration(SYSTEM_CONF_PATH . '/' . SERVICES_DIR . '/' . SERVICE_UM_DIR . '/' . SERVICE_UM_AUTHCONFIGURATIONS_DIR . '/eyeos_default.xml');
     $this->loginContext = new LoginContext('eyeos-login', new Subject(), $this->config);
     $this->loginContext->getSubject()->getPrivateCredentials()->append(new EyeosPasswordCredential('john', 'john'));
     $this->loginContext->login();
     $proc = new Process('init');
     $proc->setLoginContext($this->loginContext);
     ProcManager::getInstance()->execute($proc);
     self::$MyProcPid = $proc->getPid();
 }
コード例 #4
0
ファイル: MMapAPI.php プロジェクト: DavidGarciaCat/eyeos
 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));
     }
 }
コード例 #5
0
 public function setUp()
 {
     if (self::$InitProcessToRestore === null) {
         self::$InitProcessToRestore = ProcManager::getInstance()->getCurrentProcess();
     }
     try {
         UMManager::getInstance()->deletePrincipal(UMManager::getInstance()->getUserByName('fakeUser'));
     } catch (EyeNoSuchUserException $e) {
     }
     try {
         UMManager::getInstance()->deletePrincipal(UMManager::getInstance()->getGroupByName('fakeGroup'));
     } catch (EyeNoSuchGroupException $e) {
     }
     $this->group = UMManager::getInstance()->getNewGroupInstance();
     $this->group->setName('fakeGroup');
     UMManager::getInstance()->createGroup($this->group);
     $this->idGroup = $this->group->getId();
     $this->user = UMManager::getInstance()->getNewUserInstance();
     $this->user->setName('fakeUser');
     $this->user->setPassword('fakePassword', true);
     $this->user->setPrimaryGroupId($this->group->getId());
     UMManager::getInstance()->createUser($this->user);
     $this->idUser = $this->user->getId();
     $proc = new Process('example');
     $loginContext = new LoginContext('example', new Subject());
     $loginContext->getSubject()->getPrivateCredentials()->append(new EyeosPasswordCredential('fakeUser', 'fakePassword'));
     $loginContext->login();
     $proc->setLoginContext($loginContext);
     ProcManager::getInstance()->execute($proc);
     self::$MyProcPid = $proc->getPid();
     $this->fixture_file_path = USERS_PATH . '/fakeUser/' . USERS_FILES_DIR . '/testFile.txt';
     $this->fixture_newFile_path = USERS_PATH . '/fakeUser/' . USERS_FILES_DIR . '/testDir/testFile2.txt';
     $this->fixture_file = FSI::getFile('home://~fakeUser/testFile.txt');
     $this->fixture_dir_path = USERS_PATH . '/fakeUser/' . USERS_FILES_DIR . '/testDir';
     $this->fixture_dir = FSI::getFile('home://~fakeUser/testDir');
 }
コード例 #6
0
 public function setUp()
 {
     if (self::$InitProcessToRestore === null) {
         self::$InitProcessToRestore = ProcManager::getInstance()->getCurrentProcess();
     }
     if (!self::$ClassSetUpRun) {
         $this->tearDown();
         $this->owner = UMManager::getInstance()->getUserByName('john');
         $this->group = UMManager::getGroupByName(SERVICE_UM_DEFAULTUSERSGROUP);
         //create group "wonderland"
         $this->secGroup = UMManager::getInstance()->getNewGroupInstance();
         $this->secGroup->setName('wonderland');
         UMManager::getInstance()->createGroup($this->secGroup);
         //create user "alice"
         $this->collaborator1 = UMManager::getInstance()->getNewUserInstance();
         $this->collaborator1->setName('alice');
         $this->collaborator1->setPassword('alice', true);
         $this->collaborator1->setPrimaryGroupId($this->secGroup->getId());
         UMManager::getInstance()->createUser($this->collaborator1);
         //create user "bob"
         $this->collaborator2 = UMManager::getInstance()->getNewUserInstance();
         $this->collaborator2->setName('bob');
         $this->collaborator2->setPassword('bob', true);
         $this->collaborator2->setPrimaryGroupId($this->secGroup->getId());
         UMManager::getInstance()->createUser($this->collaborator2);
         //create user "charlie"
         $this->collaborator3 = UMManager::getInstance()->getNewUserInstance();
         $this->collaborator3->setName('charlie');
         $this->collaborator3->setPassword('charlie', true);
         $this->collaborator3->setPrimaryGroupId($this->secGroup->getId());
         UMManager::getInstance()->createUser($this->collaborator3);
         $proc = new Process('example');
         $loginContext = new LoginContext('example', new Subject());
         $proc->setLoginContext($loginContext);
         ProcManager::getInstance()->execute($proc);
         self::$MyProcPid = $proc->getPid();
         $this->loginAsJohn();
         self::$ClassSetUpRun = true;
     } else {
         $this->owner = UMManager::getInstance()->getUserByName('john');
         $this->collaborator1 = UMManager::getInstance()->getUserByName('alice');
         $this->collaborator2 = UMManager::getInstance()->getUserByName('bob');
         $this->collaborator3 = UMManager::getInstance()->getUserByName('charlie');
     }
     AdvancedPathLib::rmdirs(USERS_PATH . '/john/' . USERS_FILES_DIR, true);
     AdvancedPathLib::rmdirs(USERS_PATH . '/john/' . USERS_METAFILES_DIR, true);
     $this->fixture = FSI::getFile('home://~john/myFile.ext');
     $this->loginAsRoot();
     try {
         $this->fixture->delete();
     } catch (Exception $e) {
     }
     $this->loginAsJohn();
     $this->fixture->createNewFile(true);
     $conf = SharingManager::getConfiguration('SharingManager');
     $providerClassName = (string) $conf->providerClassName[0];
     if ($providerClassName == 'DefaultSQLiteShareInfoProvider') {
         if (is_file(USERS_PATH . '/' . $this->owner->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db')) {
             unlink(USERS_PATH . '/' . $this->owner->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db');
         }
         if (is_file(USERS_PATH . '/' . $this->collaborator1->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db')) {
             unlink(USERS_PATH . '/' . $this->collaborator1->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db');
         }
         if (is_file(USERS_PATH . '/' . $this->collaborator2->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db')) {
             unlink(USERS_PATH . '/' . $this->collaborator2->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db');
         }
         if (is_file(USERS_PATH . '/' . $this->collaborator3->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db')) {
             unlink(USERS_PATH . '/' . $this->collaborator3->getName() . '/' . USERS_CONF_DIR . '/' . USERS_SHARE_DIR . '/shares.db');
         }
     } else {
         if ($providerClassName == 'DefaultMySQLShareInfoProvider') {
             try {
                 require_once SERVICE_SHARING_SHARINGMANAGERS_PROVIDERS_PATH . '/DefaultMySQLShareInfoProvider.php';
                 $dao = StorageManager::getInstance()->getHandler(SQL_DAOHANDLER);
                 $dao->send('TRUNCATE TABLE ' . DefaultMySQLShareInfoProvider::SHAREINFO_TABLE_NAME);
                 $dao->send('TRUNCATE TABLE ShareableVirtualFilesHandler');
             } catch (PDOException $e) {
             }
         }
     }
 }
コード例 #7
0
ファイル: ProcManager.php プロジェクト: DavidGarciaCat/eyeos
 /**
  * Execute a new process, and add it to the process table.
  * This function do not return any value, it fills the object Process received in the arguments
  * with the information of the new process.
  * 
  * @param Process $proc The process to be executed, the attribute <b>name</b> should be filled with the application name to execute
  * @throws EyeInvalidArgumentException If the arguments are incorrect
  */
 public function execute(Process $proc)
 {
     try {
         $processTable = $this->getProcessesTable();
         do {
             $pid = mt_rand(ProcManager::MINPIDNUMBER, ProcManager::MAXPIDNUMBER);
         } while (array_key_exists($pid, $processTable));
         $proc->setPid($pid);
         $proc->setTime(time());
         $proc->setChecknum(mt_rand(ProcManager::MINCHECKNUMNUMBER, ProcManager::MAXCHECKNUMNUMBER));
         //Check if we are in a context
         //if given process has no login context, default is to copy the current process' one
         if ($proc->getLoginContext() === null) {
             if ($this->currentProcess !== null) {
                 $currentLoginContext = $this->currentProcess->getLoginContext();
                 if ($currentLoginContext !== null) {
                     $proc->setLoginContext(clone $currentLoginContext);
                 } else {
                     //FIXME: TODO: move to a metadata!!!!
                     if ($proc->getName() != 'login' && $proc->getName() != 'init' && $proc->getName() != 'register') {
                         throw new EyeProcException('Cannot execute this application without a valid login context');
                     }
                 }
             }
         }
         Kernel::enterSystemMode();
         //when executing the first process, we need to tell the system
         //that our session has been activated. So regenerated is 0
         if (count($processTable) == 0) {
             $this->memoryManager->set('regenerated', 0);
         }
         $processTable[$pid] = $proc;
         $this->currentProcess = $proc;
         $this->memoryManager->set('processTable', $processTable);
         Kernel::exitSystemMode();
         $this->logger->debug('Process execution started: ' . $proc);
         $this->fireEvent('processStarted', new ProcEvent($proc));
     } catch (Exception $e) {
         $this->logger->warn('Error executing process: ' . $proc . ' (' . $e->getMessage() . ')');
         if ($this->logger->isDebugEnabled()) {
             $this->logger->debug(ExceptionStackUtil::getStackTrace($e, false));
         }
         throw $e;
     }
 }