diff --git a/domain-server/resources/web/index.shtml b/domain-server/resources/web/index.shtml index 29c39f6c02..bba4dc4d22 100644 --- a/domain-server/resources/web/index.shtml +++ b/domain-server/resources/web/index.shtml @@ -1,5 +1,9 @@

Nodes

+
+ diff --git a/domain-server/resources/web/js/tables.js b/domain-server/resources/web/js/tables.js index ae5095592b..18e67ac6e7 100644 --- a/domain-server/resources/web/js/tables.js +++ b/domain-server/resources/web/js/tables.js @@ -49,4 +49,18 @@ $(document).ready(function(){ } }); }); + + $(document.body).on('click', '#kill-all-btn', function() { + var confirmed_kill = confirm("Are you sure?"); + + if (confirmed_kill == true) { + $.ajax({ + url: "/nodes/", + type: 'DELETE', + success: function(result) { + console.log("Successful request to delete all nodes."); + } + }); + } + }); }); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 913ca44e12..035e6c9a20 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -657,6 +657,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url const QString URI_ASSIGNMENT = "/assignment"; const QString URI_NODES = "/nodes"; + const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"; + if (connection->requestOperation() == QNetworkAccessManager::GetOperation) { if (url.path() == "/assignments.json") { // user is asking for json list of assignments @@ -726,9 +728,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url return true; } else { - const QString NODE_REGEX_STRING = - QString("\\%1\\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).json\\/?$").arg(URI_NODES); - QRegExp nodeShowRegex(NODE_REGEX_STRING); + const QString NODE_JSON_REGEX_STRING = QString("\\%1\\/(%2).json\\/?$").arg(URI_NODES).arg(UUID_REGEX_STRING); + QRegExp nodeShowRegex(NODE_JSON_REGEX_STRING); if (nodeShowRegex.indexIn(url.path()) != -1) { QUuid matchingUUID = QUuid(nodeShowRegex.cap(1)); @@ -801,29 +802,35 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url return true; } } else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) { - if (url.path().startsWith(URI_NODES)) { - // this is a request to DELETE a node by UUID + const QString ALL_NODE_DELETE_REGEX_STRING = QString("\\%1\\/?$").arg(URI_NODES); + const QString NODE_DELETE_REGEX_STRING = QString("\\%1\\/(%2)\\/$").arg(URI_NODES).arg(UUID_REGEX_STRING); + + QRegExp allNodesDeleteRegex(ALL_NODE_DELETE_REGEX_STRING); + QRegExp nodeDeleteRegex(NODE_DELETE_REGEX_STRING); + + if (nodeDeleteRegex.indexIn(url.path()) != -1) { + // this is a request to DELETE one node by UUID - // pull the UUID from the url - QUuid deleteUUID = QUuid(url.path().mid(URI_NODES.size() + sizeof('/'))); + // pull the captured string, if it exists + QUuid deleteUUID = QUuid(nodeDeleteRegex.cap(1)); - if (!deleteUUID.isNull()) { - SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID); + SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID); + + if (nodeToKill) { + // start with a 200 response + connection->respond(HTTPConnection::StatusCode200); - if (nodeToKill) { - // start with a 200 response - connection->respond(HTTPConnection::StatusCode200); - - // we have a valid UUID and node - kill the node that has this assignment - QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID)); - - // successfully processed request - return true; - } + // we have a valid UUID and node - kill the node that has this assignment + QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID)); + + // successfully processed request + return true; } - // bad request, couldn't pull a node ID - connection->respond(HTTPConnection::StatusCode400); + return true; + } else if (allNodesDeleteRegex.indexIn(url.path()) != -1) { + qDebug() << "Received request to kill all nodes."; + NodeList::getInstance()->eraseAllNodes(); return true; } diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index e80f25709a..e150e42464 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -359,7 +359,7 @@ NodeHash NodeList::getNodeHash() { return NodeHash(_nodeHash); } -void NodeList::clear() { +void NodeList::eraseAllNodes() { qDebug() << "Clearing the NodeList. Deleting all nodes in list."; QMutexLocker locker(&_nodeHashMutex); @@ -373,7 +373,7 @@ void NodeList::clear() { } void NodeList::reset() { - clear(); + eraseAllNodes(); _numNoReplyDomainCheckIns = 0; // refresh the owner UUID to the NULL UUID diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index d892223f75..2eccc32aa4 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -128,6 +128,7 @@ public: void saveData(QSettings* settings); public slots: void reset(); + void eraseAllNodes(); void sendDomainServerCheckIn(); void pingInactiveNodes(); @@ -154,8 +155,6 @@ private: const QUuid& connectionSecret); NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill); - - void clear(); void processDomainServerAuthRequest(const QByteArray& packet); void requestAuthForDomainServer();