Skip to content

Conversation

@shuemon4
Copy link

Summary

Major feature release adding a modern React-based web UI and numerous backend improvements:

  • React UI: Complete rebuild using React 18 + TypeScript + Vite + Tailwind CSS
  • Authentication: Session-based auth with bcrypt password hashing and CSRF protection
  • Media Management: Folder-based browsing, thumbnails, pagination, and delete functionality
  • Configuration: JSON API endpoints, batch config updates, configuration profiles
  • Streaming: Client-side MJPEG parser with FPS display
  • System Integration: systemd watchdog support, automated installer
  • Security: CSRF protection, session tokens, secure cookie handling

Key Changes

Frontend (React)

  • Dashboard with camera streaming and quick settings
  • Settings page with scope filtering (global vs camera)
  • Media browser with folder navigation and thumbnails
  • Visual schedule picker for motion detection
  • Hardware encoding warnings and recommendations
  • Configuration profiles for presets

Backend (C++)

  • Migrated from legacy POST processor to JSON API
  • Added session token authentication for streams
  • Thumbnail generation for media library
  • libmicrohttpd static file serving with SPA support
  • Removed legacy webu_html and webu_post modules

Infrastructure

  • systemd service installation with watchdog integration
  • Automated installer script with dependency management
  • bcrypt-based password management CLI tool
  • Comprehensive installation guide

Test plan

  • Verify React UI loads at webcontrol port
  • Test authentication flow (login/logout)
  • Verify camera streaming works
  • Test configuration changes persist
  • Verify media browser shows recordings
  • Test on Raspberry Pi 4 and Pi 5

🤖 Generated with Claude Code

shuemon4 and others added 9 commits January 24, 2026 00:47
Major feature release adding a modern React-based web UI and numerous
backend improvements for the Motion video surveillance daemon.

Frontend (React 18 + TypeScript + Vite + Tailwind CSS):
- Dashboard with camera streaming and quick settings bottom sheet
- Settings page with scope filtering (global vs camera parameters)
- Media browser with folder navigation, thumbnails, and pagination
- Visual schedule picker for motion detection and recording
- Hardware encoding warnings and device-aware recommendations
- Configuration profiles for save/load/delete presets

Backend (C++):
- Migrated from legacy POST processor to JSON API endpoints
- Session-based authentication with bcrypt password hashing
- CSRF protection with session tokens for streams
- Thumbnail generation for media library
- libmicrohttpd static file serving with SPA routing support
- Removed legacy webu_html and webu_post modules

Infrastructure:
- systemd service installation with watchdog integration
- Automated installer script with dependency management
- bcrypt-based password management CLI tool (motion-setup)
- Comprehensive installation guide and Quick Start docs

Security:
- Session token authentication for all API endpoints
- CSRF protection with dual token validation
- Secure cookie handling with HttpOnly flags
- Auto-detection of config paths with secure defaults

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The file data/webcontrol/samplepage.html is a static HTML file that doesn't
require autoconf processing. Automake was looking for samplepage.html.in
template file which doesn't exist and isn't needed.

This fixes the autoreconf error:
configure.ac:739: error: required file 'data/webcontrol/samplepage.html.in' not found
The file was referenced in Makefile.am but missing from the working tree,
causing build failure. Restored from git history (commit 756b22b).

Fixes make error: No rule to make target 'doc/motion.png', needed by 'all-am'
Adds full UI support for all three Motion camera backends, allowing users
to configure USB cameras (V4L2), Raspberry Pi cameras (LIBCAM), and IP
cameras (NETCAM) from a unified React interface.

Backend (C++):
- Add camera_type field to status API (libcam/v4l2/netcam/unknown)
- Add camera_device field (device path or URL)
- Expose V4L2 controls array via new public accessor
- Expose NETCAM connection status and dual-stream indicator

Frontend (React/TypeScript):
- Add useCameraInfo hook for feature detection
- Add CameraSourceSettings component (type badge, device info)
- Add V4L2Settings component (dynamic USB camera controls)
- Add NetcamSettings component (IP camera configuration)
- Update Settings page with conditional rendering
- Update MovieSettings to show passthrough only for NETCAM

Architecture: Hook-based feature detection with discriminated unions
for type safety. No breaking changes - fully backward compatible.

Files: 4 created, 7 modified (167 insertions, 17 deletions)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Required for NETCAM_STATUS enum and cls_netcam class access.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add encapsulation methods to cls_camera for safer camera type checking
and device access. This improves code maintainability by avoiding direct
pointer access from web API handlers.

Backend changes:
- Add has_v4l2(), get_v4l2_controls() for V4L2 camera access
- Add has_netcam(), has_netcam_high() for netcam stream checking
- Update webu_json.cpp to use new accessor methods

Frontend changes:
- Remove unused config/onChange props from CameraSourceSettings
- Fix TypeScript type assertion in useCameraInfo hook

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implements intelligent camera detection with user-confirmed addition workflow.
Enables first-run camera setup and runtime camera management via Settings UI.

Backend Changes:
- New cam_detect module for Pi/USB/Network camera detection
- Platform identification (Pi model, libcamera/V4L2 capabilities)
- Sensor-aware defaults (imx708/219/477/296)
- V4L2 blacklist filtering (ISP devices)
- Persistent device ID resolution (/dev/v4l/by-id/)
- 5 new API endpoints: platform, detected, add, delete, test

API Endpoints:
- GET /0/api/cameras/platform - Platform info
- GET /0/api/cameras/detected - List unconfigured cameras
- POST /0/api/cameras - Add camera from detection
- DELETE /{camId}/api/cameras - Remove camera
- POST /0/api/cameras/test - Test netcam connection

Frontend Changes:
- Camera Management section in Settings (Global Settings)
- Multi-step Add Camera Wizard (Select → Configure → Test → Complete)
- Detected camera cards with specs and resolutions
- Configured camera cards with view/remove actions
- First-run welcome experience for zero-camera setups
- React Query hooks for detection and management

Key Features:
- Auto-detects Pi cameras (CSI) and USB cameras (V4L2)
- Manual network camera configuration with connection test
- CPU-efficient on-demand detection (no background scanning)
- Sensor-specific optimal defaults for Pi camera modules
- Frontend caching (30s detected, ∞ platform)

Files Added:
- src/cam_detect.{cpp,hpp}
- frontend/src/components/settings/CameraManagement.tsx
- frontend/src/components/settings/AddCameraWizard.tsx
- frontend/src/components/settings/DetectedCameraCard.tsx
- frontend/src/components/settings/ConfiguredCameraCard.tsx

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Enable seamless camera navigation within the Quick Settings panel via
dropdown selector, allowing users to switch between cameras without
closing and reopening the sheet. The switcher automatically hides for
single-camera setups to reduce UI clutter.

Changes:
- Add CameraSwitcher component with dropdown for multi-camera selection
- Integrate switcher into Dashboard bottom sheet header
- Simplify sheet title (camera name now shown in dropdown)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add type casting for API POST calls to resolve TypeScript errors
- Split CI workflow into separate frontend and backend jobs
- Add frontend linting and build verification to CI
- Remove unused platformInfo prop from AddCameraWizard
- Add support for unknown camera type in DetectedCameraCard
- Change CameraManagement to default export
- Regenerate build artifacts with fixes

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@Mr-Dave
Copy link
Member

Mr-Dave commented Jan 26, 2026

Thanks for PR. There is a lot here so it will take some time to review and pull this in. I'm currently busy with "life" but from just an initial look, I think we'd need the following:

  1. On my server it did not compile. Looks like some of the compatibility with prior versions of ffmpeg were removed and need to be restored.
  2. On my dev machine, I noticed the the M4 directory isn't in the UI branch and is needed. (Note that some of the custom clean scripts need to get adjusted to prevent this from be cleaned away)
  3. The branch seems to have some problems with the webcontrol vs webui being installed.
  4. Since Motion isn't just PI software (it is all platform, etc), we'd need to remove the PI specific things like the scripts.
  5. I see the webu_post was remove in favor of JSON. I think that may be too much for some of our users and we'd need to bring that back to be alongside of the JSON. The change from GET to POST was already almost too much for our users. (Note that the previous processing had some unresolved problems with the url encoding requirements)
  6. I think the default directories need a discussion. Historically it was in /etc/motion but that prevented users from accessing/changing things while the app is running. In V5 I was inclined to go to /var/lib/motion so configurations as well a runtime data could be stored. I think I saw in the PR that it was using /usr/local/etc/motion.
  7. There were a few compiler warnings. I've gone with the approach that Motion doesn't have any warnings.
  8. I was able to get the point of seeing the start page but only got a "Unable to connect to Motion. Please check the server." Probably due to some of the new authorization items added but I didn't do. We probably need to think about legacy users as well as new ones.

