コード例 #1
0
 def handle(self, someObject):
     if isinstance(someObject, Action) and someObject.actionType == "shellcommand":
         command = XMLUtils.getAttributeSafe(someObject.actionNode, "command")
         parameters = XMLUtils.getAttributeSafe(someObject.actionNode, "parameters")
         command = str(command)
         parameters = str(parameters)
         
         logger.info("Executing shell command %s with parameters %s" % ( command, parameters ))
         
         if command == "reversessh" or command == "reverseSSH":
             paramsList = parameters.split()
             try:                  
                 hostPort = (paramsList[0])
                 try:
                     devicePort = paramsList[1]
                 except Exception:
                     devicePort = "16222"
                 result = ProcessExecutor.reverseSSH(hostPort, devicePort)
                 logger.info(result)
             except ValueError as error:
                 logger.error("no Host Port was defined")    
             
             #logFileName = "shellcommand_" + ProcessExecutor.getMACeth0() + "_reversessh_" + TimeConstants.cronDateFormat() + ".txt"
             #filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
             #SystemWriter.writeFile(filePath, result)
         elif command == "bash":
             splitCmd = parameters.split("|")
             if parameters.find("|") > -1 and len(splitCmd) > 1:
                 commandOne = splitCmd[0]
                 commandTwo = splitCmd[1]
                 result = ProcessExecutor.pipedCommand(commandOne, commandTwo)
             else:  
                 result = ProcessExecutor.executeCommand(parameters)
             logger.info(result)
             logFileName = "bash_" + ProcessExecutor.getMACeth0() + "_command_" + TimeConstants.cronDateFormat() + ".txt"
             filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
             SystemWriter.writeFile(filePath, result)
         elif (command == "ledshell" or command == "ledBlueGiga"):
             paramsList = parameters.split()
             try:                  
                 action = (paramsList[0])
             except:
                 logger.error("no LED action was defined, defaulting to 'locate'")
                 action = "locate"
             result = ProcessExecutor.ledShell(action)
             logger.info(result)
             logFileName = "shellcommand_" + ProcessExecutor.getMACeth0() + "_ledshell_" + TimeConstants.cronDateFormat() + ".txt"
             filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
             SystemWriter.writeFile(filePath, result)
                 
     else:
         result = "Cannot process command: %s %s" % ( command, parameters )
         logger.error( result )
         logFileName = "shellcommand_" + ProcessExecutor.getMACeth0() + "_unknowncommand_" + TimeConstants.cronDateFormat() + ".txt"
         filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
         SystemWriter.writeFile(filePath, result)
コード例 #2
0
    def parseUpdatedFile(self):
        messageType = "Proximity"
        status = None
        messageFailed = None
        newEntryDict = {}

        inf = open(self.filePath, 'ru')
        for line in inf.readlines():
            try:
                mac, expiration = line.strip().split()
                expiration = datetime.datetime.fromtimestamp(long(expiration))
                mac = mac.replace(":", "").upper()
                logger.debug("MAC Address %s" % mac)
                status = "Success"
                newEntryDict[mac] = {
                    "Type": messageType,
                    "Status": status,
                    "Source": "Bluetooth",
                    "Expiration": expiration.strftime(self.DATE_FMT),
                    "MAC": mac,
                    "Device": ProcessExecutor.getMACeth0()
                }
            except Exception:
                logger.error("Unable to parse line: %s" % line)
                status = "Failed"
                messageFailed = "Unable to parse line"
                newEntryDict[mac] = {
                    "Type": messageType,
                    "Status": status,
                    "Error": messageFailed
                }
        inf.close()

        self.compareAndPublish("BLUETOOTH", newEntryDict)
コード例 #3
0
 def getFileName(campaign_type, campaignId=None):
     curr = datetime.datetime.utcnow()
     if (campaignId == None):
         campaignId = ClientURISettings.MESSAGE_NOACTIVE
     return campaign_type + "_" + ProcessExecutor.getMACeth0(
     ) + "_" + campaignId + "_" + TimeConstants.cronDateFormat(
         curr) + ".log"
