Browse Source

added feature to set browser by default manually

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

332
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,96 +112,252 @@ class bc(object):
""" """
Check browsers used by system Check browsers used by system
""" """
if sys.platform == 'darwin': print "Browser Options:\n" + '='*45 + "\n"
self.operating_system = 'darwin'
# paths to the browsing history db's # make browser set manually by user
f_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Firefox/Profiles') if self.options.browser:
c_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Google/Chrome/Default/History') if self.options.browser == "F" or self.options.browser == "f": # Firefox
chromium_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Chromium/Default/History') if sys.platform == 'darwin': # on darwin
s_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Safari/History.plist') self.operating_system = 'darwin'
# path to the browser executables f_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Firefox/Profiles')
f_osx = '/Applications/Firefox.app/Contents/MacOS/firefox' f_osx = '/Applications/Firefox.app/Contents/MacOS/firefox'
c_osx = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' try:
chromium_osx = '/Applications/Chromium.app/Contents/MacOS/Chromium' if os.path.exists(f_his_osx):
s_osx = '/Applications/Safari.app/Contents/MacOS/Safari' if len(os.listdir(f_his_osx)) > 2:
try: print 'You have multiple profiles, choosing the last one used'
if os.path.exists(f_his_osx): # filter to use the directory that was last modified.
if len(os.listdir(f_his_osx)) > 2: all_subdirs = [os.path.join(f_his_osx,d)for d in os.listdir(f_his_osx)]
print 'You have multiple profiles, choosing the last one used' try:
#filter to use the directory that was last modified. all_subdirs.remove(os.path.join(f_his_osx,'.DS_Store')) # throwing out .DS_store
all_subdirs = [os.path.join(f_his_osx,d)for d in os.listdir(f_his_osx)] except:
try: pass
all_subdirs.remove(os.path.join(f_his_osx,'.DS_Store')) #throwing out .DS_store latest_subdir = max(all_subdirs, key=os.path.getmtime)
except: osx_profile = os.path.join(f_his_osx, latest_subdir)
pass if self.options.browser_history_history: # if exists, extract user browser's history path
latest_subdir = max(all_subdirs, key=os.path.getmtime) self.browser_history_path = self.options.browser_history
osx_profile = os.path.join(f_his_osx, latest_subdir) else:
if self.options.browser: # if exists, extract user browser's history path self.browser_history_path = os.path.join(osx_profile, 'places.sqlite')
self.browser_history_path = self.options.browser else:
else: for folder in os.listdir(f_his_osx):
self.browser_history_path = os.path.join(osx_profile, 'places.sqlite') if folder.endswith('.default'):
else: osx_default = os.path.join(f_his_osx, folder)
for folder in os.listdir(f_his_osx): 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'): if folder.endswith('.default'):
osx_default = os.path.join(f_his_osx, 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(osx_default, 'places.sqlite') self.browser_history_path = os.path.join(lin_default, 'places.sqlite')
self.browser = "F" self.browser = "F"
self.browser_path = f_osx
elif os.path.exists(c_his_osx):
self.browser = "C"
if self.options.browser: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser
else:
self.browser_history_path = c_his_osx
self.browser_path = c_osx
elif os.path.exists(chromium_his_osx):
self.browser = "CHROMIUM"
if self.options.browser: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser
else: else:
self.browser_history_path = chromium_his_osx print "Warning: Firefox hasn't been detected on your Unix system.\n"
self.browser_path = chromium_osx sys.exit(2)
elif os.path.exists(s_his_osx): else:
self.browser = "S" print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
if self.options.browser: # if exists, extract user browser's history path sys.exit(2)
self.browser_history_path = self.options.browser 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: else:
self.browser_history_path = s_his_osx print "Warning: Chrome hasn't been detected on your Unix system.\n"
self.browser_path = s_osx sys.exit(2)
except: else:
print "Warning: None of the currently supported browsers (Firefox, Chrome, Chromium, Safari) are installed." print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
sys.exit(2)
elif sys.platform.startswith('linux'): elif self.options.browser == "Ch" or self.options.browser == "CH" or self.options.browser == "ch": # Chromium
self.operating_system = 'linux' if sys.platform == 'darwin': # on darwin
f_lin = os.path.join(os.path.expanduser('~'), '.mozilla/firefox/') #add the next folder self.operating_system = 'darwin'
c_lin = os.path.join(os.path.expanduser('~'), '.config/google-chrome/History') chromium_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Chromium/Default/History')
chromium_lin = os.path.join(os.path.expanduser('~'), '.config/chromium/Default/History') chromium_osx = '/Applications/Chromium.app/Contents/MacOS/Chromium'
if os.path.exists(f_lin): try:
#missing multiple profile support if os.path.exists(chromium_his_osx):
for folder in os.listdir(f_lin): self.browser = "CHROMIUM"
if folder.endswith('.default'): if self.options.browser_history: # if exists, extract user browser's history path
lin_default = os.path.join(f_lin, folder) self.browser_history_path = self.options.browser_history
if self.options.browser: # if exists, extract user browser's history path else:
self.browser_history_path = self.options.browser 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: else:
self.browser_history_path = os.path.join(lin_default, 'places.sqlite') self.browser_history_path = chromium_lin
self.browser = "F" else:
elif os.path.exists(c_lin): print "Warning: Chromium hasn't been detected on your Unix system.\n"
self.browser = "C" sys.exit(2)
if self.options.browser: # if exists, extract user browser's history path
self.browser_history_path = self.options.browser
else: else:
self.browser_history_path = c_lin print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
elif os.path.exists(chromium_lin): sys.exit(2)
self.browser = "CHROMIUM" elif self.options.browser == "S" or self.options.browser == "s": # Safari
if self.options.browser: # if exists, extract user browser's history path if sys.platform == 'darwin': # on darwin
self.browser_history_path = self.options.browser 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: else:
self.browser_history_path = chromium_lin print "Warning: Only GNU/Linux or Darwin operating systems supported.\n"
print "Browser Options:\n" + '='*45 + "\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':
self.operating_system = 'darwin'
# paths to the browsing history db's
f_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Firefox/Profiles')
c_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Google/Chrome/Default/History')
chromium_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Application Support/Chromium/Default/History')
s_his_osx = os.path.join(os.path.expanduser('~'), 'Library/Safari/History.plist')
# path to the browser executables
f_osx = '/Applications/Firefox.app/Contents/MacOS/firefox'
c_osx = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
chromium_osx = '/Applications/Chromium.app/Contents/MacOS/Chromium'
s_osx = '/Applications/Safari.app/Contents/MacOS/Safari'
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
elif 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
elif 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
elif 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: None of the currently supported browsers (Firefox, Chrome, Chromium, Safari) are installed."
elif sys.platform.startswith('linux'):
self.operating_system = 'linux'
f_lin = os.path.join(os.path.expanduser('~'), '.mozilla/firefox/') #add the next folder
c_lin = os.path.join(os.path.expanduser('~'), '.config/google-chrome/History')
chromium_lin = os.path.join(os.path.expanduser('~'), '.config/chromium/Default/History')
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"
elif 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
elif 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
# 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":
self.browser_version = subprocess.check_output([self.browser_path, '--version']).strip('\n') try:
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