Compare commits

...
22 Commits
Author SHA1 Message Date
yisier 19a1e31904 log 2024-01-02 22:57:48 +08:00
yisier bc9525938a Merge pull request #116 from lesteryou/logs
log中remoteAddr优先从X-Forwarded-For中获取
2024-01-02 22:28:28 +08:00
yisier 605b6af9d5 tls 流量加密 2024-01-02 22:02:03 +08:00
lesteryou 0c25fca0f8 Merge branch 'master' into logs 2023-08-21 14:44:07 +08:00
lesteryou 790d985afc log中remoteAddr优先从X-Forwarded-For中获取 2023-08-21 14:12:45 +08:00
yisier 4a347fe301 新增一次客户端,列表会增加2个一样的客户端,Bug 修复 2023-06-05 23:34:22 +08:00
yisier 05011dec7b 新增一次客户端,列表会增加2个一样的客户端,Bug 修复 2023-06-05 23:32:22 +08:00
yisier 0d9b65ce8a Merge remote-tracking branch 'origin/master' 2023-06-05 23:10:41 +08:00
yisier 97f39e5124 dockerfile 2023-06-05 23:10:18 +08:00
yisier 9aea12ce5a Update README.md 2023-06-03 14:06:57 +08:00
yisier b96555fa42 dockerfile 2023-06-02 17:53:49 +08:00
yisier 59a7a4e529 dockerfile 2023-06-02 17:27:29 +08:00
yisier 691a4d00f8 QQ group 2023-06-02 17:00:34 +08:00
yisier dc1e9a8aaa build 2023-06-02 10:33:15 +08:00
yisier 05cc45b068 ***修复***:https 流量不统计 Bug 修复。
***新增***:新增全局黑名单IP,用于防止被肉鸡扫描端口或被恶意攻击。
  ***新增***:新增客户端上次在线时间。
