Compare commits

..

23 Commits

Author SHA1 Message Date
vxclutch
645fdc37d8 maint: remove deps and add docs 2026-06-04 07:30:08 -04:00
vxclutch
35d908cd73 maint: update todo 2026-06-03 08:26:20 -04:00
vxclutch
f188264f39 maint: done with todo 2026-06-03 08:25:50 -04:00
vxclutch
1436b8cf2f save 2026-06-03 08:23:45 -04:00
vxclutch
459fe380db save 2026-06-02 14:53:21 -04:00
vxclutch
ec19585e9b maint: changes 2026-06-02 07:52:52 -04:00
vxclutch
9ced6600e3 remove mDNS 2026-06-01 07:30:13 -04:00
vxclutch
b78cc02d5c save 2026-05-31 10:33:57 -04:00
vxclutch
a93fa2f61f start mDNS 2026-05-29 14:48:57 -04:00
vxclutch
230e58c286 feat: kill server after n downloads 2026-05-29 08:05:00 -04:00
vxclutch
09e147f2f1 Merge branch 'main' of https://git.vxserver.dev/vx-clutch/lash 2026-05-29 07:10:31 -04:00
vxclutch
28e88cc833 maint: todo 2026-05-28 17:34:25 -04:00
vxclutch
d06a7cf09d maint: update todo 2026-05-28 08:30:48 -04:00
vxclutch
d18838dfee feat: share link 2026-05-28 08:25:59 -04:00
vxclutch
363c3b6c96 maint: comment source code 2026-05-28 07:55:10 -04:00
vxclutch
b436415980 feat: port flag 2026-05-28 07:44:33 -04:00
vxclutch
d0ff3003b2 todo -> TODO 2026-05-27 19:16:10 -04:00
vxclutch
bea0213387 maint: update todo 2026-05-27 19:13:11 -04:00
vxclutch
4d284b7c5a save 2026-05-27 19:09:59 -04:00
vxclutch
1234288e03 1.0 version 2026-05-27 19:00:09 -04:00
vxclutch
7ee19a2883 save 2026-05-27 18:52:37 -04:00
vxclutch
6da1bb9fc1 save 2026-05-27 11:14:26 -04:00
vxclutch
fb7d0ee80d maint: makefile 2026-05-27 09:47:54 -04:00
19 changed files with 343 additions and 88 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
lash

12
Makefile Normal file
View File

@@ -0,0 +1,12 @@
GO?= go
.PHONY: build lint
all: build
build:
$(GO) build -o lash ./bin/main.go
lint:
$(GO) fmt ./...
$(GO) vet ./...

View File

@@ -1 +1,21 @@
# LASH (Local Area Share HTTP) # LASH (Local Area Share HTTP)
## Usage
Using lash is pretty simple. You just provide any amount of command line
arguments and it will generate a share link, and a code. You either go-to
http://<your-local-ip>:port or goto http://<your-share-link> to access the
files.
## Building from Source
Lash only has one dependency and that it is Go >= 1.26.3. To build it you just
run either of the two following commands.
```sh
$ make
```
or
```sh
$ go build -o lash ./bin/main.go
```

1
TODO Normal file
View File

@@ -0,0 +1 @@
feat: sumbit code with press of enter key

44
bin/main.go Normal file
View File

@@ -0,0 +1,44 @@
package main
import (
_ "embed"
"flag"
"fmt"
"lash"
"lash/internal/app"
"lash/internal/errx"
share "lash/internal/shareLink"
"net/http"
)
var versionFlag = flag.Bool("version", false, "Print out version and exit.")
var port = flag.Int("p", 1337, "Set the port for LASH exchanges.")
var numberOfShares = flag.Int("n", -1, "Number of shares to allow before killing the server.")
func main() {
flag.Parse()
if *versionFlag {
fmt.Print("lash/vxc v", lash.Version)
return
}
ctx := lash.LashContext{
N: *numberOfShares,
}
srv := app.New(&ctx)
server := http.Server{
Addr: fmt.Sprintf(":%d", *port),
Handler: srv,
}
errx.Log("Your share link is %s", share.GenerateShareLink(*port))
errx.Log("Your token is \033[1;92m%s\033[0m", lash.Token)
errx.Log("starting server at http://%s:%d", share.GetLocalIP(), *port)
if err := server.ListenAndServe(); err != nil {
errx.FatalPerror(err)
}
}

View File

