edge004-base0.2.1

Corrected the NetSock and made the install script compliant
This commit is contained in:
2024-11-22 20:03:56 +01:00
parent 7d42a35f7a
commit 349160e3cf
4 changed files with 32 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
""" """
Install script for the Python jailer. Install script for the Python jailer.
Version: 0.2.0-alpha2 Version: 0.3.0-main1
""" """
import os import os
import shutil import shutil
@@ -68,7 +68,7 @@ if setup_posix.lower() == "y":
with open("./proc/kcore", "a+") as f: with open("./proc/kcore", "a+") as f:
f.write("/sys/jail_mgr.py") f.write("/sys/jail_mgr.py")
f.close() f.close()
else: else: # POSIX and NO-POSIX have a firm split now.
print("Creating directories...") print("Creating directories...")
os.mkdir("./bin") os.mkdir("./bin")
os.mkdir("./sys") os.mkdir("./sys")
@@ -77,9 +77,25 @@ else:
os.mkdir(f"./home/{usrname}") os.mkdir(f"./home/{usrname}")
os.mkdir("./sys/krnl/") os.mkdir("./sys/krnl/")
print("Copying files...") print("Copying files...")
shutil.move("./main.py", "./sys/jail_mgr.py") try:
shutil.move("./sh.py", "./bin/shell.py") shutil.move("./nps/main.py", "./sys/jail_mgr.py")
shutil.move("./ledit.py", "./bin/ledit.py") shutil.move("./nps/sh.py", "./bin/shell.py")
shutil.move("./nps/ledit.py", "./bin/ledit.py")
except Exception as e:
print("Failure to install! Non-POSIX files are most likely not present! Aborting install...")
shutil.move("../main.py", "../runner.py")
shutil.move("./main.py", "../main.py")
shutil.move("./sh.py", "../sh.py")
shutil.move("./ledit.py", "../ledit.py")
os.rmdir("./bin")
os.rmdir("./sys/krnl/")
os.rmdir("./sys")
os.rmdir("./usr")
os.rmdir("./proc")
os.rmdir(f"./home/{usrname}")
os.chdir("../")
shutil.rmtree("./vfs/")
exit(-1)
print("Creating system configuration files...") print("Creating system configuration files...")
with open("./sys/usr.conf", "a+") as f: with open("./sys/usr.conf", "a+") as f:
f.write(usrname) f.write(usrname)

View File

@@ -1 +1 @@
0.1.1-main1 edge0004-base0.2.1

15
main.py
View File

@@ -1,6 +1,6 @@
""" """
This is the PyJail, a jailing tool for running Python apps in a sandboxed environment. This is the PyJail, a jailing tool for running Python apps in a sandboxed environment.
Version: edge0003-base0.2.1 Version: edge0004-base0.2.1
""" """
import os import os
import time import time
@@ -58,8 +58,10 @@ class PyJail:
msg = f"[{time.time}] [{caller}] [{log_level}] {message}" msg = f"[{time.time}] [{caller}] [{log_level}] {message}"
with open(self.fs("/proc/klog"), "a+") as f: with open(self.fs("/proc/klog"), "a+") as f:
f.write(msg) f.write(msg)
if emit is True: if emit is True and (log_level.upper() == "ERROR" or log_level.upper() == "CRITICAL"):
print(msg) print(msg)
elif emit is True:
return 0 return 0
def fs(self, check_path=None, resolve_symlinks=True): def fs(self, check_path=None, resolve_symlinks=True):
@@ -135,7 +137,7 @@ class PyJail:
""" """
Returns the kernel version Returns the kernel version
""" """
return "edge0003-base0.2.1" return "edge0004-base0.2.1"
def netsock(self, ip, port, mode, msg): def netsock(self, ip, port, mode, msg):
""" """
@@ -183,9 +185,10 @@ class PyJail:
with open(self.fs(f"/usr/netsock/cache/{pkg}.pmd"), "a+") as f: with open(self.fs(f"/usr/netsock/cache/{pkg}.pmd"), "a+") as f:
f.write(file_io) f.write(file_io)
f.close() f.close()
else:
with open(self.fs(f"/usr/netsock/cache/{pkg}.py"))
f.write(file_io)
f.close()
else: else:
raise NotImplementedError("TODO: UDP will be implemented later!") raise NotImplementedError("TODO: UDP will be implemented later!")

View File

@@ -1 +1 @@
0.1.0 edge