'Alert the user when the configured target is set to a site which will
301 redirect all requests to https://
:see: https://github.com/andresriancho/w3af/issues/14976
:return: True if the site returns 301 for all resources. Also an Info
instance is saved to the KB in order to alert the user.'

def alert_if_target_is_301_all(self):

    site_does_redirect = False
    msg = 'The    configured    target    domain    redirects    all    HTTP    requests    to    a    different    location.    The    most    common    scenarios    are:\n\n                *    HTTP    redirect    to    HTTPS\n                *    domain.com    redirect    to    www.domain.com\n\nWhile    the    scan    engine    can    identify    URLs    and    vulnerabilities    using    the    current    configuration    it    might    be    wise    to    start    a    new    scan    setting    the    target    URL    to    the    redirect    target.'
    targets = cf.cf.get('targets')
    for url in targets:
        try:
            http_response = self._w3af_core.uri_opener.GET(url, cache=False)
        except ScanMustStopByUserRequest:
            raise
        except Exception as e:
            emsg = 'Exception    found    during    alert_if_target_is_301_all():    "%s"'
            emsg %= e
            om.out.debug(emsg)
            raise ScanMustStopException(emsg)
        else:
            if (300 <= http_response.get_code() <= 399):
                lower_headers = http_response.get_lower_case_headers()
                redirect_url = None
                for header_name in ('location', 'uri'):
                    if (header_name in lower_headers):
                        header_value = lower_headers[header_name]
                        header_value = header_value.strip()
                        try:
                            redirect_url = URL(header_value)
                        except ValueError:
                            continue
                if (not redirect_url):
                    continue
                target_proto = url.get_protocol()
                redirect_proto = redirect_url.get_protocol()
                if (target_proto != redirect_proto):
                    site_does_redirect = True
                    break
                target_domain = url.get_domain()
                redirect_domain = redirect_url.get_domain()
                if (target_domain != redirect_domain):
                    site_does_redirect = True
                    break
    if site_does_redirect:
        name = 'Target    redirect'
        info = Info(name, msg, http_response.id, name)
        info.set_url(url)
        info.add_to_highlight(http_response.get_redir_url().url_string)
        kb.kb.append_uniq('core', 'core', info)
        om.out.report_finding(info)
    return site_does_redirect
