mirror of
https://github.com/gryf/wicd.git
synced 2026-01-06 22:04:19 +01:00
Merged mainline, which includes NaCl's curses stuff and all fixes and
such from this branch.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||||
<!--Generated with glade3 3.4.5 on Mon Jan 26 10:54:15 2009 -->
|
<!--Generated with glade3 3.4.5 on Sun Feb 1 21:38:09 2009 -->
|
||||||
<glade-interface>
|
<glade-interface>
|
||||||
<widget class="GtkWindow" id="window1">
|
<widget class="GtkWindow" id="window1">
|
||||||
<property name="width_request">450</property>
|
<property name="width_request">450</property>
|
||||||
@@ -895,7 +895,7 @@ is already active.</property>
|
|||||||
<child>
|
<child>
|
||||||
<widget class="GtkTable" id="table2">
|
<widget class="GtkTable" id="table2">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="n_rows">6</property>
|
<property name="n_rows">8</property>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkLabel" id="route_flush_label">
|
<widget class="GtkLabel" id="route_flush_label">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@@ -961,7 +961,7 @@ is already active.</property>
|
|||||||
<widget class="GtkRadioButton" id="route_flush_radio">
|
<widget class="GtkRadioButton" id="route_flush_radio">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="label" translatable="yes">route </property>
|
<property name="label" translatable="yes">route</property>
|
||||||
<property name="response_id">0</property>
|
<property name="response_id">0</property>
|
||||||
<property name="active">True</property>
|
<property name="active">True</property>
|
||||||
<property name="draw_indicator">True</property>
|
<property name="draw_indicator">True</property>
|
||||||
@@ -1125,6 +1125,92 @@ is already active.</property>
|
|||||||
<property name="y_options"></property>
|
<property name="y_options"></property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkLabel" id="sudo_app_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
<property name="label" translatable="yes"><b>Graphical Sudo Application</b></property>
|
||||||
|
<property name="use_markup">True</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="top_attach">6</property>
|
||||||
|
<property name="bottom_attach">7</property>
|
||||||
|
<property name="y_options"></property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkAlignment" id="alignment25">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="left_padding">12</property>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkVBox" id="vbox1">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkRadioButton" id="sudo_auto_radio">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="label" translatable="yes">Automatic (recommended)</property>
|
||||||
|
<property name="response_id">0</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkRadioButton" id="gksudo_radio">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="label" translatable="yes">gksudo</property>
|
||||||
|
<property name="response_id">0</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<property name="group">sudo_auto_radio</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkRadioButton" id="kdesu_radio">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="label" translatable="yes">kdesu</property>
|
||||||
|
<property name="response_id">0</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<property name="group">sudo_auto_radio</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkRadioButton" id="ktsuss_radio">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="label" translatable="yes">ktsuss</property>
|
||||||
|
<property name="response_id">0</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<property name="group">sudo_auto_radio</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="position">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</widget>
|
||||||
|
</child>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="top_attach">7</property>
|
||||||
|
<property name="bottom_attach">8</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
This module implements functions to control and obtain information from
|
This module implements functions to control and obtain information from
|
||||||
network interfaces.
|
network interfaces.
|
||||||
|
|
||||||
def SetDNS() -- Set the DNS servers of the system.
|
|
||||||
def GetWirelessInterfaces() -- Get the wireless interfaces available.
|
|
||||||
class Interface() -- Control a network interface.
|
class Interface() -- Control a network interface.
|
||||||
class WiredInterface() -- Control a wired network interface.
|
class WiredInterface() -- Control a wired network interface.
|
||||||
class WirelessInterface() -- Control a wireless network interface.
|
class WirelessInterface() -- Control a wireless network interface.
|
||||||
@@ -31,9 +29,9 @@ class WirelessInterface() -- Control a wireless network interface.
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
import wicd.misc as misc
|
from wicd import misc
|
||||||
import wicd.wnettools as wnettools
|
from wicd import wnettools
|
||||||
|
from wicd.wnettools import *
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
@@ -78,30 +76,6 @@ auth_pattern = re.compile('.*wpa_state=(.*?)\n', re.I | re.M | re.S)
|
|||||||
RALINK_DRIVER = 'ralink legacy'
|
RALINK_DRIVER = 'ralink legacy'
|
||||||
|
|
||||||
|
|
||||||
def SetDNS(*args, **kargs):
|
|
||||||
""" Call the wnettools SetDNS method. """
|
|
||||||
return wnettools.SetDNS(*args, **kargs)
|
|
||||||
|
|
||||||
def GetDefaultGateway(*args, **kargs):
|
|
||||||
""" Call the wnettools GetDefaultGateway method. """
|
|
||||||
return wnettools.GetDefaultGateway(*args, **kargs)
|
|
||||||
|
|
||||||
def StopDHCP(*args, **kargs):
|
|
||||||
""" Call the wnettools StopDHCP method. """
|
|
||||||
return wnettools.StopDHCP(*args, **kargs)
|
|
||||||
|
|
||||||
def GetWirelessInterfaces(*args, **kargs):
|
|
||||||
""" Call the wnettools GetWirelessInterfaces method. """
|
|
||||||
return wnettools.GetWirelessInterfaces(*args, **kargs)
|
|
||||||
|
|
||||||
def GetWiredInterfaces(*args, **kargs):
|
|
||||||
""" Call the wnettools GetWiredInterfaces method. """
|
|
||||||
return wnettools.GetWiredInterfaces(*args, **kargs)
|
|
||||||
|
|
||||||
def IsValidWpaSuppDriver(*args, **kargs):
|
|
||||||
""" Call the wnettools IsValidWpaSuppDrive method. """
|
|
||||||
return wnettools.IsValidWpaSuppDriver(*args, **kargs)
|
|
||||||
|
|
||||||
def NeedsExternalCalls(*args, **kargs):
|
def NeedsExternalCalls(*args, **kargs):
|
||||||
""" Return True, since this backend using iwconfig/ifconfig. """
|
""" Return True, since this backend using iwconfig/ifconfig. """
|
||||||
return True
|
return True
|
||||||
@@ -220,10 +194,10 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
|
|||||||
except (IOError, ValueError, TypeError):
|
except (IOError, ValueError, TypeError):
|
||||||
print 'Error checking link using /sys/class/net/%s/carrier' % self.iface
|
print 'Error checking link using /sys/class/net/%s/carrier' % self.iface
|
||||||
|
|
||||||
if self.ETHTOOL_FOUND and self.link_detect != misc.MIITOOL:
|
if self.miitool_cmd and self.link_detect == misc.MIITOOL:
|
||||||
return self._eth_get_plugged_in()
|
|
||||||
elif self.MIITOOL_FOUND:
|
|
||||||
return self._mii_get_plugged_in()
|
return self._mii_get_plugged_in()
|
||||||
|
elif self.ethtool_cmd:
|
||||||
|
return self._eth_get_plugged_in()
|
||||||
else:
|
else:
|
||||||
print 'Error: No way of checking for a wired connection. Make ' + \
|
print 'Error: No way of checking for a wired connection. Make ' + \
|
||||||
'sure that either mii-tool or ethtool is installed.'
|
'sure that either mii-tool or ethtool is installed.'
|
||||||
@@ -236,14 +210,15 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
|
|||||||
True if a link is detected, False otherwise.
|
True if a link is detected, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
link_tool = 'ethtool'
|
cmd = "%s %s" % (self.ethtool_cmd, self.iface)
|
||||||
if not self.IsUp():
|
if not self.IsUp():
|
||||||
print 'Wired Interface is down, putting it up'
|
print 'Wired Interface is down, putting it up'
|
||||||
self.Up()
|
self.Up()
|
||||||
time.sleep(6)
|
time.sleep(6)
|
||||||
tool_data = misc.Run(link_tool + ' ' + self.iface, True)
|
if self.verbose: print cmd
|
||||||
if misc.RunRegex(re.compile('(Link detected: yes)', re.I | re.M |
|
tool_data = misc.Run(cmd, include_stderr=True)
|
||||||
re.S), tool_data) is not None:
|
if misc.RunRegex(re.compile('(Link detected: yes)', re.I | re.M | re.S),
|
||||||
|
tool_data):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@@ -255,14 +230,16 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
|
|||||||
True if a link is detected, False otherwise.
|
True if a link is detected, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
link_tool = 'mii-tool'
|
cmd = "%s %s" % (self.miitool_cmd, self.iface)
|
||||||
tool_data = misc.Run(link_tool + ' ' + self.iface, True)
|
if self.verbose: print cmd
|
||||||
|
tool_data = misc.Run(cmd, include_stderr=True)
|
||||||
if misc.RunRegex(re.compile('(Invalid argument)', re.I | re.M | re.S),
|
if misc.RunRegex(re.compile('(Invalid argument)', re.I | re.M | re.S),
|
||||||
tool_data) is not None:
|
tool_data) is not None:
|
||||||
print 'Wired Interface is down, putting it up'
|
print 'Wired Interface is down, putting it up'
|
||||||
self.Up()
|
self.Up()
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
tool_data = misc.Run(link_tool + ' ' + self.iface, True)
|
if self.verbose: print cmd
|
||||||
|
tool_data = misc.Run(cmd, include_stderr=True)
|
||||||
|
|
||||||
if misc.RunRegex(re.compile('(link ok)', re.I | re.M | re.S),
|
if misc.RunRegex(re.compile('(link ok)', re.I | re.M | re.S),
|
||||||
tool_data) is not None:
|
tool_data) is not None:
|
||||||
@@ -421,14 +398,14 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
# Right now there's no way to do this for these drivers
|
# Right now there's no way to do this for these drivers
|
||||||
if self.wpa_driver == RALINK_DRIVER or not self.WPA_CLI_FOUND:
|
if self.wpa_driver == RALINK_DRIVER or not self.wpa_cli_cmd:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
MAX_TIME = 35
|
MAX_TIME = 35
|
||||||
MAX_DISCONNECTED_TIME = 3
|
MAX_DISCONNECTED_TIME = 3
|
||||||
disconnected_time = 0
|
disconnected_time = 0
|
||||||
while (time.time() - auth_time) < MAX_TIME:
|
while (time.time() - auth_time) < MAX_TIME:
|
||||||
cmd = 'wpa_cli -i ' + self.iface + ' status'
|
cmd = '%s -i %s status' % (self.wpa_cli_cmd, self.iface)
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
result = misc.RunRegex(auth_pattern, output)
|
result = misc.RunRegex(auth_pattern, output)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ This module implements functions to control and obtain information from
|
|||||||
network interfaces. It utilizes ioctl calls and python modules to
|
network interfaces. It utilizes ioctl calls and python modules to
|
||||||
obtain this information whenever possible.
|
obtain this information whenever possible.
|
||||||
|
|
||||||
def SetDNS() -- Set the DNS servers of the system.
|
|
||||||
def GetWirelessInterfaces() -- Get the wireless interfaces available.
|
|
||||||
class Interface() -- Control a network interface.
|
class Interface() -- Control a network interface.
|
||||||
class WiredInterface() -- Control a wired network interface.
|
class WiredInterface() -- Control a wired network interface.
|
||||||
class WirelessInterface() -- Control a wireless network interface.
|
class WirelessInterface() -- Control a wireless network interface.
|
||||||
@@ -31,9 +29,10 @@ class WirelessInterface() -- Control a wireless network interface.
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
import wicd.misc as misc
|
from wicd import misc
|
||||||
import wicd.wnettools as wnettools
|
from wicd import wnettools
|
||||||
import wicd.wpath as wpath
|
from wicd import wpath
|
||||||
|
from wicd.wnettools import *
|
||||||
|
|
||||||
import iwscan
|
import iwscan
|
||||||
import wpactrl
|
import wpactrl
|
||||||
@@ -82,29 +81,6 @@ SIOCGMIIPHY = 0x8947
|
|||||||
SIOCETHTOOL = 0x8946
|
SIOCETHTOOL = 0x8946
|
||||||
SIOCGIFFLAGS = 0x8913
|
SIOCGIFFLAGS = 0x8913
|
||||||
|
|
||||||
def SetDNS(*args, **kargs):
|
|
||||||
""" Call the wnettools SetDNS method. """
|
|
||||||
return wnettools.SetDNS(*args, **kargs)
|
|
||||||
|
|
||||||
def GetDefaultGateway(*args, **kargs):
|
|
||||||
""" Call the wnettools GetDefaultGateway method. """
|
|
||||||
return wnettools.GetDefaultGateway(*args, **kargs)
|
|
||||||
|
|
||||||
def StopDHCP(*args, **kargs):
|
|
||||||
""" Call the wnettools StopDHCP method. """
|
|
||||||
return wnettools.StopDHCP(*args, **kargs)
|
|
||||||
|
|
||||||
def GetWirelessInterfaces(*args, **kargs):
|
|
||||||
""" Call the wnettools GetWirelessInterfaces method. """
|
|
||||||
return wnettools.GetWirelessInterfaces(*args, **kargs)
|
|
||||||
|
|
||||||
def GetWiredInterfaces(*args, **kargs):
|
|
||||||
""" Call the wnettools GetWiredInterfaces method. """
|
|
||||||
return wnettools.GetWiredInterfaces(*args, **kargs)
|
|
||||||
|
|
||||||
def IsValidWpaSuppDriver(*args, **kargs):
|
|
||||||
""" Call the wnettools IsValidWpaSuppDrive method. """
|
|
||||||
return wnettools.IsValidWpaSuppDriver(*args, **kargs)
|
|
||||||
|
|
||||||
def get_iw_ioctl_result(iface, call):
|
def get_iw_ioctl_result(iface, call):
|
||||||
""" Makes the given ioctl call and returns the results.
|
""" Makes the given ioctl call and returns the results.
|
||||||
@@ -215,9 +191,9 @@ class WiredInterface(Interface, wnettools.BaseWiredInterface):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
if not self.iface: return False
|
||||||
if self.ETHTOOL_FOUND and self.link_detect != misc.MIITOOL:
|
if self.ethtool_cmd and self.link_detect != misc.MIITOOL:
|
||||||
return self._eth_get_plugged_in()
|
return self._eth_get_plugged_in()
|
||||||
elif self.MIITOOL_FOUND:
|
elif self.miitool_cmd:
|
||||||
return self._mii_get_plugged_in()
|
return self._mii_get_plugged_in()
|
||||||
else:
|
else:
|
||||||
print 'Error: No way of checking for a wired connection. Make \
|
print 'Error: No way of checking for a wired connection. Make \
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ from dbus import version as dbus_version
|
|||||||
from wicd import misc
|
from wicd import misc
|
||||||
from wicd import wpath
|
from wicd import wpath
|
||||||
from wicd import dbusmanager
|
from wicd import dbusmanager
|
||||||
|
from wicd import prefs
|
||||||
from wicd.misc import noneToString
|
from wicd.misc import noneToString
|
||||||
from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry
|
from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry
|
||||||
from wicd.prefs import PreferencesDialog
|
from wicd.prefs import PreferencesDialog
|
||||||
@@ -45,12 +46,6 @@ from wicd.guiutil import error, GreyLabel, LabelEntry, SmallLabel
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
wpath.chdir(__file__)
|
wpath.chdir(__file__)
|
||||||
|
|
||||||
try:
|
|
||||||
import pygtk
|
|
||||||
pygtk.require("2.0")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
proxy_obj = daemon = wireless = wired = bus = None
|
proxy_obj = daemon = wireless = wired = bus = None
|
||||||
language = misc.get_language_list_gui()
|
language = misc.get_language_list_gui()
|
||||||
DBUS_AVAIL = False
|
DBUS_AVAIL = False
|
||||||
@@ -71,6 +66,7 @@ def setup_dbus(force=True):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
prefs.setup_dbus()
|
||||||
bus = dbusmanager.get_bus()
|
bus = dbusmanager.get_bus()
|
||||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
||||||
daemon = dbus_ifaces['daemon']
|
daemon = dbus_ifaces['daemon']
|
||||||
|
|||||||
33
wicd/misc.py
33
wicd/misc.py
@@ -29,26 +29,40 @@ from commands import getoutput
|
|||||||
# wicd imports
|
# wicd imports
|
||||||
import wpath
|
import wpath
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# Connection state constants
|
||||||
wpath.chdir(__file__)
|
|
||||||
|
|
||||||
NOT_CONNECTED = 0
|
NOT_CONNECTED = 0
|
||||||
CONNECTING = 1
|
CONNECTING = 1
|
||||||
WIRELESS = 2
|
WIRELESS = 2
|
||||||
WIRED = 3
|
WIRED = 3
|
||||||
SUSPENDED = 4
|
SUSPENDED = 4
|
||||||
|
|
||||||
|
# Automatic app selection constant
|
||||||
AUTO = 0
|
AUTO = 0
|
||||||
|
|
||||||
|
# DHCP Clients
|
||||||
DHCLIENT = 1
|
DHCLIENT = 1
|
||||||
DHCPCD = 2
|
DHCPCD = 2
|
||||||
PUMP = 3
|
PUMP = 3
|
||||||
|
|
||||||
|
# Link detection tools
|
||||||
ETHTOOL = 1
|
ETHTOOL = 1
|
||||||
MIITOOL = 2
|
MIITOOL = 2
|
||||||
|
|
||||||
|
# Route flushing tools
|
||||||
IP = 1
|
IP = 1
|
||||||
ROUTE = 2
|
ROUTE = 2
|
||||||
|
|
||||||
|
# Graphical sudo apps
|
||||||
|
GKSUDO = 1
|
||||||
|
KDESU = 2
|
||||||
|
KTSUSS = 3
|
||||||
|
sudo_dict = {
|
||||||
|
AUTO : "",
|
||||||
|
GKSUDO : "gksudo",
|
||||||
|
KDESU : "kdesu",
|
||||||
|
KTSUSS: "ktsuss",
|
||||||
|
}
|
||||||
|
|
||||||
class WicdError(Exception):
|
class WicdError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -375,9 +389,9 @@ def detect_desktop_environment():
|
|||||||
pass
|
pass
|
||||||
return desktop_environment
|
return desktop_environment
|
||||||
|
|
||||||
def get_sudo_cmd(msg):
|
def get_sudo_cmd(msg, prog_num=0):
|
||||||
""" Returns a graphical sudo command for generic use. """
|
""" Returns a graphical sudo command for generic use. """
|
||||||
sudo_prog = choose_sudo_prog()
|
sudo_prog = choose_sudo_prog(prog_num)
|
||||||
if not sudo_prog: return None
|
if not sudo_prog: return None
|
||||||
if re.search("(ktsuss|gksu|gksudo)$", sudo_prog):
|
if re.search("(ktsuss|gksu|gksudo)$", sudo_prog):
|
||||||
msg_flag = "-m"
|
msg_flag = "-m"
|
||||||
@@ -385,8 +399,10 @@ def get_sudo_cmd(msg):
|
|||||||
msg_flag = "--caption"
|
msg_flag = "--caption"
|
||||||
return [sudo_prog, msg_flag, msg]
|
return [sudo_prog, msg_flag, msg]
|
||||||
|
|
||||||
def choose_sudo_prog():
|
def choose_sudo_prog(prog_num=0):
|
||||||
""" Try to intelligently decide which graphical sudo program to use. """
|
""" Try to intelligently decide which graphical sudo program to use. """
|
||||||
|
if prog_num:
|
||||||
|
return find_path(sudo_dict[prog_num])
|
||||||
desktop_env = detect_desktop_environment()
|
desktop_env = detect_desktop_environment()
|
||||||
env_path = os.environ['PATH'].split(":")
|
env_path = os.environ['PATH'].split(":")
|
||||||
|
|
||||||
@@ -412,7 +428,10 @@ def find_path(cmd):
|
|||||||
the file can not be found.
|
the file can not be found.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
paths = os.getenv("PATH", default="/usr/bin:/usr/local/bin").split(':')
|
paths = os.getenv("PATH").split(':')
|
||||||
|
if not paths:
|
||||||
|
paths = ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin",
|
||||||
|
"/sbin", "/bin"]
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if os.path.exists(os.path.join(path, cmd)):
|
if os.path.exists(os.path.join(path, cmd)):
|
||||||
return os.path.join(path, cmd)
|
return os.path.join(path, cmd)
|
||||||
|
|||||||
@@ -275,8 +275,9 @@ class ConnectionStatus(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Some checks to keep reconnect retries from going crazy.
|
# Some checks to keep reconnect retries from going crazy.
|
||||||
if self.reconnect_tries > 2 and \
|
if (self.reconnect_tries > 3 and
|
||||||
(time.time() - self.last_reconnect_time) < 300:
|
(time.time() - self.last_reconnect_time) < 200):
|
||||||
|
print "Throttling autoreconnect"
|
||||||
return
|
return
|
||||||
|
|
||||||
self.reconnecting = True
|
self.reconnecting = True
|
||||||
|
|||||||
@@ -237,7 +237,8 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
|||||||
profile = self.prof_name
|
profile = self.prof_name
|
||||||
cmdend = [os.path.join(wpath.lib, "configscript.py"), profile, "wired"]
|
cmdend = [os.path.join(wpath.lib, "configscript.py"), profile, "wired"]
|
||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'])
|
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'],
|
||||||
|
prog_num=daemon.GetSudoApp())
|
||||||
if not cmdbase:
|
if not cmdbase:
|
||||||
error(None, language["no_sudo_prog"])
|
error(None, language["no_sudo_prog"])
|
||||||
return
|
return
|
||||||
@@ -336,7 +337,8 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
cmdend = [os.path.join(wpath.lib, "configscript.py"),
|
cmdend = [os.path.join(wpath.lib, "configscript.py"),
|
||||||
str(self.networkID), "wireless"]
|
str(self.networkID), "wireless"]
|
||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'])
|
cmdbase = misc.get_sudo_cmd(language['scripts_need_pass'],
|
||||||
|
prog_num=daemon.GetSudoApp())
|
||||||
if not cmdbase:
|
if not cmdbase:
|
||||||
error(None, language["no_sudo_prog"])
|
error(None, language["no_sudo_prog"])
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -105,10 +105,34 @@ def get_backend_description_dict():
|
|||||||
if be:
|
if be:
|
||||||
d[be] = get_backend_description(be)
|
d[be] = get_backend_description(be)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def expand_script_macros(script, msg, bssid, essid):
|
||||||
|
"""Expands any supported macros in a script.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
script -- the script to execute.
|
||||||
|
msg -- the name of the script, %{script} will be expanded to this.
|
||||||
|
bssid -- the bssid of the network we connect to, defaults to 'wired'.
|
||||||
|
essid -- the essid of the network we connect to, defaults to 'wired'."""
|
||||||
|
def repl(match):
|
||||||
|
macro = match.group(1).lower()
|
||||||
|
if macro_dict.has_key(macro):
|
||||||
|
return macro_dict[macro]
|
||||||
|
print 'Warning: found illegal macro %s in %s script' % (macro, msg)
|
||||||
|
return match.group()
|
||||||
|
|
||||||
|
macro_dict = { 'script' : msg,
|
||||||
|
'bssid' : bssid,
|
||||||
|
'essid' : essid }
|
||||||
|
regex = re.compile(r'%\{([a-zA-Z0-9]+)\}')
|
||||||
|
expanded = regex.sub(repl, script)
|
||||||
|
print "Expanded '%s' to '%s'" % (script, expanded)
|
||||||
|
return expanded
|
||||||
|
|
||||||
|
|
||||||
class Controller(object):
|
class Controller(object):
|
||||||
""" Parent class for the different interface types. """
|
""" Parent class for the different interface types. """
|
||||||
def __init__(self):
|
def __init__(self, debug=False):
|
||||||
""" Initialise the class. """
|
""" Initialise the class. """
|
||||||
self.global_dns_1 = None
|
self.global_dns_1 = None
|
||||||
self.global_dns_2 = None
|
self.global_dns_2 = None
|
||||||
@@ -117,7 +141,7 @@ class Controller(object):
|
|||||||
self.global_search_dom = None
|
self.global_search_dom = None
|
||||||
self._dhcp_client = None
|
self._dhcp_client = None
|
||||||
self._flush_tool = None
|
self._flush_tool = None
|
||||||
self._debug = None
|
self._debug = debug
|
||||||
self._backend = None
|
self._backend = None
|
||||||
self.connecting_thread = None
|
self.connecting_thread = None
|
||||||
self.before_script = None
|
self.before_script = None
|
||||||
@@ -138,8 +162,6 @@ class Controller(object):
|
|||||||
self._dhcp_client = value
|
self._dhcp_client = value
|
||||||
if self.iface:
|
if self.iface:
|
||||||
self.iface.DHCP_CLIENT = value
|
self.iface.DHCP_CLIENT = value
|
||||||
self.iface.CheckDHCP()
|
|
||||||
|
|
||||||
def get_dhcp_client(self): return self._dhcp_client
|
def get_dhcp_client(self): return self._dhcp_client
|
||||||
dhcp_client = property(get_dhcp_client, set_dhcp_client)
|
dhcp_client = property(get_dhcp_client, set_dhcp_client)
|
||||||
|
|
||||||
@@ -166,6 +188,7 @@ class Controller(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def StopDHCP(self):
|
def StopDHCP(self):
|
||||||
|
""" Stops all running DHCP clients. """
|
||||||
return BACKEND.StopDHCP()
|
return BACKEND.StopDHCP()
|
||||||
|
|
||||||
def GetIP(self, ifconfig=""):
|
def GetIP(self, ifconfig=""):
|
||||||
@@ -214,32 +237,11 @@ class Controller(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
return self.iface.Down()
|
return self.iface.Down()
|
||||||
|
|
||||||
def expand_script_macros(script, msg, bssid, essid):
|
|
||||||
"""Expands any supported macros in a script.
|
|
||||||
|
|
||||||
Keyword arguments:
|
|
||||||
script -- the script to execute.
|
|
||||||
msg -- the name of the script, %{script} will be expanded to this.
|
|
||||||
bssid -- the bssid of the network we connect to, defaults to 'wired'.
|
|
||||||
essid -- the essid of the network we connect to, defaults to 'wired'."""
|
|
||||||
|
|
||||||
macro_dict = { 'script' : msg,
|
|
||||||
'bssid' : bssid,
|
|
||||||
'essid' : essid }
|
|
||||||
|
|
||||||
# Define a replacement function, this is done here so that %{script} will be substituted correctly
|
def AppAvailable(self, app):
|
||||||
def repl(match):
|
""" Determine if the given application is installed. """
|
||||||
macro = match.group( 1 ).lower()
|
return self.iface.AppAvailable(app)
|
||||||
if macro_dict.has_key( macro ):
|
|
||||||
return macro_dict[macro]
|
|
||||||
print 'Warning: found illegal macro %s in %s script' % (macro, msg)
|
|
||||||
return match.group()
|
|
||||||
|
|
||||||
regex = re.compile( r'%\{([a-zA-Z0-9]+)\}' )
|
|
||||||
expanded = regex.sub( repl, script )
|
|
||||||
print "Expanded '%s' to '%s'" % (script, expanded)
|
|
||||||
return expanded
|
|
||||||
|
|
||||||
class ConnectThread(threading.Thread):
|
class ConnectThread(threading.Thread):
|
||||||
""" A class to perform network connections in a multi-threaded way.
|
""" A class to perform network connections in a multi-threaded way.
|
||||||
@@ -475,9 +477,9 @@ class ConnectThread(threading.Thread):
|
|||||||
class Wireless(Controller):
|
class Wireless(Controller):
|
||||||
""" A wrapper for common wireless interface functions. """
|
""" A wrapper for common wireless interface functions. """
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, debug=False):
|
||||||
""" Initialize the class. """
|
""" Initialize the class. """
|
||||||
Controller.__init__(self)
|
Controller.__init__(self, debug=debug)
|
||||||
self._wpa_driver = None
|
self._wpa_driver = None
|
||||||
self._wireless_interface = None
|
self._wireless_interface = None
|
||||||
self.wiface = None
|
self.wiface = None
|
||||||
@@ -666,7 +668,11 @@ class Wireless(Controller):
|
|||||||
The first available wireless interface.
|
The first available wireless interface.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return BACKEND.GetWirelessInterfaces()
|
ifaces = BACKEND.GetWirelessInterfaces()
|
||||||
|
if ifaces:
|
||||||
|
return ifaces[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def GetKillSwitchStatus(self):
|
def GetKillSwitchStatus(self):
|
||||||
""" Get the current status of the Killswitch.
|
""" Get the current status of the Killswitch.
|
||||||
@@ -838,9 +844,9 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
class Wired(Controller):
|
class Wired(Controller):
|
||||||
""" A wrapper for common wired interface functions. """
|
""" A wrapper for common wired interface functions. """
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, debug=False):
|
||||||
""" Initialise the class. """
|
""" Initialise the class. """
|
||||||
Controller.__init__(self)
|
Controller.__init__(self, debug=debug)
|
||||||
self.wpa_driver = None
|
self.wpa_driver = None
|
||||||
self._link_detect = None
|
self._link_detect = None
|
||||||
self._wired_interface = None
|
self._wired_interface = None
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import gtk.glade
|
|||||||
|
|
||||||
from wicd import misc
|
from wicd import misc
|
||||||
from wicd import wpath
|
from wicd import wpath
|
||||||
|
from wicd import dbusmanager
|
||||||
from wicd.misc import checkboxTextboxToggle, noneToBlankString
|
from wicd.misc import checkboxTextboxToggle, noneToBlankString
|
||||||
|
|
||||||
daemon = None
|
daemon = None
|
||||||
@@ -40,17 +41,37 @@ wired = None
|
|||||||
|
|
||||||
language = misc.get_language_list_gui()
|
language = misc.get_language_list_gui()
|
||||||
|
|
||||||
|
def setup_dbus():
|
||||||
|
global daemon, wireless, wired
|
||||||
|
daemon = dbusmanager.get_interface('daemon')
|
||||||
|
wireless = dbusmanager.get_interface('wireless')
|
||||||
|
wired = dbusmanager.get_interface('wired')
|
||||||
|
|
||||||
class PreferencesDialog(object):
|
class PreferencesDialog(object):
|
||||||
""" Class for handling the wicd preferences dialog window. """
|
""" Class for handling the wicd preferences dialog window. """
|
||||||
def __init__(self, wTree, dbus):
|
def __init__(self, wTree, dbus):
|
||||||
global daemon, wireless, wired
|
setup_dbus()
|
||||||
daemon = dbus['daemon']
|
|
||||||
wireless = dbus['wireless']
|
|
||||||
wired = dbus['wired']
|
|
||||||
self.wTree = wTree
|
self.wTree = wTree
|
||||||
self.prep_settings_diag()
|
self.prep_settings_diag()
|
||||||
self.load_preferences_diag()
|
self.load_preferences_diag()
|
||||||
|
|
||||||
|
def _setup_external_app_radios(self, radio_list, get_method, set_method):
|
||||||
|
""" Generic function for setting up external app radios. """
|
||||||
|
def set_available(apps):
|
||||||
|
for app in apps:
|
||||||
|
app.set_sensitive(daemon.GetAppAvailable(app.get_label()))
|
||||||
|
|
||||||
|
# Disable radios for apps that aren't installed.
|
||||||
|
set_available(radio_list[1:])
|
||||||
|
selected_app = get_method()
|
||||||
|
# Make sure the app we want to select is actually available.
|
||||||
|
if radio_list[selected_app].get_property("sensitive"):
|
||||||
|
radio_list[selected_app].set_active(True)
|
||||||
|
else:
|
||||||
|
# If it isn't, default to Automatic.
|
||||||
|
set_method(misc.AUTO)
|
||||||
|
radio_list[misc.AUTO].set_active(True)
|
||||||
|
|
||||||
def load_preferences_diag(self):
|
def load_preferences_diag(self):
|
||||||
""" Loads data into the preferences Dialog. """
|
""" Loads data into the preferences Dialog. """
|
||||||
|
|
||||||
@@ -62,19 +83,24 @@ class PreferencesDialog(object):
|
|||||||
|
|
||||||
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
dhcp_list = [self.dhcpautoradio, self.dhclientradio, self.dhcpcdradio,
|
||||||
self.pumpradio]
|
self.pumpradio]
|
||||||
dhcp_method = daemon.GetDHCPClient()
|
self._setup_external_app_radios(dhcp_list, daemon.GetDHCPClient,
|
||||||
print 'DHCP method is %s' % daemon.GetDHCPClient()
|
daemon.SetDHCPClient)
|
||||||
dhcp_list[dhcp_method].set_active(True)
|
|
||||||
|
|
||||||
wired_link_list = [self.linkautoradio, self.ethtoolradio,
|
wired_link_list = [self.linkautoradio, self.ethtoolradio,
|
||||||
self.miitoolradio]
|
self.miitoolradio]
|
||||||
wired_link_method = daemon.GetLinkDetectionTool()
|
self._setup_external_app_radios(wired_link_list,
|
||||||
wired_link_list[wired_link_method].set_active(True)
|
daemon.GetLinkDetectionTool,
|
||||||
|
daemon.SetLinkDetectionTool)
|
||||||
|
|
||||||
flush_list = [self.flushautoradio, self.ipflushradio,
|
flush_list = [self.flushautoradio, self.ipflushradio,
|
||||||
self.routeflushradio]
|
self.routeflushradio]
|
||||||
flush_method = daemon.GetFlushTool()
|
self._setup_external_app_radios(flush_list, daemon.GetFlushTool,
|
||||||
flush_list[flush_method].set_active(True)
|
daemon.SetFlushTool)
|
||||||
|
|
||||||
|
sudo_list = [self.sudoautoradio, self.gksudoradio, self.kdesuradio,
|
||||||
|
self.ktsussradio]
|
||||||
|
self._setup_external_app_radios(sudo_list, daemon.GetSudoApp,
|
||||||
|
daemon.SetAudoApp)
|
||||||
|
|
||||||
auto_conn_meth = daemon.GetWiredAutoConnectMethod()
|
auto_conn_meth = daemon.GetWiredAutoConnectMethod()
|
||||||
if auto_conn_meth == 1:
|
if auto_conn_meth == 1:
|
||||||
@@ -185,6 +211,16 @@ class PreferencesDialog(object):
|
|||||||
else:
|
else:
|
||||||
flush_tool = misc.ROUTE
|
flush_tool = misc.ROUTE
|
||||||
daemon.SetFlushTool(flush_tool)
|
daemon.SetFlushTool(flush_tool)
|
||||||
|
|
||||||
|
if self.sudoautoradio.get_active():
|
||||||
|
sudo_tool = misc.AUTO
|
||||||
|
elif self.gksudoradio.get_active():
|
||||||
|
sudo_tool = misc.GKSUDO
|
||||||
|
elif self.kdesuradio.get_active():
|
||||||
|
sudo_tool = misc.KDESU
|
||||||
|
else:
|
||||||
|
sudo_tool = misc.KTSUSS
|
||||||
|
daemon.SetSudoApp(sudo_tool)
|
||||||
|
|
||||||
[width, height] = self.dialog.get_size()
|
[width, height] = self.dialog.get_size()
|
||||||
daemon.WriteWindowSize(width, height, "pref")
|
daemon.WriteWindowSize(width, height, "pref")
|
||||||
@@ -289,6 +325,12 @@ class PreferencesDialog(object):
|
|||||||
'wicd_auto_config')
|
'wicd_auto_config')
|
||||||
self.ipflushradio = setup_label("ip_flush_radio")
|
self.ipflushradio = setup_label("ip_flush_radio")
|
||||||
self.routeflushradio = setup_label("route_flush_radio")
|
self.routeflushradio = setup_label("route_flush_radio")
|
||||||
|
|
||||||
|
# Graphical Sudo Apps
|
||||||
|
self.sudoautoradio = setup_label("sudo_auto_radio", "wicd_auto_config")
|
||||||
|
self.gksudoradio = setup_label("gksudo_radio")
|
||||||
|
self.kdesuradio = setup_label("kdesu_radio")
|
||||||
|
self.ktsussradio = setup_label("ktsuss_radio")
|
||||||
|
|
||||||
# Replacement for the combo box hack
|
# Replacement for the combo box hack
|
||||||
self.wpadrivercombo = build_combobox("pref_wpa_combobox")
|
self.wpadrivercombo = build_combobox("pref_wpa_combobox")
|
||||||
@@ -317,11 +359,10 @@ class PreferencesDialog(object):
|
|||||||
# Load backend combobox
|
# Load backend combobox
|
||||||
self.backends = daemon.GetBackendList()
|
self.backends = daemon.GetBackendList()
|
||||||
self.be_descriptions = daemon.GetBackendDescriptionDict()
|
self.be_descriptions = daemon.GetBackendDescriptionDict()
|
||||||
# "" is included as a hack for DBus limitations, so we remove it.
|
|
||||||
self.backends.remove("")
|
|
||||||
|
|
||||||
for x in self.backends:
|
for x in self.backends:
|
||||||
self.backendcombo.append_text(x)
|
if x:
|
||||||
|
self.backendcombo.append_text(x)
|
||||||
|
|
||||||
def be_combo_changed(self, combo):
|
def be_combo_changed(self, combo):
|
||||||
""" Update the description label for the given backend. """
|
""" Update the description label for the given backend. """
|
||||||
|
|||||||
@@ -79,10 +79,11 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
""" Initializes the daemon DBus object. """
|
""" Initializes the daemon DBus object. """
|
||||||
dbus.service.Object.__init__(self, bus_name=bus_name,
|
dbus.service.Object.__init__(self, bus_name=bus_name,
|
||||||
object_path=object_path)
|
object_path=object_path)
|
||||||
self.wifi = networking.Wireless()
|
|
||||||
self.wired = networking.Wired()
|
|
||||||
self.config = ConfigManager(os.path.join(wpath.etc,
|
self.config = ConfigManager(os.path.join(wpath.etc,
|
||||||
"manager-settings.conf"))
|
"manager-settings.conf"))
|
||||||
|
self._debug_mode = bool(self.config.get("Settings", "debug_mode"))
|
||||||
|
self.wifi = networking.Wireless(debug=self._debug_mode)
|
||||||
|
self.wired = networking.Wired(debug=self._debug_mode)
|
||||||
self.wired_bus= WiredDaemon(bus_name, self, wired=self.wired)
|
self.wired_bus= WiredDaemon(bus_name, self, wired=self.wired)
|
||||||
self.wireless_bus = WirelessDaemon(bus_name, self, wifi=self.wifi)
|
self.wireless_bus = WirelessDaemon(bus_name, self, wifi=self.wifi)
|
||||||
self.forced_disconnect = False
|
self.forced_disconnect = False
|
||||||
@@ -99,6 +100,7 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
self.dhcp_client = 0
|
self.dhcp_client = 0
|
||||||
self.link_detect_tool = 0
|
self.link_detect_tool = 0
|
||||||
self.flush_tool = 0
|
self.flush_tool = 0
|
||||||
|
self.sudo_app = 0
|
||||||
|
|
||||||
# This will speed up the scanning process - if a client doesn't
|
# This will speed up the scanning process - if a client doesn't
|
||||||
# need a fresh scan, just feed them the old one. A fresh scan
|
# need a fresh scan, just feed them the old one. A fresh scan
|
||||||
@@ -273,8 +275,8 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
""" Sets if debugging mode is on or off. """
|
""" Sets if debugging mode is on or off. """
|
||||||
self.config.set("Settings", "debug_mode", debug, write=True)
|
self.config.set("Settings", "debug_mode", debug, write=True)
|
||||||
self.debug_mode = misc.to_bool(debug)
|
self.debug_mode = misc.to_bool(debug)
|
||||||
self.wifi.debug = self.debug_mode
|
self.wifi.debug = debug
|
||||||
self.wired.debug = self.debug_mode
|
self.wired.debug = debug
|
||||||
self.wireless_bus.debug_mode = debug
|
self.wireless_bus.debug_mode = debug
|
||||||
self.wired_bus.debug_mode = debug
|
self.wired_bus.debug_mode = debug
|
||||||
|
|
||||||
@@ -569,6 +571,11 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
return bool(self.need_profile_chooser)
|
return bool(self.need_profile_chooser)
|
||||||
|
|
||||||
|
@dbus.service.method("org.wicd.daemon")
|
||||||
|
def GetAppAvailable(self, app):
|
||||||
|
""" Determine if a given application is available."""
|
||||||
|
return bool(self.wifi.AppAvailable(app) or self.wired.AppAvailable(app))
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetDHCPClient(self):
|
def GetDHCPClient(self):
|
||||||
@@ -630,6 +637,17 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
self.wired.flush_tool = int(flush_tool)
|
self.wired.flush_tool = int(flush_tool)
|
||||||
self.wifi.flush_tool = int(flush_tool)
|
self.wifi.flush_tool = int(flush_tool)
|
||||||
self.config.set("Settings", "flush_tool", flush_tool, write=True)
|
self.config.set("Settings", "flush_tool", flush_tool, write=True)
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon')
|
||||||
|
def GetSudoApp(self):
|
||||||
|
""" Get the preferred sudo app. """
|
||||||
|
return self.sudo_app
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon')
|
||||||
|
def SetSudoApp(self, sudo_app):
|
||||||
|
""" Set the preferred sudo app. """
|
||||||
|
self.sudo_app = sudo_app
|
||||||
|
self.config.set("Settings", "sudo_app", sudo_app, write=True)
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def WriteWindowSize(self, width, height, win_name):
|
def WriteWindowSize(self, width, height, win_name):
|
||||||
@@ -814,7 +832,6 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
b_wired = self.wired_bus
|
b_wired = self.wired_bus
|
||||||
b_wifi = self.wireless_bus
|
b_wifi = self.wireless_bus
|
||||||
app_conf= self.config
|
app_conf= self.config
|
||||||
verbose = True
|
|
||||||
# Load the backend.
|
# Load the backend.
|
||||||
be_def = 'external'
|
be_def = 'external'
|
||||||
self.SetBackend(app_conf.get("Settings", "backend", default=be_def))
|
self.SetBackend(app_conf.get("Settings", "backend", default=be_def))
|
||||||
@@ -845,15 +862,16 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
default=True))
|
default=True))
|
||||||
self.SetDebugMode(app_conf.get("Settings", "debug_mode", default=False))
|
self.SetDebugMode(app_conf.get("Settings", "debug_mode", default=False))
|
||||||
self.SetWiredAutoConnectMethod(app_conf.get("Settings",
|
self.SetWiredAutoConnectMethod(app_conf.get("Settings",
|
||||||
"wired_connect_mode",
|
"wired_connect_mode",
|
||||||
default=1))
|
default=1))
|
||||||
self.SetSignalDisplayType(app_conf.get("Settings",
|
self.SetSignalDisplayType(app_conf.get("Settings",
|
||||||
"signal_display_type",
|
"signal_display_type",
|
||||||
default=0))
|
default=0))
|
||||||
self.SetDHCPClient(app_conf.get("Settings", "dhcp_client", default=0))
|
self.SetDHCPClient(app_conf.get("Settings", "dhcp_client", default=0))
|
||||||
self.SetLinkDetectionTool(app_conf.get("Settings", "link_detect_tool",
|
self.SetLinkDetectionTool(app_conf.get("Settings", "link_detect_tool",
|
||||||
default=0))
|
default=0))
|
||||||
self.SetFlushTool(app_conf.get("Settings", "flush_tool", default=0))
|
self.SetFlushTool(app_conf.get("Settings", "flush_tool", default=0))
|
||||||
|
self.SetSudoApp(app_conf.get("Settings", "sudo_app", default=0))
|
||||||
self.SetPreferWiredNetwork(app_conf.get("Settings", "prefer_wired",
|
self.SetPreferWiredNetwork(app_conf.get("Settings", "prefer_wired",
|
||||||
default=False))
|
default=False))
|
||||||
app_conf.write()
|
app_conf.write()
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ from string import maketrans, translate
|
|||||||
|
|
||||||
import wpath
|
import wpath
|
||||||
import misc
|
import misc
|
||||||
|
from misc import find_path
|
||||||
|
|
||||||
RALINK_DRIVER = 'ralink legacy'
|
RALINK_DRIVER = 'ralink legacy'
|
||||||
|
|
||||||
@@ -46,6 +47,9 @@ blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ '
|
|||||||
blacklist_norm = ";`$!*|><&\\"
|
blacklist_norm = ";`$!*|><&\\"
|
||||||
blank_trans = maketrans("", "")
|
blank_trans = maketrans("", "")
|
||||||
|
|
||||||
|
__all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces", "StopDHCP",
|
||||||
|
"GetWirelessInterfaces", "IsValidWpaSuppDriver", "NeedsExternalCalls"]
|
||||||
|
|
||||||
def _sanitize_string(string):
|
def _sanitize_string(string):
|
||||||
if string:
|
if string:
|
||||||
return translate(str(string), blank_trans, blacklist_norm)
|
return translate(str(string), blank_trans, blacklist_norm)
|
||||||
@@ -123,7 +127,7 @@ def GetWirelessInterfaces():
|
|||||||
ifnames = [iface for iface in os.listdir(dev_dir) if os.path.isdir(dev_dir + iface)
|
ifnames = [iface for iface in os.listdir(dev_dir) if os.path.isdir(dev_dir + iface)
|
||||||
and 'wireless' in os.listdir(dev_dir + iface)]
|
and 'wireless' in os.listdir(dev_dir + iface)]
|
||||||
|
|
||||||
return bool(ifnames) and ifnames[0] or None
|
return ifnames
|
||||||
|
|
||||||
def GetWiredInterfaces():
|
def GetWiredInterfaces():
|
||||||
""" Returns a list of wired interfaces on the system. """
|
""" Returns a list of wired interfaces on the system. """
|
||||||
@@ -160,11 +164,6 @@ class BaseInterface(object):
|
|||||||
self.iface = _sanitize_string_strict(iface)
|
self.iface = _sanitize_string_strict(iface)
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.DHCP_CLIENT = None
|
self.DHCP_CLIENT = None
|
||||||
self.DHCP_CMD = None
|
|
||||||
self.DHCP_RELEASE = None
|
|
||||||
self.MIITOOL_FOUND = False
|
|
||||||
self.ETHTOOL_FOUND = False
|
|
||||||
self.IP_FOUND = False
|
|
||||||
self.flush_tool = None
|
self.flush_tool = None
|
||||||
self.link_detect = None
|
self.link_detect = None
|
||||||
|
|
||||||
@@ -181,29 +180,94 @@ class BaseInterface(object):
|
|||||||
"""
|
"""
|
||||||
self.iface = _sanitize_string_strict(str(iface))
|
self.iface = _sanitize_string_strict(str(iface))
|
||||||
|
|
||||||
def _find_client_path(self, client):
|
def _find_program_path(self, program):
|
||||||
""" Determines the full path for the given program.
|
""" Determines the full path for the given program.
|
||||||
|
|
||||||
Searches a hardcoded list of paths for a given program name.
|
Searches for a given program name on the PATH.
|
||||||
|
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
client -- The name of the program to search for
|
program -- The name of the program to search for
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The full path of the program or None
|
The full path of the program or None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/',
|
path = find_path(program)
|
||||||
'/usr/local/sbin/', '/usr/local/bin/']
|
if not path and self.verbose:
|
||||||
for path in paths:
|
print "WARNING: No path found for %s" % program
|
||||||
if os.path.exists("%s%s" % (path, client)):
|
return path
|
||||||
return "%s%s" % (path, client)
|
|
||||||
if self.verbose:
|
|
||||||
print "WARNING: No path found for %s" % (client)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
|
def _get_dhcp_command(self, flavor=None):
|
||||||
|
""" Returns the correct DHCP client command.
|
||||||
|
|
||||||
|
Given a type of DHCP request (create or release a lease),
|
||||||
|
this method will build a command to complete the request
|
||||||
|
using the correct dhcp client, and cli options.
|
||||||
|
|
||||||
|
"""
|
||||||
|
def get_client_name(cl):
|
||||||
|
""" Converts the integer value for a dhcp client to a string. """
|
||||||
|
if (cl in [misc.DHCLIENT, "dhclient"] or
|
||||||
|
(cl == misc.AUTO and self.dhclient_cmd)):
|
||||||
|
client = "dhclient"
|
||||||
|
cmd = self.dhclient_cmd
|
||||||
|
elif (cl in [misc.DHCPCD, "dhcpcd"] or
|
||||||
|
(cl == misc.AUTO and self.dhcpcd_cmd)):
|
||||||
|
client = "dhcpcd"
|
||||||
|
cmd = self.dhcpcd_cmd
|
||||||
|
elif (cl in [misc.PUMP, "pump"] or
|
||||||
|
(cl == misc.AUTO and self.pump_cmd)):
|
||||||
|
client = "pump"
|
||||||
|
cmd = self.pump_cmd
|
||||||
|
else:
|
||||||
|
client = None
|
||||||
|
cmd = ""
|
||||||
|
return (client, cmd)
|
||||||
|
|
||||||
|
connect_dict = {
|
||||||
|
"dhclient" : r"%s %s",
|
||||||
|
"pump" : r"%s -i %s",
|
||||||
|
"dhcpcd" : r"%s %s",
|
||||||
|
}
|
||||||
|
release_dict = {
|
||||||
|
"dhclient" : r"%s -r %s",
|
||||||
|
"pump" : r"%s -r -i %s",
|
||||||
|
"dhcpcd" : r"%s -k %s",
|
||||||
|
}
|
||||||
|
(client_name, cmd) = get_client_name(self.DHCP_CLIENT)
|
||||||
|
if not client_name or not cmd:
|
||||||
|
print "WARNING: Failed to find a valid dhcp client!"
|
||||||
|
return ""
|
||||||
|
|
||||||
|
if flavor == "connect":
|
||||||
|
return connect_dict[client_name] % (cmd, self.iface)
|
||||||
|
elif flavor == "release":
|
||||||
|
return release_dict[client_name] % (cmd, self.iface)
|
||||||
|
else:
|
||||||
|
return str(cmd)
|
||||||
|
|
||||||
|
def AppAvailable(self, app):
|
||||||
|
""" Return whether a given app is available.
|
||||||
|
|
||||||
|
Given the name of an executable, determines if it is
|
||||||
|
available for use by checking for a defined 'app'_cmd
|
||||||
|
instance variable.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return bool(self.__dict__.get("%s_cmd" % app.replace("-", "")))
|
||||||
|
|
||||||
|
def Check(self):
|
||||||
|
""" Check that all required tools are available. """
|
||||||
|
# THINGS TO CHECK FOR: ethtool, pptp-linux, dhclient, host
|
||||||
|
self.CheckDHCP()
|
||||||
|
self.CheckWiredTools()
|
||||||
|
self.CheckWirelessTools()
|
||||||
|
self.CheckSudoApplications()
|
||||||
|
self.CheckRouteFlushTool()
|
||||||
|
|
||||||
def CheckDHCP(self):
|
def CheckDHCP(self):
|
||||||
""" Check for a valid DHCP client.
|
""" Check for the existence of valid DHCP clients.
|
||||||
|
|
||||||
Checks for the existence of a supported 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
|
found, the appropriate values for DHCP_CMD, DHCP_RELEASE, and
|
||||||
@@ -211,97 +275,30 @@ class BaseInterface(object):
|
|||||||
warning is printed.
|
warning is printed.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def get_client_name(cl):
|
self.dhclient_cmd = self._find_program_path("dhclient")
|
||||||
""" Converts the integer value for a dhcp client to a string. """
|
self.dhcpcd_cmd = self._find_program_path("dhcpcd")
|
||||||
if cl in [misc.DHCLIENT, "dhclient"]:
|
self.pump_cmd = self._find_program_path("pump")
|
||||||
client = "dhclient"
|
|
||||||
elif cl in [misc.DHCPCD, "dhcpcd"]:
|
|
||||||
client = "dhcpcd"
|
|
||||||
else:
|
|
||||||
client = "pump"
|
|
||||||
return client
|
|
||||||
|
|
||||||
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"]
|
|
||||||
for client in dhcpclients:
|
|
||||||
dhcp_path = self._find_client_path(client)
|
|
||||||
if dhcp_path:
|
|
||||||
dhcp_client = client
|
|
||||||
break
|
|
||||||
|
|
||||||
if not dhcp_client:
|
|
||||||
print "WARNING: No supported DHCP Client could be found!"
|
|
||||||
return
|
|
||||||
elif dhcp_client in [misc.DHCLIENT, "dhclient"]:
|
|
||||||
dhcp_client = misc.DHCLIENT
|
|
||||||
dhcp_cmd = dhcp_path
|
|
||||||
dhcp_release = dhcp_cmd + " -r"
|
|
||||||
elif dhcp_client in [misc.PUMP, "pump"]:
|
|
||||||
dhcp_client = misc.PUMP
|
|
||||||
dhcp_cmd = dhcp_path + " -i"
|
|
||||||
dhcp_release = dhcp_cmd + " -r -i"
|
|
||||||
elif dhcp_client in [misc.DHCPCD, "dhcpcd"]:
|
|
||||||
dhcp_client = misc.DHCPCD
|
|
||||||
dhcp_cmd = dhcp_path
|
|
||||||
dhcp_release = dhcp_cmd + " -k"
|
|
||||||
else:
|
|
||||||
dhcp_client = None
|
|
||||||
dhcp_cmd = None
|
|
||||||
dhcp_release = None
|
|
||||||
|
|
||||||
self.DHCP_CMD = dhcp_cmd
|
|
||||||
self.DHCP_RELEASE = dhcp_release
|
|
||||||
self.DHCP_CLIENT = dhcp_client
|
|
||||||
|
|
||||||
def CheckWiredTools(self):
|
def CheckWiredTools(self):
|
||||||
""" Check for the existence of ethtool and mii-tool. """
|
""" Check for the existence of ethtool and mii-tool. """
|
||||||
miitool_path = self._find_client_path("mii-tool")
|
self.miitool_cmd = self._find_program_path("mii-tool")
|
||||||
if miitool_path:
|
self.ethtool_cmd = self._find_program_path("ethtool")
|
||||||
self.miitool_cmd = miitool_path
|
|
||||||
self.MIITOOL_FOUND = True
|
|
||||||
else:
|
|
||||||
self.miitool_cmd = None
|
|
||||||
self.MIITOOL_FOUND = False
|
|
||||||
|
|
||||||
ethtool_path = self._find_client_path("ethtool")
|
|
||||||
if ethtool_path:
|
|
||||||
self.ethtool_cmd = ethtool_path
|
|
||||||
self.ETHTOOL_FOUND = True
|
|
||||||
else:
|
|
||||||
self.ethtool_cmd = None
|
|
||||||
self.ETHTOOL_FOUND = False
|
|
||||||
|
|
||||||
def CheckWirelessTools(self):
|
def CheckWirelessTools(self):
|
||||||
""" Check for the existence of wpa_cli """
|
""" Check for the existence of wpa_cli """
|
||||||
wpa_cli_path = self._find_client_path("wpa_cli")
|
self.wpa_cli_cmd = self._find_program_path("wpa_cli")
|
||||||
if wpa_cli_path:
|
if not self.wpa_cli_cmd:
|
||||||
self.WPA_CLI_FOUND = True
|
|
||||||
else:
|
|
||||||
self.WPA_CLI_FOUND = False
|
|
||||||
print "wpa_cli not found. Authentication will not be validated."
|
print "wpa_cli not found. Authentication will not be validated."
|
||||||
|
|
||||||
def Check(self):
|
def CheckRouteFlushTool(self):
|
||||||
""" Check that all required tools are available. """
|
""" Check for a route flush tool. """
|
||||||
# THINGS TO CHECK FOR: ethtool, pptp-linux, dhclient, host
|
self.ip_cmd = self._find_program_path("ip")
|
||||||
self.CheckDHCP()
|
self.route_cmd = self._find_program_path("route")
|
||||||
self.CheckWiredTools()
|
|
||||||
self.CheckWirelessTools()
|
def CheckSudoApplications(self):
|
||||||
|
self.gksudo_cmd = self._find_program_path("gksudo")
|
||||||
ip_path = self._find_client_path("ip")
|
self.kdesu_cmd = self._find_program_path("kdesu")
|
||||||
if ip_path:
|
self.ktsuss_cmd = self._find_program_path("ktsuss")
|
||||||
self.ip_cmd = ip_path
|
|
||||||
self.IP_FOUND = True
|
|
||||||
else:
|
|
||||||
self.ip_cmd = None
|
|
||||||
self.IP_FOUND = False
|
|
||||||
|
|
||||||
def Up(self):
|
def Up(self):
|
||||||
""" Bring the network interface up.
|
""" Bring the network interface up.
|
||||||
@@ -461,7 +458,8 @@ class BaseInterface(object):
|
|||||||
"""
|
"""
|
||||||
if not self.iface: return False
|
if not self.iface: return False
|
||||||
|
|
||||||
cmd = self.DHCP_CMD + " " + self.iface
|
cmd = "%s %s" % (self._get_dhcp_command('connect'), self.iface)
|
||||||
|
#cmd = self.DHCP_CMD + " " + self.iface
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
pipe = misc.Run(cmd, include_stderr=True, return_pipe=True)
|
pipe = misc.Run(cmd, include_stderr=True, return_pipe=True)
|
||||||
|
|
||||||
@@ -476,19 +474,23 @@ class BaseInterface(object):
|
|||||||
def ReleaseDHCP(self):
|
def ReleaseDHCP(self):
|
||||||
""" Release the DHCP lease for this interface. """
|
""" Release the DHCP lease for this interface. """
|
||||||
if not self.iface: return False
|
if not self.iface: return False
|
||||||
cmd = self.DHCP_RELEASE + " " + self.iface
|
cmd = "%s %s" % (self._get_dhcp_command("release"), self.iface)
|
||||||
|
#cmd = self.DHCP_RELEASE + " " + self.iface
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|
||||||
def FlushRoutes(self):
|
def FlushRoutes(self):
|
||||||
""" Flush all network routes. """
|
""" Flush all network routes. """
|
||||||
if not self.iface: return False
|
if not self.iface: return False
|
||||||
if self.IP_FOUND and self.flush_tool == misc.IP:
|
if self.route_cmd and self.flush_tool == misc.ROUTE:
|
||||||
#cmd = "ip route flush dev " + self.iface
|
cmds = ['%s del default' % self.route_cmd]
|
||||||
cmds = ['ip route flush all']
|
|
||||||
else:
|
|
||||||
cmds = ['route del default']
|
|
||||||
cmds.append('route del dev %s' % self.iface)
|
cmds.append('route del dev %s' % self.iface)
|
||||||
|
elif self.ip_cmd:
|
||||||
|
#cmd = "ip route flush dev " + self.iface
|
||||||
|
cmds = ['%s route flush all' % self.ip_cmd]
|
||||||
|
else:
|
||||||
|
print "No flush command available!"
|
||||||
|
cmds = []
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
misc.Run(cmd)
|
misc.Run(cmd)
|
||||||
|
|||||||
Reference in New Issue
Block a user