Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
 - 增加到期时间限制
 - 新增配置面板 https 访问后,http 自动跳转 https(同端口)
 - 降低获取系统连接数的 cpu 使用率
 - 优化界面
 - VMess 协议 alterId 默认改为 0
 - 修复旧版本 iOS 系统白屏问题
 - 修复重启面板后 xray 没有启动的问题
  • Loading branch information
vaxilu committed Jul 26, 2021
1 parent f1057b1 commit 292d5b8
Show file tree
Hide file tree
Showing 22 changed files with 473 additions and 146 deletions.
2 changes: 1 addition & 1 deletion config/version
@@ -1 +1 @@
0.2.0
0.3.0
10 changes: 8 additions & 2 deletions logger/logger.go
Expand Up @@ -7,16 +7,22 @@ import (

var logger *logging.Logger

func init() {
InitLogger(logging.INFO)
}

func InitLogger(level logging.Level) {
format := logging.MustStringFormatter(
`%{time:2006/01/02 15:04:05} %{level} - %{message}`,
)
logger = logging.MustGetLogger("x-ui")
newLogger := logging.MustGetLogger("x-ui")
backend := logging.NewLogBackend(os.Stderr, "", 0)
backendFormatter := logging.NewBackendFormatter(backend, format)
backendLeveled := logging.AddModuleLevel(backendFormatter)
backendLeveled.SetLevel(level, "")
logger.SetBackend(backendLeveled)
newLogger.SetBackend(backendLeveled)

logger = newLogger
}

func Debug(args ...interface{}) {
Expand Down
Empty file added util/sys/a.s
Empty file.
8 changes: 8 additions & 0 deletions util/sys/psutil.go
@@ -0,0 +1,8 @@
package sys

import (
_ "unsafe"
)

//go:linkname HostProc github.com/shirou/gopsutil/internal/common.HostProc
func HostProc(combineWith ...string) string
23 changes: 23 additions & 0 deletions util/sys/sys_darwin.go
@@ -0,0 +1,23 @@
// +build darwin

package sys

import (
"github.com/shirou/gopsutil/net"
)

func GetTCPCount() (int, error) {
stats, err := net.Connections("tcp")
if err != nil {
return 0, err
}
return len(stats), nil
}

func GetUDPCount() (int, error) {
stats, err := net.Connections("udp")
if err != nil {
return 0, err
}
return len(stats), nil
}
70 changes: 70 additions & 0 deletions util/sys/sys_linux.go
@@ -0,0 +1,70 @@
// +build linux

package sys

import (
"bytes"
"fmt"
"io"
"os"
)

func getLinesNum(filename string) (int, error) {
file, err := os.Open(filename)
if err != nil {
return 0, err
}
defer file.Close()

sum := 0
buf := make([]byte, 8192)
for {
n, err := file.Read(buf)

var buffPosition int
for {
i := bytes.IndexByte(buf[buffPosition:], '\n')
if i < 0 || n == buffPosition {
break
}
buffPosition += i + 1
sum++
}

if err == io.EOF {
return sum, nil
} else if err != nil {
return sum, err
}
}
}

func GetTCPCount() (int, error) {
root := HostProc()

tcp4, err := getLinesNum(fmt.Sprintf("%v/net/tcp", root))
if err != nil {
return tcp4, err
}
tcp6, err := getLinesNum(fmt.Sprintf("%v/net/tcp6", root))
if err != nil {
return tcp4 + tcp6, nil
}

return tcp4 + tcp6, nil
}

func GetUDPCount() (int, error) {
root := HostProc()

udp4, err := getLinesNum(fmt.Sprintf("%v/net/udp", root))
if err != nil {
return udp4, err
}
udp6, err := getLinesNum(fmt.Sprintf("%v/net/udp6", root))
if err != nil {
return udp4 + udp6, nil
}

return udp4 + udp6, nil
}
83 changes: 54 additions & 29 deletions web/assets/js/model/models.js
@@ -1,14 +1,18 @@
class User {
username = "";
password = "";

constructor() {
this.username = "";
this.password = "";
}
}

class Msg {
success = false;
msg = "";
obj = null;

constructor(success, msg, obj) {
this.success = false;
this.msg = "";
this.obj = null;

if (success != null) {
this.success = success;
}
Expand All @@ -22,24 +26,25 @@ class Msg {
}

class DBInbound {
id = 0;
userId = 0;
up = 0;
down = 0;
total = 0;
remark = "";
enable = true;
expiryTime = 0;

listen = "";
port = 0;
protocol = "";
settings = "";
streamSettings = "";
tag = "";
sniffing = "";

constructor(data) {
this.id = 0;
this.userId = 0;
this.up = 0;
this.down = 0;
this.total = 0;
this.remark = "";
this.enable = true;
this.expiryTime = 0;

this.listen = "";
this.port = 0;
this.protocol = "";
this.settings = "";
this.streamSettings = "";
this.tag = "";
this.sniffing = "";

if (data == null) {
return;
}
Expand Down Expand Up @@ -86,6 +91,25 @@ class DBInbound {
return address;
}

get _expiryTime() {
if (this.expiryTime === 0) {
return null;
}
return moment(this.expiryTime);
}

set _expiryTime(t) {
if (t == null) {
this.expiryTime = 0;
} else {
this.expiryTime = t.valueOf();
}
}

get isExpiry() {
return this.expiryTime < new Date().getTime();
}

toInbound() {
let settings = {};
if (!ObjectUtil.isEmpty(this.settings)) {
Expand Down Expand Up @@ -132,17 +156,18 @@ class DBInbound {
}

class AllSetting {
webListen = "";
webPort = 54321;
webCertFile = "";
webKeyFile = "";
webBasePath = "/";

xrayTemplateConfig = "";
constructor(data) {
this.webListen = "";
this.webPort = 54321;
this.webCertFile = "";
this.webKeyFile = "";
this.webBasePath = "/";

timeLocation = "Asia/Shanghai";
this.xrayTemplateConfig = "";

this.timeLocation = "Asia/Shanghai";

constructor(data) {
if (data == null) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion web/assets/js/model/xray.js
Expand Up @@ -1165,7 +1165,7 @@ Inbound.VmessSettings = class extends Inbound.Settings {
}
};
Inbound.VmessSettings.Vmess = class extends XrayCommonClass {
constructor(id=RandomUtil.randomUUID(), alterId=64) {
constructor(id=RandomUtil.randomUUID(), alterId=0) {
super();
this.id = id;
this.alterId = alterId;
Expand Down
29 changes: 15 additions & 14 deletions web/assets/js/util/utils.js
Expand Up @@ -77,18 +77,19 @@ class PromiseUtil {

}

const seq = [
'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z'
];

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

static randomIntRange(min, max) {
return parseInt(Math.random() * (max - min) + min, 10);
Expand All @@ -101,15 +102,15 @@ class RandomUtil {
static randomSeq(count) {
let str = '';
for (let i = 0; i < count; ++i) {
str += this.seq[this.randomInt(62)];
str += seq[this.randomInt(62)];
}
return str;
}

static randomLowerAndNum(count) {
let str = '';
for (let i = 0; i < count; ++i) {
str += this.seq[this.randomInt(36)];
str += seq[this.randomInt(36)];
}
return str;
}
Expand All @@ -121,7 +122,7 @@ class RandomUtil {
if (index <= 9) {
str += index;
} else {
str += this.seq[index - 10];
str += seq[index - 10];
}
}
return str;
Expand Down
2 changes: 1 addition & 1 deletion web/controller/inbound.go
Expand Up @@ -37,7 +37,7 @@ func (a *InboundController) startTask() {
c := webServer.GetCron()
c.AddFunc("@every 10s", func() {
if a.xrayService.IsNeedRestartAndSetFalse() {
err := a.xrayService.RestartXray()
err := a.xrayService.RestartXray(false)
if err != nil {
logger.Error("restart xray failed:", err)
}
Expand Down
13 changes: 13 additions & 0 deletions web/html/xui/form/inbound.html
Expand Up @@ -39,6 +39,19 @@
</span>
<a-input-number v-model="dbInbound.totalGB" :min="0"></a-input-number>
</a-form-item>
<a-form-item>
<span slot="label">
到期时间
<a-tooltip>
<template slot="title">
留空则永不到期
</template>
<a-icon type="question-circle" theme="filled"></a-icon>
</a-tooltip>
</span>
<a-date-picker :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm"
v-model="dbInbound._expiryTime" style="width: 300px;"></a-date-picker>
</a-form-item>
</a-form>

<!-- vmess settings -->
Expand Down

1 comment on commit 292d5b8

@shminer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addFallback() {

大佬,容我多个需求
就是类似于fallback这样 ,可以在同一个bind port上绑定多个UUID,可以增删的那种。(可能会影响到多个UUID的流量统计,可能会整复杂了)
这种主要是为了解决伪装时可以不用bind多个端口。

作者看来被各种小白问题惹恼了。。。如果不愿意写的话等我去学学js。。。。

............................
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "xxxxxx",
"flow": "xtls-rprx-direct",
"level": 0,
"email": "xxxxxx"
},
{
"id": "xxxxx",
"flow": "xtls-rprx-direct",
"level": 0,
"email": "xxxxxxx"
}
]
...................................

Please sign in to comment.