Skip to main content

Adding new feature code for ALL tenants

Posted by olekaas on Sun, 10/18/2009

I haven't foud a button on the dashboard that will propagate a new feature code to all tenants. With hundreds of tenants (or just more than 10), adding them manually is no fun and error prone. Luckily you can just pop the hood and get your hands dirty with grep, sed and diff:

Lets say you've made an awesome new script that all your tenant should have available through the same feature code (*74). Make a working copy:

cp /etc/asterisk/extensions.include .

Do not alter this copy. If you need to make changes, make a new copy. Next we want to make sure that no one is already using *74:

grep "exten => \*74" extensions.include

We need to escape the * with a \. If grep yields any results, resolve them before going any further. Either remap, delete or select another feature code. Next we are going to use sed. sed can find a pattern and append a line to it using the "a" modifier:

sed '/^\[feature-extensions-.*\]$/ a exten => *74,1,Macro(brew-coffee,no-cream) ; Let the user pour fresh coffee out of their handset' < extensions.include > wip

We search for the feature contexts [feature-extensions-TENANT]. Start and end of line is matched with ^ and $. The [ and ] must be escaped by prepending a \ and the tenant is matched with ".*" . After the "a" modifier the feature code definitions is appended.
We're almost there. Use diff to check if the extension.include file have been modified while we were hacking:

diff extensions.include /etc/asterisk/extensions.include

If diff yields any results - start over. Else stop webmin (or something), run diff again to be absolutely sure and move the modified file in to place:

mv wip /etc/asterisk/extensions.include

Reload asterisk and start webmin again. By strike of luck (if lack of skills) you should have en new feature code for all tenants.

/Ole


Submitted by thirdlane on Sun, 10/18/2009 Permalink

At some point I considered the “propagate” or “mass create/update” feature in PBX Manager (for both feature codes and outbound routes) – just did not have a chance to think it through. It probably should be available to the “root” only – could be quite dangerous.

I wonder what people think?

Submitted by dozment on Fri, 11/13/2009 Permalink

I just tried this for the first time. Very cool! Thanks, Ole! Would be nice to have it as a tool in the GUI or as a script. Could be very dangerous, though.