
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
Elf                @   s(  d dl Z e jdd d dlmZ d dlmZ d dlmZ d dlmZ d dlZd dl	Z	d dl
Z
d dl
mZmZmZ d dlZ	d dlZ	d dlZd dlZd dlZd dlZd	Zy:d dlZi Zejd0k rded< ejefddde W nL   yd dlZeejd< W n( ek
r$   d dlZeejd< Y nX Y nX i Zxe	j D ]Z!e!ee	j e! < q8W e"de"dgZ#e"de"dgZ$dd Z%d dl&Z'e"de"dfZ(e"de"dfZ)d Z*dZ+d Z,dZ-dZ.d Z/dZ0dZ1d Z2dZ3dZ4d
Z5dZ6dZ7dZ8d Z9d!Z:d"Z;d#d$d%d&d'd(d)d*d+g	Z<e"d,Z=G d-d. d.Z>e?d/kr$e> Z@dS )1    NGtkz3.0)r   )Gdk)GLib)SELinuxDBus)DISABLED
PERMISSIVE	ENFORCINGzselinux-python   Tunicodez/usr/share/localezutf-8)Z	localedirZcodeset_ZNoZYesZDisableZEnablec             C   s<   | d kr|d krdS | d kr dS |d kr,dS | |k| |k  S )Nr       )abr   r   /usr/lib/python3.6/gui.pycmpF   s    r   zAdvanced >>zAdvanced <<zAdvanced Search >>zAdvanced Search <<r                     	   booleanfcontextzfcontext-equivportloginusermodulenode	interfacez<small>
To change from Disabled to Enforcing mode
- Change the system mode from Disabled to Permissive
- Reboot, so that the system can relabel
- Once the system is working as planned
  * Change the system mode to Enforcing</small>
c               @   s  e Zd Zd%ddZdd Zdd Zd	d
 Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Z d?d@ Z!dAdB Z"dCdD Z#dEdF Z$dGdH Z%dIdJ Z&dKdL Z'dMdN Z(dOdP Z)dQdR Z*dSdT Z+dUdV Z,dWdX Z-dYdZ Z.d[d\ Z/d]d^ Z0d_d` Z1dadb Z2dcdd Z3dedf Z4dgdh Z5didj Z6dkdl Z7dmdn Z8dodp Z9dqdr Z:dsdt Z;dudv Z<dwdx Z=dydz Z>d{d| Z?d}d~ Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zad&ddÄZbddń ZcddǄ ZdddɄ Zedd˄ Zfdd̈́ Zgddτ Zhddф Ziddӄ ZjddՄ Zkddׄ Zlddل Zmddۄ Zndd݄ Zodd߄ Zpdd Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zdd Zd d Zdd Zdd Zdd Zdd	 Zd
d Zdd Zdd Zdd Zdd Zd'ddZdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ ZdS ((  
SELinuxGuiNFc          Q   C   s  d| _ d| _t| _t | _y| jj }W n6 tjjk
r^ } zt	| | j
  W Y d d }~X nX | j  || _d| _tj }tjjddd | _| jd }|j| |jd| _|jd| _|jd	| _|jd
| _d| _|jd| _|jd| _tjtjj | _!tjtjj"| _#t$j% d | _&d | _'d | _(d| _)d| _*d| _+d| _,g | _-g | _.i | _/|jd| _0|jd| _1|jd| _2d| _3|jd| _4|jd| _5| j5j6| j7 |jd| _8|jd| _9|jd| _:d| _;|jd| _<|jd| _=|jd| _>|jd| _?|jd| _@|jd| _A|jd| _B|jd| _C|jd| _D| jDjEdtjFjG |jd | _H| jHj6| j7 |jd!| _I|jd"| _J|jd#| _K|jd$| _L|jd%| _M|jd&| _N| jNjEdtjFjG |jd'| _O| jOj6| j7 |jd(| _P|jd)| _Q|jd*| _R|jd+| _S|jd,| _T|jd-| _U|jd.| _V|jd/| _W|jd0| _X|jd1| _Y|jd2| _Z|jd3| _[|jd4| _\|jd5| _]|jd6| _^|jd7| __|jd8| _`| j`jEdtjFjG |jd9| _a|jd:| _b| jbj6| j7 |jd;| _c|jd<| _d|jd=| _e|jd>| _f|jd?| _g|jd@| _h|jdA| _i|jdB| _j|jdC| _k|jdD| _l|jdE| _m|jdF| _n|jdG| _o|jdH| _p|jdI| _q|jdJ| _r|jdK| _s|jdL| _tg | _u| jv dMk r| jkjwd | jmjwd | jtjwd |jdN| _x|jdO| _y|jdP| _z| j{  |jdQ| _||jdR| _}|jdS| _~|jdT| _|jdU| _|jdV| _|jdW| _|jdX| _|jdY| _|jdZ| _|jd[| _|jd\| _|jd]| _|jd^| _|jd_| _|jd`| _|jda| _|jdb| _|jdc| _|jdd| _|jde| _|jdf| _|jdg| _|jdh| _|jdi| _|jdj| _|jdk| _|jdl| _|jdm| _|jdn| _|jdo| _|jdp| _|jdq| _|jdr| _|jds| _|jdt| _|jdu| _|jdv| _|jdw| _|jdx| _|jdy| _|jdz| _|jd{| _|jd|| _|jd}| _|jd~| _| jjd |jd| _|jd| _|jd| _|jd| _|jd| _|jd| _|jd| _|jd| _|jd| _|jd| _|jd| _|jd| _| jj6| j7 |jd| _| jj | _|jd| _| jjEdtjFjG |jd| _| jj | _|jd| _|jd| _| jjEdtjFjG |jd| _| jj6| j7 |jd| _| jj | _|jd| _|jd| _| jj6| j7 |jd| _| jj | _|jd| _| jjEdtjFjG |jd| _| jj | _|jd| _| jj | _|jd| _|jd| _| jjEdtjFjG |jd| _| jj6| j7 |jd| _| jj | _|jd| _|jd| _| jjEdtjFjG |jd| _| jj6| j7 |jd| _| jj | _|jd| _|jd| _| jjEdMtjFjG |jd| _| jj6| j7 |jd| _|jd| _|jd| _|jd| _| j| _| jj | _|jd| _|jd| _| jjEdtjFjG |jd| _| jj6| j7 |jd| _| jj | _|jd| _| jj | _|jd| _|jd| _| jjEdMtjFjG |jd| _| jj6| j7 |jd| _| jj | _|jd| _|jd| _| jjEdtjFjG |jd| _| jj6| j7 |jd| _| jj | _|jd| _|jd| _|jd| _|jd| _| jjd | jjd | jj| jd  | jj| j | jjdtj |jd| _|jd| _|jd| _|jd| _|jd| _| jjd| _|jd| _|jd| _ |jd| _|jd| _|jd| _| jjd| j| j |jdÃ| _| jjd| j| jc |jdă| _| jjd| j| jY |jdŃ| _| jjd| j| jJ |jdƃ| _	| j	jd| j| j |jdǃ| _
|jd| _|jdȃ| _|jdɃ| _|jdʃ| _|jd˃}| j
jd| j| j g | _| jjd| j| jԃ d| _d }|rddg| _-|r$|| j-kr$| j-j| ntj | _-| j-jtjd΍ |rj|| j-krj| jtdσ|  | j
  |j  t| j-}	tj }
