Compare commits

..

No commits in common. "8b3f1933a5bfd6a9ac7d6b24cb6492565907469f" and "fdfe35c5c30e0c79c60791ea0db594835a628b6e" have entirely different histories.

5 changed files with 112 additions and 88 deletions

View File

@ -1,6 +1,6 @@
# HP ePrint like service clone (web edition)
# S3 Client Web
This is a HP ePrint clone that has similar functions to normal HP ePrint but its on the web and it is not HP printer specific
This is a WebGUI for [s3-client](https://git.fluffy.pw/leafus/s3-client)
## Prerequisites
@ -10,17 +10,17 @@ This is a HP ePrint clone that has similar functions to normal HP ePrint but its
1. Clone the repository:
```
git clone https://git.fluffy.pw/matu6968/web-hp-eprint-clone
git clone https://git.fluffy.pw/leafus/s3-client-web
```
2. Go to the project directory:
```
cd web-hp-eprint-clone
cd s3-client-web
```
3. Build the binary:
```
go build -o web-hp-eprint
go build -o s3-client-web
```
## Configuration
@ -29,25 +29,10 @@ In the .env file this is the only thing you can set
```
PORT=8080
LOG=log # enables file logging (aka copies file to user home directory under the folder imagelog so make a folder first in the home root if you wish to enable it), to disable it replace it with nolog
```
### For this to even work
Setup a printer on your host by connecting it over USB or WiFi and then adding the printer in your OS
and put the eprintcloned script (ePrint clone daemon aka it handles the printing) in the "/usr/bin" folder !IMPORTANT! you need to modify the script to include your printer name (it is at the top and is called printer and not the one used in the included configuration in the repository
for example change it from
```
#!/bin/bash
printer=examplename # replace this with your actual printer name before putting it into /usr/bin
```
to
```
#!/bin/bash
printer=Deskjet-2600 # replace this with your actual printer name before putting it into /usr/bin
```
You need to download a latest linux binary release of [s3-client](https://git.fluffy.pw/leafus/s3-client) from the "Releases" tab for your architecture
and put the binary in the "bin" folder !IMPORTANT! you need to rename the file to just s3-client and create s3config.toml file, the configuration of that is in the [s3-client](https://git.fluffy.pw/leafus/s3-client) repository

View File

@ -1,38 +0,0 @@
#!/bin/bash
printer=Deskjet-2600 # replace this with your actual printer name
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 FILELOG=nolog in .env file" # add a custom logging of files message
# Loop through each file passed as an argument
for file in "$1"; do
# Get the MIME type of the file
mime_type=$(file --mime-type -b "$file")
# Check if the MIME type is for images, text, or PDF files
if [[ "$mime_type" == image/* || "$mime_type" == application/pdf ]]; then
if [[ $2 == log ]]; then
echo $imagelogmsg
cp $1 $HOME/imagelog
echo "Printing image/document"
lpr -o portrait -o media=A4 $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 $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
echo "Printing text"
lpr -o portrait -o media=A4 $1 -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
ntfymailsend $3
else
echo "Printing text"
lpr -o portrait -o media=A4 $1 -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
ntfymailsend $3
fi
else
echo "Error: Invalid file type or, ePrint clone only accepts the following MIME types: text/*, image/*, application/pdf"
exit 1
fi
done

63
main.go
View File

@ -20,11 +20,6 @@ func main() {
log.Fatal("Error loading .env file")
}
filelog := os.Getenv("LOG")
if filelog == "" {
filelog = "nolog"
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
@ -73,9 +68,9 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
}
defer file.Close()
targetmail := r.FormValue("targetmail")
if targetmail == "" {
fmt.Printf("Warning: User did not specify a mail on sent request")
directory := r.FormValue("directory")
if directory == "" {
directory = "/"
}
tempFileName := filepath.Join(os.TempDir(), handler.Filename)
@ -93,16 +88,17 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
return
}
s3ClientPath := filepath.Join(".", "bin", "s3-client")
configFilePath := filepath.Join(".", "bin", "s3config.toml")
cmd := exec.Command(s3ClientPath, "-config", configFilePath, "-directory", directory, "-file", tempFile.Name())
printingcmdPath := filepath.Join("/", "usr", "bin", "eprintcloned")
filelog := os.Getenv("LOG")
cmd := exec.Command(printingcmdPath, tempFile.Name(), filelog, targetmail)
cmd.Args = append(cmd.Args, "-overwrite")
output, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error printing file: %s\n", output)
log.Printf("Error uploading file: %s\n", output)
json.NewEncoder(w).Encode(map[string]string{
"error": fmt.Sprintf("Error printing file to printer: %s", output),
"error": fmt.Sprintf("Error uploading file to S3: %s", output),
})
return
}
@ -111,7 +107,7 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
Message string `json:"message"`
Output string `json:"output"`
}{
Message: fmt.Sprintf("File %s printed successfully", handler.Filename),
Message: fmt.Sprintf("File %s uploaded successfully", handler.Filename),
Output: string(output),
}
@ -120,6 +116,43 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
func handleDelete(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"message": "To delete logs of your sent images from the instance you have sent them to, contact the owner of the instance to do it. "})
if r.Method != http.MethodPost {
json.NewEncoder(w).Encode(map[string]string{"error": "Method not allowed"})
return
}
err := r.ParseMultipartForm(10 << 20)
if err != nil {
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
return
}
filename := r.FormValue("filename")
if filename == "" {
json.NewEncoder(w).Encode(map[string]string{"error": "Filename is required"})
return
}
s3ClientPath := filepath.Join(".", "bin", "s3-client")
configFilePath := filepath.Join(".", "bin", "s3config.toml")
cmd := exec.Command(s3ClientPath, "-config", configFilePath, "-delete", filename)
output, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error deleting file: %s\n", output)
json.NewEncoder(w).Encode(map[string]string{
"error": fmt.Sprintf("Error deleting file from S3: %s", output),
})
return
}
response := struct {
Message string `json:"message"`
Output string `json:"output"`
}{
Message: fmt.Sprintf("File %s deleted successfully from S3", filename),
Output: string(output),
}
json.NewEncoder(w).Encode(response)
}

View File

@ -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);
@ -27,3 +27,33 @@ uploadForm.addEventListener('submit', async (e) => {
uploadStatus.textContent = `Error: ${error.message}`;
}
});
const deleteForm = document.getElementById('deleteForm');
const deleteStatus = document.getElementById('deleteStatus');
const deleteOutput = document.getElementById('deleteOutput');
deleteForm.addEventListener('submit', async (e) => {
e.preventDefault();
deleteStatus.textContent = 'Deleting...';
deleteOutput.textContent = '';
const formData = new FormData(deleteForm);
try {
const response = await fetch('/delete', {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.error) {
throw new Error(result.error);
} else {
deleteStatus.textContent = result.message;
deleteOutput.textContent = result.output;
}
} catch (error) {
deleteStatus.textContent = `Error: ${error.message}`;
}
});

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/assets/global.css" />
<title>HP ePrint clone Web Wrapper</title>
<title>S3-Client Web Wrapper</title>
<style>
#uploadStatus,
#commandOutput {
@ -13,16 +13,16 @@
</style>
</head>
<body>
<div class="header">HP ePrint like printing WebGUI</div>
<div class="header">S3-Client WebGUI</div>
<fieldset>
<legend>File Selection</legend>
<form id="uploadForm">
<input type="file" accept=".jpg, .jpeg, .png, .gif, .txt, .pdf" name="file" required />
<input type="file" name="file" required />
<input
type="text"
name="targetmail"
placeholder="Confirmation e-mail after printing finishes [Optional]"
name="directory"
placeholder="Directory to upload to [Optional]"
style="width: 210px;"
/>
<br />
@ -30,6 +30,20 @@
</form>
</fieldset>
<fieldset style="margin-top: 10px">
<legend>Delete</legend>
<form style="display: flex;" id="deleteForm">
<input
type="text"
name="filename"
placeholder="Filename to delete"
required
style="width: 100%;"
/>
<button style="margin-left: 10px;" type="submit">Delete</button>
</form>
</fieldset>
<fieldset style="margin-top: 10px">
<legend>Terminal</legend>
<div id="uploadStatus"></div>
@ -41,8 +55,8 @@
</fieldset>
<div style="margin-top: 10px;" class="footer">
<a href="https://git.fluffy.pw/matu6968/web-hp-eprint-clone">[ web-hp-eprint-clone ]</a> -
<a href="https://git.fluffy.pw/leafus/s3-client-web">[ forked of s3-client-web ]</a> - Licensed under MIT
<a href="https://git.fluffy.pw/leafus/s3-client">[ s3-client ]</a> -
<a href="https://git.fluffy.pw/leafus/s3-client-web">[ s3-client-web ]</a> - Licensed under MIT
</div>
<script src="/assets/index.js"></script>