/** * @param String $action * @param Array $httpVars * @param Array $fileVars * @return String */ function authTokenActions($action, $httpVars, $fileVars) { if (AuthService::getLoggedUser() == null) { return; } $this->storage = ConfService::getConfStorageImpl(); if (!is_a($this->storage, "sqlConfDriver")) { return false; } $user = AuthService::getLoggedUser()->getId(); if (AuthService::getLoggedUser()->isAdmin() && isset($httpVars["user_id"])) { $user = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS); } switch ($action) { case "keystore_generate_auth_token": if (ConfService::getCoreConf("SESSION_SET_CREDENTIALS", "auth")) { $this->logDebug("Keystore Generate Tokens", "Session Credentials set: returning empty tokens to force basic authentication"); HTMLWriter::charsetHeader("text/plain"); echo ""; break; } $token = AJXP_Utils::generateRandomString(); $private = AJXP_Utils::generateRandomString(); $data = array("USER_ID" => $user, "PRIVATE" => $private); if (!empty($httpVars["device"])) { // Revoke previous tokens for this device $device = $httpVars["device"]; $keys = $this->storage->simpleStoreList("keystore", null, "", "serial", '%"DEVICE_ID";s:' . strlen($device) . ':"' . $device . '"%'); foreach ($keys as $keyId => $keyData) { if ($keyData["USER_ID"] != $user) { continue; } $this->storage->simpleStoreClear("keystore", $keyId); } $data["DEVICE_ID"] = $device; } $data["DEVICE_UA"] = $_SERVER['HTTP_USER_AGENT']; $data["DEVICE_IP"] = $_SERVER['REMOTE_ADDR']; $this->storage->simpleStoreSet("keystore", $token, $data, "serial"); HTMLWriter::charsetHeader("application/json"); echo json_encode(array("t" => $token, "p" => $private)); break; case "keystore_revoke_tokens": // Invalidate previous tokens $mess = ConfService::getMessages(); $passedKeyId = ""; if (isset($httpVars["key_id"])) { $passedKeyId = $httpVars["key_id"]; } $keys = $this->storage->simpleStoreList("keystore", null, $passedKeyId, "serial", '%"USER_ID";s:' . strlen($user) . ':"' . $user . '"%'); foreach ($keys as $keyId => $keyData) { $this->storage->simpleStoreClear("keystore", $keyId); } $message = array("result" => "SUCCESS", "message" => $mess["keystore.8"]); HTMLWriter::charsetHeader("application/json"); echo json_encode($message); break; case "keystore_list_tokens": if (!isset($user)) { break; } $keys = $this->storage->simpleStoreList("keystore", null, "", "serial", '%"USER_ID";s:' . strlen($user) . ':"' . $user . '"%'); foreach ($keys as $keyId => &$keyData) { unset($keyData["PRIVATE"]); unset($keyData["USER_ID"]); $deviceDesc = "Web Browser"; $deviceOS = "Unkown"; if (isset($keyData["DEVICE_UA"])) { $agent = $keyData["DEVICE_UA"]; if (strpos($agent, "python-requests") !== false) { $deviceDesc = "PydioSync"; if (strpos($agent, "Darwin") !== false) { $deviceOS = "Mac OS X"; } else { if (strpos($agent, "Windows/7") !== false) { $deviceOS = "Windows 7"; } else { if (strpos($agent, "Windows/8") !== false) { $deviceOS = "Windows 8"; } else { if (strpos($agent, "Linux") !== false) { $deviceOS = "Linux"; } } } } } else { $deviceOS = AJXP_Utils::osFromUserAgent($agent); } } $keyData["DEVICE_DESC"] = $deviceDesc; $keyData["DEVICE_OS"] = $deviceOS; } header("Content-type: application/json;"); echo json_encode($keys); break; default: break; } return null; }
/** * @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"]); } } } } } }
/** * Delete an existing remote share * @param RemoteShare $remoteShare * @return bool */ public function deleteRemoteShare(RemoteShare $remoteShare) { $this->storage->simpleStoreClear(OCS_SQLSTORE_NS_REMOTE_SHARE, $remoteShare->getId()); return true; }