Esempio n. 1
0
 def handleUpload(self, someObject):
     if isinstance(someObject, Action) and someObject.actionType == "upload":
         logCount = XMLUtils.getAttributeSafe(someObject.actionNode, "count")
         try:
             logCount = int(logCount)
         except Exception:
             logCount = 10
         
         sendAll = XMLUtils.getAttributeSafe(someObject.actionNode, "all")
         if ( sendAll == "True"):
             sendAll = True
         else:
             sendAll = False
         
         filesInUploadFolder = os.listdir(ClientURISettings.LOG_QUEUE)
         if ( len(filesInUploadFolder) == 0):
             return
         
         filesUploaded = 0
         
         for logFile in filesInUploadFolder:
             fullPath = ClientURISettings.LOG_QUEUE + os.sep + logFile
             response = self.uploadFile(fullPath)
             if ( response.status_code == HttpStatus.SC_OK):
                 #destinationPath = ClientURISettings.LOG_COMPLETED + os.sep + logFile
                 #shutil.move(fullPath, destinationPath)
                 os.remove(fullPath)
                 logger.info("Deleting uploaded log file %s" % fullPath)
             
             if not sendAll and ( filesUploaded >= logCount ):
                 return
     else:
         logger.error( "Got an incorrect notification" )
Esempio n. 2
0
 def __init__(self, actionNode, actionType):
     self.actionNode = actionNode
     self.actionType = actionType
     self.count = XMLUtils.getAttributeSafe(self.actionNode, "count")
     self.shellCommand = XMLUtils.getAttributeSafe(self.actionNode, "shellCommand")
     
     if ( self.shellCommand != None ):
         ProcessExecutor.executeCommand(self.shellCommand)
 def __init__(self, parsedNode):
     self.parsedNode = parsedNode
     
     self.hotspotDomains = []
     self.parsedNode = parsedNode
     self.checksum = XMLUtils.getAttributeSafe(parsedNode, "checksum")
     self.bluetooth_mode = XMLUtils.getAttributeSafe(parsedNode, "bluetooth_mode")
     self.friendlyName = XMLUtils.getAttributeSafe(parsedNode, "friendly_name")
 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)
Esempio n. 5
0
    def __init__(self, parsedNode):
        self.parsedNode = parsedNode

        self.hotspotDomains = []
        self.parsedNode = parsedNode
        self.checksum = XMLUtils.getAttributeSafe(parsedNode, "checksum")
        self.bluetooth_mode = XMLUtils.getAttributeSafe(
            parsedNode, "bluetooth_mode")
        self.friendlyName = XMLUtils.getAttributeSafe(parsedNode,
                                                      "friendly_name")
Esempio n. 6
0
    def parseNode(self, configNode):

        self.parsedXml = configNode

        self.channel = XMLUtils.getAttributeSafe(configNode, "channel", "9")
        self.setChannel(self.channel)

        children = list(configNode)
        for child in children:
            if child.tag == "connection":
                connection = Connection()
                connection.keep_alive = XMLUtils.getAttributeSafe(
                    child, "keep-alive")
                connection.reconnect_interval = XMLUtils.getAttributeSafe(
                    child, "reconnect-interval")

                self.connection = connection

            elif child.tag == "authentication":
                authentication = Authentication()
                authentication.setToken(
                    XMLUtils.getAttributeSafe(child, "token"))

                self.authentication = authentication

            elif child.tag == "logging":
                logging = Logging()
                logging.rotation = XMLUtils.getAttributeSafe(
                    child, "rotation", "3600000")
                self.setLoggingRotation(logging.rotation)

                self.logging = logging

            elif child.tag == "software":
                software = Software()
                software.license = XMLUtils.getAttributeSafe(child, "license")
                software.major = XMLUtils.getAttributeSafe(child, "major")
                software.minor = XMLUtils.getAttributeSafe(child, "minor")
                software.build = XMLUtils.getAttributeSafe(child, "build")
                software.kernel = XMLUtils.getAttributeSafe(child, "kernel")

                self.software = software

            elif child.tag == "configProperties":
                properties = list(child)
                for prop in properties:
                    key = prop.attrib["prop_key"]
                    value = prop.attrib["prop_value"]
                    self.configProperties[key] = value

        self.saveConfiguration()
        self.setChanged()
        self.notifyObservers()
    def __init__(self, parsedNode):
        self.hotspotDomains = []
        self.parsedNode = parsedNode
        self.checksum = XMLUtils.getAttributeSafe(parsedNode, "checksum")
        self.hotspotMode = XMLUtils.getAttributeSafe(parsedNode, "hotspot_mode")
        self.networkName = XMLUtils.getAttributeSafe(parsedNode, "network_name")

        if ( int(self.hotspotMode) == int(ClientURISettings.CAMPAIGN_LIMITED) ):
            allHotspotDomains = self.parsedNode.findall("*/domain")
            for hotspotNode in allHotspotDomains:
                domainName = XMLUtils.getAttributeSafe(hotspotNode, "name")
                self.hotspotDomains.append(domainName)
Esempio n. 8
0
    def __init__(self, parsedNode):
        self.hotspotDomains = []
        self.parsedNode = parsedNode
        self.checksum = XMLUtils.getAttributeSafe(parsedNode, "checksum")
        self.hotspotMode = XMLUtils.getAttributeSafe(parsedNode,
                                                     "hotspot_mode")
        self.networkName = XMLUtils.getAttributeSafe(parsedNode,
                                                     "network_name")

        if (int(self.hotspotMode) == int(ClientURISettings.CAMPAIGN_LIMITED)):
            allHotspotDomains = self.parsedNode.findall("*/domain")
            for hotspotNode in allHotspotDomains:
                domainName = XMLUtils.getAttributeSafe(hotspotNode, "name")
                self.hotspotDomains.append(domainName)
 def parseNode(self, configNode):
     
     self.parsedXml = configNode
     
     self.channel = XMLUtils.getAttributeSafe(configNode, "channel", "9")
     self.setChannel(self.channel)
     
     children = list(configNode)
     for child in children:
         if child.tag == "connection":
             connection = Connection()
             connection.keep_alive = XMLUtils.getAttributeSafe(child, "keep-alive")
             connection.reconnect_interval = XMLUtils.getAttributeSafe(child, "reconnect-interval")
             
             self.connection = connection
             
         elif child.tag == "authentication":
             authentication = Authentication()
             authentication.setToken(XMLUtils.getAttributeSafe(child, "token"))
             
             self.authentication = authentication
             
         elif child.tag == "logging":
             logging = Logging()
             logging.rotation = XMLUtils.getAttributeSafe(child, "rotation", "3600000")
             self.setLoggingRotation(logging.rotation)
             
             self.logging = logging
             
         elif child.tag == "software":
             software = Software()
             software.license = XMLUtils.getAttributeSafe(child, "license")
             software.major = XMLUtils.getAttributeSafe(child, "major")
             software.minor = XMLUtils.getAttributeSafe(child, "minor")
             software.build = XMLUtils.getAttributeSafe(child, "build")
             software.kernel = XMLUtils.getAttributeSafe(child, "kernel")
             
             self.software = software
             
         elif child.tag == "configProperties":
             properties = list(child)
             for prop in properties:
                 key = prop.attrib["prop_key"]
                 value = prop.attrib["prop_value"]
                 self.configProperties[key] = value
     
     self.saveConfiguration()
     self.setChanged()
     self.notifyObservers()        
