From c266b003fb0525202b15c0e4d6675d0d3cd8428e Mon Sep 17 00:00:00 2001 From: Kalila L Date: Fri, 10 Sep 2021 02:06:50 -0400 Subject: [PATCH] Get Domain creation working; revise metaverse forwarding. (TLS init fail issue present) --- .../components/login/MetaverseLogin.vue | 6 +- .../src/pages/FirstTimeWizard/Index.vue | 136 ++++++++++++++++-- domain-server/src/DomainServer.cpp | 55 ++++--- domain-server/src/DomainServer.h | 1 + .../embedded-webserver/src/HTTPConnection.cpp | 4 +- 5 files changed, 168 insertions(+), 34 deletions(-) diff --git a/domain-server/resources/web/web-new/src/components/components/login/MetaverseLogin.vue b/domain-server/resources/web/web-new/src/components/components/login/MetaverseLogin.vue index b9c5bf9dfd..3fe58121d3 100644 --- a/domain-server/resources/web/web-new/src/components/components/login/MetaverseLogin.vue +++ b/domain-server/resources/web/web-new/src/components/components/login/MetaverseLogin.vue @@ -73,10 +73,10 @@ export default { methods: { async onSubmit () { - const metaverseURL = await this.retrieveMetaverseUrl(); - const result = await this.attemptLogin(metaverseURL, this.username, this.password); + const metaverseUrl = await this.retrieveMetaverseUrl(); + const result = await this.attemptLogin(metaverseUrl, this.username, this.password); - this.$emit("loginResult", { "success": result.success, "metaverse": metaverseURL, "data": result.response }); + this.$emit("loginResult", { "success": result.success, "metaverse": metaverseUrl, "data": result.response }); }, // TODO: This needs to be addressed in a more modular fashion to reuse and save state across multiple components. diff --git a/domain-server/resources/web/web-new/src/pages/FirstTimeWizard/Index.vue b/domain-server/resources/web/web-new/src/pages/FirstTimeWizard/Index.vue index 8faa567fbb..77fb061645 100644 --- a/domain-server/resources/web/web-new/src/pages/FirstTimeWizard/Index.vue +++ b/domain-server/resources/web/web-new/src/pages/FirstTimeWizard/Index.vue @@ -232,7 +232,7 @@ {{ connectMetaverseSuccess ? 'Connected' : 'Connect' }} + + +
Let's give your Domain a label.
+
This is to help you identify your Domains in your Metaverse account.
+
+ + + + + + + + Next + + + Back + + +
+ + + Let's configure some security settings for your world. - +
Who should be an in-world admin of your Domain?
{ + Log.info(Log.types.METAVERSE, "Successfully configured Domain with Metaverse."); + console.info("received", response); + const settingsToCommit = { + "metaverse": { + "automatic_networking": "full", + "id": response.data.domain.domainId + }, + "descriptors": { + "world_name": this.domainLabel + } + }; + + this.commitMetaverseConfig(settingsToCommit); + }) + .catch((error) => { + Log.error(Log.types.METAVERSE, `Failed to configure Domain with Metaverse: ${error}`); + this.$q.notify({ + type: "negative", + textColor: "white", + icon: "warning", + message: `Failed to label your Domain on the Metaverse: ${error}` + }); + }); + }, + + async commitMetaverseConfig (jsonToCommit) { + const committed = await this.commitSettings(jsonToCommit); + + if (committed === true) { + Log.info(Log.types.METAVERSE, "Successfully committed Domain server config for the Metaverse."); + this.$q.notify({ + type: "positive", + textColor: "white", + icon: "cloud_done", + message: "Successfully labeled your Domain on your Metaverse account." + }); + } else { + Log.error(Log.types.METAVERSE, "Failed to configure server with Metaverse: Could not commit config to settings."); + this.$q.notify({ + type: "negative", + textColor: "white", + icon: "warning", + message: "Domain label with Metaverse attempt failed because the settings were unable to be saved." + }); + } + }, + async saveSecuritySettings () { const friendsCanConnect = this.connectionSecurityModel.includes("friends"); const friendsCanRez = this.rezSecurityModel.includes("friends"); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 4a4bc2fe33..a3e0879930 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -87,6 +87,7 @@ QString DomainServer::_userConfigFilename; int DomainServer::_parentPID { -1 }; bool DomainServer::forwardMetaverseAPIRequest(HTTPConnection* connection, + const QUrl& requestUrl, const QString& metaversePath, const QString& requestSubobjectKey, std::initializer_list requiredData, @@ -101,23 +102,43 @@ bool DomainServer::forwardMetaverseAPIRequest(HTTPConnection* connection, QJsonObject subobject; - auto params = connection->parseUrlEncodedForm(); + if (requestUrl.hasQuery()) { + QUrlQuery query(requestUrl); - for (auto& key : requiredData) { - auto it = params.find(key); - if (it == params.end()) { - auto error = "Bad request, expected param '" + key + "'"; - connection->respond(HTTPConnection::StatusCode400, error.toLatin1()); - return true; + for (auto& key : requiredData) { + if (query.hasQueryItem(key)) { + subobject.insert(key, query.queryItemValue(key)); + } else { + auto error = "Domain Server: Bad request, expected param '" + key + "'"; + connection->respond(HTTPConnection::StatusCode400, error.toLatin1()); + return true; + } } - subobject.insert(key, it.value()); - } - for (auto& key : optionalData) { - auto it = params.find(key); - if (it != params.end()) { + for (auto& key : optionalData) { + if (query.hasQueryItem(key)) { + subobject.insert(key, query.queryItemValue(key)); + } + } + } else { + auto params = connection->parseUrlEncodedForm(); + + for (auto& key : requiredData) { + auto it = params.find(key); + if (it == params.end()) { + auto error = "Domain Server: Bad request, expected param '" + key + "'"; + connection->respond(HTTPConnection::StatusCode400, error.toLatin1()); + return true; + } subobject.insert(key, it.value()); } + + for (auto& key : optionalData) { + auto it = params.find(key); + if (it != params.end()) { + subobject.insert(key, it.value()); + } + } } QJsonObject root; @@ -2296,12 +2317,12 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url return true; } else if (url.path() == URI_API_DOMAINS) { - return forwardMetaverseAPIRequest(connection, "/api/v1/domains", ""); + return forwardMetaverseAPIRequest(connection, url, "/api/v1/domains", ""); } else if (url.path().startsWith(URI_API_DOMAINS_ID)) { auto id = url.path().mid(URI_API_DOMAINS_ID.length()); - return forwardMetaverseAPIRequest(connection, "/api/v1/domains/" + id, "", {}, {}, false); + return forwardMetaverseAPIRequest(connection, url, "/api/v1/domains/" + id, "", {}, {}, false); } else if (url.path() == URI_API_PLACES) { - return forwardMetaverseAPIRequest(connection, "/api/v1/user/places", ""); + return forwardMetaverseAPIRequest(connection, url, "/api/v1/user/places", ""); } else { // check if this is for json stats for a node const QString NODE_JSON_REGEX_STRING = QString("\\%1\\/(%2).json\\/?$").arg(URI_NODES).arg(UUID_REGEX_STRING); @@ -2438,7 +2459,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url } } else if (url.path() == URI_API_DOMAINS) { - return forwardMetaverseAPIRequest(connection, "/api/v1/domains", "domain", { "label" }); + return forwardMetaverseAPIRequest(connection, url, "/api/v1/domains", "domain", { "label" }); } else if (url.path().startsWith(URI_API_BACKUPS_RECOVER)) { auto id = url.path().mid(QString(URI_API_BACKUPS_RECOVER).length()); @@ -2465,7 +2486,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url return true; } auto domainID = domainSetting.toString(); - return forwardMetaverseAPIRequest(connection, "/api/v1/domains/" + domainID, "domain", + return forwardMetaverseAPIRequest(connection, url, "/api/v1/domains/" + domainID, "domain", { }, { "network_address", "network_port", "label" }); } else if (url.path() == URI_API_PLACES) { auto accessTokenVariant = _settingsManager.valueForKeyPath(ACCESS_TOKEN_KEY_PATH); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index deb204de1c..d0b350fb7a 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -228,6 +228,7 @@ private: bool processPendingContent(HTTPConnection* connection, QString itemName, QString filename, QByteArray dataChunk); bool forwardMetaverseAPIRequest(HTTPConnection* connection, + const QUrl& requestUrl, const QString& metaversePath, const QString& requestSubobject, std::initializer_list requiredData = { }, diff --git a/libraries/embedded-webserver/src/HTTPConnection.cpp b/libraries/embedded-webserver/src/HTTPConnection.cpp index 5932c7ed56..f5f0fe0289 100644 --- a/libraries/embedded-webserver/src/HTTPConnection.cpp +++ b/libraries/embedded-webserver/src/HTTPConnection.cpp @@ -176,7 +176,7 @@ QList HTTPConnection::parseFormData() const { break; } } - + QByteArray start = "--" + boundary; QByteArray end = "\r\n--" + boundary + "--\r\n"; @@ -394,6 +394,6 @@ void HTTPConnection::readContent() { if (_requestContent->bytesLeftToWrite() == 0) { _socket->disconnect(this, SLOT(readContent())); - _parentManager->handleHTTPRequest(this, _requestUrl.path()); + _parentManager->handleHTTPRequest(this, _requestUrl); } }