diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eba74f4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +venv/ \ No newline at end of file diff --git a/app.py b/app.py index aff7923..b193c01 100644 --- a/app.py +++ b/app.py @@ -6,14 +6,15 @@ from os import environ from distutils.util import strtobool from threading import Thread -pastey_version = "0.5" +pastey_version = "0.5.1" loaded_config = {} loaded_themes = [] app = Flask(__name__) limiter = Limiter( app, - key_func=get_remote_address + key_func=get_remote_address, + storage_uri="memory://" ) guess = Guess() @@ -37,6 +38,7 @@ config.ignore_guess = environ["PASTEY_IGNORE_GUESS"].split(",") if "PASTEY_IGNOR config.show_cli_button = bool(strtobool(environ["PASTEY_SHOW_CLI_BUTTON"])) if "PASTEY_SHOW_CLI_BUTTON" in environ else config.show_cli_button config.force_https_links = bool(strtobool(environ["PASTEY_FORCE_HTTPS_LINKS"])) if "PASTEY_FORCE_HTTPS_LINKS" in environ else config.force_https_links config.override_domain = environ["PASTEY_OVERRIDE_DOMAIN"] if "PASTEY_OVERRIDE_DOMAIN" in environ else config.override_domain +config.minimum_url_length = int(environ["PASTEY_MINIMUM_URL_LENGTH"]) if "PASTEY_MINIMUM_URL_LENGTH" in environ else config.minimum_url_length # Main loop if __name__ == "__main__": diff --git a/docker-compose.yml b/docker-compose.yml index 33eaf53..3dd7566 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,9 +2,7 @@ services: pastey: image: cesura/pastey:latest environment: - PASTEY_WORKERS: 2 - PASTEY_THREADS: 4 - PASTEY_LISTEN_PORT: 7778 + PASTEY_LISTEN_PORT: 5000 PASTEY_DEFAULT_THEME: Dark PASTEY_BEHIND_PROXY: "true" PASTEY_FORCE_SHOW_RECENT: "true" diff --git a/pastey/common.py b/pastey/common.py index f0abe5f..3c65137 100644 --- a/pastey/common.py +++ b/pastey/common.py @@ -1,10 +1,12 @@ from . import config -from __main__ import guess import ipaddress from os import path from pathlib import Path from datetime import datetime, timedelta +# Supported languages (required for non-guesslang builds) +supported_languages = ['Assembly', 'Batchfile', 'C', 'C#', 'C++', 'Clojure', 'CMake', 'COBOL', 'CoffeeScript', 'CSS', 'CSV', 'Dart', 'DM', 'Dockerfile', 'Elixir', 'Erlang', 'Fortran', 'Go', 'Groovy', 'Haskell', 'HTML', 'INI', 'Java', 'JavaScript', 'JSON', 'Julia', 'Kotlin', 'Lisp', 'Lua', 'Makefile', 'Markdown', 'Matlab', 'Objective-C', 'OCaml', 'Pascal', 'Perl', 'PHP', 'PowerShell', 'Prolog', 'Python', 'R', 'Ruby', 'Rust', 'Scala', 'Shell', 'SQL', 'Swift', 'TeX', 'TOML', 'TypeScript', 'Verilog', 'Visual Basic', 'XML', 'YAML'] + ########## Common functions ########## # Check request IP is in config whitelist @@ -66,7 +68,7 @@ def get_themes(): # Get a list of all supported languages from guesslang def get_languages(): - return guess.supported_languages + return supported_languages # Get file path from unique id # This is a wrapper to check for files with the .expires extension diff --git a/pastey/config.py b/pastey/config.py index 1c384e0..388b18d 100644 --- a/pastey/config.py +++ b/pastey/config.py @@ -59,4 +59,7 @@ force_https_links = False # # Note: exclude the http:// or https:// prefix, as well as anything # following the domain (except the port, if applicable) -override_domain = "" \ No newline at end of file +override_domain = "" + +# Minumum number of characters for generated URLs +minimum_url_length = 5 diff --git a/pastey/functions.py b/pastey/functions.py index 6be3de3..a8387df 100644 --- a/pastey/functions.py +++ b/pastey/functions.py @@ -1,4 +1,6 @@ -from __main__ import guess, app +from __main__ import app +from __main__ import guess # Intentionally put on a separate line + from . import config, common from os import path, remove, listdir @@ -85,12 +87,13 @@ def delete_paste(unique_id): # Create new paste def new_paste(title, content, source_ip, expires=0, single=False, encrypt=False, language="AUTO"): # this calculates the number of digits of a base64 number needed to be unlikely to have collisions - id_len = int(math.ceil( 3*math.log(len(listdir(config.data_directory))+1)/math.log(256) + 1.5 )) unique_id = secrets.token_urlsafe(id_len) + id_len = int(math.ceil( 3*math.log(len(listdir(config.data_directory))+1)/math.log(256) + 1.5 )) + unique_id = secrets.token_urlsafe(id_len if id_len >= config.minimum_url_length else config.minimum_url_length) output_file = config.data_directory + "/" + unique_id # Check for existing paste id (unlikely) while path.exists(output_file) or path.exists(output_file + ".expires"): - unique_id = secrets.token_urlsafe(id_len) + unique_id = secrets.token_urlsafe(id_len if id_len >= config.minimum_url_length else config.minimum_url_length) output_file = config.data_directory + "/" + unique_id # Attempt to guess programming language diff --git a/patch_no_tensorflow.sh b/patch_no_tensorflow.sh index 45123d1..af25eab 100755 --- a/patch_no_tensorflow.sh +++ b/patch_no_tensorflow.sh @@ -9,9 +9,6 @@ sed -i '/^[^#]/ s/\(^.*language = guesses.*$\)/ language = "Plaintext"/' sed -i '/^[^#]/ s/\(^.*from guesslang import Guess.*$\)/#\ \1/' app.py sed -i '/^[^#]/ s/\(^.*guess = Guess().*$\)/#\ \1/' app.py -# Patch common.py -sed -i '/^[^#]/ s/\(^.*from __main__ import guess.*$\)/#\ \1/' pastey/common.py - # Patch templates/new.html sed -i '/^.*value="AUTO".*$/d' templates/new.html diff --git a/templates/pastey.sh b/templates/pastey.sh index b1bcb84..c20833b 100755 --- a/templates/pastey.sh +++ b/templates/pastey.sh @@ -22,7 +22,7 @@ show_help() { -- Stop further option parsing Arguments passed after the -- option are evaluated as a command, and that command's output is pasted. - The full command is used a the title. + The full command is used as the title. If zero arguments are passed, or none of --file or -- are passed, diff --git a/templates/view.html b/templates/view.html index 418a69e..eb02ffe 100644 --- a/templates/view.html +++ b/templates/view.html @@ -193,8 +193,8 @@ - - + +