def profiler_produce_report(profiler: Profiler, session: str) -> None: "persist profiler session report" report_dir = profiler_report_dir() report_file = profiler_report_file(session) fs_mkdir(report_dir) with open(report_file, "w") as report_text: report_text.write(profiler.output_text())
def arkon_tinc(): logger.info("setup tinc") conf = "/etc/tinc" tinc = f"{this_dir}/etc/tinc" fs_mkdir(conf) fs_copy(tinc, conf) fs_chmod(conf, dir_off=0o007, file_off=0o007) fs_chown(conf, 'root', 'root')
def arkon_systemd(): # TODO if not convert_text2bool(os.environ.get('ARKON_SYTEMD', 'no')): return logger.info("setup systemd") conf = "/etc/systemd" systemd = f"{this_dir}/etc/systemd" fs_mkdir(conf) fs_copy(systemd, conf) fs_chmod(conf, mode=0o555, dir_on=0o6000, file_off=0o111) fs_chown(conf, 'root', 'root')
def syncer_make_pipe( pipe_path: str, own_uid="service", own_gid="dovecot", ) -> None: "produce fifo pipe for the syncer plugin" pipe_dir = os.path.dirname(pipe_path) fs_mkdir(pipe_dir) fs_rmany(pipe_path) os.mkfifo(pipe_path) fs_chmod(pipe_dir, mode=0o660, dir_on=0o2770) fs_chown(pipe_dir, own_uid, own_gid)
def akron_postfix(): logger.info("setup postfix") # conf = "/etc/postfix" fs_mkdir(conf) postfix_prepare(conf) fs_chmod(conf, mode=0o640, dir_on=0o6750) fs_chown(conf, 'root', 'postfix') # snap = f"{conf}/conf.snap" # configuration snapshot fs_mkdir(snap) os.system(f'postconf -f > "{snap}/postconf-main-settings.conf"') os.system(f'postconf -fn > "{snap}/postconf-main-override.conf"') os.system(f'postconf -fM > "{snap}/postconf-master.conf"') fs_chmod(snap, mode=0o640, dir_on=0o6750) fs_chown(snap, 'root', 'root')
def test_notify(): print() fs_mkdir('/tmp/notify') notify = inotify.adapters.InotifyTree('/tmp/notify') for index in range(3): with open(f'/tmp/notify/test-file-{index}', 'w'): pass event_list = notify.event_gen(yield_nones=False, timeout_s=1) event_list = list(event_list) for event in event_list: print(event) time.sleep(1)
def keeper_repair_maildir(user_name: str, maildir_name: str) -> None: "ensure proper mailbox layout for maildir" "https://en.wikipedia.org/wiki/Maildir" mail_location = config_mail_location(user_name) if not os.path.isdir(mail_location): logger.warning(f"no mail_location: {mail_location}") return mbox_list_file = f"{mail_location}/keeper-mbox-list.txt" sieve_persist_mbox_list(user_name, mbox_list_file) with open(mbox_list_file, "r") as entry_list: for entry in entry_list: mbox_name = fs_strip_eol(entry) # relative path mbox_path = f"{mail_location}/{mbox_name}" # absolute path maildir_path = f"{mbox_path}/{maildir_name}" # mail storage dir folder_list = [ # layout folders f"{maildir_path}/cur", f"{maildir_path}/new", f"{maildir_path}/tmp", ] for folder in folder_list: fs_mkdir(folder)
def arkon_dovecot(): logger.info("setup dovecot") # conf = "/etc/dovecot" fs_mkdir(conf) fs_chmod(conf, mode=0o640, dir_on=0o6750) fs_chown(conf, 'root', 'dovecot') # pipe = "/run/dovecot/syncer" fs_mkdir(pipe) fs_chmod(pipe, mode=0o660) fs_chown(pipe, 'service', 'dovecot') # data = "/home/data" fs_mkdir(data) fs_chmod(data, mode=0o660, dir_on=0o6750) fs_chown(data, 'service', 'service') # snap = f"{conf}/conf.snap" # configuration snapshot fs_mkdir(snap) os.system(f'doveconf -a > "{snap}/dovecot-settings.conf"') os.system(f'doveconf -n > "{snap}/dovecot-override.conf"') fs_chmod(snap, mode=0o640, dir_on=0o6750) fs_chown(snap, 'root', 'root')
def arkon_opendkim(): logger.info("setup opendkim") conf = "/etc/opendkim" fs_mkdir(conf) fs_chmod(conf, mode=0o640, dir_on=0o6750) fs_chown(conf, 'root', 'opendkim')
def arkon_getmail(): logger.info("setup getmail") conf = "/etc/getmail" fs_mkdir(conf) fs_chmod(conf, mode=0o640, dir_on=0o6750) fs_chown(conf, 'service', 'service')
def arkon_tls(): logger.info("setup tls") conf = "/etc/tls" fs_mkdir(conf) fs_chmod(conf, mode=0o640, dir_on=0o550) fs_chown(conf, 'root', 'root')
def sieve_build_user(user_name: str) -> None: "build sieve filters for single user" logger.debug(f"sieve build: {user_name}") sieve_dir = config_sieve_path(user_name) build_dir = f"{sieve_dir}/sys" # ensure build folder fs_rmany(build_dir) fs_mkdir(build_dir) # persist user mailbox list mailbox_list = f"{build_dir}/a_mailbox_list.txt" sieve_persist_mbox_list(user_name, mailbox_list) # collect base mailbox list include_list = f"{build_dir}/a_include_list.txt" # sieve root script arkon = sieve_arkon() arkon_name = sieve_system_name(arkon) arkon_file = sieve_system_file(build_dir, arkon) # create filter tree with open(arkon_file, "w") as arkon_text, open(include_list, "w") as include_text: arkon_text.write(f'# {arkon_name}\n') arkon_text.write(f'require "include";\n') # create base filters with open(mailbox_list, "r") as entry_list: for entry in entry_list: mbox_path = fs_strip_eol(entry) match_root = sieve_regex_base.match(mbox_path) if match_root: base_mbox = match_root.group(1) base_name = sieve_system_name(base_mbox) base_file = sieve_system_file(build_dir, base_mbox) # arkon uses base script arkon_text.write(f'include :personal "{base_name}";\n') # setup initial base script with open(base_file, "w") as script: # create script.write(f'# {base_name}\n') script.write(f'require "fileinto";\n') # remember base filters include_text.write(f'{base_mbox}\n') # populate base filters with open(mailbox_list, "r") as entry_list: for entry in entry_list: mbox_path = fs_strip_eol(entry) match_define = sieve_regex_define.match(mbox_path) if match_define: base_mbox = match_define.group(1) base_name = sieve_system_name(base_mbox) base_file = sieve_system_file(build_dir, base_mbox) define_subj = match_define.group(2) define_addr = match_define.group(3) if define_subj: define_subj = define_subj[1:-1] # remove [] # provide filter expression sieve_code = sieve_code_entry(define_subj, define_addr, mbox_path) with open(base_file, "a") as script: # append script.write(f"{sieve_code}\n") # activate generated filters with open(include_list, "r") as entry_list: for entry in entry_list: base_mbox = fs_strip_eol(entry) base_name = sieve_system_name(base_mbox) base_file = sieve_system_file(build_dir, base_mbox) sieve_persist_filter(user_name, base_name, base_file) sieve_persist_filter(user_name, arkon_name, arkon_file)