Skip to content

Commit

Permalink
Add iran.dat when updating xray (#870)
Browse files Browse the repository at this point in the history
we can download iran.dat, because it's one of the required files in our settings
  • Loading branch information
hamid-gh98 committed Aug 8, 2023
1 parent 22cf278 commit 24eb367
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
48 changes: 38 additions & 10 deletions web/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
}

func (s *ServerService) StopXrayService() (string error) {

err := s.xrayService.StopXray()
if err != nil {
logger.Error("stop xray failed:", err)
Expand All @@ -265,7 +264,6 @@ func (s *ServerService) StopXrayService() (string error) {
}

func (s *ServerService) RestartXrayService() (string error) {

s.xrayService.StopXray()
defer func() {
err := s.xrayService.RestartXray(true)
Expand Down Expand Up @@ -363,17 +361,47 @@ func (s *ServerService) UpdateXray(version string) error {
return err
}

err = copyZipFile("xray", xray.GetBinaryPath())
if err != nil {
downloadFile := func(fileName string, url string) error {
os.Remove(fileName)
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_RDWR|os.O_TRUNC, fs.ModePerm)
if err != nil {
return err
}
defer file.Close()
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("download file failed: %s", resp.Status)
}
_, err = io.Copy(file, resp.Body)
return err
}
err = copyZipFile("geosite.dat", xray.GetGeositePath())
if err != nil {
return err

copyFiles := map[string]string{
"xray": xray.GetBinaryPath(),
"geosite.dat": xray.GetGeositePath(),
"geoip.dat": xray.GetGeoipPath(),
}
err = copyZipFile("geoip.dat", xray.GetGeoipPath())
if err != nil {
return err

downloadFiles := map[string]string{
xray.GetIranPath(): "https://github.com/MasterKia/iran-hosted-domains/releases/latest/download/iran.dat",
}

for fileName, filePath := range copyFiles {
err := copyZipFile(fileName, filePath)
if err != nil {
return err
}
}

for fileName, filePath := range downloadFiles {
err := downloadFile(fileName, filePath)
if err != nil {
return err
}
}

return nil
Expand Down
5 changes: 5 additions & 0 deletions xray/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"sync"
"syscall"

"x-ui/config"
"x-ui/logger"
"x-ui/util/common"
Expand Down Expand Up @@ -40,6 +41,10 @@ func GetGeoipPath() string {
return config.GetBinFolderPath() + "/geoip.dat"
}

func GetIranPath() string {
return config.GetBinFolderPath() + "/iran.dat"
}

func GetIPLimitLogPath() string {
return config.GetLogFolder() + "/3xipl.log"
}
Expand Down

0 comments on commit 24eb367

Please sign in to comment.