diff --git a/.github/workflows/FUNDING.yml b/.github/workflows/FUNDING.yml new file mode 100644 index 0000000..8fc887f --- /dev/null +++ b/.github/workflows/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +github: szabodanika +ko_fi: dani_sz diff --git a/Cargo.lock b/Cargo.lock index 5ad8089..21101c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -401,6 +401,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bit_field" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" + [[package]] name = "bitflags" version = "1.3.2" @@ -455,6 +461,18 @@ version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +[[package]] +name = "bytemuck" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.2.1" @@ -558,6 +576,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "convert_case" version = "0.4.0" @@ -599,6 +623,55 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -676,6 +749,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + [[package]] name = "encoding_rs" version = "0.8.31" @@ -698,6 +777,21 @@ dependencies = [ "termcolor", ] +[[package]] +name = "exr" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb5f255b5980bb0c8cf676b675d1a99be40f316881444f44e0462eaf5df5ded" +dependencies = [ + "bit_field", + "flume", + "half", + "lebe", + "miniz_oxide 0.6.2", + "smallvec", + "threadpool", +] + [[package]] name = "flate2" version = "1.0.24" @@ -705,7 +799,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.5.4", +] + +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spin", ] [[package]] @@ -835,8 +942,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "gif" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" +dependencies = [ + "color_quant", + "weezl", ] [[package]] @@ -858,6 +977,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad6a9459c9c30b177b925162351f97e7d967c7ea8bab3b8352805327daf45554" +dependencies = [ + "crunchy", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -879,6 +1007,15 @@ dependencies = [ "libc", ] +[[package]] +name = "html-escape" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e7479fa1ef38eb49fb6a42c426be515df2d063f06cb8efd3e50af073dbc26c" +dependencies = [ + "utf8-width", +] + [[package]] name = "http" version = "0.2.8" @@ -954,6 +1091,25 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "image" +version = "0.24.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd8e4fb07cf672b1642304e731ef8a6a4c7891d67bb4fd4f5ce58cd6ed86803c" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "exr", + "gif", + "jpeg-decoder", + "num-rational", + "num-traits", + "png", + "scoped_threadpool", + "tiff", +] + [[package]] name = "indexmap" version = "1.9.1" @@ -979,6 +1135,15 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-decoder" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b" +dependencies = [ + "rayon", +] + [[package]] name = "js-sys" version = "0.3.60" @@ -1000,6 +1165,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + [[package]] name = "lexical-core" version = "0.7.6" @@ -1095,9 +1266,18 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "microbin" -version = "1.1.0" +version = "1.2.0" dependencies = [ "actix-files", "actix-multipart", @@ -1113,6 +1293,7 @@ dependencies = [ "lazy_static", "linkify", "log", + "qrcode-generator", "rand", "sanitize-filename", "serde", @@ -1145,6 +1326,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.5" @@ -1157,6 +1347,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom", +] + [[package]] name = "nom" version = "6.1.2" @@ -1180,6 +1379,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -1277,6 +1487,26 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1309,6 +1539,18 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "png" +version = "0.17.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f0e7f4c94ec26ff209cee506314212639d6c91b80afb82984819fafce9df01c" +dependencies = [ + "bitflags", + "crc32fast", + "flate2", + "miniz_oxide 0.5.4", +] + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -1348,6 +1590,23 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "qrcode-generator" +version = "4.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501c33c9127afb867693646b38817bf63a9a756d4b66aefbc5c0d7e5e8c3125a" +dependencies = [ + "html-escape", + "image", + "qrcodegen", +] + +[[package]] +name = "qrcodegen" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4339fc7a1021c9c1621d87f5e3505f2805c8c105420ba2f2a4df86814590c142" + [[package]] name = "quote" version = "1.0.21" @@ -1393,6 +1652,30 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -1459,6 +1742,12 @@ dependencies = [ "regex", ] +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + [[package]] name = "scopeguard" version = "1.1.0" @@ -1565,6 +1854,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6002a767bff9e83f8eeecf883ecb8011875a21ae8da43bffb817a57e78cc09" +dependencies = [ + "lock_api", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -1652,6 +1950,26 @@ dependencies = [ "syn", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + +[[package]] +name = "tiff" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7259662e32d1e219321eb309d5f9d898b779769d81b76e762c07c8e5d38fcb65" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.1.44" @@ -1838,6 +2156,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8-width" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" + [[package]] name = "version_check" version = "0.9.4" @@ -1921,6 +2245,12 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 4b0821e..19a334a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "microbin" -version = "1.1.0" +version = "1.2.0" edition = "2021" authors = ["Daniel Szabo "] license = "BSD-3-Clause" @@ -31,6 +31,7 @@ env_logger = "0.9.0" actix-web-httpauth = "0.6.0" lazy_static = "1.4.0" syntect = "5.0" +qrcode-generator = "4.1.6" [profile.release] lto = true diff --git a/README.MD b/README.MD index fee6476..610cad0 100644 --- a/README.MD +++ b/README.MD @@ -255,6 +255,24 @@ Require username for HTTP Basic Authentication when visiting the service. If `-- Require password for HTTP Basic Authentication when visiting the service. Will not have any affect unless `--auth-username` is also set. If `--auth-username` is set but `--auth-password ` is not, just leave the password field empty when logging in. You can also just go to https://username:password@yourserver.net or https://username@yourserver.net if password is not set instead of typing into the password prompt. +### -b, --bind [ADDRESS] + +Default value: `0.0.0.0` + +Sets the bind address for the server will be listening on. Both ipv4 and ipv6 are supported. + +### --default-expiry [EXPIRY] + +Default value: `24hour` + +Selects the default expiry time in the dropdown list. + +Options: `1min`, `10min`, `1hour`, `24hour` and `1week` + +### --no-eternal-pasta + +Disables the option to create never expiring pastas. + ### --editable 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. @@ -293,21 +311,26 @@ Default value: 8080 Sets the port for the server will be listening on. +### --public-path [PUBLIC_PATH] -### -b, --bind [ADDRESS] +Add the given public path prefix to all urls. -Default value: 0.0.0.0 +The URL copy feature will only copy the entire URL if this is provided. Otherwise only the path (eg. `/url/dog-cat-bat`) will be copied to your clipboard! -Sets the bind address for the server will be listening on. Both ipv4 and ipv6 are supported. +This allows you to host MicroBin behind a reverse proxy on a subpath. +Note that MicroBin itself still expects all routes to be as without this option, and thus is unsuited +if you are running MicroBin directly. -### --private - -Enables private pastas. Adds a new checkbox to make your pasta private, which then won't show up on the pastalist page. With the URL to your pasta, it will still be accessible. +Example: `--public-path https://myserver.com` or `--public-path http://localhost:8080` ### --pure-html Disables main CSS styling, just uses a few in-line stylings for the layout. With this option you will lose dark-mode support. +### --private + +Enables private pastas. Adds a new checkbox to make your pasta private, which then won't show up on the pastalist page. With the URL to your pasta, it will still be accessible. + ### --readonly Disables adding/editing/removing pastas entirely. @@ -330,18 +353,6 @@ Displays your MicroBin's version information. Changes the maximum width of the UI from 720 pixels to 1080 pixels. -### --public-path [PUBLIC_PATH] - -Add the given public path prefix to all urls. - -The URL copy feature will only copy the entire URL if this is provided. Otherwise only the path (eg. `/url/dog-cat-bat`) will be copied to your clipboard! - -This allows you to host MicroBin behind a reverse proxy on a subpath. -Note that MicroBin itself still expects all routes to be as without this option, and thus is unsuited -if you are running MicroBin directly. - -Example: `--public-path https://myserver.com` or `--public-path http://localhost:8080` - #### Example Usage (caddy) An example of running MicroBin behind the reverse proxy `caddy` on the path `/paste` (using systemd) diff --git a/SECURITY.md b/SECURITY.md index f86af39..695fc0f 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,19 +1,12 @@ # Security Policy -## Supported Versions +## Version Support -Use this section to tell people about which versions of your project are -currently being supported with security updates. - -| Version | Supported | -| ------- | ------------------ | -| 1.1.* | :white_check_mark: | -| < 1.1.0 | :x: | +Currently we only have capacity to support the latest version of MicroBin. We recommend that you always update to the newest one and check our pages regularly for announcements. ## Reporting a Vulnerability -Security vulnerabilities can be reported directly to -the developer/maintainer at d@szab.eu. +Security vulnerabilities can be reported directly to the developer/maintainer at d@szab.eu. Sensitive information may be GPG encrypted with my public key available at https://szab.eu/assets/files/daniel-szabo-pub.asc. diff --git a/src/args.rs b/src/args.rs index b570cb8..3c61cbd 100644 --- a/src/args.rs +++ b/src/args.rs @@ -63,11 +63,32 @@ pub struct Args { #[clap(short, long, env = "MICROBIN_THREADS", default_value_t = 1)] pub threads: u8, + #[clap(short, long, env = "MICROBIN_GC_DAYS", default_value_t = 90)] + pub gc_days: u16, + + #[clap(long, env = "MICROBIN_ENABLE_BURN_AFTER")] + pub enable_burn_after: bool, + + #[clap(short, long, env = "MICROBIN_DEFAULT_BURN_AFTER", default_value_t = 0)] + pub default_burn_after: u16, + #[clap(long, env = "MICROBIN_WIDE")] pub wide: bool, + #[clap(long, env = "MICROBIN_QR")] + pub qr: bool, + + #[clap(long, env = "MICROBIN_NO_ETERNAL_PASTA")] + pub no_eternal_pasta: bool, + + #[clap(long, env = "MICROBIN_DEFAULT_EXPIRY", default_value = "24hour")] + pub default_expiry: String, + #[clap(short, long, env = "MICROBIN_NO_FILE_UPLOAD")] pub no_file_upload: bool, + + #[clap(long, env = "MICROBIN_CUSTOM_CSS")] + pub custom_css: Option, } #[derive(Debug, Clone)] diff --git a/src/endpoints/create.rs b/src/endpoints/create.rs index 7b6ca6d..30f463e 100644 --- a/src/endpoints/create.rs +++ b/src/endpoints/create.rs @@ -54,6 +54,9 @@ pub async fn create( private: false, editable: false, created: timenow, + read_count: 0, + burn_after_reads: 0, + last_read: timenow, pasta_type: String::from(""), expiration: 0, }; @@ -78,9 +81,34 @@ pub async fn create( "1hour" => timenow + 60 * 60, "24hour" => timenow + 60 * 60 * 24, "1week" => timenow + 60 * 60 * 24 * 7, - "never" => 0, + "never" => { + if ARGS.no_eternal_pasta { + timenow + 60 * 60 * 24 * 7 + } else { + 0 + } + } _ => { log::error!("{}", "Unexpected expiration time!"); + timenow + 60 * 60 * 24 * 7 + } + }; + } + + continue; + } + "burn_after" => { + while let Some(chunk) = field.try_next().await? { + new_pasta.burn_after_reads = match std::str::from_utf8(&chunk).unwrap() { + // give an extra read because the user will be redirected to the pasta page automatically + "1" => 2, + "10" => 10, + "100" => 100, + "1000" => 1000, + "10000" => 10000, + "0" => 0, + _ => { + log::error!("{}", "Unexpected burn after value!"); 0 } }; @@ -126,8 +154,11 @@ pub async fn create( } }; - std::fs::create_dir_all(format!("./pasta_data/public/{}", &new_pasta.id_as_animals())) - .unwrap(); + std::fs::create_dir_all(format!( + "./pasta_data/public/{}", + &new_pasta.id_as_animals() + )) + .unwrap(); let filepath = format!( "./pasta_data/public/{}/{}", @@ -158,6 +189,9 @@ pub async fn create( save_to_file(&pastas); Ok(HttpResponse::Found() - .append_header(("Location", format!("{}/pasta/{}", ARGS.public_path, to_animal_names(id)))) + .append_header(( + "Location", + format!("{}/pasta/{}", ARGS.public_path, to_animal_names(id)), + )) .finish()) } diff --git a/src/endpoints/help.rs b/src/endpoints/help.rs deleted file mode 100644 index 2ca8f38..0000000 --- a/src/endpoints/help.rs +++ /dev/null @@ -1,23 +0,0 @@ -use crate::args::{Args, ARGS}; -use actix_web::{get, HttpResponse}; -use askama::Template; -use std::marker::PhantomData; - -#[derive(Template)] -#[template(path = "help.html")] -struct Help<'a> { - args: &'a Args, - _marker: PhantomData<&'a ()>, -} - -#[get("/help")] -pub async fn help() -> HttpResponse { - HttpResponse::Ok().content_type("text/html").body( - Help { - args: &ARGS, - _marker: Default::default(), - } - .render() - .unwrap(), - ) -} diff --git a/src/endpoints/info.rs b/src/endpoints/info.rs new file mode 100644 index 0000000..bbdc4fe --- /dev/null +++ b/src/endpoints/info.rs @@ -0,0 +1,42 @@ +use crate::args::{Args, ARGS}; +use crate::pasta::Pasta; +use crate::AppState; +use actix_web::{get, web, HttpResponse}; +use askama::Template; + +#[derive(Template)] +#[template(path = "info.html")] +struct Info<'a> { + args: &'a Args, + pastas: &'a Vec, + status: &'a String, + version_string: &'a String, + message: &'a String, +} + +#[get("/info")] +pub async fn info(data: web::Data) -> HttpResponse { + // get access to the pasta collection + let mut pastas = data.pastas.lock().unwrap(); + + // todo status report more sophisticated + let mut status = "OK"; + let mut message = ""; + + if ARGS.public_path.to_string() == "" { + status = "WARNING"; + message = "Warning: No public URL set with --public-path parameter. QR code and URL Copying functions have been disabled" + } + + HttpResponse::Ok().content_type("text/html").body( + Info { + args: &ARGS, + pastas: &pastas, + status: &String::from(status), + version_string: &String::from("1.2.0-20221029"), + message: &String::from(message), + } + .render() + .unwrap(), + ) +} diff --git a/src/endpoints/pasta.rs b/src/endpoints/pasta.rs index 26ac11d..4242ab7 100644 --- a/src/endpoints/pasta.rs +++ b/src/endpoints/pasta.rs @@ -1,12 +1,14 @@ -use actix_web::{get, web, HttpResponse}; -use askama::Template; - use crate::args::{Args, ARGS}; +use crate::dbio::save_to_file; use crate::endpoints::errors::ErrorTemplate; use crate::pasta::Pasta; use crate::util::animalnumbers::to_u64; use crate::util::misc::remove_expired; use crate::AppState; +use actix_web::rt::time; +use actix_web::{get, web, HttpResponse}; +use askama::Template; +use std::time::{SystemTime, UNIX_EPOCH}; #[derive(Template)] #[template(path = "pasta.html", escape = "none")] @@ -17,27 +19,60 @@ struct PastaTemplate<'a> { #[get("/pasta/{id}")] pub async fn getpasta(data: web::Data, id: web::Path) -> HttpResponse { + // get access to the pasta collection let mut pastas = data.pastas.lock().unwrap(); + // get the u64 id from the animal names in the path let id = to_u64(&*id.into_inner()).unwrap_or(0); - println!("{}", id); - + // remove expired pastas (including this one if needed) remove_expired(&mut pastas); - for pasta in pastas.iter() { + // find the index of the pasta in the collection based on u64 id + let mut index: usize = 0; + let mut found: bool = false; + for (i, pasta) in pastas.iter().enumerate() { if pasta.id == id { - return HttpResponse::Ok().content_type("text/html").body( - PastaTemplate { - pasta: &pasta, - args: &ARGS, - } - .render() - .unwrap(), - ); + index = i; + found = true; + break; } } + if found { + // increment read count + pastas[index].read_count = pastas[index].read_count + 1; + + // save the updated read count + save_to_file(&pastas); + + // serve pasta in template + let response = HttpResponse::Ok().content_type("text/html").body( + PastaTemplate { + pasta: &pastas[index], + args: &ARGS, + } + .render() + .unwrap(), + ); + + // get current unix time in seconds + let timenow: i64 = match SystemTime::now().duration_since(UNIX_EPOCH) { + Ok(n) => n.as_secs(), + Err(_) => { + log::error!("SystemTime before UNIX EPOCH!"); + 0 + } + } as i64; + + // update last read time + pastas[index].last_read = timenow; + + return response; + } + + // otherwise + // send pasta not found error HttpResponse::Ok() .content_type("text/html") .body(ErrorTemplate { args: &ARGS }.render().unwrap()) @@ -45,26 +80,62 @@ pub async fn getpasta(data: web::Data, id: web::Path) -> HttpR #[get("/url/{id}")] pub async fn redirecturl(data: web::Data, id: web::Path) -> HttpResponse { + // get access to the pasta collection let mut pastas = data.pastas.lock().unwrap(); + // get the u64 id from the animal names in the path let id = to_u64(&*id.into_inner()).unwrap_or(0); + // remove expired pastas (including this one if needed) remove_expired(&mut pastas); - for pasta in pastas.iter() { + // find the index of the pasta in the collection based on u64 id + let mut index: usize = 0; + let mut found: bool = false; + for (i, pasta) in pastas.iter().enumerate() { if pasta.id == id { - if pasta.pasta_type == "url" { - return HttpResponse::Found() - .append_header(("Location", String::from(&pasta.content))) - .finish(); - } else { - return HttpResponse::Ok() - .content_type("text/html") - .body(ErrorTemplate { args: &ARGS }.render().unwrap()); - } + index = i; + found = true; + break; } } + if found { + // increment read count + pastas[index].read_count = pastas[index].read_count + 1; + + // save the updated read count + save_to_file(&pastas); + + // send redirect if it's a url pasta + if pastas[index].pasta_type == "url" { + let response = HttpResponse::Found() + .append_header(("Location", String::from(&pastas[index].content))) + .finish(); + + // get current unix time in seconds + let timenow: i64 = match SystemTime::now().duration_since(UNIX_EPOCH) { + Ok(n) => n.as_secs(), + Err(_) => { + log::error!("SystemTime before UNIX EPOCH!"); + 0 + } + } as i64; + + // update last read time + pastas[index].last_read = timenow; + + return response; + // send error if we're trying to open a non-url pasta as a redirect + } else { + HttpResponse::Ok() + .content_type("text/html") + .body(ErrorTemplate { args: &ARGS }.render().unwrap()); + } + } + + // otherwise + // send pasta not found error HttpResponse::Ok() .content_type("text/html") .body(ErrorTemplate { args: &ARGS }.render().unwrap()) @@ -72,17 +143,50 @@ pub async fn redirecturl(data: web::Data, id: web::Path) -> Ht #[get("/raw/{id}")] pub async fn getrawpasta(data: web::Data, id: web::Path) -> String { + // get access to the pasta collection let mut pastas = data.pastas.lock().unwrap(); + // get the u64 id from the animal names in the path let id = to_u64(&*id.into_inner()).unwrap_or(0); + // remove expired pastas (including this one if needed) remove_expired(&mut pastas); - for pasta in pastas.iter() { + // find the index of the pasta in the collection based on u64 id + let mut index: usize = 0; + let mut found: bool = false; + for (i, pasta) in pastas.iter().enumerate() { if pasta.id == id { - return pasta.content.to_owned(); + index = i; + found = true; + break; } } + if found { + // increment read count + pastas[index].read_count = pastas[index].read_count + 1; + + // get current unix time in seconds + let timenow: i64 = match SystemTime::now().duration_since(UNIX_EPOCH) { + Ok(n) => n.as_secs(), + Err(_) => { + log::error!("SystemTime before UNIX EPOCH!"); + 0 + } + } as i64; + + // update last read time + pastas[index].last_read = timenow; + + // save the updated read count + save_to_file(&pastas); + + // send raw content of pasta + return pastas[index].content.to_owned(); + } + + // otherwise + // send pasta not found error as raw text String::from("Pasta not found! :-(") } diff --git a/src/endpoints/qr.rs b/src/endpoints/qr.rs new file mode 100644 index 0000000..4d714d5 --- /dev/null +++ b/src/endpoints/qr.rs @@ -0,0 +1,34 @@ +use crate::args::{Args, ARGS}; +use crate::pasta::Pasta; +use crate::util::misc::{self, remove_expired}; +use crate::AppState; +use actix_web::{get, web, HttpResponse}; +use askama::Template; +use qrcode_generator::QrCodeEcc; +use std::time::{SystemTime, UNIX_EPOCH}; + +#[derive(Template)] +#[template(path = "qr.html", escape = "none")] +struct QRTemplate<'a> { + qr: &'a String, + args: &'a Args, +} + +#[get("/qr/{id}")] +pub async fn getqr(data: web::Data, id: web::Path) -> HttpResponse { + // find the index of the pasta in the collection based on u64 id + + let svg: String = misc::string_to_qr_svg( + format!("{}/pasta/{}", &ARGS.public_path, &*id.into_inner()).as_str(), + ); + + // serve qr code in template + HttpResponse::Ok().content_type("text/html").body( + QRTemplate { + qr: &svg, + args: &ARGS, + } + .render() + .unwrap(), + ) +} diff --git a/src/main.rs b/src/main.rs index 099a2a6..86e9322 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ extern crate core; use crate::args::ARGS; use crate::endpoints::{ - create, edit, errors, help, pasta as pasta_endpoint, pastalist, remove, static_resources, + create, edit, errors, info, pasta as pasta_endpoint, pastalist, qr, remove, static_resources, }; use crate::pasta::Pasta; use crate::util::dbio; @@ -31,9 +31,10 @@ pub mod endpoints { pub mod create; pub mod edit; pub mod errors; - pub mod help; + pub mod info; pub mod pasta; pub mod pastalist; + pub mod qr; pub mod remove; pub mod static_resources; } @@ -66,8 +67,14 @@ async fn main() -> std::io::Result<()> { match fs::create_dir_all("./pasta_data/public") { Ok(dir) => dir, Err(error) => { - log::error!("Couldn't create data directory ./pasta_data/public/: {:?}", error); - panic!("Couldn't create data directory ./pasta_data/public/: {:?}", error); + log::error!( + "Couldn't create data directory ./pasta_data/public/: {:?}", + error + ); + panic!( + "Couldn't create data directory ./pasta_data/public/: {:?}", + error + ); } }; @@ -80,13 +87,14 @@ async fn main() -> std::io::Result<()> { .app_data(data.clone()) .wrap(middleware::NormalizePath::trim()) .service(create::index) - .service(help::help) + .service(info::info) .service(pasta_endpoint::getpasta) .service(pasta_endpoint::getrawpasta) .service(pasta_endpoint::redirecturl) .service(edit::get_edit) .service(edit::post_edit) .service(static_resources::static_resources) + .service(qr::getqr) .service(actix_files::Files::new("/file", "./pasta_data/public/")) .service(web::resource("/upload").route(web::post().to(create::create))) .default_service(web::route().to(errors::not_found)) diff --git a/src/pasta.rs b/src/pasta.rs index a728211..b6e98bd 100644 --- a/src/pasta.rs +++ b/src/pasta.rs @@ -3,6 +3,7 @@ use chrono::{Datelike, Local, TimeZone, Timelike}; use serde::{Deserialize, Serialize}; use std::fmt; use std::path::Path; +use std::time::{SystemTime, UNIX_EPOCH}; use crate::util::animalnumbers::to_animal_names; use crate::util::syntaxhighlighter::html_highlight; @@ -39,6 +40,9 @@ pub struct Pasta { pub editable: bool, pub created: i64, pub expiration: i64, + pub last_read: i64, + pub read_count: u64, + pub burn_after_reads: u64, pub pasta_type: String, } @@ -73,6 +77,58 @@ impl Pasta { } } + pub fn last_read_time_ago_as_string(&self) -> String { + // get current unix time in seconds + let timenow: i64 = match SystemTime::now().duration_since(UNIX_EPOCH) { + Ok(n) => n.as_secs(), + Err(_) => { + log::error!("SystemTime before UNIX EPOCH!"); + 0 + } + } as i64; + + // get seconds since last read and convert it to days + let days = ((timenow - self.last_read) / 86400) as u16; + if days > 1 { + return format!("{} days ago", days); + }; + + // it's less than 1 day, let's do hours then + let hours = ((timenow - self.last_read) / 3600) as u16; + if hours > 1 { + return format!("{} hours ago", hours); + }; + + // it's less than 1 hour, let's do minutes then + let minutes = ((timenow - self.last_read) / 60) as u16; + if minutes > 1 { + return format!("{} minutes ago", minutes); + }; + + // it's less than 1 minute, let's do seconds then + let seconds = (timenow - self.last_read) as u16; + if seconds > 1 { + return format!("{} seconds ago", seconds); + }; + + // it's less than 1 second????? + return String::from("just now"); + } + + pub fn last_read_days_ago(&self) -> u16 { + // get current unix time in seconds + let timenow: i64 = match SystemTime::now().duration_since(UNIX_EPOCH) { + Ok(n) => n.as_secs(), + Err(_) => { + log::error!("SystemTime before UNIX EPOCH!"); + 0 + } + } as i64; + + // get seconds since last read and convert it to days + return ((timenow - self.last_read) / 86400) as u16; + } + pub fn content_syntax_highlighted(&self) -> String { html_highlight(&self.content, &self.extension) } diff --git a/src/util/misc.rs b/src/util/misc.rs index d1f4693..489b891 100644 --- a/src/util/misc.rs +++ b/src/util/misc.rs @@ -1,6 +1,8 @@ use std::time::{SystemTime, UNIX_EPOCH}; +use crate::args::ARGS; use linkify::{LinkFinder, LinkKind}; +use qrcode_generator::QrCodeEcc; use std::fs; use crate::{dbio, Pasta}; @@ -16,8 +18,16 @@ pub fn remove_expired(pastas: &mut Vec) { } as i64; pastas.retain(|p| { - // expiration is `never` or not reached - if p.expiration == 0 || p.expiration > timenow { + // keep if: + // expiration is `never` or not reached + // AND + // read count is less than burn limit, or no limit set + // AND + // has been read in the last N days where N is the arg --gc-days OR N is 0 (no GC) + if (p.expiration == 0 || p.expiration > timenow) + && (p.read_count < p.burn_after_reads || p.burn_after_reads == 0) + && (p.last_read_days_ago() < ARGS.gc_days || ARGS.gc_days == 0) + { // keep true } else { @@ -45,6 +55,10 @@ pub fn remove_expired(pastas: &mut Vec) { dbio::save_to_file(pastas); } +pub fn string_to_qr_svg(str: &str) -> String { + qrcode_generator::to_svg_to_string(str, QrCodeEcc::Low, 512, None::<&str>).unwrap() +} + pub fn is_valid_url(url: &str) -> bool { let finder = LinkFinder::new(); let spans: Vec<_> = finder.spans(url).collect(); diff --git a/templates/error.html b/templates/error.html index 6e60b7c..806229e 100644 --- a/templates/error.html +++ b/templates/error.html @@ -4,7 +4,7 @@ Not Found

- Go Home + Go Home

-{% include "footer.html" %} +{% include "footer.html" %} \ No newline at end of file diff --git a/templates/header.html b/templates/header.html index 351b3a4..d282c93 100644 --- a/templates/header.html +++ b/templates/header.html @@ -12,13 +12,18 @@ {% if !args.pure_html %} + {% if args.custom_css.as_ref().is_none() %} + {%- else %} + {%- endif %} + {%- endif %} + {% if args.wide %} - New Pasta + New + Pasta Pasta List - Help + Info
diff --git a/templates/help.html b/templates/help.html deleted file mode 100644 index abef0ce..0000000 --- a/templates/help.html +++ /dev/null @@ -1,160 +0,0 @@ -{% include "header.html" %} - - -

Welcome to MicroBin!

-

This page contains help regarding the installation, configuration and use of MicroBin. If you have questions that are not answered here, head to our GitHub repository.

-

1 Usage

-

What is a "pasta" anyway?

-

In microbin, a pasta can be:

-
    -
  • A text that you want to paste from one machine to another, eg. some code
  • -
  • A file that you want to share, eg. a video that is too large for Discord, a zip with a code project in it or an image
  • -
  • A URL redirect
  • -
-

When is MicroBin useful?

-

You can use MicroBin

-
    -
  • As a URL shortener/redirect service,
  • -
  • To send long texts to other people,
  • -
  • To send large files to other people,
  • -
  • To serve content on the web, eg. configuration files for testing, images, or any other file content using the Raw functionality,
  • -
  • To move files between your desktop and a server you access from the console,
  • -
  • As a "postbox" service where people can upload their files or texts, but they cannot see or remove what others sent you - just disable the pastalist page
  • -
  • To take notes! Simply create an editable pasta.
  • -
-

...and many other things, why not get creative?

-

Creating a Pasta

-

Navigate to the root of your server, for example https://microbin.myserver.com/. This should show you a form where you will at the very least see an expiration selector, a file attachment input, a content text field and a green save button. Depending on your configuration there miight also be a syntax highlight selector, an editable checkbox and a private ceckbox.

-

Use the expiration dropdown to choose how long you want your pasta to exist. When the selected time has expired, it will be removed from the server. The content can be any text, including plain text, code, html, even a URL. A URL is a special case, because when you open the pasta again, it will redirect you to that URL instead of showing it as a text. Entering content is optional, and so is the file attachment. If you want, you can even submit a pasta completely empty.

-

You will be redirected to the URL of the pasta, which will end with a few animal names. If you remember those animals, you can simply type them in on another machine and open your pasta elsewhere.

-

If you have editable pastas enabled and you check the editable checkbox, then later on there will be an option to change the text content of your pasta. Selecting the private checkbox will simply prevent your pasta to show up on the pasta list page, if that is enabled.

-

If you have syntax higlighting enabled, then select your language from the dropdown, or leave it as none if you just want to upload plain with no highlighting.

-

Listing Pastas

-

If you have pasta listing enabled, then there is a pasta list option in the navigation bar, which will list all the pastas on the server in two groups: regular pastas and URL redirects (pastas containing nothing but a URL). If you have private pastas enabled, they will not show up here at all.

-

From the pasta list page, you will be able to view individual pastas by clicking on their animal identifiers on the lest, view their raw contrent by clicking on the Raw button, remove them, and if you have editable pastas enabled, then open them in edit view.

-

Use MicroBin from the console with cURL

-

Simple text Pasta: curl -d "expiration=10min&content=This is a test pasta" -X POST https://microbin.myserver.com/create

-

File contents: curl -d "expiration=10min&content=$( < mypastafile.txt )" -X POST https://microbin.myserver.com/create

-

Available expiration options: - 1min, 10min, 1hour, 24hour, 1week, never

-

Use cURL to read the pasta: curl https://microbin.myserver.com/rawpasta/fish-pony-crow,

-

or to download the pasta: curl https://microbin.myserver.com/rawpasta/fish-pony-crow > output.txt (use /file instead of /rawpasta to download attached file).

-

2 Installation

-

From Cargo

-

Install from Cargo:

-

cargo install microbin

-

Remember, MicroBin will create your database and file storage wherever you execute it. I recommend that you create a folder for it first and execute it there:

-

mkdir ~/microbin/

-

cd ~/microbin/

-

microbin --port 8080 --highlightsyntax --editable

-

Building MicroBin

-

Simply clone the repository, build it with cargo build --release and run the microbin executable in the created target/release/ directory. It will start on port 8080. You can change the port with -p or --port CL arguments. For other arguments see the Wiki.

-
git clone https://github.com/szabodanika/microbin.git
-cd microbin
-cargo build --release
-./target/release/microbin -p 80
-

MicroBin as a service

-

To install it as a service on your Linux machine, create a file called /etc/systemd/system/microbin.service, paste this into it with the [username] and [path to installation directory] replaced with the actual values. If you installed MicroBin from Cargo, your executable will be in your system's Cargo directory, e.g. /Users/daniel/.cargo/bin/microbin.

-
[Unit]
-Description=MicroBin
-After=network.target
-
-[Service]
-Type=simple
-Restart=always
-User=[username]
-RootDirectory=/
-WorkingDirectory=[path to installation directory]
-ExecStart=[path to installation directory]/target/release/microbin
-
-[Install]
-WantedBy=multi-user.target
-

Here is my microbin.service for example, with some optional arguments:

-
[Unit]
-Description=MicroBin
-After=network.target
-
-[Service]
-Type=simple
-Restart=always
-User=ubuntu
-RootDirectory=/
-
-# This is the directory where I want to run microbin. It will store all the pastas here.
-WorkingDirectory=/home/ubuntu/server/microbin
-
-# This is the location of my executable - I also have 2 optional features enabled
-ExecStart=/home/ubuntu/server/microbin/target/release/microbin --editable --linenumbers --highlightsyntax
-
-# I keep my installation in the home directory, so I need to add this
-ProtectHome=off
-
-[Install]
-WantedBy=multi-user.target
-

Then start the service with systemctl start microbin and enable it on boot with systemctl enable microbin. To update your MicroBin, simply update or clone the repository again, build it again, and then restart the service with systemctl restart microbin. An update will never affect your existing pastas, unless there is a breaking change in the data model (in which case MicroBin just won't be able to import your DB), which will always be mentioned explicitly.

-

NGINX configuration

-
server {
-    # I have HTTPS enabled using certbot - you can use HTTP of course if you want!
-  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;
-        proxy_set_header    Host $host;
-        proxy_set_header    X-Forwarded-Proto $scheme;
-        proxy_set_header    X-Real-IP $remote_addr;
-        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
-    }
-
-    # 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
-  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
-}
-

3 Command Line Arguments

-

There is an ever expanding list of customisations built into MicroBin so you can use it the way you want. Instead of a configuration file, we simply use arguments that you pass to the executable, making the workflow even simpler. Read the following options and if you cannot find what you need, you can always open an issue at our GitHub repository and request a new feature!

-

--auth-username [AUTH_USERNAME]

-

Require username for HTTP Basic Authentication when visiting the service. If --auth-username is set but --auth-password is not, just leave the password field empty when logging in. You can also just go to https://username:password@yourserver.net or https://username@yourserver.net if password is not set instead of typing into the password

-

--auth-password [AUTH_PASSWORD]

-

Require password for HTTP Basic Authentication when visiting the service. Will not have any affect unless --auth-username is also set. If --auth-username is set but --auth-password is not, just leave the password field empty when logging in. You can also just go to https://username:password@yourserver.net or https://username@yourserver.net if password is not set instead of typing into the password prompt.

-

--editable

-

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.

- -

Replaces the default footer text with your own. If you want to hide the footer, use --hide-footer instead.

-

-h, --help

-

Show all commands in the terminal.

- -

Hides the footer on every page.

-

--hide-header

-

Hides the navigation bar on every page.

- -

Hides the MicroBin logo from the navigation bar on every page.

-

--no-listing

-

Disables the /pastalist endpoint, essentially making all pastas private.

-

--highlightsyntax

-

Enables syntax highlighting support. When creating a new pasta, a new dropdown selector will be added where you can select your pasta's syntax, or just leave it empty for no highlighting.

-

-p, --port [PORT]

-

Default value: 8080

-

Sets the port for the server will be listening on.

-

--private

-

Enables private pastas. Adds a new checkbox to make your pasta private, which then won't show up on the pastalist page. With the URL to your pasta, it will still be accessible.

-

--pure-html

-

Disables main CSS styling, just uses a few in-line stylings for the layout. With this option you will lose dark-mode support.

-

--readonly

-

Disables adding/editing/removing pastas entirely.

-

--title [TITLE]

-

Replaces "MicroBin" with your title of choice in the navigation bar.

-

-t, --threads [THREADS]

-

Default value: 1

-

Number of workers MicroBin is allowed to have. Increase this to the number of CPU cores you have if you want to go beast mode, but for personal use one worker is enough.

-

-V, --version

-

Displays your MicroBin's version information.

-

--wide

-

Changes the maximum width of the UI from 720 pixels to 1080 pixels.

- -{% include "footer.html" %} diff --git a/templates/index.html b/templates/index.html index 6d4ecdd..3c92851 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,26 +1,108 @@ {% include "header.html" %} +

-
+

+ {% if args.enable_burn_after %} +
+
+ +
+ {%- endif %} + {% if args.highlightsyntax %}
-
+
{%- endif %} - {% if !args.no_file_upload %}
- -
-
- + {% if args.editable || args.private %} + + {%- endif %} + {% if args.editable %} +
+ +
+ {%- endif %} + {% if args.private %} +
+ + +
+ {%- endif %}
- {% endif %} + + + +

-
-
- {% if args.editable %} -
- - -
- {%- endif %} - {% if args.private %} -
- - -
- {%- endif %} + {% if !args.no_file_upload %} +
+ +
+
- + {% endif %} {% if args.readonly %} {%- else %} @@ -101,23 +183,40 @@
+ + diff --git a/templates/info.html b/templates/info.html new file mode 100644 index 0000000..2e12c73 --- /dev/null +++ b/templates/info.html @@ -0,0 +1,42 @@ +{% include "header.html" %} + +

Welcome to MicroBin

+
+ + +
+

Info

+ + + + + + + + + + + + + +
Version{{version_string}}
Status{{status}}
Pastas{{pastas.len()}}
+
+
+ +{% if message != "" %} +

Messages

+

{{message}}

+{%- endif %} + +
+ +{% include "footer.html" %} \ No newline at end of file diff --git a/templates/pasta.html b/templates/pasta.html index d21e4fd..decfb75 100644 --- a/templates/pasta.html +++ b/templates/pasta.html @@ -1,26 +1,39 @@ {% include "header.html" %}
- Raw Text Content - {% if pasta.file.is_some() %} - - Attached file'{{pasta.file.as_ref().unwrap().name()}}' [{{pasta.file.as_ref().unwrap().size}}] - + {% if pasta.content != "No Text Content" %} + + Raw Text + Content + {%- endif %} + {% if args.qr && args.public_path.to_string() != "" %} + QR {%- endif %} {% if pasta.editable %} - Edit + Edit {%- endif %} - Remove + Remove
- {{pasta.id_as_animals()}} - + {%- endif %}
+{% if pasta.file.is_some() %}
+
+ + Download attached file: '{{pasta.file.as_ref().unwrap().name()}}' [{{pasta.file.as_ref().unwrap().size}}] + +{%- endif %} +
+
+{% if pasta.content != "No Text Content" %}
{% if args.highlightsyntax %} @@ -30,16 +43,33 @@ {%- endif %}
+{%- endif %} +
+

Read {{pasta.read_count}} times, last {{pasta.last_read_time_ago_as_string()}}

+
+ +
+