From 51678b834d7bba8dac1aadf341582fa5f35d06db Mon Sep 17 00:00:00 2001 From: anmol Date: Sat, 17 Oct 2020 17:22:59 +0530 Subject: [PATCH] Port fixes --- scripts/install | 12 ++++++------ scripts/remove | 8 ++++---- scripts/restore | 14 +++++++------- scripts/upgrade | 28 +++++++++++----------------- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/scripts/install b/scripts/install index 80d77ff..55cc6aa 100755 --- a/scripts/install +++ b/scripts/install @@ -52,8 +52,8 @@ ynh_script_progression --message="Configuring firewall..." ### - Remove the section "CLOSE A PORT" in the remove script # Find an available port -port=$(ynh_find_port --port=$squid_port) -ynh_app_setting_set --app=$app --key=port --value=$port +squid_port=$(ynh_find_port --port=$squid_port) +ynh_app_setting_set --app=$app --key=squid_port --value=$squid_port ynh_app_setting_set --app=$app --key=new_port --value=$new_port # Optional: Expose this port publicly @@ -61,7 +61,7 @@ ynh_app_setting_set --app=$app --key=new_port --value=$new_port # If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) # Open the port - ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port + ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port #================================================= # INSTALL DEPENDENCIES @@ -98,7 +98,7 @@ else ynh_die "No squid folder found in /etc. Looks like squid 3 package is not installed. Try installing it manually by apt-get install squid3" fi -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/squid.conf" +ynh_replace_string --match_string="__PORT__" --replace_string="$squid_port" --target_file="../conf/squid.conf" ynh_replace_string --match_string="__SQUID__" --replace_string="$squid" --target_file="../conf/squid.conf" cp -f "../conf/squid.conf" "/etc/$squid/." # Save squid folder in app settings @@ -167,7 +167,7 @@ ynh_script_progression --message="Starting a systemd service..." ### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script # Start a systemd service -ynh_systemd_action --service_name=$squid --action="restart" --log_path="/var/log/$squid/access.log" +ynh_systemd_action --service_name=$squid --action="restart" --log_path="/var/log/$squid/cache.log" yunohost app ssowatconf @@ -184,7 +184,7 @@ Enter these value in the below feilds. --------------------------------------------------------------------- | Http proxy: Your any registered domain name or ip eg domain.tld | -|port: $port +|port: $squid_port | |Tick mark use this proxy server for all protocols | diff --git a/scripts/remove b/scripts/remove index b92ca03..d2870ba 100755 --- a/scripts/remove +++ b/scripts/remove @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -port=$(ynh_app_setting_get $app port) +squid_port=$(ynh_app_setting_get $app squid_port) squid=$(ynh_app_setting_get $app squid_folder) #================================================= @@ -42,10 +42,10 @@ ynh_remove_app_dependencies # CLOSE A PORT #================================================= -if yunohost firewall list | grep -q "\- $port$" +if yunohost firewall list | grep -q "\- $squid_port$" then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port + ynh_script_progression --message="Closing port $squid_port..." + ynh_exec_warn_less yunohost firewall disallow TCP $squid_port fi #================================================= diff --git a/scripts/restore b/scripts/restore index 1427b8c..8f48729 100755 --- a/scripts/restore +++ b/scripts/restore @@ -26,7 +26,7 @@ ynh_abort_if_errors app=$YNH_APP_INSTANCE_NAME -port=$(ynh_app_setting_get $app port) +squid_port=$(ynh_app_setting_get $app squid_port) #================================================= # SPECIFIC RESTORATION @@ -46,9 +46,9 @@ ynh_install_app_dependencies $pkg_dependencies # If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) # Find an available port - port=$(ynh_find_port --port=$squid_port) - ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port - ynh_app_setting_set --app=$app --key=port --value=$port + squid_port=$(ynh_find_port --port=$squid_port) + ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port + ynh_app_setting_set --app=$app --key=squid_port --value=$squid_port #================================================= # MODIFY A CONFIG FILE @@ -70,7 +70,7 @@ else fi # Save squid folder -ynh_app_setting_set $app squid_folder $squid +ynh_app_setting_set --app=$app --key=squid_folder --value=$squid #================================================= # RESTORE INOTIFY'S CONFIG @@ -83,7 +83,7 @@ yunohost app ssowatconf # ADVERTISE SERVICE IN ADMIN PANEL #================================================= -yunohost service add squid3 --log "/var/log/$squid/access.log" +yunohost service add squid3 --log "/var/log/$squid/cache.log" #================================================= @@ -99,7 +99,7 @@ Enter these value in the below feilds. --------------------------------------------------------------------- | Http proxy: Your any registered domain name or ip eg domain.tld | -|port: $port +|port: $squid_port | |Tick mark use this proxy server for all protocols | diff --git a/scripts/upgrade b/scripts/upgrade index 30fe538..6d3d249 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= app=$YNH_APP_INSTANCE_NAME -port=$(ynh_app_setting_get $app port) +squid_port=$(ynh_app_setting_get $app squid_port) new_port=$(ynh_app_setting_get $app new_port) #================================================= @@ -37,7 +37,7 @@ ynh_abort_if_errors #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." - +ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies @@ -46,27 +46,21 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # If #new_port is not defined test the $port and keep it open if [ -z $new_port ] then - # Optional: Expose this port publicly - # (N.B. : you only need to do this if the app actually needs to expose the port publicly. - # If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) - - # Find an available port - port=$(ynh_find_port --port=$squid_port) - ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port - ynh_app_setting_set --app=$app --key=port --value=$port + ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port + ynh_app_setting_set --app=$app --key=port --value=$squid_port # If $new_port is define close the $port and open the $new_port else #Close $port - if yunohost firewall list | grep -q "\- $port$" + if yunohost firewall list | grep -q "\- $squid_port$" then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port + ynh_script_progression --message="Closing port $squid_port..." + ynh_exec_warn_less yunohost firewall disallow TCP $squid_port fi # Open $new_port port=$(ynh_find_port --port=$squid_new_port) #Add the value of $new_port to $port - ynh_app_setting_set --app=$app --key=port --value=$port + ynh_app_setting_set --app=$app --key=squid_port --value=$squid_port #Remove the value of $new_port ynh_app_setting_set --app=$app --key=new_port --value="" fi @@ -96,7 +90,7 @@ fi ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ynh_backup_if_checksum_is_different --file="/etc/$squid/squid.conf" -ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/squid.conf" +ynh_replace_string --match_string="__PORT__" --replace_string="$squid_port" --target_file="../conf/squid.conf" ynh_replace_string --match_string="__SQUID__" --replace_string="$squid" --target_file="../conf/squid.conf" cp -f "../conf/squid.conf" "/etc/$squid/." # Save squid folder @@ -119,7 +113,7 @@ ynh_store_file_checksum --file="/etc/$squid/squid.conf" ### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script ### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script -yunohost service add squid3 --log "/var/log/$squid/access.log" +yunohost service add squid3 --log "/var/log/$squid/cache.log" #================================================= # RESTART SQUID'S SERVICE and SSOWATCONF @@ -141,7 +135,7 @@ Enter these value in the below feilds. --------------------------------------------------------------------- | Http proxy: Your any registered domain name or ip eg domain.tld | -|port: $port +|port: $squid_port | |Tick mark use this proxy server for all protocols |