Skip to content

Commit

Permalink
use logged-in user's default domain if no domain is configured for rm…
Browse files Browse the repository at this point in the history
…agent; code cleanup; bump version and copyright date
  • Loading branch information
obiltschnig committed Mar 6, 2022
1 parent 6c20365 commit 716513e
Show file tree
Hide file tree
Showing 45 changed files with 323 additions and 270 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,18 @@ size before deploying it to the device.

## Running the Gateway

Edit the configuration file [rmgateway.properties](rmgateway.properties) and change the default
macchina.io REMOTE domain.

Change the value of the `webtunnel.domain` property to the domain UUID of your
macchina.io REMOTE server account.
Review the configuration file [rmgateway.properties](rmgateway.properties) and
make some changes to the configuration if desired.

The most important setting is `webtunnel.domain`, which specifies the default
domain any devices created through the web user interface will be assigned to.
This can be left at the default (`00000000-0000-0000-0000-000000000000`).
In this case, the default domain of the logged-in user will be used. The default
domain UUID can be overridden when creating a device.

The value of the `webtunnel.domain` property can also be set to a specific value.
In this case, when a user logs in, the Gateway will verify that the user has access
to that specific domain, and deny login if not.

Optionally, you can also change other configuration properties, such as the
port of the internal web server (defaults to 8080).
Expand Down
2 changes: 1 addition & 1 deletion html/footer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<footer>
<div class="footercontainer">
<div class="footer">
<%= pageTemplate["softwareVersion"] %> | &copy; 2015-2021 by <a href="https://macchina.io">Applied Informatics GmbH</a> | Gateway Domain: <%= U::htmlize(pageTemplate["domain"]) %>
<%= pageTemplate["softwareVersion"] %> | &copy; 2015-2022 by <a href="https://macchina.io">Applied Informatics GmbH</a>
</div>
</div>
</footer>
Expand Down
5 changes: 5 additions & 0 deletions rmgateway.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ gateway.http.port = 8080
#

# The domain UUID is used to associate the device with a user account.
# If set to a non-nil UUID (00000000-0000-0000-0000-000000000000),
# the Gateway will verify whether a user logging in to the Gateway
# web user interface has the permission to access that domain.
# If set to a nil UUID, the default domain of the logged-in
# user will be used (if the user has a default domain assigned).
webtunnel.domain = 00000000-0000-0000-0000-000000000000

# The URL of the reflector server.
Expand Down
2 changes: 1 addition & 1 deletion src/AjaxCore.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AjaxCore.cpp
//
// This file has been generated from AjaxCore.cpsp on 2021-11-27 19:58:16.
// This file has been generated from AjaxCore.cpsp on 2022-03-06 09:57:47.
//


Expand Down
2 changes: 1 addition & 1 deletion src/AjaxCore.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// AjaxCore.h
//
// This file has been generated from AjaxCore.cpsp on 2021-11-27 19:58:16.
// This file has been generated from AjaxCore.cpsp on 2022-03-06 09:57:47.
//


Expand Down
24 changes: 10 additions & 14 deletions src/CreateDevicePage.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// CreateDevicePage.cpp
//
// This file has been generated from CreateDevicePage.cpsp on 2021-11-27 20:06:35.
// This file has been generated from CreateDevicePage.cpsp on 2022-03-06 10:01:18.
//


Expand Down Expand Up @@ -47,7 +47,6 @@ if (response.sent()) return;
if (ctrl.mustRedirect()) return;

