Exemple #1
0
 def __init__(self, queryServer=None):
     ##ugur
     self.rpclogger = createLogger('RPC')
     self.rpclogger.info('Starting JSONRPCServer')
     self.queryServer = queryServer
     self.queryManager = QueryManager(
         store=self.queryServer.createStore(),
         sources=self.queryServer.config.sources,
         plugins=self.queryServer.config.plugins)
Exemple #2
0
 def refresh_server_list(self, liststore, tab):
     """
     Refreshes the Serverlist of a tab
     
     @param liststore - the liststore which contains the servers to be 
                        refreshed
     @param tab - the tab requesting the refresh
     """
     Log.log.debug('[GuiController] refresh_server_list called...')
     qm = QueryManager()
     tab.set_querymanager(qm)
     qm.start_serverlist_refresh(liststore, tab)
Exemple #3
0
    def loadRecentServer(self, tab):
        """
        Loads the list of recent servers from a file using the FileManager
        and update the serverlist on the requesting tab. All of this is done
        on background threads using the QueryManager

        
        @param tab - the tab requesting the recent server list
        """
        Log.log.debug('[GuiController] loadRecentServer called...')
        gobject.idle_add(tab.clearServerList)
        qm = QueryManager()
        tab.set_querymanager(qm)
        qm.startRecentServersLoadingThread(tab)
Exemple #4
0
 def lookup_server(self, server, tab):
     """
     This method performs a lookup of a certain server. Its like a search
     with the adress as paremeter so it clears the serverlist on the 
     requesting tab and only adds the server object with the looked up 
     data to the list afterwards.
     
     @param server - the server to be looked up
     @param tab - the requesting tab
     """
     #clear the serverlist on the tab
     tab.serverlist.clear()
     
     #start the lookup in an extra thread using the querymanager
     qm = QueryManager()
     qm.lookup_server(server, tab)
Exemple #5
0
 def loadMasterServerList(self, serverlistfilter, tab):
     """
     Loads the Serverlist from the masterserver.
     This method is executed in a background thread which is triggered by 
     the executeMasterServerQuery method
     
     @param serverlistfilter - instance of the serverlistfilter profiding
                               query and filter paramters
     @tab - the tab requesting the serverlist
     """
     Log.log.debug('[GuiController] loadMasterServerList called...')
     #clear the current serverlist
     gobject.idle_add(tab.clearServerList)
     
     #perform the master server query
     qm = QueryManager()
     tab.set_querymanager(qm)
     qm.startMasterServerQueryThread(serverlistfilter, tab)
Exemple #6
0
 def __init__(self, queryServer = None):
     ##ugur
     self.rpclogger = createLogger('RPC')
     self.rpclogger.info('Starting JSONRPCServer')
     self.queryServer = queryServer
     self.queryManager = QueryManager(store=self.queryServer.createStore(), sources=self.queryServer.config.sources, plugins=self.queryServer.config.plugins)
Exemple #7
0
class jsonRPCServer(jsonrpc.JSONRPC):
    """
    An example object to be published.
    """

    def __init__(self, queryServer = None):
        ##ugur
        self.rpclogger = createLogger('RPC')
        self.rpclogger.info('Starting JSONRPCServer')
        self.queryServer = queryServer
        self.queryManager = QueryManager(store=self.queryServer.createStore(), sources=self.queryServer.config.sources, plugins=self.queryServer.config.plugins)

    def render(self, request):
        # check if db connection is lost or not!
        self.queryManager.setStore(self.queryServer.dbEnsureConnected(self.queryManager.store))
        return (jsonrpc.JSONRPC.render(self, request))

    def jsonrpc_push_alerts(self, plugin_ip, query_id_list, start_time, end_time):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.queryManager.pushAlerts(plugin_ip, query_id_list, start_time, end_time)

    def jsonrpc_push_statistics(self, plugin_id, query_id, number_of_flows, number_of_bytes, number_of_packets, time_window):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.queryManager.pushStatistics(plugin_ip, query_id_list, start_time, end_time)

    def jsonrpc_register(self,plugin_ip):
        result = []
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        # DEBUG mode da hangi fieldlarin hatali geldigini yazdirabiliriz tabiki sadece query server ' a.
        plugin = self.queryManager.store.find(Plugin, Plugin.plugin_ip == plugin_ip).one()
        #TODO Anywhere plugins registered flags not set. Flags must be define.
        if plugin is None:
            result.append(0);
            return result
        else:
            if plugin.registered == 1:
                result.append(1)
                return result
            if plugin.registered == 2:
                result.append(2)
                return result
            if plugin.registered == 3:
                result.append(3)
                return result
        return result
#    print organization
#    print prefix_list
#    print plugin_ip
#    print adm_publickey_file
#    print adm_tel
#    print adm_name
#    print adm_mail
#        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
#        # DEBUG mode da hangi fieldlarin hatali geldigini yazdirabiliriz tabiki sadece query server ' a.
#        #print "Registration information : %s,%s,%s,%s,%s,%s,%s" % (organization, adm_name, adm_mail, adm_tel, adm_publickey, prefix_list, plugin_ip)
#        self.store = db.get_store()
#        plugin = self.store.find(Plugin, Plugin.organization == unicode(organization)).one()
#        if plugin is None:
#            message =  'Your plugin is not registered to QueryServer yet.'
#            message += 'Plugin is not found.'
#            message += 'Please ask to QS Administrator about your registration process.'
#            self.rpclogger.info("AAAAAAAAAAa")
#            print message
#        result.append(0)
#        print result
#            return result
#        else:
#            checksum = hashlib.md5()
#            checksum.update( organization + adm_name + adm_mail +
#                             adm_tel      + adm_publickey_file  +
#                             prefix_list  + plugin_ip )
#            if checksum.hexdigest() != plugin.checksum:
#                message = 'Your plugin information doesn\'t match with the QueryServer side.'
#                message += 'Plugin Checksum Error'
#                message += 'Please check your information and try again.'
#            result.append(1)
#            print result
#                return result
#               # print message
#            elif checksum.hexdigest() == plugin.checksum:
#                # Set the plugin registered
#                plugin.registered = True
#                self.store.add(plugin)
#                self.store.commit()
#                message =  'Your plugin is registered.\n'
#                message += 'Feel free to checkout query subscriptions.'
#                #print message
#            result.append(2)
#            print result
#                return result
#                #return self.jsonrpc_get_subscriptions()

    def jsonrpc_get_statistics(self, alert_id):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        result = self.queryManager.getStatistics(alert_id)
        return result

    def jsonrpc_get_topn_query(self, n):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        result = self.queryManager.getTopNQuery(n)
        return result


    def jsonrpc_get_query_filter(self,query_id):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('returning query filter')
        return self.queryManager.getFilter(query_id)


    def jsonrpc_get_subscription_detail(self, subscription):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('returning subscriptions detail')
        return self.queryManager.getSubscription(subscription)

    def jsonrpc_get_subscriptions(self):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('returning subscriptions')
        subs = self.queryManager.getAllSubscriptions()
        return subs


    def jsonrpc_get_subscription(self, name, method_call):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting subscription information')
        return self.queryManager.getSubscription(name, method_call)



    def jsonrpc_get_all_prefixes(self):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting all prefix list information')
        plugin_list = self.queryManager.store.find(Plugin)
        prefix_list = {}
        for plugin in plugin_list:
            prefix_list[plugin.id] = plugin.prefix.prefix.replace(" ","").split(',')
        print prefix_list
        return prefix_list


    def jsonrpc_get_plugin_id(self, ip_address):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting plugin id of ip address')
        return self.queryManager.getPluginId(ip_address)

    def jsonrpc_get_prefixes(self, ip_address):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting prefix list information')
        plugin = self.queryManager.store.find( Plugin,
                                     Plugin.plugin_ip == unicode(ip_address)
                                   ).one()
        if not plugin:
            self.rpclogger.warning('Plugin ip is not correct')
            self.rpclogger.warning('Can not return prefix list')
            return
        else:
             p_list = {}
             p_list[plugin.id] = plugin.prefix.prefix.replace(" ","").split(',')
             return p_list


    def jsonrpc_get_alert(self, alert):
        print '\n'
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        result = self.queryManager.registerAlert(alert)
        return result

    def jsonrpc_get_my_alerts(self, plugin_ip):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        return self.queryManager.getMyAlerts(plugin_ip)

    def jsonrpc_generate_query(self, query_info_list, mandatory, plugin_ip):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        return self.queryManager.generateQuery(query_info_list, mandatory, plugin_ip)
