Skip to content

Commit

Permalink
Show x-ui log on panel (#46)
Browse files Browse the repository at this point in the history
* fix

* Bump google.golang.org/grpc from 1.54.0 to 1.55.0 (#40)

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.54.0 to 1.55.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.54.0...v1.55.0)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* add

* warp

* fix

* fix

* Bump github.com/shirou/gopsutil/v3 from 3.23.3 to 3.23.4 (#43)

Bumps [github.com/shirou/gopsutil/v3](https://github.com/shirou/gopsutil) from 3.23.3 to 3.23.4.
- [Release notes](https://github.com/shirou/gopsutil/releases)
- [Commits](shirou/gopsutil@v3.23.3...v3.23.4)

---
updated-dependencies:
- dependency-name: github.com/shirou/gopsutil/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix

* project info

* optimize

* Bump gorm.io/gorm from 1.25.0 to 1.25.1 (#45)

Bumps [gorm.io/gorm](https://github.com/go-gorm/gorm) from 1.25.0 to 1.25.1.
- [Release notes](https://github.com/go-gorm/gorm/releases)
- [Commits](go-gorm/gorm@v1.25.0...v1.25.1)

---
updated-dependencies:
- dependency-name: gorm.io/gorm
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Show x-ui log on panel

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
Misaka-blog and dependabot[bot] authored May 9, 2023
1 parent 47285ab commit 7cb6f40
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.3.7
v0.3.3.8
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
golang.org/x/text v0.9.0
google.golang.org/grpc v1.55.0
gorm.io/driver/sqlite v1.5.0
gorm.io/gorm v1.25.0
gorm.io/gorm v1.25.1
)

require (
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.5.0 h1:zKYbzRCpBrT1bNijRnxLDJWPjVfImGEn0lSnUY5gZ+c=
gorm.io/driver/sqlite v1.5.0/go.mod h1:kDMDfntV9u/vuMmz8APHtHF0b4nyBB7sfCieC6G8k8I=
gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU=
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.1 h1:nsSALe5Pr+cM3V1qwwQ7rOkw+6UeLrX5O4v3llhHa64=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gvisor.dev/gvisor v0.0.0-20220901235040-6ca97ef2ce1c h1:m5lcgWnL3OElQNVyp3qcncItJ2c0sQlSGjYK2+nJTA4=
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
2 changes: 1 addition & 1 deletion web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class TlsStreamSettings extends XrayCommonClass {
maxVersion = TLS_VERSION_OPTION.TLS13,
cipherSuites = '',
allowInsecure = false,
fingerprint = UTLS_FINGERPRINT.UTLS_CHROME,
fingerprint = UTLS_FINGERPRINT.UTLS_RANDOM,
certificates = [new TlsStreamSettings.Cert()], alpn = ['']) {
super();
this.server = serverName;
Expand Down
11 changes: 11 additions & 0 deletions web/controller/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (a *ServerController) initRouter(g *gin.RouterGroup) {
g.POST("/stopXrayService", a.stopXrayService)
g.POST("/restartXrayService", a.restartXrayService)
g.POST("/installXray/:version", a.installXray)
g.POST("/logs/:count", a.getLogs)
g.POST("/getGeoipVersion", a.getGeoipVersion)
g.POST("/installGeoip/:version", a.installGeoip)
g.POST("/getGeositeVersion", a.getGeositeVersion)
Expand Down Expand Up @@ -124,6 +125,16 @@ func (a *ServerController) installXray(c *gin.Context) {
jsonMsg(c, "安装 xray", err)
}

func (a *ServerController) getLogs(c *gin.Context) {
count := c.Param("count")
logs, err := a.serverService.GetLogs(count)
if err != nil {
jsonMsg(c, "getLogs", err)
return
}
jsonObj(c, logs, nil)
}

func (a *ServerController) getGeoipVersion(c *gin.Context) {
now := time.Now()
if now.Sub(a.lastGeoipGetVersionsTime) <= time.Minute {
Expand Down
4 changes: 2 additions & 2 deletions web/html/xui/form/protocol/vless.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<a-input v-model.trim="vlessobj.id"></a-input>
</a-form-item>

<a-form-item v-if="inbound.tls && inbound.isTcp" label="流控">
<a-select v-model="vlessobj.flow" style="width: 180px">
<a-form-item v-if="inbound.tls && inbound.isTcp" label="flow">
<a-select v-model="vlessobj.flow" style="width: 150px">
<a-select-option value=""></a-select-option>
<a-select-option v-for="key in FLOW_VISION" :value="key">[[ key ]]</a-select-option>
</a-select>
Expand Down
72 changes: 72 additions & 0 deletions web/html/xui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<a-tag color="blue" style="cursor: pointer;" @click="stopXrayService">停止</a-tag>
<a-tag color="blue" style="cursor: pointer;" @click="restartXrayService">重启</a-tag>
<a-tag color="blue" @click="openSelectV2rayVersion">版本切换</a-tag>
<a-tag color="blue" style="cursor: pointer;" @click="openLogs(20)">查看日志</a-tag>
</a-card>
</a-col>
<a-col :sm="24" :md="12">
Expand Down Expand Up @@ -169,6 +170,25 @@
</a-row>
</a-card>
</a-col>
<a-col :sm="24" :md="12">
<a-card hoverable>
x-ui 版本:
<a-tag color="green">{{ .cur_ver }}</a-tag>
GitHub 项目:
<a href="https://github.com/sing-web/x-ui" target="_blank"><a-tag
color="green">sing-web/x-ui</a-tag></a>
</a-card>
</a-col>
<a-col :sm="24" :md="12">
<a-card hoverable>
Telegram 频道:
<a href="https://t.me/sing_web" target="_blank"><a-tag
color="blue">@sing_web</a-tag></a>
Telegram 群组:
<a href="https://t.me/sing_web_group" target="_blank"><a-tag
color="blue">@sing_web_group</a-tag></a>
</a-card>
</a-col>
</a-row>
</transition>
</a-layout-content>
Expand All @@ -183,6 +203,7 @@ <h2>点击你想切换的版本</h2>
</a-tag>
</template>
</a-modal>

<a-modal id="version-modal" v-model="versionModal.geoip" title="geoip更新" :closable="true"
@ok="() => versionModal.geoip = false" ok-text="确定" cancel-text="取消">
<h2>点击你想更新的版本</h2>
Expand All @@ -194,6 +215,7 @@ <h2>点击你想更新的版本</h2>
</a-tag>
</template>
</a-modal>

<a-modal id="version-modal" v-model="versionModal.geosite" title="geosite更新" :closable="true"
@ok="() => versionModal.geosite = false" ok-text="确定" cancel-text="取消">
<h2>点击你想更新的版本</h2>
Expand All @@ -205,6 +227,33 @@ <h2>点击你想更新的版本</h2>
</a-tag>
</template>
</a-modal>

<a-modal id="log-modal" v-model="logModal.visible" title="x-ui logs" :closable="true"
@ok="() => logModal.visible = false" @cancel="() => logModal.visible = false" width="800px" footer="">
<a-form layout="inline">
<a-form-item label="行数">
<a-select v-model="logModal.rows" style="width: 80px" @change="openLogs(logModal.rows)">
<a-select-option value="10">10</a-select-option>
<a-select-option value="20">20</a-select-option>
<a-select-option value="50">50</a-select-option>
<a-select-option value="100">100</a-select-option>
</a-select>
</a-form-item>
<a-form-item>
<button class="ant-btn ant-btn-primary" @click="openLogs(logModal.rows)"><a-icon
type="sync"></a-icon> 刷新</button>
</a-form-item>
<a-form-item>
<a-button type="primary" style="margin-bottom: 10px;"
:href="'data:application/text;charset=utf-8,' + encodeURIComponent(logModal.logs)"
download="x-ui.log">
下载 x-ui.log
</a-button>
</a-form-item>
</a-form>
<a-input type="textarea" v-model="logModal.logs" disabled="true"
:autosize="{ minRows: 10, maxRows: 22}"></a-input>
</a-modal>
</a-layout>
{{template "js" .}}
<script>
Expand Down Expand Up @@ -310,6 +359,20 @@ <h2>点击你想更新的版本</h2>
},
};

const logModal = {
visible: false,
logs: '',
rows: 20,
show(logs, rows) {
this.visible = true;
this.rows = rows;
this.logs = logs.join("\n");
},
hide() {
this.visible = false;
},
};

const app = new Vue({
delimiters: ['[[', ']]'],
el: '#app',
Expand Down Expand Up @@ -359,6 +422,15 @@ <h2>点击你想更新的版本</h2>
return;
}
},
async openLogs(rows) {
this.loading(true);
const msg = await HttpUtil.post('server/logs/' + rows);
this.loading(false);
if (!msg.success) {
return;
}
logModal.show(msg.obj, rows);
},
async geoipUpdate() {
this.loading(true);
const msg = await HttpUtil.post('server/getGeoipVersion');
Expand Down
27 changes: 26 additions & 1 deletion web/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"io/fs"
"net/http"
"os"
"os/exec"
"runtime"
"strings"
"time"
"x-ui/config"
"x-ui/logger"
Expand Down Expand Up @@ -199,6 +201,29 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
return versions, nil
}

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", count}
} else {
return []string{"Unsupported operating system"}, nil
}

// Run the command
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
return nil, err
}

lines := strings.Split(out.String(), "\n")

return lines, nil
}

func (s *ServerService) StopXrayService() (string error) {
err := s.xrayService.StopXray()
if err != nil {
Expand Down Expand Up @@ -478,4 +503,4 @@ func (s *ServerService) GetDatabase() ([]byte, error) {
}

return fileContents, nil
}
}

0 comments on commit 7cb6f40

Please sign in to comment.