Skip to main content

Prepare the PBX

1. AMI user on the PBX​

Plain Asterisk: in manager.conf; FreePBX: in manager_custom.conf (not in the manager.conf generated by FreePBX, which FreePBX rewrites when it applies the configuration):

[wbvoip]
secret = <long, random>
deny = 0.0.0.0/0.0.0.0
permit = <IP of the Odoo server>/255.255.255.255
read =
write = system ; only with lamps switched on: write = system,call
  • Residual risk: with write = system Asterisk also allows actions such as GetConfig (reads configuration files, including SIP passwords) and ModuleLoad; Asterisk cannot block single actions. Odoo only sends DBGet, DBPut, DBDel, PJSIPShowEndpoints and Ping (plus Challenge, Login, Logoff), with lamps switched on also Setvar, and never any other action (allow list in the code).
  • Treat the account like an administrator password: permit only for the IP of the Odoo server (if Odoo runs in Docker behind NAT, the PBX sees the host's address), switch on TLS ([general]: tlsenable = yes, usually port 5039, certificate of the PBX). In Odoo TLS is therefore the default (port 5039); without TLS the form shows a warning. In Odoo the secret is stored encrypted and only for system administrators.
  • The lamps on the desk phone (switch "Device state lamps" on the PBX, profile FreePBX only, default off) set Custom:DND<extension> and Custom:CF<extension> and additionally need write = call. They only work for purely numeric extensions with at most 20 digits. If setting them fails, the log shows a warning; the AstDB stays authoritative.

2. Read-only user for the CDR database​

Only SELECT on the one table:

  • MySQL/MariaDB (FreePBX: database asteriskcdrdb, table cdr):

    CREATE USER 'wbvoip_cdr'@'<Odoo IP>' IDENTIFIED BY '<long, random>';
    GRANT SELECT ON asteriskcdrdb.cdr TO 'wbvoip_cdr'@'<Odoo IP>';

    With TLS also ALTER USER 'wbvoip_cdr'@'<Odoo IP>' REQUIRE SSL;.

  • PostgreSQL (cdr_pgsql):

    CREATE ROLE wbvoip_cdr LOGIN PASSWORD '<long, random>';
    GRANT CONNECT ON DATABASE <cdr database> TO wbvoip_cdr;
    GRANT USAGE ON SCHEMA public TO wbvoip_cdr;
    GRANT SELECT ON public.cdr TO wbvoip_cdr;

    In pg_hba.conf only one line hostssl <cdr database> wbvoip_cdr <Odoo IP>/32 scram-sha-256.

Odoo itself sets the session to read-only and limits every query: PostgreSQL 15 seconds (statement_timeout), MariaDB/MySQL 12 seconds (max_statement_time or max_execution_time), i.e. before Odoo's own read timeout of 15 seconds. If the server aborts, the sync shrinks the time window. For a CDR table you created yourself, add an index on calldate if it is missing (the query filters and sorts by it), e.g. CREATE INDEX cdr_calldate ON cdr (calldate);. Without the index the server reads the whole table on every run and hits the time limit on large tables.

3. Firewall​

make AMI (5038/5039) and the database (3306/5432) reachable only from the IP of the Odoo server, never from the internet.