def getMACeth0(): if ProcessExecutor.MAC != None: return ProcessExecutor.MAC if (Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA or \ Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG or \ Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT): result = ProcessExecutor.executeCommand("/sbin/ifconfig eth0") for line in result: if (line.find("HWaddr") > -1): for token in line.split(): if (ProcessExecutor.macRE.match(token)): ProcessExecutor.MAC = ProcessExecutor.formatMAC( token) return ProcessExecutor.MAC elif (Platform.getPlatform() == Platform.PLATFORM_MAC): result = ProcessExecutor.executeCommand("/sbin/ifconfig en0") for line in result: if (line.find("ether") > -1): for token in line.split(): if ProcessExecutor.macRE.match(token): ProcessExecutor.MAC = ProcessExecutor.formatMAC( token) return ProcessExecutor.MAC else: logger.info( "getMACeth0 not implemented for this platform yet, please do so" ) logger.fatal("Could not determine the MAC address for this device!!!") return None
def getMACeth0(): if ProcessExecutor.MAC != None: return ProcessExecutor.MAC if ( Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA or Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG or Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT ): result = ProcessExecutor.executeCommand("/sbin/ifconfig eth0") for line in result: if line.find("HWaddr") > -1: for token in line.split(): if ProcessExecutor.macRE.match(token): ProcessExecutor.MAC = ProcessExecutor.formatMAC(token) return ProcessExecutor.MAC elif Platform.getPlatform() == Platform.PLATFORM_MAC: result = ProcessExecutor.executeCommand("/sbin/ifconfig en0") for line in result: if line.find("ether") > -1: for token in line.split(): if ProcessExecutor.macRE.match(token): ProcessExecutor.MAC = ProcessExecutor.formatMAC(token) return ProcessExecutor.MAC else: logger.info("getMACeth0 not implemented for this platform yet, please do so") logger.fatal("Could not determine the MAC address for this device!!!") return None
def getSerialNumber(): if Platform.getPlatform() == Platform.PLATFORM_MAC: result = ProcessExecutor.executeCommand("/usr/sbin/system_profiler -detailLevel basic") for line in result: if line.find("Serial Number (system)") > -1: serial = line.strip().split()[-1] # get the last item return serial elif Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA: result = ProcessExecutor.executeCommand("/sbin/wrapid") for line in result: if line.find("Hardware serial number") > -1: serial = line.strip().split()[-1] # get the last item return serial return "Unknown"
def getSerialNumber(): if (Platform.getPlatform() == Platform.PLATFORM_MAC): result = ProcessExecutor.executeCommand( "/usr/sbin/system_profiler -detailLevel basic") for line in result: if (line.find("Serial Number (system)") > -1): serial = line.strip().split()[-1] # get the last item return serial elif Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA: result = ProcessExecutor.executeCommand("/sbin/wrapid") for line in result: if (line.find("Hardware serial number") > -1): serial = line.strip().split()[-1] # get the last item return serial return "Unknown"
def writeHostAPDConfFile(campaign, restartServer=True): global DeviceClientInstance clientConfig = DeviceClientInstance.clientConfig if campaign != None: wifiCampaign = campaign.wifiCampaign else: wifiCampaign = None if wifiCampaign == None: networkName = ClientURISettings.MESSAGE_DEFAULT_WIFI else: networkName = wifiCampaign.networkName accessPointInterface = SystemWriter.getCurrentAccessPointInterface() data = hostapd.CONTENT.replace("PROXIMUSCHANNELHERE", clientConfig.channel).replace( "PROXIMUSNETWORKNAMEHERE", networkName).replace( "PROXIMUSACCESSPOINTHERE", accessPointInterface) if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT): logger.info("writing hostapd.conf file %s" % ClientURISettings.HOSTAPD_CONF_FILE_DDWRT) SystemWriter.writeFile(ClientURISettings.HOSTAPD_CONF_FILE_DDWRT, data) else: logger.info("writing hostapd.conf file %s" % ClientURISettings.HOSTAPD_CONF_FILE) SystemWriter.writeFile(ClientURISettings.HOSTAPD_CONF_FILE, data) if (restartServer): ProcessExecutor.restartLighttpd( ) # on bluegiga this script restarts the hostapd daemon too
def writeLogProperties(props=None, read=True): global DeviceClientInstance if props != None: pass elif (read): props = SystemWriter.readLogProperties() else: props = {} currentBTCampaignId = None currentWifiCampaignId = None currentBTCampaign = DeviceClientInstance.campaignHandler.getActiveCampaign( ClientURISettings.MESSAGE_BLUETOOTH) if (currentBTCampaign != None): currentBTCampaignId = currentBTCampaign.id currentWifiCampaign = DeviceClientInstance.campaignHandler.getActiveCampaign( ClientURISettings.MESSAGE_WIFI) if (currentWifiCampaign != None): currentWifiCampaignId = currentWifiCampaign.id platform = Platform.getPlatform().lower() currBluetoothTransferFile = SystemWriter.getFileName( ("bluetoothTransfer_%s" % platform), currentBTCampaignId) props[ClientURISettings. BLUETOOTH_TRANSFER_PROP] = currBluetoothTransferFile currentWifiLogFile = SystemWriter.getFileName(("wifi_%s" % platform), currentWifiCampaignId) props[ClientURISettings.WIFI_TRANSFER_PROP] = currentWifiLogFile SystemWriter.saveLogProperties(props) return props
def writeLogProperties(props=None, read=True): global DeviceClientInstance if props != None: pass elif (read): props = SystemWriter.readLogProperties() else: props = {} currentBTCampaignId = None currentWifiCampaignId = None currentBTCampaign = DeviceClientInstance.campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_BLUETOOTH) if (currentBTCampaign != None): currentBTCampaignId = currentBTCampaign.id currentWifiCampaign = DeviceClientInstance.campaignHandler.getActiveCampaign(ClientURISettings.MESSAGE_WIFI) if (currentWifiCampaign != None): currentWifiCampaignId = currentWifiCampaign.id platform = Platform.getPlatform().lower() currBluetoothTransferFile = SystemWriter.getFileName(("bluetoothTransfer_%s" % platform), currentBTCampaignId) props[ClientURISettings.BLUETOOTH_TRANSFER_PROP] = currBluetoothTransferFile currentWifiLogFile = SystemWriter.getFileName(("wifi_%s" % platform), currentWifiCampaignId) props[ClientURISettings.WIFI_TRANSFER_PROP] = currentWifiLogFile SystemWriter.saveLogProperties(props) return props
def getKernelVersion(): if (Platform.getPlatform() == Platform.PLATFORM_MAC): result = ProcessExecutor.executeCommand("/usr/bin/uname -r") else: result = ProcessExecutor.executeCommand("/bin/uname -r") for line in result: return line.strip()
def getKernelVersion(): if Platform.getPlatform() == Platform.PLATFORM_MAC: result = ProcessExecutor.executeCommand("/usr/bin/uname -r") else: result = ProcessExecutor.executeCommand("/bin/uname -r") for line in result: return line.strip()
def writeHostAPDConfFile(campaign, restartServer=True): global DeviceClientInstance clientConfig = DeviceClientInstance.clientConfig if campaign != None: wifiCampaign = campaign.wifiCampaign else: wifiCampaign = None if wifiCampaign == None: networkName = ClientURISettings.MESSAGE_DEFAULT_WIFI else: networkName = wifiCampaign.networkName accessPointInterface = SystemWriter.getCurrentAccessPointInterface() data = hostapd.CONTENT.replace("PROXIMUSCHANNELHERE", clientConfig.channel ).replace("PROXIMUSNETWORKNAMEHERE", networkName ).replace("PROXIMUSACCESSPOINTHERE", accessPointInterface) if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT): logger.info("writing hostapd.conf file %s" % ClientURISettings.HOSTAPD_CONF_FILE_DDWRT) SystemWriter.writeFile(ClientURISettings.HOSTAPD_CONF_FILE_DDWRT, data) else: logger.info("writing hostapd.conf file %s" % ClientURISettings.HOSTAPD_CONF_FILE) SystemWriter.writeFile(ClientURISettings.HOSTAPD_CONF_FILE, data) if (restartServer): ProcessExecutor.restartLighttpd() # on bluegiga this script restarts the hostapd daemon too
def setHotSpotMode(self): correctActiveCampaign = self.getActiveCampaign(ClientURISettings.MESSAGE_WIFI) if (correctActiveCampaign == None): logger.info("No campaign is active (hotspot)") ProcessExecutor.openCaptiveOrLimitedPortal() return logger.info("Loading initial campaign hotspot mode as " + correctActiveCampaign.wifiCampaign.hotspotMode) #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 " + correctActiveCampaign.wifiCampaign.hotspotMode) else: logger.debug("Alternate campaign modes not set up for this platform")
def executePortalPythonScript(argumentString): if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): logger.info("Opening Portal: %s" % argumentString) return ProcessExecutor.executeCommand(ClientURISettings.BIN_DIR + os.sep + "portal.py " + argumentString) else: logger.error("Sorry, portal.py not working for this platform yet")
def getCurrentAccessPointInterface(): content = SystemWriter.readFileToString(ClientURISettings.ACCESS_POINT_INTERFACE_FILE) if (content != None): return content.strip() else: if(Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): return "uap0" else: return "wlan0"
def getCurrentAccessPointInterface(): content = SystemWriter.readFileToString( ClientURISettings.ACCESS_POINT_INTERFACE_FILE) if (content != None): return content.strip() else: if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): return "uap0" else: return "wlan0"
def getCorrectExtBackhaulInterface(write=True): try: if ( write ): ProcessExecutor.setCorrectBackhaulInterface() content = SystemWriter.readFileToString(ClientURISettings.CAPTIVEPORTAL_BACKHAUL_EXT_INTERFACE_FILE) if (content != None): return content.strip() else: if Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA: return "nap" else: return "eth0" except Exception as err: logger.error(err) logger.debug("Returning default interface") if Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA: return "nap" else: return "eth0"
def getCorrectExtBackhaulInterface(write=True): try: if (write): ProcessExecutor.setCorrectBackhaulInterface() content = SystemWriter.readFileToString( ClientURISettings.CAPTIVEPORTAL_BACKHAUL_EXT_INTERFACE_FILE) if (content != None): return content.strip() else: if Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA: return "nap" else: return "eth0" except Exception as err: logger.error(err) logger.debug("Returning default interface") if Platform.getPlatform() == Platform.PLATFORM_LINUX_BLUEGIGA: return "nap" else: return "eth0"
def setCorrectBackhaulInterface(): if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG): result = ProcessExecutor.executeCommand( ClientURISettings.BASH_DIR + os.sep + Platform.PLATFORM_LINUX_DREAMPLUG + os.sep + "autoInterface.sh backhaul") logger.debug(str(result)) else: result = ProcessExecutor.executeCommand( ClientURISettings.BASH_DIR + os.sep + "autoInterface.sh backhaul") logger.debug(str(result))
def makeLighttpdConfFile(campaign=None, restartServer=True): props = SystemWriter.readLogProperties() try: logger.info("writing lighttpd.conf file %s" % ClientURISettings.LIGHTTPD_FILE) proxdata = "" phppath = "/usr/bin/php" if (campaign != None): campaign_id = campaign.id doc_root = ClientURISettings.CAMPAIGNS_ROOT_DIR + os.sep + campaign_id + "/WIFI/" else: doc_root = ClientURISettings.CAMPAIGNS_ROOT_DIR log_file = ClientURISettings.LOG_WORKING + os.sep + props[ ClientURISettings.WIFI_TRANSFER_PROP] http_doc_root = """server.document-root = "%s"\n""" % doc_root proxdata += http_doc_root if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: # On non-bluegiga devices we have to insert the MAC address in a pipe logger proxdata += """accesslog.filename = "|/home/proximus/bin/accesslog_addmac.py"\n""" proxdata += """accesslog.format = "[%h] %t [%r] [%s] [%{User-Agent}i] [%V]"\n""" phppath = "/usr/bin/php-cgi" else: proxdata += """accesslog.filename = "%s"\n""" % log_file proxdata += """accesslog.format = "[%h] %t [%r] [%s] [%{User-Agent}i] [%V] [%M]"\n""" phppath = "/usr/bin/php" content = lighttpd.CONTENT.replace("PROXIMUS_HTTP_CONFIG_HERE", proxdata) # virtual dir setup coolspot.proximusmobility\.com virtualDir = """ $HTTP["host"] =~ "(^|\.)coolspot.proximusmobility\.com$" { %s }""" % http_doc_root content = content.replace("PROXIMUS_VIRTUAL_DIR", virtualDir) content = content.replace("PROXIMUS_PHP_PATH", phppath) SystemWriter.writeFile(ClientURISettings.LIGHTTPD_FILE, content) # Commented out, why is this here? Do it separately #SystemWriter.writeCaptivePortalConf(campaign) if (restartServer): ProcessExecutor.restartLighttpd() except Exception as err: logger.error(err)
def setCorrectBackhaulInterface(): if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: result = ProcessExecutor.executeCommand( ClientURISettings.BASH_DIR + os.sep + Platform.PLATFORM_LINUX_DREAMPLUG + os.sep + "autoInterface.sh backhaul" ) logger.debug(str(result)) else: result = ProcessExecutor.executeCommand(ClientURISettings.BASH_DIR + os.sep + "autoInterface.sh backhaul") logger.debug(str(result))
def makeDefaultDnsmasqConfFile(restartDNSMasq=True): #Only write file if its a dreamplug #bluegiga captiveportal takes care of this automatically if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: try: ProcessExecutor.setCorrectBackhaulInterface() logger.info("writing dnsmasq file %s" % ClientURISettings.DNSMASQ_DEFAULT_FILE) content = default_dnsmasq.CONTENT.replace("PROXIMUS_DNSMASQ_CONFIG_FILE", ClientURISettings.DNSMASQ_CONFIG_FILE).replace("PROXIMUS_DNS_INTERFACE", SystemWriter.getCurrentAccessPointInterface()) SystemWriter.writeFile(ClientURISettings.DNSMASQ_DEFAULT_FILE, content) if (restartDNSMasq): ProcessExecutor.restartDNS() except Exception as err: logger.error(err)
def makeLighttpdConfFile(campaign=None, restartServer=True): props = SystemWriter.readLogProperties() try: logger.info("writing lighttpd.conf file %s" % ClientURISettings.LIGHTTPD_FILE) proxdata = "" phppath = "/usr/bin/php" if (campaign != None): campaign_id = campaign.id doc_root = ClientURISettings.CAMPAIGNS_ROOT_DIR + os.sep + campaign_id + "/WIFI/" else: doc_root = ClientURISettings.CAMPAIGNS_ROOT_DIR log_file = ClientURISettings.LOG_WORKING + os.sep + props[ClientURISettings.WIFI_TRANSFER_PROP] http_doc_root = """server.document-root = "%s"\n""" % doc_root proxdata += http_doc_root if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: # On non-bluegiga devices we have to insert the MAC address in a pipe logger proxdata += """accesslog.filename = "|/home/proximus/bin/accesslog_addmac.py"\n""" proxdata += """accesslog.format = "[%h] %t [%r] [%s] [%{User-Agent}i] [%V]"\n""" phppath = "/usr/bin/php-cgi" else: proxdata += """accesslog.filename = "%s"\n""" % log_file proxdata += """accesslog.format = "[%h] %t [%r] [%s] [%{User-Agent}i] [%V] [%M]"\n""" phppath = "/usr/bin/php" content = lighttpd.CONTENT.replace("PROXIMUS_HTTP_CONFIG_HERE", proxdata) # virtual dir setup coolspot.proximusmobility\.com virtualDir =""" $HTTP["host"] =~ "(^|\.)coolspot.proximusmobility\.com$" { %s }""" % http_doc_root content = content.replace("PROXIMUS_VIRTUAL_DIR", virtualDir) content = content.replace("PROXIMUS_PHP_PATH", phppath) SystemWriter.writeFile(ClientURISettings.LIGHTTPD_FILE, content) # Commented out, why is this here? Do it separately #SystemWriter.writeCaptivePortalConf(campaign) if (restartServer): ProcessExecutor.restartLighttpd() except Exception as err: logger.error(err)
def makeDnsmasqConfFile(restartDNSMasq=True): try: logger.info("writing dnsmasq.conf file %s" % ClientURISettings.DNSMASQ_CONFIG_FILE) range = "dhcp-range=192.168.45.50,192.168.45.150,1h" leases = "dhcp-leasefile=%s" % (ClientURISettings.DNSMASQ_LEASES_FILE) config_dir = "conf-dir=/home/proximus/config/dnsmasq.d" if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: pass content = dnsmasq.CONTENT.replace("PROXIMUS_DHCP_RANGE", range).replace("PROXIMUS_DNS_LEASES_FILE", leases).replace("PROXIMUS_DNS_CONFIG_DIR", config_dir) SystemWriter.writeFile(ClientURISettings.DNSMASQ_CONFIG_FILE, content) if (restartDNSMasq): ProcessExecutor.restartDNS() except Exception as err: logger.error(err)
def executeCommand(cmd): if type(cmd) == types.StringType: cmd = shlex.split(cmd) logger.debug(cmd) try: proc = None shell = False if Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT: shell = True else: shell = False proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=shell) (stdout_value, stderr_value) = proc.communicate() logger.debug("O:" + str(stdout_value)) logger.debug("E:" + str(stderr_value)) return stdout_value.strip().split("\n") except Exception as err: logger.error("%s - %s" % (cmd, str(err))) return None
def makeDefaultDnsmasqConfFile(restartDNSMasq=True): #Only write file if its a dreamplug #bluegiga captiveportal takes care of this automatically if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: try: ProcessExecutor.setCorrectBackhaulInterface() logger.info("writing dnsmasq file %s" % ClientURISettings.DNSMASQ_DEFAULT_FILE) content = default_dnsmasq.CONTENT.replace( "PROXIMUS_DNSMASQ_CONFIG_FILE", ClientURISettings.DNSMASQ_CONFIG_FILE).replace( "PROXIMUS_DNS_INTERFACE", SystemWriter.getCurrentAccessPointInterface()) SystemWriter.writeFile(ClientURISettings.DNSMASQ_DEFAULT_FILE, content) if (restartDNSMasq): ProcessExecutor.restartDNS() except Exception as err: logger.error(err)
def makeDnsmasqConfFile(restartDNSMasq=True): try: logger.info("writing dnsmasq.conf file %s" % ClientURISettings.DNSMASQ_CONFIG_FILE) range = "dhcp-range=192.168.45.50,192.168.45.150,1h" leases = "dhcp-leasefile=%s" % ( ClientURISettings.DNSMASQ_LEASES_FILE) config_dir = "conf-dir=/home/proximus/config/dnsmasq.d" if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: pass content = dnsmasq.CONTENT.replace( "PROXIMUS_DHCP_RANGE", range).replace("PROXIMUS_DNS_LEASES_FILE", leases).replace("PROXIMUS_DNS_CONFIG_DIR", config_dir) SystemWriter.writeFile(ClientURISettings.DNSMASQ_CONFIG_FILE, content) if (restartDNSMasq): ProcessExecutor.restartDNS() except Exception as err: logger.error(err)
def executeCommand(cmd): if (type(cmd) == types.StringType): cmd = shlex.split(cmd) logger.debug(cmd) try: proc = None shell = False if (Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT): shell = True else: shell = False proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=shell) (stdout_value, stderr_value) = proc.communicate() logger.debug("O:" + str(stdout_value)) logger.debug("E:" + str(stderr_value)) return stdout_value.strip().split("\n") except Exception as err: logger.error("%s - %s" % (cmd, str(err))) return None
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 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 executePortalPythonScript(argumentString): if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: logger.info("Opening Portal: %s" % argumentString) return ProcessExecutor.executeCommand(ClientURISettings.BIN_DIR + os.sep + "portal.py " + argumentString) else: logger.error("Sorry, portal.py not working for this platform yet")
class ClientURISettings: DEV = True if DEV: SSL = False else: SSL = True WAR_NAME_API = "ProximusTomorrow-war/api" # if this is explicitly set it overrides the "DEV" flag server = None server_port = None #DEV_SERVER = "localhost" DEV_SERVER = "dev.proximusmobility.net" PROD_SERVER = "devices.proximusmobility.com" if Platform.getPlatform() == Platform.PLATFORM_LINUX_DDWRT: PROXIMUS_ROOT = "/jffs/home/proximus" else: PROXIMUS_ROOT = "/home/proximus" #client's config files CONFIG_ROOT = PROXIMUS_ROOT + os.sep + "config" CONFIG_FILE = CONFIG_ROOT + os.sep + "client.cfg.xml" CAMPAIGNS_FILE = CONFIG_ROOT + os.sep + "campaigns.cfg.xml" BLUETOOTH_CONFIG_FILE = "bluetooth.cfg.xml" #This is campaign dependent (don't know the absolute path) ACCESS_POINT_INTERFACE_FILE = CONFIG_ROOT + os.sep + "access_point.conf" CAPTIVEPORTAL_BACKHAUL_EXT_INTERFACE_FILE = CONFIG_ROOT + os.sep + "backhaul.conf" BLUETOOTH_OBEXSENDER_CONFIG_FILE = CONFIG_ROOT + os.sep + "obexsender.conf" if Platform.getPlatform() == Platform.PLATFORM_LINUX_DREAMPLUG: BLUETOOTH_OBEXSENDER_BLOCK_LIST = CONFIG_ROOT + os.sep + "blocklist.dump" else: BLUETOOTH_OBEXSENDER_BLOCK_LIST = "/home/proximus/config/blocklist.dump" BLUETOOTH_IWRAP_CONFIG_FILE = "/etc/bluetooth.conf" CAPTIVEPORTAL_CONFIG_DIR = "/etc/sysconfig" CAPTIVEPORTAL_CONFIG_FILE = CAPTIVEPORTAL_CONFIG_DIR + os.sep + "captiveportal" HOSTAPD_CONF_FILE = "/etc/hostapd.conf" HOSTAPD_CONF_FILE_DDWRT = CONFIG_ROOT + os.sep + "hostapd.conf" DNSMASQ_DEFAULT_FILE = "/etc/default/dnsmasq" DNSMASQ_CONFIG_FILE = CONFIG_ROOT + os.sep + "dnsmasq.conf" DNSMASQ_CONFIG_FOLDER = CONFIG_ROOT + os.sep + "dnsmasq.d" DNSMASQ_LEASES_FILE = CONFIG_ROOT + os.sep + "dnsmasq.leases" LIGHTTPD_FILE = CONFIG_ROOT + os.sep + "lighttpd-inc.conf" PROXIMUS_PROPERTIES_FILE = CONFIG_ROOT + os.sep + "proximus.properties" LOG_PROPERTIES_FILE = CONFIG_ROOT + os.sep + "log.properties" BLUETOOTH_TRANSFER_PROP = "bluetooth_transfer" BLUETOOTH_DWELL_PROP = "bluetooth_dwell" WIFI_TRANSFER_PROP = "wifi_transfer" #client's server content CAMPAIGNS_ROOT_DIR = PROXIMUS_ROOT + os.sep + "campaigns" ERROR_ROOT_DIR = CONFIG_ROOT + os.sep + "www-errors" SWUPDATE_ROOT_DIR = PROXIMUS_ROOT + os.sep + "swupdate" # campaign connectivity types CAMPAIGN_NO_INTERNET = 1 CAMPAIGN_LIMITED = 2 CAMPAIGN_HOTSPOT = 3 CAMPAIGN_MOBILOZOPHY = 4 CAMPAIGN_FACEBOOK = 5 # Bluegiga defaults to this value ACCESS_POINT = "192.168.45.3" ACCESS_POINT_PORT = "8080" #client log directory structure LOG_ROOT = PROXIMUS_ROOT + os.sep + "logs" LOG_QUEUE = LOG_ROOT + os.sep + "queue" LOG_COMPLETED = LOG_ROOT + os.sep + "completed" LOG_WORKING = LOG_ROOT + os.sep + "working" #client bin directory BIN_DIR = PROXIMUS_ROOT + os.sep + "bin" BASH_DIR = BIN_DIR + os.sep + "bash_scripts" # messages MESSAGE_NOACTIVE = "-1" MESSAGE_BLUETOOTH = "BLUETOOTH" MESSAGE_WIFI = "WIFI" MESSAGE_DEFAULT_WIFI = "Proximus Mobility Offer Network" MESSAGE_DEFAULT_BT = "Proximus Mobility" @staticmethod def isDEV(): return ClientURISettings.DEV @staticmethod def getServer(): if (ClientURISettings.server == None): this_server = ClientURISettings.DEV_SERVER if ClientURISettings.DEV else ClientURISettings.PROD_SERVER else: this_server = ClientURISettings.server if (ClientURISettings.SSL): transport = "https" else: transport = "http" return transport + "://" + this_server + ":" + ClientURISettings.getPort() + "/" + ClientURISettings.WAR_NAME_API @staticmethod def getPort(): if (ClientURISettings.server_port != None): return ClientURISettings.server_port else: if (ClientURISettings.SSL): server_port = "8181" if ClientURISettings.isDEV() else "8443" else: server_port = "8080" if ClientURISettings.isDEV() else "80" return server_port @staticmethod def getRegistrationUri(): logger.debug("Returning %s" % ClientURISettings.getServer() + "/register") return ClientURISettings.getServer() + "/register" @staticmethod def getStatusUri(): return ClientURISettings.getServer() + "/status" @staticmethod def getUploadUri(): return ClientURISettings.getServer() + "/upload" @staticmethod def getDownloadUri(): return ClientURISettings.getServer() + "/download" @staticmethod def getSoftwareUpdateURI(): return ClientURISettings.getServer() + "/software-update" """ * Change it only if a valid and is not the same as the previous one * @param server """ @staticmethod def changeServer(server): if (server != None and (len(server) > 0) and (server != ClientURISettings.server)): ClientURISettings.server = server ClientURISettings.logger.debug("Changing server to: " + ClientURISettings.server) @staticmethod def changePort(port): if ((port != None) and (len(port) > 0) and (port != ClientURISettings.server_port)): ClientURISettings.server_port = port ClientURISettings.logger.debug("Changing port to: " + ClientURISettings.server_port) @staticmethod def changeAccessPoint(accessPoint): if((accessPoint != None) and (len(accessPoint) > 0) and (accessPoint != ClientURISettings.ACCESS_POINT)): ClientURISettings.ACCESS_POINT = accessPoint ClientURISettings.logger.debug("Changing Access Point to: " + ClientURISettings.ACCESS_POINT)