mirror of
https://github.com/FAUSheppy/atlantis-event-dispatcher
synced 2025-12-06 06:21:36 +01:00
Compare commits
3 Commits
f2137e7e4c
...
4e4f53b330
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e4f53b330 | |||
| 35f9fc2a99 | |||
| 53e6f32a18 |
@@ -27,7 +27,7 @@ def debug_send(uuid, data, fail_it=False):
|
|||||||
def email_send(dispatch_uuid, email_address, message, smtp_target,
|
def email_send(dispatch_uuid, email_address, message, smtp_target,
|
||||||
smtp_target_port, smtp_user, smtp_pass):
|
smtp_target_port, smtp_user, smtp_pass):
|
||||||
'''Send message via email'''
|
'''Send message via email'''
|
||||||
|
|
||||||
if not email_address:
|
if not email_address:
|
||||||
print("Missing E-Mail Address for STMP send", file=sys.stderr)
|
print("Missing E-Mail Address for STMP send", file=sys.stderr)
|
||||||
report_failed_dispatch(dispatch_uuid, "Missing email-field in dispatch infor")
|
report_failed_dispatch(dispatch_uuid, "Missing email-field in dispatch infor")
|
||||||
@@ -54,21 +54,32 @@ def ntfy_api_get_topic(ntfy_api_server, ntfy_api_token, username):
|
|||||||
print(r.text)
|
print(r.text)
|
||||||
return r.json().get("topic")
|
return r.json().get("topic")
|
||||||
|
|
||||||
def ntfy_send(dispatch_uuid, user_topic, title, message, ntfy_push_target, ntfy_user, ntfy_pass):
|
def ntfy_send(dispatch_uuid, user_topic, title, message, link,
|
||||||
|
ntfy_push_target, ntfy_user, ntfy_pass):
|
||||||
'''Send message via NTFY topic'''
|
'''Send message via NTFY topic'''
|
||||||
|
|
||||||
|
# check message for links #
|
||||||
|
if not link:
|
||||||
|
pattern = r"https:\/\/[^\s]+"
|
||||||
|
match = re.search(pattern, text)
|
||||||
|
if match:
|
||||||
|
link = match.group(0)
|
||||||
|
|
||||||
# limit message length and title #
|
# limit message length and title #
|
||||||
title = title or ""
|
title = title or ""
|
||||||
message = message or ""
|
message = message or ""
|
||||||
message = message[:1024]
|
message = message[:1024]
|
||||||
title = title[:512]
|
title = title[:512]
|
||||||
|
|
||||||
|
|
||||||
if not user_topic:
|
if not user_topic:
|
||||||
report_failed_dispatch(dispatch_uuid, "No user topic")
|
report_failed_dispatch(dispatch_uuid, "No user topic")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# build message #
|
# build message #
|
||||||
payload = {
|
payload = {
|
||||||
"topic" : user_topic,
|
"topic" : user_topic,
|
||||||
@@ -77,7 +88,7 @@ def ntfy_send(dispatch_uuid, user_topic, title, message, ntfy_push_target, ntfy_
|
|||||||
#"tags" : [],
|
#"tags" : [],
|
||||||
"priority" : 4,
|
"priority" : 4,
|
||||||
#"attach" : None,
|
#"attach" : None,
|
||||||
"click" : "https://vid.pr0gramm.com/2022/11/06/ed66c8c5a9cd1a3b.mp4",
|
"click" : link,
|
||||||
#"actions" : []
|
#"actions" : []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +151,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
parser.add_argument('--loop', default=True, action=argparse.BooleanOptionalAction)
|
parser.add_argument('--loop', default=True, action=argparse.BooleanOptionalAction)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
dispatch_server = args.dispatch_server or os.environ.get("DISPATCH_SERVER")
|
dispatch_server = args.dispatch_server or os.environ.get("DISPATCH_SERVER")
|
||||||
@@ -166,7 +177,7 @@ if __name__ == "__main__":
|
|||||||
while args.loop or first_run:
|
while args.loop or first_run:
|
||||||
|
|
||||||
# request dispatches #
|
# request dispatches #
|
||||||
response = requests.get(dispatch_server +
|
response = requests.get(dispatch_server +
|
||||||
"/get-dispatch?method=all&timeout=0&dispatch-access-token={}".format(DISPATCH_ACCESS_TOKEN))
|
"/get-dispatch?method=all&timeout=0&dispatch-access-token={}".format(DISPATCH_ACCESS_TOKEN))
|
||||||
|
|
||||||
# check status #
|
# check status #
|
||||||
@@ -190,6 +201,7 @@ if __name__ == "__main__":
|
|||||||
method = entry["method"]
|
method = entry["method"]
|
||||||
message = entry["message"]
|
message = entry["message"]
|
||||||
title = entry.get("title")
|
title = entry.get("title")
|
||||||
|
link = entry.get("link")
|
||||||
|
|
||||||
# method dependent fields #
|
# method dependent fields #
|
||||||
phone = entry.get("phone")
|
phone = entry.get("phone")
|
||||||
@@ -200,7 +212,7 @@ if __name__ == "__main__":
|
|||||||
pass
|
pass
|
||||||
elif method == "ntfy":
|
elif method == "ntfy":
|
||||||
user_topic = ntfy_api_get_topic(ntfy_api_server, ntfy_api_token, user)
|
user_topic = ntfy_api_get_topic(ntfy_api_server, ntfy_api_token, user)
|
||||||
ntfy_send(dispatch_uuid, user_topic, title, message,
|
ntfy_send(dispatch_uuid, user_topic, title, message, link,
|
||||||
ntfy_push_target, ntfy_user, ntfy_pass)
|
ntfy_push_target, ntfy_user, ntfy_pass)
|
||||||
elif method == "email":
|
elif method == "email":
|
||||||
email_send(dispatch_uuid, email_address, message, smtp_target,
|
email_send(dispatch_uuid, email_address, message, smtp_target,
|
||||||
@@ -216,6 +228,6 @@ if __name__ == "__main__":
|
|||||||
# wait a moment #
|
# wait a moment #
|
||||||
if args.loop:
|
if args.loop:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
# handle non-loop runs #
|
# handle non-loop runs #
|
||||||
first_run = False
|
first_run = False
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ class DispatchObject(db.Model):
|
|||||||
title = Column(String)
|
title = Column(String)
|
||||||
message = Column(String, primary_key=True)
|
message = Column(String, primary_key=True)
|
||||||
method = Column(String)
|
method = Column(String)
|
||||||
|
link = Column(String)
|
||||||
|
|
||||||
dispatch_secret = Column(String)
|
dispatch_secret = Column(String)
|
||||||
dispatch_error = Column(String)
|
dispatch_error = Column(String)
|
||||||
@@ -98,6 +99,7 @@ class DispatchObject(db.Model):
|
|||||||
"email" : self.email,
|
"email" : self.email,
|
||||||
"title" : _apply_substitution(self.title),
|
"title" : _apply_substitution(self.title),
|
||||||
"message" : _apply_substitution(self.message),
|
"message" : _apply_substitution(self.message),
|
||||||
|
"link" : self.link,
|
||||||
"uuid" : self.dispatch_secret,
|
"uuid" : self.dispatch_secret,
|
||||||
"method" : self.method,
|
"method" : self.method,
|
||||||
"error" : self.dispatch_error,
|
"error" : self.dispatch_error,
|
||||||
@@ -378,9 +380,10 @@ def smart_send_to_clients(path=None):
|
|||||||
instructions = flask.request.json
|
instructions = flask.request.json
|
||||||
users = instructions.get("users")
|
users = instructions.get("users")
|
||||||
groups = instructions.get("groups")
|
groups = instructions.get("groups")
|
||||||
message = instructions.get("msg")
|
message = instructions.get("msg") or instructions.get("message")
|
||||||
title = instructions.get("title")
|
title = instructions.get("title")
|
||||||
method = instructions.get("method")
|
method = instructions.get("method")
|
||||||
|
link = instructions.get("link")
|
||||||
|
|
||||||
if app.config["DOWNTIME"] > datetime.datetime.now():
|
if app.config["DOWNTIME"] > datetime.datetime.now():
|
||||||
print("Ignoring because of Downtime:", title, message, users, file=sys.stderr)
|
print("Ignoring because of Downtime:", title, message, users, file=sys.stderr)
|
||||||
@@ -389,6 +392,9 @@ def smart_send_to_clients(path=None):
|
|||||||
|
|
||||||
# authenticated by access token or webhook path #
|
# authenticated by access token or webhook path #
|
||||||
dispatch_acces_token = flask.request.args.get("dispatch-access-token") or ""
|
dispatch_acces_token = flask.request.args.get("dispatch-access-token") or ""
|
||||||
|
if not dispatch_acces_token:
|
||||||
|
dispatch_acces_token = flask.request.headers.get("Dispatcher-Token") or ""
|
||||||
|
|
||||||
print(path)
|
print(path)
|
||||||
if path:
|
if path:
|
||||||
webhook_path = db.session.query(WebHookPaths).filter(WebHookPaths.path==path).first()
|
webhook_path = db.session.query(WebHookPaths).filter(WebHookPaths.path==path).first()
|
||||||
@@ -418,7 +424,7 @@ def smart_send_to_clients(path=None):
|
|||||||
else:
|
else:
|
||||||
persons = ldaptools.select_targets(users, groups, app.config["LDAP_ARGS"])
|
persons = ldaptools.select_targets(users, groups, app.config["LDAP_ARGS"])
|
||||||
|
|
||||||
dispatch_secrets = save_in_dispatch_queue(persons, title, message, method)
|
dispatch_secrets = save_in_dispatch_queue(persons, title, message, method, link)
|
||||||
return flask.jsonify(dispatch_secrets)
|
return flask.jsonify(dispatch_secrets)
|
||||||
|
|
||||||
|
|
||||||
@@ -442,6 +448,7 @@ def save_in_dispatch_queue(persons, title, message, method):
|
|||||||
timestamp=datetime.datetime.now().timestamp(),
|
timestamp=datetime.datetime.now().timestamp(),
|
||||||
dispatch_secret=dispatch_secret,
|
dispatch_secret=dispatch_secret,
|
||||||
title=title,
|
title=title,
|
||||||
|
link=link,
|
||||||
message=message)
|
message=message)
|
||||||
|
|
||||||
db.session.merge(obj)
|
db.session.merge(obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user