From 294847d90a45fdc6efddd37816f20a33f9858fa6 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sat, 6 Jan 2024 14:37:28 +0100 Subject: [PATCH] wip: --- .gitignore | 2 ++ interface.py | 1 + signal-query-dispatch.py | 34 ++++++++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 3717fe5..dd955a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.swp +*.sqlite +sqlite.db instance/ __pycache__/ signal_targets.txt diff --git a/interface.py b/interface.py index 1a8367f..2ccd69d 100755 --- a/interface.py +++ b/interface.py @@ -36,6 +36,7 @@ class DispatchObject(db.Model): message = Column(String, primary_key=True) method = Column(String) dispatch_secret = Column(String) + dispatch_error = Column(String) @app.route('/get-dispatch-status') def get_dispatch_status(): diff --git a/signal-query-dispatch.py b/signal-query-dispatch.py index 9a1e20c..514ad32 100755 --- a/signal-query-dispatch.py +++ b/signal-query-dispatch.py @@ -14,15 +14,23 @@ def signal_send(phone, message): '''Send message via signal''' cmd = [signal_cli_bin, "send", "-m", "'{}'".format(message.replace("'","")), phone] p = subprocess.run(cmd) + # TODO check return code # + + +def report_dispatch_error(target, uid, error): + '''Report an error for a give dispatch''' + + pass # TODO def confirm_dispatch(target, uid): - '''Confirm to server that message has been dispatched and can be removed''' + response = requests.post(target + "/confirm-dispatch", json=[{ "uid" : uid }], auth=(args.user, args.password)) if response.status_code not in [200, 204]: - print("Failed to confirm disptach with server for {} ({})".format(uid, response.text), file=sys.stderr) + print("Failed to confirm disptach with server for {} ({})".format( + uid, response.text), file=sys.stderr) if __name__ == "__main__": @@ -43,6 +51,7 @@ if __name__ == "__main__": if args.signal_cli_bin: signal_cli_bin = args.signal_cli_bin + # request dispatches # response = requests.get(args.target + "/get-dispatch?method={}".format(args.method), auth=(args.user, args.password)) @@ -50,9 +59,16 @@ if __name__ == "__main__": if response.status_code == HTTP_NOT_FOUND: sys.exit(0) + # fallback check for status # response.raise_for_status() + # track dispatches that were confirmed to avoid duplicate confirmation # dispatch_confirmed = [] + + # track failed dispatches # + errors = dict() + + # iterate over dispatch requests # for entry in response.json(): user = entry["person"] @@ -62,16 +78,22 @@ if __name__ == "__main__": # send message # if entry["method"] == "signal": - signal_send(phone, message) + uid, error = signal_send(phone, message) else: - print("Unsupported dispatch method {}".format(entry["method"]), sys=sys.stderr) + print("Unsupported dispatch method {}".format(entry["method"]), + sys=sys.stderr) # confirm dispatch if not args.no_confirm: for uid in uid_list: if uid not in dispatch_confirmed: - confirm_dispatch(args.target, uid) - dispatch_confirmed.append(uid) + + # confirm or report fail # + if errors[uid]: + report_dispatch_error(args.target, uid, errors[uid]) + else: + confirm_dispatch(args.target, uid) + dispatch_confirmed.append(uid) else: continue