def active_ssid_connection(self, ssid):
        '''try only one connection now'''
        if get_cache().getobject(self.object_path).is_active():
            conn = get_cache().getobject(self.object_path).get_active_connection().get_connection()
            if TypeConvert.ssid_ascii2string(conn.settings_dict["802-11-wireless"]["ssid"])== ssid:
                return None
        else:
            pass

        nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
        connections = nm_remote_settings.get_ssid_associate_connections(ssid)
        #print connections, "active ssid connection"
        if connections:
            conn = sorted(connections, key = lambda x: int(nm_remote_settings.cf.get("conn_priority", x.settings_dict["connection"]["uuid"])), 
                    reverse = True)[0]
            try:
                specific = self.get_ap_by_ssid(ssid)
                nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
                nmclient.activate_connection(conn.object_path, self.object_path, specific.object_path)
                if get_cache().getobject(self.object_path).is_active():
                    return None
                else:
                    return conn
            except:
                return conn
        else:
            return nm_remote_settings.new_wireless_connection(ssid, None)
    def auto_connect(self):
        if get_cache().getobject(self.object_path).is_active():
            return True
        if get_cache().getobject(self.object_path).get_state() < 30:
            return False

        nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
        if nm_remote_settings.get_wired_connections():

            wired_prio_connections = sorted(nm_remote_settings.get_wired_connections(),
                                    key = lambda x: int(nm_remote_settings.cf.get("conn_priority", x.settings_dict["connection"]["uuid"])),
                                    reverse = True)
            
            primary_connection = nm_remote_settings.get_primary_wire(self.object_path)
            if primary_connection: wired_prio_connections.insert(0, primary_connection)

            self.thread_wiredauto = ThreadWiredAuto(self.object_path, wired_prio_connections)
            self.thread_wiredauto.setDaemon(True)
            self.thread_wiredauto.start()

        else:
            try:
                nmconn = nm_remote_settings.new_wired_connection()
                conn = nm_remote_settings.new_connection_finish(nmconn.settings_dict)
                nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
                nmclient.activate_connection(conn.object_path, self.object_path, "/")
            except:
                return False
    def run(self):
        nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
        for conn in self.conns:
            for active_conn in nmclient.get_active_connections():
                if active_conn.get_state() == 2:
                    for device in active_conn.get_devices():
                        if self.run_flag:
                            try:
                                active = nmclient.activate_connection(
                                    conn.object_path, device.object_path,
                                    active_conn.object_path)
                                self.active_conn_creat(active)

                                vpn_connection = get_cache().get_spec_object(
                                    active.object_path)

                                while (vpn_connection.get_vpnstate() < 5
                                       and self.run_flag):
                                    time.sleep(1)

                                if vpn_connection.get_vpnstate() == 5:
                                    self.stop_run()
                                    self.succeed = True
                                    return True
                                else:
                                    continue
                            except Exception, e:
                                print e
                                pass
                        else:
                            break
                else:
                    continue

            return False
    def run(self):
        nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
        for active_conn in nmclient.get_active_connections():
            if active_conn.get_state() == 2:
                for device in active_conn.get_devices():
                    if self.run_flag:
                        try:
                            active = nmclient.activate_connection(self.connection.object_path,
                                                                  device.object_path,
                                                                  active_conn.object_path)
                            self.active_conn_creat_cb(active)
            
                            vpn_connection = get_cache().get_spec_object(active.object_path)

                            while(vpn_connection.get_vpnstate() < 5 and self.run_flag):
                                time.sleep(1)
                            
                            if vpn_connection.get_vpnstate() == 5:
                                self.stop_run()
                                self.succeed = True
                                return True
                            else:
                                continue
                        except Exception, e:
                            print "except",e
                            pass
                    else:
                        break
            else:
                continue
    def vpn_auto_connect(self, active_conn_creat_cb):
        nm_remote_settings = get_cache().getobject(
            "/org/freedesktop/NetworkManager/Settings")
        print "vpn auto connect state", self.get_state()
        if self.get_state() != 2:
            return False
        elif nm_remote_settings.get_vpn_connections():
            vpn_prio_connections = sorted(
                nm_remote_settings.get_vpn_connections(),
                key=lambda x: int(
                    nm_remote_settings.cf.get(
                        "conn_priority", x.settings_dict["connection"]["uuid"])
                ),
                reverse=True)

            nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
            if len(nmclient.get_vpn_active_connection()) == 0:
                self.thread_vpnauto = ThreadVPNAuto(self.object_path,
                                                    vpn_prio_connections,
                                                    active_conn_creat_cb)
                self.thread_vpnauto.setDaemon(True)
                self.thread_vpnauto.start()
                return self.thread_vpnauto
            else:
                return True
 def __init__(self):
     self.auto_register = ""
     self.identifier = "org.freedesktop.NetworkManager.SecretAgent"
     self.registered = ""
     try:
         get_cache().getobject("/org/freedesktop/NetworkManager/AgentManager").register(self.identifier)
     except:
         traceback.print_exc()
 def delete(self):
     try:
         self.dbus_interface.Delete(reply_handler = self.delete_finish, error_handler = self.delete_error)
         nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
         nm_remote_settings.cf.remove_option("conn_priority", self.settings_dict["connection"]["uuid"]) 
         nm_remote_settings.cf.write(open(nm_remote_settings.config_file, "w"))
         get_cache().delobject(self.object_path)
     except:
         traceback.print_exc()
 def __init__(self):
     self.auto_register = ""
     self.identifier = "org.freedesktop.NetworkManager.SecretAgent"
     self.registered = ""
     try:
         get_cache().getobject(
             "/org/freedesktop/NetworkManager/AgentManager").register(
                 self.identifier)
     except:
         traceback.print_exc()
 def get_primary_wire(self, wired_device):
     if type(wired_device) is str:
         devices = get_cache().get_spec_object(wired_device)
     else:
         devices = get_cache().get_spec_object(wired_device.object_path)
     hw_address = devices.get_hw_address().replace(":", "-")
     if hw_address in self.cf.options(WIRE_SECTION):
         return self.remove_gones(hw_address, self.cf.get(WIRE_SECTION, hw_address))
     else:
         return None
 def get_primary_wire(self, wired_device):
     if type(wired_device) is str:
         devices = get_cache().get_spec_object(wired_device)
     else:
         devices = get_cache().get_spec_object(wired_device.object_path)
     hw_address = devices.get_hw_address().replace(":", "-")
     if hw_address in self.cf.options(WIRE_SECTION):
         return self.remove_gones(hw_address,
                                  self.cf.get(WIRE_SECTION, hw_address))
     else:
         return None
    def access_point_removed_cb(self, ap_object_path):
        try:
            removed_ssid = self.ap_record_dict[ap_object_path]
            if len(filter(lambda x: x == removed_ssid, self.ap_record_dict.values())) == 1:
                self.origin_ap_list = self.get_access_points()
                self.ap_timer_id = glib.timeout_add(300, self.emit_cb, "access-point-removed")

            get_cache().getobject(ap_object_path).remove_signals()

            del self.ap_record_dict[ap_object_path]
        except:
            traceback.print_exc()
 def add_connection(self, settings_dict):
     conn_path = self.dbus_method("AddConnection", settings_dict)
     if conn_path:
         nm_connection = get_cache().getobject(conn_path)
         nm_connection.settings_dict = settings_dict
         nm_connection.update()
         get_cache().new_object(conn_path)
         self.cf.set("conn_priority", nm_connection.settings_dict["connection"]["uuid"], 0)
         self.cf.write(open(self.config_file, "w"))
         return nm_connection
     else:
         return None
예제 #13
0
 def delete(self):
     try:
         self.dbus_interface.Delete(reply_handler=self.delete_finish,
                                    error_handler=self.delete_error)
         nm_remote_settings = get_cache().getobject(
             "/org/freedesktop/NetworkManager/Settings")
         nm_remote_settings.cf.remove_option(
             "conn_priority", self.settings_dict["connection"]["uuid"])
         nm_remote_settings.cf.write(
             open(nm_remote_settings.config_file, "w"))
         get_cache().delobject(self.object_path)
     except:
         traceback.print_exc()
 def add_connection(self, settings_dict):
     conn_path = self.dbus_method("AddConnection", settings_dict)
     if conn_path:
         nm_connection = get_cache().getobject(conn_path)
         nm_connection.settings_dict = settings_dict
         nm_connection.update()
         get_cache().new_object(conn_path)
         self.cf.set("conn_priority",
                     nm_connection.settings_dict["connection"]["uuid"], 0)
         self.cf.write(open(self.config_file, "w"))
         return nm_connection
     else:
         return None
    def agent_save_secrets(self, conn_path, setting_name, method):
        service = self.generate_service_name(get_cache().getobject(conn_path).settings_dict["connection"]["uuid"], 
                                             setting_name, method)
        username = getpass.getuser()

        if setting_name == "vpn":
            password = get_cache().getobject(conn_path).settings_dict[setting_name]["secrets"][method]
        else:    
            password = get_cache().getobject(conn_path).settings_dict[setting_name][method]
        try:
            keyring.set_password(service, username, password)
        except:
            traceback.print_exc()
