mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
fixed global DNS
This commit is contained in:
25
daemon.py
25
daemon.py
@@ -1,4 +1,10 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
############
|
||||||
|
## USES 4 SPACES FOR INDENT
|
||||||
|
## NO TABS
|
||||||
|
############
|
||||||
|
|
||||||
#change to the directory that the file lives in
|
#change to the directory that the file lives in
|
||||||
import os,sys
|
import os,sys
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -40,8 +46,9 @@ import misc
|
|||||||
#
|
#
|
||||||
# This is released under the
|
# This is released under the
|
||||||
# GNU General Public License
|
# GNU General Public License
|
||||||
|
#
|
||||||
# The terms can be found at
|
# The terms can be found at
|
||||||
# http://www.gnu.org/copyleft/gpl.html
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 Adam Blackburn
|
# Copyright (C) 2007 Adam Blackburn
|
||||||
###############################
|
###############################
|
||||||
@@ -222,6 +229,7 @@ class ConnectionWizard(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
|
||||||
|
print 'global dns servers are',dns1,dns2,dns3
|
||||||
configfile = open(self.app_conf,"w")
|
configfile = open(self.app_conf,"w")
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
#end function SetWirelessInterface
|
#end function SetWirelessInterface
|
||||||
@@ -775,7 +783,6 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
print self.LastScan[id]["bssid"]
|
print self.LastScan[id]["bssid"]
|
||||||
if config.has_section(self.LastScan[id]["bssid"]):
|
if config.has_section(self.LastScan[id]["bssid"]):
|
||||||
self.LastScan[id]["has_profile"] = True
|
self.LastScan[id]["has_profile"] = True
|
||||||
|
|
||||||
if config.has_option(self.LastScan[id]["bssid"],"beforescript"):
|
if config.has_option(self.LastScan[id]["bssid"],"beforescript"):
|
||||||
self.LastScan[id]["beforescript"]=misc.Noneify(config.get(self.LastScan[id]["bssid"],"beforescript"))
|
self.LastScan[id]["beforescript"]=misc.Noneify(config.get(self.LastScan[id]["bssid"],"beforescript"))
|
||||||
else:
|
else:
|
||||||
@@ -788,13 +795,14 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
#wireless networks now - but only read it if it is hidden
|
#wireless networks now - but only read it if it is hidden
|
||||||
if self.LastScan[id]["hidden"] == True:
|
if self.LastScan[id]["hidden"] == True:
|
||||||
self.LastScan[id]["essid"] = misc.Noneify(config.get(self.LastScan[id]["bssid"],"essid"))
|
self.LastScan[id]["essid"] = misc.Noneify(config.get(self.LastScan[id]["bssid"],"essid"))
|
||||||
|
|
||||||
for x in config.options(self.LastScan[id]["bssid"]):
|
for x in config.options(self.LastScan[id]["bssid"]):
|
||||||
if self.LastScan[id].has_key(x) == False:
|
if self.LastScan[id].has_key(x) == False:
|
||||||
self.LastScan[id][x] = misc.Noneify(config.get(self.LastScan[id]["bssid"],x))
|
self.LastScan[id][x] = misc.Noneify(config.get(self.LastScan[id]["bssid"],x))
|
||||||
return "100: Loaded Profile"
|
return "100: Loaded Profile"
|
||||||
else:
|
else:
|
||||||
self.LastScan[id]["has_profile"] = False
|
self.LastScan[id]["has_profile"] = False
|
||||||
|
self.LastScan[id]['use_static_dns'] = bool(int(self.GetUseGlobalDNS()))
|
||||||
|
self.LastScan[id]['use_global_dns'] = bool(int(self.GetUseGlobalDNS()))
|
||||||
return "500: Profile Not Found"
|
return "500: Profile Not Found"
|
||||||
#end function ReadWirelessNetworkProfile
|
#end function ReadWirelessNetworkProfile
|
||||||
|
|
||||||
@@ -855,10 +863,6 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
else:
|
else:
|
||||||
self.debug_mode = False
|
self.debug_mode = False
|
||||||
config.set("Settings","debug_mode","False")
|
config.set("Settings","debug_mode","False")
|
||||||
if config.has_option('Settings','dns1') and config.has_option('Settings','dns2') and config.has_option('Settings','dns3'):
|
|
||||||
self.SetGlobalDNS(config.get('Settings','dns1'),config.get('Settings','dns2'),config.get('Settings','dns3'))
|
|
||||||
else:
|
|
||||||
self.SetGlobalDNS("None","None","None")
|
|
||||||
else:
|
else:
|
||||||
print "configuration file exists, no settings found, adding defaults..."
|
print "configuration file exists, no settings found, adding defaults..."
|
||||||
configfile = open(self.app_conf,"w")
|
configfile = open(self.app_conf,"w")
|
||||||
@@ -950,8 +954,9 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
#end function ReadConfig
|
#end function ReadConfig
|
||||||
|
|
||||||
## fork from the parent terminal
|
## fork from the parent terminal
|
||||||
|
## borrowed from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012
|
||||||
|
|
||||||
if True: #for easy disabling
|
if False: #True: #for easy disabling
|
||||||
try:
|
try:
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
if pid > 0:
|
if pid > 0:
|
||||||
@@ -979,8 +984,8 @@ if True: #for easy disabling
|
|||||||
#kill output
|
#kill output
|
||||||
#POI:500 stdout redirection
|
#POI:500 stdout redirection
|
||||||
output = FlushWriter()
|
output = FlushWriter()
|
||||||
sys.stdout = output #open("data/wicd.log","w")
|
#sys.stdout = output #open("data/wicd.log","w")
|
||||||
sys.stderr = output
|
#sys.stderr = output
|
||||||
|
|
||||||
print "---------------------------"
|
print "---------------------------"
|
||||||
print "wicd initalizing..."
|
print "wicd initalizing..."
|
||||||
|
|||||||
26
gui.py
26
gui.py
@@ -400,6 +400,8 @@ class NetworkEntry(gtk.Expander):
|
|||||||
#start with all disabled, then they will be enabled later
|
#start with all disabled, then they will be enabled later
|
||||||
self.checkboxStaticIP.set_active(False)
|
self.checkboxStaticIP.set_active(False)
|
||||||
self.checkboxStaticDNS.set_active(False)
|
self.checkboxStaticDNS.set_active(False)
|
||||||
|
print 'using global dns:',daemon.GetUseGlobalDNS()
|
||||||
|
#self.checkboxGlobalDNS.set_active(bool(int(daemon.GetUseGlobalDNS())))
|
||||||
|
|
||||||
def setDefaults(self,widget=None,event=None):
|
def setDefaults(self,widget=None,event=None):
|
||||||
#after the user types in the IP address,
|
#after the user types in the IP address,
|
||||||
@@ -442,6 +444,7 @@ class NetworkEntry(gtk.Expander):
|
|||||||
#unused boxes
|
#unused boxes
|
||||||
self.toggleIPCheckbox()
|
self.toggleIPCheckbox()
|
||||||
self.toggleDNSCheckbox()
|
self.toggleDNSCheckbox()
|
||||||
|
self.toggleGlobalDNSCheckbox()
|
||||||
|
|
||||||
def toggleIPCheckbox(self,widget=None):
|
def toggleIPCheckbox(self,widget=None):
|
||||||
#should disable the static IP text boxes
|
#should disable the static IP text boxes
|
||||||
@@ -459,13 +462,14 @@ class NetworkEntry(gtk.Expander):
|
|||||||
self.txtGateway.set_sensitive(self.checkboxStaticIP.get_active())
|
self.txtGateway.set_sensitive(self.checkboxStaticIP.get_active())
|
||||||
|
|
||||||
def toggleDNSCheckbox(self,widget=None):
|
def toggleDNSCheckbox(self,widget=None):
|
||||||
|
print 'dns checkbox toggled',self.checkboxStaticDNS.get_active()
|
||||||
#should disable the static DNS boxes
|
#should disable the static DNS boxes
|
||||||
if self.checkboxStaticIP.get_active() == True:
|
if self.checkboxStaticIP.get_active() == True:
|
||||||
self.checkboxStaticDNS.set_active(self.checkboxStaticIP.get_active())
|
self.checkboxStaticDNS.set_active(self.checkboxStaticIP.get_active())
|
||||||
self.checkboxStaticDNS.set_sensitive(False)
|
self.checkboxStaticDNS.set_sensitive(False)
|
||||||
|
|
||||||
self.checkboxGlobalDNS.set_sensitive(self.checkboxStaticDNS.get_active())
|
self.checkboxGlobalDNS.set_sensitive(self.checkboxStaticDNS.get_active())
|
||||||
if self.checkboxStaticDNS.get_active():
|
if self.checkboxStaticDNS.get_active() == True:
|
||||||
self.txtDNS1.set_sensitive(not self.checkboxGlobalDNS.get_active()) #if global dns is on, use local dns
|
self.txtDNS1.set_sensitive(not self.checkboxGlobalDNS.get_active()) #if global dns is on, use local dns
|
||||||
self.txtDNS2.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
self.txtDNS2.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
||||||
self.txtDNS3.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
self.txtDNS3.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
||||||
@@ -475,6 +479,7 @@ class NetworkEntry(gtk.Expander):
|
|||||||
self.txtDNS3.set_sensitive(False)
|
self.txtDNS3.set_sensitive(False)
|
||||||
|
|
||||||
def toggleGlobalDNSCheckbox(self,widget=None):
|
def toggleGlobalDNSCheckbox(self,widget=None):
|
||||||
|
self.checkboxStaticDNS.set_active(True)
|
||||||
self.txtDNS1.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
self.txtDNS1.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
||||||
self.txtDNS2.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
self.txtDNS2.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
||||||
self.txtDNS3.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
self.txtDNS3.set_sensitive(not self.checkboxGlobalDNS.get_active())
|
||||||
@@ -643,6 +648,9 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
self.txtNetmask.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"netmask")))
|
self.txtNetmask.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"netmask")))
|
||||||
self.txtGateway.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"gateway")))
|
self.txtGateway.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"gateway")))
|
||||||
|
|
||||||
|
if wireless.GetWirelessProperty(networkID,'use_global_dns'):
|
||||||
|
self.checkboxGlobalDNS.set_active(True)
|
||||||
|
|
||||||
if wireless.GetWirelessProperty(networkID,"dns1") != None:
|
if wireless.GetWirelessProperty(networkID,"dns1") != None:
|
||||||
self.txtDNS1.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"dns1")))
|
self.txtDNS1.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"dns1")))
|
||||||
|
|
||||||
@@ -881,9 +889,9 @@ class appGui:
|
|||||||
dns_addresses = daemon.GetGlobalDNSAddresses()
|
dns_addresses = daemon.GetGlobalDNSAddresses()
|
||||||
|
|
||||||
useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
|
useGlobalDNSCheckbox.set_active(daemon.GetUseGlobalDNS())
|
||||||
dns1Entry.set_text(dns_addresses[0])
|
dns1Entry.set_text(noneToBlankString(dns_addresses[0]))
|
||||||
dns2Entry.set_text(dns_addresses[1])
|
dns2Entry.set_text(noneToBlankString(dns_addresses[1]))
|
||||||
dns3Entry.set_text(dns_addresses[2])
|
dns3Entry.set_text(noneToBlankString(dns_addresses[2]))
|
||||||
|
|
||||||
dialog.vbox.pack_start(wpabox)
|
dialog.vbox.pack_start(wpabox)
|
||||||
dialog.vbox.pack_start(entryWirelessInterface)
|
dialog.vbox.pack_start(entryWirelessInterface)
|
||||||
@@ -1051,16 +1059,16 @@ class appGui:
|
|||||||
wireless.SetWirelessProperty(networkid,"gateway",'')
|
wireless.SetWirelessProperty(networkid,"gateway",'')
|
||||||
|
|
||||||
if networkentry.expander.checkboxStaticDNS.get_active() == True and networkentry.expander.checkboxGlobalDNS.get_active() == False:
|
if networkentry.expander.checkboxStaticDNS.get_active() == True and networkentry.expander.checkboxGlobalDNS.get_active() == False:
|
||||||
wireless.SetWirelessProperty(networkid,'global_dns',False)
|
wireless.SetWirelessProperty(networkid,'use_static_dns',True)
|
||||||
wireless.SetWirelessProperty(networkid,'static_dns',True)
|
wireless.SetWirelessProperty(networkid,'use_global_dns',False)
|
||||||
wireless.SetWirelessProperty(networkid,'dns1',noneToString(networkentry.expander.txtDNS1.get_text()))
|
wireless.SetWirelessProperty(networkid,'dns1',noneToString(networkentry.expander.txtDNS1.get_text()))
|
||||||
wireless.SetWirelessProperty(networkid,'dns2',noneToString(networkentry.expander.txtDNS2.get_text()))
|
wireless.SetWirelessProperty(networkid,'dns2',noneToString(networkentry.expander.txtDNS2.get_text()))
|
||||||
wireless.SetWirelessProperty(networkid,'dns3',noneToString(networkentry.expander.txtDNS3.get_text()))
|
wireless.SetWirelessProperty(networkid,'dns3',noneToString(networkentry.expander.txtDNS3.get_text()))
|
||||||
elif networkentry.expander.checkboxStaticDNS.get_active() == True and networkentry.expander.checkboxGlobalDNS.get_active() == True:
|
elif networkentry.expander.checkboxStaticDNS.get_active() == True and networkentry.expander.checkboxGlobalDNS.get_active() == True:
|
||||||
wireless.SetWirelessProperty(networkid,'static_dns',True)
|
wireless.SetWirelessProperty(networkid,'use_static_dns',True)
|
||||||
wireless.SetWirelessProperty(networkid,'global_dns',True)
|
wireless.SetWirelessProperty(networkid,'use_global_dns',True)
|
||||||
else:
|
else:
|
||||||
wireless.SetWirelessProperty(networkid,'static_dns',False) #disable static dns
|
wireless.SetWirelessProperty(networkid,'use_static_dns',False) #disable static dns
|
||||||
|
|
||||||
if networkentry.expander.checkboxEncryption.get_active() == True:
|
if networkentry.expander.checkboxEncryption.get_active() == True:
|
||||||
print "setting encryption info..."
|
print "setting encryption info..."
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ class Wireless:
|
|||||||
|
|
||||||
def Connect(self,network):
|
def Connect(self,network):
|
||||||
#call the thread, so we don't hang up the entire works
|
#call the thread, so we don't hang up the entire works
|
||||||
self.ConnectingThread = self.ConnectThread(network,self.wireless_interface,self.wired_interface,self.wpa_driver,self.before_script,self.after_script)
|
self.ConnectingThread = self.ConnectThread(network,self.wireless_interface,self.wired_interface,self.wpa_driver,self.before_script,self.after_script,self.global_dns_1,self.global_dns_2,self.global_dns_3)
|
||||||
self.ConnectingThread.start()
|
self.ConnectingThread.start()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ class Wireless:
|
|||||||
ShouldDie = False
|
ShouldDie = False
|
||||||
lock = thread.allocate_lock()
|
lock = thread.allocate_lock()
|
||||||
|
|
||||||
def __init__(self,network,wireless,wired,wpa_driver,before_script,after_script):
|
def __init__(self,network,wireless,wired,wpa_driver,before_script,after_script,gdns1,gdns2,gdns3):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.network = network
|
self.network = network
|
||||||
self.wireless_interface = wireless
|
self.wireless_interface = wireless
|
||||||
@@ -231,6 +231,10 @@ class Wireless:
|
|||||||
self.before_script = before_script
|
self.before_script = before_script
|
||||||
self.after_script = after_script
|
self.after_script = after_script
|
||||||
|
|
||||||
|
self.global_dns_1 = gdns1
|
||||||
|
self.global_dns_2 = gdns2
|
||||||
|
self.global_dns_3 = gdns3
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
self.ConnectingMessage = 'interface_down'
|
self.ConnectingMessage = 'interface_down'
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
@@ -382,50 +386,6 @@ class Wireless:
|
|||||||
print "setting the broadcast address..." + network["broadcast"]
|
print "setting the broadcast address..." + network["broadcast"]
|
||||||
misc.Run("ifconfig " + self.wireless_interface + " broadcast " + network["broadcast"])
|
misc.Run("ifconfig " + self.wireless_interface + " broadcast " + network["broadcast"])
|
||||||
|
|
||||||
|
|
||||||
if not network.get("dns1") == None:
|
|
||||||
self.lock.acquire()
|
|
||||||
self.ConnectingMessage = 'setting_static_dns'
|
|
||||||
self.lock.release()
|
|
||||||
|
|
||||||
print "setting the first dns server...", network["dns1"]
|
|
||||||
resolv = open("/etc/resolv.conf","w")
|
|
||||||
misc.WriteLine(resolv,"nameserver " + network["dns1"])
|
|
||||||
if not network.get("dns2") == None:
|
|
||||||
print "setting the second dns server...", network["dns2"]
|
|
||||||
misc.WriteLine(resolv,"nameserver " + network["dns2"])
|
|
||||||
if not network.get("dns3") == None:
|
|
||||||
print "setting the third dns server..."
|
|
||||||
misc.WriteLine(resolv,"nameserver " + network["dns3"])
|
|
||||||
if network.get('static_dns') == True and network.get('global_dns') == False:
|
|
||||||
if not network.get("dns1") == None:
|
|
||||||
self.lock.acquire()
|
|
||||||
self.ConnectingMessage = 'setting_static_dns'
|
|
||||||
self.lock.release()
|
|
||||||
print "setting the first dns server...", network["dns1"]
|
|
||||||
resolv = open("/etc/resolv.conf","w")
|
|
||||||
misc.WriteLine(resolv,"nameserver " + network["dns1"])
|
|
||||||
if not network.get("dns2") == None:
|
|
||||||
print "setting the second dns server...", network["dns2"]
|
|
||||||
misc.WriteLine(resolv,"nameserver " + network["dns2"])
|
|
||||||
if not network.get("dns3") == None:
|
|
||||||
print "setting the third dns server..."
|
|
||||||
misc.WriteLine(resolv,"nameserver " + network["dns3"])
|
|
||||||
else:
|
|
||||||
if not self.global_dns_1 == None:
|
|
||||||
self.lock.acquire()
|
|
||||||
self.ConnectingMessage = 'setting_static_dns'
|
|
||||||
self.lock.release()
|
|
||||||
print "setting the first dns server...", self.global_dns_1
|
|
||||||
resolv = open("/etc/resolv.conf","w")
|
|
||||||
misc.WriteLine(resolv,"nameserver " + self.global_dns_1)
|
|
||||||
if not self.global_dns_2 == None:
|
|
||||||
print "setting the second dns server...", self.global_dns_2
|
|
||||||
misc.WriteLine(resolv,"nameserver " + self.global_dns_2)
|
|
||||||
if not self.global_dns_3 == None:
|
|
||||||
print "setting the third dns server..."
|
|
||||||
misc.WriteLine(resolv,"nameserver " + self.global_dns_3)
|
|
||||||
|
|
||||||
if not network.get('ip') == None:
|
if not network.get('ip') == None:
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
self.ConnectingMessage = 'setting_static_ip'
|
self.ConnectingMessage = 'setting_static_ip'
|
||||||
@@ -446,6 +406,43 @@ class Wireless:
|
|||||||
if not self.ShouldDie:
|
if not self.ShouldDie:
|
||||||
misc.Run("dhclient " + self.wireless_interface)
|
misc.Run("dhclient " + self.wireless_interface)
|
||||||
|
|
||||||
|
#code repetition --- bad.
|
||||||
|
#however, I think this is the best way
|
||||||
|
|
||||||
|
if network.get('use_static_dns') == True and network.get('use_global_dns') == False:
|
||||||
|
#just using normal dns
|
||||||
|
if not network.get("dns1") == None:
|
||||||
|
self.lock.acquire()
|
||||||
|
self.ConnectingMessage = 'setting_static_dns'
|
||||||
|
self.lock.release()
|
||||||
|
print "setting the first dns server...", network["dns1"]
|
||||||
|
resolv = open("/etc/resolv.conf","w")
|
||||||
|
misc.WriteLine(resolv,"nameserver " + network["dns1"])
|
||||||
|
if not network.get("dns2") == None:
|
||||||
|
print "setting the second dns server...", network["dns2"]
|
||||||
|
misc.WriteLine(resolv,"nameserver " + network["dns2"])
|
||||||
|
if not network.get("dns3") == None:
|
||||||
|
print "setting the third dns server..."
|
||||||
|
misc.WriteLine(resolv,"nameserver " + network["dns3"])
|
||||||
|
resolv.close()
|
||||||
|
|
||||||
|
if network.get('use_static_dns') == True and network.get('use_global_dns') == True:
|
||||||
|
#using static dns
|
||||||
|
if not self.global_dns_1 == None:
|
||||||
|
self.lock.acquire()
|
||||||
|
self.ConnectingMessage = 'setting_static_dns'
|
||||||
|
self.lock.release()
|
||||||
|
print "setting the first dns server...", self.global_dns_1
|
||||||
|
resolv = open("/etc/resolv.conf","w")
|
||||||
|
misc.WriteLine(resolv,"nameserver " + self.global_dns_1)
|
||||||
|
if not misc.Noneify(self.global_dns_2) == None:
|
||||||
|
print "setting the second dns server...", self.global_dns_2
|
||||||
|
misc.WriteLine(resolv,"nameserver " + self.global_dns_2)
|
||||||
|
if not misc.Noneify(self.global_dns_3) == None:
|
||||||
|
print "setting the third dns server..."
|
||||||
|
misc.WriteLine(resolv,"nameserver " + self.global_dns_3)
|
||||||
|
resolv.close()
|
||||||
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
self.ConnectingMessage = 'done'
|
self.ConnectingMessage = 'done'
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|||||||
Reference in New Issue
Block a user