MCPcopy
hub / github.com/Gozargah/Marzban

github.com/Gozargah/Marzban @v0.8.4 sqlite

repository ↗ · DeepWiki ↗ · release v0.8.4 ↗
1,085 symbols 3,962 edges 343 files 172 documented · 16%
README

  <img width="160" height="160" src="https://github.com/Gozargah/Marzban-docs/raw/master/screenshots/logo-light.png">

Marzban

Unified GUI Censorship Resistant Solution Powered by <a href="https://github.com/XTLS/Xray-core">Xray</a>










<a href="#">
    <img src="https://img.shields.io/github/actions/workflow/status/gozargah/marzban/build.yml?style=flat-square" />
</a>
<a href="https://hub.docker.com/r/gozargah/marzban" target="_blank">
    <img src="https://img.shields.io/docker/pulls/gozargah/marzban?style=flat-square&logo=docker" />
</a>
<a href="#">
    <img src="https://img.shields.io/github/license/gozargah/marzban?style=flat-square" />
</a>
<a href="https://t.me/gozargah_marzban" target="_blank">
    <img src="https://img.shields.io/badge/telegram-group-blue?style=flat-square&logo=telegram" />
</a>
<a href="#">
    <img src="https://img.shields.io/badge/twitter-commiunity-blue?style=flat-square&logo=twitter" />
</a>
<a href="#">
    <img src="https://img.shields.io/github/stars/gozargah/marzban?style=social" />
</a>







<a href="https://github.com/Gozargah/Marzban/raw/v0.8.4/README.md">
English
</a>
/
<a href="https://github.com/Gozargah/Marzban/raw/v0.8.4/README-fa.md">
فارسی
</a>
/

简体中文 / Русский

Marzban screenshots

目录

概览

Marzban(Marzban一词源自波斯语,意为“边境警卫”,发音为 /mærz'ban/)是一个代理管理工具,提供简单易用的用户界面,可管理数百个代理账户,由 Xray-core 提供支持,使用 Python 和 Reactjs 构建。

为什么要使用 Marzban?

Marzban 是一个用户友好、功能丰富且可靠的工具。它让您可以为用户创建不同的代理,无需进行任何复杂的配置。通过其内置的 Web 界面,您可以监视、修改和限制用户。

特性

  • 内置 Web 界面
  • 完全支持 REST API 的后端
  • 支持 VmessVLESSTrojanShadowsocks 协议
  • 单用户的多协议支持
  • 单入站的多用户支持
  • 单端口的多入站支持(使用 fallbacks)
  • 流量过期日期限制
  • 周期性的流量限制(例如每天、每周等)
  • 兼容 V2ray订阅链接(例如 V2RayNG、SingBox、Nekoray 等)和 Clash
  • 自动化的分享链接二维码生成器
  • 系统监控和流量统计
  • 可自定义的 xray 配置
  • TLS 支持
  • 集成的 Telegram Bot
  • 多管理员支持(WIP)

安装指南

运行以下命令以使用 SQLite 数据库安装 Marzban。

sudo bash -c "$(curl -sL https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh)" @ install

运行以下命令以使用 MySQL 数据库安装 Marzban。

sudo bash -c "$(curl -sL https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh)" @ install --database mysql

运行以下命令以使用 MariaDB 数据库安装 Marzban。

sudo bash -c "$(curl -sL https://github.com/Gozargah/Marzban-scripts/raw/master/marzban.sh)" @ install --database mariadb

Once the installation is complete:

  • You will see the logs that you can stop watching them by closing the terminal or pressing Ctrl+C
  • The Marzban files will be located at /opt/marzban
  • The configuration file can be found at /opt/marzban/.env (refer to configurations section to see variables)
  • The data files will be placed at /usr/lib/marzban
  • For security reasons, the Marzban dashboard is not accessible via IP address. Therefore, you must obtain SSL certificate and access your Marzban dashboard by opening a web browser and navigating to https://YOUR_DOMAIN:8000/dashboard/ (replace YOUR_DOMAIN with your actual domain)
  • You can also use SSH port forwarding to access the Marzban dashboard locally without a domain. Replace user@serverip with your actual SSH username and server IP and Run the command below:
ssh -L 8000:localhost:8000 user@serverip

Finally, you can enter the following link in your browser to access your Marzban dashboard:

http://localhost:8000/dashboard/

You will lose access to the dashboard as soon as you close the SSH terminal. Therefore, this method is recommended only for testing purposes.

Next, you need to create a sudo admin for logging into the Marzban dashboard by the following command

marzban cli admin create --sudo

That's it! You can login to your dashboard using these credentials

To see the help message of the Marzban script, run the following command

marzban --help

If you are eager to run the project using the source code, check the section below

手动安装(高级)

在您的机器上安装 xray

您可以使用 Xray-install 脚本进行安装:

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

克隆项目并安装依赖项。

您需要 Python>=3.8 版本。

git clone https://github.com/Gozargah/Marzban.git
cd Marzban
wget -qO- https://bootstrap.pypa.io/get-pip.py | python3 -
python3 -m pip install -r requirements.txt

另外,为了拥有一个隔离的环境,您可以使用 Python Virtualenv

然后运行以下命令运行数据库迁移脚本:

alembic upgrade head

现在开始配置:

复制 .env.example 文件,查看并使用文本编辑器(如nano)进行编辑。

您可能想要修改管理员凭据。

cp .env.example .env
nano .env

请查看配置部分以获取更多信息。

最终,使用以下命令启动应用程序:

python3 main.py

也可使用 linux systemctl 启动:

systemctl enable /var/lib/marzban/marzban.service
systemctl start marzban

配合 nginx 使用:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name  example.com;

    ssl_certificate      /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem;

    location ~* /(dashboard|statics|sub|api|docs|redoc|openapi.json) {
        proxy_pass http://0.0.0.0:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    # xray-core ws-path: /
    # client ws-path: /marzban/me/2087
    #
    # 所有流量通过 443 端口进行代理,然后分发至真正的 xray 端口(2087、2088 等等)。
    # 路径中的 “/marzban” 可以改为任意合法 URL 字符.
    #
    # /${path}/${username}/${xray-port}
    location ~* /marzban/.+/(.+)$ {
        proxy_redirect off;
        proxy_pass http://127.0.0.1:$1/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name  marzban.example.com;

    ssl_certificate      /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass http://0.0.0.0:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

默认情况下,应用将在 http://localhost:8000/dashboard 上运行。您可以通过更改 UVICORN_HOSTUVICORN_PORT 环境变量来进行配置。

配置

您可以使用环境变量或将其放置在 env.env 文件中来设置以下设置。

变量 描述
SUDO_USERNAME 管理员用户名(默认: admin)
SUDO_PASSWORD 管理员密码(默认: admin)
SQLALCHEMY_DATABASE_URL 数据库文档(SQLAlchemy's docs
UVICORN_HOST 绑定应用程序到此主机(默认为 0.0.0.0
UVICORN_PORT 绑定应用程序到此端口(默认为 8000
UVICORN_UDS 将应用程序绑定到一个 UNIX 域套接字
UVICORN_SSL_CERTFILE SSL 证书文件路径
UVICORN_SSL_KEYFILE SSL 密钥文件路径
UVICORN_SSL_CA_TYPE 授权 SSL 证书的类型。使用“private”来测试自签名 CA(默认值:public
XRAY_JSON Xray 的 json 配置文件路径(默认: xray_config.json
XRAY_EXECUTABLE_PATH Xray 的执行程序路径: /usr/local/bin/xray
XRAY_ASSETS_PATH Xray 的资源目录: /usr/local/share/xray
XRAY_SUBSCRIPTION_URL_PREFIX 订阅URL的前缀
XRAY_FALLBACKS_INBOUND_TAG 包含 fallbacks 的入站标记, 在您需要使用 fallbacks 配置此项
XRAY_EXCLUDE_INBOUND_TAGS 不需要此应用程序管理或在链接中包含的入站标记
CLASH_SUBSCRIPTION_TEMPLATE 将用于生成冲突配置的模板(默认值:clash/default.yml
SUBSCRIPTION_PAGE_TEMPLATE 用于生成订阅信息页面的模板(默认:subscription/index.html
HOME_PAGE_TEMPLATE 诱饵页面模板(默认:home/index.html
TELEGRAM_API_TOKEN Telegram bot API 令牌(可以从 @botfather 获取)
TELEGRAM_ADMIN_ID 管理员的 Telegram ID(可以使用 @userinfobot 查找您的 ID)
TELEGRAM_PROXY_URL 在代理下运行 Telegram bot。
JWT_ACCESS_TOKEN_EXPIRE_MINUTES Access Tokens 的过期时间,以分钟为单位,0 表示无限期(默认为 1440 分钟)
DOCS API 文档是否应该在 /docs/redoc 上提供(默认为 False
DEBUG Debug mode for development (default: False)
WEBHOOK_ADDRESS Webhook address to send notifications to. Webhook notifications will be sent if this value was set.
WEBHOOK_SECRET Webhook secret will be sent with each request as x-webhook-secret in the header (default: None)
NUMBER_OF_RECURRENT_NOTIFICATIONS How many times to retry if an error detected in sending a notification (default: 3)
RECURRENT_NOTIFICATIONS_TIMEOUT Timeout between each retry if an error detected in sending a notification in seconds (default: 180)
NOTIFY_REACHED_USAGE_PERCENT At which percentage of usage to send the warning notification (default: 80)
NOTIFY_DAYS_LEFT When to send warning notifaction about expiration (default: 3)
USERS_AUTODELETE_DAYS Delete expired (and optionally limited users) after this many days (Negative values disable this feature, default: -1)
USER_AUTODELETE_INCLUDE_LIMITED_ACCOUNTS Weather to include limited accounts in the auto-delete feature (default: False)
USE_CUSTOM_JSON_DEFAULT Enable custom JSON config for ALL supported clients (default: False)
USE_CUSTOM_JSON_FOR_V2RAYNG Enable custom JSON config only for V2rayNG (default: False)
USE_CUSTOM_JSON_FOR_STREISAND Enable custom JSON config only for Streisand (default: False)
USE_CUSTOM_JSON_FOR_V2RAYN Enable custom JSON config only for V2rayN (default: False)

Extension points exported contracts — how you extend this code

CustomTypeOptions (Interface)
(no doc)
app/dashboard/src/locales/i18n.ts

Core symbols most depended-on inside this repo

get
called by 372
app/utils/store.py
schedule_delete_message
called by 74
app/telegram/handlers/admin.py
add
called by 60
app/subscription/v2ray.py
set
called by 54
app/utils/store.py
readable_size
called by 50
app/utils/system.py
values
called by 33
app/utils/store.py
update
called by 31
app/utils/store.py
cleanup_messages
called by 18
app/telegram/handlers/admin.py

Shape

Function 584
Method 289
Class 153
Route 58
Interface 1

Languages

Python88%
TypeScript12%

Modules by API surface

app/db/crud.py57 symbols
app/telegram/handlers/admin.py53 symbols
app/xray/node.py45 symbols
app/subscription/v2ray.py33 symbols
app/models/user.py32 symbols
app/routers/user.py28 symbols
app/models/proxy.py23 symbols
app/utils/store.py21 symbols
app/routers/admin.py21 symbols
app/db/models.py21 symbols
app/routers/node.py19 symbols
xray_api/proto/app/router/command/command_pb2_grpc.py17 symbols

Dependencies from manifests, versioned

@chakra-ui/cli2.3.0 · 1×
@chakra-ui/react2.5.5 · 1×
@emotion/react11.10.5 · 1×
@emotion/styled11.10.5 · 1×
@heroicons/react2.0.12 · 1×
@hookform/resolvers2.9.10 · 1×
@types/jsoneditor9.9.0 · 1×
@types/lodash.debounce4.0.7 · 1×
@types/react18.0.17 · 1×
@types/react-copy-to-clipboard5.0.4 · 1×
@types/react-datepicker4.8.0 · 1×
@types/react-dom18.0.6 · 1×

For agents

$ claude mcp add Marzban \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact