Skip to content

OpenIPC web UI plugin: the camex settings page and init script - #223

Merged
compot-dev merged 3 commits into
masterfrom
openipc-webui-plugin
Nov 25, 2026
Merged

compot-dev merged 3 commits into
masterfrom
openipc-webui-plugin

Conversation

@compot-dev

@compot-dev compot-dev commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 lists plugin-*.cgi pages 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 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.

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add OpenIPC camex settings page and camera init script

✨ Enhancement 📝 Documentation 🕐 20-40 Minutes

Grey Divider

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.
Sources

examples/openipc-webui/plugin-camex.cgi[60-75]

env_write() {
	local v val tmp rc changed=""
	for v in $vars; do
		[ "$(t_value "$v")" = "$(env_get "$v")" ] || changed=1
	done
	[ -n "$changed" ] || return 0
	tmp=$(umask 077; mktemp /tmp/camex-env.XXXXXX) || return 1
	for v in $vars; do
		val=$(t_value "$v")
		if [ -n "$val" ]; then printf '%s %s\n' "$v" "$val"; else printf '%s\n' "$v"; fi
	done > "$tmp"
	fw_setenv -s "$tmp" >/dev/null 2>&1
	rc=$?
	rm -f "$tmp"
	return $rc
}

examples/openipc-webui/plugin-camex.cgi[104-110]

		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"

examples/openipc-webui/S98camex[37-55]

	[ -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" -- "$@"
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Coordinated invariants

  • 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.
Sources

examples/openipc-webui/plugin-camex.cgi[60-75]

env_write() {
	local v val tmp rc changed=""
	for v in $vars; do
		[ "$(t_value "$v")" = "$(env_get "$v")" ] || changed=1
	done
	[ -n "$changed" ] || return 0
	tmp=$(umask 077; mktemp /tmp/camex-env.XXXXXX) || return 1
	for v in $vars; do
		val=$(t_value "$v")
		if [ -n "$val" ]; then printf '%s %s\n' "$v" "$val"; else printf '%s\n' "$v"; fi
	done > "$tmp"
	fw_setenv -s "$tmp" >/dev/null 2>&1
	rc=$?
	rm -f "$tmp"
	return $rc
}

examples/openipc-webui/plugin-camex.cgi[104-110]

		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"

examples/openipc-webui/S98camex[37-55]

	[ -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.
Sources

examples/openipc-webui/plugin-camex.cgi[60-75]

env_write() {
	local v val tmp rc changed=""
	for v in $vars; do
		[ "$(t_value "$v")" = "$(env_get "$v")" ] || changed=1
	done
	[ -n "$changed" ] || return 0
	tmp=$(umask 077; mktemp /tmp/camex-env.XXXXXX) || return 1
	for v in $vars; do
		val=$(t_value "$v")
		if [ -n "$val" ]; then printf '%s %s\n' "$v" "$val"; else printf '%s\n' "$v"; fi
	done > "$tmp"
	fw_setenv -s "$tmp" >/dev/null 2>&1
	rc=$?
	rm -f "$tmp"
	return $rc
}

examples/openipc-webui/plugin-camex.cgi[91-105]

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
Assessed commit 1616571
Diagram

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.

examples/openipc-webui/S98camex

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.

examples/openipc-webui/plugin-camex.cgi

Documentation (2) +21 / -0
README.mdLink the camera-specific OpenIPC example +3/-0

Link the camera-specific OpenIPC example

• Distinguishes the new camera client example from the existing server installation examples and links to its directory.

examples/README.md

README.mdDocument plugin installation and camera build +18/-0

Document plugin installation and camera build

• Lists installation paths, U-Boot variables, startup requirements, and a static Cortex-A7 client build command.

examples/openipc-webui/README.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

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.
Code

examples/openipc-webui/plugin-camex.cgi[R80-83]

+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.

examples/openipc-webui/plugin-camex.cgi[80-97]
examples/openipc-webui/plugin-camex.cgi[131-144]

Agent prompt
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



Remediation recommended

2. Failed client starts appear successful ✓ Resolved
Description
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.

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@compot-dev

Copy link
Copy Markdown
Collaborator Author

The review of 564ed32:

  1. 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.
  2. 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.
  3. 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.

@compot-dev
compot-dev merged commit 8379af6 into master Nov 25, 2026
18 checks passed
@compot-dev
compot-dev deleted the openipc-webui-plugin branch November 25, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant