带登录认证的安全文件服务器
Project description
File Server
带登录认证的安全文件服务器。
功能特性
- 用户认证系统 - 基于用户名/密码的登录认证,使用 bcrypt 加密存储密码
- 会话管理 - 基于 Cookie 的安全会话机制,1小时超时
- 文件浏览 - 目录列表功能,分开展示 HTML 文件和其他文件
- 文件下载 - 支持任意文件下载,显示文件大小
- 用户管理 - 创建、删除、修改用户密码
安全特性
- bcrypt 密码加密(rounds=12)
- 安全会话 ID(secrets.token_hex)
- HttpOnly + SameSite Cookie
- 会话超时机制
- 访问控制(未认证用户重定向到登录页)
安装
pip install file-server
或使用 pipx 安装(推荐):
pipx install file-server
使用方法
1. 创建用户
file-server user create
# 或指定用户名
file-server user create -u admin
2. 启动服务器
file-server
# 或指定端口
file-server -p 9000
命令行参数
| 参数 | 说明 | 默认值 |
|---|---|---|
-p, --port |
服务器端口 | 8000 |
-d, --directory |
文件服务目录 | 当前目录 |
-c, --config-dir |
配置文件目录 | 脚本目录 |
-s, --static-dir |
静态文件目录 | 脚本目录 |
用户管理命令
# 创建用户
file-server user create [-u 用户名]
# 列出用户
file-server user list
# 删除用户
file-server user delete [-u 用户名]
# 修改密码
file-server user passwd [-u 用户名]
示例
# 在端口 9000 启动服务器
file-server -p 9000
# 指定文件服务目录
file-server -d /path/to/files
# 自定义配置和静态文件目录
file-server -c /etc/file-server -s /var/www/files
访问
启动后访问 http://localhost:8000 或局域网 IP 地址。
项目结构
file-server/
├── src/file_server/
│ ├── __init__.py # 包入口
│ ├── __main__.py # CLI 入口
│ ├── config.py # 配置模块
│ ├── auth.py # 认证模块
│ ├── templates.py # HTML 模板
│ ├── handlers.py # HTTP 处理器
│ ├── server.py # 服务器启动
│ └── cli.py # 命令行工具
├── tests/
│ ├── test_auth.py # 认证模块测试
│ └── test_config.py # 配置模块测试
├── users.json # 用户数据存储
├── pyproject.toml # 项目配置
└── README.md # 文档
开发与发布
安装开发依赖
pip install -e ".[test]"
运行测试
pytest tests/ -v
构建
pip install build
python -m build
发布到 TestPyPI
pip install twine
python -m twine upload --repository testpypi dist/*
发布到 PyPI
python -m twine upload dist/*
要求
- Python >= 3.13
- bcrypt >= 5.0.0
许可证
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyfileserv-0.2.2.tar.gz
(21.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfileserv-0.2.2.tar.gz.
File metadata
- Download URL: pyfileserv-0.2.2.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e308e9edebb82df2732d9a655220c82d1bde64a3397bce6be812963a9b05ea3
|
|
| MD5 |
aeb69bdbdaa18f542452ea1451d1db7d
|
|
| BLAKE2b-256 |
4484b1c89ab8a7c599a09629f953bb6b739a532f6f4b1b4359a8ed8d699da601
|
File details
Details for the file pyfileserv-0.2.2-py3-none-any.whl.
File metadata
- Download URL: pyfileserv-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
125bb318c13563c40fbb0521a9e1a65fd5f41bb55c1c8659622283a259dd4a84
|
|
| MD5 |
1d015e5ddc975b2a837fac260b240ff7
|
|
| BLAKE2b-256 |
2ee3c40b02cea1ec47eb3e34e0f19643b0831a493c1cab623bbe6c7060bff017
|