Ejemplo n.º 1
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $paths = $params->paths;
     $result = array();
     foreach ($paths as $path) {
         if ($this->hasPath($result, $path)) {
             continue;
         }
         $file = MOXMAN::getFile($path);
         $config = $file->getConfig();
         if ($config->get('general.demo')) {
             throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
         }
         if (!$file->exists()) {
             throw new MOXMAN_Exception("Path doesn't exist: " . $file->getPublicPath(), MOXMAN_Exception::FILE_DOESNT_EXIST);
         }
         $parentFile = $file->getParentFile();
         if (!$parentFile || !$parentFile->canWrite()) {
             throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
         }
         $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "delete");
         if (!$filter->accept($file)) {
             throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
         }
         $result[] = $this->fileToJson($file);
         if ($file->exists()) {
             $args = $this->fireBeforeFileAction(MOXMAN_Vfs_FileActionEventArgs::DELETE, $file);
             $result = array_merge($result, $this->filesToJson($args->getFileList()));
             $file->delete(true);
             $args = $this->fireFileAction(MOXMAN_Vfs_FileActionEventArgs::DELETE, $file);
             $result = array_merge($result, $this->filesToJson($args->getFileList()));
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $paths = $params->paths;
     $result = array();
     foreach ($paths as $path) {
         $file = MOXMAN::getFile($path);
         $config = $file->getConfig();
         if ($config->get('general.demo')) {
             throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
         }
         if (!$file->exists()) {
             throw new MOXMAN_Exception("Path doesn't exist: " . $file->getPublicPath(), MOXMAN_Exception::FILE_DOESNT_EXIST);
         }
         if (!$file->canWrite()) {
             throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
         }
         $filter = MOXMAN_Vfs_BasicFileFilter::createFromConfig($config);
         if ($filter->accept($file, $file->isFile()) !== MOXMAN_Vfs_BasicFileFilter::ACCEPTED) {
             throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
         }
         $result[] = $this->fileToJson($file);
         if ($file->exists()) {
             $file->delete(true);
             $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::DELETE, $file);
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $config = MOXMAN::getConfig();
     if ($config->get('SymfonyAuthenticator.application_name') == '') {
         die('You should define a SymfonyAuthenticator.application_name name in Moxiemanager config file.');
     }
     if ($config->get('SymfonyAuthenticator.application_env') == '') {
         die('You should define a SymfonyAuthenticator.application_env in Moxiemanager config file.');
     }
     if ($config->get('SymfonyAuthenticator.project_configuration_path') == '') {
         die('You should define a SymfonyAuthenticator.project_configuration_path in Moxiemanager config file.');
     }
     require_once $config->get('SymfonyAuthenticator.project_configuration_path');
     $configuration = ProjectConfiguration::getApplicationConfiguration($config->get('SymfonyAuthenticator.application_name'), $config->get('SymfonyAuthenticator.application_env'), false);
     $context = sfContext::createInstance($configuration);
     // Is the user authenticated ?
     if ($context->getUser()->isAuthenticated()) {
         // Do we need a special role to access to the moxiemanager ?
         if ($config->get('SymfonyAuthenticator.credential') != '') {
             if ($context->getUser()->hasCredential($config->get('SymfonyAuthenticator.credential'))) {
                 return true;
             } else {
                 return false;
             }
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Process a request using the specified context.
  *
  * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
  */
 public function processRequest(MOXMAN_Http_Context $httpContext)
 {
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     try {
         $config = MOXMAN::getConfig();
         $allItems = $config->getAll();
         $licenseKey = trim($config->get("general.license"));
         $installed = !empty($allItems);
         $response->disableCache();
         $response->setHeader('Content-type', 'application/json');
         if ($installed && !$config->get('filesystem.rootpath')) {
             throw new MOXMAN_Exception("You must configure filesystem.rootpath.");
         }
         if ($request->getMethod() != 'POST') {
             throw new MOXMAN_Exception("Not a HTTP post request.");
         }
         if ($installed && !preg_match('/^([0-9A-Z]{4}\\-){7}[0-9A-Z]{4}$/', $licenseKey)) {
             throw new MOXMAN_Exception("Invalid license key specified in config.");
         }
         $authInfo = (object) array("token" => MOXMAN_Http_Csrf::createToken(MOXMAN::getConfig()->get('general.license')), "installed" => $installed, "loggedin" => MOXMAN::getAuthManager()->isAuthenticated(), "loginurl" => $config->get("authenticator.login_page", ""), "standalone" => MOXMAN::getAuthManager()->hasStandalone(), "overwrite_action" => $config->get("filesystem.overwrite_action", ""));
         $args = new MOXMAN_Auth_AuthInfoEventArgs();
         MOXMAN::getPluginManager()->get("core")->fire("AuthInfo", $args);
         foreach ($args->getInfo() as $key => $value) {
             $authInfo->{$key} = $value;
         }
         $response->sendJson($authInfo);
     } catch (Exception $e) {
         $response->sendJson((object) array("error" => array("code" => $e->getCode(), "message" => $e->getMessage())));
     }
 }
Ejemplo n.º 5
0
 /**
  * Process a request using the specified context.
  *
  * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
  */
 public function processRequest(MOXMAN_Http_Context $httpContext)
 {
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     $response->disableCache();
     $response->setHeader('Content-type', 'text/javascript');
     // Set prefix if it's a tinymce language pack or not
     $prefix = MOXMAN_ROOT . '/langs/moxman_';
     if ($request->get("tinymce")) {
         $prefix = MOXMAN_ROOT . '/langs/';
     }
     // Load TinyMCE specific pack if it exists
     $langCode = preg_replace('/[^a-z_\\-]/i', '', $request->get('code'));
     if ($langCode) {
         $langFile = $prefix . $langCode . '.js';
         if (file_exists($langFile)) {
             $response->sendContent(file_get_contents($langFile));
             return;
         }
     }
     // Fallback to configured language pack
     $langCode = MOXMAN::getConfig()->get("general.language");
     if ($langCode) {
         $langFile = $prefix . $langCode . '.js';
         if (file_exists($langFile)) {
             $response->sendContent(file_get_contents($langFile));
             return;
         }
     }
 }
Ejemplo n.º 6
0
 private function addVideoMeta(MOXMAN_Vfs_IFile $file, $metaData)
 {
     $fileName = $file->getName();
     $ext = strtolower(MOXMAN_Util_PathUtils::getExtension($fileName));
     if (preg_match('/^(mp4|ogv|webm)$/', $ext)) {
         $metaData->url_type = MOXMAN_Util_Mime::get($fileName);
         $name = substr($fileName, 0, strlen($fileName) - strlen($ext));
         // Alternative video formats
         $altExt = array("mp4", "ogv", "webm");
         foreach ($altExt as $altExt) {
             if ($ext != $altExt) {
                 $altFile = MOXMAN::getFile($file->getParent(), $name . $altExt);
                 if ($altFile->exists()) {
                     $metaData->alt_url = $altFile->getUrl();
                     break;
                 }
             }
         }
         // Alternative image format
         $altFile = MOXMAN::getFile($file->getParent(), $name . "jpg");
         if ($altFile->exists()) {
             $metaData->alt_img = $altFile->getUrl();
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $toPath = $params->to;
     $ext = MOXMAN_Util_PathUtils::getExtension($toPath);
     if ($ext !== 'zip') {
         $toPath .= '.zip';
     }
     $toFile = MOXMAN::getFile($toPath);
     $config = $toFile->getConfig();
     if ($config->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     if (!$toFile->canWrite()) {
         throw new MOXMAN_Exception("No write access to file: " . $toFile->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
     }
     $zipWriter = new MOXMAN_Zip_ZipWriter(array("compressionLevel" => 5));
     $filter = MOXMAN_Vfs_BasicFileFilter::createFromConfig($config);
     $path = $params->path;
     foreach ($params->names as $name) {
         $fromFile = MOXMAN::getFile(MOXMAN_Util_PathUtils::combine($path, $name));
         $this->addZipFiles($fromFile, $fromFile->getParent(), $filter, $zipWriter);
     }
     $stream = $toFile->open(MOXMAN_Vfs_IFileStream::WRITE);
     if ($stream) {
         $stream->write($zipWriter->toString());
         $stream->close();
     }
     $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::ADD, $toFile);
     return $this->fileToJson($toFile);
 }
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $file = MOXMAN::getFile($params->path);
     $config = $file->getConfig();
     if ($config->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     if (!$file->canWrite()) {
         throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
     }
     if ($file->exists()) {
         throw new MOXMAN_Exception("File already exist: " . $file->getPublicPath(), MOXMAN_Exception::FILE_EXISTS);
     }
     $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "createdir");
     if (!$filter->accept($file, false)) {
         throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     if (isset($params->template)) {
         // TODO: Security audit this
         $templateFile = MOXMAN::getFile($params->template);
         if (!$templateFile->exists()) {
             throw new MOXMAN_Exception("Template file doesn't exists: " . $file->getPublicPath(), MOXMAN_Exception::FILE_DOESNT_EXIST);
         }
         $args = $this->fireBeforeTargetFileAction(MOXMAN_Vfs_FileActionEventArgs::COPY, $templateFile, $file);
         $file = $args->getTargetFile();
         $templateFile->copyTo($file);
         $this->fireTargetFileAction(MOXMAN_Vfs_FileActionEventArgs::COPY, $templateFile, $file);
     } else {
         $args = $this->fireBeforeFileAction(MOXMAN_Vfs_FileActionEventArgs::ADD, $file);
         $file = $args->getFile();
         $file->mkdir();
         $this->fireFileAction(MOXMAN_Vfs_FileActionEventArgs::ADD, $file);
     }
     return $this->fileToJson($file, true);
 }
Ejemplo n.º 9
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $config = MOXMAN::getConfig();
     $session = MOXMAN_Http_Context::getCurrent()->getSession();
     // Check logged in key
     $sessionValue = $session->get($config->get("SessionAuthenticator.logged_in_key"), false);
     if (!$sessionValue || $sessionValue === "false") {
         return false;
     }
     // Extend config with session prefixed sessions
     $sessionConfig = array();
     $configPrefix = $config->get("SessionAuthenticator.config_prefix");
     if ($configPrefix) {
         foreach ($_SESSION as $key => $value) {
             if (strpos($key, $configPrefix) === 0) {
                 $sessionConfig[substr($key, strlen($configPrefix) + 1)] = $value;
             }
         }
     }
     // Extend the config with the session config
     $config->extend($sessionConfig);
     // Replace ${user} with all config items
     $key = $config->get("SessionAuthenticator.user_key");
     if ($key && isset($_SESSION[$key])) {
         $config->replaceVariable("user", $session->get($key));
     }
     // The user is authenticated so let them though
     return true;
 }
Ejemplo n.º 10
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $config = MOXMAN::getConfig();
     $session = new CI_Session();
     // Check logged in key
     $sessionValue = $session->userdata($config->get("CodeIgniterAuthenticator.logged_in_key", "loggedin"));
     if (!$sessionValue || $sessionValue === "false") {
         return false;
     }
     // Extend config with session prefixed sessions
     $sessionConfig = array();
     $configPrefix = $config->get("CodeIgniterAuthenticator.config_prefix", "moxiemanager");
     if ($configPrefix) {
         $allData = $session->all_userdata();
         foreach ($allData as $key => $value) {
             if (strpos($key, $configPrefix) === 0) {
                 $sessionConfig[substr($key, strlen($configPrefix) + 1)] = $value;
             }
         }
     }
     // Extend the config with the session config
     $config->extend($sessionConfig);
     // Replace ${user} with all config items
     $key = $config->get("CodeIgniterAuthenticator.user_key");
     if ($key) {
         $value = $session->userdata($key);
         $config->replaceVariable("user", $value);
         $user->setName($value);
     }
     return true;
 }
Ejemplo n.º 11
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $file = MOXMAN::getFile($params->path);
     $config = $file->getConfig();
     $resolution = $params->resolution;
     if ($config->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     $content = $this->getUrlContent($params->url, $config);
     // Fire before file action add event
     $args = $this->fireBeforeFileAction("add", $file, strlen($content));
     $file = $args->getFile();
     if (!$file->canWrite()) {
         throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
     }
     $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "upload");
     if (!$filter->accept($file, true)) {
         throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     if ($resolution == "rename") {
         $file = MOXMAN_Util_FileUtils::uniqueFile($file);
     } else {
         if ($resolution == "overwrite") {
             MOXMAN::getPluginManager()->get("core")->deleteFile($file);
         } else {
             throw new MOXMAN_Exception("To file already exist: " . $file->getPublicPath(), MOXMAN_Exception::FILE_EXISTS);
         }
     }
     $stream = $file->open(MOXMAN_Vfs_IFileStream::WRITE);
     $stream->write($content);
     $stream->close();
     $args = new MOXMAN_Vfs_FileActionEventArgs("add", $file);
     MOXMAN::getPluginManager()->get("core")->fire("FileAction", $args);
     return parent::fileToJson($file, true);
 }
Ejemplo n.º 12
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $sessionContainerName = MOXMAN::getConfig()->get("ZendAuthenticator.session_container");
     if ($sessionContainerName) {
         $session = new Zend\Session\Container($sessionContainerName);
     } else {
         $session = new Zend\Session\Container();
     }
     $config = MOXMAN::getConfig();
     $loggedInKey = $config->get("ZendAuthenticator.logged_in_key", "loggedin");
     if (isset($session->{$loggedInKey}) && ($session->{$loggedInKey} === true || strtolower($session->{$loggedInKey}) === "true")) {
         // Extend config with session prefixed sessions
         $sessionConfig = array();
         $configPrefix = $config->get("ZendAuthenticator.config_prefix");
         if ($configPrefix) {
             foreach ($session as $key => $value) {
                 if (strpos($key, $configPrefix) === 0) {
                     $sessionConfig[substr($key, strlen($configPrefix) + 1)] = $value;
                 }
             }
         }
         // Extend the config with the session config
         $config->extend($sessionConfig);
         // Replace ${user} with all config items
         $key = $config->get("ZendAuthenticator.user_key");
         if ($key && isset($session->{$key})) {
             $config->replaceVariable("user", $session->{$key});
             $user->setName($session->{$key});
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 13
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     if (isset($params->paths)) {
         $result = array();
         foreach ($params->paths as $path) {
             $file = MOXMAN::getFile($path);
             $fileInfo = $this->fileToJson($file, true);
             $args = $this->fireCustomInfo(MOXMAN_Core_CustomInfoEventArgs::INSERT_TYPE, $file);
             $fileInfo->info = (object) $args->getInfo();
             if (isset($params->insert) && $params->insert) {
                 $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::INSERT, $file);
             }
             $result[] = $fileInfo;
         }
     } else {
         $file = MOXMAN::getFile($params->path);
         $fileInfo = $this->fileToJson($file, true);
         $args = $this->fireCustomInfo(MOXMAN_Core_CustomInfoEventArgs::INSERT_TYPE, $file);
         $fileInfo->info = (object) $args->getInfo();
         if (isset($params->insert) && $params->insert) {
             $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::INSERT, $file);
         }
         $result = $fileInfo;
     }
     return $result;
 }
Ejemplo n.º 14
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     if (isset($params->path) && $params->path) {
         return $this->getPublicConfig(MOXMAN::getFile($params->path));
     }
     return $this->getPublicConfig();
 }
Ejemplo n.º 15
0
 /**
  * Process a request using the specified context.
  *
  * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
  */
 public function processRequest(MOXMAN_Http_Context $httpContext)
 {
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     $path = $request->get("path");
     $names = explode('/', $request->get("names", ""));
     $zipName = $request->get("zipname", "files.zip");
     if (count($names) === 1) {
         $file = MOXMAN::getFile(MOXMAN_Util_PathUtils::combine($path, $names[0]));
         $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig(MOXMAN::getFile($path)->getConfig(), "download");
         if (!$filter->accept($file)) {
             throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
         }
         if ($file->isFile()) {
             $response->sendFile($file, true);
             return;
         }
     }
     // Download multiple files as zip
     $zipWriter = new MOXMAN_Zip_ZipWriter(array("compressionLevel" => 0));
     // Setup download headers
     $response->disableCache();
     $response->setHeader("Content-type", "application/octet-stream");
     $response->setHeader("Content-Disposition", 'attachment; filename="' . $zipName . '"');
     $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig(MOXMAN::getFile($path)->getConfig(), "download");
     // Combine files to zip
     foreach ($names as $name) {
         $fromFile = MOXMAN::getFile(MOXMAN_Util_PathUtils::combine($path, $name));
         $this->addZipFiles($fromFile, $fromFile->getParent(), $filter, $zipWriter);
     }
     $response->sendContent($zipWriter->toString());
 }
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $file = MOXMAN::getFile($params->path);
     $config = $file->getConfig();
     if ($config->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     if (!$file->canWrite()) {
         throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
     }
     $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "edit");
     if ($filter->accept($file) !== MOXMAN_Vfs_CombinedFileFilter::ACCEPTED) {
         throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     if ($file->exists()) {
         $file->delete(true);
     }
     // Write contents to file
     $stream = $file->open(MOXMAN_Vfs_IFileStream::WRITE);
     if ($stream) {
         $stream->write($params->content);
         $stream->close();
     }
     $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::ADD, $file);
     return $this->fileToJson($file);
 }
 /**
  * Wrap Moxiemanager's api.php in a controller action.
  *
  * @return void
  */
 public function api()
 {
     try {
         $pluginPath = Plugin::path('CkTools');
         define('MOXMAN_CLASSES', $pluginPath . 'src/Lib/moxiemanager/classes');
         define('MOXMAN_PLUGINS', $pluginPath . 'src/Lib/moxiemanager/plugins');
         define('MOXMAN_ROOT', $pluginPath . 'src/Lib/moxiemanager');
         define('MOXMAN_API_FILE', __FILE__);
         $appConfig = Configure::read('CkTools.moxiemanager');
         Configure::load('CkTools.moxiemanager');
         $moxieManagerConfig = Configure::read('moxiemanager');
         if (is_array($appConfig)) {
             $moxieManagerConfig = Hash::merge($moxieManagerConfig, $appConfig);
         }
         $GLOBALS['moxieManagerConfig'] = $moxieManagerConfig;
         require_once MOXMAN_CLASSES . '/MOXMAN.php';
         $context = \MOXMAN_Http_Context::getCurrent();
         $pluginManager = \MOXMAN::getPluginManager();
         foreach ($pluginManager->getAll() as $plugin) {
             if ($plugin instanceof \MOXMAN_Http_IHandler) {
                 $plugin->processRequest($context);
             }
         }
     } catch (Exception $e) {
         \MOXMAN_Exception::printException($e);
     }
     return $this->render(false, false);
 }
Ejemplo n.º 18
0
 /**
  * Adds a plugin instance by name to the manager.
  *
  * @param string $name Name of the plugin to add.
  * @param MOXMAN_IPlugin $plugin Plugin instance to add.
  */
 public function add($name, MOXMAN_IPlugin $plugin)
 {
     if ($plugin instanceof MOXMAN_Auth_IAuthenticator) {
         MOXMAN::getAuthManager()->add($name, $plugin);
     }
     $this->plugins[$name] = $plugin;
     $this->unInitialized[] = $name;
 }
Ejemplo n.º 19
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $config = MOXMAN::getConfig();
     $this->validateConfig($config);
     $json = $this->getJson($config);
     $this->updateUserAndConfig($this->parseJson($json), $user, $config);
     $this->cacheJsonResult($json);
     return true;
 }
Ejemplo n.º 20
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $file = MOXMAN::getFile($params->path);
     $url = parse_url($params->url);
     $config = $file->getConfig();
     if ($config->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     if ($file->exists()) {
         throw new MOXMAN_Exception("To file already exist: " . $file->getPublicPath(), MOXMAN_Exception::FILE_EXISTS);
     }
     if (!$file->canWrite()) {
         throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS);
     }
     $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "upload");
     if (!$filter->accept($file, true)) {
         throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     $port = "";
     if (isset($url["port"])) {
         $port = ":" . $url["port"];
     }
     $query = "";
     if (isset($url["query"])) {
         $query = "?" . $url["query"];
     }
     $path = $url["path"] . $query;
     $host = $url["scheme"] . "://" . $url["host"] . $port;
     $httpClient = new MOXMAN_Http_HttpClient($host);
     $request = $httpClient->createRequest($path);
     $response = $request->send();
     // Handle redirects
     $location = $response->getHeader("location");
     if ($location) {
         $httpClient->close();
         $httpClient = new MOXMAN_Http_HttpClient($location);
         $request = $httpClient->createRequest($location);
         $response = $request->send();
     }
     // Read file into ram
     // TODO: This should not happen if we know the file size
     $content = "";
     while (($chunk = $response->read()) != "") {
         $content .= $chunk;
     }
     $httpClient->close();
     // Fire before file action add event
     $args = $this->fireBeforeFileAction("add", $file, strlen($content));
     $file = $args->getFile();
     $stream = $file->open(MOXMAN_Vfs_IFileStream::WRITE);
     $stream->write($content);
     $stream->close();
     $args = new MOXMAN_Vfs_FileActionEventArgs("add", $file);
     MOXMAN::getPluginManager()->get("core")->fire("FileAction", $args);
     return parent::fileToJson($file, true);
 }
