Beispiel #1
0
//NewRuleFileParser creates a new RuleFileParser, returns an error if the object is not valid
func NewRuleFileParser(ruleFile string) (*RuleFileParser, error) {
	fileReader, err := os.Open(ruleFile)
	if err != nil {
		return nil, err
	}
	r := csv.NewReader(fileReader)
	r.TrimLeadingSpace = true
	r.Comment = '#'
	r.Comma = ';'
	records, err := r.ReadAll()
	if err != nil {
		return nil, err
	}

	lines := []RuleLine{}
	for _, elements := range records {
		command, args, err := parseCommand(elements[2])
		if err != nil {
			return nil, err
		}

		if len(elements[0]) == 0 && len(elements[1]) == 0 {
			if len(lines) == 0 {
				return nil, fmt.Errorf("The first rule can not referance back")
			}
			lastRule := lines[len(lines)-1]
			lines = append(lines, RuleLine{name: lastRule.name,
				condition: lastRule.condition,
				command:   command,
				args:      args,
				flags:     helper.StringToMap(elements[3], ",", "="),
			})
		} else {
			lines = append(lines,
				RuleLine{name: elements[0],
					condition: elements[1],
					command:   command,
					args:      args,
					flags:     helper.StringToMap(elements[3], ",", "="),
				})
		}
	}
	client, err := Logging.NewClientOwnName(Config.GetClientConfig().LogServer.RPCInterface, "RuleSystem")
	if err != nil {
		return nil, err
	}
	return &RuleFileParser{ruleFile: ruleFile, lines: lines, externalModule: *Module.NewExternalModule(), LogClient: client}, nil
}
//NewProxyRPCInterface creates a new ProxyRPCInterface
func NewProxyRPCInterface() *ProxyRPCInterface {
	rpc := NewRPCInterface(Config.GetServerConfig().Proxy.RPCInterface)
	ruleRPC := &ProxyRPCInterface{RPCInterface: rpc}
	rpc.publishHandler(&ProxyRPCHandler{Module.NewExternalModule()})
	return ruleRPC
}