Skip to content

SimpleAPI move from php to python http - #4182

Open
seaspotter wants to merge 9 commits into
openWB:masterfrom
seaspotter:php-to-python-simpleapi
Open

seaspotter wants to merge 9 commits into
openWB:masterfrom
seaspotter:php-to-python-simpleapi

Conversation

@seaspotter

@seaspotter seaspotter commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Warum

PHP2Shell (CVE-2026-109618/109619) betrifft jede von Apache ausführbare .php-Datei. simpleAPI ist die größte PHP-Komponente (~4.400 Zeilen) und die einzige mit dauerhafter Drittanbieter-Nutzung (Home Assistant, node-red, ioBroker) - daher zuerst komplett durch Python ersetzt.

Was

  • Python-HTTP-Server im bereits laufenden simpleAPI_mqtt.py-Daemon (jetzt simpleapi.py), keine neue Dependency
  • Gleiche URL, gleiches Request/Response-Format, gleiche Auth (4-stufig)
  • Alte PHP-Dateien entfernt, Apache leitet auf den neuen Server um
  • get_lastlivevaluesjson entfernt (undokumentiert, ungenutzt)
  • Ein echter Bug gefunden und gefixt: Schreibzugriffe auf instant_charging_limit*/pv_charging_limit* per MQTT-Topic haben eine explizite Ladepunkt-ID ignoriert und immer den niedrigsten Ladepunkt getroffen

Tests

  • Mit echtem Ladepunkt, echter Batterie/PV/Zähler/Verbraucher-Hardware geteset
  • Lesen und Schreiben über eine echte Drittanbieter-Integration (ioBroker) getestet, live über koala bestätigt
  • pytest/flake8 sauber, keine Änderungen an packages/

Summary by Sourcery

Move simpleAPI from PHP to the existing Python MQTT daemon while retaining compatibility and improving component access and chargepoint-targeted writes.

New Features:

  • Replace the PHP simpleAPI implementation with an integrated Python HTTP server while preserving existing endpoints, request/response formats, and authentication behavior.
  • Add simpleAPI support for component discovery, vehicle and manual SoC management, and digital/analog IO reads and writes.
  • Expose expanded cached read parameters for chargepoints, counters, batteries, PV systems, consumers, and IO devices.

Bug Fixes:

  • Correct chargepoint-targeted charging-limit writes so explicit chargepoint IDs are honored instead of always selecting the lowest ID.

Enhancements:

  • Run the HTTP API alongside the MQTT daemon and serve requests from cached MQTT data without per-request broker round trips.
  • Refactor simpleAPI parameter handling, authentication, and MQTT write operations into dedicated Python modules with shared validation and response handling.
  • Remove the obsolete PHP implementation and the unused get_lastlivevaluesjson endpoint.

Build:

  • Enable Apache HTTP proxying for the Python simpleAPI server and replace the legacy service configuration with the new Python configuration.

Deployment:

  • Route HTTP and HTTPS simpleAPI requests through Apache to the local Python server.

Chores:

  • Rename the daemon and configuration files to reflect the Python simpleAPI implementation.

@kevinwieland

Copy link
Copy Markdown
Contributor

#4162 (reply in thread)

Erstmal gibt es einen php fix.
Komplett anderen Unterbau kann ich aktuell zeitlich nicht bewerten. So oder so sollten wir das nochmal diskutieren.

@seaspotter

Copy link
Copy Markdown
Collaborator Author

#4162 (reply in thread)

Erstmal gibt es einen php fix. Komplett anderen Unterbau kann ich aktuell zeitlich nicht bewerten. So oder so sollten wir das nochmal diskutieren.

Ja okay, aber:

Ein Punkt, der unabhängig von der Sicherheitsfrage für sich steht: die Geschwindigkeit hat sich spürbar verbessert. Die alte PHP-Implementierung hat pro Lese-/Schreibzugriff einen eigenen mosquitto_sub/mosquitto_pub-Prozess gestartet (teils mehrere pro Request bei zusammengesetzten Werten), jeweils mit bis zu 1s Wartezeit - list_components hat dadurch bei mir real ~8s gedauert. Der neue Python-Server läuft im bereits dauerhaft verbundenen simpleAPI-Daemon und bedient Lesezugriffe direkt aus dem Live-Cache, Schreibzugriffe über die schon offene Verbindung - ohne Prozess-Spawning. Hab das auch über eine echte Drittanbieter-Integration (ioBroker) getestet: Schreibzugriffe wie bat_mode/bat_power_reserve oder Änderung der Chargemodes laufen jetzt sofort statt mit Verzögerung bei php.

Das ist nur für die API allein schon ein echter Gamechanger.

@kevinwieland

Copy link
Copy Markdown
Contributor

Was hältst du von PHP fix direkt und Python Unterbau in die nächste Alpha?

@seaspotter

Copy link
Copy Markdown
Collaborator Author

Was hältst du von PHP fix direkt und Python Unterbau in die nächste Alpha?

Völlig okay für mich, ich hab meine Systeme schon alle gepatcht :)
Die simpleAPI hatte halt die meisten Zeilen Code in php, daher hab ich nur die angefasst und nichts anderes und die Geschwindigkeit via python ist halt auch echt nochmal n richtiger Schritt, von daher sollte man defintiv drüber nachdenken.

@kevinwieland

Copy link
Copy Markdown
Contributor

Unbedingt. Sollte dann nur in der Alpha getestet werden um sicherzustellen das es mit allen Anbindungen und so läuft.
Da ist der quick fix mit gepatchtem PHP risikoärmer.

@seaspotter seaspotter added this to the 2.4.0 milestone Oct 24, 2026
@seaspotter seaspotter added the enhancement New feature or request label Oct 24, 2026
@LKuemmel LKuemmel moved this to In progress in openWB Roadmap Oct 29, 2026
@seaspotter
seaspotter force-pushed the php-to-python-simpleapi branch from 5b83751 to 6cf5f3c Compare November 16, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants