mirror of
https://github.com/gryf/wicd.git
synced 2025-12-22 05:48:03 +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:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!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>
|
||||
<widget class="GtkWindow" id="window1">
|
||||
<property name="width_request">450</property>
|
||||
@@ -548,6 +548,39 @@
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</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>
|
||||
<widget class="GtkHBox" id="hbox12">
|
||||
<property name="visible">True</property>
|
||||
@@ -579,7 +612,7 @@
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">3</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -613,7 +646,7 @@
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">4</property>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -646,7 +679,7 @@
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">5</property>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -661,7 +694,7 @@
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">6</property>
|
||||
<property name="position">7</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -676,7 +709,7 @@
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">7</property>
|
||||
<property name="position">8</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -691,7 +724,7 @@
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">8</property>
|
||||
<property name="position">9</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -702,7 +735,7 @@
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">9</property>
|
||||
<property name="position">10</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -714,7 +747,7 @@
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">10</property>
|
||||
<property name="position">11</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -729,7 +762,7 @@
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">11</property>
|
||||
<property name="position">12</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -745,7 +778,7 @@
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">12</property>
|
||||
<property name="position">13</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@@ -761,7 +794,7 @@
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">13</property>
|
||||
<property name="position">14</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
@@ -31,6 +31,7 @@ import wicd.wpath as wpath
|
||||
|
||||
|
||||
class BackendManager(object):
|
||||
""" Manages, validates, and loads wicd backends. """
|
||||
def __init__(self):
|
||||
""" Initialize the backend manager. """
|
||||
self.backend_dir = wpath.backends
|
||||
@@ -57,6 +58,7 @@ class BackendManager(object):
|
||||
return be_list
|
||||
|
||||
def get_update_interval(self):
|
||||
""" Returns how often in seconds the wicd monitor should update. """
|
||||
if self.__loaded_backend:
|
||||
return self.__loaded_backend.UPDATE_INTERVAL
|
||||
else:
|
||||
|
||||
@@ -34,8 +34,6 @@ import wicd.misc as misc
|
||||
import wicd.wnettools as wnettools
|
||||
|
||||
import re
|
||||
import os
|
||||
import wicd.wpath as wpath
|
||||
import time
|
||||
|
||||
|
||||
@@ -77,22 +75,22 @@ auth_pattern = re.compile('.*wpa_state=(.*?)\n', re.I | re.M | re.S)
|
||||
RALINK_DRIVER = 'ralink legacy'
|
||||
|
||||
|
||||
def SetDNS(dns1=None, dns2=None, dns3=None):
|
||||
return wnettools.SetDNS(dns1, dns2, dns3)
|
||||
def SetDNS(*args, **kargs):
|
||||
return wnettools.SetDNS(*args, **kargs)
|
||||
|
||||
def GetDefaultGateway():
|
||||
return wnettools.GetDefaultGateway()
|
||||
def GetDefaultGateway(*args, **kargs):
|
||||
return wnettools.GetDefaultGateway(*args, **kargs)
|
||||
|
||||
def StopDHCP():
|
||||
return wnettools.StopDHCP()
|
||||
def StopDHCP(*args, **kargs):
|
||||
return wnettools.StopDHCP(*args, **kargs)
|
||||
|
||||
def GetWirelessInterfaces():
|
||||
return wnettools.GetWirelessInterfaces()
|
||||
def GetWirelessInterfaces(*args, **kargs):
|
||||
return wnettools.GetWirelessInterfaces(*args, **kargs)
|
||||
|
||||
def GetWiredInterfaces():
|
||||
return wnettools.GetWiredInterfaces()
|
||||
def GetWiredInterfaces(*args, **kargs):
|
||||
return wnettools.GetWiredInterfaces(*args, **kargs)
|
||||
|
||||
def NeedsExternalCalls():
|
||||
def NeedsExternalCalls(*args, **kargs):
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -82,20 +82,20 @@ SIOCGMIIPHY = 0x8947
|
||||
SIOCETHTOOL = 0x8946
|
||||
SIOCGIFFLAGS = 0x8913
|
||||
|
||||
def SetDNS(dns1=None, dns2=None, dns3=None):
|
||||
return wnettools.SetDNS(dns1, dns2, dns3)
|
||||
def SetDNS(*args, **kargs):
|
||||
return wnettools.SetDNS(*args, **kargs)
|
||||
|
||||
def GetDefaultGateway():
|
||||
return wnettools.GetDefaultGateway()
|
||||
def GetDefaultGateway(*args, **kargs):
|
||||
return wnettools.GetDefaultGateway(*args, **kargs)
|
||||
|
||||
def StopDHCP():
|
||||
return wnettools.StopDHCP()
|
||||
def StopDHCP(*args, **kargs):
|
||||
return wnettools.StopDHCP(*args, **kargs)
|
||||
|
||||
def GetWirelessInterfaces():
|
||||
return wnettools.GetWirelessInterfaces()
|
||||
def GetWirelessInterfaces(*args, **kargs):
|
||||
return wnettools.GetWirelessInterfaces(*args, **kargs)
|
||||
|
||||
def GetWiredInterfaces():
|
||||
return wnettools.GetWiredInterfaces()
|
||||
def GetWiredInterfaces(*args, **kargs):
|
||||
return wnettools.GetWiredInterfaces(*args, **kargs)
|
||||
|
||||
def get_iw_ioctl_result(iface, call):
|
||||
""" Makes the given ioctl call and returns the results.
|
||||
@@ -120,7 +120,7 @@ def get_iw_ioctl_result(iface, call):
|
||||
return None
|
||||
return buff.tostring()
|
||||
|
||||
def NeedsExternalCalls():
|
||||
def NeedsExternalCalls(*args, **kargs):
|
||||
return False
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ class WirelessInterface(Interface, wnettools.BaseWirelessInterface):
|
||||
|
||||
"""
|
||||
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:
|
||||
return None
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ A module for storing wicd's dbus interfaces.
|
||||
import dbus
|
||||
|
||||
class DBusManager(object):
|
||||
""" Manages the DBus objects used by wicd. """
|
||||
def __init__(self):
|
||||
self._bus = dbus.SystemBus()
|
||||
self._dbus_ifaces = {}
|
||||
@@ -35,6 +36,7 @@ class DBusManager(object):
|
||||
return self._dbus_ifaces
|
||||
|
||||
def get_interface(self, iface):
|
||||
""" Returns a DBus Interface. """
|
||||
return self._dbus_ifaces[iface]
|
||||
|
||||
def get_bus(self):
|
||||
|
||||
46
wicd/gui.py
46
wicd/gui.py
@@ -673,8 +673,7 @@ class appGui(object):
|
||||
|
||||
return True
|
||||
|
||||
def save_wired_settings(self, entry):
|
||||
""" Saved wired network settings. """
|
||||
def _save_gen_settings(self, entry):
|
||||
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()))
|
||||
@@ -688,6 +687,7 @@ class appGui(object):
|
||||
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("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("dns2", noneToString(entry.txt_dns_2.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)
|
||||
else:
|
||||
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("dns2", '')
|
||||
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)
|
||||
return True
|
||||
|
||||
@@ -711,8 +717,7 @@ class appGui(object):
|
||||
encryption_info = entry.encryption_info
|
||||
encrypt_methods = misc.LoadEncryptionMethods()
|
||||
entry.set_net_prop("enctype",
|
||||
encrypt_methods[entry.combo_encryption.
|
||||
get_active()][1])
|
||||
encrypt_methods[entry.combo_encryption.get_active()][1])
|
||||
for x in encryption_info:
|
||||
if encryption_info[x].get_text() == "":
|
||||
error(self.window, language['encrypt_info_missing'])
|
||||
@@ -728,40 +733,9 @@ class appGui(object):
|
||||
"encryption"))
|
||||
print "no encryption specified..."
|
||||
entry.set_net_prop("enctype", "None")
|
||||
|
||||
self._save_gen_settings(entry)
|
||||
entry.set_net_prop("automatic",
|
||||
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():
|
||||
entry.set_net_prop('use_settings_globally', True)
|
||||
|
||||
11
wicd/misc.py
11
wicd/misc.py
@@ -22,7 +22,6 @@ import locale
|
||||
import gettext
|
||||
import sys
|
||||
from subprocess import Popen, STDOUT, PIPE, call
|
||||
import subprocess
|
||||
import commands
|
||||
|
||||
# wicd imports
|
||||
@@ -291,12 +290,11 @@ def get_gettext():
|
||||
|
||||
def to_unicode(x):
|
||||
""" Attempts to convert a string to utf-8. """
|
||||
try: # This may never fail, but let's be safe
|
||||
encoding = locale.getpreferredencoding()
|
||||
except:
|
||||
# Just guess utf-8 if it fails.
|
||||
encoding = 'utf-8'
|
||||
try:
|
||||
ret = x.decode(encoding, 'replace').encode('utf-8')
|
||||
except:
|
||||
ret = x.decode('utf-8', 'replace').encode('utf-8')
|
||||
return ret
|
||||
|
||||
def RenameProcess(new_name):
|
||||
@@ -328,7 +326,6 @@ def detect_desktop_environment():
|
||||
desktop_environment = 'xfce'
|
||||
except (OSError, RuntimeError):
|
||||
pass
|
||||
|
||||
return desktop_environment
|
||||
|
||||
def choose_sudo_prog():
|
||||
@@ -436,6 +433,7 @@ def get_language_list_gui():
|
||||
language["route_flush"] = _("Route Table Flushing")
|
||||
language["backend"] = _("Backend")
|
||||
language["backend_alert"] = _("Changes to your backend won't occur until the daemon is restarted.")
|
||||
language['search_domain'] = _("Search Domain")
|
||||
|
||||
language['0'] = _('0')
|
||||
language['1'] = _('1')
|
||||
@@ -505,6 +503,5 @@ def stringToBoolean(text):
|
||||
return text
|
||||
|
||||
def checkboxTextboxToggle(checkbox, textboxes):
|
||||
# Really bad practice, but checkbox == self
|
||||
for textbox in textboxes:
|
||||
textbox.set_sensitive(checkbox.get_active())
|
||||
|
||||
@@ -114,6 +114,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
|
||||
self.txt_ip.entry.connect('focus-out-event', self.set_defaults)
|
||||
self.txt_netmask = LabelEntry(language['netmask'])
|
||||
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_2 = LabelEntry(language['dns'] + ' ' + language['2'])
|
||||
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_gateway, 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_2, 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)
|
||||
else:
|
||||
self.chkbox_static_ip.set_active(False)
|
||||
self.chkbox_static_dns.set_active(False)
|
||||
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)
|
||||
else:
|
||||
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. """
|
||||
# Should disable the static DNS boxes
|
||||
if self.chkbox_static_ip.get_active():
|
||||
self.chkbox_static_dns.set_active(self.chkbox_static_ip.
|
||||
get_active())
|
||||
self.chkbox_static_dns.set_active(True)
|
||||
self.chkbox_static_dns.set_sensitive(False)
|
||||
|
||||
self.chkbox_global_dns.set_sensitive(self.chkbox_static_dns.
|
||||
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 global dns is on, don't use local dns
|
||||
self.txt_dns_1.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
self.txt_dns_2.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
self.txt_dns_3.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
for w in l:
|
||||
w.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
else:
|
||||
self.txt_dns_1.set_sensitive(False)
|
||||
self.txt_dns_2.set_sensitive(False)
|
||||
self.txt_dns_3.set_sensitive(False)
|
||||
for w in l:
|
||||
w.set_sensitive(False)
|
||||
self.chkbox_global_dns.set_active(False)
|
||||
|
||||
def toggle_global_dns_checkbox(self, widget=None):
|
||||
""" Set the DNS entries' sensitivity based on the Global checkbox. """
|
||||
if daemon.GetUseGlobalDNS() and self.chkbox_static_dns.get_active():
|
||||
self.txt_dns_1.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
self.txt_dns_2.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
self.txt_dns_3.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
for w in [self.txt_dns_1, self.txt_dns_2,
|
||||
self.txt_dns_3, self.txt_search_dom]:
|
||||
w.set_sensitive(not self.chkbox_global_dns.get_active())
|
||||
|
||||
def destroy_called(self, *args):
|
||||
""" Clean up everything.
|
||||
@@ -261,6 +263,8 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
|
||||
self.txt_dns_1.set_text(self.format_entry("dns1"))
|
||||
self.txt_dns_2.set_text(self.format_entry("dns2"))
|
||||
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()
|
||||
|
||||
def format_entry(self, label):
|
||||
@@ -361,10 +365,13 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
||||
|
||||
self.chkbox_global_dns.set_active(bool(wireless.GetWirelessProperty(networkID,
|
||||
'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_2.set_text(self.format_entry(networkID, "dns2"))
|
||||
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.chkbox_encryption.set_active(bool(wireless.GetWirelessProperty(networkID,
|
||||
|
||||
@@ -82,6 +82,7 @@ class Controller(object):
|
||||
self.global_dns_1 = None
|
||||
self.global_dns_2 = None
|
||||
self.global_dns_3 = None
|
||||
self.global_search_dom = None
|
||||
self._wired_interface = None
|
||||
self._wireless_interface = None
|
||||
self._dhcp_client = None
|
||||
@@ -181,7 +182,8 @@ class ConnectThread(threading.Thread):
|
||||
lock = thread.allocate_lock()
|
||||
|
||||
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.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -213,6 +215,7 @@ class ConnectThread(threading.Thread):
|
||||
self.global_dns_1 = gdns1
|
||||
self.global_dns_2 = gdns2
|
||||
self.global_dns_3 = gdns3
|
||||
self.global_search_dom = gsearch_dom
|
||||
|
||||
self.wiface = wiface
|
||||
self.liface = liface
|
||||
@@ -338,13 +341,15 @@ class ConnectThread(threading.Thread):
|
||||
if self.network.get('use_global_dns'):
|
||||
BACKEND.SetDNS(misc.Noneify(self.global_dns_1),
|
||||
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
|
||||
self.network.get('dns2') or self.network.get('dns3')):
|
||||
self.SetStatus('setting_static_dns')
|
||||
BACKEND.SetDNS(self.network.get('dns1'),
|
||||
self.network.get('dns2'),
|
||||
self.network.get('dns3'))
|
||||
self.network.get('dns3'),
|
||||
self.network.get('search_domain'))
|
||||
|
||||
def connect_aborted(self, reason):
|
||||
""" 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.wpa_driver, self.before_script, self.after_script,
|
||||
self.disconnect_script, self.global_dns_1,
|
||||
self.global_dns_2, self.global_dns_3, self.wiface, self.liface,
|
||||
debug)
|
||||
self.global_dns_2, self.global_dns_3, self.global_search_dom,
|
||||
self.wiface, self.liface, debug)
|
||||
self.connecting_thread.setDaemon(True)
|
||||
self.connecting_thread.start()
|
||||
return True
|
||||
@@ -657,7 +662,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
|
||||
def __init__(self, network, wireless, wired, wpa_driver,
|
||||
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.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -675,7 +680,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3, wiface, liface, debug)
|
||||
gdns2, gdns3, gsearch_dom, wiface, liface, debug)
|
||||
self.wpa_driver = wpa_driver
|
||||
|
||||
|
||||
@@ -844,8 +849,8 @@ class Wired(Controller):
|
||||
self.wireless_interface, self.wired_interface,
|
||||
self.before_script, self.after_script,
|
||||
self.disconnect_script, self.global_dns_1,
|
||||
self.global_dns_2, self.global_dns_3, self.wiface, self.liface,
|
||||
debug)
|
||||
self.global_dns_2, self.global_dns_3, self.global_search_dom,
|
||||
self.wiface, self.liface, debug)
|
||||
self.connecting_thread.setDaemon(True)
|
||||
self.connecting_thread.start()
|
||||
return True
|
||||
@@ -915,7 +920,7 @@ class WiredConnectThread(ConnectThread):
|
||||
"""
|
||||
def __init__(self, network, wireless, wired,
|
||||
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.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -932,7 +937,7 @@ class WiredConnectThread(ConnectThread):
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, wired,
|
||||
before_script, after_script, disconnect_script, gdns1,
|
||||
gdns2, gdns3, wiface, liface, debug)
|
||||
gdns2, gdns3, gsearch_dom, wiface, liface, debug)
|
||||
|
||||
def run(self):
|
||||
""" The main function of the connection thread.
|
||||
|
||||
@@ -167,22 +167,24 @@ class PreferencesDialog(object):
|
||||
# Set up global DNS stuff
|
||||
self.useGlobalDNSCheckbox = setup_label("pref_global_check",
|
||||
'use_global_dns')
|
||||
|
||||
self.searchDomEntry = self.wTree.get_widget("pref_search_dom_entry")
|
||||
self.dns1Entry = self.wTree.get_widget("pref_dns1_entry")
|
||||
self.dns2Entry = self.wTree.get_widget("pref_dns2_entry")
|
||||
self.dns3Entry = self.wTree.get_widget("pref_dns3_entry")
|
||||
|
||||
self.useGlobalDNSCheckbox.connect("toggled", checkboxTextboxToggle,
|
||||
(self.dns1Entry, self.dns2Entry,
|
||||
self.dns3Entry))
|
||||
self.dns3Entry, self.searchDomEntry))
|
||||
|
||||
dns_addresses = daemon.GetGlobalDNSAddresses()
|
||||
self.useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
|
||||
self.dns1Entry.set_text(noneToBlankString(dns_addresses[0]))
|
||||
self.dns2Entry.set_text(noneToBlankString(dns_addresses[1]))
|
||||
self.dns3Entry.set_text(noneToBlankString(dns_addresses[2]))
|
||||
self.searchDomEntry.set_text(noneToBlankString(dns_addresses[3]))
|
||||
|
||||
if not daemon.GetUseGlobalDNS():
|
||||
self.searchDomEntry.set_sensitive(False)
|
||||
self.dns1Entry.set_sensitive(False)
|
||||
self.dns2Entry.set_sensitive(False)
|
||||
self.dns3Entry.set_sensitive(False)
|
||||
@@ -220,7 +222,7 @@ class PreferencesDialog(object):
|
||||
def save_results(self):
|
||||
daemon.SetUseGlobalDNS(self.useGlobalDNSCheckbox.get_active())
|
||||
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.SetWiredInterface(self.entryWiredInterface.get_text())
|
||||
daemon.SetWPADriver(self.wpadrivers[self.wpadrivercombo.get_active()])
|
||||
@@ -290,9 +292,10 @@ class PreferencesDialog(object):
|
||||
atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD, 0, 50))
|
||||
entryWiredAutoMethod.set_attributes(atrlist)
|
||||
|
||||
self.set_label("pref_dns1_label", language['dns'] + ' ' + language['1'])
|
||||
self.set_label("pref_dns2_label", language['dns'] + ' ' + language['2'])
|
||||
self.set_label("pref_dns3_label", language['dns'] + ' ' + language['3'])
|
||||
self.set_label("pref_wifi_label", language['wireless_interface'] + ':')
|
||||
self.set_label("pref_wired_label", language['wired_interface'] + ':')
|
||||
self.set_label("pref_driver_label", language['wpa_supplicant_driver'] + ':')
|
||||
self.set_label("pref_dns1_label", "%s %s" % (language['dns'], language['1']))
|
||||
self.set_label("pref_dns2_label", "%s %s" % (language['dns'], language['2']))
|
||||
self.set_label("pref_dns3_label", "%s %s" % (language['dns'], language['3']))
|
||||
self.set_label("pref_search_dom_label", "%s:" % language['search_domain'])
|
||||
self.set_label("pref_wifi_label", "%s:" % language['wireless_interface'])
|
||||
self.set_label("pref_wired_label", "%s:" % language['wired_interface'])
|
||||
self.set_label("pref_driver_label", "%s:" % language['wpa_supplicant_driver'])
|
||||
|
||||
@@ -634,7 +634,7 @@ Arguments:
|
||||
"""
|
||||
|
||||
def setup_dbus():
|
||||
global bus, daemon, wireless, wired, dbus_manager
|
||||
global daemon, wireless, wired, dbus_manager
|
||||
|
||||
dbus_manager = DBusManager()
|
||||
try:
|
||||
|
||||
@@ -38,7 +38,6 @@ import os
|
||||
import sys
|
||||
import time
|
||||
import getopt
|
||||
import ConfigParser
|
||||
import signal
|
||||
|
||||
# DBUS
|
||||
@@ -162,7 +161,7 @@ class WicdDaemon(dbus.service.Object):
|
||||
self.wired.use_global_dns = use
|
||||
|
||||
@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. """
|
||||
print "setting global dns"
|
||||
self.config.set("Settings", "global_dns_1", misc.noneToString(dns1), True)
|
||||
@@ -177,7 +176,12 @@ class WicdDaemon(dbus.service.Object):
|
||||
self.dns3 = dns3
|
||||
self.wifi.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 'search domain is %s' % search_dom
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def SetBackend(self, backend):
|
||||
@@ -320,7 +324,7 @@ class WicdDaemon(dbus.service.Object):
|
||||
def GetGlobalDNSAddresses(self):
|
||||
""" Returns the global dns addresses. """
|
||||
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')
|
||||
def CheckIfConnecting(self):
|
||||
@@ -563,20 +567,21 @@ class WicdDaemon(dbus.service.Object):
|
||||
|
||||
def _wired_autoconnect(self):
|
||||
""" Attempts to autoconnect to a wired network. """
|
||||
if self.GetWiredAutoConnectMethod() == 3 and \
|
||||
wiredb = self.wired_bus
|
||||
if wiredb.GetWiredAutoConnectMethod() == 3 and \
|
||||
not self.GetNeedWiredProfileChooser():
|
||||
# attempt to smartly connect to a wired network
|
||||
# by using various wireless networks detected
|
||||
# and by using plugged in USB devices
|
||||
print self.LastScan
|
||||
if self.GetWiredAutoConnectMethod() == 2 and \
|
||||
if wiredb.GetWiredAutoConnectMethod() == 2 and \
|
||||
not self.GetNeedWiredProfileChooser():
|
||||
self.LaunchChooser()
|
||||
return True
|
||||
|
||||
# Default Profile.
|
||||
elif self.GetWiredAutoConnectMethod() == 1:
|
||||
network = self.GetDefaultWiredNetwork()
|
||||
elif wiredb.GetWiredAutoConnectMethod() == 1:
|
||||
network = wiredb.GetDefaultWiredNetwork()
|
||||
if not network:
|
||||
print "Couldn't find a default wired connection," + \
|
||||
" wired autoconnect failed."
|
||||
@@ -585,15 +590,15 @@ class WicdDaemon(dbus.service.Object):
|
||||
|
||||
# Last-Used.
|
||||
else:
|
||||
network = self.GetLastUsedWiredNetwork()
|
||||
network = wiredb.GetLastUsedWiredNetwork()
|
||||
if not network:
|
||||
print "no previous wired profile available, wired " + \
|
||||
"autoconnect failed."
|
||||
self.wireless_bus._wireless_autoconnect()
|
||||
return
|
||||
|
||||
self.ReadWiredNetworkProfile(network)
|
||||
self.ConnectWired()
|
||||
wiredb.ReadWiredNetworkProfile(network)
|
||||
wiredb.ConnectWired()
|
||||
print "Attempting to autoconnect with wired interface..."
|
||||
self.auto_connecting = True
|
||||
time.sleep(1.5)
|
||||
@@ -675,7 +680,8 @@ class WicdDaemon(dbus.service.Object):
|
||||
dns1 = app_conf.get("Settings", "global_dns_1", default='None')
|
||||
dns2 = app_conf.get("Settings", "global_dns_2", 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",
|
||||
default=True))
|
||||
self.SetDebugMode(app_conf.get("Settings", "debug_mode", default=False))
|
||||
@@ -1370,6 +1376,7 @@ def daemonize():
|
||||
# stdin always from /dev/null
|
||||
sys.stdin = open('/dev/null', 'r')
|
||||
|
||||
child_pid = None
|
||||
|
||||
def main(argv):
|
||||
""" The main daemon program.
|
||||
|
||||
@@ -32,7 +32,6 @@ class WirelessInterface() -- Control a wireless network interface.
|
||||
#
|
||||
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
|
||||
import wpath
|
||||
@@ -42,20 +41,26 @@ RALINK_DRIVER = 'ralink legacy'
|
||||
|
||||
|
||||
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 = [';', '`', '$', '!', '*', '|', '>', '<']
|
||||
new_string = []
|
||||
|
||||
if not string:
|
||||
return string
|
||||
|
||||
for c in string:
|
||||
if c in blacklist:
|
||||
new_string.append("\\" + c)
|
||||
for char in string:
|
||||
if char in blacklist:
|
||||
new_string.append("\\" + char)
|
||||
else:
|
||||
new_string.append(c)
|
||||
new_string.append(char)
|
||||
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.
|
||||
|
||||
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")
|
||||
if search_dom:
|
||||
resolv.write('search %s\n' % _sanitize_string(search_dom))
|
||||
for dns in [dns1, dns2, dns3]:
|
||||
if dns:
|
||||
if misc.IsValidIP(dns):
|
||||
@@ -117,12 +124,14 @@ def GetWirelessInterfaces():
|
||||
return bool(ifnames) and ifnames[0] or None
|
||||
|
||||
def GetWiredInterfaces():
|
||||
""" Returns a list of wired interfaces on the system. """
|
||||
basedir = '/sys/class/net/'
|
||||
return [iface for iface in os.listdir(basedir) if not 'wireless'
|
||||
in os.listdir(basedir + iface) and
|
||||
open(basedir + iface + "/type").readlines()[0].strip() == "1"]
|
||||
|
||||
def NeedsExternalCalls():
|
||||
""" Returns True if the backend needs to use an external program. """
|
||||
print ("NeedsExternalCalls: returning default of True. You should " +
|
||||
"implement this yourself.")
|
||||
return True
|
||||
@@ -180,7 +189,7 @@ class BaseInterface(object):
|
||||
if os.access("%s%s" % (path, client), os.F_OK):
|
||||
return "%s%s" % (path, client)
|
||||
if self.verbose:
|
||||
"WARNING: No path found for %s" % (client)
|
||||
print "WARNING: No path found for %s" % (client)
|
||||
return None
|
||||
|
||||
def _client_found(self, client):
|
||||
@@ -508,7 +517,6 @@ class BaseInterface(object):
|
||||
|
||||
"""
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
def IsUp(self):
|
||||
""" Determines if the interface is up.
|
||||
@@ -518,7 +526,6 @@ class BaseInterface(object):
|
||||
|
||||
"""
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
|
||||
class BaseWiredInterface(BaseInterface):
|
||||
@@ -545,7 +552,6 @@ class BaseWiredInterface(BaseInterface):
|
||||
|
||||
"""
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
|
||||
class BaseWirelessInterface(BaseInterface):
|
||||
@@ -661,6 +667,7 @@ class BaseWirelessInterface(BaseInterface):
|
||||
|
||||
"""
|
||||
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
|
||||
info = x.split()
|
||||
# Make sure we read in a valid entry
|
||||
@@ -786,7 +793,6 @@ class BaseWirelessInterface(BaseInterface):
|
||||
|
||||
"""
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
def _AuthenticateRalinkLegacy(self, network):
|
||||
""" Authenticate with the specified wireless network.
|
||||
@@ -848,7 +854,6 @@ class BaseWirelessInterface(BaseInterface):
|
||||
def GetBSSID(self, iwconfig=None):
|
||||
""" Get the MAC address for the interface. """
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
def GetSignalStrength(self, iwconfig=None):
|
||||
""" Get the signal strength of the current network.
|
||||
@@ -858,7 +863,6 @@ class BaseWirelessInterface(BaseInterface):
|
||||
|
||||
"""
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
def GetDBMStrength(self, iwconfig=None):
|
||||
""" Get the dBm signal strength of the current network.
|
||||
@@ -868,7 +872,6 @@ class BaseWirelessInterface(BaseInterface):
|
||||
|
||||
"""
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
def GetCurrentNetwork(self, iwconfig=None):
|
||||
""" Get the essid of the current network.
|
||||
@@ -878,5 +881,4 @@ class BaseWirelessInterface(BaseInterface):
|
||||
|
||||
"""
|
||||
print 'Implement this in a derived class!'
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user