Example #1
0
def remove_spammer(store, name, confirm=False):
    user = store.get_user(name)
    if not user:
        sys.exit('user %r does not exist' % name)

    cursor = st.get_cursor()
    cursor.execute(
        """
       select distinct(submitted_from)
        from journals
        where submitted_by = %s
    """, (name, ))
    print 'IP addresses of spammers to possibly block:'
    for (ip, ) in cursor.fetchall():
        print '  ', ip

    for p in store.get_user_packages(name):
        print p['package_name']
        if confirm:
            store.remove_package(p['package_name'])

    if confirm:
        cursor.execute(
            "update accounts_user set password='******' where name=%s",
            (name, ))
Example #2
0
def nuke_nested_lists(store):
    c = store.get_cursor()
    c.execute("""select name, version, summary from releases
        where summary like '%nested lists%'""")
    hits = {}
    for name, version, summary in c.fetchall():
        for f in store.list_files(name, version):
            path = store.gen_file_path(f['python_version'], name, f['filename'])
            if path.endswith('.zip'):
                z = zipfile.ZipFile(path)
                for i in z.infolist():
                    if not i.filename.endswith('.py'): continue
                    if 'def print_lol' in z.read(i.filename):
                        hits[name] = summary
            elif path.endswith('.tar.gz'):
                z = gzip.GzipFile(path)
                t = tarfile.TarFile(fileobj=z)
                for i in t.getmembers():
                    if not i.name.endswith('.py'): continue
                    f = t.extractfile(i.name)
                    if 'def print_lol' in f.read():
                        hits[name] = summary
    for name in hits:
        store.remove_package(name)
        print '%s: %s' % (name, hits[name])
    print 'removed %d packages' % len(hits)
Example #3
0
def nuke_nested_lists(store, confirm=False):
    c = store.get_cursor()
    c.execute("""select name, version, summary from releases
        where lower(name) like '%nester%' or
        lower(summary) like '%nested lists%' or
        lower(summary) like '%geschachtelter listen%'""")
    hits = {}
    for name, version, summary in c.fetchall():
        if "printer of nested lists" in summary:
            hits[name] = summary
            continue
        if "Einfache Ausgabe geschachtelter Listen" in summary:
            hits[name] = summary
            continue
        for f in store.list_files(name, version):
            path = f['path']
            key = store.package_bucket.get_key(path)
            if key is None:
                print "PACKAGE %s FILE %s MISSING" % (name, path)
                continue
            contents = StringIO.StringIO(key.read())
            if path.endswith('.zip'):
                z = zipfile.ZipFile(contents)
                for i in z.infolist():
                    if not i.filename.endswith('.py'):
                        continue
                    src = z.read(i.filename)
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
            elif path.endswith('.tar.gz'):
                z = gzip.GzipFile(path, fileobj=contents)
                t = tarfile.TarFile(fileobj=z)
                for i in t.getmembers():
                    if not i.name.endswith('.py'): continue
                    f = t.extractfile(i.name)
                    src = f.read()
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
    for name in hits:
        if confirm:
            store.remove_package(name)
        print '%s: %s' % (name, hits[name])
    if confirm:
        print 'removed %d packages' % len(hits)
    else:
        print 'WOULD HAVE removed %d packages' % len(hits)
