0.3.0 base, now with autoconvert
This commit is contained in:
25
main.py
25
main.py
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
This is the PyJail, a jailing tool for running Python apps in a sandboxed environment.
|
||||
Version: edge0005-base0.2.1
|
||||
Version: edge0007-base0.2.1
|
||||
"""
|
||||
|
||||
import os
|
||||
@@ -57,14 +57,18 @@ class PyJail:
|
||||
emit: If the message needs to be passed to apps.
|
||||
log_level: The loglevel, either DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||
"""
|
||||
emit_full = False
|
||||
if self._debug is True:
|
||||
emit = True
|
||||
emit_full = True
|
||||
accepted_log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
||||
if log_level.upper() not in accepted_log_levels:
|
||||
self.msg(
|
||||
"jailmgr.msg()", f"Not accepted loglevel!! {log_level}", False, "ERROR"
|
||||
)
|
||||
return 1
|
||||
if log_level == "DEBUG" and self._debug is False:
|
||||
emit = False
|
||||
emit_full = False
|
||||
msg = f"[{time.time}] [{caller}] [{log_level}] {message}"
|
||||
with open(self.fs("/proc/klog"), "a+") as f:
|
||||
f.write(msg)
|
||||
@@ -72,6 +76,8 @@ class PyJail:
|
||||
print(msg)
|
||||
elif emit is True:
|
||||
print(message)
|
||||
elif emit_full is True:
|
||||
print(msg)
|
||||
return 0
|
||||
|
||||
def fs(self, check_path=None, resolve_symlinks=True):
|
||||
@@ -170,7 +176,7 @@ class PyJail:
|
||||
"""
|
||||
Returns the kernel version
|
||||
"""
|
||||
return "edge0006-base0.2.1"
|
||||
return "edge0007-base0.2.1"
|
||||
|
||||
def netsock(self, ip, port, mode, msg):
|
||||
"""
|
||||
@@ -233,6 +239,17 @@ class PyJail:
|
||||
f.close()
|
||||
|
||||
else:
|
||||
raise NotImplementedError("TODO: UDP will be implemented later!")
|
||||
# Create a UDP socket
|
||||
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
# Send the message to the server
|
||||
client_socket.sendto(msg.encode(), (ip, port))
|
||||
|
||||
# Receive the response from the server
|
||||
response, _ = client_socket.recvfrom(1024)
|
||||
self.msg(f"{self}", f"Received from server: {response.decode()}")
|
||||
|
||||
# Close the socket
|
||||
client_socket.close()
|
||||
|
||||
# raise NotImplementedError("TODO: Netsock will be implemented once 0.3.0 comes around!")
|
||||
|
Reference in New Issue
Block a user