Software /
code /
prosody-modules
Annotate
mod_turn_external/mod_turn_external.lua @ 5210:898575a0c6f3
mod_http_oauth2: Switch to '303 See Other' redirects
This is the recommendation by draft-ietf-oauth-v2-1-07 section 7.5.2. It is
the only redirect code that guarantees the user agent will use a GET request,
rather than re-submitting a POST request to the new URL.
The latter would be bad for us, as we are encoding auth tokens in the form
data.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 06 Mar 2023 10:37:43 +0000 |
parent | 4895:2542fd80cd15 |
rev | line source |
---|---|
4894
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local set = require "util.set"; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local secret = module:get_option_string("turn_external_secret"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local host = module:get_option_string("turn_external_host", module.host); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local user = module:get_option_string("turn_external_user"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local port = module:get_option_number("turn_external_port", 3478); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local ttl = module:get_option_number("turn_external_ttl", 86400); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local tcp = module:get_option_boolean("turn_external_tcp", false); |
4895
2542fd80cd15
mod_turn_external: Fix type of config option (thanks mirux)
Kim Alvefur <zash@zash.se>
parents:
4894
diff
changeset
|
9 local tls_port = module:get_option_number("turn_external_tls_port"); |
4894
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 if not secret then error("mod_" .. module.name .. " requires that 'turn_external_secret' be set") end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local services = set.new({ "stun-udp"; "turn-udp" }); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 if tcp then |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 services:add("stun-tcp"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 services:add("turn-tcp"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 if tls_port then |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 services:add("turns-tcp"); |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 module:depends "external_services"; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 for _, type in ipairs({ "stun"; "turn"; "turns" }) do |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 for _, transport in ipairs({"udp"; "tcp"}) do |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 if services:contains(type .. "-" .. transport) then |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 module:add_item("external_service", { |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 type = type; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 transport = transport; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 host = host; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 port = type == "turns" and tls_port or port; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 username = type == "turn" and user or nil; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 secret = type == "turn" and secret or nil; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 ttl = type == "turn" and ttl or nil; |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 }) |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |
bfa2cca2bdd5
mod_turn_external: Import from prosody trunk @ ed23bbf3b946
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 end |