def configNode(self): """ Node configuration """ self.create_config() # Add all network interface when using Cloud with computer symbol if not self.default_symbol: if sys.platform.startswith('win'): interfaces = getWindowsInterfaces() for interface in interfaces: match = re.search( r"""^rpcap://(\\Device\\NPF_{[a-fA-F0-9\-]*})(.*)""", interface) interface = match.group(1) nio = 'nio_gen_eth:' + str(interface).lower() if not nio in self.config['nios']: self.config['nios'].append(nio) name_match = re.search(r"""^\ :.*:\ (.+)""", match.group(2)) if name_match: interface_name = name_match.group(1) else: # The interface name could not be found, let's use the interface model instead model_match = re.search( r"""^\ :\ (.*)\ on local host:.*""", match.group(2)) if model_match: interface_name = model_match.group(1) else: interface_name = translate( "Cloud", "Unknown name") self.config['rpcap_mapping'][nio] = interface_name else: interfaces = map(lambda interface: interface.name(), QtNetwork.QNetworkInterface.allInterfaces()) for interface in interfaces: if str(interface).startswith("tap"): nio = 'nio_tap:' + str(interface) else: nio = 'nio_gen_eth:' + str(interface) if not nio in self.config['nios']: self.config['nios'].append(nio) # adding NIO UDPs for VPCS self.config['nios'].extend([ 'nio_udp:30000:127.0.0.1:20000', 'nio_udp:30001:127.0.0.1:20001', 'nio_udp:30002:127.0.0.1:20002', 'nio_udp:30003:127.0.0.1:20003', 'nio_udp:30004:127.0.0.1:20004', 'nio_udp:30005:127.0.0.1:20005', 'nio_udp:30006:127.0.0.1:20006', 'nio_udp:30007:127.0.0.1:20007', 'nio_udp:30008:127.0.0.1:20008' ]) return True
def check_replace_GUID_NIO(self, filename): """ Check and replace non-existing GUID (network interface ID) on Windows """ file = open(filename,'r') lines = file.readlines() cregex = re.compile("^.*nio_gen_eth:(.*)") niolist = [] for currentline in lines: currentline = currentline.lower().strip() match_obj = cregex.match(currentline) if match_obj: niolist.append(match_obj.group(1)) niolist = set(niolist) if len(niolist): rpcaps = getWindowsInterfaces() interfaces = {} for rpcap in rpcaps: match = re.search(r"""^rpcap://(\\Device\\NPF_{[a-fA-F0-9\-]*}).*:(.*)""", rpcap) interface_guid = str(match.group(1)).lower() interfaces[interface_guid] = unicode(match.group(2)).strip() for nio in niolist: if not interfaces.has_key(nio): (selection, ok) = QtGui.QInputDialog.getItem(globals.GApp.mainWindow, translate("DynagenSub", "NIO connection"), unicode(translate("DynagenSub", "%s cannot be found\nPlease choose an alternate network interface:")) % nio, interfaces.values(), 0, False) if ok: interface = "" for (key, name) in interfaces.iteritems(): if name == unicode(selection): interface = key break index = 0 for currentline in lines: match_obj = cregex.match(currentline.lower()) if match_obj: currentline = currentline.replace(nio, interface) lines[index] = currentline index += 1 else: continue file.close() if len(niolist): # write changes file = open(filename,'w') for line in lines: file.write(line) file.close()
def configNode(self): """ Node configuration """ self.create_config() # Add all network interface when using Cloud with computer symbol if not self.default_symbol: if sys.platform.startswith('win'): interfaces = getWindowsInterfaces() for interface in interfaces: match = re.search(r"""^rpcap://(\\Device\\NPF_{[a-fA-F0-9\-]*})(.*)""", interface) interface = match.group(1) nio = 'nio_gen_eth:' + str(interface).lower() if not nio in self.config['nios']: self.config['nios'].append(nio) name_match = re.search(r"""^\ :.*:\ (.+)""", match.group(2)) if name_match: interface_name = name_match.group(1) else: # The interface name could not be found, let's use the interface model instead model_match = re.search(r"""^\ :\ (.*)\ on local host:.*""", match.group(2)) if model_match: interface_name = model_match.group(1) else: interface_name = translate("Cloud", "Unknown name") self.config['rpcap_mapping'][nio] = interface_name else: interfaces = map(lambda interface: interface.name(), QtNetwork.QNetworkInterface.allInterfaces()) for interface in interfaces: if str(interface).startswith("tap"): nio = 'nio_tap:' + str(interface) else: nio = 'nio_gen_eth:' + str(interface) if not nio in self.config['nios']: self.config['nios'].append(nio) # adding NIO UDPs for VPCS self.config['nios'].extend(['nio_udp:30000:127.0.0.1:20000', 'nio_udp:30001:127.0.0.1:20001', 'nio_udp:30002:127.0.0.1:20002', 'nio_udp:30003:127.0.0.1:20003', 'nio_udp:30004:127.0.0.1:20004', 'nio_udp:30005:127.0.0.1:20005', 'nio_udp:30006:127.0.0.1:20006', 'nio_udp:30007:127.0.0.1:20007', 'nio_udp:30008:127.0.0.1:20008']) return True
def __init__(self): QtGui.QWidget.__init__(self) self.setupUi(self) self.setObjectName("Cloud") # connect slots self.connect(self.pushButtonAddGenericEth, QtCore.SIGNAL('clicked()'), self.slotAddGenEth) self.connect(self.pushButtonDeleteGenericEth, QtCore.SIGNAL('clicked()'), self.slotDeleteGenEth) self.connect(self.listWidgetGenericEth, QtCore.SIGNAL('itemSelectionChanged()'), self.slotGenEthChanged) self.connect(self.pushButtonAddLinuxEth, QtCore.SIGNAL('clicked()'), self.slotAddLinuxEth) self.connect(self.pushButtonDeleteLinuxEth, QtCore.SIGNAL('clicked()'), self.slotDeleteLinuxEth) self.connect(self.listWidgetLinuxEth, QtCore.SIGNAL('itemSelectionChanged()'), self.slotLinuxEthChanged) self.connect(self.comboBoxGenEth, QtCore.SIGNAL('currentIndexChanged(int)'), self.slotSelectedGenEth) self.connect(self.comboBoxLinuxEth, QtCore.SIGNAL('currentIndexChanged(int)'), self.slotSelectedLinuxEth) self.connect(self.pushButtonAddUDP, QtCore.SIGNAL('clicked()'), self.slotAddUDP) self.connect(self.pushButtonDeleteUDP, QtCore.SIGNAL('clicked()'), self.slotDeleteUDP) self.connect(self.listWidgetUDP, QtCore.SIGNAL('itemSelectionChanged()'), self.slotUDPChanged) self.connect(self.listWidgetUDP, QtCore.SIGNAL('currentRowChanged(int)'), self.slotUDPselected) self.connect(self.pushButtonAddTAP, QtCore.SIGNAL('clicked()'), self.slotAddTAP) self.connect(self.pushButtonDeleteTAP, QtCore.SIGNAL('clicked()'), self.slotDeleteTAP) self.connect(self.listWidgetTAP, QtCore.SIGNAL('itemSelectionChanged()'), self.slotTAPChanged) self.connect(self.pushButtonAddUNIX, QtCore.SIGNAL('clicked()'), self.slotAddUNIX) self.connect(self.pushButtonDeleteUNIX, QtCore.SIGNAL('clicked()'), self.slotDeleteUNIX) self.connect(self.listWidgetUNIX, QtCore.SIGNAL('itemSelectionChanged()'), self.slotUNIXChanged) self.connect(self.listWidgetUNIX, QtCore.SIGNAL('currentRowChanged(int)'), self.slotUNIXselected) self.connect(self.pushButtonAddVDE, QtCore.SIGNAL('clicked()'), self.slotAddVDE) self.connect(self.pushButtonDeleteVDE, QtCore.SIGNAL('clicked()'), self.slotDeleteVDE) self.connect(self.listWidgetVDE, QtCore.SIGNAL('itemSelectionChanged()'), self.slotVDEChanged) self.connect(self.listWidgetVDE, QtCore.SIGNAL('currentRowChanged(int)'), self.slotVDEselected) self.connect(self.pushButtonAddNull, QtCore.SIGNAL('clicked()'), self.slotAddNull) self.connect(self.pushButtonDeleteNull, QtCore.SIGNAL('clicked()'), self.slotDeleteNull) self.connect(self.listWidgetNull, QtCore.SIGNAL('itemSelectionChanged()'), self.slotNullChanged) self.connect(self.listWidgetNull, QtCore.SIGNAL('currentRowChanged(int)'), self.slotNullselected) self.nios = [] self.rpcap_mapping = {} if sys.platform.startswith('win'): interfaces = getWindowsInterfaces() else: interfaces = map(lambda interface: interface.name(), QtNetwork.QNetworkInterface.allInterfaces()) self.comboBoxLinuxEth.addItems(interfaces) self.comboBoxGenEth.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.comboBoxGenEth.addItems(interfaces)
def check_replace_GUID_NIO(self, filename): """ Check and replace non-existing GUID (network interface ID) on Windows """ debugmsg(2, "DynagenSub::check_replace_GUID_NIO(%s)" % unicode(filename)) file = open(filename, 'r') lines = file.readlines() cregex = re.compile( r"""^.*nio_gen_eth:(\\device\\npf_{[a-fA-F0-9\-]*}).*""") niolist = [] for currentline in lines: currentline = currentline.lower().strip() match_obj = cregex.match(currentline) if match_obj and match_obj.group(1) not in niolist: niolist.append(match_obj.group(1)) self.rpcap_mapping.clear() niolist = set(niolist) if len(niolist): rpcaps = getWindowsInterfaces() interfaces = {} for rpcap in rpcaps: match = re.search( r"""^rpcap://(\\Device\\NPF_{[a-fA-F0-9\-]*})(.*)""", rpcap) interface_guid = str(match.group(1)).lower() interfaces[interface_guid] = unicode(match.group(2)).strip() name_match = re.search(r"""^\ :.*:\ (.+)""", match.group(2)) if name_match: interface_name = name_match.group(1) else: # The interface name could not be found, let's use the interface model instead model_match = re.search( r"""^\ :\ (.*)\ on local host:.*""", match.group(2)) if model_match: interface_name = model_match.group(1) else: interface_name = translate("DynagenSub", "Unknown name") self.rpcap_mapping['nio_gen_eth:' + interface_guid] = interface_name for nio in niolist: if not interfaces.has_key(nio): (selection, ok) = QtGui.QInputDialog.getItem( globals.GApp.mainWindow, translate("DynagenSub", "NIC binding"), translate( "DynagenSub", "NIC ID %s cannot be found on this host\nPlease choose an alternate network interface:" ) % nio, interfaces.values(), 0, False) if ok: interface = "" for (key, name) in interfaces.iteritems(): if name == unicode(selection): interface = key break index = 0 for currentline in lines: match_obj = cregex.match(currentline.lower()) if match_obj: currentline = currentline.replace( nio, interface) lines[index] = currentline index += 1 else: continue file.close() if len(niolist): # write changes file = open(filename, 'w') for line in lines: file.write(line) file.close()
def __init__(self): QtGui.QWidget.__init__(self) self.setupUi(self) self.setObjectName("Cloud") # connect slots self.connect(self.pushButtonAddGenericEth, QtCore.SIGNAL('clicked()'), self.slotAddGenEth) self.connect(self.pushButtonDeleteGenericEth, QtCore.SIGNAL('clicked()'), self.slotDeleteGenEth) self.connect(self.listWidgetGenericEth, QtCore.SIGNAL('itemSelectionChanged()'), self.slotGenEthChanged) self.connect(self.pushButtonAddLinuxEth, QtCore.SIGNAL('clicked()'), self.slotAddLinuxEth) self.connect(self.pushButtonDeleteLinuxEth, QtCore.SIGNAL('clicked()'), self.slotDeleteLinuxEth) self.connect(self.listWidgetLinuxEth, QtCore.SIGNAL('itemSelectionChanged()'), self.slotLinuxEthChanged) self.connect(self.comboBoxGenEth, QtCore.SIGNAL('currentIndexChanged(int)'), self.slotSelectedGenEth) self.connect(self.comboBoxLinuxEth, QtCore.SIGNAL('currentIndexChanged(int)'), self.slotSelectedLinuxEth) self.connect(self.pushButtonAddUDP, QtCore.SIGNAL('clicked()'), self.slotAddUDP) self.connect(self.pushButtonDeleteUDP, QtCore.SIGNAL('clicked()'), self.slotDeleteUDP) self.connect(self.listWidgetUDP, QtCore.SIGNAL('itemSelectionChanged()'), self.slotUDPChanged) self.connect(self.listWidgetUDP, QtCore.SIGNAL('currentRowChanged(int)'), self.slotUDPselected) self.connect(self.pushButtonAddTAP, QtCore.SIGNAL('clicked()'), self.slotAddTAP) self.connect(self.pushButtonDeleteTAP, QtCore.SIGNAL('clicked()'), self.slotDeleteTAP) self.connect(self.listWidgetTAP, QtCore.SIGNAL('itemSelectionChanged()'), self.slotTAPChanged) self.connect(self.pushButtonAddUNIX, QtCore.SIGNAL('clicked()'), self.slotAddUNIX) self.connect(self.pushButtonDeleteUNIX, QtCore.SIGNAL('clicked()'), self.slotDeleteUNIX) self.connect(self.listWidgetUNIX, QtCore.SIGNAL('itemSelectionChanged()'), self.slotUNIXChanged) self.connect(self.listWidgetUNIX, QtCore.SIGNAL('currentRowChanged(int)'), self.slotUNIXselected) self.connect(self.pushButtonAddVDE, QtCore.SIGNAL('clicked()'), self.slotAddVDE) self.connect(self.pushButtonDeleteVDE, QtCore.SIGNAL('clicked()'), self.slotDeleteVDE) self.connect(self.listWidgetVDE, QtCore.SIGNAL('itemSelectionChanged()'), self.slotVDEChanged) self.connect(self.listWidgetVDE, QtCore.SIGNAL('currentRowChanged(int)'), self.slotVDEselected) self.connect(self.pushButtonAddNull, QtCore.SIGNAL('clicked()'), self.slotAddNull) self.connect(self.pushButtonDeleteNull, QtCore.SIGNAL('clicked()'), self.slotDeleteNull) self.connect(self.listWidgetNull, QtCore.SIGNAL('itemSelectionChanged()'), self.slotNullChanged) self.connect(self.listWidgetNull, QtCore.SIGNAL('currentRowChanged(int)'), self.slotNullselected) self.nios = [] self.rpcap_mapping = {} if sys.platform.startswith('win'): interfaces = getWindowsInterfaces() else: interfaces = map(lambda interface: interface.name(), QtNetwork.QNetworkInterface.allInterfaces()) self.comboBoxLinuxEth.addItems(interfaces) self.comboBoxGenEth.setSizeAdjustPolicy( QtGui.QComboBox.AdjustToContents) self.comboBoxGenEth.addItems(interfaces)
def check_replace_GUID_NIO(self, filename): """ Check and replace non-existing GUID (network interface ID) on Windows """ debugmsg(2, "DynagenSub::check_replace_GUID_NIO(%s)" % unicode(filename)) file = open(filename, 'r') lines = file.readlines() cregex = re.compile(r"""^.*nio_gen_eth:(\\device\\npf_{[a-fA-F0-9\-]*}).*""") niolist = [] for currentline in lines: currentline = currentline.lower().strip() match_obj = cregex.match(currentline) if match_obj and match_obj.group(1) not in niolist: niolist.append(match_obj.group(1)) self.rpcap_mapping.clear() niolist = set(niolist) if len(niolist): rpcaps = getWindowsInterfaces() interfaces = {} for rpcap in rpcaps: match = re.search(r"""^rpcap://(\\Device\\NPF_{[a-fA-F0-9\-]*})(.*)""", rpcap) interface_guid = str(match.group(1)).lower() interfaces[interface_guid] = unicode(match.group(2)).strip() name_match = re.search(r"""^\ :.*:\ (.+)""", match.group(2)) if name_match: interface_name = name_match.group(1) else: # The interface name could not be found, let's use the interface model instead model_match = re.search(r"""^\ :\ (.*)\ on local host:.*""", match.group(2)) if model_match: interface_name = model_match.group(1) else: interface_name = translate("DynagenSub", "Unknown name") self.rpcap_mapping['nio_gen_eth:' + interface_guid] = interface_name for nio in niolist: if not interfaces.has_key(nio): (selection, ok) = QtGui.QInputDialog.getItem(globals.GApp.mainWindow, translate("DynagenSub", "NIC binding"), translate("DynagenSub", "NIC ID %s cannot be found on this host\nPlease choose an alternate network interface:") % nio, interfaces.values(), 0, False) if ok: interface = "" for (key, name) in interfaces.iteritems(): if name == unicode(selection): interface = key break index = 0 for currentline in lines: match_obj = cregex.match(currentline.lower()) if match_obj: currentline = currentline.replace(nio, interface) lines[index] = currentline index += 1 else: continue file.close() if len(niolist): # write changes file = open(filename, 'w') for line in lines: file.write(line) file.close()