blob: 3f70122b87e8b1fdf4e2ca67a5380687d9bd1cc0 [file] [log] [blame]
Nicolas Iooss72dc5c62019-02-17 21:57:41 +01001#!/usr/bin/python3 -Es
Dan Walsh514af852012-04-13 11:04:45 -04002#
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#
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020023import os
Dan Walsh514af852012-04-13 11:04:45 -040024import signal
Dan Walshdd6c6192012-11-05 14:59:46 -050025import sys
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020026import gi
27gi.require_version('Gtk', '3.0')
Dan Walshdd6c6192012-11-05 14:59:46 -050028try:
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020029 from gi.repository import Gtk
Jason Zaman4d340e42016-08-05 02:34:03 +080030except RuntimeError as e:
31 print("system-config-selinux:", e)
32 print("This is a graphical application and requires DISPLAY to be set.")
Jason Zaman789d0eb2015-07-24 16:07:13 +080033 sys.exit(1)
Dan Walshdd6c6192012-11-05 14:59:46 -050034
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020035from gi.repository import GObject
Dan Walsh514af852012-04-13 11:04:45 -040036import statusPage
37import booleansPage
38import loginsPage
39import usersPage
40import portsPage
41import modulesPage
42import domainsPage
43import fcontextPage
44import selinux
45##
46## I18N
47##
Jason Zaman789d0eb2015-07-24 16:07:13 +080048PROGNAME = "policycoreutils"
Dan Walsh514af852012-04-13 11:04:45 -040049try:
Jason Zamanaf595442016-08-05 02:34:02 +080050 import gettext
51 kwargs = {}
52 if sys.version_info < (3,):
53 kwargs['unicode'] = True
Dan Walsh514af852012-04-13 11:04:45 -040054 gettext.install(PROGNAME,
55 localedir="/usr/share/locale",
Jason Zamanaf595442016-08-05 02:34:02 +080056 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
Dan Walsh514af852012-04-13 11:04:45 -040065
Dan Walsh514af852012-04-13 11:04:45 -040066version = "1.0"
67
68sys.path.append('/usr/share/system-config-selinux')
69
70
Dan Walsh514af852012-04-13 11:04:45 -040071##
72## Pull in the Glade file
73##
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020074xml = 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")
Dan Walsh514af852012-04-13 11:04:45 -040078else:
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020079 xml.add_from_file("/usr/share/system-config-selinux/system-config-selinux.ui")
Jason Zaman789d0eb2015-07-24 16:07:13 +080080
Dan Walsh514af852012-04-13 11:04:45 -040081
82class childWindow:
Jason Zaman789d0eb2015-07-24 16:07:13 +080083
Dan Walsh514af852012-04-13 11:04:45 -040084 def __init__(self):
Jason Zaman789d0eb2015-07-24 16:07:13 +080085 self.tabs = []
Dan Walsh514af852012-04-13 11:04:45 -040086 self.xml = xml
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +020087 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 })
Dan Walsh514af852012-04-13 11:04:45 -040097 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))
Jason Zaman789d0eb2015-07-24 16:07:13 +0800105 self.add_page(modulesPage.modulesPage(xml)) # modules
106 self.add_page(domainsPage.domainsPage(xml)) # domains
Jason Zaman4d340e42016-08-05 02:34:03 +0800107 except ValueError as e:
Dan Walsh514af852012-04-13 11:04:45 -0400108 self.error(e.message)
109
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200110 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")
Dan Walsh514af852012-04-13 11:04:45 -0400113
114 def error(self, message):
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200115 dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR,
116 Gtk.ButtonsType.CLOSE,
Dan Walsh514af852012-04-13 11:04:45 -0400117 message)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200118 dlg.set_position(Gtk.WindowPosition.MOUSE)
Dan Walsh514af852012-04-13 11:04:45 -0400119 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")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800128
Dan Walsh514af852012-04-13 11:04:45 -0400129 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):
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200145 dlg = xml.get_object("aboutWindow")
Jason Zaman789d0eb2015-07-24 16:07:13 +0800146 dlg.run()
147 dlg.hide()
Dan Walsh514af852012-04-13 11:04:45 -0400148
149 def destroy(self, args):
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200150 Gtk.main_quit()
Dan Walsh514af852012-04-13 11:04:45 -0400151
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
Dan Walsh514af852012-04-13 11:04:45 -0400166 def setupScreen(self):
167 # Bring in widgets from glade file.
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200168 self.mainWindow = self.xml.get_object("mainWindow")
169 self.notebook = self.xml.get_object("notebook")
170 self.view = self.xml.get_object("selectView")
Dan Walsh514af852012-04-13 11:04:45 -0400171 self.view.get_selection().connect("changed", self.itemSelected)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200172 self.store = Gtk.ListStore(GObject.TYPE_STRING)
Dan Walsh514af852012-04-13 11:04:45 -0400173 self.view.set_model(self.store)
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200174 col = Gtk.TreeViewColumn("", Gtk.CellRendererText(), text=0)
Dan Walsh514af852012-04-13 11:04:45 -0400175 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())
Jason Zaman789d0eb2015-07-24 16:07:13 +0800181 self.view.get_selection().select_path((0,))
Dan Walsh514af852012-04-13 11:04:45 -0400182
183 def stand_alone(self):
Nicolas Ioossb550c0e2019-08-05 22:11:20 +0200184 desktopName = _("Configure SELinux")
Dan Walsh514af852012-04-13 11:04:45 -0400185
186 self.setupScreen()
187
188 self.mainWindow.connect("destroy", self.destroy)
189
190 self.mainWindow.show_all()
Nicolas Iooss0f3beeb2017-09-20 08:56:54 +0200191 Gtk.main()
Dan Walsh514af852012-04-13 11:04:45 -0400192
193if __name__ == "__main__":
Jason Zaman789d0eb2015-07-24 16:07:13 +0800194 signal.signal(signal.SIGINT, signal.SIG_DFL)
Dan Walsh514af852012-04-13 11:04:45 -0400195
196 app = childWindow()
197 app.stand_alone()