Compare commits

..

3 Commits

Author SHA1 Message Date
4d2930780f feat: add support for fish scripts 2024-10-17 00:25:26 -03:00
d9f840de51 docs: add screenshots to readme 2024-10-17 00:25:26 -03:00
3cf851f232 docs: add features to readme 2024-10-16 23:48:28 -03:00
6 changed files with 4 additions and 81 deletions

View File

@ -7,14 +7,6 @@ abyss is a basic and mostly single user http server written in go made for uploa
<figcaption>this is abyss' default home page<figcaption/>
</figure>
## features
- **file uploads**: supports uploading various file types, including images, videos, and documents.
- **flexible media display**: automatically renders uploaded files on a webpage based on their type (images, pdfs, videos, or plain text).
- **customizable interface**: allows for easy modification of color schemes and layout to suit specific design needs.
- **syntax highlighting for code**: syntax highlighting available by default for code files, with support for multiple programming languages. (can be tweaked/changed and even removed)
- **security considerations**: as it is single user, it's mostly secure but there are still some edges to sharpen
## table of contents
- [features](#features)
@ -61,11 +53,7 @@ docker compose up -d # might be docker-compose depending on distro
#### with curl
- you can upload both with the main key and with jwt tokens
##### main key
- to upload your files with main key:
- to upload your files with curl:
```bash
curl -F "file=@/path/to/file" -H "X-Auth: "$(cat /path/to/.key) http://localhost:3235/
@ -89,7 +77,7 @@ pst() {
return 1
fi
curl -F "file=@$file" -H "X-Auth: $(cat ~/.key)" http://localhost:3235/
curl -F "file=@$file" -H "X-Auth: $(cat ~/.key)" http://localhost:3235
if [[ -p /dev/stdin ]]; then
rm "$file"
@ -113,7 +101,7 @@ function pst
set file "$argv[1]"
end
curl -F "file=@$file" -H "X-Auth: $(cat ~/.key)" http://localhost:3235/
curl -F "file=@$file" -H "X-Auth: $(cat ~/.key)" http://localhost:3235
if command test -p /dev/stdin
rm "$file"
@ -123,22 +111,6 @@ end
</details>
##### with jwt tokens
- you first need to generate them:
```bash
curl -u admin http://localhost:3235/token # you can also access the url in the browser directly
```
- the user will be the value of `$AUTH_USERNAME` and password the value of `$AUTH_PASSWORD`
- then you use the token in place of the main key:
```bash
curl -F"file=@/path/to/file.jpg" -H "X-Auth: your-token" http://localhost:3235/
```
#### through the browser
- you can only upload text through the browser, to do so, simply write text in the form in the default webpage and click upload.

View File

@ -93,8 +93,6 @@ func setupHandlers(mux *http.ServeMux, app *Application) {
mux.HandleFunc("/last", app.lastUploadedHandler)
mux.HandleFunc("/token", BasicAuth(app.createTokenHandler, app))
mux.HandleFunc("/files/", app.fileHandler)
if app.authText == "yes" {

2
go.mod
View File

@ -3,5 +3,3 @@ module github.com/jabuxas/abyss
go 1.22.6
require github.com/joho/godotenv v1.5.1
require github.com/golang-jwt/jwt/v5 v5.2.1 // indirect

2
go.sum
View File

@ -1,4 +1,2 @@
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=

View File

@ -9,9 +9,6 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/golang-jwt/jwt/v5"
)
type Application struct {
@ -201,17 +198,3 @@ func (app *Application) publicURL(file io.Reader, extension string) string {
return filename
}
func (app *Application) createTokenHandler(w http.ResponseWriter, r *http.Request) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"exp": time.Now().Add(time.Hour * 2).Unix(),
})
tokenString, err := token.SignedString([]byte(app.key))
if err != nil {
http.Error(w, "Error generating token", http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "%s", tokenString)
}

View File

@ -9,8 +9,6 @@ import (
"io"
"net/http"
"os"
"github.com/golang-jwt/jwt/v5"
)
type FileInfo struct {
@ -29,31 +27,7 @@ type TemplateData struct {
}
func CheckAuth(r *http.Request, key string) bool {
receivedKey := r.Header.Get("X-Auth")
if receivedKey == key {
return true
} else if err := validateToken(receivedKey, key); err == nil {
return true
}
return false
}
func validateToken(tokenString, key string) error {
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
return []byte(key), nil
})
if err != nil {
return err
}
if _, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
return nil
} else {
return fmt.Errorf("invalid token")
}
return r.Header.Get("X-Auth") == key
}
func FormatFileSize(size int64) string {