Server can now respond to get messages.

This commit is contained in:
WickedJack99
2023-12-28 21:50:21 +01:00
parent b0aa30101d
commit adcb90a85a

View File

@@ -15,6 +15,7 @@ receive_message_queue = queue.Queue()
############################################################################################################
#
def start_server(host_ip, port, logs_path):
global server_running
server_running = True
# Create an SSL context.
@@ -106,31 +107,49 @@ def get_syslog_path():
############################################################################################################
# Read data from the client and put it into message queue.
def receive_messages_and_put_into_message_queue(message_queue, ssl_socket):
global server_running
error_occured = False
while not error_occured and server_running:
try:
data = ssl_socket.recv(1024).decode('utf-8')
message_queue.put(data)
print(f"Received from client: {data} and put into message queue.")
if (data != ""):
message_queue.put(data)
print(f"Received from client: {data} and put into message queue.")
else:
error_occured = True
except:
error_occured = True
############################################################################################################
#
def process_received_messages_and_send_response(message_queue, ssl_socket, logs_path):
while server_running:
global server_running
error_occured = False
while not error_occured and server_running:
if not message_queue.empty():
message = message_queue.get()
print(f"Took {message} from message_queue.")
match message:
case["stopAgent"]:
case "":
print("case empty")
error_occured = True
case " ":
print("case empty")
error_occured = True
case "stopAgent\n":
print("case stopAgent")
server_running = False
case["getSysInf"]:
case "getSysInf\n":
print("case getSysInf")
send_system_information(ssl_socket)
case["getCon"]:
case "getCon\n":
print("case getCon")
send_connections_info(ssl_socket)
case["getLogs"]:
case "getLogs\n":
print("case getLogs")
send_logs(logs_path)
case["getNFTConf"]:
case "getNFTConf\n":
print("case getNFTConf")
send_nftables_configuration(ssl_socket)
case _:
print(f"Unknown message: {message}.")
@@ -167,14 +186,14 @@ def send_connections_info(ssl_socket):
def get_network_connections_as_string():
kinds = ['inet', 'inet4', 'inet6', 'tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6', 'unix', 'all']
network_connections_as_string = ""
network_connections = psutil.net_connections(kind=kinds[0])
network_connections = psutil.net_connections(kind=kinds[10])
for connection in network_connections:
network_connections_as_string += str(connection) + "\n"
return network_connections_as_string
#################################################
#
def send_logs(logs_path):
def send_logs(ssl_socket, logs_path):
print("TODO")
#################################################