Beispiel #1
0
def store_configuration(config, private_key, certificate, interactive=False):
    target = Path('eduVPN.ovpn').resolve()
    if interactive and nm_available():
        if write_to_nm_choice():
            save_connection_with_mainloop(config, private_key, certificate)
        else:
            write_config(config, private_key, certificate, target)
    else:
        if nm_available():
            save_connection_with_mainloop(config, private_key, certificate)
        else:
            write_config(config, private_key, certificate, target)
Beispiel #2
0
def status():
    uuid, current_auth_url, metadata = get_storage(check=False)

    print("\n\n# Global configuration\n")
    print(f"uuid: {uuid}")
    print(f"auth_url: {current_auth_url}")

    if nm_available():
        active_uuid, status = connection_status(get_client())
        print(f"VPN connection active: {bool(active_uuid)}")
        print(f"VPN NM status is: {status}")
        print(f"Active VPN connection is EduVPN: {bool(uuid == active_uuid)}")

    print("\n\n## Previous connection properties\n")

    for auth_url, props in get_all_metadatas().items():
        if auth_url == current_auth_url:
            print(" ** CURRENT ACTIVE CONFIGURATION **")
        print(f"auth_url {auth_url}")
        for t in [
                'api_url', 'display_name', 'support_contact', 'profile_id',
                'token_endpoint', 'authorization_endpoint', 'con_type',
                'country_id'
        ]:
            print(f"{t}: {props[t]}")
        print(f"token.token_type: {props['token']['token_type']}")
        print(f"token.expires_in: {props['token']['expires_in']}")
        print(f"token.expires_at: {props['token']['expires_at']}")
        print("\n\n")
Beispiel #3
0
def write_to_nm_choice() -> bool:
    """
    When Network Manager is available, asks user to add VPN to Network Manager
    """
    if nm_available():
        print("\nWhat would you like to do with your VPN configuration:\n")
        print("* [0] Write .ovpn file to current directory")
        print("* [1] Add VPN configuration to Network Manager")
        return bool(input_int(max_=2))
    else:
        return False
 def test_nm_available(self):
     nm_available()
from unittest import TestCase, skipIf

from eduvpn.nm import (nm_available, add_connection, import_ovpn, get_client,
                       get_mainloop)
from eduvpn.ovpn import Ovpn
from eduvpn.storage import get_uuid
from tests.mock_config import mock_config


@skipIf(not nm_available(), "Network manager not available")
class TestNm(TestCase):
    def test_nm_available(self):
        nm_available()

    def test_import_ovpn(self):
        ovpn = Ovpn.parse(mock_config)
        import_ovpn(ovpn)

    def test_get_mainloop(self):
        get_mainloop()

    def test_get_add_connection(self):
        client = get_client()
        ovpn = Ovpn.parse(mock_config)
        simple_connection = import_ovpn(ovpn)
        add_connection(client, simple_connection)

    def test_get_uuid(self):
        get_uuid()

    def test_activate_connection(self):