new: the events ignore list is now exported as the events.stream state object via api.rest

This commit is contained in:
evilsocket 2019-03-21 11:59:41 +01:00
commit 80000ed737
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 11 additions and 2 deletions

View file

@ -49,6 +49,8 @@ func NewEventsStream(s *session.Session) *EventsStream {
triggerList: NewTriggerList(), triggerList: NewTriggerList(),
} }
mod.State.Store("ignoring", &mod.Session.EventsIgnoreList)
mod.AddHandler(session.NewModuleHandler("events.stream on", "", mod.AddHandler(session.NewModuleHandler("events.stream on", "",
"Start events stream.", "Start events stream.",
func(args []string) error { func(args []string) error {

View file

@ -1,6 +1,7 @@
package session package session
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
@ -30,6 +31,12 @@ func NewEventsIgnoreList() *EventsIgnoreList {
} }
} }
func (l *EventsIgnoreList) MarshalJSON() ([]byte, error) {
l.RLock()
defer l.RUnlock()
return json.Marshal(l.filters)
}
func (l *EventsIgnoreList) checkExpression(expr string) (string, error) { func (l *EventsIgnoreList) checkExpression(expr string) (string, error) {
expr = str.Trim(expr) expr = str.Trim(expr)
if expr == "" { if expr == "" {
@ -88,8 +95,8 @@ func (l *EventsIgnoreList) Remove(expr string) (err error) {
} }
func (l *EventsIgnoreList) Clear() { func (l *EventsIgnoreList) Clear() {
l.RLock() l.Lock()
defer l.RUnlock() defer l.Unlock()
l.filters = make([]filter, 0) l.filters = make([]filter, 0)
} }