From 6cea6262b82b5f61a41aec6bd620124ddbd3beb3 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:08:02 -0800 Subject: [PATCH 01/17] init git ignore --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73fab07 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb From 8223dd497334179c65e08d26ffe9159100d6b739 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:11:16 -0800 Subject: [PATCH 02/17] export port 8080 in dockerfile --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 21e31e9..3e10f7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,4 +30,7 @@ COPY --from=build \ /app/target/release/microbin \ /usr/bin/microbin +# Expose webport used for the webserver to the docker runtime +EXPOSE 8080 + ENTRYPOINT ["microbin"] \ No newline at end of file From 1e8b17bb8935b7d0ec1c4cef9d3a34d355a18629 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:37:26 -0800 Subject: [PATCH 03/17] add copy button to viewer --- templates/pasta.html | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/templates/pasta.html b/templates/pasta.html index 879c948..adf52cb 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -16,13 +16,31 @@ {{pasta.id_as_animals()}}
-
- {% if args.highlightsyntax %} -
{{pasta.content_syntax_highlighted()}}
- {%- else %} -
{{pasta.content_not_highlighted()}}
- {%- endif %} +
+ +
+ {% if args.highlightsyntax %} +
{{pasta.content_syntax_highlighted()}}
+ {%- else %} +
{{pasta.content_not_highlighted()}}
+ {%- endif %} +
+ + + {% include "footer.html" %} From cc504f781e34570aeecb88ec7c6fdfb9a60c3be0 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:51:52 -0800 Subject: [PATCH 04/17] add favicon resource --- templates/favicon.svg | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 templates/favicon.svg diff --git a/templates/favicon.svg b/templates/favicon.svg new file mode 100644 index 0000000..f65dd39 --- /dev/null +++ b/templates/favicon.svg @@ -0,0 +1,3 @@ + + + From ef5d07392b19bb17a1f331b16e357bd13e2f72ba Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 21:52:08 -0800 Subject: [PATCH 05/17] add in template and as static resource --- src/endpoints/static_resources.rs | 13 +++++++++++++ templates/header.html | 1 + 2 files changed, 14 insertions(+) diff --git a/src/endpoints/static_resources.rs b/src/endpoints/static_resources.rs index 9a5318e..728d617 100644 --- a/src/endpoints/static_resources.rs +++ b/src/endpoints/static_resources.rs @@ -8,6 +8,12 @@ struct WaterCSS<'a> { _marker: PhantomData<&'a ()>, } +#[derive(Template)] +#[template(path = "favicon.svg", escape = "none")] +struct Favicon<'a> { + _marker: PhantomData<&'a ()>, +} + #[get("/static/{resource}")] pub async fn static_resources(resource_id: web::Path) -> HttpResponse { match resource_id.into_inner().as_str() { @@ -18,6 +24,13 @@ pub async fn static_resources(resource_id: web::Path) -> HttpResponse { .render() .unwrap(), ), + "favicon.svg" => HttpResponse::Ok().content_type("image/svg+xml").body( + Favicon { + _marker: Default::default(), + } + .render() + .unwrap(), + ), _ => HttpResponse::NotFound().content_type("text/html").finish(), } } diff --git a/templates/header.html b/templates/header.html index 37d2de0..46bb7dc 100644 --- a/templates/header.html +++ b/templates/header.html @@ -9,6 +9,7 @@ + {% if !args.pure_html %} {%- endif %} From e17b26994f56b251057ede5ed483fe70489eaaae Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 22:10:43 -0800 Subject: [PATCH 06/17] add cli args to disable file upload --- src/args.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/args.rs b/src/args.rs index 577fa0f..1472391 100644 --- a/src/args.rs +++ b/src/args.rs @@ -59,4 +59,7 @@ pub struct Args { #[clap(long, env="MICROBIN_WIDE")] pub wide: bool, + + #[clap(short, long, env="MICROBIN_NO_FILE_UPLOAD")] + pub no_file_upload: bool, } \ No newline at end of file From fc3998243bdd3fa0725ed3a854ebe39034b3c15b Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 22:11:03 -0800 Subject: [PATCH 07/17] ignore file processing if no_file_upload is true --- src/endpoints/create.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/endpoints/create.rs b/src/endpoints/create.rs index 8c8b1a3..40efa41 100644 --- a/src/endpoints/create.rs +++ b/src/endpoints/create.rs @@ -106,6 +106,10 @@ pub async fn create( continue; } "file" => { + if ARGS.no_file_upload { + continue; + } + let path = field.content_disposition().get_filename(); let path = match path { From 82c30ce6cd16843a0d1e75f25664245a6635f7a2 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 22:11:25 -0800 Subject: [PATCH 08/17] conditionally render file upload --- templates/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/index.html b/templates/index.html index e1c4ef7..943de85 100644 --- a/templates/index.html +++ b/templates/index.html @@ -59,11 +59,13 @@ {%- endif %} + {% if !args.no_file_upload %}

+ {% endif %}

From 0b5dea5dd1510cff4d1652be29f575c4bd70e948 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 30 Sep 2022 22:12:24 -0800 Subject: [PATCH 09/17] add flag to docs --- README.MD | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.MD b/README.MD index 18006f6..b64e4c4 100644 --- a/README.MD +++ b/README.MD @@ -11,8 +11,8 @@ MicroBin is a super tiny, feature rich, configurable, self-contained and self-hosted paste bin web application. It is very easy to set up and use, and will only require a few megabytes of memory and disk storage. It takes only a couple minutes to set it up, why not give it a try now? [![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/szabodanika/microbin) - -Or install from Cargo: + +Or install from Cargo: `cargo install microbin` @@ -37,7 +37,7 @@ And run with your custom configuration: - Automatic dark mode (follows system preferences) - Very little CSS and absolutely no JS (see [water.css](https://github.com/kognise/water.css)) - Most of the above can be toggled on and off! - + ## 1 Usage ### What is a "pasta" anyway? @@ -222,7 +222,7 @@ server { listen 443 ssl; # managed by Certbot server_name microbin.myserver.com; - + location / { # Make sure to change the port if you are not running MicroBin at 8080! proxy_pass http://127.0.0.1:8080$request_uri; @@ -234,7 +234,7 @@ server { # Limit content size - I have 1GB because my MicroBin server is private, no one else will use it. client_max_body_size 1024M; - + ssl_certificate /etc/letsencrypt/live/microbin.myserver.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/microbin.myserver.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot @@ -329,3 +329,7 @@ Displays your MicroBin's version information. ### --wide Changes the maximum width of the UI from 720 pixels to 1080 pixels. + +### --no-file-upload + +Disables and hides the file upload option in the UI. \ No newline at end of file From c39b77823461dba7f47debc6fba885069cc3735b Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 1 Oct 2022 20:50:05 -0800 Subject: [PATCH 10/17] properly escape content --- src/pasta.rs | 4 ++++ templates/pasta.html | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pasta.rs b/src/pasta.rs index 3a54070..a728211 100644 --- a/src/pasta.rs +++ b/src/pasta.rs @@ -80,6 +80,10 @@ impl Pasta { pub fn content_not_highlighted(&self) -> String { html_highlight(&self.content, "txt") } + + pub fn content_escaped(&self) -> String { + self.content.replace("`", "\\`").replace("$", "\\$") + } } impl fmt::Display for Pasta { diff --git a/templates/pasta.html b/templates/pasta.html index adf52cb..587619c 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -33,7 +33,7 @@ @@ -79,8 +81,8 @@ code-line::before { background: transparent; top: 0; right: 0; - padding: 8px; - margin: 5px; + padding: 3px; + margin: 3px; } From e031ea0e9510bb3bd281d1c3b62fce7349aab3d4 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 22 Oct 2022 10:30:16 -0800 Subject: [PATCH 15/17] use a tag instead of button --- templates/pasta.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/templates/pasta.html b/templates/pasta.html index 1198e30..540011e 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -17,9 +17,9 @@
- +
{% if args.highlightsyntax %}
{{pasta.content_syntax_highlighted()}}
@@ -83,6 +83,7 @@ code-line::before { right: 0; padding: 3px; margin: 3px; + cursor: pointer; } From fd8a66bcbcc9c4d992d35d60705694e3be0dfb26 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 22 Oct 2022 10:34:39 -0800 Subject: [PATCH 16/17] use proper semantics for a tag as button --- templates/pasta.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/pasta.html b/templates/pasta.html index 540011e..388c8a6 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -17,7 +17,7 @@

- + Copy
From b1ccb43855080bc21bfec2f96daf8f5a44973271 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 22 Oct 2022 10:37:43 -0800 Subject: [PATCH 17/17] remove hash --- templates/pasta.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/pasta.html b/templates/pasta.html index 388c8a6..6e069ac 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -17,7 +17,7 @@