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