From fd6022ad467ce03cf8159da4caf382eae0418f0d Mon Sep 17 00:00:00 2001 From: Dillenn Terumalai Date: Wed, 16 Feb 2022 14:15:00 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20a=20bug=20with=20the?= =?UTF-8?q?=20sftp=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spsp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/spsp b/spsp index b66d03f..4dbfe60 100755 --- a/spsp +++ b/spsp @@ -437,9 +437,16 @@ autoMode() { for FILE in *.*; do if [ -f "$FILE" ]; then - echo put "$FILE" | sftp -q -b- "${SFTP_URL}/$VIRUSES" 1>/dev/null 2>>"../../$ERRORLOGFILE" - ((SUCCESS = SUCCESS + 1)) - echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE" + echo put "$FILE" | sftp -b- "${SFTP_URL}/$VIRUSES" 2>>"../../$ERRORLOGFILE" 1>&2 + if [[ $? -eq 0 ]]; then + ((SUCCESS = SUCCESS + 1)) + echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE" + else + ((ERRORS = ERRORS + 1)) + ((STEP_ERRORS = STEP_ERRORS + 1)) + echo "[$(date +"%T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$LOGFILE" + echo "[$(date +"%F %T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$ERRORLOGFILE" + fi if [[ "$*" == *--no-archive* ]] || [[ "$*" == *-NA* ]]; then rm -rf "$FILE" echo "[$(date +"%T")] local.SUCCESS: --NA activated, $FILE successfully removed" >>"../../$LOGFILE" @@ -454,9 +461,16 @@ autoMode() { for FILE in *.*; do if [ -f "$FILE" ]; then - echo put "$FILE" | sftp -q -b- -o LogLevel=QUIET "${SFTP_URL}/$BACTERIA" 1>/dev/null 2>>"../../$ERRORLOGFILE" - ((SUCCESS = SUCCESS + 1)) - echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE" + echo put "$FILE" | sftp -b- "${SFTP_URL}/$BACTERIA" 2>>"../../$ERRORLOGFILE" 1>&2 + if [[ $? -eq 0 ]]; then + ((SUCCESS = SUCCESS + 1)) + echo "[$(date +"%T")] local.SUCCESS: $FILE has been successfully transferred to the remote server" >>"../../$LOGFILE" + else + ((ERRORS = ERRORS + 1)) + ((STEP_ERRORS = STEP_ERRORS + 1)) + echo "[$(date +"%T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$LOGFILE" + echo "[$(date +"%F %T")] local.ERROR: sftp transfer of $FILE to ${SFTP_URL}/$VIRUSES failed" >>"../../$ERRORLOGFILE" + fi if [[ "$*" == *--no-archive* ]] || [[ "$*" == *-NA* ]]; then rm -rf "$FILE" echo "[$(date +"%T")] local.SUCCESS: --NA activated, $FILE successfully removed" >>"../../$LOGFILE" -- GitLab From 772291af82cc43404cd49e5f218aaa18a58d5b41 Mon Sep 17 00:00:00 2001 From: Dillenn Terumalai Date: Fri, 19 Aug 2022 10:25:43 +0200 Subject: [PATCH 2/4] fix: Validate .env config file permissions (600) --- spsp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spsp b/spsp index aed4ce2..c8c82c9 100755 --- a/spsp +++ b/spsp @@ -141,6 +141,22 @@ initMode() { fi fi + if [ "$MACHINE" == "linux" ]; then + if [ "$(stat -c "%a" .env)" != "600" ]; then + printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" + printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" + printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}http://netcat.sourceforge.net/${COL_RESET}" + exit 22 + fi + elif [ "$MACHINE" == "mac" ]; then + if [ "$(stat -f "%Lp" .env)" != "600" ]; then + printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" + printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" + printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}http://netcat.sourceforge.net/${COL_RESET}" + exit 22 + fi + fi + chmod +x spsp gpg -q --import --fingerprint .pub @@ -852,6 +868,7 @@ if [ $# -gt 0 ]; then echo "ID=$identifier" >.env echo 'HOST=spsp.sib.swiss' >>.env echo 'SFTP_URL=${ID}@${HOST}:data' >>.env + chmod 600 .env answer=true else echo "" -- GitLab From 8556a26bca2ee3971635d15e394ccf9e7c59bbeb Mon Sep 17 00:00:00 2001 From: Dillenn Terumalai Date: Fri, 19 Aug 2022 10:27:01 +0200 Subject: [PATCH 3/4] fix: Fixed link in error output --- spsp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spsp b/spsp index c8c82c9..3d666b9 100755 --- a/spsp +++ b/spsp @@ -145,14 +145,14 @@ initMode() { if [ "$(stat -c "%a" .env)" != "600" ]; then printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" - printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}http://netcat.sourceforge.net/${COL_RESET}" + printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#configure-the-env-file${COL_RESET}" exit 22 fi elif [ "$MACHINE" == "mac" ]; then if [ "$(stat -f "%Lp" .env)" != "600" ]; then printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" - printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}http://netcat.sourceforge.net/${COL_RESET}" + printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#configure-the-env-file${COL_RESET}" exit 22 fi fi -- GitLab From fd0bbba11042958a29e21856f055e9c421c76ccd Mon Sep 17 00:00:00 2001 From: Dillenn Terumalai Date: Fri, 19 Aug 2022 10:37:07 +0200 Subject: [PATCH 4/4] fix: Moved config file permissions to be executed only in specific conditions --- spsp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/spsp b/spsp index 3d666b9..5ed9a71 100755 --- a/spsp +++ b/spsp @@ -2,7 +2,7 @@ # SPSP transfer-tool is developed and maintained by SIB. For more information, please contact spsp-support@sib.swiss -VERSION="1.11.0" # bumped to support spsp --help, spsp --version +VERSION="1.12.0" # bumped to support spsp --help, spsp --version # Define colors that are used in the help screen @@ -120,14 +120,14 @@ initMode() { if [ ! -x "$(command -v sftp)" ]; then printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" printf "${BACK_RED} error ${COL_RESET} command unavailable: the sftp command is not available on this system and is mandatory for the pipeline.\n" - printf "${BACK_CYAN} INFO ${COL_RESET} Check out OpenSSH at ${COL_CYAN}https://www.openssh.com/${COL_RESET}" + printf "${BACK_CYAN} INFO ${COL_RESET} Check out OpenSSH at ${COL_CYAN} https://www.openssh.com/ ${COL_RESET}" exit 22 fi if [ ! -x "$(command -v nc)" ]; then printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" printf "${BACK_RED} error ${COL_RESET} command unavailable: the nc command is not available on this system and is mandatory for the pipeline.\n" - printf "${BACK_CYAN} INFO ${COL_RESET} Check out Netcat at ${COL_CYAN}http://netcat.sourceforge.net/${COL_RESET}" + printf "${BACK_CYAN} INFO ${COL_RESET} Check out Netcat at ${COL_CYAN} http://netcat.sourceforge.net/ ${COL_RESET}" exit 22 fi @@ -141,22 +141,6 @@ initMode() { fi fi - if [ "$MACHINE" == "linux" ]; then - if [ "$(stat -c "%a" .env)" != "600" ]; then - printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" - printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" - printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#configure-the-env-file${COL_RESET}" - exit 22 - fi - elif [ "$MACHINE" == "mac" ]; then - if [ "$(stat -f "%Lp" .env)" != "600" ]; then - printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" - printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" - printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN}https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#configure-the-env-file${COL_RESET}" - exit 22 - fi - fi - chmod +x spsp gpg -q --import --fingerprint .pub @@ -857,6 +841,21 @@ if [ $# -gt 0 ]; then echo " - Ignoring .env file..." else if [ -f .env ]; then + if [ "$MACHINE" == "linux" ]; then + if [ "$(stat -c "%a" .env)" != "600" ]; then + printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" + printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" + printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN} https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#configure-the-env-file ${COL_RESET}" + exit 22 + fi + elif [ "$MACHINE" == "mac" ]; then + if [ "$(stat -f "%Lp" .env)" != "600" ]; then + printf "${BACK_RED} ERROR ${COL_RESET} ${COL_RED}Stopped with 1 error${COL_RESET} ${COL_GREY} ${TIME} ${COL_RESET}\n" + printf "${BACK_RED} error ${COL_RESET} permissions incorrect: the configuration file should be configured with 600 permissions (chmod 600 .env).\n" + printf "${BACK_CYAN} INFO ${COL_RESET} More info at ${COL_CYAN} https://gitlab.sib.swiss/SPSP/transfer-tool/-/wikis/Installation#configure-the-env-file ${COL_RESET}" + exit 22 + fi + fi source .env else echo " - Creating a new .env file..." -- GitLab