From c70cc50c99eb3f2fa7bbf3ff49138d2e9975d1b6 Mon Sep 17 00:00:00 2001 From: Mehdi Aslani Date: Wed, 4 Nov 2026 10:18:19 +0330 Subject: [PATCH] ... --- .run/backend.pid | 2 +- .run/frontend.pid | 2 +- .../layout/AdminMenu.tsx | 9 +- .../layout/MenuItems.tsx | 9 +- .../locales/En/English.json | 47 +- .../locales/Pe/Persian.json | 47 +- .../routes/AppRoutes.tsx | 2 + .../pages/settings/nginx/NginxManagement.tsx | 11 +- .../pages/settings/nginx/RTPSettings.tsx | 411 +++++++ .../sip-profile-parameters/SipParams.tsx | 38 +- .../pages/sip/sip-users/SipUsers.tsx | 124 +- installer/debian/nginx-manager | 4 +- logs/backend/backend.log | 144 ++- logs/frontend/frontend.log | 6 +- .../NginxManagementController.java | 407 ++++++- .../SipProfileDetailsController.java | 8 +- .../java/ir/peeco/pline/init/Initializer.java | 57 +- .../peeco/pline/plineServer/PlineTools.java | 35 +- .../fileGeneratorTools/HttpGenerator.java | 4 +- .../PlineSettingsGenerator.java | 1017 +++++++++-------- 20 files changed, 1785 insertions(+), 599 deletions(-) create mode 100644 cti_app/src/components/pages/settings/nginx/RTPSettings.tsx diff --git a/.run/backend.pid b/.run/backend.pid index 4699bfb..1b510ec 100644 --- a/.run/backend.pid +++ b/.run/backend.pid @@ -1 +1 @@ -2922310 +329755 diff --git a/.run/frontend.pid b/.run/frontend.pid index 3addcb5..0ee56c5 100644 --- a/.run/frontend.pid +++ b/.run/frontend.pid @@ -1 +1 @@ -2922459 +329872 diff --git a/cti_app/src/components/application-components/layout/AdminMenu.tsx b/cti_app/src/components/application-components/layout/AdminMenu.tsx index 3ecb27c..194eeb7 100644 --- a/cti_app/src/components/application-components/layout/AdminMenu.tsx +++ b/cti_app/src/components/application-components/layout/AdminMenu.tsx @@ -117,11 +117,18 @@ export const AdminMenu = [ { id: "180", label: "setting.nginx.title", - class: "end", link: "/settings/nginx", access: "1_18", icon: , }, + { + id: "181", + label: "nginxManagement.rtpSettingsTitle", + class: "end", + link: "/settings/rtp", + access: "1_18", + icon: , + }, ], }, { diff --git a/cti_app/src/components/application-components/layout/MenuItems.tsx b/cti_app/src/components/application-components/layout/MenuItems.tsx index 54715d9..4feb3b8 100644 --- a/cti_app/src/components/application-components/layout/MenuItems.tsx +++ b/cti_app/src/components/application-components/layout/MenuItems.tsx @@ -119,11 +119,18 @@ export const menuData = [ { id: "180", label: "setting.nginx.title", - class: "end", link: "/settings/nginx", access: "1_18", icon: , }, + { + id: "181", + label: "nginxManagement.rtpSettingsTitle", + class: "end", + link: "/settings/rtp", + access: "1_18", + icon: , + }, ], }, { diff --git a/cti_app/src/components/application-components/locales/En/English.json b/cti_app/src/components/application-components/locales/En/English.json index 28849fc..322a3bc 100644 --- a/cti_app/src/components/application-components/locales/En/English.json +++ b/cti_app/src/components/application-components/locales/En/English.json @@ -79,7 +79,7 @@ "title": "Settings", "about": "About", "certificates": "SSL Certificates", - "nginx": { "title": "Nginx Management" }, + "nginx": { "title": "WebServer Management" }, "ami_ari_information": "ARI/AMI ID Information", "feature": "Feature Codes", "backup": "Take Backup / Restore Backup", @@ -125,7 +125,7 @@ } }, "nginxManagement": { - "title": "Nginx Management", + "title": "WebServer Management", "baseTitle": "Protected base configuration", "webrtc": "WebRTC proxy", "webrtcHelp": "Choose how browser signaling reaches Asterisk. RTP/DTLS media still connects directly to Asterisk and needs its UDP ports reachable.", @@ -147,6 +147,43 @@ "dtlsFullchain": "DTLS certificate", "dtlsPrivateKey": "DTLS private key", "dtlsRequired": "Paste the DTLS certificate and matching private key.", + "rtpSettingsTitle": "RTP Settings", + "saveRtp": "Save RTP settings", + "rtpSuccess": "RTP, ICE, and TURN settings applied successfully.", + "rtpRange": "Asterisk UDP RTP port range", + "rtpStart": "RTP start port", + "rtpEnd": "RTP end port", + "rtpHelp": "Open this UDP range in the server firewall. The settings apply to Asterisk RTP.", + "stunHost": "Asterisk STUN hostname or IP (optional)", + "stunPort": "Asterisk STUN port", + "clientStunHost": "Browser client STUN hostname or IP (optional)", + "clientStunPort": "Browser client STUN port", + "clientStunHelp": "This STUN server is sent to WebRTC clients in iceServers. It is separate from Asterisk's RTP STUN setting above.", + "iceHostCandidates": "Static ICE address mappings (one per line)", + "iceHostCandidatesHelp": "Use local IP => public IP for a server behind one-to-one NAT. Leave STUN empty when mappings are set.", + "includeLocalIceCandidates": "Advertise both local and public ICE addresses", + "turnTitle": "TURN relay (coturn) client settings", + "turnEnabled": "Use TURN for browser clients", + "turnHelp": "These settings generate time-limited TURN credentials for SIP user QR codes. Configure coturn separately with the same shared secret, realm, ports, relay range, and TLS files.", + "turnHost": "TURN hostname or IP", + "turnRealm": "TURN realm", + "turnCredentialTtl": "Credential lifetime (seconds)", + "turnUdpPort": "TURN UDP/TCP port", + "turnTlsPort": "TURN over TLS port", + "turnRelayStart": "Relay range start", + "turnRelayEnd": "Relay range end", + "turnUdp": "UDP", + "turnTcp": "TCP", + "turnTls": "TLS (turns)", + "turnInternalIp": "Coturn Internal IP (optional)", + "turnExternalIp": "Coturn Public IP (optional)", + "turnTlsCertPath": "coturn TLS certificate path", + "turnTlsKeyPath": "coturn TLS private key path", + "turnSharedSecret": "Coturn Shared Secret", + "turnSecretKeep": "Leave blank to keep the saved secret", + "turnSecretConfigured": "A secret is saved and will not be returned to the browser. Leave blank to keep it or enter a new secret.", + "turnSecretRequired": "Set the same secret on coturn. Use at least 32 characters.", + "turnExternalNotice": "This page does not install or change coturn. Apply matching use-auth-secret/static-auth-secret, realm, listening ports, relay range, NAT mapping, and certificate paths on the TURN server.", "hostSsl": "Host SSL", "serverName": "Server name (server_name)", "httpPort": "HTTP port", @@ -288,11 +325,9 @@ "qr_show": "Show SIP user QR code", "qr_title": "SIP user QR code", "qr_settings_title": "QR settings", - "qr_settings_help": "Enter the SIP server or hostname and TURN settings. Port and WebRTC are read from each user's SIP profile.", + "qr_settings_help": "Enter the SIP server or hostname for non-WebRTC accounts. WebRTC signaling and TURN are taken from central settings.", "qr_server_ip": "SIP Server or Hostname", - "qr_turn_server": "TURN server", - "qr_turn_user": "TURN user", - "qr_turn_password": "TURN password", + "qr_turn_central": "WebRTC QR codes use the central signaling/TURN configuration. TURN credentials are generated for this SIP user and expire automatically.", "qr_ip_required": "Enter the SIP server or hostname", "qr_profile_missing": "No SIP profile is assigned to this user", "qr_profile_port_missing": "No port was found in the SIP profile's transport.bind setting", diff --git a/cti_app/src/components/application-components/locales/Pe/Persian.json b/cti_app/src/components/application-components/locales/Pe/Persian.json index 39d36f2..d6faa8e 100644 --- a/cti_app/src/components/application-components/locales/Pe/Persian.json +++ b/cti_app/src/components/application-components/locales/Pe/Persian.json @@ -81,7 +81,7 @@ "title": "تنظیمات", "about": "دربارهٔ سیستم", "certificates": "گواهینامه‌های SSL", - "nginx": { "title": "مدیریت Nginx" }, + "nginx": { "title": "مدیریت وب‌سرور" }, "advance": "تنظیمات بیشتر", "ha": "دسترس بودن بالا (HA)", "personalize": "شخصی سازی", @@ -130,7 +130,7 @@ } }, "nginxManagement": { - "title": "مدیریت Nginx", + "title": "مدیریت وب‌سرور", "baseTitle": "تنظیمات اصلی و قفل‌شده", "webrtc": "پروکسی WebRTC", "webrtcHelp": "روش اتصال سیگنال‌دهی مرورگر به Asterisk را انتخاب کنید. صدای RTP/DTLS همچنان مستقیماً به Asterisk می‌رسد و پورت‌های UDP آن باید در دسترس باشند.", @@ -152,6 +152,43 @@ "dtlsFullchain": "گواهی DTLS", "dtlsPrivateKey": "کلید خصوصی DTLS", "dtlsRequired": "گواهی DTLS و کلید خصوصی متناظر را وارد کنید.", + "rtpSettingsTitle": "RTP Settings", + "saveRtp": "ذخیره تنظیمات RTP", + "rtpSuccess": "تنظیمات RTP، ICE و TURN با موفقیت اعمال شد.", + "rtpRange": "بازه پورت UDP رسانهٔ RTP در Asterisk", + "rtpStart": "پورت آغاز RTP", + "rtpEnd": "پورت پایان RTP", + "rtpHelp": "این بازهٔ UDP را در فایروال سرور باز کنید. تنظیمات روی RTP در Asterisk اعمال می‌شود.", + "stunHost": "نام میزبان یا IP سرور STUN در Asterisk (اختیاری)", + "stunPort": "پورت STUN در Asterisk", + "clientStunHost": "نام میزبان یا IP سرور STUN برای مرورگر (اختیاری)", + "clientStunPort": "پورت STUN برای مرورگر", + "clientStunHelp": "این STUN در iceServers به کلاینت WebRTC فرستاده می‌شود و از STUN مربوط به RTP در Asterisk جداست.", + "iceHostCandidates": "نگاشت ثابت نشانی ICE (هر خط یک مورد)", + "iceHostCandidatesHelp": "برای سرور پشت NAT یک‌به‌یک، local IP => public IP بنویسید. اگر نگاشت وارد شده، STUN را خالی بگذارید.", + "includeLocalIceCandidates": "ارسال هم‌زمان نشانی محلی و عمومی ICE", + "turnTitle": "تنظیمات TURN برای کلاینت‌ها (coturn)", + "turnEnabled": "استفاده از TURN برای کلاینت‌های مرورگر", + "turnHelp": "این مقادیر برای QR کاربران SIP اعتبار موقت TURN می‌سازند. coturn جداگانه و با secret، realm، پورت‌ها، بازهٔ relay و فایل‌های TLS یکسان تنظیم می‌شود.", + "turnHost": "نام میزبان یا IP سرور TURN", + "turnRealm": "قلمرو (realm) در TURN", + "turnCredentialTtl": "مدت اعتبار رمز (ثانیه)", + "turnUdpPort": "پورت TURN روی UDP/TCP", + "turnTlsPort": "پورت TURN روی TLS", + "turnRelayStart": "ابتدای بازهٔ Relay", + "turnRelayEnd": "انتهای بازهٔ Relay", + "turnUdp": "UDP", + "turnTcp": "TCP", + "turnTls": "TLS (turns)", + "turnInternalIp": "Coturn Internal IP (optional)", + "turnExternalIp": "Coturn Public IP (optional)", + "turnTlsCertPath": "مسیر گواهی TLS در coturn", + "turnTlsKeyPath": "مسیر کلید خصوصی TLS در coturn", + "turnSharedSecret": "Coturn Shared Secret", + "turnSecretKeep": "برای نگه‌داشتن رمز ذخیره‌شده خالی بگذارید", + "turnSecretConfigured": "رمز ذخیره شده و به مرورگر برگردانده نمی‌شود. برای حفظ آن خالی بگذارید یا رمز جدید وارد کنید.", + "turnSecretRequired": "همین رمز را در coturn هم تنظیم کنید؛ حداقل ۳۲ نویسه.", + "turnExternalNotice": "این صفحه coturn را نصب یا تغییر نمی‌دهد. use-auth-secret و static-auth-secret، realm، پورت‌ها، بازهٔ relay، نگاشت NAT و مسیر گواهی را در سرور TURN همسان تنظیم کنید.", "hostSsl": "SSL میزبان", "serverName": "نام سرور (server_name)", "httpPort": "پورت HTTP", @@ -279,11 +316,9 @@ "qr_show": "نمایش QR داخلی", "qr_title": "QR داخلی", "qr_settings_title": "تنظیمات QR", - "qr_settings_help": "سرور SIP یا نام میزبان و تنظیمات TURN را وارد کنید؛ پورت و WebRTC از پروفایل هر داخلی خوانده می‌شود.", + "qr_settings_help": "برای داخلی‌های غیر WebRTC، سرور SIP یا نام میزبان را وارد کنید. نشانی سیگنال‌دهی WebRTC و TURN از تنظیمات مرکزی گرفته می‌شود.", "qr_server_ip": "سرور SIP یا نام میزبان", - "qr_turn_server": "سرور TURN", - "qr_turn_user": "کاربر TURN", - "qr_turn_password": "رمز TURN", + "qr_turn_central": "QR کاربران WebRTC از تنظیمات مرکزی سیگنال‌دهی و TURN استفاده می‌کند. اعتبار TURN برای همان داخلی ساخته می‌شود و خودکار منقضی می‌شود.", "qr_ip_required": "سرور SIP یا نام میزبان را وارد کنید", "qr_profile_missing": "برای این داخلی پروفایل SIP مشخص نشده است", "qr_profile_port_missing": "پورت در تنظیمات transport.bind پروفایل SIP پیدا نشد", diff --git a/cti_app/src/components/application-components/routes/AppRoutes.tsx b/cti_app/src/components/application-components/routes/AppRoutes.tsx index 9e78ba1..2ebf7e8 100644 --- a/cti_app/src/components/application-components/routes/AppRoutes.tsx +++ b/cti_app/src/components/application-components/routes/AppRoutes.tsx @@ -78,6 +78,7 @@ const Certificates = React.lazy(() => import("../../pages/settings/certificate/C const QueueReports = React.lazy(() => import("../../pages/monitoring/queue-reports/QueueReports")); const About = React.lazy(() => import("../../pages/settings/about/About")); const NginxManagement = React.lazy(() => import("../../pages/settings/nginx/NginxManagement")); +const RTPSettings = React.lazy(() => import("../../pages/settings/nginx/RTPSettings")); export interface IAppRouteNode { path: string; @@ -98,6 +99,7 @@ export const AppRoutes = [ { path: "/settings/cti-settings", element: }, { path: "/settings/about", element: }, { path: "/settings/nginx", element: }, + { path: "/settings/rtp", element: }, { path: "/settings/system-sip-settings", element: }, { path: "/sip-profiles/index", element: }, { path: "/sip-profiles/edit/:id", element: }, diff --git a/cti_app/src/components/pages/settings/nginx/NginxManagement.tsx b/cti_app/src/components/pages/settings/nginx/NginxManagement.tsx index 97cd820..d5da375 100644 --- a/cti_app/src/components/pages/settings/nginx/NginxManagement.tsx +++ b/cti_app/src/components/pages/settings/nginx/NginxManagement.tsx @@ -29,8 +29,9 @@ interface WebRtcConfiguration { const API = "/nginx-management"; const ACCESS = AccessCodeSettings.Nginx; const defaultHost: HostSettings = { serverName: "_", httpPort: 80, httpsPort: 443, redirectHttpToHttps: true }; -const defaultWebRtc: WebRtcConfiguration = { mode: "proxy", dtlsMode: "auto", serverName: "_", port: 443 }; - +const defaultWebRtc: WebRtcConfiguration = { + mode: "proxy", dtlsMode: "auto", serverName: "_", port: 443, +}; const NginxManagement: React.FC = () => { const { t } = useTranslation(); const [loading, setLoading] = useState(true); @@ -56,7 +57,10 @@ const NginxManagement: React.FC = () => { setHost({ ...defaultHost, ...(current.host ?? {}) }); setSavedHttpsPort(Number(current.host?.httpsPort ?? 443)); setSavedHttpPort(Number(current.host?.httpPort ?? 80)); - setWebRtc({ ...defaultWebRtc, ...(current.webrtc ?? {}) }); + setWebRtc({ + ...defaultWebRtc, + ...(current.webrtc ?? {}), + }); setFullchain(current.sslContents?.fullchain ?? ""); setPrivateKey(current.sslContents?.privateKey ?? ""); } @@ -111,7 +115,6 @@ const NginxManagement: React.FC = () => { }, ACCESS, RequestActions.Update); setBusy(false); if (response && !response.Error) { - setWebRtc({ ...webRtc, ...(response.data?.result?.webrtc ?? {}) }); setDtlsFullchain(""); setDtlsPrivateKey(""); toast.success(t("nginxManagement.webrtcSuccess")); diff --git a/cti_app/src/components/pages/settings/nginx/RTPSettings.tsx b/cti_app/src/components/pages/settings/nginx/RTPSettings.tsx new file mode 100644 index 0000000..55a3f3d --- /dev/null +++ b/cti_app/src/components/pages/settings/nginx/RTPSettings.tsx @@ -0,0 +1,411 @@ +import React, { useEffect, useState } from "react"; +import { Alert, Button, Card, Col, Form, Row, Spinner } from "react-bootstrap"; +import { useTranslation } from "react-i18next"; +import toast from "react-hot-toast"; +import RequestService from "../../../services/RequestService"; +import { AccessCodeSettings, RequestActions } from "../../../application-components/user/Permissions/AccessCodes"; + +interface RtpConfiguration { + rtpStart: number; + rtpEnd: number; + stunHost: string; + stunPort: number; + clientStunHost: string; + clientStunPort: number; + iceHostCandidates: string; + includeLocalIceCandidates: boolean; + turnEnabled: boolean; + turnHost: string; + turnPort: number; + turnTlsPort: number; + turnUdpEnabled: boolean; + turnTcpEnabled: boolean; + turnTlsEnabled: boolean; + turnRelayStart: number; + turnRelayEnd: number; + turnRealm: string; + turnInternalIp: string; + turnExternalIp: string; + turnTlsCertPath: string; + turnTlsPrivateKeyPath: string; + turnCredentialTtlSeconds: number; + turnSecretConfigured: boolean; +} + +const API = "/nginx-management"; +const ACCESS = AccessCodeSettings.Nginx; +const defaultRtp: RtpConfiguration = { + rtpStart: 10000, + rtpEnd: 20000, + stunHost: "", + stunPort: 3478, + clientStunHost: "", + clientStunPort: 3478, + iceHostCandidates: "", + includeLocalIceCandidates: false, + turnEnabled: false, + turnHost: "", + turnPort: 3478, + turnTlsPort: 5349, + turnUdpEnabled: true, + turnTcpEnabled: false, + turnTlsEnabled: false, + turnRelayStart: 49152, + turnRelayEnd: 65535, + turnRealm: "", + turnInternalIp: "", + turnExternalIp: "", + turnTlsCertPath: "", + turnTlsPrivateKeyPath: "", + turnCredentialTtlSeconds: 3600, + turnSecretConfigured: false, +}; + +const RTPSettings: React.FC = () => { + const { t } = useTranslation(); + const [loading, setLoading] = useState(true); + const [busy, setBusy] = useState(false); + const [rtp, setRtp] = useState(defaultRtp); + const [turnSharedSecret, setTurnSharedSecret] = useState(""); + + const load = async () => { + setLoading(true); + const response = await RequestService.GetRequest(API, ACCESS, RequestActions.Read); + if (response && !response.Error && response.data?.result?.rtp) { + const current = response.data.result.rtp; + setRtp({ + ...defaultRtp, + ...current, + iceHostCandidates: Array.isArray(current.iceHostCandidates) + ? current.iceHostCandidates.join("\n") + : current.iceHostCandidates ?? "", + }); + } + setLoading(false); + }; + + useEffect(() => { void load(); }, []); + + const save = async (event: React.FormEvent) => { + event.preventDefault(); + setBusy(true); + const response = await RequestService.PostRequest(`${API}/rtp`, { + rtpStart: Number(rtp.rtpStart), + rtpEnd: Number(rtp.rtpEnd), + stunHost: rtp.stunHost, + stunPort: Number(rtp.stunPort), + clientStunHost: rtp.clientStunHost, + clientStunPort: Number(rtp.clientStunPort), + iceHostCandidates: rtp.iceHostCandidates, + includeLocalIceCandidates: rtp.includeLocalIceCandidates, + turnEnabled: rtp.turnEnabled, + turnHost: rtp.turnHost, + turnPort: Number(rtp.turnPort), + turnTlsPort: Number(rtp.turnTlsPort), + turnUdpEnabled: rtp.turnUdpEnabled, + turnTcpEnabled: rtp.turnTcpEnabled, + turnTlsEnabled: rtp.turnTlsEnabled, + turnRelayStart: Number(rtp.turnRelayStart), + turnRelayEnd: Number(rtp.turnRelayEnd), + turnRealm: rtp.turnRealm, + turnInternalIp: rtp.turnInternalIp, + turnExternalIp: rtp.turnExternalIp, + turnTlsCertPath: rtp.turnTlsCertPath, + turnTlsPrivateKeyPath: rtp.turnTlsPrivateKeyPath, + turnCredentialTtlSeconds: Number(rtp.turnCredentialTtlSeconds), + turnSharedSecret, + }, ACCESS, RequestActions.Update); + setBusy(false); + if (response && !response.Error) { + setTurnSharedSecret(""); + toast.success(t("nginxManagement.rtpSuccess")); + await load(); + } + }; + + if (loading) { + return ( + + + + ); + } + + return ( + +

{t("nginxManagement.rtpSettingsTitle")}

+ + {t("nginxManagement.rtpSettingsTitle")} + +
+ + {t("nginxManagement.rtpRange")} + + + setRtp({ ...rtp, rtpStart: Number(e.target.value) })} + /> + + + setRtp({ ...rtp, rtpEnd: Number(e.target.value) })} + /> + + + {t("nginxManagement.rtpHelp")} + + + + + {t("nginxManagement.stunHost")} + setRtp({ ...rtp, stunHost: e.target.value })} + placeholder="stun.example.com" + autoComplete="off" + /> + + + + + {t("nginxManagement.stunPort")} + setRtp({ ...rtp, stunPort: Number(e.target.value) })} + /> + + + + + + + {t("nginxManagement.clientStunHost")} + setRtp({ ...rtp, clientStunHost: e.target.value })} + placeholder="stun.example.com" + autoComplete="off" + /> + + + + + {t("nginxManagement.clientStunPort")} + setRtp({ ...rtp, clientStunPort: Number(e.target.value) })} + /> + + + + {t("nginxManagement.clientStunHelp")} + + {t("nginxManagement.iceHostCandidates")} + setRtp({ ...rtp, iceHostCandidates: e.target.value })} + placeholder="192.168.1.10 => 203.0.113.10" + autoComplete="off" + spellCheck={false} + /> + {t("nginxManagement.iceHostCandidatesHelp")} + + setRtp({ ...rtp, includeLocalIceCandidates: e.target.checked })} + /> +
+
+
{t("nginxManagement.turnTitle")}
+ setRtp({ ...rtp, turnEnabled: e.target.checked })} + /> +
+

