/** * Save Temporary Data. * Implementation uses serialised files because of the overhead incurred with a full db implementation. * * @param $key String key of data to save. * @param $value Value to save */ public function saveTemporaryData($key, $value) { $dirPath = $this->storage->getOption("USERS_DIRPATH"); if ($dirPath == "") { $dirPath = AJXP_INSTALL_PATH . "/data/users"; AJXP_Logger::info(__CLASS__, "setTemporaryData", array("Warning" => "The conf.sql driver is missing a mandatory option USERS_DIRPATH!")); } $id = AuthService::ignoreUserCase() ? strtolower($this->getId()) : $this->getId(); AJXP_Utils::saveSerialFile($dirPath . "/" . $id . "/temp-" . $key . ".ser", $value); }
/** * Delete a user in the auth/conf driver impl * @static * @param $userId * @return bool */ public static function deleteUser($userId) { $userId = AuthService::filterUserSensitivity($userId); AJXP_Controller::applyHook("user.before_delete", array($userId)); $authDriver = ConfService::getAuthDriverImpl(); $authDriver->deleteUser($userId); $subUsers = array(); ConfService::getConfStorageImpl()->deleteUser($userId, $subUsers); foreach ($subUsers as $deletedUser) { $authDriver->deleteUser($deletedUser); } AJXP_Controller::applyHook("user.after_delete", array($userId)); AJXP_Logger::info(__CLASS__, "Delete User", array("user_id" => $userId, "sub_user" => implode(",", $subUsers))); return true; }
/** * See static method * @param $repoId * @return int */ public function deleteRepositoryInst($repoId) { AJXP_Controller::applyHook("workspace.before_delete", array($repoId)); $confStorage = self::getConfStorageImpl(); $res = $confStorage->deleteRepository($repoId); if ($res == -1) { return $res; } AJXP_Controller::applyHook("workspace.after_delete", array($repoId)); AJXP_Logger::info(__CLASS__, "Delete Repository", array("repo_id" => $repoId)); $this->invalidateLoadedRepositories(); }
/** * See static method * @param $repoId * @return int */ public function deleteRepositoryInst($repoId) { AJXP_Controller::applyHook("workspace.before_delete", array($repoId)); $confStorage = self::getConfStorageImpl(); $shares = $confStorage->listRepositoriesWithCriteria(array("parent_uuid" => $repoId)); $toDelete = array(); foreach ($shares as $share) { $toDelete[] = $share->getId(); } $res = $confStorage->deleteRepository($repoId); if ($res == -1) { return $res; } foreach ($toDelete as $deleteId) { $this->deleteRepositoryInst($deleteId); } AJXP_Controller::applyHook("workspace.after_delete", array($repoId)); AJXP_Logger::info(__CLASS__, "Delete Repository", array("repo_id" => $repoId)); $this->invalidateLoadedRepositories(); return 0; }
private function setPTGStorage() { switch (strtolower($this->pgt_storage_mode)) { case 'file': phpCAS::setPGTStorageFile(session_save_path()); break; case 'db': $dbconfig = ConfService::getConfStorageImpl(); /** * support only for mySQL */ if ($dbconfig instanceof sqlConfDriver) { if (!empty($dbconfig->sqlDriver["username"])) { $db_username = $dbconfig->sqlDriver["username"]; $db_password = $dbconfig->sqlDriver["password"]; $db_database = "mysql:" . "dbname=" . $dbconfig->sqlDriver["database"] . ";host=" . $dbconfig->sqlDriver["host"]; $db_table = "ajxp_cas_pgt"; AJXP_Logger::info(__CLASS__, __FUNCTION__, $db_database); phpCAS::setPGTStorageDB($db_database, $db_username, $db_password, $db_table, ""); } } break; default: break; } }
public function rename($url_from, $url_to) { $url_from = smb::cleanUrl($url_from); $url_to = smb::cleanUrl($url_to); list($from, $to) = array(smb::parse_url($url_from), smb::parse_url($url_to)); if ($from['host'] != $to['host'] || $from['share'] != $to['share'] || $from['user'] != $to['user'] || $from['pass'] != $to['pass'] || $from['domain'] != $to['domain']) { trigger_error('rename(): FROM & TO must be in same server-share-user-pass-domain', E_USER_ERROR); } if ($from['type'] != 'path' || $to['type'] != 'path') { trigger_error('rename(): error in URL', E_USER_ERROR); } smb::clearstatcache($url_from); $res = smb::execute('rename "' . $from['path'] . '" "' . $to['path'] . '"', $to); if (empty($res)) { return true; } AJXP_Logger::info(__CLASS__, "SmbClient rename error: " . $res); return false; }
function macerrorSftp($packet) { AJXP_Logger::info(__CLASS__, "SSH2.FTP.macerror", ""); throw new Exception('SSH2.FTP : macerror' . $packet); }
protected function getRemoteUsers() { $result = $this->apiCall('GET', 'users'); $map = array(); foreach ($result->body as $user) { if ($user->state == 'active') { $map[$user->username] = ''; } } AJXP_Logger::info(__CLASS__ . '.getRemoteUsers', json_encode(array_keys($map)), ""); return $map; }
/** * HTTP PUT method * * This HTTP method updates a file, or creates a new one. * * If a new resource was created, a 201 Created status code should be returned. If an existing resource is updated, it's a 204 No Content * * @param string $uri * @return bool */ protected function httpPut($uri) { $body = $this->httpRequest->getBody(); // Intercepting Content-Range if ($this->httpRequest->getHeader('Content-Range')) { /** Content-Range is dangerous for PUT requests: PUT per definition stores a full resource. draft-ietf-httpbis-p2-semantics-15 says in section 7.6: An origin server SHOULD reject any PUT request that contains a Content-Range header field, since it might be misinterpreted as partial content (or might be partial content that is being mistakenly PUT as a full representation). Partial content updates are possible by targeting a separately identified resource with state that overlaps a portion of the larger resource, or by using a different method that has been specifically defined for partial updates (for example, the PATCH method defined in [RFC5789]). This clarifies RFC2616 section 9.6: The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases. OTOH is a PUT request with a Content-Range currently the only way to continue an aborted upload request and is supported by curl, mod_dav, Tomcat and others. Since some clients do use this feature which results in unexpected behaviour (cf PEAR::HTTP_WebDAV_Client 1.0.1), we reject all PUT requests with a Content-Range for now. */ throw new Exception\NotImplemented('PUT with Content-Range is not allowed.'); } // Intercepting the Finder problem if (($expected = $this->httpRequest->getHeader('X-Expected-Entity-Length')) && $expected > 0) { /** Many webservers will not cooperate well with Finder PUT requests, because it uses 'Chunked' transfer encoding for the request body. The symptom of this problem is that Finder sends files to the server, but they arrive as 0-length files in PHP. If we don't do anything, the user might think they are uploading files successfully, but they end up empty on the server. Instead, we throw back an error if we detect this. The reason Finder uses Chunked, is because it thinks the files might change as it's being uploaded, and therefore the Content-Length can vary. Instead it sends the X-Expected-Entity-Length header with the size of the file at the very start of the request. If this header is set, but we don't get a request body we will fail the request to protect the end-user. */ // Only reading first byte $firstByte = fread($body, 1); if (strlen($firstByte) !== 1) { throw new Exception\Forbidden('This server is not compatible with OS/X finder. Consider using a different WebDAV client or webserver.'); } // The body needs to stay intact, so we copy everything to a // temporary stream. $newBody = fopen('php://temp', 'r+'); fwrite($newBody, $firstByte); stream_copy_to_stream($body, $newBody); rewind($newBody); $body = $newBody; } if ($this->tree->nodeExists($uri)) { $node = $this->tree->getNodeForPath($uri); // Checking If-None-Match and related headers. if (!$this->checkPreconditions()) { return; } // If the node is a collection, we'll deny it if (!$node instanceof IFile) { throw new Exception\Conflict('PUT is not allowed on non-files.'); } if (!$this->broadcastEvent('beforeWriteContent', array($uri, $node, &$body))) { return false; } $etag = $node->put($body); $this->broadcastEvent('afterWriteContent', array($uri, $node)); $this->httpResponse->setHeader('Content-Length', '0'); if ($etag) { $this->httpResponse->setHeader('ETag', $etag); } $this->httpResponse->sendStatus(204); } else { $etag = null; // If we got here, the resource didn't exist yet. if (!$this->createFile($this->getRequestUri(), $body, $etag)) { // For one reason or another the file was not created. return; } $this->httpResponse->setHeader('Content-Length', '0'); if ($etag) { $this->httpResponse->setHeader('ETag', $etag); } $this->httpResponse->sendStatus(201); } $repositories = \ConfService::getRepositoriesList("user"); \AJXP_Logger::info(__CLASS__, "Upload", array("files" => $repositories[\ConfService::getCurrentRepositoryId()]->getSlug() . "/" . $uri)); }
/** * See static method * @param $repoId * @return int */ public function deleteRepositoryInst($repoId) { $confStorage = self::getConfStorageImpl(); $res = $confStorage->deleteRepository($repoId); if ($res == -1) { return $res; } AJXP_Logger::info(__CLASS__, "Delete Repository", array("repo_id" => $repoId)); $this->invalidateLoadedRepositories(); }