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:
|
volumes:
|
||||||
- ./uploads:/uploads
|
- ./uploads:/uploads
|
||||||
- ./templates:/templates
|
- ./templates:/templates
|
||||||
- ./static:/static
|
|
||||||
|
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
|
27
go/main.go
27
go/main.go
|
@ -1,8 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
@ -27,9 +25,6 @@ func main() {
|
||||||
http.HandleFunc("/upload", uploadHandler)
|
http.HandleFunc("/upload", uploadHandler)
|
||||||
http.HandleFunc("/image/", imageHandler)
|
http.HandleFunc("/image/", imageHandler)
|
||||||
http.HandleFunc("/view/", viewHandler)
|
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")
|
fmt.Println("Server listening on :8080")
|
||||||
http.ListenAndServe(":8080", nil)
|
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) {
|
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
|
// 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", "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))
|
|
||||||
|
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
defer mu.Unlock()
|
defer mu.Unlock()
|
||||||
|
@ -162,11 +139,9 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := struct {
|
data := struct {
|
||||||
Message string
|
Message string
|
||||||
Filename string
|
Filename string
|
||||||
Nonce string
|
|
||||||
}{
|
}{
|
||||||
Message: "Bild erfolgreich hochgeladen.",
|
Message: "Bild erfolgreich hochgeladen.",
|
||||||
Filename: filename, // Geändert, um den möglicherweise modifizierten Dateinamen anzuzeigen
|
Filename: filename, // Geändert, um den möglicherweise modifizierten Dateinamen anzuzeigen
|
||||||
Nonce: nonce,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>{{.Message}}</p>
|
<p>{{.Message}}</p>
|
||||||
<!-- Anzeigen des Links zum Bild, um es zu betrachten -->
|
<a href="/view/{{.Filename}}">Ihr Bild anzeigen</a>
|
||||||
<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>
|
|
||||||
<p><a href="/upload">Zurück zum Upload</a></p>
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue