Пример #1
0
 def test_xml_serialization(self):
     """
     test new serialization in contrast with legacy serializer to ensure compatibility
     """
     from FreeTAKServer.model.FTSModel.Event import Event
     xmlstring = '<event version="2.0" uid="GeoChat.ANDROID-359975090666199.FEATHER.27d8ef23-8578-4cb4-8f53-02f5dc150cd2" type="b-t-f" how="h-g-i-g-o" start="2021-01-03T19:01:35.472Z" time="2021-01-03T19:01:35.472Z" stale="2021-01-04T19:01:35.472Z"><detail><__chat id="S-1-5-21-2720623347-3037847324-4167270909-1002" parent="RootContactGroup" chatroom="FEATHER" groupOwner="false"><chatgrp uid0="ANDROID-359975090666199" uid1="S-1-5-21-2720623347-3037847324-4167270909-1002" id="S-1-5-21-2720623347-3037847324-4167270909-1002"/></__chat><link uid="ANDROID-359975090666199" relation="p-p" type="a-f-G-E-V-A"/><remarks time="2021-01-03T19:01:35.472Z" source="BAO.F.ATAK.ANDROID-359975090666199" to="S-1-5-21-2720623347-3037847324-4167270909-1002">at VDO</remarks><__serverdestination destinations="192.168.2.66:4242:tcp:ANDROID-359975090666199"/><marti><dest callsign = "WOLF"/><dest callsign="GALLOP"/><dest callsign="FEATHER"/></marti></detail><point le="9999999.0" ce="3.2" hae="22.958679722315807" lon="-66.10803" lat="43.855711"/></event>'
     fts_obj = XmlSerializer().from_format_to_fts_object(
         xmlstring, Event.GeoChat())
     obj = XmlSerializer().from_fts_object_to_format(fts_obj)
     print(etree.tostring(obj).decode())
     legacyftsobj = XMLCoTController().serialize_CoT_to_model(
         Event.GeoChat(), etree.fromstring(xmlstring))
     legacy_string = XMLCoTController().serialize_model_to_CoT(legacyftsobj)
     self.assertEqual(legacy_string.decode(), etree.tostring(obj).decode())
Пример #2
0
def test(json):
    modelObject = Event.dropPoint()
    out = XMLCoTController().serialize_CoT_to_model(modelObject,
                                                    etree.fromstring(json))
    xml = XMLCoTController().serialize_model_to_CoT(out, 'event')
    from FreeTAKServer.controllers.SpecificCoTControllers.SendDropPointController import SendDropPointController
    rawcot = RawCoT()
    rawcot.xmlString = xml
    rawcot.clientInformation = None
    object = SendDropPointController(rawcot)
    print(
        etree.tostring(object.sendDropPoint.xmlString,
                       pretty_print=True).decode())
    '''EventObject = json
Пример #3
0
 def __init__(self, json):
     tempObject = event.Presence()
     object = SendPresence()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(object.modelObject, json)
     object.setXmlString(XMLCoTController().serialize_model_to_CoT(object.modelObject))
     self.setCoTObject(object)
Пример #4
0
    def send_active_emergencys(self, client):
        """
        this function needs to be cleaned up however it's functionality is as follows
        it query's the DB for active emergency's at which point it iterates over all
        emergency objects, transforms them into model objects and then xmlStrings
        finally the object is sent to the client.
        """
        try:

            from FreeTAKServer.model.SpecificCoT.SendEmergency import SendEmergency
            emergencys = self.dbController.query_ActiveEmergency()
            for emergency in emergencys:
                emergencyobj = SendEmergency()
                modelObject = Event.emergecyOn()

                filledModelObject = SqlAlchemyObjectController(
                ).convert_sqlalchemy_to_modelobject(emergency.event,
                                                    modelObject)
                emergencyobj.setXmlString(
                    XMLCoTController().serialize_model_to_CoT(
                        filledModelObject))
                emergencyobj.setModelObject(filledModelObject)
                SendDataController().sendDataInQueue(None, emergencyobj,
                                                     [client])

        except Exception as e:
            self.logger.error(
                'an exception has been thrown in sending active emergencies ' +
                str(e))
Пример #5
0
 def __init__(self, json):
     tempObject = event.SimpleCoT()
     object = SendSimpleCoT()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(object.modelObject, json)
     DatabaseController().create_CoT(object.modelObject)
     object.setXmlString(XMLCoTController().serialize_model_to_CoT(object.modelObject))
     self.setCoTObject(object)
Пример #6
0
 def create_xml_string(self, modelObject):
     """
     this function calls the model to xml serializer within XMLCoTController
     with an instantiated model object supplied in the function argument
     """
     from FreeTAKServer.controllers.XMLCoTController import XMLCoTController
     try:
         xml = XMLCoTController().serialize_model_to_CoT(modelObject, 'event')
         return xml
     except Exception as e:
         logger.error('there has been an exception in the creation of the xml string ' +str(e))
         return -1
Пример #7
0
    def serialize_main_contentv1(self, protoobject, ftsobject):
        print('beginning serialization to FT')
        try:
            event = protoobject.event


            # the following try and except statements format milliseconds to CoT compatible DT
            try:
                datetime.datetime.strftime(datetime.datetime.strptime(str(datetime.datetime.fromtimestamp(float(event.sendTime) / 1000.0)), "%Y-%m-%d %H:%M:%S"), "%Y-%m-%dT %H:%M:%S.%fZ")
            except:
                datetime.datetime.strftime(datetime.datetime.strptime(str(datetime.datetime.fromtimestamp(float(event.sendTime) / 1000.0)), "%Y-%m-%d %H:%M:%S.%f"), "%Y-%m-%dT %H:%M:%S.%fZ")

            try:
                formatedDatatime = str(datetime.datetime.fromtimestamp(float(event.startTime) / 1000.0))
                datetime.datetime.strftime(datetime.datetime.strptime(formatedDatatime, "%Y-%m-%d %H:%M:%S"), "%Y-%m-%dT %H:%M:%S.%fZ")
            except Exception as e:
                formatedDatatime = str(datetime.datetime.fromtimestamp(float(event.startTime) / 1000.0))
                datetime.datetime.strftime(datetime.datetime.strptime(formatedDatatime, "%Y-%m-%d %H:%M:%S.%f"),"%Y-%m-%dT %H:%M:%S.%fZ")

            try:
                datetime.datetime.strftime(datetime.datetime.strptime(str(datetime.datetime.fromtimestamp(float(event.staleTime) / 1000.0)), "%Y-%m-%d %H:%M:%S"), "%Y-%m-%dT %H:%M:%S.%fZ")
            except:
                datetime.datetime.strftime(datetime.datetime.strptime(str(datetime.datetime.fromtimestamp(float(event.staleTime) / 1000.0)), "%Y-%m-%d %H:%M:%S.%f"), "%Y-%m-%dT %H:%M:%S.%fZ")

            ftsobject.setuid(event.uid)
            ftsobject.settype(event.type)
            ftsobject.sethow(event.coordSource)

            point = ftsobject.getpoint()
            point.setce(event.ce)
            point.setle(event.le)
            point.setlon(event.lon)
            point.setlat(event.lat)
            point.sethae(event.hae)

            ftsobject.setpoint(point)

            detail = event.other

            obj = SendFederatedCoT()
            obj.modelObject = ftsobject
            tempxmlstring = etree.fromstring(XMLCoTController().serialize_model_to_CoT(ftsobject))
            eventString = tempxmlstring
            eventString.append(etree.fromstring(detail.encode()))
            obj.xmlString = etree.tostring(eventString)
            print('serialized protobuf to ' + str(obj.xmlString))
            return obj
        except Exception as e:
            print(e)
            return -1
Пример #8
0
 def monitorRawCoT(self, data):
     # this needs to be the most robust function as it is the keystone of the program
     # this will attempt to define the type of CoT along with the designated controller
     try:
         if isinstance(data, int):
             return None
         else:
             CoT = XMLCoTController().determineCoTGeneral(data)
             function = getattr(self, CoT[0])
             output = function(CoT[1])
             return output
     except Exception as e:
         self.logger.error(loggingConstants.MONITORRAWCOTERRORB + str(e))
         return -1
Пример #9
0
 def test_xml_serialization(self):
     """
     test new serialization in contrast with legacy serializer to ensure compatibility
     """
     from FreeTAKServer.model.FTSModel.Event import Event
     # xmlstring = '<event version="2.0" uid="GeoChat.ANDROID-359975090666199.FEATHER.27d8ef23-8578-4cb4-8f53-02f5dc150cd2" type="b-t-f" how="h-g-i-g-o" start="2021-01-03T19:01:35.472Z" time="2021-01-03T19:01:35.472Z" stale="2021-01-04T19:01:35.472Z"><detail><__chat id="S-1-5-21-2720623347-3037847324-4167270909-1002" parent="RootContactGroup" chatroom="FEATHER" groupOwner="false"><chatgrp uid0="ANDROID-359975090666199" uid1="S-1-5-21-2720623347-3037847324-4167270909-1002" id="S-1-5-21-2720623347-3037847324-4167270909-1002"/></__chat><link uid="ANDROID-359975090666199" relation="p-p" type="a-f-G-E-V-A"/><remarks time="2021-01-03T19:01:35.472Z" source="BAO.F.ATAK.ANDROID-359975090666199" to="S-1-5-21-2720623347-3037847324-4167270909-1002">at VDO</remarks><__serverdestination destinations="192.168.2.66:4242:tcp:ANDROID-359975090666199"/><marti><dest callsign = "WOLF"/><dest callsign="GALLOP"/><dest callsign="FEATHER"/></marti></detail><point le="9999999.0" ce="3.2" hae="22.958679722315807" lon="-66.10803" lat="43.855711"/></event>'
     xmlstring = '<event version="2.0" uid="115e1a1a-9947-4531-801c-40215fa4888c" type="b-m-r" time="2021-03-17T21:53:08.07Z" start="2021-03-17T21:53:08.07Z" stale="2021-03-24T21:53:08.07Z" how="h-e"><point lat="0" lon="0" hae="0" ce="9999999" le="9999999" /><detail><contact callsign="Eliopoli/BOP" /><link uid="4eaf4026-8db6-48ef-83c2-063dd0120339" type="b-m-p-w" point="44.1644630, -65.7995800,85.84967474" callsign="Eliopoli/BOP SP" relation="c" remarks="" /><link uid="42882562-9dc6-481b-9c89-9a5ba96fbf57" type="b-m-p-w" point="43.9676310, -66.1266740,16.80836837" callsign="Eliopoli" relation="c" remarks="" /><link_attr color="-1" type="b-m-r" method="Driving" direction="Infil" routetype="Primary" order="Ascending Check Points" /></detail></event>'
     # fts_obj = XmlSerializer().from_format_to_fts_object(xmlstring, Event.GeoChat())
     fts_obj = XmlSerializer().from_format_to_fts_object(xmlstring, Event.Route())
     obj = XmlSerializer().from_fts_object_to_format(fts_obj)
     print(etree.tostring(obj).decode())
     # legacyftsobj = XMLCoTController().serialize_CoT_to_model(Event.GeoChat(), etree.fromstring(xmlstring))
     legacy_string = XMLCoTController().serialize_model_to_CoT(fts_obj)
     self.assertEqual(legacy_string.decode(), etree.tostring(obj).decode())
Пример #10
0
def SendGeoChat():
    try:
        json = request.json
        modelObject = Event.GeoChat()
        out = ApplyFullJsonController().serializeJsonToModel(modelObject, json)
        xml = XMLCoTController().serialize_model_to_CoT(out, 'event')
        from FreeTAKServer.controllers.SpecificCoTControllers.SendGeoChatController import SendGeoChatController
        rawcot = RawCoT()
        rawcot.xmlString = xml
        rawcot.clientInformation = None
        object = SendGeoChatController(rawcot)
        APIPipe.send(object.getObject())
        return '200', 200
    except Exception as e:
        print(e)
Пример #11
0
 def __init__(self, json):
     if isinstance(json, EmergencyPost):
         tempObject = event.emergecyOn()
     elif isinstance(json, EmergencyDelete):
         tempObject = event.emergecyOff()
     else:
         raise Exception(
             'unsupported object type passed under json argument')
     object = SendEmergency()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(
         object.modelObject, json)
     object.setXmlString(XMLCoTController().serialize_model_to_CoT(
         object.modelObject))
     self.setCoTObject(object)
Пример #12
0
    def test_xml_serialization(self):
        """
        test new serialization in contrast with legacy serializer to ensure compatibility
        """
        from FreeTAKServer.model.FTSModel.Event import Event
        # xmlstring = '<event version="2.0" uid="GeoChat.ANDROID-359975090666199.FEATHER.27d8ef23-8578-4cb4-8f53-02f5dc150cd2" type="b-t-f" how="h-g-i-g-o" start="2021-01-03T19:01:35.472Z" time="2021-01-03T19:01:35.472Z" stale="2021-01-04T19:01:35.472Z"><detail><__chat id="S-1-5-21-2720623347-3037847324-4167270909-1002" parent="RootContactGroup" chatroom="FEATHER" groupOwner="false"><chatgrp uid0="ANDROID-359975090666199" uid1="S-1-5-21-2720623347-3037847324-4167270909-1002" id="S-1-5-21-2720623347-3037847324-4167270909-1002"/></__chat><link uid="ANDROID-359975090666199" relation="p-p" type="a-f-G-E-V-A"/><remarks time="2021-01-03T19:01:35.472Z" source="BAO.F.ATAK.ANDROID-359975090666199" to="S-1-5-21-2720623347-3037847324-4167270909-1002">at VDO</remarks><__serverdestination destinations="192.168.2.66:4242:tcp:ANDROID-359975090666199"/><marti><dest callsign = "WOLF"/><dest callsign="GALLOP"/><dest callsign="FEATHER"/></marti></detail><point le="9999999.0" ce="3.2" hae="22.958679722315807" lon="-66.10803" lat="43.855711"/></event>'
        xmlstring = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><event version="2.0" uid="03Z0170972" type="a-f-A-M-H-Q" time="2021-06-17T19:08:19.699Z" start="2021-06-17T19:08:19.699Z" stale="2021-06-18T19:08:23.199Z" how="m-g"><point lat="43.85566678637877" lon="-66.10800161079035" hae="0.11165844181401496" ce="0.0" le="0.0" /><detail> <contact callsign="UAS-NOVA" /><sensor elevation="0.0" vfov="66.0" north="226.70000076293945" roll="0.0" range="300" azimuth="46.0" model="Phantom 3 Advanced Camera" fov="81.0" type="r-e" version="0.6" /></detail></event>'

        # fts_obj = XmlSerializer().from_format_to_fts_object(xmlstring, Event.GeoChat())
        fts_obj = XmlSerializer().from_format_to_fts_object(
            xmlstring, Event.DroneSensor())
        obj = XmlSerializer().from_fts_object_to_format(fts_obj)
        print(etree.tostring(obj).decode())
        # legacyftsobj = XMLCoTController().serialize_CoT_to_model(Event.GeoChat(), etree.fromstring(xmlstring))
        legacy_string = XMLCoTController().serialize_model_to_CoT(fts_obj)
        self.assertEqual(legacy_string.decode(), etree.tostring(obj).decode())
 def intstantiateClientInformationModelFromConnection(
         self, rawClientInformation, queue):
     try:
         tempObject = Event.Connection()
         self.clientInformation = ClientInformation()
         argument = "initialConnection"
         self.clientInformation.dataQueue = queue
         self.clientInformation.socket = rawClientInformation.socket
         self.clientInformation.IP = rawClientInformation.ip
         self.clientInformation.idData = rawClientInformation.xmlString
         self.clientInformation.alive = 1
         self.clientInformation.ID = uuid.uuid1().int
         self.clientInformation.modelObject = XMLCoTController(
         ).serialize_CoT_to_model(
             tempObject,
             etree.fromstring(rawClientInformation.xmlString.encode()))
         return self.clientInformation
     except Exception as e:
         logger.debug('error in client information controller ' + str(e))
         return -1
Пример #14
0
 def __init__(self):
     log_format = logging.Formatter(loggingConstants.LOGFORMAT)
     self.logger = logging.getLogger(loggingConstants.LOGNAME)
     self.logger.setLevel(logging.DEBUG)
     self.logger.addHandler(
         self.newHandler(loggingConstants.DEBUGLOG, logging.DEBUG,
                         log_format))
     self.logger.addHandler(
         self.newHandler(loggingConstants.ERRORLOG, logging.ERROR,
                         log_format))
     self.logger.addHandler(
         self.newHandler(loggingConstants.INFOLOG, logging.INFO,
                         log_format))
     # create necessary queues
     self.clientInformationQueue = []
     # this contains a list of all pipes which are transmitting CoT from clients
     self.pipeList = []
     # Internal Pipe used for CoT generated by the server itself
     self.internalCoTArray = []
     self.ClientReceptionHandlerEventPipe = ''
     # health check events
     self.healthCheckEventArray = []
     # instantiate controllers
     self.ActiveThreadsController = ActiveThreadsController()
     self.ClientInformationController = ClientInformationController()
     self.ClientInformationQueueController = ClientInformationQueueController(
     )
     self.ClientSendHandler = ClientSendHandler()
     self.DataQueueController = DataQueueController()
     self.ReceiveConnections = ReceiveConnections()
     self.ReceiveConnectionsProcessController = ReceiveConnectionsProcessController(
     )
     self.MainSocketController = MainSocketController()
     self.XMLCoTController = XMLCoTController()
     self.SendClientData = SendClientData()
     self.KillSwitch = 0
     self.openSockets = 0
     self.openSocketsArray = []
Пример #15
0
def updatetemplate(checklistid, taskid):
    from flask import request
    from defusedxml import ElementTree as etree
    from FreeTAKServer.controllers.SpecificCoTControllers.SendExcheckUpdateController import SendExcheckUpdateController
    from FreeTAKServer.controllers.XMLCoTController import XMLCoTController
    from FreeTAKServer.model.FTSModel.Event import Event
    from FreeTAKServer.model.RawCoT import RawCoT
    import uuid
    import hashlib

    data = request.data

    xml = etree.parse(
        str(
            PurePath(Path(MainConfig.ExCheckChecklistFilePath),
                     Path(checklistid + '.xml')))).getroot()
    updatedTask = etree.fromstring(data)
    tasks = xml.find('checklistTasks')
    for task in tasks:
        uid = task.find('uid')
        if uid.text == taskid:
            tasks.replace(task, updatedTask)
        else:
            pass
    with open(
            str(
                PurePath(Path(MainConfig.ExCheckChecklistFilePath),
                         Path(checklistid + '.xml'))), 'w+') as file:
        file.write(etree.tostring(xml).decode())
        file.close()

    # Create Object to send to client
    object = Event.ExcheckUpdate()
    object.setuid(str(uuid.uuid4()))
    object.setversion('2.0')
    object.detail.mission.settype("CHANGE")
    object.detail.mission.settool("ExCheck")
    object.detail.mission.setname(checklistid)
    object.detail.mission.setauthorUid(request.args.get("clientUid"))
    object.detail.mission.MissionChanges.MissionChange.creatorUid.setINTAG(
        request.args.get("clientUid"))
    object.detail.mission.MissionChanges.MissionChange.missionName.setINTAG(
        checklistid)
    object.detail.mission.MissionChanges.MissionChange.type.setINTAG(
        "ADD_CONTENT")
    object.detail.mission.MissionChanges.MissionChange.contentResource.filename.setINTAG(
        taskid + '.xml')
    object.detail.mission.MissionChanges.MissionChange.contentResource.hash.setINTAG(
        str(
            hashlib.sha256(
                str(
                    open(
                        MainConfig.ExCheckChecklistFilePath + '/' +
                        checklistid + '.xml', 'r')).encode()).hexdigest()))
    object.detail.mission.MissionChanges.MissionChange.contentResource.keywords.setINTAG(
        'Task')
    object.detail.mission.MissionChanges.MissionChange.contentResource.name.setINTAG(
        taskid)
    object.detail.mission.MissionChanges.MissionChange.contentResource.size.setINTAG(
        str(len(data)))
    #TODO: change this value
    object.detail.mission.MissionChanges.MissionChange.contentResource.submitter.setINTAG(
        'atak')
    object.detail.mission.MissionChanges.MissionChange.contentResource.uid.setINTAG(
        taskid)
    '''object = etree.fromstring(templateex)
    object.uid = uuid.uuid4()
    object.find('detail').find('mission').type= "CHANGE"
    object.find('detail').find('mission').name = taskid
    object.find('detail').find('mission').Uid = request.args.get("clientUid")
    object.find('detail').find('mission').find('MissionChanges').find('MissionChange').find('creatorUid').text = request.args.get("clientUid")
    object.find('detail').find('mission').find('MissionChanges').find('MissionChange').find('missionName').text = taskid
    object.find('detail').find('mission').find('MissionChanges').find('MissionChange').find('filename').text = checklistid+'.xml'
    object.detail.mission.MissionChanges.MissionChange.contentResource.hash.setINTAG(str(hashlib.sha256(str(data).encode()).hexdigest()))
    object.detail.mission.MissionChanges.MissionChange.contentResource.keywords.setINTAG('Task')
    object.detail.mission.MissionChanges.MissionChange.contentResource.name.setINTAG(checklistid)
    object.detail.mission.MissionChanges.MissionChange.contentResource.size.setINTAG(str(len(data)))
    #TODO: change this value
    object.detail.mission.MissionChanges.MissionChange.contentResource.submitter.setINTAG('test')
    object.detail.mission.MissionChanges.MissionChange.contentResource.uid.setINTAG(checklistid)'''
    rawcot = RawCoT()
    xml = XMLCoTController().serialize_model_to_CoT(object)
    rawcot.xmlString = xml

    PIPE.put(rawcot)
    #PIPE.send()

    return '', 200
Пример #16
0
                    self.setdest()
                    returnvalue = self.dest[self.__index]
                    return returnvalue
                else:
                    self.__index = 0
                    return self.dest[self.__index]
            except IndexError:
                self.__index = 0
                return self.dest[self.__index]

    def setdest(self, Dest=None):
        if not Dest:
            Dest = DestObject(self.__index)
        self.dest.append(Dest)
        self.__index += 1


if __name__ == "__main__":
    from FreeTAKServer.controllers.XMLCoTController import XMLCoTController
    from lxml import etree
    a = Marti.other()
    b = etree.fromstring(b'<marti><dest callsign = "bbbb"/></marti>')
    x = XMLCoTController().serialize_CoT_to_model(a, b)
    y = x.getdest().callsign
    print(a.__dict__)
    M = DestObject()
    M.setcallsign('13243432w')
    a.setdest(M)
    for x in a.dest:
        f = a.getdest()
    print('done')