Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2023-07-31 19:41:47 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-07-31 19:41:47 +0300
commitbf971911d50b26492fc27b4f904026ee73c0c918 (patch)
tree3bb247ea7cc44b22bdcd4c3fef7a72a1e4d07daf /web
parentc46ced0c4c57bd9e243bca1b068017aa8a97f4b0 (diff)
log level & syslog
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
Diffstat (limited to 'web')
-rw-r--r--web/assets/js/model/xray.js5
-rw-r--r--web/controller/server.go9
-rw-r--r--web/html/xui/index.html27
-rw-r--r--web/service/server.go35
4 files changed, 37 insertions, 39 deletions
diff --git a/web/assets/js/model/xray.js b/web/assets/js/model/xray.js
index 94dc4eaa..bf766cf0 100644
--- a/web/assets/js/model/xray.js
+++ b/web/assets/js/model/xray.js
@@ -402,7 +402,7 @@ class HttpStreamSettings extends XrayCommonClass {
}
static fromJson(json={}) {
- return new HttpStreamSettings(json.path, json.host, json.sockopt);
+ return new HttpStreamSettings(json.path, json.host);
}
toJson() {
@@ -461,8 +461,7 @@ class GrpcStreamSettings extends XrayCommonClass {
static fromJson(json={}) {
return new GrpcStreamSettings(
json.serviceName,
- json.multiMode,
- json.sockopt
+ json.multiMode
);
}
diff --git a/web/controller/server.go b/web/controller/server.go
index 086d9ec9..10baacb9 100644
--- a/web/controller/server.go
+++ b/web/controller/server.go
@@ -118,12 +118,9 @@ func (a *ServerController) restartXrayService(c *gin.Context) {
func (a *ServerController) getLogs(c *gin.Context) {
count := c.Param("count")
- logLevel := c.PostForm("logLevel")
- logs, err := a.serverService.GetLogs(count, logLevel)
- if err != nil {
- jsonMsg(c, "getLogs", err)
- return
- }
+ level := c.PostForm("level")
+ syslog := c.PostForm("syslog")
+ logs := a.serverService.GetLogs(count, level, syslog)
jsonObj(c, logs, nil)
}
diff --git a/web/html/xui/index.html b/web/html/xui/index.html
index 236ab010..0942b0ad 100644
--- a/web/html/xui/index.html
+++ b/web/html/xui/index.html
@@ -86,7 +86,7 @@
<a-col :sm="24" :md="12">
<a-card hoverable :class="themeSwitcher.darkCardClass">
{{ i18n "menu.link" }}:
- <a-tag color="blue" style="cursor: pointer;" @click="openLogs(logModal.rows, logModal.logLevel)">{{ i18n "pages.index.logs" }}</a-tag>
+ <a-tag color="blue" style="cursor: pointer;" @click="openLogs()">{{ i18n "pages.index.logs" }}</a-tag>
<a-tag color="blue" style="cursor: pointer;" @click="openConfig">{{ i18n "pages.index.config" }}</a-tag>
<a-tag color="blue" style="cursor: pointer;" @click="openBackup">{{ i18n "pages.index.backup" }}</a-tag>
</a-card>
@@ -253,7 +253,7 @@
<a-form-item label="Count">
<a-select v-model="logModal.rows"
style="width: 80px"
- @change="openLogs(logModal.rows, logModal.logLevel)"
+ @change="openLogs()"
:dropdown-class-name="themeSwitcher.darkCardClass">
<a-select-option value="10">10</a-select-option>
<a-select-option value="20">20</a-select-option>
@@ -262,9 +262,9 @@
</a-select>
</a-form-item>
<a-form-item label="Log Level">
- <a-select v-model="logModal.logLevel"
+ <a-select v-model="logModal.level"
style="width: 120px"
- @change="openLogs(logModal.rows, logModal.logLevel)"
+ @change="openLogs()"
:dropdown-class-name="themeSwitcher.darkCardClass">
<a-select-option value="debug">Debug</a-select-option>
<a-select-option value="info">Info</a-select-option>
@@ -273,8 +273,11 @@
<a-select-option value="err">Error</a-select-option>
</a-select>
</a-form-item>
+ <a-form-item label="SysLog">
+ <a-checkbox v-model="logModal.syslog" @change="openLogs()"></a-checkbox>
+ </a-form-item>
<a-form-item>
- <button class="ant-btn ant-btn-primary" @click="openLogs(logModal.rows, logModal.logLevel)"><a-icon type="sync"></a-icon> Reload</button>
+ <button class="ant-btn ant-btn-primary" @click="openLogs()"><a-icon type="sync"></a-icon> Reload</button>
</a-form-item>
<a-form-item>
<a-button type="primary" style="margin-bottom: 10px;"
@@ -409,11 +412,11 @@
visible: false,
logs: '',
rows: 20,
- logLevel: 'info',
- show(logs, rows) {
+ level: 'info',
+ syslog: false,
+ show(logs) {
this.visible = true;
- this.rows = rows;
- this.logs = logs.join("\n");
+ this.logs = logs? logs.join("\n"): "No Record...";
},
hide() {
this.visible = false;
@@ -514,14 +517,14 @@
return;
}
},
- async openLogs(rows, logLevel) {
+ async openLogs(){
this.loading(true);
- const msg = await HttpUtil.post('server/logs/' + rows, { logLevel: `${logLevel}` });
+ const msg = await HttpUtil.post('server/logs/'+logModal.rows,{level: logModal.level, syslog: logModal.syslog});
this.loading(false);
if (!msg.success) {
return;
}
- logModal.show(msg.obj, rows);
+ logModal.show(msg.obj);
},
async openConfig() {
this.loading(true);
diff --git a/web/service/server.go b/web/service/server.go
index 3de5f3ff..376126df 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"runtime"
+ "strconv"
"strings"
"time"
@@ -378,28 +379,26 @@ func (s *ServerService) UpdateXray(version string) error {
return nil
}
-func (s *ServerService) GetLogs(count string, logLevel string) ([]string, error) {
- var cmdArgs []string
- if runtime.GOOS == "linux" {
- cmdArgs = []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", count}
- if logLevel != "" {
- cmdArgs = append(cmdArgs, "-p", logLevel)
+func (s *ServerService) GetLogs(count string, level string, syslog string) []string {
+ c, _ := strconv.Atoi(count)
+ var lines []string
+
+ if syslog == "true" {
+ cmdArgs := []string{"journalctl", "-u", "x-ui", "--no-pager", "-n", count, "-p", level}
+ // Run the command
+ cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
+ var out bytes.Buffer
+ cmd.Stdout = &out
+ err := cmd.Run()
+ if err != nil {
+ return []string{"Failed to run journalctl command!"}
}
+ lines = strings.Split(out.String(), "\n")
} else {
- return []string{"Unsupported operating system"}, nil
- }
-
- cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
- var out bytes.Buffer
- cmd.Stdout = &out
- err := cmd.Run()
- if err != nil {
- return nil, err
+ lines = logger.GetLogs(c, level)
}
- lines := strings.Split(out.String(), "\n")
-
- return lines, nil
+ return lines
}
func (s *ServerService) GetConfigJson() (interface{}, error) {