x| j-D ]}| j|| tt| jt|	 | _| jj| j | jj | j | j!  xH|
j"|g D ]6}tj#|}|r| j|| | j.j| qW |  jd7  _qW |j$  | jj%| j | j:j%| j8 | j&| j'| j(| j)| j*| j+| j,| j-| j.| j/| j0| j1| j2| j3| j4| j5| j6| j7| j8| j9| j:| j;| j<| j=| j>| j?| j@| jA| jB| jC| jD| jE| j1| jF| jG| jH| jI| jJ| jJ| jK| jL| jM| jN| jO| jP| jQ| jR| jS| jT| jU| jV| jH| jW| jX| jY| jZ| j[| j\| j\| j\| j]| j^| j_| j7| j`| jadМB}| jb| |jc| | jj  tdjed| jf | jf  d| _g| jj$  | j j$  | jhtikr| jj  nV| jr| jjk| j | jjl| j | jm  | j`  n| jn  | jjot | jp  d| _ tjq  d S )NFT )Zplat_specificz
/sepolicy/zsepolicy.gladeouter_notebookZSELinux_windowZMain_selection_menumain_advanced_labelr   applications_selection_buttonZRevert_buttonr   Zadd_path_dialogerror_check_windowerror_check_labeladvanced_search_windowZadvanced_filterZadvanced_sortadvanced_filter_entryadvanced_search_treeviewZLogin_labellogin_seuser_comboboxZlogin_seuser_liststorelogin_name_entrylogin_mls_labellogin_mls_entryZLogin_buttonlogin_treeviewlogin_liststorelogin_filterlogin_popup_windowlogin_delete_liststorelogin_delete_windowuser_popup_windowZUser_buttonuser_liststoreuser_filteruser_treeviewuser_roles_comboboxZuser_roles_liststoreZ
User_labeluser_name_entryuser_mls_labeluser_mls_level_entryuser_mls_entryZselinux_user_comboboxuser_delete_liststoreuser_delete_windowfile_equiv_labelfile_equiv_source_entryfile_equiv_dest_entryZfile_equiv_buttonfile_equiv_treeviewfile_equiv_liststorefile_equiv_popup_windowZfile_equiv_filterfile_equiv_delete_liststorefile_equiv_delete_windowapp_system_buttonZSystem_buttonZLockdown_buttonZSystems_boxZRelabel_buttonZRelabel_button_noadvanced_systemouter_notebook_frameZsystem_policy_type_labelselect_button_browsecancel_button_browsemoreTypes_window_filesZmore_types_file_liststoreZmoreTypes_treeview_filessystem_policy_type_liststoresystem_policy_type_comboboxr   ZEnforcing_button_defaultZPermissive_button_defaultZDisabled_button_defaultZenable_unconfinedZdisable_unconfinedZenable_permissiveZdisable_permissiveZenable_ptraceZdisable_ptracehelp_windowZ
help_textv	info_text
help_imageforward_buttonback_buttonupdate_windowupdate_treeviewZUpdate_treestoreapply_buttonZUpdate_buttonZ
Add_buttonZDelete_buttonfiles_path_entrynetwork_ports_entryfiles_popup_windownetwork_popup_windowZNetwork_labelZfiles_labelZmake_path_recursiveZfiles_type_combo_storeZfiles_class_combo_storefiles_type_comboboxfiles_class_comboboxfiles_mls_labelfiles_mls_entryZAdvanced_text_filesZcancel_delete_filesZ
tcp_buttonZ
udp_buttonZnetwork_type_combo_storeZnetwork_type_comboboxnetwork_mls_labelnetwork_mls_entryZAdvanced_text_networkZcancel_network_deleteZShow_mislabeled_filesmislabeled_files_labelwarning_filesZModify_buttonfix_label_windowfixlabel_labelfix_label_cancelfiles_delete_windowfiles_delete_treeviewfiles_delete_liststorenetwork_delete_windownetwork_delete_treeviewnetwork_delete_liststoreprogress_barZExecutable_files_treeviewexecutable_files_filterZExecutable_files_tabZexecutable_files_treestoreZfiles_buttonZWritable_files_treeviewZwritable_files_treestorewritable_files_filterZWritable_files_tabZApplication_files_treeviewapplication_files_filterZApplication_files_tabZapplication_files_treestoreZnetwork_buttonZoutbound_treeviewnetwork_out_liststorenetwork_out_filternetwork_out_tabZinbound_treeviewnetwork_in_liststorenetwork_in_filternetwork_in_tabZBoolean_treeviewboolean_liststoreboolean_filterZbooleans_more_detail_windowZbooleans_more_detail_treeviewZbooleans_more_detail_liststoreZBooleans_buttontransitions_into_treeviewtransitions_into_liststoretransitions_into_filterZTransitions_into_tabZTransitions_buttontransitions_from_treeviewtransitions_from_treestoretransitions_from_filterZTransitions_from_tabZfile_transitions_treeviewZfile_transitions_liststoreZfile_transitions_filterZfile_transitionsZcombobox_orgapplication_liststorecompletion_entryentrycompletion_objZShow_modified_only_toggleZEnforcing_labelZEnforcing_buttonZPermissive_button
status_barzSELinux statusfilter_entry
filter_boxadd_modify_delete_boxZactivateZfiles_toggle_deleteZtoggledZfile_equiv_toggle_delete1Zuser_toggle_deleteZlogin_toggle_deleteZnetwork_toggle_deleteZtoggle_updateZfiles_inner_notebookZnetwork_inner_notebookZtransitions_inner_notebookloading_guiZhttpd_tZabrt_t)keyz%s is not a valid domain)BZon_combo_button_clickedZon_disable_ptrace_toggledZ!on_SELinux_window_configure_eventZ%on_entrycompletion_obj_match_selectedZon_filter_changedZ"on_save_changes_file_equiv_clickedZon_save_changes_login_clickedZon_save_changes_user_clickedZon_save_changes_files_clickedZon_save_changes_network_clickedZ)on_Advanced_text_files_button_press_eventZitem_in_tree_selectedZ2on_Application_file_types_treeview_configure_eventon_save_delete_clickedZ)on_moreTypes_treeview_files_row_activatedZon_retry_button_files_clickedZon_make_path_recursive_toggledZ&on_files_path_entry_button_press_eventZon_files_path_entry_changedZon_select_type_files_clickedZon_choose_fileZon_Enforcing_button_toggledZon_confirmation_closeZon_column_clickedZon_tab_switchZon_file_equiv_button_clickedzon_app/system_button_clickedzon_app/users_button_clickedon_show_advanced_search_windowZ on_Show_mislabeled_files_toggledZon_Browse_button_files_clickedZon_cancel_popup_clickedZon_treeview_cursor_changedZ on_login_seuser_combobox_changedZon_user_roles_combobox_changedZon_cancel_button_browse_clickedZon_apply_button_clickedZon_Revert_button_clickedZon_Update_button_clickedZ on_advanced_filter_entry_changedZ)on_advanced_search_treeview_row_activatedZ!on_Select_advanced_search_clickedZ!on_info_button_button_press_eventZon_back_button_clickedZon_forward_button_clickedZ#on_Boolean_treeview_columns_changedZon_completion_entry_changedZon_Add_button_clickedZon_Delete_button_clickedZon_Modify_button_clickedZon_Show_modified_only_toggledZon_cancel_button_config_clickedZon_Import_button_clickedZon_Export_button_clickedZon_enable_unconfined_toggledZon_enable_permissive_toggledZ&on_system_policy_type_combobox_changedZ#on_Enforcing_button_default_toggledZ$on_Permissive_button_default_toggledZ"on_Disabled_button_default_toggledZon_Relabel_button_toggled_cbZ%on_advanced_system_button_press_eventZon_files_type_combobox_changedZon_filter_row_changedZon_button_toggledZgtk_main_quitr   (r  finish_initZadvanced_init
START_PAGEopager   dbus
customized
exceptionsDBusExceptionprintquitinit_curapplication
filter_txtr   ZBuilder	distutils	sysconfigZget_python_lib	code_pathZadd_from_fileZ
get_objectr$   windowmain_selection_windowr%   popupr&   revert_buttonr   ZCursorZ
CursorTypeZWATCHbusy_cursorZLEFT_PTRready_cursorselinuxselinux_getpolicytypeinitialtypecurrent_popupimport_exportclear_entry	files_addnetwork_addmislabeled_filesZall_domainsZinstalled_listZpreviously_modifiedfile_dialogr'   r(   Zinvalid_entryr)   advanced_search_filterZset_visible_funcfilter_the_dataZadvanced_search_sortr*   r+   Zadvanced_searchlogin_labelr,   login_seuser_combolistr-   r.   r/   login_radio_buttonr0   r1   Zset_sort_column_idZSortTypeZ	ASCENDINGr2   r3   r4   r5   r6   user_radio_buttonr7   r8   r9   r:   user_roles_combolist
user_labelr;   r<   r=   r>   Zuser_comboboxr?   r@   rA   rB   rC   file_equiv_radio_buttonrD   rE   rF   Zfile_equiv_treefilterrG   rH   rI   system_radio_buttonlockdown_radio_buttonZsystems_boxrelabel_buttonrelabel_button_norJ   rK   system_policy_labelrL   rM   rN   more_types_files_liststoremoreTypes_treeviewrO   rP   Zpolicy_listpopulate_system_policyset_visibleenforcing_button_defaultpermissive_button_defaultdisabled_button_defaultinitialize_system_default_modeenable_unconfined_buttondisable_unconfined_buttonenable_permissive_buttondisable_permissive_buttonZenable_ptrace_buttondisable_ptrace_buttonrQ   	help_textrR   rS   rT   rU   rV   rW   update_treestorerX   update_button
add_buttondelete_buttonrY   rZ   r[   r\   popup_network_labelpopup_files_labelrecursive_path_togglefiles_type_combolistfiles_class_combolistr]   r^   r_   r`   advanced_text_filesZfiles_cancel_buttonnetwork_tcp_buttonnetwork_udp_buttonnetwork_port_type_combolistnetwork_port_type_comboboxra   rb   advanced_text_networkZnetwork_cancel_buttonshow_mislabeled_files_onlyrc   rd   modify_buttonset_sensitivere   rf   rg   rh   ri   rj   rk   rl   rm   rn   executable_files_treeviewro   executable_files_tabZget_tooltip_textZ executable_files_tab_tooltip_txtexecutable_files_liststorefiles_radio_buttonZfiles_button_tooltip_txtwritable_files_treeviewwritable_files_liststorerp   writable_files_tabZwritable_files_tab_tooltip_txtapplication_files_treeviewrq   application_files_tabZ!application_files_tab_tooltip_txtapplication_files_liststorenetwork_radio_buttonZnetwork_button_tooltip_txtnetwork_out_treeviewrr   rs   rt   Znetwork_out_tab_tooltip_txtnetwork_in_treeviewru   rv   rw   Znetwork_in_tab_tooltip_txtboolean_treeviewrx   ry   boolean_more_detail_windowZboolean_more_detail_treeview!boolean_more_detail_tree_data_setboolean_radio_buttonactive_buttonZboolean_button_tooltip_txtrz   r{   r|   transitions_into_tabZ transitions_into_tab_tooltip_txttransitions_radio_buttonZtransitions_button_tooltip_txtr}   r~   r   transitions_from_tabZ transitions_from_tab_tooltip_txttransitions_file_treeviewtransitions_file_liststoreZtransitions_file_filtertransitions_file_tabZ transitions_file_tab_tooltip_txtZcombobox_menur   r   r   Zset_minimum_key_lengthZset_text_columnZset_match_func
match_funcZset_completionZset_icon_from_stockZ
STOCK_FINDshow_modified_onlycurrent_status_labelcurrent_status_enforcingcurrent_status_permissiver   Zget_context_id
context_idr   r   r   cellZdel_cell_filesconnecton_toggle_updateZdel_cell_files_equivZdel_cell_userZdel_cell_loginZdel_cell_networkZupdate_cellinner_notebook_filesinner_notebook_networkinner_notebook_transitionsZall_entries	on_toggleZloadingappendsepolicyZget_all_domainssortstrlowererrorr   showlenZget_init_entrypoints_strcombo_box_addfloatZ
percentageZset_fractionZset_pulse_step	idle_funcgetZfind_entrypoint_pathhideZ	set_modelopen_combo_menuon_disable_ptracehide_combo_menuset_application_labelget_filter_dataupdate_to_file_equivupdate_to_loginupdate_to_userupdate_to_filesupdate_to_networkreveal_advancedcursor_changedresize_wrapr   populate_type_comboinvalid_entry_retryrecursive_pathhighlight_entry_textautofill_add_files_entryselect_type_moreon_browse_selectset_enforceconfirmation_closecolumn_clickedclear_filtersshow_file_equiv_pagesystem_interfaceusers_interfacer   show_mislabeled_filesbrowse_for_filesclose_popuplogin_seuser_combobox_changeuser_roles_combobox_changeclose_config_windowapply_changes_button_pressupdate_or_revert_changesget_advanced_filter_dataadvanced_item_selectedadvanced_item_button_pushon_help_buttonon_help_back_clickedon_help_forward_clickedresize_columnsapplication_selectedadd_button_clickeddelete_button_clickedmodify_button_clickedon_show_modified_onlyimport_config_showexport_config_showunconfined_togglepermissive_togglechange_default_policychange_default_moderelabel_on_rebootreveal_advanced_systemshow_more_types
tab_changeclosewindowpreviously_modified_initializeZconnect_signalsr   Ztimeout_add_secondsselinux_statuslockdown_initedstatusr   show_system_page	set_labelset_textshow_applications_pageclearbuttonsset_current_pagereinitmain)selfappZtestr   eZbuilderZ
glade_filer   pathlengthZentrypoint_dictdomainZ
entrypointdicr   r   r   __init__u   s    




"





zSELinuxGui.__init__c             C   s"   i | _ xtD ]}i | j |< qW d S )N)cur_dictkeys)rP  kr   r   r   r   s  s    
zSELinuxGui.init_curc             C   sL   d}xB| j D ]8}x2| j | D ]$}||kr8| j | |= d S |d7 }qW qW d S )Nr   r   )rX  )rP  ctrirZ  jr   r   r   
remove_curx  s    zSELinuxGui.remove_curc             C   s  yt j | _W n tk
r(   t| _Y nX | jtkr| jjd | jjd | jjd | j	jd | j
j| jtd | jjt n| j| j tjjdr| jjd n| jjd t j d }t j d }|tkr| j	jd |tkr| jjd |tkr| jjd dS )NFzSystem Status: Disabledz/.autorelabelTr   )r   Zsecurity_getenforcerG  OSErrorr   r   r   r   r   r   r   pushr   r   rR   rI  DISABLED_TEXTset_enforce_textosrS  existsr   
set_activer   r   selinux_getenforcemoder   r   r   r   )rP  Z
policytypemoder   r   r   rE    s0    

zSELinuxGui.selinux_statusc             C   s   | j r
d S | j  d| _ | jjtjd i | _xN| jj j	dD ]:}|j	 }t
|dk r\qB|d t
|dkd| j|d < qBW | jj| jd d	   | jj| jd
 d	   | j  d S )NTZdeny_ptrace
r	   r   )ZpriorityDisabledr   
unconfinedri  permissivedomains)rF  
wait_mouser   re  r   Zsecurity_get_boolean_activeZmodule_dictr   Zsemodule_listsplitr  r   r   ready_mouse)rP  mmodr   r   r   lockdown_init  s    $zSELinuxGui.lockdown_initc             G   s   | j  }|sd S | jtkr4|j dkr4| j| j| | jtkrp| jj|d}|j dkrp|rp| j	| jj|d | jt
kr| jj|d}|r| jj  | jj| d S )NZmore_detail_colr	   Zrestorecon_colr   r   )get_selected_iterr   BOOLEANS_PAGEZget_namedisplay_more_detailr   
FILES_PAGE	liststore	get_valuefix_mislabeledTRANSITIONS_PAGEr   Zclickedr   rJ  )rP  treeviewZtreepathZtreecolargsiterZvisibleZ	bool_namer   r   r   r     s    



zSELinuxGui.column_clickedc             C   s   xt j rt j  qW d S )N)r   Zevents_pendingZmain_iteration)rP  r   r   r   r    s    
zSELinuxGui.idle_funcc             C   s:   y | j j|dj|dkrdS dS  tk
r4   Y nX d S )Nr   r   TFr   )r   rw  findAttributeError)rP  Z
completionZ
key_stringr|  Z	func_datar   r   r   r     s    zSELinuxGui.match_funcc             C   s   | j j| jdk | jj| jt| jd k  y0td| j| j| j f d}|j }|j	  W n t
k
rv   d}Y nX | jj }|j|d| ji  | jj| | jjd| j| j| j f  | j| j d S )Nr   r   z%shelp/%s.txtrr#   APPz%shelp/%s.png)rU   r   	help_pagerT   r  	help_listopenr   readcloseIOErrorr   Z
get_bufferrJ  r   Z
set_bufferrS   Zset_from_file
show_popuprQ   )rP  fdbufr   r   r   r   help_show_page  s    

zSELinuxGui.help_show_pagec             G   s   |  j d8  _ | j  d S )Nr   )r  r  )rP  r{  r   r   r   r1    s    zSELinuxGui.on_help_back_clickedc             G   s   |  j d7  _ | j  d S )Nr   )r  r  )rP  r{  r   r   r   r2    s    z"SELinuxGui.on_help_forward_clickedc             G   st  d| _ g | _| jtkr.| jjtd dg| _| jtkrV| jjtd ddddg| _| jtkr| j	j
 }|tkr| jjtd	 d
g| _|tkr| jjtd dg| _|tkr| jjtd dg| _| jtkr$| jj
 }|tkr| jjtd dg| _|tkr$| jjtd dg| _| jtkr| jj
 }|tkrb| jjtd ddddg| _|tkr| jjtd dg| _|tkr| jjtd dg| _| jtkr| jjtd dddd d!d"g| _| jtkr| jjtd# d$d%d&d'g| _| jtkr$| jjtd( d)d*g| _| jtkrH| jjtd+ d,g| _| jtkrl| jjtd- d.g| _| j S )/Nr   zHelp: Start PagestartzHelp: Booleans PageZbooleansZbooleans_toggledZbooleans_moreZbooleans_more_showzHelp: Executable Files PageZ
files_execzHelp: Writable Files PageZfiles_writezHelp: Application Types PageZ	files_appz'Help: Outbound Network Connections PageZports_outboundz&Help: Inbound Network Connections PageZports_inboundz&Help: Transition from application PageZtransition_fromZtransition_from_booleanZtransition_from_boolean_1Ztransition_from_boolean_2z&Help: Transition into application PageZtransition_toz&Help: Transition application file PageZtransition_filezHelp: Systems PagesystemZsystem_boot_modeZsystem_current_modeZsystem_exportZsystem_policy_typeZsystem_relabelzHelp: Lockdown PageZlockdownZlockdown_unconfinedZlockdown_permissiveZlockdown_ptracezHelp: Login Pager   Zlogin_defaultzHelp: SELinux User PageuserszHelp: File Equivalence PageZ
file_equiv)r  r  r   r   rQ   	set_titler   rs  ru  r   get_current_pageEXE_PAGEWRITABLE_PAGEAPP_PAGENETWORK_PAGEr   OUTBOUND_PAGEINBOUND_PAGEry  r   TRANSITIONS_FROM_PAGETRANSITIONS_TO_PAGETRANSITIONS_FILE_PAGESYSTEM_PAGELOCKDOWN_PAGE
LOGIN_PAGE	USER_PAGEFILE_EQUIV_PAGEr  )rP  r{  ipager   r   r   r0    sl    











zSELinuxGui.on_help_buttonc             G   sX   | j dkrDd| _ | jj }| jj|d d |d d  | jj  n| jj  d| _ d S )Nr   r   r   A   )r   r   Zget_positionr   Zmover  r	  )rP  r{  locationr   r   r   r
  )  s    


zSELinuxGui.open_combo_menuc             G   s   | j j  d| _d S )Nr   )r   r	  r   )rP  r{  r   r   r   r  3  s    
zSELinuxGui.hide_combo_menuc             G   s
   d| _ d S )NT)r  )rP  r{  r   r   r   r  7  s    z SELinuxGui.set_application_labelc             G   s   t | d S )N)r   )rP  r{  r   r   r   r  :  s    zSELinuxGui.resize_wrapc             C   sH   t j d | _| jtkr | j| _| jtkr2| j| _| jtkrD| j	| _d S )Nr   )
r   rf  enforce_moder   r   enforce_buttonr   r   r   r   )rP  r   r   r   r   =  s    


z)SELinuxGui.initialize_system_default_modec             C   sv   t tjtj ddd }|j  d}xJ|D ]B}| jj }| jj|d| || j	krf| j
j| || _|d7 }q,W |S )NT)topdownr   r   )nextrc  walkr   Zselinux_pathr   rO   r   	set_valuer   rP   re  typeHistory)rP  typesr[  itemr|  r   r   r   r   F  s    


z!SELinuxGui.populate_system_policyc             G   s   | j dkrdS yxtd|j D ]p}yR|j||}|dksJ|dksJ|d krLw |j| j dksp|j j| j dkrtdS W q  ttfk
r   Y q X q W W n   Y nX dS )Nr#   Tr   Fr   r   r   )r   rangeget_n_columnsrw  r}  r  r~  	TypeError)rP  listr|  r{  xvalr   r   r   r   S  s    
$zSELinuxGui.filter_the_datac       
      C   s   x|j  D ]|}xv|| D ]j\}}dj||f}	|	| jd krl| jd |	 d dkrTq|| jd |	 d krlq| j|dj||| qW q
W d S )N,r   actionz-dtypez, )rY  joinrX  network_initial_data_insert)
rP  rQ  netdprotocol	directionmodelrZ  tportsZpkeyr   r   r   
net_updatef  s    zSELinuxGui.net_updatec             C   s   | j   tj }| jj  x|D ]}| jj }|| d rX| j|}| j|| d }n|}|| d }| jj|d| | jj|d| | jj|d|| d  q W | j  d S )Nmodifyequivr   r   r   )	rl  r   Zget_file_equivrE   clearr   markupr  rn  )rP  Zedictfr|  namer  r   r   r   file_equiv_initializeq  s    



z SELinuxGui.file_equiv_initializec             C   s   | j   | jj  xtj D ]}| jj }| jj|dt|d  |d }d|kr\|jd | jj|ddj	| | jj|d|j
dd	 | jj|d
|j
dd	 | jj|dd qW | j  d S )Nr   r  rolesZobject_rr   z, r   levelr#   r	   r  r   T)rl  r7   r  r   get_selinux_usersr   r  r   remover  r  rn  )rP  ur|  r  r   r   r   user_initialize  s    


zSELinuxGui.user_initializec             C   s   | j   | jj  xftj D ]Z}| jj }| jj|d|d  | jj|d|d  | jj|d|d  | jj|dd qW | j  d S )	Nr   r  r   seuserr   mlsr	   T)rl  r1   r  r   Zget_login_mappingsr   r  rn  )rP  r  r|  r   r   r   login_initialize  s    

zSELinuxGui.login_initializec             C   s|   t jj|dddd}| j||dt| j t jj|dddd}| j||dt| j t jj|dddd}| j||dt| j d S )Ntcpname_connectT)check_bools	name_bindudp)r   networkget_network_connectr  r  rr   r  ru   )rP  rQ  r  r   r   r   network_initialize  s    zSELinuxGui.network_initializec             C   sD   |j  }|j|d| |j|d| |j|d| |j|dd d S )Nr   r   r   r   T)r   r  )rP  r  r  ZportTyper  r|  r   r   r   r    s
    z&SELinuxGui.network_initial_data_insertc             C   s   d}|j  }x.|D ]&}|d |kr0|j| d S |d7 }qW |j|d }|j|dtdkrr|j|}|d }n|j }|j|d| |j| d S )Nr   r   zMore...)	get_modelre  get_iterrw  r   Zinsert_beforer   r  )rP  comboboxr  r[  rv  r\  niterr|  r   r   r   combo_set_active_text  s    



z SELinuxGui.combo_set_active_textc             C   s2   |j  }|j }|dk rd S |j|}|j|dS )Nr   )r  
get_activer  rw  )rP  r  rv  indexr|  r   r   r   combo_get_active_text  s    
z SELinuxGui.combo_get_active_textc             C   s:   |d krd S | j j }| j j|d| | j j|d| d S )Nr   r   )r   r   r  )rP  r  val1r|  r   r   r   r    s
    
zSELinuxGui.combo_box_addc             G   sN   | j j }|j d }|d kr"d S | jj|d}| j| j| | j| j d S )Nr   r   )	r   get_selectionget_selectedr   rw  r  r]   rC  rN   )rP  r{  rQ  r|  r   r   r   r    s    
zSELinuxGui.select_type_morec             G   sx   | j j }|j \}}|j|}| jj|}| jj|d}|d krFd S | jjd | j	j
  | j| j | jj| d S )Nr   r#   )r+   r  r  convert_iter_to_child_iterr   r   rw  r*   rJ  r)   r	  r  r%   r   )rP  r{  rowr  r|  rQ  r   r   r   r/    s    


z$SELinuxGui.advanced_item_button_pushc             G   s`   | j j|}| j j|}| jj|d}| jjd | jj  | j	| j
 | jj| | j  d S )Nr   r#   )r   r  r  r   rw  r*   rJ  r)   r	  r  r%   r   r4  )rP  rz  rS  r{  r|  rQ  r   r   r   r.    s    
z!SELinuxGui.advanced_item_selectedc             C   s4   |r0t |dkr0x| jD ]}||d krdS qW dS )Nr   TF)r  r   )rP  rQ  itemsr   r   r   find_application  s
    zSELinuxGui.find_applicationc             G   s  | j jd | jjd | jjd | jjd | jj }| j|sHd S | j	  | j
jd | jjd | jj  | jj  | jj  | jj  | jj  | jj  | jj  | jj  | jj  y(|d dkrtj|}|sd S || _W n tk
r    Y nX | j  | j| jj  | j  | j | d| _!| j"| | j#| | j$| | j%| | j&| | j'| | j(| | j)j*t+d|  | j,j*t+d|  | j-j*t+d|  | j.j*t+d	|  | j/j*t+d
|  | j0j*t+d|  | j1j*t+d|  | j2j*t+d|  | j3j4t+d|  | j5j4t+d|  | j6j4t+d|  | j3j*t+d|  | j5j*t+d|  | j6j*t+d|  | j7j*t+d|  || _| j8j4| j | j9  d S )NFr#   Tr   /z(File path used to enter the '%s' domain.z)Files to which the '%s' domain can write.z6Network Ports to which the '%s' is allowed to connect.z5Network Ports to which the '%s' is allowed to listen.z File Types defined for the '%s'.zODisplay boolean information that can be used to modify the policy for the '%s'.z;Display file type information that can be used by the '%s'.zADisplay network ports to which the '%s' can connect or listen to.z!Application Transitions Into '%s'z!Application Transitions From '%s'zFile Transitions From '%s'zVExecutables which will transition to '%s', when executing selected domains entrypoint.zQExecutables which will transition to a different domain, when '%s' executes them.z4Files by '%s' with transitions to a different label.zADisplay applications that can transition into or out of the '%s'.):r   r   rc   rd   r   rJ  r   get_textr  rK  r   r   r   r   r  ru   rr   rx   r{   r~   r   r   r   r   Zget_init_transtyper   
IndexErrorrl  rD  r   r   rN  boolean_initializer   executable_files_initializer  writable_files_initializetransitions_into_initializetransitions_from_initializeapplication_files_initializetransitions_files_initializer   set_tooltip_textr   r   rt   rw   r   r   r   r   r   rI  r   r   r   r&   rn  )rP  r{  rQ  r   r   r   r4    sr    




















zSELinuxGui.application_selectedc             C   s    t j  t j | _t j | _d S )N)r   rN  Z
get_fcdictfcdictZget_local_file_pathslocal_file_paths)rP  r   r   r   rN  6  s    
zSELinuxGui.reinitc             C   s  i | _ x|jdD ]}|j }t|dkr0q|d dkr>q|d | j krZi | j |d < |d dkrd|d dki| j d |d < |d d	kr|d
 |d d| j d	 |d  < |d dkrd|d
 i| j d |d! < |d dkrd|d
 |d d| j d |d" < |d dkr6d|d
 i| j d |d# |d$ f< |d dkrj|d
 |d |d d| j d |d% < |d dkr|d dkrd| j kri | j d< d|d
 i| j d |d& < n"d|d i| j d |d' |d
 f< |d dkrd|d dki| j d |d( < qW d| j krd S xJd| jfd| jfgD ]2\}}|| j d kr.|j| j d | d  q.W x*tD ]"}|| j krj| j j|i i qjW d S ))Nrh  r   r   z-Dr   activer   z-1r   r	   r   )r  r  r!   r  r   s0)r  r  roler   r    r   )maskr  r  r   z-ezfcontext-equivr  r   enabledz-drj  rk  r   r   r   r   r   r   r   r   r   )	cust_dictrm  r  r   r   re  rY  update)rP  r  r\  ZrecZsemodulebuttonr   r   r   rD  ;  sJ     ""&
