2023-12-06 14:31:51 +00:00
|
|
|
#!/usr/bin/python3 -EsI
|
2012-04-13 15:04:45 +00:00
|
|
|
#
|
|
|
|
# system-config-selinux.py - GUI for SELinux Config tool in system-config-selinux
|
|
|
|
#
|
|
|
|
# Dan Walsh <dwalsh@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright 2006-2009 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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, write to the Free Software
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
#
|
2017-09-20 06:56:54 +00:00
|
|
|
import os
|
2012-04-13 15:04:45 +00:00
|
|
|
import signal
|
2012-11-05 19:59:46 +00:00
|
|
|
import sys
|
2017-09-20 06:56:54 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
2012-11-05 19:59:46 +00:00
|
|
|
try:
|
2017-09-20 06:56:54 +00:00
|
|
|
from gi.repository import Gtk
|
2016-08-04 18:34:03 +00:00
|
|
|
except RuntimeError as e:
|
|
|
|
print("system-config-selinux:", e)
|
|
|
|
print("This is a graphical application and requires DISPLAY to be set.")
|
2015-07-24 08:07:13 +00:00
|
|
|
sys.exit(1)
|
2012-11-05 19:59:46 +00:00
|
|
|
|
2023-12-06 14:31:51 +00:00
|
|
|
sys.path.append('/usr/share/system-config-selinux')
|
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
from gi.repository import GObject
|
2012-04-13 15:04:45 +00:00
|
|
|
import statusPage
|
|
|
|
import booleansPage
|
|
|
|
import loginsPage
|
|
|
|
import usersPage
|
|
|
|
import portsPage
|
|
|
|
import modulesPage
|
|
|
|
import domainsPage
|
|
|
|
import fcontextPage
|
|
|
|
import selinux
|
|
|
|
##
|
|
|
|
## I18N
|
|
|
|
##
|
2022-04-01 09:57:24 +00:00
|
|
|
PROGNAME = "selinux-gui"
|
2012-04-13 15:04:45 +00:00
|
|
|
try:
|
2016-08-04 18:34:02 +00:00
|
|
|
import gettext
|
|
|
|
kwargs = {}
|
|
|
|
if sys.version_info < (3,):
|
|
|
|
kwargs['unicode'] = True
|
2022-05-06 14:06:23 +00:00
|
|
|
t = gettext.translation(PROGNAME,
|
2012-04-13 15:04:45 +00:00
|
|
|
localedir="/usr/share/locale",
|
2022-06-24 14:24:25 +00:00
|
|
|
**kwargs,
|
|
|
|
fallback=True)
|
2022-05-06 14:06:23 +00:00
|
|
|
_ = t.gettext
|
2016-08-04 18:34:02 +00:00
|
|
|
except:
|
|
|
|
try:
|
|
|
|
import builtins
|
|
|
|
builtins.__dict__['_'] = str
|
|
|
|
except ImportError:
|
|
|
|
import __builtin__
|
|
|
|
__builtin__.__dict__['_'] = unicode
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
version = "1.0"
|
|
|
|
|
|
|
|
|
|
|
|
##
|
|
|
|
## Pull in the Glade file
|
|
|
|
##
|
2017-09-20 06:56:54 +00:00
|
|
|
xml = Gtk.Builder()
|
|
|
|
xml.set_translation_domain(PROGNAME)
|
|
|
|
if os.access("system-config-selinux.ui", os.F_OK):
|
|
|
|
xml.add_from_file("system-config-selinux.ui")
|
2012-04-13 15:04:45 +00:00
|
|
|
else:
|
2017-09-20 06:56:54 +00:00
|
|
|
xml.add_from_file("/usr/share/system-config-selinux/system-config-selinux.ui")
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
class childWindow:
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
def __init__(self):
|
2015-07-24 08:07:13 +00:00
|
|
|
self.tabs = []
|
2012-04-13 15:04:45 +00:00
|
|
|
self.xml = xml
|
2017-09-20 06:56:54 +00:00
|
|
|
xml.connect_signals({
|
|
|
|
"on_quit_activate": self.destroy,
|
|
|
|
"on_delete_clicked": self.delete,
|
|
|
|
"on_add_clicked": self.add,
|
|
|
|
"on_properties_clicked": self.properties,
|
|
|
|
"on_local_clicked": self.on_local_clicked,
|
|
|
|
"on_policy_activate": self.policy,
|
|
|
|
"on_logging_activate": self.logging,
|
|
|
|
"on_about_activate": self.on_about_activate,
|
|
|
|
})
|
2012-04-13 15:04:45 +00:00
|
|
|
self.add_page(statusPage.statusPage(xml))
|
|
|
|
if selinux.is_selinux_enabled() > 0:
|
|
|
|
try:
|
|
|
|
self.add_page(booleansPage.booleansPage(xml))
|
|
|
|
self.add_page(fcontextPage.fcontextPage(xml))
|
|
|
|
self.add_page(loginsPage.loginsPage(xml))
|
|
|
|
self.add_page(usersPage.usersPage(xml))
|
|
|
|
self.add_page(portsPage.portsPage(xml))
|
2015-07-24 08:07:13 +00:00
|
|
|
self.add_page(modulesPage.modulesPage(xml)) # modules
|
|
|
|
self.add_page(domainsPage.domainsPage(xml)) # domains
|
2016-08-04 18:34:03 +00:00
|
|
|
except ValueError as e:
|
2012-04-13 15:04:45 +00:00
|
|
|
self.error(e.message)
|
|
|
|
|
2017-09-20 06:56:54 +00:00
|
|
|
self.add_menu = xml.get_object("add_menu_item")
|
|
|
|
self.properties_menu = xml.get_object("properties_menu_item")
|
|
|
|
self.delete_menu = xml.get_object("delete_menu_item")
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
def error(self, message):
|
2017-09-20 06:56:54 +00:00
|
|
|
dlg = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR,
|
|
|
|
Gtk.ButtonsType.CLOSE,
|
2012-04-13 15:04:45 +00:00
|
|
|
message)
|
2017-09-20 06:56:54 +00:00
|
|
|
dlg.set_position(Gtk.WindowPosition.MOUSE)
|
2012-04-13 15:04:45 +00:00
|
|
|
dlg.show_all()
|
|
|
|
dlg.run()
|
|
|
|
dlg.destroy()
|
|
|
|
|
|
|
|
def add_page(self, page):
|
|
|
|
self.tabs.append(page)
|
|
|
|
|
|
|
|
def policy(self, args):
|
|
|
|
os.spawnl(os.P_NOWAIT, "/usr/share/system-config-selinux/semanagegui.py")
|
2015-07-24 08:07:13 +00:00
|
|
|
|
2012-04-13 15:04:45 +00:00
|
|
|
def logging(self, args):
|
|
|
|
os.spawnl(os.P_NOWAIT, "/usr/bin/seaudit")
|
|
|
|
|
|
|
|
def delete(self, args):
|
|
|
|
self.tabs[self.notebook.get_current_page()].deleteDialog()
|
|
|
|
|
|
|
|
def add(self, args):
|
|
|
|
self.tabs[self.notebook.get_current_page()].addDialog()
|
|
|
|
|
|
|
|
def properties(self, args):
|
|
|
|
self.tabs[self.notebook.get_current_page()].propertiesDialog()
|
|
|
|
|
|
|
|
def on_local_clicked(self, button):
|
|
|
|
self.tabs[self.notebook.get_current_page()].on_local_clicked(button)
|
|
|
|
|
|
|
|
def on_about_activate(self, args):
|
2017-09-20 06:56:54 +00:00
|
|
|
dlg = xml.get_object("aboutWindow")
|
2015-07-24 08:07:13 +00:00
|
|
|
dlg.run()
|
|
|
|
dlg.hide()
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
def destroy(self, args):
|
2017-09-20 06:56:54 +00:00
|
|
|
Gtk.main_quit()
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
def use_menus(self, use_menus):
|
|
|
|
self.add_menu.set_sensitive(use_menus)
|
|
|
|
self.properties_menu.set_sensitive(use_menus)
|
|
|
|
self.delete_menu.set_sensitive(use_menus)
|
|
|
|
|
|
|
|
def itemSelected(self, selection):
|
|
|
|
store, rows = selection.get_selected_rows()
|
|
|
|
if store != None and len(rows) > 0:
|
|
|
|
self.notebook.set_current_page(rows[0][0])
|
|
|
|
self.use_menus(self.tabs[rows[0][0]].use_menus())
|
|
|
|
else:
|
|
|
|
self.notebook.set_current_page(0)
|
|
|
|
self.use_menus(self.tabs[0].use_menus())
|
|
|
|
|
|
|
|
def setupScreen(self):
|
|
|
|
# Bring in widgets from glade file.
|
2017-09-20 06:56:54 +00:00
|
|
|
self.mainWindow = self.xml.get_object("mainWindow")
|
|
|
|
self.notebook = self.xml.get_object("notebook")
|
|
|
|
self.view = self.xml.get_object("selectView")
|
2012-04-13 15:04:45 +00:00
|
|
|
self.view.get_selection().connect("changed", self.itemSelected)
|
2017-09-20 06:56:54 +00:00
|
|
|
self.store = Gtk.ListStore(GObject.TYPE_STRING)
|
2012-04-13 15:04:45 +00:00
|
|
|
self.view.set_model(self.store)
|
2017-09-20 06:56:54 +00:00
|
|
|
col = Gtk.TreeViewColumn("", Gtk.CellRendererText(), text=0)
|
2012-04-13 15:04:45 +00:00
|
|
|
col.set_resizable(True)
|
|
|
|
self.view.append_column(col)
|
|
|
|
|
|
|
|
for page in self.tabs:
|
|
|
|
iter = self.store.append()
|
|
|
|
self.store.set_value(iter, 0, page.get_description())
|
2015-07-24 08:07:13 +00:00
|
|
|
self.view.get_selection().select_path((0,))
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
def stand_alone(self):
|
2019-08-05 20:11:20 +00:00
|
|
|
desktopName = _("Configure SELinux")
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
self.setupScreen()
|
|
|
|
|
|
|
|
self.mainWindow.connect("destroy", self.destroy)
|
|
|
|
|
|
|
|
self.mainWindow.show_all()
|
2017-09-20 06:56:54 +00:00
|
|
|
Gtk.main()
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-07-24 08:07:13 +00:00
|
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
2012-04-13 15:04:45 +00:00
|
|
|
|
|
|
|
app = childWindow()
|
|
|
|
app.stand_alone()
|