diff --git a/README.md b/README.md index 308fe88..6363e5c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ How to configure this app: a plain file with SSH. For testing we can use Trickle-Ice testing tool. Go to [trickle-ice page](https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice) and enter following details. ``` -STUN or TURN URI : turn::5349 +TURN URI : turn::5349 TURN username: TURN password: ``` diff --git a/conf/cron_coturn b/conf/cron_coturn new file mode 100644 index 0000000..4fe0cc3 --- /dev/null +++ b/conf/cron_coturn @@ -0,0 +1,3 @@ +# Check if the IP as not changed at every 15th minute +# */15 * * * * root bash /__SCRIPT_PATH__/Coturn_config_rotate.sh; +*/15 * * * * __USER__ bash /__SCRIPT_PATH__/Coturn_config_rotate.sh; \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index b293f7c..1ab2257 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -15,7 +15,6 @@ pkg_dependencies="sqlite3 libsqlite3-dev coturn acl" # EXPERIMENTAL HELPERS #================================================= - # Send an email to inform the administrator # # usage: ynh_send_readme_to_admin --app_message=app_message [--recipients=recipients] [--type=type] @@ -152,4 +151,3 @@ __PRE_TAG1__$(yunohost tools diagnosis | grep -B 100 "services:" | sed '/service # Send the email to the recipients cat mail_to_send | $mail_bin -a "Content-Type: $content_type; charset=UTF-8" -s "$mail_subject" "$recipients" } - diff --git a/scripts/install b/scripts/install index 971deb1..a988000 100644 --- a/scripts/install +++ b/scripts/install @@ -146,6 +146,27 @@ fi ynh_store_file_checksum --file="$coturn_config_path" + +#================================================= +# ADD SCRIPT FOR COTURN CRON +#================================================= + +# WARNING : theses command are used in INSTALL, UPGRADE +# For any update do it in all files +script_path=/opt/yunohost/coturn +ynh_app_setting_set --app=$app --key=script_path --value=$script_path +mkdir $script_path +cp ../sources/Coturn_config_rotate.sh $script_path/Coturn_config_rotate.sh +chmod +x $script_path/Coturn_config_rotate.sh + +#================================================= +# SET COTURN CRON +#================================================= + +cp ../conf/cron_coturn /etc/cron.d/$app +ynh_replace_string --match_string="__USER__" --replace_string=turnserver --target_file=/etc/cron.d/$app +ynh_replace_string --match_string="__SCRIPT_PATH__" --replace_string=$script_path --target_file=/etc/cron.d/$app + #================================================= # SETUP LOGROTATE #================================================= diff --git a/scripts/remove b/scripts/remove index 4212dd4..50b141c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -22,6 +22,7 @@ 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) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name +script_path=$(ynh_app_setting_get --app=$app --key=script_path) #================================================= # STANDARD REMOVE @@ -42,7 +43,6 @@ fi ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 # Remove the dedicated systemd config -#ynh_remove_systemd_config ynh_remove_systemd_config #================================================= @@ -71,6 +71,19 @@ ynh_script_progression --message="Removing logrotate configuration..." --weight= # Remove the app-specific logrotate config ynh_remove_logrotate +#================================================= +# REMOVE SCRIPT +#================================================= + +# Remove coturn/Coturn_config_rotate.sh +ynh_secure_remove --file=$script_path + +#================================================= +# REMOVE CRON JOB +#================================================= + +ynh_secure_remove --file="/etc/cron.d/$app" + #================================================= # CLOSE A PORT #================================================= diff --git a/sources/Coturn_config_rotate.sh b/sources/Coturn_config_rotate.sh new file mode 100644 index 0000000..9ac92e4 --- /dev/null +++ b/sources/Coturn_config_rotate.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +source /usr/share/yunohost/helpers + +external_IP_line="external-ip=__IPV4__,__IPV6__" + +public_ip4="$(curl ip.yunohost.org)" || true +public_ip6="$(curl ipv6.yunohost.org)" || true + +if [ -n "$public_ip4" ] && ynh_validate_ip4 --ip_address="$public_ip4" +then + echo "external-ip=$public_ip4" >> "$coturn_config_path" +fi + +if [ -n "$public_ip6" ] && ynh_validate_ip6 --ip_address="$public_ip6" +then + echo "external-ip=$public_ip6" >> "$coturn_config_path" +fi + +old_config_line=$(egrep "^external-ip=.*\$" "/etc/turnserver.conf") +ynh_replace_string "^external-ip=.*\$" "$external_IP_line" "/etc/turnserver.conf" +new_config_line=$(egrep "^external-ip=.*\$" "/etc/turnserver.conf") + +#setfacl -R -m user:turnserver:rX /etc/$app_instance + +if [ "$old_config_line" != "$new_config_line" ] +then + systemctl restart coturn.service +fi + +exit 0