Exemple #1
0
def get_cookies_from_ff(db_filename):
    con = sqlite.connect(db_filename)
    con.execute("pragma journal_mode=WAL")
    cur = con.cursor()
    cur.execute(
            "select host, path, isSecure, expiry, name, value from moz_cookies"
            )
    container = []
    while True:
        try:
            row = cur.fetchone()
        except:
            continue
        if not row:
            break
        if not row[4].startswith('chkSlider'):  # FIXME: this is a dirty fix
            container.append(row)
    con.close()
    ftstr = ["FALSE", "TRUE"]
    s = StringIO()
    s.write("""\
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file!  Do not edit.
""")
    for item in container:
        v = "%s\t%s\t%s\t%s\t%s\t%s\t%s\n" % (
            item[0], ftstr[item[0].startswith('.')], item[1],
            ftstr[item[2]], item[3], item[4], item[5])
        s.write(v)
    s.seek(0)
    cookie_jar = MozillaCookieJar()
    cookie_jar._really_load(s, '', True, True)
    return cookie_jar