""
z)SELinuxGui.previously_modified_initializec             C   s   t j|| _x| jj D ]}t| j| dkr0q| j| d }xr| j| d D ]`}||f| jd kr| jd ||f d dkrqN|| jd ||f d krqN| j| j||| qNW qW d S )Nr   r   r   r  z-dr  )r   Zget_entrypointsentrypointsrY  r  rX  files_initial_data_insertr   )rP  r   exe
file_classrS  r   r   r   r  e  s    z&SELinuxGui.executable_files_initializec             C   s@   y&t j|dd }t j|d }||kS  tk
r:   dS X d S )Nr   r   F)r   matchpathcon
getfileconr_  )rP  rS  concurr   r   r   
mislabeleds  s    zSELinuxGui.mislabeledc             C   s   | j |sd S tj|dd }tj|d }d| _|j|dd |j|dd |j|dd |j|d|jdd  |j|d	|jdd  d S )
Nr   r   Tr	   r   r   :r   r   )r  r   r  r  r   r  rm  )rP  treerS  r|  r  r  r   r   r   r   set_mislabeled{  s    
zSELinuxGui.set_mislabeledc             C   s   t j|| _x| jj D ]}t| j| dk rF| j| jd |td q| j| d }xr| j| d D ]`}||f| jd kr| jd ||f d dkrqd|| jd ||f d krqd| j| j||| qdW qW d S )	Nr   z	all filesr   r   r   r  z-dr  )	r   Zget_writable_fileswritable_filesrY  r  r  r   r   rX  )rP  r   writer  rS  r   r   r   r    s    z$SELinuxGui.writable_files_initializec       	      C   s   |j d }|d kr td}d}nl||f| jk}x:tj|D ],}|j |}|j|d| | j|||| q:W |r| j|}| j|}| j|}|j|d| |j|d| |j|d| |j|d| d S )NzMISSING FILE PATHFr   r   r   r   )r   r   r  r   Z	find_filer  r  r  )	rP  rv  rS  Zselinux_labelr  r|  r  pr  r   r   r   r    s"    




z$SELinuxGui.files_initial_data_insertc             C   s   d| S )Nz	<b>%s</b>r   )rP  r  r   r   r   r    s    zSELinuxGui.markupc             C   s    |rt jddt jdd|S d S )Nz</b>$r#   z^<b>)resub)rP  r  r   r   r   unmarkup  s    zSELinuxGui.unmarkupc             C   s   t j|| _x| jj D ]}t| j| dkr0q| j| d }x| j| d D ]p}t j|| jd}||f| jd kr| jd ||f d dkrqN|| jd ||f d krqN| j| j	||| qNW qW d S )Nr   r   )r  r   r  z-dr  )
r   Zget_file_types
file_typesrY  r  Zget_descriptionr  rX  r  r   )rP  r   rQ  r  rS  descr   r   r   r    s    z'SELinuxGui.application_files_initializec             C   s.   d}x$| j D ]}t| j | dkrdS qW dS )Nr   TF)rX  r  )rP  r\  rZ  r   r   r   modified  s
    zSELinuxGui.modifiedc             C   sb   x\t j|D ]N}xH|D ]@\}}|| jd kr>| jd | d }t j|}| j||| qW qW d S )Nr   r  )r   Z	get_boolsrX  boolean_descboolean_initial_data_insert)rP  r   blistr   r  r  r   r   r   r    s    
zSELinuxGui.boolean_initializec             C   sR   | j j }| j j|d| | j j|d| | j j|d| | j j|dtd d S )Nr   r   r   r	   zMore...)rx   r   r  r   )rP  r  r  r  r|  r   r   r   r    s
    
z&SELinuxGui.boolean_initial_data_insertc             C   sb   x\t j|D ]N}d }d }d }d|kr,|d }d|kr<|d }d|krL|d }| j||| qW d S )Nr   targetsource)r   Zget_transitions_into$transitions_into_initial_data_insert)rP  r   r  r  
executabler  r   r   r   r    s    z&SELinuxGui.transitions_into_initializec             C   sd   | j j }|d kr0| j j|dt|d d   n| j j|dd | j j|d| | j j|d| d S )Nr   r   Defaultr   )r{   r   r  r  )rP  r  r  r  r|  r   r   r   r    s    
z/SELinuxGui.transitions_into_initial_data_insertc             C   s   xt j|D ]}d }d }d }d|kr,|d }d|kr<|d }d|krL|d }| j||| y*x$| j| d D ]}| j||| qlW W q tk
r   Y qX qW d S )Nr   r  	transtypeZregex)r   Zget_transitions$transitions_from_initial_data_insertr  KeyError)rP  r   r  r  r  r  Zexecutable_typer   r   r   r    s     z&SELinuxGui.transitions_from_initializec             C   s   | j jd }|d kr6| j j|dd | j j|dd n| j j|}| j j|dt|d d   d}|d d r| j j|dtd	|  n| j j|dtd
|  | j j|d|d d  | j j|dd | j j|d| | j j|d| d S )Nr   r  r   Fr   <span foreground="blue"><u></u></span>r   z:To disable this transition, go to the %sBoolean section%s.z9To enable this transition, go to the %sBoolean section%s.Tr	   )r  r  )r~   r   r  r  r   )rP  r  r  r  r|  r  r  r   r   r   r    s    z/SELinuxGui.transitions_from_initial_data_insertc             C   sJ   xDt j|D ]6}d|kr"|d }nd }| j|d |d |d | qW d S )Nfilenamer  classr  )r   Zget_file_transitions$transitions_files_inital_data_insert)rP  r   r\  r  r   r   r   r    s
    
z'SELinuxGui.transitions_files_initializec             C   sZ   | j j }| j j|d| | j j|d| | j j|d| |d krFd}| j j|d| d S )Nr   r   r   *r	   )r   r   r  )rP  rS  tclassdestr  r|  r   r   r   r  "  s    
z/SELinuxGui.transitions_files_inital_data_insertc             G   s8  | j   d | _d | _d | _d | _| jjd | jj  | j	j
d | jj
d | jj
d | jj
d | jj r| jjt | j| _| j	j
d | jj r| j| j | j	j
d | jj
| j | jj
| j | jj
| j | jjt |d | jkr|d }n
| jj }|tkr*| j| _td}n6|tkrF| j| _td}n|tkr`| j | _td}| j!j"td|| j#d	  | j$j"td
|| j#d	  | jj"td|| j#d	  | j%j r| jj&  | j	j
d | jjt' |d | j(kr|d }n
| j(j }|t)kr | j*| _td}|t+kr:| j,| _td}| j!j"td| j#|d  | j$j"td| j#|d  | jj"td| j#|d  | j-j r | jjt. |d | j/kr|d }n
| j/j }|t0kr| j1| _|t2kr| j3| _|t4kr | j5| _| j6j r"| jjt7 | j8j  | j9j rL| j:  | jjt; | j8j  | j<j r| jjt= | jj&  | j	j
d | j>| _| j!j"td | j$j"td | jj"td | j?j r| jjt@ | jj&  | j	j
d | jA| _| j!j"td | j$j"td | jj"td | jBj r~| jjtC | jj&  | j	j
d | jD| _| j!j"td | j$j"td | jj"td | jj | _E| jr(| j8j&  | jjF | _| jjF | _| jjF | _xXtGd| jjH D ]D}| jjI|}|r|jJ d }tK|tLjMr| jjN|| jOd  qW | jjP jQ  | jjd d S )NFTr   r   r  writabler   z4Add new %(TYPE)s file path for '%(DOMAIN)s' domains.)ZTYPEZDOMAINz3Delete %(TYPE)s file paths for '%(DOMAIN)s' domain.zModify %(TYPE)s file path for '%(DOMAIN)s' domain. Only bolded items in the list can be selected, this indicates they were modified previously.r   zlisten for inbound connectionszMAdd new port definition to which the '%(APP)s' domain is allowed to %(PERM)s.)r  ZPERMzVDelete modified port definitions to which the '%(APP)s' domain is allowed to %(PERM)s.zMModify port definitions to which the '%(APP)s' domain is allowed to %(PERM)s.z%Add new SELinux User/Role definition.z.Delete modified SELinux User/Role definitions.z7Modify selected modified SELinux User/Role definitions.z!Add new Login Mapping definition.z*Delete modified Login Mapping definitions.z3Modify selected modified Login Mapping definitions.z$Add new File Equivalence definition.z-Delete modified File Equivalence definitions.zModify selected modified File Equivalence definitions. Only bolded items in the list can be selected, this indicates they were modified previously.)Rr!  rz  treesort
treefilterrv  r   r   r   r	  r   r   r   rc   rd   r   r  r$   rM  rs  r   r   r  r   ru  r   r  r  r   r   r  r   r  r   r   r  r   r   r   r  r  r   r  r   r  r   r   ry  r   r  r}   r  rz   r  r   r   r  r   r   rq  r  r   r  r9   r   r  r0   r   r  rD   r   r  r  r  Z
get_columnZ	get_cells
isinstancer   ZCellRendererTextZset_sort_func	stripsortr  Zunselect_all)rP  r{  r  categoryr  colr   r   r   r   rB  +  s    
























zSELinuxGui.tab_changec       	      C   s:   |j  \}}| j|j||}| j|j||}t||S )N)Zget_sort_column_idr
  rw  r   )	rP  r  Zrow1Zrow2Z	user_dataZsort_columnr   r  Zval2r   r   r   r%    s    zSELinuxGui.stripsortc             C   s   | j j|}| j j|}| jj  | jjtd| jj	|d  t
j| j| jj	|d}x,|D ]$}| j|d |d |d |d  q^W | j| j d S )NzBoolean %s Allow Rulesr   r  r  r  Zpermlist)ry   r  r  r   r  r   r  r   rx   rw  r   Zget_boolean_rulesr   display_more_detail_initr  )rP  windowsrS  itr  r   r   r   r   rt    s    

$zSELinuxGui.display_more_detailc          	   C   s0   | j j }| j j|dd|||dj|f  d S )Nr   zallow %s %s:%s { %s }; )r   r   r  r  )rP  r  r  Z
class_typeZ
permissionr|  r   r   r   r(    s    
z#SELinuxGui.display_more_detail_initc             G   s  d| _ | jtkrJ| jjtd| j  | jjtd| j  | j	| d S | jt
kr| jjtd| j  | jjtd| j  | j| | jj }|tkr| jjd n| jjd d| _| jtkr| jjtd	 | jjtd
 | j| d| _| jtkr2| jjtd | jjtd | j| d| _| jtkr| jjd | jjd | jjtd | jjtd d| _| j | j | j!  d S )NFzGAdd Network Port for %s.  Ports will be created when update is applied.zAdd Network Port for %szMAdd File Labeling for %s. File labels will be created when update is applied.zAdd File Labeling for %szex: /usr/sbin/Foobarzex: /var/lib/FoobarTzGAdd Login Mapping. User Mapping will be created when Update is applied.zAdd Login MappingzQAdd SELinux User Role. SELinux user roles will be created when update is applied.zAdd SELinux Usersr#   zMAdd File Equivalency Mapping. Mapping will be created when update is applied.zAdd SELinux File Equivalency)"r  r   r  r   rJ  r   r   r\   r  init_network_dialogru  r   r[   init_files_dialogr   r  r  rY   r   r  r   r3   login_init_dialogr  r   r6   user_init_dialogr  rB   rC   rA   rF   r  new_updates)rP  r{  r  r   r   r   r5    sB    







zSELinuxGui.add_button_clickedc             C   s   || _ |j  d S )N)r   r  )rP  r   r   r   r   r    s    zSELinuxGui.show_popupc             G   s   | j j  | jjd dS )NT)r   r	  r   r   )rP  r{  r   r   r   r'    s    
zSELinuxGui.close_popupc             G   s  d }| j r&| j }|s&| jjd d S d| _| jtkr@| j| | jtkr\| j	j
td| j  | jjtd| j  d | _| j| d| _d}d}| jj }|tkr | jj|}|| _| jj|d}| jj
| | jj|d}|d kr| j| j| | jj|d}|d kr | j| j| |tkr| jj|}|| _| jj|d}| jj
| | jj|d}	|	d kr|| j| j|	 | jj|d}|d kr| j| j| |tkr\| j j|}|| _| j!j|d}| jj
| y&| j!j|d}
|
j"d	d j"d
}
W n t#k
r   Y nX | j!j|d}	|	d kr<| j| j|	 |
d }|d kr\| j| j| | jt$kr| j%| | j&j
| j'j|d | j(j
| j'j|d | j)j
| j'j|d | j| j*| j'j|d | j+j
td | j,jtd | j-| j, | jt.kr~| j/| | j0j
| j1j|d | j2j
| j1j|d | j| j3| j1j|d | j4j
td | j5jtd | j-| j5 | jt6kr| j7j
| j8| j9j|d | j:j
| j8| j9j|d | j;j
td | j<jtd d| _=| j-| j< d S )NFTzPModify File Labeling for %s. File labels will be created when update is applied.zAdd File Labeling for %sModifyr   r   r   z<b>z</b>r	   zUModify SELinux User Role. SELinux user roles will be modified when update is applied.zModify SELinux UserszLModify Login Mapping. Login Mapping will be modified when Update is applied.zModify Login MappingzPModify File Equivalency Mapping. Mapping will be created when update is applied.zModify SELinux File Equivalency)>rz  rr  r   r   r  r   r  modify_button_network_clickedru  r   rJ  r   r   r[   r  delete_old_itemr-  r   r  r  ro   r  r   rw  rY   r  r]   r^   r  rp   r   r  rq   r   rm  r~  r  r/  r;   r7   r=   r>   r:   r   r6   r  r  r.  r-   r1   r/   r,   r   r3   r  rB   r
  rE   rC   rA   rF   r   )rP  r{  r|  	operationr  r  rS  ftyper  r  Zget_typer   r   r   r7    s    













z SELinuxGui.modify_button_clickedc             G   sB   | j j|}| j j|d}| j| j| | j| j | jj  d S )Nr   )	r   r  rw  r  r]   r  r[   rN   r	  )rP  r  locr{  r|  r5  r   r   r   r  H  s
    zSELinuxGui.populate_type_comboc             C   s.   |d krd S |j drd}nd}|j|d S )NZ	_script_tZ_tr   )endswithrm  )rP  rU  Z
split_charr   r   r   strip_domainO  s    
zSELinuxGui.strip_domainc             C   s    x|D ]}|j |rdS qW dS )NTF)
startswith)rP  r  exclude_listrR  r   r   r   exclude_typeX  s    

zSELinuxGui.exclude_typec             G   s  g }| j jd | j| j | jj }| jj  | jj  | j	| j
}xN| jD ]D}|d j|rN|d | j
krN|d jd rN|j| j	|d  qNW | jj  yx.tjD ]$}| jj }| jj|dtj|  qW |tko| jd krXxR| jj D ]D}|j|r| jj }| jj|d| | jj }| jj|d| qW | j jd | j jd n(|tkr| jd krxp| jj D ]b}	|	j|r| j|	| r|	| jkr| jj }| jj|d|	 | jj }| jj|d|	 qzW | j jd n|tkr| jd krxntj D ]b}
|
j|r|
j|rT| j|
| rT| jj }| jj|d|
 | jj }| jj|d|
 qW | j jd W n tk
r   td Y nX | jjd | jj d | jj }| jj|dt!d d S )	NTr   Z	httpd_sysr   Fr  r  zMore...)"r^   r   r  r[   r   r  r   r  r   r8  r   r   r9  r   r   r   file_type_strr  r  r  rY  re  r  r  r;  r  r  Zget_all_file_typesr~  r   r]   r`   rJ  r   )rP  r{  r:  r  Zcomparedfilesr|  r  r  rQ  r   r   r   r-  ^  s`    


,



(




zSELinuxGui.init_files_dialogc             G   s   | j  }|s| jjd d S | jjtd| j  | jjtd| j  d | _	| j
| d}d}d| _| j  }| jj|d}| jj| | jj|d}|dkr| jjd n|d	kr| jjd | jj|d
}|d kr| j| j| || _	d S )NFzJModify Network Port for %s.  Ports will be created when update is applied.zModify Network Port for %sr1  r   Tr   r  r  r   )rr  r   r   r   rJ  r   r   r\   r  r3  r,  r  rv  rw  rZ   r   re  r   r  r   )rP  r{  r|  r4  r  r   r  r  r   r   r   r2    s.    
z(SELinuxGui.modify_button_network_clickedc             G   s  | j | j | jj }| jj  | jjd y:|tkrPt	j
j| jdddd}n8|tkrt	j
j| jdddd}|t	j
j| jdddd7 }g }xL|j D ]@}x:|| D ].\}}||dd	g kr|jd
rq|j| qW qW |j  | j| j}|d dkr|d d }|d }d}	d}
x@|D ]8}|j|r2|	}
| jj }| jj|d| |	d7 }	qW | jj|
 W n tk
r~   Y nX | jjd | jjd d S )Nr#   r  r  T)r  r  r  Zport_tZunreserved_port_tZ_typer   r=  r   r   r  r   r   )r  r\   r   r  r   r  rZ   rJ  r  r   r  r  r   r  rY  r7  r   r   r8  r9  r  r   re  r~  r   rb   )rP  r{  r  r  Z
port_typesrZ  r  r  Zshort_domainr[  foundr|  r   r   r   r,    sF    




zSELinuxGui.init_network_dialogc             G   sN   | j |}| jj dkrJx0tj D ]$}||d kr"| jj|jdd q"W d S )Nr#   r  r  )r  r/   r  r   r  rJ  r  )rP  combor{  r  r  r   r   r   r(    s
    
z'SELinuxGui.login_seuser_combobox_changec             G   sN   | j |}| jj dkrJx0tj D ]$}||d kr"| jj|jdd q"W d S )Nr#   r  r  )r  r>   r  r   get_all_rolesrJ  r  )rP  r@  r{  Zseroler  r   r   r   r)    s
    
z%SELinuxGui.user_roles_combobox_changec             C   sN   d }| j sd S | j j }|s d S |j \}}|rJ|j|}|rJ| jj|}|S )N)rz  r  r  r  r#  )rP  r|  r  r"  r   r   r   rr    s    

zSELinuxGui.get_selected_iterc             G   sf   | j jd | j }|d kr,| j jd d S | j|  sH| j| d  rLd S | j j| j| d  d S )NFr   r   r   )r   r   rr  rv  )rP  r{  r|  r   r   r   r    s    zSELinuxGui.cursor_changedc             G   sn   | j | j | jj  tj }|j  x*|D ]"}| jj }| jj|dt	| q,W | j
jd | jjd d S )Nr   r#   )r  r3   r   r  r   Zget_all_usersr   r   r  r   r-   rJ  r/   )rP  r{  r  r  r|  r   r   r   r.    s    


zSELinuxGui.login_init_dialogc             G   sn   | j | j | jj  tj }|j  x*|D ]"}| jj }| jj|dt	| q,W | j
jd | jjd d S )Nr   r#   )r  r6   r   r  r   rA  r   r   r  r   r;   rJ  r>   )rP  r{  r  r  r|  r   r   r   r/  	  s    


zSELinuxGui.user_init_dialogc             C   sh   | j rdd|j  }| j  y| jj| W n0 tjjk
rZ } z| j| W Y d d }~X nX | j  d S )Nzboolean -m -%d deny_ptrace)	r   r  rl  r   semanager   r   r  rn  )rP  checkbuttonupdate_bufferrR  r   r   r   r    s    zSELinuxGui.on_disable_ptracec                s  | j j   fdd}g }| jtkrh|j s8| j| jS x.| j D ]$}|d | jd kr@|j|| q@W | jt	kr| j
j }|j s|tkr| j| jS |tkr| j| jS |tkr| j| jS x2| j D ](}|d |d f| jd kr|j| qW | jtkrR|j s| j| jS x:| j D ]0}|d |d f| jd kr|j|| qW | jtkr|j d	kst| j S x2| j D ](}|d | jd
 kr||j|| q|W | jtkr|j s| j S x2| j D ](}|d | jd kr|j|| qW | jtkrP|j d	ks| j S x2| j D ](}|d | jd kr$|j|| q$W | j j  xB|D ]:}| j j }x(td D ]}| j j||||  qzW q`W d S )Nc                s*   g }x t d D ]}|j| |  qW |S )Nr   )r  r   )r  lr\  )rT  r   r   dup_row!  s    z1SELinuxGui.on_show_modified_only.<locals>.dup_rowr   r   r   r   r   r   Tzfcontext-equivr   r   )rv  r  r   rs  r  r  r   r  r   ru  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )rP  rC  rF  Zappend_listr  r  r|  r\  r   )rT  r   r8    sd    