2023-06-01 18:01:43 +08:00
yisier 00e4fc7a46 Merge branch 'dev' 2023-05-31 09:46:31 +08:00
yisier 5202ff3450 https 流量统计bug fix 2023-05-29 11:51:30 +08:00
yisier 5d24ada208 Update README.md 2023-05-17 11:12:57 +08:00
yisier fda685d0e1 Update README.md 2023-05-05 10:48:33 +08:00
yisier 4306090a8a Update README.md 2023-04-25 15:25:06 +08:00
yisier c7db78dac9 rollback install server 2023-04-01 01:31:42 +08:00
yisier e19b776cd4 Update README.md 2023-02-24 22:06:59 +08:00
34 changed files with 354 additions and 24 deletions
+1 -1
View File
@@ -70,4 +70,4 @@ jobs:
windows_amd64_server.tar.gz
npc_sdk.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+1 -1
View File
@@ -2,7 +2,7 @@ FROM golang:1.15 as builder
ARG GOPROXY=direct
WORKDIR /go/src/ehang.io/nps
COPY . .
RUN go get -d -v ./...
RUN go get -d -v ./...
RUN CGO_ENABLED=0 go build -ldflags="-w -s -extldflags -static" ./cmd/nps/nps.go
FROM scratch
+19 -3
View File
@@ -1,4 +1,3 @@
# NPS
[README](https://github.com/ehang-io/nps/blob/master/README.md)|[中文文档](https://github.com/ehang-io/nps/blob/master/README_zh.md)
@@ -10,18 +9,35 @@
***DockerHub***: [NPS](https://hub.docker.com/r/yisier1/nps) [NPC](https://hub.docker.com/r/yisier1/npc)
# 交流群
聊天灌水QQ群:619833483
# 捐赠
![image](image/new/payCode.png)
## 更新日志
- 2024-01-02 v0.27.01
***新增***:tls 流量加密,(客户端忽略证书校验,谨慎使用,客户端与服务端需要同时开启,或同时关闭),使用方式:
服务端:nps.conf `tls_enable=true`;
客户端:npc.conf `tls_enable=true` 或者 `npc.exe -server=xxx -vkey=xxx -tls_enable=true`
- 2023-06-01 v0.26.16
***修复***:https 流量不统计 Bug 修复。
***新增***:新增全局黑名单IP,用于防止被肉鸡扫描端口或被恶意攻击。
***新增***:新增客户端上次在线时间。
- 2023-02-24 v0.26.15
***修复***:更新程序 url 更改到当前仓库中
***修复***:nps 在外部路径启动时找不到配置文件
***新增***:增加 nps 启动参数,`-conf_path=D:\test\nps`,可用于加载指定nps配置文件和web文件目录。
***window 使用示例:***
启动:`nps.exe -conf_path=D:\test\nps`
直接启动:`nps.exe -conf_path=D:\test\nps`
安装:`nps.exe install -conf_path=D:\test\nps`
安装启动:`nps start`
安装启动:`nps.exe start`
***linux 使用示例:***
直接启动:`./nps -conf_path=/app/nps`
+11 -1
View File
@@ -1,6 +1,8 @@
package bridge
import (
"crypto/tls"
_ "crypto/tls"
"ehang.io/nps/lib/nps_mux"
"encoding/binary"
"errors"
@@ -23,6 +25,8 @@ import (
"github.com/astaxie/beego/logs"
)
var ServerTlsEnable bool = false
type Client struct {
tunnel *nps_mux.Mux
signal *conn.Conn
@@ -82,8 +86,14 @@ func (s *Bridge) StartTunnel() error {
os.Exit(0)
return err
}
conn.Accept(listener, func(c net.Conn) {
s.cliProcess(conn.NewConn(c))
// tls
if ServerTlsEnable {
s.cliProcess(conn.NewConn(tls.Server(c, &tls.Config{Certificates: []tls.Certificate{crypt.GetCert()}})))
} else {
s.cliProcess(conn.NewConn(c))
}
})
}
return nil
+1 -1
View File
@@ -1,5 +1,5 @@
#/bash/sh
export VERSION=0.26.12
export VERSION=0.26.16
export GOPROXY=direct
sudo apt-get update
+6 -1
View File
@@ -7,6 +7,7 @@ import (
"net"
"net/http"
"strconv"
"strings"
"sync"
"time"
@@ -197,7 +198,11 @@ func (s *TRPClient) handleChan(src net.Conn) {
targetConn.Close()
break
} else {
logs.Trace("http request, method %s, host %s, url %s, remote address %s", r.Method, r.Host, r.URL.Path, r.RemoteAddr)
remoteAddr := strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
if len(remoteAddr) == 0 {
remoteAddr = r.RemoteAddr
}
logs.Trace("http request, method %s, host %s, url %s, remote address %s", r.Method, r.Host, r.URL.Path, remoteAddr)
r.Write(targetConn)
}
}
+22 -1
View File
@@ -2,6 +2,7 @@ package client
import (
"bufio"
"crypto/tls"
"encoding/base64"
"encoding/binary"
"errors"
@@ -29,6 +30,16 @@ import (
"golang.org/x/net/proxy"
)
var tlsEnable1 = false
func SetTlsEnable(tlsEnable11 bool) {
tlsEnable1 = tlsEnable11
}
func GetTlsEnable() bool {
return tlsEnable1
}
func GetTaskStatus(path string) {
cnf, err := config.NewConfig(path)
if err != nil {
@@ -96,6 +107,8 @@ func StartFromFile(path string) {
}
logs.Info("Loading configuration file %s successfully", path)
SetTlsEnable(cnf.CommonConfig.TlsEnable)
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), GetTlsEnable())
re:
if first || cnf.CommonConfig.AutoReconnection {
if !first {
@@ -202,7 +215,15 @@ func NewConn(tp string, vkey string, server string, connType string, proxyUrl st
connection, err = NewHttpProxyConn(u, server)
}
} else {
connection, err = net.Dial("tcp", server)
if GetTlsEnable() {
//tls 流量加密
conf := &tls.Config{
InsecureSkipVerify: true,
}
connection, err = tls.Dial("tcp", server, conf)
} else {
connection, err = net.Dial("tcp", server)
}
}
} else {
sess, err = kcp.DialWithOptions(server, nil, 10, 3)
+3 -1
View File
@@ -39,6 +39,7 @@ var (
stunAddr = flag.String("stun_addr", "stun.stunprotocol.org:3478", "stun server address (eg:stun.stunprotocol.org:3478)")
ver = flag.Bool("version", false, "show current version")
disconnectTime = flag.Int("disconnect_timeout", 60, "not receiving check packet times, until timeout will disconnect the client")
tlsEnable = flag.Bool("tls_enable", false, "enable tls")
)
func main() {
@@ -228,8 +229,9 @@ func run() {
if *verifyKey == "" {
*verifyKey, _ = env["NPC_SERVER_VKEY"]
}
logs.Info("the version of client is %s, the core version of client is %s", version.VERSION, version.GetVersion())
if *verifyKey != "" && *serverAddr != "" && *configPath == "" {
client.SetTlsEnable(*tlsEnable)
logs.Info("the version of client is %s, the core version of client is %s,tls enable is %t", version.VERSION, version.GetVersion(), client.GetTlsEnable())
go func() {
for {
client.NewRPClient(*serverAddr, *verifyKey, *connType, *proxyUrl, nil, *disconnectTime).Start()
+4 -1
View File
@@ -1,6 +1,7 @@
package main
import (
"ehang.io/nps/bridge"
"ehang.io/nps/lib/daemon"
"flag"
"log"
@@ -80,6 +81,8 @@ func main() {
Option: options,
}
bridge.ServerTlsEnable = beego.AppConfig.DefaultBool("tls_enable", false)
for _, v := range os.Args[1:] {
switch v {
case "install", "start", "stop", "uninstall", "restart":
@@ -227,7 +230,7 @@ func run() {
}
logs.Info("the config path is:" + common.GetRunPath())
logs.Info("the version of server is %s ,allow client core version to be %s", version.VERSION, version.GetVersion())
logs.Info("the version of server is %s ,allow client core version to be %s,tls enable is %t", version.VERSION, version.GetVersion(), bridge.ServerTlsEnable)
connection.InitConnectionService()
//crypt.InitTls(filepath.Join(common.GetRunPath(), "conf", "server.pem"), filepath.Join(common.GetRunPath(), "conf", "server.key"))
crypt.InitTls()
+2
View File
@@ -0,0 +1,2 @@
{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"a82kjhdyllqnlruk","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":551,"InletFlow":551,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.12","BlackIpList":[""]}
*#*
+2
View File
@@ -0,0 +1,2 @@
{"Id":1,"Host":"testlocal.com","HeaderChange":"","HostChange":"","Location":"/","Remark":"","Scheme":"all","CertFilePath":"","KeyFilePath":"","NoStore":false,"IsClose":false,"Flow":{"ExportFlow":0,"InletFlow":0,"FlowLimit":0},"Client":{"Cnf":{"U":"","P":"","Compress":false,"Crypt":false},"Id":2,"VerifyKey":"a82kjhdyllqnlruk","Addr":"127.0.0.1","Remark":"","Status":true,"IsConnect":false,"RateLimit":0,"Flow":{"ExportFlow":551,"InletFlow":551,"FlowLimit":0},"Rate":{"NowRate":0},"NoStore":false,"NoDisplay":false,"MaxConn":0,"NowConn":0,"WebUserName":"","WebPassword":"","ConfigConnAllow":true,"MaxTunnelNum":0,"Version":"0.26.12","BlackIpList":[""]},"Target":{"TargetStr":"127.0.0.1:8080","TargetArr":["127.0.0.1:8080"],"LocalProxy":false}}
*#*
+1
View File
@@ -14,6 +14,7 @@ crypt=true
compress=true
#pprof_addr=0.0.0.0:9999
disconnect_timeout=60
tls_enable = true
[health_check_test1]
health_check_timeout=1
+8 -2
View File
@@ -51,7 +51,9 @@ web_key_file=conf/server.key
#Web API unauthenticated IP address(the len of auth_crypt_key must be 16)
#Remove comments if needed
#auth_key=test
auth_crypt_key =1234567812345678
auth_key=123
#获取服务端authKey时的aes加密密钥,16位
auth_crypt_key =213
#allow_ports=9001-9009,10001,11000-12000
@@ -92,4 +94,8 @@ http_add_origin_header=false
disconnect_timeout=60
#管理面板开启验证码校验
open_captcha=true
open_captcha=false
# 是否开启tls
tls_enable=true
-2
View File
@@ -1,6 +1,4 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
ehang.io/nps-mux v0.0.0-20210407130203-4afa0c10c992 h1:LvlcB+8JveSBprHnva0g+OyLwAH8CRxEwtWzTe6ocoE=
ehang.io/nps-mux v0.0.0-20210407130203-4afa0c10c992/go.mod h1:v54y/8ICChiM/aVUuKxGIcWwjm4HGNRyyAwbgLBoMbI=
fyne.io/fyne/v2 v2.0.2 h1:6pDvFuCmL1odyT/fPI+2L54hMJW1Zt9Dno41HmLInRs=
fyne.io/fyne/v2 v2.0.2/go.mod h1:3+FYmLJVgeb8EvTPJ5YzZeo7LkAq4bbuY3Zrir6xHbg=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

+3
View File
@@ -15,6 +15,7 @@ type CommonConfig struct {
VKey string
Tp string //bridgeType kcp or tcp
AutoReconnection bool
TlsEnable bool
ProxyUrl string
Client *file.Client
DisconnectTime int
@@ -150,6 +151,8 @@ func dealCommon(s string) *CommonConfig {
common.InitPProfFromArg(item[1])
case "disconnect_timeout":
c.DisconnectTime = common.GetIntNoErrByStr(item[1])
case "tls_enable":
c.TlsEnable = common.GetBoolByStr(item[1])
}
}
return c
+4
View File
@@ -30,6 +30,10 @@ func InitTls() {
}
}
func GetCert() tls.Certificate {
return cert
}
func NewTlsServerConn(conn net.Conn) net.Conn {
var err error
if err != nil {
+11
View File
@@ -29,6 +29,7 @@ func GetDb() *DbUtils {
jsonDb.LoadClientFromJsonFile()
jsonDb.LoadTaskFromJsonFile()
jsonDb.LoadHostFromJsonFile()
jsonDb.LoadGlobalFromJsonFile()
Db = &DbUtils{JsonDb: jsonDb}
})
return Db
@@ -115,6 +116,12 @@ func (s *DbUtils) UpdateTask(t *Tunnel) error {
return nil
}
func (s *DbUtils) SaveGlobal(t *Glob) error {
s.JsonDb.Global = t
s.JsonDb.StoreGlobalToJsonFile()
return nil
}
func (s *DbUtils) DelTask(id int) error {
s.JsonDb.Tasks.Delete(id)
s.JsonDb.StoreTasksToJsonFile()
@@ -288,6 +295,10 @@ func (s *DbUtils) GetClient(id int) (c *Client, err error) {
return
}
func (s *DbUtils) GetGlobal() (c *Glob) {
return s.JsonDb.Global
}
func (s *DbUtils) GetClientIdByVkey(vkey string) (id int, err error) {
var exist bool
s.JsonDb.Clients.Range(func(key, value interface{}) bool {
+59
View File
@@ -20,6 +20,7 @@ func NewJsonDb(runPath string) *JsonDb {
TaskFilePath: filepath.Join(runPath, "conf", "tasks.json"),
HostFilePath: filepath.Join(runPath, "conf", "hosts.json"),
ClientFilePath: filepath.Join(runPath, "conf", "clients.json"),
GlobalFilePath: filepath.Join(runPath, "conf", "global.json"),
}
}
@@ -28,6 +29,7 @@ type JsonDb struct {
Hosts sync.Map
HostsTmp sync.Map
Clients sync.Map
Global *Glob
RunPath string
ClientIncreaseId int32 //client increased id
TaskIncreaseId int32 //task increased id
@@ -35,6 +37,7 @@ type JsonDb struct {
TaskFilePath string //task file path
HostFilePath string //host file path
ClientFilePath string //client file path
GlobalFilePath string //global file path
}
func (s *JsonDb) LoadTaskFromJsonFile() {
@@ -91,6 +94,16 @@ func (s *JsonDb) LoadHostFromJsonFile() {
})
}
func (s *JsonDb) LoadGlobalFromJsonFile() {
loadSyncMapFromFileWithSingleJson(s.GlobalFilePath, func(v string) {
post := new(Glob)
if json.Unmarshal([]byte(v), &post) != nil {
return
}
s.Global = post
})
}
func (s *JsonDb) GetClient(id int) (c *Client, err error) {
if v, ok := s.Clients.Load(id); ok {
c = v.(*Client)
@@ -124,6 +137,14 @@ func (s *JsonDb) StoreClientsToJsonFile() {
clientLock.Unlock()
}
var globalLock sync.Mutex
func (s *JsonDb) StoreGlobalToJsonFile() {
globalLock.Lock()
storeGlobalToFile(s.Global, s.GlobalFilePath)
globalLock.Unlock()
}
func (s *JsonDb) GetClientId() int32 {
return atomic.AddInt32(&s.ClientIncreaseId, 1)
}
@@ -146,6 +167,19 @@ func loadSyncMapFromFile(filePath string, f func(value string)) {
}
}
func loadSyncMapFromFileWithSingleJson(filePath string, f func(value string)) {
if !common.FileExists(filePath) {
return
}
b, err := common.ReadAllFromFile(filePath)
if err != nil {
panic(err)
}
f(string(b))
}
func storeSyncMapToFile(m sync.Map, filePath string) {
file, err := os.Create(filePath + ".tmp")
// first create a temporary file to store
@@ -174,6 +208,9 @@ func storeSyncMapToFile(m sync.Map, filePath string) {
return true
}
b, err = json.Marshal(obj)
//case *Glob:
// obj := value.(*Glob)
// b, err = json.Marshal(obj)
default:
return true
}
@@ -199,3 +236,25 @@ func storeSyncMapToFile(m sync.Map, filePath string) {
}
// replace the file, maybe provides atomic operation
}
func storeGlobalToFile(m *Glob, filePath string) {
file, err := os.Create(filePath + ".tmp")
// first create a temporary file to store
if err != nil {
panic(err)
}
var b []byte
b, err = json.Marshal(m)
_, err = file.Write(b)
if err != nil {
panic(err)
}
_ = file.Sync()
_ = file.Close()
// must close file first, then rename it
err = os.Rename(filePath+".tmp", filePath)
if err != nil {
logs.Error(err, "store to file err, data will lost")
}
}
+6
View File
@@ -52,6 +52,7 @@ type Client struct {
MaxTunnelNum int
Version string
BlackIpList []string
LastOnlineTime string
sync.RWMutex
}
@@ -210,3 +211,8 @@ func (s *Target) GetRandomTarget() (string, error) {
s.nowIndex++
return s.TargetArr[s.nowIndex], nil
}
type Glob struct {
BlackIpList []string
sync.RWMutex
}
+2 -2
View File
@@ -1,8 +1,8 @@
package version
const VERSION = "0.26.14"
const VERSION = "0.27.01"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {
return "0.26.0"
return "0.27.0"
}
+21
View File
@@ -97,6 +97,12 @@ func in(target string, str_array []string) bool {
func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string,
rb []byte, tp string, f func(), flow *file.Flow, localProxy bool, task *file.Tunnel) error {
// 判断访问地址是否在全局黑名单内
if IsGlobalBlackIp(c.RemoteAddr().String()) {
c.Close()
return nil
}
// 判断访问地址是否在黑名单内
if common.IsBlackIp(c.RemoteAddr().String(), client.VerifyKey, client.BlackIpList) {
c.Close()
@@ -116,3 +122,18 @@ func (s *BaseServer) DealClient(c *conn.Conn, client *file.Client, addr string,
}
return nil
}
// 判断访问地址是否在全局黑名单内
func IsGlobalBlackIp(ipPort string) bool {
// 判断访问地址是否在全局黑名单内
global := file.GetDb().GetGlobal()
if global != nil {
ip := common.GetIpByAddr(ipPort)
if in(ip, global.BlackIpList) {
logs.Error("IP地址[" + ip + "]在全局黑名单列表内")
return true
}
}
return false
}
+14 -1
View File
@@ -133,6 +133,7 @@ func (s *httpServer) handleHttp(c *conn.Conn, r *http.Request) {
lenConn *conn.LenConn
isReset bool
wg sync.WaitGroup
remoteAddr string
)
defer func() {
if connClient != nil {
@@ -166,6 +167,12 @@ reset:
return
}
// 判断访问地址是否在全局黑名单内
if IsGlobalBlackIp(c.RemoteAddr().String()) {
c.Close()
return
}
// 判断访问地址是否在黑名单内
if common.IsBlackIp(c.RemoteAddr().String(), host.Client.VerifyKey, host.Client.BlackIpList) {
c.Close()
@@ -231,7 +238,13 @@ reset:
//change the host and header and set proxy setting
common.ChangeHostAndHeader(r, host.HostChange, host.HeaderChange, c.Conn.RemoteAddr().String(), s.addOrigin)
logs.Info("%s request, method %s, host %s, url %s, remote address %s, target %s", r.URL.Scheme, r.Method, r.Host, r.URL.Path, c.RemoteAddr().String(), lk.Host)
remoteAddr = strings.TrimSpace(r.Header.Get("X-Forwarded-For"))
if len(remoteAddr) == 0 {
remoteAddr = c.RemoteAddr().String()
}
logs.Info("%s request, method %s, host %s, url %s, remote address %s, target %s", r.URL.Scheme, r.Method, r.Host, r.URL.Path, remoteAddr, lk.Host)
//write
lenConn = conn.NewLenConn(connClient)
//lenConn = conn.LenConn
+1 -1
View File
@@ -130,7 +130,7 @@ func (https *HttpsServer) handleHttps(c net.Conn) {
logs.Warn(err.Error())
}
logs.Trace("new https connection,clientId %d,host %s,remote address %s", host.Client.Id, r.Host, c.RemoteAddr().String())
https.DealClient(conn.NewConn(c), host.Client, targetAddr, rb, common.CONN_TCP, nil, host.Flow, host.Target.LocalProxy, nil)
https.DealClient(conn.NewConn(c), host.Client, targetAddr, rb, common.CONN_TCP, nil, host.Client.Flow, host.Target.LocalProxy, nil)
}
type HttpsListener struct {
+10 -5
View File
@@ -47,6 +47,11 @@ func (s *UdpModeServer) Start() error {
continue
}
// 判断访问地址是否在全局黑名单内
if IsGlobalBlackIp(addr.String()) {
break
}
// 判断访问地址是否在黑名单内
if common.IsBlackIp(addr.String(), s.task.Client.VerifyKey, s.task.Client.BlackIpList) {
break
@@ -94,7 +99,7 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
s.task.Client.Flow.Add(int64(len(data)), int64(len(data)))
for {
clientConn.SetReadDeadline(time.Now().Add(time.Minute * 10))
clientConn.SetReadDeadline(time.Now().Add(time.Duration(60) * time.Second))
if n, err := target.Read(buf); err != nil {
s.addrMap.Delete(addr.String())
logs.Warn(err)
@@ -107,10 +112,10 @@ func (s *UdpModeServer) process(addr *net.UDPAddr, data []byte) {
}
s.task.Client.Flow.Add(int64(n), int64(n))
}
if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
logs.Warn("client id %d, task id %d,error %s, when udp connection", s.task.Client.Id, s.task.Id, err.Error())
return
}
//if err := s.CheckFlowAndConnNum(s.task.Client); err != nil {
// logs.Warn("client id %d, task id %d,error %s, when udp connection", s.task.Client.Id, s.task.Id, err.Error())
// return
//}
}
}
}
+2
View File
@@ -288,6 +288,7 @@ func dealClientData() {
v := value.(*file.Client)
if vv, ok := Bridge.Client.Load(v.Id); ok {
v.IsConnect = true
v.LastOnlineTime = time.Now().Format("2006-01-02 15:04:05")
v.Version = vv.(*bridge.Client).Version
} else {
v.IsConnect = false
@@ -469,6 +470,7 @@ func flowSession(m time.Duration) {
file.GetDb().JsonDb.StoreHostToJsonFile()
file.GetDb().JsonDb.StoreTasksToJsonFile()
file.GetDb().JsonDb.StoreClientsToJsonFile()
file.GetDb().JsonDb.StoreGlobalToJsonFile()
}
}
}
+47
View File
@@ -0,0 +1,47 @@
package controllers
import (
"ehang.io/nps/lib/file"
"strings"
)
type GlobalController struct {
BaseController
}
func (s *GlobalController) Index() {
//if s.Ctx.Request.Method == "GET" {
//
// return
//}
s.Data["menu"] = "global"
s.SetInfo("global")
s.display("global/index")
global := file.GetDb().GetGlobal()
if global == nil {
return
}
s.Data["globalBlackIpList"] = strings.Join(global.BlackIpList, "\r\n")
}
//添加全局黑名单IP
func (s *GlobalController) Save() {
//global, err := file.GetDb().GetGlobal()
//if err != nil {
// return
//}
if s.Ctx.Request.Method == "GET" {
s.Data["menu"] = "global"
s.SetInfo("save global")
s.display()
} else {
t := &file.Glob{BlackIpList: RemoveRepeatedElement(strings.Split(s.getEscapeString("globalBlackIpList"), "\r\n"))}
if err := file.GetDb().SaveGlobal(t); err != nil {
s.AjaxErr(err.Error())
}
s.AjaxOk("save success")
}
}
+3
View File
@@ -14,6 +14,7 @@ func Init() {
beego.NSAutoRouter(&controllers.LoginController{}),
beego.NSAutoRouter(&controllers.ClientController{}),
beego.NSAutoRouter(&controllers.AuthController{}),
beego.NSAutoRouter(&controllers.GlobalController{}),
)
beego.AddNamespace(ns)
} else {
@@ -22,5 +23,7 @@ func Init() {
beego.AutoRouter(&controllers.LoginController{})
beego.AutoRouter(&controllers.ClientController{})
beego.AutoRouter(&controllers.AuthController{})
beego.AutoRouter(&controllers.GlobalController{})
}
}
+13
View File
@@ -161,6 +161,19 @@ function submitform(action, url, postdata) {
}
}
});
return;
case 'global':
$.ajax({
type: "POST",
url: url,
data: postdata,
success: function (res) {
alert(langreply(res.msg));
if (res.status) {
document.location.reload();
}
}
});
}
}
+22
View File
@@ -237,6 +237,10 @@
<zh-CN>仪表盘</zh-CN>
<en-US>Dashboard</en-US>
</lang>
<lang id="word-globalparam">
<zh-CN>全局参数</zh-CN>
<en-US>Global Params</en-US>
</lang>
<lang id="word-exportflow">
<zh-CN>出口流量</zh-CN>
<en-US>Export Flow</en-US>
@@ -558,6 +562,12 @@
<lang id="word-">
</lang>
<lang id="word-globalparam">
<zh-CN>全局参数</zh-CN>
<en-US>global Param</en-US>
</lang>
<lang id="info-autogenerated">
<zh-CN>唯一值,不填将自动生成</zh-CN>
<en-US>Unique, non-filling will be generated automatically</en-US>
@@ -701,6 +711,12 @@
<en-US>IP Black List</en-US>
</lang>
<lang id="word-globalblackiplist">
<zh-CN>全局IP黑名单(防暴力破解)</zh-CN>
<en-US>Global IP Black List</en-US>
</lang>
<lang id="info-suchasblackiplist">
<zh-CN>例如&#10;10.1.50.203&#10;10.1.50.202</zh-CN>
<en-US>such as&#10;10.1.50.203&#10;10.1.50.202</en-US>
@@ -717,6 +733,10 @@
<en-US>IP Black List</en-US>
</lang>
<lang id="word-lastonlinetime">
<zh-CN>上次在线时间</zh-CN>
<en-US>Last Online Time</en-US>
</lang>
<confirm>
<lang id="delete">
@@ -1005,5 +1025,7 @@
</array>
</series>
</lang>
</charts>
</content>
+1
View File
@@ -71,6 +71,7 @@
+ '<b langtag="word-compress"></b>: <span langtag="word-' + row.Cnf.Compress + '"></span>&emsp;'
+ '<b langtag="word-connectbyconfig"></b>: <span langtag="word-' + row.ConfigConnAllow + '"></span>&emsp;<br/><br/>'
+ '<b langtag="word-blackip"></b>: ' + row.BlackIpList + '&emsp;<br/><br/>'
+ '<b langtag="word-lastonlinetime"></b>: ' + row.LastOnlineTime + '&emsp;<br/><br/>'
+ '<b langtag="word-commandclient"></b>: ' + "<code>./npc{{.win}} -server={{.ip}}:{{.p}} -vkey=" + row.VerifyKey + " -type=" +{{.bridgeType}} +"</code>"
},
//表格的列
+44
View File
@@ -0,0 +1,44 @@
<div class="wrapper wrapper-content">
<!--全局参数-->
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5 langtag="word-globalparam"></h5>
</div>
<div class="ibox-content">
<form class="form-horizontal">
<div class="form-group" id="black_ip_list">
<label class="control-label font-bold" langtag="word-globalblackiplist"></label>
<div class="col-sm-4">
<textarea class="form-control" rows="10" type="text" name="globalBlackIpList" placeholder=""
langtag="info-suchasblackiplist">{{.globalBlackIpList}}</textarea>
<span class="help-block m-b-none" langtag="info-descblackiplist"></span>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-success" type="button"
onclick="submitform('global', '{{.web_base_url}}/global/save', $('form').serializeArray())">
<i class="fa fa-fw fa-lg fa-check-circle"></i> <span langtag="word-save"></span>
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
window.addEventListener('resize', () => {
for (var key in charts) {
charts[key].resize();
}
});
</script>
+1
View File
@@ -45,6 +45,7 @@
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="ibox float-e-margins">
+9
View File
@@ -54,6 +54,9 @@
<a href="{{.web_base_url}}/"><i class="fa fa-tachometer-alt fa-lg"></i>
<span class="nav-label" langtag="word-dashboard"></span></a>
</li>
<li class="{{if eq "client" .menu}}active{{end}}">
<a href="{{.web_base_url}}/client/list"><i class="fa fa-desktop fa-lg"></i>
<span class="nav-label" langtag="word-client"></span></a>
@@ -90,6 +93,12 @@
<a href="{{.web_base_url}}/index/file"><i class="fa fa-briefcase fa-lg"></i>
<span class="nav-label" langtag="scheme-file"></span></a>
</li>
<li class="{{if eq "global" .menu}}active{{end}}">
<a href="{{.web_base_url}}/global/index"><i class="fa fa-cog fa-lg"></i>
<span class="nav-label" langtag="word-globalparam"></span></a>
</li>
<li class="{{if eq "help" .menu}}active{{end}}">
<a href="https://ehang.io/nps/documents" target="_blank"><i class="fa fa-lightbulb fa-lg"></i>
<span class="nav-label" langtag="word-help"></span></a>