public function workgroupDeleted(UMEvent $e) { if ($e->getSource() instanceof AbstractEyeosWorkgroup) { $workgroupDirPath = UMManager::getEyeosWorkgroupDirectory($e->getSource()->getName()); AdvancedPathLib::rmdirs($workgroupDirPath); } }
/** * @param mixed $object * @param String $params * @return boolean * @throws EyeException * @throws EyeErrorException */ public function deleteMeta($object, $params) { if (!$object instanceof EyeUserFile) { throw new EyeInvalidArgumentException('$object must be an EyeUserFile.'); } $meta = $this->retrieveMeta($object, $params); if ($meta !== null) { SecurityManager::getInstance()->checkPermission($meta, new MetaDataPermission('delete', null, $object)); } $urlParts = $object->getURLComponents(); if ($urlParts['path'] == '/') { $realpath = $this->getUserMetaFilesPath($urlParts['principalname']) . '/' . USERS_FILES_DIR; } else { $realpath = $this->getUserMetaFilesPath($urlParts['principalname']) . '/' . USERS_FILES_DIR . $urlParts['path']; } if (is_dir($realpath)) { AdvancedPathLib::rmdirs($realpath); } return @unlink($realpath . USERS_METAFILES_EXTENSION); }
public static function createFile($params) { $number = 1; $newfile = FSI::getFile($params[0]); $info = pathinfo($params[0]); while ($newfile->exists()) { $newfile = FSI::getFile($info['dirname'] . '/' . $info['filename'] . ' ' . $number . '.' . $info['extension']); $number++; } if (strtoupper($info['extension']) == 'EDOC') { $rand = md5(uniqid(time())); mkdir('/tmp/' . $rand); $uniqid = uniqid(); shell_exec('touch /tmp/' . $rand . '/document.html'); file_put_contents('/tmp/' . $rand . '/duid', $uniqid); $myFile = FSI::getFile($params[0] . '_tmp'); $myFile->checkWritePermission(); $myRealFile = $myFile->getRealFile(); $fileNameOriginal = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()); //this is REALLY annoying to be forced to do this, but zip command line util is a mess $oldDir = getcwd(); chdir('/tmp/' . $rand); $cmd = 'zip -r ' . escapeshellarg($fileNameOriginal) . ' ./'; shell_exec($cmd); //we return into the normal directory...this is ugly chdir($oldDir); AdvancedPathLib::rmdirs('/tmp/' . $rand); // creating a fake file trought FSI, so we can have our nice xml :) $newfile->createNewFile(true); $newfile->putContents($myFile->getContents()); unlink($fileNameOriginal); // FIXME!!!!! } else { $newfile->createNewFile(); } $return = array('class' => get_class($newfile), 'type' => $newfile->isDirectory() ? 'folder' : ($newfile->isLink() ? 'link' : 'file'), 'extension' => utf8_strtoupper($newfile->getExtension()), 'size' => $newfile->isDirectory() ? 0 : $newfile->getSize(), 'permissions' => $newfile->getPermissions(false), 'owner' => $newfile->getOwner(), 'group' => $newfile->getGroup(), 'absolutepath' => $newfile->getAbsolutePath(), 'meta' => $newfile->getMeta()->getAll()); if ($return['extension'] == 'LNK') { $return['content'] = $newfile->getContents(); } $return['name'] = $newfile->getName() != '/' ? $newfile->getName() : $return['absolutepath']; if ($newfile instanceof EyeosAbstractVirtualFile) { $return['virtual'] = 'true'; } else { $return['virtual'] = 'false'; } return $return; }
/** * TODO: Will need to be moved/merged to/with FileSystemExecModule */ public static function createNewFile($params) { $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $settings = MetaManager::getInstance()->retrieveMeta($currentUser); $newFile = FSI::getFile($params[0]); $name = explode(".", $newFile->getName()); $extension = (string) $name[count($name) - 1]; if ($newFile->exists()) { $name = explode(".", $newFile->getName()); $path = str_replace($newFile->getName(), '', $newFile->getPath()); $extension = (string) $name[count($name) - 1]; $theName = substr($newFile->getName(), 0, strlen($newFile->getName()) - strlen($extension) - 1); $futureName = array($theName, 1); $nameForCheck = implode(' ', $futureName); $nameForCheck .= '.' . $extension; $newFile = FSI::getFile($path . "/" . $nameForCheck); while ($newFile->exists()) { $futureName[1] += 1; $nameForCheck = implode(' ', $futureName); $nameForCheck .= '.' . $extension; $newFile = FSI::getFile($path . "/" . $nameForCheck); } } if ($extension == 'edoc') { $rand = md5(uniqid(time())); mkdir('/tmp/' . $rand); $uniqid = uniqid(); shell_exec('touch /tmp/' . $rand . '/document.html'); file_put_contents('/tmp/' . $rand . '/duid', $uniqid); $myFile = FSI::getFile($params[0] . '_tmp'); $myFile->checkWritePermission(); $myRealFile = $myFile->getRealFile(); $fileNameOriginal = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()); //this is REALLY annoying to be forced to do this, but zip command line util is a mess $oldDir = getcwd(); chdir('/tmp/' . $rand); $cmd = 'zip -r ' . escapeshellarg($fileNameOriginal) . ' ./'; shell_exec($cmd); //we return into the normal directory...this is ugly chdir($oldDir); AdvancedPathLib::rmdirs('/tmp/' . $rand); // creating a fake file trought FSI, so we can have our nice xml :) $newFile->createNewFile(true); $newFile->putContents($myFile->getContents()); unlink($fileNameOriginal); // FIXME!!!!! } else { $newFile->createNewFile(); } return self::getFileInfo($newFile, $settings); }
/** * Open eyeOS document (.edoc) * @return * Array ( * images => Array () paths of the images * previews => Array() paths with the preview of the images * hash => string See schema above * ) */ public static function openEdocument($filepath) { //get information about path $pathinfo = pathinfo($filepath); //get the extension $extension = strtoupper($pathinfo['extension']); //if the extension is not edoc, it won't work if ($filepath === null || $extension != 'EDOC') { throw new EyeInvalidArgumentException('Missing or invalid $filepath'); } $file = FSI::getFile($filepath); $file->checkReadPermission(); $filepath = 'home:///'; $myFile = FSI::getFile($filepath); $myRealFile = $myFile->getRealFile(); $home = $myRealFile; $home = AdvancedPathLib::getPhpLocalHackPath($home->getPath()); $fileNameDestination = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()); $fileNameDestination .= '/.office/documents/' . ProcManager::getInstance()->getCurrentProcess()->getPid(); if (!file_exists(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/')) { mkdir(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/'); } else { $cmd = 'rm -fr ' . escapeshellarg(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/documents/'); shell_exec($cmd); } mkdir(AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()) . '/.office/documents/'); if (file_exists($fileNameDestination)) { AdvancedPathLib::rmdirs($fileNameDestination); } mkdir($fileNameDestination); $myRealFile = $file->getRealFile(); $originalFile = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()); $cmd = 'unzip -d ' . escapeshellarg($fileNameDestination) . ' ' . escapeshellarg($originalFile); shell_exec($cmd); $pathToFile = $fileNameDestination . '/document.html'; //this path should be eyeos, not real $pathToFile = str_replace($home, 'home:///', $pathToFile); //now we need to convert this file to pdf return self::openOOdocument($pathToFile); }
function __shutdown_test() { try { // We need to be root to delete test principals $myUManager = UMManager::getInstance(); $subject = new Subject(); $loginContext = new LoginContext('init', $subject); $subject->getPrivateCredentials()->append(new EyeosPasswordCredential('root', 'root')); $loginContext->login(); // we need a fake shutdown process $procManager = ProcManager::getInstance(); $myProcess = new Process('shutdown'); $procManager->execute($myProcess); $procManager->setProcessLoginContext($myProcess->getPid(), $loginContext); // clean deletion of users foreach (UMManager::getInstance()->getAllUsers() as $user) { UMManager::getInstance()->deletePrincipal($user); } AdvancedPathLib::rmdirs(USERS_PATH, true); } catch (Exception $e) { echo 'Uncaught exception on shutdown!' . "\n"; ExceptionStackUtil::printStackTrace($e, false); } }
public function tearDown() { unset($this->fixture_file); unset($this->fixture_dir); AdvancedPathLib::rmdirs(TESTS_FSI_LOCALFILE_TMP_PATH); }
/** * Executed once after each test method. */ public function tearDown() { try { ProcManager::getInstance()->kill(ProcManager::getInstance()->getProcessByPid(self::$MyProcPid)); } catch (EyeProcException $e) { } ProcManager::getInstance()->setCurrentProcess(self::$InitProcessToRestore); unset($this->fixture_file1); unset($this->fixture_file2); unset($this->fixture_dir1); unset($this->fixture_dir2); if (is_file($this->fixture_file1_path)) { unlink($this->fixture_file1_path); } if (is_file($this->fixture_file2_path)) { unlink($this->fixture_file2_path); } if (is_dir($this->fixture_dir1_path)) { try { AdvancedPathLib::rmdirs($this->fixture_dir1_path); } catch (Exception $e) { } } if (is_dir($this->fixture_dir2_path)) { try { AdvancedPathLib::rmdirs($this->fixture_dir2_path); } catch (Exception $e) { } } AdvancedPathLib::rmdirs(EYEOS_TESTS_TMP_PATH); }
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) { } } } }
public static function fileSaveAs(array $datas) { $foo = explode(".", $datas[0]); $datas[0] = $foo[0] . '.edoc'; // creating a tmp directory... $rand = md5(uniqid(time())); mkdir('/tmp/' . $rand); // creating an images directory, and saving all the images contained // in the document... mkdir('/tmp/' . $rand . '/images/'); preg_match_all('/<img src="([^"]+)"/', $datas[1], $matches); if (is_array($matches) && is_array($matches[1])) { foreach ($matches[1] as $value) { if (strpos($value, 'params=')) { $filename = substr($value, strpos($value, 'params=') + 7); $md5 = md5($value); $myFile = FSI::getFile($filename); $myFile->checkReadPermission(); if ($myFile instanceof EyeUserFile) { $myRealFile = $myFile->getRealFile(); $fileNameOriginal = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()); } else { $userName = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getName(); $fileNameOriginal = USERS_PATH . '/' . $userName . '/files/.office/' . ProcManager::getInstance()->getCurrentProcess()->getPid() . '/' . utf8_basename($filename); } copy($fileNameOriginal, '/tmp/' . $rand . '/images/' . $md5 . '.' . $myFile->getExtension()); $datas[1] = str_replace($value, 'index.php?checknum=CHECKNUM_HERE&message=getImg¶ms=images/' . $md5 . '.' . $myFile->getExtension(), $datas[1]); } } } $datas[1] = preg_replace('/<p class="mceNonEditable editor_[^"]+" style="[^"]+"/', '<p style="border: 0px solid black; padding-left: 0px; margin-left: 0px;"', $datas[1]); file_put_contents('/tmp/' . $rand . '/document.html', $datas[1]); if (!isset($datas[2]) || !$datas[2]) { $datas[2] = uniqid(); } file_put_contents('/tmp/' . $rand . '/duid', $datas[2]); $myFile = FSI::getFile($datas[0] . '_tmp'); $myFile->checkWritePermission(); $myRealFile = $myFile->getRealFile(); $fileNameOriginal = AdvancedPathLib::getPhpLocalHackPath($myRealFile->getPath()); //this is REALLY annoying to be forced to do this, but zip command line util is a mess $oldDir = getcwd(); chdir('/tmp/' . $rand); $cmd = 'zip -r ' . escapeshellarg($fileNameOriginal) . ' ./'; shell_exec($cmd); //we return into the normal directory...this is ugly chdir($oldDir); AdvancedPathLib::rmdirs('/tmp/' . $rand); // creating a fake file trought FSI, so we can have our nice xml :) $newFile = FSI::getFile($datas[0]); $newFile->createNewFile(true); $newFile->putContents($myFile->getContents()); $myFile->delete(true); return $datas[0]; }
public function testRmdirs() { mkdir(EYEOS_TESTS_TMP_PATH . '/myDir1/myDir2/myDir3', 0777, true); $files = array(EYEOS_TESTS_TMP_PATH . '/myDir1/myFile1-1.ext', EYEOS_TESTS_TMP_PATH . '/myDir1/myFile1-2.ext', EYEOS_TESTS_TMP_PATH . '/myDir1/myDir2/myFile2.ext', EYEOS_TESTS_TMP_PATH . '/myDir1/myDir2/myDir3/myFile3.ext'); foreach ($files as $file) { file_put_contents($file, 'some content'); } foreach ($files as $file) { $this->assertTrue(is_file($file)); } $this->assertTrue(AdvancedPathLib::rmdirs(EYEOS_TESTS_TMP_PATH . '/myDir1')); foreach ($files as $file) { $this->assertFalse(is_file($file)); } $this->assertFalse(is_dir(EYEOS_TESTS_TMP_PATH . '/myDir1')); }