z SELinuxGui.on_show_modified_onlyc       	      C   s8   |j d }|j|d| |j|d| |j|d| d S )Nr   r   r   )r   r  )	rP  r  rQ  r  r4  rS  Zfclassr5  r|  r   r   r   init_modified_files_liststoreb  s    
z(SELinuxGui.init_modified_files_liststorec             G   s   t d d S )Nzrestore to defualt clicked...)r   )rP  r{  r   r   r   restore_to_defaulth  s    zSELinuxGui.restore_to_defaultc             G   s(   | j | j | jjd | jjd d S )NT)rC  r'   r[   r   r\   )rP  r{  r   r   r   r  k  s    zSELinuxGui.invalid_entry_retryc             C   sV   t |dks|d dkrR| jj  | jjd | jjd | jjtd|  dS dS )Nr   r  FzAThe entry '%s' is not a valid path.  Paths must begin with a '/'.T)	r  r'   r  r[   r   r\   r(   rJ  r   )rP  Z
insert_txtr   r   r   error_check_filesp  s    
zSELinuxGui.error_check_filesc             C   sl   y t |}|dk s|dkrtW nF tk
rf   | jj  | jjd | jjd | jjt	d dS X dS )Nr   i   Fz'Port number must be between 1 and 65536T)
int
ValueErrorr'   r  r[   r   r\   r(   rJ  r   )rP  r   Zpnumr   r   r   error_check_networky  s    
zSELinuxGui.error_check_networkc             G   s2   | j r.| j| jtdkr.| jj  | jj  d S )NzMore...)r   r  r]   r   r[   r	  rN   r  )rP  r{  r   r   r   rA    s    
zSELinuxGui.show_more_typesc       	      G   s  | j   | j| j}| jj }| jj }| jr| j }| jj	|d}| jj	|d}| jj	|d}| j
j|d| | j
j|d| | j
j|d| d|||||d| jd |< n"| j
jd }d||d| jd |< | j
j|d| | j
j|d| | j
j|d| | j  d S )	Nr   r   r   z-m)r  r  r  oldrange	oldseuseroldnamer   z-a)r  r  r  )r'  r  r,   r/   r  r-   r  rr  r1   rw  rv  r  rX  r   r0  )	rP  r{  r  	mls_ranger  r|  rO  rN  rM  r   r   r   r    s&    

zSELinuxGui.update_to_loginc          	   G   sj  | j   | j| j}| jj }| jj }| jj }| jr| j }| j	j
|d}| j	j
|d}| j	j
|d}	| j	j
|d}
| jj|d| | jj|d| | jj|d|	 | jj|d|
 d||||
|	||d| jd |< nD| jjd }|s|r
d|||d	| jd |< nd|d
| jd |< | jj|d| | jj|d| | jj|d| | jj|d| | j  d S )Nr   r   r	   r   z-m)r  r  r  r  rM  oldleveloldrolesrO  r   z-a)r  r  r  r  )r  r  )r'  r  r:   r=   r  r>   r;   r  rr  r7   rw  rv  r  rX  r   r0  )rP  r{  r  r  rP  r  r|  rO  rR  rQ  rM  r   r   r   r    s2    


"
zSELinuxGui.update_to_userc             G   s   | j   | jj }| jj }| jrl| j }| j| jj|d}| j| jj|d}d|||d| j	d |< n | jj
d }d|d| j	d |< | jj|d| j| | jj|d| j| d S )Nr   r   z-m)r  srcoldsrcolddestzfcontext-equivz-a)r  rS  )r'  rC   r  rB   r  rr  r
  rv  r  rX  r   r  )rP  r{  r   rS  r|  rU  rT  r   r   r   r    s    

zSELinuxGui.update_to_file_equivc       
      G   s0  | j   d| _| jj }| j|r&d S | j| j}| jj }| j| j}| j	r| j
 }| j| jj|d}| j| jj|d}| jj|d}	d||||	d| jd ||f< n$| jjd }d|d	| jd ||f< | jj|d| j| | jj|d| j| | jj|d| j| d
| _| jjd
 | j  d S )NTr   r   r   z-m)r  r  oldtypeoldpathZoldclassr   z-a)r  r  F)r'  r   rY   r  rI  r  r]   r`   r^   r  rr  unmarkrv  rw  r  rX  r   r  r   re  r0  )
rP  r{  rS  setyper  r  r|  rW  	oldsetypeZ	oldtclassr   r   r   r    s,    


 zSELinuxGui.update_to_filesc       
      G   s2  d| _ | jj }| j|rd S | jj r.d}nd}| j| j}| jj }| j	r| j
 }| j| jj|d}| j| jj|d}| j| jj|d}	d|||	||d| jd	 ||f< n&| jjd }d
