mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-04-19 21:42:24 +00:00
Merge pull request #261 from hamid-gh98/main
Support set db and bin folder path from env
This commit is contained in:
commit
b70ecc12b3
5 changed files with 121 additions and 103 deletions
|
@ -45,6 +45,22 @@ func IsDebug() bool {
|
|||
return os.Getenv("XUI_DEBUG") == "true"
|
||||
}
|
||||
|
||||
func GetDBPath() string {
|
||||
return fmt.Sprintf("/etc/%s/%s.db", GetName(), GetName())
|
||||
func GetBinFolderPath() string {
|
||||
binFolderPath := os.Getenv("XUI_BIN_FOLDER")
|
||||
if binFolderPath == "" {
|
||||
binFolderPath = "bin"
|
||||
}
|
||||
return binFolderPath
|
||||
}
|
||||
|
||||
func GetDBFolderPath() string {
|
||||
dbFolderPath := os.Getenv("XUI_DB_FOLDER")
|
||||
if dbFolderPath == "" {
|
||||
dbFolderPath = "/etc/x-ui"
|
||||
}
|
||||
return dbFolderPath
|
||||
}
|
||||
|
||||
func GetDBPath() string {
|
||||
return fmt.Sprintf("%s/%s.db", GetDBFolderPath(), GetName())
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -217,7 +217,7 @@ func main() {
|
|||
|
||||
v2uiCmd := flag.NewFlagSet("v2-ui", flag.ExitOnError)
|
||||
var dbPath string
|
||||
v2uiCmd.StringVar(&dbPath, "db", "/etc/v2-ui/v2-ui.db", "set v2-ui db file path")
|
||||
v2uiCmd.StringVar(&dbPath, "db", fmt.Sprintf("%s/v2-ui.db", config.GetDBFolderPath()), "set v2-ui db file path")
|
||||
|
||||
settingCmd := flag.NewFlagSet("setting", flag.ExitOnError)
|
||||
var port int
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
package job
|
||||
|
||||
import (
|
||||
"x-ui/logger"
|
||||
"x-ui/web/service"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"regexp"
|
||||
ss "strings"
|
||||
"x-ui/database"
|
||||
"x-ui/database/model"
|
||||
"os"
|
||||
ss "strings"
|
||||
"regexp"
|
||||
"encoding/json"
|
||||
"x-ui/logger"
|
||||
"x-ui/web/service"
|
||||
"x-ui/xray"
|
||||
// "strconv"
|
||||
"github.com/go-cmd/cmd"
|
||||
"net"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
"net"
|
||||
"github.com/go-cmd/cmd"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type CheckClientIpJob struct {
|
||||
xrayService service.XrayService
|
||||
inboundService service.InboundService
|
||||
}
|
||||
|
||||
var job *CheckClientIpJob
|
||||
var disAllowedIps []string
|
||||
|
||||
|
@ -35,14 +37,14 @@ func (j *CheckClientIpJob) Run() {
|
|||
|
||||
// disAllowedIps = []string{"192.168.1.183","192.168.1.197"}
|
||||
blockedIps := []byte(ss.Join(disAllowedIps, ","))
|
||||
err := os.WriteFile("./bin/blockedIPs", blockedIps, 0755)
|
||||
err := os.WriteFile(xray.GetBlockedIPsPath(), blockedIps, 0755)
|
||||
checkError(err)
|
||||
|
||||
}
|
||||
|
||||
func processLogFile() {
|
||||
accessLogPath := GetAccessLogPath()
|
||||
if(accessLogPath == "") {
|
||||
if accessLogPath == "" {
|
||||
logger.Warning("xray log not init in config.json")
|
||||
return
|
||||
}
|
||||
|
@ -62,26 +64,24 @@ func processLogFile() {
|
|||
emailRegx, _ := regexp.Compile(`email:.+`)
|
||||
|
||||
matchesIp := ipRegx.FindString(line)
|
||||
if(len(matchesIp) > 0) {
|
||||
if len(matchesIp) > 0 {
|
||||
ip := string(matchesIp)
|
||||
if( ip == "127.0.0.1" || ip == "1.1.1.1") {
|
||||
if ip == "127.0.0.1" || ip == "1.1.1.1" {
|
||||
continue
|
||||
}
|
||||
|
||||
matchesEmail := emailRegx.FindString(line)
|
||||
if(matchesEmail == "") {
|
||||
if matchesEmail == "" {
|
||||
continue
|
||||
}
|
||||
matchesEmail = ss.Split(matchesEmail, "email: ")[1]
|
||||
|
||||
if(InboundClientIps[matchesEmail] != nil) {
|
||||
if(contains(InboundClientIps[matchesEmail],ip)){
|
||||
if InboundClientIps[matchesEmail] != nil {
|
||||
if contains(InboundClientIps[matchesEmail], ip) {
|
||||
continue
|
||||
}
|
||||
InboundClientIps[matchesEmail] = append(InboundClientIps[matchesEmail], ip)
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
InboundClientIps[matchesEmail] = append(InboundClientIps[matchesEmail], ip)
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func processLogFile() {
|
|||
for clientEmail, ips := range InboundClientIps {
|
||||
inboundClientIps, err := GetInboundClientIps(clientEmail)
|
||||
sort.Sort(sort.StringSlice(ips))
|
||||
if(err != nil){
|
||||
if err != nil {
|
||||
addInboundClientIps(clientEmail, ips)
|
||||
|
||||
} else {
|
||||
|
@ -102,7 +102,6 @@ func processLogFile() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
// check if inbound connection is more than limited ip and drop connection
|
||||
LimitDevice := func() { LimitDevice() }
|
||||
|
||||
|
@ -113,15 +112,15 @@ func processLogFile() {
|
|||
}
|
||||
func GetAccessLogPath() string {
|
||||
|
||||
config, err := os.ReadFile("bin/config.json")
|
||||
config, err := os.ReadFile(xray.GetConfigPath())
|
||||
checkError(err)
|
||||
|
||||
jsonConfig := map[string]interface{}{}
|
||||
err = json.Unmarshal([]byte(config), &jsonConfig)
|
||||
checkError(err)
|
||||
if(jsonConfig["log"] != nil) {
|
||||
if jsonConfig["log"] != nil {
|
||||
jsonLog := jsonConfig["log"].(map[string]interface{})
|
||||
if(jsonLog["access"] != nil) {
|
||||
if jsonLog["access"] != nil {
|
||||
|
||||
accessLogPath := jsonLog["access"].(string)
|
||||
|
||||
|
@ -208,7 +207,7 @@ func updateInboundClientIps(inboundClientIps *model.InboundClientIps,clientEmail
|
|||
|
||||
limitIp := client.LimitIP
|
||||
|
||||
if(limitIp < len(ips) && limitIp != 0 && inbound.Enable) {
|
||||
if limitIp < len(ips) && limitIp != 0 && inbound.Enable {
|
||||
|
||||
disAllowedIps = append(disAllowedIps, ips[limitIp:]...)
|
||||
}
|
||||
|
@ -288,7 +287,6 @@ func LimitDevice() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
func LocalIP() ([]string, error) {
|
||||
// get machine ips
|
||||
|
||||
|
@ -321,8 +319,7 @@ func LocalIP() ([]string, error) {
|
|||
return ips, nil
|
||||
}
|
||||
|
||||
|
||||
func IPsToRegex(ips []string) (string){
|
||||
func IPsToRegex(ips []string) string {
|
||||
|
||||
regx := ""
|
||||
for _, ip := range ips {
|
|
@ -106,8 +106,8 @@
|
|||
"expireDate" = "Expire date"
|
||||
"resetTraffic" = "Reset traffic"
|
||||
"addInbound" = "Add Inbound"
|
||||
"addTo" = "Add To"
|
||||
"revise" = "Revise"
|
||||
"addTo" = "Create"
|
||||
"revise" = "Update"
|
||||
"modifyInbound" = "Modify InBound"
|
||||
"deleteInbound" = "Delete Inbound"
|
||||
"deleteInboundContent" = "Are you sure you want to delete inbound?"
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
"x-ui/config"
|
||||
"x-ui/util/common"
|
||||
|
||||
"github.com/Workiva/go-datastructures/queue"
|
||||
|
@ -29,19 +30,23 @@ func GetBinaryName() string {
|
|||
}
|
||||
|
||||
func GetBinaryPath() string {
|
||||
return "bin/" + GetBinaryName()
|
||||
return config.GetBinFolderPath() + "/" + GetBinaryName()
|
||||
}
|
||||
|
||||
func GetConfigPath() string {
|
||||
return "bin/config.json"
|
||||
return config.GetBinFolderPath() + "/config.json"
|
||||
}
|
||||
|
||||
func GetGeositePath() string {
|
||||
return "bin/geosite.dat"
|
||||
return config.GetBinFolderPath() + "/geosite.dat"
|
||||
}
|
||||
|
||||
func GetGeoipPath() string {
|
||||
return "bin/geoip.dat"
|
||||
return config.GetBinFolderPath() + "/geoip.dat"
|
||||
}
|
||||
|
||||
func GetBlockedIPsPath() string {
|
||||
return config.GetBinFolderPath() + "/blockedIPs"
|
||||
}
|
||||
|
||||
func stopProcess(p *Process) {
|
||||
|
@ -162,7 +167,7 @@ func (p *process) Start() (err error) {
|
|||
return common.NewErrorf("Failed to write configuration file: %v", err)
|
||||
}
|
||||
|
||||
cmd := exec.Command(GetBinaryPath(), "-c", configPath, "-restrictedIPsPath", "./bin/blockedIPs")
|
||||
cmd := exec.Command(GetBinaryPath(), "-c", configPath, "-restrictedIPsPath", GetBlockedIPsPath())
|
||||
p.cmd = cmd
|
||||
|
||||
stdReader, err := cmd.StdoutPipe()
|
||||
|
|
Loading…
Reference in a new issue