1.1 --- a/OpenSecurity/bin/vmmanager.pyw Fri Aug 22 09:35:02 2014 +0100
1.2 +++ b/OpenSecurity/bin/vmmanager.pyw Fri Aug 29 10:56:26 2014 +0100
1.3 @@ -112,7 +112,6 @@
1.4 browsingManager = None
1.5 blacklistedRSD = None
1.6 status_message = 'Starting up...'
1.7 -
1.8
1.9 def __init__(self):
1.10 # only proceed if we have a working background environment
1.11 @@ -202,8 +201,15 @@
1.12
1.13 return True
1.14
1.15 + def template_installed(self):
1.16 + """ check if we do have our root VMs installed """
1.17 + vms = self.listVM()
1.18 + if not self.vmRootName in vms:
1.19 + self.status_message = 'Unable to locate root SecurityDVM. Please download and setup the initial image.'
1.20 + return False
1.21 + return True
1.22 +
1.23 def backend_ok(self):
1.24 -
1.25 """check if the backend (VirtualBox) is sufficient for our task"""
1.26
1.27 # ensure we have our system props
1.28 @@ -221,20 +227,16 @@
1.29 self.status_message = 'Unsure if suitable extension pack is installed. Please install the "Oracle VM VirtualBox Extension Pack" from https://www.virtualbox.org/wiki/Downloads.'
1.30 return False
1.31
1.32 - # check if we do have our root VMs installed
1.33 - vms = self.listVM()
1.34 - if not self.vmRootName in vms:
1.35 - self.status_message = 'Unable to locate root SecurityDVM. Please download and setup the initial image.'
1.36 + # check the existing hostOnly network settings and try to reconfigure if faulty
1.37 + if not self.verifyHostOnlySettings():
1.38 return False
1.39 -
1.40 +
1.41 # basically all seems nice and ready to rumble
1.42 self.status_message = 'All is ok.'
1.43 -
1.44 - self.verifyHostOnlySettings()
1.45 -
1.46 return True
1.47
1.48 def stop(self):
1.49 + Cygwin.denyExec()
1.50 if self.rsdHandler != None:
1.51 self.rsdHandler.stop()
1.52 self.rsdHandler.join()
1.53 @@ -244,17 +246,21 @@
1.54 self.browsingManager.stop()
1.55 self.browsingManager.join()
1.56 self.browsingManager = None
1.57 + Cygwin.allowExec()
1.58
1.59 def start(self):
1.60 self.stop()
1.61 - self.browsingManager = BrowsingManager(self)
1.62 - self.browsingManager.start()
1.63 - self.rsdHandler = DeviceHandler(self)
1.64 - self.rsdHandler.start()
1.65 + Cygwin.allowExec()
1.66 + if self.backend_ok() and self.template_installed():
1.67 + self.browsingManager = BrowsingManager(self)
1.68 + self.browsingManager.start()
1.69 + self.rsdHandler = DeviceHandler(self)
1.70 + self.rsdHandler.start()
1.71
1.72
1.73 def cleanup(self):
1.74 self.stop()
1.75 + Cygwin.allowExec()
1.76 ip = self.getHostOnlyIP(None)
1.77 try:
1.78 result = urllib2.urlopen('http://127.0.0.1:8090/netcleanup?'+'hostonly_ip='+ip).readline()
1.79 @@ -320,14 +326,25 @@
1.80 # check if the device is mass storage type
1.81 @staticmethod
1.82 def isMassStorageDevice(device):
1.83 - keyname = 'SYSTEM\CurrentControlSet\Enum\USB' + '\VID_' + device.vendorid+'&'+'PID_'+ device.productid
1.84 - key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyname)
1.85 - devinfokeyname = win32api.RegEnumKey(key, 0)
1.86 - win32api.RegCloseKey(key)
1.87 -
1.88 - devinfokey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyname+'\\'+devinfokeyname)
1.89 - value = win32api.RegQueryValueEx(devinfokey, 'SERVICE')[0]
1.90 - win32api.RegCloseKey(devinfokey)
1.91 + vidkey = None
1.92 + devinfokey = None
1.93 + value = ""
1.94 + try:
1.95 + keyname = 'SYSTEM\CurrentControlSet\Enum\USB' + '\VID_' + device.vendorid+'&'+'PID_'+ device.productid
1.96 + vidkey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyname)
1.97 + devinfokeyname = win32api.RegEnumKey(vidkey, 0)
1.98 + win32api.RegCloseKey(vidkey)
1.99 +
1.100 + devinfokey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyname+'\\'+devinfokeyname)
1.101 + value = win32api.RegQueryValueEx(devinfokey, 'SERVICE')[0]
1.102 + win32api.RegCloseKey(devinfokey)
1.103 + except Exception as ex:
1.104 + logger.error('Error reading registry.Exception details: %s' %ex)
1.105 + finally:
1.106 + if vidkey is not None:
1.107 + win32api.RegCloseKey(vidkey)
1.108 + if devinfokey is not None:
1.109 + win32api.RegCloseKey(devinfokey)
1.110
1.111 return 'USBSTOR' in value
1.112
1.113 @@ -498,8 +515,6 @@
1.114 self.changeStorageType(template_storage,'immutable')
1.115 self.attachStorage(self.vmRootName)
1.116
1.117 - #self.start()
1.118 -
1.119 #"SATA-0-0"="C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\Snapshots\{d0af827d-f13a-49be-8ac1-df20b13bda83}.vmdk"
1.120 #"SATA-ImageUUID-0-0"="d0af827d-f13a-49be-8ac1-df20b13bda83"
1.121 @staticmethod
1.122 @@ -918,10 +933,8 @@
1.123 self.started.set()
1.124 logger.info("Browsing SDVM running.")
1.125 self.restart.wait()
1.126 - except OpenSecurityException, e:
1.127 - logger.error(''.join(e))
1.128 - except:
1.129 - logger.error("Unexpected error: " + sys.exc_info()[0])
1.130 + except Exception as e:
1.131 + logger.error("Unexpected error: ".join(e))
1.132 logger.error("BrowsingHandler failed. Cleaning up")
1.133 #self.running= False
1.134
1.135 @@ -938,7 +951,6 @@
1.136 self.running = False
1.137
1.138 def run(self):
1.139 -
1.140 self.existingRSDs = dict()
1.141 self.attachedRSDs = self.vmm.getAttachedRSDs()
1.142