def HandleBullhornAnnouncement(self,node,rawData,fromAddr): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="Bullhorn"> # <Version>1.0</Version> # <UniqueID>3236</UniqueID> # <Hostname>pgkutch.beervana.net</Hostname> # <Key>md5 hash</Key> # <Port>5000</Port> #</Marvin> try: version = node.getElementsByTagName('Version')[0].firstChild.nodeValue Hash = node.getElementsByTagName('Key')[0].firstChild.nodeValue Port = node.getElementsByTagName('Port')[0].firstChild.nodeValue UniqueID = node.getElementsByTagName('UniqueID')[0].firstChild.nodeValue IP = fromAddr[0].lower() Hostname = node.getElementsByTagName('Hostname')[0].firstChild.nodeValue except Exception as _: Statistics.GetStatistics().OnMalformedPacketReceived("Received invalid Marvin Bullhorn Packet : " + rawData) return RemoteKey = Configuration.get().GetMarvinAutoConnectKeyFromHash(Hash) strID = Hostname + ":[" + IP + ":" + Port +"]" if None == RemoteKey: #don't have anything configured that matches Log.getLogger().warning("Received Marvin Dynamic Connection Message, with no corropsonding Key from: " + strID) return strID += " Key=" + RemoteKey HashMapKey = IP + ":" + str(Port) objExisting = TargetManager.GetTargetManager().GetDownstreamTarget(HashMapKey) if None == objExisting: # could be NDS name not resolved, so try by IP address objExisting = TargetManager.GetTargetManager().GetDownstreamTargetEx(IP,Port) if None != objExisting: if hasattr(objExisting,'_ReceivedOnUniqueID') and UniqueID != objExisting._ReceivedOnUniqueID: Log.getLogger().warning("Received Marvin Dynamic Connection Message, for already active connection: " + strID) else: pass # is simply the additional packets (marvin sends multiples as it is UDP traffic) return # doesn't already exist, so let's to add! if "1.0" == version: objTarget = Target.Target(IP,Port,ConnectionType.DynamicMarvin,True) else: objTarget = Target.Target(IP,Port,ConnectionType.DynamicOscar,True) objTarget._ReceivedOnUniqueID = UniqueID # so we can filter out dups due to UDP objTarget._UserKey = RemoteKey TargetManager.GetTargetManager().AddDownstreamTarget(objTarget,HashMapKey) Log.getLogger().info("Creating Dynamic Connection:" + strID) return
def HandleIncomingMinionConnectionInformation(self, node, rawData, fromAddr): #<?xml version="1.0" encoding="utf-8"?> #<Minion Type="ConnectionInformation"> # <Version>1.0</Version>" # <MinionVersion>17.02.12 Build 3</MinionVersion>" # <Namespace>NamespaceFoo</Namespace> # <Port>12345</Port> #</Minion> try: version = node.getElementsByTagName( 'Version')[0].firstChild.nodeValue except Exception as Ex: Statistics.GetStatistics().OnMalformedPacketReceived( "Received invalid Minion Connection Information Packet : " + rawData) return try: namespace = node.getElementsByTagName( 'Namespace')[0].firstChild.nodeValue namespace = namespace.lower() except Exception as Ex: Statistics.GetStatistics().OnMalformedPacketReceived( "Received invalid Minion ConnectionInformation Packet : " + rawData) return try: port = node.getElementsByTagName('Port')[0].firstChild.nodeValue except Exception as Ex: Statistics.GetStatistics().OnMalformedPacketReceived( "Received invalid Minion ConnectionInformation Packet : " + rawData) return IP = fromAddr[0].lower() TargetID = namespace + ":" + IP + ":" + port CP = TargetManager.GetTargetManager().GetUpstreamTarget(TargetID) if None == CP: objUpstreamTarget = Target.Target( IP, port, ConnectionPoint.ConnectionType.Minion, False) TargetManager.GetTargetManager().AddUpstreamTarget( objUpstreamTarget, TargetID) # add it as a upstream target for tasks and such try: minionVersion = node.getElementsByTagName( 'MinionVersion')[0].firstChild.nodeValue Log.getLogger().info("Received Connection from Minion " + TargetID + " version: " + minionVersion) except Exception as Ex: pass elif CP.Type != ConnectionPoint.ConnectionType.Minion: Statistics.GetStatistics().OnMalformedPacketReceived( "Unexpected Connection Type: " + str(CP.Type))
def HandleIncomingOscarConnectionInformation(self, node, rawData, fromAddress): #<?xml version="1.0" encoding="utf-8"?> #<Oscar Type="ConnectionInformation"> # <Version>1.0</Version> # <OccarVersion>16.11.21 Build 2</OscarVersion> # <ID>Foo</Foo> # <Port>Port</Port> #</Oscar> try: version = node.getElementsByTagName( 'Version')[0].firstChild.nodeValue ID = node.getElementsByTagName('ID')[0].firstChild.nodeValue Port = int( node.getElementsByTagName('Port')[0].firstChild.nodeValue) except Exception as Ex: Statistics.GetStatistics().OnMalformedPacketReceived( "Received invalid Oscar Connection Information Packet : " + rawData) return try: oscarVersion = node.getElementsByTagName( 'OscarVersion')[0].firstChild.nodeValue except Exception: oscarVersion = 'Unknown' IP = fromAddress[0].lower() Key = "Oscar:" + ID objTarget = TargetManager.GetTargetManager().GetUpstreamTarget( Key) # Chained Oscar, from Upstream # if None == objTarget: # objTarget = TargetManager.GetTargetManager().GetDownstreamTargetEx(IP,Port) # if using DNS, do lookup based on real IP, not DNS name if None == objTarget: Log.getLogger().info("Adding Upstream Oscar: " + Key + " version- " + oscarVersion) objTarget = Target.Target(IP, Port, ConnectionType.UpstreamOscar, False) TargetManager.GetTargetManager().AddUpstreamTarget(objTarget, Key) elif IP != objTarget.getIP() or Port != objTarget.getPort( ): #hmm, doesn't match, Oscar ID's current connection inf should be unique, so assume is an update from a restart of Oscar strOld = str(objTarget) objTarget.IP = IP objTarget.Port = Port Log.getLogger().warning( "Received a Oscar Connection Information Packet, with Different Connection Info from previously configured [" + ID + "] " + strOld + "--> " + str(objTarget))
def __ReadDownstreamTargets(self, domDoc): retList = [] nodeList = domDoc.getElementsByTagName("TargetConnection") if None != nodeList and len(nodeList) > 0: for node in nodeList: attributes = node.attributes if "IP" in attributes: IP = Alias.Alias(attributes["IP"].nodeValue) else: Log.getLogger().error("No Target IP specified") return False if "PORT" in attributes: try: Port = int(Alias.Alias(attributes["PORT"].nodeValue)) except Exception as Ex: Log.getLogger().error(str(Ex)) Log.getLogger().error( "Invalid Port set for Target Connection") return False else: Log.getLogger().error("No Target IP specified") return False connType = ConnectionType.Unknown objTarget = Target.Target( IP, Port, connType, True) # could be Marvin or another Oscar Key = IP + ":" + str(Port) TargetManager.GetTargetManager().AddDownstreamTarget( objTarget, Key) retList.append(Target) elif None == self.__DynamicConnectMarvinMap: Log.getLogger().error("TargetConnection not defined") return retList
def RescanTargets(self): try: if self.GetConfFileModificationInfo( ) == Configuration.modification_date(self.GetConfigFilename()): return filename = self.GetConfigFilename() Log.getLogger().info("Re-scanning config file: " + filename) self.__ConfigFileTimeStamp = Configuration.modification_date( filename) filename = self.GetConfigFilename() #open the xml file for reading: file = open(filename, 'r') #convert to string: data = file.read() #close file because we dont need it anymore: file.close() except: return try: domDoc = xml.dom.minidom.parseString(data) except Exception as ex: self.__HandleInvalidXML("Bad Content - XML error: " + str(ex)) return nodeList = domDoc.getElementsByTagName("TargetConnection") if None != nodeList and len(nodeList) > 0: for node in nodeList: attributes = node.attributes if "IP" in attributes: IP = Alias.Alias(attributes["IP"].nodeValue) else: Log.getLogger().error("No Target IP specified") return False if "PORT" in attributes: try: Port = int(Alias.Alias(attributes["PORT"].nodeValue)) except Exception as Ex: Log.getLogger().error(str(Ex)) Log.getLogger().error( "Invalid Port set for Target Connection") return False else: Log.getLogger().error("No Target IP specified") return False objTarget = Target.Target( IP, Port, ConnectionType.Unknown, True) # could be Marvin or another Oscar #Key = socket.gethostbyname(IP) + ":" +str(Port) Key = IP + ":" + str(Port) if not TargetManager.GetTargetManager().GetDownstreamTarget( Key): Log.getLogger().info("Adding new Downstream target: " + Key) TargetManager.GetTargetManager().AddDownstreamTarget( objTarget, Key)