Stage for 0.5.1 release

pull/31/head
Cesura 2 years ago
parent 8972cb8a0c
commit be4e2248d2

@ -0,0 +1 @@
venv/

@ -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__":

@ -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"

@ -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

@ -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 = ""
override_domain = ""
# Minumum number of characters for generated URLs
minimum_url_length = 5

@ -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

@ -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

@ -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,

@ -193,8 +193,8 @@
<script type="text/javascript" src="/static/js/common.js"></script>
<script type="text/javascript" src="/static/js/qrcode.min.js"></script>
<script type="text/javascript" src="/static/js/mdb.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script>
<script type="text/javascript" src="/static/js/highlight.min.js"></script>
<script type="text/javascript" src="/static/js/highlightjs-line-numbers.min.js"></script>
<!-- Decrypt paste and generate QR code -->
<script type="text/javascript">

Loading…
Cancel
Save