Skip to content

Commit 292d5b8

Browse files
committed
0.3.0
- 增加到期时间限制 - 新增配置面板 https 访问后,http 自动跳转 https(同端口) - 降低获取系统连接数的 cpu 使用率 - 优化界面 - VMess 协议 alterId 默认改为 0 - 修复旧版本 iOS 系统白屏问题 - 修复重启面板后 xray 没有启动的问题
1 parent f1057b1 commit 292d5b8

22 files changed

+473
-146
lines changed

config/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.3.0

logger/logger.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ import (
77

88
var logger *logging.Logger
99

10+
func init() {
11+
InitLogger(logging.INFO)
12+
}
13+
1014
func InitLogger(level logging.Level) {
1115
format := logging.MustStringFormatter(
1216
`%{time:2006/01/02 15:04:05} %{level} - %{message}`,
1317
)
14-
logger = logging.MustGetLogger("x-ui")
18+
newLogger := logging.MustGetLogger("x-ui")
1519
backend := logging.NewLogBackend(os.Stderr, "", 0)
1620
backendFormatter := logging.NewBackendFormatter(backend, format)
1721
backendLeveled := logging.AddModuleLevel(backendFormatter)
1822
backendLeveled.SetLevel(level, "")
19-
logger.SetBackend(backendLeveled)
23+
newLogger.SetBackend(backendLeveled)
24+
25+
logger = newLogger
2026
}
2127

2228
func Debug(args ...interface{}) {

util/sys/a.s

Whitespace-only changes.

util/sys/psutil.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package sys
2+
3+
import (
4+
_ "unsafe"
5+
)
6+
7+
//go:linkname HostProc github.com/shirou/gopsutil/internal/common.HostProc
8+
func HostProc(combineWith ...string) string

util/sys/sys_darwin.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// +build darwin
2+
3+
package sys
4+
5+
import (
6+
"github.com/shirou/gopsutil/net"
7+
)
8+
9+
func GetTCPCount() (int, error) {
10+
stats, err := net.Connections("tcp")
11+
if err != nil {
12+
return 0, err
13+
}
14+
return len(stats), nil
15+
}
16+
17+
func GetUDPCount() (int, error) {
18+
stats, err := net.Connections("udp")
19+
if err != nil {
20+
return 0, err
21+
}
22+
return len(stats), nil
23+
}

util/sys/sys_linux.go

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// +build linux
2+
3+
package sys
4+
5+
import (
6+
"bytes"
7+
"fmt"
8+
"io"
9+
"os"
10+
)
11+
12+
func getLinesNum(filename string) (int, error) {
13+
file, err := os.Open(filename)
14+
if err != nil {
15+
return 0, err
16+
}
17+
defer file.Close()
18+
19+
sum := 0
20+
buf := make([]byte, 8192)
21+
for {
22+
n, err := file.Read(buf)
23+
24+
var buffPosition int
25+
for {
26+
i := bytes.IndexByte(buf[buffPosition:], '\n')
27+
if i < 0 || n == buffPosition {
28+
break
29+
}
30+
buffPosition += i + 1
31+
sum++
32+
}
33+
34+
if err == io.EOF {
35+
return sum, nil
36+
} else if err != nil {
37+
return sum, err
38+
}
39+
}
40+
}
41+
42+
func GetTCPCount() (int, error) {
43+
root := HostProc()
44+
45+
tcp4, err := getLinesNum(fmt.Sprintf("%v/net/tcp", root))
46+
if err != nil {
47+
return tcp4, err
48+
}
49+
tcp6, err := getLinesNum(fmt.Sprintf("%v/net/tcp6", root))
50+
if err != nil {
51+
return tcp4 + tcp6, nil
52+
}
53+
54+
return tcp4 + tcp6, nil
55+
}
56+
57+
func GetUDPCount() (int, error) {
58+
root := HostProc()
59+
60+
udp4, err := getLinesNum(fmt.Sprintf("%v/net/udp", root))
61+
if err != nil {
62+
return udp4, err
63+
}
64+
udp6, err := getLinesNum(fmt.Sprintf("%v/net/udp6", root))
65+
if err != nil {
66+
return udp4 + udp6, nil
67+
}
68+
69+
return udp4 + udp6, nil
70+
}

web/assets/js/model/models.js

+54-29
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
class User {
2-
username = "";
3-
password = "";
2+
3+
constructor() {
4+
this.username = "";
5+
this.password = "";
6+
}
47
}
58

69
class Msg {
7-
success = false;
8-
msg = "";
9-
obj = null;
1010

1111
constructor(success, msg, obj) {
12+
this.success = false;
13+
this.msg = "";
14+
this.obj = null;
15+
1216
if (success != null) {
1317
this.success = success;
1418
}
@@ -22,24 +26,25 @@ class Msg {
2226
}
2327

2428
class DBInbound {
25-
id = 0;
26-
userId = 0;
27-
up = 0;
28-
down = 0;
29-
total = 0;
30-
remark = "";
31-
enable = true;
32-
expiryTime = 0;
33-
34-
listen = "";
35-
port = 0;
36-
protocol = "";
37-
settings = "";
38-
streamSettings = "";
39-
tag = "";
40-
sniffing = "";
4129

4230
constructor(data) {
31+
this.id = 0;
32+
this.userId = 0;
33+
this.up = 0;
34+
this.down = 0;
35+
this.total = 0;
36+
this.remark = "";
37+
this.enable = true;
38+
this.expiryTime = 0;
39+
40+
this.listen = "";
41+
this.port = 0;
42+
this.protocol = "";
43+
this.settings = "";
44+
this.streamSettings = "";
45+
this.tag = "";
46+
this.sniffing = "";
47+
4348
if (data == null) {
4449
return;
4550
}
@@ -86,6 +91,25 @@ class DBInbound {
8691
return address;
8792
}
8893

94+
get _expiryTime() {
95+
if (this.expiryTime === 0) {
96+
return null;
97+
}
98+
return moment(this.expiryTime);
99+
}
100+
101+
set _expiryTime(t) {
102+
if (t == null) {
103+
this.expiryTime = 0;
104+
} else {
105+
this.expiryTime = t.valueOf();
106+
}
107+
}
108+
109+
get isExpiry() {
110+
return this.expiryTime < new Date().getTime();
111+
}
112+
89113
toInbound() {
90114
let settings = {};
91115
if (!ObjectUtil.isEmpty(this.settings)) {
@@ -132,17 +156,18 @@ class DBInbound {
132156
}
133157

134158
class AllSetting {
135-
webListen = "";
136-
webPort = 54321;
137-
webCertFile = "";
138-
webKeyFile = "";
139-
webBasePath = "/";
140159

141-
xrayTemplateConfig = "";
160+
constructor(data) {
161+
this.webListen = "";
162+
this.webPort = 54321;
163+
this.webCertFile = "";
164+
this.webKeyFile = "";
165+
this.webBasePath = "/";
142166

143-
timeLocation = "Asia/Shanghai";
167+
this.xrayTemplateConfig = "";
168+
169+
this.timeLocation = "Asia/Shanghai";
144170

145-
constructor(data) {
146171
if (data == null) {
147172
return
148173
}

web/assets/js/model/xray.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ Inbound.VmessSettings = class extends Inbound.Settings {
11651165
}
11661166
};
11671167
Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
1168-
constructor(id=RandomUtil.randomUUID(), alterId=64) {
1168+
constructor(id=RandomUtil.randomUUID(), alterId=0) {
11691169
super();
11701170
this.id = id;
11711171
this.alterId = alterId;

web/assets/js/util/utils.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,19 @@ class PromiseUtil {
7777

7878
}
7979

80+
const seq = [
81+
'a', 'b', 'c', 'd', 'e', 'f', 'g',
82+
'h', 'i', 'j', 'k', 'l', 'm', 'n',
83+
'o', 'p', 'q', 'r', 's', 't',
84+
'u', 'v', 'w', 'x', 'y', 'z',
85+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
86+
'A', 'B', 'C', 'D', 'E', 'F', 'G',
87+
'H', 'I', 'J', 'K', 'L', 'M', 'N',
88+
'O', 'P', 'Q', 'R', 'S', 'T',
89+
'U', 'V', 'W', 'X', 'Y', 'Z'
90+
];
91+
8092
class RandomUtil {
81-
static seq = [
82-
'a', 'b', 'c', 'd', 'e', 'f', 'g',
83-
'h', 'i', 'j', 'k', 'l', 'm', 'n',
84-
'o', 'p', 'q', 'r', 's', 't',
85-
'u', 'v', 'w', 'x', 'y', 'z',
86-
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
87-
'A', 'B', 'C', 'D', 'E', 'F', 'G',
88-
'H', 'I', 'J', 'K', 'L', 'M', 'N',
89-
'O', 'P', 'Q', 'R', 'S', 'T',
90-
'U', 'V', 'W', 'X', 'Y', 'Z'
91-
];
9293

9394
static randomIntRange(min, max) {
9495
return parseInt(Math.random() * (max - min) + min, 10);
@@ -101,15 +102,15 @@ class RandomUtil {
101102
static randomSeq(count) {
102103
let str = '';
103104
for (let i = 0; i < count; ++i) {
104-
str += this.seq[this.randomInt(62)];
105+
str += seq[this.randomInt(62)];
105106
}
106107
return str;
107108
}
108109

109110
static randomLowerAndNum(count) {
110111
let str = '';
111112
for (let i = 0; i < count; ++i) {
112-
str += this.seq[this.randomInt(36)];
113+
str += seq[this.randomInt(36)];
113114
}
114115
return str;
115116
}
@@ -121,7 +122,7 @@ class RandomUtil {
121122
if (index <= 9) {
122123
str += index;
123124
} else {
124-
str += this.seq[index - 10];
125+
str += seq[index - 10];
125126
}
126127
}
127128
return str;

web/controller/inbound.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (a *InboundController) startTask() {
3737
c := webServer.GetCron()
3838
c.AddFunc("@every 10s", func() {
3939
if a.xrayService.IsNeedRestartAndSetFalse() {
40-
err := a.xrayService.RestartXray()
40+
err := a.xrayService.RestartXray(false)
4141
if err != nil {
4242
logger.Error("restart xray failed:", err)
4343
}

web/html/xui/form/inbound.html

+13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@
3939
</span>
4040
<a-input-number v-model="dbInbound.totalGB" :min="0"></a-input-number>
4141
</a-form-item>
42+
<a-form-item>
43+
<span slot="label">
44+
到期时间
45+
<a-tooltip>
46+
<template slot="title">
47+
留空则永不到期
48+
</template>
49+
<a-icon type="question-circle" theme="filled"></a-icon>
50+
</a-tooltip>
51+
</span>
52+
<a-date-picker :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm"
53+
v-model="dbInbound._expiryTime" style="width: 300px;"></a-date-picker>
54+
</a-form-item>
4255
</a-form>
4356

4457
<!-- vmess settings -->

0 commit comments

Comments
 (0)