Browse Source

added support for safari, fixed some indentation

pull/3/head
rscmbbng 11 years ago
parent
commit
0eaf6bc4db
  1. 57
      main.py

57
main.py

@ -75,6 +75,7 @@ class bc(object):
f_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Firefox/Profiles') f_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Firefox/Profiles')
c_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Google/Chrome/Default/History') c_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Google/Chrome/Default/History')
chromium_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Chromium/Default/History') chromium_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Chromium/Default/History')
s_osx = os.path.join(os.path.expanduser('~'), 'Library/Safari/History.plist')
try: try:
if os.path.exists(f_osx): if os.path.exists(f_osx):
if len(os.listdir(f_osx)) > 2: if len(os.listdir(f_osx)) > 2:
@ -87,15 +88,13 @@ class bc(object):
pass pass
latest_subdir = max(all_subdirs, key=os.path.getmtime) latest_subdir = max(all_subdirs, key=os.path.getmtime)
osx_profile = os.path.join(f_osx, latest_subdir) osx_profile = os.path.join(f_osx, latest_subdir)
osx_self.browser_path = os.path.join(osx_profile, 'places.sqlite') self.browser_path = os.path.join(osx_profile, 'places.sqlite')
self.browser_path = osx_self.browser_path
else: else:
for folder in os.listdir(f_osx): for folder in os.listdir(f_osx):
if folder.endswith('.default'): if folder.endswith('.default'):
osx_default = os.path.join(f_osx, folder) osx_default = os.path.join(f_osx, folder)
osx_self.browser_path = os.path.join(osx_default, 'places.sqlite') self.browser_path = os.path.join(osx_default, 'places.sqlite')
print "Setting:", osx_self.browser_path, "as history file" print "Setting:", self.browser_path, "as history file"
self.browser_path = osx_self.browser_path
self.browser = "F" self.browser = "F"
elif os.path.exists(c_osx): elif os.path.exists(c_osx):
self.browser = "C" self.browser = "C"
@ -103,8 +102,11 @@ class bc(object):
elif os.path.exists(chromium_osx): elif os.path.exists(chromium_osx):
self.browser = "CHROMIUM" self.browser = "CHROMIUM"
self.browser_path = chromium_osx self.browser_path = chromium_osx
elif os.path.exists(s_osx):
self.browser = "S"
self.browser_path = s_osx
except: except:
print "Warning: No Firefox, Chrome or Chromium installed." print "Warning: None of the currently supported browsers (Firefox, Chrome, Chromium, Safari) are installed."
elif sys.platform.startswith('linux'): elif sys.platform.startswith('linux'):
f_lin = os.path.join(os.path.expanduser('~'), '.mozilla/firefox/') #add the next folder f_lin = os.path.join(os.path.expanduser('~'), '.mozilla/firefox/') #add the next folder
@ -133,27 +135,45 @@ class bc(object):
conn = sqlite3.connect(self.browser_path) conn = sqlite3.connect(self.browser_path)
c = conn.cursor() c = conn.cursor()
c.execute('select url, last_visit_date from moz_places ORDER BY last_visit_date DESC') c.execute('select url, last_visit_date from moz_places ORDER BY last_visit_date DESC')
url = c.fetchone()
elif self.browser == "C" or self.browser == "CHROMIUM": #Chrome/Chromium history database elif self.browser == "C" or self.browser == "CHROMIUM": #Chrome/Chromium history database
#Hack that makes a copy of the locked database to access it while Chrome is running.
#Removes the copied database afterwards
import filecmp import filecmp
a = self.browser_path + 'Copy' a = self.browser_path + 'Copy'
if os.path.exists(a): if os.path.exists(a):
if filecmp.cmp(self.browser_path, a) == False: if filecmp.cmp(self.browser_path, a) == False:
os.system('rm ' + a) os.system('rm "' + a+'"')
os.system('cp "' + self.browser_path + '" "' + a + '"') os.system('cp "' + self.browser_path + '" "' + a + '"')
else: else:
os.system('cp "' + self.browser_path + '" "' + a + '"') os.system('cp "' + self.browser_path + '" "' + a + '"')
conn = sqlite3.connect(a) conn = sqlite3.connect(a)
c = conn.cursor() c = conn.cursor()
c.execute('select urls.url, urls.last_visit_time FROM urls ORDER BY urls.last_visit_time DESC') c.execute('select urls.url, urls.last_visit_time FROM urls ORDER BY urls.last_visit_time DESC')
url = c.fetchone()
os.system('rm "' + a + '"') os.system('rm "' + a + '"')
elif self.browser == "S": #Safari history database
try:
from biplist import *
except:
print "\nError importing: biplist lib. \n\nTo run BC with Safari you need the biplist Python Library:\n\n $ pip install biplist\n"
plist = readPlist(self.browser_path)
url = [plist['WebHistoryDates'][0][''], '']
else: # Browser not allowed else: # Browser not allowed
print "\nSorry, you haven't a compatible browser\n\n" print "\nSorry, you haven't a compatible browser\n\n"
exit(2) exit(2)
url = c.fetchone()
self.url = url self.url = url
print "Fetching URL:", self.url[0], "\n" print "Fetching URL:", self.url[0], "\n"
return url[0] return url[0]
def traces(self): def traces(self):
while True: while True:
url = urlparse(self.url[0]).netloc url = urlparse(self.url[0]).netloc
@ -196,30 +216,29 @@ class bc(object):
Get Geolocation database (http://dev.maxmind.com/geoip/legacy/geolite/) Get Geolocation database (http://dev.maxmind.com/geoip/legacy/geolite/)
""" """
# Download and extract database # Download and extract database
import urllib if not os.path.exists('GeoLiteCity.dat'):
geo_db_path = "geo/" import urllib, gzip
if not os.path.exists(os.path.dirname(geo_db_path)): geo_db_path = '/'
os.makedirs(os.path.dirname(geo_db_path))
try: try:
print "Downloading GeoIP database...\n" print "Downloading GeoIP database...\n"
urllib.urlretrieve('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz', urllib.urlretrieve('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz',
geo_db_path+'GeoLiteCity.gz') 'GeoLiteCity.gz')
except: except:
try: try:
urllib.urlretrieve('http://xsser.sf.net/map/GeoLiteCity.dat.gz', urllib.urlretrieve('http://xsser.sf.net/map/GeoLiteCity.dat.gz',
geo_db_path+'GeoLiteCity.gz') 'GeoLiteCity.gz')
except: except:
print("[Error] - Something wrong fetching GeoIP maps from the Internet. Aborting..."), "\n" print("[Error] - Something wrong fetching GeoIP maps from the Internet. Aborting..."), "\n"
sys.exit(2) sys.exit(2)
else: f_in = gzip.open('GeoLiteCity.gz', 'rb')
f_in = gzip.open(geo_db_path+'GeoLiteCity.gz', 'rb') f_out = open('GeoLiteCity.dat', 'wb')
f_out = open(geo_db_path, 'wb')
f_out.write(f_in.read()) f_out.write(f_in.read())
f_in.close() f_in.close()
os.remove(geo_db_path+'GeoIPdb.gz')
os.remove('GeoLiteCity.gz')
# Set database (GeoLiteCity) # Set database (GeoLiteCity)
geoip= pygeoip.GeoIP(geo_db_path + 'GeoLiteCity.dat') geoip= pygeoip.GeoIP('GeoLiteCity.dat')
def run(self, opts=None): def run(self, opts=None):
""" """

Loading…
Cancel
Save