diff options
| author | Mohammad Movaghari <52345697+mohammadmovaghari@users.noreply.github.com> | 2023-04-12 16:29:17 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-12 16:29:17 +0300 |
| commit | c575425292e2c4c690728174e42a6f34963394c2 (patch) | |
| tree | c9b033457baa55a98cea23a8769645f8f3dbd476 /web/service/server.go | |
| parent | 63f71e527ceddc724e0bd2893c4946b01f3a5f6c (diff) | |
| parent | 82b2809fccb6a131b4f84e2ca236f8bea567beae (diff) | |
Merge branch 'MHSanaei:main' into main
Diffstat (limited to 'web/service/server.go')
| -rw-r--r-- | web/service/server.go | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/web/service/server.go b/web/service/server.go index 5e6065b5..c73fce57 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -13,6 +13,7 @@ import ( "runtime" "strings" "time" + "x-ui/config" "x-ui/logger" "x-ui/util/sys" "x-ui/xray" @@ -327,11 +328,11 @@ func (s *ServerService) UpdateXray(version string) error { } -func (s *ServerService) GetLogs() ([]string, error) { +func (s *ServerService) GetLogs(count string) ([]string, error) { // Define the journalctl command and its arguments var cmdArgs []string if runtime.GOOS == "linux" { - cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", "100"} + cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", count} } else { return []string{"Unsupported operating system"}, nil } @@ -349,3 +350,43 @@ func (s *ServerService) GetLogs() ([]string, error) { return lines, nil } + +func (s *ServerService) GetConfigJson() (interface{}, error) { + // Open the file for reading + file, err := os.Open(xray.GetConfigPath()) + if err != nil { + return nil, err + } + defer file.Close() + + // Read the file contents + fileContents, err := io.ReadAll(file) + if err != nil { + return nil, err + } + + var jsonData interface{} + err = json.Unmarshal(fileContents, &jsonData) + if err != nil { + return nil, err + } + + return jsonData, nil +} + +func (s *ServerService) GetDb() ([]byte, error) { + // Open the file for reading + file, err := os.Open(config.GetDBPath()) + if err != nil { + return nil, err + } + defer file.Close() + + // Read the file contents + fileContents, err := io.ReadAll(file) + if err != nil { + return nil, err + } + + return fileContents, nil +} |
