41
41
# and helped keep this project moving.
50
import wicd.wpath as wpath
51
import wicd.wnettools as wnettools
50
from wicd import wpath
51
from wicd import wnettools
53
53
if __name__ == '__main__':
54
54
wpath.chdir(__file__)
183
183
self.debug = debug
185
185
self.SetStatus('interface_down')
187
def get_should_die(self):
188
return self._should_die
190
def set_should_die(self, val):
193
self._should_die = val
197
should_die = property(get_should_die, set_should_die)
188
200
def SetStatus(self, status):
305
317
if self.abort_reason:
306
318
reason = self.abort_reason
307
self.SetStatus(reason)
319
self.connecting_message = reason
308
320
self.is_aborted = True
309
321
self.abort_msg = reason
310
322
self.is_connecting = False
311
323
print 'exiting connection thread'
313
def abort_connection(self, reason):
325
def abort_connection(self, reason=""):
314
326
""" Schedule a connection abortion for the given reason. """
315
327
self.abort_reason = reason
316
328
self.should_die = True
330
342
def abort_if_needed(self):
331
343
""" Abort the thread is it has been requested. """
333
self.connect_aborted('aborted')
347
self.connect_aborted('aborted')
336
352
def put_iface_up(self, iface):
337
353
""" Bring up given interface. """
363
379
def LoadInterfaces(self):
364
380
""" Load the wnettools controls for the wired/wireless interfaces. """
365
381
self.wiface = wnettools.WirelessInterface(self.wireless_interface,
366
self.debug, self.wpa_driver)
383
self.flush_tool, self.debug,
368
386
def Scan(self, essid=None):
369
387
""" Scan for available wireless networks.
415
435
network -- network to connect to
438
if not self.wireless_interface: return False
418
440
self.connecting_thread = WirelessConnectThread(network,
419
441
self.wireless_interface, self.wired_interface,
420
442
self.wpa_driver, self.before_script, self.after_script,
645
667
self.run_script_if_needed(self.before_script, 'pre-connection')
646
668
self.abort_if_needed()
648
# Dake down interface and clean up previous connections.
670
# Take down interface and clean up previous connections.
649
671
self.put_iface_down(wiface)
650
672
self.abort_if_needed()
651
673
self.release_dhcp_clients(wiface, liface)
700
722
def generate_psk_and_authenticate(self, wiface):
701
723
""" Generates a PSK and authenticates if necessary.
703
Generates a PSK using wpa_passphrase, and starts the authentication
704
process if encryption is on.
725
Generates a PSK, and starts the authentication process
708
""" Escapes characters wpa_supplicant doesn't handle properly. """
710
blacklist = ["$", "`", "\""]
713
new_key.append("\\" + c)
716
return ''.join(new_key)
718
# Check to see if we need to generate a PSK (only for non-ralink
720
729
if self.network.get('key'):
721
730
self.SetStatus('generating_psk')
723
731
print 'Generating psk...'
724
key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',
726
self.network['psk'] = misc.RunRegex(key_pattern,
727
misc.Run(''.join(['wpa_passphrase "',
728
self.network['essid'], '" "',
729
_sanitize(self.network['key']), '"'])))
732
self.network['psk'] = self.wiface.GeneratePSK(self.network)
731
if not self.network['psk']:
734
if not self.network.get('psk'):
732
735
self.network['psk'] = self.network['key']
733
736
print 'WARNING: PSK generation failed! Falling back to ' + \
734
737
'wireless key.\nPlease report this error to the wicd ' + \
758
761
def get_link_detect(self): return self._link_detect
760
763
link_detect = property(get_link_detect, set_link_detect)
762
765
def LoadInterfaces(self):
763
766
""" Load the wnettools controls for the wired/wireless interfaces. """
764
self.liface = wnettools.WiredInterface(self.wired_interface, self.debug)
767
self.liface = wnettools.WiredInterface(self.wired_interface,
768
self.dhcp_client, self.flush_tool,
769
self.link_detect, self.debug)
766
771
def CheckPluggedIn(self):
767
772
""" Check whether the wired connection is plugged in.
779
784
network -- network to connect to
787
if not self.wired_interface: return False
782
788
self.connecting_thread = WiredConnectThread(network,
783
789
self.wireless_interface, self.wired_interface,
784
790
self.before_script, self.after_script,