/** * Initializes the storage instance. * * @param MOXMAN_Util_Config $config Config instance. * @param int $type Storage type to use, can be any of the type constants. * @param string $name Name of the user/group if those types are used or an empty string. */ public function initialize($config, $type, $name) { $this->config = $config; $this->type = $type; $this->name = $name; $this->storagePath = MOXMAN_Util_PathUtils::combine($config->get("storage.path"), ($name ? $type . "." . $name : $type) . ".json"); }
/** * Initializes the storage instance. * * @param MOXMAN_Util_Config $config Config instance. * @param int $type Storage type to use, can be any of the type constants. * @param string $name Name of the user/group if those types are used or an empty string. */ public function initialize($config, $type, $name) { $this->config = $config; $this->type = $type; $this->name = $name; $this->pdo = new MOXMAN_Util_Pdo($config->get("sql.connection"), $config->get("sql.username"), $config->get("sql.password"), array(), $config->get("sql.table_prefix")); $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
private function sendRequest(MOXMAN_Util_Config $config) { $secretKey = $config->get("ExternalAuthenticator.secret_key"); $authUrl = $config->get("ExternalAuthenticator.external_auth_url"); $url = ""; $defaultPort = 80; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") { $url = "https://"; $defaultPort = 443; } $url .= $_SERVER['HTTP_HOST']; if ($_SERVER['SERVER_PORT'] != $defaultPort) { $url .= ':' . $defaultPort; } $httpClient = new MOXMAN_Http_HttpClient($url); $httpClient->setProxy($config->get("general.http_proxy", "")); $authUrl = MOXMAN_Util_PathUtils::toAbsolute(dirname($_SERVER["REQUEST_URI"]) . '/plugins/ExternalAuthenticator', $authUrl); $request = $httpClient->createRequest($authUrl, "POST"); $authUser = $config->get("ExternalAuthenticator.basic_auth_user"); $authPw = $config->get("ExternalAuthenticator.basic_auth_password"); if ($authUser && $authPw) { $request->setAuth($authUser, $authPw); } $cookie = isset($_SERVER["HTTP_COOKIE"]) ? $_SERVER["HTTP_COOKIE"] : ""; if ($cookie) { $request->setHeader('cookie', $cookie); } $seed = hash_hmac('sha256', $cookie . uniqid() . time(), $secretKey); $hash = hash_hmac('sha256', $seed, $secretKey); $response = $request->send(array("seed" => $seed, "hash" => $hash)); if ($response->getCode() < 200 || $response->getCode() > 399) { throw new MOXMAN_Exception("Did not get a proper http status code from Auth url: " . $url . $authUrl . ".", $response->getCode()); } return $response->getBody(); }
/** * Creates a config instance from the specified config. It will use various config options * for setting up a filter instance. This is a helper function. * * @param MOXMAN_Util_Config $config Config instance to get settings from. * @param String $prefix Prefix of subfilter for example "edit" * @return MOXMAN_Vfs_CombinedFileFilter Basic file filter instance based on config. */ public static function createFromConfig(MOXMAN_Util_Config $config, $prefix) { $filter1 = new MOXMAN_Vfs_BasicFileFilter(); $filter1->setIncludeDirectoryPattern($config->get('filesystem.include_directory_pattern')); $filter1->setExcludeDirectoryPattern($config->get('filesystem.exclude_directory_pattern')); $filter1->setIncludeFilePattern($config->get('filesystem.include_file_pattern')); $filter1->setExcludeFilePattern($config->get('filesystem.exclude_file_pattern')); $filter1->setIncludeExtensions($config->get('filesystem.extensions')); $filter1->setExcludeFiles($config->get('filesystem.local.access_file_name')); $filter2 = new MOXMAN_Vfs_BasicFileFilter(); $filter2->setIncludeDirectoryPattern($config->get($prefix . '.include_directory_pattern')); $filter2->setExcludeDirectoryPattern($config->get($prefix . '.exclude_directory_pattern')); $filter2->setIncludeFilePattern($config->get($prefix . '.include_file_pattern')); $filter2->setExcludeFilePattern($config->get($prefix . '.exclude_file_pattern')); $filter2->setIncludeExtensions($config->get($prefix . '.extensions')); $filter2->setExcludeFiles($config->get($prefix . '.local.access_file_name')); $filter = new MOXMAN_Vfs_CombinedFileFilter(); $filter->addFilter($filter1); $filter->addFilter($filter2); return $filter; }
/** * Returns a new config object based on the specified files path. * This will match the file path with the path.overrides in the config. * * @param MOXMAN_Vfs_IFile $file File to match agains path.overrides. * @return MOXMAN_Util_Config New path specific config instance. */ public function getFileConfig(MOXMAN_Vfs_IFile $file) { $config = new MOXMAN_Util_Config($this->items); $pathOverrides = $this->get("filesystem.directories"); if (is_array($pathOverrides) && !empty($pathOverrides)) { if ($file->isFile()) { $file = $file->getParentFile(); // @codeCoverageIgnoreStart if (!$file) { return $config; } // @codeCoverageIgnoreEnd } $path = $file->getPublicPath(); foreach (array_keys($pathOverrides) as $pattern) { $overrides = $this->getOverrides($pattern); if (strpos($pattern, 'regexp:') === 0) { // regexp:/pattern/ if (preg_match(substr($pattern, 7), $path)) { $config->extend($overrides); } } else { foreach (explode(',', $pattern) as $pattern) { if (strpos($pattern, '/') === false) { // Directory name $pattern = "/\\/" . preg_quote($pattern) . "(\\/|\$)/"; if (preg_match($pattern, $path)) { $config->extend($overrides); } } else { if (strrchr($pattern, '/') === '/') { $pattern = substr($pattern, 0, strlen($pattern) - 1); } if (preg_match("/\\/\\.\$/", $pattern)) { // Directory path with /. at the end if ($path === substr($pattern, 0, strlen($pattern) - 2)) { $config->extend($overrides); } } else { if ($path === $pattern || strpos($path, $pattern . '/') === 0) { // Directory path $config->extend($overrides); } } } } } } } return $config; }