I am considering building a freepbx system for an infrastructure as code environment. This means the configuration of the freepbx system must be automated.
For example, I want to create an inbound & outbound route, extensions, queues, time conditions, time groups, etc. All this has to be done on the command line.
So, my guess is that for every configuration change I make on the freepbx web interface, there’s an underlying shell command sent to the system.
Where would I start, for configuring a freepbx system from the command line?
Grossly oversimplified view: Asterisk is the PBX system. It’s controlled by numerous configuration files (what you see in /etc/asterisk). Although these are ‘plain text’ (nothing is binary, encrypted or intentionally obfuscated), it’s a very complex system.
FreePBX can be thought of as a ‘GUI for Asterisk’. Its model of the configuration is maintained in a database. The ‘user’ side displays the database (as a website) in an organized fashion that’s easy for humans to read and understand, and accepts form submissions to modify the database. Whenever the database is modified, the content gets ‘compiled’ into the various files that tell Asterisk how to process calls. Just as a C compiler doesn’t directly generate machine code for every statement; complex ones call on pre-written library functions, FreePBX contains a library of macros, sections of dial plan, etc., which are called by the compiled sections of the generated configuration files. Shell commands play a relatively minor role, for example commanding Asterisk to re-read files that have been modified.
I can imagine three ways your system might work:
You write your own Asterisk configuration compiler. This could avoid FreePBX altogether, or (more likely) it would leverage the FreePBX ‘library’ and possibly some of its database translation code.
You write a system that manipulates the FreePBX database, calling its compilation functions as needed.
You write a system that accesses the FreePBX website programmatically, simulating the configuration actions that a human would make.
Any of these would be a huuuge project. In addition, it would be very difficult to build a system that would be robust in the face of updates to either Asterisk or FreePBX. Someone wanting to take advantage of new Asterisk or FreePBX features would almost certainly be dependent on your updates.