websocket.cfg 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. event_route[xhttp:request] {
  2. set_reply_close();
  3. set_reply_no_connect();
  4. #!ifdef WITH_XMLRPC
  5. if ($hu =~ "^/RPC") {
  6. route(XMLRPC);
  7. exit;
  8. }
  9. #!endif
  10. if ($Rp != MY_WS_PORT
  11. #!ifdef WITH_TLS
  12. && $Rp != MY_WSS_PORT
  13. #!endif
  14. ) {
  15. xlog("L_WARN", "HTTP request received on $Rp\n");
  16. xhttp_reply("403", "Forbidden - HTTP request received on $Rp", "", "");
  17. exit;
  18. }
  19. if ($hdr(Upgrade)=~"websocket"
  20. && in_list("Upgrade", $hdr(Connection), ",")
  21. && $rm=~"GET") {
  22. # Validate Host - make sure the client is using the correct
  23. # alias for WebSockets
  24. if ($hdr(Host) == $null || !is_myself("sip:" + $hdr(Host))) {
  25. xlog("L_WARN", "Bad host $hdr(Host)\n");
  26. xhttp_reply("403", "Forbidden - invalid host", "", "");
  27. exit;
  28. }
  29. #!ifdef WEBSOCKET_WEBSERVER
  30. # Validate Origin - make sure the client is from the authorised website
  31. if ($hdr(Origin) != "http://"+WEBSOCKET_WEBSERVER
  32. #!ifdef WITH_TLS
  33. && $hdr(Origin) != "https://"+WEBSOCKET_WEBSERVER
  34. #!endif
  35. ) {
  36. xlog("L_WARN", "Unauthorised client $hdr(Origin)\n");
  37. xhttp_reply("403", "Forbidden - invalid website", "", "");
  38. exit;
  39. }
  40. #!endif
  41. # ws_handle_handshake() exits (no further configuration file
  42. # processing of the request) when complete.
  43. if (ws_handle_handshake()) {
  44. # Optional... cache some information about the
  45. # successful connection
  46. exit;
  47. }
  48. }
  49. # xhttp_reply("200", "OK", "text/html", "<html><body>Wrong URL $hu</body></html>");
  50. xhttp_reply("404", "Not Found", "", "");
  51. }
  52. event_route[websocket:closed] {
  53. xlog("L_DBG", "WebSocket connection from $si:$sp has closed\n");
  54. }