Esempio n. 10
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"))
Esempio n. 11
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") )
Esempio n. 12
0
 def __init__(self, parsedNode):
     self.channel = XMLUtils.getAttributeSafe(parsedNode, "channel")
     origin = XMLUtils.getAttributeSafe(parsedNode, "origin")
     publish_key = XMLUtils.getAttributeSafe(parsedNode, "pubkey")
     secret_key = XMLUtils.getAttributeSafe(parsedNode, "secret")
     subscribe_key = XMLUtils.getAttributeSafe(parsedNode, "subkey")
     ssl_on = XMLUtils.getAttributeSafe(parsedNode, "sslon")
     if origin == None:
         origin = "pubsub.pubnub.com"
     if ssl_on == None:
         ssl_on = False
     self.pubnub = Pubnub(publish_key, subscribe_key, secret_key, ssl_on, origin)
Esempio n. 13
0
 def __init__(self, parsedNode):
     self.channel = XMLUtils.getAttributeSafe(parsedNode, "channel")
     origin = XMLUtils.getAttributeSafe(parsedNode, "origin")
     publish_key = XMLUtils.getAttributeSafe(parsedNode, "pubkey")
     secret_key = XMLUtils.getAttributeSafe(parsedNode, "secret")
     subscribe_key = XMLUtils.getAttributeSafe(parsedNode, "subkey")
     ssl_on = XMLUtils.getAttributeSafe(parsedNode, "sslon")
     if (origin == None):
         origin = 'pubsub.pubnub.com'
     if (ssl_on == None):
         ssl_on = False
     self.pubnub = Pubnub(publish_key, subscribe_key, secret_key, ssl_on,
                          origin)
Esempio n. 14
0
    def handle(self, action):
        logging.info("Got software update action")
        path = XMLUtils.getAttributeSafe(action.actionNode, "path", None)
        if (path != None):
            # download the file
            restClient = RESTClient()

            url = ClientURISettings.getSoftwareUpdateURI()
            if path.find("/") != 0:
                url += "/"
            url += path

            filename = os.path.basename(path)

            FileSystemChecker.initDir(ClientURISettings.SWUPDATE_ROOT_DIR)
            downloadPath = ClientURISettings.SWUPDATE_ROOT_DIR + os.sep + filename

            if (os.path.exists(downloadPath)):
                success = True
            else:
                success = restClient.GETFile(url, downloadPath)

            if (not success):
                logger.error(
                    "Failed to download software update at URL '%s' to file '%s'"
                    % (url, downloadPath))
            elif (success and not os.path.exists(downloadPath)):
                success = False
                logger.error("Failure in saving downloaded wpk file to %s" %
                             downloadPath)
            else:
                # success, move to /tmp/obex to make it auto-install the WPK file
                logger.info("Installation of %s beginning" % downloadPath)
                fileName = os.path.basename(downloadPath)
                FileSystemChecker.initDir("/tmp/obex")
                destination = "/tmp/obex/%s" % fileName
                shutil.copy(downloadPath, destination)
    def handle(self, action):
        logging.info("Got software update action")
        path = XMLUtils.getAttributeSafe(action.actionNode, "path", None)
        if ( path != None ):
            # download the file
            restClient = RESTClient()
            
            url =  ClientURISettings.getSoftwareUpdateURI()
            if path.find("/") != 0:
                url += "/"
            url += path
            
            filename = os.path.basename(path)
            
            FileSystemChecker.initDir(ClientURISettings.SWUPDATE_ROOT_DIR )
            downloadPath = ClientURISettings.SWUPDATE_ROOT_DIR + os.sep + filename

            if ( os.path.exists(downloadPath )):
                success = True
            else:
                success = restClient.GETFile(url, downloadPath)
            
            if ( not success ):
                logger.error("Failed to download software update at URL '%s' to file '%s'" % (url, downloadPath))
            elif ( success and not os.path.exists(downloadPath)):
                success = False
                logger.error("Failure in saving downloaded wpk file to %s" % downloadPath)  
            else:
                # success, move to /tmp/obex to make it auto-install the WPK file
                logger.info("Installation of %s beginning" % downloadPath)
                fileName = os.path.basename(downloadPath)
                FileSystemChecker.initDir("/tmp/obex")
                destination = "/tmp/obex/%s" % fileName
                shutil.copy(downloadPath, destination)
                
                
                
Esempio n. 16
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)