Add suppor for manual connections to remote proxy

This commit is contained in:
Michael Zanetti 2022-01-21 16:56:05 +01:00
parent 8f015aeee3
commit b7ccd5c923
10 changed files with 56 additions and 37 deletions

View File

@ -445,6 +445,7 @@ void JsonRpcClient::processAuthenticate(int /*commandId*/, const QVariantMap &da
} else {
m_permissionScopes = UserInfo::PermissionScopeAdmin;
}
emit permissionsChanged();
QSettings settings;
settings.beginGroup("jsonTokens");
settings.setValue(m_serverUuid, m_token);
@ -720,6 +721,11 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap &params)
qCInfo(dcJsonRpc()) << "Handshake reply:" << "Protocol version:" << protoVersionString << "InitRequired:" << m_initialSetupRequired << "AuthRequired:" << m_authenticationRequired << "PushButtonAvailable:" << m_pushButtonAuthAvailable;
if (m_connection->currentHost()->uuid().isNull()) {
qCDebug(dcJsonRpc()) << "Updating Server UUID in connection:" << m_connection->currentHost()->uuid().toString() << "->" << m_serverUuid;
m_connection->currentHost()->setUuid(m_serverUuid);
}
QVersionNumber minimumRequiredVersion = QVersionNumber(5, 0);
QVersionNumber maximumMajorVersion = QVersionNumber(6);
if (m_jsonRpcVersion < minimumRequiredVersion) {
@ -795,11 +801,6 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap &params)
emit handshakeReceived();
if (m_connection->currentHost()->uuid().isNull()) {
qCDebug(dcJsonRpc()) << "Updating Server UUID in connection:" << m_connection->currentHost()->uuid().toString() << "->" << m_serverUuid;
m_connection->currentHost()->setUuid(m_serverUuid);
}
if (m_initialSetupRequired) {
qCInfo(dcJsonRpc()) << "Initial setup is required for this nymea instance!";
emit initialSetupRequiredChanged();

View File

@ -279,6 +279,10 @@ QVariant Users::data(const QModelIndex &index, int role) const
switch (role) {
case RoleUsername:
return m_users.at(index.row())->username();
case RoleDisplayName:
return m_users.at(index.row())->displayName();
case RoleEmail:
return m_users.at(index.row())->email();
case RoleScopes:
return static_cast<int>(m_users.at(index.row())->scopes());
}
@ -289,6 +293,8 @@ QHash<int, QByteArray> Users::roleNames() const
{
QHash<int, QByteArray> roles;
roles.insert(RoleUsername, "username");
roles.insert(RoleDisplayName, "displayName");
roles.insert(RoleEmail, "email");
roles.insert(RoleScopes, "scopes");
return roles;
}
@ -296,6 +302,18 @@ QHash<int, QByteArray> Users::roleNames() const
void Users::insertUser(UserInfo *userInfo)
{
userInfo->setParent(this);
connect(userInfo, &UserInfo::displayNameChanged, this, [=](){
int idx = m_users.indexOf(userInfo);
if (idx >= 0) {
emit dataChanged(index(idx), index(idx), {RoleDisplayName});
}
});
connect(userInfo, &UserInfo::emailChanged, this, [=](){
int idx = m_users.indexOf(userInfo);
if (idx >= 0) {
emit dataChanged(index(idx), index(idx), {RoleEmail});
}
});
connect(userInfo, &UserInfo::scopesChanged, this, [=](){
int idx = m_users.indexOf(userInfo);
if (idx >= 0) {

View File

@ -97,6 +97,8 @@ class Users: public QAbstractListModel {
public:
enum Roles {
RoleUsername,
RoleDisplayName,
RoleEmail,
RoleScopes
};
Q_ENUM(Roles)

View File

@ -21,23 +21,6 @@ ConfiguredHostsModel::ConfiguredHostsModel(QObject *parent) : QAbstractListModel
m_currentIndex = settings.value("currentIndex", 0).toInt();
settings.endGroup();
// If there aren't any in the config, try migrating settings from old tab model
if (m_list.isEmpty() && settings.contains("tabCount")) {
qCInfo(dcApplication()) << "Migrating tab settings to mainmenumodel";
int tabCount = settings.value("tabCount", 0).toInt();
qCDebug(dcApplication()) << "Tab count:" << tabCount;
for (int i = 0; i < tabCount; i++) {
settings.beginGroup(QString("tabSettings%1").arg(i));
QUuid uuid = settings.value("lastConnectedHost").toUuid();
ConfiguredHost *host = new ConfiguredHost(uuid, this);
addHost(host);
settings.endGroup();
}
settings.remove("tabCount");
}
// There must be always 1 at least
if (m_list.isEmpty()) {
createHost();

View File

@ -12,7 +12,6 @@
<file>ui/mainviews/FavoritesView.qml</file>
<file>ui/mainviews/ThingsView.qml</file>
<file>ui/connection/ConnectPage.qml</file>
<file>ui/connection/ManualConnectPage.qml</file>
<file>ui/connection/ConnectingPage.qml</file>
<file>ui/connection/wifisetup/BluetoothDiscoveryPage.qml</file>
<file>ui/connection/wifisetup/WirelessSetupPage.qml</file>

View File

@ -721,7 +721,6 @@ Page {
text: qsTr("Disconnect")
Layout.preferredWidth: Math.max(cancelButton.implicitWidth, disconnectButton.implicitWidth)
onClicked: {
tabSettings.lastConnectedHost = "";
engine.jsonRpcClient.disconnectFromHost();
}
}

View File

@ -173,7 +173,6 @@ Item {
print("opening push button auth")
var page = pageStack.push(Qt.resolvedUrl("PushButtonAuthPage.qml"))
page.backPressed.connect(function() {
// tabSettings.lastConnectedHost = "";
engine.jsonRpcClient.disconnectFromHost();
init();
})
@ -182,7 +181,6 @@ Item {
if (engine.jsonRpcClient.initialSetupRequired) {
var page = pageStack.push(Qt.resolvedUrl("connection/SetupWizard.qml"));
page.backPressed.connect(function() {
// tabSettings.lastConnectedHost = "";
engine.jsonRpcClient.disconnectFromHost()
init();
})
@ -191,7 +189,6 @@ Item {
var page = pageStack.push(Qt.resolvedUrl("connection/LoginPage.qml"));
page.backPressed.connect(function() {
// tabSettings.lastConnectedHost = "";
engine.jsonRpcClient.disconnectFromHost()
init();
})
@ -314,7 +311,6 @@ Item {
if (engine.jsonRpcClient.connected) {
nymeaDiscovery.cacheHost(engine.jsonRpcClient.currentHost)
configuredHost.uuid = engine.jsonRpcClient.serverUuid
// tabSettings.lastConnectedHost = engine.jsonRpcClient.serverUuid
}
init();
}
@ -333,14 +329,12 @@ Item {
popup.actualVersion = actualVersion;
popup.minVersion = minVersion;
popup.open()
// tabSettings.lastConnectedHost = ""
}
onInvalidMaximumVersion: {
var popup = invalidVersionComponent.createObject(app.contentItem);
popup.actualVersion = actualVersion;
popup.maxVersion = maxVersion;
popup.open()
// tabSettings.lastConnectedHost = ""
}
}
@ -353,7 +347,7 @@ Item {
}
}
Connections {
target: engien.nymeaConfiguration.tunnelProxyServerConfigurations
target: engine.nymeaConfiguration.tunnelProxyServerConfigurations
onCountChanged: syncRemoteConnection();
}

View File

@ -308,6 +308,12 @@ WizardPageBase {
} else {
rpcUrl = "ws://" + hostAddress + ":" + port
}
} else if (connectionTypeComboBox.currentIndex == 2) {
if (secureCheckBox.checked) {
rpcUrl = "tunnels://" + hostAddress + ":" + port + "?uuid=" + serverUuidTextInput.text
} else {
rpcUrl = "tunnel://" + hostAddress + ":" + port + "?uuid=" + serverUuidTextInput.text
}
}
print("Try to connect ", rpcUrl)
@ -331,28 +337,43 @@ WizardPageBase {
ComboBox {
id: connectionTypeComboBox
Layout.fillWidth: true
model: [ qsTr("TCP"), qsTr("Websocket") ]
model: [ qsTr("TCP"), qsTr("Websocket"), qsTr("Remote proxy") ]
}
Label { text: qsTr("Address:") }
Label {
text: connectionTypeComboBox.currentIndex < 2 ? qsTr("Address:") : qsTr("Proxy address:")
}
TextField {
id: addressTextInput
objectName: "addressTextInput"
Layout.fillWidth: true
placeholderText: "127.0.0.1"
placeholderText: connectionTypeComboBox.currentIndex < 2 ? "127.0.0.1" : "dev-remoteproxy.nymea.io"
}
Label {
text: qsTr("%1 UUID:").arg(Configuration.systemName)
visible: connectionTypeComboBox.currentIndex == 2
}
TextField {
id: serverUuidTextInput
Layout.fillWidth: true
visible: connectionTypeComboBox.currentIndex == 2
}
Label { text: qsTr("Port:") }
TextField {
id: portTextInput
Layout.fillWidth: true
placeholderText: connectionTypeComboBox.currentIndex === 0 ? "2222" : "4444"
placeholderText: connectionTypeComboBox.currentIndex === 0
? "2222"
: connectionTypeComboBox.currentIndex == 1
? "4444"
: "2213"
validator: IntValidator{bottom: 1; top: 65535;}
}
Label {
Layout.fillWidth: true
text: qsTr("Encrypted connection:")
text: qsTr("SSL:")
}
CheckBox {
id: secureCheckBox

View File

@ -138,6 +138,7 @@ SettingsPageBase {
}
SettingsPageSectionHeader {
text: qsTr("Remote connection server interfaces")
visible: engine.jsonRpcClient.ensureServerVersion("6.0")
}
Repeater {
@ -171,6 +172,7 @@ SettingsPageBase {
Layout.fillWidth: true
Layout.margins: app.margins
text: qsTr("Add")
visible: engine.jsonRpcClient.ensureServerVersion("6.0")
onClicked: {
var config = engine.nymeaConfiguration.createTunnelProxyServerConfiguration("dev-remoteproxy.nymea.io", 2213, true, true, false);
var component = Qt.createComponent(Qt.resolvedUrl("TunnelProxyServerConfigurationDialog.qml"));

View File

@ -278,7 +278,7 @@ SettingsPageBase {
model: userManager.users
delegate: NymeaItemDelegate {
Layout.fillWidth: true
text: engine.jsonRpcClient.ensureServerVersion("6.0") && model.displayName ? model.displayName : model.username
text: engine.jsonRpcClient.ensureServerVersion("6.0") && model.displayName !== "" ? model.displayName : model.username
subText: engine.jsonRpcClient.ensureServerVersion("6.0") && model.displayName ? model.username : ""
iconName: "/ui/images/account.svg"
iconColor: userManager.userInfo.scopes & UserInfo.PermissionScopeAdmin ? Style.accentColor : Style.iconColor