style(be):使用goimport 格式化代码并添加golangci
This commit is contained in:
parent
88b0200095
commit
d366cbd00d
21
.github/workflows/golangci-lint.yml
vendored
Normal file
21
.github/workflows/golangci-lint.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
name: golangci-lint
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- be-*
|
||||||
|
- dev
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
golangci:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
|
||||||
|
version: v1.29
|
26
.golangci.yml
Normal file
26
.golangci.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
linters-settings:
|
||||||
|
goimports:
|
||||||
|
local-prefixes: uqingtech.com
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- deadcode
|
||||||
|
- errcheck
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- typecheck
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
|
||||||
|
run:
|
||||||
|
skip-dirs:
|
||||||
|
- api/
|
||||||
|
- module/
|
||||||
|
skip-files:
|
||||||
|
- test_ssh.go
|
1
go.mod
1
go.mod
@ -10,6 +10,7 @@ require (
|
|||||||
github.com/labstack/echo/v4 v4.1.17
|
github.com/labstack/echo/v4 v4.1.17
|
||||||
github.com/labstack/gommon v0.3.0
|
github.com/labstack/gommon v0.3.0
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/pkg/sftp v1.12.0
|
github.com/pkg/sftp v1.12.0
|
||||||
github.com/pquerna/otp v1.3.0
|
github.com/pquerna/otp v1.3.0
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
|
28
main.go
28
main.go
@ -3,6 +3,20 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"next-terminal/pkg/api"
|
||||||
|
"next-terminal/pkg/config"
|
||||||
|
"next-terminal/pkg/constant"
|
||||||
|
"next-terminal/pkg/global"
|
||||||
|
"next-terminal/pkg/handle"
|
||||||
|
"next-terminal/pkg/model"
|
||||||
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
nested "github.com/antonfisher/nested-logrus-formatter"
|
nested "github.com/antonfisher/nested-logrus-formatter"
|
||||||
"github.com/labstack/gommon/log"
|
"github.com/labstack/gommon/log"
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
@ -12,18 +26,6 @@ import (
|
|||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
"io"
|
|
||||||
"next-terminal/pkg/api"
|
|
||||||
"next-terminal/pkg/config"
|
|
||||||
"next-terminal/pkg/constant"
|
|
||||||
"next-terminal/pkg/global"
|
|
||||||
"next-terminal/pkg/handle"
|
|
||||||
"next-terminal/pkg/model"
|
|
||||||
"next-terminal/pkg/utils"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const Version = "v0.3.3"
|
const Version = "v0.3.3"
|
||||||
@ -227,7 +229,7 @@ func Run() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if jobs == nil || len(jobs) == 0 {
|
if jobs == nil {
|
||||||
job := model.Job{
|
job := model.Job{
|
||||||
ID: utils.UUID(),
|
ID: utils.UUID(),
|
||||||
Name: "资产状态检测",
|
Name: "资产状态检测",
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/totp"
|
"next-terminal/pkg/totp"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
@ -5,12 +5,14 @@ import (
|
|||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/labstack/echo/v4"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AssetCreateEndpoint(c echo.Context) error {
|
func AssetCreateEndpoint(c echo.Context) error {
|
||||||
|
@ -2,11 +2,13 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"next-terminal/pkg/model"
|
|
||||||
"next-terminal/pkg/utils"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"next-terminal/pkg/model"
|
||||||
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CommandCreateEndpoint(c echo.Context) error {
|
func CommandCreateEndpoint(c echo.Context) error {
|
||||||
|
@ -2,12 +2,14 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/labstack/echo/v4"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CredentialAllEndpoint(c echo.Context) error {
|
func CredentialAllEndpoint(c echo.Context) error {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"next-terminal/pkg/model"
|
|
||||||
"next-terminal/pkg/utils"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"next-terminal/pkg/model"
|
||||||
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func JobCreateEndpoint(c echo.Context) error {
|
func JobCreateEndpoint(c echo.Context) error {
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"next-terminal/pkg/global"
|
|
||||||
"next-terminal/pkg/model"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"next-terminal/pkg/global"
|
||||||
|
"next-terminal/pkg/model"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoginLogPagingEndpoint(c echo.Context) error {
|
func LoginLogPagingEndpoint(c echo.Context) error {
|
||||||
@ -32,7 +35,9 @@ func LoginLogDeleteEndpoint(c echo.Context) error {
|
|||||||
for i := range split {
|
for i := range split {
|
||||||
token := split[i]
|
token := split[i]
|
||||||
global.Cache.Delete(token)
|
global.Cache.Delete(token)
|
||||||
model.Logout(token)
|
if err := model.Logout(token); err != nil {
|
||||||
|
logrus.WithError(err).Error("Cache Delete Failed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := model.DeleteLoginLogByIdIn(split); err != nil {
|
if err := model.DeleteLoginLogByIdIn(split); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -2,14 +2,16 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"net"
|
"net"
|
||||||
"next-terminal/pkg/constant"
|
|
||||||
"next-terminal/pkg/global"
|
|
||||||
"next-terminal/pkg/utils"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"next-terminal/pkg/constant"
|
||||||
|
"next-terminal/pkg/global"
|
||||||
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrorHandler(next echo.HandlerFunc) echo.HandlerFunc {
|
func ErrorHandler(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Counter struct {
|
type Counter struct {
|
||||||
|
@ -3,9 +3,11 @@ package api
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"next-terminal/pkg/model"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"next-terminal/pkg/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func PropertyGetEndpoint(c echo.Context) error {
|
func PropertyGetEndpoint(c echo.Context) error {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RU struct {
|
type RU struct {
|
||||||
|
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/log"
|
"next-terminal/pkg/log"
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SecurityCreateEndpoint(c echo.Context) error {
|
func SecurityCreateEndpoint(c echo.Context) error {
|
||||||
@ -33,7 +35,7 @@ func ReloadAccessSecurity() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if rules != nil && len(rules) > 0 {
|
if rules != nil {
|
||||||
var securities []*global.Security
|
var securities []*global.Security
|
||||||
for i := 0; i < len(rules); i++ {
|
for i := 0; i < len(rules); i++ {
|
||||||
rule := global.Security{
|
rule := global.Security{
|
||||||
|
@ -4,21 +4,23 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/pkg/sftp"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"next-terminal/pkg/constant"
|
|
||||||
"next-terminal/pkg/global"
|
|
||||||
"next-terminal/pkg/model"
|
|
||||||
"next-terminal/pkg/utils"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"next-terminal/pkg/constant"
|
||||||
|
"next-terminal/pkg/global"
|
||||||
|
"next-terminal/pkg/model"
|
||||||
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/pkg/sftp"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SessionPagingEndpoint(c echo.Context) error {
|
func SessionPagingEndpoint(c echo.Context) error {
|
||||||
|
@ -2,19 +2,21 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/guacd"
|
"next-terminal/pkg/guacd"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/term"
|
"next-terminal/pkg/term"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"path"
|
|
||||||
"strconv"
|
"github.com/gorilla/websocket"
|
||||||
"time"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var UpGrader = websocket.Upgrader{
|
var UpGrader = websocket.Upgrader{
|
||||||
|
@ -2,15 +2,17 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gorilla/websocket"
|
"path"
|
||||||
"github.com/labstack/echo/v4"
|
"strconv"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/guacd"
|
"next-terminal/pkg/guacd"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"path"
|
|
||||||
"strconv"
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -98,7 +100,6 @@ func TunEndpoint(c echo.Context) error {
|
|||||||
configuration.SetParameter(guacd.DisableBitmapCaching, propertyMap[guacd.DisableBitmapCaching])
|
configuration.SetParameter(guacd.DisableBitmapCaching, propertyMap[guacd.DisableBitmapCaching])
|
||||||
configuration.SetParameter(guacd.DisableOffscreenCaching, propertyMap[guacd.DisableOffscreenCaching])
|
configuration.SetParameter(guacd.DisableOffscreenCaching, propertyMap[guacd.DisableOffscreenCaching])
|
||||||
configuration.SetParameter(guacd.DisableGlyphCaching, propertyMap[guacd.DisableGlyphCaching])
|
configuration.SetParameter(guacd.DisableGlyphCaching, propertyMap[guacd.DisableGlyphCaching])
|
||||||
break
|
|
||||||
case "ssh":
|
case "ssh":
|
||||||
if len(session.PrivateKey) > 0 && session.PrivateKey != "-" {
|
if len(session.PrivateKey) > 0 && session.PrivateKey != "-" {
|
||||||
configuration.SetParameter("username", session.Username)
|
configuration.SetParameter("username", session.Username)
|
||||||
@ -114,11 +115,9 @@ func TunEndpoint(c echo.Context) error {
|
|||||||
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
|
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
|
||||||
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
|
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
|
||||||
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
|
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
|
||||||
break
|
|
||||||
case "vnc":
|
case "vnc":
|
||||||
configuration.SetParameter("username", session.Username)
|
configuration.SetParameter("username", session.Username)
|
||||||
configuration.SetParameter("password", session.Password)
|
configuration.SetParameter("password", session.Password)
|
||||||
break
|
|
||||||
case "telnet":
|
case "telnet":
|
||||||
configuration.SetParameter("username", session.Username)
|
configuration.SetParameter("username", session.Username)
|
||||||
configuration.SetParameter("password", session.Password)
|
configuration.SetParameter("password", session.Password)
|
||||||
@ -128,7 +127,6 @@ func TunEndpoint(c echo.Context) error {
|
|||||||
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
|
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
|
||||||
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
|
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
|
||||||
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
|
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
|
||||||
break
|
|
||||||
case "kubernetes":
|
case "kubernetes":
|
||||||
|
|
||||||
configuration.SetParameter(guacd.FontSize, propertyMap[guacd.FontSize])
|
configuration.SetParameter(guacd.FontSize, propertyMap[guacd.FontSize])
|
||||||
@ -136,6 +134,9 @@ func TunEndpoint(c echo.Context) error {
|
|||||||
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
|
configuration.SetParameter(guacd.ColorScheme, propertyMap[guacd.ColorScheme])
|
||||||
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
|
configuration.SetParameter(guacd.Backspace, propertyMap[guacd.Backspace])
|
||||||
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
|
configuration.SetParameter(guacd.TerminalType, propertyMap[guacd.TerminalType])
|
||||||
|
default:
|
||||||
|
logrus.WithField("configuration.Protocol", configuration.Protocol).Error("UnSupport Protocol")
|
||||||
|
return Fail(c, 400, "不支持的协议")
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration.SetParameter("hostname", session.IP)
|
configuration.SetParameter("hostname", session.IP)
|
||||||
@ -209,7 +210,7 @@ func TunEndpoint(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for true {
|
for {
|
||||||
instruction, err := tunnel.Read()
|
instruction, err := tunnel.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if connectionId == "" {
|
if connectionId == "" {
|
||||||
@ -230,7 +231,7 @@ func TunEndpoint(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for true {
|
for {
|
||||||
_, message, err := ws.ReadMessage()
|
_, message, err := ws.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if connectionId == "" {
|
if connectionId == "" {
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserGroup struct {
|
type UserGroup struct {
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserCreateEndpoint(c echo.Context) error {
|
func UserCreateEndpoint(c echo.Context) error {
|
||||||
@ -87,12 +90,15 @@ func UserDeleteEndpoint(c echo.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if loginLogs != nil && len(loginLogs) > 0 {
|
|
||||||
for j := range loginLogs {
|
for j := range loginLogs {
|
||||||
global.Cache.Delete(loginLogs[j].ID)
|
global.Cache.Delete(loginLogs[j].ID)
|
||||||
model.Logout(loginLogs[j].ID)
|
if err := model.Logout(loginLogs[j].ID); err != nil {
|
||||||
|
logrus.WithError(err).WithField("id:", loginLogs[j].ID).Error("Cache Deleted Error")
|
||||||
|
return Fail(c, 500, "强制下线错误")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除用户
|
// 删除用户
|
||||||
model.DeleteUserById(userId)
|
model.DeleteUserById(userId)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/pflag"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"next-terminal/pkg/config"
|
||||||
|
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"next-terminal/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DB *gorm.DB
|
var DB *gorm.DB
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"next-terminal/pkg/guacd"
|
|
||||||
"next-terminal/pkg/term"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"next-terminal/pkg/guacd"
|
||||||
|
"next-terminal/pkg/term"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tun struct {
|
type Tun struct {
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package handle
|
package handle
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/guacd"
|
"next-terminal/pkg/guacd"
|
||||||
"next-terminal/pkg/model"
|
"next-terminal/pkg/model"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"os"
|
|
||||||
"strconv"
|
"github.com/sirupsen/logrus"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunTicker() {
|
func RunTicker() {
|
||||||
@ -18,7 +20,7 @@ func RunTicker() {
|
|||||||
go func() {
|
go func() {
|
||||||
for range unUsedSessionTicker.C {
|
for range unUsedSessionTicker.C {
|
||||||
sessions, _ := model.FindSessionByStatusIn([]string{constant.NoConnect, constant.Connecting})
|
sessions, _ := model.FindSessionByStatusIn([]string{constant.NoConnect, constant.Connecting})
|
||||||
if sessions != nil && len(sessions) > 0 {
|
if sessions != nil {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for i := range sessions {
|
for i := range sessions {
|
||||||
if now.Sub(sessions[i].ConnectedTime.Time) > time.Hour*1 {
|
if now.Sub(sessions[i].ConnectedTime.Time) > time.Hour*1 {
|
||||||
@ -51,7 +53,7 @@ func RunTicker() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if sessions != nil && len(sessions) > 0 {
|
if sessions != nil {
|
||||||
var sessionIds []string
|
var sessionIds []string
|
||||||
for i := range sessions {
|
for i := range sessions {
|
||||||
sessionIds = append(sessionIds, sessions[i].ID)
|
sessionIds = append(sessionIds, sessions[i].ID)
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Asset struct {
|
type Asset struct {
|
||||||
@ -94,7 +95,7 @@ func FindPageAsset(pageIndex, pageSize int, name, protocol, tags string, account
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if userGroupIds != nil && len(userGroupIds) > 0 {
|
if userGroupIds != nil {
|
||||||
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
||||||
dbCounter = dbCounter.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
dbCounter = dbCounter.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
||||||
}
|
}
|
||||||
@ -209,7 +210,7 @@ func CountAssetByUserId(userId string) (total int64, err error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if userGroupIds != nil && len(userGroupIds) > 0 {
|
if userGroupIds != nil {
|
||||||
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
||||||
}
|
}
|
||||||
err = db.Find(&Asset{}).Count(&total).Error
|
err = db.Find(&Asset{}).Count(&total).Error
|
||||||
|
@ -2,12 +2,14 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/guacd"
|
"next-terminal/pkg/guacd"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AssetAttribute struct {
|
type AssetAttribute struct {
|
||||||
|
@ -123,7 +123,7 @@ func CountCredentialByUserId(userId string) (total int64, err error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if userGroupIds != nil && len(userGroupIds) > 0 {
|
if userGroupIds != nil {
|
||||||
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
db = db.Or("resource_sharers.user_group_id in ?", userGroupIds)
|
||||||
}
|
}
|
||||||
err = db.Find(&Credential{}).Count(&total).Error
|
err = db.Find(&Credential{}).Count(&total).Error
|
||||||
|
@ -4,14 +4,16 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/robfig/cron/v3"
|
"strings"
|
||||||
"github.com/sirupsen/logrus"
|
"time"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/term"
|
"next-terminal/pkg/term"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"strings"
|
|
||||||
"time"
|
"github.com/robfig/cron/v3"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
@ -197,7 +199,7 @@ func (r CheckAssetStatusJob) Run() {
|
|||||||
assets, _ = FindAssetByIds(strings.Split(r.ResourceIds, ","))
|
assets, _ = FindAssetByIds(strings.Split(r.ResourceIds, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
if assets == nil || len(assets) == 0 {
|
if assets == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +257,7 @@ func (r ShellJob) Run() {
|
|||||||
assets, _ = FindAssetByProtocolAndIds("ssh", strings.Split(r.ResourceIds, ","))
|
assets, _ = FindAssetByProtocolAndIds("ssh", strings.Split(r.ResourceIds, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
if assets == nil || len(assets) == 0 {
|
if assets == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LoginLog struct {
|
type LoginLog struct {
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jordan-wright/email"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
|
||||||
"next-terminal/pkg/constant"
|
"next-terminal/pkg/constant"
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/guacd"
|
"next-terminal/pkg/guacd"
|
||||||
|
|
||||||
|
"github.com/jordan-wright/email"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Property struct {
|
type Property struct {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResourceSharer struct {
|
type ResourceSharer struct {
|
||||||
@ -117,15 +119,22 @@ func AddSharerResources(userGroupId, userId, resourceType string, resourceIds []
|
|||||||
switch resourceType {
|
switch resourceType {
|
||||||
case "asset":
|
case "asset":
|
||||||
resource := Asset{}
|
resource := Asset{}
|
||||||
err = tx.Where("id = ?", resourceId).First(&resource).Error
|
if err = tx.Where("id = ?", resourceId).First(&resource).Error; err != nil {
|
||||||
|
return errors.Wrap(err, "find asset fail")
|
||||||
|
}
|
||||||
owner = resource.Owner
|
owner = resource.Owner
|
||||||
case "command":
|
case "command":
|
||||||
resource := Command{}
|
resource := Command{}
|
||||||
err = tx.Where("id = ?", resourceId).First(&resource).Error
|
if err = tx.Where("id = ?", resourceId).First(&resource).Error; err != nil {
|
||||||
|
return errors.Wrap(err, "find command fail")
|
||||||
|
}
|
||||||
owner = resource.Owner
|
owner = resource.Owner
|
||||||
case "credential":
|
case "credential":
|
||||||
resource := Credential{}
|
resource := Credential{}
|
||||||
err = tx.Where("id = ?", resourceId).First(&resource).Error
|
if err = tx.Where("id = ?", resourceId).First(&resource).Error; err != nil {
|
||||||
|
return errors.Wrap(err, "find credential fail")
|
||||||
|
|
||||||
|
}
|
||||||
owner = resource.Owner
|
owner = resource.Owner
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +175,7 @@ func FindAssetIdsByUserId(userId string) (assetIds []string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
db := global.DB.Table("resource_sharers").Select("resource_id").Where("user_id = ?", userId)
|
db := global.DB.Table("resource_sharers").Select("resource_id").Where("user_id = ?", userId)
|
||||||
if groupIds != nil && len(groupIds) > 0 {
|
if groupIds != nil {
|
||||||
db = db.Or("user_group_id in ?", groupIds)
|
db = db.Or("user_group_id in ?", groupIds)
|
||||||
}
|
}
|
||||||
err = db.Find(&sharerAssetIds).Error
|
err = db.Find(&sharerAssetIds).Error
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"next-terminal/pkg/constant"
|
|
||||||
"next-terminal/pkg/global"
|
|
||||||
"next-terminal/pkg/utils"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"next-terminal/pkg/constant"
|
||||||
|
"next-terminal/pkg/global"
|
||||||
|
"next-terminal/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserGroup struct {
|
type UserGroup struct {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"next-terminal/pkg/global"
|
"next-terminal/pkg/global"
|
||||||
"next-terminal/pkg/utils"
|
"next-terminal/pkg/utils"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package term
|
package term
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/pkg/sftp"
|
"github.com/pkg/sftp"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type NextTerminal struct {
|
type NextTerminal struct {
|
||||||
|
@ -2,9 +2,10 @@ package term
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"next-terminal/pkg/utils"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"next-terminal/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Env struct {
|
type Env struct {
|
||||||
|
@ -2,8 +2,9 @@ package term
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/crypto/ssh"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewSshClient(ip string, port int, username, password, privateKey, passphrase string) (*ssh.Client, error) {
|
func NewSshClient(ip string, port int, username, password, privateKey, passphrase string) (*ssh.Client, error) {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
@ -29,7 +30,7 @@ func main() {
|
|||||||
|
|
||||||
client, err := ssh.Dial("tcp", "172.16.101.32:22", sshConfig)
|
client, err := ssh.Dial("tcp", "172.16.101.32:22", sshConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ func (t *SSHTerminal) updateTerminalSize() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Session.WindowChange(currTermHeight, currTermWidth)
|
err = t.Session.WindowChange(currTermHeight, currTermWidth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Unable to send window-change reqest: %s.", err)
|
fmt.Printf("Unable to send window-change reqest: %s.", err)
|
||||||
continue
|
continue
|
||||||
@ -86,9 +87,9 @@ func (t *SSHTerminal) interactiveSession() error {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if t.exitMsg == "" {
|
if t.exitMsg == "" {
|
||||||
fmt.Fprintln(os.Stdout, "the connection was closed on the remote side on ", time.Now().Format(time.RFC822))
|
logrus.Info(os.Stdout, "the connection was closed on the remote side on ", time.Now().Format(time.RFC822))
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(os.Stdout, t.exitMsg)
|
logrus.Info(os.Stdout, t.exitMsg)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -103,10 +104,7 @@ func ImageToBase64Encode(img image.Image) (string, error) {
|
|||||||
func FileExists(path string) bool {
|
func FileExists(path string) bool {
|
||||||
_, err := os.Stat(path) //os.Stat获取文件信息
|
_, err := os.Stat(path) //os.Stat获取文件信息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsExist(err) {
|
return os.IsExist(err)
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -209,3 +207,9 @@ func StringToInt(in string) (out int) {
|
|||||||
out, _ = strconv.Atoi(in)
|
out, _ = strconv.Atoi(in)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Check(f func() error) {
|
||||||
|
if err := f(); err != nil {
|
||||||
|
logrus.Error("Received error:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user