From 2ac56d8870890c72d4ca9b8226bd6f583fd46b65 Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Tue, 1 Aug 2023 16:19:28 -0700 Subject: [PATCH 1/4] feat: add ability to send to ftps server This commit adds a new shell script called `sendtoftps.sh` that uses curl to send a file to an ftps server. I've also added it to all of the scanto* shell scripts. If you don't pass in the FTP env vars it will simply skip the step where it uploads via curl. --- script/scanRear.sh | 9 ++++++++- script/scantofile-0.2.4-1.sh | 8 +++++++- script/scantoimage-0.2.4-1.sh | 7 +++++++ script/scantoocr-0.2.4-1.sh | 7 +++++++ script/sendtoftps.sh | 27 +++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) mode change 100644 => 100755 script/scanRear.sh create mode 100755 script/sendtoftps.sh diff --git a/script/scanRear.sh b/script/scanRear.sh old mode 100644 new mode 100755 index a524d36..bb5c61f --- a/script/scanRear.sh +++ b/script/scanRear.sh @@ -71,6 +71,13 @@ fi ( curl -F "userfile=@/scans/$date.pdf" -H "Expect:" -o /scans/$date-ocr.pdf localhost:32800/ocr.php /opt/brother/scanner/brscan-skey/script/trigger_inotify.sh $SSH_USER $SSH_PASSWORD $SSH_HOST $SSH_PATH $date-ocr.pdf + + /opt/brother/scanner/brscan-skey/script/sendtoftps.sh \ + "${FTP_USER}" \ + "${FTP_PASSWORD}" \ + "${FTP_HOST}" \ + "${FTP_PATH}" \ + "${date}.pdf" ) & ) & -) & \ No newline at end of file +) & diff --git a/script/scantofile-0.2.4-1.sh b/script/scantofile-0.2.4-1.sh index ffa0bc5..fdd74a5 100755 --- a/script/scantofile-0.2.4-1.sh +++ b/script/scantofile-0.2.4-1.sh @@ -53,8 +53,14 @@ fi ( curl -F "userfile=@/scans/$date.pdf" -H "Expect:" -o /scans/$date-ocr.pdf localhost:32800/ocr.php /opt/brother/scanner/brscan-skey/script/trigger_inotify.sh $SSH_USER $SSH_PASSWORD $SSH_HOST $SSH_PATH $date-ocr.pdf + /opt/brother/scanner/brscan-skey/script/sendtoftps.sh \ + "${FTP_USER}" \ + "${FTP_PASSWORD}" \ + "${FTP_HOST}" \ + "${FTP_PATH}" \ + "${date}.pdf" ) & ) & ) & echo $! > scan_pid -echo "conversion process for $date is running in PID: "$(cat scan_pid) \ No newline at end of file +echo "conversion process for $date is running in PID: "$(cat scan_pid) diff --git a/script/scantoimage-0.2.4-1.sh b/script/scantoimage-0.2.4-1.sh index 90443ba..97a7939 100755 --- a/script/scantoimage-0.2.4-1.sh +++ b/script/scantoimage-0.2.4-1.sh @@ -32,3 +32,10 @@ gm convert /scans/$date-page*.pnm /scans/$date.pdf rm /scans/$date-page*.pnm /opt/brother/scanner/brscan-skey/script/trigger_inotify.sh $SSH_USER $SSH_PASSWORD $SSH_HOST $SSH_PATH $date.pdf + +/opt/brother/scanner/brscan-skey/script/sendtoftps.sh \ + "${FTP_USER}" \ + "${FTP_PASSWORD}" \ + "${FTP_HOST}" \ + "${FTP_PATH}" \ + "${date}.pdf" diff --git a/script/scantoocr-0.2.4-1.sh b/script/scantoocr-0.2.4-1.sh index a0a7725..b21486a 100755 --- a/script/scantoocr-0.2.4-1.sh +++ b/script/scantoocr-0.2.4-1.sh @@ -32,3 +32,10 @@ gm convert /scans/$date-page*.pnm /scans/$date.pdf rm /scans/$date-page*.pnm /opt/brother/scanner/brscan-skey/script/trigger_inotify.sh "${SSH_USER}" "${SSH_PASSWORD}" "${SSH_HOST}" "${SSH_PATH}" "${date}.pdf" + +/opt/brother/scanner/brscan-skey/script/sendtoftps.sh \ + "${FTP_USER}" \ + "${FTP_PASSWORD}" \ + "${FTP_HOST}" \ + "${FTP_PATH}" \ + "${date}.pdf" diff --git a/script/sendtoftps.sh b/script/sendtoftps.sh new file mode 100755 index 0000000..63bd2a0 --- /dev/null +++ b/script/sendtoftps.sh @@ -0,0 +1,27 @@ +user=$1 +password=$2 +address=$3 +filepath=$4 +file=$5 + +if [ -z "${user}" ] || [ -z "${password}" ] || [ -z "${address}" ] || [ -z "${filepath}" ] || [ -z "${file}" ]; then + echo "FTP environment variables not set, skipping inotify trigger." +else + if curl --silent \ + --show-error \ + --insecure \ + --ssl-reqd \ + --user "${user}:${password}" \ + --upload-file "${file}" \ + "ftp://${address}${filepath}" ; then + echo "Uploading to ftp server ${address} successful." + else + echo "Uploading to ftp failed while using curl" + echo "user: ${user}" + echo "address: ${address}" + echo "filepath: ${filepath}" + echo "file: ${file}" + exit 1 + fi +fi + From d48736f3cf441e44cbe0c9d9d0351669c3b058e0 Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Tue, 1 Aug 2023 16:21:00 -0700 Subject: [PATCH 2/4] fix: remove insecure from curl for security --- script/sendtoftps.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/script/sendtoftps.sh b/script/sendtoftps.sh index 63bd2a0..7e3472a 100755 --- a/script/sendtoftps.sh +++ b/script/sendtoftps.sh @@ -9,7 +9,6 @@ if [ -z "${user}" ] || [ -z "${password}" ] || [ -z "${address}" ] || [ -z "${fi else if curl --silent \ --show-error \ - --insecure \ --ssl-reqd \ --user "${user}:${password}" \ --upload-file "${file}" \ From bfa8264b3c3c3c5c4cff58151da665a908466a49 Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Tue, 1 Aug 2023 16:35:48 -0700 Subject: [PATCH 3/4] fix: forgot to cd first --- script/sendtoftps.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/sendtoftps.sh b/script/sendtoftps.sh index 7e3472a..f2106ec 100755 --- a/script/sendtoftps.sh +++ b/script/sendtoftps.sh @@ -4,6 +4,8 @@ address=$3 filepath=$4 file=$5 +cd /scans + if [ -z "${user}" ] || [ -z "${password}" ] || [ -z "${address}" ] || [ -z "${filepath}" ] || [ -z "${file}" ]; then echo "FTP environment variables not set, skipping inotify trigger." else From f761e97c635ac96fa7cddbd0f33982d439452a07 Mon Sep 17 00:00:00 2001 From: Chris Wiggins Date: Tue, 1 Aug 2023 16:44:26 -0700 Subject: [PATCH 4/4] fix: env vars need to be empty or the script will try to upload to ftp --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f4f2210..a643fa0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,10 +27,11 @@ ENV SSH_HOST="" ENV SSH_PATH="" #only set these variables, if you need FTP upload: -ENV FTP_USER="scanner" -ENV FTP_PASSWORD="scanner" -ENV FTP_HOST="ftp.mydomain.com" -ENV FTP_PATH="/" +ENV FTP_USER="" +ENV FTP_PASSWORD="" +ENV FTP_HOST="" +# Make sure this ends in a slash. +ENV FTP_PATH="/scans/" EXPOSE 54925 EXPOSE 54921