mirror of
https://github.com/gryf/wicd.git
synced 2026-01-05 05:14:17 +01:00
Provide a pre-/post-down script mechanism
WICD currently only provides pre-/post-connection scripts, and only one disconnection script, that is run before actually disconnecting. This provides pre-/post-disconnection scripts, thus increasing configuration flexibility.
This commit is contained in:
@@ -151,7 +151,8 @@ class Controller(object):
|
||||
self.connecting_thread = None
|
||||
self.before_script = None
|
||||
self.after_script = None
|
||||
self.disconnect_script = None
|
||||
self.pre_disconnect_script = None
|
||||
self.post_disconnect_script = None
|
||||
self.driver = None
|
||||
self.iface = None
|
||||
|
||||
@@ -203,17 +204,23 @@ class Controller(object):
|
||||
def Disconnect(self, *args, **kargs):
|
||||
""" Disconnect from the network. """
|
||||
iface = self.iface
|
||||
misc.ExecuteScripts(wpath.disconnectscripts, self.debug)
|
||||
if self.disconnect_script:
|
||||
print 'Running disconnect script'
|
||||
misc.ExecuteScript(expand_script_macros(self.disconnect_script,
|
||||
'disconnection', *args),
|
||||
misc.ExecuteScripts(wpath.predisconnectscripts, self.debug)
|
||||
if self.pre_disconnect_script:
|
||||
print 'Running pre-disconnect script'
|
||||
misc.ExecuteScript(expand_script_macros(self.pre_disconnect_script,
|
||||
'pre-disconnection', *args),
|
||||
self.debug)
|
||||
iface.ReleaseDHCP()
|
||||
iface.SetAddress('0.0.0.0')
|
||||
iface.FlushRoutes()
|
||||
iface.Down()
|
||||
iface.Up()
|
||||
misc.ExecuteScripts(wpath.postdisconnectscripts, self.debug)
|
||||
if self.post_disconnect_script:
|
||||
print 'Running post-disconnect script'
|
||||
misc.ExecuteScript(expand_script_macros(self.post_disconnect_script,
|
||||
'post-disconnection', *args),
|
||||
self.debug)
|
||||
|
||||
def ReleaseDHCP(self):
|
||||
""" Release the DHCP lease for this interface. """
|
||||
@@ -273,8 +280,8 @@ class ConnectThread(threading.Thread):
|
||||
lock = threading.Lock()
|
||||
|
||||
def __init__(self, network, interface_name, before_script, after_script,
|
||||
disconnect_script, gdns1, gdns2, gdns3, gdns_dom, gsearch_dom,
|
||||
iface, debug):
|
||||
pre_disconnect_script, post_disconnect_script, gdns1,
|
||||
gdns2, gdns3, gdns_dom, gsearch_dom, iface, debug):
|
||||
""" Initialise the required object variables and the thread.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -283,7 +290,8 @@ class ConnectThread(threading.Thread):
|
||||
wired -- name of the wired interface
|
||||
before_script -- script to run before bringing up the interface
|
||||
after_script -- script to run after bringing up the interface
|
||||
disconnect_script -- script to run after disconnection
|
||||
pre_disconnect_script -- script to run before disconnection
|
||||
post_disconnect_script -- script to run after disconnection
|
||||
gdns1 -- global DNS server 1
|
||||
gdns2 -- global DNS server 2
|
||||
gdns3 -- global DNS server 3
|
||||
@@ -297,7 +305,8 @@ class ConnectThread(threading.Thread):
|
||||
self.connect_result = None
|
||||
self.before_script = before_script
|
||||
self.after_script = after_script
|
||||
self.disconnect_script = disconnect_script
|
||||
self.pre_disconnect_script = pre_disconnect_script
|
||||
self.post_disconnect_script = post_disconnect_script
|
||||
self._should_die = False
|
||||
self.abort_reason = ""
|
||||
self.connect_result = ""
|
||||
@@ -607,7 +616,8 @@ class Wireless(Controller):
|
||||
|
||||
self.connecting_thread = WirelessConnectThread(network,
|
||||
self.wireless_interface, self.wpa_driver, self.before_script,
|
||||
self.after_script, self.disconnect_script, self.global_dns_1,
|
||||
self.after_script, self.pre_disconnect_script,
|
||||
self.post_disconnect_script, self.global_dns_1,
|
||||
self.global_dns_2, self.global_dns_3, self.global_dns_dom,
|
||||
self.global_search_dom, self.wiface, debug)
|
||||
self.connecting_thread.setDaemon(True)
|
||||
@@ -779,8 +789,9 @@ class WirelessConnectThread(ConnectThread):
|
||||
"""
|
||||
|
||||
def __init__(self, network, wireless, wpa_driver, before_script,
|
||||
after_script, disconnect_script, gdns1, gdns2, gdns3,
|
||||
gdns_dom, gsearch_dom, wiface, debug=False):
|
||||
after_script, pre_disconnect_script, post_disconnect_script,
|
||||
gdns1, gdns2, gdns3, gdns_dom, gsearch_dom, wiface,
|
||||
debug=False):
|
||||
""" Initialise the thread with network information.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -789,14 +800,16 @@ class WirelessConnectThread(ConnectThread):
|
||||
wpa_driver -- type of wireless interface
|
||||
before_script -- script to run before bringing up the interface
|
||||
after_script -- script to run after bringing up the interface
|
||||
disconnect_script -- script to run after disconnection
|
||||
pre_disconnect_script -- script to run before disconnection
|
||||
post_disconnect_script -- script to run after disconnection
|
||||
gdns1 -- global DNS server 1
|
||||
gdns2 -- global DNS server 2
|
||||
gdns3 -- global DNS server 3
|
||||
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wireless, before_script,
|
||||
after_script, disconnect_script, gdns1, gdns2,
|
||||
after_script, pre_disconnect_script,
|
||||
post_disconnect_script, gdns1, gdns2,
|
||||
gdns3, gdns_dom, gsearch_dom, wiface, debug)
|
||||
self.wpa_driver = wpa_driver
|
||||
|
||||
@@ -967,9 +980,10 @@ class Wired(Controller):
|
||||
if not self.liface: return False
|
||||
self.connecting_thread = WiredConnectThread(network,
|
||||
self.wired_interface, self.before_script, self.after_script,
|
||||
self.disconnect_script, self.global_dns_1, self.global_dns_2,
|
||||
self.global_dns_3, self.global_dns_dom, self.global_search_dom,
|
||||
self.liface, debug)
|
||||
self.pre_disconnect_script, self.post_disconnect_script,
|
||||
self.global_dns_1, self.global_dns_2, self.global_dns_3,
|
||||
self.global_dns_dom, self.global_search_dom, self.liface,
|
||||
debug)
|
||||
self.connecting_thread.setDaemon(True)
|
||||
self.connecting_thread.start()
|
||||
return self.connecting_thread
|
||||
@@ -993,8 +1007,8 @@ class WiredConnectThread(ConnectThread):
|
||||
|
||||
"""
|
||||
def __init__(self, network, wired, before_script, after_script,
|
||||
disconnect_script, gdns1, gdns2, gdns3, gdns_dom, gsearch_dom,
|
||||
liface, debug=False):
|
||||
pre_disconnect_script, post_disconnect_script, gdns1,
|
||||
gdns2, gdns3, gdns_dom, gsearch_dom, liface, debug=False):
|
||||
""" Initialise the thread with network information.
|
||||
|
||||
Keyword arguments:
|
||||
@@ -1003,14 +1017,16 @@ class WiredConnectThread(ConnectThread):
|
||||
wired -- name of the wired interface
|
||||
before_script -- script to run before bringing up the interface
|
||||
after_script -- script to run after bringing up the interface
|
||||
disconnect_script -- script to run after disconnection
|
||||
pre_disconnect_script -- script to run before disconnection
|
||||
post_disconnect_script -- script to run after disconnection
|
||||
gdns1 -- global DNS server 1
|
||||
gdns2 -- global DNS server 2
|
||||
gdns3 -- global DNS server 3
|
||||
|
||||
"""
|
||||
ConnectThread.__init__(self, network, wired, before_script,
|
||||
after_script, disconnect_script, gdns1, gdns2,
|
||||
after_script, pre_disconnect_script,
|
||||
post_disconnect_script, gdns1, gdns2,
|
||||
gdns3, gdns_dom, gsearch_dom, liface, debug)
|
||||
|
||||
def _connect(self):
|
||||
|
||||
Reference in New Issue
Block a user