• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3 -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 os
24import signal
25import sys
26import gi
27gi.require_version('Gtk', '3.0')
28try:
29    from gi.repository import Gtk
30except RuntimeError as e:
31    print("system-config-selinux:", e)
32    print("This is a graphical application and requires DISPLAY to be set.")
33    sys.exit(1)
34
35from gi.repository import GObject
36import statusPage
37import booleansPage
38import loginsPage
39import usersPage
40import portsPage
41import modulesPage
42import domainsPage
43import fcontextPage
44import selinux
45##
46## I18N
47##
48PROGNAME = "policycoreutils"
49try:
50    import gettext
51    kwargs = {}
52    if sys.version_info < (3,):
53        kwargs['unicode'] = True
54    gettext.install(PROGNAME,
55                    localedir="/usr/share/locale",
56                    codeset='utf-8',
57                    **kwargs)
58except:
59    try:
60        import builtins
61        builtins.__dict__['_'] = str
62    except ImportError:
63        import __builtin__
64        __builtin__.__dict__['_'] = unicode
65
66version = "1.0"
67
68sys.path.append('/usr/share/system-config-selinux')
69
70
71##
72## Pull in the Glade file
73##
74xml = Gtk.Builder()
75xml.set_translation_domain(PROGNAME)
76if os.access("system-config-selinux.ui", os.F_OK):
77    xml.add_from_file("system-config-selinux.ui")
78else:
79    xml.add_from_file("/usr/share/system-config-selinux/system-config-selinux.ui")
80
81
82class childWindow:
83
84    def __init__(self):
85        self.tabs = []
86        self.xml = xml
87        xml.connect_signals({
88            "on_quit_activate": self.destroy,
89            "on_delete_clicked": self.delete,
90            "on_add_clicked": self.add,
91            "on_properties_clicked": self.properties,
92            "on_local_clicked": self.on_local_clicked,
93            "on_policy_activate": self.policy,
94            "on_logging_activate": self.logging,
95            "on_about_activate": self.on_about_activate,
96        })
97        self.add_page(statusPage.statusPage(xml))
98        if selinux.is_selinux_enabled() > 0:
99            try:
100                self.add_page(booleansPage.booleansPage(xml))
101                self.add_page(fcontextPage.fcontextPage(xml))
102                self.add_page(loginsPage.loginsPage(xml))
103                self.add_page(usersPage.usersPage(xml))
104                self.add_page(portsPage.portsPage(xml))
105                self.add_page(modulesPage.modulesPage(xml))  # modules
106                self.add_page(domainsPage.domainsPage(xml))  # domains
107            except ValueError as e:
108                self.error(e.message)
109
110        self.add_menu = xml.get_object("add_menu_item")
111        self.properties_menu = xml.get_object("properties_menu_item")
112        self.delete_menu = xml.get_object("delete_menu_item")
113
114    def error(self, message):
115        dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR,
116                                Gtk.ButtonsType.CLOSE,
117                                message)
118        dlg.set_position(Gtk.WindowPosition.MOUSE)
119        dlg.show_all()
120        dlg.run()
121        dlg.destroy()
122
123    def add_page(self, page):
124        self.tabs.append(page)
125
126    def policy(self, args):
127        os.spawnl(os.P_NOWAIT, "/usr/share/system-config-selinux/semanagegui.py")
128
129    def logging(self, args):
130        os.spawnl(os.P_NOWAIT, "/usr/bin/seaudit")
131
132    def delete(self, args):
133        self.tabs[self.notebook.get_current_page()].deleteDialog()
134
135    def add(self, args):
136        self.tabs[self.notebook.get_current_page()].addDialog()
137
138    def properties(self, args):
139        self.tabs[self.notebook.get_current_page()].propertiesDialog()
140
141    def on_local_clicked(self, button):
142        self.tabs[self.notebook.get_current_page()].on_local_clicked(button)
143
144    def on_about_activate(self, args):
145        dlg = xml.get_object("aboutWindow")
146        dlg.run()
147        dlg.hide()
148
149    def destroy(self, args):
150        Gtk.main_quit()
151
152    def use_menus(self, use_menus):
153        self.add_menu.set_sensitive(use_menus)
154        self.properties_menu.set_sensitive(use_menus)
155        self.delete_menu.set_sensitive(use_menus)
156
157    def itemSelected(self, selection):
158        store, rows = selection.get_selected_rows()
159        if store != None and len(rows) > 0:
160            self.notebook.set_current_page(rows[0][0])
161            self.use_menus(self.tabs[rows[0][0]].use_menus())
162        else:
163            self.notebook.set_current_page(0)
164            self.use_menus(self.tabs[0].use_menus())
165
166    def setupScreen(self):
167        # Bring in widgets from glade file.
168        self.mainWindow = self.xml.get_object("mainWindow")
169        self.notebook = self.xml.get_object("notebook")
170        self.view = self.xml.get_object("selectView")
171        self.view.get_selection().connect("changed", self.itemSelected)
172        self.store = Gtk.ListStore(GObject.TYPE_STRING)
173        self.view.set_model(self.store)
174        col = Gtk.TreeViewColumn("", Gtk.CellRendererText(), text=0)
175        col.set_resizable(True)
176        self.view.append_column(col)
177
178        for page in self.tabs:
179            iter = self.store.append()
180            self.store.set_value(iter, 0, page.get_description())
181        self.view.get_selection().select_path((0,))
182
183    def stand_alone(self):
184        desktopName = _("Configue SELinux")
185
186        self.setupScreen()
187
188        self.mainWindow.connect("destroy", self.destroy)
189
190        self.mainWindow.show_all()
191        Gtk.main()
192
193if __name__ == "__main__":
194    signal.signal(signal.SIGINT, signal.SIG_DFL)
195
196    app = childWindow()
197    app.stand_alone()
198