util

package
v0.0.0-...-99505da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NUmStr    = "0123456789"
	CharStr   = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	SpecStr   = "+=-@#~,.[]()!%^*$"
	CommonKey = "95PmsApi20180704"
)

Variables

This section is empty.

Functions

func CreateSSHConfig

func CreateSSHConfig(user, password, privateKey, keyPwd string, timeOut int) (ssh.ClientConfig, error)

设置ssh所需的config

func DecryptUserPwd

func DecryptUserPwd(crypted string) (string, error)

解密系统用户密码

func EncryptPass

func EncryptPass(username, password, salt string) string

加密api用户密码

func EncryptUserPwd

func EncryptUserPwd(passwd []byte) (string, error)

加密系统用户密码

func GeneratePasswd

func GeneratePasswd() string

生成系统用户密码

func GenerateToken

func GenerateToken(username, password string) (string, error)

生产token

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

Types

type Claims

type Claims struct {
	Username string `json:"username"`
	Password string `json:"password"`
	jwt.StandardClaims
}

func ParseToken

func ParseToken(token string) (*Claims, error)

解析token

type Result

type Result struct {
	Rst  bool
	Msg  string
	Code int
	Ip   string
}

func DialSuccess

func DialSuccess(ip string, port int, config ssh.ClientConfig) Result

测试是否能连接

func RunCmd

func RunCmd(ip string, port int, command string, config ssh.ClientConfig) Result

执行命令

type SSHClient

type SSHClient struct {
	Ip            string
	User          string
	Password      string
	PrivateKey    string
	PrivateKeyPwd string
	Port          int
	Timeout       int
}

ssh client

func DefaultSSHClient

func DefaultSSHClient() SSHClient

带默认值的ssh client

func (*SSHClient) Connect

func (s *SSHClient) Connect(config ssh.ClientConfig) (*ssh.Session, error)

建立连接

func (*SSHClient) ParseConfig

func (client *SSHClient) ParseConfig() (ssh.ClientConfig, error)

设置ssh所需的config

func (*SSHClient) RunCmd

func (s *SSHClient) RunCmd(command string) Result

执行命令

func (*SSHClient) SftpConnect

func (s *SSHClient) SftpConnect(config ssh.ClientConfig) (*sftp.Client, error)

建立sftp连接

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL