szabodanika / microbin Goto Github PK
View Code? Open in Web Editor NEWA secure, configurable file-sharing and URL shortening web app written in Rust.
Home Page: https://microbin.eu
License: BSD 3-Clause "New" or "Revised" License
A secure, configurable file-sharing and URL shortening web app written in Rust.
Home Page: https://microbin.eu
License: BSD 3-Clause "New" or "Revised" License
Tracking issue for:
This function can probably be cleaned up a bit.
Something to look at later, sent by a Reddit user:
Hard disagree with the other post about the range being more readable, particularly given that those bounds were wrong anyway. :)
This will upset previous conversions, but rather than thinking about it like left-to-right decimals, you'd find the logic much simpler going right-to-left:
const BASE: usize = ANIMAL_NAMES.len();
pub fn to_animal_names(n: u64) -> String {
let mut s = String::new();
let mut n = n as usize;
while n >= BASE {
s.push_str(ANIMAL_NAMES[n % BASE]);
s.push('-');
n /= BASE;
}
s.push_str(ANIMAL_NAMES[n]);
s
}
Add option to encode URL (final URL made by microbin, not the original) as QR Code using https://docs.rs/qrcode/latest/qrcode/. It could be simply displayed and it would be extremely useful for sending data from CLI or desktop to mobile for example, if the phone does not support good OCR for reading the URL itself
Please add a image on dockerhub or github registry. For a kubernetes Setup it is really not that easy to deploy it without creating a ci pipeline.
Since the service uses only 2 or 3 colors, an option to choose custom colors would be fantastic. Purely nice to have.
To begin with, it could just be a matter of supplying the color hex codes as environment variables. A color picker in the ui is always a nice to have.
Add download attribute to anchor to force a file to download instead of opening in a new tab
Will there be an official Docker image?
If i short an URL by just simply pasting only the URL in my Pasta and opening it on a other device i just get the normal text and dont get redirected to the URL.
I am using this to store links to some websites. It will be nice if I can give a custom bookmark name instead of auto generated pasta name.
Heya @szabodanika,
Great project you have!
I understand that you're not so hot on Docker stuff currently, and there's quite a few variables that aren't available.
Would something like this be suitable for starters (I'm sure others could improve on it)?
#!/bin/bash
set -e
# Website
# https://github.com/szabodanika/microbin
# Version variables
MICROBINVER=$(microbin --version)
# Software versions
echo $MICROBINVER
# Declare Variables
PORT="${PORT:-"8080"}"
THREADS="${THREADS:-"1"}"
# Declare the string array
arrVar=()
# Add to string array if variable is true
if [ "$EDITABLE" == "true" ]
then
arrVar+=("--editable")
fi
if [ "$HIDE_FOOTER" == "true" ]
then
arrVar+=("--hide-footer")
fi
if [ "$HIGHLIGHTSYNTAX" == "true" ]
then
arrVar+=("--highlightsyntax")
fi
if [ "$PRIVATE" == "true" ]
then
arrVar+=("--private")
fi
if [ "$HIDE_FOOTER" == "true" ]
then
arrVar+=("--hide-footer")
fi
if [ "$HIDE_HEADER" == "true" ]
then
arrVar+=("--hide-header")
fi
if [ "$HIDE_LOGO" == "true" ]
then
arrVar+=("--hide-logo")
fi
if [ "$NO_LISTING" == "true" ]
then
arrVar+=("--no-listing")
fi
if [ "$PURE_HTML" == "true" ]
then
arrVar+=("--pure-html")
fi
if [ "$READ_ONLY" == "true" ]
then
arrVar+=("--readonly")
fi
if [ "$WIDE" == "true" ]
then
arrVar+=("--wide")
fi
#########################
#User Editable Variables#
#########################
if [ -v AUTH_USERNAME ]
then
arrVar+=("--auth-username $AUTH_USERNAME")
fi
if [ -v AUTH_PASSWORD ]
then
arrVar+=("--auth-password $AUTH_PASSWORD")
fi
if [ -v FOOTER_TEXT ]
then
arrVar+=("--footer_text $FOOTER_TEXT")
fi
if [ -v BIND_ADDR ]
then
arrVar+=("--bind $BIND_ADDR")
fi
# Save and define variables
printf -v str ' %s' "${arrVar[@]}" # save to variable str without printing
MICROBIN_VARS="${str:1}" # to remove the leading space
# Show defined variables
echo "Microbin starting with following variables: microbin --port $PORT --threads $THREADS $MICROBIN_VARS"
# Start Microbin
microbin --port $PORT --threads $THREADS $MICROBIN_VARS
This would give you the following variables:
Variable | Value | Result of true |
---|---|---|
EDITABLE | true false |
--editable |
HIDE_FOOTER | true false |
--hide-footer |
HIGHLIGHTSYNTAX | true false |
--highlightsyntax |
PRIVATE | true false |
--private |
HIDE_FOOTER | true false |
--hide-footer |
HIDE_HEADER | true false |
--hide-header |
HIDE_LOGO | true false |
--hide-logo |
NO_LISTING | true false |
--no-listing |
PURE_HTML | true false |
--pure-html |
READ_ONLY | true false |
--readonly |
WIDE | true false |
--wide |
AUTH_USERNAME | user value |
--auth-username uservalue |
AUTH_PASSWORD | user value |
--auth-password uservalue |
FOOTER_TEXT | user value |
--footer_text uservalue |
BIND_ADDR | user value |
--bind uservalue |
Variable | Value | Default Value |
---|---|---|
PORT | user value |
8080 |
THREADS | user value |
1 |
This way, no more needing to do commands or anything "non-standard" in Docker, and can easily be changed/added as new features come along without changing how you do things on the backend.
The best option of course, is in the backend, to import OS Variables and use them as required, but this should be a suitable workaround for now.
I can also tweak the dockerfile to be more in-line with buildkit, with better layer caching.
I'd be happy to raise a PR if you'd like?
After send request with curl every 15 second, I get this error and server get down after that
thread 'actix-rt|system:0|arbiter:0' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 2697, error_len: None }', src/endpoints/create.rs:93:69
note: run with `RUST_BACKTRACE=1` environment variable to display a backtracethread 'actix-rt|system:0|arbiter:0' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 2697, error_len: None }', src/endpoints/create.rs:93:69
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I should restart container, any idea to solve the problem?
Hi again
It would be great if you could attach the binaires for microbin to the release page like this
https://github.com/sigoden/dufs/releases/tag/v0.29.0
That is a Rust project as well so you can explore that repo and see how they're able to do this with GitHub workflows
something went wrong on building the docker image. could someone check. thanks.
Currently the pasta page shows the name of the attached file (if there is one) but I think it would be nice if it showed the size of the file as well
I just created a Docker container on my Synoloy NAS and used:
volumes:
- ./microbin-data:/usr/local/bin/pasta_data
But after examining the container itself I noticed the folder should be:
/app/pasta_data
Or at least /usr/local/bin/pasta_data
is empty for me and /app/pasta_data
has the database.json file etc.
As the title says. If it is not implemented yet, how else can I change the default behavior?
My feature request is a very easy to install version of MicroBin on the Unraid Community Apps.
I tried to do it myself but I have very little knowledge with Docker, Docker Hub or how to officially add an app to the Unraid CA:
I clicked on ADD CONTAINER
in the Unraid docker GUI and added the following:
Name: microbin
Repository: solarft/microbin
I added a new port:
WebUI:
Container Port: 8080
Host Port: e.g. 7123
I added a new path:
Data Path:
Container Path: /usr/local/bin/pasta_data
Host Path: /mnt/user/appdata/microbin/data/
As you can tell from the screenshot, basic functionality works and I can access, create and save new pasta in my local network.
I don't know if solarft/microbin
is the official MicroBin docker hub repository, there were about 4 different ones and I tried them until one worked.
Also I have no idea how to pass command line arguments like --highlightsyntax
. I tried many things but none of them worked.
I've done what I can and failed, maybe someone else is able to fulfill this feature request.
Thank you!
I cannot seem to figure out how to pass a string to these arguments.
For context, I am trying to pass these arguments in the docker compose like so:
command: ["microbin", "--highlightsyntax", "--editable", "--hide-footer", "--title 'newtitle'"]
Tried different combinations such as
title:'new'
title new
title 'new'
nothing seem to be working. I have a feeling I am doing something dumb. Appreciate your help.
An option to allow or disallow different filetypes. I don't want to allow upload of binaries or similar. I would only allow textbased.
If not possible the issue to completly disable file upload as in #67
Would be nice to have 3 options:
So you can manually change to dark or light mode if you want.
I believe automatic is default now and gives you a dark theme if you're using a dark mode on your machine/phone.
A pasta set to expire after say, 24 hours does get deleted from the UI as well as the underlying directory.
However if we force "Remove" from pasta list, then the file remains in the host directory. I am currently running a small script to clear them every 24 hours or so, but its not ideal.
When we select "Remove" from UI, it is being cleared from the database.json file. but it should also clear data from directory.
When I reboot the machine, I have to manually start microbin. Like linux, can we have a way to start microbin automatically on reboot using windows service.
Right now, if you create a URL redirection pasta, and you don't copy the link from the pastalist, there's no obvious way to use the redirect feature.
I propose adding a read-only text box with the /url/ endpoint in a copyable format, perhaps to the right of the Remove button or between the Raw/Remove buttons and the content. Then when redirected to the /pasta/ endpoint when creating it, you will be able to copy the /url/ endpoint to send off. :)
This code get called immediately when the page redirect to the newly created pasta
and the check at line 394 will always be true for pasta with expiration of "never"
Lines 392 to 402 in 9e4940e
this should fix it and do one less comparison
pastas.retain(|p| {
// expiration is `never` or not reached
if p.expiration == 0 || p.expiration > timenow {
// keep
true
} else {
// remove the file itself
fs::remove_file(format!("./pasta_data/{}/{}", p.id_as_animals(), p.file));
// and remove the containing directory
fs::remove_dir(format!("./pasta_data/{}/", p.id_as_animals()));
// remove
false
}
});
The software should come with built-in user manual, either with the installation or as a static page.
When using the following CLI argument -V
or --version
in docker the container won't (re)start.
It keeps starting and than stops.
Other arguments like --hide-footer
and --private
do work.
Currently the newly created pasta name only shows up within the url. For people using the service on mobile devices, it might not be easy to view. Hence it would be good to add pasta name to the main page once its created.
When the URL/identifier for a private, non-expiring, pasta is forgotten, the pasta may remain forever with nobody who can delete it except for some administrator or imaginary GC mechanism within microbin that has access to the underlying data files. This can result in endless garbage accumulation.
For this problem, perhaps there can be an administrative tool (e.g. program) to list the URLs/identifiers for pastas that meet certain criteria, optionally deleting them. For example, someone could be interested in private pastas that have not been accessed in the past n days. Potentially problematic concurrent access to the underlying data files by microbin and this tool needs to be considered.
Alternatively, there could be a switch to disallow non-expiring, private, pastas.
Add ability to upload a file as a pasta, on its own or accompanied with a text message.
Maybe create a brand new pasta page that shows a download button for the file + the message, while the raw path would just download the file.
Currently water.css is accessed from a static folder next to the executable. This makes setup a bit annoying, it would be so much better if the executable could be used on its own and a single file. Either an advanced method should be used to include this static folder in the binary or using Askama a template could be dedicated to it.
not a major issue, but for just sharing links (over copy/paste) I'd rather it be as short as possible, as the animal names can get pretty long for their relative low density of information
I'm not sure if this is so useful as I think it would be, however adding tags would make it easier to organize and find pastas more easily once we have a bunch of them. Let me know what you think!
Hi ππΌ
I am building a rootless Docker container for microbin and there doesn't seem to be a arg to set where the pastes or configuration is stored and appears to just be stored in the same dir as microbin binary.
Lines 66 to 72 in f55a5eb
Logs in the Docker image I am building:
Couldn't create data directory ./pasta_data/public/: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }
I would be great if you could add a arg called --config-dir
and --paste-dir
which would point to there the respected paths
e.g.
microbin --config-dir /config --paste-dir /data
/config
would contain the database.json
and microbin.conf
/data
would contain the pastesIt would be nice to add automatic code detection so you donΒ΄t have to choose from the dropdown menu what language it is.
Error message: microbin: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by microbin)
This issue is happening after the latest code merge on July 25. Was never an issue before
I would like to be able to disable the file upload option in my instance, it would be great if there was a flag to disable it. Someting like --no-fileupload
Add option to show image on pasta page if the file type is displayable
Heya,
Great project you have!
I understand that you're not so hot on Docker stuff currently, and there's quite a few variables that aren't available.
Would something like this be suitable for starters (I'm sure others could improve on it)?
#!/bin/bash
set -e
# Website
# https://github.com/szabodanika/microbin
# Version variables
MICROBINVER=$(microbin --version)
# Software versions
echo $MICROBINVER
# Declare Variables
PORT="${PORT:-"8080"}"
THREADS="${THREADS:-"1"}"
# Declare the string array
arrVar=()
# Add to string array if variable is true
if [ "$EDITABLE" == "true" ]
then
arrVar+=("--editable")
fi
if [ "$HIDE_FOOTER" == "true" ]
then
arrVar+=("--hide-footer")
fi
if [ "$HIGHLIGHTSYNTAX" == "true" ]
then
arrVar+=("--highlightsyntax")
fi
if [ "$PRIVATE" == "true" ]
then
arrVar+=("--private")
fi
if [ "$HIDE_FOOTER" == "true" ]
then
arrVar+=("--hide-footer")
fi
if [ "$HIDE_HEADER" == "true" ]
then
arrVar+=("--hide-header")
fi
if [ "$HIDE_LOGO" == "true" ]
then
arrVar+=("--hide-logo")
fi
if [ "$NO_LISTING" == "true" ]
then
arrVar+=("--no-listing")
fi
if [ "$PURE_HTML" == "true" ]
then
arrVar+=("--pure-html")
fi
if [ "$READ_ONLY" == "true" ]
then
arrVar+=("--readonly")
fi
if [ "$WIDE" == "true" ]
then
arrVar+=("--wide")
fi
#########################
#User Editable Variables#
#########################
if [ -v AUTH_USERNAME ]
then
arrVar+=("--auth-username $AUTH_USERNAME")
fi
if [ -v AUTH_PASSWORD ]
then
arrVar+=("--auth-password $AUTH_PASSWORD")
fi
if [ -v FOOTER_TEXT ]
then
arrVar+=("--footer_text $FOOTER_TEXT")
fi
if [ -v BIND_ADDR ]
then
arrVar+=("--bind $BIND_ADDR")
fi
# Save and define variables
printf -v str ' %s' "${arrVar[@]}" # save to variable str without printing
MICROBIN_VARS="${str:1}" # to remove the leading space
# Show defined variables
echo "Microbin starting with following variables: microbin --port $PORT --threads $THREADS $MICROBIN_VARS"
# Start Microbin
microbin --port $PORT --threads $THREADS $MICROBIN_VARS
This would give you the following variables:
Variable | Value |
---|---|
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE | true false |
EDITABLE="${EDITABLE:-}"
PORT="${PORT:-"8080"}"
THREADS="${THREADS:-"1"}"
Would be great if we could set the default expiration time ourselves.
By default it's set to 24 hours. But for instance I would like to set the default to 1 min.
Hello!
Project looks great! I'm building a Kubernetes one-click installer for microbin for https://pibox.io - but ran into an issue. When building the image for ARM64 (or any arch), I fail to copy /usr/src/microbin/static
https://github.com/szabodanika/microbin/blob/master/Dockerfile#L23
It looks like that directory has been renamed "templates" in 4cc7377
Is the fix as easy as changing the line to:
COPY --from=builder /usr/src/microbin/templates /usr/local/bin/templates
I'll test this now, but figured you might want to know about it! β€οΈ
Currently all pastas are stored in the memory. Can we save them on the disk in either a tiny database or simply in files? Storing everything in the memory could be bad if the service is running on a tiny VM for example with limited RAM, or if the pastas are important and the user wants to retain them even if the service is restarted.
Hi,
thanks for your great piece of software! I just faced a small bug. I wanted to write a small script to create pastas from stdin in the terminal and for that I wanted to use curl. More specifically, I wanted to follow this example from microbin's help page:
Simple text Pasta:
curl -d "expiration=10min&content=This is a test pasta" -X POST https://microbin.myserver.com/create
However, it seems that the /create
endpoint is not existing. I just get HTTP 404
as response. Am I doing something wrong or is this maybe a bug?
Cheers
It would be great to have markdown support added. In fact we can even have syntax highlighting within a markdown text by specifying what syntax the code belongs to. I am not sure if that is the default implementation of markdown, but I know obsidian does it that way.
e.g.
At the moment there is no favicon available for the website, at least in the Docker image.
Would be nice to have the MicroBin logo as favicon.
Ran microbin in my Documents folder (not as sudo).
Program crashed when I attempted to create new text pasta, at which point I killed the process.
2022-06-04T13:40:39 [INFO] - MicroBin starting on http://127.0.0.1:8080
2022-06-04T13:40:39 [INFO] - Starting 1 workers
2022-06-04T13:40:39 [INFO] - Actix runtime found; starting in Actix runtime
2022-06-04T13:40:48 [INFO] - 127.0.0.1 "GET / HTTP/1.1" 302 2615 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0" 0.000127
2022-06-04T13:40:48 [INFO] - 127.0.0.1 "GET /static/water.css HTTP/1.1" 302 22668 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0" 0.000121
2022-06-04T13:40:48 [INFO] - 127.0.0.1 "GET /favicon.ico HTTP/1.1" 302 1138 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0" 0.000093
2022-06-04T13:40:52 [INFO] - 127.0.0.1 "POST /upload HTTP/1.1" 302 0 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0" 0.000682
56942
thread 'actix-rt|system:0|arbiter:0' panicked at 'Failed to delete file no-file!: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/util/misc.rs:26:18
note: run with RUST_BACKTRACE=1
environment variable to display a backtrace
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
thread 'actix-rt|system:0|arbiter:0' panicked at 'called Result::unwrap()
on an Err
value: PoisonError { .. }', src/endpoints/pasta.rs:20:41
^C2022-06-04T13:41:06 [INFO] - SIGINT received; starting forced shutdown
Received this error twice (not back to back).
I am unable to recreate this error no matter what I try.
(not sure if this info is needed, but here it is anyway)
Mac M1
macOS Monterey v12.3.1
Firefox 101.0 (64-Bit)
Microbin was installed via "cargo install --git https://github.com/szabodanika/microbin"
any pastas longer than a few K characters are inconsistently saved, sometimes they'll be cut off to a much shorter length, sometimes it'll save correctly, nothing appears wrong in microbins logs and there are no other issues (apart from the copy button also failing on long pastas nevermind, that just seems to be broken)
Hi there!
Thanks for publishing and maintaining this cool crate! I'm still testing it out but so far, it looks fantastic.
I was wondering if there was any interest in adding sentry logging with the sentry-actix crate? I would probably use it so I'd be happy to write a PR for that. But if that isn't of much interest, I can just keep it on my fork.
Thanks
Hi, it would be nice if there would be a copy button in the upper right corner for simple copy the pasta.
Hello π
I run a security community that finds and fixes vulnerabilities in OSS. A researcher (@ablGH) has found a potential issue, which I would be eager to share with you.
Could you add a SECURITY.md
file with an e-mail address for me to send further details to? GitHub recommends a security policy to ensure issues are responsibly disclosed, and it would help direct researchers in the future.
Looking forward to hearing from you π
(cc @huntr-helper)
Currently the status of pasta list is either open (for everyone that has access to see and remove pastas if private pasta is not enabled) or closed (nobody can see anything at all).
I'm hoping for a mode that only the pasta list requires authentication. Or, if private pasta is enabled, one can see all the private pastas after authentication. Basically this sets an "administrator" role who can manage all the pastas.
I understand that microbin is not meant for public usage. But I think it will be useful if someone wants to manage all the pastas without turning on/off list and private and restarting the instance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.