Пример #1
0
    def __init__(self, parsedNode):

        self.id = XMLUtils.getAttributeSafe(parsedNode, "id")
        self.name = XMLUtils.getAttributeSafe(parsedNode, "name")

        h = hashlib.new('ripemd160')
        h.update(XMLUtils.elementToString(parsedNode))
        self.checksum = h.hexdigest()

        self.active = XMLUtils.getAttributeSafe(parsedNode, "active")

        # THIS SHOULD NOT EXIST AT THE CAMPAIGN LEVEL AND AT THE WIFI/BT LEVEL TOO
        self.days_of_week = TimeConstants.getDaysOfWeek(
            XMLUtils.getAttributeSafe(parsedNode, "days_of_week"))

        self.start_date = TimeConstants.dateParseUTC(
            XMLUtils.getAttributeSafe(parsedNode, "start_date"))
        self.end_date = TimeConstants.dateParseUTC(
            XMLUtils.getAttributeSafe(parsedNode, "end_date"))

        self.start_time = XMLUtils.getAttributeSafe(parsedNode, "start_time")
        self.end_time = XMLUtils.getAttributeSafe(parsedNode, "end_time")

        self.wifiNode = parsedNode.find("wifi_campaign")
        self.btNode = parsedNode.find("bluetooth_campaign")
        self.pubNubNode = parsedNode.find("pubNubKey")

        self.type = []
        self.wifiCampaign = None
        self.bluetoothCampaign = None
        self.pubNubKey = None
        if (self.wifiNode != None):
            self.type.append(ClientURISettings.MESSAGE_WIFI)
            self.wifiCampaign = WifiCampaign(self.wifiNode)

        if (self.btNode != None):
            self.type.append(ClientURISettings.MESSAGE_BLUETOOTH)
            self.bluetoothCampaign = BluetoothCampaign(self.btNode)

        if (self.pubNubNode != None):
            self.pubNubKey = PubNubKey(self.pubNubNode)

        # this exists to allow you to dynamically get the content by type
        self.content = {}
        self.content[
            ClientURISettings.MESSAGE_BLUETOOTH] = self.bluetoothCampaign
        self.content[ClientURISettings.MESSAGE_WIFI] = self.wifiCampaign

        self.last_modified = TimeConstants.dateParseUTC(
            XMLUtils.getAttributeSafe(parsedNode, "last_modified"))
Пример #2
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"
Пример #3
0
    def __init__(self, parsedNode):
        
        self.id = XMLUtils.getAttributeSafe(parsedNode, "id")
        self.name = XMLUtils.getAttributeSafe(parsedNode, "name")
        
        h = hashlib.new('ripemd160')
        h.update(XMLUtils.elementToString(parsedNode))
        self.checksum = h.hexdigest()
        
        self.active = XMLUtils.getAttributeSafe(parsedNode, "active")
        
        # THIS SHOULD NOT EXIST AT THE CAMPAIGN LEVEL AND AT THE WIFI/BT LEVEL TOO
        self.days_of_week = TimeConstants.getDaysOfWeek( XMLUtils.getAttributeSafe(parsedNode, "days_of_week") )
        
        self.start_date = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "start_date") )
        self.end_date = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "end_date") )

        self.start_time = XMLUtils.getAttributeSafe(parsedNode, "start_time")
        self.end_time = XMLUtils.getAttributeSafe(parsedNode, "end_time")
        
        self.wifiNode = parsedNode.find("wifi_campaign")
        self.btNode = parsedNode.find("bluetooth_campaign")
        self.pubNubNode = parsedNode.find("pubNubKey")
        
        self.type = []
        self.wifiCampaign = None
        self.bluetoothCampaign = None
        self.pubNubKey = None
        if ( self.wifiNode != None ):
            self.type.append(ClientURISettings.MESSAGE_WIFI)
            self.wifiCampaign = WifiCampaign(self.wifiNode)
            
        if ( self.btNode != None ):
            self.type.append(ClientURISettings.MESSAGE_BLUETOOTH)
            self.bluetoothCampaign = BluetoothCampaign(self.btNode)
                      
        if ( self.pubNubNode != None ):
            self.pubNubKey = PubNubKey(self.pubNubNode)
        
        # this exists to allow you to dynamically get the content by type
        self.content = {}
        self.content[ClientURISettings.MESSAGE_BLUETOOTH] = self.bluetoothCampaign
        self.content[ClientURISettings.MESSAGE_WIFI] = self.wifiCampaign
        
        self.last_modified = TimeConstants.dateParseUTC( XMLUtils.getAttributeSafe(parsedNode, "last_modified") )
 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)
Пример #5
0
 def isConnectNeeded():
     global DeviceClientInstance
     
     try:
         intervalBetweenConnects = DeviceClientInstance.clientConfig.connection.reconnect_interval
     except:
         logger.info("No connect interval available, defaulting to 60s")
         intervalBetweenConnects = 60000 # 60 seconds, if it can't read a value
     
     if TimeConstants.dateIntervalExceeded(DeviceClientInstance.getLastStatusApiTime(), intervalBetweenConnects):
         return True
     else:
         return False
Пример #6
0
 def isRotationNeeded():
     global DeviceClientInstance
     
     logging = DeviceClientInstance.clientConfig.logging
     if ( logging == None):
         return False
     rotationInterval = logging.rotation  # interval in MS
     
     props = SystemWriter.readLogProperties()
     if props.has_key(ClientURISettings.WIFI_TRANSFER_PROP):
         wifiLogName = props[ClientURISettings.WIFI_TRANSFER_PROP]
     else:
         props = SystemWriter.writeLogProperties(props, False)
         wifiLogName = props[ClientURISettings.WIFI_TRANSFER_PROP]
         
     # wifi_bluegiga_B88D1200CFE2_-1_2012-03-27.12-04-41.log
     lastRotationDateStr = wifiLogName.split("_")[-1].replace(".log", "")
     lastRotationDate = TimeConstants.dateParseCronDate(lastRotationDateStr)
     if TimeConstants.dateIntervalExceeded(lastRotationDate, rotationInterval):
         return True
     else:
         return False
Пример #7
0
    def isRotationNeeded():
        global DeviceClientInstance

        logging = DeviceClientInstance.clientConfig.logging
        if (logging == None):
            return False
        rotationInterval = logging.rotation  # interval in MS

        props = SystemWriter.readLogProperties()
        if props.has_key(ClientURISettings.WIFI_TRANSFER_PROP):
            wifiLogName = props[ClientURISettings.WIFI_TRANSFER_PROP]
        else:
            props = SystemWriter.writeLogProperties(props, False)
            wifiLogName = props[ClientURISettings.WIFI_TRANSFER_PROP]

        # wifi_bluegiga_B88D1200CFE2_-1_2012-03-27.12-04-41.log
        lastRotationDateStr = wifiLogName.split("_")[-1].replace(".log", "")
        lastRotationDate = TimeConstants.dateParseCronDate(lastRotationDateStr)
        if TimeConstants.dateIntervalExceeded(lastRotationDate,
                                              rotationInterval):
            return True
        else:
            return False
Пример #8
0
    def isConnectNeeded():
        global DeviceClientInstance

        try:
            intervalBetweenConnects = DeviceClientInstance.clientConfig.connection.reconnect_interval
        except:
            logger.info("No connect interval available, defaulting to 60s")
            intervalBetweenConnects = 60000  # 60 seconds, if it can't read a value

        if TimeConstants.dateIntervalExceeded(
                DeviceClientInstance.getLastStatusApiTime(),
                intervalBetweenConnects):
            return True
        else:
            return False
Пример #9
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)
Пример #10
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"