Ejemplo n.º 21
0
 public static function startSession()
 {
     $sessionName = MOXMAN::getConfig()->get("SessionAuthenticator.session_name");
     if ($sessionName) {
         @session_name($sessionName);
     }
     if (session_id() == '') {
         @session_start();
     }
 }
Ejemplo n.º 22
0
 public function onFileAction(MOXMAN_Vfs_FileActionEventArgs $args)
 {
     switch ($args->getAction()) {
         case MOXMAN_Vfs_FileActionEventArgs::DELETE:
         case MOXMAN_Vfs_FileActionEventArgs::COPY:
         case MOXMAN_Vfs_FileActionEventArgs::ADD:
             MOXMAN::getUserStorage()->put("quota.size", max(0, $this->currentSize));
             break;
     }
 }
Ejemplo n.º 23
0
 /**
  * Returns a config based on the specified file.
  *
  * @param MOXMAN_Vfs_IFile $file File to get the config for.
  * @return MOXMAN_Util_Config Config for the specified file.
  */
 public function getConfig(MOXMAN_Vfs_IFile $file)
 {
     $config = clone $this->config;
     $path = $file->isFile() ? $file->getParent() : $file->getPath();
     $root = $this->fileSystem->getRootPath();
     $mcAccessFile = $this->config->get("filesystem.local.access_file_name", "mc_access");
     $user = MOXMAN::getUser();
     $configFiles = array();
     $targetConfigPath = $path . '/' . $mcAccessFile;
     // Collect config files
     while ($path && strlen($path) >= strlen($root)) {
         if (file_exists($path . '/' . $mcAccessFile)) {
             $configFiles[] = $path . '/' . $mcAccessFile;
         }
         $path = MOXMAN_Util_PathUtils::getParent($path);
     }
     // Extend current config with the config files
     for ($i = count($configFiles) - 1; $i >= 0; $i--) {
         // Parse mc_access file
         $iniParser = new MOXMAN_Util_IniParser();
         $iniParser->load($configFiles[$i]);
         // Loop and extend it
         $items = $iniParser->getItems();
         foreach ($items as $key => $value) {
             // Group specific config
             if (is_array($value)) {
                 $targetGroups = explode(',', $key);
                 foreach ($targetGroups as $targetGroup) {
                     if ($user->isMemberOf($targetGroup)) {
                         foreach ($value as $key2 => $value2) {
                             if (strpos($key2, '_') === 0) {
                                 if ($targetConfigPath == $configFiles[$i]) {
                                     $key2 = substr($key2, 1);
                                 } else {
                                     continue;
                                 }
                             }
                             $config->put($key2, $value2);
                         }
                     }
                 }
             } else {
                 if (strpos($key, '_') === 0) {
                     if ($targetConfigPath == $configFiles[$i]) {
                         $key = substr($key, 1);
                     } else {
                         continue;
                     }
                 }
                 $config->put($key, $value);
             }
         }
     }
     return $config;
 }
