Browse Source

added feature to set browser by default manually

pull/3/head
psy 11 years ago
parent
commit
eb4ce6244c
  1. 198
      main.py
  2. 7
      options.py

198
main.py

@ -38,7 +38,7 @@ class bc(object):
# check_browser(): # check_browser():
self.operating_system = '' #The operating system being used. Either darwin/linux self.operating_system = '' #The operating system being used. Either darwin/linux
self.browser = "" # "F" Firefox / "C" Chrome self.browser = "" # "F" Firefox / "C" Chrome / "S" Safari / "CHROMIUM" Chromium
self.browser_path = "" #the path to the browser application self.browser_path = "" #the path to the browser application
self.browser_history_path = "" # the path to the browser history file self.browser_history_path = "" # the path to the browser history file
self.browser_version = "" # the version of the browser self.browser_version = "" # the version of the browser
@ -112,6 +112,161 @@ class bc(object):
""" """
Check browsers used by system Check browsers used by system
""" """
print "Browser Options:\n" + '='*45 + "\n"
# make browser set manually by user
if self.options.browser:
if self.options.browser == "F" or self.options.browser == "f": # Firefox
if sys.platform == 'darwin': # on darwin
self.operating_system = 'darwin'
f_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Firefox/Profiles')
f_osx = '/Applications/Firefox.app/Contents/MacOS/firefox'
try:
if os.path.exists(f_his_osx):
if len(os.listdir(f_his_osx)) > 2:
print 'You have multiple profiles, choosing the last one used'
# filter to use the directory that was last modified.
all_subdirs = [os.path.join(f_his_osx,d)for d in os.listdir(f_his_osx)]
try:
all_subdirs.remove(os.path.join(f_his_osx,'.DS_Store')) # throwing out .DS_store
except:
pass
latest_subdir = max(all_subdirs, key=os.path.getmtime)
osx_profile = os.path.join(f_his_osx, latest_subdir)
if self.options.browser_history_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = os.path.join(osx_profile, 'places.sqlite')
else:
for folder in os.listdir(f_his_osx):
if folder.endswith('.default'):
osx_default = os.path.join(f_his_osx, folder)
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = os.path.join(osx_default, 'places.sqlite')
self.browser = "F"
self.browser_path = f_osx
except:
print "Warning: Firefox hasn't been detected on your Darwin system.\n"
sys.exit(2)
elif sys.platform.startswith('linux'): # on unix
self.operating_system = 'linux'
f_lin = os.path.join(os.path.expanduser('~'), '.mozilla/firefox/') #add the next folder
if os.path.exists(f_lin):
#missing multiple profile support
for folder in os.listdir(f_lin):
if folder.endswith('.default'):
lin_default = os.path.join(f_lin, folder)
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = os.path.join(lin_default, 'places.sqlite')
self.browser = "F"
else:
print "Warning: Firefox hasn't been detected on your Unix system.\n"
sys.exit(2)
else:
print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
sys.exit(2)
elif self.options.browser == "C" or self.options.browser == "c": # Chrome
if sys.platform == 'darwin': # on darwin
self.operating_system = 'darwin'
c_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Google/Chrome/Default/History')
c_osx = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
try:
if os.path.exists(c_his_osx):
self.browser = "C"
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = c_his_osx
self.browser_path = c_osx
except:
print "Warning: Chrome hasn't been detected on your Darwin system.\n"
sys.exit(2)
elif sys.platform.startswith('linux'): # on unix
self.operating_system = 'linux'
c_lin = os.path.join(os.path.expanduser('~'), '.config/google-chrome/History')
if os.path.exists(c_lin):
self.browser = "C"
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = c_lin
else:
print "Warning: Chrome hasn't been detected on your Unix system.\n"
sys.exit(2)
else:
print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
sys.exit(2)
elif self.options.browser == "Ch" or self.options.browser == "CH" or self.options.browser == "ch": # Chromium
if sys.platform == 'darwin': # on darwin
self.operating_system = 'darwin'
chromium_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Chromium/Default/History')
chromium_osx = '/Applications/Chromium.app/Contents/MacOS/Chromium'
try:
if os.path.exists(chromium_his_osx):
self.browser = "CHROMIUM"
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = chromium_his_osx
self.browser_path = chromium_osx
except:
print "Warning: Chromium hasn't been detected on your Darwin system.\n"
sys.exit(2)
elif sys.platform.startswith('linux'): # on unix
self.operating_system = 'linux'
chromium_lin = os.path.join(os.path.expanduser('~'), '.config/chromium/Default/History')
if os.path.exists(chromium_lin):
self.browser = "CHROMIUM"
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = chromium_lin
else:
print "Warning: Chromium hasn't been detected on your Unix system.\n"
sys.exit(2)
else:
print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
sys.exit(2)
elif self.options.browser == "S" or self.options.browser == "s": # Safari
if sys.platform == 'darwin': # on darwin
self.operating_system = 'darwin'
s_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Safari/History.plist')
s_osx = '/Applications/Safari.app/Contents/MacOS/Safari'
try:
if os.path.exists(s_his_osx):
self.browser = "S"
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = s_his_osx
self.browser_path = s_osx
except:
print "Warning: Safari hasn't been detected on your Darwin system.\n"
sys.exit(2)
elif sys.platform.startswith('linux'): # on unix
self.operating_system = 'linux'
safari_lin = os.path.join(os.path.expanduser('~'), 'Library/Safari/History.plist')
if os.path.exists(safari_lin):
self.browser = "S"
if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser_history
else:
self.browser_history_path = safari_lin
else:
print "Warning: Safari hasn't been detected on your Unix system.\n"
sys.exit(2)
else:
print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
sys.exit(2)
else: # browser not supported error
print "You must enter a correct input to set your browser manually: F = Firefox / C = Chrome / S = Safari / Ch = Chromium\n"
sys.exit(2)
# make browser set, automatically
else:
if sys.platform == 'darwin': if sys.platform == 'darwin':
self.operating_system = 'darwin' self.operating_system = 'darwin'
# paths to the browsing history db's # paths to the browsing history db's
@ -136,38 +291,38 @@ 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_his_osx, latest_subdir) osx_profile = os.path.join(f_his_osx, latest_subdir)
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = os.path.join(osx_profile, 'places.sqlite') self.browser_history_path = os.path.join(osx_profile, 'places.sqlite')
else: else:
for folder in os.listdir(f_his_osx): for folder in os.listdir(f_his_osx):
if folder.endswith('.default'): if folder.endswith('.default'):
osx_default = os.path.join(f_his_osx, folder) osx_default = os.path.join(f_his_osx, folder)
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = os.path.join(osx_default, 'places.sqlite') self.browser_history_path = os.path.join(osx_default, 'places.sqlite')
self.browser = "F" self.browser = "F"
self.browser_path = f_osx self.browser_path = f_osx
elif os.path.exists(c_his_osx): elif os.path.exists(c_his_osx):
self.browser = "C" self.browser = "C"
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = c_his_osx self.browser_history_path = c_his_osx
self.browser_path = c_osx self.browser_path = c_osx
elif os.path.exists(chromium_his_osx): elif os.path.exists(chromium_his_osx):
self.browser = "CHROMIUM" self.browser = "CHROMIUM"
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = chromium_his_osx self.browser_history_path = chromium_his_osx
self.browser_path = chromium_osx self.browser_path = chromium_osx
elif os.path.exists(s_his_osx): elif os.path.exists(s_his_osx):
self.browser = "S" self.browser = "S"
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = s_his_osx self.browser_history_path = s_his_osx
self.browser_path = s_osx self.browser_path = s_osx
@ -184,24 +339,25 @@ class bc(object):
for folder in os.listdir(f_lin): for folder in os.listdir(f_lin):
if folder.endswith('.default'): if folder.endswith('.default'):
lin_default = os.path.join(f_lin, folder) lin_default = os.path.join(f_lin, folder)
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = os.path.join(lin_default, 'places.sqlite') self.browser_history_path = os.path.join(lin_default, 'places.sqlite')
self.browser = "F" self.browser = "F"
elif os.path.exists(c_lin): elif os.path.exists(c_lin):
self.browser = "C" self.browser = "C"
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = c_lin self.browser_history_path = c_lin
elif os.path.exists(chromium_lin): elif os.path.exists(chromium_lin):
self.browser = "CHROMIUM" self.browser = "CHROMIUM"
if self.options.browser: # if exists, extract user browser's history path if self.options.browser_history: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser self.browser_history_path = self.options.browser_history
else: else:
self.browser_history_path = chromium_lin self.browser_history_path = chromium_lin
print "Browser Options:\n" + '='*45 + "\n"
# ouput browser used on different platforms
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):
if self.browser == "F": if self.browser == "F":
print "Using: Firefox\n" print "Using: Firefox\n"
@ -214,7 +370,11 @@ class bc(object):
if self.options.debug == True: if self.options.debug == True:
if sys.platform == 'darwin': if sys.platform == 'darwin':
if self.browser == "F" or self.browser == "C" or self.browser == "CHROMIUM": if self.browser == "F" or self.browser == "C" or self.browser == "CHROMIUM":
try:
self.browser_version = subprocess.check_output([self.browser_path, '--version']).strip('\n') self.browser_version = subprocess.check_output([self.browser_path, '--version']).strip('\n')
except:
a = subprocess.Popen(['firefox', '--version'], stdout=subprocess.PIPE)
self.browser_version = a.stdout.read()
elif sys.platform.startswith('linux') and self.browser == "F": elif sys.platform.startswith('linux') and self.browser == "F":
try: try:
self.browser_version = subprocess.check_output(['firefox', '--version']).strip('\n') self.browser_version = subprocess.check_output(['firefox', '--version']).strip('\n')
@ -261,7 +421,7 @@ class bc(object):
plist = readPlist(self.browser_history_path) plist = readPlist(self.browser_history_path)
url = [plist['WebHistoryDates'][0][''], ''] url = [plist['WebHistoryDates'][0][''], '']
else: # Browser not allowed else: # Browser not allowed
print "\nSorry, you don't have a compatible browser\n\n" print "Sorry, you don't have a compatible browser\n\n"
exit(2) exit(2)
self.url = url self.url = url
return url[0] return url[0]

