def loadConfiguration(self): logger.info("Loading configuration from:" + ClientURISettings.CONFIG_FILE) if not (os.path.exists(ClientURISettings.CONFIG_FILE) and os.path.isfile(ClientURISettings.CONFIG_FILE)): outf = open(ClientURISettings.CONFIG_FILE, "w") outf.write(self.getDefaultConfiguration()) outf.close() try: xmlContent = SystemWriter.readFileToString( ClientURISettings.CONFIG_FILE) if (xmlContent.strip() == ""): logger.error( "Client config was empty, putting device into limbo with default config" ) os.remove(ClientURISettings.CONFIG_FILE) outf = open(ClientURISettings.CONFIG_FILE, "w") outf.write(self.getDefaultConfiguration()) outf.close() xmlContent = SystemWriter.readFileToString( ClientURISettings.CONFIG_FILE) configNode = XMLUtils.stringToElement(xmlContent) self.parseNode(configNode) except Exception as err: logger.error(err)
def run(): global DeviceClientInstance if not LogRotation.isRotationNeeded(): logger.debug("Log rotation not needed at this time") return logger.info("Running log rotation") ProcessExecutor.stopBluetooth() ProcessExecutor.stopLighttpd() try: newProps = SystemWriter.writeLogProperties(None, False) try: logger.info( "Rotating bluetooth log, new file is %s" % newProps[ClientURISettings.BLUETOOTH_TRANSFER_PROP]) logger.info("Rotating wi-fi log, new file is %s" % newProps[ClientURISettings.WIFI_TRANSFER_PROP]) except: pass # don't care filesToKeep = newProps.values() workingDir = ClientURISettings.LOG_WORKING for file in os.listdir(workingDir): if file not in filesToKeep: sourceFile = ClientURISettings.LOG_WORKING + os.sep + file destFile = ClientURISettings.LOG_QUEUE + os.sep + file logger.info("Moving %s to queue" % sourceFile) shutil.move(sourceFile, destFile) else: logger.info("%s is active" % file) campaignHandler = DeviceClientInstance.campaignHandler if (campaignHandler != None): activeBTCampaign = campaignHandler.getActiveCampaign( ClientURISettings.MESSAGE_BLUETOOTH) activeWifiCampaign = campaignHandler.getActiveCampaign( ClientURISettings.MESSAGE_WIFI) # we write some additional things here because it also runs at startup SystemWriter.writeHostAPDConfFile(activeWifiCampaign, False) SystemWriter.makeLighttpdConfFile(activeWifiCampaign, False) SystemWriter.writeObexSenderConfig(activeBTCampaign) SystemWriter.writeBluetoothConfig(activeBTCampaign) except Exception as err: logger.error(err) try: ProcessExecutor.startBluetooth() ProcessExecutor.startLighttpd() except Exception as err: logger.error(err)
def run(): global DeviceClientInstance if not LogRotation.isRotationNeeded(): logger.debug("Log rotation not needed at this time") return logger.info("Running log rotation") ProcessExecutor.stopBluetooth() ProcessExecutor.stopLighttpd() try: newProps = SystemWriter.writeLogProperties(None, False) try: logger.info("Rotating bluetooth log, new file is %s" % newProps[ClientURISettings.BLUETOOTH_TRANSFER_PROP]) logger.info("Rotating wi-fi log, new file is %s" % newProps[ClientURISettings.WIFI_TRANSFER_PROP]) except: pass # don't care filesToKeep = newProps.values() workingDir = ClientURISettings.LOG_WORKING for file in os.listdir(workingDir): if file not in filesToKeep: sourceFile = ClientURISettings.LOG_WORKING + os.sep + file destFile = ClientURISettings.LOG_QUEUE + os.sep + file logger.info("Moving %s to queue" % sourceFile) shutil.move(sourceFile, destFile) else: logger.info("%s is active" % file) campaignHandler = DeviceClientInstance.campaignHandler if ( campaignHandler != None): activeBTCampaign = campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_BLUETOOTH) activeWifiCampaign = campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_WIFI) # we write some additional things here because it also runs at startup SystemWriter.writeHostAPDConfFile(activeWifiCampaign, False) SystemWriter.makeLighttpdConfFile(activeWifiCampaign, False) SystemWriter.writeObexSenderConfig(activeBTCampaign) SystemWriter.writeBluetoothConfig(activeBTCampaign) except Exception as err: logger.error(err) try: ProcessExecutor.startBluetooth() ProcessExecutor.startLighttpd() except Exception as err: logger.error(err)
def saveCampaigns(self): if (self.parsedXml != None): stringCurrentXML = XMLUtils.elementToString(self.parsedXml) stringSavedXML = SystemWriter.readFileToString(ClientURISettings.CAMPAIGNS_FILE) if ((stringCurrentXML != stringSavedXML) and (len(stringCurrentXML) > 0)): XMLUtils.writeNodeToFile(ClientURISettings.CAMPAIGNS_FILE, self.parsedXml) logger.info("Campaigns updated on file system") else: logger.info("Campaigns change not needed") else: logger.error("Cannot save Campaigns: no data available")
def initFileSystem(self): # Filesystem setup dirs = [] # Config Dir dirs.append(ClientURISettings.CONFIG_ROOT) dirs.append(ClientURISettings.DNSMASQ_CONFIG_FOLDER) dirs.append(ClientURISettings.BIN_DIR) dirs.append(ClientURISettings.CAPTIVEPORTAL_CONFIG_DIR) # Campaigns Dir dirs.append(ClientURISettings.CAMPAIGNS_ROOT_DIR) # Logs Dirs dirs.append(ClientURISettings.LOG_ROOT) dirs.append(ClientURISettings.LOG_COMPLETED) dirs.append(ClientURISettings.LOG_QUEUE) dirs.append(ClientURISettings.LOG_WORKING) FileSystemChecker.initDirs(dirs) # Setting up the default WEB CONTENT and config properties SystemWriter.makeDefaultIndexPage() SystemWriter.makeErrorsPage() ProcessExecutor.giveLogPermission()
def loadConfiguration(self): logger.info("Loading configuration from:" + ClientURISettings.CONFIG_FILE) if not (os.path.exists(ClientURISettings.CONFIG_FILE) and os.path.isfile(ClientURISettings.CONFIG_FILE)): outf = open(ClientURISettings.CONFIG_FILE, "w") outf.write(self.getDefaultConfiguration()) outf.close() try: xmlContent = SystemWriter.readFileToString(ClientURISettings.CONFIG_FILE) if ( xmlContent.strip() == "" ): logger.error("Client config was empty, putting device into limbo with default config") os.remove(ClientURISettings.CONFIG_FILE) outf = open(ClientURISettings.CONFIG_FILE, "w") outf.write(self.getDefaultConfiguration()) outf.close() xmlContent = SystemWriter.readFileToString(ClientURISettings.CONFIG_FILE) configNode = XMLUtils.stringToElement(xmlContent) self.parseNode(configNode) except Exception as err: logger.error(err)
def saveConfiguration(self): if ( self.parsedXml != None ): self.setMacAddr() stringCurrentXML = XMLUtils.elementToString(self.parsedXml) stringSavedXML = SystemWriter.readFileToString(ClientURISettings.CONFIG_FILE) if (( stringCurrentXML != stringSavedXML) and ( len(stringCurrentXML) != len(self.getDefaultConfiguration()))): XMLUtils.writeNodeToFile(ClientURISettings.CONFIG_FILE, self.parsedXml) logger.info("ClientConfig updated on file system") else: logger.debug("ClientConfig change not needed") else: logger.error("Cannot save ClientConfig: no data available")
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
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
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)
def saveConfiguration(self): if (self.parsedXml != None): self.setMacAddr() stringCurrentXML = XMLUtils.elementToString(self.parsedXml) stringSavedXML = SystemWriter.readFileToString( ClientURISettings.CONFIG_FILE) if ((stringCurrentXML != stringSavedXML) and (len(stringCurrentXML) != len( self.getDefaultConfiguration()))): XMLUtils.writeNodeToFile(ClientURISettings.CONFIG_FILE, self.parsedXml) logger.info("ClientConfig updated on file system") else: logger.debug("ClientConfig change not needed") else: logger.error("Cannot save ClientConfig: no data available")
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()
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)
def run(): global DeviceClientInstance # See which campaign is active now, if it's not right, # the right way to see which Wi-Fi is active is to read the lighttpd.conf # and look at the 'server.document-root' logger.debug("WifiActiveCampaignCron running...") currentCampaignId = None try: if (os.path.exists(ClientURISettings.LIGHTTPD_FILE)): inf = open(ClientURISettings.LIGHTTPD_FILE, "r") for line in inf.readlines(): # """server.document-root = "%s"\n""" % doc_root if line.find("server.document-root") == 0: try: dirs = line.split('"')[1].split("/") if len(dirs) == 4: # no active campaign pass else: currentCampaignId = dirs[4] break except Exception as err: logger.info(err) inf.close() if (currentCampaignId == ClientURISettings.MESSAGE_NOACTIVE): currentCampaignId = None else: # lighttpd doesn't exist, so we should ensure below that one gets written SystemWriter.makeLighttpdConfFile(None, True) SystemWriter.writeCaptivePortalConf(None) correctActiveCampaign = DeviceClientInstance.campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_WIFI) # Check to see if the Channel is correct, if not, that needs to happen too currentChannel = None currentAccessPointInterface = None currentSSID = None if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT): hostAPDFile = ClientURISettings.HOSTAPD_CONF_FILE_DDWRT else: hostAPDFile = ClientURISettings.HOSTAPD_CONF_FILE if (os.path.exists(hostAPDFile)): inf = open(hostAPDFile, "r") for line in inf.readlines(): # """server.document-root = "%s"\n""" % doc_root if line.find("channel") == 0: try: currentChannel = line.split("=")[1].strip() except Exception as err: logger.info(err) elif line.find("interface") == 0: try: currentAccessPointInterface = line.split("=")[1].strip() except Exception as err: logger.info(err) elif line.find("ssid") == 0: try: currentSSID = line.split("=")[1].strip() except Exception as err: logger.info(err) inf.close() correctChannel = DeviceClientInstance.clientConfig.channel correctAccessPointInterface = SystemWriter.getCurrentAccessPointInterface() try: correctSSID = correctActiveCampaign.wifiCampaign.networkName except: correctSSID = ClientURISettings.MESSAGE_DEFAULT_WIFI needHostAPDUpdate = False if (correctChannel != currentChannel): logger.info("Current channel: %s, correct channel is %s" % (currentChannel, correctChannel)) needHostAPDUpdate = True if (correctSSID != currentSSID): logger.info("Current SSID: %s, correct SSID is %s" % (currentSSID, correctSSID)) needHostAPDUpdate = True if (correctAccessPointInterface != currentAccessPointInterface): logger.info("Current interface: %s, correct interface is %s" % (currentAccessPointInterface, correctAccessPointInterface)) needHostAPDUpdate = True needCaptivePortalConfUpdate = False #correct correctBackhaul = SystemWriter.getCorrectExtBackhaulInterface() #current currentBackhaul = SystemWriter.getCurrentExtBackhaulInterface() if (currentBackhaul != correctBackhaul): logger.info("current (%s) != correct (%s)" % (str(currentBackhaul), str(correctBackhaul))) needCaptivePortalConfUpdate = True # Make sure the hotspot domains are correct WifiActiveCampaignCron.ensureDNSMasqCorrect(correctActiveCampaign) """ Possibilites: 1) No campaign is active and none should be -- RETURN 2) A campaign is active, and it's the right one -- RETURN 3) A campaign is active, but none should be -- REDO AS DEFAULT CONFIG & RESTART 4) No campaign is active and one should be -- REDO CONFIG & RESTART 5) A campaign is active, but it's the wrong one -- REDO CONFIG & RESTART For the Wi-Fi Channel, if it is incorrect, writing hostapd.conf and restarting lighttpd will fix it. """ logger.debug("Need HOSTAPD Update: %s " % str(needHostAPDUpdate)) logger.debug("Need CaptivePortalConf Update: %s" % str(needCaptivePortalConfUpdate)) if ((currentCampaignId == None) and (correctActiveCampaign == None)): if (needHostAPDUpdate): SystemWriter.writeHostAPDConfFile(None, True) if (needCaptivePortalConfUpdate): SystemWriter.writeCaptivePortalConf(currentCampaignId) logger.debug("No campaign changes necessary, no campaign active") elif ((currentCampaignId != None) and (correctActiveCampaign != None) and ( int(currentCampaignId) == int(correctActiveCampaign.id) ) ): if (needHostAPDUpdate): SystemWriter.writeHostAPDConfFile(correctActiveCampaign, True) if (needCaptivePortalConfUpdate): SystemWriter.writeCaptivePortalConf(correctActiveCampaign) logger.debug("No campaign changes necessary, campaign %s active" % str(correctActiveCampaign.id)) elif (correctActiveCampaign == None): logger.info("No campaign should be active, deactivating") SystemWriter.setLogProperty(ClientURISettings.WIFI_TRANSFER_PROP, SystemWriter.getFileName(ClientURISettings.MESSAGE_WIFI, None)) SystemWriter.writeCaptivePortalConf(None) SystemWriter.makeLighttpdConfFile(None, False) SystemWriter.writeHostAPDConfFile(None, True) if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): ProcessExecutor.openCaptiveOrLimitedPortal() else: logger.info("Campaign changes needed, updating and restarting with from campaign [%s] to active [%s]" % (str(currentCampaignId), (str(correctActiveCampaign.id)))) SystemWriter.setLogProperty(ClientURISettings.WIFI_TRANSFER_PROP, SystemWriter.getFileName(ClientURISettings.MESSAGE_WIFI, correctActiveCampaign.id)) SystemWriter.writeCaptivePortalConf(correctActiveCampaign) SystemWriter.makeLighttpdConfFile(correctActiveCampaign, False) SystemWriter.writeHostAPDConfFile(correctActiveCampaign, True) #CAMPAIGN_NO_INTERNET = 1 #CAMPAIGN_LIMITED = 2 #CAMPAIGN_HOTSPOT = 3 #CAMPAIGN_MOBILOZOPHY = 4 #CAMPAIGN_FACEBOOK = 5 if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): if (int(correctActiveCampaign.wifiCampaign.hotspotMode) == int(ClientURISettings.CAMPAIGN_HOTSPOT)): ProcessExecutor.openHotspotPortal() elif (int(correctActiveCampaign.wifiCampaign.hotspotMode) == int(ClientURISettings.CAMPAIGN_NO_INTERNET)): ProcessExecutor.openCaptiveOrLimitedPortal() elif (int(correctActiveCampaign.wifiCampaign.hotspotMode) == int(ClientURISettings.CAMPAIGN_LIMITED)): ProcessExecutor.openCaptiveOrLimitedPortal() elif (int(correctActiveCampaign.wifiCampaign.hotspotMode) == int(ClientURISettings.CAMPAIGN_FACEBOOK)): ProcessExecutor.openFacebookPortal() else: logger.error("Not sure what to do with wifi campaign of type %s" % correctActiveCampaign.wifiCampaign.hotspotMode) else: logger.debug("Alternate campaign modes not set up for this platform") except Exception as err: logger.error(err)
def writeNodeToFile(filepath, node): SystemWriter.writeFile(filepath, XMLUtils.elementToString(node))
def initDNSAndDHCP(self): #if not bluegiga SystemWriter.makeDefaultDnsmasqConfFile(False) SystemWriter.makeDnsmasqConfFile()
def run(): global DeviceClientInstance # See which campaign is active now, if it's not right, # the right way to see which Wi-Fi is active is to read the lighttpd.conf # and look at the 'server.document-root' # we really should test further and see if the content served matches the content # in the campaign currentCampaignId = None if (os.path.exists(ClientURISettings.BLUETOOTH_OBEXSENDER_CONFIG_FILE)): inf = open(ClientURISettings.BLUETOOTH_OBEXSENDER_CONFIG_FILE, "r") for line in inf.readlines(): # """server.document-root = "%s"\n""" % doc_root if line.find("basedir ") == 0: try: bt_dir = line.split("/") if (len(bt_dir) == 4) or (len(bt_dir) == 5): pass # no active else: currentCampaignId = line.split("/")[4] break except Exception as err: logger.info(err) inf.close() if (currentCampaignId == ClientURISettings.MESSAGE_NOACTIVE): currentCampaignId = None else: logger.debug("Config file does not exist %s" % ClientURISettings.BLUETOOTH_OBEXSENDER_CONFIG_FILE) correctActiveCampaign = DeviceClientInstance.campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_BLUETOOTH) """ Possibilites: 1) No campaign is active and none should be -- RETURN 2) A campaign is active, and it's the right one -- RETURN 3) A campaign is active, but none should be -- REDO AS DEFAULT CONFIG & RESTART 4) No campaign is active and one should be -- REDO CONFIG & RESTART 5) A campaign is active, but it's the wrong one -- REDO CONFIG & RESTART """ if (currentCampaignId == None and correctActiveCampaign == None): logger.debug("No campaign changes necessary, no campaign active") if(Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): logger.debug("Stopping bluetooth so we don't clog the wifi") ProcessExecutor.stopBluetooth() return elif ((currentCampaignId != None) and (correctActiveCampaign != None) and (int(currentCampaignId) == int(correctActiveCampaign.id))): logger.debug("No campaign changes necessary, campaign %d active" % str(correctActiveCampaign.id)) return elif correctActiveCampaign == None: logger.info("No campaign should be active, deactivating") SystemWriter.setLogProperty(ClientURISettings.BLUETOOTH_TRANSFER_PROP, SystemWriter.getFileName(ClientURISettings.MESSAGE_BLUETOOTH, None)) SystemWriter.writeObexSenderConfig(None) SystemWriter.writeBluetoothConfig(None) if(Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): logger.debug("Stopping bluetooth") ProcessExecutor.stopBluetooth() if(Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA): logger.debug("Restarting bluetooth") ProcessExecutor.restartBluetooth() else: logger.info("Campaign changes needed, updating and restarting") SystemWriter.setLogProperty(ClientURISettings.BLUETOOTH_TRANSFER_PROP, SystemWriter.getFileName(ClientURISettings.MESSAGE_BLUETOOTH, correctActiveCampaign.id)) SystemWriter.writeObexSenderConfig(correctActiveCampaign) SystemWriter.writeBluetoothConfig(correctActiveCampaign) SystemWriter.clearObexSenderBlockList() logger.debug("Restarting bluetooth") ProcessExecutor.restartBluetooth()
def readNodeFromFile(filepath): data = SystemWriter.readFileToString(filepath) node = XMLUtils.stringToElement(data) return node