예제 #16
0
    def access_point_removed_cb(self, ap_object_path):
        try:
            removed_ssid = self.ap_record_dict[ap_object_path]
            if len(
                    filter(lambda x: x == removed_ssid,
                           self.ap_record_dict.values())) == 1:
                self.origin_ap_list = self.get_access_points()
                self.ap_timer_id = glib.timeout_add(300, self.emit_cb,
                                                    "access-point-removed")

            get_cache().getobject(ap_object_path).remove_signals()

            del self.ap_record_dict[ap_object_path]
        except:
            traceback.print_exc()
    def dsl_auto_connect(self):
        nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
        if not get_cache().getobject(self.object_path).is_active():
            return False

        elif not nm_remote_settings.get_pppoe_connections():
            return False
        else:
            pppoe_prio_connections = sorted(nm_remote_settings.get_pppoe_connections(),
                                    key = lambda x: int(nm_remote_settings.cf.get("conn_priority", x.settings_dict["connection"]["uuid"])),
                                    reverse = True)

            self.thread_dslauto = ThreadWiredAuto(self.object_path, pppoe_prio_connections)
            self.thread_dslauto.setDaemon(True)
            self.thread_dslauto.start()
 def add_and_activate_connection(self, connection_path, device_path, specific_object_path):
     try:
         active = self.dbus_interface.AddAndActivateConnection(connection_path, device_path, specific_object_path)
         if active:
             return get_cache().getobject(active)
     except:
         traceback.print_exc()
    def run(self):
        for conn in self.conns:
            if self.run_flag:
                ssid = TypeConvert.ssid_ascii2string(conn.settings_dict["802-11-wireless"]["ssid"])
                if ssid in self.device.get_ssid_record():
                    try:
                        specific = self.device.get_ap_by_ssid(ssid)
                        nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
                        active_conn = nmclient.activate_connection(conn.object_path, self.device.object_path, specific.object_path)
                        while(active_conn.get_state() == 1 and self.run_flag):
                            time.sleep(1)

                        if active_conn.get_state() == 2:
                            self.stop_run()
                            return True
                        else:
                            continue
                    except:
                        pass
                else:
                    continue
            else:
                return False

        self.stop_run()
