Bepasty Server

repository·master·Indexed 42 days ago

https://github.com/bepasty/bepasty-server

A binary pastebin and file upload service designed to host code snippets and multimedia with granular permission controls and flexible storage backends. Includes a REST API for chunked uploads, a CLI for object management (bepasty-object), and support for production deployment using Gunicorn and Nginx.

Tokens
14K
Snippets
50
Records
71
Agent score
52%

What's inside Bepasty

  1. Overview of bepasty features

    master

    bepasty is a generic file-sharing service (similar to a pastebin) that supports text, images, audio, video, documents, and binary files.

    Key capabilities include:

    • Generic File Handling: Drag-and-drop multiple file uploads, unique view links for each file, metadata display, and the ability to bundle multiple files into a single pastebin link.
    • Text Support: Syntax highlighting via Pygments, line numbers, and line-specific anchors for direct linking.
    • Media Support: Browser-native rendering for images (including carousel/slideshow views), audio, video, and PDFs. It also supports .cast files via an asciinema player.
    • URL Shortening: Supports linking to or redirecting to external URLs.
    • Storage Management: Files can be purged based on age, inactivity, size, or type. It also supports consistency checks on storage.
    • Permissions: Granular control with roles including read, create, modify, delete, list, and admin. Permissions can be assigned to specific users (via login secrets) or to anonymous users.
  2. Understand Bepasty permissions

    master

    Permissions are assigned to specific login credentials or to anonymous (not logged-in) users. The available permission levels are:

    • create: Ability to create pastebins.
    • modify: Ability to modify existing pastebins.
    • read: Ability to read or download pastebins.
    • delete: Ability to delete pastebins.
    • list: Ability to list (discover) all pastebins. (Note: Granting this to everyone reduces privacy).
    • admin: Ability to lock/unlock files and perform actions even if an upload is incomplete or an item is locked.
  3. Verify file integrity using SHA256 hashes

    master

    Bepasty provides a SHA256 hash for every file. You can use this hash as a 'fingerprint' to ensure file integrity:

    • Post-upload: Compare the size and hash shown on Bepasty with your local file to confirm a successful upload.
    • Post-download: Compare the hash of your downloaded file with the hash shown on Bepasty.
    • End-to-end: Compare the hash of the file at the source (Location A) with the hash at the destination (Location C) to ensure no corruption occurred during the transfer via Bepasty.
  4. Configure bepasty storage backends

    master

    bepasty uses a storage backend API to manage file data and metadata.

    Currently, the following backends are available:

    • Filesystem Storage: The standard implementation. To use it, configure a filesystem directory where the server will store <uuid>.meta and <uuid>.data files.
    • Ceph Cluster Storage: A specialized implementation for Ceph. Note that this is currently not available in the master branch or official releases; it is maintained in the ceph-storage branch due to ongoing issues.
  5. Create the Gunicorn startup script

    master

    Create an executable shell script at /home/bepasty/bin/gunicorn_bepasty to manage the Gunicorn process. This script sets the BEPASTY_CONFIG environment variable and uses the gevent worker class.

    Ensure you make the script executable with chmod +x ~/bin/gunicorn_bepasty after creation.

    #!/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
  6. Start the Bepasty server

    master

    To run the Bepasty server with a specific configuration, set the BEPASTY_CONFIG environment variable to the absolute path of your configuration file.

    Development vs. Production: The built-in WSGI server is intended for development only. For production environments, use a production-grade WSGI server like Gunicorn, Apache + mod_wsgi, or Nginx + uWSU6.

    # Development (using built-in server)
    BEPASTY_CONFIG=/srv/bepasty/bepasty.conf bepasty-server
    
    # Production (using Gunicorn)
    gunicorn bepasty.wsgi
  7. Invoke Bepasty CLI commands

    master

    All Bepasty CLI commands require access to a configuration file. You can provide this either by using the --config <configfilename> argument or by setting the BEPASTY_CONFIG environment variable.

    Common commands include bepasty-object, which operates on objects in storage. Subcommands for bepasty-object include:

    • info: Get information about objects.
    • set: Set flags on objects.
    • purge: Remove objects based on criteria.
    • consistency: Check storage consistency.
    • migrate: Upgrade stored metadata to the current schema (required after upgrades).
    # Example: Purge objects (dry-run) that are >= 10MiB and >= 14 days old
    bepasty-object purge --dry-run --size 10 --age 14 '*'
    
    # Example: Migrate metadata after an upgrade
    bepasty-object migrate '*'
  8. Install Bepasty

    master

    You can install Bepasty from PyPI for the latest stable release, or directly from the Git repository for the latest available code. If you require MIME type detection via python-magic, install the [magic] extra.

    # from PyPI:
    pip install bepasty
    
    # with python-magic support:
    pip install bepasty[magic]
    
    # from Git repository:
    pip install -e git+https://github.com/bepasty/bepasty-server.git#egg=bepasty-server
  9. Paste text to Bepasty

    master

    To create a text paste:

    1. Enter your text into the large upper text input box.
    2. Content-Type: Optionally select a content type below the box to enable syntax highlighting (powered by Pygments). For example, typing pyt will suggest Python options.
    3. File name: Optionally provide a filename. If provided, browsers will use this name when downloading the file.
    4. Maximum lifetime: Set an expiration time after which the file will be automatically deleted.
    5. Click Submit. Bepasty will redirect you to a unique URL for your paste.
  10. Set up a local development environment for bepasty-server

    master

    To develop on bepasty-server, you should use a virtual environment and install the package in editable mode. This allows changes to the source code to take effect immediately without re-installing, and enables auto-reloading during development.

    Follow these steps:

    1. Create and activate a new virtual environment.
    2. Clone the repository.
    3. Install the package in editable mode using pip install -e ..
    4. Run the server in debug mode.
    # Create a new virtualenv
    virtualenv bepasty-server-env
    
    # Activate the virtualenv
    source bepasty-server-env/bin/activate
    
    # Clone the official bepasty-server
    git clone https://github.com/bepasty/bepasty-server.git
    cd bepasty-server
    
    # Install in editable mode (enables auto-reload and uses current directory)
    pip install -e .
    
    # Run the Bepasty server in debug mode
    bepasty-server --debug
  11. Log in to Bepasty using passwords

    master
    Bepasty uses a password-only authentication scheme. There are no separate usernames; your credential is simply a password or passphrase. To log in, obtain credentials from the site administrator. Your current permissions are displayed in the navigation bar of the web interface.