當前位置: 首頁>>代碼示例>>Golang>>正文


Golang fail2go.Conn類代碼示例

本文整理匯總了Golang中github.com/Sean-Der/fail2go.Conn的典型用法代碼示例。如果您正苦於以下問題:Golang Conn類的具體用法?Golang Conn怎麽用?Golang Conn使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Conn類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: jailTestFailRegexHandler

func jailTestFailRegexHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
	var input jailFailRegexBody
	json.NewDecoder(req.Body).Decode(&input)

	regexp, err := regexp.Compile(strings.Replace(input.FailRegex, "<HOST>", "(?:::f{4,6}:)?(?P<host>\\S+)", -1))

	if err != nil {
		writeHTTPError(res, err)
		return
	}

	_, _, fileList, _, _, _, err := fail2goConn.JailStatus(mux.Vars(req)["jail"])
	if err != nil {
		writeHTTPError(res, err)
		return
	}

	output := make(map[string][]RegexResult)
	for _, fileName := range fileList {
		file, err := os.Open(fileName)
		if err != nil {
			writeHTTPError(res, err)
			return
		}
		scanner := bufio.NewScanner(file)
		for scanner.Scan() {
			output[fileName] = append(output[fileName], RegexResult{Match: regexp.MatchString(scanner.Text()), Line: scanner.Text()})
		}
	}

	encodedOutput, _ := json.Marshal(output)
	res.Write(encodedOutput)
}
開發者ID:Erreur32,項目名稱:fail2rest,代碼行數:33,代碼來源:jail.go

示例2: jailUnbanIPHandler

func jailUnbanIPHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
	var input jailBanIPBody
	json.NewDecoder(req.Body).Decode(&input)
	output, err := fail2goConn.JailUnbanIP(mux.Vars(req)["jail"], input.IP)
	if err != nil {
		writeHTTPError(res, err)
		return
	}

	encodedOutput, _ := json.Marshal(map[string]interface{}{"unBannedIP": output})
	res.Write(encodedOutput)
}
開發者ID:Erreur32,項目名稱:fail2rest,代碼行數:12,代碼來源:jail.go

示例3: jailDeleteFailRegexHandler

func jailDeleteFailRegexHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
	var input jailFailRegexBody
	json.NewDecoder(req.Body).Decode(&input)

	output, err := fail2goConn.JailDeleteFailRegex(mux.Vars(req)["jail"], input.FailRegex)
	if err != nil {
		writeHTTPError(res, err)
		return
	}

	encodedOutput, _ := json.Marshal(map[string]interface{}{"FailRegex": output})
	res.Write(encodedOutput)
}
開發者ID:Erreur32,項目名稱:fail2rest,代碼行數:13,代碼來源:jail.go

示例4: jailSetMaxRetryHandler

func jailSetMaxRetryHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
	var input jailMaxRetryBody
	json.NewDecoder(req.Body).Decode(&input)

	output, err := fail2goConn.JailSetMaxRetry(mux.Vars(req)["jail"], input.MaxRetry)
	if err != nil {
		writeHTTPError(res, err)
		return
	}

	encodedOutput, _ := json.Marshal(map[string]interface{}{"maxRetry": output})
	res.Write(encodedOutput)
}
開發者ID:Erreur32,項目名稱:fail2rest,代碼行數:13,代碼來源:jail.go

示例5: jailGetHandler

func jailGetHandler(res http.ResponseWriter, req *http.Request, fail2goConn *fail2go.Conn) {
	currentlyFailed, totalFailed, fileList, currentlyBanned, totalBanned, IPList, err := fail2goConn.JailStatus(mux.Vars(req)["jail"])
	if err != nil {
		writeHTTPError(res, err)
		return
	}

	failRegexes, _ := fail2goConn.JailFailRegex(mux.Vars(req)["jail"])
	findTime, _ := fail2goConn.JailFindTime(mux.Vars(req)["jail"])
	useDNS, _ := fail2goConn.JailUseDNS(mux.Vars(req)["jail"])
	maxRetry, _ := fail2goConn.JailMaxRetry(mux.Vars(req)["jail"])

	if IPList == nil {
		IPList = []string{}
	}
	if failRegexes == nil {
		failRegexes = []string{}
	}

	encodedOutput, _ := json.Marshal(map[string]interface{}{
		"currentlyFailed": currentlyFailed,
		"totalFailed":     totalFailed,
		"fileList":        fileList,
		"currentlyBanned": currentlyBanned,
		"totalBanned":     totalBanned,
		"IPList":          IPList,
		"failRegexes":     failRegexes,
		"findTime":        findTime,
		"useDNS":          useDNS,
		"maxRetry":        maxRetry})
	res.Write(encodedOutput)
}
開發者ID:Erreur32,項目名稱:fail2rest,代碼行數:32,代碼來源:jail.go


注:本文中的github.com/Sean-Der/fail2go.Conn類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。