Compare commits

..

17 Commits

Author SHA1 Message Date
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
d7678274be added pull info
Some checks failed
/ push_to_registry (push) Failing after 1m38s
2026-01-17 22:57:04 +01:00
4a8f7525e7 updated README 2026-01-17 22:54:57 +01:00
fb55f47e5c fixed spelling 2026-01-17 22:32:35 +01:00
0251b9dc69 undo centered image, did not work 2026-01-17 22:30:58 +01:00
2b505b0d9d centered image 2026-01-17 22:30:00 +01:00
cb3545f261 updated claim in README.md 2026-01-17 22:29:08 +01:00
d673b97b4b deleted obsolete lines in misc/docker-compose.traefik.yml 2026-01-17 22:26:58 +01:00
1be4aeb6b8 updated MoreUsage.md 2026-01-17 22:24:16 +01:00
0a3f4ab5ef added dynamic hostname to helpHandler
Some checks failed
/ push_to_registry (push) Failing after 1m34s
2026-01-17 21:59:54 +01:00
5 changed files with 154 additions and 88 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

@@ -1,6 +1,6 @@
# Web-Password # Web-Password
_a web based password generator_ _a web based password generator, with an API endpoint_
![App Screenshot](img/screenshot.png) ![App Screenshot](img/screenshot.png)
@@ -16,7 +16,7 @@ There is a demo at [https://passwd.scu.si](https://passwd.scu.si)
## Usage ## Usage
The follwoing example shows how to get up your own instance with `docker compose`. The following example shows how to get up your own instance with `docker compose`.
``` ```
git clone https://gitea.scu.si/FlorianWalther/Web-Password.git git clone https://gitea.scu.si/FlorianWalther/Web-Password.git
@@ -26,4 +26,15 @@ docker compose pull
docker compose up -d docker compose up -d
``` ```
## Docker image
The latest official docker image is at [https://gitea.scu.si/FlorianWalther/-/packages/container/password-generator/latest](https://gitea.scu.si/FlorianWalther/-/packages/container/password-generator/latest)
You can pull it like this:
```
docker pull gitea.scu.si/florian.walther/password-generator:latest
```
## more usage examples
There are some more usage example in [misc/MoreUsage.md](misc/MoreUsage.md) There are some more usage example in [misc/MoreUsage.md](misc/MoreUsage.md)

163
main.go
View File

@@ -46,83 +46,98 @@ func passwordHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, password) fmt.Fprint(w, password)
} }
// new help handler
func helpHandler(w http.ResponseWriter, r *http.Request) { func helpHandler(w http.ResponseWriter, r *http.Request) {
helpHTML := ` log.Printf("helpHandler called from %s\n", r.RemoteAddr)
<!DOCTYPE html> helpHTML := `
<html> <!DOCTYPE html>
<head> <html>
<title>Hilfe</title> <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hilfe</title>
<style> <meta name="viewport" content="width=device-width, initial-scale=1.0">
body { <style>
font-family: 'Helvetica Neue', Arial, sans-serif; body {
display: flex; font-family: 'Helvetica Neue', Arial, sans-serif;
justify-content: center; display: flex;
align-items: center; justify-content: center;
height: 100vh; align-items: center;
margin: 0; height: 100vh;
background-color: #f5f5f5; margin: 0;
color: #333; background-color: #f5f5f5;
} color: #333;
.help-container { }
text-align: left; .help-container {
background: white; text-align: left;
padding: 2rem; background: white;
border-radius: 8px; padding: 2rem;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); border-radius: 8px;
max-width: 800px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 90%; max-width: 800px;
min-width: 500px; width: 90%;
} min-width: 500px;
h1 { }
font-size: 1.5rem; h1 {
margin-bottom: 1.5rem; font-size: 1.5rem;
color: #444; margin-bottom: 1.5rem;
} color: #444;
pre { }
font-family: 'Courier New', Courier, monospace; pre {
background: #f0f0f0; font-family: 'Courier New', Courier, monospace;
padding: 0.8rem; background: #f0f0f0;
border-radius: 4px; padding: 0.8rem;
overflow-x: auto; border-radius: 4px;
} overflow-x: auto;
a { }
color: #007BFF; a {
text-decoration: none; color: #007BFF;
} text-decoration: none;
a:hover { }
text-decoration: underline; a:hover {
} text-decoration: underline;
</style> }
</head> </style>
<body> </head>
<div class="help-container"> <body>
<h1>Hilfe: API-Endpunkt</h1> <div class="help-container">
<p> <h1>Hilfe: API-Endpunkt</h1>
Diese Anwendung bietet einen API-Endpunkt, um Passwörter direkt über die Kommandozeile abzurufen. <p>
Der Endpunkt gibt das Passwort im Plain-Text-Format zurück. Diese Anwendung bietet einen API-Endpunkt, um Passwörter direkt über die Kommandozeile abzurufen.
</p> Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
<h2>Endpunkt:</h2> </p>
<p><code>http://localhost:8080/api/password</code></p> <h2>Endpunkt:</h2>
<h2>Beispiele:</h2> <p><code id="api-endpoint"></code></p>
<h3>Mac/Linux (Terminal):</h3> <h2>Beispiele:</h2>
<pre>echo $(curl -s http://localhost:8080/api/password)</pre> <h3>Mac/Linux (Terminal):</h3>
<h3>Windows (PowerShell):</h3> <pre id="curl-example"></pre>
<pre>Invoke-RestMethod -Uri http://localhost:8080/api/password</pre> <h3>Windows (PowerShell):</h3>
<h3>Windows (cmd):</h3> <pre id="powershell-example"></pre>
<pre>curl http://localhost:8080/api/password</pre> <h3>Windows (cmd):</h3>
<p> <pre id="cmd-example"></pre>
<a href="/">Zurück zur Passwort-Generierung</a> <p>
</p> <a href="/">Zurück zur Passwort-Generierung</a>
</div> </p>
</body> </div>
</html> <script>
` // Dynamisch den aktuellen Hostnamen ermitteln
w.Header().Set("Content-Type", "text/html; charset=utf-8") const currentHost = window.location.host;
fmt.Fprint(w, helpHTML) const apiEndpoint = "https://" + currentHost + "/api/password";
// 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>
</html>
`
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, helpHTML)
} }
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>
@@ -243,7 +258,7 @@ html := fmt.Sprintf(
<body> <body>
<div class="container"> <div class="container">
<a href="/help" class="help-link">API</a> <a href="/help" class="help-link">API</a>
<a class="about-link" href="https://gitea.scu.si/FlorianWalther/Web-Password">code</a> <a class="about-link" href="https://gitea.scu.si/Florian.Walther/Web-Password">code</a>
<h1>Generiertes Passwort</h1> <h1>Generiertes Passwort</h1>
<div id="password">%s</div> <div id="password">%s</div>
<div class="buttons"> <div class="buttons">

View File

@@ -1,31 +1,66 @@
## bash alias
You can configure an bash alias in your `~/.bashrc` like this:
# Baue die Go-Anwendung ```
## genpasswd alias
alias genpasswd='echo $(curl -s https://passwd.scu.si/api/password)'
```
After making above changes you have to reload your ~/bashrc, in order to activate your changes.
```
. ~/.bashrc
```
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
you can build the app yourself like this:
``` ```
go build -o password-generator ./ go build -o password-generator ./
``` ```
# Baue das Docker-Image
# build a docker container
``` ```
docker build -t password-generator . docker build -t password-generator .
``` ```
# Starte den Docker Container # start the docker container
``` ```
docker run -p 8080:8080 password-generator docker run -p 8080:8080 password-generator
``` ```
## mit docker-compose ## docker-compose
Ein `docker-compose.yml` wird mitgeliefert. There are two example docker-compose files in the [misc](./) directory.
### docker-compose.yml
A basic variant that just brings up the container and export port 8080.
The basic variant can be used without modifications.
### docker-compose.traefik.yml
The other one is meant to be used behind a traefik reverse proxy.
This variant has lables to configure traefik accordingly.
The traefik variant needs to be adjusted to your environment before
you can use it successfully.
### initial pull ### initial pull
``` ```
docker compose login gitea.scu.si
docker compose pull docker compose pull
``` ```
@@ -41,5 +76,12 @@ docker compose up -d
docker compose down docker compose down
``` ```
### update container
In order to update your container to the current version, do this:
```
docker compose pull
docker compose up -d
```

View File

@@ -5,8 +5,6 @@ services:
restart: always restart: always
expose: expose:
- "8080:8080" - "8080:8080"
# Falls die Registry privat ist, muss der Host zuvor mit
# 'docker login gitea.scu.si' angemeldet worden sein.
labels: labels:
- "traefik.enable=true" - "traefik.enable=true"
- "traefik.docker.network=traefik_backend" - "traefik.docker.network=traefik_backend"