Documentation
¶
Overview ¶
*
安全策略,監控用戶的行爲。 危險行爲定義: 1.高頻請求 - 限流處理,已實現,見apper.iplimiter - 掃描目錄,多次訪問不存在目錄,例如/project/user,/project/admin,404錯誤一個周期内超過50次,則封禁該ip - 遍歷爆破,例如:登錄接口多次頻繁嘗試密碼,采用時間間隔監控 2.輸入内容異常 - 異常參數:sql注入,XSS,命令注入,// ! 待完善 - 提交大文件/數據,// ! 待完善 方案: IP監控周期5分鐘,禁用規則 1.404錯誤,超過50次 2.10次内的訪問時間間隔相同,或少於1秒的次數超過7次 3.url正則匹配,防止sql漏洞,XSS漏洞,命令 // ! 待完善
Index ¶
- type Apper
- func (this *Apper) Close()
- func (this *Apper) Get(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
- func (this *Apper) GetClientIP(r *http.Request) string
- func (this *Apper) Logger()
- func (this *Apper) Post(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
- func (this *Apper) Route(method string, path string, f http.HandlerFunc, mid ...MiddlewareFunc)
- func (this *Apper) Run()
- func (this *Apper) RunTLS(certFile, keyFile string)
- func (this *Apper) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (this *Apper) SetConfig()
- func (this *Apper) SetLimit()
- func (this *Apper) SetLog()
- func (this *Apper) SetPort()
- func (this *Apper) Use(middleware ...MiddlewareFunc)
- type Behaver
- func (this *Behaver) CheckNotFound(ip string) bool
- func (this *Behaver) CheckScan(ip string) bool
- func (this *Behaver) Clear()
- func (this *Behaver) IsLock(ip string) bool
- func (this *Behaver) Lock(ip string)
- func (this *Behaver) Record(ip string, code int)
- func (this *Behaver) RegexUrl(url string) bool
- type Cacher
- type Configer
- type FileUploader
- type IpInfo
- type Jwter
- func (this *Jwter) Decode(token string) (string, error)
- func (this *Jwter) Encode() (string, error)
- func (this *Jwter) GetArr(tokenstr string) ([]string, error)
- func (this *Jwter) GetJoin(key string, exp string, code string) (string, error)
- func (this *Jwter) OneToTwo(val string) string
- func (this *Jwter) Validate(token string) error
- type MiddlewareFunc
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Apper ¶
type Apper struct {
// 配置信息结构体指针
// Configuration information struct pointer
Config *Configer
// contains filtered or unexported fields
}
Apper 是应用程序的主结构体,包含路由映射、配置信息、端口、日志等信息 Apper is the main struct of the application, containing route mappings, configuration information, port, logs, etc.
func (*Apper) Close ¶
func (this *Apper) Close()
Close 关闭应用程序资源,包括日志文件和消息通道 Close closes application resources, including log file and message channel
func (*Apper) Get ¶
func (this *Apper) Get(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
Get 注册GET请求的路由处理函数 Get registers the route handler function for GET requests
func (*Apper) GetClientIP ¶
GetClientIP 获取客户端真实IP地址 GetClientIP get client real IP address
func (*Apper) Logger ¶
func (this *Apper) Logger()
Logger 处理日志记录,监听消息通道并将日志写入文件或控制台 Logger handles log recording, listens to the message channel and writes logs to file or console
func (*Apper) Post ¶
func (this *Apper) Post(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
Post 注册POST请求的路由处理函数 Post registers the route handler function for POST requests
func (*Apper) Route ¶
func (this *Apper) Route(method string, path string, f http.HandlerFunc, mid ...MiddlewareFunc)
Route 注册指定HTTP方法的路由处理函数 Route registers the route handler function for the specified HTTP method
func (*Apper) ServeHTTP ¶
func (this *Apper) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP 实现http.Handler接口,处理HTTP请求 ServeHTTP implements the http.Handler interface to handle HTTP requests
func (*Apper) SetConfig ¶
func (this *Apper) SetConfig()
SetConfig 从config.ini文件中读取配置信息 SetConfig reads configuration information from config.ini file
func (*Apper) SetLog ¶
func (this *Apper) SetLog()
SetLog 根据配置设置日志记录器 SetLog sets up the logger according to configuration
func (*Apper) SetPort ¶
func (this *Apper) SetPort()
SetPort 从配置中设置服务器端口,默认为8080 SetPort sets the server port from configuration, default is 8080
func (*Apper) Use ¶
func (this *Apper) Use(middleware ...MiddlewareFunc)
全局中間件處理 Global middleware processing
type Behaver ¶ added in v0.1.6
type Behaver struct {
IpMontion map[string]*IpInfo
// 監控IP最大值
IpMax int
// 禁用IP
IpDisable map[string]int64
// 監控時間間隔
Expire int64
// 自動清理時間,分鐘
CleanSecond int64
// contains filtered or unexported fields
}
func NewBehaver ¶ added in v0.1.6
func NewBehaver() *Behaver
func (*Behaver) CheckNotFound ¶ added in v0.1.6
* 檢查404錯誤
type Cacher ¶
type Cacher struct {
// contains filtered or unexported fields
}
type FileUploader ¶
type FileUploader struct {
MaxSize int64
AllowedTypes []string
SavePath string
MaxFiles int //一次最大上传文件数量
FieldName string // 添加单文件字段名
FieldNames string // 添加多文件字段名
Keyword string // 添加文件名关键字
}
func NewFileUploader ¶
func NewFileUploader(maxSize int64, allowedTypes []string, savePath string) *FileUploader
func (*FileUploader) HandleUpload ¶
func (f *FileUploader) HandleUpload(r *http.Request) ([]string, error)
HandleUpload 修改为支持批量文件上传
