Add debug statements
All checks were successful
Build and push container / Build-Docker-Container (push) Successful in 1m37s
All checks were successful
Build and push container / Build-Docker-Container (push) Successful in 1m37s
This commit is contained in:
parent
d21f611289
commit
f388664482
5
main.go
5
main.go
@ -23,12 +23,17 @@ func (h *dnsHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
|||||||
|
|
||||||
if question.Qtype == dns.TypeCNAME || question.Qtype == dns.TypeA || question.Qtype == dns.TypeAAAA {
|
if question.Qtype == dns.TypeCNAME || question.Qtype == dns.TypeA || question.Qtype == dns.TypeAAAA {
|
||||||
if strings.HasSuffix(question.Name, "prime.cringe-studios.com") || strings.HasSuffix(question.Name, "prime.cringe-studios.com.") {
|
if strings.HasSuffix(question.Name, "prime.cringe-studios.com") || strings.HasSuffix(question.Name, "prime.cringe-studios.com.") {
|
||||||
|
log.Println("Prime request")
|
||||||
primeAnswer := HandlePrimeNumberChecker(question)
|
primeAnswer := HandlePrimeNumberChecker(question)
|
||||||
|
log.Println("about to append request: %i", primeAnswer)
|
||||||
|
|
||||||
if primeAnswer != nil {
|
if primeAnswer != nil {
|
||||||
|
log.Println("appending")
|
||||||
msg.Answer = append(msg.Answer, primeAnswer)
|
msg.Answer = append(msg.Answer, primeAnswer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("finished")
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
prime.go
30
prime.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -18,74 +19,102 @@ func IsNumber(stringToCheck string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandlePrimeNumberChecker(question dns.Question) dns.RR {
|
func HandlePrimeNumberChecker(question dns.Question) dns.RR {
|
||||||
|
log.Println("1")
|
||||||
mainDomainPartindex := strings.LastIndex(question.Name, "prime.cringe-studios.com")
|
mainDomainPartindex := strings.LastIndex(question.Name, "prime.cringe-studios.com")
|
||||||
|
log.Println("2")
|
||||||
if mainDomainPartindex == 0 || mainDomainPartindex == 1 {
|
if mainDomainPartindex == 0 || mainDomainPartindex == 1 {
|
||||||
// TODO handle ns page part.. maybe send back a CNAME for a page to enter the number
|
// TODO handle ns page part.. maybe send back a CNAME for a page to enter the number
|
||||||
|
log.Println("3")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
isQuestionPartIndex := strings.LastIndex(question.Name, "is.prime.cringe-studios.com")
|
isQuestionPartIndex := strings.LastIndex(question.Name, "is.prime.cringe-studios.com")
|
||||||
|
log.Println("4")
|
||||||
if isQuestionPartIndex == 0 || isQuestionPartIndex == 1 {
|
if isQuestionPartIndex == 0 || isQuestionPartIndex == 1 {
|
||||||
|
log.Println("5")
|
||||||
// TODO handle resource found
|
// TODO handle resource found
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
isnotQuestionPartIndex := strings.LastIndex(question.Name, "isnot.prime.cringe-studios.com")
|
isnotQuestionPartIndex := strings.LastIndex(question.Name, "isnot.prime.cringe-studios.com")
|
||||||
|
log.Println("6")
|
||||||
if isnotQuestionPartIndex == 0 || isnotQuestionPartIndex == 1 {
|
if isnotQuestionPartIndex == 0 || isnotQuestionPartIndex == 1 {
|
||||||
// TODO handle resource found
|
// TODO handle resource found
|
||||||
|
log.Println("7")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeQuestionPartIndex := strings.LastIndex(question.Name, "maybe.prime.cringe-studios.com")
|
maybeQuestionPartIndex := strings.LastIndex(question.Name, "maybe.prime.cringe-studios.com")
|
||||||
|
log.Println("8")
|
||||||
if maybeQuestionPartIndex == 0 || maybeQuestionPartIndex == 1 {
|
if maybeQuestionPartIndex == 0 || maybeQuestionPartIndex == 1 {
|
||||||
// TODO handle resource found
|
// TODO handle resource found
|
||||||
|
log.Println("9")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mainDomainPart := question.Name[0 : mainDomainPartindex-1] // subtract 1 for the p in prime
|
mainDomainPart := question.Name[0 : mainDomainPartindex-1] // subtract 1 for the p in prime
|
||||||
|
log.Println("10:" + mainDomainPart)
|
||||||
|
|
||||||
if !strings.HasSuffix(mainDomainPart, ".") {
|
if !strings.HasSuffix(mainDomainPart, ".") {
|
||||||
// unknown subdomain like 123prime.cringe-studios.com
|
// unknown subdomain like 123prime.cringe-studios.com
|
||||||
|
log.Println("11")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
mainDomainPart = mainDomainPart[0 : len(mainDomainPart)-2] // subtract 1 to accomodate for the length being one bigger then the last index, and subtract another one for the dot at the end
|
mainDomainPart = mainDomainPart[0 : len(mainDomainPart)-2] // subtract 1 to accomodate for the length being one bigger then the last index, and subtract another one for the dot at the end
|
||||||
|
log.Println("12:" + mainDomainPart)
|
||||||
|
|
||||||
if len(mainDomainPart) == 0 {
|
if len(mainDomainPart) == 0 {
|
||||||
// .prime.cringe-studios.com
|
// .prime.cringe-studios.com
|
||||||
|
log.Println("13")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
firstIsIndex := strings.Index(mainDomainPart, "is.")
|
firstIsIndex := strings.Index(mainDomainPart, "is.")
|
||||||
|
|
||||||
|
log.Println("14")
|
||||||
|
|
||||||
if firstIsIndex == 0 || firstIsIndex == 1 {
|
if firstIsIndex == 0 || firstIsIndex == 1 {
|
||||||
// word "is." found at the beginning of the question.. trim
|
// word "is." found at the beginning of the question.. trim
|
||||||
mainDomainPart = mainDomainPart[len("is.") : len(mainDomainPart)-1]
|
mainDomainPart = mainDomainPart[len("is.") : len(mainDomainPart)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("15: " + mainDomainPart)
|
||||||
|
|
||||||
if len(mainDomainPart) == 0 {
|
if len(mainDomainPart) == 0 {
|
||||||
// requested domain was is.prime.cringe-studios.com or something like that...
|
// requested domain was is.prime.cringe-studios.com or something like that...
|
||||||
// TODO
|
// TODO
|
||||||
|
log.Println("16")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("16.5")
|
||||||
|
|
||||||
if !IsNumber(mainDomainPart) {
|
if !IsNumber(mainDomainPart) {
|
||||||
// TODO return cname to isnot.prime.cringe-studios.com
|
// TODO return cname to isnot.prime.cringe-studios.com
|
||||||
|
log.Println("17")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("18")
|
||||||
|
|
||||||
bigNumber := new(big.Int)
|
bigNumber := new(big.Int)
|
||||||
fmt.Sscan(mainDomainPart, bigNumber)
|
fmt.Sscan(mainDomainPart, bigNumber)
|
||||||
|
|
||||||
|
log.Println("19")
|
||||||
|
|
||||||
if bigNumber.Cmp(maximumPrimeNumber) == 1 {
|
if bigNumber.Cmp(maximumPrimeNumber) == 1 {
|
||||||
// number is bigger than the maximum limit for the propablyprime function
|
// number is bigger than the maximum limit for the propablyprime function
|
||||||
// TODO return CNAME for maybe.prime.cringe-studios.com
|
// TODO return CNAME for maybe.prime.cringe-studios.com
|
||||||
|
|
||||||
|
log.Println("20")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if bigNumber.ProbablyPrime(20) {
|
if bigNumber.ProbablyPrime(20) {
|
||||||
|
log.Println("21")
|
||||||
// is prime, because the cases bigger than 2^64-1 have been catched above
|
// is prime, because the cases bigger than 2^64-1 have been catched above
|
||||||
return &dns.CNAME{
|
return &dns.CNAME{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
@ -97,6 +126,7 @@ func HandlePrimeNumberChecker(question dns.Question) dns.RR {
|
|||||||
Target: "is.prime.cringe-studios.com.",
|
Target: "is.prime.cringe-studios.com.",
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
log.Println("22")
|
||||||
// is not prime
|
// is not prime
|
||||||
return &dns.CNAME{
|
return &dns.CNAME{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
|
Loading…
Reference in New Issue
Block a user