Configure freepbx on the command line (IAC)

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?

Thanks

Read and understand every line of the open source code base of FreePBX ? After you have done that you will find it to be a piece of cake :wink:

1 Like

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:

  1. 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.

  2. You write a system that manipulates the FreePBX database, calling its compilation functions as needed.

  3. 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.

You gotta be kidding.

1 Like

well, this sounds like a challenge :slight_smile:

1 Like

Technically “EASY” but you do need to get a grasp of the code…

Start here: https://wiki.freepbx.org/display/FOP/Bootstrap

This may be worth a look as a starting point
https://git.freepbx.org/projects/FRCM/repos/restapi/browse?at=refs%2Fheads%2Frelease%2F13.0

With bootstrapping you can use all native functions and methods.

When you submit a trunk/extension etc this is the method that processes the form so you can see the data structure.

https://git.freepbx.org/projects/FREEPBX/repos/core/browse/Core.class.php#791

Method for adding a DID:
https://git.freepbx.org/projects/FREEPBX/repos/core/browse/Core.class.php#2193

example

<?php
include '/etc/freepbx.conf';
//Creates FreePBX object for reuse
$FreePBX = FreePBX::Create();
//phone number(DID)
//Source Caller IS
$settings = array(
   'extension' => '4805551212',
   'cidnum' => '4805551213'
);
//Call the add method. 
$FreePBX->Core->addDID($settings);

Note “functions” will be in functions.inc.php and will look like core_add_foo(); these can be called with just the include.

Methods are in Module.class.php and require creating the BMO object like the example above.
You can call
$BMOobject->Module->Method();

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.