pageTemplate.set("title", "Gateway > Create Device");
pageTemplate.set("domain", ctrl.defaultDomain());
std::ostream& _responseStream = response.send();
Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1);
std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;
Expand Down Expand Up @@ -99,7 +98,7 @@ pageTemplate.set("domain", ctrl.defaultDomain());
responseStream << " <div class=\"username\">\n";
responseStream << " &nbsp;\n";
responseStream << " ";
#line 38 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 37 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
responseStream << ( ctrl.username() );
responseStream << "\n";
responseStream << " &nbsp;\n";
Expand All @@ -112,23 +111,23 @@ pageTemplate.set("domain", ctrl.defaultDomain());
responseStream << " </div>\n";
responseStream << "</nav>\n";
responseStream << "\n";
#line 49 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 48 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
if (!ctrl.message().empty()) { responseStream << "\n";
responseStream << " <div class=\"error\">\n";
responseStream << " ";
#line 51 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 50 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
responseStream << ( U::htmlize(ctrl.message()) );
responseStream << "\n";
responseStream << " </div>\n";
#line 53 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 52 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
} responseStream << "\n";
responseStream << "<div class=\"groupbox\">\n";
responseStream << " <h2>New Device Properties</h2>\n";
responseStream << "\n";
responseStream << " <form name=\"actionForm\" method=\"post\">\n";
responseStream << " <input type=\"hidden\" name=\"action\" value=\"create\">\n";
responseStream << " <input type=\"hidden\" name=\"csrfToken\" value=\"";
#line 60 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 59 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
responseStream << ( ctrl.csrfToken() );
responseStream << "\">\n";
responseStream << " <table class=\"list\">\n";
Expand All @@ -139,7 +138,7 @@ pageTemplate.set("domain", ctrl.defaultDomain());
responseStream << " <input type=\"text\"\n";
responseStream << " name=\"deviceName\"\n";
responseStream << " value=\"";
#line 68 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 67 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
responseStream << ( U::htmlize(ctrl.name()) );
responseStream << "\"\n";
responseStream << " size=\"64\"\n";
Expand All @@ -154,7 +153,7 @@ pageTemplate.set("domain", ctrl.defaultDomain());
responseStream << " <input type=\"text\"\n";
responseStream << " name=\"deviceId\"\n";
responseStream << " value=\"";
#line 80 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 79 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
responseStream << ( U::htmlize(ctrl.deviceId()) );
responseStream << "\"\n";
responseStream << " size=\"64\"\n";
Expand All @@ -168,7 +167,7 @@ pageTemplate.set("domain", ctrl.defaultDomain());
responseStream << " <input type=\"text\"\n";
responseStream << " name=\"domain\"\n";
responseStream << " value=\"";
#line 91 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
#line 90 "/Users/guenter/ws/git/my-devices/gateway/src/CreateDevicePage.cpsp"
responseStream << ( U::htmlize(ctrl.domain()) );
responseStream << "\"\n";
responseStream << " size=\"64\"\n";
Expand Down Expand Up @@ -197,10 +196,7 @@ pageTemplate.set("domain", ctrl.defaultDomain());
responseStream << " ";
#line 6 "/Users/guenter/ws/git/my-devices/gateway/html/footer.inc"
responseStream << ( pageTemplate["softwareVersion"] );
responseStream << " | &copy; 2015-2021 by <a href=\"https://macchina.io\">Applied Informatics GmbH</a> | Gateway Domain: ";
#line 6 "/Users/guenter/ws/git/my-devices/gateway/html/footer.inc"
responseStream << ( U::htmlize(pageTemplate["domain"]) );
responseStream << "\n";
responseStream << " | &copy; 2015-2022 by <a href=\"https://macchina.io\">Applied Informatics GmbH</a>\n";
responseStream << " </div>\n";
responseStream << " </div>\n";
responseStream << " </footer>\n";
Expand Down
1 change: 0 additions & 1 deletion src/CreateDevicePage.cpsp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ if (response.sent()) return;
if (ctrl.mustRedirect()) return;

pageTemplate.set("title", "Gateway > Create Device");
pageTemplate.set("domain", ctrl.defaultDomain());
%>

<%@ include file="../html/header.inc" %>
Expand Down
2 changes: 1 addition & 1 deletion src/CreateDevicePage.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// CreateDevicePage.h
//
// This file has been generated from CreateDevicePage.cpsp on 2021-11-27 20:06:35.
// This file has been generated from CreateDevicePage.cpsp on 2022-03-06 10:01:18.
//


Expand Down
33 changes: 18 additions & 15 deletions src/CreateDevicePageController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "Poco/Path.h"


using namespace std::string_literals;


namespace MyDevices {
namespace Gateway {

Expand All @@ -45,17 +48,17 @@ namespace
CreateDevicePageController::CreateDevicePageController(DeviceManager::Ptr pDeviceManager, const Poco::Net::HTTPServerRequest& request, const Poco::Net::HTMLForm& form):
PageController(pDeviceManager, request, form)
{
WebSession::Ptr pSession = pDeviceManager->webSessionManager().find("rmgateway", request);
if (!pSession || !pSession->has("username"))
WebSession::Ptr pSession = pDeviceManager->webSessionManager().find("rmgateway"s, request);
if (!pSession || !pSession->has("username"s))
{
request.response().redirect("/");
request.response().redirect("/"s);
return;
}
username(pSession->getValue<std::string>("username"));
username(pSession->getValue<std::string>("username"s));
csrfToken(pSession->csrfToken());
try
{
if (form.has("action"))
if (form.has("action"s))
{
processForm();
}
Expand All @@ -64,7 +67,7 @@ CreateDevicePageController::CreateDevicePageController(DeviceManager::Ptr pDevic
Poco::UUIDGenerator uuidGen;
_deviceId = uuidGen.createRandom().toString();
_name = "Unnamed Device";
_domain = defaultDomain();
_domain = pSession->getValue<std::string>("domain"s, defaultDomain());
}
}
catch (Poco::Exception& exc)
Expand All @@ -81,36 +84,36 @@ CreateDevicePageController::~CreateDevicePageController()

void CreateDevicePageController::processForm()
{
std::string action = form().get("action", "");
std::string token = form().get("csrfToken", "");
const std::string action = form().get("action"s, ""s);
const std::string token = form().get("csrfToken"s, ""s);

if (token == csrfToken())
{
if (action == "create")
{
_deviceId = form().get("deviceId");
_name = form().get("deviceName");
_domain = form().get("domain");
_deviceId = form().get("deviceId"s);
_name = form().get("deviceName"s);
_domain = form().get("domain"s);

if (!isValidId(_deviceId))
{
message("Invalid device ID: " + _deviceId);
message("Invalid device ID: "s + _deviceId);
return;
}

if (!isValidId(_domain))
{
message("Invalid domain ID: " + _domain);
message("Invalid domain ID: "s + _domain);
return;
}

Poco::AutoPtr<Poco::Util::AbstractConfiguration> pDeviceConfig = deviceManager()->createDevice(_deviceId, _domain, _name);

request().response().redirect("/device/" + _deviceId);
request().response().redirect("/device/"s + _deviceId);
}
else if (action == "cancel")
{
request().response().redirect("/devices");
request().response().redirect("/devices"s);
}
}
}
Expand Down
Loading

0 comments on commit 716513e

Please sign in to comment.