diff --git a/stage_ui/console_core/backend/app.py b/stage_ui/console_core/backend/app.py index 63c8dc6..fe98572 100644 --- a/stage_ui/console_core/backend/app.py +++ b/stage_ui/console_core/backend/app.py @@ -39,7 +39,7 @@ APP_DIR = "/opt/iomatex-console" PUBLIC_DIR = os.path.join(APP_DIR, "public") PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d") CONFIG_PATH = "/etc/iomatex/console.json" -UI_VERSION = "V 2.2.3" +UI_VERSION = "V 2.2.4" DEFAULT_CONFIG = { "bind": "0.0.0.0", diff --git a/stage_ui/console_core/backend/itscreen_registration.py b/stage_ui/console_core/backend/itscreen_registration.py index fbe2b66..41aa5b4 100644 --- a/stage_ui/console_core/backend/itscreen_registration.py +++ b/stage_ui/console_core/backend/itscreen_registration.py @@ -25,6 +25,7 @@ HOST_RE = re.compile(r"^(?=.{1,253}$)(?!-)[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za- DEVICE_ID_PATH = "/userdata/device-id" DEVICE_ID_RE = re.compile(r"^g-box-[a-f0-9]{8}$") SETTINGS_CATEGORY = "server" +ITSCREEN_CONFIG_PATH = "/var/lib/itscreen/config/it-screen/it-screen.conf" SETTINGS_CONTRACTS = ( {"contract_prefix": "it-screen", "base_prefix": "it-screen/$devices/settings"}, {"contract_prefix": "iomatex", "base_prefix": "iomatex/$devices/settings"}, @@ -264,6 +265,45 @@ def _bool_value(value, default=False): return bool(value) +def _read_simple_key_value_file(path): + data = {} + try: + with open(path, "r", encoding="utf-8", errors="ignore") as fh: + for raw_line in fh: + line = raw_line.strip() + if not line or line.startswith("[") or "=" not in line: + continue + key, value = line.split("=", 1) + key = key.strip() + if not key: + continue + data[key] = value.strip() + except Exception: + return {} + return data + + +def _load_registration_from_itscreen_config(device_id, persisted=None): + if not os.path.exists(ITSCREEN_CONFIG_PATH): + return {} + raw = _read_simple_key_value_file(ITSCREEN_CONFIG_PATH) + if not raw: + return {} + host = _truncate_empty(raw.get("server")) + contract_hint = _host_contract_hint(host) or DEFAULT_CONTRACT_PREFIX + contract_meta = _build_contract_topics(device_id, contract_hint) + payload = { + "host": host, + "server": host, + "username": _truncate_empty(raw.get("deviceName")) or _truncate_empty(raw.get("devTitle")) or device_id, + "password": _truncate_empty(raw.get("password")), + "device_name": _truncate_empty(raw.get("deviceName")) or _truncate_empty(raw.get("devTitle")) or device_id, + "registered": _bool_value(raw.get("isRegistered"), default=False), + "logged": _bool_value(raw.get("isLogged"), default=False), + } + return _normalize_registration_payload(payload, persisted=persisted, source="config", contract_meta=contract_meta) + + def _extract_response_payload(response_text): raw = str(response_text or "").strip() if not raw: @@ -728,6 +768,30 @@ def get_registration_status(): state["status"] = "error" if persisted.get("status") != "registering" else persisted.get("status") fallback = _build_public_status(state) error_text, details = _public_error(exc) + config_fallback = _load_registration_from_itscreen_config(state["device_id"], persisted=state) + if config_fallback: + merged = _default_state() + merged.update(state) + merged.update({ + "host": _truncate_empty(config_fallback.get("host")), + "username": _truncate_empty(config_fallback.get("username")), + "password": _truncate_empty(config_fallback.get("password")), + "device_name": _truncate_empty(config_fallback.get("device_name")), + "contract_prefix": _truncate_empty(config_fallback.get("contract_prefix")), + "request_topic": _truncate_empty(config_fallback.get("request_topic")), + "response_topic": _truncate_empty(config_fallback.get("response_topic")), + "registered": _bool_value(config_fallback.get("registered"), default=False), + "logged": _bool_value(config_fallback.get("logged"), default=False), + "status": "ready" if _bool_value(config_fallback.get("registered"), default=False) else "not_registered", + }) + save_state(merged) + fallback = _build_public_status(merged, error_text=error_text) + return { + "ok": True, + "warning": error_text, + "details": details, + "data": fallback, + } return { "ok": False, "error": error_text, diff --git a/stage_ui/console_core/frontend/console.js b/stage_ui/console_core/frontend/console.js index 40a4169..7e58434 100644 --- a/stage_ui/console_core/frontend/console.js +++ b/stage_ui/console_core/frontend/console.js @@ -43,7 +43,7 @@ { mode: "test_by", label: "TEST BY", host: "rest.test.it-screen.by" }, { mode: "custom", label: "Custom", host: "" } ]; - const UI_VERSION = "V 2.2.3"; + const UI_VERSION = "V 2.2.4"; const ITSCREEN_LOG_INITIAL_LINES = 50; const ITSCREEN_LOG_BUFFER_LIMIT = 300; const ITSCREEN_LOG_BATCH_MS = 250;