### Setting up a Development Environment for Bepasty Server Source: https://bepasty-server.readthedocs.io/en/latest/_sources/project.rst.txt These commands guide you through creating a virtual environment, cloning the repository, installing the package in editable mode, and running the server for development. ```bash # Create a new virtualenv virtualenv bepasty-server-env # Activate the virtualenv source bepasty-server-env/bin/activate # Clone the official bepasty-server (or your fork, if you want to send pull requests) git clone https://github.com/bepasty/bepasty-server.git cd bepasty-server # This will use the current directory for the installed package. # Very useful during development! It will also auto-reload when files are changed. pip install -e . # Run the Bepasty server in debug mode. The server is reachable at http://127.0.0.1:5000 bepasty-server --debug ``` -------------------------------- ### Install Preliminary Packages Source: https://bepasty-server.readthedocs.io/en/latest/_sources/install-tutorial.rst.txt Installs essential packages required for building and running the Bepasty server. ```bash apt-get install build-essential nginx supervisor python-dev git-core python-pip python-virtualenv ``` -------------------------------- ### Install Preliminary Packages Source: https://bepasty-server.readthedocs.io/en/latest/install-tutorial.html Installs essential packages required for building and running Bepasty on a Debian system. ```bash apt-get install build-essential nginx supervisor python-dev git-core python-pip python-virtualenv ``` -------------------------------- ### Install Bepasty from PyPI Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Install the latest release of Bepasty from the Python Package Index. ```bash pip install bepasty ``` -------------------------------- ### Install Bepasty from Git Repository Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Install the latest available code for Bepasty directly from its Git repository. ```bash pip install -e git+https://github.com/bepasty/bepasty-server.git#egg=bepasty-server ``` -------------------------------- ### GET Response for Item List Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Example JSON response when retrieving a list of all items on the server. Each item is identified by its unique ID and includes its file metadata and URI. ```json { "N24bFRZm": { "file-meta": { "complete": true, "filename": "Wallpaper Work.7z", "hash": "dded24ba6f1d953bedb9d2745635a6f7462817061763b0d70f68b7952722f275", "locked": false, "size": 150225567, "timestamp-download": 1414483078, "timestamp-max-life": -1, "timestamp-upload": 1414443534, "type": "application/x-7z-compressed" }, "uri": "/apis/rest/items/N24bFRZm" }, ... } ``` -------------------------------- ### System User and Repository Setup Source: https://bepasty-server.readthedocs.io/en/latest/_sources/install-tutorial.rst.txt Creates a dedicated user for Bepasty, clones the repository, and sets up storage and log directories. ```bash adduser bepasty sudo su - bepasty git clone https://github.com/bepasty/bepasty-server.git repo mkdir storage mkdir logs ``` -------------------------------- ### Bepasty Configuration File Example Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Example of a local Bepasty configuration file with essential settings. Ensure to remove the Config class and outdent settings from the default config.py. ```ini # Note: no Config class required, just simple KEY = value lines: SECRET_KEY = '........................' STORAGE = 'filesystem' STORAGE_FILESYSTEM_DIRECTORY = '/srv/bepasty/storage/' # ... ``` -------------------------------- ### Virtual Environment and Dependency Installation Source: https://bepasty-server.readthedocs.io/en/latest/_sources/install-tutorial.rst.txt Sets up a Python virtual environment and installs Bepasty along with its dependencies, including Gunicorn and Gevent for hosting. ```bash virtualenv . . bin/activate cd repo pip install -e . pip install gunicorn gevent ``` -------------------------------- ### Virtual Environment and Dependency Installation Source: https://bepasty-server.readthedocs.io/en/latest/install-tutorial.html Sets up a Python virtual environment and installs Bepasty along with its hosting dependencies (Gunicorn and Gevent). ```bash # create virtualenv virtualenv . # activate virtualenv . bin/activate cd repo # install bepasty and requirements pip install -e . # add gunicorn and gevent for hosting pip install gunicorn gevent ``` -------------------------------- ### Install Bepasty with Python Magic support Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Install Bepasty along with the python-magic library to help determine files' MIME types. ```bash pip install bepasty[magic] ``` -------------------------------- ### System User and Repository Setup Source: https://bepasty-server.readthedocs.io/en/latest/install-tutorial.html Creates a dedicated user for Bepasty, clones the repository, and sets up necessary directories for storage and logs. ```bash # add user bepasty to system adduser bepasty # change to user bepasty sudo su - bepasty # clone repository from GitHub git clone https://github.com/bepasty/bepasty-server.git repo # create folder for storage mkdir storage # create folder for logs mkdir logs ``` -------------------------------- ### GET Response for Item Metadata Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Example JSON response from the server when requesting metadata for a specific item. It includes file details like filename, size, timestamps, and hash. ```json { "file-meta": { "complete": true, "filename": "Wallpaper Work.7z", "hash": "dded24ba6f1d953bedb9d2745635a6f7462817061763b0d70f68b7952722f275", "locked": false, "size": 150225567, "timestamp-download": 1414483078, "timestamp-max-life": -1, "timestamp-upload": 1414443534, "type": "application/x-7z-compressed" }, "uri": "/apis/rest/items/N24bFRZm" } ``` -------------------------------- ### Configure Bepasty Permissions Source: https://bepasty-server.readthedocs.io/en/latest/quickstart.html Example configuration for PERMISSIONS dict, mapping secrets to user permissions. ```python PERMISSIONS = { 'myadminsecret_1.21d-3!wdar34': 'admin,list,create,modify,read,delete', 'uploadersecret_rtghtrbrrrfsd': 'create,read', 'joe_doe_89359299887711335537': 'create,read,delete', } ``` -------------------------------- ### Start Bepasty Server with Local Configuration Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Run the Bepasty server using a custom local configuration file. Ensure to use an absolute path for the configuration file. ```bash BEPASTY_CONFIG=/srv/bepasty/bepasty.conf bepasty-server ``` -------------------------------- ### Run Bepasty Server with Gunicorn Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Start the Bepasty server using Gunicorn, a production-ready WSGI HTTP server. This is recommended for production environments. ```bash gunicorn bepasty.wsgi ``` -------------------------------- ### Get Help for Bepasty Object Command Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Display help information for the main 'bepasty-object' command, which manages stored objects. ```bash bepasty-object --help ``` -------------------------------- ### GET /apis/rest/items//download Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Initiates the download of a specific file from the server. ```APIDOC ## GET /apis/rest/items//download ### Description Initiates the download of a specific file from the Bepasty server. ### Method GET ### Endpoint /apis/rest/items//download ### Parameters #### Path Parameters - **itemname** (string) - Required - The name of the item (file) to download. ``` -------------------------------- ### GET /apis/rest/items Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Retrieves a list of all items (files) available on the server. ```APIDOC ## GET /apis/rest/items ### Description Retrieves a list of all items (files) currently stored on the Bepasty server. ### Method GET ### Endpoint /apis/rest/items ``` -------------------------------- ### Get Help for Bepasty Object Purge Subcommand Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Display help information for the 'purge' subcommand of 'bepasty-object', used for removing stored objects. ```bash bepasty-object purge --help ``` -------------------------------- ### HTTP Response Headers for File Download Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Example HTTP response headers returned when downloading a file. These headers provide information about the file's content type, size, and disposition. ```http Content-Type: application/x-7z-compressed Content-Length: 150225568 Content-Disposition: attachment; filename="Wallpaper Work.7z" Content-Range: bytes 0-150225567/150225567 ``` -------------------------------- ### Download a File via REST API Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Use this GET request to download a file. The server responds with binary data and relevant headers like Content-Type and Content-Disposition. ```http GET /apis/rest/items//download ``` ```http Content-Type: application/x-7z-compressed Content-Length: 150225568 Content-Disposition: attachment; filename="Wallpaper Work.7z" Content-Range: bytes 0-150225567/150225567 ``` -------------------------------- ### GET Request for Item List Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Use this endpoint to retrieve a list of all items on the server. Requires 'list' permission. No parameters are needed for the request. ```http GET /apis/rest/items ``` -------------------------------- ### Get Item Information Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Retrieves metadata and URI for a specific item on the server using its itemname. ```APIDOC ## GET /apis/rest/items/ ### Description Retrieves metadata and the URI for a specific file on the server. ### Method GET ### Endpoint /apis/rest/items/ ### Parameters #### Path Parameters - **itemname** (string) - Required - The itemname of the file requested. ### Response #### Success Response (200) - **uri** (string) - The URI of the file on the server. - **file-meta** (object) - Metadata about the file. - **complete** (boolean) - True if the file upload is completed. - **filename** (string) - The filename of the uploaded file. - **hash** (string) - The SHA256 hash of the file. - **locked** (boolean) - Whether the file is locked or not. - **size** (integer) - The calculated size of the file on the server. - **timestamp-download** (integer) - The timestamp of the last download. - **timestamp-max-life** (integer) - The lifetime timestamp of the file in seconds (-1 for forever). - **timestamp-upload** (integer) - The timestamp of the moment the file was uploaded. - **type** (string) - MIME type of the file uploaded. ### Response Example { "file-meta": { "complete": true, "filename": "Wallpaper Work.7z", "hash": "dded24ba6f1d953bedb9d2745635a6f7462817061763b0d70f68b7952722f275", "locked": false, "size": 150225567, "timestamp-download": 1414483078, "timestamp-max-life": -1, "timestamp-upload": 1414443534, "type": "application/x-7z-compressed" }, "uri": "/apis/rest/items/N24bFRZm" } ``` -------------------------------- ### GET /apis/rest/items/ Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Retrieves information about a specific file on the server using its item name. ```APIDOC ## GET /apis/rest/items/ ### Description Retrieves detailed information about a specific file stored on the Bepasty server. ### Method GET ### Endpoint /apis/rest/items/ ### Parameters #### Path Parameters - **itemname** (string) - Required - The name of the item (file) to retrieve information for. ``` -------------------------------- ### Run Bepasty Object Purge (Dry-Run) Source: https://bepasty-server.readthedocs.io/en/latest/quickstart.html Execute the object purge command in dry-run mode to simulate removal without deleting any data. This example targets files that are at least 10MiB in size and older than 14 days, operating on all objects. ```bash bepasty-object purge --dry-run --size 10 --age 14 '*' ``` -------------------------------- ### GET Request for File Information Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Use this endpoint to retrieve metadata for a specific file using its item name. Requires 'read' permission. ```http GET /apis/rest/items/ ``` -------------------------------- ### Run Bepasty Object Purge (Dry Run) Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Perform a dry run of the 'bepasty-object purge' command to identify objects that would be removed. This example targets files larger than 10MiB and older than 14 days. ```bash bepasty-object purge --dry-run --size 10 --age 14 '*' ``` -------------------------------- ### GET /apis/rest Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Retrieves information for uploading files, including maximum allowed file size and maximum POST request body size. ```APIDOC ## GET /apis/rest ### Description Retrieves server configuration details relevant to file uploads and downloads, such as maximum file size and body size limits. ### Method GET ### Endpoint /apis/rest ### Response #### Success Response (200) - **MAX_ALLOWED_FILE_SIZE** (integer) - The maximum allowed file size that can be stored on the server. - **MAX_BODY_SIZE** (integer) - The maximum size of a POST request body, which also dictates the maximum chunk size for uploads. ### Response Example ```json { "MAX_ALLOWED_FILE_SIZE": 5000000000, "MAX_BODY_SIZE": 1048576 } ``` ``` -------------------------------- ### POST Request Body for Modifying Filename Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Example JSON payload for modifying the filename of an item. The Content-Type header must be set to application/json. ```json {"filename": "new-filename.txt"} ``` -------------------------------- ### GET Response for Upload Information Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt This JSON response provides server configuration details relevant for file uploads, such as maximum allowed file size and maximum request body size. ```json { MAX_ALLOWED_FILE_SIZE: 5000000000, MAX_BODY_SIZE: 1048576 } ``` -------------------------------- ### GET Request for Upload Information Source: https://bepasty-server.readthedocs.io/en/latest/rest.html This API endpoint retrieves server configuration details relevant to file uploads and downloads, such as maximum body and file sizes. ```http GET /apis/rest ``` -------------------------------- ### REST API Error Response Example Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt This JSON structure represents an error response from the REST API. It includes an error code and a detailed message. ```json { "error": { "code": , "message": "" } } ``` -------------------------------- ### POST Request Body for Modifying Filename and Type Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Example JSON payload for modifying both the filename and MIME type of an item. The Content-Type header must be set to application/json. ```json {"filename": "new-filename.txt", "type": "new-mimetype"} ``` -------------------------------- ### Advanced pastebinit upload with options Source: https://bepasty-server.readthedocs.io/en/latest/_sources/user-cli.rst.txt Upload content with a specified title (filename), password, and input file. ```bash pastebinit -t example.py -p yourpassword -i example.py ``` -------------------------------- ### Configure Bepasty Storage Source: https://bepasty-server.readthedocs.io/en/latest/install-tutorial.html Sets the storage backend to 'filesystem' and specifies the directory for storing files. ```ini STORAGE = 'filesystem' STORAGE_FILESYSTEM_DIRECTORY = '/home/bepasty/storage/' ``` -------------------------------- ### Upload from stdin with title and format Source: https://bepasty-server.readthedocs.io/en/latest/_sources/user-cli.rst.txt Upload content from stdin, providing a title (filename) and specifying the content type format. ```bash cat README | pastebinit -t README -f text/plain ``` -------------------------------- ### Bepasty Configuration Class Source: https://bepasty-server.readthedocs.io/en/latest/_modules/bepasty/config.html The main configuration class for bepasty. Settings are loaded at startup and require a restart to take effect. ```python class Config: """ This is the basic configuration class for bepasty. IMPORTANT: The config is only loaded at startup time of the app, so if you change it, you need to restart the WSGI app process(es) to make it load the updated config. """ #: name of this site (put YOUR bepasty FQDN here) SITENAME = 'bepasty.example.org' #: base URL path of the app (if not served on root URL, but e.g. on http://example.org/bepasty). #: setting this to a non-None value will activate the PrefixMiddleware that splits PATH_INFO #: into SCRIPT_NAME (== APP_BASE_PATH) and the rest of PATH_INFO. APP_BASE_PATH = None # '/bepasty' #: Whether files are automatically locked after upload. #: #: If you want to require admin approval and manual unlocking for each #: uploaded file, set this to True. UPLOAD_LOCKED = False #: The asciinema player theme (one of asciinema, tango, solarized-dark, #: solarized-light, monokai) ASCIINEMA_THEME = 'asciinema' #: The site admin can set some maximum allowed file size he wants to #: accept here. This is the maximum size an uploaded file may have. MAX_ALLOWED_FILE_SIZE = 5 * 1000 * 1000 * 1000 #: The maximum HTTP request body size. #: This information is provided to REST API clients so they can adjust #: their chunk size accordingly. #: #: This needs to be in sync with (or at least not beyond) the web server #: settings: #: apache: LimitRequestBody 1048576 # apache default is 0 (unlimited) #: nginx: client_max_body_size 1m; # nginx default (== 1048576) MAX_BODY_SIZE = 1 * 1024 * 1024 - 8192 # 8 KiB safety margin, issue #155 #: Setup maximum file sizes for specific content types. If an item is #: beyond the limit set for its type, it will not be rendered, but just #: offered for download. Lookup within MAX_RENDER_SIZE is done by #: first-match and it is automatically sorted for longer content-type- #: prefixes first. #: #: Format of entries: content-type-prefix: max_size MAX_RENDER_SIZE = { # each list entry has 38 bytes, do not render > 1000 items 'text/x-bepasty-list': 1000 * 38, # stuff rendered with syntax highlighting (expensive for server and # client) and also used for other text/* types as we use same code to # get a (non-highlighted) display with line numbers: 'HIGHLIGHT_TYPES': 100 * 1000, # the in-browser pdf reader is sometimes rather slow and should # rather not be used for big PDFs: 'application/pdf': 10 * 1000 * 1000, 'application/x-pdf': 10 * 1000 * 1000, # images / audio / video can be rather big, we do not process them: 'image/': 20 * 1000 * 1000, 'audio/': 1 * 1000 * 1000 * 1000, 'video/': 5 * 1000 * 1000 * 1000, # DEFAULT - matches everything not matched otherwise. # As we have catched everything we are able to render already, # this maybe should be a medium size, just for the case we forget # something: '': 1 * 1000 * 1000, } # Whether to use the python-magic module to guess a file's MIME # type by looking into its content (if the MIME type cannot be # determined from the filename extension). # NOTE: # libmagic may have security issues, so maybe you should only use # it if you trust all users with upload permissions ('create'). USE_PYTHON_MAGIC = False #: Define storage backend, choose from: #: #: - 'filesystem' #: STORAGE = 'filesystem' #: Filesystem storage path STORAGE_FILESYSTEM_DIRECTORY = '/tmp/' #: Server secret key needed for safe session cookies. #: You must set a very long (20–100 chars), very random, very secret string here, #: otherwise bepasty will not work (and will crash when trying to log in)! SECRET_KEY = '' #: Transmit cookie only over HTTPS (if you use HTTP, set this to False) SESSION_COOKIE_SECURE = True #: use a permanent session (True, cookie will expire after the given #: time, see below) or not (False, cookie will get removed when browser #: is closed) PERMANENT_SESSION = False #: lifetime of the permanent session (in seconds) PERMANENT_SESSION_LIFETIME = 31 * 24 * 3600 ``` -------------------------------- ### Supervisor Configuration for Bepasty Source: https://bepasty-server.readthedocs.io/en/latest/install-tutorial.html Sets up Supervisor to manage the Gunicorn process, ensuring it runs as the 'bepasty' user and logs output. ```ini [program:bepasty] command = /home/bepasty/bin/gunicorn_bepasty ; Command to start app user = bepasty ; User to run as stdout_logfile = /home/bepasty/logs/gunicorn_supervisor.log ; Where to write log messages redirect_stderr = true ; Save stderr in the same log ``` -------------------------------- ### Supervisor Configuration for Bepasty Source: https://bepasty-server.readthedocs.io/en/latest/_sources/install-tutorial.rst.txt Sets up Supervisor to manage the Gunicorn process for Bepasty, ensuring it runs as a specific user and logs output correctly. ```ini [program:bepasty] command = /home/bepasty/bin/gunicorn_bepasty ; Command to start app user = bepasty ; User to run as stdout_logfile = /home/bepasty/logs/gunicorn_supervisor.log ; Where to write log messages redirect_stderr = true ; Save stderr in the same log ``` -------------------------------- ### Bepasty Configuration File Source: https://bepasty-server.readthedocs.io/en/latest/_sources/install-tutorial.rst.txt Configures Bepasty's storage settings by modifying the configuration file. Ensure the STORAGE_FILESYSTEM_DIRECTORY points to your created storage path. ```ini STORAGE = 'filesystem' STORAGE_FILESYSTEM_DIRECTORY = '/home/bepasty/storage/' ``` -------------------------------- ### Upload content using pastebinit Source: https://bepasty-server.readthedocs.io/en/latest/_sources/user-cli.rst.txt Basic usage of pastebinit to upload content from stdin to Bepasty. ```bash echo "test" | pastebinit ``` -------------------------------- ### Configure pastebinit for Bepasty Source: https://bepasty-server.readthedocs.io/en/latest/_sources/user-cli.rst.txt XML configuration for pastebinit to point to a Bepasty instance. Sets the pastebin URL and an empty default format. ```xml https://bepasty.example.org ``` -------------------------------- ### Bepasty Configuration for pastebinit Source: https://bepasty-server.readthedocs.io/en/latest/_sources/user-cli.rst.txt Configuration file for pastebinit to define Bepasty server details, including basename, regex, format mappings, and default page settings. ```ini [pastebin] basename = bepasty.example.org regexp = https://bepasty.example.org [format] content = text title = filename format = contenttype page = page password = token [defaults] page = +upload ``` -------------------------------- ### Migrate Bepasty Stored Metadata Source: https://bepasty-server.readthedocs.io/en/latest/quickstart.html Run the object migrate command to upgrade the stored metadata to the current bepasty metadata schema. This is often necessary after upgrading bepasty. The '*' operates on all names in storage. ```bash bepasty-object migrate '*' ``` -------------------------------- ### Gunicorn Configuration for Bepasty Source: https://bepasty-server.readthedocs.io/en/latest/install-tutorial.html A bash script to configure and run Gunicorn with Bepasty, using a Unix socket for communication and the gevent worker type. ```bash #!/bin/bash NAME="bepasty" HOME=/home/bepasty SOCKFILE=$HOME/gunicorn.sock # we will communicate using this unix socket PIDFILE=$HOME/gunicorn.pid NUM_WORKERS=3 # how many worker processes should Gunicorn spawn export BEPASTY_CONFIG=$HOME/bepasty.conf source $HOME/bin/activate cd $HOME/repo exec gunicorn bepasty.wsgi \ --name $NAME \ --workers $NUM_WORKERS \ --log-level=info \ --bind=unix:$SOCKFILE \ --pid $PIDFILE \ -k gevent ``` -------------------------------- ### Download a file Source: https://bepasty-server.readthedocs.io/en/latest/rest.html This endpoint allows users to download a file by its item name. It returns a stream of the file's binary data with appropriate content headers. ```APIDOC ## GET /apis/rest/items//download ### Description Opens up a stream and delivers the binary data directly. The above headers can be found in the HTTP Response. ### Method GET ### Endpoint /apis/rest/items//download ### Parameters #### Path Parameters - **itemname** (string) - Required - The name of the item to download. ### Response #### Success Response (200) - **Content-Type** (string) - The MIME type of the file. - **Content-Length** (integer) - The size of the file in bytes. - **Content-Disposition** (string) - Specifies how to output the response content, typically as an attachment with a filename. - **Content-Range** (string) - Indicates the range of bytes the response covers. ### Response Example ``` Content-Type: application/x-7z-compressed Content-Length: 150225568 Content-Disposition: attachment; filename="Wallpaper Work.7z" Content-Range: bytes 0-150225567/150225567 ``` ``` -------------------------------- ### Download File Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Initiates a stream to download a specific file from the server. ```APIDOC ## GET /apis/rest/items//download ### Description Opens a stream to deliver the binary data of a file directly. ### Method GET ### Endpoint /apis/rest/items//download ### Parameters #### Path Parameters - **itemname** (string) - Required - The itemname of the file to download. ### Response #### Success Response (200) - The raw binary data of the file. - Headers include `Content-Type`, `Content-Length`, `Content-Disposition`, and `Content-Range`. ### Response Example Content-Type: application/x-7z-compressed Content-Length: 150225568 Content-Disposition: attachment; filename="Wallpaper Work.7z" Content-Range: bytes 0-150225567/150225567 ``` -------------------------------- ### Gunicorn Service Script for Bepasty Source: https://bepasty-server.readthedocs.io/en/latest/_sources/install-tutorial.rst.txt A bash script to configure and run Gunicorn for the Bepasty application. It sets up the environment, binds to a Unix socket, and specifies worker processes. ```bash #!/bin/bash NAME="bepasty" HOME=/home/bepasty SOCKFILE=$HOME/gunicorn.sock # we will communicate using this unix socket PIDFILE=$HOME/gunicorn.pid NUM_WORKERS=3 # how many worker processes should Gunicorn spawn export BEPASTY_CONFIG=$HOME/bepasty.conf source $HOME/bin/activate cd $HOME/repo exec gunicorn bepasty.wsgi \ --name $NAME \ --workers $NUM_WORKERS \ --log-level=info \ --bind=unix:$SOCKFILE \ --pid $PIDFILE \ -k gevent ``` -------------------------------- ### Upload with HTTP Basic Auth using curl Source: https://bepasty-server.readthedocs.io/en/latest/changelog.html This snippet demonstrates how to upload a file using curl with HTTP basic authentication. The username is ignored, and only the password from the header is used. ```bash $ curl -F 'file=@somefile;type=text/plain' http://user:password@localhost:5000/+upload ``` -------------------------------- ### Retrieve Item List Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Fetches a list of all items available on the server, including their metadata and URIs. ```APIDOC ## GET /apis/rest/items ### Description Retrieves a list of all items available on the server. ### Method GET ### Endpoint /apis/rest/items ### Parameters No Parameters ### Response #### Success Response (200) - A JSON object where keys are itemnames and values are objects containing file metadata and URI. ### Response Example { "N24bFRZm": { "file-meta": { "complete": true, "filename": "Wallpaper Work.7z", "hash": "dded24ba6f1d953bedb9d2745635a6f7462817061763b0d70f68b7952722f275", "locked": false, "size": 150225567, "timestamp-download": 1414483078, "timestamp-max-life": -1, "timestamp-upload": 1414443534, "type": "application/x-7z-compressed" }, "uri": "/apis/rest/items/N24bFRZm" } } ``` -------------------------------- ### POST /apis/rest/items Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Uploads a file to the server using a mandatory chunked upload process. Requires Content-Range and Transaction-ID headers. ```APIDOC ## POST /apis/rest/items ### Description Uploads a file to the Bepasty server. This endpoint mandates chunked uploads and requires specific headers for managing the upload process. ### Method POST ### Endpoint /apis/rest/items ### Parameters #### Request Body - The body of the POST request contains the Base64-encoded binary of the file to be uploaded. #### Headers - **Content-Range** (string) - Required - Specifies the range of the current upload chunk, following W3C specifications. Essential for resuming aborted uploads. - **Transaction-ID** (string) - Required (after first chunk) - Provided by the server after the initial upload chunk and must be included in subsequent requests to continue the upload. - *Content-Type* (string) - Optional - The MIME type of the file. If omitted, the server attempts to guess the type from the filename; otherwise, it defaults to 'application/octet-stream'. - *Content-Length* (integer) - Optional - Can indicate the final file size. If it exceeds the server's maximum allowed size, the upload is aborted. - *Content-Filename* (string) - Optional - The desired name for the file on the server. If omitted, a name is generated. Maximum length is 50 characters. - *Maxlife-Unit* (string) - Optional - The unit for the file's lifetime (e.g., 'MINUTES', 'HOURS', 'DAYS', 'WEEKS', 'MONTHS', 'YEARS', 'FOREVER'). Defaults to 'FOREVER' if omitted. - *Maxlife-Value* (integer) - Optional - The value corresponding to the `Maxlife-Unit` to define the file's lifetime. ### Response #### Success Response (200) - **Transaction-ID** (string) - Provided for continued upload in a chunked process. - **Content-Location** (string) - The URI of the newly uploaded file on the server. Only provided upon successful completion of the upload. ### Request Example ```json { "example": "Base64-encoded file content" } ``` ``` -------------------------------- ### POST /apis/rest/items Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Uploads a new item to the server. ```APIDOC ## POST /apis/rest/items ### Description Uploads a new item (file) to the Bepasty server. ### Method POST ### Endpoint /apis/rest/items ``` -------------------------------- ### Configure User Permissions with Secrets Source: https://bepasty-server.readthedocs.io/en/latest/_modules/bepasty/config.html Define access control for users by mapping secrets (passphrases) to specific permission sets. This allows for granular control over user actions based on the secret they use to log in. ```python PERMISSIONS = { 'myadminsecret_1.21d-3!wdar34': 'admin,list,create,modify,read,delete', 'uploadersecret_rtghtrbrrrfsd': 'create,read', 'joe_doe_89359299887711335537': 'create,read,delete', } ``` -------------------------------- ### CLI Command Fix: bepasty-object set Source: https://bepasty-server.readthedocs.io/en/latest/changelog.html Corrects a typo in the 'bepasty-object set' CLI command, changing 'uncomplete' to 'incomplete'. ```bash bepasty-object set --incomplete ``` -------------------------------- ### Unlock a File via REST API Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Use this endpoint to unlock a file, allowing further modifications. Requires admin privileges. ```bash POST /apis/rest/items//unlock ``` -------------------------------- ### POST /apis/rest/items Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Uploads a file to the server using a chunked upload process. The request body must contain the Base64-encoded binary of the file. Specific headers are required for managing the upload process, including chunking, transaction identification, and optional file metadata. ```APIDOC ## POST /apis/rest/items ### Description Uploads a file to the server using a mandatory chunked upload process. The server expects the file content to be Base64-encoded in the request body. This endpoint supports resuming aborted uploads via the `Transaction-ID` header. ### Method POST ### Endpoint /apis/rest/items ### Parameters #### Request Body - **Base64-encoded file binary** (string) - Required - The binary content of the file, encoded in Base64. #### Headers - **Content-Range** (string) - Required - Specifies the range of the current chunk according to W3C specifications. Used for chunked uploads and resuming aborted uploads. - **Transaction-ID** (string) - Required (after first chunk) - Provided by the server after the first upload chunk. Must be included in subsequent requests to continue the upload. - **Content-Type** (string) - Optional - The MIME type of the file. If omitted, the server attempts to guess the type, defaulting to 'application/octet-stream'. - **Content-Length** (string) - Optional - Indicates the final file size. Mostly ignored by the server, but can be used to check against maximum allowed server size. - **Content-Filename** (string) - Optional - The desired name for the file on the server. Maximum length is 50 characters. If omitted, the server generates a name. - **Maxlife-Unit** (string) - Optional - The unit for the file's lifetime. Allowed values: 'MINUTES', 'HOURS', 'DAYS', 'WEEKS', 'MONTHS', 'YEARS', 'FOREVER'. Defaults to 'FOREVER' if omitted. - **Maxlife-Value** (string) - Optional - The value corresponding to the `Maxlife-Unit` to define the file's lifetime. ### Response #### Success Response (200 OK) - **Transaction-ID** (string) - Provided for continued upload in a chunked upload process. This is returned after the first chunk. - **Content-Location** (string) - The URI of the newly uploaded file on the server. This header is only provided when the upload is finished and successful. #### Error Response - The server may return error codes for issues like exceeding `MAX_BODY_SIZE`, invalid `Content-Range`, or permission errors (required permission: `create`). ``` -------------------------------- ### Nginx Configuration for Bepasty Source: https://bepasty-server.readthedocs.io/en/latest/install-tutorial.html Configures Nginx to proxy requests to the Gunicorn socket and serve static files for the Bepasty application. ```nginx upstream pasty_server { server unix:/home/bepasty/gunicorn.sock fail_timeout=0; } server { listen 80; #listen [::]:80; #uncomment this if your server supports IPv6 server_name paste.example.org; # <-- add your domainname here access_log /home/bepasty/logs/nginx-access.log; error_log /home/bepasty/logs/nginx-error.log; client_max_body_size 32M; location / { proxy_set_header Host $http_host; proxy_pass http://pasty_server; } location /static/ { alias /home/bepasty/repo/src/bepasty/static/; } } ``` -------------------------------- ### Allowed Maxlife Units Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Defines the acceptable units for file lifetime when using the Maxlife-Unit header. If omitted, the file lifetime defaults to 'FOREVER'. ```Text ['MINUTES', 'HOURS', 'DAYS', 'WEEKS', 'MONTHS', 'YEARS', 'FOREVER'] ``` -------------------------------- ### Nginx Configuration for Bepasty Source: https://bepasty-server.readthedocs.io/en/latest/_sources/install-tutorial.rst.txt Configures Nginx to act as a reverse proxy for the Gunicorn-served Bepasty application. It forwards requests to the Gunicorn socket and serves static files. ```nginx upstream pasty_server { server unix:/home/bepasty/gunicorn.sock fail_timeout=0; } server { listen 80; #listen [::]:80; #uncomment this if your server supports IPv6 server_name paste.example.org; # <-- add your domainname here access_log /home/bepasty/logs/nginx-access.log; error_log /home/bepasty/logs/nginx-error.log; client_max_body_size 32M; location / { proxy_set_header Host $http_host; proxy_pass http://pasty_server; } location /static/ { alias /home/bepasty/repo/src/bepasty/static/; } } ``` -------------------------------- ### Lock a File via REST API Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Use this endpoint to lock a file, preventing further modifications. Requires admin privileges. ```bash POST /apis/rest/items//lock ``` -------------------------------- ### Migrate Bepasty Stored Metadata Source: https://bepasty-server.readthedocs.io/en/latest/_sources/quickstart.rst.txt Upgrade the stored metadata of Bepasty objects to the current schema. The '*' argument, quoted with single-quotes, indicates operation on all objects. ```bash bepasty-object migrate '*' ``` -------------------------------- ### Bepasty REST API Endpoints Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Lists the available API endpoints for interacting with Bepasty. These include operations for retrieving, uploading, modifying, and deleting items. ```text GET /apis/rest GET /apis/rest/items POST /apis/rest/items GET /apis/rest/items/ GET /apis/rest/items//download POST /apis/rest/items//modify POST /apis/rest/items//delete POST /apis/rest/items//lock POST /apis/rest/items//unlock ``` -------------------------------- ### Default Permissions for Unauthenticated Users Source: https://bepasty-server.readthedocs.io/en/latest/_modules/bepasty/config.html Set the default permissions granted to users who do not log in. Typically, this is set to an empty string (no permissions) or 'read' for read-only access. ```python DEFAULT_PERMISSIONS = '' ``` -------------------------------- ### File Upload Endpoint Source: https://bepasty-server.readthedocs.io/en/latest/rest.html The endpoint for uploading files to the Bepasty server. Chunked upload is mandatory for all file uploads. ```HTTP POST /apis/rest/items ``` -------------------------------- ### POST /apis/rest/items//modify Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Modifies an existing file on the server. Requires specific permissions. ```APIDOC ## POST /apis/rest/items//modify ### Description Modifies an existing file on the Bepasty server. This operation may require specific user permissions. ### Method POST ### Endpoint /apis/rest/items//modify ### Parameters #### Path Parameters - **itemname** (string) - Required - The name of the item (file) to modify. ``` -------------------------------- ### POST /apis/rest/items//unlock Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Unlocks a specific file on the server, allowing further modifications. Requires specific permissions. ```APIDOC ## POST /apis/rest/items//unlock ### Description Unlocks a specific file on the Bepasty server, allowing further modifications. This operation may require specific user permissions. ### Method POST ### Endpoint /apis/rest/items//unlock ### Parameters #### Path Parameters - **itemname** (string) - Required - The name of the item (file) to unlock. ``` -------------------------------- ### Unlocking a file Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Unlocks a file specified by its item name. This operation requires administrator privileges. ```APIDOC ## POST /apis/rest/items//unlock ### Description Unlocks a file specified by ``. This operation requires administrator privileges. ### Method POST ### Endpoint /apis/rest/items//unlock ### Parameters #### Path Parameters - **itemname** (string) - Required - The itemname of the target file. ### Response #### Success Response (200) Indicates the file was successfully unlocked. #### Error Response Returns a non-200 status code if the file could not be unlocked. ``` -------------------------------- ### POST /apis/rest/items//delete Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Deletes a specific file from the server. Requires specific permissions. ```APIDOC ## POST /apis/rest/items//delete ### Description Deletes a specific file from the Bepasty server. This operation may require specific user permissions. ### Method POST ### Endpoint /apis/rest/items//delete ### Parameters #### Path Parameters - **itemname** (string) - Required - The name of the item (file) to delete. ``` -------------------------------- ### Unlock File Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Unlocks a specified file, allowing modifications. ```APIDOC ## POST /apis/rest/items//unlock ### Description Unlocks a specified file, allowing modifications. ### Method POST ### Endpoint /apis/rest/items//unlock ### Parameters #### Path Parameters - **itemname** (string) - Required - The itemname of the target file. ### Response #### Success Response (200) - Status code 200 indicates successful unlocking. ``` -------------------------------- ### POST /apis/rest/items//modify Source: https://bepasty-server.readthedocs.io/en/latest/rest.html Modifies an existing item on the server. ```APIDOC ## POST /apis/rest/items//modify ### Description Modifies an existing item on the Bepasty server. This might include updating metadata or content. ### Method POST ### Endpoint /apis/rest/items//modify ### Parameters #### Path Parameters - **itemname** (string) - Required - The name of the item to modify. ``` -------------------------------- ### File Upload POST Request Headers Source: https://bepasty-server.readthedocs.io/en/latest/_sources/rest.rst.txt Essential headers for uploading files via the REST API, including Content-Range and Transaction-ID for chunked uploads. Optional headers like Content-Type and Content-Filename can also be provided. ```http POST /apis/rest/items HTTP/1.1 Content-Range: bytes 0-1023/1048576 Transaction-ID: Content-Type: image/jpeg Content-Filename: my_image.jpg Maxlife-Unit: DAYS Maxlife-Value: 30 ```