提交 v1.3.0 beta

This commit is contained in:
dushixiang
2022-10-23 20:05:13 +08:00
parent 4ff4d37442
commit 112435199a
329 changed files with 18340 additions and 58458 deletions

View File

@ -15,8 +15,10 @@ const (
var TokenManager *cache.Cache
var LoginFailedKeyManager *cache.Cache
var UserRolesManager *cache.Cache
func init() {
TokenManager = cache.New(5*time.Minute, 10*time.Minute)
LoginFailedKeyManager = cache.New(5*time.Minute, 10*time.Minute)
UserRolesManager = cache.New(5*time.Minute, 10*time.Minute)
}

View File

@ -4,10 +4,10 @@ import (
"errors"
"fmt"
"net"
"next-terminal/server/common/term"
"os"
"sync"
"next-terminal/server/term"
"next-terminal/server/utils"
"golang.org/x/crypto/ssh"
@ -90,7 +90,9 @@ func (g *Gateway) CloseSshTunnel(id string) {
}
if len(g.tunnels) == 0 {
_ = g.SshClient.Close()
if g.SshClient != nil {
_ = g.SshClient.Close()
}
g.Connected = false
g.Message = "暂未使用"
}

View File

@ -3,7 +3,6 @@ package gateway
import (
"sync"
"next-terminal/server/log"
"next-terminal/server/model"
)
@ -33,7 +32,6 @@ func (m *manager) Add(model *model.AccessGateway) *Gateway {
tunnels: make(map[string]*Tunnel),
}
m.gateways.Store(g.ID, g)
log.Infof("add Gateway: %s", g.ID)
return g
}
@ -43,7 +41,6 @@ func (m *manager) Del(id string) {
g.Close()
}
m.gateways.Delete(id)
log.Infof("del Gateway: %s", id)
}
var GlobalGatewayManager *manager

View File

