• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python -Es
2#
3# system-config-selinux.py - GUI for SELinux Config tool in system-config-selinux
4#
5# Dan Walsh <dwalsh@redhat.com>
6#
7# Copyright 2006-2009 Red Hat, Inc.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22#
23import signal
24import string
25import sys
26try:
27    import gtk
28except RuntimeError as e:
29    print("system-config-selinux:", e)
30    print("This is a graphical application and requires DISPLAY to be set.")
31    sys.exit(1)
32
33import gtk.glade
34import os
35import gobject
36import gnome
37import statusPage
38import booleansPage
39import loginsPage
40import usersPage
41import portsPage
42import modulesPage
43import domainsPage
44import fcontextPage
45import selinux
46##
47## I18N
48##
49PROGNAME = "policycoreutils"
50try:
51    import gettext
52    kwargs = {}
53    if sys.version_info < (3,):
54        kwargs['unicode'] = True
55    gettext.install(PROGNAME,
56                    localedir="/usr/share/locale",
57                    codeset='utf-8',
58                    **kwargs)
59except:
60    try:
61        import builtins
62        builtins.__dict__['_'] = str
63    except ImportError:
64        import __builtin__
65        __builtin__.__dict__['_'] = unicode
66
67gnome.program_init("SELinux Management Tool", "5")
68
69version = "1.0"
70
71sys.path.append('/usr/share/system-config-selinux')
72
73
74##
75## Pull in the Glade file
76##
77if os.access("system-config-selinux.glade", os.F_OK):
78    xml = gtk.glade.XML("system-config-selinux.glade", domain=PROGNAME)
79else:
80    xml = gtk.glade.XML("/usr/share/system-config-selinux/system-config-selinux.glade", domain=PROGNAME)
81
82
83class childWindow:
84
85    def __init__(self):
86        self.tabs = []
87        self.xml = xml
88        xml.signal_connect("on_quit_activate", self.destroy)
89        xml.signal_connect("on_delete_clicked", self.delete)
90        xml.signal_connect("on_add_clicked", self.add)
91        xml.signal_connect("on_properties_clicked", self.properties)
92        xml.signal_connect("on_local_clicked", self.on_local_clicked)
93        self.add_page(statusPage.statusPage(xml))
94        if selinux.is_selinux_enabled() > 0:
95            try:
96                self.add_page(booleansPage.booleansPage(xml))
97                self.add_page(fcontextPage.fcontextPage(xml))
98                self.add_page(loginsPage.loginsPage(xml))
99                self.add_page(usersPage.usersPage(xml))
100                self.add_page(portsPage.portsPage(xml))
101                self.add_page(modulesPage.modulesPage(xml))  # modules
102                self.add_page(domainsPage.domainsPage(xml))  # domains
103            except ValueError as e:
104                self.error(e.message)
105
106        xml.signal_connect("on_quit_activate", self.destroy)
107        xml.signal_connect("on_policy_activate", self.policy)
108        xml.signal_connect("on_logging_activate", self.logging)
109        xml.signal_connect("on_about_activate", self.on_about_activate)
110
111        self.add_menu = xml.get_widget("add_menu_item")
112        self.properties_menu = xml.get_widget("properties_menu_item")
113        self.delete_menu = xml.get_widget("delete_menu_item")
114
115    def error(self, message):
116        dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
117                                gtk.BUTTONS_CLOSE,
118                                message)
119        dlg.set_position(gtk.WIN_POS_MOUSE)
120        dlg.show_all()
121        dlg.run()
122        dlg.destroy()
123
124    def add_page(self, page):
125        self.tabs.append(page)
126
127    def policy(self, args):
128        os.spawnl(os.P_NOWAIT, "/usr/share/system-config-selinux/semanagegui.py")
129
130    def logging(self, args):
131        os.spawnl(os.P_NOWAIT, "/usr/bin/seaudit")
132
133    def delete(self, args):
134        self.tabs[self.notebook.get_current_page()].deleteDialog()
135
136    def add(self, args):
137        self.tabs[self.notebook.get_current_page()].addDialog()
138
139    def properties(self, args):
140        self.tabs[self.notebook.get_current_page()].propertiesDialog()
141
142    def on_local_clicked(self, button):
143        self.tabs[self.notebook.get_current_page()].on_local_clicked(button)
144
145    def on_about_activate(self, args):
146        dlg = xml.get_widget("aboutWindow")
147        dlg.run()
148        dlg.hide()
149
150    def destroy(self, args):
151        gtk.main_quit()
152
153    def use_menus(self, use_menus):
154        self.add_menu.set_sensitive(use_menus)
155        self.properties_menu.set_sensitive(use_menus)
156        self.delete_menu.set_sensitive(use_menus)
157
158    def itemSelected(self, selection):
159        store, rows = selection.get_selected_rows()
160        if store != None and len(rows) > 0:
161            self.notebook.set_current_page(rows[0][0])
162            self.use_menus(self.tabs[rows[0][0]].use_menus())
163        else:
164            self.notebook.set_current_page(0)
165            self.use_menus(self.tabs[0].use_menus())
166
167    def setupScreen(self):
168        # Bring in widgets from glade file.
169        self.mainWindow = self.xml.get_widget("mainWindow")
170        self.notebook = self.xml.get_widget("notebook")
171        self.view = self.xml.get_widget("selectView")
172        self.view.get_selection().connect("changed", self.itemSelected)
173        self.store = gtk.ListStore(gobject.TYPE_STRING)
174        self.view.set_model(self.store)
175        col = gtk.TreeViewColumn("", gtk.CellRendererText(), text=0)
176        col.set_resizable(True)
177        self.view.append_column(col)
178
179        for page in self.tabs:
180            iter = self.store.append()
181            self.store.set_value(iter, 0, page.get_description())
182        self.view.get_selection().select_path((0,))
183
184    def stand_alone(self):
185        desktopName = _("Configue SELinux")
186
187        self.setupScreen()
188
189        self.mainWindow.connect("destroy", self.destroy)
190
191        self.mainWindow.show_all()
192        gtk.main()
193
194if __name__ == "__main__":
195    signal.signal(signal.SIGINT, signal.SIG_DFL)
196
197    app = childWindow()
198    app.stand_alone()
199