예제 #20
0
    def run(self):
        for conn in self.conns:
            if self.run_flag:
                ssid = TypeConvert.ssid_ascii2string(
                    conn.settings_dict["802-11-wireless"]["ssid"])
                if ssid in self.device.get_ssid_record():
                    try:
                        specific = self.device.get_ap_by_ssid(ssid)
                        nmclient = get_cache().getobject(
                            "/org/freedesktop/NetworkManager")
                        active_conn = nmclient.activate_connection(
                            conn.object_path, self.device.object_path,
                            specific.object_path)
                        while (active_conn.get_state() == 1 and self.run_flag):
                            time.sleep(1)

                        if active_conn.get_state() == 2:
                            self.stop_run()
                            return True
                        else:
                            continue
                    except:
                        pass
                else:
                    continue
            else:
                return False

        self.stop_run()
 def __init__(self, active_path, connections, active_conn_creat_cb):
     threading.Thread.__init__(self)
     self.activeconn = get_cache().getobject(active_path)
     self.conns = connections
     self.active_conn_creat = active_conn_creat_cb
     self.run_flag = True
     self.succeed = False
 def __init__(self, active_path, connections, active_conn_creat_cb):
     threading.Thread.__init__(self)
     self.activeconn = get_cache().getobject(active_path)
     self.conns = connections
     self.active_conn_creat = active_conn_creat_cb
     self.run_flag = True
     self.succeed = False
    def run(self):
        for conn in self.conns:
            if self.run_flag:
                if "mac-address" in conn.settings_dict["802-3-ethernet"].iterkeys():
                    if TypeConvert.dbus2py(conn.settings_dict["802-3-ethernet"]["mac-address"]) != self.device.get_hw_address():
                            print "connection mac address doesn't match the device"
                            continue
                    else:
                        pass
                try:
                    nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
                    active_conn = nmclient.activate_connection(conn.object_path, self.device.object_path, "/")

                    while(active_conn.get_state() == 1 and self.run_flag):
                        time.sleep(1)

                    if active_conn.get_state() == 2:
                        self.stop_run()
                        return True
                    else:
                        continue
                except:
                    pass
            else:
                return True
        self.stop_run()
        return True
