1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-22 14:07:59 +01:00

branches/experimental

- Add support for entering search domain into static DNS settings.
- Fix some errors in how static setting texboxes were getting set.
- Fixed a bunch of errors/warnings found by pylint.
This commit is contained in:
imdano
2008-09-20 10:22:06 +00:00
parent 244b419f3f
commit c197b5fcbc
13 changed files with 172 additions and 142 deletions

View File

@@ -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 Sat Aug 23 23:56:47 2008 --> <!--Generated with glade3 3.4.5 on Sat Sep 20 13:28:27 2008 -->
<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>
@@ -548,6 +548,39 @@
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<child>
<widget class="GtkLabel" id="pref_search_dom_label">
<property name="width_request">170</property>
<property name="visible">True</property>
<property name="label" translatable="yes">Search Domain</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="pref_search_dom_entry">
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child> <child>
<widget class="GtkHBox" id="hbox12"> <widget class="GtkHBox" id="hbox12">
<property name="visible">True</property> <property name="visible">True</property>
@@ -579,7 +612,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">3</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -613,7 +646,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">4</property> <property name="position">5</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -646,7 +679,7 @@
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">5</property> <property name="position">6</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -661,7 +694,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">6</property> <property name="position">7</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -676,7 +709,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">7</property> <property name="position">8</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -691,7 +724,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">8</property> <property name="position">9</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -702,7 +735,7 @@
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">9</property> <property name="position">10</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -714,7 +747,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="fill">False</property>
<property name="position">10</property> <property name="position">11</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -729,7 +762,7 @@
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">11</property> <property name="position">12</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -745,7 +778,7 @@
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">12</property> <property name="position">13</property>
</packing> </packing>
</child> </child>
<child> <child>
@@ -761,7 +794,7 @@
</widget> </widget>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">13</property> <property name="position">14</property>
</packing> </packing>
</child> </child>
</widget> </widget>

View File

@@ -31,6 +31,7 @@ import wicd.wpath as wpath
class BackendManager(object): class BackendManager(object):
""" Manages, validates, and loads wicd backends. """
def __init__(self): def __init__(self):
""" Initialize the backend manager. """ """ Initialize the backend manager. """
self.backend_dir = wpath.backends self.backend_dir = wpath.backends
@@ -57,6 +58,7 @@ class BackendManager(object):
return be_list return be_list
def get_update_interval(self): def get_update_interval(self):
""" Returns how often in seconds the wicd monitor should update. """
if self.__loaded_backend: if self.__loaded_backend:
return self.__loaded_backend.UPDATE_INTERVAL return self.__loaded_backend.UPDATE_INTERVAL
else: else:

View File

@@ -34,8 +34,6 @@ import wicd.misc as misc
import wicd.wnettools as wnettools import wicd.wnettools as wnettools
import re import re
import os
import wicd.wpath as wpath
import time import time
@@ -77,22 +75,22 @@ auth_pattern = re.compile('.*wpa_state=(.*?)\n', re.I | re.M | re.S)
RALINK_DRIVER = 'ralink legacy' RALINK_DRIVER = 'ralink legacy'
def SetDNS(dns1=None, dns2=None, dns3=None): def SetDNS(*args, **kargs):
return wnettools.SetDNS(dns1, dns2, dns3) return wnettools.SetDNS(*args, **kargs)
def GetDefaultGateway(): def GetDefaultGateway(*args, **kargs):
return wnettools.GetDefaultGateway() return wnettools.GetDefaultGateway(*args, **kargs)
def StopDHCP(): def StopDHCP(*args, **kargs):
return wnettools.StopDHCP() return wnettools.StopDHCP(*args, **kargs)
def GetWirelessInterfaces(): def GetWirelessInterfaces(*args, **kargs):
return wnettools.GetWirelessInterfaces() return wnettools.GetWirelessInterfaces(*args, **kargs)
def GetWiredInterfaces(): def GetWiredInterfaces(*args, **kargs):
return wnettools.GetWiredInterfaces() return wnettools.GetWiredInterfaces(*args, **kargs)
def NeedsExternalCalls(): def NeedsExternalCalls(*args, **kargs):
return True return True

View File

@@ -82,20 +82,20 @@ SIOCGMIIPHY = 0x8947
SIOCETHTOOL = 0x8946 SIOCETHTOOL = 0x8946
SIOCGIFFLAGS = 0x8913 SIOCGIFFLAGS = 0x8913
def SetDNS(dns1=None, dns2=None, dns3=None): def SetDNS(*args, **kargs):
return wnettools.SetDNS(dns1, dns2, dns3) return wnettools.SetDNS(*args, **kargs)
def GetDefaultGateway(): def GetDefaultGateway(*args, **kargs):
return wnettools.GetDefaultGateway() return wnettools.GetDefaultGateway(*args, **kargs)
def StopDHCP(): def StopDHCP(*args, **kargs):
return wnettools.StopDHCP() return wnettools.StopDHCP(*args, **kargs)
def GetWirelessInterfaces(): def GetWirelessInterfaces(*args, **kargs):
return wnettools.GetWirelessInterfaces() return wnettools.GetWirelessInterfaces(*args, **kargs)
def GetWiredInterfaces(): def GetWiredInterfaces(*args, **kargs):
return wnettools.GetWiredInterfaces() return wnettools.GetWiredInterfaces(*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.
@@ -120,7 +120,7 @@ def get_iw_ioctl_result(iface, call):
return None return None
return buff.tostring() return buff.tostring()
def NeedsExternalCalls(): def NeedsExternalCalls(*args, **kargs):
return False return False
@@ -516,7 +516,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
""" """
if not self.iface: return -100 if not self.iface: return -100
buff = misc.get_irwange_ioctl_result(self.iface, SIOCGIWSTATS) buff = get_iw_ioctl_result(self.iface, SIOCGIWSTATS)
if not buff: if not buff:
return None return None

View File

@@ -26,6 +26,7 @@ A module for storing wicd's dbus interfaces.
import dbus import dbus
class DBusManager(object): class DBusManager(object):
""" Manages the DBus objects used by wicd. """
def __init__(self): def __init__(self):
self._bus = dbus.SystemBus() self._bus = dbus.SystemBus()
self._dbus_ifaces = {} self._dbus_ifaces = {}
@@ -35,6 +36,7 @@ class DBusManager(object):
return self._dbus_ifaces return self._dbus_ifaces
def get_interface(self, iface): def get_interface(self, iface):
""" Returns a DBus Interface. """
return self._dbus_ifaces[iface] return self._dbus_ifaces[iface]
def get_bus(self): def get_bus(self):

View File

@@ -673,8 +673,7 @@ class appGui(object):
return True return True
def save_wired_settings(self, entry): def _save_gen_settings(self, entry):
""" Saved wired network settings. """
if entry.chkbox_static_ip.get_active(): if entry.chkbox_static_ip.get_active():
entry.set_net_prop("ip", noneToString(entry.txt_ip.get_text())) entry.set_net_prop("ip", noneToString(entry.txt_ip.get_text()))
entry.set_net_prop("netmask", noneToString(entry.txt_netmask.get_text())) entry.set_net_prop("netmask", noneToString(entry.txt_netmask.get_text()))
@@ -688,6 +687,7 @@ class appGui(object):
not entry.chkbox_global_dns.get_active(): not entry.chkbox_global_dns.get_active():
entry.set_net_prop('use_static_dns', True) entry.set_net_prop('use_static_dns', True)
entry.set_net_prop('use_global_dns', False) entry.set_net_prop('use_global_dns', False)
entry.set_net_prop("search_domain", noneToString(entry.txt_search_dom.get_text()))
entry.set_net_prop("dns1", noneToString(entry.txt_dns_1.get_text())) entry.set_net_prop("dns1", noneToString(entry.txt_dns_1.get_text()))
entry.set_net_prop("dns2", noneToString(entry.txt_dns_2.get_text())) entry.set_net_prop("dns2", noneToString(entry.txt_dns_2.get_text()))
entry.set_net_prop("dns3", noneToString(entry.txt_dns_3.get_text())) entry.set_net_prop("dns3", noneToString(entry.txt_dns_3.get_text()))
@@ -697,9 +697,15 @@ class appGui(object):
entry.set_net_prop('use_global_dns', True) entry.set_net_prop('use_global_dns', True)
else: else:
entry.set_net_prop('use_static_dns', False) entry.set_net_prop('use_static_dns', False)
entry.set_net_prop('use_global_dns', False)
entry.set_net_prop("search_domain", '')
entry.set_net_prop("dns1", '') entry.set_net_prop("dns1", '')
entry.set_net_prop("dns2", '') entry.set_net_prop("dns2", '')
entry.set_net_prop("dns3", '') entry.set_net_prop("dns3", '')
def save_wired_settings(self, entry):
""" Saved wired network settings. """
self._save_gen_settings(entry)
wired.SaveWiredNetworkProfile(entry.prof_name) wired.SaveWiredNetworkProfile(entry.prof_name)
return True return True
@@ -711,8 +717,7 @@ class appGui(object):
encryption_info = entry.encryption_info encryption_info = entry.encryption_info
encrypt_methods = misc.LoadEncryptionMethods() encrypt_methods = misc.LoadEncryptionMethods()
entry.set_net_prop("enctype", entry.set_net_prop("enctype",
encrypt_methods[entry.combo_encryption. encrypt_methods[entry.combo_encryption.get_active()][1])
get_active()][1])
for x in encryption_info: for x in encryption_info:
if encryption_info[x].get_text() == "": if encryption_info[x].get_text() == "":
error(self.window, language['encrypt_info_missing']) error(self.window, language['encrypt_info_missing'])
@@ -728,40 +733,9 @@ class appGui(object):
"encryption")) "encryption"))
print "no encryption specified..." print "no encryption specified..."
entry.set_net_prop("enctype", "None") entry.set_net_prop("enctype", "None")
self._save_gen_settings(entry)
entry.set_net_prop("automatic", entry.set_net_prop("automatic",
noneToString(netent.chkbox_autoconnect.get_active())) noneToString(netent.chkbox_autoconnect.get_active()))
# Save IP info
if entry.chkbox_static_ip.get_active():
entry.set_net_prop("ip", noneToString(entry.txt_ip.get_text()))
entry.set_net_prop("netmask",
noneToString(entry.txt_netmask.get_text()))
entry.set_net_prop("gateway",
noneToString(entry.txt_gateway.get_text()))
else:
# Blank the values
entry.set_net_prop("ip", '')
entry.set_net_prop("netmask", '')
entry.set_net_prop("gateway", '')
# Save DNS info
if entry.chkbox_static_dns.get_active() and \
not entry.chkbox_global_dns.get_active():
entry.set_net_prop('use_static_dns', True)
entry.set_net_prop('use_global_dns', False)
entry.set_net_prop('dns1', noneToString(entry.txt_dns_1.get_text()))
entry.set_net_prop('dns2', noneToString(entry.txt_dns_2.get_text()))
entry.set_net_prop('dns3', noneToString(entry.txt_dns_3.get_text()))
elif entry.chkbox_static_dns.get_active() and \
entry.chkbox_global_dns.get_active():
entry.set_net_prop('use_static_dns', True)
entry.set_net_prop('use_global_dns', True)
else:
entry.set_net_prop('use_static_dns', False)
entry.set_net_prop('use_global_dns', False)
entry.set_net_prop('dns1', '')
entry.set_net_prop('dns2', '')
entry.set_net_prop('dns3', '')
if entry.chkbox_global_settings.get_active(): if entry.chkbox_global_settings.get_active():
entry.set_net_prop('use_settings_globally', True) entry.set_net_prop('use_settings_globally', True)

View File

@@ -22,7 +22,6 @@ import locale
import gettext import gettext
import sys import sys
from subprocess import Popen, STDOUT, PIPE, call from subprocess import Popen, STDOUT, PIPE, call
import subprocess
import commands import commands
# wicd imports # wicd imports
@@ -291,12 +290,11 @@ def get_gettext():
def to_unicode(x): def to_unicode(x):
""" Attempts to convert a string to utf-8. """ """ Attempts to convert a string to utf-8. """
try: # This may never fail, but let's be safe
encoding = locale.getpreferredencoding() encoding = locale.getpreferredencoding()
except: try:
# Just guess utf-8 if it fails.
encoding = 'utf-8'
ret = x.decode(encoding, 'replace').encode('utf-8') ret = x.decode(encoding, 'replace').encode('utf-8')
except:
ret = x.decode('utf-8', 'replace').encode('utf-8')
return ret return ret
def RenameProcess(new_name): def RenameProcess(new_name):
@@ -328,7 +326,6 @@ def detect_desktop_environment():
desktop_environment = 'xfce' desktop_environment = 'xfce'
except (OSError, RuntimeError): except (OSError, RuntimeError):
pass pass
return desktop_environment return desktop_environment
def choose_sudo_prog(): def choose_sudo_prog():
@@ -436,6 +433,7 @@ def get_language_list_gui():
language["route_flush"] = _("Route Table Flushing") language["route_flush"] = _("Route Table Flushing")
language["backend"] = _("Backend") language["backend"] = _("Backend")
language["backend_alert"] = _("Changes to your backend won't occur until the daemon is restarted.") language["backend_alert"] = _("Changes to your backend won't occur until the daemon is restarted.")
language['search_domain'] = _("Search Domain")
language['0'] = _('0') language['0'] = _('0')
language['1'] = _('1') language['1'] = _('1')
@@ -505,6 +503,5 @@ def stringToBoolean(text):
return text return text
def checkboxTextboxToggle(checkbox, textboxes): def checkboxTextboxToggle(checkbox, textboxes):
# Really bad practice, but checkbox == self
for textbox in textboxes: for textbox in textboxes:
textbox.set_sensitive(checkbox.get_active()) textbox.set_sensitive(checkbox.get_active())

View File

@@ -114,6 +114,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.txt_ip.entry.connect('focus-out-event', self.set_defaults) self.txt_ip.entry.connect('focus-out-event', self.set_defaults)
self.txt_netmask = LabelEntry(language['netmask']) self.txt_netmask = LabelEntry(language['netmask'])
self.txt_gateway = LabelEntry(language['gateway']) self.txt_gateway = LabelEntry(language['gateway'])
self.txt_search_dom = LabelEntry(language['search_domain'])
self.txt_dns_1 = LabelEntry(language['dns'] + ' ' + language['1']) self.txt_dns_1 = LabelEntry(language['dns'] + ' ' + language['1'])
self.txt_dns_2 = LabelEntry(language['dns'] + ' ' + language['2']) self.txt_dns_2 = LabelEntry(language['dns'] + ' ' + language['2'])
self.txt_dns_3 = LabelEntry(language['dns'] + ' ' + language['3']) self.txt_dns_3 = LabelEntry(language['dns'] + ' ' + language['3'])
@@ -129,6 +130,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.vbox.pack_start(self.txt_netmask, fill=False, expand=False) self.vbox.pack_start(self.txt_netmask, fill=False, expand=False)
self.vbox.pack_start(self.txt_gateway, fill=False, expand=False) self.vbox.pack_start(self.txt_gateway, fill=False, expand=False)
self.vbox.pack_start(self.hbox_dns, fill=False, expand=False) self.vbox.pack_start(self.hbox_dns, fill=False, expand=False)
self.vbox.pack_start(self.txt_search_dom, fill=False, expand=False)
self.vbox.pack_start(self.txt_dns_1, fill=False, expand=False) self.vbox.pack_start(self.txt_dns_1, fill=False, expand=False)
self.vbox.pack_start(self.txt_dns_2, fill=False, expand=False) self.vbox.pack_start(self.txt_dns_2, fill=False, expand=False)
self.vbox.pack_start(self.txt_dns_3, fill=False, expand=False) self.vbox.pack_start(self.txt_dns_3, fill=False, expand=False)
@@ -166,10 +168,10 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.chkbox_static_dns.set_sensitive(False) self.chkbox_static_dns.set_sensitive(False)
else: else:
self.chkbox_static_ip.set_active(False) self.chkbox_static_ip.set_active(False)
self.chkbox_static_dns.set_active(False)
self.chkbox_static_dns.set_sensitive(True) self.chkbox_static_dns.set_sensitive(True)
if stringToNone(self.txt_dns_1.get_text()): if stringToNone(self.txt_dns_1.get_text()) or \
self.chkbox_global_dns.get_active():
self.chkbox_static_dns.set_active(True) self.chkbox_static_dns.set_active(True)
else: else:
self.chkbox_static_dns.set_active(False) self.chkbox_static_dns.set_active(False)
@@ -198,29 +200,29 @@ class AdvancedSettingsDialog(gtk.Dialog):
""" Toggle entries and checkboxes based on the static dns checkbox. """ """ Toggle entries and checkboxes based on the static dns checkbox. """
# Should disable the static DNS boxes # Should disable the static DNS boxes
if self.chkbox_static_ip.get_active(): if self.chkbox_static_ip.get_active():
self.chkbox_static_dns.set_active(self.chkbox_static_ip. self.chkbox_static_dns.set_active(True)
get_active())
self.chkbox_static_dns.set_sensitive(False) self.chkbox_static_dns.set_sensitive(False)
self.chkbox_global_dns.set_sensitive(self.chkbox_static_dns. self.chkbox_global_dns.set_sensitive(self.chkbox_static_dns.
get_active()) get_active())
l = [self.txt_dns_1, self.txt_dns_2, self.txt_dns_3,
self.txt_search_dom]
if self.chkbox_static_dns.get_active(): if self.chkbox_static_dns.get_active():
# If global dns is on, don't use local dns # If global dns is on, don't use local dns
self.txt_dns_1.set_sensitive(not self.chkbox_global_dns.get_active()) for w in l:
self.txt_dns_2.set_sensitive(not self.chkbox_global_dns.get_active()) w.set_sensitive(not self.chkbox_global_dns.get_active())
self.txt_dns_3.set_sensitive(not self.chkbox_global_dns.get_active())
else: else:
self.txt_dns_1.set_sensitive(False) for w in l:
self.txt_dns_2.set_sensitive(False) w.set_sensitive(False)
self.txt_dns_3.set_sensitive(False)
self.chkbox_global_dns.set_active(False) self.chkbox_global_dns.set_active(False)
def toggle_global_dns_checkbox(self, widget=None): def toggle_global_dns_checkbox(self, widget=None):
""" Set the DNS entries' sensitivity based on the Global checkbox. """ """ Set the DNS entries' sensitivity based on the Global checkbox. """
if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active(): if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active():
self.txt_dns_1.set_sensitive(not self.chkbox_global_dns.get_active()) for w in [self.txt_dns_1, self.txt_dns_2,
self.txt_dns_2.set_sensitive(not self.chkbox_global_dns.get_active()) self.txt_dns_3, self.txt_search_dom]:
self.txt_dns_3.set_sensitive(not self.chkbox_global_dns.get_active()) w.set_sensitive(not self.chkbox_global_dns.get_active())
def destroy_called(self, *args): def destroy_called(self, *args):
""" Clean up everything. """ Clean up everything.
@@ -261,6 +263,8 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
self.txt_dns_1.set_text(self.format_entry("dns1")) self.txt_dns_1.set_text(self.format_entry("dns1"))
self.txt_dns_2.set_text(self.format_entry("dns2")) self.txt_dns_2.set_text(self.format_entry("dns2"))
self.txt_dns_3.set_text(self.format_entry("dns3")) self.txt_dns_3.set_text(self.format_entry("dns3"))
self.txt_search_dom.set_text(self.format_entry("search_domain"))
self.chkbox_global_dns.set_active(bool(wired.GetWiredPropery("use_global_dns")))
self.reset_static_checkboxes() self.reset_static_checkboxes()
def format_entry(self, label): def format_entry(self, label):
@@ -361,10 +365,13 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.chkbox_global_dns.set_active(bool(wireless.GetWirelessProperty(networkID, self.chkbox_global_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
'use_global_dns'))) 'use_global_dns')))
self.chkbox_static_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
'use_static_dns')))
self.txt_dns_1.set_text(self.format_entry(networkID, "dns1")) self.txt_dns_1.set_text(self.format_entry(networkID, "dns1"))
self.txt_dns_2.set_text(self.format_entry(networkID, "dns2")) self.txt_dns_2.set_text(self.format_entry(networkID, "dns2"))
self.txt_dns_3.set_text(self.format_entry(networkID, "dns3")) self.txt_dns_3.set_text(self.format_entry(networkID, "dns3"))
self.txt_search_dom.set_text(self.format_entry(networkID, "search_domain"))
self.reset_static_checkboxes() self.reset_static_checkboxes()
self.chkbox_encryption.set_active(bool(wireless.GetWirelessProperty(networkID, self.chkbox_encryption.set_active(bool(wireless.GetWirelessProperty(networkID,

View File

@@ -82,6 +82,7 @@ class Controller(object):
self.global_dns_1 = None self.global_dns_1 = None
self.global_dns_2 = None self.global_dns_2 = None
self.global_dns_3 = None self.global_dns_3 = None
self.global_search_dom = None
self._wired_interface = None self._wired_interface = None
self._wireless_interface = None self._wireless_interface = None
self._dhcp_client = None self._dhcp_client = None
@@ -181,7 +182,8 @@ class ConnectThread(threading.Thread):
lock = thread.allocate_lock() lock = thread.allocate_lock()
def __init__(self, network, wireless, wired, before_script, after_script, def __init__(self, network, wireless, wired, before_script, after_script,
disconnect_script, gdns1, gdns2, gdns3, wiface, liface, debug): disconnect_script, gdns1, gdns2, gdns3, gsearch_dom,
wiface, liface, debug):
""" Initialise the required object variables and the thread. """ Initialise the required object variables and the thread.
Keyword arguments: Keyword arguments:
@@ -213,6 +215,7 @@ class ConnectThread(threading.Thread):
self.global_dns_1 = gdns1 self.global_dns_1 = gdns1
self.global_dns_2 = gdns2 self.global_dns_2 = gdns2
self.global_dns_3 = gdns3 self.global_dns_3 = gdns3
self.global_search_dom = gsearch_dom
self.wiface = wiface self.wiface = wiface
self.liface = liface self.liface = liface
@@ -338,13 +341,15 @@ class ConnectThread(threading.Thread):
if self.network.get('use_global_dns'): if self.network.get('use_global_dns'):
BACKEND.SetDNS(misc.Noneify(self.global_dns_1), BACKEND.SetDNS(misc.Noneify(self.global_dns_1),
misc.Noneify(self.global_dns_2), misc.Noneify(self.global_dns_2),
misc.Noneify(self.global_dns_3)) misc.Noneify(self.global_dns_3),
misc.Noneify(self.global_search_dom))
elif self.network.get('use_static_dns') and (self.network.get('dns1') or elif self.network.get('use_static_dns') and (self.network.get('dns1') or
self.network.get('dns2') or self.network.get('dns3')): self.network.get('dns2') or self.network.get('dns3')):
self.SetStatus('setting_static_dns') self.SetStatus('setting_static_dns')
BACKEND.SetDNS(self.network.get('dns1'), BACKEND.SetDNS(self.network.get('dns1'),
self.network.get('dns2'), self.network.get('dns2'),
self.network.get('dns3')) self.network.get('dns3'),
self.network.get('search_domain'))
def connect_aborted(self, reason): def connect_aborted(self, reason):
""" Sets the thread status to aborted in a thread-safe way. """ Sets the thread status to aborted in a thread-safe way.
@@ -476,8 +481,8 @@ class Wireless(Controller):
self.wireless_interface, self.wired_interface, self.wireless_interface, self.wired_interface,
self.wpa_driver, self.before_script, self.after_script, self.wpa_driver, self.before_script, self.after_script,
self.disconnect_script, self.global_dns_1, self.disconnect_script, self.global_dns_1,
self.global_dns_2, self.global_dns_3, self.wiface, self.liface, self.global_dns_2, self.global_dns_3, self.global_search_dom,
debug) self.wiface, self.liface, debug)
self.connecting_thread.setDaemon(True) self.connecting_thread.setDaemon(True)
self.connecting_thread.start() self.connecting_thread.start()
return True return True
@@ -657,7 +662,7 @@ class WirelessConnectThread(ConnectThread):
def __init__(self, network, wireless, wired, wpa_driver, def __init__(self, network, wireless, wired, wpa_driver,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, wiface, liface, debug=False): gdns2, gdns3, gsearch_dom, wiface, liface, debug=False):
""" Initialise the thread with network information. """ Initialise the thread with network information.
Keyword arguments: Keyword arguments:
@@ -675,7 +680,7 @@ class WirelessConnectThread(ConnectThread):
""" """
ConnectThread.__init__(self, network, wireless, wired, ConnectThread.__init__(self, network, wireless, wired,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, wiface, liface, debug) gdns2, gdns3, gsearch_dom, wiface, liface, debug)
self.wpa_driver = wpa_driver self.wpa_driver = wpa_driver
@@ -844,8 +849,8 @@ class Wired(Controller):
self.wireless_interface, self.wired_interface, self.wireless_interface, self.wired_interface,
self.before_script, self.after_script, self.before_script, self.after_script,
self.disconnect_script, self.global_dns_1, self.disconnect_script, self.global_dns_1,
self.global_dns_2, self.global_dns_3, self.wiface, self.liface, self.global_dns_2, self.global_dns_3, self.global_search_dom,
debug) self.wiface, self.liface, debug)
self.connecting_thread.setDaemon(True) self.connecting_thread.setDaemon(True)
self.connecting_thread.start() self.connecting_thread.start()
return True return True
@@ -915,7 +920,7 @@ class WiredConnectThread(ConnectThread):
""" """
def __init__(self, network, wireless, wired, def __init__(self, network, wireless, wired,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, wiface, liface, debug=False): gdns2, gdns3, gsearch_dom, wiface, liface, debug=False):
""" Initialise the thread with network information. """ Initialise the thread with network information.
Keyword arguments: Keyword arguments:
@@ -932,7 +937,7 @@ class WiredConnectThread(ConnectThread):
""" """
ConnectThread.__init__(self, network, wireless, wired, ConnectThread.__init__(self, network, wireless, wired,
before_script, after_script, disconnect_script, gdns1, before_script, after_script, disconnect_script, gdns1,
gdns2, gdns3, wiface, liface, debug) gdns2, gdns3, gsearch_dom, wiface, liface, debug)
def run(self): def run(self):
""" The main function of the connection thread. """ The main function of the connection thread.

View File

@@ -167,22 +167,24 @@ class PreferencesDialog(object):
# Set up global DNS stuff # Set up global DNS stuff
self.useGlobalDNSCheckbox = setup_label("pref_global_check", self.useGlobalDNSCheckbox = setup_label("pref_global_check",
'use_global_dns') 'use_global_dns')
self.searchDomEntry = self.wTree.get_widget("pref_search_dom_entry")
self.dns1Entry = self.wTree.get_widget("pref_dns1_entry") self.dns1Entry = self.wTree.get_widget("pref_dns1_entry")
self.dns2Entry = self.wTree.get_widget("pref_dns2_entry") self.dns2Entry = self.wTree.get_widget("pref_dns2_entry")
self.dns3Entry = self.wTree.get_widget("pref_dns3_entry") self.dns3Entry = self.wTree.get_widget("pref_dns3_entry")
self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle, self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
(self.dns1Entry, self.dns2Entry, (self.dns1Entry, self.dns2Entry,
self.dns3Entry)) self.dns3Entry, self.searchDomEntry))
dns_addresses = daemon.GetGlobalDNSAddresses() dns_addresses = daemon.GetGlobalDNSAddresses()
self.useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS()) self.useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
self.dns1Entry.set_text(noneToBlankString(dns_addresses[0])) self.dns1Entry.set_text(noneToBlankString(dns_addresses[0]))
self.dns2Entry.set_text(noneToBlankString(dns_addresses[1])) self.dns2Entry.set_text(noneToBlankString(dns_addresses[1]))
self.dns3Entry.set_text(noneToBlankString(dns_addresses[2])) self.dns3Entry.set_text(noneToBlankString(dns_addresses[2]))
self.searchDomEntry.set_text(noneToBlankString(dns_addresses[3]))
if not daemon.GetUseGlobalDNS(): if not daemon.GetUseGlobalDNS():
self.searchDomEntry.set_sensitive(False)
self.dns1Entry.set_sensitive(False) self.dns1Entry.set_sensitive(False)
self.dns2Entry.set_sensitive(False) self.dns2Entry.set_sensitive(False)
self.dns3Entry.set_sensitive(False) self.dns3Entry.set_sensitive(False)
@@ -220,7 +222,7 @@ class PreferencesDialog(object):
def save_results(self): def save_results(self):
daemon.SetUseGlobalDNS(self.useGlobalDNSCheckbox.get_active()) daemon.SetUseGlobalDNS(self.useGlobalDNSCheckbox.get_active())
daemon.SetGlobalDNS(self.dns1Entry.get_text(), self.dns2Entry.get_text(), daemon.SetGlobalDNS(self.dns1Entry.get_text(), self.dns2Entry.get_text(),
self.dns3Entry.get_text()) self.dns3Entry.get_text(), self.searchDomEntry.get_text())
daemon.SetWirelessInterface(self.entryWirelessInterface.get_text()) daemon.SetWirelessInterface(self.entryWirelessInterface.get_text())
daemon.SetWiredInterface(self.entryWiredInterface.get_text()) daemon.SetWiredInterface(self.entryWiredInterface.get_text())
daemon.SetWPADriver(self.wpadrivers[self.wpadrivercombo.get_active()]) daemon.SetWPADriver(self.wpadrivers[self.wpadrivercombo.get_active()])
@@ -290,9 +292,10 @@ class PreferencesDialog(object):
atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50)) atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50))
entryWiredAutoMethod.set_attributes(atrlist) entryWiredAutoMethod.set_attributes(atrlist)
self.set_label("pref_dns1_label", language['dns'] + ' ' + language['1']) self.set_label("pref_dns1_label", "%s %s" % (language['dns'], language['1']))
self.set_label("pref_dns2_label", language['dns'] + ' ' + language['2']) self.set_label("pref_dns2_label", "%s %s" % (language['dns'], language['2']))
self.set_label("pref_dns3_label", language['dns'] + ' ' + language['3']) self.set_label("pref_dns3_label", "%s %s" % (language['dns'], language['3']))
self.set_label("pref_wifi_label", language['wireless_interface'] + ':') self.set_label("pref_search_dom_label", "%s:" % language['search_domain'])
self.set_label("pref_wired_label", language['wired_interface'] + ':') self.set_label("pref_wifi_label", "%s:" % language['wireless_interface'])
self.set_label("pref_driver_label", language['wpa_supplicant_driver'] + ':') self.set_label("pref_wired_label", "%s:" % language['wired_interface'])
self.set_label("pref_driver_label", "%s:" % language['wpa_supplicant_driver'])

View File

@@ -634,7 +634,7 @@ Arguments:
""" """
def setup_dbus(): def setup_dbus():
global bus, daemon, wireless, wired, dbus_manager global daemon, wireless, wired, dbus_manager
dbus_manager = DBusManager() dbus_manager = DBusManager()
try: try:

View File

@@ -38,7 +38,6 @@ import os
import sys import sys
import time import time
import getopt import getopt
import ConfigParser
import signal import signal
# DBUS # DBUS
@@ -162,7 +161,7 @@ class WicdDaemon(dbus.service.Object):
self.wired.use_global_dns = use self.wired.use_global_dns = use
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetGlobalDNS(self, dns1=None, dns2=None, dns3=None): def SetGlobalDNS(self, dns1=None, dns2=None, dns3=None, search_dom=None):
""" Sets the global dns addresses. """ """ Sets the global dns addresses. """
print "setting global dns" print "setting global dns"
self.config.set("Settings", "global_dns_1", misc.noneToString(dns1), True) self.config.set("Settings", "global_dns_1", misc.noneToString(dns1), True)
@@ -177,7 +176,12 @@ class WicdDaemon(dbus.service.Object):
self.dns3 = dns3 self.dns3 = dns3
self.wifi.global_dns_3 = dns3 self.wifi.global_dns_3 = dns3
self.wired.global_dns_3 = dns3 self.wired.global_dns_3 = dns3
self.config.set("Settings", "global_search_dom", misc.noneToString(search_dom), True)
self.search_dom = search_dom
self.wifi.global_search_dom = search_dom
self.wired.global_search_dom = search_dom
print 'global dns servers are', dns1, dns2, dns3 print 'global dns servers are', dns1, dns2, dns3
print 'search domain is %s' % search_dom
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def SetBackend(self, backend): def SetBackend(self, backend):
@@ -320,7 +324,7 @@ class WicdDaemon(dbus.service.Object):
def GetGlobalDNSAddresses(self): def GetGlobalDNSAddresses(self):
""" Returns the global dns addresses. """ """ Returns the global dns addresses. """
return (misc.noneToString(self.dns1), misc.noneToString(self.dns2), return (misc.noneToString(self.dns1), misc.noneToString(self.dns2),
misc.noneToString(self.dns3)) misc.noneToString(self.dns3), misc.noneToString(self.search_dom))
@dbus.service.method('org.wicd.daemon') @dbus.service.method('org.wicd.daemon')
def CheckIfConnecting(self): def CheckIfConnecting(self):
@@ -563,20 +567,21 @@ class WicdDaemon(dbus.service.Object):
def _wired_autoconnect(self): def _wired_autoconnect(self):
""" Attempts to autoconnect to a wired network. """ """ Attempts to autoconnect to a wired network. """
if self.GetWiredAutoConnectMethod() == 3 and \ wiredb = self.wired_bus
if wiredb.GetWiredAutoConnectMethod() == 3 and \
not self.GetNeedWiredProfileChooser(): not self.GetNeedWiredProfileChooser():
# attempt to smartly connect to a wired network # attempt to smartly connect to a wired network
# by using various wireless networks detected # by using various wireless networks detected
# and by using plugged in USB devices # and by using plugged in USB devices
print self.LastScan print self.LastScan
if self.GetWiredAutoConnectMethod() == 2 and \ if wiredb.GetWiredAutoConnectMethod() == 2 and \
not self.GetNeedWiredProfileChooser(): not self.GetNeedWiredProfileChooser():
self.LaunchChooser() self.LaunchChooser()
return True return True
# Default Profile. # Default Profile.
elif self.GetWiredAutoConnectMethod() == 1: elif wiredb.GetWiredAutoConnectMethod() == 1:
network = self.GetDefaultWiredNetwork() network = wiredb.GetDefaultWiredNetwork()
if not network: if not network:
print "Couldn't find a default wired connection," + \ print "Couldn't find a default wired connection," + \
" wired autoconnect failed." " wired autoconnect failed."
@@ -585,15 +590,15 @@ class WicdDaemon(dbus.service.Object):
# Last-Used. # Last-Used.
else: else:
network = self.GetLastUsedWiredNetwork() network = wiredb.GetLastUsedWiredNetwork()
if not network: if not network:
print "no previous wired profile available, wired " + \ print "no previous wired profile available, wired " + \
"autoconnect failed." "autoconnect failed."
self.wireless_bus._wireless_autoconnect() self.wireless_bus._wireless_autoconnect()
return return
self.ReadWiredNetworkProfile(network) wiredb.ReadWiredNetworkProfile(network)
self.ConnectWired() wiredb.ConnectWired()
print "Attempting to autoconnect with wired interface..." print "Attempting to autoconnect with wired interface..."
self.auto_connecting = True self.auto_connecting = True
time.sleep(1.5) time.sleep(1.5)
@@ -675,7 +680,8 @@ class WicdDaemon(dbus.service.Object):
dns1 = app_conf.get("Settings", "global_dns_1", default='None') dns1 = app_conf.get("Settings", "global_dns_1", default='None')
dns2 = app_conf.get("Settings", "global_dns_2", default='None') dns2 = app_conf.get("Settings", "global_dns_2", default='None')
dns3 = app_conf.get("Settings", "global_dns_3", default='None') dns3 = app_conf.get("Settings", "global_dns_3", default='None')
self.SetGlobalDNS(dns1, dns2, dns3) search_dom = app_conf.get("Settings", "global_search_dom", default='None')
self.SetGlobalDNS(dns1, dns2, dns3, search_dom)
self.SetAutoReconnect(app_conf.get("Settings", "auto_reconnect", self.SetAutoReconnect(app_conf.get("Settings", "auto_reconnect",
default=True)) default=True))
self.SetDebugMode(app_conf.get("Settings", "debug_mode", default=False)) self.SetDebugMode(app_conf.get("Settings", "debug_mode", default=False))
@@ -1370,6 +1376,7 @@ def daemonize():
# stdin always from /dev/null # stdin always from /dev/null
sys.stdin = open('/dev/null', 'r') sys.stdin = open('/dev/null', 'r')
child_pid = None
def main(argv): def main(argv):
""" The main daemon program. """ The main daemon program.

View File

@@ -32,7 +32,6 @@ class WirelessInterface() -- Control a wireless network interface.
# #
import os import os
import time
import re import re
import wpath import wpath
@@ -42,20 +41,26 @@ RALINK_DRIVER = 'ralink legacy'
def _sanitize_string(string): def _sanitize_string(string):
""" Makes sure a string is safe to use.
Escapes characters that can be used for doing bad stuff
at the terminal.
"""
blacklist = [';', '`', '$', '!', '*', '|', '>', '<'] blacklist = [';', '`', '$', '!', '*', '|', '>', '<']
new_string = [] new_string = []
if not string: if not string:
return string return string
for c in string: for char in string:
if c in blacklist: if char in blacklist:
new_string.append("\\" + c) new_string.append("\\" + char)
else: else:
new_string.append(c) new_string.append(char)
return ''.join(new_string) return ''.join(new_string)
def SetDNS(dns1=None, dns2=None, dns3=None): def SetDNS(dns1=None, dns2=None, dns3=None, search_dom=None):
""" Set the DNS of the system to the specified DNS servers. """ Set the DNS of the system to the specified DNS servers.
Opens up resolv.conf and writes in the nameservers. Opens up resolv.conf and writes in the nameservers.
@@ -67,6 +72,8 @@ def SetDNS(dns1=None, dns2=None, dns3=None):
""" """
resolv = open("/etc/resolv.conf", "w") resolv = open("/etc/resolv.conf", "w")
if search_dom:
resolv.write('search %s\n' % _sanitize_string(search_dom))
for dns in [dns1, dns2, dns3]: for dns in [dns1, dns2, dns3]:
if dns: if dns:
if misc.IsValidIP(dns): if misc.IsValidIP(dns):
@@ -117,12 +124,14 @@ def GetWirelessInterfaces():
return bool(ifnames) and ifnames[0] or None return bool(ifnames) and ifnames[0] or None
def GetWiredInterfaces(): def GetWiredInterfaces():
""" Returns a list of wired interfaces on the system. """
basedir = '/sys/class/net/' basedir = '/sys/class/net/'
return [iface for iface in os.listdir(basedir) if not 'wireless' return [iface for iface in os.listdir(basedir) if not 'wireless'
in os.listdir(basedir + iface) and in os.listdir(basedir + iface) and
open(basedir + iface + "/type").readlines()[0].strip() == "1"] open(basedir + iface + "/type").readlines()[0].strip() == "1"]
def NeedsExternalCalls(): def NeedsExternalCalls():
""" Returns True if the backend needs to use an external program. """
print ("NeedsExternalCalls: returning default of True. You should " + print ("NeedsExternalCalls: returning default of True. You should " +
"implement this yourself.") "implement this yourself.")
return True return True
@@ -180,7 +189,7 @@ class BaseInterface(object):
if os.access("%s%s" % (path, client), os.F_OK): if os.access("%s%s" % (path, client), os.F_OK):
return "%s%s" % (path, client) return "%s%s" % (path, client)
if self.verbose: if self.verbose:
"WARNING: No path found for %s" % (client) print "WARNING: No path found for %s" % (client)
return None return None
def _client_found(self, client): def _client_found(self, client):
@@ -508,7 +517,6 @@ class BaseInterface(object):
""" """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass
def IsUp(self): def IsUp(self):
""" Determines if the interface is up. """ Determines if the interface is up.
@@ -518,7 +526,6 @@ class BaseInterface(object):
""" """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass
class BaseWiredInterface(BaseInterface): class BaseWiredInterface(BaseInterface):
@@ -545,7 +552,6 @@ class BaseWiredInterface(BaseInterface):
""" """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass
class BaseWirelessInterface(BaseInterface): class BaseWirelessInterface(BaseInterface):
@@ -661,6 +667,7 @@ class BaseWirelessInterface(BaseInterface):
""" """
lines = ralink_info lines = ralink_info
wep_pattern = re.compile('.*Encryption key:(.*?)\n', re.I | re.M | re.S)
for x in lines: # Iterate through all networks found for x in lines: # Iterate through all networks found
info = x.split() info = x.split()
# Make sure we read in a valid entry # Make sure we read in a valid entry
@@ -786,7 +793,6 @@ class BaseWirelessInterface(BaseInterface):
""" """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass
def _AuthenticateRalinkLegacy(self, network): def _AuthenticateRalinkLegacy(self, network):
""" Authenticate with the specified wireless network. """ Authenticate with the specified wireless network.
@@ -848,7 +854,6 @@ class BaseWirelessInterface(BaseInterface):
def GetBSSID(self, iwconfig=None): def GetBSSID(self, iwconfig=None):
""" Get the MAC address for the interface. """ """ Get the MAC address for the interface. """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass
def GetSignalStrength(self, iwconfig=None): def GetSignalStrength(self, iwconfig=None):
""" Get the signal strength of the current network. """ Get the signal strength of the current network.
@@ -858,7 +863,6 @@ class BaseWirelessInterface(BaseInterface):
""" """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass
def GetDBMStrength(self, iwconfig=None): def GetDBMStrength(self, iwconfig=None):
""" Get the dBm signal strength of the current network. """ Get the dBm signal strength of the current network.
@@ -868,7 +872,6 @@ class BaseWirelessInterface(BaseInterface):
""" """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass
def GetCurrentNetwork(self, iwconfig=None): def GetCurrentNetwork(self, iwconfig=None):
""" Get the essid of the current network. """ Get the essid of the current network.
@@ -878,5 +881,4 @@ class BaseWirelessInterface(BaseInterface):
""" """
print 'Implement this in a derived class!' print 'Implement this in a derived class!'
pass