Skip to content

Navigation Menu

Sign in
Sign up

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

πŸ” Auth File Server

A lightweight, password-protected HTTP file server written in Python.
It serves directory listings, supports a public folder with redirect behavior, hides hidden files, and is fully configurable via a .env file.


πŸš€ Features

  • πŸ”’ Basic authentication with SHA256 password hashing
  • πŸ“ Directory listing (excluding hidden files)
  • 🌐 Public folder that does not show directory index
  • πŸ” Public folder can optionally redirect to a URL
  • πŸ”„ Configurable file transfer method: copyfile or sendfile
  • βš™οΈ .env support for clean configuration
  • 🧡 Threaded server for concurrent downloads
  • πŸ“¦ Docker and systemd compatible
  • πŸ§ͺ Interactive setup with --set-user and --set-pass

πŸ“¦ Requirements

Install with:

pip3 install python-dotenv

βš™οΈ Configuration

Create a .env file in the same directory as auth_server.py:

AUTH_USERNAME=peoriait
AUTH_PASSWORD_HASH=<your_sha256_hash>
AUTH_PORT=8080
AUTH_PUBLIC_DIR=public
AUTH_SERVE_DIR=.
AUTH_PUBLIC_REDIRECT=https://www.peoriait.com
TRANSFER_METHOD=copyfile

πŸ” Password Hashing

To create a password hash:

python3 auth_server.py --set-user

Or to just update the password:

python3 auth_server.py --set-pass

This safely hashes the password and updates your .env.


πŸƒ Usage

Start the server:

python3 auth_server.py

Serve from a different port or public directory:

python3 auth_server.py --port 9090 --public-dir media

🚧 Public Folder Behavior

  • Files inside the public folder do not require authentication
  • Directories inside it are not listed
  • Accessing the folder root (e.g. /public/) redirects to AUTH_PUBLIC_REDIRECT

⚑ Transfer Method

You can choose between two file transfer methods:

Method Description Recommended when...
copyfile Buffered transfer (safe, default) βœ… Portable and stable everywhere
sendfile Zero-copy OS syscall (faster) ⚠️ High-performance, but may fail in LXC

Set in .env:

TRANSFER_METHOD=copyfile

πŸ§ͺ Testing Speed

To test raw performance of the server, try curl or wget:

curl -O http://<host>:<port>/<filename>

🐳 Docker (Optional)

If you'd like to run this with Docker Compose:

version: '3.8'
services:
 auth-server:
 image: python:3
 working_dir: /app
 volumes:
 - ./auth_server.py:/app/auth_server.py
 - ./files:/app/files
 - ./public:/app/files/public
 - ./auth.env:/app/.env
 ports:
 - "8080:8080"
 command: python3 auth_server.py

πŸ–₯ systemd Service (Linux)

You can also run this as a service. Create a systemd file like:

[Unit]
Description=Python Auth File Server
After=network.target
[Service]
ExecStart=/usr/bin/python3 /opt/auth-server/auth_server.py
WorkingDirectory=/opt/auth-server
EnvironmentFile=/opt/auth-server/.env
Restart=always
[Install]
WantedBy=multi-user.target

Enable with:

sudo systemctl daemon-reexec
sudo systemctl enable --now auth-server

πŸ›‘ Security Notes

  • All credentials are stored in .env β€” protect it like a password
  • SHA256 is used for password hashing, not bcrypt (for simplicity)
  • No HTTPS built-in β€” use a reverse proxy (like Nginx) for encryption

πŸ™Œ Credits

Built with ❀️ by PeoriaIT.


πŸ“œ License

MIT

About

A lightweight, password-protected HTTP file server written in Python. It serves directory listings, supports a public folder with redirect behavior, hides hidden files, and is fully configurable via a .env file.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /