Updated select module and refined message retrieval process in RMASS definitions

This commit is contained in:
Lyncoln
2026-10-16 17:59:28 -04:00
parent b5e6d4eaea
commit 9f282a4bd8
35 changed files with 296 additions and 75 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6 -1
View File
@@ -1,10 +1,15 @@
import json
def buildOutput(response, action, outputs):
#if select_data != "not applied":
#response_data = select_data
#else:
#response_data = response.json()
if hasattr(action, "outputs"):
response_data = response.json()
try:
response_data = response.json()
except AttributeError:
response_data = json.loads(response)
response_objects = [response_data]
while response_objects:
+4 -2
View File
@@ -5,12 +5,14 @@ def recursiveSet(definition, outputs):
for item in outputs[definition.recursiveset["source"]]:
outputs[definition.recursiveset["outputlabel"]] = item
#outputs["recursive"] = item
print("DEBUGGING recursiveset item")
print(outputs[definition.recursiveset["outputlabel"]])
for job in recursiveset:
outputs, response = buildAction(job, outputs)
print(outputs["profile"])
print(outputs["messages"])
#print(outputs["profile"])
#print(outputs["messages"])
return outputs
from core.execution.action.action import buildAction
+40
View File
@@ -1,4 +1,5 @@
import json
import sqlite3
def buildSave(action, outputs):
if hasattr(action, "savedata"):
@@ -11,6 +12,27 @@ def buildSave(action, outputs):
json.dump(save_data, save_file)
print(f"Data saved by {action.name} to {action.savepath}")
database = sqlite3.connect("savedata/rmmanager.db")
for key, value in save_data.items():
database.execute("""
CREATE TABLE IF NOT EXISTS output_test (
dictionary TEXT NOT NULL UNIQUE,
value TEXT NOT NULL UNIQUE
)
""")
database.execute("""
INSERT INTO output_test(dictionary, value)
VALUES (?, ?)
ON CONFLICT (dictionary)
DO UPDATE SET value = excluded.value
""", (key, value)
)
database.commit()
database.close()
return outputs
def loadSave(action, outputs):
@@ -23,3 +45,21 @@ def loadSave(action, outputs):
print(f"Data loaded by {action.name} from {action.savepath}")
return outputs
def buildSave2(action, outputs):
database.execute("""
CREATE TABLE IF NOT EXISTS message_mapping (
rmass_message_id INTEGER PRIMARY KEY,
matrix_event_id TEXT NOT NULL UNIQUE
)
""")
database = sqlite3.connect("rmmanager.db")
database.execute(
"INSERT INTO message_mapping VALUES (?, ?)",
(action.savedata[savename], outputs["event_id"])
)
database.commit()
database.close()
+7 -3
View File
@@ -24,11 +24,15 @@ def buildSelect(action, outputs):
if include_match and exclude_match:
select_data.append(item)
outputs[action.select["source"]] = select_data
#print(select_data)
#outputs[{action.select["source"]}] = select_data
outputs[action.alias] = select_data
print("DEBUGGING", action.alias)
print(outputs[action.alias])
return select_data, action, outputs
except: (KeyError, TypeError)
except (KeyError, TypeError):
print("Error in selection")
#select_data = ["no selection"]
return select_data, action, outputs
Binary file not shown.
+103 -52
View File
@@ -1,72 +1,123 @@
import socket
import json
import os
import logging
import json
from http.server import HTTPServer, BaseHTTPRequestHandler
from .dispatcher import dispatchRequest
from .createresponse import buildResponse
from core.runtime.outputs import buildOutput
from plugins.rmass.inbound import receive
port = int(os.environ.get("SERVER_PORT", 19001))
from http.server import HTTPServer, BaseHTTPRequestHandler
class RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
lifecycles = {}
print("POST request received")
self.send_response(200)
max_request_size = 1024
content_length = self.headers.get("Content-Length")
# Check whether Content-Length exists
if content_length is None:
response = {
"status": "error",
"message": "Content length required"
}
status = 411
else:
# Attempt to convert the header into an integer
try:
length = int(content_length)
except ValueError:
length = None
# Validate the converted length
if length is None:
response = {
"status": "error",
"message": "Invalid Content-Length"
}
status = 400
elif length < 0:
response = {
"status": "error",
"message": "Bad Request"
}
status = 400
elif length > max_request_size:
response = {
"status": "error",
"message": "Content exceeds maximum request size"
}
status = 413
else:
# Content-Length is valid, so read the body
data = self.rfile.read(length)
try:
request = json.loads(data)
except json.JSONDecodeError:
response = {
"status": "error",
"message": "Invalid JSON received"
}
status = 400
else:
# Only valid JSON reaches the dispatcher
thread, lifecycles, module, mode = dispatchRequest(
request, lifecycles
)
response = buildResponse(module, thread, mode)
status = 200
# Serialize the response
responsebytes = json.dumps(response).encode("utf-8")
# Send one HTTP response
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(responsebytes)))
self.end_headers()
self.wfile.write(b'{"status": "ok"}')
self.wfile.write(responsebytes)
def do_PUT(self):
print("PUT request received")
if self.path.startswith("/_matrix/app/v1/transactions/"):
print("Matrix transaction received")
outputs = {}
content_length = int(self.headers["Content-Length"])
data = self.rfile.read(content_length)
request = json.loads(data)
requestjson = json.dumps(request, indent=4)
print (request)
print(requestjson)
outputs = buildOutput(data, receive, outputs)
print (outputs)
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", "2")
self.end_headers()
self.wfile.write(b"{}")
else:
self.send_error(404)
def startServer():
server = HTTPServer(("127.0.0.1", port), RequestHandler)
server = HTTPServer(("0.0.0.0", port), RequestHandler)
print(f"Server listening on port {port}")
server.serve_forever()
def startServer2():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("0.0.0.0", port))
lifecycles = {}
server.listen()
print(f"Server listening on port {port}")
while True:
connection, address = server.accept()
print("Accepting connections")
connection.settimeout(30)
try:
while True:
data = connection.recv(4096)
if not data:
print("Client Disconnected")
break
request = json.loads(data)
thread, lifecycles, module, mode = dispatchRequest(request, lifecycles)
response = buildResponse(module, thread, mode)
connection.sendall(
json.dumps(response).encode("utf-8"),
)
except json.decoder.JSONDecodeError as error:
print("Invalid JSON received", error)
print("Closing client connection")
except socket.timeout:
print("Client connection timed out")
finally:
connection.close()
# server.close()
server.serve_forever()