Python CSC Electronic Office
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

import os, syslog
from subprocess import Popen, PIPE, STDOUT
from ceo import conf
from ceo.ops import get_ceo_user, check_group
CONFIG_FILE = '/etc/csc/'
cfg = {}
def configure():
string_fields = ['members_list', 'list_domain']
# read configuration file
cfg_tmp =
# verify configuration
conf.check_string_fields(CONFIG_FILE, string_fields, cfg_tmp)
# update the current configuration with the loaded values
def main():
remote_user = get_ceo_user()
user_to_add = raw_input()
if cfg['members_list'] == 'none':
print 'Disabled: %s' % user_to_add
if remote_user == user_to_add or check_group(remote_user, 'office') or check_group(remote_user, 'syscom'):
mailman = Popen(["/opt/mailman3/bin/mailman", "addmembers", "-", "%s@%s" % (cfg['members_list'], cfg['list_domain'])],
stdin=PIPE, stdout=PIPE, stderr=STDOUT)
out, err = mailman.communicate("%s@%s\n" % (user_to_add, cfg['list_domain']))
syslog.syslog(syslog.LOG_INFO, out)
print out
message = "Access denied: user '%s' cannot subscribe users to %s" % (remote_user, cfg['members_list'])
syslog.syslog(syslog.LOG_NOTICE, message)
print message
if __name__ == '__main__':
syslog.openlog('op-mailman', syslog.LOG_PID, syslog.LOG_DAEMON)