utils

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COMPRESS_NONE_ENCODE = iota
	COMPRESS_NONE_DECODE
	COMPRESS_SNAPY_ENCODE
	COMPRESS_SNAPY_DECODE
	VERIFY_EER        = "vkey"
	WORK_MAIN         = "main"
	WORK_CHAN         = "chan"
	RES_SIGN          = "sign"
	RES_MSG           = "msg0"
	CONN_SUCCESS      = "sucs"
	CONN_ERROR        = "fail"
	TEST_FLAG         = "tst"
	CONN_TCP          = "tcp"
	CONN_UDP          = "udp"
	UnauthorizedBytes = `HTTP/1.1 401 Unauthorized
Content-Type: text/plain; charset=utf-8
WWW-Authenticate: Basic realm="easyProxy"

401 Unauthorized`
	IO_EOF              = "PROXYEOF"
	ConnectionFailBytes = `HTTP/1.1 404 Not Found

`
)

Variables

View Source
var BufPoolUdp = sync.Pool{
	New: func() interface{} {
		return make([]byte, poolSizeUdp)
	},
}

Functions

func AesDecrypt

func AesDecrypt(crypted, key []byte) ([]byte, error)

de

func AesEncrypt

func AesEncrypt(origData, key []byte) ([]byte, error)

en

func ChangeHostAndHeader added in v0.0.9

func ChangeHostAndHeader(r *http.Request, host string, header string, addr string)

func CheckAuth

func CheckAuth(r *http.Request, user, passwd string) bool

检查basic认证

func DomainCheck

func DomainCheck(domain string) bool

检查是否是域名

func FlushConn

func FlushConn(c net.Conn)

连接重置 清空缓存区

func GetBoolByStr

func GetBoolByStr(s string) bool

get bool by str

func GetCompressType

func GetCompressType(compress string) (int, int)

判断压缩方式

func GetHostByName added in v0.0.10

func GetHostByName(hostname string) string

通过host获取对应的ip地址

func GetIntNoErrByStr added in v0.0.10

func GetIntNoErrByStr(str string) int

int

func GetLenByBytes

func GetLenByBytes(buf []byte) (int, error)

解析出长度

func GetLenBytes

func GetLenBytes(buf []byte) (b []byte, err error)

获取长度+内容

func GetRandomString

func GetRandomString(l int) string

生成随机验证密钥

func GetStrByBool

func GetStrByBool(b bool) string

get str by bool

func Getverifyval

func Getverifyval(vkey string) string

简单的一个校验值

func Md5

func Md5(s string) string

生成32位md5字串

func PKCS5Padding

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

补全

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) (error, []byte)

去补

func ReadAllFromFile added in v0.0.10

func ReadAllFromFile(filePth string) ([]byte, error)

func Relay

func Relay(in, out net.Conn, compressType int, crypt, mux bool) (n int64, err error)

copy

func ReplayWaitGroup added in v0.0.9

func ReplayWaitGroup(conn1 net.Conn, conn2 net.Conn, compressEncode, compressDecode int, crypt, mux bool) (out int64, in int64)

wait replay group conn1 网桥 conn2

Types

type Client added in v0.0.10

type Client struct {
	Cnf       *Config
	Id        int    //id
	VerifyKey string //验证密钥
	Addr      string //客户端ip地址
	Remark    string //备注
	Status    bool   //是否开启
	IsConnect bool   //是否连接
	Flow      *Flow
}

type Config added in v0.0.10

type Config struct {
	U              string //socks5验证用户名
	P              string //socks5验证密码
	Compress       string //压缩方式
	Crypt          bool   //是否加密
	Mux            bool   //是否加密
	CompressEncode int    //加密方式
	CompressDecode int    //解密方式
}

func DeepCopyConfig added in v0.0.10

func DeepCopyConfig(c *Config) *Config

深拷贝Tunnel

type Conn

type Conn struct {
	Conn net.Conn
}

func NewConn

func NewConn(conn net.Conn) *Conn

new conn

func (*Conn) Close

func (s *Conn) Close() error

close

func (*Conn) GetConnInfoFromConn

func (s *Conn) GetConnInfoFromConn() (en, de int, crypt, mux bool)

获取压缩方式,是否加密

func (*Conn) GetHost

func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request)

从tcp报文中解析出host,连接类型等 TODO 多种情况

func (*Conn) GetHostFromConn

func (s *Conn) GetHostFromConn() (typeStr string, host string, en, de int, crypt, mux bool, err error)

读取host 连接地址 压缩类型

func (*Conn) GetLen

func (s *Conn) GetLen() (int, error)

获取长度

func (*Conn) Read

func (s *Conn) Read(b []byte) (int, error)

read

func (*Conn) ReadFlag

func (s *Conn) ReadFlag() (string, error)

读取flag

func (*Conn) ReadFrom

func (s *Conn) ReadFrom(b []byte, compress int, crypt bool) (int, error)

单独读(加密|压缩)

func (*Conn) ReadLen

func (s *Conn) ReadLen(cLen int) ([]byte, error)

读取指定长度内容

func (*Conn) SetAlive

func (s *Conn) SetAlive()

设置连接为长连接

func (*Conn) Write

func (s *Conn) Write(b []byte) (int, error)

write

func (*Conn) WriteChan

func (s *Conn) WriteChan() (int, error)

write chan

func (*Conn) WriteConnInfo

func (s *Conn) WriteConnInfo(en, de int, crypt, mux bool)

写压缩方式,加密

func (*Conn) WriteError

func (s *Conn) WriteError() (int, error)

write error