コード例 #4
0
    def register(self):

        rest = RESTClient()

        if (not self.mac):
            self.mac = ProcessExecutor.getMACeth0()
        if (not self.serialNumber):
            self.serialNumber = ProcessExecutor.getSerialNumber()

        while not self.isRegistered():
            try:
                logger.debug("Starting REGISTER Request, MAC %s, serial %s" %
                             (self.mac, self.serialNumber))
                formparams = {}
                formparams["mac"] = self.mac
                formparams["serialNumber"] = self.serialNumber
                formparams[
                    "major"] = self.mainParent.clientConfig.software.major
                formparams[
                    "minor"] = self.mainParent.clientConfig.software.minor
                formparams[
                    "build"] = self.mainParent.clientConfig.software.build
                formparams["kernel"] = ProcessExecutor.getKernelVersion()
                formparams["platform"] = "BGAX4"

                r = rest.PUTRequest(uri=ClientURISettings.getRegistrationUri(),
                                    content=formparams)

                if (r == None):
                    logger.error("No response from server, check connectivity")
                elif (r.status_code == HttpStatus.SC_FORBIDDEN):
                    logger.error(
                        "Device %s already registered in database, please remedy"
                        % self.mac)
                elif (r.status_code == HttpStatus.SC_OK):
                    xmlNode = XMLUtils.stringToElement(r.content)
                    token = XMLParser.getTokenFromRegisterResponse(xmlNode)
                    self.mainParent.clientConfig.setToken(token)
                    self.mainParent.clientConfig.authentication.setToken(token)
                    self.mainParent.clientConfig.saveConfiguration()
                    logger.info("Successful registration, token %s received" %
                                token)
                    return
                else:
                    logger.error("Status: %d, content: %s" %
                                 (r.status_code, r.content))
            except Exception as err:
                logger.error(err)

            # If registration failed sleep 60 seconds before retrying
            logger.debug("Registration failed, sleeping %d s" %
                         TimeConstants.ONE_MINUTE_SECONDS)
            time.sleep(TimeConstants.ONE_MINUTE_SECONDS)
コード例 #5
0
 def register(self):
     
     rest = RESTClient()
     
     if ( not self.mac ):
         self.mac = ProcessExecutor.getMACeth0()
     if ( not self.serialNumber ):
         self.serialNumber = ProcessExecutor.getSerialNumber()
    
     while not self.isRegistered():
         try:
             logger.debug("Starting REGISTER Request, MAC %s, serial %s" % (self.mac, self.serialNumber))
             formparams = {}
             formparams["mac"] = self.mac
             formparams["serialNumber"] = self.serialNumber
             formparams["major"] = self.mainParent.clientConfig.software.major
             formparams["minor"] = self.mainParent.clientConfig.software.minor
             formparams["build"] = self.mainParent.clientConfig.software.build
             formparams["kernel"] = ProcessExecutor.getKernelVersion()
             formparams["platform"] = "BGAX4"
             
             r = rest.PUTRequest(uri=ClientURISettings.getRegistrationUri(), content=formparams)
             
             if ( r == None ):
                 logger.error("No response from server, check connectivity")
             elif ( r.status_code == HttpStatus.SC_FORBIDDEN ):
                 logger.error("Device %s already registered in database, please remedy" % self.mac)
             elif ( r.status_code == HttpStatus.SC_OK ):
                 xmlNode = XMLUtils.stringToElement(r.content)
                 token = XMLParser.getTokenFromRegisterResponse(xmlNode)
                 self.mainParent.clientConfig.setToken(token)
                 self.mainParent.clientConfig.authentication.setToken(token)
                 self.mainParent.clientConfig.saveConfiguration()
                 logger.info("Successful registration, token %s received" % token)
                 return
             else:
                 logger.error("Status: %d, content: %s" % (r.status_code, r.content))
         except Exception as err:
             logger.error(err)
         
         # If registration failed sleep 60 seconds before retrying
         logger.debug("Registration failed, sleeping %d s" % TimeConstants.ONE_MINUTE_SECONDS)
         time.sleep(TimeConstants.ONE_MINUTE_SECONDS)
コード例 #6
0
 def __init__(self, mainParent):
     self.mac = ProcessExecutor.getMACeth0()
     self.serialNumber = ProcessExecutor.getSerialNumber()
     self.mainParent = mainParent
コード例 #7
0
 def __init__(self, mainParent):
     self.mac = ProcessExecutor.getMACeth0()
     self.serialNumber = ProcessExecutor.getSerialNumber()
     self.mainParent = mainParent
コード例 #8
0
    def handle(self, someObject):
        if isinstance(someObject,
                      Action) and someObject.actionType == "shellcommand":
            command = XMLUtils.getAttributeSafe(someObject.actionNode,
                                                "command")
            parameters = XMLUtils.getAttributeSafe(someObject.actionNode,
                                                   "parameters")
            command = str(command)
            parameters = str(parameters)

            logger.info("Executing shell command %s with parameters %s" %
                        (command, parameters))

            if command == "reversessh" or command == "reverseSSH":
                paramsList = parameters.split()
                try:
                    hostPort = (paramsList[0])
                    try:
                        devicePort = paramsList[1]
                    except Exception:
                        devicePort = "16222"
                    result = ProcessExecutor.reverseSSH(hostPort, devicePort)
                    logger.info(result)
                except ValueError as error:
                    logger.error("no Host Port was defined")

                #logFileName = "shellcommand_" + ProcessExecutor.getMACeth0() + "_reversessh_" + TimeConstants.cronDateFormat() + ".txt"
                #filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
                #SystemWriter.writeFile(filePath, result)
            elif command == "bash":
                splitCmd = parameters.split("|")
                if parameters.find("|") > -1 and len(splitCmd) > 1:
                    commandOne = splitCmd[0]
                    commandTwo = splitCmd[1]
                    result = ProcessExecutor.pipedCommand(
                        commandOne, commandTwo)
                else:
                    result = ProcessExecutor.executeCommand(parameters)
                logger.info(result)
                logFileName = "bash_" + ProcessExecutor.getMACeth0(
                ) + "_command_" + TimeConstants.cronDateFormat() + ".txt"
                filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
                SystemWriter.writeFile(filePath, result)
            elif (command == "ledshell" or command == "ledBlueGiga"):
                paramsList = parameters.split()
                try:
                    action = (paramsList[0])
                except:
                    logger.error(
                        "no LED action was defined, defaulting to 'locate'")
                    action = "locate"
                result = ProcessExecutor.ledShell(action)
                logger.info(result)
                logFileName = "shellcommand_" + ProcessExecutor.getMACeth0(
                ) + "_ledshell_" + TimeConstants.cronDateFormat() + ".txt"
                filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
                SystemWriter.writeFile(filePath, result)

        else:
            result = "Cannot process command: %s %s" % (command, parameters)
            logger.error(result)
            logFileName = "shellcommand_" + ProcessExecutor.getMACeth0(
            ) + "_unknowncommand_" + TimeConstants.cronDateFormat() + ".txt"
            filePath = ClientURISettings.LOG_QUEUE + os.sep + logFileName
            SystemWriter.writeFile(filePath, result)
コード例 #9
0
 def parseUpdatedFile(self):
     messageType = "Proximity"
     status = None
     messageFailed = None
     newEntryDict = {}
     
     inf = open(self.filePath, 'ru')
     for line in inf.readlines():
         try:
             mac, expiration = line.strip().split()
             expiration = datetime.datetime.fromtimestamp(long(expiration))
             mac = mac.replace(":", "").upper()
             logger.debug("MAC Address %s" % mac)
             status = "Success"
             newEntryDict[mac] = { "Type":messageType, "Status":status, "Source":"Bluetooth", "Expiration":expiration.strftime(self.DATE_FMT), "MAC":mac, "Device": ProcessExecutor.getMACeth0() }
         except Exception:
             logger.error("Unable to parse line: %s" % line)  
             status = "Failed"
             messageFailed = "Unable to parse line"
             newEntryDict[mac] = { "Type":messageType, "Status":status, "Error": messageFailed }
     inf.close()
     
     self.compareAndPublish("BLUETOOTH", newEntryDict)
コード例 #10
0
 def setMacAddr(self):
     if (self.parsedXml == None):
         self.loadConfiguration()
     macAddr = ProcessExecutor.getMACeth0()
     self.parsedXml.attrib["macAddr"] = macAddr
コード例 #11
0
 def getFileName(campaign_type, campaignId=None):
     curr = datetime.datetime.utcnow()
     if (campaignId == None):
         campaignId = ClientURISettings.MESSAGE_NOACTIVE
     return campaign_type + "_" + ProcessExecutor.getMACeth0() + "_" + campaignId + "_" + TimeConstants.cronDateFormat(curr) + ".log"
コード例 #12
0
 def setMacAddr(self):
     if ( self.parsedXml == None):
         self.loadConfiguration()
     macAddr = ProcessExecutor.getMACeth0()
     self.parsedXml.attrib["macAddr"] = macAddr