This file is indexed.

/usr/share/wicd/gtk/configscript.py is in wicd-gtk 1.7.4+tb2-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#! /usr/bin/python

""" configscript -- Configure the scripts for a particular network.

Script for configuring the scripts for a network passed in as a
command line argument.  This needs to run a separate process because
editing scripts requires root access, and the GUI/Tray are typically
run as the current user.

"""

#
#   Copyright (C) 2007-2009 Adam Blackburn
#   Copyright (C) 2007-2009 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 sys
import os
import gtk

from wicd import wpath
from wicd.translations import _
from wicd import dbusmanager
from wicd.configmanager import ConfigManager

dbus = dbusmanager.DBusManager()
dbus.connect_to_dbus()

wireless = dbus.get_interface("wireless")
wired = dbus.get_interface("wired")

wireless_conf = wpath.etc + 'wireless-settings.conf'
wired_conf = wpath.etc + 'wired-settings.conf'


def none_to_blank(text):
    """ Converts special string cases to a blank string.

    If text is None, 'None', or '' then this method will
    return '', otherwise it will just return str(text).

    """
    if text in (None, "None", ""):
        return ""
    else:
        return str(text)

def blank_to_none(text):
    """ Convert an empty or null string to 'None'. """
    if text in ("", None):
        return "None"
    else:
        return str(text)

def get_script_info(network, network_type):
    """ Read script info from disk and load it into the configuration dialog """
    info = {}
    if network_type == "wired":
        con = ConfigManager(wired_conf)
        if con.has_section(network):
            info["pre_entry"] = con.get(network, "beforescript", None)
            info["post_entry"] = con.get(network, "afterscript", None)
            info["pre_disconnect_entry"] = con.get(network,
                "predisconnectscript", None)
            info["post_disconnect_entry"] = con.get(network,
                "postdisconnectscript", None)
    else:
        bssid = wireless.GetWirelessProperty(int(network), "bssid")
        con = ConfigManager(wireless_conf)
        if con.has_section(bssid):
            info["pre_entry"] = con.get(bssid, "beforescript", None)
            info["post_entry"] = con.get(bssid, "afterscript", None)
            info["pre_disconnect_entry"] = con.get(bssid,
                "predisconnectscript", None)
            info["post_disconnect_entry"] = con.get(bssid,
                "postdisconnectscript", None)
    return info

def write_scripts(network, network_type, script_info):
    """ Writes script info to disk and loads it into the daemon. """
    if network_type == "wired":
        con = ConfigManager(wired_conf)
        con.set(network, "beforescript", script_info["pre_entry"])
        con.set(network, "afterscript", script_info["post_entry"])
        con.set(network, "predisconnectscript",
            script_info["pre_disconnect_entry"])
        con.set(network, "postdisconnectscript",
            script_info["post_disconnect_entry"])
        con.write()
        wired.ReloadConfig()
        wired.ReadWiredNetworkProfile(network)
        wired.SaveWiredNetworkProfile(network)
    else:
        bssid = wireless.GetWirelessProperty(int(network), "bssid")
        con = ConfigManager(wireless_conf)
        con.set(bssid, "beforescript", script_info["pre_entry"])
        con.set(bssid, "afterscript", script_info["post_entry"])
        con.set(bssid, "predisconnectscript",
            script_info["pre_disconnect_entry"])
        con.set(bssid, "postdisconnectscript",
            script_info["post_disconnect_entry"])
        con.write()
        wireless.ReloadConfig()
        wireless.ReadWirelessNetworkProfile(int(network))
        wireless.SaveWirelessNetworkProfile(int(network))


def main (argv):
    """ Runs the script configuration dialog. """
    if len(argv) < 2:
        print 'Network id to configure is missing, aborting.'
        sys.exit(1)

    network = argv[1]
    network_type = argv[2]

    script_info = get_script_info(network, network_type)

    gladefile = os.path.join(wpath.gtk, "wicd.ui")
    wTree = gtk.Builder()
    wTree.set_translation_domain('wicd')
    wTree.add_from_file(gladefile)
    dialog = wTree.get_object("configure_script_dialog")
    wTree.get_object("pre_label").set_label(_('Pre-connection Script') + ":")
    wTree.get_object("post_label").set_label(_('Post-connection Script') + ":")
    wTree.get_object("pre_disconnect_label").\
        set_label(_('Pre-disconnection Script') + ":")
    wTree.get_object("post_disconnect_label").\
        set_label(_('Post-disconnection Script') + ":")
    wTree.get_object("window1").hide()

    pre_entry = wTree.get_object("pre_entry")
    post_entry = wTree.get_object("post_entry")
    pre_disconnect_entry = wTree.get_object("pre_disconnect_entry")
    post_disconnect_entry = wTree.get_object("post_disconnect_entry")

    pre_entry.set_text(none_to_blank(script_info.get("pre_entry")))
    post_entry.set_text(none_to_blank(script_info.get("post_entry")))
    pre_disconnect_entry.set_text(
        none_to_blank(script_info.get("pre_disconnect_entry"))
    )
    post_disconnect_entry.set_text(
        none_to_blank(script_info.get("post_disconnect_entry"))
    )

    dialog.show_all()

    result = dialog.run()
    if result == 1:
        script_info["pre_entry"] = blank_to_none(pre_entry.get_text())
        script_info["post_entry"] = blank_to_none(post_entry.get_text())
        script_info["pre_disconnect_entry"] = \
            blank_to_none(pre_disconnect_entry.get_text())
        script_info["post_disconnect_entry"] = \
            blank_to_none(post_disconnect_entry.get_text())
        write_scripts(network, network_type, script_info)
    dialog.destroy()


if __name__ == '__main__':
    if os.getuid() != 0:
        print "Root privileges are required to configure scripts.  Exiting."
        sys.exit(0)
    main(sys.argv)