func (*Conn) WriteFail

func (s *Conn) WriteFail() (int, error)

write test

func (*Conn) WriteHost

func (s *Conn) WriteHost(ltype string, host string) (int, error)

写连接类型 和 host地址

func (*Conn) WriteLen

func (s *Conn) WriteLen(buf []byte) (int, error)

写入长度+内容 粘包

func (*Conn) WriteMain

func (s *Conn) WriteMain() (int, error)

write main

func (*Conn) WriteSign

func (s *Conn) WriteSign() (int, error)

write sign flag

func (*Conn) WriteSuccess

func (s *Conn) WriteSuccess() (int, error)

write test

func (*Conn) WriteTest

func (s *Conn) WriteTest() (int, error)

write test

func (*Conn) WriteTo

func (s *Conn) WriteTo(b []byte, compress int, crypt bool) (n int, err error)

单独写(加密|压缩)

type CryptConn

type CryptConn struct {
	// contains filtered or unexported fields
}

func NewCryptConn

func NewCryptConn(conn net.Conn, crypt bool) *CryptConn

func (*CryptConn) Read

func (s *CryptConn) Read(b []byte) (n int, err error)

解密读

func (*CryptConn) Write

func (s *CryptConn) Write(b []byte) (n int, err error)

加密写

type Csv added in v0.0.10

type Csv struct {
	Tasks            []*Tunnel
	Path             string
	Hosts            []*Host   //域名列表
	Clients          []*Client //客户端
	ClientIncreaseId int       //客户端id
	TaskIncreaseId   int       //任务自增ID
	sync.Mutex
}
var (
	CsvDb *Csv
)

func GetCsvDb added in v0.0.10

func GetCsvDb() *Csv

init csv from file

func NewCsv added in v0.0.10

func NewCsv() *Csv

func (*Csv) DelClient added in v0.0.10

func (s *Csv) DelClient(id int) error

func (*Csv) DelHost added in v0.0.10

func (s *Csv) DelHost(host string) error

func (*Csv) DelTask added in v0.0.10

func (s *Csv) DelTask(id int) error

func (*Csv) GetClient added in v0.0.10

func (s *Csv) GetClient(id int) (v *Client, err error)

func (*Csv) GetClientId added in v0.0.10

func (s *Csv) GetClientId() int

func (*Csv) GetClientList added in v0.0.10

func (s *Csv) GetClientList(start, length int) ([]*Client, int)

func (*Csv) GetHost added in v0.0.10

func (s *Csv) GetHost(start, length int, id int) ([]*Host, int)

func (*Csv) GetIdByVerifyKey added in v0.0.10

func (s *Csv) GetIdByVerifyKey(vKey string, addr string) (int, error)

func (*Csv) GetTask added in v0.0.10

func (s *Csv) GetTask(id int) (v *Tunnel, err error)

func (*Csv) GetTaskId added in v0.0.10

func (s *Csv) GetTaskId() int

func (*Csv) Init added in v0.0.10

func (s *Csv) Init()

func (*Csv) LoadClientFromCsv added in v0.0.10

func (s *Csv) LoadClientFromCsv()

func (*Csv) LoadHostFromCsv added in v0.0.10

func (s *Csv) LoadHostFromCsv()

func (*Csv) LoadTaskFromCsv added in v0.0.10

func (s *Csv) LoadTaskFromCsv()

func (*Csv) NewClient added in v0.0.10

func (s *Csv) NewClient(c *Client)

func (*Csv) NewHost added in v0.0.10

func (s *Csv) NewHost(t *Host)

func (*Csv) NewTask added in v0.0.10

func (s *Csv) NewTask(t *Tunnel)

func (*Csv) StoreClientsToCsv added in v0.0.10

func (s *Csv) StoreClientsToCsv()

func (*Csv) StoreHostToCsv added in v0.0.10

func (s *Csv) StoreHostToCsv()

func (*Csv) StoreTasksToCsv added in v0.0.10

func (s *Csv) StoreTasksToCsv()

func (*Csv) UpdateClient added in v0.0.10

func (s *Csv) UpdateClient(t *Client) error

func (*Csv) UpdateHost added in v0.0.10

func (s *Csv) UpdateHost(t *Host) error

func (*Csv) UpdateTask added in v0.0.10

func (s *Csv) UpdateTask(t *Tunnel) error

type Flow added in v0.0.10

type Flow struct {
	ExportFlow int64 //出口流量
	InletFlow  int64 //入口流量
}

type Host added in v0.0.10

type Host struct {
	Host         string //启动方式
	Target       string //目标
	HeaderChange string //host修改
	HostChange   string //host修改
	Flow         *Flow
	Client       *Client
	Remark       string //备注
}

type SnappyConn

type SnappyConn struct {
	// contains filtered or unexported fields
}

func NewSnappyConn

func NewSnappyConn(conn net.Conn, crypt bool) *SnappyConn

func (*SnappyConn) Read

func (s *SnappyConn) Read(b []byte) (n int, err error)

snappy压缩读 包含解密

func (*SnappyConn) Write

func (s *SnappyConn) Write(b []byte) (n int, err error)

snappy压缩写 包含加密

type Tunnel added in v0.0.10

type Tunnel struct {
	Id           int     //Id
	TcpPort      int     //服务端与客户端通信端口
	Mode         string  //启动方式
	Target       string  //目标
	Status       bool    //是否开启
	Client       *Client //所属客户端id
	Flow         *Flow
	Config       *Config
	UseClientCnf bool   //是否继承客户端配置
	Remark       string //备注
}

Jump to

Keyboard shortcuts

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