mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Experimental/Testing:
- Improved behavior in the networking backend. The wired/wireless wnettools instances now refer to each other, and get passed on to connection threads as well, which simplifies passing settings for external program usage. Also removed some unecessary creating of duplicate wnettools instances which ended up causing some issues. - Fixed bug where dhclient was being used as the dhcp client even if it was selected in the options menu. - Fixed a typo in the connection commands used for ralink cards. - Fixed the wrong cli option for releasing a dhcpcd lease. - Monitor.py no longer calls for an auto-rescan if the daemon is currently connecting to a network. - Cleaned up some comments and simplified the logic in a few methods/functions.
This commit is contained in:
@@ -155,9 +155,10 @@ class ConnectionWizard(dbus.service.Object):
|
||||
# Make a variable that will hold the wired network profile
|
||||
self.WiredNetwork = {}
|
||||
|
||||
# Load our wired/wireless interfaces
|
||||
self.wifi.LoadInterfaces()
|
||||
self.wired.LoadInterfaces()
|
||||
# Kind of hackish way to load the secondary wnettools interface
|
||||
# for both wired and wireless connection managers.
|
||||
self.wifi.liface = self.wired.liface
|
||||
self.wired.wiface = self.wifi.wiface
|
||||
|
||||
# Scan since we just got started
|
||||
if auto_connect:
|
||||
@@ -590,6 +591,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def SetDHCPClient(self, client):
|
||||
print "Setting dhcp client to %i" % (int(client))
|
||||
self.dhcp_client = int(client)
|
||||
self.wifi.dhcp_client = int(client)
|
||||
self.wired.dhcp_client = int(client)
|
||||
|
||||
2
gui.py
2
gui.py
@@ -382,7 +382,7 @@ class appGui:
|
||||
dhclientradio = self.wTree.get_widget("dhclient_radio")
|
||||
pumpradio = self.wTree.get_widget("pump_radio")
|
||||
dhcpcdradio = self.wTree.get_widget("dhcpcd_radio")
|
||||
dhcp_list = [dhcpautoradio, dhclientradio, pumpradio, dhcpcdradio]
|
||||
dhcp_list = [dhcpautoradio, dhclientradio, dhcpcdradio, pumpradio]
|
||||
|
||||
dhcp_method = daemon.GetDHCPClient()
|
||||
dhcp_list[dhcp_method].set_active(True)
|
||||
|
||||
11
misc.py
11
misc.py
@@ -283,14 +283,11 @@ def get_gettext():
|
||||
def to_unicode(x):
|
||||
""" Attempts to convert a string to utf-8. """
|
||||
try: # This may never fail, but let's be safe
|
||||
default_encoding = locale.getpreferredencoding()
|
||||
encoding = locale.getpreferredencoding()
|
||||
except:
|
||||
default_encoding = None
|
||||
|
||||
if default_encoding:
|
||||
ret = x.decode(default_encoding, 'replace').encode('utf-8')
|
||||
else: # Just guess UTF-8
|
||||
ret = x.decode('utf-8', 'replace').encode('utf-8')
|
||||
# Just guess utf-8 if it fails.
|
||||
encoding = 'utf-8'
|
||||
ret = x.decode(encoding, 'replace').encode('utf-8')
|
||||
return ret
|
||||
|
||||
def RenameProcess(new_name):
|
||||
|
||||
@@ -260,7 +260,7 @@ class ConnectionStatus():
|
||||
def rescan_networks(self):
|
||||
""" Calls a wireless scan. """
|
||||
try:
|
||||
if daemon.GetSuspend():
|
||||
if daemon.GetSuspend() or daemon.CheckIfConnecting():
|
||||
return True
|
||||
wireless.Scan()
|
||||
daemon.SendScanSignal()
|
||||
|
||||
@@ -103,8 +103,10 @@ class Controller(object):
|
||||
self._dhcp_client = value
|
||||
if self.wiface:
|
||||
self.wiface.DHCP_CLIENT = value
|
||||
self.wiface.CheckDHCP()
|
||||
if self.liface:
|
||||
self.liface.DHCP_CLIENT = value
|
||||
self.liface.CheckDHCP()
|
||||
|
||||
def get_dhcp_client(self):
|
||||
return self._dhcp_client
|
||||
@@ -140,7 +142,7 @@ class ConnectThread(threading.Thread):
|
||||
lock = thread.allocate_lock()
|
||||
|
||||
def __init__(self, network, wireless, wired, before_script, after_script,
|
||||
disconnect_script, gdns1, gdns2, gdns3, debug):
|
||||
disconnect_script, gdns1, gdns2, gdns3, wiface, liface, debug):
|
||||
""" Initialise the required object variables and the thread.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -173,6 +175,9 @@ class ConnectThread(threading.Thread):
|
||||
self.global_dns_2 = gdns2
|
||||
self.global_dns_3 = gdns3
|
||||
|
||||
self.wiface = wiface
|
||||
self.liface = liface
|
||||
|
||||
self.connecting_message = None
|
||||
self.debug = debug
|
||||
|
||||
@@ -391,7 +396,8 @@ class Wireless(Controller):
|
||||
self.wireless_interface, self.wired_interface,
|
||||
self.wpa_driver, self.before_script, self.after_script,
|
||||
self.disconnect_script, self.global_dns_1,
|
||||
self.global_dns_2, self.global_dns_3, debug)
|
||||
self.global_dns_2, self.global_dns_3, self.wiface, self.liface,
|
||||
debug)
|
||||
self.connecting_thread.setDaemon(True)
|
||||
self.connecting_thread.start()
|
||||
return True
|
||||
@@ -570,7 +576,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
|
||||
def __init__(self, network, wireless, wired, wpa_driver,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3, debug=False):
|
||||
gdns2, gdns3, wiface, liface, debug=False):
|
||||
""" Initialise the thread with network information.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -588,7 +594,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3, debug)
|
||||
gdns2, gdns3, wiface, liface, debug)
|
||||
self.wpa_driver = wpa_driver
|
||||
|
||||
|
||||
@@ -606,9 +612,8 @@ class WirelessConnectThread(ConnectThread):
|
||||
5. Get/set IP address and DNS servers.
|
||||
|
||||
"""
|
||||
wiface = wnettools.WirelessInterface(self.wireless_interface,
|
||||
self.debug, self.wpa_driver)
|
||||
liface = wnettools.WiredInterface(self.wired_interface, self.debug)
|
||||
wiface = self.wiface
|
||||
liface = self.liface
|
||||
self.is_connecting = True
|
||||
|
||||
# Run pre-connection script.
|
||||
@@ -747,7 +752,7 @@ class Wired(Controller):
|
||||
self.wireless_interface, self.wired_interface,
|
||||
self.before_script, self.after_script,
|
||||
self.disconnect_script, self.global_dns_1,
|
||||
self.global_dns_2, self.global_dns_3, debug)
|
||||
self.global_dns_2, self.global_dns_3, wiface, liface, debug)
|
||||
self.connecting_thread.setDaemon(True)
|
||||
self.connecting_thread.start()
|
||||
return True
|
||||
@@ -809,7 +814,7 @@ class WiredConnectThread(ConnectThread):
|
||||
"""
|
||||
def __init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3, debug=False):
|
||||
gdns2, gdns3, wiface, liface, debug=False):
|
||||
""" Initialise the thread with network information.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -826,7 +831,7 @@ class WiredConnectThread(ConnectThread):
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3, debug)
|
||||
gdns2, gdns3, wiface, liface, debug)
|
||||
|
||||
def run(self):
|
||||
""" The main function of the connection thread.
|
||||
@@ -842,8 +847,8 @@ class WiredConnectThread(ConnectThread):
|
||||
5. Run post-connection script.
|
||||
|
||||
"""
|
||||
wiface = wnettools.WirelessInterface(self.wireless_interface, self.debug)
|
||||
liface = wnettools.WiredInterface(self.wired_interface, self.debug)
|
||||
wiface = self.wiface
|
||||
liface = self.liface
|
||||
|
||||
self.is_connecting = True
|
||||
|
||||
|
||||
27
wnettools.py
27
wnettools.py
@@ -239,15 +239,31 @@ class Interface(object):
|
||||
def CheckDHCP(self):
|
||||
""" Check for a valid DHCP client.
|
||||
|
||||
Checks for the existence of a support DHCP client. If one is
|
||||
Checks for the existence of a supported DHCP client. If one is
|
||||
found, the appropriate values for DHCP_CMD, DHCP_RELEASE, and
|
||||
DHCP_CLIENT are set. If a supported client is not found, a
|
||||
warning is printed.
|
||||
|
||||
"""
|
||||
if self.DHCP_CLIENT:
|
||||
dhcp_client = self.DHCP_CLIENT
|
||||
def get_client_name(cl):
|
||||
""" Converts the integer value for a dhcp client to a string. """
|
||||
if cl in [misc.DHCLIENT, "dhclient"]:
|
||||
client = "dhclient"
|
||||
elif cl in [misc.DHCPCD, "dhcpcd"]:
|
||||
client = "dhcpcd"
|
||||
else:
|
||||
client = "pump"
|
||||
return client
|
||||
|
||||
print 'checking dhcp...'
|
||||
|
||||
if self.DHCP_CLIENT:
|
||||
dhcp_client = get_client_name(self.DHCP_CLIENT)
|
||||
dhcp_path = self._find_client_path(dhcp_client)
|
||||
if not dhcp_path:
|
||||
print "WARNING: Could not find selected dhcp client. Wicd " + \
|
||||
" will try to find another supported client."
|
||||
if not self.DHCP_CLIENT or not dhcp_path:
|
||||
dhcp_client = None
|
||||
dhcp_path = None
|
||||
dhcpclients = ["dhclient", "dhcpcd", "pump"]
|
||||
@@ -271,7 +287,7 @@ class Interface(object):
|
||||
elif dhcp_client in [misc.DHCPCD, "dhcpcd"]:
|
||||
dhcp_client = misc.DHCPCD
|
||||
dhcp_cmd = dhcp_path
|
||||
dhcp_release = dhcp_cmd + " -r"
|
||||
dhcp_release = dhcp_cmd + " -k"
|
||||
else:
|
||||
dhcp_client = None
|
||||
dhcp_cmd = None
|
||||
@@ -1126,7 +1142,7 @@ class WirelessInterface(Interface):
|
||||
cmd_list = []
|
||||
cmd_list.append('NetworkType=' + info[6])
|
||||
cmd_list.append('AuthMode=' + auth_mode)
|
||||
cmd_list.append('EncryptType=' + info[4])
|
||||
cmd_list.append('EncrypType=' + info[4])
|
||||
cmd_list.append('SSID=' + info[2])
|
||||
cmd_list.append(key_name + '=' + network.get('key'))
|
||||
if info[5] == 'SHARED' and info[4] == 'WEP':
|
||||
@@ -1207,6 +1223,7 @@ class WirelessInterface(Interface):
|
||||
if self.verbose:
|
||||
print "SIOCGIWRANGE failed: " + str(e)
|
||||
return None
|
||||
# This defines the iwfreq struct, used to get singal strength.
|
||||
fmt = "iiihb6ii4B4Bi32i2i2i2i2i3h8h2b2bhi8i2b3h2i2ihB17x" + 32 * "ihbb"
|
||||
size = struct.calcsize(fmt)
|
||||
data = buff.tostring()
|
||||
|
||||
Reference in New Issue
Block a user