|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Module Overview |
| 6 | + |
| 7 | +ModuleAutoprovision is a MikoPBX extension module for automatic IP phone provisioning. It discovers phones on the local network via PnP multicast (224.0.1.75:5060), generates vendor-specific configuration files, and delivers them over HTTP. Supported vendors: Yealink, Snom, Fanvil, Grandstream. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +### JavaScript compilation (ES6 to ES5) |
| 12 | +```bash |
| 13 | +/Users/nb/PhpstormProjects/mikopbx/MikoPBXUtils/node_modules/.bin/babel \ |
| 14 | + public/assets/js/src/module-autoprovision-index.js \ |
| 15 | + --out-dir public/assets/js/ \ |
| 16 | + --source-maps inline \ |
| 17 | + --presets airbnb |
| 18 | +``` |
| 19 | + |
| 20 | +### PHP static analysis |
| 21 | +```bash |
| 22 | +phpstan analyse |
| 23 | +``` |
| 24 | + |
| 25 | +### CI/CD |
| 26 | +Pushes to `master` or `develop` trigger `.github/workflows/build.yml`, which uses the shared `mikopbx/.github-workflows` extension-publish workflow (initial version: 1.62). |
| 27 | + |
| 28 | +## Architecture |
| 29 | + |
| 30 | +### Namespace |
| 31 | +All PHP classes use `Modules\ModuleAutoprovision\` namespace with PSR-4 autoloading rooted at `/`. |
| 32 | + |
| 33 | +### Key Layers |
| 34 | + |
| 35 | +**MVC (Phalcon Framework):** |
| 36 | +- `App/Controllers/ModuleAutoprovisionController.php` — Web UI controller (settings tabs: phones, templates, URIs, phonebook, PnP config) |
| 37 | +- `App/Forms/ModuleAutoprovisionForm.php` — Form field definitions |
| 38 | +- `App/Views/index.volt` — Phalcon Volt template with Semantic UI |
| 39 | + |
| 40 | +**Business Logic (`Lib/`):** |
| 41 | +- `AutoprovisionConf.php` — Extends `ConfigClass`. Registers workers, defines REST API routes, constants (`BASE_URI = /pbxcore/api/autoprovision-http`) |
| 42 | +- `Autoprovision.php` — Core config generation. Routes to vendor-specific classes, sends SIP NOTIFY for phone reboot, AGI entry point |
| 43 | +- `ConfManager.php` — Interface with single method `generateConfig($req_data, $sip_peers): string` |
| 44 | +- `AutoprovisionYealink.php`, `AutoprovisionSnom.php`, `AutoprovisionFanvil.php` — Vendor-specific implementations of `ConfManager` |
| 45 | +- `WorkerProvisioningServerPnP.php` — Background worker: multicast PnP server, MAC filtering, device discovery |
| 46 | +- `RestAPI/Controllers/GetController.php` — REST API: config delivery, phonebook, device/user CRUD |
| 47 | + |
| 48 | +**Models (Phalcon ORM, `Models/`):** |
| 49 | +- `ModuleAutoprovision` — Global settings (extension pattern, PBX host, MAC white/blacklists, additional INI params) |
| 50 | +- `ModuleAutoprovisionDevice` — Phone devices (MAC, model, IP). Has many `Users` and `BLF` |
| 51 | +- `ModuleAutoprovisionUsers` — Maps users to device lines. Belongs to `Users` (core) and `Device` |
| 52 | +- `ModuleAutoprovisionBLF` — BLF button configs per device |
| 53 | +- `Templates`, `TemplatesUri`, `TemplatesUsers` — Template system for config file generation |
| 54 | +- `OtherPBX` — External PBX phonebook entries |
| 55 | + |
| 56 | +All models extend `ModulesModelsBase`. Table names use `m_` prefix (e.g., `m_ModuleAutoprovisionDevice`). |
| 57 | + |
| 58 | +**Setup:** |
| 59 | +- `Setup/PbxExtensionSetup.php` — DB table creation, default data, extension registration. Extends `PbxExtensionSetupBase` |
| 60 | + |
| 61 | +**AGI:** |
| 62 | +- `agi-bin/ModuleAutoprovisionAGI.php` — Asterisk AGI script triggered by dial pattern (e.g., `*2*XXXX`). Resolves phone IP → MAC → device registration |
| 63 | + |
| 64 | +### Frontend |
| 65 | +- Source: `public/assets/js/src/module-autoprovision-index.js` (ES6) |
| 66 | +- Compiled: `public/assets/js/module-autoprovision-index.js` |
| 67 | +- Uses Semantic UI components, dynamic table management, AJAX form submission |
| 68 | + |
| 69 | +### REST API Flow |
| 70 | +Phones request configs via `GET /pbxcore/api/autoprovision-http/*` → `AutoprovisionConf::moduleRestAPICallback()` → `GetController::getConfigStatic()` → vendor-specific `ConfManager::generateConfig()`. |
| 71 | + |
| 72 | +### Adding a New Phone Vendor |
| 73 | +1. Create `Lib/AutoprovisionNewVendor.php` implementing `ConfManager` interface |
| 74 | +2. Add MAC prefix detection in `GetController::getConfigStatic()` |
| 75 | +3. Add config generation routing in `Autoprovision::generateConfigPhone()` |
| 76 | + |
| 77 | +## Translations |
| 78 | +30 language files in `Messages/`. Key file: `en.php`. Translation keys prefixed with `module_autoprovision_` or `mod_autoprovision_`. |
0 commit comments