@@ -1,20 +0,0 @@
package main
import (
_ "embed"
"lash"
"lash/internal/app"
"lash/internal/errx"
"net/http"
)
func main() {
srv := app.New()
errx.Log("Your token is \033[1;92m%s\033[0m", lash.Token)
errx.Log("starting server at http://127.0.0.1:1337")
if err := http.ListenAndServe(":1337", srv); err != nil {
errx.FatalPerror(err)
}
}

2
go.mod
View File

@@ -1,5 +1,3 @@
module lash module lash
go 1.26.3 go 1.26.3
require github.com/google/uuid v1.6.0 // indirect

2
go.sum
View File

@@ -1,2 +0,0 @@
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

View File

@@ -1,19 +0,0 @@
package app
import (
"errors"
"os"
"strings"
)
func GetFilePath() (string, error) {
fp := ""
for _, v := range os.Args[1:] {
if !strings.HasPrefix(v, "-") {
fp = v
return fp, nil
}
}
return "", errors.New("not enough arguments")
}

View File

@@ -1,29 +1,45 @@
package app package app
import ( import (
"flag"
"lash" "lash"
"lash/internal/errx" "lash/internal/errx"
"lash/internal/handlers" "lash/internal/handlers"
"net/http" "net/http"
"os"
) )
func New() http.Handler { func New(ctx *lash.LashContext) http.Handler {
mux := http.NewServeMux() mux := http.NewServeMux()
fp, err := GetFilePath() share := handlers.ShareData{
Version: lash.Version,
}
file := handlers.FileHandler{
Ctx: ctx,
}
fps := flag.Args()
if len(fps) < 1 {
errx.FatalPerror(errx.ErrNotEnoughArgs)
}
for _, fp := range fps {
contents, err := os.ReadFile(fp)
if err != nil { if err != nil {
errx.FatalPerror(err) errx.FatalPerror(err)
} }
share := handlers.ShareData{ file.FileData = append(file.FileData, handlers.FileData{
Version: lash.Version, Contents: contents,
FileName: fp, FileName: fp,
})
} }
file := handlers.FileData{}
mux.HandleFunc("/", share.Handler) mux.HandleFunc("/", share.Handler)
mux.HandleFunc("/api/receive-token", file.APIHandler) mux.HandleFunc("/api/receive-token", file.APIHandler)
mux.HandleFunc("/"+lash.ShareLinkToken, file.FileHandler)
return mux return mux
} }

5
internal/errx/define.go Normal file
View File

@@ -0,0 +1,5 @@
package errx
import "errors"
var ErrNotEnoughArgs error = errors.New("not enough arguments")

View File

@@ -2,6 +2,6 @@ package errx
import "fmt" import "fmt"
func Log(msg string, k... any) { func Log(msg string, k ...any) {
fmt.Printf("lash: " + msg + "\n", k...) fmt.Printf("lash: "+msg+"\n", k...)
} }

View File

@@ -0,0 +1,55 @@
package generator
import (
"math/rand/v2"
)
var keys []string = []string{
"octo",
"cool",
"whip",
"keys",
"cats",
"part",
"rate",
"face",
"lard",
"larp",
"dogs",
"cash",
"city",
"cold",
"desk",
"down",
"dirt",
"long",
"mean",
"news",
"only",
"open",
"year",
"wood",
"wing",
"work",
"wash",
"vote",
"onyx",
"snow",
"john",
"json",
"fang",
}
func Generate(n int) (code string) {
codeLen := n
start := rand.IntN(len(keys))
for i := range codeLen {
code += keys[(start+i)%len(keys)]
if i != codeLen-1 {
code += "-"
}
}
return
}

View File

@@ -1,35 +1,83 @@
package handlers package handlers
import ( import (
"archive/zip"
"encoding/json" "encoding/json"
"fmt"
"lash" "lash"
"lash/internal/errx" "lash/internal/errx"
"net/http" "net/http"
"strconv"
) )
type FileHandler struct {
Ctx *lash.LashContext
FileData []FileData
}
type FileData struct { type FileData struct {
Contents []byte Contents []byte
FileName string
} }
type ValidateRequest struct { type ValidateRequest struct {
Token string Token string
} }
func (h FileData) APIHandler(w http.ResponseWriter, r *http.Request) { var sent int = 0
func (h FileHandler) APIHandler(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body) decoder := json.NewDecoder(r.Body)
var t ValidateRequest var t ValidateRequest
err := decoder.Decode(&t) err := decoder.Decode(&t)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if t.Token != lash.Token {
http.Error(w, "Invalid Token", http.StatusUnauthorized)
return
}
http.Redirect(w, r, fmt.Sprintf("/%s", lash.ShareLinkToken), http.StatusTemporaryRedirect)
}
func (h FileHandler) FileHandler(w http.ResponseWriter, r *http.Request) {
if sent >= h.Ctx.N && h.Ctx.N != -1 {
http.Error(w, "Too many requests", http.StatusTooManyRequests)
return
}
filename := h.FileData[0].FileName
if len(h.FileData) > 1 {
filename = "lash.zip"
}
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
w.Header().Set("Content-Type", "application/octet-stream")
if len(h.FileData) == 1 {
w.Header().Set("Content-Length", strconv.Itoa(len(h.FileData[0].Contents)))
w.WriteHeader(http.StatusOK)
_, _ = w.Write(h.FileData[0].Contents)
} else {
w.WriteHeader(http.StatusOK)
zw := zip.NewWriter(w)
defer zw.Close()
for _, f := range h.FileData {
fw, err := zw.Create(f.FileName)
if err != nil { if err != nil {
errx.FatalPerror(err) errx.FatalPerror(err)
} }
_, err = fw.Write(f.Contents)
if t.Token == lash.Token { if err != nil {
errx.Log("Got token") errx.FatalPerror(err)
} else { }
errx.Log("No Token") }
} }
}
func (h FileData) DownloadHandler(w http.ResponseWriter, r *http.Request) { sent++
w.Write(h.Contents)
} }

View File

@@ -2,8 +2,9 @@ package handlers
import ( import (
"html/template" "html/template"
"lash"
"net/http" "net/http"
"lash"
) )
type ShareData struct { type ShareData struct {
@@ -11,7 +12,10 @@ type ShareData struct {
FileName string FileName string
} }
func (h ShareData) Handler(w http.ResponseWriter, r *http.Request) { func (h *ShareData) Handler(w http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFS(lash.Templates, "share.html")) tmpl := template.Must(template.ParseFS(lash.Templates, "templates/share.html"))
tmpl.ExecuteTemplate(w, "share.html", h)
if err := tmpl.ExecuteTemplate(w, "share.html", h); err != nil {
http.Error(w, "template render error: "+err.Error(), http.StatusInternalServerError)
}
} }

View File

@@ -0,0 +1,29 @@
package sharelink
import (
"fmt"
"lash"
"lash/internal/errx"
"net"
)
func GenerateShareLink(port int) string {
link := "http://"
link += GetLocalIP()
link += fmt.Sprintf(":%d", port)
link += "/"
link += lash.ShareLinkToken
return link
}
func GetLocalIP() string {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
errx.FatalPerror(err)
}
defer conn.Close()
localAddress := conn.LocalAddr().(*net.UDPAddr)
return localAddress.IP.String()
}

17
lash.go
View File

@@ -1,11 +1,22 @@
package lash package lash
import "embed" import (
"embed"
"lash/internal/generator"
"net/http"
)
//go:embed templates/* type LashContext struct {
N int
Server *http.Server
}
//go:embed templates/*.html
var Templates embed.FS var Templates embed.FS
//go:embed version //go:embed version
var Version string var Version string
var Token string = "SICK-COOL-TOKEN" var Token string = generator.Generate(5)
var ShareLinkToken string = generator.Generate(8)

View File

@@ -1,26 +1,78 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lash v{{.Version}}</title> <title>Lash v{{.Version}}</title>
</head> </head>
<body> <body>
<h1>Enter Token</h1>
<form id="tform" action="localpage.html" method="POST"> <input
<input name="token" id="token" placeholder="Enter token"> type="text"
<button type="submit">Go</button> id="tokenInput"
</form> placeholder="Enter token"
/>
</body> <button id="submitBtn">
Submit
</button>
<script> <p id="status"></p>
await fetch('/api/receive-token', {
<script>
const tokenInput = document.getElementById('tokenInput');
const submitBtn = document.getElementById('submitBtn');
const status = document.getElementById('status');
submitBtn.addEventListener('click', async () => {
const token = tokenInput.value.trim();
if (!token) {
status.textContent = 'Please enter a token.';
return;
}
try {
const response = await fetch('/api/receive-token', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: {
body: JSON.stringify({ token: USER_TOKEN }) 'Content-Type': 'application/json'
}); },
</script> body: JSON.stringify({ token })
});
if (!response.ok) {
status.textContent = 'Download failed.';
return;
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const disposition = response.headers.get('Content-Disposition');
let filename = 'download.bin';
if (disposition && disposition.includes('filename=')) {
filename = disposition
.split('filename=')[1]
.replace(/"/g, '');
}
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
status.textContent = 'Download started.';
} catch (err) {
console.error(err);
status.textContent = 'An error occurred.';
}
});
</script>
</body>
</html> </html>

View File

@@ -1 +1 @@
0.1.0 6