7
options.py

@ -10,13 +10,14 @@ class BCOptions(optparse.OptionParser):
def __init__(self, *args): def __init__(self, *args):
optparse.OptionParser.__init__(self, optparse.OptionParser.__init__(self,
prog='bc.py', prog='bc.py',
version='\nBC (Border-Check) 0.1v - 2013 - (GPLv3.0) -> by psy\n', version='\nBC (Border-Check) 0.1v - 2013 - (GPLv3.0)\n',
usage= '\n\nbc [OPTIONS]') usage= '\n\nbc [OPTIONS]')
self.add_option("-d", "--debug", action="store_true", dest="debug", help="debug mode") self.add_option("-d", "--debug", action="store_true", dest="debug", help="debug mode")
self.add_option("-b", action="store", dest="browser", help="set browser's history path")
#self.add_option("--proxy", action="store", dest="proxy", help="set proxy server")
self.add_option("--xml", action="store", dest="export_xml", help="export traces to xml (ex: --xml foo.xml)") self.add_option("--xml", action="store", dest="export_xml", help="export traces to xml (ex: --xml foo.xml)")
self.add_option("--bh", action="store", dest="browser_history", help="set browser's history path")
self.add_option("-b", action="store", dest="browser", help="set browser to be user: F = Firefox / C = Chrome / S = Safari / Ch = Chromium")
#self.add_option("--proxy", action="store", dest="proxy", help="set proxy server")
def get_options(self, user_args=None): def get_options(self, user_args=None):
(options, args) = self.parse_args(user_args) (options, args) = self.parse_args(user_args)

Loading…
Cancel
Save