Since this is pretty big and there seem to be a few issues to resolved. How do you want to go about discussing/resolving them? Separate discussions for each item? (I don't know a way to have separate discussions/resolutions to each topic/issue in a PR and I want the discussion somewhere in the Motion repo for tracking)

@shuemon4
Copy link
Author

shuemon4 commented Jan 26, 2026 via email

Restores backward compatibility with IoT devices and scripts that use
form-urlencoded POST requests while maintaining security through optional
CSRF token validation.

Key Changes:
- Restored webu_post.cpp/hpp (967 lines) from pre-removal state
- Added Content-Type based routing (form-urlencoded vs JSON)
- Implemented optional CSRF validation:
  * No token: Allowed (backward compatible)
  * Valid token: Allowed (secure mode)
  * Invalid token: Blocked (attack prevention)
- Fixed compilation issues:
  * Added ctx_detected_cam forward declaration in conf.hpp
  * Added camera.hpp include in cam_detect.cpp
  * Fixed JsonParser.getInt() -> getNumber() in webu_json.cpp
- Added comprehensive test script (test_urlencoded_post.sh)

API Support:
- URL-encoded POST: snapshot, pause, events, PTZ, config, camera mgmt
- JSON API: Unchanged, full CSRF protection maintained
- Both APIs coexist without interference

Security Model:
- JSON API (React UI): Always protected with CSRF + session tokens
- URL-encoded POST: Optional CSRF for backward compatibility
- Invalid CSRF tokens: Always blocked

Tested on Raspberry Pi 5 with all commands verified working.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@Mr-Dave
Copy link
Member

Mr-Dave commented Jan 27, 2026

  1. Can the UI be self-contained, a Use-it-As-is feature, or does it need to
    be designed with a specific? Meaning, does this need to be designed
    a specific way or can it follow a "Here are the majority of options for the
    widest range of users" design?
    a. With proper documentation which includes examples, are you
    comfortable with exposing API's for anyone that doesn't want to use the
    built-in UI so they can interface using a different UI?

Quite a few users interact with the Motion application via the web interface api (previously via the GET commands). The default web page interface itself doesn't need to show all the parameters but I think that the API would need to handle all of them. The web control/interface page also needs to be optional and have an option that does not rely upon any external resources/libraries. i.e. It retrieves nothing from the internet/web to work.

  1. The POST, What is the purpose of this? An easy connection for custom
    built UI or connecting to Motion externally?

Updating a parameter, pausing/starting detection, checking whether detection is running, starting a recording, getting a snapshot, working a timelapse, etc. All this may be just by the user's own curl scripts/cron jobs, etc or perhaps their own web page they built. The JSON may be easier, I haven't tried it. I was just thinking of keeping the post to not change too much from what was in place before as well as still giving them the option of the previous standalone isolated web control page.

Regarding the M4 problem (number 2). It is resolved by adding a new dependency for autoconf-archive . Once that is installed, the error message goes away and the make cleanall doesn't need to get adjusted.

  1. Keep the Pi scripts if Pi is detected, but ensure it is modular. This
    can be used as an example for adding scripting fields for other devices as
    well (ex. Arduino, trigger Python scripts, etc).

Yea, I'm not sure I'm going to be persuaded on including PI scripts. Motion is packaged with Debian and therefore it will come with RapsiOS. Motion is also deployed across a variety of other platforms. I've had my experience of trying to include various OS builds and its just not worth the effort. e.g. I'm not going to creating and maintaining scripts for my PI zero, my PI2, the next PI6, the Arduino, the OrangePi, the PIs running BSD, the Suse servers, the Macs, Rocky, the....(you get the point)

I do have lots of other comments and changes that I'd want before it goes to master (I'm guessing some of them may not be what you'd want such as the PI scripts). I'm thinking we may just want to implement a few changes and then pull it into the 5.0 branch with your changes all intact and then revise from there.

@Mr-Dave
Copy link
Member

Mr-Dave commented Jan 27, 2026

One fix that was needed on my dev machine to get this work was to revert the change made on the parse_url from this back to this I'm not sure why this was revised nor how the UI works on your machine as it is.

@shuemon4
Copy link
Author

shuemon4 commented Jan 28, 2026 via email

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.

2 participants