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, 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" 50 51import gettext 52gettext.bindtextdomain(PROGNAME, "/usr/share/locale") 53gettext.textdomain(PROGNAME) 54try: 55 gettext.install(PROGNAME, 56 localedir="/usr/share/locale", 57 unicode=False, 58 codeset='utf-8') 59except IOError: 60 import __builtin__ 61 __builtin__.__dict__['_'] = unicode 62 63gnome.program_init("SELinux Management Tool", "5") 64 65version = "1.0" 66 67sys.path.append('/usr/share/system-config-selinux') 68 69 70## 71## Pull in the Glade file 72## 73if os.access("system-config-selinux.glade", os.F_OK): 74 xml = gtk.glade.XML("system-config-selinux.glade", domain=PROGNAME) 75else: 76 xml = gtk.glade.XML("/usr/share/system-config-selinux/system-config-selinux.glade", domain=PROGNAME) 77 78 79class childWindow: 80 81 def __init__(self): 82 self.tabs = [] 83 self.xml = xml 84 xml.signal_connect("on_quit_activate", self.destroy) 85 xml.signal_connect("on_delete_clicked", self.delete) 86 xml.signal_connect("on_add_clicked", self.add) 87 xml.signal_connect("on_properties_clicked", self.properties) 88 xml.signal_connect("on_local_clicked", self.on_local_clicked) 89 self.add_page(statusPage.statusPage(xml)) 90 if selinux.is_selinux_enabled() > 0: 91 try: 92 self.add_page(booleansPage.booleansPage(xml)) 93 self.add_page(fcontextPage.fcontextPage(xml)) 94 self.add_page(loginsPage.loginsPage(xml)) 95 self.add_page(usersPage.usersPage(xml)) 96 self.add_page(portsPage.portsPage(xml)) 97 self.add_page(modulesPage.modulesPage(xml)) # modules 98 self.add_page(domainsPage.domainsPage(xml)) # domains 99 except ValueError, e: 100 self.error(e.message) 101 102 xml.signal_connect("on_quit_activate", self.destroy) 103 xml.signal_connect("on_policy_activate", self.policy) 104 xml.signal_connect("on_logging_activate", self.logging) 105 xml.signal_connect("on_about_activate", self.on_about_activate) 106 107 self.add_menu = xml.get_widget("add_menu_item") 108 self.properties_menu = xml.get_widget("properties_menu_item") 109 self.delete_menu = xml.get_widget("delete_menu_item") 110 111 def error(self, message): 112 dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR, 113 gtk.BUTTONS_CLOSE, 114 message) 115 dlg.set_position(gtk.WIN_POS_MOUSE) 116 dlg.show_all() 117 dlg.run() 118 dlg.destroy() 119 120 def add_page(self, page): 121 self.tabs.append(page) 122 123 def policy(self, args): 124 os.spawnl(os.P_NOWAIT, "/usr/share/system-config-selinux/semanagegui.py") 125 126 def logging(self, args): 127 os.spawnl(os.P_NOWAIT, "/usr/bin/seaudit") 128 129 def delete(self, args): 130 self.tabs[self.notebook.get_current_page()].deleteDialog() 131 132 def add(self, args): 133 self.tabs[self.notebook.get_current_page()].addDialog() 134 135 def properties(self, args): 136 self.tabs[self.notebook.get_current_page()].propertiesDialog() 137 138 def on_local_clicked(self, button): 139 self.tabs[self.notebook.get_current_page()].on_local_clicked(button) 140 141 def on_about_activate(self, args): 142 dlg = xml.get_widget("aboutWindow") 143 dlg.run() 144 dlg.hide() 145 146 def destroy(self, args): 147 gtk.main_quit() 148 149 def use_menus(self, use_menus): 150 self.add_menu.set_sensitive(use_menus) 151 self.properties_menu.set_sensitive(use_menus) 152 self.delete_menu.set_sensitive(use_menus) 153 154 def itemSelected(self, selection): 155 store, rows = selection.get_selected_rows() 156 if store != None and len(rows) > 0: 157 self.notebook.set_current_page(rows[0][0]) 158 self.use_menus(self.tabs[rows[0][0]].use_menus()) 159 else: 160 self.notebook.set_current_page(0) 161 self.use_menus(self.tabs[0].use_menus()) 162 163 def setupScreen(self): 164 # Bring in widgets from glade file. 165 self.mainWindow = self.xml.get_widget("mainWindow") 166 self.notebook = self.xml.get_widget("notebook") 167 self.view = self.xml.get_widget("selectView") 168 self.view.get_selection().connect("changed", self.itemSelected) 169 self.store = gtk.ListStore(gobject.TYPE_STRING) 170 self.view.set_model(self.store) 171 col = gtk.TreeViewColumn("", gtk.CellRendererText(), text=0) 172 col.set_resizable(True) 173 self.view.append_column(col) 174 175 for page in self.tabs: 176 iter = self.store.append() 177 self.store.set_value(iter, 0, page.get_description()) 178 self.view.get_selection().select_path((0,)) 179 180 def stand_alone(self): 181 desktopName = _("Configue SELinux") 182 183 self.setupScreen() 184 185 self.mainWindow.connect("destroy", self.destroy) 186 187 self.mainWindow.show_all() 188 gtk.main() 189 190if __name__ == "__main__": 191 signal.signal(signal.SIGINT, signal.SIG_DFL) 192 193 app = childWindow() 194 app.stand_alone() 195