Exemple #1
0
 def filter_request(self, info: interceptor.Request) -> None:
     """Block the given request if necessary."""
     if self._is_blocked(request_url=info.request_url,
                         first_party_url=info.first_party_url):
         logger.debug("Request to {} blocked by host blocker.".format(
             info.request_url.host()))
         info.block()
Exemple #2
0
def filter_yt(info: interceptor.Request):
	"""Block the given request if necessary."""
	url = info.request_url
	if (url.host() == 'www.youtube.com' and
			url.path() == '/get_video_info' and
			'&adformat=' in url.query()):
		info.block()
Exemple #3
0
def ytfilter(info: interceptor.Request):
    url = info.request_url
    if(url.host() == "www.youtube.com"
       and url.path() == "/get_video_info"
       and "&adformat" in url.query()
       ):
        info.block()
Exemple #4
0
def filterYoutube(info: interceptor.Request):
    """Block the given request if necessary."""
    # and url.path() == "/get_video_info"

    url = info.request_url
    if "youtube.com" in url.host() and "adformat=" in url.query():
        info.block()
Exemple #5
0
 def filter_request(self, info: interceptor.Request) -> None:
     """Block the given request if necessary."""
     if self._is_blocked(request_url=info.request_url,
                         first_party_url=info.first_party_url):
         logger.info("Request to {} blocked by host blocker."
                     .format(info.request_url.host()))
         info.block()
Exemple #6
0
 def filter_request(self, info: interceptor.Request) -> None:
     """Block the given request if necessary."""
     if self._is_blocked(info.request_url, info.first_party_url, info.resource_type):
         logger.debug(
             "Request to %s blocked by ad blocker.",
             info.request_url.toDisplayString(),
         )
         info.block()
Exemple #7
0
def redirect(info: interceptor.Request):
    url = info.request_url
    if url.host() == 'www.reddit.com':
        url.setHost('old.reddit.com')
        try:
            info.redirect(url)
            message.info("Redirecting to " + url.toString())
        except RedirectException:
            pass
Exemple #8
0
def intercept_fn(info: interceptor.Request):
    url = info.request_url

    # Work around AWS urls when working on VPN
    url_host = url.host()
    if EMR_URL_REGEX.match(url_host):
        redir_url_host = _aws_dns_to_ip(url_host)
        url.setHost(redir_url_host)
        info.redirect(url)
Exemple #9
0
def int_fn(info: interceptor.Request):
    """Block the given request if necessary."""
    if (info.resource_type != interceptor.ResourceType.main_frame
            or info.request_url.scheme() in {"data", "blob"}):
        return
    url = info.request_url
    redir = REDIRECT_MAP.get(url.host())
    if redir is not None and redir(url) is not False:
        message.info("Redirecting to " + url.toString())
        info.redirect(url)
Exemple #10
0
def int_fn(info: interceptor.Request):
    """Redirect logic."""
    url = info.request_url
    if (info.resource_type != interceptor.ResourceType.main_frame) or (
        url.scheme() in {"data", "blob",}
    ):
        return
    host = url.host()
    if host[:4] == "www.":
        host = host[4:]
    redir = REDIRECT_MAP.get(host)
    if redir is not None and redir(url) is not False:
        message.info("Redirecting to " + url.toString())
        info.redirect(url)
Exemple #11
0
def filter_yt(info: interceptor.Request):
    """Block the given request if necessary."""
    url = info.request_url
    print("Received request " + url.scheme() + "://" + url.host() + "  " +
          url.query())
    if (url.host() == 'start.mpv'):
        activated = True
        info.block()
        host = url.host()
        query = url.query()
        q = parse_qs(query)
        #           os.system("terminal -e 'bash -c \""+q.url+" "+q.x+" "+q.y+" \"'")

        print('Intecepted MPV-start')
        print(q)
        #            os.system("mpv https://www.youtube.com/watch?v=lSjhdfRYNsA")
        subprocess.Popen([
            "/home/max/git/dotfiles/qutebrowser/start-mpv.sh", q['url'][0],
            str(int(q['right'][0]) - int(q['left'][0])),
            str(int(q['bottom'][0]) - int(q['top'][0])), q['left'][0],
            q['top'][0]
        ])
    if (url.host() == 'move.mpv'):
        info.block()
        host = url.host()
        query = url.query()
        q = parse_qs(query)
        #           os.system("terminal -e 'bash -c \""+q.url+" "+q.x+" "+q.y+" \"'")

        print('Intecepted MPV-move')
        print(q)
        #            os.system("mpv https://www.youtube.com/watch?v=lSjhdfRYNsA")
        subprocess.Popen([
            "/home/max/git/dotfiles/qutebrowser/move-mpv.sh", q['url'][0],
            str(int(q['right'][0]) - int(q['left'][0])),
            str(int(q['bottom'][0]) - int(q['top'][0])), q['left'][0],
            q['top'][0]
        ])
    if (url.host() == 'stop.mpv'):
        activated = False
        info.block()
        host = url.host()
        query = url.query()
        q = parse_qs(query)
        #           os.system("terminal -e 'bash -c \""+q.url+" "+q.x+" "+q.y+" \"'")

        print('Intecepted MPV-start')
        print(q)
        #            os.system("mpv https://www.youtube.com/watch?v=lSjhdfRYNsA")
        subprocess.Popen([
            "/home/max/git/dotfiles/qutebrowser/stop-mpv.sh", q['url'][0],
            str(int(q['right'][0]) - int(q['left'][0])),
            str(int(q['bottom'][0]) - int(q['top'][0])), q['left'][0],
            q['top'][0]
        ])
    if ('googlevideo.com' in url.host() and False):
        info.block()
