mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
* Completely reworked the gui/tray system. gui.py and edgy/dapper/tray.py are now all run from the same wicd.py file.
* Added a connection_lost_counter to prevent the wicd frontend from trying to automatically reconnect too quickly if signal strength is briefly lost. * Added some code to hopefully fix some of the dbus-related encoding problems caused by essids with weird characters. (Might still need work). * The tray/gui will now show up in the process manager under the name wicd (along with the wicd icon), instead of just python. * Added a GetCurrentInterface() method to the daemon that will eventually be used in the VPN plugin. * Fixed a possible crash caused by signal strength not being returned correctly. * Split the Wired Profile Chooser from the appGui class, so they are now called separately within wicd.py. When the profile chooser is called from the daemon, it sets a flag as well as sending a dbus signal, so the chooser will still launch if the wicd frontend isn't running yet. * Added some docstrings, comments, etc. Probably a few other small changes I'm forgetting.
This commit is contained in:
167
daemon.py
167
daemon.py
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
""" wicd - wireless connection daemon implementation.
|
""" wicd - wireless connection daemon implementation.
|
||||||
|
|
||||||
This module implements the wicd daemon that provides network
|
This module implements the wicd daemon that provides network
|
||||||
@@ -51,6 +52,16 @@ import misc
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
wpath.chdir(__file__)
|
wpath.chdir(__file__)
|
||||||
|
|
||||||
|
if sys.platform == 'linux2':
|
||||||
|
# Set process name. Only works on Linux >= 2.1.57.
|
||||||
|
try:
|
||||||
|
import dl
|
||||||
|
libc = dl.open('/lib/libc.so.6')
|
||||||
|
libc.call('prctl', 15, 'wicd-daemon\0', 0, 0, 0) # 15 is PR_SET_NAME
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
logging_enabled = True
|
logging_enabled = True
|
||||||
|
|
||||||
class LogWriter:
|
class LogWriter:
|
||||||
@@ -83,6 +94,7 @@ class LogWriter:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
global logging_enabled
|
global logging_enabled
|
||||||
|
data = data.encode('utf-8')
|
||||||
if len(data) <= 0: return
|
if len(data) <= 0: return
|
||||||
if logging_enabled:
|
if logging_enabled:
|
||||||
if self.eol:
|
if self.eol:
|
||||||
@@ -121,7 +133,6 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
auto_connect=True):
|
auto_connect=True):
|
||||||
dbus.service.Object.__init__(self, bus_name, object_path)
|
dbus.service.Object.__init__(self, bus_name, object_path)
|
||||||
|
|
||||||
#set variables needed to run - these probably won't be changed too often
|
|
||||||
self.app_conf = wpath.etc + 'manager-settings.conf'
|
self.app_conf = wpath.etc + 'manager-settings.conf'
|
||||||
self.wireless_conf = wpath.etc + 'wireless-settings.conf'
|
self.wireless_conf = wpath.etc + 'wireless-settings.conf'
|
||||||
self.wired_conf = wpath.etc + 'wired-settings.conf'
|
self.wired_conf = wpath.etc + 'wired-settings.conf'
|
||||||
@@ -130,20 +141,21 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
self.wired = networking.Wired()
|
self.wired = networking.Wired()
|
||||||
self.forced_disconnect = False
|
self.forced_disconnect = False
|
||||||
self.need_profile_chooser = False
|
self.need_profile_chooser = False
|
||||||
|
self.current_interface = None
|
||||||
|
self.vpn_session = None
|
||||||
|
|
||||||
#load the config file - it should have most of the stuff we need to run...
|
# Load the config file
|
||||||
self.ReadConfig()
|
self.ReadConfig()
|
||||||
|
|
||||||
#set some other stuff needed to run - these probably will be changed often
|
# 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
|
||||||
#this will speed up the scanning process - if a client doesn't need a fresh scan, just
|
# can be done by calling FreshScan(self,interface)
|
||||||
#feed them the old one. a fresh scan can be done by calling FreshScan(self,interface)
|
|
||||||
self.LastScan = ''
|
self.LastScan = ''
|
||||||
|
|
||||||
#make a variable that will hold the wired network profile
|
# Make a variable that will hold the wired network profile
|
||||||
self.WiredNetwork = {}
|
self.WiredNetwork = {}
|
||||||
|
|
||||||
#scan since we just got started
|
# Scan since we just got started
|
||||||
if auto_connect:
|
if auto_connect:
|
||||||
print "autoconnecting...",str(self.GetWirelessInterface()[5:])
|
print "autoconnecting...",str(self.GetWirelessInterface()[5:])
|
||||||
print self.AutoConnect(True)
|
print self.AutoConnect(True)
|
||||||
@@ -155,7 +167,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def Hello(self):
|
def Hello(self):
|
||||||
'''returns the version number'''
|
''' Returns the version number '''
|
||||||
#returns a version number.
|
#returns a version number.
|
||||||
#this number is major-minor-micro
|
#this number is major-minor-micro
|
||||||
#major is only incremented if minor
|
#major is only incremented if minor
|
||||||
@@ -165,14 +177,14 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
#micro is for everything else.
|
#micro is for everything else.
|
||||||
#and micro may be anything >= 0
|
#and micro may be anything >= 0
|
||||||
#this number is effective starting wicd v1.2.0
|
#this number is effective starting wicd v1.2.0
|
||||||
version = '1.3.3'
|
version = '1.4.0'
|
||||||
print 'returned version number',version
|
print 'returned version number',version
|
||||||
return version
|
return version
|
||||||
#end function Hello
|
#end function Hello
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetWiredInterface(self,interface):
|
def SetWiredInterface(self,interface):
|
||||||
'''sets the wired interface for the daemon to use'''
|
''' Sets the wired interface for the daemon to use '''
|
||||||
print "setting wired interface" , str(interface)
|
print "setting wired interface" , str(interface)
|
||||||
self.wired.wired_interface = interface
|
self.wired.wired_interface = interface
|
||||||
self.wifi.wired_interface = interface
|
self.wifi.wired_interface = interface
|
||||||
@@ -184,7 +196,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetWirelessInterface(self,interface):
|
def SetWirelessInterface(self,interface):
|
||||||
'''sets the wireless interface the daemon will use'''
|
''' Sets the wireless interface the daemon will use '''
|
||||||
print "setting wireless interface" , str(interface)
|
print "setting wireless interface" , str(interface)
|
||||||
self.wifi.wireless_interface = interface
|
self.wifi.wireless_interface = interface
|
||||||
self.wired.wireless_interface = interface
|
self.wired.wireless_interface = interface
|
||||||
@@ -197,7 +209,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetWPADriver(self,driver):
|
def SetWPADriver(self,driver):
|
||||||
'''sets the wpa driver the wpa_supplicant will use'''
|
''' Sets the wpa driver the wpa_supplicant will use '''
|
||||||
print "setting wpa driver" , str(driver)
|
print "setting wpa driver" , str(driver)
|
||||||
self.wifi.wpa_driver = driver
|
self.wifi.wpa_driver = driver
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
@@ -209,6 +221,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetUseGlobalDNS(self,use):
|
def SetUseGlobalDNS(self,use):
|
||||||
|
''' Sets a boolean which determines if global DNS is enabled '''
|
||||||
print 'setting use global dns to',use
|
print 'setting use global dns to',use
|
||||||
use = bool(use)
|
use = bool(use)
|
||||||
print 'setting use global dns to boolean',use
|
print 'setting use global dns to boolean',use
|
||||||
@@ -223,7 +236,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetGlobalDNS(self,dns1=None,dns2=None,dns3=None):
|
def SetGlobalDNS(self,dns1=None,dns2=None,dns3=None):
|
||||||
'''sets the global dns addresses'''
|
''' Sets the global dns addresses '''
|
||||||
print "setting global dns"
|
print "setting global dns"
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(self.app_conf)
|
config.read(self.app_conf)
|
||||||
@@ -247,35 +260,36 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetUseGlobalDNS(self):
|
def GetUseGlobalDNS(self):
|
||||||
|
''' Returns a boolean that determines if global dns is enabled '''
|
||||||
return bool(self.use_global_dns)
|
return bool(self.use_global_dns)
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetWPADriver(self):
|
def GetWPADriver(self):
|
||||||
'''returns the wpa driver the daemon is using'''
|
''' Returns the wpa driver the daemon is using '''
|
||||||
print 'returned wpa driver'
|
print 'returned wpa driver'
|
||||||
return str(self.wifi.wpa_driver)
|
return str(self.wifi.wpa_driver)
|
||||||
#end function GetWPADriver
|
#end function GetWPADriver
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetWiredInterface(self):
|
def GetWiredInterface(self):
|
||||||
'''returns the wired interface'''
|
''' Returns the wired interface '''
|
||||||
print 'returning wired interface'
|
print 'returning wired interface'
|
||||||
return str(self.wired.wired_interface)
|
return str(self.wired.wired_interface)
|
||||||
#end function GetWiredInterface
|
#end function GetWiredInterface
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetWirelessInterface(self):
|
def GetWirelessInterface(self):
|
||||||
'''returns the wireless interface the daemon is using'''
|
''' Returns the wireless interface the daemon is using '''
|
||||||
print 'returning wireless interface to client'
|
print 'returning wireless interface to client'
|
||||||
return str(self.wifi.wireless_interface)
|
return str(self.wifi.wireless_interface)
|
||||||
#end function GetWirelessInterface
|
#end function GetWirelessInterface
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetDebugMode(self, debug):
|
def SetDebugMode(self, debug):
|
||||||
'''sets if debugging mode is on or off'''
|
''' Sets if debugging mode is on or off '''
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(self.app_conf)
|
config.read(self.app_conf)
|
||||||
config.set("Settings","debug_mode",int(debug))
|
config.set("Settings","debug_mode",debug)
|
||||||
configfile = open(self.app_conf,"w")
|
configfile = open(self.app_conf,"w")
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
self.debug_mode = debug
|
self.debug_mode = debug
|
||||||
@@ -283,13 +297,13 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetDebugMode(self):
|
def GetDebugMode(self):
|
||||||
'''returns whether debugging is enabled'''
|
''' Returns whether debugging is enabled '''
|
||||||
return int(self.debug_mode)
|
return int(self.debug_mode)
|
||||||
#end function GetDebugMode
|
#end function GetDebugMode
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetSignalDisplayType(self):
|
def GetSignalDisplayType(self):
|
||||||
''' returns the signal display type
|
''' Returns the signal display type
|
||||||
|
|
||||||
Returns either 0 or 1.
|
Returns either 0 or 1.
|
||||||
0 for signal strength as a percentage
|
0 for signal strength as a percentage
|
||||||
@@ -304,7 +318,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
''' Sets the signal display type and writes it the wicd config file '''
|
''' Sets the signal display type and writes it the wicd config file '''
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(self.app_conf)
|
config.read(self.app_conf)
|
||||||
config.set("Settings","signal_display_type",int(value))
|
config.set("Settings","signal_display_type",value)
|
||||||
configfile = open(self.app_conf,"w")
|
configfile = open(self.app_conf,"w")
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
self.signal_display_type = value
|
self.signal_display_type = value
|
||||||
@@ -319,7 +333,6 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
return (signal + "%")
|
return (signal + "%")
|
||||||
# End function FormatSignalForPrinting
|
# End function FormatSignalForPrinting
|
||||||
|
|
||||||
|
|
||||||
@dbus.service. method('org.wicd.daemon')
|
@dbus.service. method('org.wicd.daemon')
|
||||||
def AutoConnect(self,fresh):
|
def AutoConnect(self,fresh):
|
||||||
'''first tries to autoconnect to a wired network, if that fails it tries a wireless connection'''
|
'''first tries to autoconnect to a wired network, if that fails it tries a wireless connection'''
|
||||||
@@ -328,31 +341,13 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
#self.AutoConnectScan() # Also scans for hidden networks
|
#self.AutoConnectScan() # Also scans for hidden networks
|
||||||
if self.CheckPluggedIn() == True:
|
if self.CheckPluggedIn() == True:
|
||||||
if self.GetWiredAutoConnectMethod() == 2:
|
if self.GetWiredAutoConnectMethod() == 2:
|
||||||
#self.SetNeedWiredProfileChooser(True)
|
|
||||||
self.LaunchChooser()
|
self.LaunchChooser()
|
||||||
elif self.GetWiredAutoConnectMethod() == 3:
|
|
||||||
lastUsedNetwork = self.GetLastUsedWiredNetwork()
|
|
||||||
if lastUsedNetwork != None:
|
|
||||||
self.ReadWiredNetworkProfile(lastUsedNetwork)
|
|
||||||
self.wired.profilename = lastUsedNetwork
|
|
||||||
self.ConnectWired()
|
|
||||||
time.sleep(1)
|
|
||||||
print "Attempting to autoconnect with last used wired interface..."
|
|
||||||
while self.CheckIfWiredConnecting(): #Leaving this for wired since you're probably not going to have DHCP problems
|
|
||||||
time.sleep(1)
|
|
||||||
print "...done autoconnecting with last used wired connection."
|
|
||||||
else:
|
|
||||||
print "there is no last used wired connection, wired autoconnect failed"
|
|
||||||
else:
|
else:
|
||||||
defaultNetwork = self.GetDefaultWiredNetwork()
|
defaultNetwork = self.GetDefaultWiredNetwork()
|
||||||
if defaultNetwork != None:
|
if defaultNetwork != None:
|
||||||
self.ReadWiredNetworkProfile(defaultNetwork)
|
self.ReadWiredNetworkProfile(defaultNetwork)
|
||||||
self.ConnectWired()
|
self.ConnectWired()
|
||||||
time.sleep(1)
|
|
||||||
print "Attempting to autoconnect with wired interface..."
|
print "Attempting to autoconnect with wired interface..."
|
||||||
while self.CheckIfWiredConnecting(): #Leaving this for wired since you're probably not going to have DHCP problems
|
|
||||||
time.sleep(1)
|
|
||||||
print "...done autoconnecting."
|
|
||||||
else:
|
else:
|
||||||
print "couldn't find a default wired connection, wired autoconnect failed"
|
print "couldn't find a default wired connection, wired autoconnect failed"
|
||||||
else:
|
else:
|
||||||
@@ -365,40 +360,11 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
if bool(self.LastScan[x].get('automatic')):
|
if bool(self.LastScan[x].get('automatic')):
|
||||||
print 'trying to automatically connect to...',str(self.LastScan[x]["essid"])
|
print 'trying to automatically connect to...',str(self.LastScan[x]["essid"])
|
||||||
self.ConnectWireless(x)
|
self.ConnectWireless(x)
|
||||||
time.sleep(5)
|
time.sleep(1)
|
||||||
return
|
return
|
||||||
#Changed this because the while loop would cause dbus errors if
|
|
||||||
#there was trouble connecting or connecting took a long time
|
|
||||||
#print "autoconnecting... hold"
|
|
||||||
#while self.CheckIfWirelessConnecting():
|
|
||||||
#not sure why I need to get IPs, but
|
|
||||||
#it solves the autoconnect problem
|
|
||||||
#i think it has something to do with
|
|
||||||
#making IO calls while threads are working...?
|
|
||||||
#if anyone knows why...email me at compwiz18@gmail.com
|
|
||||||
#only some people need these statements for autoconnect
|
|
||||||
#to function properly
|
|
||||||
#self.GetWirelessIP()
|
|
||||||
###
|
|
||||||
# removed line below for 1.3.0 - if there is trouble with
|
|
||||||
# connecting at boot,
|
|
||||||
# add back to file -- adam
|
|
||||||
###
|
|
||||||
# as far as I can tell, it seems fine - what does everyone else
|
|
||||||
# think? -- adam
|
|
||||||
###
|
|
||||||
#self.GetWiredIP()
|
|
||||||
#time.sleep(3)
|
|
||||||
#if self.GetWirelessIP() != None:
|
|
||||||
# print "autoconnecting... done"
|
|
||||||
# return
|
|
||||||
#else:
|
|
||||||
# print 'autoconnect was taking too long, aborted.'
|
|
||||||
# self.SetForcedDisconnect(True)
|
|
||||||
# return
|
|
||||||
print "unable to autoconnect, you'll have to manually connect"
|
print "unable to autoconnect, you'll have to manually connect"
|
||||||
else:
|
else:
|
||||||
print 'autoconnect failed because wireless interface == None'
|
print 'autoconnect failed because wireless interface returned None'
|
||||||
#end function AutoConnect
|
#end function AutoConnect
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
@@ -419,6 +385,14 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
return True
|
return True
|
||||||
#end function CheckIfConnecting
|
#end function CheckIfConnecting
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon')
|
||||||
|
def GetCurrentInterface(self):
|
||||||
|
return self.current_interface
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon')
|
||||||
|
def SetCurrentInterface(self, iface):
|
||||||
|
self.current_interface = iface
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetNeedWiredProfileChooser(self,val):
|
def SetNeedWiredProfileChooser(self,val):
|
||||||
self.need_profile_chooser = val
|
self.need_profile_chooser = val
|
||||||
@@ -432,21 +406,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
@dbus.service.signal(dbus_interface='org.wicd.daemon', signature='')
|
||||||
def LaunchChooser(self):
|
def LaunchChooser(self):
|
||||||
print 'calling wired profile chooser'
|
print 'calling wired profile chooser'
|
||||||
|
daemon.SetNeedWiredProfileChooser(True)
|
||||||
@dbus.service.signal(dbus_interface='org.wicd.daemon',signature='')
|
|
||||||
def CloseGui(self, killed):
|
|
||||||
''' Sends a dbus signal announcing the GUI is closing '''
|
|
||||||
print 'sending close signal'
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
|
||||||
def close_gui(self):
|
|
||||||
''' Calls the CloseGui method
|
|
||||||
|
|
||||||
intermediary method to send a signal announcing gui.py is being
|
|
||||||
closed. It's needed because a method can't be both a
|
|
||||||
service.method and service.signal
|
|
||||||
|
|
||||||
'''
|
|
||||||
self.CloseGui(True)
|
|
||||||
|
|
||||||
########## WIRELESS FUNCTIONS
|
########## WIRELESS FUNCTIONS
|
||||||
#################################
|
#################################
|
||||||
@@ -461,13 +421,12 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
def Scan(self):
|
def Scan(self):
|
||||||
'''scans for wireless networks, optionally using a (hidden) essid set with SetHiddenNetworkESSID'''
|
'''scans for wireless networks, optionally using a (hidden) essid set with SetHiddenNetworkESSID'''
|
||||||
print 'scanning start'
|
print 'scanning start'
|
||||||
scan = self.wifi.Scan(str(self.hidden_essid)) #_should_ already be a string but you never know...
|
scan = self.wifi.Scan(str(self.hidden_essid))
|
||||||
self.LastScan = scan
|
self.LastScan = scan
|
||||||
print 'scanning done'
|
print 'scanning done'
|
||||||
print 'found',str(len(scan)),'networks:',
|
print 'found',str(len(scan)),'networks:',
|
||||||
for i, network in enumerate(scan):
|
for i, network in enumerate(scan):
|
||||||
self.ReadWirelessNetworkProfile(i)
|
self.ReadWirelessNetworkProfile(i)
|
||||||
print
|
|
||||||
|
|
||||||
# This is unfinished so not on dbus yet
|
# This is unfinished so not on dbus yet
|
||||||
def AutoConnectScan(self):
|
def AutoConnectScan(self):
|
||||||
@@ -572,6 +531,10 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
'''retrieves wireless property from the network specified'''
|
'''retrieves wireless property from the network specified'''
|
||||||
value = self.LastScan[networkid].get(property)
|
value = self.LastScan[networkid].get(property)
|
||||||
print 'returned wireless network',networkid,'property',property,'of value',value
|
print 'returned wireless network',networkid,'property',property,'of value',value
|
||||||
|
try:
|
||||||
|
value = value.encode('utf-8')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return value
|
return value
|
||||||
#end function GetWirelessProperty
|
#end function GetWirelessProperty
|
||||||
|
|
||||||
@@ -595,7 +558,10 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def GetCurrentSignalStrength(self):
|
def GetCurrentSignalStrength(self):
|
||||||
'''returns the current signal strength'''
|
'''returns the current signal strength'''
|
||||||
|
try:
|
||||||
strength = int(self.wifi.GetSignalStrength())
|
strength = int(self.wifi.GetSignalStrength())
|
||||||
|
except:
|
||||||
|
strength = 0
|
||||||
print 'returning current signal strength',strength
|
print 'returning current signal strength',strength
|
||||||
return strength
|
return strength
|
||||||
#end function GetCurrentSignalStrength
|
#end function GetCurrentSignalStrength
|
||||||
@@ -630,9 +596,9 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def ConnectWireless(self,id):
|
def ConnectWireless(self,id):
|
||||||
'''connects the the wireless network specified by id'''
|
'''connects the the wireless network specified by id'''
|
||||||
#will returned instantly, that way we don't hold up dbus
|
# Will returned instantly, that way we don't hold up dbus.
|
||||||
# CheckIfWirelessConnecting can be used to test if the connection
|
# CheckIfWirelessConnecting can be used to test if the connection
|
||||||
#is done
|
# is done.
|
||||||
self.SetForcedDisconnect(False)
|
self.SetForcedDisconnect(False)
|
||||||
self.wifi.before_script = self.GetWirelessProperty(id,'beforescript')
|
self.wifi.before_script = self.GetWirelessProperty(id,'beforescript')
|
||||||
self.wifi.after_script = self.GetWirelessProperty(id,'afterscript')
|
self.wifi.after_script = self.GetWirelessProperty(id,'afterscript')
|
||||||
@@ -649,16 +615,22 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def SetForcedDisconnect(self,value):
|
def SetForcedDisconnect(self,value):
|
||||||
'''sets whether wireless has been disconnected by user since last connection'''
|
'''
|
||||||
|
|
||||||
|
Set to True when a user manually disconnects or cancels a connection.
|
||||||
|
It gets set to False as soon as the connection process is manually
|
||||||
|
started.
|
||||||
|
|
||||||
|
'''
|
||||||
self.forced_disconnect = value
|
self.forced_disconnect = value
|
||||||
#end function SetForcedDisconnect
|
#end function SetForcedDisconnect
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def CheckIfWirelessConnecting(self):
|
def CheckIfWirelessConnecting(self):
|
||||||
'''returns True if wireless interface is connecting, otherwise False'''
|
''' Returns True if wireless interface is connecting, otherwise False'''
|
||||||
if not self.wifi.connecting_thread == None:
|
if not self.wifi.connecting_thread == None:
|
||||||
#if connecting_thread exists, then check for it's
|
# If connecting_thread exists, then check for it's
|
||||||
#status, if it doesn't, we aren't connecting
|
# status, if it doesn't, we aren't connecting.
|
||||||
status = self.wifi.connecting_thread.is_connecting
|
status = self.wifi.connecting_thread.is_connecting
|
||||||
print 'wireless connecting',status
|
print 'wireless connecting',status
|
||||||
return status
|
return status
|
||||||
@@ -819,7 +791,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wired')
|
@dbus.service.method('org.wicd.daemon.wired')
|
||||||
def CheckPluggedIn(self):
|
def CheckPluggedIn(self):
|
||||||
if not self.wired.wired_interface == None:
|
if not self.wired.wired_interface == None and self.wired.wired_interface != "None":
|
||||||
return self.__printReturn('returning plugged in',self.wired.CheckPluggedIn())
|
return self.__printReturn('returning plugged in',self.wired.CheckPluggedIn())
|
||||||
else:
|
else:
|
||||||
return self.__printReturn("returning plugged in",None)
|
return self.__printReturn("returning plugged in",None)
|
||||||
@@ -828,7 +800,6 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
@dbus.service.method('org.wicd.daemon.wired')
|
@dbus.service.method('org.wicd.daemon.wired')
|
||||||
def ConnectWired(self):
|
def ConnectWired(self):
|
||||||
'''connects to a wired network'''
|
'''connects to a wired network'''
|
||||||
#simple enough.
|
|
||||||
self.wired.before_script = self.GetWiredProperty("beforescript")
|
self.wired.before_script = self.GetWiredProperty("beforescript")
|
||||||
self.wired.after_script = self.GetWiredProperty("afterscript")
|
self.wired.after_script = self.GetWiredProperty("afterscript")
|
||||||
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
|
self.wired.disconnect_script = self.GetWiredProperty("disconnectscript")
|
||||||
@@ -908,8 +879,6 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
self.SaveWiredNetworkProfile(profile)
|
self.SaveWiredNetworkProfile(profile)
|
||||||
#end function UnsetWiredDefault
|
#end function UnsetWiredDefault
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.config')
|
@dbus.service.method('org.wicd.daemon.config')
|
||||||
def GetDefaultWiredNetwork(self):
|
def GetDefaultWiredNetwork(self):
|
||||||
''' Returns the current default wired network '''
|
''' Returns the current default wired network '''
|
||||||
|
|||||||
83
gui.py
83
gui.py
@@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import wpath
|
import wpath
|
||||||
|
import signal
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
wpath.chdir(__file__)
|
wpath.chdir(__file__)
|
||||||
try:
|
try:
|
||||||
@@ -38,6 +39,7 @@ except:
|
|||||||
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
|
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
|
||||||
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
|
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
|
||||||
wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
|
wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
|
||||||
|
vpn_session = dbus.Interface(proxy_obj, 'org.wicd.daemon.vpn')
|
||||||
config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config')
|
config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config')
|
||||||
|
|
||||||
#Translation stuff
|
#Translation stuff
|
||||||
@@ -823,16 +825,8 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
def setMode(self,mode):
|
def setMode(self,mode):
|
||||||
self.lblMode.set_label(str(mode))
|
self.lblMode.set_label(str(mode))
|
||||||
|
|
||||||
class appGui:
|
class WiredProfileChooser:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print "starting gui.py..."
|
|
||||||
# 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:
|
|
||||||
daemon.SetNeedWiredProfileChooser(False)
|
|
||||||
# Profile chooser init block.
|
|
||||||
# Import and init WiredNetworkEntry to steal some of the
|
# Import and init WiredNetworkEntry to steal some of the
|
||||||
# functions and widgets it uses.
|
# functions and widgets it uses.
|
||||||
wiredNetEntry = WiredNetworkEntry()
|
wiredNetEntry = WiredNetworkEntry()
|
||||||
@@ -877,29 +871,37 @@ class appGui:
|
|||||||
config.ReadWiredNetworkProfile(wiredNetEntry.comboProfileNames.get_active_text())
|
config.ReadWiredNetworkProfile(wiredNetEntry.comboProfileNames.get_active_text())
|
||||||
wired.ConnectWired()
|
wired.ConnectWired()
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
sys.exit(0)
|
|
||||||
else:
|
else:
|
||||||
if stoppopcheckbox.get_active() == True:
|
if stoppopcheckbox.get_active() == True:
|
||||||
# Stops the pop-up from reappearing if cancelled
|
# Stops the pop-up from reappearing if cancelled
|
||||||
wired.use_default_profile = 1
|
wired.use_default_profile = 1
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
sys.exit(0)
|
class appGui:
|
||||||
else:
|
def __init__(self):
|
||||||
#normal init block
|
|
||||||
gladefile = "data/wicd.glade"
|
gladefile = "data/wicd.glade"
|
||||||
self.windowname = "gtkbench"
|
self.windowname = "gtkbench"
|
||||||
self.wTree = gtk.glade.XML(gladefile)
|
self.wTree = gtk.glade.XML(gladefile)
|
||||||
|
|
||||||
dic = { "refresh_clicked" : self.refresh_networks, "quit_clicked" : self.exit, 'disconnect_clicked' : self.disconnect_wireless, "main_exit" : self.exit, "cancel_clicked" : self.cancel_connect, "connect_clicked" : self.connect_hidden, "preferences_clicked" : self.settings_dialog, "about_clicked" : self.about_dialog, 'create_adhoc_network_button_button' : self.create_adhoc_network}
|
dic = { "on_vpn_connection" : self.on_vpn_connection,
|
||||||
|
"refresh_clicked" : self.refresh_networks,
|
||||||
|
"quit_clicked" : self.exit,
|
||||||
|
"disconnect_clicked" : self.disconnect_wireless,
|
||||||
|
"main_exit" : self.exit,
|
||||||
|
"cancel_clicked" : self.cancel_connect,
|
||||||
|
"connect_clicked" : self.connect_hidden,
|
||||||
|
"preferences_clicked" : self.settings_dialog,
|
||||||
|
"about_clicked" : self.about_dialog,
|
||||||
|
"create_adhoc_network_button_button" : self.create_adhoc_network}
|
||||||
self.wTree.signal_autoconnect(dic)
|
self.wTree.signal_autoconnect(dic)
|
||||||
|
|
||||||
#set some strings in the GUI - they may be translated
|
# Set some strings in the GUI - they may be translated
|
||||||
|
|
||||||
self.wTree.get_widget("label_instructions").set_label(language['select_a_network'])
|
self.wTree.get_widget("label_instructions").set_label(language['select_a_network'])
|
||||||
#I don't know how to translate a menu entry
|
# I don't know how to translate a menu entry.
|
||||||
#more specifically, I don't know how to set a menu entry's text
|
# More specifically, I don't know how to set a menu entry's text
|
||||||
# self.wTree.get_widget("connect_button").modify_text(language['_network'])
|
# self.wTree.get_widget("connect_button").modify_text(language['_network'])
|
||||||
self.wTree.get_widget("progressbar").set_text(language['connecting'])
|
self.wTree.get_widget("progressbar").set_text(language['connecting'])
|
||||||
|
self.window = self.wTree.get_widget("window1")
|
||||||
|
|
||||||
self.network_list = self.wTree.get_widget("network_list_vbox")
|
self.network_list = self.wTree.get_widget("network_list_vbox")
|
||||||
self.status_area = self.wTree.get_widget("connecting_hbox")
|
self.status_area = self.wTree.get_widget("connecting_hbox")
|
||||||
@@ -908,13 +910,17 @@ class appGui:
|
|||||||
|
|
||||||
self.statusID = None
|
self.statusID = None
|
||||||
|
|
||||||
gobject.timeout_add(300,self.update_statusbar)
|
self.vpn_connection_pipe = None
|
||||||
|
self.is_visible = True
|
||||||
|
|
||||||
|
self.window.connect('delete_event', self.exit)
|
||||||
|
|
||||||
|
gobject.timeout_add(600, self.update_statusbar)
|
||||||
gobject.timeout_add(100, self.pulse_progress_bar)
|
gobject.timeout_add(100, self.pulse_progress_bar)
|
||||||
|
|
||||||
def create_adhoc_network(self,widget=None):
|
def create_adhoc_network(self,widget=None):
|
||||||
'''shows a dialog that creates a new adhoc network'''
|
'''shows a dialog that creates a new adhoc network'''
|
||||||
#create a new adhoc network here.
|
print "Starting the Ad-Hoc Network Creation Process..."
|
||||||
print 'create adhoc network'
|
|
||||||
dialog = gtk.Dialog(title = language['create_adhoc_network'],
|
dialog = gtk.Dialog(title = language['create_adhoc_network'],
|
||||||
flags = gtk.DIALOG_MODAL,
|
flags = gtk.DIALOG_MODAL,
|
||||||
buttons=(gtk.STOCK_OK, 1, gtk.STOCK_CANCEL, 2))
|
buttons=(gtk.STOCK_OK, 1, gtk.STOCK_CANCEL, 2))
|
||||||
@@ -973,7 +979,8 @@ class appGui:
|
|||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def settings_dialog(self,widget,event=None):
|
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 = 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_has_separator(False)
|
||||||
dialog.set_size_request(465,-1)
|
dialog.set_size_request(465,-1)
|
||||||
wiredcheckbox = gtk.CheckButton(language['wired_always_on'])
|
wiredcheckbox = gtk.CheckButton(language['wired_always_on'])
|
||||||
@@ -1001,7 +1008,8 @@ class appGui:
|
|||||||
wpadriverlabel.set_size_request(75,-1)
|
wpadriverlabel.set_size_request(75,-1)
|
||||||
wpadrivercombo = gtk.combo_box_new_text()
|
wpadrivercombo = gtk.combo_box_new_text()
|
||||||
wpadrivercombo.set_size_request(50,-1)
|
wpadrivercombo.set_size_request(50,-1)
|
||||||
wpadrivers = [ "hostap","hermes","madwifi","atmel","wext","ndiswrapper","broadcom","ipw","ralink legacy" ]
|
wpadrivers = ["hostap","hermes","madwifi","atmel","wext","ndiswrapper",
|
||||||
|
"broadcom","ipw","ralink legacy"]
|
||||||
i = 0
|
i = 0
|
||||||
found = False
|
found = False
|
||||||
for x in wpadrivers:
|
for x in wpadrivers:
|
||||||
@@ -1011,12 +1019,11 @@ class appGui:
|
|||||||
if found == False:
|
if found == False:
|
||||||
i+=1
|
i+=1
|
||||||
wpadrivercombo.append_text(x)
|
wpadrivercombo.append_text(x)
|
||||||
#set active here.
|
# Set active here.
|
||||||
#if we set active an item to active, then add more items
|
# If we set active an item to active, then add more items
|
||||||
#it loses the activeness
|
# it loses the activeness.
|
||||||
wpadrivercombo.set_active(i)
|
wpadrivercombo.set_active(i)
|
||||||
#select wext as the default driver, because
|
# Select wext as the default driver, because it works for most cards
|
||||||
#it works for most cards
|
|
||||||
wpabox = gtk.HBox(False,1)
|
wpabox = gtk.HBox(False,1)
|
||||||
wpabox.pack_start(wpadriverlabel)
|
wpabox.pack_start(wpadriverlabel)
|
||||||
wpabox.pack_start(wpadrivercombo)
|
wpabox.pack_start(wpadrivercombo)
|
||||||
@@ -1085,10 +1092,8 @@ class appGui:
|
|||||||
daemon.SetWPADriver(wpadrivers[wpadrivercombo.get_active()])
|
daemon.SetWPADriver(wpadrivers[wpadrivercombo.get_active()])
|
||||||
wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active())
|
wired.SetAlwaysShowWiredInterface(wiredcheckbox.get_active())
|
||||||
wireless.SetAutoReconnect(reconnectcheckbox.get_active())
|
wireless.SetAutoReconnect(reconnectcheckbox.get_active())
|
||||||
|
|
||||||
daemon.SetDebugMode(debugmodecheckbox.get_active())
|
daemon.SetDebugMode(debugmodecheckbox.get_active())
|
||||||
daemon.SetSignalDisplayType(displaytypecheckbox.get_active())
|
daemon.SetSignalDisplayType(displaytypecheckbox.get_active())
|
||||||
|
|
||||||
if showlistradiobutton.get_active():
|
if showlistradiobutton.get_active():
|
||||||
wired.SetWiredAutoConnectMethod(2)
|
wired.SetWiredAutoConnectMethod(2)
|
||||||
elif lastusedradiobutton.get_active():
|
elif lastusedradiobutton.get_active():
|
||||||
@@ -1129,7 +1134,10 @@ class appGui:
|
|||||||
wireless.SetForcedDisconnect(True)
|
wireless.SetForcedDisconnect(True)
|
||||||
|
|
||||||
def pulse_progress_bar(self):
|
def pulse_progress_bar(self):
|
||||||
|
try:
|
||||||
self.wTree.get_widget("progressbar").pulse()
|
self.wTree.get_widget("progressbar").pulse()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def update_statusbar(self):
|
def update_statusbar(self):
|
||||||
@@ -1313,12 +1321,13 @@ class appGui:
|
|||||||
config.SaveWiredNetworkProfile(networkentry.expander.comboProfileNames.get_active_text())
|
config.SaveWiredNetworkProfile(networkentry.expander.comboProfileNames.get_active_text())
|
||||||
wired.ConnectWired()
|
wired.ConnectWired()
|
||||||
|
|
||||||
def exit(self,widget,event=None):
|
def exit(self, widget=None, event=None):
|
||||||
# Call close_gui so the daemon can send a signal to alert
|
self.window.hide()
|
||||||
# the tray that the gui has closed (prevents zombies)
|
self.is_visible = False
|
||||||
daemon.close_gui()
|
while gtk.events_pending():
|
||||||
sys.exit(0)
|
gtk.main_iteration()
|
||||||
|
return True
|
||||||
|
|
||||||
#start the app
|
def show_win(self):
|
||||||
app = appGui()
|
self.window.show_all()
|
||||||
gtk.main()
|
self.is_visible = True
|
||||||
|
|||||||
89
misc.py
89
misc.py
@@ -1,7 +1,7 @@
|
|||||||
''' Misc - miscellaneous functions for wicd '''
|
''' Misc - miscellaneous functions for wicd '''
|
||||||
|
|
||||||
#pretty much useless to anyone else...
|
# Pretty much useless to anyone else...
|
||||||
#but if it is useful, feel free to use under the terms of the GPL
|
# But if it is useful, feel free to use under the terms of the GPL
|
||||||
#
|
#
|
||||||
# This is released under the
|
# This is released under the
|
||||||
# GNU General Public License
|
# GNU General Public License
|
||||||
@@ -13,8 +13,14 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import wpath
|
import wpath
|
||||||
|
import locale
|
||||||
|
import gettext
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
wpath.chdir(__file__)
|
wpath.chdir(__file__)
|
||||||
|
|
||||||
def Run(cmd, include_std_error = False):
|
def Run(cmd, include_std_error = False):
|
||||||
''' Run a command '''
|
''' Run a command '''
|
||||||
if not include_std_error:
|
if not include_std_error:
|
||||||
@@ -48,6 +54,10 @@ def RunRegex(regex,string):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def log(text):
|
||||||
|
log = self.LogWriter()
|
||||||
|
log.write(text + "\n")
|
||||||
|
|
||||||
def WriteLine(my_file, text):
|
def WriteLine(my_file, text):
|
||||||
''' write a line to a file '''
|
''' write a line to a file '''
|
||||||
my_file.write(text + "\n")
|
my_file.write(text + "\n")
|
||||||
@@ -189,3 +199,78 @@ def noneToString(text):
|
|||||||
return "None"
|
return "None"
|
||||||
else:
|
else:
|
||||||
return str(text)
|
return str(text)
|
||||||
|
|
||||||
|
def get_gettext():
|
||||||
|
local_path = os.path.realpath(os.path.dirname(sys.argv[0])) + '/translations'
|
||||||
|
langs = []
|
||||||
|
lc, encoding = locale.getdefaultlocale()
|
||||||
|
if (lc):
|
||||||
|
langs = [lc]
|
||||||
|
osLanguage = os.environ.get('LANGUAGE', None)
|
||||||
|
if (osLanguage):
|
||||||
|
langs += osLanguage.split(":")
|
||||||
|
langs += ["en_US"]
|
||||||
|
lang = gettext.translation('wicd', local_path, languages=langs,
|
||||||
|
fallback = True)
|
||||||
|
_ = lang.gettext
|
||||||
|
return _
|
||||||
|
|
||||||
|
class LogWriter():
|
||||||
|
""" A class to provide timestamped logging. """
|
||||||
|
def __init__(self):
|
||||||
|
self.file = open(wpath.log + 'wicd.log','a')
|
||||||
|
self.eol = True
|
||||||
|
self.logging_enabled = True
|
||||||
|
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.file.close()
|
||||||
|
|
||||||
|
|
||||||
|
def write(self, data):
|
||||||
|
""" Writes the data to the log with a timestamp.
|
||||||
|
|
||||||
|
This function handles writing of data to a log file. In order to
|
||||||
|
handle output redirection, we need to be careful with how we
|
||||||
|
handle the addition of timestamps. In any set of data that is
|
||||||
|
written, we replace the newlines with a timestamp + new line,
|
||||||
|
except for newlines that are the final character in data.
|
||||||
|
|
||||||
|
When a newline is the last character in data, we set a flag to
|
||||||
|
indicate that the next write should have a timestamp prepended
|
||||||
|
as well, which ensures that the timestamps match the time at
|
||||||
|
which the data is written, rather than the previous write.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
data -- The string to write to the log.
|
||||||
|
|
||||||
|
"""
|
||||||
|
#global logging_enabled
|
||||||
|
data = data.encode('utf-8')
|
||||||
|
if len(data) <= 0: return
|
||||||
|
if self.logging_enabled:
|
||||||
|
if self.eol:
|
||||||
|
self.file.write(self.get_time() + ' :: ')
|
||||||
|
self.eol = False
|
||||||
|
|
||||||
|
if data[-1] == '\n':
|
||||||
|
self.eol = True
|
||||||
|
data = data[:-1]
|
||||||
|
|
||||||
|
self.file.write(
|
||||||
|
data.replace('\n', '\n' + self.get_time() + ' :: '))
|
||||||
|
if self.eol: self.file.write('\n')
|
||||||
|
self.file.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def get_time(self):
|
||||||
|
""" Return a string with the current time nicely formatted.
|
||||||
|
|
||||||
|
The format of the returned string is yyyy/mm/dd HH:MM:SS
|
||||||
|
|
||||||
|
"""
|
||||||
|
x = time.localtime()
|
||||||
|
return ''.join([
|
||||||
|
str(x[0]).rjust(4,'0'), '/', str(x[1]).rjust(2,'0'), '/',
|
||||||
|
str(x[2]).rjust(2,'0'), ' ', str(x[3]).rjust(2,'0'), ':',
|
||||||
|
str(x[4]).rjust(2,'0'), ':', str(x[5]).rjust(2,'0')])
|
||||||
@@ -47,6 +47,7 @@ import thread
|
|||||||
import misc
|
import misc
|
||||||
import wnettools
|
import wnettools
|
||||||
import wpath
|
import wpath
|
||||||
|
import os
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
wpath.chdir(__file__)
|
wpath.chdir(__file__)
|
||||||
@@ -81,7 +82,6 @@ class ConnectThread(threading.Thread):
|
|||||||
should_die = False
|
should_die = False
|
||||||
lock = thread.allocate_lock()
|
lock = thread.allocate_lock()
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, network, wireless, wired,
|
def __init__(self, network, wireless, wired,
|
||||||
before_script, after_script, disconnect_script, gdns1,
|
before_script, after_script, disconnect_script, gdns1,
|
||||||
gdns2, gdns3):
|
gdns2, gdns3):
|
||||||
@@ -290,7 +290,8 @@ class Wireless(Controller):
|
|||||||
misc.Run('iptables -N fw-open')
|
misc.Run('iptables -N fw-open')
|
||||||
misc.Run('iptables -F fw-interfaces')
|
misc.Run('iptables -F fw-interfaces')
|
||||||
misc.Run('iptables -F fw-open')
|
misc.Run('iptables -F fw-open')
|
||||||
misc.Run('iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu')
|
misc.Run('iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS \
|
||||||
|
--clamp-mss-to-pmtu')
|
||||||
misc.Run('iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT')
|
misc.Run('iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT')
|
||||||
misc.Run('iptables -A FORWARD -j fw-interfaces ')
|
misc.Run('iptables -A FORWARD -j fw-interfaces ')
|
||||||
misc.Run('iptables -A FORWARD -j fw-open ')
|
misc.Run('iptables -A FORWARD -j fw-open ')
|
||||||
@@ -298,7 +299,9 @@ class Wireless(Controller):
|
|||||||
misc.Run('iptables -P FORWARD DROP')
|
misc.Run('iptables -P FORWARD DROP')
|
||||||
misc.Run('iptables -A fw-interfaces -i ' + self.wireless_interface + ' -j ACCEPT')
|
misc.Run('iptables -A fw-interfaces -i ' + self.wireless_interface + ' -j ACCEPT')
|
||||||
net_ip = '.'.join(ip_parts[0:3]) + '.0'
|
net_ip = '.'.join(ip_parts[0:3]) + '.0'
|
||||||
misc.Run('iptables -t nat -A POSTROUTING -s ' + net_ip + '/255.255.255.0 -o ' + self.wired_interface + ' -j MASQUERADE')
|
misc.Run('iptables -t nat -A POSTROUTING -s ' + net_ip + \
|
||||||
|
'/255.255.255.0 -o ' + self.wired_interface + \
|
||||||
|
' -j MASQUERADE')
|
||||||
misc.Run('echo 1 > /proc/sys/net/ipv4/ip_forward') # Enable routing
|
misc.Run('echo 1 > /proc/sys/net/ipv4/ip_forward') # Enable routing
|
||||||
|
|
||||||
|
|
||||||
@@ -323,8 +326,6 @@ class Wireless(Controller):
|
|||||||
wiface.SetAddress('0.0.0.0')
|
wiface.SetAddress('0.0.0.0')
|
||||||
wiface.Down()
|
wiface.Down()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class WirelessConnectThread(ConnectThread):
|
class WirelessConnectThread(ConnectThread):
|
||||||
""" A thread class to perform the connection to a wireless network.
|
""" A thread class to perform the connection to a wireless network.
|
||||||
|
|
||||||
@@ -459,8 +460,7 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
wiface.StartDHCP()
|
wiface.StartDHCP()
|
||||||
|
|
||||||
if ((self.network.get('dns1') or self.network.get('dns2') or
|
if ((self.network.get('dns1') or self.network.get('dns2') or
|
||||||
self.network.get('dns3')) and
|
self.network.get('dns3')) and self.network.get('use_static_dns')):
|
||||||
self.network.get('use_static_dns')):
|
|
||||||
self.SetStatus('setting_static_dns')
|
self.SetStatus('setting_static_dns')
|
||||||
if self.network.get('use_global_dns'):
|
if self.network.get('use_global_dns'):
|
||||||
wnettools.SetDNS(misc.Noneify(self.global_dns_1),
|
wnettools.SetDNS(misc.Noneify(self.global_dns_1),
|
||||||
@@ -470,7 +470,7 @@ class WirelessConnectThread(ConnectThread):
|
|||||||
wnettools.SetDNS(self.network.get('dns1'),
|
wnettools.SetDNS(self.network.get('dns1'),
|
||||||
self.network.get('dns2'), self.network.get('dns3'))
|
self.network.get('dns2'), self.network.get('dns3'))
|
||||||
|
|
||||||
#save as last used profile
|
# Save as last used profile
|
||||||
print 'Saving last used profile'
|
print 'Saving last used profile'
|
||||||
config.UnsetLastUsedDefault() # Makes sure there is only one last used profile at a time
|
config.UnsetLastUsedDefault() # Makes sure there is only one last used profile at a time
|
||||||
self.network.SetWiredProperty("lastused", True)
|
self.network.SetWiredProperty("lastused", True)
|
||||||
@@ -596,7 +596,7 @@ class WiredConnectThread(ConnectThread):
|
|||||||
|
|
||||||
# Execute pre-connection script if necessary
|
# Execute pre-connection script if necessary
|
||||||
if self.before_script != '' and self.before_script != None:
|
if self.before_script != '' and self.before_script != None:
|
||||||
print 'executing pre-connectiong script'
|
print 'executing pre-connection script'
|
||||||
misc.ExecuteScript(self.before_script)
|
misc.ExecuteScript(self.before_script)
|
||||||
|
|
||||||
# Put it down
|
# Put it down
|
||||||
@@ -645,8 +645,7 @@ class WiredConnectThread(ConnectThread):
|
|||||||
liface.StartDHCP()
|
liface.StartDHCP()
|
||||||
|
|
||||||
if ((self.network.get('dns1') or self.network.get('dns2') or
|
if ((self.network.get('dns1') or self.network.get('dns2') or
|
||||||
self.network.get('dns3')) and
|
self.network.get('dns3')) and self.network.get('use_static_dns')):
|
||||||
self.network.get('use_static_dns')):
|
|
||||||
self.SetStatus('setting_static_dns')
|
self.SetStatus('setting_static_dns')
|
||||||
if self.network.get('use_global_dns'):
|
if self.network.get('use_global_dns'):
|
||||||
wnettools.SetDNS(misc.Noneify(self.global_dns_1),
|
wnettools.SetDNS(misc.Noneify(self.global_dns_1),
|
||||||
|
|||||||
501
wicd.py
Executable file
501
wicd.py
Executable file
@@ -0,0 +1,501 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
""" wicd - wireless connection daemon frontend implementation
|
||||||
|
|
||||||
|
This module implements a usermode frontend for wicd. It updates connection
|
||||||
|
information, provides an (optional) tray icon, and allows for launching of
|
||||||
|
the wicd GUI and Wired Profile Chooser.
|
||||||
|
|
||||||
|
class TrayIcon() -- Parent class of TrayIconGUI and IconConnectionInfo.
|
||||||
|
class TrayConnectionInfo() -- Child class of TrayIcon which provides
|
||||||
|
and updates connection status.
|
||||||
|
class TrayIconGUI() -- Child class of TrayIcon which implements the tray.
|
||||||
|
icon itself. Parent class of EdgyTrayIconGUI and DapperTrayIconGUI.
|
||||||
|
class EdgyTrayIconGUI() -- Implements the tray icon using a gtk.StatusIcon.
|
||||||
|
class DapperTrayIconGUI() -- Implements the tray icon using egg.trayicon.
|
||||||
|
def usage() -- Prints usage information.
|
||||||
|
def main() -- Runs the wicd frontend main loop.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright (C) 2007 Adam Blackburn
|
||||||
|
# Copyright (C) 2007 Dan O'Reilly
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import gtk
|
||||||
|
import gobject
|
||||||
|
import dbus
|
||||||
|
import dbus.service
|
||||||
|
import locale
|
||||||
|
import gettext
|
||||||
|
import signal
|
||||||
|
import getopt
|
||||||
|
|
||||||
|
# Import egg.trayicon if we're using an older gtk version
|
||||||
|
if not (gtk.gtk_version[0] >= 2 and gtk.gtk_version[1] >= 10):
|
||||||
|
import egg.trayicon
|
||||||
|
USE_EGG = True
|
||||||
|
else:
|
||||||
|
USE_EGG = False
|
||||||
|
|
||||||
|
if getattr(dbus, 'version', (0, 0, 0)) >= (0, 41, 0):
|
||||||
|
import dbus.glib
|
||||||
|
|
||||||
|
# Wicd specific imports
|
||||||
|
import wpath
|
||||||
|
import misc
|
||||||
|
import gui
|
||||||
|
|
||||||
|
if sys.platform == 'linux2':
|
||||||
|
# Set process name. Only works on Linux >= 2.1.57.
|
||||||
|
try:
|
||||||
|
import dl
|
||||||
|
libc = dl.open('/lib/libc.so.6')
|
||||||
|
libc.call('prctl', 15, 'wicd\0', 0, 0, 0) # 15 is PR_SET_NAME
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
wpath.chdir(__file__)
|
||||||
|
|
||||||
|
log = misc.LogWriter()
|
||||||
|
bus = dbus.SystemBus()
|
||||||
|
|
||||||
|
# Connect to the daemon
|
||||||
|
try:
|
||||||
|
log.write('Attempting to connect daemon...')
|
||||||
|
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
|
||||||
|
log.write('Success.')
|
||||||
|
except:
|
||||||
|
log.write('Daemon not running...')
|
||||||
|
misc.PromptToStartDaemon()
|
||||||
|
|
||||||
|
daemon = dbus.Interface(proxy_obj, 'org.wicd.daemon')
|
||||||
|
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
|
||||||
|
wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
|
||||||
|
config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config')
|
||||||
|
|
||||||
|
_ = misc.get_gettext()
|
||||||
|
language = {}
|
||||||
|
language['connected_to_wireless'] = _('Connected to $A at $B (IP: $C)')
|
||||||
|
language['connected_to_wired'] = _('Connected to wired network (IP: $A)')
|
||||||
|
language['not_connected'] = _('Not connected')
|
||||||
|
language['connecting'] = _('Connecting...')
|
||||||
|
|
||||||
|
class TrayIcon():
|
||||||
|
def __init__(self, use_tray):
|
||||||
|
if USE_EGG:
|
||||||
|
self.tr = self.DapperIconGUI(use_tray)
|
||||||
|
else:
|
||||||
|
self.tr = self.EdgyTrayIconGUI(use_tray)
|
||||||
|
self.icon_info = self.TrayConnectionInfo(self.tr)
|
||||||
|
|
||||||
|
class TrayConnectionInfo():
|
||||||
|
''' class for updating the tray icon status '''
|
||||||
|
def __init__(self, tr):
|
||||||
|
''' initialize variables needed for the icon status methods '''
|
||||||
|
self.last_strength = -2
|
||||||
|
self.still_wired = False
|
||||||
|
self.network = ''
|
||||||
|
self.tried_reconnect = False
|
||||||
|
self.connection_lost_counter = 0
|
||||||
|
self.tr = tr
|
||||||
|
|
||||||
|
def wired_profile_chooser(self):
|
||||||
|
''' Launched the wired profile chooser '''
|
||||||
|
daemon.SetNeedWiredProfileChooser(False)
|
||||||
|
chooser = gui.WiredProfileChooser()
|
||||||
|
|
||||||
|
def check_for_wired_connection(self, wired_ip):
|
||||||
|
''' Checks for an active wired connection
|
||||||
|
|
||||||
|
Checks for and updates the tray icon for an active wired connection
|
||||||
|
Returns True if wired connection is active, false if inactive.
|
||||||
|
|
||||||
|
'''
|
||||||
|
if wired_ip is not None and wired.CheckPluggedIn():
|
||||||
|
# Only set image/tooltip if it hasn't been set already
|
||||||
|
# and the wire is actually plugged in.
|
||||||
|
if not self.still_wired:
|
||||||
|
daemon.SetCurrentInterface(daemon.GetWiredInterface())
|
||||||
|
self.tr.set_from_file("images/wired.png")
|
||||||
|
self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
|
||||||
|
wired_ip))
|
||||||
|
self.still_wired = True
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def check_for_wireless_connection(self, wireless_ip):
|
||||||
|
''' Checks for an active wireless connection
|
||||||
|
|
||||||
|
Checks for and updates the tray icon for an active wireless connection
|
||||||
|
Returns True if wireless connection is active, False otherwise.
|
||||||
|
|
||||||
|
'''
|
||||||
|
if wireless.GetWirelessIP() is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Reset this, just in case
|
||||||
|
self.tried_reconnect = False
|
||||||
|
|
||||||
|
# Try getting signal strength, default to 0 if something goes wrong.
|
||||||
|
try:
|
||||||
|
if daemon.GetSignalDisplayType() == 0:
|
||||||
|
wireless_signal = int(wireless.GetCurrentSignalStrength())
|
||||||
|
else:
|
||||||
|
wireless_signal = int(wireless.GetCurrentDBMStrength())
|
||||||
|
except:
|
||||||
|
wireless_signal = 0
|
||||||
|
|
||||||
|
if wireless_signal == 0:
|
||||||
|
# If we have no signal, increment connection loss counter.
|
||||||
|
# If we haven't gotten any signal 4 runs in a row (12 seconds),
|
||||||
|
# try to reconnect.
|
||||||
|
self.connection_lost_counter += 1
|
||||||
|
print self.connection_lost_counter
|
||||||
|
if self.connection_lost_counter > 4:
|
||||||
|
self.connection_lost_counter = 0
|
||||||
|
self.auto_reconnect()
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Only update if the signal strength has changed because doing I/O
|
||||||
|
# calls is expensive, and the icon flickers
|
||||||
|
if (wireless_signal != self.last_strength or
|
||||||
|
self.network != wireless.GetCurrentNetwork()):
|
||||||
|
self.last_strength = wireless_signal
|
||||||
|
# Set the string to '' so that when it is put in "high-signal" +
|
||||||
|
# lock + ".png", there will be nothing
|
||||||
|
lock = ''
|
||||||
|
|
||||||
|
# cur_net_id needs to be checked because a negative value
|
||||||
|
# will break the tray when passed to GetWirelessProperty.
|
||||||
|
cur_net_id = wireless.GetCurrentNetworkID()
|
||||||
|
|
||||||
|
if cur_net_id > -1 and \
|
||||||
|
wireless.GetWirelessProperty(cur_net_id, "encryption"):
|
||||||
|
# Set the string to '-lock' so that it will display the
|
||||||
|
# lock picture
|
||||||
|
lock = '-lock'
|
||||||
|
# Update the tooltip and icon picture
|
||||||
|
self.network = str(wireless.GetCurrentNetwork())
|
||||||
|
daemon.SetCurrentInterface(daemon.GetWirelessInterface())
|
||||||
|
str_signal = daemon.FormatSignalForPrinting(str(wireless_signal))
|
||||||
|
self.tr.set_tooltip(language['connected_to_wireless']
|
||||||
|
.replace('$A', self.network)
|
||||||
|
.replace('$B', str_signal)
|
||||||
|
.replace('$C', str(wireless_ip)))
|
||||||
|
self.set_signal_image(wireless_signal, lock)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def update_tray_icon(self):
|
||||||
|
''' Updates the tray icon and current connection status '''
|
||||||
|
|
||||||
|
# Disable logging if debugging isn't on to prevent log spam
|
||||||
|
if not daemon.GetDebugMode():
|
||||||
|
config.DisableLogging()
|
||||||
|
|
||||||
|
# First check for an active wired network, then for an
|
||||||
|
# active wireless network. If neither is found, change
|
||||||
|
# icon to reflect that and run auto_reconnect()
|
||||||
|
wired_ip = wired.GetWiredIP()
|
||||||
|
wired_found = self.check_for_wired_connection(wired_ip)
|
||||||
|
if not wired_found:
|
||||||
|
self.still_wired = False # We're not wired any more
|
||||||
|
wireless_ip = wireless.GetWirelessIP()
|
||||||
|
wireless_found = self.check_for_wireless_connection(wireless_ip)
|
||||||
|
if not wireless_found: # No connection at all
|
||||||
|
self.tr.set_from_file("images/no-signal.png")
|
||||||
|
if daemon.CheckIfConnecting():
|
||||||
|
self.tr.set_tooltip(language['connecting'])
|
||||||
|
else:
|
||||||
|
self.tr.set_tooltip(language['not_connected'])
|
||||||
|
daemon.SetCurrentInterface('')
|
||||||
|
self.auto_reconnect()
|
||||||
|
|
||||||
|
if not daemon.GetDebugMode():
|
||||||
|
config.EnableLogging()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def set_signal_image(self, wireless_signal, lock):
|
||||||
|
''' Sets the tray icon picture for an active wireless connection '''
|
||||||
|
if wireless_signal == 0:
|
||||||
|
# We handle a signal of 0 the same regardless of dBm or %
|
||||||
|
# signal strength. Set the image based on connection loss
|
||||||
|
# counter, and then return so the counter isn't reset.
|
||||||
|
if self.connection_lost_counter < 4:
|
||||||
|
self.tr.set_from_file(wpath.images + "bad-signal" + lock + ".png")
|
||||||
|
else:
|
||||||
|
self.tr.set_from_file(wpath.images + "no-signal.png")
|
||||||
|
return
|
||||||
|
elif daemon.GetSignalDisplayType() == 0:
|
||||||
|
if wireless_signal > 75:
|
||||||
|
self.tr.set_from_file(wpath.images + "high-signal" + lock + ".png")
|
||||||
|
elif wireless_signal > 50:
|
||||||
|
self.tr.set_from_file(wpath.images + "good-signal" + lock + ".png")
|
||||||
|
elif wireless_signal > 25:
|
||||||
|
self.tr.set_from_file(wpath.images + "low-signal" + lock + ".png")
|
||||||
|
elif wireless_signal > 0:
|
||||||
|
self.tr.set_from_file(wpath.images + "bad-signal" + lock + ".png")
|
||||||
|
else:
|
||||||
|
if wireless_signal >= -60:
|
||||||
|
self.tr.set_from_file(wpath.images + "high-signal" + lock + ".png")
|
||||||
|
elif wireless_signal >= -70:
|
||||||
|
self.tr.set_from_file(wpath.images + "good-signal" + lock + ".png")
|
||||||
|
elif wireless_signal >= -80:
|
||||||
|
self.tr.set_from_file(wpath.images + "low-signal" + lock + ".png")
|
||||||
|
else:
|
||||||
|
self.tr.set_from_file(wpath.images + "bad-signal" + lock + ".png")
|
||||||
|
# Since we have a signal, we should reset
|
||||||
|
# the connection loss counter.
|
||||||
|
self.connection_lost_counter = 0
|
||||||
|
|
||||||
|
def auto_reconnect(self):
|
||||||
|
''' Automatically reconnects to a network if needed
|
||||||
|
|
||||||
|
If automatic reconnection is turned on, this method will
|
||||||
|
attempt to first reconnect to the last used wireless network, and
|
||||||
|
should that fail will simply run AutoConnect()
|
||||||
|
|
||||||
|
'''
|
||||||
|
if wireless.GetAutoReconnect() and not daemon.CheckIfConnecting() and \
|
||||||
|
not wireless.GetForcedDisconnect():
|
||||||
|
print 'Starting automatic reconnect process'
|
||||||
|
# First try connecting through ethernet
|
||||||
|
if wired.CheckPluggedIn():
|
||||||
|
print "Wired connection available, trying to connect..."
|
||||||
|
daemon.AutoConnect(False)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Next try the last wireless network we were connected to
|
||||||
|
cur_net_id = wireless.GetCurrentNetworkID()
|
||||||
|
if cur_net_id > -1: # Needs to be a valid network
|
||||||
|
if not self.tried_reconnect:
|
||||||
|
print 'Trying to reconnect to last used wireless network'
|
||||||
|
wireless.ConnectWireless(cur_net_id)
|
||||||
|
self.tried_reconnect = True
|
||||||
|
elif wireless.CheckIfWirelessConnecting() == False:
|
||||||
|
print "Couldn't reconnect to last used network, \
|
||||||
|
scanning for an autoconnect network..."
|
||||||
|
daemon.AutoConnect(True)
|
||||||
|
else:
|
||||||
|
daemon.AutoConnect(True)
|
||||||
|
|
||||||
|
class TrayIconGUI():
|
||||||
|
def __init__(self):
|
||||||
|
menu = '''
|
||||||
|
<ui>
|
||||||
|
<menubar name="Menubar">
|
||||||
|
<menu action="Menu">
|
||||||
|
<menuitem action="Connect"/>
|
||||||
|
<separator/>
|
||||||
|
<menuitem action="About"/>
|
||||||
|
<menuitem action="Quit"/>
|
||||||
|
</menu>
|
||||||
|
</menubar>
|
||||||
|
</ui>
|
||||||
|
'''
|
||||||
|
actions = [
|
||||||
|
('Menu', None, 'Menu'),
|
||||||
|
('Connect', gtk.STOCK_CONNECT, '_Connect...', None,
|
||||||
|
'Connect to network', self.on_preferences),
|
||||||
|
('About', gtk.STOCK_ABOUT, '_About...', None,
|
||||||
|
'About wicd-tray-icon', self.on_about),
|
||||||
|
('Quit',gtk.STOCK_QUIT,'_Quit',None,'Quit wicd-tray-icon',
|
||||||
|
self.on_quit),
|
||||||
|
]
|
||||||
|
actg = gtk.ActionGroup('Actions')
|
||||||
|
actg.add_actions(actions)
|
||||||
|
self.manager = gtk.UIManager()
|
||||||
|
self.manager.insert_action_group(actg, 0)
|
||||||
|
self.manager.add_ui_from_string(menu)
|
||||||
|
self.menu = self.manager.get_widget('/Menubar/Menu/About').props.parent
|
||||||
|
self.gui_win = None
|
||||||
|
|
||||||
|
def on_activate(self, data=None):
|
||||||
|
''' Opens the wicd GUI '''
|
||||||
|
self.toggle_wicd_gui()
|
||||||
|
|
||||||
|
def on_quit(self, widget=None):
|
||||||
|
''' Closes the tray icon '''
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
def on_preferences(self, data=None):
|
||||||
|
''' Opens the wicd GUI '''
|
||||||
|
self.toggle_wicd_gui()
|
||||||
|
|
||||||
|
def on_about(self, data = None):
|
||||||
|
''' Opens the About Dialog '''
|
||||||
|
dialog = gtk.AboutDialog()
|
||||||
|
dialog.set_name('wicd tray icon')
|
||||||
|
dialog.set_version('0.4')
|
||||||
|
dialog.set_comments('an icon that shows your network connectivity')
|
||||||
|
dialog.set_website('http://wicd.sourceforge.net')
|
||||||
|
dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
|
def set_from_file(self, path = None):
|
||||||
|
''' Sets a new tray icon picture '''
|
||||||
|
if not self.use_tray: return
|
||||||
|
if path != self.current_icon_path:
|
||||||
|
self.current_icon_path = path
|
||||||
|
gtk.StatusIcon.set_from_file(self, path)
|
||||||
|
|
||||||
|
def toggle_wicd_gui(self):
|
||||||
|
''' Toggles the wicd GUI '''
|
||||||
|
if self.gui_win == None:
|
||||||
|
self.gui_win = gui.appGui()
|
||||||
|
elif self.gui_win.is_active == False:
|
||||||
|
self.gui_win.show_win()
|
||||||
|
else:
|
||||||
|
self.gui_win.exit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class DapperTrayIconGUI(TrayIconGUI):
|
||||||
|
def __init__(self, use_tray=True):
|
||||||
|
''' initializes the tray icon '''
|
||||||
|
TrayIcon.TrayIconGUI.__init__()
|
||||||
|
self.use_tray = use_tray
|
||||||
|
if not use_tray:
|
||||||
|
self.toggle_wicd_gui()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.tooltip = gtk.Tooltips()
|
||||||
|
self.eb = gtk.EventBox()
|
||||||
|
self.tray = egg.trayicon.TrayIcon("WicdTrayIcon")
|
||||||
|
self.pic = gtk.Image()
|
||||||
|
self.tooltip.set_tip(self.eb, "Initializing wicd...")
|
||||||
|
self.pic.set_from_file("images/no-signal.png")
|
||||||
|
|
||||||
|
self.eb.connect('button_press_event', tray_display.tray_clicked)
|
||||||
|
self.eb.add(pic)
|
||||||
|
self.tray.add(eb)
|
||||||
|
self.tray.show_all()
|
||||||
|
|
||||||
|
def tray_clicked(self, widget, event):
|
||||||
|
''' Handles tray mouse click events '''
|
||||||
|
if event.button == 1:
|
||||||
|
self.open_wicd_gui()
|
||||||
|
if event.button == 3:
|
||||||
|
self.menu.popup(None, None, None, event.button, event.time)
|
||||||
|
|
||||||
|
def set_from_file(str):
|
||||||
|
''' Calls set_from_file on the gtk.Image for the tray icon '''
|
||||||
|
if not self.use_tray: return
|
||||||
|
self.pic.set_from_file(str)
|
||||||
|
|
||||||
|
def set_tooltip(str):
|
||||||
|
'''
|
||||||
|
Sets the tooltip for the gtk.ToolTips associated with this
|
||||||
|
tray icon.
|
||||||
|
'''
|
||||||
|
if not self.use_tray: return
|
||||||
|
self.tooltip.set_tip(self.eb, str)
|
||||||
|
|
||||||
|
class EdgyTrayIconGUI(gtk.StatusIcon, TrayIconGUI):
|
||||||
|
''' Class for creating the wicd tray icon '''
|
||||||
|
def __init__(self, use_tray=True):
|
||||||
|
TrayIcon.TrayIconGUI.__init__(self)
|
||||||
|
self.use_tray = use_tray
|
||||||
|
if not use_tray:
|
||||||
|
self.toggle_wicd_gui()
|
||||||
|
return
|
||||||
|
|
||||||
|
gtk.StatusIcon.__init__(self)
|
||||||
|
|
||||||
|
self.current_icon_path = ''
|
||||||
|
wireless.SetForcedDisconnect(False)
|
||||||
|
self.set_visible(True)
|
||||||
|
self.connect('activate', self.on_activate)
|
||||||
|
self.connect('popup-menu', self.on_popup_menu)
|
||||||
|
self.set_from_file("images/no-signal.png")
|
||||||
|
self.set_tooltip("Initializing wicd...")
|
||||||
|
|
||||||
|
def on_popup_menu(self, status, button, time):
|
||||||
|
''' Opens the right click menu for the tray icon '''
|
||||||
|
self.menu.popup(None, None, None, button, time)
|
||||||
|
|
||||||
|
def set_from_file(self, path = None):
|
||||||
|
''' Sets a new tray icon picture '''
|
||||||
|
if not self.use_tray: return
|
||||||
|
if path != self.current_icon_path:
|
||||||
|
self.current_icon_path = path
|
||||||
|
gtk.StatusIcon.set_from_file(self, path)
|
||||||
|
|
||||||
|
|
||||||
|
def usage():
|
||||||
|
print """
|
||||||
|
wicd 1.40
|
||||||
|
wireless (and wired) connection daemon front-end.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
\t-n\t--no-tray\tRun wicd without the tray icon.
|
||||||
|
\t-h\t--help\t\tPrint this help.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
""" The main frontend program.
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
argv -- The arguments passed to the script.
|
||||||
|
|
||||||
|
"""
|
||||||
|
use_tray = True
|
||||||
|
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], 'nh',
|
||||||
|
['help', 'no-tray'])
|
||||||
|
except getopt.GetoptError:
|
||||||
|
# Print help information and exit
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
for o, a in opts:
|
||||||
|
if o in ('-h', '--help'):
|
||||||
|
usage()
|
||||||
|
sys.exit()
|
||||||
|
if o in ('-n', '--no-tray'):
|
||||||
|
use_tray = False
|
||||||
|
|
||||||
|
# Redirect stderr and stdout for logging purposes
|
||||||
|
sys.stderr = log
|
||||||
|
sys.stdout = log
|
||||||
|
|
||||||
|
# Set up the tray icon GUI and backend
|
||||||
|
tray_icon = TrayIcon(use_tray)
|
||||||
|
|
||||||
|
# Check to see if wired profile chooser was called before icon
|
||||||
|
# was launched (typically happens on startup or daemon restart)
|
||||||
|
if daemon.GetNeedWiredProfileChooser():
|
||||||
|
daemon.SetNeedWiredProfileChooser(False)
|
||||||
|
tray_icon.icon_info.wired_profile_chooser()
|
||||||
|
|
||||||
|
# Add dbus signal listener for wired_profile_chooser
|
||||||
|
bus.add_signal_receiver(tray_icon.icon_info.wired_profile_chooser,
|
||||||
|
'LaunchChooser', 'org.wicd.daemon')
|
||||||
|
|
||||||
|
# Run update_tray_icon every 3000ms (3 seconds)
|
||||||
|
gobject.timeout_add(3000, tray_icon.icon_info.update_tray_icon)
|
||||||
|
|
||||||
|
# Enter the main loop
|
||||||
|
mainloop = gobject.MainLoop()
|
||||||
|
mainloop.run()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv)
|
||||||
10
wnettools.py
10
wnettools.py
@@ -260,7 +260,7 @@ class WirelessInterface(Interface):
|
|||||||
results = misc.Run(cmd)
|
results = misc.Run(cmd)
|
||||||
|
|
||||||
# Split the networks apart, using Cell as our split point
|
# Split the networks apart, using Cell as our split point
|
||||||
# this way we can look at only one network at a time
|
# this way we can look at only one network at a time.
|
||||||
networks = results.split( ' Cell ' )
|
networks = results.split( ' Cell ' )
|
||||||
|
|
||||||
# Get available network info from iwpriv get_site_survey
|
# Get available network info from iwpriv get_site_survey
|
||||||
@@ -532,7 +532,7 @@ class WirelessInterface(Interface):
|
|||||||
if len(info) < 5:
|
if len(info) < 5:
|
||||||
break
|
break
|
||||||
if info[2] == network.get('essid'):
|
if info[2] == network.get('essid'):
|
||||||
if info[5] == 'WEP' or (info[5] == 'OPEN' and info[4] == 'WEP'): # Needs to be tested
|
if info[5] == 'WEP' or (info[5] == 'OPEN' and info[4] == 'WEP'):
|
||||||
print 'Setting up WEP'
|
print 'Setting up WEP'
|
||||||
cmd = 'iwconfig ' + self.iface + ' key ' + network.get('key')
|
cmd = 'iwconfig ' + self.iface + ' key ' + network.get('key')
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
@@ -610,5 +610,7 @@ class WirelessInterface(Interface):
|
|||||||
cmd = 'iwconfig ' + self.iface
|
cmd = 'iwconfig ' + self.iface
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
output = misc.Run(cmd)
|
output = misc.Run(cmd)
|
||||||
return misc.RunRegex(re.compile('.*ESSID:"(.*?)"',re.DOTALL | re.I | re.M | re.S), output)
|
network = misc.RunRegex(re.compile('.*ESSID:"(.*?)"',re.DOTALL | re.I | re.M | re.S), output)
|
||||||
|
if network is not None:
|
||||||
|
network = network.encode('utf-8')
|
||||||
|
return network
|
||||||
|
|||||||
Reference in New Issue
Block a user