||d| jd	 ||f< | jj|d| | jj|d| | jj|d| d| _ | jj  | jjd | j  d S )NTr  r  r   r   r   z-m)r  r  r  rV  oldprotocololdportsr   z-a)r  r  r  F)r   rZ   r  rL  r   r  r  r   rb   r  rr  rX  rv  rw  r  rX  r   r\   r	  r   r   r0  )
rP  r{  r  r  rY  r  r|  r\  r[  rZ  r   r   r   r    s0    



"
zSELinuxGui.update_to_networkc             G   s  d}| j jd | jtkr| jj  | jd }xZ|D ]R\}}|||f d }| jj }| jj|d| | jj|d| | jj|d| q4W | j	| j
 d S | jtkr,| jj  | jd }x`|D ]X\}	}
||	|
f d }| jj }| jj|d|	 | jj|d| | jj|dtj|
  qW | j	| j d S | jtkr| jj  | jd	 }x|D ]|}|| d
 }|| jdd}|| jdd}| jj }| jj|d| | jj|d| | jj|d| | jj|d| qRW | j	| j d S | jtkrx| jj  | jd }xd|D ]\}|| d }|| jdd}| jj }| jj|d| | jj|d| | jj|d| qW | j	| j d S | jtkr| jj  xX| jD ]N}|d r| jj }| jj|d| j|d  | jj|d| j|d  qW | j	| j d S d S )NZAddFr   r  r   r   r	   r   r   r  r  r#   r  r   r   r  r   )r   r   r   r  rm   r  r  r   r  r  rk   ru  rj   r   r<  rh   r  r?   r  r@   r  r4   r5   r  rG   rE   r
  rH   )rP  r{  r4  Z	port_dictr  r  rY  r|  Zfcontext_dictrS  r  Z	user_dictr   r  r  r  Z
login_dictr   r  r  r   r   r   r6    sv    

















 z SELinuxGui.delete_button_clickedc             G   sx  | j   | jtkrNx:| jD ]0}|d rd|d d| jd |d |d f< qW | jtkrx>| jD ]4}|d r`d|d d| jd |d t|d  f< q`W | jtkrx8| j	D ].}|d rd|d |d	 d
| jd |d < qW | jt
kr(x>| jD ]4}|d rd|d |d |d d| jd |d < qW | jtkrlx6| jD ],}|d r<d|d d| jd |d < q<W | j  d S )Nr   z-dr	   )r  r  r   r   r   r   r   )r  r  r  r   )r  r   r  r  r   )r  rS  zfcontext-equiv)r'  r   r  rm   rX  ru  rj   reverse_file_type_strr  r?   r  r4   r  rG   r0  )rP  r{  deleter   r   r   r   O  s,    
(
,
&,
"z!SELinuxGui.on_save_delete_clickedc             G   s,   x&| j D ]}t|d |d |d  qW d S )Nr   r   r   )rj   r   )rP  r{  r^  r   r   r   !on_save_delete_file_equiv_clickedg  s    z,SELinuxGui.on_save_delete_file_equiv_clickedc             C   s   || d  || d< d S )Nr   r   )rP  r   rS  r  r   r   r   r   k  s    zSELinuxGui.on_toggle_updatec             C   sV   d}xL|D ]D}|d |d krF|d |d krF|j |}|j| d S |d7 }q
W d S )Nr   r   r   )r  r  )rP  rv  r   r[  r  r|  r   r   r   ipage_deleten  s    
 

zSELinuxGui.ipage_deletec             C   s   |sd S | j j|}| j j|}|j|d}|j|d|j|d  |j|d}|| jd krl| jd |= nd|i| jd |< | j  d S )Nr   r   r   r  )ry   r  r  rw  r  rX  r0  )rP  r   rS  r  r|  r  r  r   r   r   r   w  s    zSELinuxGui.on_togglec             G   s   |j  | _| jj  d S )N)r  r   r   refilter)rP  entryr{  r   r   r   r-    s    
z#SELinuxGui.get_advanced_filter_datac             G   s   |j  | _| jj  d S )N)r  r   r#  ra  )rP  r)  r{  r   r   r   r    s    
zSELinuxGui.get_filter_datac             G   sF  d| _ | jj  x| jd D ]}| jd | d }| jjd }| jj|dd | jj|dtj| | jj|dt| jd | d   | jj|dd | jj|}| jj|dt	d	|  | jj|dd
 qW x| jd D ]~\}}| jd ||f d }| jd ||f d }| jjd }| jj|dd | jj|d| | jj|dd |dkrr| jj|dt	d| j
  |dkr| jj|dt	d| j
  |dkr| jj|dt	d| j
  | jj|}| jj|dd
 | jj|dt	d|  | jj|}| jj|dd
 | jj|dt	dtj|   | jj|}| jj|dd
 | jj|dt	d|  qW x| jd D ]z\}	}
| jd |	|
f d }| jjd }| jj|dd | jj|d| | jj|dd |dkr| jj|dt	d| j
  |dkr| jj|dt	d| j
  |dkr6| jj|dt	d| j
  | jj|}| jj|dt	d|	  | jj|dd
 | jj|}| jj|dt	d|
  | jj|dd
 | jd |	|
f d }| jj|}| jj|dd
 | jj|dt	d|  qnW x| jd D ]r}| jd | d }| jjd }| jj|dd | jj|d| | jj|dd |dkrn| jj|dt	d |dkr| jj|dt	d |dkr| jj|dt	d | jj|}| jj|dt	d |  | jj|dd
 | jj|}| jj|dd
 | jd | d! }| jj|dt	d"|  | jd | jd#d$}| jj|}| jj|dd
 | jj|dt	d%|  qW x| jd& D ]r}| jd& | d }| jjd }| jj|dd | jj|d| | jj|dd |dkr| jj|dt	d' |dkr| jj|dt	d( |dkr0| jj|dt	d) | jj|}| jj|dd
 | jj|dt	d*|  | jj|}| jj|dd
 | jd& | d+ }| jj|dt	d,|  | jd& | jd#d$}| jj|}| jj|dd
 | jj|dt	d%|  qW x8| jd- D ](}| jd- | d }| jjd }| jj|dd | jj|d| | jj|dd |dkrz| jj|dt	d. |dkr| jj|dt	d/ |dkr| jj|dt	d0 | jj|}| jj|dd
 | jj|dt	d1|  | jj|}| jj|dd
 | jd- | d2 }| jj|dt	d3|  qW | j| j d S )4NTr   r  r   r   r   r  r	   zSELinux name: %sFr   r  z-azAdd file labeling for %sz-dzDelete file labeling for %sz-mzModify file labeling for %szFile path: %szFile class: %szSELinux file type: %sr   zAdd ports for %szDelete ports for %szModify ports for %szNetwork ports: %szNetwork protocol: %sr   zAdd userzDelete userzModify userzSELinux User : %sr  z	Roles: %sr  r#   zMLS/MCS Range: %sr   zAdd login mappingzDelete login mappingzModify login mappingzLogin Name : %sr  zSELinux User: %szfcontext-equivzAdd file equiv labeling.zDelete file equiv labeling.zModify file equiv labeling.zFile path : %srS  zEquivalence: %s)r  r   r  rX  r   r  r   r  r  r   r   r<  r  r  rV   )rP  r{  Zboolsr4  r|  r  rS  r  rY  r   r  r   r  r  r   r  rS  r   r   r   
update_gui  s    
"














zSELinuxGui.update_guic             C   sL   | j j r| j | _| jj r$| j| _| jj r6| j| _| jj rH| j| _d S )N)r   r  r   r   r   r   )rP  r   r   r   set_active_application_button	  s    



z(SELinuxGui.set_active_application_buttonTc             C   s~   | j j  | jjd | jjd | jjd | jjd | jjd | jjd | j	jd | j
jd |rz| jjd d S )NFr#   )r   r	  r   r   r   r   r   r   r   r   r   r   rJ  )rP  r  r   r   r   rL   	  s    
zSELinuxGui.clearbuttonsc             C   sP   | j   | jjd | jjd | jjtd | jjd | j  | j	  d S )NTZSystem)
rL  r   r   r   r&   rI  r   re  rB  r  )rP  r   r   r   rH  -	  s    zSELinuxGui.show_system_pagec             G   sX   | j   | j  | jjd | jjtd | j  | j  | j	j
d | jj
d d S )NTzFile Equivalence)rL  r  r   re  r&   rI  r   rB  r  r   r   r   )rP  r{  r   r   r   r"  6	  s    zSELinuxGui.show_file_equiv_pagec             C   sx   | j   | jjd | jjd | jjtd | jjd | j  | j	  | j
  | j  | jjd | jjd d S )NTZUsers)rL  r   r   r   r&   rI  r   re  rB  r  r  r  r   r   r   )rP  r   r   r   show_users_page@	  s    zSELinuxGui.show_users_pagec             C   sZ   | j d | jjd | jjd | jjd | jjd | jjd | j  | j  d S )NFT)	rL  r   r   r   r   r   re  rB  r  )rP  r   r   r   rK  M	  s    
z!SELinuxGui.show_applications_pagec             G   s   | j   d S )N)rH  )rP  r{  r   r   r   r#  W	  s    zSELinuxGui.system_interfacec             G   s   | j   d S )N)re  )rP  r{  r   r   r   r$  Z	  s    zSELinuxGui.users_interfacec       	      G   s   g }d}| j j }|j dkrx^| jD ]T}| jj|}| jj|}| jj|}|d kr&| jj|ddkrr|j	| |d7 }q&W xn|D ]}| jj
| qW nT| jd kr| jj  |tkr| j| j n*|tkr| j| j n|tkr| j| j d S )Nr   Tr   Fr   )r   r  r  rv  r"  r  r  r#  rw  r   r  r   r  r  r  r  r  r  r  )	rP  rC  r{  Ziterlistr[  r  r  r|  Zitersr   r   r   r%  ]	  s,    




z SELinuxGui.show_mislabeled_filesc             C   sp   t j|d jdd }t j|dd jdd }| jtd|||d ddtjjkrl| j	j
| | j  d S )	Nr   r  r   r   zbRun restorecon on %(PATH)s to change its type from %(CUR_CONTEXT)s to the default %(DEF_CONTEXT)s?)PATHZCUR_CONTEXTZDEF_CONTEXTzrestorecon dialog)title)r   r  rm  r  verifyr   r   ResponseTypeZYESr   Z
restoreconr4  )rP  rS  r   r  r   r   r   rx  v	  s
    &zSELinuxGui.fix_mislabeledc             G   s$   | j j| j  | jj| j  d S )N)r   r   r  r   )rP  r{  r   r   r   r0  }	  s    zSELinuxGui.new_updatesc             G   sF   | j   |j tdk| _| jr2| jjtd n| jjtd d S )NZUpdatezUpdate ChangeszRevert Changes)rc  	get_labelr   r  rV   r  )rP  r  r{  r   r   r   r,  	  s
    z#SELinuxGui.update_or_revert_changesc             G   sb   | j   | jr| j  n| j  d| _| j| jj  d| _| j  | j	  | j
  | jj  d S )NFT)r'  r  update_the_systemrevert_datar   rD  r   r   r!  r4  r0  r   r  )rP  r{  r   r   r   r+  	  s    
z%SELinuxGui.apply_changes_button_pressc             G   sl   | j   | j }| j  y| jj| W n. tjjk
rV } zt| W Y d d }~X nX | j  | j	  d S )N)
r'  format_updaterl  r   rB  r   r   r   rn  r   )rP  r{  rD  rR  r   r   r   rk  	  s    zSELinuxGui.update_the_systemc             C   s2   dddddd}x|D ]}||kr|| S qW dS )Nr   r   r   )zExecutable FileszWritable FileszApplication File TypeZInboundZOutboundZBooleansr   )rP  lookupZipage_valuesvaluer   r   r   ipage_value_lookup	  s
    
zSELinuxGui.ipage_value_lookupc             C   s4   |j dd }|j dd }|dkr,|| _n|S d S )Nz: r   r   zSELinux name)rm  Zbool_revert)rP  Z	attributeZbool_idr   r   r   get_attributes_update	  s
    z SELinuxGui.get_attributes_updatec       	   	   C   s  | j   d}xp| jD ]d}|dkrVx0| j| D ]"}|d| j| | d |f 7 }q0W |dkrx| j| D ]}| j| | d dkr|d| 7 }qld	| j| | kr|d
| j| | d | j| | d | j| | d	 |f 7 }ql|d| j| | d | j| | d |f 7 }qlW |dkrx| j| D ]}| j| | d dkrX|d| 7 }nd| j| | krd	| j| | kr|d| j| | d | j| | d | j| | d	 | j| | d |f 7 }n.|d| j| | d | j| | d |f 7 }q.W |dkrxxh| j| D ]Z}| j| | d dkrD|d| 7 }n.|d| j| | d | j| | d |f 7 }qW |dkrxx| j| D ]j}| j| | d dkr|d| 7 }n>|d| j| | d | j| | d | j| | d |f 7 }qW |dkrxv| j| D ]h\}}| j| ||f d dkrF|d||f 7 }n0|d| j| | d | j| | d ||f 7 }qW qW |S )Nr#   r   zboolean -m -%d %s
r  r   r  z-dzlogin -d %s
r  zlogin %s -s %s -r %s %s
r  zlogin %s -s %s %s
r   zuser -d %s
r  zuser %s -L %s -r %s -R %s %s
r  zuser %s -R %s %s
zfcontext-equivzfcontext -d %s
zfcontext %s -e %s %s
rS  r   zfcontext %s -t %s -f %s %s
r  r  r   zport -d -p %s %s
zport %s -t %s -p %s %s
)rl  rX  )	rP  rD  rZ  r   rE  r  r  r   r  r   r   r   rm  	  sH    "
@2
(P4
4
D:zSELinuxGui.format_updatec             C   s`   d}g }d}x.| j D ]$}| j | d s0|j| |d7 }qW |j  x|D ]}| j| qJW d S )Nr   r#   r   )r   r   reverser^  )rP  r[  Zremove_listrD  r  r   r   r   rl  	  s    

