Enable/Disable extensions via program


is there any way enable/disable an extension via a programming interface?
The reason is to allow an external application (Hotel Management) to enable/disable a phone to do paying calls.
When the application checks in a new customer, the phone of the room assigned to this customer has to be enabled, and at customer checkout the phone must be disabled in order to prevent “non billable” phone calls.

Someone suggested to have a context for “disabled” extensions and have extension go in and out of this context; i understand this, and i know how to do it with the web interface, but cannot imagine how to do it with a program.

Thanks in advance for responding


kranz, If you are in the US you’ll have some interesting legel issues. The phones will need to ALWAYS dial 0 and 911, and I’m guessing any internal hotel number is probably a good thing.

If not and there is a emergency god help you.

What you want is a custom context that before it dials checks the number for internal and allows it, if not internal then check a database to see if that room is active and allow external calls or not.

Not something FreePBX is build to do, but something that can easly be done with some custom app coding.

thanks for your answer.

No, i’m not in the US, nonetheless I’m obviously aware of emergency issues, and if you read my post you will find that i am looking for a method to restrict a phone from doing toll calls (not internal or emergency calls) while the room is not assigned to a customer.

I also know that with some custom coding this can be done.

The question I posed was (and definitely is): Any idea about how to do this coding?

Your post suggests to look at the pòroblem from a different point of view: to use a custom app for dialing instead of toggling an extension between two different contexts. Do you think this can be done with AGI scripting? Can you make some suggestion?



Sorry when I read "customer checkout the phone must be disabled " I took it to mean just that, disable the phone.

Yes a agi script can be used to do it, since you have a specific need to integrate it into a existing app thsi will be a challange as I’ll guess nobody here knows that app. It is possible to create a custom webpage that if constructed properly would allow you to just change the context of the phone from one to another.

I’m not the proper person to tell you how to go about doing the coding but have you looked at any of the agi scripts that exist? there are many on the box that can be used as the basis to start from.

If you go to http://www.freepbx.org/book/export/html/1849 and scroll down you will see information on the Custom Contexts module. You could use it to create two sets of contexts, one that allows access to all routes, and the other that allows access only to no-cost routes and emergency calls. This creates a dropdown in each extension’s page that allows selecting the desired context, so you could simply go to an extension’s page and change the context. Call one context “full access” and the other “limited access” and in the limited one deny access to the outbound routes that handle chargeable calls. It will take a little work to set it up but once you have it figured out it will be quite easy to change an extension from one context to another.

Just one note, however - Custom Contexts is an unsupported module so at some point you may have to make a choice between upgrading FreePBX and having Custom Contexts stop working, or keeping Custom Contexts and not upgrading FreePBX. Thankfully that has not happened so far.

Thanks for the caveat about relying on custom, officially unsupported extensions, this is something i wasn’t taking into the right account.
As regards the specific question, I already have set up the two different contexts and called them “enabled rooms” and “disabled rooms”.

I need to allow an external program to assign/unassign extensions to these two contexts, because the person who does check-in check-out of customers at the reception desk needs to use only one program interface, and this is not the admin panel of freepbx, but the hotel management application.

SO i’m looking for hints and tips about how to do this customization: agi scripts? c program using tcp sockets? Taken by deep sadness I even thought of using some keyboard automation tool like autoit to do the job…

Again, hope some good folk lends me a helping hand…

Do you know if the hotel management app has a web interface wherein you could query the room status using CURL? Then the custom context could make the decision whether or not to allow toll calls.

This would be a relatively simple custom context and it wouldn’t require constant flipping of the extension’s settings. The extension would always be enabled, with the same custom context, and the context would make a real-time decision based on the response from the hotel app.

this is something i can try for sure. I do not know if the application has a web interface, but it surely uses a database.

Starting from this point, i can write a small web app that queries the room status, ie a ruby on rails app that exposes the room status with a REST interface so that using curl or wget i can invoke a url and obtain an xml file with the room status.

I still do not know how to invoke curl or wget form an agi macro nor how to process the result and decide if to allow dialing or not, but this is the RTFM activity i have to do in the next few days.

Thanks again because your suggestion helped to understand the “big picture”.

I issued the CURL right from the context itself, not via AGI. I can provide a sample if you like.