From fe75ea44b7f6679108475c4d3d5907dfe7bff8f0 Mon Sep 17 00:00:00 2001 From: Alexander Kraev Date: Tue, 22 Jul 2025 01:38:02 +0300 Subject: [PATCH] add vpn filter --- README.ar_EG.md | 14 ++-- README.es_ES.md | 12 +-- README.fa_IR.md | 12 +-- README.md | 12 +-- README.ru_RU.md | 12 +-- README.zh_CN.md | 12 +-- database/db.go | 1 + database/model/model.go | 8 ++ install.sh | 8 +- web/controller/blocked_domain.go | 78 ++++++++++++++++++ web/controller/xui.go | 5 ++ web/html/blocked_domains.html | 132 +++++++++++++++++++++++++++++++ web/html/component/aSidebar.html | 5 ++ web/service/blocked_domain.go | 41 ++++++++++ web/service/xray.go | 23 ++++++ web/web.go | 1 + x-ui.sh | 10 +-- 17 files changed, 340 insertions(+), 46 deletions(-) create mode 100644 web/controller/blocked_domain.go create mode 100644 web/html/blocked_domains.html create mode 100644 web/service/blocked_domain.go diff --git a/README.ar_EG.md b/README.ar_EG.md index d2f6dcc3..44330b27 100644 --- a/README.ar_EG.md +++ b/README.ar_EG.md @@ -7,10 +7,10 @@