예제 #24
0
    def run(self):
        for conn in self.conns:
            if self.run_flag:
                if "mac-address" in conn.settings_dict[
                        "802-3-ethernet"].iterkeys():
                    if TypeConvert.dbus2py(
                            conn.settings_dict["802-3-ethernet"]
                        ["mac-address"]) != self.device.get_hw_address():
                        print "connection mac address doesn't match the device"
                        continue
                    else:
                        pass
                try:
                    nmclient = get_cache().getobject(
                        "/org/freedesktop/NetworkManager")
                    active_conn = nmclient.activate_connection(
                        conn.object_path, self.device.object_path, "/")

                    while (active_conn.get_state() == 1 and self.run_flag):
                        time.sleep(1)

                    if active_conn.get_state() == 2:
                        self.stop_run()
                        return True
                    else:
                        continue
                except:
                    pass
            else:
                return True
        self.stop_run()
        return True
    def agent_save_secrets(self, conn_path, setting_name, method):
        service = self.generate_service_name(
            get_cache().getobject(conn_path).settings_dict["connection"]
            ["uuid"], setting_name, method)
        username = getpass.getuser()

        if setting_name == "vpn":
            password = get_cache().getobject(
                conn_path).settings_dict[setting_name]["secrets"][method]
        else:
            password = get_cache().getobject(
                conn_path).settings_dict[setting_name][method]
        try:
            keyring.set_password(service, username, password)
        except:
            traceback.print_exc()
    def auto_connect(self):
        if get_cache().getobject(self.object_path).is_active():
            return True
        if get_cache().getobject(self.object_path).get_state() < 30:
            return False

        nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
        wireless_connections = nm_remote_settings.get_wireless_connections()
        if wireless_connections:
            wireless_prio_connections = sorted(nm_remote_settings.get_wireless_connections(),
                                        key = lambda x: int(nm_remote_settings.cf.get("conn_priority", x.settings_dict["connection"]["uuid"])),
                                        reverse = True)

            self.thread_wifiauto = ThreadWifiAuto(self.object_path, wireless_prio_connections)
            self.thread_wifiauto.setDaemon(True)
            self.thread_wifiauto.start()
        else:
            pass
 def agent_get_secrets(self, conn_path, setting_name, method):
     service = self.generate_service_name(get_cache().getobject(conn_path).settings_dict["connection"]["uuid"],
                                          setting_name, method)
     username = getpass.getuser()
     print "agent_get_secrets"
     try:
         return keyring.get_password(service, username)
     except:
         traceback.print_exc()
    def vpn_auto_connect(self, active_conn_creat_cb):
        nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
        print "vpn auto connect state", self.get_state()
        if self.get_state() != 2:
            return False
        elif nm_remote_settings.get_vpn_connections():
            vpn_prio_connections = sorted(nm_remote_settings.get_vpn_connections(),
                                        key = lambda x:int(nm_remote_settings.cf.get("conn_priority", x.settings_dict["connection"]["uuid"])),
                                        reverse = True)

            nmclient = get_cache().getobject("/org/freedesktop/NetworkManager")
            if len(nmclient.get_vpn_active_connection()) == 0:
                self.thread_vpnauto = ThreadVPNAuto(self.object_path, vpn_prio_connections, active_conn_creat_cb)
                self.thread_vpnauto.setDaemon(True)
                self.thread_vpnauto.start()
                return self.thread_vpnauto
            else:
                return True
 def list_connections(self):
     '''return connections object'''
     try:
         return filter(lambda x: "read-only" not in x.settings_dict["connection"] or not x.settings_dict["connection"]["read-only"], 
                         map(lambda x:get_cache().getobject(x), TypeConvert.dbus2py(self.dbus_method("ListConnections")))
                     )
     except:
         traceback.print_exc()
         return []
 def new_connection_cb(self, path):
     self.init_nmobject_with_properties()
     conn = get_cache().getobject(path)
     if conn.settings_dict["connection"]['type'] == 'vpn':
         nm_events.emit("vpn-new-added", conn)
         return
     if conn.settings_dict["connection"]['type'] == 'pppoe':
         nm_events.emit("dsl-new-added", conn)
         return
 def new_connection_cb(self, path):
     self.init_nmobject_with_properties()
     conn = get_cache().getobject(path)
     if conn.settings_dict["connection"]['type'] == 'vpn':
         nm_events.emit("vpn-new-added", conn)
         return
     if conn.settings_dict["connection"]['type'] == 'pppoe':
         nm_events.emit("dsl-new-added", conn)
         return
 def agent_delete_secrets(self, conn_path, setting_name, method):
     service = self.generate_service_name(
         get_cache().getobject(conn_path).settings_dict["connection"]
         ["uuid"], setting_name, method)
     username = getpass.get_user()
     try:
         if keyring.get_password(service, username):
             keyring.set_password(service, username, "")
     except:
         traceback.print_exc()
 def list_connections(self):
     '''return connections object'''
     try:
         return filter(
             lambda x: "read-only" not in x.settings_dict["connection"] or
             not x.settings_dict["connection"]["read-only"],
             map(lambda x: get_cache().getobject(x),
                 TypeConvert.dbus2py(self.dbus_method("ListConnections"))))
     except:
         traceback.print_exc()
         return []
 def removed_cb(self):
     self.emit("removed", self.object_path)
     if self.settings_dict["connection"]["type"] == "vpn":
         nm_events.emit("vpn-connection-removed", None)
         return
     if self.settings_dict["connection"]["type"] == "pppoe":
         nm_events.emit("dsl-connection-removed", None)
         return
     nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
     hidden_items = dict(nm_remote_settings.cf.items('hidden')).values()
     if self.settings_dict["connection"]["uuid"] in hidden_items:
         nm_events.emit("hidden-connection-removed", None)
예제 #35
0
    def dsl_auto_connect(self):
        nm_remote_settings = get_cache().getobject(
            "/org/freedesktop/NetworkManager/Settings")
        if not get_cache().getobject(self.object_path).is_active():
            return False

        elif not nm_remote_settings.get_pppoe_connections():
            return False
        else:
            pppoe_prio_connections = sorted(
                nm_remote_settings.get_pppoe_connections(),
                key=lambda x: int(
                    nm_remote_settings.cf.get(
                        "conn_priority", x.settings_dict["connection"]["uuid"])
                ),
                reverse=True)

            self.thread_dslauto = ThreadWiredAuto(self.object_path,
                                                  pppoe_prio_connections)
            self.thread_dslauto.setDaemon(True)
            self.thread_dslauto.start()
    def activate_connection(self, connection_path, device_path, specific_object_path):
        '''used for multi activate, must run one by one'''
        try:
            active = self.dbus_interface.ActivateConnection(connection_path, device_path, specific_object_path)
            if active:
                if "vpn" in get_cache().getobject(connection_path).settings_dict.iterkeys():
                    vpn_active_connection = get_cache().get_spec_object(active)
                    
                    if vpn_active_connection.get_vpnstate() in [1, 2, 3, 4]:
                        vpn_active_connection.emit("vpn-connecting")
                        return get_cache().getobject(active)

                    elif vpn_active_connection.get_vpnstate() == 5:
                        vpn_active_connection.emit("vpn-connected")
                        return get_cache().getobject(active)

                    else:
                        vpn_active_connection.emit("vpn-disconnected")
                        return get_cache().getobject(active)

                else:    
                    return get_cache().getobject(active)
            else:
                return None
        except:
            traceback.print_exc()
            return None
    def set_primary_wire(self, wired_device, connection):
        if connection == None:
            result = self.get_primary_wire(wired_device)
            if result:
                self.cf.remove_option(WIRE_SECTION, result)
        else:
            devices = get_cache().get_spec_object(wired_device.object_path)
            hw_address = devices.get_hw_address().replace(":", "-")
            uuid = connection.settings_dict["connection"]["uuid"]
            self.cf.set(WIRE_SECTION, hw_address, uuid)

        self.write_config()
        return True
예제 #38
0
 def removed_cb(self):
     self.emit("removed", self.object_path)
     if self.settings_dict["connection"]["type"] == "vpn":
         nm_events.emit("vpn-connection-removed", None)
         return
     if self.settings_dict["connection"]["type"] == "pppoe":
         nm_events.emit("dsl-connection-removed", None)
         return
     nm_remote_settings = get_cache().getobject(
         "/org/freedesktop/NetworkManager/Settings")
     hidden_items = dict(nm_remote_settings.cf.items('hidden')).values()
     if self.settings_dict["connection"]["uuid"] in hidden_items:
         nm_events.emit("hidden-connection-removed", None)
    def set_primary_wire(self, wired_device, connection):
        if connection == None:
            result = self.get_primary_wire(wired_device)
            if result:
                self.cf.remove_option(WIRE_SECTION, result)
        else:
            devices = get_cache().get_spec_object(wired_device.object_path)
            hw_address = devices.get_hw_address().replace(":", "-")
            uuid = connection.settings_dict["connection"]["uuid"]
            self.cf.set(WIRE_SECTION, hw_address, uuid)

        self.write_config()
        return True
