PearlPBX2
For engineers

The architecture under the hood

How PearlPBX2 turns Django models into a working Asterisk configuration, validates it before it's ever applied, and lets you roll back any change.

Stack

Python3.10+ (CI/Docker — 3.12)
Django5.2.8
PostgreSQL14+ (CI/Docker — 17)
Redis7+
Asterisk22+ with res_pjsip, res_agi, cdr_pgsql

Configuration generation

30+ Django models, each editable through the admin interface, and a configuration generator (core/conf.py, ~950 lines) turns them into Asterisk configuration files. Apply Changes shows a preview of every file before writing it, versions the configuration in the database, and only then soft-reloads or fully restarts Asterisk over AMI. A backup is created automatically before overwriting.

The AEL dialplan validator

core/validators.py(1000+ lines) parses if/else/while/for/switch block structure, balances braces, quotes, and${...} expressions, and checks every application call against a whitelist of ~150 Asterisk applications. Extension patterns are checked for correct syntax and rendered sorted by specificity — exact matches before wildcards. Bad dialplan is rejected in the web form before it ever reaches Asterisk.

Ansible and deployment rollback

Install, update, and rollback are separate scripts (install.sh,update.sh,rollback.sh) over 10 Ansible roles. A fourth script,update-asterisk.sh, upgrades Asterisk itself in place: it backs up the config, binaries, and modules, compiles the new version while the current one keeps serving calls, drains active calls gracefully, and can roll back to the previous binaries on demand. The installer compiles Asterisk 22 from source, generates every secret, sets up the cron jobs the system needs (database backup, Asterisk config backup, log rotation, recording conversion and offload, system monitoring), and configures nftables, detecting and logging the SSH port before applying the rules.rollback.sh -n <steps>reverts code, database migrations, and services to a previous state using the deploy-state ledger. The automated installer targets Debian or Ubuntu only — tested on Debian 13 and Ubuntu 24.04; a Docker Compose stack for evaluation and development isn't tied to a distro, and a separate integration-test compose file runs the test suite against a real Asterisk 22 container in CI.

systempostgresredisasteriskasterisk_updatepearlpbx2servicesnginxtftpfirewall

REST API

Token authentication (Authorization: Token <key>): click-to-call, ad-hoc conferencing, queue-agent pause control, call-recording downloads. The full endpoint list is in the live OpenAPI schema with Swagger UI and ReDoc. REST API documentation →