Exemple #12
0
def jblock_intercept(info: interceptor.Request):
    global jblock_buckets
    global blocking_time
    global blocking_num
    global slowest_urls
    global psl
    global whitelist_urls
    global block_history
    # we may be making the first request.

    # We don't pre-initialize buckets as when starting qutebrowser over IPC,
    # config is run first. We only want to add overhead to the main instance.

    # TODO fix race condition which allows 'jblock_reload' to run multiple
    # times on startup Unfortunately doing this properly with locks results in
    # a large regression, but it should be possible to do this more correctly
    # without locks.
    if jblock_buckets is None or psl is None:
        # First time init
        jblock_reload(quiet=True)

    start_time = time.perf_counter()
    request_scheme = info.request_url.scheme()
    if info.is_blocked or request_scheme in {"data", "blob"}:
        # Don't do anything if we are already blocked or a internal url
        return

    request_host, context_host = info.request_url.host(
    ), info.first_party_url.host()

    if (whitelist_urls and any(
            map(functools.partial(operator.contains, whitelist_urls),
                tools.domain_variants(context_host)))):
        # This context is whitelisted, don't block.
        return

    first_party = psl.fp_domain(context_host) == psl.fp_domain(request_host)

    url = info.request_url.toString()
    if hasattr(info, 'resource_type') and info.resource_type is not None:
        resource_type = info.resource_type
    else:
        # On a backend that does not support resource_type. Technically this
        # is un-supported, as adblock lists need this to work properly.
        resource_type = interceptor.ResourceType.unknown
    options = {
        'domain': context_host,
        'script': resource_type == interceptor.ResourceType.script,
        'image': resource_type == interceptor.ResourceType.image,
        'stylesheet': resource_type == interceptor.ResourceType.stylesheet,
        'object': resource_type == interceptor.ResourceType.object,
        'subdocument': resource_type in {
            interceptor.ResourceType.sub_frame,
            interceptor.ResourceType.sub_resource
        },
        'document': resource_type == interceptor.ResourceType.main_frame,
        'third-party': not first_party,
    }
    if jblock_buckets.should_block(url, options):
        info.block()
        block_history.appendleft("BLOCKED:  " + url)
    else:
        block_history.appendleft("ALLOWED:  " + url)
    time_change = time.perf_counter() - start_time
    blocking_time += time_change
    blocking_num += 1
    heapq.heappush(slowest_urls, (time_change, url))
    if len(slowest_urls) > JBLOCK_SLOWEST_URL_WINDOW:
        heapq.heappop(slowest_urls)
Exemple #13
0
def filter_yt(info: interceptor.Request):
    url = info.request_url
    if url.host() == 'www.youtube.com' and url.path() == '/get_video_info' and '&adformat=' in url.query():
        info.block()
Exemple #14
0
def filter_yt(info: interceptor.Request):
    #Block the given request if necessary.
    url = info.request_url
    if (url.host() == "www.youtube.com" and url.path() == "/get_video_info"
            and "&adformat=" in url.query()):
        info.block()
Exemple #15
0
def jblock_intercept(info: interceptor.Request):
    global jblock_buckets
    global blocking_time
    global blocking_num
    global slowest_urls
    global psl
    global whitelist_urls
    global block_history
    # we may be making the first request.

    # We don't pre-initialize buckets as when starting qutebrowser over IPC, config is run first.
    # We only want to add overhead to the main instance.
    if jblock_buckets is None:
        # First time init
        jblock_reload(quiet=True)

    start_time = time.perf_counter()
    request_scheme = info.request_url.scheme()
    if info.is_blocked or request_scheme in {"data", "blob"}:
        # Don't do anything if we are already blocked or a internal url
        return

    request_host, context_host = info.request_url.host(
    ), info.first_party_url.host()

    if whitelist_urls and any(
            map(
                functools.partial(operator.contains, whitelist_urls),
                tools.domain_variants(context_host),
            )):
        # This context is whitelisted, don't block.
        return

    first_party = psl.fp_domain(context_host) == psl.fp_domain(request_host)

    url = info.request_url.toString()
    if hasattr(info, "resource_type") and info.resource_type is not None:
        resource_type = info.resource_type
    else:
        # On a backend that does not support resource_type. Technically this
        # is un-supported, as adblock lists need this to work properly.
        resource_type = interceptor.ResourceType.unknown
    options = {
        "domain": context_host,
        "script": resource_type == interceptor.ResourceType.script,
        "image": resource_type == interceptor.ResourceType.image,
        "stylesheet": resource_type == interceptor.ResourceType.stylesheet,
        "object": resource_type == interceptor.ResourceType.object,
        "subdocument": resource_type in {
            interceptor.ResourceType.sub_frame,
            interceptor.ResourceType.sub_resource
        },
        "document": resource_type == interceptor.ResourceType.main_frame,
        "third-party": not first_party,
    }
    if jblock_buckets.should_block(url, options):
        info.block()
        block_history.appendleft("%s %s" % ("BLOCKED: ", url))
    else:
        block_history.appendleft("%s %s" % ("ALLOWED: ", url))
    time_change = time.perf_counter() - start_time
    blocking_time += time_change
    blocking_num += 1
    heapq.heappush(slowest_urls, (time_change, url))
    if len(slowest_urls) > JBLOCK_SLOWEST_URL_WINDOW:
        heapq.heappop(slowest_urls)
Exemple #16
0
def filter_youtube(info: interceptor.Request):
    """Block request to get Advt."""
    url = info.request_url
    if (url.host() == 'www.youtube.com' and url.path() == '/get_video_info'
            and '&adformat=' in url.query()):
        info.block()