function clearExpiredFiles() { $files = glob(PUBLIC_DOWNLOAD_FOLDER . "/*.php"); $loggedUser = AuthService::getLoggedUser(); $userId = $loggedUser->getId(); $deleted = array(); foreach ($files as $file) { $publicletData = $this->loadPublicletData($file); if (!isset($publicletData["OWNER_ID"]) || $publicletData["OWNER_ID"] != $userId) { continue; } if (isset($publicletData["EXPIRE_TIME"]) && is_numeric($publicletData["EXPIRE_TIME"]) && $publicletData["EXPIRE_TIME"] > 0 && $publicletData["EXPIRE_TIME"] < time()) { unlink($file); $deleted[] = basename($file); require_once INSTALL_PATH . "/server/classes/class.PublicletCounter.php"; PublicletCounter::delete(str_replace(".php", "", basename($file))); } } return $deleted; }
/** * @param String $type * @param String $element * @throws Exception * @return bool */ public function deleteShare($type, $element) { $mess = ConfService::getMessages(); AJXP_Logger::debug(__CLASS__, __FILE__, "Deleting shared element " . $type . "-" . $element); if ($type == "repository") { if (strpos($element, "repo-") === 0) { $element = str_replace("repo-", "", $element); } $repo = ConfService::getRepositoryById($element); if ($repo == null) { // Maybe a share has $share = $this->loadShare($element); if (is_array($share) && isset($share["REPOSITORY"])) { $repo = ConfService::getRepositoryById($share["REPOSITORY"]); } if ($repo == null) { throw new Exception("Cannot find associated share"); } $element = $share["REPOSITORY"]; } $this->testUserCanEditShare($repo->getOwner()); $res = ConfService::deleteRepository($element); if ($res == -1) { throw new Exception($mess[427]); } if ($this->sqlSupported) { if (isset($share)) { $this->confStorage->simpleStoreClear("share", $element); } else { $shares = self::findSharesForRepo($element); if (count($shares)) { $keys = array_keys($shares); $this->confStorage->simpleStoreClear("share", $keys[0]); } } } } else { if ($type == "minisite") { $minisiteData = $this->loadShare($element); $repoId = $minisiteData["REPOSITORY"]; $repo = ConfService::getRepositoryById($repoId); if ($repo == null) { return false; } $this->testUserCanEditShare($repo->getOwner()); $res = ConfService::deleteRepository($repoId); if ($res == -1) { throw new Exception($mess[427]); } // Silently delete corresponding role if it exists AuthService::deleteRole("AJXP_SHARED-" . $repoId); // If guest user created, remove it now. if (isset($minisiteData["PRELOG_USER"]) && AuthService::userExists($minisiteData["PRELOG_USER"])) { AuthService::deleteUser($minisiteData["PRELOG_USER"]); } // If guest user created, remove it now. if (isset($minisiteData["PRESET_LOGIN"]) && AuthService::userExists($minisiteData["PRESET_LOGIN"])) { AuthService::deleteUser($minisiteData["PRESET_LOGIN"]); } if (isset($minisiteData["PUBLICLET_PATH"]) && is_file($minisiteData["PUBLICLET_PATH"])) { unlink($minisiteData["PUBLICLET_PATH"]); } else { if ($this->sqlSupported) { $this->confStorage->simpleStoreClear("share", $element); } } } else { if ($type == "user") { $this->testUserCanEditShare($element); AuthService::deleteUser($element); } else { if ($type == "file") { $publicletData = $this->loadShare($element); if (isset($publicletData["OWNER_ID"]) && $this->testUserCanEditShare($publicletData["OWNER_ID"])) { PublicletCounter::delete($element); if (isset($publicletData["PUBLICLET_PATH"]) && is_file($publicletData["PUBLICLET_PATH"])) { unlink($publicletData["PUBLICLET_PATH"]); } else { if ($this->sqlSupported) { $this->confStorage->simpleStoreClear("share", $element); } } } else { throw new Exception($mess["share_center.160"]); } } } } } }
public function clearExpiredFiles() { $files = glob(ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER") . "/*.php"); $loggedUser = AuthService::getLoggedUser(); $userId = $loggedUser->getId(); $deleted = array(); foreach ($files as $file) { $ar = explode(".", basename($file)); $id = array_shift($ar); if (strlen($id) != 32) { continue; } $publicletData = ShareCenter::loadPublicletData($id); if (!isset($publicletData["OWNER_ID"]) || $publicletData["OWNER_ID"] != $userId) { continue; } if (isset($publicletData["EXPIRE_TIME"]) && is_numeric($publicletData["EXPIRE_TIME"]) && $publicletData["EXPIRE_TIME"] > 0 && $publicletData["EXPIRE_TIME"] < time() || isset($publicletData["DOWNLOAD_LIMIT"]) && $publicletData["DOWNLOAD_LIMIT"] > 0 && $publicletData["DOWNLOAD_LIMIT"] <= $publicletData["DOWNLOAD_COUNT"]) { unlink($file); $deleted[] = basename($file); PublicletCounter::delete(str_replace(".php", "", basename($file))); } } return $deleted; }
/** * @static * @param String $type * @param String $element * @param AbstractAjxpUser $loggedUser * @throws Exception */ public static function deleteSharedElement($type, $element, $loggedUser) { $mess = ConfService::getMessages(); AJXP_Logger::debug($type . "-" . $element); if ($type == "repository") { $repo = ConfService::getRepositoryById($element); if ($repo == null) { return; } if (!$repo->hasOwner() || $repo->getOwner() != $loggedUser->getId()) { throw new Exception($mess["ajxp_shared.12"]); } else { $res = ConfService::deleteRepository($element); if ($res == -1) { throw new Exception($mess["ajxp_conf.51"]); } } } else { if ($type == "minisite") { $minisiteData = self::loadPublicletData($element); $repoId = $minisiteData["REPOSITORY"]; $repo = ConfService::getRepositoryById($repoId); if ($repo == null) { return false; } if (!$repo->hasOwner() || $repo->getOwner() != $loggedUser->getId()) { throw new Exception($mess["ajxp_shared.12"]); } else { $res = ConfService::deleteRepository($repoId); if ($res == -1) { throw new Exception($mess["ajxp_conf.51"]); } // Silently delete corresponding role if it exists AuthService::deleteRole("AJXP_SHARED-" . $repoId); // If guest user created, remove it now. if (isset($minisiteData["PRELOG_USER"])) { AuthService::deleteUser($minisiteData["PRELOG_USER"]); } unlink($minisiteData["PUBLICLET_PATH"]); } } else { if ($type == "user") { $confDriver = ConfService::getConfStorageImpl(); $object = $confDriver->createUserObject($element); if (!$object->hasParent() || $object->getParent() != $loggedUser->getId()) { throw new Exception($mess["ajxp_shared.12"]); } else { AuthService::deleteUser($element); } } else { if ($type == "file") { $publicletData = self::loadPublicletData($element); if (isset($publicletData["OWNER_ID"]) && $publicletData["OWNER_ID"] == $loggedUser->getId()) { PublicletCounter::delete($element); unlink($publicletData["PUBLICLET_PATH"]); } else { throw new Exception($mess["ajxp_shared.12"]); } } } } } }
/** Load a uncyphered publiclet */ function loadPubliclet($data) { // create driver from $data $className = $data["DRIVER"] . "AccessDriver"; if ($data["EXPIRE_TIME"] && time() > $data["EXPIRE_TIME"]) { // Remove the publiclet, it's done if (strstr(realpath($_SERVER["SCRIPT_FILENAME"]), realpath(PUBLIC_DOWNLOAD_FOLDER)) !== FALSE) { $hash = md5(serialize($data)); require_once INSTALL_PATH . "/server/classes/class.PublicletCounter.php"; PublicletCounter::delete($hash); unlink($_SERVER["SCRIPT_FILENAME"]); } echo "Link is expired, sorry."; exit; } // Check password if (strlen($data["PASSWORD"])) { if (!isset($_POST['password']) || $_POST['password'] != $data["PASSWORD"]) { $content = file_get_contents(INSTALL_PATH . "/client/html/public_links.html"); $language = "en"; if (isset($_GET["lang"])) { $language = $_GET["lang"]; } $messages = array(); if (is_file(INSTALL_PATH . "/client/i18n/{$language}.php")) { include INSTALL_PATH . "/client/i18n/{$language}.php"; $messages = $mess; } if (preg_match_all("/AJXP_MESSAGE(\\[.*?\\])/", $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $messId = str_replace("]", "", str_replace("[", "", $match[1])); if (isset($messages[$messId])) { $content = str_replace("AJXP_MESSAGE[{$messId}]", $messages[$messId], $content); } } } echo $content; exit(1); } } $filePath = INSTALL_PATH . "/plugins/access." . $data["DRIVER"] . "/class." . $className . ".php"; if (!is_file($filePath)) { die("Warning, cannot find driver for conf storage! ({$name}, {$filePath})"); } require_once $filePath; $driver = new $className($data["PLUGIN_ID"], $data["BASE_DIR"]); $driver->loadManifest(); $driver->init($data["REPOSITORY"], $data["OPTIONS"]); ConfService::setRepository($data["REPOSITORY"]); $driver->initRepository(); // Increment counter $hash = md5(serialize($data)); require_once INSTALL_PATH . "/server/classes/class.PublicletCounter.php"; PublicletCounter::increment($hash); // Now call switchAction //@todo : switchAction should not be hard coded here!!! // Re-encode file-path as it will be decoded by the action. try { $driver->switchAction($data["ACTION"], array("file" => SystemTextEncoding::toUTF8($data["FILE_PATH"])), ""); } catch (Exception $e) { die($e->getMessage()); } }
/** * @static * @param String $type * @param String $element * @param AbstractAjxpUser $loggedUser * @return void */ public static function deleteSharedElement($type, $element, $loggedUser) { $mess = ConfService::getMessages(); if ($type == "repository") { $repo = ConfService::getRepositoryById($element); if (!$repo->hasOwner() || $repo->getOwner() != $loggedUser->getId()) { throw new Exception($mess["ajxp_shared.12"]); } else { $res = ConfService::deleteRepository($element); if ($res == -1) { throw new Exception($mess["ajxp_conf.51"]); } } } else { if ($type == "user") { $confDriver = ConfService::getConfStorageImpl(); $object = $confDriver->createUserObject($element); if (!$object->hasParent() || $object->getParent() != $loggedUser->getId()) { throw new Exception($mess["ajxp_shared.12"]); } else { AuthService::deleteUser($element); } } else { if ($type == "file") { $publicletData = self::loadPublicletData($element); if (isset($publicletData["OWNER_ID"]) && $publicletData["OWNER_ID"] == $loggedUser->getId()) { PublicletCounter::delete($element); unlink($publicletData["PUBLICLET_PATH"]); } else { throw new Exception($mess["ajxp_shared.12"]); } } } } }