Exemplo n.º 1
0
 def test_settings(self):
     # test some basic settings
     speedify.packetaggregation(False)
     speedify.jumbo(False)
     my_settings = speedify.show_settings()
     self.assertFalse(my_settings["packetAggregation"])
     self.assertFalse(my_settings["jumboPackets"])
     speedify.packetaggregation(True)
     speedify.jumbo(True)
     my_settings = speedify.show_settings()
     self.assertTrue(my_settings["packetAggregation"])
     self.assertTrue(my_settings["jumboPackets"])
Exemplo n.º 2
0
    def test_transport(self):
        mysettings = speedify.transport("https")
        serverinfo = speedify.connect()
        mysettings = speedify.show_settings()
        self.assertEqual(mysettings["transportMode"], "https")

        # to make sure runtime changed, could check stats and look for connectionstats : connections[] : protocol
        mysettings = speedify.transport("tcp")
        self.assertEqual(mysettings["transportMode"], "tcp")
        serverinfo = speedify.connect()
        mysettings = speedify.show_settings()
        self.assertEqual(mysettings["transportMode"], "tcp")
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
 def test_set_defaults(self):
     speedify.encryption(False)
     speedify.transport("tcp")
     self.assertTrue(speedifysettings.apply_speedify_settings(speedifysettings.speedify_defaults))
     settings = speedify.show_settings()
     self.assertTrue(settings["encrypted"])
     self.assertTrue(settings["jumboPackets"])
     self.assertEqual( settings["transportMode"] , "auto")
Exemplo n.º 5
0
 def test_set_json(self):
     # lets use a settings string to apply it back
     json_string ='{"encryption" : false, "jumbo" : false, "packet_aggregation":false,"transport":"tcp","adapter_priority_wifi" : "backup"}'
     self.assertTrue( speedifysettings.apply_speedify_settings(json_string))
     settings = speedify.show_settings()
     self.assertFalse(settings["encrypted"])
     self.assertFalse(settings["jumboPackets"])
     self.assertFalse(settings["packetAggregation"])
     self.assertEqual( settings["transportMode"] , "tcp")
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 def test_routedefault(self):
     speedify.connect()
     if not speedifyutil.using_speedify():
         time.sleep(3)
         self.assertTrue(speedifyutil.using_speedify())
     speedify.routedefault(False)
     self.assertFalse(speedify.show_settings()["enableDefaultRoute"])
     time.sleep(1)
     if speedifyutil.using_speedify():
         # try twice in case it takes a moment to settle
         time.sleep(1)
         self.assertFalse(speedifyutil.using_speedify())
     speedify.routedefault(True)
     # for whatever reason getting the route back takes longer than giving it up
     self.assertTrue(speedify.show_settings()["enableDefaultRoute"])
     time.sleep(2)
     if not speedifyutil.using_speedify():
         # try twice in case it takes a moment to settle
         time.sleep(2)
         self.assertTrue(speedifyutil.using_speedify())
Exemplo n.º 8
0
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