Skip to content

Commit

Permalink
Merge pull request #134 from PiBrewing/python-systemd_test
Browse files Browse the repository at this point in the history
Fix for issue #132 (CVE-2024-3955)
  • Loading branch information
avollkopf authored May 2, 2024
2 parents 0cac23e + f5593fd commit fe15b4c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cbpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "4.4.1.a3"
__version__ = "4.4.1.a6"
__codename__ = "Yeast Starter"

32 changes: 25 additions & 7 deletions cbpi/controller/system_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
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:

Expand Down Expand Up @@ -77,19 +85,29 @@ async def downloadlog(self, logtime):
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)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
'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',
Expand Down

0 comments on commit fe15b4c

Please sign in to comment.