Пример #1
0
    def handel_connection_data(self, receiveConnectionOutput):
        try:
            print('handling conn data')
            if receiveConnectionOutput == -1:
                return None

            CoTOutput = self.monitorRawCoT(receiveConnectionOutput)
            if CoTOutput != -1 and CoTOutput != None:
                output = SendDataController().sendDataInQueue(
                    CoTOutput, CoTOutput, self.clientInformationQueue,
                    self.CoTSharePipe)
                if self.checkOutput(output):
                    self.logger.debug(
                        'connection data from client ' +
                        str(CoTOutput.modelObject.detail.contact.callsign) +
                        ' successfully processed')
                else:
                    raise Exception('error in sending data')
            else:
                pass
        except Exception as e:
            self.logger.error(
                'exception in receive connection data processing within main run function '
                + str(e) + ' data is ' + str(CoTOutput))
            return -1
        self.sendInternalCoT(CoTOutput)
        return 1
Пример #2
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))
Пример #3
0
    def handel_shared_data(self, modelData):
        try:
            print('data received within orchestrator ' +
                  str(modelData.xmlString))
            if hasattr(modelData, 'clientInformation'):
                output = SendDataController().sendDataInQueue(
                    modelData.clientInformation, modelData,
                    self.clientInformationQueue)
            #

            elif modelData.type == "connmessage":
                self.internalCoTArray.append(modelData)

            # this runs in the event of a new connection
            else:
                output = SendDataController().sendDataInQueue(
                    None, modelData, self.clientInformationQueue)
        except Exception as e:
            print(e)
Пример #4
0
 def sendInternalCoT(self, client):
     try:
         if len(self.internalCoTArray) > 0:
             for processedCoT in self.internalCoTArray:
                 SendDataController().sendDataInQueue(
                     processedCoT.clientInformation, processedCoT, [client])
         else:
             pass
         self.send_active_emergencys(client)
         return 1
     except Exception as e:
         self.logger.error(
             loggingConstants.MONITORRAWCOTERRORINTERNALSCANERROR + str(e))
         return -1
Пример #5
0
    def handel_regular_data(self, clientDataOutput):
        try:
            for clientDataOutputSingle in clientDataOutput:
                try:
                    print('handling reg data')
                    if clientDataOutputSingle == -1:
                        continue
                    CoTOutput = self.monitorRawCoT(clientDataOutputSingle)
                    if CoTOutput == 1:
                        continue
                    elif self.checkOutput(CoTOutput):
                        output = SendDataController().sendDataInQueue(
                            CoTOutput.clientInformation, CoTOutput,
                            self.clientInformationQueue, self.CoTSharePipe)
                        if self.checkOutput(output) and isinstance(
                                output, tuple) == False:
                            pass
                        elif isinstance(output, tuple):
                            self.logger.error(
                                'issue sending data to client now disconnecting'
                            )
                            self.clientDisconnected(output[1])

                        else:
                            self.logger.error(
                                'send data failed in main run function with data '
                                + str(CoTOutput.xmlString) + ' from client ' +
                                CoTOutput.clientInformation.modelObject.detail.
                                contact.callsign)

                    else:
                        raise Exception('error in general data processing')
                except Exception as e:
                    self.logger.info(
                        'exception in client data, data processing within main run function '
                        + str(e) + ' data is ' + str(CoTOutput))
                    pass
                except Exception as e:
                    self.logger.info(
                        'exception in client data, data processing within main run function '
                        + str(e) + ' data is ' + str(clientDataOutput))
        except Exception as e:
            self.logger.info(
                "there has been an error iterating client data output " +
                str(e))
            return -1
        return 1
Пример #6
0
    def sendUserConnectionGeoChat(self, clientInformation):
        # TODO: refactor as it has a proper implementation of a PM to a user generated by the server
        '''
        function to create and send pm to connecting user
        :param clientInformation:
        :return:
        '''
        from FreeTAKServer.controllers.SpecificCoTControllers.SendGeoChatController import SendGeoChatController
        from FreeTAKServer.model.RawCoT import RawCoT
        from FreeTAKServer.model.FTSModel.Dest import Dest
        import uuid
        if OrchestratorConstants().DEFAULTCONNECTIONGEOCHATOBJ != None:
            ChatObj = RawCoT()
            ChatObj.xmlString = f'<event><point/><detail><remarks>{OrchestratorConstants().DEFAULTCONNECTIONGEOCHATOBJ}</remarks><marti><dest/></marti></detail></event>'

            classobj = SendGeoChatController(ChatObj, AddToDB=False)
            instobj = classobj.getObject()
            instobj.modelObject.detail._chat.chatgrp.setuid1(
                clientInformation.modelObject.uid)
            dest = Dest()
            dest.setcallsign(
                clientInformation.modelObject.detail.contact.callsign)
            instobj.modelObject.detail.marti.setdest(dest)
            instobj.modelObject.detail._chat.setchatroom(
                clientInformation.modelObject.detail.contact.callsign)
            instobj.modelObject.detail._chat.setparent("RootContactGroup")
            instobj.modelObject.detail._chat.setid(
                clientInformation.modelObject.uid)
            instobj.modelObject.detail._chat.setgroupOwner("True")
            instobj.modelObject.detail.remarks.setto(
                clientInformation.modelObject.uid)
            instobj.modelObject.setuid(
                'GeoChat.' + 'SERVER-UID.' +
                clientInformation.modelObject.detail.contact.callsign + '.' +
                str(uuid.uuid1()))
            instobj.modelObject.detail._chat.chatgrp.setid(
                clientInformation.modelObject.uid)
            classobj.reloadXmlString()
            SendDataController().sendDataInQueue(None, instobj,
                                                 self.clientInformationQueue)
            return 1
        else:
            return 1
