Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
TelcoDB
Web Frontend
Commits
24e74443
Verified
Commit
24e74443
authored
Oct 22, 2019
by
Elias Ojala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Punycode & TLD handling in search
parent
d24aa129
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
3 deletions
+44
-3
src/controllers/search.controller.ts
src/controllers/search.controller.ts
+44
-3
No files found.
src/controllers/search.controller.ts
View file @
24e74443
...
...
@@ -3,6 +3,11 @@ import isIp from "is-ip";
import
domainNameRegex
from
"
domain-name-regex
"
;
import
isAsn
from
"
is-asn
"
;
import
isCidr
from
"
is-cidr
"
;
import
punycode
from
"
punycode
"
;
import
isDomainName
from
"
is-domain-name
"
;
const
{
Resolver
}
=
require
(
'
dns
'
).
promises
;
const
resolver
=
new
Resolver
();
const
router
:
Router
=
Router
();
...
...
@@ -19,10 +24,46 @@ router.get("/", (req: Request, res: Response, next: NextFunction) => {
res
.
redirect
(
`/
${
query
}
`
);
}
else
if
(
isCidr
(
query
))
{
res
.
redirect
(
`/net/
${
query
}
`
);
}
else
if
(
domainNameRegex
.
test
(
query
))
{
res
.
redirect
(
`/dns/
${
query
}
`
);
}
else
if
(
domainNameRegex
.
test
(
punycode
.
toASCII
(
query
))
)
{
res
.
redirect
(
`/dns/
${
punycode
.
toASCII
(
query
)
}
`
);
}
else
{
res
.
send
(
"
Query:
"
+
query
);
/**
* TLD check
*/
if
(
isDomainName
(
punycode
.
toASCII
(
query
)))
{
const
tld
=
punycode
.
toASCII
(
query
);
if
(
tld
.
toLowerCase
()
!==
tld
&&
tld
.
toUpperCase
()
!==
tld
)
{
// If query is partially upper case, do not continue to TLD resolve.
//
// google -> TLD
// Google -> continue_search
// GOOGLE -> TLD
continue_search
(
query
);
}
else
{
resolver
.
resolveNs
(
tld
)
.
then
(
addresses
=>
{
if
(
addresses
.
length
>
2
)
{
res
.
redirect
(
`/tld/
${
tld
}
`
)
}
})
.
catch
(
err
=>
{
if
(
err
.
errno
===
"
ENOTFOUND
"
)
{
// TLD not found
continue_search
(
query
);
}
else
{
// DNS errors
next
(
err
);
}
})
}
}
else
{
continue_search
(
query
);
}
function
continue_search
(
query
)
{
res
.
send
(
"
Query:
"
+
query
);
}
}
}
else
{
next
();
...
...
Write
Preview
Markdown
is supported
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