-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add support for DNS #2214
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
Open
filips123
wants to merge
25
commits into
HelloZeroNet:py3
Choose a base branch
from
filips123:dns
base: py3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add support for DNS #2214
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
fd11d4f
Add support for DNS
filips123 586f2dd
Add plugin description for Zeroname
filips123 08b84a9
Install plugin dependencies in CI
filips123 79759a3
Install plugin dependencies in Docker and Vagrant
filips123 060c66a
Use DNSPython temporary fork until PR is merged
filips123 476f612
Update DNSLink to allow Python 3.4
filips123 b17a365
Use hard-coded commit hash for DNSPython
filips123 460a103
Resolve requested changes
filips123 66516c0
Remove trailing commas
filips123 649cd90
Remove UiRequestPlugin from DNS plugin
filips123 a22b074
Merge branch 'py3' of https://github.com/HelloZeroNet/ZeroNet into py3
filips123 9104f42
Merge branch 'py3' of https://github.com/HelloZeroNet/ZeroNet into dns
filips123 2caf10b
Update DNSPython
filips123 1c099d5
Add wrapperInfo command
purplesyringa bcbd27e
Always support transparent proxies (including classic DNS)
purplesyringa 071f1c6
Bundle plugin dependencies along source code
filips123 e679f81
Update dependencies
filips123 db3f586
Update dependencies
filips123 0bda4b4
Requests with `HOST` in `ui_host` shouldn't be proxy requests
filips123 1fe1e06
Also check if `HOST` is in `ui_host` before changing route path
filips123 633aaea
Fix checking for UI host where config is not set
filips123 c9883a1
Allow setting custom WS URL for proxy requests
filips123 5cff378
Merge branch 'py3' into dns
filips123 4b3e8cd
Install plugin dependencies in GitHub Actions
filips123 2078a48
Replace SecureDNS and Dnswarden with LibreDNS
filips123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
FROM alpine:3.8 | ||
|
||
#Base settings | ||
# Base settings | ||
ENV HOME /root | ||
WORKDIR /root | ||
|
||
COPY requirements.txt /root/requirements.txt | ||
# Add ZeroNet source | ||
COPY . /root | ||
VOLUME /root/data | ||
|
||
#Install ZeroNet | ||
# Install dependencies | ||
RUN apk --no-cache --no-progress add python3 python3-dev gcc libffi-dev musl-dev make tor openssl \ | ||
&& pip3 install -r /root/requirements.txt \ | ||
&& pip3 install -r requirements.txt \ | ||
&& for PLUGIN in $(ls plugins/[^disabled-]*/requirements.txt); do pip3 install -r ${PLUGIN}; done \ | ||
&& apk del python3-dev gcc libffi-dev musl-dev make \ | ||
&& echo "ControlPort 9051" >> /etc/tor/torrc \ | ||
&& echo "CookieAuthentication 1" >> /etc/tor/torrc | ||
|
||
#Add Zeronet source | ||
COPY . /root | ||
VOLUME /root/data | ||
|
||
#Control if Tor proxy is started | ||
# Control if Tor proxy is started | ||
ENV ENABLE_TOR false | ||
|
||
WORKDIR /root | ||
|
||
#Set upstart command | ||
# Set upstart command | ||
CMD (! ${ENABLE_TOR} || tor&) && python3 zeronet.py --ui_ip 0.0.0.0 --fileserver_port 26552 | ||
|
||
#Expose ports | ||
# Expose ports | ||
EXPOSE 43110 26552 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from Plugin import PluginManager | ||
|
||
@PluginManager.registerTo('ConfigPlugin') | ||
class ConfigPlugin: | ||
def createArguments(self): | ||
nameservers = [ | ||
'https://doh.securedns.eu/dns-query', | ||
|
||
'https://doh-de.blahdns.com/dns-query', | ||
'https://doh-jp.blahdns.com/dns-query', | ||
'https://doh-ch.blahdns.com/dns-query', | ||
|
||
'https://doh.dnswarden.com/uncensored', | ||
] | ||
|
||
group = self.parser.add_argument_group('DNS plugin') | ||
|
||
group.add_argument('--dns_nameservers', help='Nameservers for DNS plugin', default=nameservers, metavar='address', nargs='*') | ||
group.add_argument('--dns_configure', help='Configure resolver with system config for DNS plugin', action='store_true', default=False) | ||
|
||
return super(ConfigPlugin, self).createArguments() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from Config import config | ||
|
||
import logging | ||
import time | ||
import json | ||
import re | ||
import os | ||
|
||
log = logging.getLogger('DNSPlugin') | ||
|
||
class DNSResolver: | ||
loaded = False | ||
cache = {} | ||
|
||
def __init__(self, site_manager, nameservers, configure): | ||
self.site_manager = site_manager | ||
self.nameservers = nameservers | ||
self.configure = configure | ||
|
||
def load(self): | ||
if not self.loaded: | ||
self.loadModule() | ||
self.loadCache() | ||
|
||
self.resolver = dns.resolver.Resolver(configure=self.configure) | ||
|
||
if not self.configure: | ||
self.resolver.nameservers = self.nameservers | ||
|
||
self.loaded = True | ||
|
||
def loadModule(self): | ||
import dns.resolver | ||
import dnslink | ||
|
||
if config.tor == 'always': | ||
response = type('lamdbaobject', (object,), {})() | ||
response.flags = dns.flags.TC | ||
|
||
query = lambda *x, **y: response | ||
dns.query.udp = query | ||
|
||
globals()['dns'] = locals()['dns'] | ||
globals()['dnslink'] = locals()['dnslink'] | ||
filips123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def loadCache(self, path=os.path.join(config.data_dir, 'dns_cache.json')): | ||
if os.path.isfile(path): | ||
try: self.cache = json.load(open(path)) | ||
except json.decoder.JSONDecodeError: pass | ||
filips123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def saveCache(self, path=os.path.join(config.data_dir, 'dns_cache.json')): | ||
json.dump(self.cache, open(path, 'w'), indent=2) | ||
filips123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def isDomain(self, address): | ||
return re.match(r'(.*?)([A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)$', address) | ||
|
||
def resolveDomain(self, domain): | ||
if not self.loaded: | ||
self.load() | ||
|
||
domain = domain.lower() | ||
|
||
cache_entry = self.cache.get(domain) | ||
if cache_entry and time.time() < cache_entry['timeout']: | ||
log.info('cache: %s -> %s', domain, cache_entry['address']) | ||
return cache_entry['address'] | ||
|
||
try: | ||
resolver_record = dnslink.resolve(domain, protocol='zeronet', resolver=self.resolver)[0] | ||
resolver_entry = {'domain': domain, 'address': resolver_record.split('/', 2)[2]} | ||
except IndexError: | ||
resolver_entry = None | ||
|
||
resolver_error = None | ||
try: | ||
self.resolver.query(domain, 'TXT') | ||
except dns.resolver.NXDOMAIN: | ||
pass | ||
except dns.resolver.NoAnswer: | ||
pass | ||
except dns.exception.DNSException as err: | ||
resolver_error = err | ||
|
||
if resolver_entry and not resolver_error: | ||
log.info('resolver: %s -> %s', domain, resolver_entry['address']) | ||
self.saveInCache(resolver_entry) | ||
return resolver_entry['address'] | ||
|
||
if cache_entry and resolver_error: | ||
log.info('fallback: %s -> %s', domain, cache_entry['address']) | ||
self.extendInCache(cache_entry) | ||
return cache_entry['address'] | ||
|
||
def saveInCache(self, entry): | ||
entry['timeout'] = time.time() + 60 * 60 | ||
self.cache[entry['domain']] = entry | ||
|
||
self.saveCache() | ||
|
||
def extendInCache(self, entry): | ||
self.cache[entry['domain']]['timeout'] = time.time() + 60 * 15 | ||
|
||
self.saveCache() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from Config import config | ||
from Plugin import PluginManager | ||
|
||
from .DNSResolver import DNSResolver | ||
|
||
allow_reload = False | ||
|
||
@PluginManager.registerTo('SiteManager') | ||
class SiteManagerPlugin: | ||
_dns_resolver = None | ||
|
||
@property | ||
def dns_resolver(self): | ||
if not self._dns_resolver: | ||
nameservers = config.dns_nameservers | ||
configure = config.dns_configure | ||
|
||
self._dns_resolver = DNSResolver( | ||
site_manager=self, | ||
nameservers=nameservers, | ||
configure=configure, | ||
filips123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
return self._dns_resolver | ||
|
||
def load(self, *args, **kwargs): | ||
super(SiteManagerPlugin, self).load(*args, **kwargs) | ||
self.dns_resolver.load() | ||
|
||
def isDomain(self, address): | ||
return self.dns_resolver.isDomain(address) or super(SiteManagerPlugin, self).isDomain(address) | ||
|
||
def resolveDomain(self, domain): | ||
return self.dns_resolver.resolveDomain(domain) or super(SiteManagerPlugin, self).resolveDomain(domain) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from Plugin import PluginManager | ||
|
||
import re | ||
|
||
@PluginManager.registerTo('UiRequest') | ||
class UiRequestPlugin: | ||
def __init__(self, *args, **kwargs): | ||
from Site import SiteManager | ||
self.site_manager = SiteManager.site_manager | ||
|
||
super(UiRequestPlugin, self).__init__(*args, **kwargs) | ||
|
||
def actionSiteMedia(self, path, **kwargs): | ||
match = re.match(r'/media/(?P<address>[A-Za-z0-9-]+\.[A-Za-z0-9\.-]+)(?P<inner_path>/.*|$)', path) | ||
|
||
if match: | ||
domain = match.group('address') | ||
address = self.site_manager.dns_resolver.resolveDomain(domain) | ||
|
||
if address: | ||
path = '/media/' + address + match.group('inner_path') | ||
|
||
return super(UiRequestPlugin, self).actionSiteMedia(path, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import ConfigPlugin | ||
from . import UiRequestPlugin | ||
from . import SiteManagerPlugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "DNS", | ||
"description": "Support classic DNS as domain system.", | ||
"default": "enabled" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dnspython @ git+https://github.com/filips123/dnspython@dns-over-https | ||
filips123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dnslink>=1.0.2,<2.0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Zeroname", | ||
"description": "Support Namecoin as domain system.", | ||
"default": "enabled" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.