Compare commits
No commits in common. "7cc4b410dcb007a57ad5e0512feed2966ffc0e59" and "074fad28bdb2cc9e2646b23b5a7394fdb8c81a5a" have entirely different histories.
7cc4b410dc
...
074fad28bd
4 changed files with 2 additions and 67 deletions
|
@ -19,7 +19,6 @@ services:
|
|||
volumes:
|
||||
- ./uploads:/uploads
|
||||
- ./templates:/templates
|
||||
- ./static:/static
|
||||
|
||||
restart: always
|
||||
|
||||
|
|
27
go/main.go
27
go/main.go
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
|
@ -27,9 +25,6 @@ func main() {
|
|||
http.HandleFunc("/upload", uploadHandler)
|
||||
http.HandleFunc("/image/", imageHandler)
|
||||
http.HandleFunc("/view/", viewHandler)
|
||||
// Statischen Dateipfad setzen
|
||||
fs := http.FileServer(http.Dir("static"))
|
||||
http.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||
|
||||
fmt.Println("Server listening on :8080")
|
||||
http.ListenAndServe(":8080", nil)
|
||||
|
@ -58,27 +53,9 @@ func homeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func generateNonce() (string, error) {
|
||||
nonceBytes := make([]byte, 16) // 16 Bytes generieren eine ausreichend lange Zeichenfolge für den Nonce
|
||||
if _, err := rand.Read(nonceBytes); err != nil {
|
||||
return "", err // Im Fehlerfall, geben Sie den Fehler zurück
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(nonceBytes), nil
|
||||
}
|
||||
|
||||
func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||
nonce, err := generateNonce()
|
||||
if err != nil {
|
||||
// Fehlerbehandlung, z.B. Senden eines Serverfehlers
|
||||
http.Error(w, "Serverfehler", http.StatusInternalServerError)
|
||||
log.Printf("Fehler beim Generieren des Nonce: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Setzen der Content Security Policy
|
||||
//w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; object-src 'none';")
|
||||
//w.Header().Set("Content-Security-Policy", fmt.Sprintf("default-src 'self'; script-src 'self' 'nonce-%s'; object-src 'none';", nonce))
|
||||
w.Header().Set("Content-Security-Policy", fmt.Sprintf("script-src 'self' 'nonce-%s';", nonce))
|
||||
w.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; object-src 'none';")
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
@ -162,11 +139,9 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
data := struct {
|
||||
Message string
|
||||
Filename string
|
||||
Nonce string
|
||||
}{
|
||||
Message: "Bild erfolgreich hochgeladen.",
|
||||
Filename: filename, // Geändert, um den möglicherweise modifizierten Dateinamen anzuzeigen
|
||||
Nonce: nonce,
|
||||
}
|
||||
|
||||
err = tmpl.Execute(w, data)
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
document.getElementById('copyButton').addEventListener('click', kopiereURL);
|
||||
});
|
||||
|
||||
function kopiereURL() {
|
||||
var copyText = document.getElementById("imageURL");
|
||||
copyText.select();
|
||||
copyText.setSelectionRange(0, 99999); // Für mobile Geräte
|
||||
|
||||
navigator.clipboard.writeText(copyText.value).then(function() {
|
||||
console.log('Kopieren in die Zwischenablage erfolgreich.');
|
||||
}, function(err) {
|
||||
console.error('Fehler beim Kopieren in die Zwischenablage: ', err);
|
||||
});
|
||||
}
|
|
@ -5,31 +5,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<p>{{.Message}}</p>
|
||||
<!-- Anzeigen des Links zum Bild, um es zu betrachten -->
|
||||
<p><a href="/view/{{.Filename}}" target="_blank">Ihr Bild anzeigen</a></p>
|
||||
<!-- Eingabefeld mit der URL des Bildes -->
|
||||
<input type="text" value="https://pick.brothertec.eu/view/{{.Filename}}" id="imageURL" readonly>
|
||||
<!-- Button, um die URL zu kopieren -->
|
||||
<button id="copyButton">URL kopieren</button>
|
||||
<a href="/view/{{.Filename}}">Ihr Bild anzeigen</a>
|
||||
<p><a href="/upload">Zurück zum Upload</a></p>
|
||||
|
||||
<script src="/static/js/script.js" nonce="{{.Nonce}}"></script>
|
||||
|
||||
<!-- <script type="text/javascript" nonce="{{.Nonce}}">
|
||||
function kopiereURL() {
|
||||
// Finde das Textfeld mit der URL
|
||||
var copyText = document.getElementById("imageURL");
|
||||
// Wähle den Text innerhalb des Textfeldes
|
||||
copyText.select();
|
||||
copyText.setSelectionRange(0, 99999); // Für mobile Geräte
|
||||
|
||||
// Versuche, den Text ins Clipboard zu kopieren
|
||||
navigator.clipboard.writeText(copyText.value).then(function() {
|
||||
console.log('Kopieren in die Zwischenablage erfolgreich.');
|
||||
}, function(err) {
|
||||
console.error('Fehler beim Kopieren in die Zwischenablage: ', err);
|
||||
});
|
||||
}
|
||||
</script> -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue