Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/maint/bin
File: secgroup.py
#!/opt/imh-python/bin/python3
[0] Fix | Delete
"""Adds cPanel users to a common supplementary group"""
[1] Fix | Delete
import grp
[2] Fix | Delete
from subprocess import check_call, CalledProcessError
[3] Fix | Delete
import rads
[4] Fix | Delete
[5] Fix | Delete
COMMON_GROUP = 'cpanel-users'
[6] Fix | Delete
[7] Fix | Delete
[8] Fix | Delete
def main():
[9] Fix | Delete
# cron config appends stdout/err to /var/log/maint/secgroups.log
[10] Fix | Delete
logger = rads.setup_logging(
[11] Fix | Delete
path=None,
[12] Fix | Delete
print_out='stdout',
[13] Fix | Delete
name='secgroup',
[14] Fix | Delete
loglevel='INFO',
[15] Fix | Delete
fmt='%(asctime)s [%(levelname)s] %(message)s',
[16] Fix | Delete
)
[17] Fix | Delete
[18] Fix | Delete
cpanel_users = set(rads.all_cpusers())
[19] Fix | Delete
group_members = grp.getgrnam(COMMON_GROUP).gr_mem
[20] Fix | Delete
missing_users = cpanel_users.difference(group_members)
[21] Fix | Delete
[22] Fix | Delete
for user in missing_users:
[23] Fix | Delete
logger.info('%s not in %s', user, COMMON_GROUP)
[24] Fix | Delete
try:
[25] Fix | Delete
check_call(['usermod', '-G', COMMON_GROUP, user])
[26] Fix | Delete
except CalledProcessError:
[27] Fix | Delete
logger.critical('Failed to add %s to %s', user, COMMON_GROUP)
[28] Fix | Delete
else:
[29] Fix | Delete
logger.info('Added %s to %s', user, COMMON_GROUP)
[30] Fix | Delete
[31] Fix | Delete
[32] Fix | Delete
if __name__ == '__main__':
[33] Fix | Delete
main()
[34] Fix | Delete
[35] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function