mirror of
https://github.com/gryf/wicd.git
synced 2025-12-28 17:32:36 +01:00
Change behaviour when dealing with hostnames: don't send any if the user didn't tick the box (previously, the current system name was sent).
This commit is contained in:
@@ -470,11 +470,12 @@ class ConnectThread(threading.Thread):
|
||||
self.network['usedhcphostname'] = False
|
||||
if self.network.get('dhcphostname') == None:
|
||||
self.network['dhcphostname'] = os.uname()[1]
|
||||
if not self.network['usedhcphostname']:
|
||||
hname = os.uname()[1]
|
||||
else:
|
||||
if self.network['usedhcphostname']:
|
||||
hname = self.network['dhcphostname']
|
||||
print "Running DHCP with hostname", hname
|
||||
print "Running DHCP with hostname", hname
|
||||
else:
|
||||
hname = None
|
||||
print "Running DHCP with NO hostname"
|
||||
dhcp_status = iface.StartDHCP(hname)
|
||||
if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']:
|
||||
if self.connect_result != "aborted":
|
||||
|
||||
@@ -38,6 +38,7 @@ import time
|
||||
from string import maketrans, translate
|
||||
import dbus
|
||||
import socket, fcntl
|
||||
import shutil
|
||||
|
||||
import wpath
|
||||
import misc
|
||||
@@ -333,21 +334,25 @@ class BaseInterface(object):
|
||||
client_dict = {
|
||||
"dhclient" :
|
||||
{'connect' : r"%(cmd)s -cf %(dhclientconf)s %(iface)s",
|
||||
'connect_with_hostname' : r"%(cmd)s -cf %(dhclientconf)s %(iface)s",
|
||||
'release' : r"%(cmd)s -r %(iface)s",
|
||||
'id' : misc.DHCLIENT,
|
||||
},
|
||||
"pump" :
|
||||
{ 'connect' : r"%(cmd)s -i %(iface)s -h %(hostname)s",
|
||||
{ 'connect' : r"%(cmd)s -i %(iface)s",
|
||||
'connect_with_hostname' : r"%(cmd)s -i %(iface)s -h %(hostname)s",
|
||||
'release' : r"%(cmd)s -r -i %(iface)s",
|
||||
'id' : misc.PUMP,
|
||||
},
|
||||
"dhcpcd" :
|
||||
{'connect' : r"%(cmd)s -h %(hostname)s --noipv4ll %(iface)s ",
|
||||
{'connect' : r"%(cmd)s --noipv4ll %(iface)s",
|
||||
'connect_with_hostname' : r"%(cmd)s -h %(hostname)s --noipv4ll %(iface)s ",
|
||||
'release' : r"%(cmd)s -k %(iface)s",
|
||||
'id' : misc.DHCPCD,
|
||||
},
|
||||
"udhcpc":
|
||||
{'connect' : r"%(cmd)s -n -i %(iface)s -H %(hostname)s ",
|
||||
{'connect' : r"%(cmd)s -n -i %(iface)s",
|
||||
'connect_with_hostname' : r"%(cmd)s -n -i %(iface)s -H %(hostname)s ",
|
||||
'release' : r"killall -SIGUSR2 %(cmd)s",
|
||||
'id' : misc.UDHCPC,
|
||||
},
|
||||
@@ -357,24 +362,25 @@ class BaseInterface(object):
|
||||
# cause dhclient doesn't have a handy dandy argument
|
||||
# for specifing the hostname to be sent
|
||||
if client_name == "dhclient" and flavor:
|
||||
if hostname == None:
|
||||
# <hostname> will use the system hostname
|
||||
# we'll use that if there is hostname passed
|
||||
# that shouldn't happen, though
|
||||
hostname = '<hostname>'
|
||||
print 'attempting to set hostname with dhclient'
|
||||
print 'using dhcpcd or another supported client may work better'
|
||||
dhclient_template = \
|
||||
open(os.path.join(wpath.etc, 'dhclient.conf.template'), 'r')
|
||||
if hostname:
|
||||
print 'attempting to set hostname with dhclient'
|
||||
print 'using dhcpcd or another supported client may work better'
|
||||
|
||||
output_conf = open(dhclient_conf_path, 'w')
|
||||
dhclient_template = \
|
||||
open(os.path.join(wpath.etc, 'dhclient.conf.template'), 'r')
|
||||
output_conf = open(dhclient_conf_path, 'w')
|
||||
|
||||
for line in dhclient_template.readlines():
|
||||
line = line.replace('$_HOSTNAME', hostname)
|
||||
output_conf.write(line)
|
||||
for line in dhclient_template.readlines():
|
||||
line = line.replace('# <WICDHOSTNAME>', 'send host-name "%s";' \
|
||||
% hostname)
|
||||
output_conf.write(line)
|
||||
|
||||
output_conf.close()
|
||||
dhclient_template.close()
|
||||
else:
|
||||
shutil.copy(os.path.join(wpath.etc, 'dhclient.conf.template'), \
|
||||
dhclient_conf_path)
|
||||
|
||||
output_conf.close()
|
||||
dhclient_template.close()
|
||||
os.chmod(dhclient_conf_path, 0644)
|
||||
|
||||
if not client_name or not cmd:
|
||||
@@ -382,13 +388,17 @@ class BaseInterface(object):
|
||||
return ""
|
||||
|
||||
if flavor == "connect":
|
||||
if not hostname:
|
||||
hostname = os.uname()[1]
|
||||
return client_dict[client_name]['connect'] % \
|
||||
if hostname:
|
||||
return client_dict[client_name]['connect_with_hostname'] % \
|
||||
{ "cmd" : cmd,
|
||||
"iface" : self.iface,
|
||||
"hostname" : hostname,
|
||||
'dhclientconf' : dhclient_conf_path }
|
||||
else:
|
||||
return client_dict[client_name]['connect'] % \
|
||||
{ "cmd" : cmd,
|
||||
"iface" : self.iface,
|
||||
'dhclientconf' : dhclient_conf_path }
|
||||
elif flavor == "release":
|
||||
return client_dict[client_name]['release'] % \
|
||||
{"cmd": cmd, "iface": self.iface}
|
||||
|
||||
Reference in New Issue
Block a user