# along with this program. If not, see <https://www.gnu.org/licenses/>.
import logging
-from urllib.parse import urlparse
-import validators
-from fba import csrf
+from urllib.parse import urlparse
from fba.helpers import config
from fba.helpers import domain as domain_helper
+from fba.http import csrf
from fba.http import network
from fba.models import instances
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
-def fetch(domain: str, path: str = None, nodeinfo_url: str = None) -> dict:
- logger.debug("domain='%s',path='%s',nodeinfo_url='%s' - CALLED!", domain, path, nodeinfo_url)
+def fetch(domain: str, path: str = None, update_mode: bool = True) -> dict:
+ logger.debug("domain='%s',path='%s',update_mode='%s' - CALLED!", domain, path, update_mode)
domain_helper.raise_on(domain)
if not isinstance(path, str) and path is not None:
raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'")
- elif not isinstance(nodeinfo_url, str) and nodeinfo_url is not None:
- raise ValueError(f"Parameter nodeinfo_url[]='{type(nodeinfo_url)}' is not of type 'str'")
-
- logger.debug("nodeinfo_url='%s'", nodeinfo_url)
- is_url = nodeinfo_url is not None and not nodeinfo_url.startswith("/") and validators.url(nodeinfo_url)
+ elif not isinstance(update_mode, bool) and update_mode is not None:
+ raise ValueError(f"Parameter update_mode[]='{type(update_mode)}' is not of type 'bool'")
- logger.debug("is_url='%s'", is_url)
- if not is_url:
+ if path is None and update_mode:
logger.debug("Fetching well-known nodeinfo from domain='%s' ...", domain)
data = fetch_wellknown_nodeinfo(domain)
https_url = f"https://{domain}{str(path) if path is not None else '/'}"
logger.debug("path[%s]='%s',request='%s',http_url='%s',https_url='%s'", type(path), path, request, http_url, https_url)
- if (path is None and nodeinfo_url is None) or path in [request, http_url, https_url] or (is_url and nodeinfo_url.endswith(request)):
+ if path is None or path in [request, http_url, https_url]:
logger.debug("Fetching request='%s' from domain='%s' ...", request, domain)
data = network.get_json_api(
domain,
if "error_message" not in data and "json" in data:
logger.debug("Success: request='%s' - Setting detection_mode=STATIC_CHECK ...", request)
instances.set_last_nodeinfo(domain)
- instances.set_detection_mode(domain, "STATIC_CHECK")
- instances.set_nodeinfo_url(domain, "https://{domain}{request}")
+ if update_mode:
+ instances.set_detection_mode(domain, "STATIC_CHECK")
+ instances.set_nodeinfo_url(domain, "https://{domain}{request}")
break
logger.warning("Failed fetching nodeinfo from domain='%s',status_code='%s',error_message='%s'", domain, data['status_code'], data['error_message'])
# Default is that 'href' has a complete URL, but some hosts don't send that
logger.debug("link[rel]='%s' matches niid='%s'", link["rel"], niid)
- url = link["href"]
+ url = link["href"].lower()
components = urlparse(url)
logger.debug("components[%s]='%s'", type(components), components)
url = f"{components.scheme}://{domain}{components.path}"
components = urlparse(url)
- logger.debug("components.netloc[]='%s'", type(components.netloc))
- if not domain_helper.is_wanted(components.netloc):
- logger.debug("components.netloc='%s' is not wanted - SKIPPED!", components.netloc)
+ domain2 = components.netloc.lower().split(":")[0]
+ logger.debug("domain2='%s'", domain2)
+ if not domain_helper.is_wanted(domain2):
+ logger.debug("domain2='%s' is not wanted - SKIPPED!", domain2)
continue
logger.debug("Fetching nodeinfo from url='%s' ...", url)