diff --git a/eprintcloned b/eprintcloned
index b180e95..63b9fbd 100755
--- a/eprintcloned
+++ b/eprintcloned
@@ -1,8 +1,29 @@
#!/bin/bash
+# Check for specified arguments
+if [ $# -lt 3 ]
+then
+ echo "Not enough arguments - exiting"
+ echo ""
+ exit 1
+fi
printer=examplename # replace this with your actual printer name before putting it into /usr/bin
imagelogmsg="Server hoster decided to enable file logging, if you don't wish your file to be logged, ask the server owner to delete your sent file or if you are the server hoster set LOG=nolog in .env file" # add a custom logging of files message
+# check if quality is specified, it it isn't then set the default quality
+if [ $# -gt 4 ]; then
+ quality=$3
+else
+ quality=4
+fi
+
+# check if page range is specified, it it isn't then ignore setting a page range
+if [ $# -gt 4 ]; then
+ pagerange=$4
+else
+ pagerange=""
+fi
+
# Loop through each file passed as an argument
for file in "$1"; do
# Get the MIME type of the file
@@ -12,22 +33,22 @@ for file in "$1"; do
if [[ "$mime_type" == image/* || "$mime_type" == application/pdf ]]; then
if [[ $2 == log ]]; then
echo $imagelogmsg
- cp $1 $HOME/imagelog
+ cp "$1" $HOME/imagelog/
echo "Printing image/document"
- lpr -o portrait -o media=A4 -o fit-to-page $1 -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
+ lpr -r -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
else
echo "Printing image/document"
- lpr -o portrait -o media=A4 -o fit-to-page $1 -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
+ lpr -r -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
fi
elif [[ "$mime_type" == text/* ]]; then
if [[ $2 == log ]]; then
echo $imagelogmsg
- cp $1 $HOME/imagelog
+ cp "$1" $HOME/imagelog/
echo "Printing text"
- lpr -o portrait -o media=A4 -o fit-to-page $1 -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
+ lpr -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
else
echo "Printing text"
- lpr -o portrait -o media=A4 -o fit-to-page $1 -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
+ lpr -r -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
fi
else
echo "Error: Invalid file type or, ePrint clone only accepts the following MIME types: text/*, image/*, application/pdf"
diff --git a/main.go b/main.go
index 609deb5..d73153b 100644
--- a/main.go
+++ b/main.go
@@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "regexp"
"github.com/joho/godotenv"
)
@@ -72,12 +73,32 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
return
}
defer file.Close()
-
- targetmail := r.FormValue("targetmail")
- if targetmail == "" {
- fmt.Printf("Warning: User did not specify a mail on sent request")
+
+ // Regular expression to check if input contains only numbers and hyphens so that user canot execute arbitary code
+ printconfig := r.FormValue("printconfig")
+ if printconfig == "" {
+ fmt.Printf("Warning: User did not specify page range on sent request\n")
+ } else {
+ re := regexp.MustCompile(`^[0-9]+(-[0-9]+)*$`)
+ if !re.MatchString(printconfig) {
+ json.NewEncoder(w).Encode(map[string]string{"error": "Invalid page range"})
+ fmt.Printf("debug: printconfig is: %s\n", printconfig)
+ return
}
-
+}
+ // Regular expression to check if input contains only numbers so that user canot execute arbitary code
+ printres := r.FormValue("res")
+ if printres == "" {
+ fmt.Printf("Warning: User did not specify quality on sent request, assuming normal quality\n")
+ printres = "4"
+ } else {
+ re := regexp.MustCompile(`^[1-5]+$`)
+ if !re.MatchString(printres) {
+ json.NewEncoder(w).Encode(map[string]string{"error": "Invalid quality range"})
+ fmt.Printf("debug: res is: %s\n", printres)
+ return
+ }
+}
tempFileName := filepath.Join(os.TempDir(), handler.Filename)
tempFile, err := os.Create(tempFileName)
if err != nil {
@@ -96,7 +117,7 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
printingcmdPath := filepath.Join("/", "usr", "bin", "eprintcloned")
filelog := os.Getenv("LOG")
- cmd := exec.Command(printingcmdPath, tempFile.Name(), filelog, targetmail)
+ cmd := exec.Command(printingcmdPath, tempFile.Name(), filelog, printres, printconfig)
output, err := cmd.CombinedOutput()
if err != nil {
diff --git a/web/assets/index.js b/web/assets/index.js
index 419e1eb..d62be4d 100644
--- a/web/assets/index.js
+++ b/web/assets/index.js
@@ -4,7 +4,7 @@ const commandOutput = document.getElementById('commandOutput');
uploadForm.addEventListener('submit', async (e) => {
e.preventDefault();
- uploadStatus.textContent = 'Uploading and printing...';
+ uploadStatus.textContent = 'Uploading...';
commandOutput.textContent = '';
const formData = new FormData(uploadForm);
diff --git a/web/index.html b/web/index.html
index 736cf9a..4ea870e 100644
--- a/web/index.html
+++ b/web/index.html
@@ -21,12 +21,21 @@
-
+