mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 21:08:06 +01:00
Added disconnection script
Changed auto-reconnection behavior slightly to prevent possible hanging issues Changed/Added some comments
This commit is contained in:
32
daemon.py
32
daemon.py
@@ -399,6 +399,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
'''disconnects all wireless networks'''
|
'''disconnects all wireless networks'''
|
||||||
self.SetForcedDisconnect(True)
|
self.SetForcedDisconnect(True)
|
||||||
self.wifi.Disconnect()
|
self.wifi.Disconnect()
|
||||||
|
self.wired.Disconnect()
|
||||||
#end function DisconnectWireless
|
#end function DisconnectWireless
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
@@ -409,6 +410,14 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
self.wifi.before_script = script
|
self.wifi.before_script = script
|
||||||
#end function SetWirelessBeforeScript
|
#end function SetWirelessBeforeScript
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
|
def SetWirelessDisconnectScript(self,networkid,script):
|
||||||
|
if script == '':
|
||||||
|
script = None
|
||||||
|
self.SetWirelessProperty(networkid,"disconnectscript",script)
|
||||||
|
self.wifi.disconnect_script = script
|
||||||
|
#end function SetWirelessDisconnectScript
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wireless')
|
@dbus.service.method('org.wicd.daemon.wireless')
|
||||||
def SetWirelessAfterScript(self,networkid,script):
|
def SetWirelessAfterScript(self,networkid,script):
|
||||||
if script == '':
|
if script == '':
|
||||||
@@ -511,6 +520,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
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')
|
||||||
|
self.wifi.disconnect_script = self.GetWirelessProperty(id,'disconnectscript')
|
||||||
print 'connecting to wireless network',self.LastScan[id]['essid']
|
print 'connecting to wireless network',self.LastScan[id]['essid']
|
||||||
return self.wifi.Connect(self.LastScan[id])
|
return self.wifi.Connect(self.LastScan[id])
|
||||||
#end function Connect
|
#end function Connect
|
||||||
@@ -604,6 +614,15 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
self.wired.before_script = script
|
self.wired.before_script = script
|
||||||
#end function SetWiredBeforeScript
|
#end function SetWiredBeforeScript
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon.wired')
|
||||||
|
def SetWiredDisconnectScript(self,script):
|
||||||
|
'''sets script to run on connection disconnect'''
|
||||||
|
if script == '':
|
||||||
|
script = None
|
||||||
|
self.SetWiredProperty("disconnectscript",script)
|
||||||
|
self.wired.disconnect_script = script
|
||||||
|
#end function SetWirelessDisconnectScript
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.wired')
|
@dbus.service.method('org.wicd.daemon.wired')
|
||||||
def SetWiredAfterScript(self,script):
|
def SetWiredAfterScript(self,script):
|
||||||
'''sets post-connection script to run for a wired connection'''
|
'''sets post-connection script to run for a wired connection'''
|
||||||
@@ -695,6 +714,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
#simple enough.
|
#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.Connect(self.WiredNetwork)
|
self.wired.Connect(self.WiredNetwork)
|
||||||
|
|
||||||
########## LOG FILE STUFF
|
########## LOG FILE STUFF
|
||||||
@@ -716,7 +736,8 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
@dbus.service.method('org.wicd.daemon.config')
|
@dbus.service.method('org.wicd.daemon.config')
|
||||||
def CreateWiredNetworkProfile(self,profilename):
|
def CreateWiredNetworkProfile(self,profilename):
|
||||||
#should include: profilename,ip,netmask,gateway,dns1,dns2,dns3
|
#should include: profilename,ip,netmask,gateway,dns1,dns2,dns3
|
||||||
print "creating profile for " + str(profilename)
|
profilename = profilename.encode('utf-8')
|
||||||
|
print "creating profile for " + profilename
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(self.wired_conf)
|
config.read(self.wired_conf)
|
||||||
if config.has_section(profilename):
|
if config.has_section(profilename):
|
||||||
@@ -731,6 +752,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
config.set(profilename,"dns3",None)
|
config.set(profilename,"dns3",None)
|
||||||
config.set(profilename,"beforescript",None)
|
config.set(profilename,"beforescript",None)
|
||||||
config.set(profilename,"afterscript",None)
|
config.set(profilename,"afterscript",None)
|
||||||
|
config.set(profilename,"disconnectscript",None)
|
||||||
config.set(profilename,"default",False)
|
config.set(profilename,"default",False)
|
||||||
config.write( open(self.wired_conf,"w"))
|
config.write( open(self.wired_conf,"w"))
|
||||||
return True
|
return True
|
||||||
@@ -765,6 +787,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon.config')
|
@dbus.service.method('org.wicd.daemon.config')
|
||||||
def DeleteWiredNetworkProfile(self,profilename):
|
def DeleteWiredNetworkProfile(self,profilename):
|
||||||
|
profilename = profilename.encode('utf-8')
|
||||||
print "deleting profile for " + str(profilename)
|
print "deleting profile for " + str(profilename)
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(self.wired_conf)
|
config.read(self.wired_conf)
|
||||||
@@ -779,6 +802,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
@dbus.service.method('org.wicd.daemon.config')
|
@dbus.service.method('org.wicd.daemon.config')
|
||||||
def SaveWiredNetworkProfile(self,profilename):
|
def SaveWiredNetworkProfile(self,profilename):
|
||||||
#should include: profilename,ip,netmask,gateway,dns1,dns2
|
#should include: profilename,ip,netmask,gateway,dns1,dns2
|
||||||
|
profilename = profilename.encode('utf-8')
|
||||||
print "setting profile for " + str(profilename)
|
print "setting profile for " + str(profilename)
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(self.wired_conf)
|
config.read(self.wired_conf)
|
||||||
@@ -794,6 +818,7 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
@dbus.service.method('org.wicd.daemon.config')
|
@dbus.service.method('org.wicd.daemon.config')
|
||||||
def ReadWiredNetworkProfile(self,profilename):
|
def ReadWiredNetworkProfile(self,profilename):
|
||||||
profile = {}
|
profile = {}
|
||||||
|
profilename = profilename.encode('utf-8')
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read(self.wired_conf)
|
config.read(self.wired_conf)
|
||||||
if config.has_section(profilename) == True:
|
if config.has_section(profilename) == True:
|
||||||
@@ -857,6 +882,11 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
self.LastScan[id]["afterscript"]=misc.Noneify(config.get(self.LastScan[id]["bssid"],"afterscript"))
|
self.LastScan[id]["afterscript"]=misc.Noneify(config.get(self.LastScan[id]["bssid"],"afterscript"))
|
||||||
else:
|
else:
|
||||||
self.LastScan[id]["afterscript"] = None
|
self.LastScan[id]["afterscript"] = None
|
||||||
|
if config.has_option(self.LastScan[id]["bssid"],"disconnectscript"):
|
||||||
|
self.LastScan[id]["disconnectscript"]=misc.Noneify(config.get(self.LastScan[id]["bssid"],"disconnectscript"))
|
||||||
|
else:
|
||||||
|
self.LastScan[id]["disconnectscript"] = None
|
||||||
|
|
||||||
#read the essid because we be needing to name those hidden
|
#read the essid because we be needing to name those hidden
|
||||||
#wireless networks now - but only read it if it is hidden
|
#wireless networks now - but only read it if it is hidden
|
||||||
if self.LastScan[id]["hidden"] == True:
|
if self.LastScan[id]["hidden"] == True:
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ try:
|
|||||||
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
|
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
|
||||||
print 'success'
|
print 'success'
|
||||||
except:
|
except:
|
||||||
print 'daemon not running, running gksudo ./daemon.py...'
|
print 'daemon not running...'
|
||||||
import misc,time
|
import misc,time
|
||||||
misc.PromptToStartDaemon()
|
misc.PromptToStartDaemon()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|||||||
14
edgy.py
14
edgy.py
@@ -32,7 +32,7 @@ try:
|
|||||||
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
|
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
|
||||||
print 'success'
|
print 'success'
|
||||||
except:
|
except:
|
||||||
print 'daemon not running, running gksudo ./daemon.py...'
|
print 'daemon not running...'
|
||||||
import misc
|
import misc
|
||||||
misc.PromptToStartDaemon()
|
misc.PromptToStartDaemon()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
@@ -154,16 +154,15 @@ def auto_reconnect():
|
|||||||
#a disconnect is forced. People who have disconnection problems need to test it to determine if it actually works.
|
#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
|
#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 a wired network or any wireless network set to autoconnect.
|
#connect to a wired network or any wireless network set to autoconnect.
|
||||||
|
global triedReconnect
|
||||||
if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False:
|
if wireless.GetAutoReconnect() == True and daemon.CheckIfConnecting() == False and wireless.GetForcedDisconnect() == False:
|
||||||
curNetID = wireless.GetCurrentNetworkID()
|
curNetID = wireless.GetCurrentNetworkID()
|
||||||
print 'Trying to autoreconnect to last used network'
|
print 'Trying to autoreconnect to last used network'
|
||||||
if curNetID > -1:
|
if curNetID > -1: #needs to be a valid network to try to connect to
|
||||||
|
if triedReconnect == False:
|
||||||
wireless.ConnectWireless(curNetID)
|
wireless.ConnectWireless(curNetID)
|
||||||
while wireless.CheckIfWirelessConnecting() == True:
|
triedReconnect = True
|
||||||
time.sleep(1)
|
elif triedReconnect == True and wireless.CheckIfWirelessConnecting() == False:
|
||||||
if wireless.GetCurrentSignalStrength() != 0:
|
|
||||||
print "Successfully autoreconnected."
|
|
||||||
else:
|
|
||||||
print "Couldn't reconnect to last used network, scanning for an autoconnect network..."
|
print "Couldn't reconnect to last used network, scanning for an autoconnect network..."
|
||||||
daemon.AutoConnect(True)
|
daemon.AutoConnect(True)
|
||||||
else:
|
else:
|
||||||
@@ -236,6 +235,7 @@ class TrackerStatusIcon(gtk.StatusIcon):
|
|||||||
LastStrength = -2
|
LastStrength = -2
|
||||||
stillWired = False
|
stillWired = False
|
||||||
network = ''
|
network = ''
|
||||||
|
triedReconnect = False
|
||||||
|
|
||||||
tr=TrackerStatusIcon()
|
tr=TrackerStatusIcon()
|
||||||
gobject.timeout_add(3000,set_signal_image)
|
gobject.timeout_add(3000,set_signal_image)
|
||||||
|
|||||||
16
gui.py
16
gui.py
@@ -126,6 +126,7 @@ language['essid'] = _('ESSID')
|
|||||||
language['use_wep_encryption'] = _('Use Encryption (WEP only)')
|
language['use_wep_encryption'] = _('Use Encryption (WEP only)')
|
||||||
language['before_script'] = _('Run script before connect')
|
language['before_script'] = _('Run script before connect')
|
||||||
language['after_script'] = _('Run script after connect')
|
language['after_script'] = _('Run script after connect')
|
||||||
|
language['disconnect_script'] = _('Run disconnect script')
|
||||||
language['script_settings'] = _('Scripts')
|
language['script_settings'] = _('Scripts')
|
||||||
language['use_ics'] = _('Activate Internet Connection Sharing')
|
language['use_ics'] = _('Activate Internet Connection Sharing')
|
||||||
language['default_wired'] = _('Use as default profile (overwrites any previous default)')
|
language['default_wired'] = _('Use as default profile (overwrites any previous default)')
|
||||||
@@ -237,7 +238,7 @@ class GreyLabel(gtk.Label):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
gtk.Label.__init__(self)
|
gtk.Label.__init__(self)
|
||||||
def set_label(self,text):
|
def set_label(self,text):
|
||||||
self.set_markup("<span color=\"grey\"><i>" + text + "</i></span>")
|
self.set_markup("<span color=\"#666666\"><i>" + text + "</i></span>")
|
||||||
self.set_alignment(0,0)
|
self.set_alignment(0,0)
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
@@ -384,8 +385,10 @@ class NetworkEntry(gtk.Expander):
|
|||||||
#self.txtDNS3.set_text(dns_addresses[2])
|
#self.txtDNS3.set_text(dns_addresses[2])
|
||||||
self.txtBeforeScript = LabelEntry(language['before_script'])
|
self.txtBeforeScript = LabelEntry(language['before_script'])
|
||||||
self.txtAfterScript = LabelEntry(language['after_script'])
|
self.txtAfterScript = LabelEntry(language['after_script'])
|
||||||
|
self.txtDisconnectScript = LabelEntry(language['disconnect_script'])
|
||||||
self.txtBeforeScript.label.set_size_request(200,-1)
|
self.txtBeforeScript.label.set_size_request(200,-1)
|
||||||
self.txtAfterScript.label.set_size_request(200,-1)
|
self.txtAfterScript.label.set_size_request(200,-1)
|
||||||
|
self.txtDisconnectScript.label.set_size_request(200,-1)
|
||||||
self.checkboxStaticIP = gtk.CheckButton(language['use_static_ip'])
|
self.checkboxStaticIP = gtk.CheckButton(language['use_static_ip'])
|
||||||
self.checkboxStaticDNS = gtk.CheckButton(language['use_static_dns'])
|
self.checkboxStaticDNS = gtk.CheckButton(language['use_static_dns'])
|
||||||
self.checkboxGlobalDNS = gtk.CheckButton(language['use_global_dns'])
|
self.checkboxGlobalDNS = gtk.CheckButton(language['use_global_dns'])
|
||||||
@@ -407,6 +410,7 @@ class NetworkEntry(gtk.Expander):
|
|||||||
self.vboxAdvanced.pack_start(self.txtDNS3,fill=False,expand=False)
|
self.vboxAdvanced.pack_start(self.txtDNS3,fill=False,expand=False)
|
||||||
self.vboxScripts.pack_start(self.txtBeforeScript,fill=False,expand=False)
|
self.vboxScripts.pack_start(self.txtBeforeScript,fill=False,expand=False)
|
||||||
self.vboxScripts.pack_start(self.txtAfterScript,fill=False,expand=False)
|
self.vboxScripts.pack_start(self.txtAfterScript,fill=False,expand=False)
|
||||||
|
self.vboxScripts.pack_start(self.txtDisconnectScript,fill=False,expand=False)
|
||||||
self.vboxTop.pack_end(self.expanderScripts,fill=False,expand=False)
|
self.vboxTop.pack_end(self.expanderScripts,fill=False,expand=False)
|
||||||
self.vboxTop.pack_end(self.expanderAdvanced,fill=False,expand=False)
|
self.vboxTop.pack_end(self.expanderAdvanced,fill=False,expand=False)
|
||||||
self.expanderAdvanced.add(self.vboxAdvanced)
|
self.expanderAdvanced.add(self.vboxAdvanced)
|
||||||
@@ -633,6 +637,7 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
self.txtBeforeScript.set_text(noneToBlankString(wired.GetWiredProperty("beforescript")))
|
self.txtBeforeScript.set_text(noneToBlankString(wired.GetWiredProperty("beforescript")))
|
||||||
self.txtAfterScript.set_text(noneToBlankString(wired.GetWiredProperty("afterscript")))
|
self.txtAfterScript.set_text(noneToBlankString(wired.GetWiredProperty("afterscript")))
|
||||||
|
self.txtDisconnectScript.set_text(noneToBlankString(wired.GetWiredProperty("disconnectscript")))
|
||||||
|
|
||||||
self.checkboxDefaultProfile.set_active(stringToBoolean(wired.GetWiredProperty("default")))
|
self.checkboxDefaultProfile.set_active(stringToBoolean(wired.GetWiredProperty("default")))
|
||||||
|
|
||||||
@@ -694,6 +699,7 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
self.txtBeforeScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"beforescript")))
|
self.txtBeforeScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"beforescript")))
|
||||||
self.txtAfterScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"afterscript")))
|
self.txtAfterScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"afterscript")))
|
||||||
|
self.txtDisconnectScript.set_text(noneToBlankString(wireless.GetWirelessProperty(networkID,"disconnectscript")))
|
||||||
|
|
||||||
self.resetStaticCheckboxes()
|
self.resetStaticCheckboxes()
|
||||||
encryptionTypes = misc.LoadEncryptionMethods()
|
encryptionTypes = misc.LoadEncryptionMethods()
|
||||||
@@ -782,10 +788,10 @@ class WirelessNetworkEntry(NetworkEntry):
|
|||||||
if on and type:
|
if on and type:
|
||||||
self.lblEncryption.set_label(language['secured'] + " " + str(type))
|
self.lblEncryption.set_label(language['secured'] + " " + str(type))
|
||||||
self.set_use_markup(True)
|
self.set_use_markup(True)
|
||||||
self.set_label(self.essid + ' <span color="grey">' + str(type) + '</span>')
|
self.set_label(self.essid + ' <span color="#666666">' + str(type) + '</span>')
|
||||||
if on and not type:
|
if on and not type:
|
||||||
self.lblEncryption.set_label(language['secured'])
|
self.lblEncryption.set_label(language['secured'])
|
||||||
self.set_label(self.essid + ' <span color="grey">Secured</span>')
|
self.set_label(self.essid + ' <span color="#666666">Secured</span>')
|
||||||
if not on:
|
if not on:
|
||||||
self.lblEncryption.set_label(language['unsecured'])
|
self.lblEncryption.set_label(language['unsecured'])
|
||||||
|
|
||||||
@@ -1202,8 +1208,10 @@ class appGui:
|
|||||||
# Script info
|
# Script info
|
||||||
before_script = networkentry.expander.txtBeforeScript.get_text()
|
before_script = networkentry.expander.txtBeforeScript.get_text()
|
||||||
after_script = networkentry.expander.txtAfterScript.get_text()
|
after_script = networkentry.expander.txtAfterScript.get_text()
|
||||||
|
disconnect_script = networkentry.expander.txtDisconnectScript.get_text()
|
||||||
wireless.SetWirelessBeforeScript(networkid,before_script)
|
wireless.SetWirelessBeforeScript(networkid,before_script)
|
||||||
wireless.SetWirelessAfterScript(networkid,after_script)
|
wireless.SetWirelessAfterScript(networkid,after_script)
|
||||||
|
wireless.SetWirelessDisconnectScript(networkid,disconnect_script)
|
||||||
|
|
||||||
# if it exists. maybe kept as a value in the network entry? Not sure...
|
# if it exists. maybe kept as a value in the network entry? Not sure...
|
||||||
print "connecting to wireless network..."
|
print "connecting to wireless network..."
|
||||||
@@ -1233,8 +1241,10 @@ class appGui:
|
|||||||
#Script Info
|
#Script Info
|
||||||
before_script = networkentry.expander.txtBeforeScript.get_text()
|
before_script = networkentry.expander.txtBeforeScript.get_text()
|
||||||
after_script = networkentry.expander.txtAfterScript.get_text()
|
after_script = networkentry.expander.txtAfterScript.get_text()
|
||||||
|
disconnect_script = networkentry.expander.txtDisconnectScript.get_text()
|
||||||
wired.SetWiredBeforeScript(before_script)
|
wired.SetWiredBeforeScript(before_script)
|
||||||
wired.SetWiredAfterScript(after_script)
|
wired.SetWiredAfterScript(after_script)
|
||||||
|
wired.SetWiredDisconnectScript(disconnect_script)
|
||||||
|
|
||||||
config.SaveWiredNetworkProfile(networkentry.expander.comboProfileNames.get_active_text())
|
config.SaveWiredNetworkProfile(networkentry.expander.comboProfileNames.get_active_text())
|
||||||
wired.ConnectWired()
|
wired.ConnectWired()
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ class Wireless:
|
|||||||
ConnectingThread = None
|
ConnectingThread = None
|
||||||
before_script = None
|
before_script = None
|
||||||
after_script = None
|
after_script = None
|
||||||
|
disconnect_script = None
|
||||||
|
|
||||||
|
|
||||||
#Create a function to scan for wireless networks
|
#Create a function to scan for wireless networks
|
||||||
def Scan(self,essid=None):
|
def Scan(self,essid=None):
|
||||||
@@ -169,13 +171,13 @@ class Wireless:
|
|||||||
if misc.RunRegex(wpa2_pattern,cell) == "WPA2":
|
if misc.RunRegex(wpa2_pattern,cell) == "WPA2":
|
||||||
CurrentNetwork["encryption_method"] = "WPA2"
|
CurrentNetwork["encryption_method"] = "WPA2"
|
||||||
|
|
||||||
else: #support for ralink legacy drivers, may not work w/ hidden networks
|
else: #support for ralink legacy drivers (maybe only serialmonkey enhanced), may not work w/ hidden networks
|
||||||
iwpriv = misc.Run("iwpriv " + self.wireless_interface + " get_site_survey")
|
iwpriv = misc.Run("iwpriv " + self.wireless_interface + " get_site_survey")
|
||||||
lines = iwpriv.splitlines()
|
lines = iwpriv.splitlines()
|
||||||
lines = lines[2:]
|
lines = lines[2:]
|
||||||
for x in lines:
|
for x in lines: #iterate through all networks found
|
||||||
info = x.split()
|
info = x.split()
|
||||||
if len(info) < 5 or info == None or info == '':
|
if len(info) < 5 or info == None or info == '': #make sure we read in a valid entry
|
||||||
break;
|
break;
|
||||||
if info[2] == CurrentNetwork["essid"]:
|
if info[2] == CurrentNetwork["essid"]:
|
||||||
CurrentNetwork["encryption"] = True
|
CurrentNetwork["encryption"] = True
|
||||||
@@ -195,11 +197,11 @@ class Wireless:
|
|||||||
#end If
|
#end If
|
||||||
|
|
||||||
if self.wpa_driver != 'ralink legacy':
|
if self.wpa_driver != 'ralink legacy':
|
||||||
#since stength needs a -1 if the quality isn't found
|
#since strength needs a -1 if the quality isn't found
|
||||||
#we need a simple if then to set it
|
#we need a simple if then to set it
|
||||||
if misc.RunRegex(strength_pattern,cell):
|
if misc.RunRegex(strength_pattern,cell):
|
||||||
CurrentNetwork["quality"] = misc.RunRegex(strength_pattern,cell)
|
CurrentNetwork["quality"] = misc.RunRegex(strength_pattern,cell)
|
||||||
elif misc.RunRegex(altstrength_pattern,cell):
|
elif misc.RunRegex(altstrength_pattern,cell): #alternate way of labeling link quality used by some drivers
|
||||||
CurrentNetwork["quality"] = misc.RunRegex(altstrength_pattern,cell)
|
CurrentNetwork["quality"] = misc.RunRegex(altstrength_pattern,cell)
|
||||||
else:
|
else:
|
||||||
CurrentNetwork["quality"] = -1
|
CurrentNetwork["quality"] = -1
|
||||||
@@ -254,7 +256,7 @@ class Wireless:
|
|||||||
|
|
||||||
def Connect(self,network):
|
def Connect(self,network):
|
||||||
#call the thread, so we don't hang up the entire works
|
#call the thread, so we don't hang up the entire works
|
||||||
self.ConnectingThread = self.ConnectThread(network,self.wireless_interface,self.wired_interface,self.wpa_driver,self.before_script,self.after_script,self.global_dns_1,self.global_dns_2,self.global_dns_3)
|
self.ConnectingThread = self.ConnectThread(network,self.wireless_interface,self.wired_interface,self.wpa_driver,self.before_script,self.after_script,self.disconnect_script,self.global_dns_1,self.global_dns_2,self.global_dns_3)
|
||||||
self.ConnectingThread.start()
|
self.ConnectingThread.start()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -264,7 +266,7 @@ class Wireless:
|
|||||||
ShouldDie = False
|
ShouldDie = False
|
||||||
lock = thread.allocate_lock()
|
lock = thread.allocate_lock()
|
||||||
|
|
||||||
def __init__(self,network,wireless,wired,wpa_driver,before_script,after_script,gdns1,gdns2,gdns3):
|
def __init__(self,network,wireless,wired,wpa_driver,before_script,after_script,disconnect_script,gdns1,gdns2,gdns3):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.network = network
|
self.network = network
|
||||||
self.wireless_interface = wireless
|
self.wireless_interface = wireless
|
||||||
@@ -273,6 +275,7 @@ class Wireless:
|
|||||||
self.IsConnecting = False
|
self.IsConnecting = False
|
||||||
self.before_script = before_script
|
self.before_script = before_script
|
||||||
self.after_script = after_script
|
self.after_script = after_script
|
||||||
|
self.disconnect_script = disconnect_script
|
||||||
|
|
||||||
self.global_dns_1 = gdns1
|
self.global_dns_1 = gdns1
|
||||||
self.global_dns_2 = gdns2
|
self.global_dns_2 = gdns2
|
||||||
@@ -301,6 +304,7 @@ class Wireless:
|
|||||||
self.IsConnecting = True
|
self.IsConnecting = True
|
||||||
network = self.network
|
network = self.network
|
||||||
|
|
||||||
|
#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-connection script'
|
print 'Executing pre-connection script'
|
||||||
print misc.Run('./run-script.py ' + self.before_script)
|
print misc.Run('./run-script.py ' + self.before_script)
|
||||||
@@ -511,6 +515,7 @@ class Wireless:
|
|||||||
print "done"
|
print "done"
|
||||||
self.IsConnecting = False
|
self.IsConnecting = False
|
||||||
|
|
||||||
|
#execute post-connection script if necessary
|
||||||
if self.after_script != '' and self.after_script != None:
|
if self.after_script != '' and self.after_script != None:
|
||||||
print 'executing post connection script'
|
print 'executing post connection script'
|
||||||
print misc.Run('./run-script.py ' + self.after_script)
|
print misc.Run('./run-script.py ' + self.after_script)
|
||||||
@@ -520,7 +525,11 @@ class Wireless:
|
|||||||
def GetSignalStrength(self):
|
def GetSignalStrength(self):
|
||||||
output = misc.Run("iwconfig " + self.wireless_interface)
|
output = misc.Run("iwconfig " + self.wireless_interface)
|
||||||
strength_pattern = re.compile('.*Quality:?=? ?(\d+)',re.DOTALL | re.I | re.M | re.S)
|
strength_pattern = re.compile('.*Quality:?=? ?(\d+)',re.DOTALL | re.I | re.M | re.S)
|
||||||
return misc.RunRegex(strength_pattern,output)
|
altstrength_pattern = re.compile('.*Signal level:?=? ?(\d\d*)',re.DOTALL | re.I | re.M | re.S)
|
||||||
|
strength = misc.RunRegex(strength_pattern,output)
|
||||||
|
if strength == None:
|
||||||
|
strength = misc.RunRegex(altstrength_pattern,output)
|
||||||
|
return strength
|
||||||
#end function GetSignalStrength
|
#end function GetSignalStrength
|
||||||
|
|
||||||
def GetCurrentNetwork(self):
|
def GetCurrentNetwork(self):
|
||||||
@@ -578,8 +587,9 @@ class Wireless:
|
|||||||
return misc.RunRegex(re.compile('(\w*)\s*\w*\s*[a-zA-Z0-9.-_]*\s*(?=ESSID)',re.DOTALL | re.I | re.M | re.S),misc.Run("iwconfig"))
|
return misc.RunRegex(re.compile('(\w*)\s*\w*\s*[a-zA-Z0-9.-_]*\s*(?=ESSID)',re.DOTALL | re.I | re.M | re.S),misc.Run("iwconfig"))
|
||||||
|
|
||||||
def Disconnect(self):
|
def Disconnect(self):
|
||||||
misc.Run('ifconfig ' + self.wired_interface + ' 0.0.0.0')
|
if self.disconnect_script != None:
|
||||||
misc.Run('ifconfig ' + self.wired_interface + ' down')
|
print 'running wireless network disconnect script'
|
||||||
|
misc.Run(self.disconnect_script)
|
||||||
misc.Run('ifconfig ' + self.wireless_interface + ' 0.0.0.0')
|
misc.Run('ifconfig ' + self.wireless_interface + ' 0.0.0.0')
|
||||||
misc.Run('ifconfig ' + self.wireless_interface + ' down')
|
misc.Run('ifconfig ' + self.wireless_interface + ' down')
|
||||||
|
|
||||||
@@ -593,6 +603,7 @@ class Wired:
|
|||||||
ConnectingThread = None
|
ConnectingThread = None
|
||||||
before_script = None
|
before_script = None
|
||||||
after_script = None
|
after_script = None
|
||||||
|
disconnect_script = None
|
||||||
|
|
||||||
def GetIP(self):
|
def GetIP(self):
|
||||||
output = misc.Run("ifconfig " + self.wired_interface)
|
output = misc.Run("ifconfig " + self.wired_interface)
|
||||||
@@ -613,7 +624,7 @@ class Wired:
|
|||||||
|
|
||||||
def Connect(self,network):
|
def Connect(self,network):
|
||||||
#call the thread, so we don't hang up the entire works
|
#call the thread, so we don't hang up the entire works
|
||||||
self.ConnectingThread = self.ConnectThread(network,self.wireless_interface,self.wired_interface,self.before_script,self.after_script)
|
self.ConnectingThread = self.ConnectThread(network,self.wireless_interface,self.wired_interface,self.before_script,self.after_script,self.disconnect_script)
|
||||||
self.ConnectingThread.start()
|
self.ConnectingThread.start()
|
||||||
return True
|
return True
|
||||||
#end function Connect
|
#end function Connect
|
||||||
@@ -624,7 +635,7 @@ class Wired:
|
|||||||
ConnectingMessage = None
|
ConnectingMessage = None
|
||||||
ShouldDie = False
|
ShouldDie = False
|
||||||
|
|
||||||
def __init__(self,network,wireless,wired,before_script,after_script):
|
def __init__(self,network,wireless,wired,before_script,after_script,disconnect_script):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.network = network
|
self.network = network
|
||||||
self.wireless_interface = wireless
|
self.wireless_interface = wireless
|
||||||
@@ -632,6 +643,7 @@ class Wired:
|
|||||||
self.IsConnecting = False
|
self.IsConnecting = False
|
||||||
self.before_script = before_script
|
self.before_script = before_script
|
||||||
self.after_script = after_script
|
self.after_script = after_script
|
||||||
|
self.disconnect_script = disconnect_script
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
self.ConnectingMessage = 'interface_down'
|
self.ConnectingMessage = 'interface_down'
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
@@ -740,3 +752,11 @@ class Wired:
|
|||||||
print 'executing post connection script'
|
print 'executing post connection script'
|
||||||
misc.Run('./run-script.py ' + self.after_script)
|
misc.Run('./run-script.py ' + self.after_script)
|
||||||
#end function run
|
#end function run
|
||||||
|
|
||||||
|
def Disconnect(self):
|
||||||
|
print 'wired disconnect running'
|
||||||
|
if self.disconnect_script != None:
|
||||||
|
print 'running wired network disconnect script'
|
||||||
|
misc.Run(self.disconnect_script)
|
||||||
|
misc.Run('ifconfig ' + self.wired_interface + ' 0.0.0.0')
|
||||||
|
misc.Run('ifconfig ' + self.wired_interface + ' down')
|
||||||
|
|||||||
Reference in New Issue
Block a user