def new_wireless_connection(self, ssid = None, key_mgmt = "wpa-psk"): ###Please pass key_mgmt as the wireless isn't privacy s_connection = NMSettingConnection() s_wireless = NMSettingWireless() s_wireless_security = NMSettingWirelessSecurity() s_ip4config = NMSettingIP4Config() s_ip6config = NMSettingIP6Config() s_connection.type = "802-11-wireless" s_connection.id = self.generate_connection_id("wireless") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_connection.permissions = [] s_wireless.mode = "infrastructure" s_wireless.ssid = ssid s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_ip6config.method = "auto" s_ip6config.routes = [] s_ip6config.dns = [] s_ip6config.addresses = [] settings_dict = {"802-11-wireless":s_wireless.prop_dict, "connection":s_connection.prop_dict, "ipv4":s_ip4config.prop_dict ,"ipv6":s_ip6config.prop_dict } if key_mgmt: s_wireless.security = "802-11-wireless-security" s_wireless_security.key_mgmt = key_mgmt settings_dict["802-11-wireless-security"] = s_wireless_security.prop_dict settings_dict["802-11-wireless-security"]["psk"] = "Password" if key_mgmt == "none": del settings_dict['802-11-wireless-security']['psk'] settings_dict['802-11-wireless-security']['wep-key-type'] = 1 from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_wireless_connection(self, ssid=None, key_mgmt="wpa-psk"): ###Please pass key_mgmt as the wireless isn't privacy s_connection = NMSettingConnection() s_wireless = NMSettingWireless() s_wireless_security = NMSettingWirelessSecurity() s_ip4config = NMSettingIP4Config() s_ip6config = NMSettingIP6Config() s_connection.type = "802-11-wireless" s_connection.id = self.generate_connection_id("wireless") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_connection.permissions = [] s_wireless.mode = "infrastructure" s_wireless.ssid = ssid s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_ip6config.method = "auto" s_ip6config.routes = [] s_ip6config.dns = [] s_ip6config.addresses = [] settings_dict = { "802-11-wireless": s_wireless.prop_dict, "connection": s_connection.prop_dict, "ipv4": s_ip4config.prop_dict, "ipv6": s_ip6config.prop_dict } if key_mgmt: s_wireless.security = "802-11-wireless-security" s_wireless_security.key_mgmt = key_mgmt settings_dict[ "802-11-wireless-security"] = s_wireless_security.prop_dict settings_dict["802-11-wireless-security"]["psk"] = "Password" if key_mgmt == "none": del settings_dict['802-11-wireless-security']['psk'] settings_dict['802-11-wireless-security']['wep-key-type'] = 1 from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_gsm_connection(self, username="", password="", apn=""): s_connection = NMSettingConnection() s_gsm = NMSettingGsm() s_serial = NMSettingSerial() s_ppp = NMSettingPPP() s_ip4config = NMSettingIP4Config() s_gsm.number = "*99#" s_gsm.username = username s_gsm.password = password s_gsm.apn = apn s_serial.baud = 115200 s_serial.bits = 8 s_serial.parity = 'n' s_serial.stopbits = 1 s_connection.type = "gsm" # s_connection.id = "gsm连接" s_connection.id = self.generate_connection_id("gsm") s_connection.autoconnect = False s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() settings_dict = { "gsm": s_gsm.prop_dict, "connection": s_connection.prop_dict, "ipv4": s_ip4config.prop_dict, "serial": s_serial.prop_dict, "ppp": s_ppp.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_gsm_connection(self, username = "", password = "", apn = ""): s_connection = NMSettingConnection() s_gsm = NMSettingGsm() s_serial = NMSettingSerial() s_ppp = NMSettingPPP() s_ip4config = NMSettingIP4Config() s_gsm.number = "*99#" s_gsm.username = username s_gsm.password = password s_gsm.apn = apn s_serial.baud = 115200 s_serial.bits = 8 s_serial.parity = 'n' s_serial.stopbits = 1 s_connection.type = "gsm" # s_connection.id = "gsm连接" s_connection.id = self.generate_connection_id("gsm") s_connection.autoconnect = False s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() settings_dict = {"gsm":s_gsm.prop_dict, "connection":s_connection.prop_dict, "ipv4":s_ip4config.prop_dict, "serial":s_serial.prop_dict, "ppp":s_ppp.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_adhoc_connection(self, ssid=None, key_mgmt="none"): ###Please pass key_mgmt as the wireless isn't privacy s_connection = NMSettingConnection() s_wireless = NMSettingWireless() s_wireless_security = NMSettingWirelessSecurity() s_ip4config = NMSettingIP4Config() s_connection.type = "802-11-wireless" s_connection.id = self.generate_connection_id("wireless") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_connection.permissions = [] s_wireless.mode = "adhoc" s_wireless.ssid = ssid if key_mgmt: s_wireless.security = "802-11-wireless-security" s_wireless_security.key_mgmt = key_mgmt s_wireless_security.auth_alg = "open" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_ip4config.method = "shared" settings_dict = { "802-11-wireless": s_wireless.prop_dict, "802-11-wireless-security": s_wireless_security.prop_dict, "connection": s_connection.prop_dict, "ipv4": s_ip4config.prop_dict } # settings_dict["802-11-wireless-security"]["psk"] = "Password" from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_adhoc_connection(self, ssid = None, key_mgmt = "none"): ###Please pass key_mgmt as the wireless isn't privacy s_connection = NMSettingConnection() s_wireless = NMSettingWireless() s_wireless_security = NMSettingWirelessSecurity() s_ip4config = NMSettingIP4Config() s_connection.type = "802-11-wireless" s_connection.id = self.generate_connection_id("wireless") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_connection.permissions = [] s_wireless.mode = "adhoc" s_wireless.ssid = ssid if key_mgmt: s_wireless.security = "802-11-wireless-security" s_wireless_security.key_mgmt = key_mgmt s_wireless_security.auth_alg = "open" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_ip4config.method = "shared" settings_dict = {"802-11-wireless":s_wireless.prop_dict, "802-11-wireless-security":s_wireless_security.prop_dict, "connection":s_connection.prop_dict, "ipv4":s_ip4config.prop_dict } # settings_dict["802-11-wireless-security"]["psk"] = "Password" from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_wired_connection(self): '''return the newly added wired remote connection object''' s_connection = NMSettingConnection() s_wired = NMSettingWired() s_ip4config = NMSettingIP4Config() s_ip6config = NMSettingIP6Config() s_connection.type = "802-3-ethernet" # s_connection.id = "有线连接" s_connection.id = self.generate_connection_id("wired") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_wired.duplex = "full" s_wired.clear_s390_options() s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_ip6config.method = "auto" s_ip6config.routes = [] s_ip6config.dns = [] s_ip6config.addresses = [] settings_dict = { "802-3-ethernet": s_wired.prop_dict, "connection": s_connection.prop_dict, "ipv4": s_ip4config.prop_dict, "ipv6": s_ip6config.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_wired_connection(self): '''return the newly added wired remote connection object''' s_connection = NMSettingConnection() s_wired = NMSettingWired() s_ip4config = NMSettingIP4Config() s_ip6config = NMSettingIP6Config() s_connection.type = "802-3-ethernet" # s_connection.id = "有线连接" s_connection.id = self.generate_connection_id("wired") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_wired.duplex = "full" s_wired.clear_s390_options() s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_ip6config.method = "auto" s_ip6config.routes = [] s_ip6config.dns = [] s_ip6config.addresses = [] settings_dict = {"802-3-ethernet":s_wired.prop_dict, "connection":s_connection.prop_dict, "ipv4":s_ip4config.prop_dict ,"ipv6":s_ip6config.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_vpn_pptp_connection(self): s_connection = NMSettingConnection() s_vpn = NMSettingVpn() s_ip4config = NMSettingIP4Config() s_connection.type = "vpn" # s_connection.id = "pptp_conn" s_connection.id = self.generate_connection_id("vpn") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_vpn.service_type = "org.freedesktop.NetworkManager.pptp" s_vpn.set_data_item("user", "") s_vpn.set_data_item("gateway", "") s_vpn.set_data_item("password-flags", "0") #s_vpn.set_data_item("require-mppe", "yes") #s_vpn.set_data_item("refuse-eap", "yes") s_vpn.set_secret_item("password", "") s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() settings_dict = { "vpn": s_vpn.prop_dict, "connection": s_connection.prop_dict, "ipv4": s_ip4config.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_pppoe_connection(self): s_connection = NMSettingConnection() s_wired = NMSettingWired() s_ip4config = NMSettingIP4Config() s_pppoe = NMSettingPPPOE() s_ppp = NMSettingPPP() s_connection.type = "pppoe" # s_connection.id = "DSL连接1" s_connection.id = self.generate_connection_id("dsl") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_wired.duplex = "full" s_wired.clear_s390_options() s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_pppoe.username = "" s_pppoe.password = "" settings_dict = { "802-3-ethernet": s_wired.prop_dict, "connection": s_connection.prop_dict, "ipv4": s_ip4config.prop_dict, "pppoe": s_pppoe.prop_dict, "ppp": s_ppp.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_vpn_pptp_connection(self): s_connection = NMSettingConnection() s_vpn = NMSettingVpn() s_ip4config = NMSettingIP4Config() s_connection.type = "vpn" # s_connection.id = "pptp_conn" s_connection.id = self.generate_connection_id("vpn") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_vpn.service_type = "org.freedesktop.NetworkManager.pptp" s_vpn.set_data_item("user", "") s_vpn.set_data_item("gateway", "") s_vpn.set_data_item("password-flags", "0") #s_vpn.set_data_item("require-mppe", "yes") #s_vpn.set_data_item("refuse-eap", "yes") s_vpn.set_secret_item("password","") s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() settings_dict = {"vpn":s_vpn.prop_dict, "connection":s_connection.prop_dict, "ipv4":s_ip4config.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection
def new_pppoe_connection(self): s_connection = NMSettingConnection() s_wired = NMSettingWired() s_ip4config = NMSettingIP4Config() s_pppoe = NMSettingPPPOE() s_ppp = NMSettingPPP() s_connection.type = "pppoe" # s_connection.id = "DSL连接1" s_connection.id = self.generate_connection_id("dsl") s_connection.autoconnect = True s_connection.uuid = uuid.uuid4() s_connection.timestamp = time.time() s_wired.duplex = "full" s_wired.clear_s390_options() s_ip4config.method = "auto" s_ip4config.clear_addresses() s_ip4config.clear_routes() s_ip4config.clear_dns() s_pppoe.username = "" s_pppoe.password = "" settings_dict = {"802-3-ethernet":s_wired.prop_dict, "connection":s_connection.prop_dict, "ipv4":s_ip4config.prop_dict, "pppoe":s_pppoe.prop_dict, "ppp":s_ppp.prop_dict } from nmutils.nmconnection import NMConnection new_connection = NMConnection() for item in settings_dict.iterkeys(): new_connection.get_setting(item).prop_dict = settings_dict[item] new_connection.settings_dict = settings_dict return new_connection