示例#1
0
def send_mass_mail(target_log, dry_run):
    username_site_pairs = []
    contact_list = []
    with open(target_log) as t_l:
        for line in t_l:
            contact_list.append(line.strip('\n'))

    vhosts = get_vhosts()
    for vhost_url in vhosts.keys():
        site = 'http://' + vhost_url
        if site in contact_list:
            username_site_pairs.append((vhosts[vhost_url]['username'],
                                        vhost_url))

    # Sanity check
    assert len(username_site_pairs) == len(contact_list)

    if not dry_run:
        print('Emailing...')
        for user, site in username_site_pairs:
            name = search.user_attrs(user)['cn'][0]
            try:
                print(user)
                mail.send_mail_user(user, subject.format(user=user),
                                    email_body.format(user=user, name=name, site=site))
            except Exception as e:
                print((name, user, site, e))
    else:
        print("Actual run would've emailed the following:")
        for user, site in username_site_pairs:
            print(user)
示例#2
0
def check_vhosting():
    with open(missing_img, 'w') as m_i, open(missing_disc, 'w') as m_d,\
            open(missing_both, 'w') as m_b, open(errors, 'w') as error_file:
        vhosts = get_vhosts()
        vhost_urls = []
        for vhost_url in vhosts.keys():
            if any(is_special(url) for url in {vhost_url} | set(vhosts[vhost_url]['aliases'])):
                continue
            vhost_urls.append('http://' + vhost_url + '\n')
        # For log niceness
        vhost_urls.sort()
        for site in vhost_urls:
            try:
                site_opened = req.urlopen(site, timeout=10)
                site_html = site_opened.readall().decode('utf-8')
                counter = False
                if not disclaimer_pattern.search(site_html):
                    counter = True
                    m_d.writelines(site)
                # Check if they have any OCF banner in their images
                img_urls = {img_url if img_url.startswith('http') else site + '/' + img_url for img_url in
                            img_regex.findall(site_html)}
                img_hashes = {hashlib.md5(requests.get(img_url).content).hexdigest() for img_url in img_urls}
                if not banner_hashes & img_hashes:
                    m_i.writelines(site)
                    if counter:
                        m_b.writelines(site)
            except Exception as e:
                error_file.writelines(site)
                error_file.writelines(str(e) + '\n\n')
示例#3
0
def test_web_vhosts():
    web_vhosts = get_vhosts()

    # Make sure we're actually getting some vhosts back
    assert(any(web_vhosts))

    # Ensure the 'staff' and 'ggroup' users have some vhosts. These are likely
    # to always stick around as they are owned by the OCF and there are
    # multiple of them present for each user
    assert(has_vhost('staff'))
    assert(has_vhost('ggroup'))

    # Check that dev-vhost.o.b.e exists as a web vhost (this is used for
    # testing by OCF staff, so it's likely to stick around). It should also
    # have a dev-host-alias.o.b.e alias present
    assert('dev-vhost.ocf.berkeley.edu' in web_vhosts)
    aliases = web_vhosts['dev-vhost.ocf.berkeley.edu']['aliases']
    assert('dev-vhost-alias.ocf.berkeley.edu' in aliases)

    flags = [vhost['flags'] for vhost in web_vhosts.values() if vhost['flags']]
    # Ensure that there's no nossl flags present, we only support SSL vhosts
    # as of rt#5347.
    assert(not any([flag_list for flag_list in flags if 'nossl' in flag_list]))
    # hsts flags are still allowed (but may become the default sometime and be
    # removed)
    assert(any([flag_list for flag_list in flags if 'hsts' in flag_list]))
示例#4
0
def subdomain_lookup(bot, msg):
    subdomain = msg.match.group(1)
    user = get_vhosts().get(subdomain)
    if user is None:
        msg.respond('A group account does not exist with this subdomain.')
        return
    user = user.get('username')
    msg.respond('The group account name corresponding with ' + subdomain +
                ' is: ' + user,
                ping=False)
示例#5
0
def group_lookup(bot, msg):
    user = msg.match.group(1)
    vhosts = get_vhosts()
    subdomain = None
    for vhost in vhosts.items():
        if user == vhost[1]['username']:
            subdomain = vhost[0]
    if subdomain is None:
        msg.respond('A subdomain does not exist with this group account.')
        return
    msg.respond('The subdomain name corresponding with ' + user + ' is: ' +
                subdomain,
                ping=False)
示例#6
0
def check_vhosting():
    with open(missing_img, 'w') as m_i, open(missing_disc, 'w') as m_d,\
            open(missing_both, 'w') as m_b, open(errors, 'w') as error_file:
        vhosts = get_vhosts()
        vhost_urls = []
        for vhost_url in vhosts.keys():
            if any(
                    is_special(url) for url in {vhost_url}
                    | set(vhosts[vhost_url]['aliases'])):
                continue
            vhost_urls.append('http://' + vhost_url + '\n')
        # For log niceness
        vhost_urls.sort()
        for site in vhost_urls:
            try:
                site_opened = req.urlopen(site, timeout=10)
                site_html = site_opened.readall().decode('utf-8')
                counter = False
                if not disclaimer_pattern.search(site_html):
                    counter = True
                    m_d.writelines(site)
                # Check if they have any OCF banner in their images
                img_urls = {
                    img_url if img_url.startswith('http') else site + '/' +
                    img_url
                    for img_url in img_regex.findall(site_html)
                }
                img_hashes = {
                    hashlib.md5(requests.get(img_url).content).hexdigest()
                    for img_url in img_urls
                }
                if not banner_hashes & img_hashes:
                    m_i.writelines(site)
                    if counter:
                        m_b.writelines(site)
            except Exception as e:
                error_file.writelines(site)
                error_file.writelines(str(e) + '\n\n')
示例#7
0
 def test_proper_parse(self, mock_get_vhosts_db):
     assert get_vhosts() == VHOSTS_EXAMPLE_PARSED
示例#8
0
 def test_proper_parse(self, mock_get_vhosts_db):
     assert get_vhosts() == VHOSTS_EXAMPLE_PARSED