Ejemplo n.º 1
0
func (this *Updater) Start() {
	ruleFilePath := path.Join(this.rulePath, "update.json")
	dbFilePath := path.Join(this.dbPath, "agent.db")
	tableName := `"update"`

	db, err := util.InitTable(fmt.Sprintf(
		"PRAGMA journal_mode = WAL; CREATE TABLE IF NOT EXISTS %s(ip TEXT, port TEXT, source TEXT, level INTEGER)",
		tableName,
	), dbFilePath)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()
	level := util.GetLastLevel(tableName, db) + 1

	e := engine.
		NewQuickEngine(ruleFilePath).
		GetEngine().
		AddPlugin(util.NewAddLevelPlugin(level)).
		SetPipeline(pipeline.NewSqlPipeline(db, tableName))

	var ok bool
	if ok = this.isAgentServerOK(); ok {
		e.AddPlugin(plugin.NewProxyPlugin())
	}
	log.Printf("started %s(isAgentServerOK: %v)\n", ruleFilePath, ok)
	e.Start()
}
Ejemplo n.º 2
0
func (this *Validator) Start() {
	ruleFilePath := path.Join(this.rulePath, "validate.json")
	dbFilePath := path.Join(this.dbPath, "agent.db")
	updateTableName := `"update"`
	validateTableName := `"validate"`

	db, err := util.InitTable(fmt.Sprintf(
		"PRAGMA journal_mode = WAL; CREATE TABLE IF NOT EXISTS %s(ip TEXT, port TEXT, domain TEXT, level INTEGER)",
		validateTableName,
	), dbFilePath)

	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()
	level := util.GetLastLevel(validateTableName, db) + 1

	qe := engine.NewQuickEngine(ruleFilePath)
	reqs := this.genRequests(qe.GetQuickEngineConfig().StartUrls, updateTableName, level, db)

	qe.
		GetEngine().
		SetStartRequests(reqs).
		AddPlugin(util.NewModifyResponsePlugin()).
		AddPlugin(util.NewAddLevelPlugin(level)).
		SetPipeline(pipeline.NewSqlPipeline(db, validateTableName)).
		Start()
}