1
0
mirror of https://github.com/gryf/wicd.git synced 2026-02-20 08:55:45 +01:00

merged dhcp-hostnames

This commit is contained in:
Adam Blackburn
2009-11-21 11:47:02 -06:00
8 changed files with 102 additions and 64 deletions

View File

@@ -27,6 +27,7 @@ import wicd.misc as misc
from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool from wicd.misc import noneToString, stringToNone, noneToBlankString, to_bool
from wicd.translations import language from wicd.translations import language
import sys
daemon = None daemon = None
wired = None wired = None
@@ -58,6 +59,8 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
dns2_t = ('editcp',language['dns']+ ' 2'+':'+' '*8) dns2_t = ('editcp',language['dns']+ ' 2'+':'+' '*8)
dns3_t = ('editcp',language['dns']+ ' 3'+':'+' '*8) dns3_t = ('editcp',language['dns']+ ' 3'+':'+' '*8)
dhcp_h_t = ('editcp',"DHCP Hostname:")
cancel_t = 'Cancel' cancel_t = 'Cancel'
ok_t = 'OK' ok_t = 'OK'
@@ -80,6 +83,8 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self.dns2 = DynWrap(urwid.Edit(dns2_t) ,False) self.dns2 = DynWrap(urwid.Edit(dns2_t) ,False)
self.dns3 = DynWrap(urwid.Edit(dns3_t) ,False) self.dns3 = DynWrap(urwid.Edit(dns3_t) ,False)
self.dhcp_h = urwid.AttrWrap(urwid.Edit(dhcp_h_t),'editbx','editfc')
_blank = urwid.Text('') _blank = urwid.Text('')
walker = urwid.SimpleListWalker([self.static_ip_cb, walker = urwid.SimpleListWalker([self.static_ip_cb,
@@ -89,7 +94,10 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
_blank, _blank,
self.checkb_cols, self.checkb_cols,
self.dns_dom_edit,self.search_dom_edit, self.dns_dom_edit,self.search_dom_edit,
self.dns1,self.dns2,self.dns3 self.dns1,self.dns2,self.dns3,
_blank,
self.dhcp_h,
_blank
]) ])
@@ -164,6 +172,7 @@ class AdvancedSettingsDialog(urwid.WidgetWrap):
self.set_net_prop("dns1", '') self.set_net_prop("dns1", '')
self.set_net_prop("dns2", '') self.set_net_prop("dns2", '')
self.set_net_prop("dns3", '') self.set_net_prop("dns3", '')
self.set_net_prop('dhcphostname',self.dhcp_h.get_edit_text())
# Prevent comboboxes from dying. # Prevent comboboxes from dying.
def ready_widgets(self,ui,body): def ready_widgets(self,ui,body):
pass pass
@@ -203,6 +212,12 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
self.set_default.set_state(to_bool(wired.GetWiredProperty("default"))) self.set_default.set_state(to_bool(wired.GetWiredProperty("default")))
dhcphname = wired.GetWiredProperty("dhcphostname")
if dhcphname is None:
dhcphname = os.uname()[1]
self.dhcp_h.set_edit_text(unicode(dhcphname))
def save_settings(self): def save_settings(self):
AdvancedSettingsDialog.save_settings(self) AdvancedSettingsDialog.save_settings(self)
if self.set_default.get_state(): if self.set_default.get_state():
@@ -304,6 +319,10 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.encryption_combo.set_focus(0) self.encryption_combo.set_focus(0)
self.change_encrypt_method() self.change_encrypt_method()
dhcphname = wireless.GetWirelessProperty(networkID,"dhcphostname")
if dhcphname is None:
dhcphname = os.uname()[1]
self.dhcp_h.set_edit_text(unicode(dhcphname))
def set_net_prop(self, option, value): def set_net_prop(self, option, value):

View File

