protected function loadPublicletData($file) { $lines = file($file); $id = str_replace(".php", "", basename($file)); $code = $lines[3] . $lines[4] . $lines[5]; eval($code); $dataModified = md5($inputData) != $id; $publicletData = unserialize($inputData); $publicletData["SECURITY_MODIFIED"] = $dataModified; require_once INSTALL_PATH . "/server/classes/class.PublicletCounter.php"; $publicletData["DOWNLOAD_COUNT"] = PublicletCounter::getCount($id); return $publicletData; }
/** * Find all expired shares and remove them. * @param bool|true $currentUser * @return array */ public function clearExpiredFiles($currentUser = true) { if ($currentUser) { $loggedUser = AuthService::getLoggedUser(); $userId = $loggedUser->getId(); $originalUser = null; } else { $originalUser = AuthService::getLoggedUser()->getId(); $userId = null; } $deleted = array(); $switchBackToOriginal = false; $publicLets = $this->listShares($currentUser ? $userId : ''); foreach ($publicLets as $hash => $publicletData) { if ($publicletData === false) { continue; } if ($currentUser && (!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"] <= PublicletCounter::getCount($hash)) { if (!$currentUser) { $switchBackToOriginal = true; } $this->deleteExpiredPubliclet($hash, $publicletData); $deleted[] = $publicletData["FILE_PATH"]; } } if ($switchBackToOriginal) { AuthService::logUser($originalUser, "", true); } return $deleted; }
public function resetDownloadCounter($hash, $userId) { $data = $this->loadShare($hash); $repoId = $data["REPOSITORY"]; $repo = ConfService::getRepositoryById($repoId); if ($repo == null) { throw new Exception("Cannot find associated share"); } $this->testUserCanEditShare($repo->getOwner()); PublicletCounter::reset($hash); }
public static function loadPublicletData($id) { $dlFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"); $file = $dlFolder . "/" . $id . ".php"; if (!is_file($file)) { return array(); } $lines = file($file); $inputData = ''; $code = $lines[3] . $lines[4] . $lines[5]; eval($code); $dataModified = self::checkHash($inputData, $id); //(md5($inputData) != $id); $publicletData = unserialize($inputData); $publicletData["SECURITY_MODIFIED"] = $dataModified; if (!isset($publicletData["REPOSITORY"])) { $publicletData["DOWNLOAD_COUNT"] = PublicletCounter::getCount($id); } $publicletData["PUBLICLET_PATH"] = $file; return $publicletData; }
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; }
/** 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()); } }
public function switchAction($action, $httpVars, $fileVars) { parent::accessPreprocess($action, $httpVars, $fileVars); $loggedUser = AuthService::getLoggedUser(); if (!AuthService::usersEnabled()) { return; } if ($action == "edit") { if (isset($httpVars["sub_action"])) { $action = $httpVars["sub_action"]; } } $mess = ConfService::getMessages(); switch ($action) { //------------------------------------ // BASIC LISTING //------------------------------------ case "ls": $rootNodes = array("users" => array("LABEL" => $mess["user_dash.1"], "ICON" => "user_shared.png", "ICON-CLASS" => "icon-book", "DESCRIPTION" => $mess["user_dash.30"]), "files" => array("LABEL" => $mess["user_dash.34"], "ICON" => "user_shared.png", "ICON-CLASS" => "icon-share", "DESCRIPTION" => $mess["user_dash.35"]), "settings" => array("LABEL" => $mess["user_dash.36"], "ICON" => "user_shared.png", "ICON-CLASS" => "icon-cog", "DESCRIPTION" => $mess["user_dash.37"]), "repositories" => array("LABEL" => $mess["user_dash.36"], "ICON" => "user_shared.png", "ICON-CLASS" => "icon-cog", "DESCRIPTION" => $mess["user_dash.37"]), "teams" => array("LABEL" => "Teams", "ICON" => "user_shared.png", "ICON-CLASS" => "icon-group", "DESCRIPTION" => "My Teams")); $dir = isset($httpVars["dir"]) ? $httpVars["dir"] : ""; $splits = explode("/", $dir); if (count($splits)) { if ($splits[0] == "") { array_shift($splits); } if (count($splits)) { $strippedDir = strtolower(urldecode($splits[0])); } else { $strippedDir = ""; } } if (array_key_exists($strippedDir, $rootNodes)) { AJXP_XMLWriter::header(); if ($strippedDir == "users") { $this->listUsers(); } else { if ($strippedDir == "teams") { $this->listTeams(); } else { if ($strippedDir == "repositories") { $this->listRepositories(); } else { if ($strippedDir == "files") { $this->listSharedFiles("files"); } } } } AJXP_XMLWriter::close(); } else { AJXP_XMLWriter::header(); /* AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="user_dash.8" attributeName="ajxp_label" sortType="String"/><column messageId="user_dash.31" attributeName="description" sortType="String"/></columns>'); foreach ($rootNodes as $key => $data) { $l = $data["LABEL"]; print '<tree text="'.$l.'" icon="'.$data["ICON"].'" filename="/'.$key.'" parentname="/" description="'.$data["DESCRIPTION"].'" />'; } */ AJXP_XMLWriter::close(); } break; case "stat": header("Content-type:application/json"); print '{"mode":true}'; break; case "delete": $mime = $httpVars["ajxp_mime"]; $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); $files = $selection->getFiles(); AJXP_XMLWriter::header(); $minisites = $this->listSharedFiles("minisites"); $shareCenter = AJXP_PluginsService::findPluginById("action.share"); foreach ($files as $index => $element) { $element = basename($element); $ar = explode("shared_", $mime); $mime = array_pop($ar); if ($mime == "repository" && isset($minisites[$element])) { $mime = "minisite"; $element = $minisites[$element]; } $shareCenter->deleteSharedElement($mime, $element, $loggedUser); if ($mime == "repository" || $mime == "minisite") { $out = $mess["ajxp_conf.59"]; } else { if ($mime == "user") { $out = $mess["ajxp_conf.60"]; } else { if ($mime == "file") { $out = $mess["user_dash.13"]; } } } } AJXP_XMLWriter::sendMessage($out, null); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); break; case "clear_expired": $shareCenter = AJXP_PluginsService::getInstance()->findPluginById("action.share"); $deleted = $shareCenter->clearExpiredFiles(true); AJXP_XMLWriter::header(); if (count($deleted)) { AJXP_XMLWriter::sendMessage(sprintf($mess["user_dash.23"], count($deleted) . ""), null); AJXP_XMLWriter::reloadDataNode(); } else { AJXP_XMLWriter::sendMessage($mess["user_dash.24"], null); } AJXP_XMLWriter::close(); break; case "reset_download_counter": $selection = new UserSelection(); $selection->initFromHttpVars($httpVars); $elements = $selection->getFiles(); foreach ($elements as $element) { PublicletCounter::reset(str_replace(".php", "", basename($element))); } AJXP_XMLWriter::header(); AJXP_XMLWriter::reloadDataNode(); AJXP_XMLWriter::close(); break; default: break; } return; }
private static function saveCounters($counters) { self::$counters = $counters; AJXP_Utils::saveSerialFile(PUBLIC_DOWNLOAD_FOLDER . "/.ajxp_publiclet_counters.ser", $counters, false); }
public function resetDownloadCounter($hash, $userId) { $data = $this->loadShare($hash); // TODO We must check that the user has the right to do that! PublicletCounter::reset($hash); }
public static function loadPublicletData($id) { $dlFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER"); $file = $dlFolder . "/" . $id . ".php"; $lines = file($file); $inputData = ''; $code = $lines[3] . $lines[4] . $lines[5]; eval($code); $dataModified = md5($inputData) != $id; $publicletData = unserialize($inputData); $publicletData["SECURITY_MODIFIED"] = $dataModified; $publicletData["DOWNLOAD_COUNT"] = PublicletCounter::getCount($id); $publicletData["PUBLICLET_PATH"] = $file; return $publicletData; }