From 306472eb3d7e8b51b0084c3c0bfce378607f1562 Mon Sep 17 00:00:00 2001 From: bashrc Date: Sun, 26 Apr 2026 17:14:10 +0100 Subject: [PATCH] Revert "Replace save and append with functions" This reverts commit fc811a36520a0f2d8b66b769da864e7fed11ef40. --- auth.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/auth.py b/auth.py index c2a62fd07..3110ab868 100644 --- a/auth.py +++ b/auth.py @@ -20,8 +20,6 @@ from utils import text_in_file from utils import remove_eol from utils import valid_nickname from timeFunctions import date_utcnow -from data import append_string -from data import save_string def _hash_password(password: str) -> str: @@ -215,12 +213,18 @@ def store_basic_credentials(base_dir: str, return False else: # append to password file - if not append_string(store_str + '\n', password_file, - 'EX: unable to append password'): + try: + with open(password_file, 'a+', encoding='utf-8') as fp_pass: + fp_pass.write(store_str + '\n') + except OSError: + print('EX: unable to append password') return False else: - if not save_string(store_str + '\n', password_file, - 'EX: unable to create password file'): + try: + with open(password_file, 'w+', encoding='utf-8') as fp_pass: + fp_pass.write(store_str + '\n') + except OSError: + print('EX: unable to create password file') return False return True @@ -301,15 +305,14 @@ def record_login_failure(base_dir: str, ip_address: str, write_type: str = 'w+' curr_time = date_utcnow() curr_time_str = curr_time.strftime("%Y-%m-%d %H:%M:%SZ") - log_str = \ - curr_time_str + ' ' + 'ip-127-0-0-1 sshd[20710]: ' + \ - 'Disconnecting invalid user epicyon ' + ip_address + ' port 443: ' + \ - 'Too many authentication failures [preauth]\n' - # here we use a similar format to an ssh log, so that - # systems such as fail2ban can parse it - if write_type == 'a+': - append_string(log_str, failure_log, - 'EX: record_login_failure failed ' + str(failure_log)) - else: - save_string(log_str, failure_log, - 'EX: record_login_failure failed ' + str(failure_log)) + try: + with open(failure_log, write_type, encoding='utf-8') as fp_fail: + # here we use a similar format to an ssh log, so that + # systems such as fail2ban can parse it + fp_fail.write(curr_time_str + ' ' + + 'ip-127-0-0-1 sshd[20710]: ' + + 'Disconnecting invalid user epicyon ' + + ip_address + ' port 443: ' + + 'Too many authentication failures [preauth]\n') + except OSError: + print('EX: record_login_failure failed ' + str(failure_log))