@@ -104,17 +104,14 @@ class PrefsDialog(urwid.WidgetWrap):
flush2_t = 'route' flush2_t = 'route'
#### Advanced Settings #### Advanced Settings
#wpa_t=('editcp',language['wpa_supplicant_driver']+':')
wpa_cat_t=('header', language['wpa_supplicant']) wpa_cat_t=('header', language['wpa_supplicant'])
wpa_t=('editcp','Driver:') wpa_t=('editcp','Driver:')
wpa_list = ['spam','double spam','triple spam','quadruple spam'] wpa_list = []
wpa_warn_t = ('important', language['always_use_wext']) wpa_warn_t = ('important', language['always_use_wext'])
backend_cat_t = ('header', language['backend']) backend_cat_t = ('header', language['backend'])
backend_t = language['backend']+':' backend_t = language['backend']+':'
backend_list = ['spam','double spam','triple spam','quadruple spam'] backend_list = []
#backend_warn_t = ('important',
# 'Changes to the backend (probably) requires a daemon restart')
debug_cat_t = ('header', language['debugging']) debug_cat_t = ('header', language['debugging'])
debug_mode_t = language['use_debug_mode'] debug_mode_t = language['use_debug_mode']
@@ -204,7 +201,8 @@ class PrefsDialog(urwid.WidgetWrap):
self.flush_l = [self.flush0,self.flush1,self.flush2] self.flush_l = [self.flush0,self.flush1,self.flush2]
externalLB = urwid.ListBox([self.dhcp_header, externalLB = urwid.ListBox([self.dhcp_header,
self.dhcp0,self.dhcp2,self.dhcp3,self.dhcp1,self.dhcp4, self.dhcp0,self.dhcp2,self.dhcp3,self.dhcp1,
self.dhcp4,
_blank, _blank,
self.wired_detect_header, self.wired_detect_header,
self.wired0,self.wired1,self.wired2, self.wired0,self.wired1,self.wired2,

View File

@@ -192,9 +192,9 @@ def about_dialog(body):
('green',"\\|| \\\\")," |+| ",('green',"// ||/ \n"), ('green',"\\|| \\\\")," |+| ",('green',"// ||/ \n"),
('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net\n", ('green'," \\\\\\")," |+| ",('green',"///")," http://wicd.net\n",
('green'," \\\\\\")," |+| ",('green',"///")," ",language["brought_to_you"],"\n", ('green'," \\\\\\")," |+| ",('green',"///")," ",language["brought_to_you"],"\n",
('green'," \\\\\\")," |+| ",('green',"///")," Adam Blackburn (wicd)\n", ('green'," \\\\\\")," |+| ",('green',"///")," Adam Blackburn\n",
" ___|+|___ Dan O'Reilly (wicd)\n", " ___|+|___ Dan O'Reilly\n",
" |---------| Andrew Psaltis (this ui)\n", " |---------| Andrew Psaltis\n",
"-----------------------------------------------------"] "-----------------------------------------------------"]
about = TextDialog(theText,16,55,header=('header','About Wicd')) about = TextDialog(theText,16,55,header=('header','About Wicd'))
about.run(ui,body) about.run(ui,body)

View File

@@ -307,7 +307,7 @@ class appGui(object):
dialog = gtk.AboutDialog() dialog = gtk.AboutDialog()
dialog.set_name("Wicd") dialog.set_name("Wicd")
dialog.set_version(daemon.Hello()) dialog.set_version(daemon.Hello())
dialog.set_authors([ "Adam Blackburn", "Dan O'Reilly" ]) dialog.set_authors([ "Adam Blackburn", "Dan O'Reilly", "Andrew Psaltis" ])
dialog.set_website("http://wicd.sourceforge.net") dialog.set_website("http://wicd.sourceforge.net")
dialog.run() dialog.run()
dialog.destroy() dialog.destroy()

View File

@@ -8,6 +8,7 @@ contained within them.
# #
# Copyright (C) 2008-2009 Adam Blackburn # Copyright (C) 2008-2009 Adam Blackburn
# Copyright (C) 2008-2009 Dan O'Reilly # Copyright (C) 2008-2009 Dan O'Reilly
# Copyright (C) 2009 Andrew Psaltis
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 2 as # it under the terms of the GNU General Public License Version 2 as
@@ -73,6 +74,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.txt_dns_1 = LabelEntry(language['dns'] + ' 1') self.txt_dns_1 = LabelEntry(language['dns'] + ' 1')
self.txt_dns_2 = LabelEntry(language['dns'] + ' 2') self.txt_dns_2 = LabelEntry(language['dns'] + ' 2')
self.txt_dns_3 = LabelEntry(language['dns'] + ' 3') self.txt_dns_3 = LabelEntry(language['dns'] + ' 3')
self.txt_dhcp_hostname = LabelEntry("DHCP Hostname")
self.chkbox_static_ip = gtk.CheckButton(language['use_static_ip']) self.chkbox_static_ip = gtk.CheckButton(language['use_static_ip'])
self.chkbox_static_dns = gtk.CheckButton(language['use_static_dns']) self.chkbox_static_dns = gtk.CheckButton(language['use_static_dns'])
self.chkbox_global_dns = gtk.CheckButton(language['use_global_dns']) self.chkbox_global_dns = gtk.CheckButton(language['use_global_dns'])
@@ -104,6 +106,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
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)
self.vbox.pack_start(self.txt_dhcp_hostname, fill=False, expand=False)
self.vbox.pack_end(self.button_hbox, fill=False, expand=False, padding=5) self.vbox.pack_end(self.button_hbox, fill=False, expand=False, padding=5)
@@ -238,6 +241,7 @@ class AdvancedSettingsDialog(gtk.Dialog):
self.set_net_prop("dns1", '') self.set_net_prop("dns1", '')
self.set_net_prop("dns2", '') self.set_net_prop("dns2", '')
self.set_net_prop("dns3", '') self.set_net_prop("dns3", '')
self.set_net_prop("dhcphostname",noneToString(self.txt_dhcp_hostname.get_text()))
class WiredSettingsDialog(AdvancedSettingsDialog): class WiredSettingsDialog(AdvancedSettingsDialog):
@@ -279,6 +283,12 @@ class WiredSettingsDialog(AdvancedSettingsDialog):
self.txt_domain.set_text(self.format_entry("dns_domain")) self.txt_domain.set_text(self.format_entry("dns_domain"))
self.txt_search_dom.set_text(self.format_entry("search_domain")) self.txt_search_dom.set_text(self.format_entry("search_domain"))
self.chkbox_global_dns.set_active(bool(wired.GetWiredProperty("use_global_dns"))) self.chkbox_global_dns.set_active(bool(wired.GetWiredProperty("use_global_dns")))
dhcphname = wired.GetWiredProperty("dhcphostname")
if dhcphname is None:
dhcphname = os.uname()[1]
self.txt_dhcp_hostname.set_text(dhcphname)
self.reset_static_checkboxes() self.reset_static_checkboxes()
def save_settings(self): def save_settings(self):
@@ -395,6 +405,11 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
self.chkbox_global_settings.set_active(bool(wireless.GetWirelessProperty(networkID, self.chkbox_global_settings.set_active(bool(wireless.GetWirelessProperty(networkID,
'use_settings_globally'))) 'use_settings_globally')))
dhcphname = wireless.GetWirelessProperty(networkID,"dhcphostname")
if dhcphname is None:
dhcphname = os.uname()[1]
self.txt_dhcp_hostname.set_text(dhcphname)
activeID = -1 # Set the menu to this item when we are done activeID = -1 # Set the menu to this item when we are done
user_enctype = wireless.GetWirelessProperty(networkID, "enctype") user_enctype = wireless.GetWirelessProperty(networkID, "enctype")
for x, enc_type in enumerate(self.encrypt_types): for x, enc_type in enumerate(self.encrypt_types):

View File

@@ -22,6 +22,7 @@ class WiredConnectThread() -- Connection thread for wired
# Copyright (C) 2007 - 2009 Adam Blackburn # Copyright (C) 2007 - 2009 Adam Blackburn
# Copyright (C) 2007 - 2009 Dan O'Reilly # Copyright (C) 2007 - 2009 Dan O'Reilly
# Copyright (C) 2007 - 2009 Byron Hillis # Copyright (C) 2007 - 2009 Byron Hillis
# Copyright (C) 2009 Andrew Psaltis
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 2 as # it under the terms of the GNU General Public License Version 2 as
@@ -290,7 +291,8 @@ class ConnectThread(threading.Thread):
def __init__(self, network, interface_name, before_script, after_script, def __init__(self, network, interface_name, before_script, after_script,
pre_disconnect_script, post_disconnect_script, gdns1, pre_disconnect_script, post_disconnect_script, gdns1,
gdns2, gdns3, gdns_dom, gsearch_dom, iface, debug): gdns2, gdns3, gdns_dom, gsearch_dom, iface,
debug):
""" Initialise the required object variables and the thread. """ Initialise the required object variables and the thread.
Keyword arguments: Keyword arguments:
@@ -446,8 +448,8 @@ class ConnectThread(threading.Thread):
else: else:
# Run dhcp... # Run dhcp...
self.SetStatus('running_dhcp') self.SetStatus('running_dhcp')
print "Running DHCP" print "Running DHCP with hostname",self.network["dhcphostname"]
dhcp_status = iface.StartDHCP() dhcp_status = iface.StartDHCP(self.network["dhcphostname"])
if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']: if dhcp_status in ['no_dhcp_offers', 'dhcp_failed']:
if self.connect_result != "aborted": if self.connect_result != "aborted":
self.abort_connection(dhcp_status) self.abort_connection(dhcp_status)
@@ -1059,7 +1061,8 @@ class WiredConnectThread(ConnectThread):
ConnectThread.__init__(self, network, wired, before_script, ConnectThread.__init__(self, network, wired, before_script,
after_script, pre_disconnect_script, after_script, pre_disconnect_script,
post_disconnect_script, gdns1, gdns2, post_disconnect_script, gdns1, gdns2,
gdns3, gdns_dom, gsearch_dom, liface, debug) gdns3, gdns_dom, gsearch_dom, liface,
debug)
def _connect(self): def _connect(self):
""" The main function of the connection thread. """ The main function of the connection thread.

View File

@@ -18,6 +18,7 @@ class WirelessDaemon() -- DBus interface to managed the wireless network.
# Copyright (C) 2007 - 2009 Adam Blackburn # Copyright (C) 2007 - 2009 Adam Blackburn
# Copyright (C) 2007 - 2009 Dan O'Reilly # Copyright (C) 2007 - 2009 Dan O'Reilly
# Copyright (C) 2007 - 2009 Byron Hillis # Copyright (C) 2007 - 2009 Byron Hillis
# Copyright (C) 2009 Andrew Psaltis
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 2 as # it under the terms of the GNU General Public License Version 2 as
@@ -1459,6 +1460,7 @@ class WiredDaemon(dbus.service.Object):
"postdisconnectscript"]: "postdisconnectscript"]:
self.config.set(profilename, option, None) self.config.set(profilename, option, None)
self.config.set(profilename, "default", default) self.config.set(profilename, "default", default)
self.config.set(profilename,"dhcphostname",os.uname()[1])
self.config.write() self.config.write()
return True return True

