Created
October 12, 2015 04:56
-
-
Save gnilchee/8f8a89b032b293ff8327 to your computer and use it in GitHub Desktop.
SELinux config file update with Python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import massedit, argparse | |
def update_to_disabled(): | |
filename = ['config'] | |
massedit.edit_files(filename, ["re.sub(r'^SELINUX=.*', 'SELINUX=disabled', line)"], dry_run=False) | |
def update_to_permissive(): | |
filename = ['config'] | |
massedit.edit_files(filename, ["re.sub(r'^SELINUX=.*', 'SELINUX=permissive', line)"], dry_run=False) | |
def update_to_enforcing(): | |
filename = ['config'] | |
massedit.edit_files(filename, ["re.sub(r'^SELINUX=.*', 'SELINUX=enforcing', line)"], dry_run=False) | |
def print_config(): | |
se_config = open("config", "r") | |
read_config = se_config.read() | |
print(read_config) | |
se_config.close() | |
parser = argparse.ArgumentParser(description='SELinux Update Config Utility') | |
parser.add_argument('--disabled', action='store_true', help='update config to disabled.') | |
parser.add_argument('--permissive', action='store_true', help='update config to permissive.') | |
parser.add_argument('--enforcing', action='store_true', help='update config to enforcing.') | |
parser.add_argument('--show', action='store_true', help='print selinux config file.') | |
args = parser.parse_args() | |
if args.disabled: | |
update_to_disabled() | |
elif args.permissive: | |
update_to_permissive() | |
elif args.enforcing: | |
update_to_enforcing() | |
elif args.show: | |
print_config() | |
else: | |
parser.print_help() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment