Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7678274be | |||
| 4a8f7525e7 | |||
| fb55f47e5c | |||
| 0251b9dc69 | |||
| 2b505b0d9d | |||
| cb3545f261 | |||
| d673b97b4b | |||
| 1be4aeb6b8 | |||
| 0a3f4ab5ef |
15
README.md
15
README.md
@@ -1,6 +1,6 @@
|
||||
# Web-Password
|
||||
|
||||
_a web based password generator_
|
||||
_a web based password generator, with an API endpoint_
|
||||
|
||||

|
||||
|
||||
@@ -16,7 +16,7 @@ There is a demo at [https://passwd.scu.si](https://passwd.scu.si)
|
||||
|
||||
## 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
|
||||
@@ -26,4 +26,15 @@ docker compose pull
|
||||
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/florianwalther/password-generator:latest
|
||||
```
|
||||
|
||||
## more usage examples
|
||||
|
||||
There are some more usage example in [misc/MoreUsage.md](misc/MoreUsage.md)
|
||||
|
||||
159
main.go
159
main.go
@@ -46,82 +46,95 @@ func passwordHandler(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, password)
|
||||
}
|
||||
|
||||
// new help handler
|
||||
func helpHandler(w http.ResponseWriter, r *http.Request) {
|
||||
helpHTML := `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hilfe</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;
|
||||
}
|
||||
.help-container {
|
||||
text-align: left;
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 800px;
|
||||
width: 90%;
|
||||
min-width: 500px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
color: #444;
|
||||
}
|
||||
pre {
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
background: #f0f0f0;
|
||||
padding: 0.8rem;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
a {
|
||||
color: #007BFF;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="help-container">
|
||||
<h1>Hilfe: API-Endpunkt</h1>
|
||||
<p>
|
||||
Diese Anwendung bietet einen API-Endpunkt, um Passwörter direkt über die Kommandozeile abzurufen.
|
||||
Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
|
||||
</p>
|
||||
<h2>Endpunkt:</h2>
|
||||
<p><code>http://localhost:8080/api/password</code></p>
|
||||
<h2>Beispiele:</h2>
|
||||
<h3>Mac/Linux (Terminal):</h3>
|
||||
<pre>echo $(curl -s http://localhost:8080/api/password)</pre>
|
||||
<h3>Windows (PowerShell):</h3>
|
||||
<pre>Invoke-RestMethod -Uri http://localhost:8080/api/password</pre>
|
||||
<h3>Windows (cmd):</h3>
|
||||
<pre>curl http://localhost:8080/api/password</pre>
|
||||
<p>
|
||||
<a href="/">Zurück zur Passwort-Generierung</a>
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprint(w, helpHTML)
|
||||
helpHTML := `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Hilfe</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;
|
||||
}
|
||||
.help-container {
|
||||
text-align: left;
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
max-width: 800px;
|
||||
width: 90%;
|
||||
min-width: 500px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
color: #444;
|
||||
}
|
||||
pre {
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
background: #f0f0f0;
|
||||
padding: 0.8rem;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
a {
|
||||
color: #007BFF;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="help-container">
|
||||
<h1>Hilfe: API-Endpunkt</h1>
|
||||
<p>
|
||||
Diese Anwendung bietet einen API-Endpunkt, um Passwörter direkt über die Kommandozeile abzurufen.
|
||||
Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
|
||||
</p>
|
||||
<h2>Endpunkt:</h2>
|
||||
<p><code id="api-endpoint"></code></p>
|
||||
<h2>Beispiele:</h2>
|
||||
<h3>Mac/Linux (Terminal):</h3>
|
||||
<pre id="curl-example"></pre>
|
||||
<h3>Windows (PowerShell):</h3>
|
||||
<pre id="powershell-example"></pre>
|
||||
<h3>Windows (cmd):</h3>
|
||||
<pre id="cmd-example"></pre>
|
||||
<p>
|
||||
<a href="/">Zurück zur Passwort-Generierung</a>
|
||||
</p>
|
||||
</div>
|
||||
<script>
|
||||
// Dynamisch den aktuellen Hostnamen ermitteln
|
||||
const currentHost = window.location.host;
|
||||
const apiEndpoint = "http://" + 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) {
|
||||
password := generatePassword()
|
||||
html := fmt.Sprintf(
|
||||
|
||||
@@ -1,31 +1,60 @@
|
||||
## 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.
|
||||
|
||||
# building the app
|
||||
|
||||
you can build the app yourself like this:
|
||||
|
||||
```
|
||||
go build -o password-generator ./
|
||||
```
|
||||
|
||||
# Baue das Docker-Image
|
||||
|
||||
|
||||
# build a docker container
|
||||
|
||||
```
|
||||
docker build -t password-generator .
|
||||
```
|
||||
|
||||
# Starte den Docker Container
|
||||
# start the docker container
|
||||
|
||||
```
|
||||
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
|
||||
|
||||
```
|
||||
docker compose login gitea.scu.si
|
||||
docker compose pull
|
||||
```
|
||||
|
||||
@@ -41,5 +70,13 @@ docker compose up -d
|
||||
docker compose down
|
||||
```
|
||||
|
||||
### update container
|
||||
|
||||
In order to update your container to the current version, do this:
|
||||
```
|
||||
docker compose pull
|
||||
docker compose down
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ services:
|
||||
restart: always
|
||||
expose:
|
||||
- "8080:8080"
|
||||
# Falls die Registry privat ist, muss der Host zuvor mit
|
||||
# 'docker login gitea.scu.si' angemeldet worden sein.
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.docker.network=traefik_backend"
|
||||
|
||||
Reference in New Issue
Block a user