mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Merged r295 of experimental-nacl
This commit is contained in:
@@ -91,13 +91,13 @@ class wrap_exceptions:
|
||||
#gobject.source_remove(redraw_tag)
|
||||
loop.quit()
|
||||
ui.stop()
|
||||
print "\n"+language['terminated']
|
||||
print >> sys.stderr, "\n"+language['terminated']
|
||||
#raise
|
||||
except DBusException:
|
||||
#gobject.source_remove(redraw_tag)
|
||||
loop.quit()
|
||||
ui.stop()
|
||||
print "\n"+language['dbus_fail']
|
||||
print >> sys.stderr,"\n"+language['dbus_fail']
|
||||
raise
|
||||
except :
|
||||
# Quit the loop
|
||||
@@ -106,7 +106,7 @@ class wrap_exceptions:
|
||||
# Zap the screen
|
||||
ui.stop()
|
||||
# Print out standard notification:
|
||||
print "\n" + language['exception']
|
||||
print >> sys.stderr, "\n" + language['exception']
|
||||
# Flush the buffer so that the notification is always above the
|
||||
# backtrace
|
||||
sys.stdout.flush()
|
||||
@@ -1026,7 +1026,7 @@ def setup_dbus(force=True):
|
||||
except DBusException:
|
||||
# I may need to be a little more verbose here.
|
||||
# Suggestions as to what should go here, please?
|
||||
print language['cannot_connect_to_daemon']
|
||||
print >> sys.stderr, language['cannot_connect_to_daemon']
|
||||
#raise
|
||||
# return False # <- Will need soon.
|
||||
bus = dbusmanager.get_bus()
|
||||
|
||||
@@ -95,6 +95,10 @@ def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False):
|
||||
else:
|
||||
err = None
|
||||
fds = False
|
||||
if return_obj:
|
||||
std_in = PIPE
|
||||
else:
|
||||
std_in = None
|
||||
|
||||
# We need to make sure that the results of the command we run
|
||||
# are in English, so we set up a temporary environment.
|
||||
@@ -105,8 +109,8 @@ def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False):
|
||||
tmpenv["LANG"] = __LANG
|
||||
|
||||
try:
|
||||
f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds,
|
||||
cwd='/', env=tmpenv)
|
||||
f = Popen(cmd, shell=False, stdout=PIPE, stdin=std_in, stderr=err,
|
||||
close_fds=fds, cwd='/', env=tmpenv)
|
||||
except OSError, e:
|
||||
print "Running command %s failed: %s" % (str(cmd), str(e))
|
||||
return ""
|
||||
|
||||
@@ -427,7 +427,7 @@ class ConnectThread(threading.Thread):
|
||||
return
|
||||
|
||||
@abortable
|
||||
def set_dns_addresses(self):
|
||||
def set_dns_addresses(self, iface):
|
||||
""" Set the DNS address(es).
|
||||
|
||||
If static DNS servers or global DNS servers are specified, set them.
|
||||
@@ -435,19 +435,19 @@ 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_dom),
|
||||
misc.Noneify(self.global_search_dom))
|
||||
iface.SetDNS(misc.Noneify(self.global_dns_1),
|
||||
misc.Noneify(self.global_dns_2),
|
||||
misc.Noneify(self.global_dns_3),
|
||||
misc.Noneify(self.global_dns_dom),
|
||||
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('dns_domain'),
|
||||
self.network.get('search_domain'))
|
||||
iface.SetDNS(self.network.get('dns1'),
|
||||
self.network.get('dns2'),
|
||||
self.network.get('dns3'),
|
||||
self.network.get('dns_domain'),
|
||||
self.network.get('search_domain'))
|
||||
|
||||
@abortable
|
||||
def release_dhcp_clients(self, iface):
|
||||
@@ -837,7 +837,7 @@ class WirelessConnectThread(ConnectThread):
|
||||
# Set up gateway, IP address, and DNS servers.
|
||||
self.set_broadcast_address(wiface)
|
||||
self.set_ip_address(wiface)
|
||||
self.set_dns_addresses()
|
||||
self.set_dns_addresses(wiface)
|
||||
|
||||
# Run post-connection script.
|
||||
self.run_global_scripts_if_needed(wpath.postconnectscripts)
|
||||
@@ -1025,7 +1025,7 @@ class WiredConnectThread(ConnectThread):
|
||||
# Set gateway, IP adresses, and DNS servers.
|
||||
self.set_broadcast_address(liface)
|
||||
self.set_ip_address(liface)
|
||||
self.set_dns_addresses()
|
||||
self.set_dns_addresses(liface)
|
||||
|
||||
# Run post-connection script.
|
||||
self.run_global_scripts_if_needed(wpath.postconnectscripts)
|
||||
|
||||
@@ -74,7 +74,7 @@ blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ '
|
||||
blacklist_norm = ";`$!*|><&\\"
|
||||
blank_trans = maketrans("", "")
|
||||
|
||||
__all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces",
|
||||
__all__ = ["GetDefaultGateway", "GetWiredInterfaces",
|
||||
"GetWirelessInterfaces", "IsValidWpaSuppDriver"]
|
||||
|
||||
def _sanitize_string(string):
|
||||
@@ -89,33 +89,6 @@ def _sanitize_string_strict(string):
|
||||
else:
|
||||
return string
|
||||
|
||||
def SetDNS(dns1=None, dns2=None, dns3=None, dns_dom=None, search_dom=None):
|
||||
""" Set the DNS of the system to the specified DNS servers.
|
||||
|
||||
Opens up resolv.conf and writes in the nameservers.
|
||||
|
||||
Keyword arguments:
|
||||
dns1 -- IP address of DNS server 1
|
||||
dns2 -- IP address of DNS server 2
|
||||
dns3 -- IP address of DNS server 3
|
||||
dns_dom -- DNS domain
|
||||
search_dom -- DNS search domain
|
||||
|
||||
"""
|
||||
resolv = open("/etc/resolv.conf", "w")
|
||||
if dns_dom:
|
||||
resolv.write("domain %s\n" % dns_dom)
|
||||
if search_dom:
|
||||
resolv.write('search %s\n' % search_dom)
|
||||
for dns in [dns1, dns2, dns3]:
|
||||
if dns:
|
||||
if misc.IsValidIP(dns):
|
||||
print 'Setting DNS : ' + dns
|
||||
resolv.write('nameserver ' + dns + '\n')
|
||||
else:
|
||||
print 'DNS IP is not a valid IP address, not writing to resolv.conf'
|
||||
resolv.close()
|
||||
|
||||
def GetDefaultGateway():
|
||||
""" Attempts to determine the default gateway by parsing route -n. """
|
||||
route_info = misc.Run("route -n")
|
||||
@@ -291,6 +264,11 @@ class BaseInterface(object):
|
||||
self.CheckWirelessTools()
|
||||
self.CheckSudoApplications()
|
||||
self.CheckRouteFlushTool()
|
||||
self.CheckResolvConf()
|
||||
|
||||
def CheckResolvConf(self):
|
||||
""" Checks for the existence of resolvconf."""
|
||||
self.resolvconf_cmd = self._find_program_path("resolvconf")
|
||||
|
||||
def CheckDHCP(self):
|
||||
""" Check for the existence of valid DHCP clients.
|
||||
@@ -519,6 +497,49 @@ class BaseInterface(object):
|
||||
if self.verbose: print cmd
|
||||
misc.Run(cmd)
|
||||
|
||||
def SetDNS(self, dns1=None, dns2=None, dns3=None,
|
||||
dns_dom=None, search_dom=None):
|
||||
""" Set the DNS of the system to the specified DNS servers.
|
||||
|
||||
Opens up resolv.conf and writes in the nameservers.
|
||||
|
||||
Keyword arguments:
|
||||
dns1 -- IP address of DNS server 1
|
||||
dns2 -- IP address of DNS server 2
|
||||
dns3 -- IP address of DNS server 3
|
||||
dns_dom -- DNS domain
|
||||
search_dom -- DNS search domain
|
||||
|
||||
"""
|
||||
if not self.iface: return False
|
||||
resolv_params = ""
|
||||
if dns_dom:
|
||||
resolv_params += 'domain %s\n' % dns_dom
|
||||
if search_dom:
|
||||
resolv_params += 'search %s\n' % search_dom
|
||||
|
||||
valid_dns_list = []
|
||||
for dns in (dns1, dns2, dns3):
|
||||
if dns:
|
||||
if misc.IsValidIP(dns):
|
||||
if self.verbose:
|
||||
print 'Setting DNS : ' + dns
|
||||
valid_dns_list.append("nameserver %s\n" % dns)
|
||||
else:
|
||||
print 'DNS IP %s is not a valid IP address, skipping' % dns
|
||||
|
||||
if valid_dns_list:
|
||||
resolv_params += ''.join(valid_dns_list)
|
||||
|
||||
if self.resolvconf_cmd:
|
||||
cmd = [self.resolvconf_cmd, '-a', self.iface]
|
||||
if self.verbose: print cmd
|
||||
p = misc.Run(cmd, include_stderr=True, return_obj=True)
|
||||
p.communicate(input=resolv_params)
|
||||
else:
|
||||
resolv = open("/etc/resolv.conf", "w")
|
||||
resolv.write(resolv_params + "\n")
|
||||
resolv.close()
|
||||
|
||||
def FlushRoutes(self):
|
||||
""" Flush network routes for this device. """
|
||||
|
||||
Reference in New Issue
Block a user