mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Added wired auto-connect profile chooser, fixed some bugs in the ralink legacy connection code, reorganized edgy.py and fixed some bugs in it, probably a few other things too
This commit is contained in:
263
daemon.py
263
daemon.py
@@ -111,6 +111,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.wifi = networking.Wireless()
|
||||
self.wired = networking.Wired()
|
||||
self.forced_disconnect = False
|
||||
self.need_profile_chooser = False
|
||||
|
||||
#load the config file - it should have most of the stuff we need to run...
|
||||
self.ReadConfig()
|
||||
@@ -119,7 +120,7 @@ class ConnectionWizard(dbus.service.Object):
|
||||
|
||||
#this will speed up the scanning process - if a client doesn't need a fresh scan, just
|
||||
#feed them the old one. a fresh scan can be done by calling FreshScan(self,interface)
|
||||
self.LastScan = None
|
||||
self.LastScan = ''
|
||||
|
||||
#make a variable that will hold the wired network profile
|
||||
self.WiredNetwork = {}
|
||||
@@ -269,95 +270,22 @@ class ConnectionWizard(dbus.service.Object):
|
||||
configfile = open(self.app_conf,"w")
|
||||
config.write(configfile)
|
||||
self.debug_mode = debug
|
||||
#end function SetDebugMode
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetDebugMode(self):
|
||||
'''returns whether debugging is enabled'''
|
||||
return bool(int(self.debug_mode))
|
||||
#end function GetDebugMode
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetGlobalDNSAddresses(self):
|
||||
'''returns the global dns addresses'''
|
||||
print 'returning global dns addresses to client'
|
||||
return (self.dns1,self.dns2,self.dns3)
|
||||
#end function GetWirelessInterface
|
||||
|
||||
########## WIRELESS FUNCTIONS
|
||||
#################################
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetHiddenNetworkESSID(self,essid):
|
||||
'''sets the ESSID of a hidden network for use with ConnectionWizard.Scan'''
|
||||
print 'setting hidden essid: ' + str(essid)
|
||||
self.hidden_essid = str(misc.Noneify(essid))
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def Scan(self):
|
||||
'''scans for wireless networks, optionally using a (hidden) essid set with SetHiddenNetworkESSID'''
|
||||
print 'scanning start'
|
||||
scan = self.wifi.Scan(str(self.hidden_essid)) #_should_ already be a string but you never know...
|
||||
self.LastScan = scan
|
||||
print 'scanning done'
|
||||
print 'found',str(len(scan)),'networks:',
|
||||
for i in scan:
|
||||
print i,
|
||||
self.ReadWirelessNetworkProfile(i)
|
||||
print
|
||||
#end function FreshScan
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def DisconnectWireless(self):
|
||||
'''disconnects all wireless networks'''
|
||||
self.SetForcedDisconnect(True)
|
||||
self.wifi.Disconnect()
|
||||
#end function DisconnectWireless
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetWirelessBeforeScript(self,script):
|
||||
self.wifi.before_script = script
|
||||
#end function SetWirelessBeforeScript
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetWirelessAfterScript(self,script):
|
||||
self.wifi.after_script = script
|
||||
#end function SetWirelessAfterScript
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetNumberOfNetworks(self):
|
||||
'''returns number of networks'''
|
||||
print 'returned number of networks...',len(self.LastScan)
|
||||
return len(self.LastScan)
|
||||
#end function GetNumberOfNetworks
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused,ics):
|
||||
'''creates an ad-hoc network using user inputted settings'''
|
||||
print 'attempting to create ad-hoc network...'
|
||||
self.wifi.CreateAdHocNetwork(essid,channel,ip,enctype,key,encused,ics)
|
||||
#end function CreateAdHocNetwork
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetAutoReconnect(self):
|
||||
'''returns if wicd should automatically try to reconnect is connection is lost'''
|
||||
do = bool(int(self.auto_reconnect))
|
||||
return self.__printReturn('returning automatically reconnect when connection drops',do)
|
||||
#end function GetAutoReconnect
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetAutoReconnect(self,value):
|
||||
'''sets if wicd should try to reconnect with connection drops'''
|
||||
print 'setting automatically reconnect when connection drops'
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(self.app_conf)
|
||||
config.set("Settings","auto_reconnect",int(value))
|
||||
config.write(open(self.app_conf,"w"))
|
||||
self.auto_reconnect = value
|
||||
#end function SetAutoReconnect
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def AutoConnect(self,fresh):
|
||||
'''first tries to autoconnect to a wireled network, if that fails it tries a wireless connection'''
|
||||
if fresh and self.CheckPluggedIn() == True:
|
||||
'''first tries to autoconnect to a wired network, if that fails it tries a wireless connection'''
|
||||
if self.CheckPluggedIn() == True:
|
||||
if self.GetWiredAutoConnectMethod() == False:
|
||||
self.SetNeedWiredProfileChooser(True)
|
||||
print 'alerting tray to display wired autoconnect wizard'
|
||||
else:
|
||||
defaultNetwork = self.GetDefaultWiredNetwork()
|
||||
if defaultNetwork != None:
|
||||
self.ReadWiredNetworkProfile(defaultNetwork)
|
||||
@@ -409,6 +337,110 @@ class ConnectionWizard(dbus.service.Object):
|
||||
print 'autoconnect failed because wireless interface == None'
|
||||
#end function AutoConnect
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetGlobalDNSAddresses(self):
|
||||
'''returns the global dns addresses'''
|
||||
print 'returning global dns addresses to client'
|
||||
return (self.dns1,self.dns2,self.dns3)
|
||||
#end function GetWirelessInterface
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def CheckIfConnecting(self):
|
||||
'''returns if a network connection is being made'''
|
||||
if self.CheckIfWiredConnecting() == False and self.CheckIfWirelessConnecting() == False:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
#end function CheckIfConnecting
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def SetNeedWiredProfileChooser(self,val):
|
||||
self.need_profile_chooser = val
|
||||
#end function SetNeedWiredProfileChooser
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def GetNeedWiredProfileChooser(self):
|
||||
return self.need_profile_chooser
|
||||
#end function GetNeedWiredProfileChooser
|
||||
|
||||
########## WIRELESS FUNCTIONS
|
||||
#################################
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetHiddenNetworkESSID(self,essid):
|
||||
'''sets the ESSID of a hidden network for use with ConnectionWizard.Scan'''
|
||||
print 'setting hidden essid: ' + str(essid)
|
||||
self.hidden_essid = str(misc.Noneify(essid))
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def Scan(self):
|
||||
'''scans for wireless networks, optionally using a (hidden) essid set with SetHiddenNetworkESSID'''
|
||||
print 'scanning start'
|
||||
scan = self.wifi.Scan(str(self.hidden_essid)) #_should_ already be a string but you never know...
|
||||
self.LastScan = scan
|
||||
print 'scanning done'
|
||||
print 'found',str(len(scan)),'networks:',
|
||||
for i in scan:
|
||||
print i,
|
||||
self.ReadWirelessNetworkProfile(i)
|
||||
print
|
||||
#end function FreshScan
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def DisconnectWireless(self):
|
||||
'''disconnects all wireless networks'''
|
||||
self.SetForcedDisconnect(True)
|
||||
self.wifi.Disconnect()
|
||||
#end function DisconnectWireless
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetWirelessBeforeScript(self,networkid,script):
|
||||
if script == '':
|
||||
script = None
|
||||
self.SetWirelessProperty(networkid,"beforescript",script)
|
||||
self.wifi.before_script = script
|
||||
#end function SetWirelessBeforeScript
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetWirelessAfterScript(self,networkid,script):
|
||||
if script == '':
|
||||
script = None
|
||||
self.SetWirelessProperty(networkid,"afterscript",script)
|
||||
self.wifi.after_script = script
|
||||
#end function SetWirelessAfterScript
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetNumberOfNetworks(self):
|
||||
'''returns number of networks'''
|
||||
print 'returned number of networks...',len(self.LastScan)
|
||||
return len(self.LastScan)
|
||||
#end function GetNumberOfNetworks
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def CreateAdHocNetwork(self,essid,channel,ip,enctype,key,encused,ics):
|
||||
'''creates an ad-hoc network using user inputted settings'''
|
||||
print 'attempting to create ad-hoc network...'
|
||||
self.wifi.CreateAdHocNetwork(essid,channel,ip,enctype,key,encused,ics)
|
||||
#end function CreateAdHocNetwork
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetAutoReconnect(self):
|
||||
'''returns if wicd should automatically try to reconnect is connection is lost'''
|
||||
do = bool(int(self.auto_reconnect))
|
||||
return self.__printReturn('returning automatically reconnect when connection drops',do)
|
||||
#end function GetAutoReconnect
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def SetAutoReconnect(self,value):
|
||||
'''sets if wicd should try to reconnect with connection drops'''
|
||||
print 'setting automatically reconnect when connection drops'
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(self.app_conf)
|
||||
config.set("Settings","auto_reconnect",int(value))
|
||||
config.write(open(self.app_conf,"w"))
|
||||
self.auto_reconnect = value
|
||||
#end function SetAutoReconnect
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wireless')
|
||||
def GetWirelessProperty(self,networkid,property):
|
||||
'''retrieves wireless property from the network specified'''
|
||||
@@ -558,15 +590,36 @@ class ConnectionWizard(dbus.service.Object):
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def SetWiredBeforeScript(self,script):
|
||||
'''sets pre-connection script to run for a wired connection'''
|
||||
if script == '':
|
||||
script = None
|
||||
self.SetWiredProperty("beforescript",script)
|
||||
self.wired.before_script = script
|
||||
#end function SetWiredBeforeScript
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def SetWiredAfterScript(self,script):
|
||||
'''sets post-connection script to run for a wired connection'''
|
||||
if script == '':
|
||||
script = None
|
||||
self.SetWiredProperty("afterscript",script)
|
||||
self.wired.after_script = script
|
||||
#end function SetWiredAfterScript
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def SetWiredAutoConnectMethod(self,method):
|
||||
'''sets which method the user wants to autoconnect to wired networks'''
|
||||
print 'method = ',method
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(self.app_conf)
|
||||
config.set("Settings","use_default_profile",int(method))
|
||||
config.write(open(self.app_conf,"w"))
|
||||
self.use_default_profile = method
|
||||
|
||||
def GetWiredAutoConnectMethod(self):
|
||||
'''returns the wired autoconnect method'''
|
||||
return bool(int(self.use_default_profile))
|
||||
#end function GetWiredAutoConnectMethod
|
||||
|
||||
@dbus.service.method('org.wicd.daemon.wired')
|
||||
def CheckWiredConnectingMessage(self):
|
||||
'''returns the wired interface\'s status message'''
|
||||
@@ -856,13 +909,18 @@ class ConnectionWizard(dbus.service.Object):
|
||||
if config.has_option("Settings","auto_reconnect"):
|
||||
self.auto_reconnect = config.get("Settings","auto_reconnect")
|
||||
else:
|
||||
config.set("Settings","auto_reconnect","False")
|
||||
config.set("Settings","auto_reconnect","0")
|
||||
self.auto_reconnect = False
|
||||
if config.has_option("Settings","debug_mode"):
|
||||
self.debug_mode = config.get("Settings","debug_mode")
|
||||
else:
|
||||
self.debug_mode = False
|
||||
config.set("Settings","debug_mode","False")
|
||||
self.debug_mode = 0
|
||||
config.set("Settings","debug_mode","0")
|
||||
if config.has_option("Settings","use_default_profile"):
|
||||
self.SetWiredAutoConnectMethod(config.get("Settings","use_default_profile"))
|
||||
else:
|
||||
config.set("Settings","use_default_profile","1")
|
||||
self.SetWiredAutoConnectMethod(config.get("Settings","use_default_profile"))
|
||||
else:
|
||||
print "configuration file exists, no settings found, adding defaults..."
|
||||
configfile = open(self.app_conf,"w")
|
||||
@@ -870,20 +928,22 @@ class ConnectionWizard(dbus.service.Object):
|
||||
config.set("Settings","wireless_interface","wlan0")
|
||||
config.set("Settings","wired_interface","eth0")
|
||||
config.set("Settings","wpa_driver","wext")
|
||||
config.set("Settings","always_show_wired_interface","False")
|
||||
config.set("Settings","auto_reconnect","False")
|
||||
config.set("Settings","debug_mode","False")
|
||||
config.set("Settings","always_show_wired_interface","0")
|
||||
config.set("Settings","auto_reconnect","0")
|
||||
config.set("Settings","debug_mode","0")
|
||||
config.set("Settings","use_default_profile","1")
|
||||
config.set("Settings","use_global_dns","False")
|
||||
config.set("Settings","dns1","None")
|
||||
config.set("Settings","dns2","None")
|
||||
config.set("Settings","dns3","None")
|
||||
self.SetGlobalDNS(config.get('Settings','dns1'),config.get('Settings','dns2'),config.get('Settings','dns3'))
|
||||
self.SetWirelessInterface(config.get("Settings","wireless_interface"))
|
||||
self.SetWiredInterface(config.get("Settings","wired_interface"))
|
||||
self.SetWPADriver(config.get("Settings","wpa_driver"))
|
||||
self.SetAlwaysShowWiredInterface(False)
|
||||
self.SetAutoReconnect(True)
|
||||
self.SetDebugMode(False)
|
||||
self.SetWirelessInterface("wlan0")
|
||||
self.SetWiredInterface("eth0")
|
||||
self.SetWPADriver("wext")
|
||||
self.SetAlwaysShowWiredInterface(0)
|
||||
self.SetAutoReconnect(1)
|
||||
self.SetDebugMode(0)
|
||||
self.SetWiredAutoConnectMethod(1)
|
||||
config.write(configfile)
|
||||
|
||||
else:
|
||||
@@ -894,9 +954,10 @@ class ConnectionWizard(dbus.service.Object):
|
||||
config.add_section("Settings")
|
||||
config.set("Settings","wireless_interface","wlan0")
|
||||
config.set("Settings","wired_interface","eth0")
|
||||
config.set("Settings","always_show_wired_interface","False")
|
||||
config.set("Settings","auto_reconnect","False")
|
||||
config.set("Settings","debug_mode","False")
|
||||
config.set("Settings","always_show_wired_interface","0")
|
||||
config.set("Settings","auto_reconnect","0")
|
||||
config.set("Settings","debug_mode","0")
|
||||
config.set("Settings","use_default_profile","1")
|
||||
config.set("Settings","dns1","None")
|
||||
config.set("Settings","dns2","None")
|
||||
config.set("Settings","dns3","None")
|
||||
@@ -911,9 +972,11 @@ class ConnectionWizard(dbus.service.Object):
|
||||
self.SetWirelessInterface(config.get("Settings","wireless_interface"))
|
||||
self.SetWiredInterface(config.get("Settings","wired_interface"))
|
||||
self.SetWPADriver(config.get("Settings","wpa_driver"))
|
||||
self.SetAlwaysShowWiredInterface(False)
|
||||
self.SetAutoReconnect(True)
|
||||
self.SetDebugMode(False)
|
||||
self.SetAlwaysShowWiredInterface(0)
|
||||
self.SetAutoReconnect(1)
|
||||
self.SetHideDupeAPs(0)
|
||||
self.SetDebugMode(0)
|
||||
self.SetWiredAutoConnectMethod(1)
|
||||
self.SetGlobalDNS(None,None,None)
|
||||
#end If
|
||||
|
||||
|
||||
49
edgy.py
49
edgy.py
@@ -77,6 +77,10 @@ def open_wicd_gui():
|
||||
if ret == 0:
|
||||
lastWinId = os.spawnlpe(os.P_NOWAIT, './gui.py', os.environ)
|
||||
|
||||
def wired_profile_chooser():
|
||||
print 'profile chooser is running'
|
||||
os.spawnlpe(os.P_WAIT, './gui.py', os.environ)
|
||||
|
||||
def set_signal_image():
|
||||
global LastStrength
|
||||
global stillWired #keeps us from resetting the wired info over and over
|
||||
@@ -86,6 +90,11 @@ def set_signal_image():
|
||||
if not daemon.GetDebugMode():
|
||||
config.DisableLogging()
|
||||
|
||||
#Check to see we wired profile autoconnect chooser needs to be displayed
|
||||
if daemon.GetNeedWiredProfileChooser() == True:
|
||||
wired_profile_chooser()
|
||||
daemon.SetNeedWiredProfileChooser(False)
|
||||
|
||||
wired_ip = wired.GetWiredIP()
|
||||
if wired.CheckPluggedIn() == True and wired_ip != None:
|
||||
if stillWired == False: # Only set image/tooltip if it hasn't been set already
|
||||
@@ -94,7 +103,7 @@ def set_signal_image():
|
||||
stillWired = True
|
||||
lock = ''
|
||||
else:
|
||||
if stillWired == True:
|
||||
if stillWired == True: #this only occurs when we were previously using wired but it became unplugged
|
||||
tr.set_from_file("images/no-signal.png")
|
||||
tr.set_tooltip(language['not_connected'])
|
||||
stillWired = False
|
||||
@@ -107,7 +116,7 @@ def set_signal_image():
|
||||
|
||||
#only update if the signal strength has changed because doing I/O calls is expensive,
|
||||
#and the icon flickers
|
||||
if (signal != LastStrength or network != wireless.GetCurrentNetwork()) and wireless_ip != None:
|
||||
if (signal != LastStrength or network != wireless.GetCurrentNetwork() or signal == 0) and wireless_ip != None:
|
||||
LastStrength = signal
|
||||
lock = '' #set the string to '' so that when it is put in "high-signal" + lock + ".png", there will be nothing
|
||||
curNetID = wireless.GetCurrentNetworkID() #the network ID needs to be checked because a negative value here will break the tray
|
||||
@@ -125,31 +134,37 @@ def set_signal_image():
|
||||
tr.set_from_file("images/bad-signal" + lock + ".png")
|
||||
elif signal == 0:
|
||||
tr.set_from_file("images/no-signal.png")
|
||||
auto_reconnect()
|
||||
|
||||
elif wireless_ip == None and wired_ip == None:
|
||||
tr.set_from_file("images/no-signal.png")
|
||||
tr.set_tooltip(language['not_connected'])
|
||||
auto_reconnect()
|
||||
|
||||
if not daemon.GetDebugMode():
|
||||
config.EnableLogging()
|
||||
|
||||
return True
|
||||
|
||||
def auto_reconnect():
|
||||
#Auto-reconnect code - not sure how well this works. I know that without the ForcedDisconnect check it reconnects you when
|
||||
#a disconnect is forced. People who have disconnection problems need to test it to determine if it actually works.
|
||||
#First it will attempt to reconnect to the last known wireless network, and if that fails it should run a scan and try to
|
||||
#connect to any network set to autoconnect.
|
||||
if wireless.GetAutoReconnect() == True and wireless.CheckIfWirelessConnecting() == False and wireless.GetForcedDisconnect() == False:
|
||||
#connect to a wired network or any wireless network set to autoconnect.
|
||||
if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False:
|
||||
curNetID = wireless.GetCurrentNetworkID()
|
||||
print 'Trying to autoreconnect to last used network'
|
||||
if curNetID > -1:
|
||||
wireless.ConnectWireless(wireless.GetCurrentNetworkID())
|
||||
print 'Trying to autoreconnect'
|
||||
wireless.ConnectWireless(curNetID)
|
||||
while wireless.CheckIfWirelessConnecting() == True:
|
||||
time.sleep(1)
|
||||
if wireless.GetCurrentSignalStrength() != 0:
|
||||
print "Successfully autoreconnected."
|
||||
else:
|
||||
print "Couldn't reconnect to last used network, scanning for an autoconnect network..."
|
||||
print wireless.AutoConnect(True)
|
||||
|
||||
elif wireless_ip == None:
|
||||
tr.set_from_file("images/no-signal.png")
|
||||
tr.set_tooltip(language['not_connected'])
|
||||
|
||||
if not daemon.GetDebugMode():
|
||||
config.EnableLogging()
|
||||
|
||||
return True
|
||||
daemon.AutoConnect(True)
|
||||
else:
|
||||
daemon.AutoConnect(True)
|
||||
|
||||
class TrackerStatusIcon(gtk.StatusIcon):
|
||||
def __init__(self):
|
||||
@@ -185,6 +200,8 @@ class TrackerStatusIcon(gtk.StatusIcon):
|
||||
self.connect('activate', self.on_activate)
|
||||
self.connect('popup-menu', self.on_popup_menu)
|
||||
|
||||
wireless.SetForcedDisconnect(False)
|
||||
|
||||
def on_activate(self, data):
|
||||
open_wicd_gui()
|
||||
|
||||
|
||||
113
gui.py
113
gui.py
@@ -13,7 +13,7 @@ except:
|
||||
print 'Missing GTK and gtk.glade. Aborting.'
|
||||
sys.exit(1)
|
||||
|
||||
import time, os, misc, gettext, locale, gobject, dbus, dbus.service
|
||||
import time, os, misc, gettext, locale, gobject, dbus, dbus.service,pango
|
||||
|
||||
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
|
||||
import dbus.glib
|
||||
@@ -131,6 +131,11 @@ language['use_ics'] = _('Activate Internet Connection Sharing')
|
||||
language['default_wired'] = _('Use as default profile (overwrites any previous default)')
|
||||
language['use_debug_mode'] = _('Enable debug mode')
|
||||
language['use_global_dns'] = _('Use global DNS servers')
|
||||
language['use_default_profile'] = _('Use default profile on wired auto-connect')
|
||||
language['show_wired_list'] = _('Prompt for profile on wired auto-connect')
|
||||
language['choose_wired_profile'] = _('Select or create a wired profile to connect with')
|
||||
language['wired_network_found'] = _('Wired connection detected')
|
||||
language['stop_showing_chooser'] = _('Stop Showing Autoconnect pop-up temporarily')
|
||||
|
||||
language['0'] = _('0')
|
||||
language['1'] = _('1')
|
||||
@@ -418,7 +423,6 @@ class NetworkEntry(gtk.Expander):
|
||||
if stringToNone(netmask.get_text()) == None: #make sure the netmask is blank
|
||||
netmask.set_text('255.255.255.0') #fill in the most common one
|
||||
|
||||
|
||||
def resetStaticCheckboxes(self):
|
||||
#enable the right stuff
|
||||
if not stringToNone(self.txtIP.get_text()) == None:
|
||||
@@ -491,14 +495,15 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
self.set_label(language['wired_network'])
|
||||
self.resetStaticCheckboxes()
|
||||
self.comboProfileNames = gtk.combo_box_entry_new_text()
|
||||
self.isFullGUI = True
|
||||
|
||||
profileList = config.GetWiredProfileList()
|
||||
if profileList: #make sure there is something in it...
|
||||
self.profileList = config.GetWiredProfileList()
|
||||
if self.profileList: #make sure there is something in it...
|
||||
for x in config.GetWiredProfileList(): #add all the names to the combobox
|
||||
self.comboProfileNames.append_text(x)
|
||||
hboxTemp = gtk.HBox(False,0)
|
||||
self.hboxTemp = gtk.HBox(False,0)
|
||||
hboxDef = gtk.HBox(False,0)
|
||||
buttonOK = gtk.Button(stock=gtk.STOCK_ADD)
|
||||
self.buttonAdd = gtk.Button(stock=gtk.STOCK_ADD)
|
||||
self.buttonDelete = gtk.Button(stock=gtk.STOCK_DELETE)
|
||||
self.profileHelp = gtk.Label(language['wired_network_instructions'])
|
||||
self.checkboxDefaultProfile = gtk.CheckButton(language['default_wired'])
|
||||
@@ -509,15 +514,15 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
self.profileHelp.set_line_wrap(True)
|
||||
|
||||
self.vboxTop.pack_start(self.profileHelp,fill=False,expand=False)
|
||||
hboxTemp.pack_start(self.comboProfileNames,fill=True,expand=True)
|
||||
hboxTemp.pack_start(buttonOK,fill=False,expand=False)
|
||||
hboxTemp.pack_start(self.buttonDelete,fill=False,expand=False)
|
||||
self.hboxTemp.pack_start(self.comboProfileNames,fill=True,expand=True)
|
||||
self.hboxTemp.pack_start(self.buttonAdd,fill=False,expand=False)
|
||||
self.hboxTemp.pack_start(self.buttonDelete,fill=False,expand=False)
|
||||
hboxDef.pack_start(self.checkboxDefaultProfile,fill=False,expand=False)
|
||||
|
||||
buttonOK.connect("clicked",self.addProfile) #hook up our buttons
|
||||
self.buttonAdd.connect("clicked",self.addProfile) #hook up our buttons
|
||||
self.buttonDelete.connect("clicked",self.removeProfile)
|
||||
self.comboProfileNames.connect("changed",self.changeProfile)
|
||||
self.vboxTop.pack_start(hboxTemp)
|
||||
self.vboxTop.pack_start(self.hboxTemp)
|
||||
self.vboxTop.pack_start(hboxDef)
|
||||
|
||||
if stringToBoolean(wired.GetWiredProperty("default")) == True:
|
||||
@@ -528,7 +533,7 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
|
||||
self.show_all()
|
||||
self.profileHelp.hide()
|
||||
if profileList != None:
|
||||
if self.profileList != None:
|
||||
self.comboProfileNames.set_active(0)
|
||||
print "wired profiles found"
|
||||
self.set_expanded(False)
|
||||
@@ -557,6 +562,7 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
config.CreateWiredNetworkProfile(profileName)
|
||||
self.comboProfileNames.prepend_text(profileName)
|
||||
self.comboProfileNames.set_active(0)
|
||||
if self.isFullGUI == True:
|
||||
self.buttonDelete.set_sensitive(True)
|
||||
self.vboxAdvanced.set_sensitive(True)
|
||||
self.higherLevel.connectButton.set_sensitive(True)
|
||||
@@ -570,6 +576,7 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
self.profileHelp.show()
|
||||
entry = self.comboProfileNames.child
|
||||
entry.set_text("")
|
||||
if self.isFullGUI == True:
|
||||
self.buttonDelete.set_sensitive(False)
|
||||
self.vboxAdvanced.set_sensitive(False)
|
||||
self.higherLevel.connectButton.set_sensitive(False)
|
||||
@@ -586,6 +593,8 @@ class WiredNetworkEntry(NetworkEntry):
|
||||
def changeProfile(self,widget):
|
||||
if self.comboProfileNames.get_active() > -1: #this way the name doesn't change
|
||||
# #everytime someone types something in
|
||||
if self.isFullGUI == False:
|
||||
return
|
||||
print "changing profile..."
|
||||
profileName = self.comboProfileNames.get_active_text()
|
||||
print profileName
|
||||
@@ -761,6 +770,56 @@ class appGui:
|
||||
|
||||
def __init__(self):
|
||||
print "starting..."
|
||||
#two possibilities here, one is that the normal GUI should be opened, the other is that wired auto-connect
|
||||
#is set to prompt the user to select a profile. It's kind of hacked together, but it'll do.
|
||||
if daemon.GetNeedWiredProfileChooser() == True:
|
||||
#profile chooser init block
|
||||
#import and init WiredNetworkEntry to steal some of the functions and widgets it uses
|
||||
wiredNetEntry = WiredNetworkEntry()
|
||||
wiredNetEntry.__init__()
|
||||
|
||||
dialog = gtk.Dialog(title=language['wired_network_found'], flags = gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CONNECT,1,gtk.STOCK_CANCEL,2))
|
||||
dialog.set_has_separator(False)
|
||||
dialog.set_size_request(400,150)
|
||||
instructLabel = gtk.Label(language['choose_wired_profile'] + ':\n')
|
||||
stoppopcheckbox = gtk.CheckButton(language['stop_showing_chooser'])
|
||||
|
||||
wiredNetEntry.isFullGUI = False
|
||||
instructLabel.set_alignment(0,0)
|
||||
stoppopcheckbox.set_active(False)
|
||||
|
||||
#remove widgets that were added to the normal WiredNetworkEntry so that they can be added to the pop-up wizard
|
||||
wiredNetEntry.vboxTop.remove(wiredNetEntry.hboxTemp)
|
||||
wiredNetEntry.vboxTop.remove(wiredNetEntry.profileHelp)
|
||||
|
||||
dialog.vbox.pack_start(instructLabel,fill=False,expand=False)
|
||||
dialog.vbox.pack_start(wiredNetEntry.profileHelp,fill=False,expand=False)
|
||||
dialog.vbox.pack_start(wiredNetEntry.hboxTemp,fill=False,expand=False)
|
||||
dialog.vbox.pack_start(stoppopcheckbox,fill=False,expand=False)
|
||||
dialog.show_all()
|
||||
|
||||
wiredNetEntry.profileHelp.hide()
|
||||
if wiredNetEntry.profileList != None:
|
||||
wiredNetEntry.comboProfileNames.set_active(0)
|
||||
print "wired profiles found"
|
||||
else:
|
||||
print "no wired profiles found"
|
||||
wiredNetEntry.profileHelp.show()
|
||||
|
||||
response = dialog.run()
|
||||
if response == 1:
|
||||
print 'reading profile ', wiredNetEntry.comboProfileNames.get_active_text()
|
||||
config.ReadWiredNetworkProfile(wiredNetEntry.comboProfileNames.get_active_text())
|
||||
wired.ConnectWired()
|
||||
dialog.destroy()
|
||||
sys.exit(0)
|
||||
else:
|
||||
if stoppopcheckbox.get_active() == True:
|
||||
wired.use_default_profile = 1 #so that the pop-up doesn't keep appearing if you cancel it
|
||||
dialog.destroy()
|
||||
sys.exit(0)
|
||||
else:
|
||||
#normal init block
|
||||
gladefile = "data/wicd.glade"
|
||||
self.windowname = "gtkbench"
|
||||
self.wTree = gtk.glade.XML(gladefile)
|
||||
@@ -843,14 +902,18 @@ class appGui:
|
||||
def settings_dialog(self,widget,event=None):
|
||||
dialog = gtk.Dialog(title=language['preferences'], flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_OK,1,gtk.STOCK_CANCEL,2))
|
||||
dialog.set_has_separator(False)
|
||||
dialog.set_size_request(375,-1)
|
||||
dialog.set_size_request(465,-1)
|
||||
wiredcheckbox = gtk.CheckButton(language['wired_always_on'])
|
||||
wiredcheckbox.set_active(wired.GetAlwaysShowWiredInterface())
|
||||
reconnectcheckbox = gtk.CheckButton(language['auto_reconnect'])
|
||||
reconnectcheckbox.set_active(wireless.GetAutoReconnect())
|
||||
debugmodecheckbox = gtk.CheckButton(language['use_debug_mode'])
|
||||
debugmodecheckbox.set_active(daemon.GetDebugMode())
|
||||
sepline = gtk.HSeparator()
|
||||
usedefaultradiobutton = gtk.RadioButton(None,language['use_default_profile'],False)
|
||||
showlistradiobutton = gtk.RadioButton(usedefaultradiobutton,language['show_wired_list'],False)
|
||||
wpadriverlabel = SmallLabel(language['wpa_supplicant_driver'] + ':')
|
||||
wpadriverlabel.set_size_request(75,-1)
|
||||
wpadrivercombo = gtk.combo_box_new_text()
|
||||
wpadrivercombo.set_size_request(50,-1)
|
||||
wpadrivers = [ "hostap","hermes","madwifi","atmel","wext","ndiswrapper","broadcom","ipw","ralink legacy" ]
|
||||
@@ -875,6 +938,9 @@ class appGui:
|
||||
|
||||
entryWirelessInterface = LabelEntry(language['wireless_interface'] + ':')
|
||||
entryWiredInterface = LabelEntry(language['wired_interface'] + ':')
|
||||
entryWirelessInterface.label.set_size_request(260,-1)
|
||||
entryWiredInterface.label.set_size_request(260,-1)
|
||||
entryWiredAutoMethod = gtk.Label('Wired Autoconnection options:')
|
||||
|
||||
entryWirelessInterface.entry.set_text(daemon.GetWirelessInterface())
|
||||
entryWiredInterface.entry.set_text(daemon.GetWiredInterface())
|
||||
@@ -893,6 +959,13 @@ class appGui:
|
||||
dns2Entry.set_text(noneToBlankString(dns_addresses[1]))
|
||||
dns3Entry.set_text(noneToBlankString(dns_addresses[2]))
|
||||
|
||||
entryWiredAutoMethod.set_alignment(0,0)
|
||||
sepline.set_size_request(2,8)
|
||||
atrlist = pango.AttrList()
|
||||
atrlist.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE,0,28))
|
||||
atrlist.insert(pango.AttrWeight(pango.WEIGHT_BOLD,0,50))
|
||||
entryWiredAutoMethod.set_attributes(atrlist)
|
||||
|
||||
dialog.vbox.pack_start(wpabox)
|
||||
dialog.vbox.pack_start(entryWirelessInterface)
|
||||
dialog.vbox.pack_start(entryWiredInterface)
|
||||
@@ -905,8 +978,13 @@ class appGui:
|
||||
dialog.vbox.pack_start(wiredcheckbox)
|
||||
dialog.vbox.pack_start(reconnectcheckbox)
|
||||
dialog.vbox.pack_start(debugmodecheckbox)
|
||||
dialog.vbox.pack_start(sepline)
|
||||
dialog.vbox.pack_start(entryWiredAutoMethod)
|
||||
dialog.vbox.pack_start(usedefaultradiobutton)
|
||||
dialog.vbox.pack_start(showlistradiobutton)
|
||||
dialog.vbox.set_spacing(5)
|
||||
dialog.show_all()
|
||||
|
||||
response = dialog.run()
|
||||
if response == 1:
|
||||
daemon.SetUseGlobalDNS(useGlobalDNSCheckbox.get_active())
|
||||
@@ -918,6 +996,7 @@ class appGui:
|
||||
wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active())
|
||||
wireless.SetAutoReconnect(reconnectcheckbox.get_active())
|
||||
daemon.SetDebugMode(debugmodecheckbox.get_active())
|
||||
wired.SetWiredAutoConnectMethod(usedefaultradiobutton.get_active())
|
||||
dialog.destroy()
|
||||
else:
|
||||
dialog.destroy()
|
||||
@@ -1084,10 +1163,8 @@ class appGui:
|
||||
# Script info
|
||||
before_script = networkentry.expander.txtBeforeScript.get_text()
|
||||
after_script = networkentry.expander.txtAfterScript.get_text()
|
||||
wireless.SetWirelessProperty(networkid,"beforescript",noneToString(before_script))
|
||||
wireless.SetWirelessProperty(networkid,"afterscript",noneToString(after_script))
|
||||
wireless.SetWirelessBeforeScript(before_script)
|
||||
wireless.SetWirelessAfterScript(after_script)
|
||||
wireless.SetWirelessBeforeScript(networkid,before_script)
|
||||
wireless.SetWirelessAfterScript(networkid,after_script)
|
||||
|
||||
# if it exists. maybe kept as a value in the network entry? Not sure...
|
||||
print "connecting to wireless network..."
|
||||
@@ -1117,8 +1194,6 @@ class appGui:
|
||||
#Script Info
|
||||
before_script = networkentry.expander.txtBeforeScript.get_text()
|
||||
after_script = networkentry.expander.txtAfterScript.get_text()
|
||||
wired.SetWiredProperty("beforescript",noneToString(before_script))
|
||||
wired.SetWiredProperty("afterscript",noneToString(after_script))
|
||||
wired.SetWiredBeforeScript(before_script)
|
||||
wired.SetWiredAfterScript(after_script)
|
||||
|
||||
|
||||
@@ -139,7 +139,8 @@ class Wireless:
|
||||
if len(info) < 5 or info == None or info == '':
|
||||
break;
|
||||
if info[2] == CurrentNetwork["essid"]:
|
||||
if info[5] == 'WEP' or info[5] == 'OPEN': # Needs to be tested
|
||||
CurrentNetwork["encryption"] = True
|
||||
if info[5] == 'WEP' or ((info[5] == 'OPEN' or info[5] == 'SHARED') and info[4] == 'WEP'): # Needs to be tested
|
||||
CurrentNetwork["encryption_method"] = 'WEP'
|
||||
elif info[5] == 'WPA-PSK':
|
||||
CurrentNetwork["encrytion_method"] = 'WPA'
|
||||
@@ -148,7 +149,7 @@ class Wireless:
|
||||
else:
|
||||
print 'Unknown AuthMode, can\'t assign encryption_method!!'
|
||||
CurrentNetwork["encryption_method"] = 'Unknown'
|
||||
CurrentNetwork["quality"] = info[1][1:] #set link strength here
|
||||
CurrentNetwork["quality"] = info[1][1:] #set signal strength here (not link quality! dBm vs %)
|
||||
else:
|
||||
CurrentNetwork["encryption"] = False
|
||||
#end If
|
||||
@@ -355,9 +356,17 @@ class Wireless:
|
||||
if len(info) < 5 or info == None or info == '': #probably overkill, but the last 2 won't get run anyways
|
||||
break;
|
||||
if info[2] == network.get("essid"):
|
||||
if info[5] == 'WEP' or info[5] == 'OPEN': # Needs to be tested
|
||||
if info[5] == 'WEP' or (info[5] == 'OPEN' and info[4] == 'WEP'): # Needs to be tested
|
||||
print 'setting up WEP'
|
||||
misc.Run("iwconfig " + self.wireless_interface + " key " + network.get('key'))
|
||||
elif info[5] == 'SHARED' and info[4] == 'WEP':
|
||||
print 'setting up WEP'
|
||||
misc.Run("iwpriv " + self.wireless_interface + " set NetworkType=" + info[6])
|
||||
misc.Run("iwpriv " + self.wireless_interface + " set AuthMode=SHARED")
|
||||
misc.Run("iwpriv " + self.wireless_interface + " set EncrypType=" + info[4])
|
||||
misc.Run("iwpriv " + self.wireless_interface + " set Key1=" + network.get('key'))
|
||||
misc.Run("iwpriv " + self.wireless_interface + " set DefaultKeyID=1")
|
||||
misc.Run("iwpriv " + self.wireless_interface + " set SSID=" + info[2])
|
||||
elif info[5] == 'WPA-PSK':
|
||||
print 'setting up WPA-PSK'
|
||||
misc.Run("iwpriv " + self.wireless_interface + " set NetworkType=" + info[6])
|
||||
@@ -386,6 +395,21 @@ class Wireless:
|
||||
print "setting the broadcast address..." + 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 not network.get('ip') == None:
|
||||
self.lock.acquire()
|
||||
self.ConnectingMessage = 'setting_static_ip'
|
||||
|
||||
Reference in New Issue
Block a user