You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenIPC web UI plugin: the camex settings page and init script - #223
S98camex, the init script. It starts the client from the U-Boot environment, and only with camex_server and either camex_network or camex_psk with camex_pubkey.
README.md, with the variables and the build for a Cortex-A7 camera.
How the page works:
Save checks the values, writes all variables in one fw_setenv -s pass and restarts the client. Nothing is written when nothing changed, and values equal to their defaults (port, transport, MAC name) are not stored.
Reset stops the client and removes the camex_* variables.
Advanced shows the raw configuration, keys included, as the WireGuard page does. The psk is also visible in ps.
Values with control characters, spaces at the ends or &# are refused.
The page has no CSRF token of its own, like the web UI's WireGuard and VTun pages.
The init script closes inherited descriptors before it starts the client. Without that, a client started by Save kept the web server's devices and sockets open, and the deleted file with the form body.
Checked on an SSC325 camera (OpenIPC lite, static armv7 client 6.3.0, 297 KB): Save over UDP and TCP, refused values, a psk with special characters, Reset with the rest of the environment unchanged, and start at boot with the final script. shellcheck was run on the init script. There are no automated tests for these files.
No version change: no code or build files are touched.
Add OpenIPC camex settings page and camera init script
✨ Enhancement📝 Documentation🕐 20-40 Minutes
AI Description
• Add an OpenIPC settings page to validate, save, reset, and inspect camera client configuration.
• Start camex from U-Boot settings only when required connection details are present.
• Document installation, configuration variables, and a Cortex-A7 client build.
Merge Risk 🟡 Medium
Blast radius 🟡 Medium💥 2 capabilities
2 affected capabilities within one bounded functional scope: OpenIPC camera Camex client integration.
The page validates, displays, persists, resets, and applies the same Camex client settings consumed by the init script.
It is part of one bounded camera-client integration rather than a separate server or deployment capability; the init script is the runtime consumer of this configuration.
The init script launches and terminates the camera's Camex client, which creates and removes the tunnel interface and routes.
This is the runtime outcome of the same bounded camera-client integration, not an independent server capability.
env_write || redirect_to "$SCRIPT_NAME" "danger" "The settings could not be written"
$init restart </dev/null >/dev/null 2>&1
sleep 2
ready || redirect_to "$SCRIPT_NAME" "warning" "Saved. Camex starts with a server and a network name, or a server, its public key and a pre-shared key"
camex_pid
[ -n "$pid" ] || redirect_to "$SCRIPT_NAME" "danger" "Saved, but Camex is not running: see the log in Advanced"
redirect_to "$SCRIPT_NAME" "success" "Saved, Camex is restarted"
[ -e /dev/net/tun ] || modprobe tun 2>/dev/null
set -- --mode client --auto "--server-host=$server" "--port=${port:-5800}" \
"--transport=${transport:-udp}"
[ -n "$network" ] && set -- "$@" "--network=$network"
[ -n "$pubkey" ] && set -- "$@" "--server-pubkey=$pubkey"
[ -n "$psk" ] && set -- "$@" "--psk=$psk"
[ -n "$name" ] && set -- "$@" "--name=$name"
logger -p daemon.info -t camex "Starting, server $server"
# Started from the web page, it would keep majestic's devices and sockets
# open, and the form's body with the key. In a shell of its own: it has no
# script file or saved descriptors of its own to close
sh -c 'for fd in /proc/$$/fd/*; do
fd=${fd##*/}
[ "$fd" -le 2 ] || eval "exec $fd>&-"
done
exec start-stop-daemon "$@"' sh \
-S -q -b -m -p "$pidfile" -x "$daemon" -- "$@"
Before: the repository had no camera-side WebUI/init integration in these changed example paths.
After: the page validates seven related settings, applies defaults, omits selected defaults from persistent storage, writes or deletes multiple U-Boot variables, stops/restarts the daemon, waits, and reports status; the init script separately gates startup, builds a conditional argument set, tracks a pidfile, and performs graceful-then-forced shutdown.
The new correctness conditions are that validation/default normalization, persisted environment values, startup eligibility, generated CLI arguments, pidfile identity, and route/interface cleanup agree across save, reset, boot, restart, and stop states.
These are newly interacting state and persistence/lifecycle conditions, not complexity inherited merely from using existing validation or process helpers.
env_write || redirect_to "$SCRIPT_NAME" "danger" "The settings could not be written"
$init restart </dev/null >/dev/null 2>&1
sleep 2
ready || redirect_to "$SCRIPT_NAME" "warning" "Saved. Camex starts with a server and a network name, or a server, its public key and a pre-shared key"
camex_pid
[ -n "$pid" ] || redirect_to "$SCRIPT_NAME" "danger" "Saved, but Camex is not running: see the log in Advanced"
redirect_to "$SCRIPT_NAME" "success" "Saved, Camex is restarted"
[ -e /dev/net/tun ] || modprobe tun 2>/dev/null
set -- --mode client --auto "--server-host=$server" "--port=${port:-5800}" \
"--transport=${transport:-udp}"
[ -n "$network" ] && set -- "$@" "--network=$network"
[ -n "$pubkey" ] && set -- "$@" "--server-pubkey=$pubkey"
[ -n "$psk" ] && set -- "$@" "--psk=$psk"
[ -n "$name" ] && set -- "$@" "--name=$name"
logger -p daemon.info -t camex "Starting, server $server"
# Started from the web page, it would keep majestic's devices and sockets
# open, and the form's body with the key. In a shell of its own: it has no
# script file or saved descriptors of its own to close
sh -c 'for fd in /proc/$$/fd/*; do
fd=${fd##*/}
[ "$fd" -le 2 ] || eval "exec $fd>&-"
done
exec start-stop-daemon "$@"' sh \
-S -q -b -m -p "$pidfile" -x "$daemon" -- "$@"
Potential damage 🟡 Medium🩹 Recoverable
If the changed page or persistence logic regresses, operators may be unable to save, reset, or apply camera Camex settings through the WebUI.
The supported recovery is to correct the submitted values or use the reset operation and restart the client; code rollback alone does not necessarily repair already-written U-Boot environment values.
No evidence supports irreversible data loss or an external financial or confidentiality consequence from this bounded configuration behavior.
Generally recoverable by restoring the page/script, correcting or removing the saved camex_* environment values, and restarting the client.
Recovery depends on working fw_setenv/fw_printenv and administrator access to the camera.
if [ "$REQUEST_METHOD" = "POST" ] && [ "$POST_action" = "reset" ]; then
for v in $vars; do eval "$v="; done
$init stop </dev/null >/dev/null 2>&1
env_write || redirect_to "$SCRIPT_NAME" "danger" "The settings could not be removed"
redirect_to "$SCRIPT_NAME" "danger" "Camex is down, its settings are removed"
elif [ "$REQUEST_METHOD" = "POST" ]; then
for v in $vars; do eval "$v=\$POST_$v"; done
: "${camex_port:=5800}" "${camex_transport:=udp}"
if check; then
# Defaults are not written, so they can change with camex
[ "$camex_port" = 5800 ] && camex_port=""
[ "$camex_transport" = udp ] && camex_transport=""
[ "$camex_name" = "$def_name" ] && camex_name=""
env_write || redirect_to "$SCRIPT_NAME" "danger" "The settings could not be written"
$init restart </dev/null >/dev/null 2>&1
graph TD
UI["Settings page"] --> V{"Valid settings?"} -->|save| E["U-Boot environment"] --> I["Init script"] --> R{"Ready to start?"} -->|yes| C["Camex client"]
UI -->|reset and stop| I
UI -->|reset and clear| E
R -->|no| X["Remain stopped"]
Loading
High-Level Assessment
The following are alternative approaches to this PR:
1. Add client-side configuration-file support
➕ Could keep the pre-shared key out of the process command line and Advanced process listing.
➖ Requires changes to the client and deployment model, outside this example-only PR.
Recommendation: The U-Boot-backed page and init script fit the stated camera deployment and avoid changing the client. Keep this approach for the example, but treat command-line secret exposure as an explicit limitation; consider client-side configuration-file support separately. Integration also depends on the separate Services-menu plugin listing work.
Files changed (4) +271 / -0
Enhancement (2) +250 / -0
S98camexManage the camera client from U-Boot settings+88/-0
Manage the camera client from U-Boot settings
• Adds start, stop, and restart handling with a configuration readiness check, TUN loading, and PID tracking. Closes inherited descriptors before launching the client so a web-triggered restart does not retain web-server resources or the form body.
plugin-camex.cgiAdd the OpenIPC camex settings page+162/-0
Add the OpenIPC camex settings page
• Adds validated Save and Reset actions that batch U-Boot environment changes, omit default values, and manage the client. Displays connection status and an Advanced view of raw configuration and diagnostics, including keys.
1. Another site can reset camera settings 🐞 Bug⛨ Security
Description
plugin-camex.cgi accepts a reset POST based only on REQUEST_METHOD and POST_action, without
verifying that the request came from the settings page. If a camera administrator visits an
attacker-controlled page while authenticated to the web UI, a cross-site form submission can stop
the client and remove its saved settings.
+if [ "$REQUEST_METHOD" = "POST" ] && [ "$POST_action" = "reset" ]; then+ for v in $vars; do eval "$v="; done+ $init stop </dev/null >/dev/null 2>&1+ env_write || redirect_to "$SCRIPT_NAME" "danger" "The settings could not be removed"
Evidence
The reset branch checks only the POST method and action before stopping the service and calling the
settings writer; the reset form has no token field.
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
## Issue description
The new CGI accepts configuration-changing POSTs without verifying that they originated from its settings page, allowing cross-site requests to reset or replace camera settings.
## Fix Focus Areas
- examples/openipc-webui/plugin-camex.cgi[80-97]
- examples/openipc-webui/plugin-camex.cgi[131-144]
## Recommended Fix
Generate a session-bound, unpredictable request token in the page, include it in both POST forms, and verify it before either reset or save performs a write or service action.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
plugin-camex.cgi discards the result of $init restart and uses ready(), which checks only
submitted settings, before displaying its success message. If the client binary is missing or exits
after launch, Save can report a successful restart even though the client is not running.
3. Invalid server addresses are saved✓ Resolved
Description
check() validates camex_server with a character pattern and length limit, so it accepts an
invalid IPv4 literal such as 999.999.999.999. When that value is saved, the init script passes it
to the client, whose IPv4 endpoint resolution fails.
Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent
Cross-site POST: no change. The camera's web server refuses a POST whose Origin is another site before the page runs. Checked on the SSC325 camera: a POST with valid credentials and Origin: http://evil.example gets 403.
Failed start shown as success: fixed. After the restart the page checks that the client process is running, and says so when it is not. Checked with the binary moved away.
Invalid IPv4: fixed. A value made only of digits and dots must be an IPv4 address; 999.999.999.999 and 1.2.3 are refused. Checked on the camera.
Also: the unused loop variable shellcheck named in S98camex is gone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Files for an OpenIPC camera that runs camex as a client, in
examples/openipc-webui/:plugin-camex.cgi, the settings page. It needs a web UI that listsplugin-*.cgipages in its Services menu; that is proposed in Services: a Plugins group for applications that bring their own page majestic-webui#745, not merged yet.S98camex, the init script. It starts the client from the U-Boot environment, and only withcamex_serverand eithercamex_networkorcamex_pskwithcamex_pubkey.README.md, with the variables and the build for a Cortex-A7 camera.How the page works:
fw_setenv -spass and restarts the client. Nothing is written when nothing changed, and values equal to their defaults (port, transport, MAC name) are not stored.camex_*variables.ps.&#are refused.The init script closes inherited descriptors before it starts the client. Without that, a client started by Save kept the web server's devices and sockets open, and the deleted file with the form body.
Checked on an SSC325 camera (OpenIPC lite, static armv7 client 6.3.0, 297 KB): Save over UDP and TCP, refused values, a psk with special characters, Reset with the rest of the environment unchanged, and start at boot with the final script.
shellcheckwas run on the init script. There are no automated tests for these files.No version change: no code or build files are touched.