Creating extensions via database

Hi all,

I am fairly new to FreePBX which has allowed me to get off the ground with Asterisk and find my way around it and what it can do. It’s great software.
I use the GUI to do most stuff but I now have a need to create extensions, conference calls etc from within my own website. Having a quick attempt at this I can see where extension settings are stored in the DB and I have successfully created working extensions by inserting data into tables sip, devices & users.
My question is this… is this acceptable practice to manually create extensions or bad practice? If so, what is the best or simplest way to create extensions outside of the FreePBX GUI? My website is built using PHP.

All advice greatly appreciated.

You probably want to look at using the Bulk handler module. Export a CSV template for yourself, and then use the bulk handler gui in the web interface to import a populated CSV file.

Bad practice…

The GUI validates what you type to make sure it’s ok before inserting it and knows how to populate each database field and tables (there could be more than one…).

Please use Bulk Handler (or Bulk Extensions for older versions) if you want to create extensions in batch (which I assume is the reason you are trying to bypass the GUI)…

Good luck and have a nice day!

Nick

Thanks guys for your help.

Yes, I saw the Bulk Extensions module. I will try that and use it’s validation functions to avoid errors.
This certainly covers my need to create extensions and very good advice. Thanks.

I also need to create Conference’s via my web app which I can’t see a way around without using the GUI. I may have to edit the DB to achieve and ensure all the required data is inserted and hope things don’t break. I was hoping that there was an API of some sort to do this.

If the answer is “I am going to touch the database” it is wrong 100% of the time. Not everything is in the database. This is more complex than that.

  1. http://wiki.freepbx.org/display/FOP/Bootstrap - Bootstrap gives you access to FreePBX internals.
  2. https://github.com/freepbx all the code is here. Use the FreePBX internals.

Things in *.class.php can typically be called with

\FreePBX::<class>-><method>

things in functions.inc.php can typically be called direct.

Thanks very much jfinstrom.

I will look into this. It looks like this is what I need.

conference settings are stored in Asterisk and backed up in the mysql database

As has been indicated by several already, but just to re-iterate, it’s ALWAYS wrong and a bad idea to think you can just populate a table, or even multiple tables, in the DB. Not only are there other places that settings are sometimes stored beyond the MySQL DB, but there’s no guarantee that things will stay the same. If you use the API, then you will almost always get consistency and a migration path as versions change.

What’s worse, you may also not always realize that you missed something since it often may work at the surface but be broken underneath in ways that are not first detected.

I agree. I guessed that it would be bad practice to edit the DB. I think Bootstrap may be the way to go for my application as it addresses these issues.

Thanks foe the advice. Appreciated.