예제 #40
0
    def auto_connect(self):
        if get_cache().getobject(self.object_path).is_active():
            return True
        if get_cache().getobject(self.object_path).get_state() < 30:
            return False

        nm_remote_settings = get_cache().getobject(
            "/org/freedesktop/NetworkManager/Settings")
        if nm_remote_settings.get_wired_connections():

            wired_prio_connections = sorted(
                nm_remote_settings.get_wired_connections(),
                key=lambda x: int(
                    nm_remote_settings.cf.get(
                        "conn_priority", x.settings_dict["connection"]["uuid"])
                ),
                reverse=True)

            primary_connection = nm_remote_settings.get_primary_wire(
                self.object_path)
            if primary_connection:
                wired_prio_connections.insert(0, primary_connection)

            self.thread_wiredauto = ThreadWiredAuto(self.object_path,
                                                    wired_prio_connections)
            self.thread_wiredauto.setDaemon(True)
            self.thread_wiredauto.start()

        else:
            try:
                nmconn = nm_remote_settings.new_wired_connection()
                conn = nm_remote_settings.new_connection_finish(
                    nmconn.settings_dict)
                nmclient = get_cache().getobject(
                    "/org/freedesktop/NetworkManager")
                nmclient.activate_connection(conn.object_path,
                                             self.object_path, "/")
            except:
                return False
예제 #41
0
    def active_ssid_connection(self, ssid):
        '''try only one connection now'''
        if get_cache().getobject(self.object_path).is_active():
            conn = get_cache().getobject(
                self.object_path).get_active_connection().get_connection()
            if TypeConvert.ssid_ascii2string(
                    conn.settings_dict["802-11-wireless"]["ssid"]) == ssid:
                return None
        else:
            pass

        nm_remote_settings = get_cache().getobject(
            "/org/freedesktop/NetworkManager/Settings")
        connections = nm_remote_settings.get_ssid_associate_connections(ssid)
        #print connections, "active ssid connection"
        if connections:
            conn = sorted(connections,
                          key=lambda x: int(
                              nm_remote_settings.cf.get(
                                  "conn_priority", x.settings_dict["connection"
                                                                   ]["uuid"])),
                          reverse=True)[0]
            try:
                specific = self.get_ap_by_ssid(ssid)
                nmclient = get_cache().getobject(
                    "/org/freedesktop/NetworkManager")
                nmclient.activate_connection(conn.object_path,
                                             self.object_path,
                                             specific.object_path)
                if get_cache().getobject(self.object_path).is_active():
                    return None
                else:
                    return conn
            except:
                return conn
        else:
            return nm_remote_settings.new_wireless_connection(ssid, None)
예제 #42
0
    def auto_connect(self):
        if get_cache().getobject(self.object_path).is_active():
            return True
        if get_cache().getobject(self.object_path).get_state() < 30:
            return False

        nm_remote_settings = get_cache().getobject(
            "/org/freedesktop/NetworkManager/Settings")
        wireless_connections = nm_remote_settings.get_wireless_connections()
        if wireless_connections:
            wireless_prio_connections = sorted(
                nm_remote_settings.get_wireless_connections(),
                key=lambda x: int(
                    nm_remote_settings.cf.get(
                        "conn_priority", x.settings_dict["connection"]["uuid"])
                ),
                reverse=True)

            self.thread_wifiauto = ThreadWifiAuto(self.object_path,
                                                  wireless_prio_connections)
            self.thread_wifiauto.setDaemon(True)
            self.thread_wifiauto.start()
        else:
            pass
    def get_access_points(self):
        try:
            ap = self.dbus_method("GetAccessPoints")
            if not self.ap_record_inited:
                self.ap_record_inited = 1
                try:
                    from nmaccesspoint import NMAccessPoint
                    for ap_path in ap:
                        self.ap_record_dict[ap_path] = NMAccessPoint(ap_path).get_ssid()
                except:
                    self.ap_recrod_dict = {}

            return map(lambda x:get_cache().getobject(x), TypeConvert.dbus2py(ap))
        except:
            return []
