Merge pull request #134 from PiBrewing/python-systemd_test

Fix for issue #132 (CVE-2024-3955)
This commit is contained in:
Alexander Vollkopf 2024-05-02 13:01:43 +02:00 committed by GitHub
commit fe15b4c0e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 9 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.4.1.a3"
__version__ = "4.4.1.a6"
__codename__ = "Yeast Starter"

View file

@ -15,6 +15,14 @@ import zipfile
import socket
import importlib
from tabulate import tabulate
from datetime import datetime, timedelta
try:
from systemd import journal
systemd_available=True
except Exception:
logger.warning("Failed to load systemd library. logfile download not available")
systemd_available=False
class SystemController:
@ -77,19 +85,29 @@ class SystemController:
fullkettlename = pathlib.Path(os.path.join(".",kettlename))
output_filename="cbpi4_log.zip"
result=[]
if systemd_available:
j = journal.Reader()
if logtime == "b":
j.this_boot()
else:
since = datetime.now() - timedelta(hours=int(logtime))
j.seek_realtime(since)
j.add_match(_SYSTEMD_UNIT="craftbeerpi.service")
if logtime == "b":
os.system('journalctl -b -u craftbeerpi.service --output cat > {}'.format(fullname))
else:
os.system('journalctl --since \"{} hours ago\" -u craftbeerpi.service --output cat > {}'.format(logtime, fullname))
for entry in j:
result.append(entry['MESSAGE'])
try:
with open(fullname, 'w') as f:
for line in result:
f.write(f"{line}\n")
except Exception as e:
logging.error(e)
plugins = await self.plugins_list()
with open(fullpluginname, 'w') as f:
f.write(plugins)
#os.system('echo "{}" >> {}'.format(plugins,fullpluginname))
try:
actors = self.cbpi.actor.get_state()
json.dump(actors['data'],open(fullactorname,'w'),indent=4, sort_keys=True)

View file

@ -64,7 +64,8 @@ setup(name='cbpi4',
'importlib_metadata',
'numpy==1.26.4',
'pandas==2.2.2'] + (
['rpi-lgpio'] if raspberrypi else [] ),
['rpi-lgpio'] if raspberrypi else [] ) + (
['systemd-python'] if localsystem == "Linux" else [] ),
dependency_links=[
'https://testpypi.python.org/pypi',