From ad013d0e05fe2cf7e3f95645aff1697a49a47c81 Mon Sep 17 00:00:00 2001 From: glougloumoute Date: Mon, 1 Feb 2021 09:13:07 +0100 Subject: [PATCH] Add metronome configuration snippet --- conf/metronome.cfg.lua | 50 ++++++++++++++++++++++++++++++++++++++++++ scripts/_common.sh | 2 ++ scripts/install | 26 ++++++++++++++++++++++ scripts/remove | 16 ++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 conf/metronome.cfg.lua diff --git a/conf/metronome.cfg.lua b/conf/metronome.cfg.lua new file mode 100644 index 0000000..06d6225 --- /dev/null +++ b/conf/metronome.cfg.lua @@ -0,0 +1,50 @@ +external_services = { + ["__DOMAIN__"] = { + [1] = { + port = "__STANDARD_PORT__", + transport = "udp", + type = "stun" + }, + + [2] = { + port = "__STANDARD_PORT__", + transport = "tcp", + type = "stun" + }, + + [3] = { + port = "__TLS_PORT__", + transport = "tcp", + type = "stuns" + }, + [4] = { + port = "__STANDARD_PORT__", + transport = "tcp", + type = "turn", + turn_secret = "__TURNPWD__", + turn_ttl = 300 + }, + + [5] = { + port = "__STANDARD_PORT__", + transport = "udp", + type = "turn", + turn_secret = "__TURNPWD__", + turn_ttl = 7200 + }, + + [6] = { + port = "__TLS_PORT__", + transport = "tcp", + type = "turns", + turn_secret = "__TURNPWD__", + turn_ttl = 7200 + } + } +}; + +jingle_nodes_turn_credentials = true; +jingle_nodes_turn_secret = "__TURNPWD__"; +jingle_nodes_turn_credentials_ttl = 86400; +jingle_nodes_restricted = false; + diff --git a/scripts/_common.sh b/scripts/_common.sh index 1ab2257..0724f2b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,8 @@ # dependencies used by the app pkg_dependencies="sqlite3 libsqlite3-dev coturn acl" +metronome_snippet_path="/etc/metronome/conf.d/coturn.cfg.lua" + #================================================= # PERSONAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 71d3712..c86e3c4 100644 --- a/scripts/install +++ b/scripts/install @@ -59,15 +59,20 @@ fi ynh_script_progression --message="Finding an available port..." --weight=3 # Find an available port +turnserver_standard_port=$(ynh_find_port --port=3478) turnserver_tls_port=$(ynh_find_port --port=5349) turnserver_alt_tls_port=$(ynh_find_port --port=$((turnserver_tls_port+1))) cli_port=$(ynh_find_port --port=5766) +# TODO also reserve UDP Port range 49152:65535 + # Open the port +ynh_exec_warn_less yunohost firewall allow Both $turnserver_standard_port ynh_exec_warn_less yunohost firewall allow Both $turnserver_tls_port ynh_exec_warn_less yunohost firewall allow Both $turnserver_alt_tls_port # Store opened ports +ynh_app_setting_set --app=$app --key=turnserver_standard_port --value=$turnserver_standard_port ynh_app_setting_set --app=$app --key=turnserver_tls_port --value=$turnserver_tls_port ynh_app_setting_set --app=$app --key=turnserver_alt_tls_port --value=$turnserver_alt_tls_port ynh_app_setting_set --app=$app --key=cli_port --value=$cli_port @@ -164,6 +169,27 @@ ynh_script_progression --message="Configuring log rotation..." --weight=1 ynh_use_logrotate --logfile "/var/log/$app" +#================================================= +# ADD METRONOME CONFIGURATION +#================================================= + +#ynh_add_config --template="metronome.cfg.lua" --destination="$metronome_snippet_path" +cp ../conf/metronome.cfg.lua "$metronome_snippet_path" +ynh_replace_string --target_file="$metronome_snippet_path" --match_string=__APP__ --replace_string=$app +ynh_replace_string --target_file="$metronome_snippet_path" --match_string=__DOMAIN__ --replace_string=$domain +ynh_replace_string --target_file="$metronome_snippet_path" --match_string=__STANDARD_PORT__ --replace_string=$turnserver_standard_port +ynh_replace_string --target_file="$metronome_snippet_path" --match_string=__TLS_PORT__ --replace_string=$turnserver_tls_port +ynh_print_OFF +ynh_replace_string --target_file="$metronome_snippet_path" --match_string=__TURNPWD__ --replace_string=$turnserver_pwd +ynh_print_ON + +# TODO make sure the two following modules are enabled in metronome's main config +# "extdisco"; +# "jingle_nodes"; + + +ynh_systemd_action --action="reload" --service_name="metronome" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/remove b/scripts/remove index b5e86a4..046a126 100644 --- a/scripts/remove +++ b/scripts/remove @@ -17,6 +17,7 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) +turnserver_standard_port=$(ynh_app_setting_get --app=$app --key=turnserver_standard_port) turnserver_tls_port=$(ynh_app_setting_get --app=$app --key=turnserver_tls_port) turnserver_alt_tls_port=$(ynh_app_setting_get --app=$app --key=turnserver_alt_tls_port) @@ -65,6 +66,13 @@ ynh_script_progression --message="Removing logrotate configuration..." --weight= # Remove the app-specific logrotate config ynh_remove_logrotate +#================================================= +# REMOVE METRONOME CONFIGURATION +#================================================= + +ynh_secure_remove --file="$metronome_snippet_path" +ynh_systemd_action --action="reload" --service_name="metronome" + #================================================= # REMOVE SCRIPT #================================================= @@ -89,6 +97,12 @@ ynh_secure_remove --file=/var/log/$app # CLOSE PORTS #================================================= +if yunohost firewall list | grep -q "\- $turnserver_standard_port$" +then + ynh_script_progression --message="Closing port $turnserver_standard_port..." --weight=1 + ynh_exec_warn_less yunohost firewall disallow Both $turnserver_standard_port +fi + if yunohost firewall list | grep -q "\- $turnserver_tls_port$" then ynh_script_progression --message="Closing port $turnserver_tls_port..." --weight=1 @@ -101,6 +115,8 @@ then ynh_exec_warn_less yunohost firewall disallow Both $turnserver_alt_tls_port fi +# TODO also release UDP port range 49152:65535 + #================================================= # GENERIC FINALIZATION #=================================================