@ -5,8 +5,6 @@ import (
"io"
"net"
"next-terminal/server/log"
"golang.org/x/crypto/ssh"
)
@ -22,34 +20,23 @@ type Tunnel struct {
}
func (r *Tunnel) Open(sshClient *ssh.Client) {
localAddr := fmt.Sprintf("%s:%d", r.localHost, r.localPort)
for {
log.Debugf("隧道 %v 等待客户端访问 %v", r.id, localAddr)
localConn, err := r.listener.Accept()
if err != nil {
log.Debugf("隧道 %v 接受连接失败 %v, 退出循环", r.id, err.Error())
log.Debug("-------------------------------------------------")
return
}
r.localConnections = append(r.localConnections, localConn)
log.Debugf("隧道 %v 新增本地连接 %v", r.id, localConn.RemoteAddr().String())
remoteAddr := fmt.Sprintf("%s:%d", r.remoteHost, r.remotePort)
log.Debugf("隧道 %v 连接远程地址 %v ...", r.id, remoteAddr)
remoteConn, err := sshClient.Dial("tcp", remoteAddr)
if err != nil {
log.Debugf("隧道 %v 连接远程地址 %v, 退出循环", r.id, err.Error())
log.Debug("-------------------------------------------------")
return
}
r.remoteConnections = append(r.remoteConnections, remoteConn)
log.Debugf("隧道 %v 连接远程主机成功", r.id)
go copyConn(localConn, remoteConn)
go copyConn(remoteConn, localConn)
log.Debugf("隧道 %v 开始转发数据 [%v]->[%v]", r.id, localAddr, remoteAddr)
log.Debug("~~~~~~~~~~~~~~~~~~~~分割线~~~~~~~~~~~~~~~~~~~~~~~~")
}
}
@ -63,7 +50,6 @@ func (r *Tunnel) Close() {
}
r.remoteConnections = nil
_ = r.listener.Close()
log.Debugf("隧道 %v 监听器关闭", r.id)
}
func copyConn(writer, reader net.Conn) {

View File

@ -0,0 +1,12 @@
package license
type License struct {
Type string `json:"type"` // 类型:免费版 free,会员版 vip, 旗舰版 ultimate, 企业版 enterprise
MachineId string `json:"machineId"` // 唯一机器码:免费版为空
Assert int64 `json:"assert"` // 资产数量
Concurrent int64 `json:"concurrent"` // 并发数量
User int64 `json:"user"` // 用户数量
Expired int64 `json:"expired"` // 过期时间
}
var CurrentLicense *License

View File

@ -3,8 +3,6 @@ package security
import (
"sort"
"sync"
"next-terminal/server/log"
)
type Security struct {
@ -54,13 +52,11 @@ func (m *Manager) Values() []*Security {
func (m *Manager) Add(s *Security) {
m.securities.Store(s.ID, s)
m.LoadData()
log.Infof("add security: %s", s.ID)
}
func (m *Manager) Del(id string) {
m.securities.Delete(id)
m.LoadData()
log.Infof("del security: %s", id)
}
var GlobalSecurityManager *Manager

View File

@ -1,14 +1,12 @@
package session
import (
"next-terminal/server/common/guacamole"
"next-terminal/server/common/term"
"sync"
"next-terminal/server/dto"
"next-terminal/server/guacd"
"next-terminal/server/log"
"next-terminal/server/term"
"github.com/gorilla/websocket"
"next-terminal/server/dto"
)
type Session struct {
@ -16,10 +14,13 @@ type Session struct {
Protocol string
Mode string
WebSocket *websocket.Conn
GuacdTunnel *guacd.Tunnel
GuacdTunnel *guacamole.Tunnel
NextTerminal *term.NextTerminal
Observer *Manager
mutex sync.Mutex
Uptime int64
Hostname string
}
func (s *Session) WriteMessage(msg dto.Message) error {
@ -79,7 +80,6 @@ func (m *Manager) GetById(id string) *Session {
func (m *Manager) Add(s *Session) {
m.sessions.Store(s.ID, s)
log.Infof("add session: %s", s.ID)
}
func (m *Manager) Del(id string) {
@ -91,7 +91,6 @@ func (m *Manager) Del(id string) {
}
}
m.sessions.Delete(id)
log.Infof("del session: %s", id)
}
func (m *Manager) Clear() {

104
server/global/stat/load.go Normal file
View File

@ -0,0 +1,104 @@
package stat
type systemLoad struct {
LoadStat *LoadStat `json:"loadStat"`
Mem *Mem `json:"mem"`
MemStat []*entry `json:"memStat"`
Cpu *Cpu `json:"cpu"`
CpuStat []*entry `json:"cpuStat"`
Disk *Disk `json:"disk"`
DiskIOStat []*ioEntry `json:"diskIO"`
NetIOStat []*ioEntry `json:"netIO"`
}
type Mem struct {
Total uint64 `json:"total"`
Available uint64 `json:"available"`
Used uint64 `json:"used"`
UsedPercent float64 `json:"usedPercent"`
}
type Cpu struct {
Count int `json:"count"`
PhyCount int `json:"phyCount"`
UsedPercent float64 `json:"usedPercent"`
Info []*CpuInfo `json:"info"`
}
type Disk struct {
Total uint64 `json:"total"`
Used uint64 `json:"used"`
Available uint64 `json:"available"`
UsedPercent float64 `json:"usedPercent"`
}
type CpuInfo struct {
ModelName string `json:"modelName"`
CacheSize int32 `json:"cacheSize"`
MHZ float64 `json:"mhz"`
}
type LoadStat struct {
Load1 float64 `json:"load1"`
Load5 float64 `json:"load5"`
Load15 float64 `json:"load15"`
Percent float64 `json:"percent"`
}
type entry struct {
Time string `json:"time"`
Value float64 `json:"value"`
}
func NewStat(time string, value float64) *entry {
return &entry{
Time: time,
Value: value,
}
}
func NewIOStat(time string, read, write uint64) *ioEntry {
return &ioEntry{
Time: time,
Read: read,
Write: write,
}
}
type ioEntry struct {
Time string `json:"time"`
Read uint64 `json:"read"`
Write uint64 `json:"write"`
}
var SystemLoad *systemLoad
func init() {
SystemLoad = &systemLoad{
LoadStat: &LoadStat{
Load1: 0,
Load5: 0,
Load15: 0,
Percent: 0,
},
Mem: &Mem{
Total: 0,
Available: 0,
Used: 0,
UsedPercent: 0,
},
MemStat: make([]*entry, 0),
Cpu: &Cpu{
Count: 0,
UsedPercent: 0,
},
CpuStat: make([]*entry, 0),
Disk: &Disk{
Total: 0,
Used: 0,
UsedPercent: 0,
},
DiskIOStat: make([]*ioEntry, 0),
NetIOStat: make([]*ioEntry, 0),
}
}