1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-21 21:38:06 +01:00

Merge 1.6 branch.

This commit is contained in:
Dan O'Reilly
2009-03-21 16:37:21 -04:00
9 changed files with 138 additions and 95 deletions

View File

@@ -18,14 +18,18 @@
PATH=/usr/sbin:/usr/bin:/sbin:/bin PATH=/usr/sbin:/usr/bin:/sbin:/bin
DESC="Network connection manager" DESC="Network connection manager"
NAME=wicd NAME=wicd
RUNDIR=/var/run/$NAME
DAEMON=%SBIN%$NAME DAEMON=%SBIN%$NAME
DAEMON_ARGS="" DAEMON_ARGS=""
PIDFILE=%PIDFILE% PIDFILE=$RUNDIR/wicd.pid
SCRIPTNAME=%INIT%%INITFILENAME% SCRIPTNAME=%INIT%%INITFILENAME%
# Exit if the package is not installed # Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0 [ -x "$DAEMON" ] || exit 0
# Create RUNDIR if it doesn't exist
[ -d "$RUNDIR" ] || mkdir -p "$RUNDIR"
# Read configuration variable file if it is present # Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME [ -r /etc/default/$NAME ] && . /etc/default/$NAME

View File

@@ -8,7 +8,7 @@
# #
# processname: wicd # processname: wicd
# config: # config:
# pidfile: /var/run/wicd.pid # pidfile: %PIDFILE%
# #
# $Id: template.init 9689 2008-03-27 16:15:39Z patrys $ # $Id: template.init 9689 2008-03-27 16:15:39Z patrys $

View File

@@ -441,7 +441,6 @@ try:
piddir = os.path.dirname(wpath.pidfile) piddir = os.path.dirname(wpath.pidfile)
if not piddir.endswith('/'): if not piddir.endswith('/'):
piddir += '/' piddir += '/'
data.append (( piddir, [] ))
if not wpath.no_install_docs: if not wpath.no_install_docs:
data.append((wpath.docdir, ['INSTALL', 'LICENSE', 'AUTHORS', data.append((wpath.docdir, ['INSTALL', 'LICENSE', 'AUTHORS',
'README', 'CHANGES', ])) 'README', 'CHANGES', ]))

View File

@@ -572,4 +572,3 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
return None return None
return buff.strip('\x00') return buff.strip('\x00')

View File

@@ -69,7 +69,8 @@ class WicdError(Exception):
__LANG = None __LANG = None
def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False): def Run(cmd, include_stderr=False, return_pipe=False,
return_obj=False, return_retcode=True):
""" Run a command. """ Run a command.
Runs the given command, returning either the output Runs the given command, returning either the output
@@ -81,8 +82,10 @@ def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False):
be included in the pipe to the cmd. be included in the pipe to the cmd.
return_pipe - Boolean specifying if a pipe to the return_pipe - Boolean specifying if a pipe to the
command should be returned. If it is command should be returned. If it is
false, all that will be returned is False, all that will be returned is
one output string from the command. one output string from the command.
return_obj - If True, Run will return the Popen object
for the command that was run.
""" """
global __LANG global __LANG
@@ -136,8 +139,14 @@ def LaunchAndWait(cmd):
cmd : A list contained the program name and its arguments. cmd : A list contained the program name and its arguments.
returns: The exit code of the process.
""" """
call(cmd, shell=False) if not isinstance(cmd, list):
cmd = to_unicode(str(cmd))
cmd = cmd.split()
p = Popen(cmd, shell=False, stdout=PIPE, stderr=STDOUT, stdin=None)
return p.wait()
def IsValidIP(ip): def IsValidIP(ip):
""" Make sure an entered IP is valid. """ """ Make sure an entered IP is valid. """

View File

@@ -183,15 +183,13 @@ class ConnectionStatus(object):
if daemon.GetSuspend(): if daemon.GetSuspend():
print "Suspended." print "Suspended."
state = misc.SUSPENDED state = misc.SUSPENDED
self.update_state(state) return self.update_state(state)
return True
# Determine what our current state is. # Determine what our current state is.
# Are we currently connecting? # Are we currently connecting?
if daemon.CheckIfConnecting(): if daemon.CheckIfConnecting():
state = misc.CONNECTING state = misc.CONNECTING
self.update_state(state) return self.update_state(state)
return True
daemon.SendConnectResultsIfAvail() daemon.SendConnectResultsIfAvail()
@@ -199,8 +197,7 @@ class ConnectionStatus(object):
wired_ip = wired.GetWiredIP("") wired_ip = wired.GetWiredIP("")
wired_found = self.check_for_wired_connection(wired_ip) wired_found = self.check_for_wired_connection(wired_ip)
if wired_found: if wired_found:
self.update_state(misc.WIRED, wired_ip=wired_ip) return self.update_state(misc.WIRED, wired_ip=wired_ip)
return True
# Check for wireless # Check for wireless
wifi_ip = wireless.GetWirelessIP("") wifi_ip = wireless.GetWirelessIP("")
@@ -219,12 +216,10 @@ class ConnectionStatus(object):
if not daemon.GetGUIOpen(): if not daemon.GetGUIOpen():
print 'Killing wireless connection to switch to wired...' print 'Killing wireless connection to switch to wired...'
wireless.DisconnectWireless() wireless.DisconnectWireless()
daemon.AutoConnect(False, reply_handler=lambda:None, daemon.AutoConnect(False, reply_handler=lambda *a:None,
error_handler=lambda:None) error_handler=lambda *a:None)
self.update_state(misc.NOT_CONNECTED) return self.update_state(misc.NOT_CONNECTED)
return True return self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
self.update_state(misc.WIRELESS, wifi_ip=wifi_ip)
return True
state = misc.NOT_CONNECTED state = misc.NOT_CONNECTED
if self.last_state == misc.WIRELESS: if self.last_state == misc.WIRELESS:
@@ -232,8 +227,7 @@ class ConnectionStatus(object):
else: else:
from_wireless = False from_wireless = False
self.auto_reconnect(from_wireless) self.auto_reconnect(from_wireless)
self.update_state(state) return self.update_state(state)
return True
def _force_update_connection_status(self): def _force_update_connection_status(self):
""" Run a connection status update on demand. """ Run a connection status update on demand.
@@ -272,6 +266,7 @@ class ConnectionStatus(object):
else: else:
print 'ERROR: Invalid state!' print 'ERROR: Invalid state!'
return True return True
daemon.SetConnectionStatus(state, info) daemon.SetConnectionStatus(state, info)
# Send a D-Bus signal announcing status has changed if necessary. # Send a D-Bus signal announcing status has changed if necessary.

View File

@@ -426,6 +426,29 @@ class ConnectThread(threading.Thread):
self.abort_connection(dhcp_status) self.abort_connection(dhcp_status)
return return
@abortable
def verify_association(self, iface):
""" Verify that our association the AP is valid.
Try to ping the gateway we have set to see if we're
really associated with it. This is only done if
we're using a static IP.
"""
if self.network.get('gateway'):
self.SetStatus('verifying_association')
print "Verifying AP association"
retcode = self.iface.VerifyAPAssociation(self.network['gateway'])
#TODO this should be in wnettools.py
if retcode:
print "Connection Failed: Failed to ping the access point!"
# Clean up before aborting.
iface.SetAddress('0.0.0.0')
iface.FlushRoutes()
if hasattr(iface, "StopWPA"):
iface.StopWPA()
self.abort_connection("association_failed")
@abortable @abortable
def set_dns_addresses(self, iface): def set_dns_addresses(self, iface):
""" Set the DNS address(es). """ Set the DNS address(es).
@@ -838,6 +861,7 @@ class WirelessConnectThread(ConnectThread):
self.set_broadcast_address(wiface) self.set_broadcast_address(wiface)
self.set_ip_address(wiface) self.set_ip_address(wiface)
self.set_dns_addresses(wiface) self.set_dns_addresses(wiface)
self.verify_association(wiface)
# Run post-connection script. # Run post-connection script.
self.run_global_scripts_if_needed(wpath.postconnectscripts) self.run_global_scripts_if_needed(wpath.postconnectscripts)

View File

@@ -153,6 +153,8 @@ language['dhcp_failed'] = _('Connection Failed: Unable to Get IP Address')
language['no_dhcp_offers'] = _('Connection Failed: No DHCP offers received.') language['no_dhcp_offers'] = _('Connection Failed: No DHCP offers received.')
language['aborted'] = _('Connection Cancelled') language['aborted'] = _('Connection Cancelled')
language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)') language['bad_pass'] = _('Connection Failed: Could not authenticate (bad password?)')
language['verifying_association'] = _("Verifying access point association...")
language['association_failed'] = _("Connection Failed: Could not contact the wireless access point.")
language['done'] = _('Done connecting...') language['done'] = _('Done connecting...')
language['scanning'] = _('Scanning') language['scanning'] = _('Scanning')
language['scanning_stand_by'] = _('Scanning networks... stand by...') language['scanning_stand_by'] = _('Scanning networks... stand by...')

View File

@@ -585,6 +585,17 @@ class BaseInterface(object):
output = ifconfig output = ifconfig
return misc.RunRegex(ip_pattern, output) return misc.RunRegex(ip_pattern, output)
def VerifyAPAssociation(self, gateway):
""" Verify assocation with an access point.
Verifies that an access point can be contacted by
trying to ping it.
"""
cmd = "ping -q -w 3 -c 1 %s" % gateway
if self.verbose: print cmd
return misc.LaunchAndWait(cmd)
def IsUp(self, ifconfig=None): def IsUp(self, ifconfig=None):
""" Determines if the interface is up. """ Determines if the interface is up.