diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-07-07 15:20:11 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-07-07 15:52:59 +0530 |
commit | e0f32fb48caf9397ac87fdd6c6597d888f9a8a40 (patch) | |
tree | 0a9c5ccabf13192264d7967533a4d8a0ddb16529 /dns | |
parent | 60aa1b7adbd133a5b1679ab2feac4ec17e3b48b5 (diff) |
api/dns: init
Diffstat (limited to 'dns')
-rw-r--r-- | dns/main.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/dns/main.go b/dns/main.go index a9be24e..3daa879 100644 --- a/dns/main.go +++ b/dns/main.go @@ -37,6 +37,7 @@ func (d *Dns) ServeDNS(w dns.ResponseWriter, req *dns.Msg) { resp = new(dns.Msg) resp.SetReply(req) w.WriteMsg(resp) + d.blackList.mutex.RUnlock() return } d.blackList.mutex.RUnlock() @@ -92,3 +93,31 @@ func New(queries *db.Queries, ctxDb context.Context) (*Dns, error) { func (d *Dns) Run() { d.server.ListenAndServe() } + +func (d *Dns) Block(domain string) error { + err := d.queries.EnterDnsBlackList(d.ctxDb, domain) + if err != nil { + log.Printf("adding dns blacklist entry: %s", err) + return err + } + + d.blackList.mutex.Lock() + d.blackList.data[domain] = true + d.blackList.mutex.Unlock() + + return nil +} + +func (d *Dns) Unblock(domain string) error { + err := d.queries.DeleteDnsBlackList(d.ctxDb, domain) + if err != nil { + log.Printf("deleting dns blacklist entry: %s", err) + return err + } + + d.blackList.mutex.Lock() + delete(d.blackList.data, domain) + d.blackList.mutex.Unlock() + + return nil +} |