mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-27 09:56:23 +00:00
Compare commits
7 commits
b621dd94d0
...
a9ddc11888
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9ddc11888 | ||
|
|
c3603b9fd8 | ||
|
|
252c24d7fd | ||
|
|
af39f42b7e | ||
|
|
159b85f979 | ||
|
|
3ec5b3589f | ||
|
|
2b1d3e7347 |
10 changed files with 73 additions and 11 deletions
9
main.go
9
main.go
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/mhsanaei/3x-ui/v2/logger"
|
"github.com/mhsanaei/3x-ui/v2/logger"
|
||||||
"github.com/mhsanaei/3x-ui/v2/sub"
|
"github.com/mhsanaei/3x-ui/v2/sub"
|
||||||
"github.com/mhsanaei/3x-ui/v2/util/crypto"
|
"github.com/mhsanaei/3x-ui/v2/util/crypto"
|
||||||
|
"github.com/mhsanaei/3x-ui/v2/util/sys"
|
||||||
"github.com/mhsanaei/3x-ui/v2/web"
|
"github.com/mhsanaei/3x-ui/v2/web"
|
||||||
"github.com/mhsanaei/3x-ui/v2/web/global"
|
"github.com/mhsanaei/3x-ui/v2/web/global"
|
||||||
"github.com/mhsanaei/3x-ui/v2/web/service"
|
"github.com/mhsanaei/3x-ui/v2/web/service"
|
||||||
|
|
@ -70,7 +71,7 @@ func runWebServer() {
|
||||||
|
|
||||||
sigCh := make(chan os.Signal, 1)
|
sigCh := make(chan os.Signal, 1)
|
||||||
// Trap shutdown signals
|
// Trap shutdown signals
|
||||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM)
|
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, sys.SIGUSR1)
|
||||||
for {
|
for {
|
||||||
sig := <-sigCh
|
sig := <-sigCh
|
||||||
|
|
||||||
|
|
@ -108,6 +109,12 @@ func runWebServer() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("Sub server restarted successfully.")
|
log.Println("Sub server restarted successfully.")
|
||||||
|
case sys.SIGUSR1:
|
||||||
|
logger.Info("Received USR1 signal, restarting xray-core...")
|
||||||
|
err := server.RestartXray()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Failed to restart xray-core:", err)
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown ---
|
// --- FIX FOR TELEGRAM BOT CONFLICT (409) on full shutdown ---
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,14 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v4/net"
|
"github.com/shirou/gopsutil/v4/net"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var SIGUSR1 = syscall.SIGUSR1
|
||||||
|
|
||||||
func GetTCPCount() (int, error) {
|
func GetTCPCount() (int, error) {
|
||||||
stats, err := net.Connections("tcp")
|
stats, err := net.Connections("tcp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,11 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var SIGUSR1 = syscall.SIGUSR1
|
||||||
|
|
||||||
func getLinesNum(filename string) (int, error) {
|
func getLinesNum(filename string) (int, error) {
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import (
|
||||||
"github.com/shirou/gopsutil/v4/net"
|
"github.com/shirou/gopsutil/v4/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var SIGUSR1 = syscall.Signal(0)
|
||||||
|
|
||||||
// GetConnectionCount returns the number of active connections for the specified protocol ("tcp" or "udp").
|
// GetConnectionCount returns the number of active connections for the specified protocol ("tcp" or "udp").
|
||||||
func GetConnectionCount(proto string) (int, error) {
|
func GetConnectionCount(proto string) (int, error) {
|
||||||
if proto != "tcp" && proto != "udp" {
|
if proto != "tcp" && proto != "udp" {
|
||||||
|
|
|
||||||
|
|
@ -490,3 +490,7 @@ func (s *Server) GetCron() *cron.Cron {
|
||||||
func (s *Server) GetWSHub() any {
|
func (s *Server) GetWSHub() any {
|
||||||
return s.wsHub
|
return s.wsHub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) RestartXray() error {
|
||||||
|
return s.xrayService.RestartXray(true)
|
||||||
|
}
|
||||||
|
|
|
||||||
5
x-ui.rc
5
x-ui.rc
|
|
@ -11,3 +11,8 @@ depend() {
|
||||||
start_pre(){
|
start_pre(){
|
||||||
cd /usr/local/x-ui
|
cd /usr/local/x-ui
|
||||||
}
|
}
|
||||||
|
reload() {
|
||||||
|
ebegin "Reloading ${RC_SVCNAME}"
|
||||||
|
kill -USR1 $pidfile
|
||||||
|
eend $?
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
|
||||||
Type=simple
|
Type=simple
|
||||||
WorkingDirectory=/usr/lib/x-ui/
|
WorkingDirectory=/usr/lib/x-ui/
|
||||||
ExecStart=/usr/lib/x-ui/x-ui
|
ExecStart=/usr/lib/x-ui/x-ui
|
||||||
|
ExecReload=kill -USR1 $MAINPID
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5s
|
RestartSec=5s
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
|
||||||
Type=simple
|
Type=simple
|
||||||
WorkingDirectory=/usr/local/x-ui/
|
WorkingDirectory=/usr/local/x-ui/
|
||||||
ExecStart=/usr/local/x-ui/x-ui
|
ExecStart=/usr/local/x-ui/x-ui
|
||||||
|
ExecReload=kill -USR1 $MAINPID
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5s
|
RestartSec=5s
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ Environment="XRAY_VMESS_AEAD_FORCED=false"
|
||||||
Type=simple
|
Type=simple
|
||||||
WorkingDirectory=/usr/local/x-ui/
|
WorkingDirectory=/usr/local/x-ui/
|
||||||
ExecStart=/usr/local/x-ui/x-ui
|
ExecStart=/usr/local/x-ui/x-ui
|
||||||
|
ExecReload=kill -USR1 $MAINPID
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5s
|
RestartSec=5s
|
||||||
|
|
||||||
|
|
|
||||||
55
x-ui.sh
55
x-ui.sh
|
|
@ -1673,15 +1673,29 @@ run_speedtest() {
|
||||||
|
|
||||||
run_librespeed() {
|
run_librespeed() {
|
||||||
|
|
||||||
if command -v librespeed-cli &>/dev/null; then
|
echo -e "${yellow}What do you want to do?\n1) Use\n2) Install/Update\n3) Delete"
|
||||||
librespeed-cli
|
read -p ": " action
|
||||||
else
|
|
||||||
#Intalling LibreSpeed
|
if [ "$action" = 1 ]; then
|
||||||
echo -e "${yellow} Installing LibreSpeed..."
|
if command -v librespeed-cli &>/dev/null; then
|
||||||
|
librespeed-cli
|
||||||
|
else
|
||||||
|
echo -e "${red}LibreSpeed is not installed!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "$action" = 2 ]; then
|
||||||
|
echo -e "${yellow} Installing\Updating LibreSpeed..."
|
||||||
|
#Uninstall old version, or actual version
|
||||||
|
rm -f librespeed-cli_*_linux_amd64.tar.gz && rm -rf /usr/bin/librespeed-cli
|
||||||
VERSION=$(curl -s "https://api.github.com/repos/librespeed/speedtest-cli/releases/latest"| grep '"tag_name":' | sed -E 's/.*"v?([^"]+)".*/\1/')
|
VERSION=$(curl -s "https://api.github.com/repos/librespeed/speedtest-cli/releases/latest"| grep '"tag_name":' | sed -E 's/.*"v?([^"]+)".*/\1/')
|
||||||
wget https://github.com/librespeed/speedtest-cli/releases/download/v${VERSION}/librespeed-cli_${VERSION}_linux_amd64.tar.gz
|
wget https://github.com/librespeed/speedtest-cli/releases/download/v${VERSION}/librespeed-cli_${VERSION}_linux_amd64.tar.gz
|
||||||
tar -xzvf librespeed-cli_${VERSION}_linux_amd64.tar.gz && mv librespeed-cli /usr/bin
|
tar -xzvf librespeed-cli_${VERSION}_linux_amd64.tar.gz && mv librespeed-cli /usr/bin
|
||||||
|
echo -e "${green}Starting libreSpeed... (Delete old archive)"
|
||||||
librespeed-cli
|
librespeed-cli
|
||||||
|
elif [ "$action" = 3 ]; then
|
||||||
|
#Uninstall LibreSpeed
|
||||||
|
rm -f librespeed-cli_*_linux_amd64.tar.gz && rm -rf /usr/bin/librespeed-cli
|
||||||
|
echo -e "${green}LibreSpeed was deleted!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1891,14 +1905,31 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
change_dns() {
|
change_dns() {
|
||||||
echo -e "${yellow}${plain}Changing DNS resolver"
|
echo -e "${yellow}Changing DNS resolver"
|
||||||
echo -e "${plain}Enter resolver (default: 9.9.9.9): "
|
echo -e "${plain}Enter resolver (default: quad9): "
|
||||||
read resolver
|
read resolver
|
||||||
|
|
||||||
if [ -n "$resolver" ]; then
|
IPv6_on=$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6)
|
||||||
echo "nameserver $resolver" > /etc/resolv.conf
|
echo $IPv6_on
|
||||||
|
|
||||||
|
if [ "$IPv6_on" = 0 ]; then
|
||||||
|
echo -e "${green}Your server using IPv6!"
|
||||||
|
echo -e "${plain}Enter server for IPv6"
|
||||||
|
read -p ": " resolver_ipv6
|
||||||
|
if [ -n "$resolver" ] && [ -n "$resolver_ipv6" ]; then
|
||||||
|
echo "nameserver $resolver" > /etc/resolv.conf
|
||||||
|
echo "nameserver $resolver_ipv6" > /etc/resolv.conf
|
||||||
|
else
|
||||||
|
echo "nameserver 9.9.9.9" > /etc/resolv.conf
|
||||||
|
echo "nameserver 2620:fe::fe" > /etc/resolv.conf
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "nameserver 9.9.9.9" > /etc/resolv.conf
|
echo -e "${green}IPv6 is disabled!"
|
||||||
|
if [ -n "$resolver" ]; then
|
||||||
|
echo "nameserver $resolver" > /etc/resolv.conf
|
||||||
|
else
|
||||||
|
echo "nameserver 9.9.9.9" > /etc/resolv.conf
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo -e "${green}${plain}Done!"
|
echo -e "${green}${plain}Done!"
|
||||||
}
|
}
|
||||||
|
|
@ -2394,6 +2425,7 @@ show_usage() {
|
||||||
│ ${blue}x-ui start${plain} - Start │
|
│ ${blue}x-ui start${plain} - Start │
|
||||||
│ ${blue}x-ui stop${plain} - Stop │
|
│ ${blue}x-ui stop${plain} - Stop │
|
||||||
│ ${blue}x-ui restart${plain} - Restart │
|
│ ${blue}x-ui restart${plain} - Restart │
|
||||||
|
| ${blue}x-ui restart-xray${plain} - Restart Xray │
|
||||||
│ ${blue}x-ui status${plain} - Current Status │
|
│ ${blue}x-ui status${plain} - Current Status │
|
||||||
│ ${blue}x-ui settings${plain} - Current Settings │
|
│ ${blue}x-ui settings${plain} - Current Settings │
|
||||||
│ ${blue}x-ui enable${plain} - Enable Autostart on OS Startup │
|
│ ${blue}x-ui enable${plain} - Enable Autostart on OS Startup │
|
||||||
|
|
@ -2561,6 +2593,9 @@ if [[ $# > 0 ]]; then
|
||||||
"restart")
|
"restart")
|
||||||
check_install 0 && restart 0
|
check_install 0 && restart 0
|
||||||
;;
|
;;
|
||||||
|
"restart-xray")
|
||||||
|
check_install 0 && restart_xray 0
|
||||||
|
;;
|
||||||
"status")
|
"status")
|
||||||
check_install 0 && status 0
|
check_install 0 && status 0
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue