protected function findAvailableID($namespace) { $id = 0; while (true) { $id = rand(); $this->storage->simpleStoreGet($namespace, $id, OCS_SQLSTORE_FORMAT, $data); if (empty($data)) { break; } } return $id; }
function tryToLogUser(&$httpVars, $isLast = false) { $token = $this->detectVar($httpVars, "auth_token"); if (empty($token)) { //$this->logDebug(__FUNCTION__, "Empty token", $_POST); return false; } $this->storage = ConfService::getConfStorageImpl(); if (!is_a($this->storage, "sqlConfDriver")) { return false; } $data = null; $this->storage->simpleStoreGet("keystore", $token, "serial", $data); if (empty($data)) { //$this->logDebug(__FUNCTION__, "Cannot find token in keystore"); return false; } //$this->logDebug(__FUNCTION__, "Found token in keystore"); $userId = $data["USER_ID"]; $private = $data["PRIVATE"]; $explode = explode("?", $_SERVER["REQUEST_URI"]); $server_uri = rtrim(array_shift($explode), "/"); $decoded = array_map("urldecode", explode("/", $server_uri)); $decoded = array_map(array("SystemTextEncoding", "toUTF8"), $decoded); $decoded = array_map("rawurlencode", $decoded); $server_uri = implode("/", $decoded); $server_uri = str_replace("~", "%7E", $server_uri); //$this->logDebug(__FUNCTION__, "Decoded URI is ".$server_uri); list($nonce, $hash) = explode(":", $this->detectVar($httpVars, "auth_hash")); //$this->logDebug(__FUNCTION__, "Nonce / hash is ".$nonce.":".$hash); $replay = hash_hmac("sha256", $server_uri . ":" . $nonce . ":" . $private, $token); //$this->logDebug(__FUNCTION__, "Replay is ".$replay); if ($replay == $hash) { $res = AuthService::logUser($userId, "", true); if ($res > 0) { return true; } } return false; }
/** * @param String $type * @param String $element * @return bool */ public function shareExists($type, $element) { if ($type == "repository") { return ConfService::getRepositoryById($element) != null; } else { if ($type == "file" || $type == "minisite") { $fileExists = is_file($this->downloadFolder . "/" . $element . ".php"); if ($fileExists) { return true; } if ($this->sqlSupported) { $this->confStorage->simpleStoreGet("share", $element, "serial", $data); if (is_array($data)) { return true; } } return false; } } }