diff --git a/db/knex_migrations/2025-02-15-2312-add-wstest.js b/db/knex_migrations/2025-02-15-2312-add-wstest.js index c2b640f3e..36f81acfa 100644 --- a/db/knex_migrations/2025-02-15-2312-add-wstest.js +++ b/db/knex_migrations/2025-02-15-2312-add-wstest.js @@ -1,13 +1,15 @@ -// Add websocket ignore headers +// Add websocket ignore headers and websocket subprotocol exports.up = function (knex) { return knex.schema .alterTable("monitor", function (table) { table.boolean("ws_ignore_headers").notNullable().defaultTo(false); + table.string("subprotocol", 255).notNullable().defaultTo(""); }); }; exports.down = function (knex) { return knex.schema.alterTable("monitor", function (table) { table.dropColumn("ws_ignore_headers"); + table.dropColumn("subprotocol"); }); }; diff --git a/server/model/monitor.js b/server/model/monitor.js index fecde2d24..e5f2f4499 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -97,6 +97,7 @@ class Monitor extends BeanModel { childrenIDs: preloadData.childrenIDs.get(this.id) || [], url: this.url, wsIgnoreHeaders: this.getWsIgnoreHeaders(), + subprotocol: this.subprotocol, method: this.method, hostname: this.hostname, port: this.port, diff --git a/server/monitor-types/websocket-upgrade.js b/server/monitor-types/websocket-upgrade.js index aa18ef07a..8b2b64be3 100644 --- a/server/monitor-types/websocket-upgrade.js +++ b/server/monitor-types/websocket-upgrade.js @@ -21,7 +21,9 @@ class WebSocketMonitorType extends MonitorType { */ async attemptUpgrade(monitor) { return new Promise((resolve) => { - const ws = new WebSocket(monitor.url); + let ws; + //If user selected a subprotocol, sets Sec-WebSocket-Protocol header. Subprotocol Identifier column: https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name + ws = monitor.subprotocol === "" ? new WebSocket(monitor.url) : new WebSocket(monitor.url, monitor.subprotocol); ws.addEventListener("open", (event) => { // Immediately close the connection diff --git a/server/server.js b/server/server.js index d8aa67a38..2d5a911e0 100644 --- a/server/server.js +++ b/server/server.js @@ -791,6 +791,7 @@ let needSetup = false; bean.type = monitor.type; bean.url = monitor.url; bean.wsIgnoreHeaders = monitor.wsIgnoreHeaders; + bean.subprotocol = monitor.subprotocol; bean.method = monitor.method; bean.body = monitor.body; bean.headers = monitor.headers; diff --git a/src/lang/en.json b/src/lang/en.json index ff2923b58..22d5ac2e2 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -88,6 +88,37 @@ "upsideDownModeDescription": "Flip the status upside down. If the service is reachable, it is DOWN.", "wsIgnoreHeadersDescription": "The websocket upgrade succeeds, but the server does not reply with Sec-WebSocket-Accept header.", "Ignore Sec-WebSocket-Accept header": "Ignore Sec-WebSocket-Accept header", + "wamp": "WAMP (The WebSocket Application Messaging Protocol)", + "sip": "WebSocket Transport for SIP (Session Initiation Protocol)", + "notificationchannel-netapi-rest.openmobilealliance.org": "OMA RESTful Network API for Notification Channel", + "wpcp": "Web Process Control Protocol (WPCP)", + "amqp": "Advanced Message Queuing Protocol (AMQP) 1.0+", + "jsflow": "jsFlow pubsub/queue protocol", + "rwpcp": "Reverse Web Process Control Protocol (RWPCP)", + "xmpp": "WebSocket Transport for the Extensible Messaging and Presence Protocol (XMPP)", + "ship": "SHIP - Smart Home IP", + "mielecloudconnect": "Miele Cloud Connect Protocol", + "v10.pcp.sap.com": "Push Channel Protocol", + "msrp": "WebSocket Transport for MSRP (Message Session Relay Protocol)", + "bfcp": "WebSocket Transport for BFCP (Binary Floor Control Protocol)", + "sldp.softvelum.com": "Softvelum Low Delay Protocol", + "opcua+uacp": "OPC UA Connection Protocol", + "opcua+uajson": "OPC UA JSON Encoding", + "v1.swindon-lattice+json": "Swindon Web Server Protocol (JSON encoding)", + "v1.usp": "USP (Broadband Forum User Services Platform)", + "coap": "Constrained Application Protocol (CoAP)", + "webrtc.softvelum.com": "Softvelum WebSocket signaling protocol", + "cobra.v2.json": "Cobra Real Time Messaging Protocol", + "drp": "Declarative Resource Protocol", + "hub.bsc.bacnet.org": "BACnet Secure Connect Hub Connection", + "dc.bsc.bacnet.org": "BACnet Secure Connect Direct Connection", + "jmap": "WebSocket Transport for JMAP (JSON Meta Application Protocol)", + "t140": "ITU-T T.140 Real-Time Text", + "done": "Done.best IoT Protocol", + "collection-update": "The Collection Update Websocket Subprotocol", + "text.ircv3.net": "Text IRC Protocol", + "binary.ircv3.net": "Binary IRC Protocol", + "v3.penguin-stats.live+proto": "Penguin Statistics Live Protocol v3 (Protobuf encoding)", "maxRedirectDescription": "Maximum number of redirects to follow. Set to 0 to disable redirects.", "Upside Down Mode": "Upside Down Mode", "Max. Redirects": "Max. Redirects", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index c5a61f6bd..aa686850b 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -122,6 +122,77 @@ + +