Ejemplo n.º 24
0
 public function onFileAction(MOXMAN_Core_FileActionEventArgs $args)
 {
     switch ($args->getAction()) {
         case MOXMAN_Core_FileActionEventArgs::LIST_FILES:
             // Recalculate quota size when listing files
             $dirs = MOXMAN::getUserStorage()->get("quota.dirs", new stdClass());
             $this->recalcQuota($args->getFile(), $dirs);
             MOXMAN::getUserStorage()->put("quota.dirs", $dirs);
             break;
     }
 }
Ejemplo n.º 25
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $config = MOXMAN::getConfig();
     $user = JFactory::getUser();
     // Not logged in
     if ($user->id == 0) {
         return false;
     }
     $config->replaceVariable("user", $user->username);
     return true;
 }
Ejemplo n.º 26
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     global $isDrupalAuth;
     global $user;
     $config = MOXMAN::getConfig();
     // If authenticated then
     if ($isDrupalAuth && isset($user)) {
         $config->replaceVariable("user", $user->uid);
     }
     return $isDrupalAuth;
 }
Ejemplo n.º 27
0
 public function listFilesFiltered(MOXMAN_Vfs_IFileFilter $filter)
 {
     $entries = MOXMAN_Util_Json::decode(MOXMAN::getUserStorage()->get("uploaded.files", "[]"));
     $files = array();
     foreach ($entries as $entry) {
         $file = new MOXMAN_Uploaded_File($this->fileSystem, $entry->path, $entry);
         if ($filter->accept($file) == MOXMAN_Vfs_IFileFilter::ACCEPTED) {
             $files[] = $file;
         }
     }
     return $files;
 }
