def _set_and_test_adapter_list(self, adapterIDs, priority, limit): for adapterID in adapterIDs: speedify.adapter_priority(adapterID, priority) speedify.adapter_ratelimit(adapterID, limit) speedify.adapter_datalimit_daily(adapterID, limit) speedify.adapter_datalimit_monthly(adapterID, limit, 0) updated_adapters = speedify.show_adapters() priorities = [adapter['priority'] for adapter in updated_adapters] rate_limits = [adapter['rateLimit'] for adapter in updated_adapters] daily_limits = [ adapter['dataUsage']['usageDailyLimit'] for adapter in updated_adapters ] monthly_limits = [ adapter['dataUsage']['usageMonthlyLimit'] for adapter in updated_adapters ] for set_priority, rate_limit, daily_limit, monthly_limit in zip( priorities, rate_limits, daily_limits, monthly_limits): # Disconnected adapters speedify is aware of will have an unchangable priority never if (set_priority != Priority.NEVER.value): self.assertEqual(set_priority, priority.value) self.assertEqual(rate_limit, limit) self.assertEqual(daily_limit, limit) self.assertEqual(monthly_limit, limit)
def get_speedify_settings(): ''' Returns the current speedify settings as a dict :returns: dict -- dict of speedify settings ''' settings = {} # pulls out the current settings... couple flaws: # can't get the privacy settings without changing them first, CAN get overflow_threshold # but the other functions can't actually set that. try: adapters = speedify.show_adapters() for adapter in adapters: logging.debug("Adapter is :" + str(adapter)) adaptername = adapter["name"] settings["adapter_ratelimit_" + adaptername] = adapter["rateLimit"] settings["adapter_priority_" + adaptername] = adapter["priority"] if "dataUsage" in adapter: limits = adapter["dataUsage"] if limits: if limits["usageMonthlyLimit"]: settings["adapter_datalimit_monthly_" + adaptername] = limits["usageMonthlyLimit"] if limits["usageDailyLimit"]: settings["adapter_datalimit_daily_" + adaptername] = limits["usageDailyLimit"] currentsettings = speedify.show_settings() logging.debug("Settings are:" + str(currentsettings)) settings["encryption"] = currentsettings["encrypted"] settings["jumbo"] = currentsettings["jumboPackets"] settings["transport"] = currentsettings["transportMode"] settings["startupconnect"] = currentsettings["startupConnect"] settings["mode"] = currentsettings["bondingMode"] settings["overflow_threshold"] = currentsettings["overflowThreshold"] settings["packet_aggregation"] = currentsettings["packetAggregation"] # TODO: can no longer get connectmethod back out! connectmethodsettings = speedify.show_connectmethod() settings["connectmethod"] = connectmethodsettings["connectMethod"] user = speedify.show_user() logging.debug("User is:" + str(user)) privacysettings = speedify.show_privacy() if ("dnsleak" in privacysettings): settings["privacy_dnsleak"] = privacysettings["dnsleak"] if ("killswitch" in privacysettings): settings["privacy_killswitch"] = privacysettings["killswitch"] # CANNOT GET "privacy_dnsleak" or "privacy_killswitch" # without setting on of them except SpeedifyError as se: logging.error("Speedify error on getSpeedfiySetting:" + str(se)) return settings
def test_encryption(self): adapters = speedify.show_adapters() self.assertTrue(adapters) # just grab first adapter for testing adapterID = [adapter['adapterID'] for adapter in adapters][0] speedify.adapter_encryption(adapterID, False) mysettings = speedify.show_settings() perConnectionEncryptionEnabled = mysettings[ "perConnectionEncryptionEnabled"] self.assertTrue(perConnectionEncryptionEnabled) encrypted = mysettings["encrypted"] perConnectionEncryptionSettings = mysettings[ "perConnectionEncryptionSettings"] firstadapter = perConnectionEncryptionSettings[0] self.assertEqual(firstadapter["adapterID"], adapterID) self.assertEqual(firstadapter["encrypted"], False) # main thing should still be encrypted just not our one adapter self.assertTrue(encrypted) speedify.encryption(False) #this should both turn off encryption and wipe the custom settings mysettings = speedify.show_settings() perConnectionEncryptionEnabled = mysettings[ "perConnectionEncryptionEnabled"] self.assertFalse(perConnectionEncryptionEnabled) encrypted = mysettings["encrypted"] self.assertFalse(encrypted) # now let's test with only the adapter being encrypted speedify.adapter_encryption(adapterID, True) mysettings = speedify.show_settings() perConnectionEncryptionEnabled = mysettings[ "perConnectionEncryptionEnabled"] self.assertTrue(perConnectionEncryptionEnabled) encrypted = mysettings["encrypted"] perConnectionEncryptionSettings = mysettings[ "perConnectionEncryptionSettings"] firstadapter = perConnectionEncryptionSettings[0] self.assertEqual(firstadapter["adapterID"], adapterID) self.assertEqual(firstadapter["encrypted"], True) speedify.encryption(True) #this should both turn on encryption and wipe the custom settings mysettings = speedify.show_settings() perConnectionEncryptionEnabled = mysettings[ "perConnectionEncryptionEnabled"] self.assertFalse(perConnectionEncryptionEnabled) encrypted = mysettings["encrypted"] self.assertTrue(encrypted)
def _find_adapterids(adaptertype="wifi"): # gives you a list of Guids which match the string you pass in. could be a type "wifi", "ethernet", # a name like "Ethernet 2" or "en0", or the GUID of an adapter. adapterGuids = [] isGuid = False isAll = False adaptertype = adaptertype.lower() if (adaptertype == "wifi"): # mdm takes "wifi", cli calls it "Wi-Fi", no biggie just fix adaptertype = "wi-fi" if (adaptertype.startswith("{")): # it's a guid! isGuid = True guid = adaptertype.lower() if (adaptertype == "all"): # applies to every adapter! Note that there's no guarantee on order here. # so if you have a "_cellular" and an "_all" it's random which setting # the cellular will have at the end. Would make sense to apply them in order # but we're just tossing them in a dictionary. isAll = True adapters = speedify.show_adapters() for adapter in adapters: if isAll: adapterGuids.append(str(adapter["adapterID"])) elif not isGuid: logging.debug("adapter type: " + str(adapter["type"])) if (adapter["type"].lower() == adaptertype): logging.debug("Found by type: " + str(adapter["description"]) + " guid " + str(adapter["adapterID"])) adapterGuids.append(str(adapter["adapterID"])) elif (adapter["name"].lower() == adaptertype): logging.debug("Found by name" + str(adapter["description"]) + " guid " + str(adapter["adapterID"])) adapterGuids.append(str(adapter["adapterID"])) else: if (adapter["adapterID"].lower() == guid): logging.debug("Found by guid, " + str(adapter["description"]) + " guid " + str(adapter["adapterID"])) adapterGuids.append(str(adapter["adapterID"])) return adapterGuids
def test_adapters(self): adapters = speedify.show_adapters() self.assertTrue(adapters) adapterIDs = [adapter['adapterID'] for adapter in adapters] self._set_and_test_adapter_list(adapterIDs, Priority.BACKUP, 10000000) self._set_and_test_adapter_list(adapterIDs, Priority.ALWAYS, 0)
# we do not want to connect everytime we login, just when we say speedify.startupconnect(False) # make our default connect(), connect to the closest server. speedify.connectmethod("closest") print("Settings configured") except SpeedifyError as se: print("Error setting settings " + se.message) sys.exit(1) try: print("connecting to the closest server") serverInfo = speedify.connect_closest() print("Server country: " + serverInfo["country"]) print("Server city: " + serverInfo["city"]) print("Server num: " + str(serverInfo["num"])) print("connected!") adapters = speedify.show_adapters() for adapter in adapters: if (adapter["type"] == "Wi-Fi"): print("Found a Wi-Fi card: " + str(adapter["description"])) guid = adapter["adapterID"] print("adapterID: " + str(guid)) newadapters = speedify.adapter_priority(guid, Priority.ALWAYS) print("Priority: " + adapter["priority"]) sys.exit(0) except SpeedifyError as se: print("problems connecting " + se.message) sys.exit(1)
def get_team_settings(locked, exportadapters): ''' Returns the current speedify settings as a dict :returns: dict -- dict of speedify settings ''' # The tree where we build our export settingsExport = {} try: currentsettings = speedify.show_settings() if exportadapters: adapters = speedify.show_adapters() #TODO: perConnectionEncryptionSettings #perConnectionEncryptionSettings = {} #settingsExport["perConnectionEncryptionSettings"] = perConnectionEncryptionSettings; prioritiesExport = { "Wi-Fi": { "value": "always", "locked": locked }, "Ethernet": { "value": "always", "locked": locked }, "Unknown": { "value": "always", "locked": locked }, "Cellular": { "value": "secondary", "locked": locked } } settingsExport["priorities"] = prioritiesExport ratelimitExport = { "Wi-Fi": { "value": 0, "locked": locked }, "Ethernet": { "value": 0, "locked": locked }, "Unknown": { "value": 0, "locked": locked }, "Cellular": { "value": 0, "locked": locked } } settingsExport["rateLimit"] = ratelimitExport monthlyLimitExport = { "Wi-Fi": { "value": { "monthlyLimit": 0, "monthlyResetDay": 0 }, "locked": locked }, "Ethernet": { "value": { "monthlyLimit": 0, "monthlyResetDay": 0 }, "locked": locked }, "Unknown": { "value": { "monthlyLimit": 0, "monthlyResetDay": 0 }, "locked": locked }, "Cellular": { "value": { "monthlyLimit": 0, "monthlyResetDay": 0 }, "locked": locked } } dailyLimitExport = { "Wi-Fi": { "value": 0, "locked": locked }, "Ethernet": { "value": 0, "locked": locked }, "Unknown": { "value": 0, "locked": locked }, "Cellular": { "value": 0, "locked": locked } } overlimitRateLimitExport = { "Wi-Fi": { "value": 0, "locked": locked }, "Ethernet": { "value": 0, "locked": locked }, "Unknown": { "value": 0, "locked": locked }, "Cellular": { "value": 0, "locked": locked } } settingsExport["overlimitRateLimit"] = overlimitRateLimitExport encyptdefault = currentsettings["encrypted"] perConnectionEncryptionSettingExport = { "Wi-Fi": { "value": encyptdefault, "locked": locked }, "Ethernet": { "value": encyptdefault, "locked": locked }, "Unknown": { "value": encyptdefault, "locked": locked }, "Cellular": { "value": encyptdefault, "locked": locked } } perConnectionEncryptionSettings = currentsettings[ "perConnectionEncryptionSettings"] anyperconnection = False anylimits = False for adapter in adapters: logging.debug("Adapter is :" + str(adapter)) adaptertype = adapter["type"] # everything is keyed on adapter type, if you have # more than one adapter with same type, one of them # will get overwritten by the other. for perConnectionEncryptionSetting in perConnectionEncryptionSettings: # the per connection encryption is tucked into settings instead of adapters, # but you still need to look in adapters to find the adaptertype if perConnectionEncryptionSetting["adapterID"] == adapter[ "adapterID"]: encryptExport = {} encryptExport[ "value"] = perConnectionEncryptionSetting[ "encrypted"] encryptExport["locked"] = locked anyperconnection = True perConnectionEncryptionSettingExport[ adaptertype] = encryptExport ratelimitExport[adaptertype] = {} ratelimitExport[adaptertype]["value"] = adapter["rateLimit"] ratelimitExport[adaptertype]["locked"] = locked prioritiesExport[adaptertype] = {} prioritiesExport[adaptertype]["value"] = adapter["priority"] prioritiesExport[adaptertype]["locked"] = locked if "dataUsage" in adapter: limits = adapter["dataUsage"] anylimits = True monthlyLimitExport[adaptertype] = {} monthlyLimitExport[adaptertype]["value"] = {} monthlyLimitExport[adaptertype]["value"][ "monthlyLimit"] = limits["usageMonthlyLimit"] monthlyLimitExport[adaptertype]["value"][ "monthlyResetDay"] = limits["usageMonthlyResetDay"] monthlyLimitExport[adaptertype]["locked"] = locked dailyLimitExport[adaptertype] = {} dailyLimitExport[adaptertype]["value"] = limits[ "usageDailyLimit"] dailyLimitExport[adaptertype]["locked"] = locked overlimitRateLimitExport[adaptertype] = {} overlimitRateLimitExport[adaptertype]["value"] = limits[ "overlimitRatelimit"] overlimitRateLimitExport[adaptertype]["locked"] = locked # add optional sections only if they have something if anyperconnection: settingsExport[ "perConnectionEncryptionSetting"] = perConnectionEncryptionSettingExport if anylimits: settingsExport["monthlyLimit"] = monthlyLimitExport settingsExport["dailyLimit"] = dailyLimitExport # done with adapters logging.debug("Settings are:" + str(currentsettings)) settingsExport["encrypted"] = {} settingsExport["encrypted"]["value"] = currentsettings["encrypted"] settingsExport["encrypted"]["locked"] = locked settingsExport["jumboPackets"] = {} settingsExport["jumboPackets"]["value"] = currentsettings[ "jumboPackets"] settingsExport["jumboPackets"]["locked"] = locked settingsExport["transportMode"] = {} settingsExport["transportMode"]["value"] = currentsettings[ "transportMode"] settingsExport["transportMode"]["locked"] = locked settingsExport["startupConnect"] = {} settingsExport["startupConnect"]["value"] = currentsettings[ "startupConnect"] settingsExport["startupConnect"]["locked"] = locked settingsExport["bondingMode"] = {} settingsExport["bondingMode"]["value"] = currentsettings["bondingMode"] settingsExport["bondingMode"]["locked"] = locked settingsExport["overflowThreshold"] = {} settingsExport["overflowThreshold"]["value"] = currentsettings[ "overflowThreshold"] settingsExport["overflowThreshold"]["locked"] = locked settingsExport["packetAggregation"] = {} settingsExport["packetAggregation"]["value"] = currentsettings[ "packetAggregation"] settingsExport["packetAggregation"]["locked"] = locked settingsExport["allowChaChaEncryption"] = {} settingsExport["allowChaChaEncryption"]["value"] = currentsettings[ "allowChaChaEncryption"] settingsExport["allowChaChaEncryption"]["locked"] = locked connectmethodsettings = speedify.show_connectmethod() settingsExport["connectMethod"] = {} settingsExport["connectMethod"][ "value"] = speedify.connectmethod_as_string(connectmethodsettings) settingsExport["connectMethod"]["locked"] = locked if "forwardedPorts" in currentsettings: forwardedPortsExport = {} forwardedPortsExport["locked"] = locked forwardedPortsExport["value"] = [] forwardedPortSettings = currentsettings["forwardedPorts"] for portInfo in forwardedPortSettings: newPortExport = {} newPortExport["port"] = portInfo["port"] newPortExport["proto"] = portInfo["protocol"] forwardedPortsExport["value"].append(newPortExport) settingsExport["forwardedPorts"] = forwardedPortsExport privacysettings = speedify.show_privacy() if "dnsLeak" in privacysettings: settingsExport["dnsleak"] = {} settingsExport["dnsleak"]["value"] = privacysettings["dnsleak"] settingsExport["dnsleak"]["locked"] = locked if "killswitch" in privacysettings: settingsExport["killswitch"] = {} settingsExport["killswitch"]["value"] = privacysettings[ "killswitch"] settingsExport["killswitch"]["locked"] = locked if "dnsAddresses" in privacysettings: settingsExport["dnsAddresses"] = {} settingsExport["dnsAddresses"]["locked"] = locked settingsExport["dnsAddresses"]["value"] = [] for dnsserver in privacysettings["dnsAddresses"]: settingsExport["dnsAddresses"]["value"].append(dnsserver) settingsExport["crashReports"] = {} settingsExport["crashReports"]["value"] = privacysettings[ "crashReports"] settingsExport["crashReports"]["locked"] = locked except SpeedifyError as se: logging.error("Speedify error on getTeamSetting:" + str(se)) jsonExport = {} jsonExport["settings"] = settingsExport return jsonExport