def add_all(users, options, dumps = None): if dumps: assert len(dumps) == len(users) else: dumps = [None] * len(users) if options.verbose: print("Creating all kerberos and ldap accounts") _add_all_kerberos(users, dumps, options) _add_all_ldap(users, dumps, options.ocf_ldap) for user, dump in zip(users, dumps): if options.verbose: print("Creating new account, {0}, for {1}" .format(user["account_name"], user["owner"])) msg = "`{}` created ({})".format(user["account_name"], user["owner"]) irc_alert(msg) _add_home_dir(user, dump = dump) _add_web_dir(user, dump = dump) _add_forward(user, dump = dump) log_creation(user, options)
def write_and_alert(path, line, all=False): """Append to the given file, alerting to IRC. Only appends/alerts if the line has not already been sent.""" # is it already in the file? if os.path.isfile(path): with open(path) as f: if line in (l.strip() for l in f.readlines()): return with open(path, "a") as f: f.write(line + "\n") irc_alert(line, all=all)
def _staff_approval(user, error_str, accepted, needs_approval, rejected, options): if not options.interactive: needs_approval.append((user, error_str)) return False prompt = "{0}\n{1} ({2})\n" prompt += "Approve this account? [yes/no/ignore] " prompt = prompt.format(error_str, user["account_name"], user["owner"]) ret = raw_input(prompt).strip().lower() if ret in ["y", "yes"]: accepted.append(user) return True elif ret in ["n", "no"]: irc_alert("`{}` ({}) rejected by `{}` ({})".format( user["account_name"], user["owner"], os.environ.get('SUDO_USER', 'root'), error_str)) rejected.append((user, error_str)) return False else: needs_approval.append((user, error_str)) return False