Exemple #8
0
 def migrate(self):
     if not os.path.isfile(self.dbFileName):
         return True
 
     encrypted = self.hasEncryptedDB()
     if encrypted:
         return True
     
     #move old db
     oldDBFilename = self.dbFileName + ".old.sqlite"
     os.rename(self.dbFileName, oldDBFilename)
     self.queryManagerOldDB = QueryManager(oldDBFilename,self.publicEncryptionKey, useAPSW=False)
     
         
     #create new db
     self.queryManagerNewDB = QueryManager(self.dbFileName,self.publicEncryptionKey, useAPSW=True)
     #self.queryManagerNewDB.executeQuery("INTO         
     
     centreCodeResults = self.queryManagerOldDB.sendQuery("SELECT * FROM admission")
     #if we have no admissions we cannot get centre code. Data upgrade is useless (NO ADMISSIONS)
     if not len(centreCodeResults):
         return
     
     self.centreCode = centreCodeResults[0]['centreCode']        
     patientClassNames = ['firstName', 'lastName', 'gender', 'birthDate', 'placeOfBirth', 'nhsNumber', 'blood', 'address', 'ehrId']
     
     self.queryManagerNewDB.sendQuery('BEGIN TRANSACTION')
     
     #ADMISSION TABLE
     print "Updating admission table"
     admissionItems = self.queryManagerOldDB.sendQuery("SELECT * FROM admission")
     newAdmissionItems = []
     
     for admissionItem in admissionItems:
         newAdmissionItem = admissionItem
         newAdmissionItem['admissionKey'] = 'A-'+ newAdmissionItem['admissionKey']
         newAdmissionItem['patientKey'] = 'P-'+ newAdmissionItem['patientKey']
         if newAdmissionItem['previousAdmissionKey'] != '':
             newAdmissionItem['previousAdmissionKey'] = 'A-'+ newAdmissionItem['previousAdmissionKey']
         newAdmissionItems.append(newAdmissionItem)
         
     queryAdmission = "INSERT INTO admission(localId, admissionKey, patientKey, centreCode, inputUserKey, inputDate, previousAdmissionKey) VALUES(:localId, :admissionKey, :patientKey, :centreCode, :inputUserKey, :inputDate, :previousAdmissionKey)"
     self.queryManagerNewDB.sendQuery(queryAdmission, bindingList=newAdmissionItems)
         
     #ADMISSION DELETED TABLE
     print "Updating admissionDeleted table"
     admissionDeletedItems = self.queryManagerOldDB.sendQuery("SELECT * FROM admissionDeleted")
     newAdmissionDeletedItems = []
     
     if len (admissionDeletedItems):
         for admissionDeletedItem in admissionDeletedItems:
             newAdmissionDeletedItem = admissionDeletedItem
             newAdmissionDeletedItem['admissionKey'] = 'A-' + newAdmissionDeletedItem['admissionKey']
             newAdmissionDeletedItem['centreCode'] = self.centreCode
             newAdmissionDeletedItems.append(newAdmissionDeletedItem)
             
         
         queryAdmissionDeleted = "INSERT INTO admissionDeleted (admissionKey, idReason, deleteUserKey, centreCode, deleteDate) VALUES (:admissionKey, :idReason, :deleteUserKey, :centreCode, :deleteDate)" 
         self.queryManagerNewDB.sendQuery(queryAdmissionDeleted, bindingList=newAdmissionDeletedItems)
         
     #attributeData TABLE
     print "Updating attributeData table"
     attributeDataItems = self.queryManagerOldDB.sendQuery("SELECT * FROM attributeData ORDER BY inputDate")
     newAttributeDataItems = []
     
     localId = 1
     
     for attributeDataItem in attributeDataItems:
         newAttributeDataItem = attributeDataItem
         newAttributeDataItem['centreCode'] = self.centreCode 
         newAttributeDataItem['value'] = str(newAttributeDataItem['value'])
         
         if newAttributeDataItem['className'] in patientClassNames:
             newAttributeDataItem['value'] = base64.b64encode(newAttributeDataItem['value'])
         else:
             newAttributeDataItem['value'] = base64.b64encode(newAttributeDataItem['value'])
         
         newAttributeDataItem['objectCode'] = newAttributeDataItem['objectCode'].split('-')[-1]    
         newAttributeDataItem['localId'] = localId
         localId += 1
         newAttributeDataItems.append(newAttributeDataItem)
         
         
     queryAttributeData = "INSERT INTO attributeData(objectCode, crfName, className, attributeName, value, multiInstanceNumber, inputUserKey, localId, centreCode, inputDate) VALUES (:objectCode, :crfName, :className, :attributeName, :value, :multiInstanceNumber, :inputUserKey, :localId, :centreCode, :inputDate)"
     self.queryManagerNewDB.sendQuery(queryAttributeData, bindingList=newAttributeDataItems)
     
     
     print "Updating crfStatus table"
     crfStatusItems = self.queryManagerOldDB.sendQuery("SELECT * FROM crfStatus")
     newCrfStatusItems = []
     
     for crfStatusItem in crfStatusItems:
         newCrfStatusItem = crfStatusItem
         newCrfStatusItem['centreCode'] = self.centreCode
         newCrfStatusItem['admissionKey'] = 'A-' + newCrfStatusItem['admissionKey']
         newCrfStatusItem['localId'] = 1
         newCrfStatusItem['inputDate'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
         newCrfStatusItems.append(newCrfStatusItem)
         
     queryCrfStatus = "INSERT INTO crfStatus (admissionKey, crfName, statusValue, crfVersion, centreCode, localId, inputDate) VALUES (:admissionKey, :crfName, :statusValue, :crfVersion, :centreCode, :localId, :inputDate)"
     self.queryManagerNewDB.sendQuery(queryCrfStatus, bindingList=newCrfStatusItems)
     
     #objectData TABLE
     print "Updating objectData table"
     objectDataItems = self.queryManagerOldDB.sendQuery("SELECT * FROM objectData")
     newObjectDataItems = []
     
     
     for objectDataItem in objectDataItems:
         newObjectDataItem = objectDataItem
         newObjectDataItem['objectCode'] = newObjectDataItem['localId']
         newObjectDataItem['centreCode'] = self.centreCode
         if newObjectDataItem['className'] in patientClassNames:
             newObjectDataItem['externalKey'] = "P-" + newObjectDataItem['externalKey']
         else:
             newObjectDataItem['externalKey'] = "A-" + newObjectDataItem['externalKey']
         newObjectDataItems.append(newObjectDataItem)
         
     queryObjectData = "INSERT INTO objectData(objectCode, multiInstanceNumber, idActionReason, externalKey, crfName, className, inputUserKey, inputDate, centreCode, crfVersion) VALUES (:objectCode, :multiInstanceNumber, :idActionReason, :externalKey, :crfName, :className, :inputUserKey, :inputDate, :centreCode, :crfVersion)"
     self.queryManagerNewDB.sendQuery(queryObjectData, bindingList=newObjectDataItems)
     
     #patient TABLE
     print "Updating patient table"
     patientItems = self.queryManagerOldDB.sendQuery("SELECT * FROM patient")
     newPatientItems = []
     
     for patientItem in patientItems:
         newPatientItem = patientItem
         newPatientItem['patientKey'] = 'P-'+ newPatientItem['patientKey']
         newPatientItems.append(newPatientItem)
         
     queryPatient = "INSERT INTO patient(localId, patientKey, centreCode, inputUserKey, inputDate) VALUES(:localId, :patientKey, :centreCode, :inputUserKey, :inputDate)"
     self.queryManagerNewDB.sendQuery(queryPatient, bindingList=newPatientItems)
     
     self.queryManagerNewDB.sendQuery('COMMIT TRANSACTION')
Exemple #9
0
class jsonRPCServer(jsonrpc.JSONRPC):
    """
    An example object to be published.
    """
    def __init__(self, queryServer=None):
        ##ugur
        self.rpclogger = createLogger('RPC')
        self.rpclogger.info('Starting JSONRPCServer')
        self.queryServer = queryServer
        self.queryManager = QueryManager(
            store=self.queryServer.createStore(),
            sources=self.queryServer.config.sources,
            plugins=self.queryServer.config.plugins)

    def render(self, request):
        # check if db connection is lost or not!
        self.queryManager.setStore(
            self.queryServer.dbEnsureConnected(self.queryManager.store))
        return (jsonrpc.JSONRPC.render(self, request))

    def jsonrpc_push_alerts(self, plugin_ip, query_id_list, start_time,
                            end_time):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.queryManager.pushAlerts(plugin_ip, query_id_list, start_time,
                                     end_time)

    def jsonrpc_push_statistics(self, plugin_id, query_id, number_of_flows,
                                number_of_bytes, number_of_packets,
                                time_window):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.queryManager.pushStatistics(plugin_ip, query_id_list, start_time,
                                         end_time)

    def jsonrpc_register(self, plugin_ip):
        result = []
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        # DEBUG mode da hangi fieldlarin hatali geldigini yazdirabiliriz tabiki sadece query server ' a.
        plugin = self.queryManager.store.find(
            Plugin, Plugin.plugin_ip == plugin_ip).one()
        #TODO Anywhere plugins registered flags not set. Flags must be define.
        if plugin is None:
            result.append(0)
            return result
        else:
            if plugin.registered == 1:
                result.append(1)
                return result
            if plugin.registered == 2:
                result.append(2)
                return result
            if plugin.registered == 3:
                result.append(3)
                return result
        return result
#    print organization
#    print prefix_list
#    print plugin_ip
#    print adm_publickey_file
#    print adm_tel
#    print adm_name
#    print adm_mail
#        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
#        # DEBUG mode da hangi fieldlarin hatali geldigini yazdirabiliriz tabiki sadece query server ' a.
#        #print "Registration information : %s,%s,%s,%s,%s,%s,%s" % (organization, adm_name, adm_mail, adm_tel, adm_publickey, prefix_list, plugin_ip)
#        self.store = db.get_store()
#        plugin = self.store.find(Plugin, Plugin.organization == unicode(organization)).one()
#        if plugin is None:
#            message =  'Your plugin is not registered to QueryServer yet.'
#            message += 'Plugin is not found.'
#            message += 'Please ask to QS Administrator about your registration process.'
#            self.rpclogger.info("AAAAAAAAAAa")
#            print message
#        result.append(0)
#        print result
#            return result
#        else:
#            checksum = hashlib.md5()
#            checksum.update( organization + adm_name + adm_mail +
#                             adm_tel      + adm_publickey_file  +
#                             prefix_list  + plugin_ip )
#            if checksum.hexdigest() != plugin.checksum:
#                message = 'Your plugin information doesn\'t match with the QueryServer side.'
#                message += 'Plugin Checksum Error'
#                message += 'Please check your information and try again.'
#            result.append(1)
#            print result
#                return result
#               # print message
#            elif checksum.hexdigest() == plugin.checksum:
#                # Set the plugin registered
#                plugin.registered = True
#                self.store.add(plugin)
#                self.store.commit()
#                message =  'Your plugin is registered.\n'
#                message += 'Feel free to checkout query subscriptions.'
#                #print message
#            result.append(2)
#            print result
#                return result
#                #return self.jsonrpc_get_subscriptions()

    def jsonrpc_get_statistics(self, alert_id):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        result = self.queryManager.getStatistics(alert_id)
        return result

    def jsonrpc_get_topn_query(self, n):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        result = self.queryManager.getTopNQuery(n)
        return result

    def jsonrpc_get_query_filter(self, query_id):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('returning query filter')
        return self.queryManager.getFilter(query_id)

    def jsonrpc_get_subscription_detail(self, subscription):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('returning subscriptions detail')
        return self.queryManager.getSubscription(subscription)

    def jsonrpc_get_subscriptions(self):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('returning subscriptions')
        subs = self.queryManager.getAllSubscriptions()
        return subs

    def jsonrpc_get_subscription(self, name, method_call):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting subscription information')
        return self.queryManager.getSubscription(name, method_call)

    def jsonrpc_get_all_prefixes(self):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting all prefix list information')
        plugin_list = self.queryManager.store.find(Plugin)
        prefix_list = {}
        for plugin in plugin_list:
            prefix_list[plugin.id] = plugin.prefix.prefix.replace(
                " ", "").split(',')
        print prefix_list
        return prefix_list

    def jsonrpc_get_plugin_id(self, ip_address):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting plugin id of ip address')
        return self.queryManager.getPluginId(ip_address)

    def jsonrpc_get_prefixes(self, ip_address):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        self.rpclogger.debug('getting prefix list information')
        plugin = self.queryManager.store.find(
            Plugin, Plugin.plugin_ip == unicode(ip_address)).one()
        if not plugin:
            self.rpclogger.warning('Plugin ip is not correct')
            self.rpclogger.warning('Can not return prefix list')
            return
        else:
            p_list = {}
            p_list[plugin.id] = plugin.prefix.prefix.replace(" ",
                                                             "").split(',')
            return p_list

    def jsonrpc_get_alert(self, alert):
        print '\n'
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        result = self.queryManager.registerAlert(alert)
        return result

    def jsonrpc_get_my_alerts(self, plugin_ip):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        return self.queryManager.getMyAlerts(plugin_ip)

    def jsonrpc_generate_query(self, query_info_list, mandatory, plugin_ip):
        self.rpclogger.debug('In %s' % sys._getframe().f_code.co_name)
        return self.queryManager.generateQuery(query_info_list, mandatory,
                                               plugin_ip)