#!/usr/bin/python import xmlrpclib import sys SATELLITE_URL = "https:///rpc/api" SATELLITE_LOGIN = "" SATELLITE_PASSWORD = "" try: server = xmlrpclib.Server(SATELLITE_URL, verbose=0) token = server.auth.login(SATELLITE_LOGIN, SATELLITE_PASSWORD) except: print "Not able to connect at %s. Exiting." %(SATELLITE_URL) sys.exit(1) ch = raw_input("Enter the configuration channel name: ") try: channelExists = server.configchannel.channelExists(token,ch) items = server.configchannel.listFiles(token,ch) except: print "Channel %s not found!" %(ch) sys.exit(1) cleanup = False print "-" * 20 print "\n%s item(s) provided by channel %s" %(len(items),ch) for f in items: rev_details = server.configchannel.getFileRevisions(token,ch,f['path']) total_rev = len(rev_details) for i in rev_details: if int(i['revision']) == total_rev: if i.has_key('selinux_ctx'): print "\tPath: %s \tSELinux Context: %s" %(i['path'],i['selinux_ctx']) cleanup = True else: print "\tPath: %s \t(no SELinux context)" %(i['path']) ## clean SELinux context for all items provided in channel if cleanup: clean_ctx = raw_input("\nWant to clean the SELinux context for all items listed above? [Y/n] ") print "\n" if clean_ctx == "Y": for f in items: rev_details = server.configchannel.getFileRevisions(token,ch,f['path']) total_rev = len(rev_details) for i in rev_details: if int(i['revision']) == total_rev and i.has_key('selinux_ctx'): if i['type'] == 'file': sb = server.configchannel.createOrUpdatePath(token,ch,i['path'],False, {'group': i['group'],'permissions': str(i['permissions']), 'selinux_ctx': '', 'owner': i['owner'],'macro-end-delimiter': i['macro-end-delimiter'], 'revision': '', 'macro-start-delimiter': i['macro-start-delimiter'], 'contents': i['contents']}) if i['type'] == 'directory': sb = server.configchannel.createOrUpdatePath(token,ch,i['path'],True, {'group': i['group'],'permissions': str(i['permissions']), 'selinux_ctx': '', 'owner': i['owner'], 'revision': ''}) if i['type'] == 'symlink': sb = server.configchannel.createOrUpdateSymlink(token,ch,i['path'], {'target_path': i['target_path'], 'selinux_ctx': '', 'revision': ''}) if sb: print "\tCleaning SELinux context for %s" %(sb['path']) else: print "\t\t\t" + ("*" * 50) print "\t\t\tItems provided by %s were not modified" %(ch) print "\t\t\tMake sure to use uppercase [Y] to confirm the operation" print "\t\t\t" + ("*" * 50) else: print "\nThe items provided by configuration channel %s does not have any SELinux context set" %(ch) server.auth.logout(token)