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..89b54ba --- /dev/null +++ b/conf/cron_coturn @@ -0,0 +1,2 @@ +# Check if the IP as not changed at every 15th minute +*/15 * * * * root bash /__DATA_PATH__/Coturn_config_rotate.sh; \ No newline at end of file diff --git a/manifest.json b/manifest.json index 6fcf136..05886ff 100644 --- a/manifest.json +++ b/manifest.json @@ -8,7 +8,7 @@ }, "version": "4.5.1.1~ynh1", "url": "https://github.com/coturn/coturn", - "license": "MIT", + "license": "", "maintainer": { "name": "", "email": "" 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..b786bf0 100644 --- a/scripts/install +++ b/scripts/install @@ -25,7 +25,6 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" -#admin=$YNH_APP_ARG_ADMIN app=$YNH_APP_INSTANCE_NAME @@ -36,7 +35,7 @@ ynh_script_progression --message="Storing installation settings..." --weight=4 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url -#ynh_app_setting_set --app=$app --key=admin --value=$admin +ynh_app_setting_set --app=$app --key=no_sso --value true #================================================= # CREATE A DH FILE @@ -146,12 +145,30 @@ 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 +data_path="/home/yunohost.app/$app" +mkdir -p $data_path +cp -f ../sources/Coturn_config_rotate.sh $data_path/ +chmod +x $data_path/Coturn_config_rotate.sh + +#================================================= +# SET COTURN CRON +#================================================= + +cp -f ../conf/cron_coturn /etc/cron.d/$app +ynh_replace_string --match_string="__DATA_PATH__" --replace_string=$data_path --target_file=/etc/cron.d/$app + #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Configuring log rotation..." --weight=1 -ynh_use_logrotate +ynh_use_logrotate --logfile "/var/log/$app" #================================================= # GENERIC FINALIZATION @@ -160,11 +177,9 @@ ynh_use_logrotate #================================================= # Set permissions to app files -#chown -R root /var/log/$app -#hown -R root /etc/$app -#chmod -R u=rwX,g=rX,o= /etc/$app -#setfacl -R -m user:turnserver:rX /etc/$app -#setfacl -R -m user:turnserver:rwX /var/log/$app +chown root: -R $data_path +chown -R turnserver:root /var/log/$app +setfacl -R -m user:turnserver:rwX /var/log/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST diff --git a/scripts/remove b/scripts/remove index 4212dd4..28f82b8 100644 --- a/scripts/remove +++ b/scripts/remove @@ -17,11 +17,8 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) 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 #================================================= # STANDARD REMOVE @@ -42,7 +39,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 #================================================= @@ -56,11 +52,9 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing Coturn main directory..." --weight=2 +ynh_script_progression --message="Removing Coturn configuration file..." --weight=2 -ynh_secure_remove --file=/var/log/$app - -ynh_secure_remove --file=/etc/turnserver.conf +ynh_secure_remove --file="/etc/turnserver.conf" mv /etc/turnserver.conf.orig /etc/turnserver.conf #================================================= @@ -71,6 +65,25 @@ 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="/home/yunohost.app/$app" + +#================================================= +# REMOVE CRON JOB +#================================================= +# Remove a cron file +ynh_secure_remove --file="/etc/cron.d/$app" + +# Remove the log files +ynh_secure_remove --file="/var/log/$app/" + +# Remove the sqlitedb file +ynh_secure_remove --file="/var/lib/turn/" + #================================================= # CLOSE A PORT #================================================= @@ -96,7 +109,7 @@ closeport() { ynh_script_progression --message="Removing the dedicated system user..." --weight=1 # Delete a system user -deluser turnserver ssl-cert +ynh_system_user_delete --username=turnserver #================================================= # END OF SCRIPT diff --git a/sources/Coturn_config_rotate.sh b/sources/Coturn_config_rotate.sh new file mode 100644 index 0000000..f1351d6 --- /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 $app.service +fi + +exit 0