1
1
#!/usr/bin/env python
3
""" Configure the scripts for a particular network.
3
""" configscript -- Configure the scripts for a particular network.
5
5
Script for configuring the scripts for a network passed in as a
6
6
command line argument. This needs to run a separate process because
13
# Copyright (C) 2007 - 2008 Adam Blackburn
14
# Copyright (C) 2007 - 2008 Dan O'Reilly
13
# Copyright (C) 2007-2009 Adam Blackburn
14
# Copyright (C) 2007-2009 Dan O'Reilly
16
16
# This program is free software; you can redistribute it and/or modify
17
17
# it under the terms of the GNU General Public License Version 2 as
32
32
import ConfigParser
36
import wicd.wpath as wpath
37
import wicd.misc as misc
35
from wicd import wpath
36
from wicd import translations
37
from wicd import dbusmanager
39
_ = misc.get_gettext()
39
_ = translations.get_gettext()
42
42
language['configure_scripts'] = _("Configure Scripts")
43
43
language['before_script'] = _("Pre-connection Script")
44
44
language['after_script'] = _("Post-connection Script")
45
language['disconnect_script'] = _("Disconnection Script")
47
bus = dbus.SystemBus()
49
# Connect to the daemon
51
print 'Attempting to connect tray to daemon...'
52
proxy_obj = bus.get_object('org.wicd.daemon', '/org/wicd/daemon')
55
print 'Daemon not running...'
56
misc.PromptToStartDaemon()
59
wireless = dbus.Interface(proxy_obj, 'org.wicd.daemon.wireless')
60
wired = dbus.Interface(proxy_obj, 'org.wicd.daemon.wired')
61
config = dbus.Interface(proxy_obj, 'org.wicd.daemon.config')
45
language['pre_disconnect_script'] = _("Pre-disconnection Script")
46
language['post_disconnect_script'] = _("Post-disconnection Script")
48
dbus = dbusmanager.DBusManager()
49
dbus.connect_to_dbus()
51
wireless = dbus.get_interface("wireless")
52
wired = dbus.get_interface("wired")
63
54
wireless_conf = wpath.etc + 'wireless-settings.conf'
64
55
wired_conf = wpath.etc + 'wired-settings.conf'
110
101
if con.has_section(network):
111
102
info["pre_entry"] = get_val(con, network, "beforescript")
112
103
info["post_entry"] = get_val(con, network, "afterscript")
113
info["disconnect_entry"] = get_val(con, network, "disconnectscript")
104
info["pre_disconnect_entry"] = get_val(con, network, "predisconnectscript")
105
info["post_disconnect_entry"] = get_val(con, network, "postdisconnectscript")
115
107
bssid = wireless.GetWirelessProperty(int(network), "bssid")
116
108
con.read(wireless_conf)
117
109
if con.has_section(bssid):
118
110
info["pre_entry"] = get_val(con, bssid, "beforescript")
119
111
info["post_entry"] = get_val(con, bssid, "afterscript")
120
info["disconnect_entry"] = get_val(con, bssid, "disconnectscript")
112
info["pre_disconnect_entry"] = get_val(con, bssid, "predisconnectscript")
113
info["post_disconnect_entry"] = get_val(con, bssid, "postdisconnectscript")
123
116
def write_scripts(network, network_type, script_info):
130
123
con.add_section(network)
131
124
con.set(network, "beforescript", script_info["pre_entry"])
132
125
con.set(network, "afterscript", script_info["post_entry"])
133
con.set(network, "disconnectscript", script_info["disconnect_entry"])
126
con.set(network, "predisconnectscript", script_info["pre_disconnect_entry"])
127
con.set(network, "postdisconnectscript", script_info["post_disconnect_entry"])
134
128
con.write(open(wired_conf, "w"))
135
config.ReadWiredNetworkProfile(network)
136
config.SaveWiredNetworkProfile(network)
130
wired.ReadWiredNetworkProfile(network)
131
wired.SaveWiredNetworkProfile(network)
138
133
bssid = wireless.GetWirelessProperty(int(network), "bssid")
139
134
con.read(wireless_conf)
141
136
con.add_section(bssid)
142
137
con.set(bssid, "beforescript", script_info["pre_entry"])
143
138
con.set(bssid, "afterscript", script_info["post_entry"])
144
con.set(bssid, "disconnectscript", script_info["disconnect_entry"])
139
con.set(bssid, "predisconnectscript", script_info["pre_disconnect_entry"])
140
con.set(bssid, "postdisconnectscript", script_info["post_disconnect_entry"])
145
141
con.write(open(wireless_conf, "w"))
146
config.ReadWirelessNetworkProfile(int(network))
147
config.SaveWirelessNetworkProfile(int(network))
142
wireless.ReloadConfig()
143
wireless.ReadWirelessNetworkProfile(int(network))
144
wireless.SaveWirelessNetworkProfile(int(network))
150
148
""" Runs the script configuration dialog. """
162
160
dialog = wTree.get_widget("configure_script_dialog")
163
161
wTree.get_widget("pre_label").set_label(language['before_script'] + ":")
164
162
wTree.get_widget("post_label").set_label(language['after_script'] + ":")
165
wTree.get_widget("disconnect_label").set_label(language['disconnect_script']
163
wTree.get_widget("pre_disconnect_label").set_label(language['pre_disconnect_script']
165
wTree.get_widget("post_disconnect_label").set_label(language['post_disconnect_script']
167
167
wTree.get_widget("window1").hide()
169
169
pre_entry = wTree.get_widget("pre_entry")
170
170
post_entry = wTree.get_widget("post_entry")
171
disconnect_entry = wTree.get_widget("disconnect_entry")
171
pre_disconnect_entry = wTree.get_widget("pre_disconnect_entry")
172
post_disconnect_entry = wTree.get_widget("post_disconnect_entry")
173
174
pre_entry.set_text(none_to_blank(script_info.get("pre_entry")))
174
175
post_entry.set_text(none_to_blank(script_info.get("post_entry")))
175
disconnect_entry.set_text(none_to_blank(script_info.get("disconnect_entry")))
176
pre_disconnect_entry.set_text(none_to_blank(script_info.get("pre_disconnect_entry")))
177
post_disconnect_entry.set_text(none_to_blank(script_info.get("post_disconnect_entry")))
177
179
dialog.show_all()
179
181
result = dialog.run()
181
183
script_info["pre_entry"] = blank_to_none(pre_entry.get_text())
182
184
script_info["post_entry"] = blank_to_none(post_entry.get_text())
183
script_info["disconnect_entry"] = blank_to_none(disconnect_entry.get_text())
185
script_info["pre_disconnect_entry"] = blank_to_none(pre_disconnect_entry.get_text())
186
script_info["post_disconnect_entry"] = blank_to_none(post_disconnect_entry.get_text())
184
187
write_scripts(network, network_type, script_info)