Compare commits
No commits in common. "main" and "v0.1" have entirely different histories.
|
|
@ -1,5 +0,0 @@
|
||||||
SSH_KEY=./id_ed25519
|
|
||||||
SSH_ADDR=:2222
|
|
||||||
HTTP_ADDR=:8080
|
|
||||||
SITE_NAME=localhost:8080
|
|
||||||
SSH_REMOTE_ADDR=localhost:2222
|
|
||||||
|
|
@ -1,3 +1 @@
|
||||||
dist/
|
dist/
|
||||||
.env
|
|
||||||
id_*
|
|
||||||
|
|
|
||||||
11
Dockerfile
11
Dockerfile
|
|
@ -1,11 +0,0 @@
|
||||||
FROM golang:1-alpine as builder
|
|
||||||
ADD . /src
|
|
||||||
RUN cd /src && go build -o /messagessh
|
|
||||||
|
|
||||||
FROM alpine:latest
|
|
||||||
COPY --from=builder /messagessh /bin/messagessh
|
|
||||||
RUN apk --no-cache add openssh
|
|
||||||
ADD ./entrypoint.sh /entrypoint.sh
|
|
||||||
EXPOSE 2222
|
|
||||||
EXPOSE 8080
|
|
||||||
ENTRYPOINT "/entrypoint.sh"
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
[[ ! -d /data ]] && mkdir /data
|
|
||||||
[[ -z $SSH_KEY ]] && SSH_KEY=/data/id_25519
|
|
||||||
[[ ! -f $SSH_KEY ]] && ssh-keygen -t ed25519 -f "$SSH_KEY" -q -N ""
|
|
||||||
[[ -z $SSH_ADDR ]] && SSH_ADDR=:2222
|
|
||||||
[[ -z $HTTP_ADDR ]] && HTTP_ADDR=:8080
|
|
||||||
[[ -z $SSH_REMOTE_ADDR ]] && {
|
|
||||||
if [[ ! -z $SITE_NAME ]]; then
|
|
||||||
SSH_REMOTE_ADDR=$SITE_NAME
|
|
||||||
else
|
|
||||||
SSH_REMOTE_ADDR=localhost:2222
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
[[ -z $SITE_NAME ]] && SITE_NAME=localhost:8080
|
|
||||||
|
|
||||||
export SSH_KEY SSH_ADDR HTTP_ADDR SSH_REMOTE_ADDR SITE_NAME
|
|
||||||
|
|
||||||
echo "Listening on $SSH_ADDR (ssh), $HTTP_ADDR (http)"
|
|
||||||
messagessh
|
|
||||||
3
go.mod
3
go.mod
|
|
@ -1,4 +1,4 @@
|
||||||
module git.kwolek.io/wojciech/msg.kwolek.io
|
module git.kwolek.io/wojciech/messages.sh
|
||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
|
|
@ -11,7 +11,6 @@ require (
|
||||||
require (
|
require (
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
||||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||||
github.com/joho/godotenv v1.4.0 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -4,8 +4,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gliderlabs/ssh v0.3.3 h1:mBQ8NiOgDkINJrZtoizkC3nDNYgSaWtxyem6S2XHBtA=
|
github.com/gliderlabs/ssh v0.3.3 h1:mBQ8NiOgDkINJrZtoizkC3nDNYgSaWtxyem6S2XHBtA=
|
||||||
github.com/gliderlabs/ssh v0.3.3/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
|
github.com/gliderlabs/ssh v0.3.3/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
|
||||||
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
|
|
||||||
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
|
|
||||||
16
main.go
16
main.go
|
|
@ -5,13 +5,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gliderlabs/ssh"
|
"github.com/gliderlabs/ssh"
|
||||||
"github.com/joho/godotenv"
|
|
||||||
|
|
||||||
terminal "golang.org/x/term"
|
terminal "golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -63,13 +60,6 @@ func CheckString(s string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
godotenv.Load()
|
|
||||||
sshKey := ssh.HostKeyFile(os.Getenv("SSH_KEY"))
|
|
||||||
sshAddr := os.Getenv("SSH_ADDR")
|
|
||||||
httpAddr := os.Getenv("HTTP_ADDR")
|
|
||||||
siteName := os.Getenv("SITE_NAME")
|
|
||||||
sshRemoteAddr := os.Getenv("SSH_REMOTE_ADDR")
|
|
||||||
|
|
||||||
m := NewMessageList(10)
|
m := NewMessageList(10)
|
||||||
pkAuth := ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
|
pkAuth := ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
|
||||||
return true
|
return true
|
||||||
|
|
@ -172,9 +162,7 @@ func main() {
|
||||||
|
|
||||||
web := Web{
|
web := Web{
|
||||||
Messages: m,
|
Messages: m,
|
||||||
SiteName: siteName,
|
|
||||||
SSHAddr: sshRemoteAddr,
|
|
||||||
}
|
}
|
||||||
go web.ListenAndServe(httpAddr)
|
go web.ListenAndServe(":8080")
|
||||||
log.Fatal(ssh.ListenAndServe(sshAddr, nil, pkAuth, sshKey))
|
log.Fatal(ssh.ListenAndServe(":2222", nil, pkAuth))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
26
web.go
26
web.go
|
|
@ -7,13 +7,11 @@ import (
|
||||||
|
|
||||||
type Web struct {
|
type Web struct {
|
||||||
Messages *MessageList
|
Messages *MessageList
|
||||||
SiteName string
|
|
||||||
SSHAddr string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var siteTemplate string = `
|
var siteTemplate string = `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<title>{{ .Name }}</title>
|
<title>messages.sh</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<style>
|
<style>
|
||||||
@import url('https://fonts.googleapis.com/css2?family=Ubuntu+Mono&display=swap');
|
@import url('https://fonts.googleapis.com/css2?family=Ubuntu+Mono&display=swap');
|
||||||
|
|
@ -105,12 +103,12 @@ h1 {
|
||||||
padding-bottom: 1em;
|
padding-bottom: 1em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<h1>{{ .Name }}</h1>
|
<h1>messages.sh</h1>
|
||||||
<p class="info">Hello! To add your own message, run:</p>
|
<p class="info">Hello! To add your own message, run:</p>
|
||||||
<pre class="info"><code>ssh {{ .Addr }}</code></pre>
|
<pre class="info"><code>ssh messages.sh</code></pre>
|
||||||
<h2>Latest messages</h2>
|
<h2>Latest messages</h2>
|
||||||
<p>
|
<p>
|
||||||
{{range .Msgs}}
|
{{range .}}
|
||||||
<div class="message">
|
<div class="message">
|
||||||
<div class="meta"><div class="ts">{{ .Timestamp.Format "2006-01-02 15:04:05 MST" }}</div> <div class="username">{{ .Username }} ({{ .PKShort }})</div></div> <div class="content">{{ .Content }}</div><br>
|
<div class="meta"><div class="ts">{{ .Timestamp.Format "2006-01-02 15:04:05 MST" }}</div> <div class="username">{{ .Username }} ({{ .PKShort }})</div></div> <div class="content">{{ .Content }}</div><br>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -119,13 +117,19 @@ h1 {
|
||||||
`
|
`
|
||||||
|
|
||||||
func (w *Web) ListenAndServe(addr string) {
|
func (w *Web) ListenAndServe(addr string) {
|
||||||
|
w.Messages.Add(Message{
|
||||||
|
Content: "2137 papiez",
|
||||||
|
Username: "weeeoefka",
|
||||||
|
PKShort: "23daa6f",
|
||||||
|
})
|
||||||
|
w.Messages.Add(Message{
|
||||||
|
Content: "2137 papiez lorem ipsum dolan sit amet saldkjaksjdf sdkjf slkdj flskjdf lkjsdlkfj ",
|
||||||
|
Username: "weeeoe",
|
||||||
|
PKShort: "23daa6f",
|
||||||
|
})
|
||||||
tmpl := template.Must(template.New("tmpl").Parse(siteTemplate))
|
tmpl := template.Must(template.New("tmpl").Parse(siteTemplate))
|
||||||
http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
|
||||||
tmpl.Execute(rw, map[string]interface{}{
|
tmpl.Execute(rw, w.Messages.Reverse())
|
||||||
"Msgs": w.Messages.Reverse(),
|
|
||||||
"Name": w.SiteName,
|
|
||||||
"Addr": w.SSHAddr,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
http.ListenAndServe(addr, nil)
|
http.ListenAndServe(addr, nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue