def from_format_to_fts_object(self, object: type, FTSObject: Event) -> Event:
        for descriptor in object.event.DESCRIPTOR.fields:
            attribute_name = descriptor.name

            if attribute_name in self.attribute_name_mapping:
                attribute_name = self.attribute_name_mapping[attribute_name]

            if hasattr(FTSObject.detail, 'marti'):
                from FreeTAKServer.model.FTSModel.Dest import Dest

                for callsign in object.event.ptpCallsigns:
                    newdest = Dest()
                    newdest.setcallsign(callsign)
                    FTSObject.detail.marti.setdest(newdest)

            elif attribute_name != 'other' and attribute_name != '':

                setters = self._get_fts_object_var_setter(FTSObject, attribute_name)
                setter = self._get_method_in_method_list(setters, 'event')

                if attribute_name == 'time' or attribute_name == 'start' or attribute_name == 'stale':
                    import datetime
                    attribute = getattr(object.event, descriptor.name)
                    try:
                        setter(datetime.datetime.strftime(
                            datetime.datetime.strptime(str(datetime.datetime.fromtimestamp(float(attribute) / 1000.0)),
                                                       "%Y-%m-%d %H:%M:%S.%f"), "%Y-%m-%dT%H:%M:%S.%fZ"))
                        continue
                    except Exception as e:
                        setter(datetime.datetime.strftime(
                            datetime.datetime.strptime(str(datetime.datetime.fromtimestamp(float(attribute) / 1000.0)),
                                                       "%Y-%m-%d %H:%M:%S"), "%Y-%m-%dT%H:%M:%S.%fZ"))
                        continue
                else:
                    setter(getattr(object.event, descriptor.name))

            elif attribute_name == 'other' and object.event.other != '':
                from defusedxml import ElementTree as etree
                from lxml.etree import Element
                xmldetail = etree.fromstring(object.event.other)
                xmldetail.remove(xmldetail.find('_flow-tags_'))

                if xmldetail.find('remarks'):
                    XmlSerializer().from_format_to_fts_object(etree.tostring(xmldetail).decode(), FTSObject.detail)
                else:
                    xmldetail.append(Element('remarks'))
                    xmldetail.find('remarks').text = 'From federation '
                    XmlSerializer().from_format_to_fts_object(etree.tostring(xmldetail).decode(), FTSObject.detail)

        return FTSObject
Ejemplo n.º 2
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())
Ejemplo n.º 3
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())
Ejemplo n.º 4
0
 def test_to_protobuf_serialization(self):
     from FreeTAKServer.model.FTSModel.Event import Event
     xmlstring = '<event version="2.0" uid="ANDROID-R5CN70EYKQH" type="a-f-G-U-C" how="h-e" start="2020-12-24T18:16:22.325Z" time="2020-12-24T18:16:22.325Z" stale="2020-12-24T18:22:37.325Z"><detail><__group name="Teal" role="Team Member"/><status battery="76"/><takv version="4.2.0.4 (47e136dd).1607456856-CIV" platform="ATAK-CIV" device="SAMSUNG SM-N986U" os="29"/><track course="159.1462509079387" speed="0.0"/><contact callsign="SPAC3SLOTH" endpoint="*:-1:stcp" /><uid Droid="SPAC3SLOTH"/><precisionlocation altsrc="GPS" geopointsrc="GPS"/></detail><point le="9999999.0" ce="11.0" hae="178.84407323983876" lon="-76.675505" lat="39.664392"/></event>'
     fts_obj = XmlSerializer().from_format_to_fts_object(
         xmlstring, Event.Connection())
     y = ProtobufSerializer().from_fts_object_to_format(fts_obj)
     1 == 1
Ejemplo n.º 5
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
            from lxml import etree
            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.setXmlString(
                    etree.tostring((XmlSerializer().from_fts_object_to_format(
                        filledModelObject))))
                print(emergencyobj.xmlString)
                emergencyobj.setModelObject(filledModelObject)
                SendDataController().sendDataInQueue(None, emergencyobj,
                                                     [client])

        except Exception as e:
            import traceback
            self.logger.error(traceback.format_exc())
            self.logger.error(
                'an exception has been thrown in sending active emergencies ' +
                str(e))
Ejemplo n.º 6
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())
Ejemplo n.º 7
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(etree.tostring(XmlSerializer().from_fts_object_to_format(object.modelObject)))
     self.setCoTObject(object)
Ejemplo n.º 8
0
 def create_cot_object(
         self, serialized_json: dict, expected_fts_obj: Event,
         final_cot_object: Types.specific_cot) -> Types.specific_cot:
     fts_object = super().from_format_to_fts_object(serialized_json,
                                                    expected_fts_obj)
     CoTObject = final_cot_object
     CoTObject.setModelObject(fts_object)
     CoTObject.setXmlString(
         etree.tostring(
             XmlSerializer().from_fts_object_to_format(fts_object)))
     return CoTObject
Ejemplo n.º 9
0
    def main(self):
        from lxml import etree
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    pass
            else:
                pass
            try:
                data = self.receive_data_from_federate(1)
            except ssl.SSLWantReadError:
                data = None
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    # event = etree.Element('event')
                    # SpecificCoTObj = XMLCoTController().categorize_type(protobuf_object.type)
                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass
 def __init__(self, json):
     tempObject = event.Route()
     # tempObject.detail.setlink(None)
     # tempObject.detail.setlink(None)
     object = SendRoute()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(
         object.modelObject, json)
     object.setXmlString(
         tostring(XmlSerializer().from_fts_object_to_format(
             object.modelObject)))
     self.setCoTObject(object)
Ejemplo n.º 11
0
    def from_fts_object_to_format(self, FTSObject: Event) -> type:
        try:
            obj = FederatedEvent()
            if hasattr(FTSObject.detail, 'marti'):
                for dest in FTSObject.detail.marti.dest:
                    callsign = dest.getcallsign()
                    if callsign:
                        obj.event.ptpCallsigns.append(callsign)
                    else:
                        pass

            for descriptor in obj.event.DESCRIPTOR.fields:
                attribute_name = descriptor.name

                if attribute_name in self.attribute_name_mapping:
                    attribute_name = self.attribute_name_mapping[
                        attribute_name]

                if attribute_name != 'other' and attribute_name:
                    getters = self._get_fts_object_var_getter(
                        FTSObject, attribute_name)
                    getter = self._get_method_in_method_list(getters, 'event')

                    if attribute_name == 'time' or attribute_name == 'start' or attribute_name == 'stale':
                        import datetime
                        attribute = getter()
                        setattr(
                            obj.event, descriptor.name,
                            int(
                                datetime.datetime.strptime(
                                    attribute,
                                    "%Y-%m-%dT%H:%M:%S.%fZ").timestamp() *
                                1000))
                    elif attribute_name in [
                            'lat', 'lon', 'hae', 'ce', 'le', 'speed', 'course'
                    ]:
                        setattr(obj.event, descriptor.name, float(getter()))
                    elif attribute_name == 'battery':
                        setattr(obj.event, descriptor.name, int(getter()))
                    else:
                        setattr(obj.event, descriptor.name, getter())

                else:
                    from lxml import etree
                    xmldetail = etree.tostring(
                        XmlSerializer().from_fts_object_to_format(
                            FTSObject.detail)).decode()
                    setattr(obj.event, 'other', xmldetail)

            return obj
        except Exception as e:
            raise e
Ejemplo n.º 12
0
 def test_from_protobuf_serialization(self):
     from FreeTAKServer.model.FTSModel.Event import Event
     from FreeTAKServer.model.protobufModel.fig_pb2 import FederatedEvent
     import lxml
     protobufString = b'\n\x83\x04\x08\xbe\xb9\xfb\x85\xeb.\x10\xbe\xb9\xfb\x85\xeb.\x18\x96\xab\x92\x86\xeb.!\xaf\xf6b\x88\\d<@) {Mcr\x1aG\xc01\x00\x00\x00\xe0\xcf\x12cA9\x00\x00\x00\xe0\xcf\x12cAA\x00\x00\x00\xe0\xcf\x12cAJ.S-1-5-21-2720623347-3037847324-4167270909-1002R\x0ba-f-G-U-C-IZ\x03h-eb\xfa\x02<detail><takv version="4.0.0.117" platform="WinTAK-CIV" os="Microsoft Windows 10 Home" device="Micro-Star International Co., Ltd MS-7C02"/><contact callsign="FEATHER" endpoint="*:-1:stcp"/><uid Droid="FEATHER"/><__group name="Cyan" role="Team Member"/><_flow-tags_ TAK-Server-c0581fed97ff4cb89eb8666a8794670cc9f77ddb-badf-48da-abe7-84545ecda69d="2020-12-29T23:04:27Z"/></detail>hd'
     # protobufString2 = b'"\x00\x00\x00="\x12;\x08\x01\x12.S-1-5-21-2720623347-3037847324-4167270909-1002\x1a\x07FEATHER'
     protobufObj = FederatedEvent()
     protobufObj.ParseFromString(protobufString)
     # protobufObj.ParseFromString(protobufString2)
     #y = [name.name for name in protobufObj.event.DESCRIPTOR.fields]
     fts_obj = ProtobufSerializer().from_format_to_fts_object(protobufObj, Event.Connection())
     z = lxml.etree.tostring(XmlSerializer().from_fts_object_to_format(fts_obj))
     1 == 1
    def main(self):
        from defusedxml import ElementTree as etree
        import time
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    logger.debug("exception in command chain " + str(e))
            else:
                pass

            data = self.receive_data_from_federate(1)
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass
Ejemplo n.º 14
0
 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 = XmlSerializer(
         ).from_format_to_fts_object(
             rawClientInformation.xmlString.encode(), tempObject)
         return self.clientInformation
     except Exception as e:
         logger.debug('error in client information controller ' + str(e))
         return -1