예제 #44
0
    def vpn_state_changed_cb(self, state, reason):
        #print state, reason
        self.init_nmobject_with_properties()
        nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
        if state in [1, 2, 3, 4]:
            #self.emit("vpn-connecting")
            nm_events.emit('vpn-connecting', self.object_path)
            print "vpn-connecting"
        elif state == 5:
            #self.emit("vpn-connected")
            #print "vpn-connected"
            nm_events.emit('vpn-connected', self.object_path)
            conn_uuid = get_cache().getobject(self.object_path).get_connection().settings_dict["connection"]["uuid"]
            try:
                priority = int(nm_remote_settings.cf.getint("conn_priority", conn_uuid)) + 1
            except:
                priority = 1

            nm_remote_settings.cf.set("conn_priority", conn_uuid, priority)
            nm_remote_settings.cf.write(open(nm_remote_settings.config_file, "w"))
        #elif state == 7:
            #nm_events.emit('vpn-user-disconnect', self.object_path)
        else:
            nm_events.emit('vpn-disconnected', self.object_path)
예제 #45
0
    def get_access_points(self):
        try:
            ap = self.dbus_method("GetAccessPoints")
            if not self.ap_record_inited:
                self.ap_record_inited = 1
                try:
                    from nmaccesspoint import NMAccessPoint
                    for ap_path in ap:
                        self.ap_record_dict[ap_path] = NMAccessPoint(
                            ap_path).get_ssid()
                except:
                    self.ap_recrod_dict = {}

            return map(lambda x: get_cache().getobject(x),
                       TypeConvert.dbus2py(ap))
        except:
            return []
예제 #46
0
    def state_changed_cb(self, new_state, old_state, reason):
        if new_state > 90 or new_state < 70:
            self.init_nmobject_with_properties()
        #print new_state, old_state, reason

        if new_state == 30 and old_state < 30:
            self.emit_in_time("device-available", new_state, old_state, reason)
            return
        
        #if old_state == 100 or reason ==39 or reason == 42 or reason == 36:
        if new_state == 30 and old_state > 30:
            self.emit_in_time("device-deactive", new_state, old_state, reason)
            return 

        if new_state == 40:
            try:
                self.is_dsl = self.get_real_active_connection().get_setting('connection').type == 'pppoe'
            except:
                self.is_dsl = False
            self.emit_in_time("activate-start", new_state, old_state, reason)
            return 

        if new_state == 100:
            try:
                conn_uuid = self.get_real_active_connection().settings_dict["connection"]["uuid"]
                self.emit_in_time("device-active", new_state, old_state, reason)
                nm_remote_settings = get_cache().getobject("/org/freedesktop/NetworkManager/Settings")
                try:
                    priority = int(nm_remote_settings.cf.getint("conn_priority", conn_uuid) + 1 )
                except:
                    priority = 1

                nm_remote_settings.cf.set("conn_priority", conn_uuid, priority)
                nm_remote_settings.cf.write(open(nm_remote_settings.config_file, "w"))
            except:
                pass
            return 

        if new_state == 120:
            self.emit_in_time("activate-failed", new_state, old_state, reason)
            return 

        if new_state == 10 or new_state == 20:
            self.emit_in_time("device-unavailable", new_state, old_state, reason)
            return 
예제 #47
0
 def get_dhcp4_config(self):
     return get_cache().getobject(self.properties["Dhcp4Config"])
 def get_connection_by_uuid(self, uuid):
     try:
         return get_cache().getobject(self.dbus_method("GetConnectionByUuid", uuid))
     except:
         return None
 def get_devices(self):
     '''return father device objects'''
     try:
         return map(lambda x: get_cache().getobject(x), TypeConvert.dbus2py(self.dbus_method("GetDevices")))
     except:
         return []
예제 #50
0
 def get_ip6_config(self):
     return get_cache().getobject(self.properties["Ip6Config"])
예제 #51
0
 def get_active_connection(self):
     '''return active connection object'''
     if self.properties["ActiveConnection"]:
         return get_cache().getobject(self.properties["ActiveConnection"])
     else:
         return None
예제 #52
0
 def get_available_connections(self):
     return map(lambda c: get_cache().getobject(c) , self.properties["AvailableConnections"])