You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1006 B
Go
52 lines
1006 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
//HTTPFlow is a type containg all the data we need.
|
|
type HTTPFlow struct {
|
|
request *http.Request
|
|
response *http.Response
|
|
sensitivity float64 // value who triggers decisions
|
|
seniority int64
|
|
collection float64
|
|
refreshtime time.Duration
|
|
}
|
|
|
|
//DebugLog tells if logs are in debug mode or not
|
|
var DebugLog bool
|
|
|
|
//ProxyFlow represents our flow
|
|
var ProxyFlow HTTPFlow
|
|
|
|
//ZClassifier is our bayesian classifier
|
|
var ZClassifier *ByClassifier
|
|
|
|
//BlockMessage is the messgae we return when blocking
|
|
var BlockMessage string
|
|
|
|
//Maturity is the minimal amount of request , needed to say Zardoz has learnt enough
|
|
var Maturity int64
|
|
|
|
func init() {
|
|
|
|
ZClassifier = new(ByClassifier)
|
|
ZClassifier.enroll()
|
|
|
|
ProxyFlow.sensitivity = 0.5
|
|
ProxyFlow.seniority = 0
|
|
|
|
bl, err := Asset("assets/message.txt")
|
|
if err != nil {
|
|
log.Println("Cannot marshal asset error message!!")
|
|
BlockMessage = ""
|
|
} else {
|
|
BlockMessage = fmt.Sprintf("%s", bl)
|
|
}
|
|
|
|
}
|