From 8073e8ab0ab69af5c8da4a79bc8b10ef9a2b7cc3 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Mon, 6 Jan 2025 00:08:27 +0100 Subject: [PATCH] delete old codes --- backend/app/app.go | 5 +---- backend/config/config.go | 24 ------------------------ backend/config/config.json | 29 ----------------------------- backend/logger/logger.go | 3 +-- backend/service/config.go | 7 ------- sing-box.service | 17 ----------------- 6 files changed, 2 insertions(+), 83 deletions(-) delete mode 100644 backend/config/config.json delete mode 100644 sing-box.service diff --git a/backend/app/app.go b/backend/app/app.go index 04f1e30..502240b 100644 --- a/backend/app/app.go +++ b/backend/app/app.go @@ -48,10 +48,7 @@ func (a *APP) Init() error { a.subServer = sub.NewServer() a.configService = service.NewConfigService(a.core) - err = a.configService.InitConfig() - if err != nil { - return err - } + return nil } diff --git a/backend/config/config.go b/backend/config/config.go index 12349b3..11c1af3 100644 --- a/backend/config/config.go +++ b/backend/config/config.go @@ -14,9 +14,6 @@ var version string //go:embed name var name string -//go:embed config.json -var defaultConfig string - type LogLevel string const ( @@ -72,24 +69,3 @@ func GetDBFolderPath() string { func GetDBPath() string { return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName()) } - -func GetDefaultConfig() string { - apiEnv := GetEnvApi() - if len(apiEnv) > 0 { - return strings.Replace(defaultConfig, "127.0.0.1:1080", apiEnv, 1) - } - return defaultConfig -} - -func GetEnvApi() string { - return os.Getenv("SINGBOX_API") -} - -func IsSystemd() bool { - pid := os.Getppid() - cmdline, err := os.ReadFile(fmt.Sprintf("/proc/%d/comm", pid)) - if err != nil { - return false - } - return string(cmdline) == "systemd\n" -} diff --git a/backend/config/config.json b/backend/config/config.json deleted file mode 100644 index bcaa44f..0000000 --- a/backend/config/config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "log": { - "level": "info" - }, - "dns": {}, - "inbounds": [], - "outbounds": [ - { - "tag": "direct", - "type": "direct" - }, - { - "type": "dns", - "tag": "dns-out" - } - ], - "route": { - "rules": [ - { - "protocol": [ - "dns" - ], - "outbound": "dns-out", - "action": "route" - } - ] - }, - "experimental": {} -} \ No newline at end of file diff --git a/backend/logger/logger.go b/backend/logger/logger.go index 49f2ac0..83622a9 100644 --- a/backend/logger/logger.go +++ b/backend/logger/logger.go @@ -3,7 +3,6 @@ package logger import ( "fmt" "os" - "s-ui/config" "time" "github.com/op/go-logging" @@ -29,7 +28,7 @@ func InitLogger(level logging.Level) { fmt.Println("Unable to use syslog: " + err.Error()) backend = logging.NewLogBackend(os.Stderr, "", 0) } - if config.IsSystemd() && err != nil { + if err != nil { format = logging.MustStringFormatter(`%{time:2006/01/02 15:04:05} %{level} - %{message}`) } else { format = logging.MustStringFormatter(`%{level} - %{message}`) diff --git a/backend/service/config.go b/backend/service/config.go index bca9fd2..e9f6fbc 100644 --- a/backend/service/config.go +++ b/backend/service/config.go @@ -2,7 +2,6 @@ package service import ( "encoding/json" - "s-ui/config" "s-ui/core" "s-ui/database" "s-ui/database/model" @@ -14,7 +13,6 @@ import ( var ( LastUpdate int64 - IsSystemd bool corePtr *core.Core ) @@ -43,11 +41,6 @@ func NewConfigService(core *core.Core) *ConfigService { return &ConfigService{} } -func (s *ConfigService) InitConfig() error { - IsSystemd = config.IsSystemd() - return nil -} - func (s *ConfigService) GetConfig(data string) (*SingBoxConfig, error) { var err error if len(data) == 0 { diff --git a/sing-box.service b/sing-box.service deleted file mode 100644 index 8103f60..0000000 --- a/sing-box.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=sing-box service -Documentation=https://sing-box.sagernet.org -After=network.target nss-lookup.target network-online.target - -[Service] -CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH -AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH -WorkingDirectory=/usr/local/s-ui/bin/ -ExecStart=/usr/local/s-ui/bin/runSingbox.sh -ExecReload=/bin/kill -HUP $MAINPID -Restart=on-failure -RestartSec=10s -LimitNOFILE=infinity - -[Install] -WantedBy=multi-user.target