Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/store log #115

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ opt/domain-owner/example/example
ta/example/private.pem
ta/example/public.pem
verifier/serv/last.log
verifier/serv/first-log.txt
22 changes: 20 additions & 2 deletions verifier/monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ctcore "github.com/akakou/ctstream/core"
"github.com/akakou/ctstream/direct"
"github.com/akakou/ctstream/monitor/crtsh"
goutils "github.com/akakou/go-utils"
"github.com/akakou/ra_webs/verifier/core"
"github.com/akakou/ra_webs/verifier/ent"
"github.com/akakou/ra_webs/verifier/ent/taserver"
Expand All @@ -18,8 +19,10 @@ import (
type CrtshStream = ctcore.CTStream[*ctcore.CTClients[*crtsh.CrtshCTClient]]

type CrtshMonitor struct {
ctstream *CrtshStream
ctx context.Context
ctstream *CrtshStream
ctx context.Context
lastLogger *goutils.File[int]
first int
}

func NewCrtshMonitor(ctx context.Context) *CrtshMonitor {
Expand All @@ -35,6 +38,16 @@ func (a *CrtshMonitor) Setup(verifier *core.Verifier) error {
return err
}

err = a.loadFileLogger()
if err != nil {
return err
}

err = a.loadFirst()
if err != nil {
return err
}

return a.ctstream.Init()
}

Expand Down Expand Up @@ -90,6 +103,11 @@ func (a *CrtshMonitor) Run(verifier *core.Verifier) {
option := params.(*crtsh.CrtshCTParams)
domain := option.Client.Domain

if option.ID > a.first {
a.first = option.ID
a.lastLogger.Store(&a.first)
}

serv, err := verifier.DB.Client.TAServer.
Query().
Where(taserver.DomainEQ(domain)).
Expand Down
32 changes: 32 additions & 0 deletions verifier/monitor/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import (
"fmt"

"github.com/akakou/ctstream/monitor/crtsh"
goutils "github.com/akakou/go-utils"
"github.com/akakou/ra_webs/verifier/core"
"github.com/akakou/ra_webs/verifier/ent/taserver"
)

const LOG_FILE_PATH = "first-log.txt"

const FILE_EMPLTY = "strconv.Atoi: parsing \"\": invalid syntax"

func (a *CrtshMonitor) loadStream(verifier *core.Verifier) error {
servers, err := verifier.DB.Client.TAServer.Query().Select(taserver.FieldDomain).All(*verifier.DB.Ctx)
if err != nil {
Expand All @@ -26,3 +31,30 @@ func (a *CrtshMonitor) loadStream(verifier *core.Verifier) error {

return nil
}

func (a *CrtshMonitor) loadFileLogger() error {
lastLogger, err := goutils.OpenIntFile(LOG_FILE_PATH)
if err != nil {
return err
}

a.lastLogger = lastLogger

return nil
}

func (a *CrtshMonitor) loadFirst() error {
first, err := a.lastLogger.Restore()

if err == nil {
} else if err.Error() == FILE_EMPLTY {
fmt.Printf("%v is empty !: %v\n", LOG_FILE_PATH, err)
first = new(int)
*first = 0
} else {
return err
}

fmt.Printf("First: %v\n", *first)
return nil
}
Loading