Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nogweii
my-certificate-alert
Commits
b0a2c21e
Commit
b0a2c21e
authored
Aug 17, 2021
by
Nogweii
Browse files
now we read from a file
parent
773d636f
Changes
2
Hide whitespace changes
Inline
Side-by-side
domains.txt
0 → 100644
View file @
b0a2c21e
*.nogweii.net
*.github.com
*.microsoft.com
*.google.com
*.netflix.com
*.cloudflare.com
flowers-to-the-world.com
sni.cloudflaressl.com
main.go
View file @
b0a2c21e
...
...
@@ -2,17 +2,23 @@ package main
import
(
"strings"
"os"
"bufio"
"github.com/CaliDog/certstream-go"
"github.com/gobwas/glob"
log
"github.com/sirupsen/logrus"
)
var
globs
[]
glob
.
Glob
func
main
()
{
log
.
WithFields
(
log
.
Fields
{
"version"
:
"0.0.0"
,
// TODO: actually get the version number
})
.
Info
(
"Starting my certificate alert"
)
readDomainsFromFile
(
"domains.txt"
)
stream
,
errStream
:=
certstream
.
CertStreamEventStream
(
true
)
for
{
...
...
@@ -46,22 +52,6 @@ func main() {
}
func
matchesDomains
(
domainName
string
)
bool
{
var
globs
[]
glob
.
Glob
myGlob
,
err
:=
glob
.
Compile
(
"*.nogweii.net"
)
if
err
!=
nil
{
log
.
WithFields
(
log
.
Fields
{
"error"
:
err
})
.
Fatal
(
"Failed to compile glob"
)
}
globs
=
append
(
globs
,
myGlob
)
// TODO: replace this with a file
globs
=
append
(
globs
,
glob
.
MustCompile
(
"*.github.com"
))
globs
=
append
(
globs
,
glob
.
MustCompile
(
"*.microsoft.com"
))
globs
=
append
(
globs
,
glob
.
MustCompile
(
"*.google.com"
))
globs
=
append
(
globs
,
glob
.
MustCompile
(
"*.netflix.com"
))
globs
=
append
(
globs
,
glob
.
MustCompile
(
"*.cloudflare.com"
))
globs
=
append
(
globs
,
glob
.
MustCompile
(
"flowers-to-the-world.com"
))
globs
=
append
(
globs
,
glob
.
MustCompile
(
"sni.cloudflaressl.com"
))
var
any_match
=
false
for
_
,
glob
:=
range
globs
{
any_match
=
glob
.
Match
(
domainName
)
||
any_match
...
...
@@ -69,3 +59,28 @@ func matchesDomains(domainName string) bool {
return
any_match
}
func
readDomainsFromFile
(
filepath
string
)
[]
glob
.
Glob
{
file
,
err
:=
os
.
Open
(
filepath
)
if
err
!=
nil
{
log
.
WithFields
(
log
.
Fields
{
"error"
:
err
})
.
Fatal
(
"Failed to open file "
,
filepath
)
}
defer
file
.
Close
()
scanner
:=
bufio
.
NewScanner
(
file
)
for
scanner
.
Scan
()
{
text
:=
scanner
.
Text
()
// TODO: skip blank and commented lines
myGlob
,
err
:=
glob
.
Compile
(
text
)
if
err
!=
nil
{
log
.
WithFields
(
log
.
Fields
{
"error"
:
err
})
.
Fatal
(
"Invalid glob "
,
text
)
}
globs
=
append
(
globs
,
myGlob
)
}
if
err
:=
scanner
.
Err
();
err
!=
nil
{
log
.
WithFields
(
log
.
Fields
{
"error"
:
err
})
.
Fatal
(
"Could not scan through file"
)
}
return
globs
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment