diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64fccb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# 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 + +pasta_data/* \ No newline at end of file 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 diff --git a/README.MD b/README.MD index b24f7a6..164ea11 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 @@ -259,7 +259,7 @@ Require password for HTTP Basic Authentication when visiting the service. Will n Enables editable pastas. You will still be able to make finalised pastas but there will be an extra checkbox to make your new pasta editable from the pasta list or the pasta view page. -### --footer_text [TEXT] +### --footer-text [TEXT] Replaces the default footer text with your own. If you want to hide the footer, use --hide-footer instead. @@ -386,4 +386,8 @@ example.com { reverse_proxy http://127.0.0.1:31333 } } -``` \ No newline at end of file +``` + +### --no-file-upload + +Disables and hides the file upload option in the UI. diff --git a/src/args.rs b/src/args.rs index ac5b525..e4029d4 100644 --- a/src/args.rs +++ b/src/args.rs @@ -65,6 +65,9 @@ pub struct Args { #[clap(long, env="MICROBIN_WIDE")] pub wide: bool, + + #[clap(short, long, env="MICROBIN_NO_FILE_UPLOAD")] + pub no_file_upload: bool, } #[derive(Debug, Clone)] @@ -83,4 +86,3 @@ impl FromStr for PublicUrl { let uri = s.strip_suffix('/').unwrap_or(s).to_owned(); Ok(PublicUrl(uri)) } -} \ No newline at end of file diff --git a/src/endpoints/create.rs b/src/endpoints/create.rs index fe39c94..7b6ca6d 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 { 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/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/favicon.svg b/templates/favicon.svg new file mode 100644 index 0000000..9a306c0 --- /dev/null +++ b/templates/favicon.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/templates/header.html b/templates/header.html index 96729da..bb9c69a 100644 --- a/templates/header.html +++ b/templates/header.html @@ -9,6 +9,7 @@ + {% if !args.pure_html %} {%- endif %} 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 %}
diff --git a/templates/pasta.html b/templates/pasta.html index 9514702..4238a57 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -16,13 +16,33 @@ {{pasta.id_as_animals()}}
-
- {% if args.highlightsyntax %} -
{{pasta.content_syntax_highlighted()}}
- {%- else %} -
{{pasta.content_not_highlighted()}}
- {%- endif %} +
+ + Copy + +
+ {% if args.highlightsyntax %} +
{{pasta.content_syntax_highlighted()}}
+ {%- else %} +
{{pasta.content_not_highlighted()}}
+ {%- endif %} +
+ + + {% include "footer.html" %}