Example #4
0
def nuke_nested_lists(store, confirm=False):
    c = store.get_cursor()
    c.execute("""select name, version, summary from releases
        where lower(name) like '%nester%' or
        lower(summary) like '%nested lists%' or
        lower(summary) like '%geschachtelter listen%'""")
    hits = {}
    for name, version, summary in c.fetchall():
        if "printer of nested lists" in summary:
            hits[name] = summary
            continue
        if "Einfache Ausgabe geschachtelter Listen" in summary:
            hits[name] = summary
            continue
        for f in store.list_files(name, version):
            path = f['path']
            key = store.package_bucket.get_key(path)
            if key is None:
                print "PACKAGE %s FILE %s MISSING" % (name, path)
                continue
            contents = StringIO.StringIO(key.read())
            if path.endswith('.zip'):
                z = zipfile.ZipFile(contents)
                for i in z.infolist():
                    if not i.filename.endswith('.py'):
                        continue
                    src = z.read(i.filename)
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
            elif path.endswith('.tar.gz'):
                z = gzip.GzipFile(path, fileobj=contents)
                t = tarfile.TarFile(fileobj=z)
                for i in t.getmembers():
                    if not i.name.endswith('.py'): continue
                    f = t.extractfile(i.name)
                    src = f.read()
                    if 'def print_lol' in src or 'def print_lvl' in src:
                        hits[name] = summary
    for name in hits:
        if confirm:
            store.remove_package(name)
        print '%s: %s' % (name, hits[name])
    if confirm:
        print 'removed %d packages' % len(hits)
    else:
        print 'WOULD HAVE removed %d packages' % len(hits)
Example #5
0
def remove_spam(store, namepat, confirm=False):
    '''Remove packages that match namepat (SQL wildcards).

    The packages will be removed. Additionally the user that created them will
    have their password set to 'spammer'.

    Pass the additional command-line argument "confirm" to perform the
    deletions and modifications.

    This will additionally display the IP address(es) of the spam submissions.
    '''
    assert confirm in (False, 'confirm')
    cursor = st.get_cursor()
    cursor.execute(
        """
       select packages.name, submitted_date, submitted_by, submitted_from
        from packages, journals
        where packages.name LIKE %s
          and packages.name = journals.name
          and action = 'create'
    """, (namepat, ))

    if not confirm:
        print 'NOT taking any action; add "confirm" to the command line to act'

    users = set()
    ips = set()
    for name, date, by, ip in cursor.fetchall():
        ips.add(ip)
        users.add(by)
        print 'delete', name, 'submitted on', date
        if confirm:
            store.remove_package(name)

    print 'IP addresses of spammers to possibly block:'
    for ip in ips:
        print '  ', ip

    for user in users:
        print 'disable user', user
        if confirm:
            cursor.execute(
                "update accounts_user set password='******' where name=%s",
                (user, ))
Example #6
0
def remove_spam(store, namepat, confirm=False):
    '''Remove packages that match namepat (SQL wildcards).

    The packages will be removed. Additionally the user that created them will
    have their password set to 'spammer'.

    Pass the additional command-line argument "confirm" to perform the
    deletions and modifications.

    This will additionally display the IP address(es) of the spam submissions.
    '''
    assert confirm in (False, 'confirm')
    cursor = st.get_cursor()
    cursor.execute("""
       select packages.name, submitted_date, submitted_by, submitted_from
        from packages, journals
        where packages.name LIKE %s
          and packages.name = journals.name
          and action = 'create'
    """, (namepat,))

    if not confirm:
        print 'NOT taking any action; add "confirm" to the command line to act'

    users = set()
    ips = set()
    for name, date, by, ip in cursor.fetchall():
        ips.add(ip)
        users.add(by)
        print 'delete', name, 'submitted on', date
        if confirm:
            store.remove_package(name)

    print 'IP addresses of spammers to possibly block:'
    for ip in ips:
        print '  ', ip

    for user in users:
        print 'disable user', user
        if confirm:
            cursor.execute("update accounts_user set password='******' where name=%s",
                (user,))
Example #7
0
def remove_spammer(store, name, confirm=False):
    user = store.get_user(name)
    if not user:
        sys.exit('user %r does not exist' % name)

    cursor = st.get_cursor()
    cursor.execute("""
       select distinct(submitted_from)
        from journals
        where submitted_by = %s
    """, (name,))
    print 'IP addresses of spammers to possibly block:'
    for (ip,) in cursor.fetchall():
        print '  ', ip

    for p in store.get_user_packages(name):
        print p['package_name']
        if confirm:
            store.remove_package(p['package_name'])

    if confirm:
        cursor.execute("update accounts_user set password='******' where name=%s",
             (name,))
Example #8
0
def remove_package(store, name):
    ''' Remove a package from the database
    '''
    store.remove_package(name)
    print 'done'