Пример #7
0
    def clientDisconnected(self, clientInformation):
        if hasattr(clientInformation, "clientInformation"):
            clientInformation = clientInformation.clientInformation
        try:
            for client in self.clientInformationQueue:
                if client.ID == clientInformation.ID:
                    self.clientInformationQueue.remove(client)
                else:
                    pass
        except AttributeError:
            for client in self.clientInformationQueue:
                if client.ID == clientInformation.clientInformation.ID:
                    self.clientInformationQueue.remove(client)
                else:
                    pass
        except Exception as e:
            self.logger.critical("client removal failed " + str(e))
        try:
            self.ActiveThreadsController.removeClientThread(clientInformation)
            self.dbController.remove_user(
                query=f'uid = "{clientInformation.modelObject.uid}"')
        except Exception as e:
            self.logger.critical(
                'there has been an error in a clients disconnection while adding information to the database '
                + str(e))
            pass
        if hasattr(clientInformation, 'clientInformation'):
            clientInformation = clientInformation.clientInformation
        else:
            pass
        try:
            self.openSockets -= 1
            socketa = clientInformation.socket
            clientInformation.socket = None
            self.clientDataPipe.put(
                ['remove', clientInformation, self.openSockets])
            clientInformation.socket = socketa
            try:
                clientInformation.socket.shutdown(socket.SHUT_RDWR)
            except Exception as e:
                self.logger.error(
                    'error shutting socket down in client disconnection')
                pass
            try:
                clientInformation.socket.close()
            except Exception as e:
                self.logger.error(
                    'error closing socket in client disconnection')
                pass

            self.logger.info(loggingConstants.CLIENTDISCONNECTSTART)
            # TODO: remove string
            tempXml = RawCoT()
            tempXml.xmlString = '<event><detail><link uid="{0}"/></detail></event>'.format(
                clientInformation.modelObject.uid).encode()
            disconnect = SendDisconnectController(tempXml)
            SendDataController().sendDataInQueue(
                disconnect.getObject().clientInformation,
                disconnect.getObject(), self.clientInformationQueue,
                self.CoTSharePipe)
            self.logger.info(
                loggingConstants.CLIENTDISCONNECTEND +
                str(clientInformation.modelObject.detail.contact.callsign))
            return 1
        except Exception as e:
            self.logger.error(loggingConstants.CLIENTCONNECTEDERROR + " " +
                              str(e))
            pass
Пример #8
0
    def clientDisconnected(self, clientInformation):
        import time
        import traceback
        from copy import deepcopy
        print(str(traceback.format_stack()))
        print('disconnecting client')
        if hasattr(clientInformation, "clientInformation"):
            clientInformation = clientInformation.clientInformation
        """try:
            clientInformation.socket.send(b'sample')
            return 1
        except:
            try:
                clientInformation.socket.settimeout(0)
                if clientInformation.socket.recv() == b'':
                    pass
                else:
                    return 1
            except:
                return 1"""
        try:
            for client in self.clientInformationQueue:
                if client.ID == clientInformation.ID:
                    self.clientInformationQueue.remove(client)
                else:
                    pass
        except AttributeError:
            for client in self.clientInformationQueue:
                if client.ID == clientInformation.clientInformation.ID:
                    self.clientInformationQueue.remove(client)
                else:
                    pass
        except Exception as e:
            self.logger.critical("client removal failed " + str(e))
        print('stage 1')
        #time.sleep(1)
        try:
            self.ActiveThreadsController.removeClientThread(clientInformation)
            self.dbController.remove_user(
                query=f'uid = "{clientInformation.modelObject.uid}"')
        except Exception as e:
            self.logger.critical(
                'there has been an error in a clients disconnection while adding information to the database '
                + str(e))
            pass
        print('stage 1 a')
        if hasattr(clientInformation, 'clientInformation'):
            clientInformation = clientInformation.clientInformation
        else:
            pass
        try:
            self.openSockets -= 1
            socketa = clientInformation.socket
            clientInformation.socket = None
            clientInformationcopy = deepcopy(clientInformation)
            print('stage 1 b')
            #time.sleep(1)
            if clientInformationcopy.socket == None:
                self.clientDataPipe.put(
                    ['remove', clientInformationcopy, self.openSockets])
            #working
            #time.sleep(1)
            print('stage 1 c')
            clientInformation.socket = socketa
            try:
                clientInformation.socket.shutdown(socket.SHUT_RDWR)
            except Exception as e:
                self.logger.error(
                    'error shutting socket down in client disconnection')
                pass
            try:
                clientInformation.socket.close()
            except Exception as e:
                self.logger.error(
                    'error closing socket in client disconnection')
                pass
            #time.sleep(1)
            print('stage 2')

            self.logger.info(loggingConstants.CLIENTDISCONNECTSTART)
            # TODO: remove string
            tempXml = RawCoT()
            tempXml.xmlString = '<event><detail><link uid="{0}"/></detail></event>'.format(
                clientInformation.modelObject.uid).encode()
            disconnect = SendDisconnectController(tempXml)
            print('stage 3')
            #working
            #time.sleep(1)
            SendDataController().sendDataInQueue(
                disconnect.getObject().clientInformation,
                disconnect.getObject(), self.clientInformationQueue,
                self.CoTSharePipe)
            self.logger.info(
                loggingConstants.CLIENTDISCONNECTEND +
                str(clientInformation.modelObject.detail.contact.callsign))
            print('client disconnected')
            return 1
        except Exception as e:
            print(e)
            self.logger.error(loggingConstants.CLIENTCONNECTEDERROR + " " +
                              str(e))
            pass