View File

@@ -16,6 +16,7 @@ class BaseWirelessInterface() -- Control a wireless network interface.
# Copyright (C) 2007 - 2009 Adam Blackburn # Copyright (C) 2007 - 2009 Adam Blackburn
# Copyright (C) 2007 - 2009 Dan O'Reilly # Copyright (C) 2007 - 2009 Dan O'Reilly
# Copyright (C) 2007 - 2009 Byron Hillis # Copyright (C) 2007 - 2009 Byron Hillis
# Copyright (C) 2009 Andrew Psaltis
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License Version 2 as # it under the terms of the GNU General Public License Version 2 as
@@ -241,7 +242,7 @@ class BaseInterface(object):
return path return path
def _get_dhcp_command(self, flavor=None): def _get_dhcp_command(self, flavor=None, hostname=None):
""" Returns the correct DHCP client command. """ Returns the correct DHCP client command.
Given a type of DHCP request (create or release a lease), Given a type of DHCP request (create or release a lease),
@@ -277,17 +278,17 @@ class BaseInterface(object):
'id' : misc.DHCLIENT, 'id' : misc.DHCLIENT,
}, },
"pump" : "pump" :
{ 'connect' : r"%(cmd)s -i %(iface)s", { 'connect' : r"%(cmd)s -i %(iface)s -h %(hostname)s",
'release' : r"%(cmd)s -r -i %(iface)s", 'release' : r"%(cmd)s -r -i %(iface)s",
'id' : misc.PUMP, 'id' : misc.PUMP,
}, },
"dhcpcd" : "dhcpcd" :
{'connect' : r"%(cmd)s %(iface)s", {'connect' : r"%(cmd)s %(iface)s -h %(hostname)s ",
'release' : r"%(cmd)s -k %(iface)s", 'release' : r"%(cmd)s -k %(iface)s",
'id' : misc.DHCPCD, 'id' : misc.DHCPCD,
}, },
"udhcpc": "udhcpc":
{'connect' : r"%(cmd)s -n -i %(iface)s", {'connect' : r"%(cmd)s -n -i %(iface)s -H %(hostname)s ",
'release' : r"killall -SIGUSR2 %(cmd)s", 'release' : r"killall -SIGUSR2 %(cmd)s",
'id' : misc.UDHCPC, 'id' : misc.UDHCPC,
}, },
@@ -298,7 +299,7 @@ class BaseInterface(object):
return "" return ""
if flavor == "connect": if flavor == "connect":
return client_dict[client_name]['connect'] % {"cmd":cmd, "iface":self.iface} return client_dict[client_name]['connect'] % {"cmd":cmd, "iface":self.iface, "hostname":hostname}
elif flavor == "release": elif flavor == "release":
return client_dict[client_name]['release'] % {"cmd":cmd, "iface":self.iface} return client_dict[client_name]['release'] % {"cmd":cmd, "iface":self.iface}
else: else:
@@ -549,7 +550,7 @@ class BaseInterface(object):
return 'dhcp_failed' return 'dhcp_failed'
@neediface(False) @neediface(False)
def StartDHCP(self): def StartDHCP(self,hostname):
""" Start the DHCP client to obtain an IP address. """ Start the DHCP client to obtain an IP address.
Returns: Returns:
@@ -557,7 +558,7 @@ class BaseInterface(object):
_check_dhcp_result for the possible values. _check_dhcp_result for the possible values.
""" """
cmd = self._get_dhcp_command('connect') cmd = self._get_dhcp_command('connect',hostname)
if self.verbose: print cmd if self.verbose: print cmd
self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True) self.dhcp_object = misc.Run(cmd, include_stderr=True, return_obj=True)
pipe = self.dhcp_object.stdout pipe = self.dhcp_object.stdout