Ejemplo n.º 28
0
 /**
  * Get an unique file
  *
  * @param MOXMAN_Vfs_IFile $file File object to check against
  * @return MOXMAN_Vfs_IFile Unique file object.
  */
 public static function uniqueFile(MOXMAN_Vfs_IFile $file)
 {
     $fileName = $file->getName();
     $ext = MOXMAN_Util_PathUtils::getExtension($fileName);
     for ($i = 2; $file->exists(); $i++) {
         if ($file->isFile() && $ext) {
             $file = MOXMAN::getFile($file->getParent(), basename($fileName, '.' . $ext) . '_' . $i . '.' . $ext);
         } else {
             $file = MOXMAN::getFile($file->getParent(), $fileName . '_' . $i);
         }
     }
     return $file;
 }
Ejemplo n.º 29
0
 public function onFileAction(MOXMAN_Vfs_FileActionEventArgs $args)
 {
     $logger = MOXMAN::getLogger();
     if ($logger) {
         if ($args->getTargetFile()) {
             // Log copy/move operations these have a target file
             $logger->debug("Action: " . $args->getAction(), "Path: " . $args->getFile()->getPath(), "TargetPath: " . $args->getTargetFile()->getPath());
         } else {
             // Log single file operations
             $logger->debug("Action: " . $args->getAction(), "Path: " . $args->getFile()->getPath());
         }
     }
 }
Ejemplo n.º 30
0
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $config = MOXMAN::getConfig();
     if (!isLogged()) {
         return false;
     }
     $s = getUsername();
     $sPath = BX_DIRECTORY_PATH_ROOT . 'media/moxie/files/' . substr($s, 0, 1) . '/' . substr($s, 0, 2) . '/' . substr($s, 0, 3) . '/' . $s;
     bx_mkdir_r($sPath);
     $config->put('filesystem.rootpath', $sPath);
     $config->replaceVariable("user", $s);
     $user->setName($s);
     return true;
 }