Ejemplo n.º 1
0
    def execute(self, options_dict, non_option_args):
        if not non_option_args:
            self.usage()

        manager = nmsettings.ConnectionManager()

        found = 0
        for name in non_option_args:
            connection = manager.get_connection_by_name(nmsettings.DBUS_SERVICE_USER_SETTINGS, name)
            if not connection:
                nmtalk.error("Can not find connection '%s'" % name)
                continue

            found += 1
            settings = connection.get_settings()
            for setting_type in settings.keys():
                print setting_type
                setting = settings[setting_type]
                for key in setting.keys():
                    print "%s : %s" % (key, setting[key])

                print

        if found == 0:
            return 1

        return 0
Ejemplo n.º 2
0
    def execute(self, options_dict, non_option_args):
        manager = nmsettings.ConnectionManager()

        if options_dict.has_key("system"):
            connections = manager.get_connections(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, "vpn")
            print_service = False
        elif options_dict.has_key("user"):
            connections = manager.get_connections(
                nmsettings.DBUS_SERVICE_USER_SETTINGS, "vpn")
            print_service = False
        else:
            connections = manager.get_connections(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, "vpn")
            connections += manager.get_connections(
                nmsettings.DBUS_SERVICE_USER_SETTINGS, "vpn")
            print_service = True

        vpn_manager = nmvpn.VpnManager()
        active_map = {}
        for c in vpn_manager.list_active_connections():
            active_map[c.get_name()] = nmvpn.vpn_connection_state_to_str(
                c.get_state())

        rows = []
        for connection in connections:
            name = connection.get_id()
            r = [name, active_map.get(name, "")]
            if print_service:
                if connection.service == nmsettings.DBUS_SERVICE_USER_SETTINGS:
                    r.append("User")
                else:
                    r.append("System")

            rows.append(r)

        if rows:
            headers = ["Name", "Status"]
            if print_service:
                headers.append("Service type")

            rows.sort(lambda x, y: cmp(x[0].lower(), y[0].lower()))
            nmformat.tabular(headers, rows)
        else:
            nmtalk.message("No VPN connections found.")

        return 0
Ejemplo n.º 3
0
    def execute(self, options_dict, non_option_args):
        manager = nmsettings.ConnectionManager()

        if options_dict.has_key("system"):
            connections = manager.get_connections(nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS)
            print_service = False
        elif options_dict.has_key("user"):
            connections = manager.get_connections(nmsettings.DBUS_SERVICE_USER_SETTINGS)
            print_service = False
        else:
            connections = manager.get_connections(nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS)
            connections += manager.get_connections(nmsettings.DBUS_SERVICE_USER_SETTINGS)
            print_service = True

        rows = []
        for connection in connections:
            r = [connection.get_id(), connection.get_type()]
            if print_service:
                if connection.service == nmsettings.DBUS_SERVICE_USER_SETTINGS:
                    r.append("User")
                else:
                    r.append("System")

            rows.append(r)

        if rows:
            if options_dict.has_key("sort-by-type"):
                rows.sort(lambda x,y:cmp(x[1].lower(), y[1].lower()))
            else:
                rows.sort(lambda x,y:cmp(x[0].lower(), y[0].lower()))

            headers = ["Name", "Type"]
            if print_service:
                headers.append("Service type")

            nmformat.tabular(headers, rows)
        else:
            nmtalk.message("No connections found.")

        return 0
Ejemplo n.º 4
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) != 1:
            self.usage()

        # Find the VPN connection
        manager = nmsettings.ConnectionManager()
        connection_name = non_option_args.pop(0)

        if options_dict.has_key("system"):
            connection = manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name,
                "vpn")
        elif options_dict.has_key("user"):
            connection = manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name, "vpn")
        else:
            connection = manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name,
                "vpn")
            if not connection:
                connection = manager.get_connection_by_name(
                    nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name,
                    "vpn")

        if not connection:
            nmtalk.error("VPN connection '%s' not found." % connection_name)
            return 1

        manager = nm.NetworkManager()

        # Find the first active device
        device = None
        for d in manager.get_devices():
            if d.get_state() == nmdevice.DEVICE_STATE_ACTIVATED:
                device = d
                break

        if not device:
            nmtalk.fatal("Can not activate VPN, no active device found")

        vpn_manager = nmvpn.VpnManager()
        vpn_connection = vpn_manager.connect(connection, device)

        if options_dict.has_key("dont-wait"):
            return 0

        loop = gobject.MainLoop()
        self.exit_status = 0

        def monitor(state, reason):
            msg = "'%s': %s" % (connection_name,
                                nmvpn.vpn_connection_state_to_str(state))
            if reason != nmvpn.VPN_CONNECTION_STATE_REASON_NONE:
                msg += " (%s)" % nmvpn.vpn_connection_state_reason_to_str(
                    reason)

            nmtalk.message(msg)

            if state == nmvpn.VPN_CONNECTION_STATE_ACTIVATED:
                loop.quit()

            elif state == nmvpn.VPN_CONNECTION_STATE_FAILED or state == nmvpn.VPN_CONNECTION_STATE_DISCONNECTED:
                loop.quit()
                self.exit_status = 1

        vpn_connection.proxy.connect_to_signal(
            "StateChanged",
            monitor,
            dbus_interface=nmvpn.DBUS_INTERFACE_VPN_CONNECTION)

        loop.run()

        return self.exit_status
Ejemplo n.º 5
0
    def execute(self, options_dict, non_option_args):
        if len(non_option_args) < 2:
            self.usage()

        manager = self.Manager()

        # Device
        device_iface = non_option_args.pop(0)
        device = manager.get_device_by_iface(device_iface)
        if not device:
            nmtalk.fatal("Invalid device %s" % device_iface)

        # Connection
        c_manager = nmsettings.ConnectionManager()
        connection_name = non_option_args.pop(0)
        if options_dict.has_key("system"):
            connection = c_manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name)
        elif options_dict.has_key("user"):
            connection = c_manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name)
        else:
            connection = c_manager.get_connection_by_name(
                nmsettings.DBUS_SERVICE_SYSTEM_SETTINGS, connection_name)
            if not connection:
                connection = c_manager.get_connection_by_name(
                    nmsettings.DBUS_SERVICE_USER_SETTINGS, connection_name)

        if not connection:
            nmtalk.fatal("Invalid connection '%s'" % connection_name)

        # Specific object
        if len(non_option_args) > 0:
            specific_object = device.get_specific_object(non_option_args)
        else:
            specific_object = None

        manager.activate_device(device, connection, specific_object)

        if options_dict.has_key("dont-wait"):
            return 0

        loop = gobject.MainLoop()
        self.exit_status = 0

        def monitor(state):
            nmtalk.message("'%s': %s" %
                           (device_iface, nmdevice.device_state_to_str(state)))
            if state == nmdevice.DEVICE_STATE_ACTIVATED:
                loop.quit()

            elif state == nmdevice.DEVICE_STATE_FAILED or state == nmdevice.DEVICE_STATE_DISCONNECTED or \
                    state == nmdevice.DEVICE_STATE_CANCELLED:
                loop.quit()
                self.exit_status = 1

        device.proxy.connect_to_signal(
            "StateChanged",
            monitor,
            dbus_interface=nmdevice.DBUS_INTERFACE_DEVICE)

        loop.run()

        return self.exit_status