Compare commits

..

11 Commits

Author SHA1 Message Date
Florian Walther
623cfd3a50 Merge branch 'main' of gitea.scu.si:Florian.Walther/Web-Password
All checks were successful
/ push_to_registry (push) Successful in 58s
2026-02-04 00:00:04 +01:00
Florian Walther
2f9ee42071 added darkmode 2026-02-03 23:55:35 +01:00
33fe4b2b80 added log statement to APIHandler
All checks were successful
/ push_to_registry (push) Successful in 51s
2026-02-02 22:06:42 +01:00
21f512c2d7 fixed log statement
All checks were successful
/ push_to_registry (push) Successful in 51s
2026-02-02 22:03:08 +01:00
dfda16f8e1 fixed update howto 2026-02-02 22:01:54 +01:00
44bb35abac added basic logging
Some checks failed
/ push_to_registry (push) Failing after 46s
2026-02-02 22:00:01 +01:00
1ae5f9c679 corrected pull url 2026-02-02 21:59:43 +01:00
9a052b3ef7 added more usage tips 2026-02-02 21:53:40 +01:00
9a906ec55c http to https changed in API page
All checks were successful
/ push_to_registry (push) Successful in 51s
2026-02-02 21:32:30 +01:00
8b93585422 workflow angepasst
All checks were successful
/ push_to_registry (push) Successful in 1m14s
2026-01-24 17:52:15 +01:00
59dd16d4ac fixed code URL
Some checks failed
/ push_to_registry (push) Failing after 1m38s
2026-01-24 17:42:32 +01:00
4 changed files with 480 additions and 200 deletions

View File

@@ -14,8 +14,8 @@ jobs:
- name: Login to Gitea - name: Login to Gitea
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ${{ secrets.REGISTRY_URL }} # gitea.scu.si registry: ${{ vars.REGISTRY_URL }} # gitea.scu.si
username: ${{ gitea.actor }} username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }} password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build and push - name: Build and push
@@ -26,5 +26,5 @@ jobs:
# Hier wird die Git-Referenz automatisch als Docker-Tag genutzt # Hier wird die Git-Referenz automatisch als Docker-Tag genutzt
#tags: gitea.scu.si/florianwalther/password-generator:${{ gitea.ref_name }} #tags: gitea.scu.si/florianwalther/password-generator:${{ gitea.ref_name }}
tags: | tags: |
gitea.scu.si/florianwalther/password-generator:${{ gitea.ref_name }} gitea.scu.si/florian.walther/password-generator:${{ gitea.ref_name }}
gitea.scu.si/florianwalther/password-generator:latest gitea.scu.si/florian.walther/password-generator:latest

View File