{t("nginxManagement.turnHelp")}

+ {rtp.turnEnabled && ( + <> + + + + {t("nginxManagement.turnHost")} + setRtp({ ...rtp, turnHost: e.target.value })} + placeholder="turn.example.com" + autoComplete="off" + /> + + + + + {t("nginxManagement.turnRealm")} + setRtp({ ...rtp, turnRealm: e.target.value })} + autoComplete="off" + /> + + + + + {t("nginxManagement.turnCredentialTtl")} + setRtp({ ...rtp, turnCredentialTtlSeconds: Number(e.target.value) })} + /> + + + + + + + {t("nginxManagement.turnUdpPort")} + setRtp({ ...rtp, turnPort: Number(e.target.value) })} /> + + + + + {t("nginxManagement.turnTlsPort")} + setRtp({ ...rtp, turnTlsPort: Number(e.target.value) })} /> + + + + + {t("nginxManagement.turnRelayStart")} + setRtp({ ...rtp, turnRelayStart: Number(e.target.value) })} /> + + + + + {t("nginxManagement.turnRelayEnd")} + setRtp({ ...rtp, turnRelayEnd: Number(e.target.value) })} /> + + + +
+ setRtp({ ...rtp, turnUdpEnabled: e.target.checked })} + /> + setRtp({ ...rtp, turnTcpEnabled: e.target.checked })} + /> + setRtp({ ...rtp, turnTlsEnabled: e.target.checked })} + /> +
+ + + + {t("nginxManagement.turnInternalIp")} + setRtp({ ...rtp, turnInternalIp: e.target.value })} autoComplete="off" /> + + + + + {t("nginxManagement.turnExternalIp")} + setRtp({ ...rtp, turnExternalIp: e.target.value })} autoComplete="off" /> + + + + {rtp.turnTlsEnabled && ( + + + + {t("nginxManagement.turnTlsCertPath")} + setRtp({ ...rtp, turnTlsCertPath: e.target.value })} autoComplete="off" /> + + + + + {t("nginxManagement.turnTlsKeyPath")} + setRtp({ ...rtp, turnTlsPrivateKeyPath: e.target.value })} autoComplete="off" /> + + + + )} + + {t("nginxManagement.turnSharedSecret")} + setTurnSharedSecret(e.target.value)} + minLength={rtp.turnSecretConfigured ? undefined : 32} + maxLength={256} + required={!rtp.turnSecretConfigured} + autoComplete="new-password" + placeholder={rtp.turnSecretConfigured ? t("nginxManagement.turnSecretKeep") : ""} + /> + + {rtp.turnSecretConfigured + ? t("nginxManagement.turnSecretConfigured") + : t("nginxManagement.turnSecretRequired")} + + + {t("nginxManagement.turnExternalNotice")} + + )} +
+
+ +
+ +
+
+ + ); +}; + +export default RTPSettings; diff --git a/cti_app/src/components/pages/sip/sip-profiles/sip-profile-parameters/SipParams.tsx b/cti_app/src/components/pages/sip/sip-profiles/sip-profile-parameters/SipParams.tsx index 8cb701e..df7e05f 100644 --- a/cti_app/src/components/pages/sip/sip-profiles/sip-profile-parameters/SipParams.tsx +++ b/cti_app/src/components/pages/sip/sip-profiles/sip-profile-parameters/SipParams.tsx @@ -45,7 +45,7 @@ const SipParams = () => { const [loading, setLoading] = useState(true); //url params comes here name and id const profileParam = useParams(); - const [editingRow, setEditingRow] = useState(null); + const [editingRow, setEditingRow] = useState(null); //grid data comes here const [rowData, setRowData] = useState([]); //skeleton loading state for reRendering Form @@ -74,6 +74,9 @@ const SipParams = () => { //create and update data from store here const [state, setState] = useState(initialState); + const getRowKey = (row: Pick) => + JSON.stringify([row.ParamType, row.parameter]); + const navigate = useNavigate(); //grid Cols const columns = [ @@ -425,6 +428,7 @@ const SipParams = () => { //Delete params from grid function DeleteRow(params: any) { + const rowKey = getRowKey(params.data); return ( <> { className="mx-2 edit-icon" // Only call handleEditRow if the row is not currently being edited onClick={() => { - if (editingRow !== params.data.parameter) { + if (editingRow !== rowKey) { handleEditRow(params.data); - setEditingRow(params.data.parameter); + setEditingRow(rowKey); } }} /> @@ -442,17 +446,23 @@ const SipParams = () => { style={{ paddingLeft: "8px" }} className="delete-icon" onClick={() => { - const rowIndexInOriginalData = rowData.findIndex( - (row: any) => row.parameter === params.data.parameter + setRowData((currentRows: InputItem[]) => + currentRows.filter((row) => getRowKey(row) !== rowKey) ); - if (rowIndexInOriginalData !== -1) { - const updatedRowData = [...rowData]; - updatedRowData.splice(rowIndexInOriginalData, 1); - setRowData(updatedRowData); - // Check if the row being deleted is the one being edited, and reset the editing state - if (editingRow === rowIndexInOriginalData) { - setEditingRow(null); - } + setSelected((currentRows: InputItem[]) => + currentRows.filter((row) => getRowKey(row) !== rowKey) + ); + setState((currentState: any) => { + const updatedType = { ...currentState[params.data.ParamType] }; + delete updatedType[params.data.parameter]; + return { ...currentState, [params.data.ParamType]: updatedType }; + }); + if (editingRow === rowKey) { + setEditingRow(null); + setMode(false); + setSelectedParamType(null); + setSelectedParam([]); + setRenderedFormControls([]); } }} size={28} @@ -570,6 +580,7 @@ const SipParams = () => { if (mode) { setMode(false); + setEditingRow(null); } setLoading(false); } @@ -660,6 +671,7 @@ const SipParams = () => { onChange={(e: any) => { if (mode) { setMode(false); + setEditingRow(null); } handleParamChange(e); }} diff --git a/cti_app/src/components/pages/sip/sip-users/SipUsers.tsx b/cti_app/src/components/pages/sip/sip-users/SipUsers.tsx index 4cb2d35..d7ea8b9 100644 --- a/cti_app/src/components/pages/sip/sip-users/SipUsers.tsx +++ b/cti_app/src/components/pages/sip/sip-users/SipUsers.tsx @@ -45,9 +45,6 @@ import QRCode from "qrcode"; type QrSettings = { ip: string; - turnServer: string; - turnUser: string; - turnPassword: string; }; const SipUsers = () => { @@ -68,15 +65,11 @@ const SipUsers = () => { const [qrSettings, setQrSettings] = useState(() => { const defaultSettings = { ip: "", - turnServer: "", - turnUser: "", - turnPassword: "", }; try { const savedSettings = localStorage.getItem("sipUserQrSettings"); - return savedSettings - ? { ...defaultSettings, ...JSON.parse(savedSettings) } - : defaultSettings; + const parsed = savedSettings ? JSON.parse(savedSettings) : {}; + return { ip: typeof parsed.ip === "string" ? parsed.ip : defaultSettings.ip }; } catch { return defaultSettings; } @@ -99,6 +92,13 @@ const SipUsers = () => { [], ); + useEffect(() => { + // Remove legacy TURN secrets that older versions stored in this browser. + try { + localStorage.setItem("sipUserQrSettings", JSON.stringify({ ip: qrSettings.ip })); + } catch { /* QR settings remain usable for this session. */ } + }, []); + const toggleSipSelection = (uid: string | number, checked: boolean) => { const uidStr = String(uid); @@ -165,11 +165,6 @@ const SipUsers = () => { }; const showUserQrCode = async (row: any) => { - if (!qrSettings.ip.trim()) { - toast.error(t("sipUsers.qr_ip_required")); - return; - } - const profileId = row.sipProfile?.id; if (!profileId) { toast.error(t("sipUsers.qr_profile_missing")); @@ -195,22 +190,53 @@ const SipUsers = () => { const details = result.data; const bind = String(details?.transport?.bind || ""); const portMatch = bind.match(/:(\d{1,5})\s*$/); - const port = portMatch ? Number(portMatch[1]) : NaN; + const webrtcValue = String(details?.endpoint?.webrtc || "").toLowerCase(); + const isWebRtc = ["yes", "true", "1"].includes(webrtcValue); + let websocketUrl = ""; + let turn: any = { urls: [], username: "", credential: "", expiresAt: 0 }; + let iceServers: any[] = []; + let port = portMatch ? Number(portMatch[1]) : NaN; + let serverIp = qrSettings.ip.trim(); + if (isWebRtc) { + const settings: any = await RequestService.GetRequest( + `/nginx-management/client-settings?username=${encodeURIComponent(String(row.uid || ""))}`, + AccessCodeSip.SipUsers, + RequestActions.Read, + ); + if (!settings?.hasPermission || settings.Error || !settings.data?.result?.signalingUrl) { + toast.error(settings?.hasPermission === false ? t("globals.error_permission") : t("sipUsers.qr_generate_error")); + return; + } + websocketUrl = String(settings.data.result.signalingUrl); + turn = settings.data.result.turn ?? turn; + iceServers = settings.data.result.iceServers ?? []; + const signalingAddress = new URL(websocketUrl); + if (!serverIp) serverIp = signalingAddress.hostname; + port = signalingAddress.port ? Number(signalingAddress.port) : 443; + } + if (!serverIp) { + toast.error(t("sipUsers.qr_ip_required")); + return; + } if (!Number.isInteger(port) || port < 1 || port > 65535) { toast.error(t("sipUsers.qr_profile_port_missing")); return; } - - const webrtcValue = String(details?.endpoint?.webrtc || "").toLowerCase(); const qrPayload = { - ip: qrSettings.ip.trim(), + ip: serverIp, port, - isWebRtc: ["yes", "true", "1"].includes(webrtcValue), + isWebRtc, user: String(row.uid || ""), pass: String(row.password || ""), - turnServer: qrSettings.turnServer.trim(), - turnUser: qrSettings.turnUser.trim(), - turnPassword: qrSettings.turnPassword, + ...(isWebRtc ? { + websocketUrl, + iceServers, + turnServers: turn.urls ?? [], + turnServer: turn.urls?.[0] ?? "", + turnUser: turn.username ?? "", + turnPassword: turn.credential ?? "", + turnCredentialExpiresAt: turn.expiresAt ?? 0, + } : {}), }; const image = await QRCode.toDataURL(JSON.stringify(qrPayload), { width: 300, @@ -229,7 +255,7 @@ const SipUsers = () => { const saveQrSettings = () => { try { - localStorage.setItem("sipUserQrSettings", JSON.stringify(qrSettings)); + localStorage.setItem("sipUserQrSettings", JSON.stringify({ ip: qrSettings.ip })); toast.success(t("sipUsers.qr_settings_saved")); setQrSettingsModalOpen(false); } catch { @@ -757,8 +783,9 @@ const SipUsers = () => { >
event.preventDefault()}>

{t("sipUsers.qr_settings_help")}

+
{t("sipUsers.qr_turn_central")}
- + {t("sipUsers.qr_server_ip")} @@ -775,55 +802,6 @@ const SipUsers = () => { required /> - - - {t("sipUsers.qr_turn_server")} - - - setQrSettings((current) => ({ - ...current, - turnServer: event.target.value, - })) - } - autoComplete="off" - /> - - - - {t("sipUsers.qr_turn_user")} - - - setQrSettings((current) => ({ - ...current, - turnUser: event.target.value, - })) - } - autoComplete="off" - /> - - - - {t("sipUsers.qr_turn_password")} - - - setQrSettings((current) => ({ - ...current, - turnPassword: event.target.value, - })) - } - autoComplete="new-password" - /> -