2015-07-12 20:36:46 +02:00
|
|
|
import logging
|
|
|
|
import re
|
2016-11-19 10:56:19 +01:00
|
|
|
import time
|
2015-07-12 20:36:46 +02:00
|
|
|
|
2016-03-22 17:12:22 +01:00
|
|
|
from Config import config
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
from Plugin import PluginManager
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
allow_reload = False # No reload supported
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
|
|
|
log = logging.getLogger("ZeronamePlugin")
|
|
|
|
|
|
|
|
|
|
|
|
@PluginManager.registerTo("SiteManager")
|
|
|
|
class SiteManagerPlugin(object):
|
2015-07-12 20:36:46 +02:00
|
|
|
site_zeroname = None
|
2016-11-19 10:56:19 +01:00
|
|
|
db_domains = None
|
|
|
|
db_domains_modified = None
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2016-09-06 14:52:55 +02:00
|
|
|
def load(self, *args, **kwargs):
|
|
|
|
super(SiteManagerPlugin, self).load(*args, **kwargs)
|
2016-03-22 17:12:22 +01:00
|
|
|
if not self.get(config.bit_resolver):
|
|
|
|
self.need(config.bit_resolver) # Need ZeroName site
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Checks if its a valid address
|
|
|
|
def isAddress(self, address):
|
|
|
|
if self.isDomain(address):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return super(SiteManagerPlugin, self).isAddress(address)
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Return: True if the address is domain
|
|
|
|
def isDomain(self, address):
|
2017-06-13 14:19:43 +02:00
|
|
|
return re.match("(.*?)([A-Za-z0-9_-]+\.bit)$", address)
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Resolve domain
|
|
|
|
# Return: The address or None
|
|
|
|
def resolveDomain(self, domain):
|
|
|
|
domain = domain.lower()
|
|
|
|
if not self.site_zeroname:
|
2016-03-22 17:12:22 +01:00
|
|
|
self.site_zeroname = self.need(config.bit_resolver)
|
2016-11-19 10:56:19 +01:00
|
|
|
|
|
|
|
site_zeroname_modified = self.site_zeroname.content_manager.contents.get("content.json", {}).get("modified", 0)
|
|
|
|
if not self.db_domains or self.db_domains_modified != site_zeroname_modified:
|
|
|
|
self.site_zeroname.needFile("data/names.json", priority=10)
|
|
|
|
s = time.time()
|
|
|
|
self.db_domains = self.site_zeroname.storage.loadJson("data/names.json")
|
|
|
|
log.debug(
|
|
|
|
"Domain db with %s entries loaded in %.3fs (modification: %s -> %s)" %
|
|
|
|
(len(self.db_domains), time.time() - s, self.db_domains_modified, site_zeroname_modified)
|
|
|
|
)
|
|
|
|
self.db_domains_modified = site_zeroname_modified
|
|
|
|
return self.db_domains.get(domain)
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Return or create site and start download site files
|
|
|
|
# Return: Site or None if dns resolve failed
|
2017-11-30 19:38:56 +01:00
|
|
|
def need(self, address, *args, **kwargs):
|
2015-07-12 20:36:46 +02:00
|
|
|
if self.isDomain(address): # Its looks like a domain
|
|
|
|
address_resolved = self.resolveDomain(address)
|
|
|
|
if address_resolved:
|
|
|
|
address = address_resolved
|
|
|
|
else:
|
|
|
|
return None
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2017-11-30 19:38:56 +01:00
|
|
|
return super(SiteManagerPlugin, self).need(address, *args, **kwargs)
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
# Return: Site object or None if not found
|
|
|
|
def get(self, address):
|
2018-04-03 14:40:47 +02:00
|
|
|
if not self.loaded: # Not loaded yet
|
2015-07-12 20:36:46 +02:00
|
|
|
self.load()
|
|
|
|
if self.isDomain(address): # Its looks like a domain
|
|
|
|
address_resolved = self.resolveDomain(address)
|
|
|
|
if address_resolved: # Domain found
|
|
|
|
site = self.sites.get(address_resolved)
|
|
|
|
if site:
|
|
|
|
site_domain = site.settings.get("domain")
|
|
|
|
if site_domain != address:
|
|
|
|
site.settings["domain"] = address
|
|
|
|
else: # Domain not found
|
|
|
|
site = self.sites.get(address)
|
version 0.2.8, Namecoin domains using internal resolver site, --disable_zeromq option to skip backward compatiblity layer and save some memory, connectionserver firstchar error fixes, missing unpacker crash fix, sitemanager class to allow extensions, add loaded plugin list to websocket api, faster content publishing, mark updating file as bad, remove coppersurfer tracker add eddie4, internal server error with error displaying, allow site domains in UiRequest, better progress bar, wait for siteinfo before before using localstorage, csslater hide only if opacity is 0
2015-03-30 23:44:29 +02:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
else: # Access by site address
|
|
|
|
site = self.sites.get(address)
|
|
|
|
return site
|