From 0650172456e66fc4b29ce8d008c94d29976712b7 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Sun, 20 Sep 2026 09:56:01 +0700 Subject: [PATCH 1/5] feat: persist bounded recent engineering resources --- .../src/ProductHardeningController.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/ied_simulator/src/ProductHardeningController.hpp b/apps/ied_simulator/src/ProductHardeningController.hpp index 41df82ea9..1e2ec8180 100644 --- a/apps/ied_simulator/src/ProductHardeningController.hpp +++ b/apps/ied_simulator/src/ProductHardeningController.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -14,6 +15,7 @@ class ProductHardeningController : public QObject { Q_PROPERTY(int workspaceIndex READ workspaceIndex WRITE setWorkspaceIndex NOTIFY stateChanged) Q_PROPERTY(QStringList recentEndpoints READ recentEndpoints NOTIFY stateChanged) + Q_PROPERTY(QStringList recentResources READ recentResources NOTIFY stateChanged) Q_PROPERTY(QString lastHost READ lastHost NOTIFY stateChanged) Q_PROPERTY(int lastPort READ lastPort NOTIFY stateChanged) Q_PROPERTY(QString statePath READ statePath CONSTANT) @@ -33,6 +35,7 @@ class ProductHardeningController : public QObject { void setWorkspaceIndex(int value); [[nodiscard]] QStringList recentEndpoints() const; + [[nodiscard]] QStringList recentResources() const; [[nodiscard]] QString lastHost() const; [[nodiscard]] int lastPort() const noexcept; [[nodiscard]] QString statePath() const { return statePath_; } @@ -48,6 +51,13 @@ class ProductHardeningController : public QObject { Q_INVOKABLE void clearRecentEndpoints(); Q_INVOKABLE QString recentHost(int index) const; Q_INVOKABLE int recentPort(int index) const; + + Q_INVOKABLE bool rememberResource(const QString& path); + Q_INVOKABLE void clearRecentResources(); + Q_INVOKABLE QString recentResourcePath(int index) const; + Q_INVOKABLE QUrl recentResourceUrl(int index) const; + Q_INVOKABLE bool recentResourceExists(int index) const; + Q_INVOKABLE bool reload(); Q_INVOKABLE void refreshRuntimeReadiness(); @@ -62,14 +72,18 @@ class ProductHardeningController : public QObject { }; static constexpr int legacyStateSchemaVersion = 1; - static constexpr int stateSchemaVersion = 2; + static constexpr int previousStateSchemaVersion = 2; + static constexpr int stateSchemaVersion = 3; static constexpr int maximumRecentEndpoints = 8; + static constexpr int maximumRecentResources = 8; + static constexpr int maximumResourcePathCharacters = 4096; static constexpr int minimumWorkspaceIndex = 0; static constexpr int maximumWorkspaceIndex = 3; static constexpr int legacyMaximumWorkspaceIndex = 6; [[nodiscard]] static QString defaultStatePath(); [[nodiscard]] static QString normalizedHost(const QString& value); + [[nodiscard]] static QString normalizedResourcePath(const QString& value); [[nodiscard]] static QString endpointLabel(const Endpoint& endpoint); [[nodiscard]] static int migrateLegacyWorkspaceIndex(int value) noexcept; [[nodiscard]] bool loadState(); @@ -80,6 +94,7 @@ class ProductHardeningController : public QObject { QString statePath_; int workspaceIndex_{}; std::vector recent_; + std::vector recentResources_; bool settingsHealthy_{true}; QString settingsStatus_{QStringLiteral("Product state ready.")}; bool npcapAvailable_{}; From 8c522c84557c7598965fd66d13ed6650661c6d28 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Sun, 20 Sep 2026 09:56:36 +0700 Subject: [PATCH 2/5] feat: migrate product state for recent SCL resources --- .../src/ProductHardeningController.cpp | 130 +++++++++++++++++- 1 file changed, 125 insertions(+), 5 deletions(-) diff --git a/apps/ied_simulator/src/ProductHardeningController.cpp b/apps/ied_simulator/src/ProductHardeningController.cpp index 0b0237734..6c0f0208c 100644 --- a/apps/ied_simulator/src/ProductHardeningController.cpp +++ b/apps/ied_simulator/src/ProductHardeningController.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,28 @@ QString ProductHardeningController::normalizedHost(const QString& value) { return host; } +QString ProductHardeningController::normalizedResourcePath(const QString& value) { + const auto candidate = value.trimmed(); + if (candidate.isEmpty() || candidate.size() > maximumResourcePathCharacters) return {}; + + QString path; + const QUrl url(candidate); + if (url.isValid() && url.isLocalFile()) { + path = url.toLocalFile(); + } else { + if (!QDir::isAbsolutePath(candidate)) return {}; + path = candidate; + } + + for (const auto character : path) { + if (character.category() == QChar::Other_Control) return {}; + } + + path = QDir::cleanPath(path); + if (path.isEmpty() || path.size() > maximumResourcePathCharacters || !QDir::isAbsolutePath(path)) return {}; + return QFileInfo(path).absoluteFilePath(); +} + QString ProductHardeningController::endpointLabel(const Endpoint& endpoint) { const auto host = endpoint.host.contains(QLatin1Char(':')) ? QStringLiteral("[%1]").arg(endpoint.host) @@ -79,6 +102,13 @@ QStringList ProductHardeningController::recentEndpoints() const { return result; } +QStringList ProductHardeningController::recentResources() const { + QStringList result; + result.reserve(static_cast(recentResources_.size())); + for (const auto& path : recentResources_) result.push_back(path); + return result; +} + QString ProductHardeningController::lastHost() const { return recent_.empty() ? QString{} : recent_.front().host; } @@ -98,6 +128,7 @@ bool ProductHardeningController::npcapRequired() const noexcept { void ProductHardeningController::resetDefaults() { workspaceIndex_ = 0; recent_.clear(); + recentResources_.clear(); } void ProductHardeningController::setStateFault(const QString& message) { @@ -136,7 +167,9 @@ bool ProductHardeningController::loadState() { const auto object = document.object(); const auto schema = object.value(QStringLiteral("schema")).toInt(-1); - if (schema != stateSchemaVersion && schema != legacyStateSchemaVersion) { + if (schema != stateSchemaVersion && + schema != previousStateSchemaVersion && + schema != legacyStateSchemaVersion) { setStateFault(QStringLiteral("Persisted state ignored: unsupported schema.")); emit stateChanged(); return false; @@ -184,19 +217,52 @@ bool ProductHardeningController::loadState() { loaded.push_back({host, port}); } + std::vector loadedResources; + if (schema == stateSchemaVersion) { + const auto resources = object.value(QStringLiteral("recentResources")); + if (!resources.isArray() || resources.toArray().size() > maximumRecentResources) { + setStateFault(QStringLiteral("Persisted state ignored: recent resource list is invalid or unbounded.")); + emit stateChanged(); + return false; + } + loadedResources.reserve(static_cast(resources.toArray().size())); + for (const auto& value : resources.toArray()) { + if (!value.isString()) { + setStateFault(QStringLiteral("Persisted state ignored: malformed recent engineering resource.")); + emit stateChanged(); + return false; + } + const auto path = normalizedResourcePath(value.toString()); + if (path.isEmpty()) { + setStateFault(QStringLiteral("Persisted state ignored: invalid recent engineering resource.")); + emit stateChanged(); + return false; + } + loadedResources.push_back(path); + } + } + workspaceIndex_ = workspace; recent_ = std::move(loaded); + recentResources_ = std::move(loadedResources); settingsHealthy_ = true; - settingsStatus_ = schema == legacyStateSchemaVersion - ? QStringLiteral("Legacy product state migrated to the four-workspace shell.") - : QStringLiteral("Persisted product state restored safely."); if (schema == legacyStateSchemaVersion) { + settingsStatus_ = QStringLiteral("Legacy product state migrated to the four-workspace File/Home schema."); + } else if (schema == previousStateSchemaVersion) { + settingsStatus_ = QStringLiteral("Product state migrated to File/Home engineering-resource history."); + } else { + settingsStatus_ = QStringLiteral("Persisted product state restored safely."); + } + + if (schema != stateSchemaVersion) { if (!persistState()) { emit stateChanged(); return false; } - settingsStatus_ = QStringLiteral("Legacy product state migrated to the four-workspace shell."); + settingsStatus_ = schema == legacyStateSchemaVersion + ? QStringLiteral("Legacy product state migrated to the four-workspace File/Home schema.") + : QStringLiteral("Product state migrated to File/Home engineering-resource history."); } emit stateChanged(); @@ -218,10 +284,14 @@ bool ProductHardeningController::persistState() { recent.append(item); } + QJsonArray resources; + for (const auto& path : recentResources_) resources.append(path); + QJsonObject object; object.insert(QStringLiteral("schema"), stateSchemaVersion); object.insert(QStringLiteral("workspaceIndex"), workspaceIndex_); object.insert(QStringLiteral("recentEndpoints"), recent); + object.insert(QStringLiteral("recentResources"), resources); const auto payload = QJsonDocument(object).toJson(QJsonDocument::Compact); QSaveFile output(statePath_); @@ -294,6 +364,56 @@ int ProductHardeningController::recentPort(const int index) const { return recent_[static_cast(index)].port; } +bool ProductHardeningController::rememberResource(const QString& pathValue) { + const auto path = normalizedResourcePath(pathValue); + if (path.isEmpty()) { + settingsStatus_ = QStringLiteral("Rejected invalid engineering-resource path."); + emit stateChanged(); + return false; + } + +#ifdef Q_OS_WIN + constexpr auto pathCaseSensitivity = Qt::CaseInsensitive; +#else + constexpr auto pathCaseSensitivity = Qt::CaseSensitive; +#endif + + const auto duplicate = std::find_if(recentResources_.begin(), recentResources_.end(), [&](const QString& existing) { + return existing.compare(path, pathCaseSensitivity) == 0; + }); + if (duplicate != recentResources_.end()) recentResources_.erase(duplicate); + recentResources_.insert(recentResources_.begin(), path); + if (recentResources_.size() > static_cast(maximumRecentResources)) { + recentResources_.resize(static_cast(maximumRecentResources)); + } + + const auto persisted = persistState(); + emit stateChanged(); + return persisted; +} + +void ProductHardeningController::clearRecentResources() { + if (recentResources_.empty()) return; + recentResources_.clear(); + (void)persistState(); + emit stateChanged(); +} + +QString ProductHardeningController::recentResourcePath(const int index) const { + if (index < 0 || index >= static_cast(recentResources_.size())) return {}; + return recentResources_[static_cast(index)]; +} + +QUrl ProductHardeningController::recentResourceUrl(const int index) const { + const auto path = recentResourcePath(index); + return path.isEmpty() ? QUrl{} : QUrl::fromLocalFile(path); +} + +bool ProductHardeningController::recentResourceExists(const int index) const { + const auto path = recentResourcePath(index); + return !path.isEmpty() && QFileInfo::exists(path) && QFileInfo(path).isFile(); +} + bool ProductHardeningController::reload() { return loadState(); } From ee535effce18cc26da1ee03e34d0a1d26429a2be Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Sun, 20 Sep 2026 09:57:07 +0700 Subject: [PATCH 3/5] test: gate bounded File Home resource history --- .../src/ied_product_hardening_qa.cpp | 164 ++++++++++++++---- 1 file changed, 129 insertions(+), 35 deletions(-) diff --git a/apps/ied_simulator/src/ied_product_hardening_qa.cpp b/apps/ied_simulator/src/ied_product_hardening_qa.cpp index e0e8906ea..3c8698927 100644 --- a/apps/ied_simulator/src/ied_product_hardening_qa.cpp +++ b/apps/ied_simulator/src/ied_product_hardening_qa.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,10 @@ bool writeJson(const QString& path, const QJsonObject& object) { QJsonObject endpoint(const QString& host, const int port) { return {{QStringLiteral("host"), host}, {QStringLiteral("port"), port}}; } + +QString absolutePath(const QString& path) { + return QFileInfo(path).absoluteFilePath(); +} } // namespace int main(int argc, char** argv) { @@ -34,10 +39,12 @@ int main(int argc, char** argv) { { ProductHardeningController state(path); if (!state.settingsHealthy() || state.workspaceIndex() != 0 || - !state.recentEndpoints().isEmpty() || state.automaticReconnectOnStartup()) { + !state.recentEndpoints().isEmpty() || !state.recentResources().isEmpty() || + state.automaticReconnectOnStartup()) { std::cerr << "Safe default product state contract failed.\n"; return 3; } + state.setWorkspaceIndex(2); for (int index = 1; index <= 10; ++index) { if (!state.rememberEndpoint(QStringLiteral("192.0.2.%1").arg(index), 100 + index)) { @@ -50,17 +57,43 @@ int main(int argc, char** argv) { std::cerr << "Recent endpoint bound/order contract failed.\n"; return 5; } - const auto beforeDedupe = state.recentEndpoints().size(); + + const auto beforeEndpointDedupe = state.recentEndpoints().size(); if (!state.rememberEndpoint(QStringLiteral("192.0.2.9"), 109) || - state.recentEndpoints().size() != beforeDedupe || state.lastHost() != QStringLiteral("192.0.2.9")) { + state.recentEndpoints().size() != beforeEndpointDedupe || + state.lastHost() != QStringLiteral("192.0.2.9")) { std::cerr << "Recent endpoint dedupe contract failed.\n"; return 6; } + + for (int index = 1; index <= 10; ++index) { + if (!state.rememberResource(temp.filePath(QStringLiteral("model-%1.scd").arg(index)))) { + std::cerr << "Could not persist recent engineering resource.\n"; + return 7; + } + } + if (state.recentResources().size() != 8 || + state.recentResourcePath(0) != absolutePath(temp.filePath(QStringLiteral("model-10.scd")))) { + std::cerr << "Recent resource bound/order contract failed.\n"; + return 8; + } + + const auto beforeResourceDedupe = state.recentResources().size(); + if (!state.rememberResource(temp.filePath(QStringLiteral("model-9.scd"))) || + state.recentResources().size() != beforeResourceDedupe || + state.recentResourcePath(0) != absolutePath(temp.filePath(QStringLiteral("model-9.scd"))) || + !state.recentResourceUrl(0).isLocalFile()) { + std::cerr << "Recent resource dedupe/url contract failed.\n"; + return 9; + } + state.setWorkspaceIndex(99); if (state.workspaceIndex() != 2 || state.rememberEndpoint(QString{}, 102) || - state.rememberEndpoint(QStringLiteral("relay.local"), 0)) { - std::cerr << "Invalid workspace/endpoint did not fail closed.\n"; - return 7; + state.rememberEndpoint(QStringLiteral("relay.local"), 0) || + state.rememberResource(QStringLiteral("relative-model.scd")) || + state.rememberResource(QStringLiteral("https://example.invalid/model.scd"))) { + std::cerr << "Invalid workspace/endpoint/resource did not fail closed.\n"; + return 10; } } @@ -68,9 +101,11 @@ int main(int argc, char** argv) { ProductHardeningController restored(path); if (!restored.settingsHealthy() || restored.workspaceIndex() != 2 || restored.recentEndpoints().size() != 8 || restored.lastHost() != QStringLiteral("192.0.2.9") || - restored.lastPort() != 109 || restored.automaticReconnectOnStartup()) { + restored.lastPort() != 109 || restored.recentResources().size() != 8 || + restored.recentResourcePath(0) != absolutePath(temp.filePath(QStringLiteral("model-9.scd"))) || + restored.automaticReconnectOnStartup()) { std::cerr << "Restart persistence contract failed.\n"; - return 8; + return 11; } #ifdef Q_OS_WIN if (!restored.npcapRequired() || restored.rawEthernetReady() != restored.npcapAvailable() || @@ -78,7 +113,7 @@ int main(int argc, char** argv) { (!restored.npcapAvailable() && !restored.npcapStatus().contains(QStringLiteral("Install Npcap"), Qt::CaseInsensitive))) { std::cerr << "Windows Npcap readiness/guidance contract failed.\n"; - return 9; + return 12; } std::cout << "WINDOWS_RUNTIME_READINESS_PASS" << " npcap_required=true" @@ -89,7 +124,7 @@ int main(int argc, char** argv) { #else if (restored.npcapRequired() || !restored.npcapAvailable() || !restored.rawEthernetReady()) { std::cerr << "Non-Windows Npcap readiness contract failed.\n"; - return 9; + return 12; } #endif } @@ -100,24 +135,54 @@ int main(int argc, char** argv) { legacy.insert(QStringLiteral("workspaceIndex"), 6); legacy.insert(QStringLiteral("recentEndpoints"), QJsonArray{endpoint(QStringLiteral("legacy.local"), 102)}); - if (!writeJson(path, legacy)) return 10; + if (!writeJson(path, legacy)) return 20; ProductHardeningController migrated(path); if (!migrated.settingsHealthy() || migrated.workspaceIndex() != 3 || migrated.lastHost() != QStringLiteral("legacy.local") || + !migrated.recentResources().isEmpty() || !migrated.settingsStatus().contains(QStringLiteral("migrated"), Qt::CaseInsensitive)) { std::cerr << "Legacy seven-workspace state migration failed.\n"; - return 11; + return 21; + } + + QFile migratedFile(path); + if (!migratedFile.open(QIODevice::ReadOnly)) return 22; + const auto migratedDocument = QJsonDocument::fromJson(migratedFile.readAll()); + if (!migratedDocument.isObject() || + migratedDocument.object().value(QStringLiteral("schema")).toInt(-1) != 3 || + migratedDocument.object().value(QStringLiteral("workspaceIndex")).toInt(-1) != 3 || + !migratedDocument.object().value(QStringLiteral("recentResources")).isArray()) { + std::cerr << "Migrated legacy state was not rewritten as schema 3.\n"; + return 23; + } + } + + { + QJsonObject p1; + p1.insert(QStringLiteral("schema"), 2); + p1.insert(QStringLiteral("workspaceIndex"), 1); + p1.insert(QStringLiteral("recentEndpoints"), + QJsonArray{endpoint(QStringLiteral("p1.local"), 102)}); + if (!writeJson(path, p1)) return 24; + + ProductHardeningController migrated(path); + if (!migrated.settingsHealthy() || migrated.workspaceIndex() != 1 || + migrated.lastHost() != QStringLiteral("p1.local") || + !migrated.recentResources().isEmpty() || + !migrated.settingsStatus().contains(QStringLiteral("migrated"), Qt::CaseInsensitive)) { + std::cerr << "P1 schema-2 state migration failed.\n"; + return 25; } QFile migratedFile(path); - if (!migratedFile.open(QIODevice::ReadOnly)) return 12; + if (!migratedFile.open(QIODevice::ReadOnly)) return 26; const auto migratedDocument = QJsonDocument::fromJson(migratedFile.readAll()); if (!migratedDocument.isObject() || - migratedDocument.object().value(QStringLiteral("schema")).toInt(-1) != 2 || - migratedDocument.object().value(QStringLiteral("workspaceIndex")).toInt(-1) != 3) { - std::cerr << "Migrated product state was not rewritten as schema 2.\n"; - return 13; + migratedDocument.object().value(QStringLiteral("schema")).toInt(-1) != 3 || + !migratedDocument.object().value(QStringLiteral("recentResources")).isArray()) { + std::cerr << "P1 state was not rewritten as schema 3.\n"; + return 27; } } @@ -126,7 +191,7 @@ int main(int argc, char** argv) { if (!corrupt.open(QIODevice::WriteOnly | QIODevice::Truncate) || corrupt.write("{not-json") < 0 || !corrupt.flush()) { std::cerr << "Could not create corrupt product state.\n"; - return 20; + return 30; } // QSaveFile replaces the target during commit. Windows correctly refuses // that replacement while another writer still owns an open handle to the @@ -138,20 +203,22 @@ int main(int argc, char** argv) { ProductHardeningController damaged(path); if (damaged.settingsHealthy() || damaged.workspaceIndex() != 0 || - !damaged.recentEndpoints().isEmpty()) { + !damaged.recentEndpoints().isEmpty() || !damaged.recentResources().isEmpty()) { std::cerr << "Corrupt state was not ignored fail-closed.\n"; - return 21; + return 31; } damaged.setWorkspaceIndex(3); - if (!damaged.settingsHealthy() || !damaged.rememberEndpoint(QStringLiteral("recovered.local"), 102)) { + if (!damaged.settingsHealthy() || !damaged.rememberEndpoint(QStringLiteral("recovered.local"), 102) || + !damaged.rememberResource(temp.filePath(QStringLiteral("recovered.scd")))) { std::cerr << "Crash-safe state recovery failed.\n"; - return 22; + return 32; } ProductHardeningController recovered(path); if (!recovered.settingsHealthy() || recovered.workspaceIndex() != 3 || - recovered.lastHost() != QStringLiteral("recovered.local")) { + recovered.lastHost() != QStringLiteral("recovered.local") || + recovered.recentResourcePath(0) != absolutePath(temp.filePath(QStringLiteral("recovered.scd")))) { std::cerr << "Recovered product state did not survive restart.\n"; - return 23; + return 33; } } @@ -160,12 +227,13 @@ int main(int argc, char** argv) { unsupported.insert(QStringLiteral("schema"), 99); unsupported.insert(QStringLiteral("workspaceIndex"), 1); unsupported.insert(QStringLiteral("recentEndpoints"), QJsonArray{}); - if (!writeJson(path, unsupported)) return 24; + unsupported.insert(QStringLiteral("recentResources"), QJsonArray{}); + if (!writeJson(path, unsupported)) return 40; ProductHardeningController rejected(path); if (rejected.settingsHealthy() || rejected.workspaceIndex() != 0 || - !rejected.recentEndpoints().isEmpty()) { + !rejected.recentEndpoints().isEmpty() || !rejected.recentResources().isEmpty()) { std::cerr << "Unsupported schema was not rejected.\n"; - return 25; + return 41; } } @@ -175,24 +243,48 @@ int main(int argc, char** argv) { tooMany.append(endpoint(QStringLiteral("198.51.100.%1").arg(index + 1), 102)); } QJsonObject unbounded; - unbounded.insert(QStringLiteral("schema"), 2); + unbounded.insert(QStringLiteral("schema"), 3); unbounded.insert(QStringLiteral("workspaceIndex"), 0); unbounded.insert(QStringLiteral("recentEndpoints"), tooMany); - if (!writeJson(path, unbounded)) return 26; + unbounded.insert(QStringLiteral("recentResources"), QJsonArray{}); + if (!writeJson(path, unbounded)) return 42; ProductHardeningController rejected(path); - if (rejected.settingsHealthy() || !rejected.recentEndpoints().isEmpty()) { - std::cerr << "Unbounded persisted recents were not rejected.\n"; - return 27; + if (rejected.settingsHealthy() || !rejected.recentEndpoints().isEmpty() || + !rejected.recentResources().isEmpty()) { + std::cerr << "Unbounded persisted endpoint recents were not rejected.\n"; + return 43; + } + } + + { + QJsonArray tooManyResources; + for (int index = 0; index < 9; ++index) { + tooManyResources.append(absolutePath(temp.filePath(QStringLiteral("oversize-%1.scd").arg(index)))); + } + QJsonObject unbounded; + unbounded.insert(QStringLiteral("schema"), 3); + unbounded.insert(QStringLiteral("workspaceIndex"), 0); + unbounded.insert(QStringLiteral("recentEndpoints"), QJsonArray{}); + unbounded.insert(QStringLiteral("recentResources"), tooManyResources); + if (!writeJson(path, unbounded)) return 44; + ProductHardeningController rejected(path); + if (rejected.settingsHealthy() || !rejected.recentEndpoints().isEmpty() || + !rejected.recentResources().isEmpty()) { + std::cerr << "Unbounded persisted resource recents were not rejected.\n"; + return 45; } } std::cout << "PRODUCT_HARDENING_PASS" << " state=atomic" << " workspace_restore=2" - << " recent=8" - << " dedupe=pass" + << " endpoint_recent=8" + << " resource_recent=8" + << " endpoint_dedupe=pass" + << " resource_dedupe=pass" << " bounded_recent=8" << " legacy_workspace_migration=pass" + << " p1_schema_migration=pass" << " crash_recovery=pass" << " auto_reconnect=false" << " npcap_policy=explicit\n"; @@ -201,6 +293,8 @@ int main(int argc, char** argv) { << " unsupported_schema=rejected" << " invalid_workspace=rejected" << " invalid_endpoint=rejected" - << " unbounded_recent=rejected\n"; + << " invalid_resource=rejected" + << " unbounded_endpoint_recent=rejected" + << " unbounded_resource_recent=rejected\n"; return 0; } From d5d76147216b73c2557a800b4e580480df02ac07 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Sun, 20 Sep 2026 09:57:42 +0700 Subject: [PATCH 4/5] feat: build File Home engineering launch workflow --- apps/ied_simulator/qml/FileWorkspace.qml | 460 ++++++++++++++++++++++- 1 file changed, 457 insertions(+), 3 deletions(-) diff --git a/apps/ied_simulator/qml/FileWorkspace.qml b/apps/ied_simulator/qml/FileWorkspace.qml index 483d0186f..9fd39982f 100644 --- a/apps/ied_simulator/qml/FileWorkspace.qml +++ b/apps/ied_simulator/qml/FileWorkspace.qml @@ -1,14 +1,468 @@ // SPDX-License-Identifier: GPL-3.0-or-later import QtQuick +import QtQuick.Controls +import QtQuick.Dialogs +import QtQuick.Layouts Item { id: root + required property var theme required property var workspace + required property var hardening + + property int viewIndex: 0 + + signal browserRequested() + signal endpointRequested(string host, int port) + signal simulatorRequested() + signal snifferRequested() + + function resourceName(path) { + var normalized = String(path).replace(/\\/g, "/") + var slash = normalized.lastIndexOf("/") + return slash >= 0 ? normalized.substring(slash + 1) : normalized + } + + Component.onCompleted: { + if (workspace.loaded) + root.viewIndex = 1 + } - SclWorkspace { + Connections { + target: workspace + function onWorkspaceChanged() { + if (workspace.loaded) + root.viewIndex = 1 + } + } + + FileDialog { + id: openDialog + title: "Open IEC 61850 engineering resource" + fileMode: FileDialog.OpenFile + nameFilters: ["IEC 61850 engineering files (*.scl *.cid *.scd *.iid *.icd)", "All files (*)"] + onAccepted: { + if (workspace.openFile(selectedFile)) + root.viewIndex = 1 + } + } + + Rectangle { anchors.fill: parent; color: root.theme.background } + + ColumnLayout { anchors.fill: parent - theme: root.theme - workspace: root.workspace + spacing: 0 + + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: 46 + color: root.theme.surface + border.width: 1 + border.color: root.theme.lineSoft + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 12 + anchors.rightMargin: 12 + spacing: 6 + + Label { + text: "File" + color: root.theme.text + font.pixelSize: 12 + font.weight: Font.DemiBold + Layout.rightMargin: 8 + } + + Button { + text: "Home" + checkable: true + checked: root.viewIndex === 0 + implicitHeight: 28 + onClicked: root.viewIndex = 0 + } + + Button { + text: workspace.loaded ? "Current resource" : "Resource" + checkable: true + checked: root.viewIndex === 1 + enabled: workspace.loaded + implicitHeight: 28 + onClicked: root.viewIndex = 1 + } + + Rectangle { + Layout.preferredWidth: 1 + Layout.preferredHeight: 22 + color: root.theme.lineSoft + Layout.leftMargin: 3 + Layout.rightMargin: 3 + } + + ActionButton { + theme: root.theme + text: "Open SCL" + primary: !workspace.loaded + enabled: !workspace.busy + onClicked: openDialog.open() + } + + Item { Layout.fillWidth: true } + + Label { + visible: workspace.loaded + Layout.maximumWidth: 420 + text: workspace.sourceName + " ยท " + workspace.editionText + color: root.theme.textSoft + font.pixelSize: 9 + elide: Text.ElideMiddle + } + + Label { + text: workspace.busy ? workspace.stateText : "" + color: root.theme.muted + font.pixelSize: 8 + } + } + } + + StackLayout { + Layout.fillWidth: true + Layout.fillHeight: true + currentIndex: root.viewIndex + + ScrollView { + contentWidth: availableWidth + + ColumnLayout { + width: Math.max(0, parent.width - 28) + x: 14 + spacing: 10 + + Item { Layout.preferredHeight: 4 } + + Label { + text: "Engineering start" + color: root.theme.text + font.pixelSize: 14 + font.weight: Font.DemiBold + } + Label { + Layout.fillWidth: true + text: "Open an engineering resource, continue with an online IED, start the simulator, or inspect network traffic." + color: root.theme.textSoft + font.pixelSize: 9 + wrapMode: Text.WordWrap + } + + GridLayout { + Layout.fillWidth: true + columns: root.width >= 1120 ? 4 : 2 + columnSpacing: 8 + rowSpacing: 8 + + SurfaceCard { + Layout.fillWidth: true + Layout.preferredHeight: 104 + theme: root.theme + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 3 + Label { text: "Engineering file"; color: root.theme.text; font.pixelSize: 10; font.weight: Font.DemiBold } + Label { + Layout.fillWidth: true + text: "Open SCL / CID / SCD / IID / ICD without changing protocol runtime." + color: root.theme.muted + font.pixelSize: 8 + wrapMode: Text.WordWrap + } + Item { Layout.fillHeight: true } + ActionButton { theme: root.theme; text: "Open SCL"; primary: true; onClicked: openDialog.open() } + } + } + + SurfaceCard { + Layout.fillWidth: true + Layout.preferredHeight: 104 + theme: root.theme + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 3 + Label { text: "Online IED"; color: root.theme.text; font.pixelSize: 10; font.weight: Font.DemiBold } + Label { + Layout.fillWidth: true + text: "Continue to the unified IED Browser with one logical endpoint." + color: root.theme.muted + font.pixelSize: 8 + wrapMode: Text.WordWrap + } + Item { Layout.fillHeight: true } + ActionButton { theme: root.theme; text: "IED Browser"; onClicked: root.browserRequested() } + } + } + + SurfaceCard { + Layout.fillWidth: true + Layout.preferredHeight: 104 + theme: root.theme + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 3 + Label { text: "Simulation"; color: root.theme.text; font.pixelSize: 10; font.weight: Font.DemiBold } + Label { + Layout.fillWidth: true + text: "Create or stimulate an IEC 61850 IED in the dedicated simulator workspace." + color: root.theme.muted + font.pixelSize: 8 + wrapMode: Text.WordWrap + } + Item { Layout.fillHeight: true } + ActionButton { theme: root.theme; text: "IED Simulator"; onClicked: root.simulatorRequested() } + } + } + + SurfaceCard { + Layout.fillWidth: true + Layout.preferredHeight: 104 + theme: root.theme + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 3 + Label { text: "Network observation"; color: root.theme.text; font.pixelSize: 10; font.weight: Font.DemiBold } + Label { + Layout.fillWidth: true + text: "Open the independent Sniffer workspace for capture and decode workflows." + color: root.theme.muted + font.pixelSize: 8 + wrapMode: Text.WordWrap + } + Item { Layout.fillHeight: true } + ActionButton { theme: root.theme; text: "Sniffer"; onClicked: root.snifferRequested() } + } + } + } + + RowLayout { + Layout.fillWidth: true + Layout.fillHeight: true + spacing: 10 + + SurfaceCard { + Layout.fillWidth: true + Layout.fillHeight: true + Layout.minimumHeight: 260 + theme: root.theme + + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 6 + + RowLayout { + Layout.fillWidth: true + Label { + text: "Recent engineering resources" + color: root.theme.text + font.pixelSize: 10 + font.weight: Font.DemiBold + } + Item { Layout.fillWidth: true } + Button { + visible: hardening.recentResources.length > 0 + text: "Clear" + flat: true + onClicked: hardening.clearRecentResources() + } + } + + Label { + visible: hardening.recentResources.length === 0 + Layout.fillWidth: true + text: "No recent engineering resources yet." + color: root.theme.muted + font.pixelSize: 9 + } + + ListView { + id: resourceList + Layout.fillWidth: true + Layout.fillHeight: true + clip: true + reuseItems: true + spacing: 2 + model: hardening.recentResources + ScrollBar.vertical: ScrollBar {} + + delegate: Rectangle { + required property int index + required property string modelData + width: ListView.view.width + height: 48 + radius: 4 + color: resourceMouse.containsMouse ? root.theme.surfaceRaised : root.theme.surfaceSoft + border.width: 1 + border.color: root.theme.lineSoft + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 9 + anchors.rightMargin: 8 + spacing: 8 + + ColumnLayout { + Layout.fillWidth: true + spacing: 1 + Label { + Layout.fillWidth: true + text: root.resourceName(modelData) + color: hardening.recentResourceExists(index) ? root.theme.text : root.theme.muted + font.pixelSize: 9 + font.weight: Font.DemiBold + elide: Text.ElideRight + } + Label { + Layout.fillWidth: true + text: modelData + color: root.theme.muted + font.pixelSize: 7 + elide: Text.ElideMiddle + } + } + + Label { + text: hardening.recentResourceExists(index) ? "OPEN" : "MISSING" + color: hardening.recentResourceExists(index) ? root.theme.accent : root.theme.amber + font.pixelSize: 7 + font.weight: Font.Bold + } + } + + MouseArea { + id: resourceMouse + anchors.fill: parent + hoverEnabled: true + enabled: hardening.recentResourceExists(index) && !workspace.busy + onClicked: { + if (workspace.openFile(hardening.recentResourceUrl(index))) + root.viewIndex = 1 + } + } + } + } + } + } + + SurfaceCard { + Layout.preferredWidth: Math.max(330, root.width * 0.32) + Layout.fillHeight: true + Layout.minimumHeight: 260 + theme: root.theme + + ColumnLayout { + anchors.fill: parent + anchors.margins: 10 + spacing: 6 + + RowLayout { + Layout.fillWidth: true + Label { + text: "Recent online endpoints" + color: root.theme.text + font.pixelSize: 10 + font.weight: Font.DemiBold + } + Item { Layout.fillWidth: true } + Button { + visible: hardening.recentEndpoints.length > 0 + text: "Clear" + flat: true + onClicked: hardening.clearRecentEndpoints() + } + } + + Label { + visible: hardening.recentEndpoints.length === 0 + Layout.fillWidth: true + text: "No recent MMS endpoints yet. Automatic reconnect remains disabled." + color: root.theme.muted + font.pixelSize: 9 + wrapMode: Text.WordWrap + } + + ListView { + id: endpointList + Layout.fillWidth: true + Layout.fillHeight: true + clip: true + reuseItems: true + spacing: 2 + model: hardening.recentEndpoints + ScrollBar.vertical: ScrollBar {} + + delegate: Rectangle { + required property int index + required property string modelData + width: ListView.view.width + height: 38 + radius: 4 + color: endpointMouse.containsMouse ? root.theme.surfaceRaised : root.theme.surfaceSoft + border.width: 1 + border.color: root.theme.lineSoft + + RowLayout { + anchors.fill: parent + anchors.leftMargin: 9 + anchors.rightMargin: 8 + spacing: 8 + Label { + Layout.fillWidth: true + text: modelData + color: root.theme.textSoft + font.pixelSize: 9 + elide: Text.ElideRight + } + Label { + text: "BROWSE" + color: root.theme.accent + font.pixelSize: 7 + font.weight: Font.Bold + } + } + + MouseArea { + id: endpointMouse + anchors.fill: parent + hoverEnabled: true + onClicked: root.endpointRequested(hardening.recentHost(index), + hardening.recentPort(index)) + } + } + } + + Label { + Layout.fillWidth: true + text: "Selecting an endpoint restores address context only; it never auto-connects." + color: root.theme.muted + font.pixelSize: 7 + wrapMode: Text.WordWrap + } + } + } + } + + Item { Layout.preferredHeight: 8 } + } + } + + SclWorkspace { + theme: root.theme + workspace: root.workspace + } + } } } From f55846b520a55ca849f7e7431c2c33e0b44d91b2 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Sun, 20 Sep 2026 09:58:02 +0700 Subject: [PATCH 5/5] feat: route File Home launches through validated workspaces --- apps/ied_simulator/qml/Main.qml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/ied_simulator/qml/Main.qml b/apps/ied_simulator/qml/Main.qml index cbd2a22f9..31d72cd90 100644 --- a/apps/ied_simulator/qml/Main.qml +++ b/apps/ied_simulator/qml/Main.qml @@ -88,6 +88,8 @@ ApplicationWindow { // accepted the engineering file. Failed/unfinished imports never // become a trusted connection source. browserSession.trustedSclPath = sclWorkspace.loaded ? sclWorkspace.sourcePath : "" + if (sclWorkspace.loaded && sclWorkspace.sourcePath.length > 0) + hardening.rememberResource(sclWorkspace.sourcePath) } } @@ -270,6 +272,17 @@ ApplicationWindow { FileWorkspace { theme: appTheme workspace: sclWorkspace + hardening: hardening + onBrowserRequested: root.workspaceIndex = 1 + onEndpointRequested: function(host, port) { + if (!browserSession.configurationLocked) { + browserSession.host = host + browserSession.port = port + } + root.workspaceIndex = 1 + } + onSimulatorRequested: root.workspaceIndex = 2 + onSnifferRequested: root.workspaceIndex = 3 } IedBrowserWorkspace {