mirror of
https://github.com/gryf/wicd.git
synced 2026-03-11 03:55:56 +01:00
Merged wired-encryption implementation by Joe MacMahon. Thanks!
This commit is contained in:
20
wicd/misc.py
20
wicd/misc.py
@@ -271,7 +271,10 @@ def ParseEncryption(network):
|
||||
"""
|
||||
enctemplate = open(wpath.encryption + network["enctype"])
|
||||
template = enctemplate.readlines()
|
||||
config_file = "ap_scan=1\n"
|
||||
if network.get('essid'):
|
||||
config_file = "ap_scan=1\n"
|
||||
else:
|
||||
config_file = "ap_scan=0\n"
|
||||
should_replace = False
|
||||
for index, line in enumerate(template):
|
||||
if not should_replace:
|
||||
@@ -303,8 +306,11 @@ def ParseEncryption(network):
|
||||
|
||||
# Write the data to the files then chmod them so they can't be read
|
||||
# by normal users.
|
||||
file_loc = os.path.join(wpath.networks,
|
||||
network['bssid'].replace(":", "").lower())
|
||||
if network.get('bssid'):
|
||||
file_name = network['bssid'].replace(":", "").lower()
|
||||
else:
|
||||
file_name = 'wired'
|
||||
file_loc = os.path.join(wpath.networks, file_name)
|
||||
f = open(file_loc, "w")
|
||||
os.chmod(file_loc, 0600)
|
||||
os.chown(file_loc, 0, 0)
|
||||
@@ -313,7 +319,7 @@ def ParseEncryption(network):
|
||||
f.write(config_file)
|
||||
f.close()
|
||||
|
||||
def LoadEncryptionMethods():
|
||||
def LoadEncryptionMethods(wired = False):
|
||||
""" Load encryption methods from configuration files
|
||||
|
||||
Loads all the encryption methods from the template files
|
||||
@@ -321,8 +327,12 @@ def LoadEncryptionMethods():
|
||||
loaded, the template must be listed in the "active" file.
|
||||
|
||||
"""
|
||||
if wired:
|
||||
active_fname = "active_wired"
|
||||
else:
|
||||
active_fname = "active"
|
||||
try:
|
||||
enctypes = open(wpath.encryption + "active","r").readlines()
|
||||
enctypes = open(wpath.encryption + active_fname,"r").readlines()
|
||||
except IOError, e:
|
||||
print "Fatal Error: template index file is missing."
|
||||
raise IOError(e)
|
||||
|
||||
@@ -518,6 +518,12 @@ class ConnectThread(threading.Thread):
|
||||
finally:
|
||||
self.lock.release()
|
||||
|
||||
@abortable
|
||||
def stop_wpa(self, iface):
|
||||
""" Stops wpa_supplicant. """
|
||||
print 'Stopping wpa_supplicant'
|
||||
iface.StopWPA()
|
||||
|
||||
@abortable
|
||||
def put_iface_up(self, iface):
|
||||
""" Bring up given interface. """
|
||||
@@ -968,13 +974,6 @@ class WirelessConnectThread(ConnectThread):
|
||||
self.abort_connection('association_failed')
|
||||
else:
|
||||
print 'not verifying'
|
||||
|
||||
|
||||
@abortable
|
||||
def stop_wpa(self, wiface):
|
||||
""" Stops wpa_supplicant. """
|
||||
print 'Stopping wpa_supplicant'
|
||||
wiface.StopWPA()
|
||||
|
||||
@abortable
|
||||
def generate_psk_and_authenticate(self, wiface):
|
||||
@@ -1073,6 +1072,10 @@ class Wired(Controller):
|
||||
|
||||
def Disconnect(self):
|
||||
Controller.Disconnect(self, 'wired', 'wired', 'wired')
|
||||
self.StopWPA()
|
||||
|
||||
def StopWPA(self):
|
||||
self.liface.StopWPA()
|
||||
|
||||
def DetectWiredInterface(self):
|
||||
""" Attempts to automatically detect a wired interface. """
|
||||
@@ -1143,11 +1146,16 @@ class WiredConnectThread(ConnectThread):
|
||||
self.put_iface_down(liface)
|
||||
self.release_dhcp_clients(liface)
|
||||
self.reset_ip_addresses(liface)
|
||||
self.stop_wpa(liface)
|
||||
self.flush_routes(liface)
|
||||
|
||||
# Bring up interface.
|
||||
self.put_iface_up(liface)
|
||||
|
||||
# Manage encryption.
|
||||
if self.network.get('encryption_enabled'):
|
||||
liface.Authenticate(self.network)
|
||||
|
||||
# Set gateway, IP adresses, and DNS servers.
|
||||
self.set_broadcast_address(liface)
|
||||
self.set_ip_address(liface)
|
||||
|
||||
@@ -1492,7 +1492,7 @@ class WiredDaemon(dbus.service.Object):
|
||||
for option in ["ip", "broadcast", "netmask", "gateway", "search_domain",
|
||||
"dns_domain", "dns1", "dns2", "dns3", "beforescript",
|
||||
"afterscript", "predisconnectscript",
|
||||
"postdisconnectscript"]:
|
||||
"postdisconnectscript", "encryption_enabled"]:
|
||||
self.config.set(profilename, option, None)
|
||||
self.config.set(profilename, "default", default)
|
||||
self.config.set(profilename,"dhcphostname",os.uname()[1])
|
||||
@@ -1580,6 +1580,7 @@ class WiredDaemon(dbus.service.Object):
|
||||
profile[x] = misc.Noneify(self.config.get(profilename, x))
|
||||
profile['use_global_dns'] = bool(profile.get('use_global_dns'))
|
||||
profile['use_static_dns'] = bool(profile.get('use_static_dns'))
|
||||
profile['encryption_enabled'] = bool(profile.get('encryption_enabled'))
|
||||
profile['profilename'] = profilename
|
||||
self.WiredNetwork = profile
|
||||
self._cur_wired_prof_name = profilename
|
||||
|
||||
@@ -768,6 +768,13 @@ class BaseInterface(object):
|
||||
print "Could not open %s, using ifconfig to determine status" % flags_file
|
||||
return self._slow_is_up(ifconfig)
|
||||
return bool(int(flags, 16) & 1)
|
||||
|
||||
@neediface(False)
|
||||
def StopWPA(self):
|
||||
""" Terminates wpa using wpa_cli"""
|
||||
cmd = 'wpa_cli -i %s terminate' % self.iface
|
||||
if self.verbose: print cmd
|
||||
misc.Run(cmd)
|
||||
|
||||
|
||||
def _slow_is_up(self, ifconfig=None):
|
||||
@@ -892,6 +899,13 @@ class BaseWiredInterface(BaseInterface):
|
||||
else:
|
||||
return False
|
||||
|
||||
def Authenticate(self, network):
|
||||
misc.ParseEncryption(network)
|
||||
cmd = ['wpa_supplicant', '-B', '-i', self.iface, '-c',
|
||||
os.path.join(wpath.networks, 'wired'),
|
||||
'-Dwired']
|
||||
if self.verbose: print cmd
|
||||
misc.Run(cmd)
|
||||
|
||||
class BaseWirelessInterface(BaseInterface):
|
||||
""" Control a wireless network interface. """
|
||||
@@ -1385,13 +1399,6 @@ class BaseWirelessInterface(BaseInterface):
|
||||
print 'wpa_supplicant rescan forced...'
|
||||
cmd = 'wpa_cli -i' + self.iface + ' scan'
|
||||
misc.Run(cmd)
|
||||
|
||||
@neediface(False)
|
||||
def StopWPA(self):
|
||||
""" Terminates wpa using wpa_cli"""
|
||||
cmd = 'wpa_cli -i %s terminate' % self.iface
|
||||
if self.verbose: print cmd
|
||||
misc.Run(cmd)
|
||||
|
||||
@neediface("")
|
||||
def GetBSSID(self, iwconfig=None):
|
||||
|
||||
Reference in New Issue
Block a user