2022-05-24 04:34:38 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-10-26 08:28:31 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022 Citadel and contributors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-05-24 04:34:38 +00:00
|
|
|
import os
|
2023-04-16 19:12:12 +00:00
|
|
|
import socket
|
2022-05-24 04:34:38 +00:00
|
|
|
|
|
|
|
rootDir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
os.chdir(rootDir)
|
|
|
|
|
2023-03-26 15:19:59 +00:00
|
|
|
if os.path.exists("events/karen.socket"):
|
|
|
|
os.remove("events/karen.socket")
|
2022-05-24 04:34:38 +00:00
|
|
|
|
|
|
|
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
2023-03-26 15:19:59 +00:00
|
|
|
server.bind("events/karen.socket")
|
2022-05-24 04:34:38 +00:00
|
|
|
|
|
|
|
while True:
|
|
|
|
server.listen(1)
|
|
|
|
conn, addr = server.accept()
|
|
|
|
datagram = conn.recv(1024)
|
|
|
|
if datagram:
|
|
|
|
instructions = datagram.decode("utf-8").strip().split()
|
|
|
|
cmd = instructions[0]
|
2023-03-26 15:19:59 +00:00
|
|
|
if cmd == "trigger":
|
2022-05-24 04:34:38 +00:00
|
|
|
trigger = instructions[1]
|
|
|
|
instructions.pop(0)
|
|
|
|
instructions.pop(0)
|
2023-04-16 19:12:12 +00:00
|
|
|
os.system("scripts/triggers/{} {}".format(trigger, " ".join(instructions)))
|
2023-03-26 15:19:59 +00:00
|
|
|
elif cmd == "exec":
|
|
|
|
instructions.pop(0)
|
|
|
|
os.system(" ".join(instructions))
|
2022-05-24 04:34:38 +00:00
|
|
|
conn.close()
|