Skip to content

Commit

Permalink
0.2.0
Browse files Browse the repository at this point in the history
 - 优化 ui 界面
 - 优化网站加载速度
 - 新增从 v2-ui 迁移账号数据的功能
  • Loading branch information
vaxilu committed Jun 17, 2021
1 parent d67dff5 commit 89677c4
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 18 deletions.
2 changes: 1 addition & 1 deletion config/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ install_x-ui() {
echo -e "x-ui enable - 设置 x-ui 开机自启"
echo -e "x-ui disable - 取消 x-ui 开机自启"
echo -e "x-ui log - 查看 x-ui 日志"
echo -e "x-ui v2-ui - 迁移本机器的 v2-ui 账号数据至 x-ui"
echo -e "x-ui update - 更新 x-ui 面板"
echo -e "x-ui install - 安装 x-ui 面板"
echo -e "x-ui uninstall - 卸载 x-ui 面板"
Expand Down
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func runWebServer() {
}

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGHUP)
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGKILL)
for {
sig := <-sigCh

if sig == syscall.SIGHUP {
switch sig {
case syscall.SIGHUP:
err := server.Stop()
if err != nil {
logger.Warning("stop server err:", err)
Expand All @@ -66,8 +67,9 @@ func runWebServer() {
log.Println(err)
return
}
} else {
continue
default:
server.Stop()
return
}
}
}
Expand Down Expand Up @@ -173,7 +175,7 @@ func main() {
}
err = v2ui.MigrateFromV2UI(dbPath)
if err != nil {
logger.Error("migrate from v2-ui failed:", err)
fmt.Println("migrate from v2-ui failed:", err)
}
case "setting":
err := settingCmd.Parse(os.Args[2:])
Expand Down
28 changes: 28 additions & 0 deletions v2ui/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v2ui

import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)

var v2db *gorm.DB

func initDB(dbPath string) error {
c := &gorm.Config{
Logger: logger.Discard,
}
var err error
v2db, err = gorm.Open(sqlite.Open(dbPath), c)
if err != nil {
return err
}

return nil
}

func getV2Inbounds() ([]*V2Inbound, error) {
inbounds := make([]*V2Inbound, 0)
err := v2db.Model(V2Inbound{}).Find(&inbounds).Error
return inbounds, err
}
41 changes: 41 additions & 0 deletions v2ui/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package v2ui

import "x-ui/database/model"

type V2Inbound struct {
Id int `gorm:"primaryKey;autoIncrement"`
Port int `gorm:"unique"`
Listen string
Protocol string
Settings string
StreamSettings string
Tag string `gorm:"unique"`
Sniffing string
Remark string
Up int64
Down int64
Enable bool
}

func (i *V2Inbound) TableName() string {
return "inbound"
}

func (i *V2Inbound) ToInbound(userId int) *model.Inbound {
return &model.Inbound{
UserId: userId,
Up: i.Up,
Down: i.Down,
Total: 0,
Remark: i.Remark,
Enable: i.Enable,
ExpiryTime: 0,
Listen: i.Listen,
Port: i.Port,
Protocol: model.Protocol(i.Protocol),
Settings: i.Settings,
StreamSettings: i.StreamSettings,
Tag: i.Tag,
Sniffing: i.Sniffing,
}
}
48 changes: 46 additions & 2 deletions v2ui/v2ui.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
package v2ui

import "errors"
import (
"fmt"
"x-ui/config"
"x-ui/database"
"x-ui/database/model"
"x-ui/util/common"
"x-ui/web/service"
)

func MigrateFromV2UI(dbPath string) error {
return errors.New("not support right now")
err := initDB(dbPath)
if err != nil {
return common.NewError("init v2-ui database failed:", err)
}
err = database.InitDB(config.GetDBPath())
if err != nil {
return common.NewError("init x-ui database failed:", err)
}

v2Inbounds, err := getV2Inbounds()
if err != nil {
return common.NewError("get v2-ui inbounds failed:", err)
}
if len(v2Inbounds) == 0 {
fmt.Println("migrate v2-ui inbounds success: 0")
return nil
}

userService := service.UserService{}
user, err := userService.GetFirstUser()
if err != nil {
return common.NewError("get x-ui user failed:", err)
}

inbounds := make([]*model.Inbound, 0)
for _, v2inbound := range v2Inbounds {
inbounds = append(inbounds, v2inbound.ToInbound(user.Id))
}

inboundService := service.InboundService{}
err = inboundService.AddInbounds(inbounds)
if err != nil {
return common.NewError("add x-ui inbounds failed:", err)
}

fmt.Println("migrate v2-ui inbounds success:", len(inbounds))

return nil
}
1 change: 0 additions & 1 deletion web/assets/ant-design-vue@1.7.2/antd.min.js

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions web/assets/js/model/xray.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ TcpStreamSettings.TcpRequest = class extends XrayCommonClass {
this.headers.push({ name: name, value: value });
}

getHeader(name) {
for (const header of this.headers) {
if (header.name.toLowerCase() === name.toLowerCase()) {
return header.value;
}
}
return null;
}

removeHeader(index) {
this.headers.splice(index, 1);
}
Expand Down Expand Up @@ -294,6 +303,15 @@ class WsStreamSettings extends XrayCommonClass {
this.headers.push({ name: name, value: value });
}

getHeader(name) {
for (const header of this.headers) {
if (header.name.toLowerCase() === name.toLowerCase()) {
return header.value;
}
}
return null;
}

removeHeader(index) {
this.headers.splice(index, 1);
}
Expand Down Expand Up @@ -643,6 +661,30 @@ class Inbound extends XrayCommonClass {
this.stream.network = network;
}

get isTcp() {
return this.network === "tcp";
}

get isWs() {
return this.network === "ws";
}

get isKcp() {
return this.network === "kcp";
}

get isQuic() {
return this.network === "quic"
}

get isGrpc() {
return this.network === "grpc";
}

get isH2() {
return this.network === "http";
}

// VMess & VLess
get uuid() {
switch (this.protocol) {
Expand Down Expand Up @@ -718,6 +760,52 @@ class Inbound extends XrayCommonClass {
return "";
}

get host() {
if (this.isTcp) {
return this.stream.tcp.request.getHeader("Host");
} else if (this.isWs) {
return this.stream.ws.getHeader("Host");
} else if (this.isH2) {
return this.stream.http.host[0];
}
return null;
}

get path() {
if (this.isTcp) {
return this.stream.tcp.request.path[0];
} else if (this.isWs) {
return this.stream.ws.path;
} else if (this.isH2) {
return this.stream.http.path[0];
}
return null;
}

get quicSecurity() {
return this.stream.quic.security;
}

get quicKey() {
return this.stream.quic.key;
}

get quicType() {
return this.stream.quic.type;
}

get kcpType() {
return this.stream.kcp.type;
}

get kcpSeed() {
return this.stream.kcp.seed;
}

get serviceName() {
return this.stream.grpc.serviceName;
}

canEnableTls() {
switch (this.protocol) {
case Protocols.VMESS:
Expand Down
27 changes: 24 additions & 3 deletions web/html/xui/component/inbound_info.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
{{define "inboundInfoStream"}}
<p>传输: <a-tag color="green">[[ inbound.network ]]</a-tag></p>

<!-- TODO -->
<template v-if="inbound.isTcp || inbound.isWs || inbound.isH2">
<p v-if="inbound.host">host: <a-tag color="green">[[ inbound.host ]]</a-tag></p>
<p v-else>host: <a-tag color="orange"></a-tag></p>

<p v-if="inbound.path">path: <a-tag color="green">[[ inbound.path ]]</a-tag></p>
<p v-else>path: <a-tag color="orange"></a-tag></p>
</template>

<template v-if="inbound.isQuic">
<p>quic 加密: <a-tag color="green">[[ inbound.quicSecurity ]]</a-tag></p>
<p>quic 密码: <a-tag color="green">[[ inbound.quicKey ]]</a-tag></p>
<p>quic 伪装: <a-tag color="green">[[ inbound.quicType ]]</a-tag></p>
</template>

<template v-if="inbound.isKcp">
<p>kcp 加密: <a-tag color="green">[[ inbound.kcpType ]]</a-tag></p>
<p>kcp 密码: <a-tag color="green">[[ inbound.kcpSeed ]]</a-tag></p>
</template>

<template v-if="inbound.isGrpc">
<p>grpc serviceName: <a-tag color="green">[[ inbound.serviceName ]]</a-tag></p>
</template>

<template v-if="inbound.tls || inbound.xtls">
<p v-if="inbound.tls">tls: <a-tag color="green">开启</a-tag></p>
Expand All @@ -11,10 +32,10 @@
<p>tls: <a-tag color="red">关闭</a-tag></p>
</template>
<p v-if="inbound.tls">
tls域名: <a-tag color="green">[[ inbound.serverName ? inbound.serverName : "无" ]]</a-tag>
tls域名: <a-tag :color="inbound.serverName ? 'green' : 'orange'">[[ inbound.serverName ? inbound.serverName : "无" ]]</a-tag>
</p>
<p v-if="inbound.xtls">
xtls域名: <a-tag color="green">[[ inbound.serverName ? inbound.serverName : "无" ]]</a-tag>
xtls域名: <a-tag :color="inbound.serverName ? 'green' : 'orange'">[[ inbound.serverName ? inbound.serverName : "无" ]]</a-tag>
</p>
{{end}}

Expand Down
27 changes: 23 additions & 4 deletions web/html/xui/inbound_info_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{template "component/inboundInfo"}}
<a-modal id="inbound-info-modal" v-model="infoModal.visible" title="详细信息" @ok="infoModal.ok"
:closable="true" :mask-closable="true"
ok-text="复制链接" cancel-text='{{ i18n "close" }}'>
ok-text="复制链接" cancel-text='{{ i18n "close" }}' :ok-button-props="infoModal.okBtnPros">
<inbound-info :db-inbound="dbInbound" :inbound="inbound"></inbound-info>
</a-modal>
<script>
Expand All @@ -11,20 +11,39 @@
visible: false,
inbound: new Inbound(),
dbInbound: new DBInbound(),
ok() {

clipboard: null,
okBtnPros: {
attrs: {
id: "inbound-info-modal-ok-btn",
style: "",
},
},
show(dbInbound) {
this.inbound = dbInbound.toInbound();
this.dbInbound = new DBInbound(dbInbound);
this.visible = true;

if (dbInbound.hasLink()) {
this.okBtnPros.attrs.style = "";
} else {
this.okBtnPros.attrs.style = "display: none";
}

if (this.clipboard == null) {
infoModalApp.$nextTick(() => {
this.clipboard = new ClipboardJS(`#${this.okBtnPros.attrs.id}`, {
text: () => this.dbInbound.genLink(),
});
this.clipboard.on('success', () => app.$message.success('复制成功'));
});
}
},
close() {
infoModal.visible = false;
},
};

new Vue({
const infoModalApp = new Vue({
delimiters: ['[[', ']]'],
el: '#inbound-info-modal',
data: {
Expand Down
Loading

0 comments on commit 89677c4

Please sign in to comment.