/** * @brief Delete a Mozilla Sync user. * * DELETE https://server/pathname/version/username * * Deletes the user account. * NOTE: Requires simple authentication with the username and password associated with the account. * * Return value: * 0 on success * * Possible errors: * 503: there was an error removing the user * 404: the user does not exist in the database * 401: authentication failed * * @param string $syncHash Mozilla Sync user hash of the user to be deleted. */ private function deleteUser($syncHash) { if (User::isAutoCreateUser()) { //auto create accounts only Utils::changeHttpStatus(Utils::STATUS_INVALID_USER); Utils::writeLog("Failed to delete user " . $syncHash . ". Delete disabled"); } if (User::syncUserExists($syncHash) === false) { Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND); Utils::writeLog("Failed to delete user " . $syncHash . ". User does not exist."); } if (User::authenticateUser($syncHash) === false) { Utils::changeHttpStatus(Utils::STATUS_INVALID_USER); Utils::writeLog("Authentication for deleting user " . $syncHash . " failed."); } $syncId = User::syncHashToSyncId($syncHash); if ($syncId === false) { Utils::changeHttpStatus(Utils::STATUS_INVALID_USER); Utils::writeLog("Failed to convert user " . $syncHash . " to Sync ID."); } if (Storage::deleteStorage($syncId) === false) { Utils::changeHttpStatus(Utils::STATUS_MAINTENANCE); Utils::writeLog("Failed to delete storage for user " . $syncId . "."); } if (User::deleteUser($syncId) === false) { Utils::changeHttpStatus(Utils::STATUS_MAINTENANCE); Utils::writeLog("Failed to delete user " . $syncId . "."); } OutputData::write('0'); }
/** * @brief Run storage service. * * @return True on successful command parsing, false otherwise. */ public function run() { // Check if given url is valid if (!$this->urlParser->isValid()) { Utils::changeHttpStatus(Utils::STATUS_INVALID_DATA); Utils::writeLog("URL: Invalid URL."); return false; } // Get Mozilla Sync user hash and authenticate user $syncHash = $this->urlParser->getSyncHash(); if (User::isAutoCreateUser() && !User::hasSyncAccount($syncHash)) { if (User::authenticateUser($syncHash, false) === false) { Utils::changeHttpStatus(Utils::STATUS_INVALID_USER); Utils::writeLog("Couldn't autocreate account for user " . $syncHash . " authentication failed."); return false; } //auto create account User::autoCreateUser($syncHash); } if (User::authenticateUser($syncHash) === false) { Utils::changeHttpStatus(Utils::STATUS_INVALID_USER); Utils::writeLog("Could not authenticate user " . $syncHash . "."); return false; } // Convert Sync hash to Sync ID $syncId = User::syncHashToSyncId($syncHash); if ($syncId === false) { Utils::changeHttpStatus(Utils::STATUS_INVALID_USER); Utils::writeLog("Could not convert user " . $syncHash . " to Sync ID."); return false; } // Delete old WBO on every run of storage service Storage::deleteOldWbo(); // Map request to functions // Info case: https://server/pathname/version/username/info/ if ($this->urlParser->commandCount() === 2 && $this->urlParser->getCommand(0) === 'info') { if (Utils::getRequestMethod() != 'GET') { Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND); Utils::writeLog("URL: Invalid HTTP method " . Utils::getRequestMethod() . " for info."); return false; } switch ($this->urlParser->getCommand(1)) { case 'collections': $this->getInfoCollections($syncId); break; case 'collection_usage': $this->getInfoCollectionUsage($syncId); break; case 'collection_counts': $this->getInfoCollectionCounts($syncId); break; case 'quota': $this->getInfoQuota($syncId); break; default: Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND); Utils::writeLog("URL: Invalid command " . $this->urlParser->getCommand(1) . " for info."); return false; } } else { if ($this->urlParser->commandCount() === 1 && $this->urlParser->getCommand(0) === 'storage') { switch (Utils::getRequestMethod()) { case 'DELETE': $this->deleteStorage($syncId); break; default: Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND); Utils::writeLog("URL: Invalid request method " . Utils::getRequestMethod() . " for storage."); return false; } } else { if ($this->urlParser->commandCount() === 2 && $this->urlParser->getCommand(0) === 'storage') { $collectionName = $this->urlParser->getCommand(1); $modifiers = $this->urlParser->getCommandModifiers(); $collectionId = Storage::collectionNameToIndex($syncId, $collectionName); switch (Utils::getRequestMethod()) { case 'GET': $this->getCollection($syncId, $collectionId, $modifiers); break; case 'POST': $this->postCollection($syncId, $collectionId); break; case 'DELETE': $this->deleteCollection($syncId, $collectionId, $modifiers); break; default: Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND); Utils::writeLog("URL: Invalid request method" . Utils::getRequestMethod() . " for collection."); return false; } } else { if ($this->urlParser->commandCount() === 3 && $this->urlParser->getCommand(0) === 'storage') { $collectionName = $this->urlParser->getCommand(1); $wboId = $this->urlParser->getCommand(2); $collectionId = Storage::collectionNameToIndex($syncId, $collectionName); switch (Utils::getRequestMethod()) { case 'GET': $this->getWBO($syncId, $collectionId, $wboId); break; case 'PUT': $this->putWBO($syncId, $collectionId, $wboId); break; case 'DELETE': $this->deleteWBO($syncId, $collectionId, $wboId); break; default: Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND); Utils::writeLog("URL: Invalid request method" . Utils::getRequestMethod() . " for WBO."); return false; } } else { Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND); Utils::writeLog("URL: Invalid storage service request. Sent " . (string) $this->urlParser->commandCount() . " commands in URL\t" . Utils::getSyncUrl() . ": " . var_export($this->urlParser->getCommands(), true)); return false; } } } } return true; }