update copy process, removed binary

This commit is contained in:
Florian Walther
2026-01-16 16:45:45 +01:00
parent 6bc39598c0
commit 0aeb1c843b
2 changed files with 145 additions and 105 deletions

250
main.go
View File

@@ -9,7 +9,8 @@ import (
const ( const (
passwordLength = 32 passwordLength = 32
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?§$%&=#+<>-:,.;_*@" chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
//chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?$%&=#+<>-:,.;_*@"
) )
func generatePassword() string { func generatePassword() string {
@@ -109,110 +110,149 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
func webHandler(w http.ResponseWriter, r *http.Request) { func webHandler(w http.ResponseWriter, r *http.Request) {
password := generatePassword() password := generatePassword()
html := fmt.Sprintf( html := fmt.Sprintf(
`<DOCTYPE html> `<DOCTYPE html>
<html> <html>
<head> <head>
<title>Passwort-Generator</title> <title>Passwort-Generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<style> <style>
body { body {
font-family: 'Helvetica Neue', Arial, sans-serif; font-family: 'Helvetica Neue', Arial, sans-serif;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100vh; height: 100vh;
margin: 0; margin: 0;
background-color: #f5f5f5; background-color: #f5f5f5;
color: #333; color: #333;
} }
.container { .container {
text-align: center; text-align: center;
background: white; background: white;
padding: 2rem; padding: 2rem;
border-radius: 8px; border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 90%%; width: 90%%;
min-width: 600px; min-width: 600px;
position: relative; position: relative;
} }
h1 { h1 {
font-size: 1.5rem; font-size: 1.5rem;
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
color: #444; color: #444;
} }
#password { #password {
font-family: 'Courier New', Courier, monospace; font-family: 'Courier New', Courier, monospace;
font-size: 1.2rem; font-size: 1.2rem;
letter-spacing: 1px; letter-spacing: 1px;
margin: 1rem auto; margin: 1rem auto;
padding: 0.8rem; padding: 0.8rem;
background: #f0f0f0; background: #f0f0f0;
border-radius: 4px; border-radius: 4px;
border: 1px solid #ddd; border: 1px solid #ddd;
width: 90%%; width: 90%%;
word-break: break-all; word-break: break-all;
} }
button { .copy-button {
background: #007BFF; background: #4CAF50;
color: white; color: white;
border: none; border: none;
padding: 0.6rem 1.2rem; padding: 0.6rem 1.2rem;
font-size: 1rem; font-size: 1rem;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
transition: background 0.2s; transition: background 0.2s;
margin: 0.3rem; margin: 0.3rem;
} }
button:hover { .copy-button:hover {
background: #0056b3; background: #45a049;
} }
.help-link { .renew-button {
position: absolute; background: #007BFF;
top: 1rem; color: white;
right: 1rem; border: none;
font-size: 1.2rem; padding: 0.6rem 1.2rem;
color: #999; font-size: 1rem;
text-decoration: none; border-radius: 4px;
} cursor: pointer;
.help-link:hover { transition: background 0.2s;
color: #444; margin: 0.3rem;
} }
.buttons { .renew-button:hover {
display: flex; background: #0056b3;
justify-content: center; }
gap: 0.5rem; .help-link {
} position: absolute;
</style> top: 1rem;
<script> right: 1rem;
function copyToClipboard() { font-size: 1.2rem;
navigator.clipboard.writeText(document.getElementById("password").innerText); color: #999;
alert("Passwort kopiert!"); text-decoration: none;
} }
function generateNewPassword() { .help-link:hover {
fetch("/api/password") color: #444;
.then(response => response.text()) }
.then(password => { .buttons {
document.getElementById("password").innerText = password; display: flex;
}) justify-content: center;
.catch(error => console.error("Fehler:", error)); gap: 0.5rem;
} }
</script> #toast {
</head> visibility: hidden;
<body> min-width: 150px;
<div class="container"> background-color: #4CAF50;
<a href="/help" class="help-link">?</a> color: white;
<h1>Generiertes Passwort</h1> text-align: center;
<div id="password">%s</div> border-radius: 4px;
<div class="buttons"> padding: 0.5rem;
<button onclick="copyToClipboard()">In Zwischenablage kopieren</button> position: fixed;
<button onclick="generateNewPassword()">Neues Passwort generieren</button> top: 20px;
</div> right: 20px;
</div> z-index: 1;
</body> font-size: 0.9rem;
</html>`, box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
password, }
) </style>
</head>
<body>
<div class="container">
<a href="/help" class="help-link">?</a>
<h1>Generiertes Passwort</h1>
<div id="password">%s</div>
<div class="buttons">
<button class="copy-button" onclick="copyToClipboard()">In Zwischenablage kopieren</button>
<button class="renew-button" onclick="generateNewPassword()">Neues Passwort generieren</button>
</div>
<div id="toast">✓ Kopiert!</div>
</div>
<script>
function copyToClipboard() {
const password = document.getElementById("password").innerText;
navigator.clipboard.writeText(password).then(() => {
const toast = document.getElementById("toast");
toast.style.visibility = "visible";
setTimeout(() => {
toast.style.visibility = "hidden";
}, 1500); // Toast verschwindet nach 1,5 Sekunden
}).catch(err => {
console.error("Fehler beim Kopieren: ", err);
alert("Kopieren fehlgeschlagen. Bitte manuell kopieren: " + password);
});
}
function generateNewPassword() {
fetch("/api/password")
.then(response => response.text())
.then(password => {
document.getElementById("password").innerText = password;
})
.catch(error => console.error("Fehler:", error));
}
</script>
</body>
</html>`,
password,
)
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, html) fmt.Fprint(w, html)

Binary file not shown.