-[![](https://img.shields.io/github/v/release/mhsanaei/3x-ui.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases) -[![](https://img.shields.io/github/actions/workflow/status/mhsanaei/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/actions) -[![GO Version](https://img.shields.io/github/go-mod/go-version/mhsanaei/3x-ui.svg?style=for-the-badge)](#) -[![Downloads](https://img.shields.io/github/downloads/mhsanaei/3x-ui/total.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases/latest) +[![](https://img.shields.io/github/v/release/c-villain/3x-ui.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases) +[![](https://img.shields.io/github/actions/workflow/status/c-villain/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/actions) +[![GO Version](https://img.shields.io/github/go-mod/go-version/c-villain/3x-ui.svg?style=for-the-badge)](#) +[![Downloads](https://img.shields.io/github/downloads/c-villain/3x-ui/total.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases/latest) [![License](https://img.shields.io/badge/license-GPL%20V3-blue.svg?longCache=true&style=for-the-badge)](https://www.gnu.org/licenses/gpl-3.0.en.html) **3X-UI** — لوحة تحكم متقدمة مفتوحة المصدر تعتمد على الويب مصممة لإدارة خادم Xray-core. توفر واجهة سهلة الاستخدام لتكوين ومراقبة بروتوكولات VPN والوكيل المختلفة. @@ -23,10 +23,10 @@ ## البدء السريع ``` -bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) +bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/master/install.sh) ``` -للحصول على الوثائق الكاملة، يرجى زيارة [ويكي المشروع](https://github.com/MHSanaei/3x-ui/wiki). +للحصول على الوثائق الكاملة، يرجى زيارة [ويكي المشروع](https://github.com/c-villain/3x-ui/wiki). ## شكر خاص إلى @@ -53,4 +53,4 @@ bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install. ## النجوم عبر الزمن -[![Stargazers over time](https://starchart.cc/MHSanaei/3x-ui.svg?variant=adaptive)](https://starchart.cc/MHSanaei/3x-ui) +[![Stargazers over time](https://starchart.cc/c-villain/3x-ui.svg?variant=adaptive)](https://starchart.cc/c-villain/3x-ui) diff --git a/README.es_ES.md b/README.es_ES.md index 52625664..3c8b2e59 100644 --- a/README.es_ES.md +++ b/README.es_ES.md @@ -7,10 +7,10 @@

-[![](https://img.shields.io/github/v/release/mhsanaei/3x-ui.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases) -[![](https://img.shields.io/github/actions/workflow/status/mhsanaei/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/actions) -[![GO Version](https://img.shields.io/github/go-mod/go-version/mhsanaei/3x-ui.svg?style=for-the-badge)](#) -[![Downloads](https://img.shields.io/github/downloads/mhsanaei/3x-ui/total.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases/latest) +[![](https://img.shields.io/github/v/release/c-villain/3x-ui.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases) +[![](https://img.shields.io/github/actions/workflow/status/c-villain/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/actions) +[![GO Version](https://img.shields.io/github/go-mod/go-version/c-villain/3x-ui.svg?style=for-the-badge)](#) +[![Downloads](https://img.shields.io/github/downloads/c-villain/3x-ui/total.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases/latest) [![License](https://img.shields.io/badge/license-GPL%20V3-blue.svg?longCache=true&style=for-the-badge)](https://www.gnu.org/licenses/gpl-3.0.en.html) **3X-UI** — panel de control avanzado basado en web de código abierto diseñado para gestionar el servidor Xray-core. Ofrece una interfaz fácil de usar para configurar y monitorear varios protocolos VPN y proxy. @@ -23,10 +23,10 @@ Como una versión mejorada del proyecto X-UI original, 3X-UI proporciona mayor e ## Inicio Rápido ``` -bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) +bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/master/install.sh) ``` -Para documentación completa, visita la [Wiki del proyecto](https://github.com/MHSanaei/3x-ui/wiki). +Para documentación completa, visita la [Wiki del proyecto](https://github.com/c-villain/3x-ui/wiki). ## Un Agradecimiento Especial a diff --git a/README.fa_IR.md b/README.fa_IR.md index 2b2dc5ec..8888ffd2 100644 --- a/README.fa_IR.md +++ b/README.fa_IR.md @@ -7,10 +7,10 @@

-[![](https://img.shields.io/github/v/release/mhsanaei/3x-ui.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases) -[![](https://img.shields.io/github/actions/workflow/status/mhsanaei/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/actions) -[![GO Version](https://img.shields.io/github/go-mod/go-version/mhsanaei/3x-ui.svg?style=for-the-badge)](#) -[![Downloads](https://img.shields.io/github/downloads/mhsanaei/3x-ui/total.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases/latest) +[![](https://img.shields.io/github/v/release/c-villain/3x-ui.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases) +[![](https://img.shields.io/github/actions/workflow/status/c-villain/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/actions) +[![GO Version](https://img.shields.io/github/go-mod/go-version/c-villain/3x-ui.svg?style=for-the-badge)](#) +[![Downloads](https://img.shields.io/github/downloads/c-villain/3x-ui/total.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases/latest) [![License](https://img.shields.io/badge/license-GPL%20V3-blue.svg?longCache=true&style=for-the-badge)](https://www.gnu.org/licenses/gpl-3.0.en.html) **3X-UI** — یک پنل کنترل پیشرفته مبتنی بر وب با کد باز که برای مدیریت سرور Xray-core طراحی شده است. این پنل یک رابط کاربری آسان برای پیکربندی و نظارت بر پروتکل‌های مختلف VPN و پراکسی ارائه می‌دهد. @@ -23,10 +23,10 @@ ## شروع سریع ``` -bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) +bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/master/install.sh) ``` -برای مستندات کامل، لطفاً به [ویکی پروژه](https://github.com/MHSanaei/3x-ui/wiki) مراجعه کنید. +برای مستندات کامل، لطفاً به [ویکی پروژه](https://github.com/c-villain/3x-ui/wiki) مراجعه کنید. ## تشکر ویژه از diff --git a/README.md b/README.md index 7cda8370..5cfd2cf6 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@

-[![](https://img.shields.io/github/v/release/mhsanaei/3x-ui.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases) -[![](https://img.shields.io/github/actions/workflow/status/mhsanaei/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/actions) -[![GO Version](https://img.shields.io/github/go-mod/go-version/mhsanaei/3x-ui.svg?style=for-the-badge)](#) -[![Downloads](https://img.shields.io/github/downloads/mhsanaei/3x-ui/total.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases/latest) +[![](https://img.shields.io/github/v/release/c-villain/3x-ui.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases) +[![](https://img.shields.io/github/actions/workflow/status/c-villain/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/actions) +[![GO Version](https://img.shields.io/github/go-mod/go-version/c-villain/3x-ui.svg?style=for-the-badge)](#) +[![Downloads](https://img.shields.io/github/downloads/c-villain/3x-ui/total.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases/latest) [![License](https://img.shields.io/badge/license-GPL%20V3-blue.svg?longCache=true&style=for-the-badge)](https://www.gnu.org/licenses/gpl-3.0.en.html) **3X-UI** — advanced, open-source web-based control panel designed for managing Xray-core server. It offers a user-friendly interface for configuring and monitoring various VPN and proxy protocols. @@ -23,10 +23,10 @@ As an enhanced fork of the original X-UI project, 3X-UI provides improved stabil ## Quick Start ```bash -bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) +bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/master/install.sh) ``` -For full documentation, please visit the [project Wiki](https://github.com/MHSanaei/3x-ui/wiki). +For full documentation, please visit the [project Wiki](https://github.com/c-villain/3x-ui/wiki). ## A Special Thanks to diff --git a/README.ru_RU.md b/README.ru_RU.md index d971f403..265d8b93 100644 --- a/README.ru_RU.md +++ b/README.ru_RU.md @@ -7,10 +7,10 @@

-[![](https://img.shields.io/github/v/release/mhsanaei/3x-ui.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases) -[![](https://img.shields.io/github/actions/workflow/status/mhsanaei/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/actions) -[![GO Version](https://img.shields.io/github/go-mod/go-version/mhsanaei/3x-ui.svg?style=for-the-badge)](#) -[![Downloads](https://img.shields.io/github/downloads/mhsanaei/3x-ui/total.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases/latest) +[![](https://img.shields.io/github/v/release/c-villain/3x-ui.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases) +[![](https://img.shields.io/github/actions/workflow/status/c-villain/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/actions) +[![GO Version](https://img.shields.io/github/go-mod/go-version/c-villain/3x-ui.svg?style=for-the-badge)](#) +[![Downloads](https://img.shields.io/github/downloads/c-villain/3x-ui/total.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases/latest) [![License](https://img.shields.io/badge/license-GPL%20V3-blue.svg?longCache=true&style=for-the-badge)](https://www.gnu.org/licenses/gpl-3.0.en.html) **3X-UI** — продвинутая панель управления с открытым исходным кодом на основе веб-интерфейса, разработанная для управления сервером Xray-core. Предоставляет удобный интерфейс для настройки и мониторинга различных VPN и прокси-протоколов. @@ -23,10 +23,10 @@ ## Быстрый старт ``` -bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) +bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/master/install.sh) ``` -Полную документацию смотрите в [вики проекта](https://github.com/MHSanaei/3x-ui/wiki). +Полную документацию смотрите в [вики проекта](https://github.com/c-villain/3x-ui/wiki). ## Особая благодарность diff --git a/README.zh_CN.md b/README.zh_CN.md index 75e75603..f380aaeb 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -7,10 +7,10 @@

-[![](https://img.shields.io/github/v/release/mhsanaei/3x-ui.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases) -[![](https://img.shields.io/github/actions/workflow/status/mhsanaei/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/actions) -[![GO Version](https://img.shields.io/github/go-mod/go-version/mhsanaei/3x-ui.svg?style=for-the-badge)](#) -[![Downloads](https://img.shields.io/github/downloads/mhsanaei/3x-ui/total.svg?style=for-the-badge)](https://github.com/MHSanaei/3x-ui/releases/latest) +[![](https://img.shields.io/github/v/release/c-villain/3x-ui.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases) +[![](https://img.shields.io/github/actions/workflow/status/c-villain/3x-ui/release.yml.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/actions) +[![GO Version](https://img.shields.io/github/go-mod/go-version/c-villain/3x-ui.svg?style=for-the-badge)](#) +[![Downloads](https://img.shields.io/github/downloads/c-villain/3x-ui/total.svg?style=for-the-badge)](https://github.com/c-villain/3x-ui/releases/latest) [![License](https://img.shields.io/badge/license-GPL%20V3-blue.svg?longCache=true&style=for-the-badge)](https://www.gnu.org/licenses/gpl-3.0.en.html) **3X-UI** — 一个基于网页的高级开源控制面板,专为管理 Xray-core 服务器而设计。它提供了用户友好的界面,用于配置和监控各种 VPN 和代理协议。 @@ -23,10 +23,10 @@ ## 快速开始 ``` -bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh) +bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/master/install.sh) ``` -完整文档请参阅 [项目Wiki](https://github.com/MHSanaei/3x-ui/wiki)。 +完整文档请参阅 [项目Wiki](https://github.com/c-villain/3x-ui/wiki)。 ## 特别感谢 diff --git a/database/db.go b/database/db.go index c72d28cf..1992a993 100644 --- a/database/db.go +++ b/database/db.go @@ -35,6 +35,7 @@ func initModels() error { &model.InboundClientIps{}, &xray.ClientTraffic{}, &model.HistoryOfSeeders{}, + &model.BlockedDomain{}, } for _, model := range models { if err := db.AutoMigrate(model); err != nil { diff --git a/database/model/model.go b/database/model/model.go index 2e7095d3..230a32d0 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -105,3 +105,11 @@ type Client struct { Comment string `json:"comment" form:"comment"` Reset int `json:"reset" form:"reset"` } + +type BlockedDomain struct { + Id int `json:"id" gorm:"primaryKey;autoIncrement"` + Domain string `json:"domain" gorm:"unique;not null"` + Comment string `json:"comment"` + CreatedAt int64 `json:"createdAt" gorm:"autoCreateTime:milli"` + UpdatedAt int64 `json:"updatedAt" gorm:"autoUpdateTime:milli"` +} diff --git a/install.sh b/install.sh index 30a0f688..94d786e7 100644 --- a/install.sh +++ b/install.sh @@ -145,13 +145,13 @@ install_x-ui() { cd /usr/local/ if [ $# == 0 ]; then - tag_version=$(curl -Ls "https://api.github.com/repos/MHSanaei/3x-ui/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + tag_version=$(curl -Ls "https://api.github.com/repos/c-villain/3x-ui/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') if [[ ! -n "$tag_version" ]]; then echo -e "${red}Failed to fetch x-ui version, it may be due to GitHub API restrictions, please try it later${plain}" exit 1 fi echo -e "Got x-ui latest version: ${tag_version}, beginning the installation..." - wget -N -O /usr/local/x-ui-linux-$(arch).tar.gz https://github.com/MHSanaei/3x-ui/releases/download/${tag_version}/x-ui-linux-$(arch).tar.gz + wget -N -O /usr/local/x-ui-linux-$(arch).tar.gz https://github.com/c-villain/3x-ui/releases/download/${tag_version}/x-ui-linux-$(arch).tar.gz if [[ $? -ne 0 ]]; then echo -e "${red}Downloading x-ui failed, please be sure that your server can access GitHub ${plain}" exit 1 @@ -166,7 +166,7 @@ install_x-ui() { exit 1 fi - url="https://github.com/MHSanaei/3x-ui/releases/download/${tag_version}/x-ui-linux-$(arch).tar.gz" + url="https://github.com/c-villain/3x-ui/releases/download/${tag_version}/x-ui-linux-$(arch).tar.gz" echo -e "Beginning to install x-ui $1" wget -N -O /usr/local/x-ui-linux-$(arch).tar.gz ${url} if [[ $? -ne 0 ]]; then @@ -193,7 +193,7 @@ install_x-ui() { chmod +x x-ui bin/xray-linux-$(arch) cp -f x-ui.service /etc/systemd/system/ - wget -O /usr/bin/x-ui https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.sh + wget -O /usr/bin/x-ui https://raw.githubusercontent.com/c-villain/3x-ui/main/x-ui.sh chmod +x /usr/local/x-ui/x-ui.sh chmod +x /usr/bin/x-ui config_after_install diff --git a/web/controller/blocked_domain.go b/web/controller/blocked_domain.go new file mode 100644 index 00000000..f4e3c986 --- /dev/null +++ b/web/controller/blocked_domain.go @@ -0,0 +1,78 @@ +package controller + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "x-ui/database/model" + "x-ui/web/service" +) + +type BlockedDomainController struct { + service *service.BlockedDomainService +} + +func NewBlockedDomainController(g *gin.RouterGroup) *BlockedDomainController { + ctrl := &BlockedDomainController{service: &service.BlockedDomainService{}} + r := g.Group("/blocked-domains") + r.GET("/", ctrl.List) + r.POST("/", ctrl.Create) + r.PUT("/:id", ctrl.Update) + r.DELETE("/:id", ctrl.Delete) + return ctrl +} + +func (ctrl *BlockedDomainController) List(c *gin.Context) { + domains, err := ctrl.service.GetAll() + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{"success": true, "obj": domains}) +} + +func (ctrl *BlockedDomainController) Create(c *gin.Context) { + var domain model.BlockedDomain + if err := c.ShouldBindJSON(&domain); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"success": false, "msg": err.Error()}) + return + } + if err := ctrl.service.Create(&domain); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{"success": true, "obj": domain}) +} + +func (ctrl *BlockedDomainController) Update(c *gin.Context) { + id, err := strconv.Atoi(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"success": false, "msg": "invalid id"}) + return + } + var domain model.BlockedDomain + if err := c.ShouldBindJSON(&domain); err != nil { + c.JSON(http.StatusBadRequest, gin.H{"success": false, "msg": err.Error()}) + return + } + domain.Id = id + if err := ctrl.service.Update(&domain); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{"success": true, "obj": domain}) +} + +func (ctrl *BlockedDomainController) Delete(c *gin.Context) { + id, err := strconv.Atoi(c.Param("id")) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"success": false, "msg": "invalid id"}) + return + } + if err := ctrl.service.Delete(id); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) + return + } + c.JSON(http.StatusOK, gin.H{"success": true}) +} \ No newline at end of file diff --git a/web/controller/xui.go b/web/controller/xui.go index 5b4c0a18..8d2b998f 100644 --- a/web/controller/xui.go +++ b/web/controller/xui.go @@ -26,6 +26,7 @@ func (a *XUIController) initRouter(g *gin.RouterGroup) { g.GET("/inbounds", a.inbounds) g.GET("/settings", a.settings) g.GET("/xray", a.xraySettings) + g.GET("/blocked-domains", a.blockedDomains) a.inboundController = NewInboundController(g) a.settingController = NewSettingController(g) @@ -47,3 +48,7 @@ func (a *XUIController) settings(c *gin.Context) { func (a *XUIController) xraySettings(c *gin.Context) { html(c, "xray.html", "pages.xray.title", nil) } + +func (a *XUIController) blockedDomains(c *gin.Context) { + html(c, "blocked_domains.html", "menu.blocked_domains", nil) +} diff --git a/web/html/blocked_domains.html b/web/html/blocked_domains.html new file mode 100644 index 00000000..cc4f1bb6 --- /dev/null +++ b/web/html/blocked_domains.html @@ -0,0 +1,132 @@ +{{define "page/blocked_domains"}} + + +{{end}} \ No newline at end of file diff --git a/web/html/component/aSidebar.html b/web/html/component/aSidebar.html index b69c8f3f..c7ff037a 100644 --- a/web/html/component/aSidebar.html +++ b/web/html/component/aSidebar.html @@ -64,6 +64,11 @@ icon: 'tool', title: '{{ i18n "menu.xray"}}' }, + { + key: '{{ .base_path }}panel/blocked-domains', + icon: 'stop', + title: 'Запрещённые сайты' + }, { key: '{{ .base_path }}logout/', icon: 'logout', diff --git a/web/service/blocked_domain.go b/web/service/blocked_domain.go new file mode 100644 index 00000000..065061ae --- /dev/null +++ b/web/service/blocked_domain.go @@ -0,0 +1,41 @@ +package service + +import ( + "x-ui/database" + "x-ui/database/model" + "gorm.io/gorm" +) + +type BlockedDomainService struct{} + +func (s *BlockedDomainService) GetAll() ([]model.BlockedDomain, error) { + db := database.GetDB() + var domains []model.BlockedDomain + err := db.Find(&domains).Error + return domains, err +} + +func (s *BlockedDomainService) GetByID(id int) (*model.BlockedDomain, error) { + db := database.GetDB() + var domain model.BlockedDomain + err := db.First(&domain, id).Error + if err != nil { + return nil, err + } + return &domain, nil +} + +func (s *BlockedDomainService) Create(domain *model.BlockedDomain) error { + db := database.GetDB() + return db.Create(domain).Error +} + +func (s *BlockedDomainService) Update(domain *model.BlockedDomain) error { + db := database.GetDB() + return db.Save(domain).Error +} + +func (s *BlockedDomainService) Delete(id int) error { + db := database.GetDB() + return db.Delete(&model.BlockedDomain{}, id).Error +} \ No newline at end of file diff --git a/web/service/xray.go b/web/service/xray.go index 40de5305..20356eb9 100644 --- a/web/service/xray.go +++ b/web/service/xray.go @@ -7,6 +7,7 @@ import ( "x-ui/logger" "x-ui/xray" + "x-ui/web/service" "go.uber.org/atomic" ) @@ -72,6 +73,28 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) { return nil, err } + // --- Блокировка запрещённых доменов --- + blockedDomains, err := service.BlockedDomainService{}.GetAll() + if err == nil && len(blockedDomains) > 0 { + var domains []string + for _, d := range blockedDomains { + domains = append(domains, d.Domain) + } + var routing map[string]any + if err := json.Unmarshal(xrayConfig.RouterConfig, &routing); err == nil { + rules, _ := routing["rules"].([]any) + blockRule := map[string]any{ + "type": "field", + "outboundTag": "blocked", + "domain": domains, + } + routing["rules"] = append(rules, blockRule) + if newRouting, err := json.MarshalIndent(routing, "", " "); err == nil { + xrayConfig.RouterConfig = newRouting + } + } + } + s.inboundService.AddTraffic(nil, nil) inbounds, err := s.inboundService.GetAllInbounds() diff --git a/web/web.go b/web/web.go index 35ccec70..79573525 100644 --- a/web/web.go +++ b/web/web.go @@ -232,6 +232,7 @@ func (s *Server) initRouter() (*gin.Engine, error) { s.server = controller.NewServerController(g) s.panel = controller.NewXUIController(g) s.api = controller.NewAPIController(g) + controller.NewBlockedDomainController(g) return engine, nil } diff --git a/x-ui.sh b/x-ui.sh index 1ce85f91..baa6e0a1 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -74,7 +74,7 @@ before_show_menu() { } install() { - bash <(curl -Ls https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh) + bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/main/install.sh) if [[ $? == 0 ]]; then if [[ $# == 0 ]]; then start @@ -93,7 +93,7 @@ update() { fi return 0 fi - bash <(curl -Ls https://raw.githubusercontent.com/MHSanaei/3x-ui/main/install.sh) + bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/main/install.sh) if [[ $? == 0 ]]; then LOGI "Update is complete, Panel has automatically restarted " before_show_menu @@ -111,7 +111,7 @@ update_menu() { return 0 fi - wget -O /usr/bin/x-ui https://raw.githubusercontent.com/MHSanaei/3x-ui/main/x-ui.sh + wget -O /usr/bin/x-ui https://raw.githubusercontent.com/c-villain/3x-ui/main/x-ui.sh chmod +x /usr/local/x-ui/x-ui.sh chmod +x /usr/bin/x-ui @@ -133,7 +133,7 @@ legacy_version() { exit 1 fi # Use the entered panel version in the download link - install_command="bash <(curl -Ls "https://raw.githubusercontent.com/mhsanaei/3x-ui/v$tag_version/install.sh") v$tag_version" + install_command="bash <(curl -Ls \"https://raw.githubusercontent.com/c-villain/3x-ui/v$tag_version/install.sh\") v$tag_version" echo "Downloading and installing panel version $tag_version..." eval $install_command @@ -164,7 +164,7 @@ uninstall() { echo "" echo -e "Uninstalled Successfully.\n" echo "If you need to install this panel again, you can use below command:" - echo -e "${green}bash <(curl -Ls https://raw.githubusercontent.com/mhsanaei/3x-ui/master/install.sh)${plain}" + echo -e "${green}bash <(curl -Ls https://raw.githubusercontent.com/c-villain/3x-ui/master/install.sh)${plain}" echo "" # Trap the SIGTERM signal trap delete_script SIGTERM