Exemplo n.º 1
0
    def run(self, serverState, request, response):
        conf = ServerConf()
        host = request.getParam('host')

        client_secure_port = request.getParam('client_secure_port')
        result = dict()
        #do we have a server with this hostname or fqdn?
        connectedNodes = conf.getNodes()

        if (connectedNodes.hostnameOrFQDNExists(host) == False):
            serv = RawServerMessage(host, client_secure_port)
            resp = ProcessedResponse(serv.sendAddNodeRequest(host))

            if resp.isOK():
                result = resp.getData()
                nodeConnectRequest = NodeConnectRequest(
                    result['serverId'], int(client_secure_port), None, None,
                    result['fqdn'], host)

                conf.addSentNodeConnectRequest(nodeConnectRequest)
                result['nodeConnectRequest'] = nodeConnectRequest
                log.info("Added node %s" % host)
                response.add('', result)
            else:
                response.add("Remote server said: %s" % resp.getMessage(),
                             status="ERROR")

        else:
            errorMessage = "%s is already trusted" % host
            response.add(errorMessage, status="ERROR")
            log.info(errorMessage)
Exemplo n.º 2
0
    def run(self, serverState, request, response):
        conf = ServerConf()
        host = request.getParam('host')

        client_secure_port = request.getParam('client_secure_port')
        result = dict()
        #do we have a server with this hostname or fqdn?
        connectedNodes = conf.getNodes()

        if (connectedNodes.hostnameOrFQDNExists(host) == False):
            serv = RawServerMessage(host, client_secure_port)
            resp = ProcessedResponse(serv.sendAddNodeRequest(host))

            if resp.isOK():
                result = resp.getData()
                nodeConnectRequest = NodeConnectRequest(result['serverId'],
                    int(client_secure_port),None,None,result['fqdn'],host)

                conf.addSentNodeConnectRequest(nodeConnectRequest)
                result['nodeConnectRequest']=nodeConnectRequest
                log.info("Added node %s" % host)
                response.add('', result)
            else:
                response.add("Remote server said: %s"%resp.getMessage(),
                            status="ERROR")

        else:
            errorMessage = "%s is already trusted" % host
            response.add(errorMessage, status="ERROR")
            log.info(errorMessage)
Exemplo n.º 3
0
 def getCommandOutputData(cmdID, workerServer):
     log.log(cpc.util.log.TRACE,"Trying to pull command output from %s"%
             workerServer)
     s2smsg=ServerMessage(workerServer)  
     rundata_response = s2smsg.pullAssetRequest(cmdID, Asset.cmdOutput())
     
     if rundata_response.getType() != "application/x-tar":
         log.error("Incorrect response type: %s, should be %s"%
                   (rundata_response.getType(), 'application/x-tar'))
         if rundata_response.getType() == "text/json":
             errormsg=rundata_response.message.read(len(rundata_response.
                                                        message))
             presp=ProcessedResponse(rundata_response)
             if not presp.isOK():
                 log.error('Response from worker server not OK: %s'%
                           errormsg)
     else:
         s2smsg.clearAssetRequest(cmdID)
         log.log(cpc.util.log.TRACE,
                 "Successfully pulled command output data from %s."%
                 workerServer)
         return rundata_response
         #runfile = rundata_response.getRawData()
         #this doesnt work because the mmap closes as it is returned
     return None