restructing
This commit is contained in:
72
lib/mozilla.py
Normal file
72
lib/mozilla.py
Normal file
@@ -0,0 +1,72 @@
|
||||
#access cookies from firefox:
|
||||
#copy (because locked): cp .mozilla/firefox/imibizoh.default/cookies.sqlite cookies.sqlite
|
||||
#Select value from moz_cookies where host like '%indeed%'
|
||||
import webbrowser
|
||||
import tempfile
|
||||
import os
|
||||
import sqlite3
|
||||
import shutil
|
||||
from time import sleep
|
||||
import manipulateString as ms
|
||||
DEBUG = True
|
||||
def log(*s):
|
||||
if DEBUG:
|
||||
print(s)
|
||||
|
||||
def findDefaultProfile(path):
|
||||
target = ''
|
||||
dirlist = os.listdir(path)
|
||||
for directory in dirlist:
|
||||
posDot = ms.skipAfterChar(directory,'.')
|
||||
stringParse = ms.dropBeforePos(directory,posDot)
|
||||
log(stringParse)
|
||||
if stringParse == "default":
|
||||
target = directory
|
||||
break;
|
||||
if target == '':
|
||||
return -1
|
||||
else:
|
||||
return target
|
||||
|
||||
def getCookiesFromBrowser(url):
|
||||
homePath = os.path.expanduser('~')
|
||||
cookiePath = homePath + "/.mozilla/firefox/" + findDefaultProfile(homePath + "/.mozilla/firefox/") + "/cookies.sqlite"
|
||||
tmpPath = "/tmp/cookies.sqlite"
|
||||
DBFILE = "../db/sqlite3.db"
|
||||
winFirefoxPath = f"""C:\\Program Files\\Mozilla Firefox\\firefox.exe"""
|
||||
wintTmpPath = tempfile.gettempdir()
|
||||
#workaround for loked database
|
||||
tries=0
|
||||
cookie = ''
|
||||
rows = [0]
|
||||
while(cookie == '' and tries < 2):
|
||||
tries+=1
|
||||
if os.name == 'posix':
|
||||
shutil.copyfile(cookiePath,tmpPath)
|
||||
elif os.name == 'nt':
|
||||
appdata = os.getenv('APPDATA')
|
||||
winCookiePath = appdata + "\\Mozilla\\Firefox\\Profiles\\" + profile + "cookies.sqlite"
|
||||
shutil.copyfile(winCookiePath,wintTmpPath)
|
||||
|
||||
with sqlite3.connect(tmpPath) as connection:
|
||||
cmd_read_cookies = f"""SELECT name,value FROM moz_cookies WHERE host like ?;"""
|
||||
print(cmd_read_cookies)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(cmd_read_cookies,(ms.urlToDomain(url),))
|
||||
while len(rows)!=0:
|
||||
rows = cursor.fetchmany(25)
|
||||
for row in rows:
|
||||
print("row:",row)
|
||||
cookie = cookie + row[0] + '=' + row[1]
|
||||
cookie += ";"
|
||||
|
||||
print("Cookies:",cookie)
|
||||
if cookie == '':
|
||||
if os.name == 'posix':
|
||||
webbrowser.register("firefox",None,webbrowser.BackgroundBrowser("firefox"))
|
||||
webbrowser.get('firefox').open(url)
|
||||
elif os.name == 'nt':
|
||||
webbrowser.register("firefox",None,webbrowser.BackgroundBrowser(winFirefoxPath))
|
||||
webbrowser.get('firefox').open(url)
|
||||
sleep(1)
|
||||
return cookie
|
||||
Reference in New Issue
Block a user