zSELinuxGui.revert_datac             G   sN   |j  td k}|r$|jtd  n|jtd  | jj| | jj| d S )Nr   r   )r  ADVANCED_LABELrJ  r   r   rP   )rP  labelr{  advancedr   r   r   r@  	  s    z!SELinuxGui.reveal_advanced_systemc             G   sf   |j  td k}|r$|jtd  n|jtd  | jj| | jj| | jj| | jj| d S )Nr   r   )r  rs  rJ  r_   r   r`   ra   rb   )rP  rt  r{  ru  r   r   r   r  	  s    zSELinuxGui.reveal_advancedc             G   sF   |j  td kr(|jtd  | j  n|jtd  | j| j d S )Nr   r   )r  ADVANCED_SEARCH_LABELrJ  r'  r  r)   )rP  rt  r{  r   r   r   r    
  s
    
z)SELinuxGui.on_show_advanced_search_windowc             C   sJ   |r&| j j| jtd | jjd n | j j| jtd | jjd d S )NzSystem Status: EnforcingTzSystem Status: Permissive)r   r`  r   r   r   re  r   )rP  ro  r   r   r   rb  
  s
    zSELinuxGui.set_enforce_textc             C   s,   | j s
d S | jj|j  | j|j  d S )N)r   r   Z
setenforcer  rb  )rP  r  r   r   r   r  
  s    zSELinuxGui.set_enforcec             G   s`   | j j }|d krd S d| _| j j  | jj| | jdkrH| j| n| jdkr\| j| d S )NFImportExport)	r   get_filenamer   r	  rY   rJ  r   import_configexport_config)rP  r{  r  r   r   r   r  
  s    



zSELinuxGui.on_browse_selectc             G   sX   | j j }| jj r0|jdsT| j j|d  n$|jdrT|jdd }| j j| d S )Nz(/.*)?r   )rY   r  r   r  r7  rJ  rm  )rP  r{  rS  r   r   r   r  #
  s    



zSELinuxGui.recursive_pathc             G   s"   |j  }| jr|jd d| _d S )Nr#   F)r  r   rJ  )rP  Z	entry_objr{  Ztxtr   r   r   r  ,
  s    
zSELinuxGui.highlight_entry_textc             C   s~   |j  }|dkrd S |jdr*| jjd xNtjD ]D}|j|r2x4| jD ]*}|d jtj| rH| j| j	|d  qHW q2W d S )Nr#   z(/.*)?Tr   )
r  r7  r   re  r   ZDEFAULT_DIRSr9  r   r  r]   )rP  rb  textr=  r  r   r   r   r  2
  s    

z#SELinuxGui.autofill_add_files_entryc             G   s&   | j jd| _| jj }| jj }d S )Nr   )r   Zget_colZboolean_column_1Z	get_widthZget_cell_renderers)rP  r{  widthZrendererr   r   r   r3  >
  s    
zSELinuxGui.resize_columnsc             G   s   | j j  d S )N)r   r  )rP  r{  r   r   r   r&  C
  s    zSELinuxGui.browse_for_filesc             G   s   | j j  d S )N)r   r	  )rP  r{  r   r   r   r*  F
  s    zSELinuxGui.close_config_windowc             G   sl   | j | jj krd S | jtdtjjkr<| jj| j  d S | j	j
| j| j | j	jd | jj | _ d S )NzChanging the policy type will cause a relabel of the entire file system on the next boot. Relabeling takes a long time depending on the size of the file system.  Do you wish to continue?T)r  rP   r  rh  r   r   ri  NOre  r   r=  r  relabel_on_boot)rP  r{  r   r   r   r=  I
  s    z SELinuxGui.change_default_policyc             C   s4   | j s
d S | j| |j r0| jj|j j  d S )N)r   enabled_changedr  r   r>  rj  r  )rP  r  r   r   r   r>  U
  s
    
zSELinuxGui.change_default_modec             G   s0   | j jtjj | j jd | j j  d| _d S )NzImport Configurationrw  )r   
set_actionr   FileChooserActionZOPENr  r  r   )rP  r{  r   r   r   r9  \
  s    
zSELinuxGui.import_config_showc             G   s0   | j jtjj | j jd | j j  d| _d S )NzExport Configurationrx  )r   r  r   r  ZSAVEr  r  r   )rP  r{  r   r   r   r:  c
  s    
zSELinuxGui.export_config_showc             C   s:   | j   | jj }t|d}|j| |j  | j  d S )Nw)rl  r   r   r  r  r  rn  )rP  r  r  r  r   r   r   r{  i
  s    


zSELinuxGui.export_configc             C   sT   t |d}|j }|j  | j  y| jj| W n tk
rF   Y nX | j  d S )Nr  )r  r  r  rl  r   rB  r_  rn  )rP  r  r  r  r   r   r   rz  q
  s    
zSELinuxGui.import_configc             C   sV   |||f|kri ||||f< ||f||||f krR|||	|
d||||f ||f< d S )N)r  r  changedoldr   )rP  rV  rQ  r  r4  r  qr5  r  r  r  r   r   r   init_dictionary|
  s    zSELinuxGui.init_dictionaryc             C   s*   |j dd }|dkrdS |dkr&dS d S )N-r   0F1T)rm  )rP  r   r   r   r   translate_bool
  s
    zSELinuxGui.translate_boolc             G   sx   | j j }tjjd}|r"|r"d S | r2| r2d S y| jj| W n0 tjjk
rr } z| j	| W Y d d }~X nX d S )Nz/.autorelabel)
r   r  rc  rS  rd  r   r  r   r   r  )rP  r{  r  rd  rR  r   r   r   r?  
  s    
zSELinuxGui.relabel_on_rebootc             G   s
  |j   | jjd | jjd | j|krV| j| j | j| j	t
dkrV| j	jd | j|kr| jrt| j| j n| jr| j| j | jj s| jj r| jjd | jjd | jjd | jjd | jjd | jjd | jj td kr| jjtd  dS )NFTzMore...r   r   )r	  r   re  r   r   rN   r  r[   r  r]   r   r'   r   r   r\   r_   Zget_visiblera   r   r   r`   r   rb   r%   r  rv  rJ  )rP  r   r{  r   r   r   rC  
  s,    

zSELinuxGui.closewindowc             C   s   | j j j| j | j  d S )N)r   
get_window
set_cursorr   r  )rP  r   r   r   rl  
  s    zSELinuxGui.wait_mousec             C   s   | j j j| j | j  d S )N)r   r  r  r   r  )rP  r   r   r   rn  
  s    zSELinuxGui.ready_mouser#   c             C   sN   t jd dt jjt jj|}|j| |jt jj	 |j
  |j }|j  |S )Nr   )r   MessageDialogMessageTypeINFOButtonsTypeZYES_NOr  set_positionWindowPositionMOUSEshow_allrundestroy)rP  messagerg  dlgZrcr   r   r   rh  
  s    
zSELinuxGui.verifyc             C   sD   t jd dt jjt jj|}|jt jj |j	  |j
  |j  d S )Nr   )r   r  r  ZERRORr  ZCLOSEr  r  r  r  r  r  )rP  r  r  r   r   r   r  
  s    zSELinuxGui.errorc             C   s   |j  sd S |j }|dkrH| jtkrH| jtdtjjkrH| j	j
d |dkr|| jtkr|| jtdtjjkr|| j	j
d || _	d S )Nri  a  Changing to SELinux disabled requires a reboot.  It is not recommended.  If you later decide to turn SELinux back on, the system will be required to relabel.  If you just want to see if SELinux is causing a problem on your system, you can go to permissive mode which will only log errors and not enforce SELinux policy.  Permissive mode does not require a reboot.  Do you wish to continue?TzChanging to SELinux enabled will cause a relabel of the entire file system on the next boot. Relabeling takes a long time depending on the size of the file system.  Do you wish to continue?)r  rj  r  r   rh  r   r   ri  r~  r  re  )rP  Zradiort  r   r   r   r  
  s    zSELinuxGui.enabled_changedc             G   s   | j jd | jjd d S )Nr#   F)r   rJ  r   re  )rP  r{  r   r   r   r!  
  s    zSELinuxGui.clear_filtersc             G   sB   | j s
d S | j  | jj r*| jjd n| jjd | j  d S )Nzmodule -e unconfinedzmodule -d unconfined)r   rl  r   r  r   rB  rn  )rP  r{  r   r   r   r;  
  s    
zSELinuxGui.unconfined_togglec             G   sB   | j s
d S | j  | jj r*| jjd n| jjd | j  d S )Nzmodule -e permissivedomainszmodule -d permissivedomains)r   rl  r   r  r   rB  rn  )rP  r{  r   r   r   r<  
  s    
zSELinuxGui.permissive_togglec             G   s:   t | jdkr.| jtdtdtjjkr.dS | j  d S )Nr   a0  You are attempting to close the application without applying your changes.
    *    To apply changes you have made during this session, click No and click Update.
    *    To leave the application without applying your changes, click Yes.  All changes that you have made during this session will be lost.zLoss of data DialogT)r  r   rh  r   r   ri  r~  r   )rP  r  r{  r   r   r   r  
  s    zSELinuxGui.confirmation_closec             G   s   t jd d S )Nr   )sysexit)rP  r{  r   r   r   r   
  s    zSELinuxGui.quit)NF)T)r#   )__name__
__module____qualname__rW  r   r^  rE  rq  r   r  r   r  r1  r2  r0  r
  r  r  r  r   r   r   r  r  r  r  r  r  r  r  r  r  r/  r.  r  r4  rN  rD  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r  r  r  rB  r%  rt  r(  r5  r  r'  r7  r  r8  r;  r-  r2  r,  r(  r)  rr  r  r.  r/  r  r8  rG  rH  r  rI  rL  rA  r  r  r  r  r  r6  r   r_  r   r`  r   r-  r  rc  rd  rL  rH  r"  re  rK  r#  r$  r%  rx  r0  r,  r+  rk  rp  rq  rm  rl  r@  r  r   rb  r  r  r  r  r  r3  r&  r*  r=  r>  r9  r:  r{  rz  r  r  r?  rC  rl  rn  rh  r  r  r!  r;  r<  r  r   r   r   r   r   r"   s   s*      	@
		
B*
	})Y	5+

D	A	 
	

/			

r"   __main__)r	   )AZgiZrequire_versionZgi.repositoryr   r   r   Zsepolicy.sedbusr   r  r   r   r   r   r   Zsepolicy.networkZsepolicy.manpager   rc  r  ZunicodedataZPROGNAMEgettextkwargsversion_infoZinstallbuiltinsr   __dict__ImportErrorZ__builtin__r
   r]  r<  r  r   r  r  r   Zdistutils.sysconfigr   rs  rv  r  r  r  r  r  r  r  r  rs  ru  r  ry  r  r  r  r  r  r   rY  ra  r"   r  r  r   r   r   r   <module>   s   
	                     
