Skip to content

Improve AJAX API and fix mactrack_disable bugs #313

@somethingwithproof

Description

@somethingwithproof

Summary

Improve the mactrack AJAX API for consistency, robustness, and fix critical bugs in mactrack_disable().

Critical bugs in mactrack_disable() (lib/mactrack_functions.php)

  1. Wrong table names: Uses mactrack_devices and mactack_devices instead of mac_track_devices
  2. Wrong variable: Passes $stat to mactrack_format_device_row() instead of $dbinfo
  3. Missing null check: No guard when $dbinfo is empty (device not found)

Proposed improvements

High priority (bug fixes)

  • Fix table names to mac_track_devices
  • Fix $stat$dbinfo
  • Add null check for $dbinfo before use

Medium priority (API consistency)

  • Standardize JSON response envelope: { "success": true|false, "data": {...}, "error": "..." }
  • Add HTTP status codes (200, 400, 404, 500)
  • Validate device_id, site_id, ifIndex at entry point
  • Handle edge cases: empty $dbinfo, disabled device, failed command

Lower priority

  • Consolidate mactrack_ajax.php and mactrack_ajax_admin.php into single router
  • Add PHPDoc to api_mactrack_* functions
  • Use POST for state-changing actions (enable, disable, rescan)

Related

  • Part of cross-plugin API consistency (see gpsmap API improvements)
  • Ref: conversation on API improvements across plugins

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions