# HG changeset patch # User BarthaM@N3SIM1218.D03.arc.local # Date 1408006271 -3600 # Node ID 4162648fb1670f363ca148aa4613c02eda96a67d # Parent 358381a8c60a6bc8911e63dbac4c17279d05d5a5 Fixed black tray icon issue (new method for checking if SDVM is started) New configuration check on the hostonly IF and DHCP server diff -r 358381a8c60a -r 4162648fb167 OpenSecurity/bin/test_vmmanager.pyw --- a/OpenSecurity/bin/test_vmmanager.pyw Wed Aug 06 17:05:54 2014 +0100 +++ b/OpenSecurity/bin/test_vmmanager.pyw Thu Aug 14 09:51:11 2014 +0100 @@ -88,7 +88,8 @@ return proxy['ProxyServer'] else: return "" - + + @unittest.skip("skipping") def testMatchProxy(self): #http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080 #212.17.86.109:8080 @@ -100,8 +101,28 @@ #def tearOffClass(self): # gvm_mgr.stop() # gvm_mgr.cleanup() + + + #VBoxManage list hostonlyifs + #VBoxManage list dhcpservers + #VBoxManage dhcpserver remove --netname "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter" + #VBoxManage dhcpserver add --ifname "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.100 --netmask 255.255.255.0 --lowerip 192.168.56.101 --upperip 192.168.56.254 --enable + #VBoxManage dhcpserver modify --ifname "VirtualBox Host-Only Ethernet Adapter" --enable + #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --dhcp + #VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.56.1 --netmask 255.255.255.0 + + + + def testHostOnlyDHCP(self): + #list hostonlyifs + #Cygwin.vboxExecute("list hostonlyifs") - + hostonlyifs = gvm_mgr.getHostOnlyIFs() + print hostonlyifs + + dhcpservers = gvm_mgr.getDHCPServers() + print dhcpservers + if __name__ == '__main__': TestVMManager.setUpClass() diff -r 358381a8c60a -r 4162648fb167 OpenSecurity/bin/vmmanager.pyw --- a/OpenSecurity/bin/vmmanager.pyw Wed Aug 06 17:05:54 2014 +0100 +++ b/OpenSecurity/bin/vmmanager.pyw Thu Aug 14 09:51:11 2014 +0100 @@ -97,7 +97,7 @@ def once(theClass): theClass.systemProperties = theClass.getSystemProperties() theClass.machineFolder = theClass.systemProperties["Default machine folder"] - theClass.hostonlyIFs = theClass.getHostOnlyIFs() + #theClass.hostonlyIF = theClass.getHostOnlyIFs()["VirtualBox Host-Only Ethernet Adapter"] theClass.blacklistedRSD = theClass.loadRSDBlacklist() return theClass @@ -108,7 +108,7 @@ _instance = None machineFolder = '' rsdHandler = None - hostonlyIFs = None + hostonlyIF = None browsingManager = None blacklistedRSD = None status_message = 'Starting up...' @@ -117,6 +117,7 @@ def __init__(self): # only proceed if we have a working background environment if self.backend_ok(): + VMManager.hostonlyIF = self.getHostOnlyIFs()["VirtualBox Host-Only Ethernet Adapter"] self.cleanup() else: logger.critical(self.status_message) @@ -131,11 +132,33 @@ #list the hostonly IFs exposed by the VBox host @staticmethod def getHostOnlyIFs(): - result = Cygwin.vboxExecute('list hostonlyifs')[1] - if result=='': - return None - props = dict((k.strip(),v.strip().strip('"')) for k,v in (line.split(':', 1) for line in result.strip().splitlines())) - return props + results = Cygwin.vboxExecute('list hostonlyifs')[1] + ifs = dict() + if results=='': + return ifs + items = list( "Name: " + result for result in results.split('Name: ') if result != '') + for item in items: + if item != "": + props = dict((k.strip(),v.strip().strip('"')) for k,v in (line.split(':', 1) for line in item.strip().splitlines())) + ifs[props["Name"]] = props + return ifs + + #props = dict((k.strip(),v.strip().strip('"')) for k,v in (line.split(':', 1) for line in result.strip().splitlines())) + #return props + + #list the hostonly IFs exposed by the VBox host + @staticmethod + def getDHCPServers(): + results = Cygwin.vboxExecute('list dhcpservers')[1] + if results=='': + return dict() + items = list( "NetworkName: " + result for result in results.split('NetworkName: ') if result != '') + dhcps = dict() + for item in items: + if item != "": + props = dict((k.strip(),v.strip().strip('"')) for k,v in (line.split(':', 1) for line in item.strip().splitlines())) + dhcps[props["NetworkName"]] = props + return dhcps # return hosty system properties @staticmethod @@ -149,6 +172,35 @@ # return the folder containing the guest VMs def getMachineFolder(self): return VMManager.machineFolder + + # verifies the hostonly interface and DHCP server settings + def verifyHostOnlySettings(self): + interfaceName = "VirtualBox Host-Only Ethernet Adapter" + networkName = "HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter" + + hostonlyifs = self.getHostOnlyIFs() + if not interfaceName in hostonlyifs.keys(): + Cygwin.vboxExecute('hostonlyif create') + hostonlyifs = self.getHostOnlyIFs() + if not interfaceName in hostonlyifs.keys(): + return False + + interface = hostonlyifs[interfaceName] + if interface['VBoxNetworkName'] != networkName or interface['DHCP'] != 'Disabled' or interface['IPAddress'] != '192.168.56.1': + Cygwin.vboxExecute('hostonlyif ipconfig "' + interfaceName + '" --ip 192.168.56.1 --netmask 255.255.255.0') + + dhcpservers = self.getDHCPServers() + if not networkName in dhcpservers.keys(): + Cygwin.vboxExecute('dhcpserver add --ifname "' + interfaceName + '" --ip 192.168.56.100 --netmask 255.255.255.0 --lowerip 192.168.56.101 --upperip 192.168.56.254 --enable') + dhcpservers = self.getDHCPServers() + if not networkName in dhcpservers.keys(): + return False + + server = dhcpservers[networkName] + if server['IP'] != '192.168.56.100' or server['NetworkMask'] != '255.255.255.0' or server['lowerIPAddress'] != '192.168.56.101' or server['upperIPAddress'] != '192.168.56.254' or server['Enabled'] != 'Yes': + Cygwin.vboxExecute('VBoxManage dhcpserver modify --netname "' + networkName + '" --ip 192.168.56.100 --netmask 255.255.255.0 --lowerip 192.168.56.101 --upperip 192.168.56.254 --enable') + + return True def backend_ok(self): @@ -178,6 +230,8 @@ # basically all seems nice and ready to rumble self.status_message = 'All is ok.' + self.verifyHostOnlySettings() + return True def stop(self): @@ -370,9 +424,8 @@ #remove eventually existing SDVM folder machineFolder = Cygwin.cygPath(VMManager.machineFolder) Cygwin.checkResult(Cygwin.bashExecute('/usr/bin/rm -rf \\\"' + machineFolder + '/' + vm_name + '\\\"')) - hostonly_if = self.getHostOnlyIFs() Cygwin.checkResult(Cygwin.vboxExecute('createvm --name ' + vm_name + ' --ostype Debian --register')) - Cygwin.checkResult(Cygwin.vboxExecute('modifyvm ' + vm_name + ' --memory 768 --vram 10 --cpus 1 --usb on --usbehci on --nic1 hostonly --hostonlyadapter1 \"' + hostonly_if['Name'] + '\" --nic2 nat')) + Cygwin.checkResult(Cygwin.vboxExecute('modifyvm ' + vm_name + ' --memory 768 --vram 10 --cpus 1 --usb on --usbehci on --nic1 hostonly --hostonlyadapter1 \"' + self.hostonlyIF['Name'] + '\" --nic2 nat')) Cygwin.checkResult(Cygwin.vboxExecute('storagectl ' + vm_name + ' --name SATA --add sata --portcount 2')) #create new SecurityDVM with automatically generated name from template (thread safe) @@ -540,8 +593,7 @@ def getHostOnlyIP(self, vm_name): if vm_name == None: logger.info('Getting hostOnly IP address for Host') - #TODO:// optimise to store on init local variable and return that value (avoid calling list hostonlyifs) - return VMManager.hostonlyIFs['IPAddress'] + return VMManager.hostonlyIF['IPAddress'] else: logger.info('Getting hostOnly IP address ' + vm_name) result = Cygwin.checkResult(Cygwin.vboxExecute('guestproperty get ' + vm_name + ' /VirtualBox/GuestInfo/Net/0/V4/IP')) @@ -587,7 +639,14 @@ # wait for machine to come up def waitStartup(self, vm_name, timeout_ms = 1000): - Cygwin.checkResult(Cygwin.vboxExecute('guestproperty wait ' + vm_name + ' SDVMStarted --timeout ' + str(timeout_ms) + ' --fail-on-timeout', try_count = 60)) + #Cygwin.checkResult(Cygwin.vboxExecute('guestproperty wait ' + vm_name + ' SDVMStarted --timeout ' + str(timeout_ms) + ' --fail-on-timeout', try_count = 60)) + started = False + while not started: + result = Cygwin.checkResult(Cygwin.vboxExecute('guestproperty get ' + vm_name + ' SDVMStarted'))[1] + if "Value: True" in result: + started = True + else: + time.sleep(3) return self.getHostOnlyIP(vm_name) # wait for machine to shutdown