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. 2
0
 def ensureDNSMasqCorrect(campaign):
     needsDNSRestart = False
     
     try:
         if (campaign == None):
             correctDomains = []
         else:
             correctDomains = campaign.wifiCampaign.hotspotDomains
         
         DEFAULT_HOTSPOT = "hotspot_rule"
         DEFAULT_CAPTIVE = "captive_rule"
         
         if (campaign != None and int(campaign.wifiCampaign.hotspotMode) == int(ClientURISettings.CAMPAIGN_HOTSPOT)):
             correctDomains.append(DEFAULT_HOTSPOT)
         elif (campaign != None and int(campaign.wifiCampaign.hotspotMode) == int(ClientURISettings.CAMPAIGN_FACEBOOK)):
             logger.debug("Facebook campaign, no DNS rules")
         else:
             correctDomains.append(DEFAULT_CAPTIVE)
         
         
         for domain_file in os.listdir(ClientURISettings.DNSMASQ_CONFIG_FOLDER):
             if domain_file not in correctDomains:
                 filepath = ClientURISettings.DNSMASQ_CONFIG_FOLDER + os.sep + domain_file
                 if (os.path.exists(filepath)):
                     logger.info("Deleting old hotspot domain %s" % domain_file)
                     os.remove(ClientURISettings.DNSMASQ_CONFIG_FOLDER + os.sep + domain_file)
                     needsDNSRestart = True
         for domain in correctDomains:
             filepath = ClientURISettings.DNSMASQ_CONFIG_FOLDER + os.sep + domain
             if not os.path.isfile(filepath):    
                 if (domain == DEFAULT_HOTSPOT):
                     strContent = "# disabled in hotspot mode\n#address=/#/192.168.45.3"
                     SystemWriter.writeFile(filepath, strContent)
                 elif (domain == DEFAULT_CAPTIVE):
                     strContent = "address=/#/192.168.45.3"
                     SystemWriter.writeFile(filepath, strContent)
                 else:
                     strContent = "server=/%s/#\n" % domain
                     SystemWriter.writeFile(filepath, strContent)
                 needsDNSRestart = True
         
     except Exception as err:
         logger.error(err)
         
     if (needsDNSRestart == True):
         ProcessExecutor.restartDNS()
Esempio n. 3
0
 def writeNodeToFile(filepath, node):
     SystemWriter.writeFile(filepath, XMLUtils.elementToString(node))
Esempio n. 4
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)