Вернул порт 8099 + 80

This commit is contained in:
Andrei Smaliak 2026-04-30 14:07:35 +04:00
parent 617c4e3d4f
commit 28bafe9f3e
5 changed files with 132 additions and 13 deletions

Binary file not shown.

View File

@ -44,6 +44,7 @@ UI_VERSION = "V 2.2.25"
DEFAULT_CONFIG = {
"bind": "0.0.0.0",
"port": 80,
"extra_ports": [],
"cache_ttl_sec": 3,
}
@ -140,6 +141,21 @@ def load_config():
data.update(loaded)
except Exception:
pass
extra_ports = data.get("extra_ports", [])
if not isinstance(extra_ports, list):
extra_ports = []
normalized_ports = []
seen_ports = set()
for raw_port in extra_ports:
try:
port = int(raw_port)
except Exception:
continue
if port < 1 or port > 65535 or port in seen_ports:
continue
seen_ports.add(port)
normalized_ports.append(port)
data["extra_ports"] = normalized_ports
return data
@ -3154,9 +3170,30 @@ def main():
cfg = load_config()
bind = str(cfg.get("bind", DEFAULT_CONFIG["bind"]))
port = int(cfg.get("port", DEFAULT_CONFIG["port"]))
server = ThreadingHTTPServer((bind, port), Handler)
print(f"[console] http://{bind}:{port}", file=sys.stderr)
server.serve_forever()
extra_ports = [
int(extra_port)
for extra_port in cfg.get("extra_ports", [])
if int(extra_port) != port
]
listen_ports = [port] + extra_ports
servers = []
threads = []
try:
for listen_port in listen_ports:
server = ThreadingHTTPServer((bind, listen_port), Handler)
servers.append(server)
print(f"[console] http://{bind}:{listen_port}", file=sys.stderr)
for server in servers[1:]:
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
threads.append(thread)
servers[0].serve_forever()
finally:
for server in servers:
try:
server.server_close()
except Exception:
pass
if __name__ == "__main__":

View File

@ -187,6 +187,8 @@ def _default_state():
"host": "",
"username": "",
"password": "",
"app_version": "",
"app_version_code": 0,
"token": "",
"organization": "",
"device_name": "",
@ -231,6 +233,8 @@ def save_state(state):
"host": str(state.get("host", "") or ""),
"username": str(state.get("username", "") or ""),
"password": str(state.get("password", "") or ""),
"app_version": str(state.get("app_version", "") or ""),
"app_version_code": int(state.get("app_version_code", 0) or 0),
"token": str(state.get("token", "") or ""),
"organization": str(state.get("organization", "") or ""),
"device_name": str(state.get("device_name", "") or ""),
@ -385,6 +389,20 @@ def _extract_registration_fields(server_state, event_payload, persisted):
merged["device_id"] = str(source.get("device_id"))
elif source.get("deviceId") not in (None, ""):
merged["device_id"] = str(source.get("deviceId"))
if source.get("app_version") not in (None, ""):
merged["app_version"] = str(source.get("app_version"))
elif source.get("client_version") not in (None, ""):
merged["app_version"] = str(source.get("client_version"))
if source.get("app_version_code") not in (None, ""):
try:
merged["app_version_code"] = int(source.get("app_version_code") or 0)
except Exception:
pass
elif source.get("version_code") not in (None, ""):
try:
merged["app_version_code"] = int(source.get("version_code") or 0)
except Exception:
pass
merged["device_name"] = merged.get("device_name") or _device_identity()["device_name"]
merged["device_id"] = _device_identity()["device_id"]
merged["registered"] = _bool_value((server_state or {}).get("registered"), default=False)
@ -478,6 +496,11 @@ def _normalize_registration_payload(server_state, persisted=None, source="mqtt",
device_name = _device_name_from_payload(payload)
host = _truncate_empty(payload.get("host")) or _truncate_empty(payload.get("server"))
password = _truncate_empty(payload.get("password"))
app_version = _truncate_empty(payload.get("app_version")) or _truncate_empty(payload.get("client_version")) or _truncate_empty(persisted.get("app_version"))
try:
app_version_code = int(payload.get("app_version_code") or payload.get("version_code") or persisted.get("app_version_code") or 0)
except Exception:
app_version_code = 0
meta = dict(contract_meta or {})
contract_prefix = _truncate_empty(meta.get("contract_prefix")) or _truncate_empty(persisted.get("contract_prefix"))
request_topic = _truncate_empty(meta.get("request_topic")) or _truncate_empty(persisted.get("request_topic"))
@ -491,6 +514,8 @@ def _normalize_registration_payload(server_state, persisted=None, source="mqtt",
"server": _text_or_default(host),
"host": _text_or_default(host),
"password": _text_or_default(password),
"app_version": _text_or_default(app_version),
"app_version_code": app_version_code,
"organization": _text_or_default(payload.get("organization")),
"token": _text_or_default(payload.get("token")),
"contract_prefix": _text_or_default(contract_prefix),
@ -873,6 +898,8 @@ def get_registration_status():
"host": _truncate_empty(merged_state.get("host")) or _truncate_empty(merged_state.get("server")),
"username": _truncate_empty(merged_state.get("username")),
"password": _truncate_empty(merged_state.get("password")),
"app_version": _truncate_empty(merged_state.get("app_version")) or _truncate_empty(merged_state.get("client_version")),
"app_version_code": int(merged_state.get("app_version_code") or merged_state.get("version_code") or 0),
"token": _truncate_empty(merged_state.get("token")),
"organization": _truncate_empty(merged_state.get("organization")),
"device_name": _device_name_from_payload(merged_state),
@ -904,6 +931,8 @@ def get_registration_status():
"host": _truncate_empty(config_fallback.get("host")),
"username": _truncate_empty(config_fallback.get("username")),
"password": _truncate_empty(config_fallback.get("password")),
"app_version": _truncate_empty(config_fallback.get("app_version")),
"app_version_code": int(config_fallback.get("app_version_code") or 0),
"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")),
@ -1027,6 +1056,8 @@ def reset_registration():
"host": _truncate_empty((server_state or {}).get("host")) or _truncate_empty((server_state or {}).get("server")),
"username": _truncate_empty((server_state or {}).get("username")),
"password": _truncate_empty((server_state or {}).get("password")),
"app_version": _truncate_empty((server_state or {}).get("app_version")) or _truncate_empty((server_state or {}).get("client_version")),
"app_version_code": int((server_state or {}).get("app_version_code") or (server_state or {}).get("version_code") or 0),
"token": _truncate_empty((server_state or {}).get("token")),
"organization": _truncate_empty((server_state or {}).get("organization")),
"device_name": _device_name_from_payload(server_state),

View File

@ -1031,6 +1031,10 @@
return state.itscreen.runtime || {};
}
function itscreenAppVersionFromRegistration(registration) {
return textValue(registration && registration.app_version, "");
}
function itscreenServerMode(host) {
const value = textValue(host, "").toLowerCase();
const option = ITSCREEN_SERVER_OPTIONS.find((item) => item.host === value);
@ -3869,7 +3873,10 @@
const registrationPayload = (payload && payload.data && typeof payload.data === "object")
? payload.data
: (payload.ok === false ? (nextData.registration || {}) : payload);
state.itscreen.data = { ...nextData, registration: registrationPayload };
const nextService = { ...(nextData.service || {}) };
const appVersion = itscreenAppVersionFromRegistration(registrationPayload);
if (appVersion) nextService.version = appVersion;
state.itscreen.data = { ...nextData, service: nextService, registration: registrationPayload };
const registration = state.itscreen.data.registration || {};
state.itscreen.error = (payload && payload.ok === false)
? (payload.error || t("It-screen status is unavailable"))
@ -4395,7 +4402,11 @@
body: JSON.stringify({ host: itscreenResolvedHost(), token: itscreenTokenInputValue(state.itscreen.customToken) })
});
const nextData = state.itscreen.data || {};
state.itscreen.data = { ...nextData, registration: payload.data || itscreenRegistration(), service: itscreenService() };
const registration = payload.data || itscreenRegistration();
const nextService = { ...(itscreenService() || {}) };
const appVersion = itscreenAppVersionFromRegistration(registration);
if (appVersion) nextService.version = appVersion;
state.itscreen.data = { ...nextData, registration, service: nextService };
syncItscreenFormFromBackend();
showToast("success", translateUiText(payload.message || t("Device successfully registered in cloud.")));
} catch (error) {
@ -4450,7 +4461,11 @@
body: "{}"
});
const nextData = state.itscreen.data || {};
state.itscreen.data = { ...nextData, registration: payload.data || itscreenRegistration(), service: itscreenService() };
const registration = payload.data || itscreenRegistration();
const nextService = { ...(itscreenService() || {}) };
const appVersion = itscreenAppVersionFromRegistration(registration);
if (appVersion) nextService.version = appVersion;
state.itscreen.data = { ...nextData, registration, service: nextService };
syncItscreenFormFromBackend();
showToast(payload.warning ? "warn" : "success", translateUiText(payload.warning || payload.message || t("Cloud registration has been reset.")));
} catch (error) {

View File

@ -36,6 +36,7 @@ SRC_LOGO="${LOGO_SOURCE:-$SCRIPT_DIR/iomatex_logo_source.png}"
SRC_GBOX="${GBOX_SOURCE:-$SCRIPT_DIR/g-box.png}"
APP_BIND="${CONSOLE_BIND:-0.0.0.0}"
APP_PORT="${CONSOLE_PORT:-80}"
APP_EXTRA_PORT="${CONSOLE_EXTRA_PORT:-8099}"
ts="$(date +%s)"
PREV_DIR="${APP_DIR}.prev.${ts}"
LEGACY_APP_DIR="/opt/iomatex-process1-webipc"
@ -73,10 +74,16 @@ rollback_deploy() {
}
wait_for_local_http() {
local attempt max_attempts url_root url_auth code_root code_auth
local attempt max_attempts url_root url_auth code_root code_auth extra_port extra_url_root extra_url_auth extra_code_root extra_code_auth
max_attempts=45
url_root="http://127.0.0.1:${APP_PORT}/"
url_auth="http://127.0.0.1:${APP_PORT}/api/auth/session"
extra_port=""
if [ -n "${APP_EXTRA_PORT}" ] && [ "${APP_EXTRA_PORT}" != "${APP_PORT}" ]; then
extra_port="${APP_EXTRA_PORT}"
extra_url_root="http://127.0.0.1:${extra_port}/"
extra_url_auth="http://127.0.0.1:${extra_port}/api/auth/session"
fi
echo "Smoke-check: waiting for local HTTP readiness on ${url_root}"
for attempt in $(seq 1 "${max_attempts}"); do
if ! systemctl is-active --quiet "${SERVICE_NAME}"; then
@ -89,19 +96,32 @@ wait_for_local_http() {
sleep 1
continue
fi
if [ -n "${extra_port}" ] && ! ss -ltnp 2>/dev/null | grep -q ":${extra_port} "; then
echo "Smoke-check attempt ${attempt}/${max_attempts}: nothing is listening on :${extra_port} yet"
sleep 1
continue
fi
code_root="$(curl -sS -o /tmp/iomatex-console-smoke-root.$$ -w '%{http_code}' --max-time 5 "${url_root}" 2>/tmp/iomatex-console-smoke-root.err || true)"
code_auth="$(curl -sS -o /tmp/iomatex-console-smoke-auth.$$ -w '%{http_code}' --max-time 5 "${url_auth}" 2>/tmp/iomatex-console-smoke-auth.err || true)"
echo "Smoke-check attempt ${attempt}/${max_attempts}: GET ${url_root} -> ${code_root:-curl_failed}; GET ${url_auth} -> ${code_auth:-curl_failed}"
if [ "${code_root}" = "200" ] && [ "${code_auth}" = "200" ]; then
if [ -n "${extra_port}" ]; then
extra_code_root="$(curl -sS -o /tmp/iomatex-console-smoke-extra-root.$$ -w '%{http_code}' --max-time 5 "${extra_url_root}" 2>/tmp/iomatex-console-smoke-extra-root.err || true)"
extra_code_auth="$(curl -sS -o /tmp/iomatex-console-smoke-extra-auth.$$ -w '%{http_code}' --max-time 5 "${extra_url_auth}" 2>/tmp/iomatex-console-smoke-extra-auth.err || true)"
echo "Smoke-check attempt ${attempt}/${max_attempts}: GET ${url_root} -> ${code_root:-curl_failed}; GET ${url_auth} -> ${code_auth:-curl_failed}; GET ${extra_url_root} -> ${extra_code_root:-curl_failed}; GET ${extra_url_auth} -> ${extra_code_auth:-curl_failed}"
else
echo "Smoke-check attempt ${attempt}/${max_attempts}: GET ${url_root} -> ${code_root:-curl_failed}; GET ${url_auth} -> ${code_auth:-curl_failed}"
fi
if [ "${code_root}" = "200" ] && [ "${code_auth}" = "200" ] \
&& { [ -z "${extra_port}" ] || { [ "${extra_code_root}" = "200" ] && [ "${extra_code_auth}" = "200" ]; }; }; then
if grep -Eq 'IOMATEX Console|console\.js|console\.css' "/tmp/iomatex-console-smoke-root.$$"; then
echo "Smoke-check passed: public shell and unauthenticated auth endpoint are reachable"
rm -f "/tmp/iomatex-console-smoke-root.$$" "/tmp/iomatex-console-smoke-auth.$$" "/tmp/iomatex-console-smoke-root.err" "/tmp/iomatex-console-smoke-auth.err"
rm -f "/tmp/iomatex-console-smoke-root.$$" "/tmp/iomatex-console-smoke-auth.$$" "/tmp/iomatex-console-smoke-root.err" "/tmp/iomatex-console-smoke-auth.err" "/tmp/iomatex-console-smoke-extra-root.$$" "/tmp/iomatex-console-smoke-extra-auth.$$" "/tmp/iomatex-console-smoke-extra-root.err" "/tmp/iomatex-console-smoke-extra-auth.err"
return 0
fi
echo "Smoke-check attempt ${attempt}/${max_attempts}: root page returned 200 but did not look like the WEB UI shell yet"
elif [ "${code_root}" = "200" ] && [ "${code_auth}" = "401" -o "${code_auth}" = "302" ]; then
elif [ "${code_root}" = "200" ] && [ "${code_auth}" = "401" -o "${code_auth}" = "302" ] \
&& { [ -z "${extra_port}" ] || { [ "${extra_code_root}" = "200" ] && { [ "${extra_code_auth}" = "401" ] || [ "${extra_code_auth}" = "302" ]; }; }; }; then
echo "Smoke-check passed: login/public shell is up and auth flow responded with ${code_auth}"
rm -f "/tmp/iomatex-console-smoke-root.$$" "/tmp/iomatex-console-smoke-auth.$$" "/tmp/iomatex-console-smoke-root.err" "/tmp/iomatex-console-smoke-auth.err"
rm -f "/tmp/iomatex-console-smoke-root.$$" "/tmp/iomatex-console-smoke-auth.$$" "/tmp/iomatex-console-smoke-root.err" "/tmp/iomatex-console-smoke-auth.err" "/tmp/iomatex-console-smoke-extra-root.$$" "/tmp/iomatex-console-smoke-extra-auth.$$" "/tmp/iomatex-console-smoke-extra-root.err" "/tmp/iomatex-console-smoke-extra-auth.err"
return 0
fi
sleep 1
@ -109,6 +129,10 @@ wait_for_local_http() {
echo "Smoke-check failed after ${max_attempts} attempts" >&2
echo "Listener snapshot on :${APP_PORT}:" >&2
ss -ltnp 2>/dev/null | grep ":${APP_PORT} " >&2 || echo " nothing listening on :${APP_PORT}" >&2
if [ -n "${extra_port}" ]; then
echo "Listener snapshot on :${extra_port}:" >&2
ss -ltnp 2>/dev/null | grep ":${extra_port} " >&2 || echo " nothing listening on :${extra_port}" >&2
fi
if [ -f "/tmp/iomatex-console-smoke-root.err" ] && [ -s "/tmp/iomatex-console-smoke-root.err" ]; then
echo "Last curl stderr for ${url_root}:" >&2
cat "/tmp/iomatex-console-smoke-root.err" >&2 || true
@ -117,7 +141,15 @@ wait_for_local_http() {
echo "Last curl stderr for ${url_auth}:" >&2
cat "/tmp/iomatex-console-smoke-auth.err" >&2 || true
fi
rm -f "/tmp/iomatex-console-smoke-root.$$" "/tmp/iomatex-console-smoke-auth.$$" "/tmp/iomatex-console-smoke-root.err" "/tmp/iomatex-console-smoke-auth.err"
if [ -f "/tmp/iomatex-console-smoke-extra-root.err" ] && [ -s "/tmp/iomatex-console-smoke-extra-root.err" ]; then
echo "Last curl stderr for ${extra_url_root}:" >&2
cat "/tmp/iomatex-console-smoke-extra-root.err" >&2 || true
fi
if [ -f "/tmp/iomatex-console-smoke-extra-auth.err" ] && [ -s "/tmp/iomatex-console-smoke-extra-auth.err" ]; then
echo "Last curl stderr for ${extra_url_auth}:" >&2
cat "/tmp/iomatex-console-smoke-extra-auth.err" >&2 || true
fi
rm -f "/tmp/iomatex-console-smoke-root.$$" "/tmp/iomatex-console-smoke-auth.$$" "/tmp/iomatex-console-smoke-root.err" "/tmp/iomatex-console-smoke-auth.err" "/tmp/iomatex-console-smoke-extra-root.$$" "/tmp/iomatex-console-smoke-extra-auth.$$" "/tmp/iomatex-console-smoke-extra-root.err" "/tmp/iomatex-console-smoke-extra-auth.err"
return 1
}
@ -196,6 +228,7 @@ cat > "$CFG_PATH" <<JSON
{
"bind": "${APP_BIND}",
"port": ${APP_PORT},
"extra_ports": [${APP_EXTRA_PORT}],
"cache_ttl_sec": 3
}
JSON
@ -310,8 +343,11 @@ fi
step "Summary"
echo "Web UI: http://<EDGE-IP>"
echo "Web UI (extra): http://<EDGE-IP>:${APP_EXTRA_PORT}"
echo "Login shell: curl -i http://127.0.0.1/ | cat"
echo "Login shell (extra): curl -i http://127.0.0.1:${APP_EXTRA_PORT}/ | cat"
echo "Auth session API: curl -i http://127.0.0.1/api/auth/session | cat"
echo "Auth session API (extra): curl -i http://127.0.0.1:${APP_EXTRA_PORT}/api/auth/session | cat"
echo "Protected status API (expected 401 without session): curl -i http://127.0.0.1/api/status | cat"
echo "Service status: systemctl status ${SERVICE_NAME} --no-pager -n 40"
echo "Install dir: ${APP_DIR}"