@@ -32,7 +32,7 @@ The latest official docker image is at [https://gitea.scu.si/FlorianWalther/-/pa
You can pull it like this: You can pull it like this:
``` ```
docker pull gitea.scu.si/florianwalther/password-generator:latest docker pull gitea.scu.si/florian.walther/password-generator:latest
``` ```
## more usage examples ## more usage examples

399
main.go
View File

@@ -42,12 +42,14 @@ func generatePassword() string {
} }
func passwordHandler(w http.ResponseWriter, r *http.Request) { func passwordHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("APIHandler called from %s\n", r.RemoteAddr)
password := generatePassword() password := generatePassword()
fmt.Fprint(w, password) fmt.Fprint(w, password)
} }
// new help handler // new help handler
func helpHandler(w http.ResponseWriter, r *http.Request) { func helpHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("helpHandler called from %s\n", r.RemoteAddr)
helpHTML := ` helpHTML := `
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -55,6 +57,34 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
<title>Hilfe</title> <title>Hilfe</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>
:root {
--bg-color: #f5f5f5;
--text-color: #333;
--container-bg: white;
--button-bg: #007BFF;
--button-hover: #0056b3;
--copy-button-bg: #4CAF50;
--copy-button-hover: #45a049;
--password-bg: #f0f0f0;
--border-color: #ddd;
--shadow-color: rgba(0, 0, 0, 0.1);
}
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #121212;
--text-color: #e0e0e0;
--container-bg: #1e1e1e;
--button-bg: #2a7df4;
--button-hover: #1a5fb4;
--copy-button-bg: #4caf60;
--copy-button-hover: #3d8b40;
--password-bg: #2d2d2d;
--border-color: #444;
--shadow-color: rgba(0, 0, 0, 0.3);
}
}
body { body {
font-family: 'Helvetica Neue', Arial, sans-serif; font-family: 'Helvetica Neue', Arial, sans-serif;
display: flex; display: flex;
@@ -62,35 +92,130 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
align-items: center; align-items: center;
height: 100vh; height: 100vh;
margin: 0; margin: 0;
background-color: #f5f5f5; background-color: var(--bg-color);
color: #333; color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
} }
.help-container {
text-align: left; .container {
background: white; text-align: center;
background: var(--container-bg);
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 var(--shadow-color);
max-width: 800px;
width: 90%; width: 90%;
min-width: 500px; min-width: 600px;
position: relative;
} }
h1 { h1 {
font-size: 1.5rem; font-size: 1.5rem;
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
color: #444; color: var(--text-color);
} }
pre {
#password {
font-family: 'Courier New', Courier, monospace; font-family: 'Courier New', Courier, monospace;
background: #f0f0f0; font-size: 1.2rem;
letter-spacing: 1px;
margin: 1rem auto;
padding: 0.8rem; padding: 0.8rem;
background: var(--password-bg);
border-radius: 4px; border-radius: 4px;
overflow-x: auto; border: 1px solid var(--border-color);
width: 90%;
word-break: break-all;
color: var(--text-color);
} }
a {
color: #007BFF; .copy-button {
background: var(--copy-button-bg);
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: var(--copy-button-hover);
}
.renew-button {
background: var(--button-bg);
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: var(--button-hover);
}
.help-link {
position: absolute;
top: 1rem;
right: 1rem;
font-size: 1.2rem;
color: var(--text-color);
opacity: 0.7;
text-decoration: none; text-decoration: none;
} }
.help-link:hover {
opacity: 1;
}
#toast {
visibility: hidden;
min-width: 150px;
background-color: var(--copy-button-bg);
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 var(--shadow-color);
}
.help-container {
text-align: left;
background: var(--container-bg);
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px var(--shadow-color);
max-width: 800px;
width: 90%;
min-width: 600px;
color: var(--text-color);
}
pre {
font-family: 'Courier New', Courier, monospace;
background: var(--password-bg);
padding: 0.8rem;
border-radius: 4px;
color: var(--text-color);
border: 1px solid var(--border-color);
}
a {
color: var(--button-bg);
text-decoration: none;
}
a:hover { a:hover {
text-decoration: underline; text-decoration: underline;
} }
@@ -104,29 +229,70 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
Der Endpunkt gibt das Passwort im Plain-Text-Format zurück. Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
</p> </p>
<h2>Endpunkt:</h2> <h2>Endpunkt:</h2>
<p><code id="api-endpoint"></code></p> <p><code>http://localhost:8080/api/password</code></p>
<h2>Beispiele:</h2> <h2>Beispiele:</h2>
<h3>Mac/Linux (Terminal):</h3> <h3>Mac/Linux (Terminal):</h3>
<pre id="curl-example"></pre> <pre>echo $(curl -s http://localhost:8080/api/password)</pre>
<h3>Windows (PowerShell):</h3> <h3>Windows (PowerShell):</h3>
<pre id="powershell-example"></pre> <pre>Invoke-RestMethod -Uri http://localhost:8080/api/password</pre>
<h3>Windows (cmd):</h3> <h3>Windows (cmd):</h3>
<pre id="cmd-example"></pre> <pre>curl http://localhost:8080/api/password</pre>
<p> <p>
<a href="/">Zurück zur Passwort-Generierung</a> <a href="/">Zurück zur Passwort-Generierung</a>
</p> </p>
</div> </div>
<script> <script>
// Dynamisch den aktuellen Hostnamen ermitteln // Darkmode-Toggle-Funktion (optional)
const currentHost = window.location.host; function toggleDarkMode() {
const apiEndpoint = "http://" + currentHost + "/api/password"; const root = document.documentElement;
const isDark = root.style.getPropertyValue('--bg-color') === 'rgb(18, 18, 18)';
if (isDark) {
// Zu Lightmode wechseln
root.style.setProperty('--bg-color', '#f5f5f5');
root.style.setProperty('--text-color', '#333');
root.style.setProperty('--container-bg', 'white');
root.style.setProperty('--button-bg', '#007BFF');
root.style.setProperty('--button-hover', '#0056b3');
root.style.setProperty('--copy-button-bg', '#4CAF50');
root.style.setProperty('--copy-button-hover', '#45a049');
root.style.setProperty('--password-bg', '#f0f0f0');
root.style.setProperty('--border-color', '#ddd');
root.style.setProperty('--shadow-color', 'rgba(0, 0, 0, 0.1)');
localStorage.setItem('theme', 'light');
} else {
// Zu Darkmode wechseln
root.style.setProperty('--bg-color', '#121212');
root.style.setProperty('--text-color', '#e0e0e0');
root.style.setProperty('--container-bg', '#1e1e1e');
root.style.setProperty('--button-bg', '#2a7df4');
root.style.setProperty('--button-hover', '#1a5fb4');
root.style.setProperty('--copy-button-bg', '#4caf60');
root.style.setProperty('--copy-button-hover', '#3d8b40');
root.style.setProperty('--password-bg', '#2d2d2d');
root.style.setProperty('--border-color', '#444');
root.style.setProperty('--shadow-color', 'rgba(0, 0, 0, 0.3)');
localStorage.setItem('theme', 'dark');
}
}
// Prüfe, ob Nutzer eine manuelle Einstellung gespeichert hat
if (localStorage.getItem('theme') === 'dark') {
toggleDarkMode();
} else if (localStorage.getItem('theme') === 'light') {
// Stelle sicher, dass Lightmode aktiv ist (falls Systemtheme dark ist)
document.documentElement.style.setProperty('--bg-color', '#f5f5f5');
document.documentElement.style.setProperty('--text-color', '#333');
document.documentElement.style.setProperty('--container-bg', 'white');
document.documentElement.style.setProperty('--button-bg', '#007BFF');
document.documentElement.style.setProperty('--button-hover', '#0056b3');
document.documentElement.style.setProperty('--copy-button-bg', '#4CAF50');
document.documentElement.style.setProperty('--copy-button-hover', '#45a049');
document.documentElement.style.setProperty('--password-bg', '#f0f0f0');
document.documentElement.style.setProperty('--border-color', '#ddd');
document.documentElement.style.setProperty('--shadow-color', 'rgba(0, 0, 0, 0.1)');
}
</script>
// Hostnamen in die Beispiele eintragen
document.getElementById("api-endpoint").textContent = apiEndpoint;
document.getElementById("curl-example").textContent = "curl " + apiEndpoint;
document.getElementById("powershell-example").textContent = "Invoke-RestMethod -Uri " + apiEndpoint;
document.getElementById("cmd-example").textContent = "curl " + apiEndpoint;
</script>
</body> </body>
</html> </html>
` `
@@ -136,6 +302,7 @@ func helpHandler(w http.ResponseWriter, r *http.Request) {
func webHandler(w http.ResponseWriter, r *http.Request) { func webHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("webHandler called from %s\n", r.RemoteAddr)
password := generatePassword() password := generatePassword()
html := fmt.Sprintf( html := fmt.Sprintf(
`<DOCTYPE html> `<DOCTYPE html>
@@ -144,6 +311,34 @@ html := fmt.Sprintf(
<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>
:root {
--bg-color: #f5f5f5;
--text-color: #333;
--container-bg: white;
--button-bg: #007BFF;
--button-hover: #0056b3;
--copy-button-bg: #4CAF50;
--copy-button-hover: #45a049;
--password-bg: #f0f0f0;
--border-color: #ddd;
--shadow-color: rgba(0, 0, 0, 0.1);
}
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #121212;
--text-color: #e0e0e0;
--container-bg: #1e1e1e;
--button-bg: #2a7df4;
--button-hover: #1a5fb4;
--copy-button-bg: #4caf60;
--copy-button-hover: #3d8b40;
--password-bg: #2d2d2d;
--border-color: #444;
--shadow-color: rgba(0, 0, 0, 0.3);
}
}
body { body {
font-family: 'Helvetica Neue', Arial, sans-serif; font-family: 'Helvetica Neue', Arial, sans-serif;
display: flex; display: flex;
@@ -151,38 +346,44 @@ html := fmt.Sprintf(
align-items: center; align-items: center;
height: 100vh; height: 100vh;
margin: 0; margin: 0;
background-color: #f5f5f5; background-color: var(--bg-color);
color: #333; color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
} }
.container { .container {
text-align: center; text-align: center;
background: white; background: var(--container-bg);
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 var(--shadow-color);
width: 90%%; width: 90%;
min-width: 500px; 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: var(--text-color);
} }
#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: var(--password-bg);
border-radius: 4px; border-radius: 4px;
border: 1px solid #ddd; border: 1px solid var(--border-color);
width: 90%%; width: 90%;
word-break: break-all; word-break: break-all;
color: var(--text-color);
} }
.copy-button { .copy-button {
background: #4CAF50; background: var(--copy-button-bg);
color: white; color: white;
border: none; border: none;
padding: 0.6rem 1.2rem; padding: 0.6rem 1.2rem;
@@ -192,11 +393,13 @@ html := fmt.Sprintf(
transition: background 0.2s; transition: background 0.2s;
margin: 0.3rem; margin: 0.3rem;
} }
.copy-button:hover { .copy-button:hover {
background: #45a049; background: var(--copy-button-hover);
} }
.renew-button { .renew-button {
background: #007BFF; background: var(--button-bg);
color: white; color: white;
border: none; border: none;
padding: 0.6rem 1.2rem; padding: 0.6rem 1.2rem;
@@ -206,40 +409,29 @@ html := fmt.Sprintf(
transition: background 0.2s; transition: background 0.2s;
margin: 0.3rem; margin: 0.3rem;
} }
.renew-button:hover { .renew-button:hover {
background: #0056b3; background: var(--button-hover);
}
.about-link {
position: absolute;
top: 1rem;
left: 1rem;
font-size: 1.2rem;
color: #999;
text-decoration: none;
}
.about-link:hover {
color: #444;
} }
.help-link { .help-link {
position: absolute; position: absolute;
top: 1rem; top: 1rem;
right: 1rem; right: 1rem;
font-size: 1.2rem; font-size: 1.2rem;
color: #999; color: var(--text-color);
opacity: 0.7;
text-decoration: none; text-decoration: none;
} }
.help-link:hover { .help-link:hover {
color: #444; opacity: 1;
}
.buttons {
display: flex;
justify-content: center;
gap: 0.5rem;
} }
#toast { #toast {
visibility: hidden; visibility: hidden;
min-width: 150px; min-width: 150px;
background-color: #4CAF50; background-color: var(--copy-button-bg);
color: white; color: white;
text-align: center; text-align: center;
border-radius: 4px; border-radius: 4px;
@@ -249,13 +441,45 @@ html := fmt.Sprintf(
right: 20px; right: 20px;
z-index: 1; z-index: 1;
font-size: 0.9rem; font-size: 0.9rem;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); box-shadow: 0 2px 10px var(--shadow-color);
}
.help-container {
text-align: left;
background: var(--container-bg);
padding: 2rem;
border-radius: 8px;
box-shadow: 0 2px 10px var(--shadow-color);
max-width: 800px;
width: 90%;
min-width: 600px;
color: var(--text-color);
}
pre {
font-family: 'Courier New', Courier, monospace;
background: var(--password-bg);
padding: 0.8rem;
border-radius: 4px;
color: var(--text-color);
border: 1px solid var(--border-color);
}
a {
color: var(--button-bg);
text-decoration: none;
}
a:hover {
text-decoration: underline;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<a href="/help" class="help-link">API</a> <a href="/help" class="help-link">API</a>
<button onclick="toggleDarkMode()" style="position: absolute; top: 1rem; left: 1rem; background: transparent; border: none; color: var(--text-color); font-size: 1.2rem; cursor: pointer;">🌓</button>
<a class="about-link" href="https://gitea.scu.si/FlorianWalther/Web-Password">code</a> <a class="about-link" href="https://gitea.scu.si/FlorianWalther/Web-Password">code</a>
<h1>Generiertes Passwort</h1> <h1>Generiertes Passwort</h1>
<div id="password">%s</div> <div id="password">%s</div>
@@ -288,6 +512,58 @@ html := fmt.Sprintf(
.catch(error => console.error("Fehler:", error)); .catch(error => console.error("Fehler:", error));
} }
</script> </script>
<script>
// Darkmode-Toggle-Funktion (optional)
function toggleDarkMode() {
const root = document.documentElement;
const isDark = root.style.getPropertyValue('--bg-color') === 'rgb(18, 18, 18)';
if (isDark) {
// Zu Lightmode wechseln
root.style.setProperty('--bg-color', '#f5f5f5');
root.style.setProperty('--text-color', '#333');
root.style.setProperty('--container-bg', 'white');
root.style.setProperty('--button-bg', '#007BFF');
root.style.setProperty('--button-hover', '#0056b3');
root.style.setProperty('--copy-button-bg', '#4CAF50');
root.style.setProperty('--copy-button-hover', '#45a049');
root.style.setProperty('--password-bg', '#f0f0f0');
root.style.setProperty('--border-color', '#ddd');
root.style.setProperty('--shadow-color', 'rgba(0, 0, 0, 0.1)');
localStorage.setItem('theme', 'light');
} else {
// Zu Darkmode wechseln
root.style.setProperty('--bg-color', '#121212');
root.style.setProperty('--text-color', '#e0e0e0');
root.style.setProperty('--container-bg', '#1e1e1e');
root.style.setProperty('--button-bg', '#2a7df4');
root.style.setProperty('--button-hover', '#1a5fb4');
root.style.setProperty('--copy-button-bg', '#4caf60');
root.style.setProperty('--copy-button-hover', '#3d8b40');
root.style.setProperty('--password-bg', '#2d2d2d');
root.style.setProperty('--border-color', '#444');
root.style.setProperty('--shadow-color', 'rgba(0, 0, 0, 0.3)');
localStorage.setItem('theme', 'dark');
}
}
// Prüfe, ob Nutzer eine manuelle Einstellung gespeichert hat
if (localStorage.getItem('theme') === 'dark') {
toggleDarkMode();
} else if (localStorage.getItem('theme') === 'light') {
// Stelle sicher, dass Lightmode aktiv ist (falls Systemtheme dark ist)
document.documentElement.style.setProperty('--bg-color', '#f5f5f5');
document.documentElement.style.setProperty('--text-color', '#333');
document.documentElement.style.setProperty('--container-bg', 'white');
document.documentElement.style.setProperty('--button-bg', '#007BFF');
document.documentElement.style.setProperty('--button-hover', '#0056b3');
document.documentElement.style.setProperty('--copy-button-bg', '#4CAF50');
document.documentElement.style.setProperty('--copy-button-hover', '#45a049');
document.documentElement.style.setProperty('--password-bg', '#f0f0f0');
document.documentElement.style.setProperty('--border-color', '#ddd');
document.documentElement.style.setProperty('--shadow-color', 'rgba(0, 0, 0, 0.1)');
}
</script>
</body> </body>
</html>`, </html>`,
password, password,
@@ -305,4 +581,3 @@ func main() {
log.Println("Plain-Text-Passwort: curl http://localhost:8080/api/password") log.Println("Plain-Text-Passwort: curl http://localhost:8080/api/password")
log.Fatal(http.ListenAndServe(":8080", nil)) log.Fatal(http.ListenAndServe(":8080", nil))
} }

View File

@@ -14,6 +14,12 @@ After making above changes you have to reload your ~/bashrc, in order to activat
Now you can enter `genpasswd` and get a fresh password from the API Endpoint. Now you can enter `genpasswd` and get a fresh password from the API Endpoint.
## get 10 fresh passwords
```bash
for i in {1..10}; do echo $(curl -s https://passwd.scu.si/api/password); done
```
# building the app # building the app
you can build the app yourself like this: you can build the app yourself like this:
@@ -75,7 +81,6 @@ docker compose down
In order to update your container to the current version, do this: In order to update your container to the current version, do this:
``` ```
docker compose pull docker compose pull
docker compose down
docker compose up -d docker compose up -d
``` ```