Ticket #1447 (closed Module Submissions: fixed)

Opened 4 years ago

Last modified 3 months ago

Custom Contexts Module

Reported by: naftali5 Assigned to: RobThomas
Priority: minor Milestone: 2.3
Component: Third Party Module Version: SVN-HEAD
Keywords: Custom Context Tennant Routing Restrict Cc:
Confirmation: Confirmed SVN Revision (if applicable):
Backend Engine: All Backend Engine Version:

Description (Last modified by gregmac)

Note: this should be integrated to core, #1690


One feature which was a bit lacking in asterisk/freePbx was the ability to easily create multiple tennants.
A number of improvements have been made.
1) inbound routing based on zap channel - i used to have to hack it by putting each zap channel in its own context.
2) authtype = database allows for dividing extension ranges
the main problem for me was outbound routing...
I wanted some extensions to dial out one route, and others out another route.
I had to create a custom context for each, then place each in their own custom context, then include all of the contexts which they should have access to. This became a nuisance as each module added its own context to from-internal-additional which could not be included as it also contains outbuond-allroutes.
The purpose of this module is to dynamically list all contexts included in any contexts you choose, and allow you to create custom contexts which can include any of these all without config editing.
As an added bonus, I added a select list to the devices/extensions page to allow you to easily select any of your custom contexts to place the device in.
I left this as minor just because I don't want anyone getting upset at me, but for me, at least, this is a major relief. :)

Attachments

customcontexts-0.0.1.tgz (5.0 kB) - added by naftali5 on 11/27/06 01:11:14.
Beta Release - please critique - took me only one day ;)
customcontexts-0.1.1.tgz (9.0 kB) - added by naftali5 on 12/10/06 22:18:44.
Version 0.1.1 Still Beta but fully functional!- Please test and post comments!
customcontexts-0.1.2.tgz (9.6 kB) - added by naftali5 on 12/13/06 15:26:20.
version 0.1.2
customcontexts-0.1.3.tgz (9.9 kB) - added by naftali5 on 12/13/06 23:12:34.
version 0.1.3 - new feature
customcontexts-0.2.0.tgz (10.3 kB) - added by naftali5 on 12/14/06 14:41:48.
version 0.2.0 I'm going to call this a new feature, see changelog
customcontexts-0.2.1.tgz (10.5 kB) - added by naftali5 on 12/14/06 21:08:46.
version 0.2.1 New Feature
customcontexts-0.2.2.tgz (10.6 kB) - added by naftali5 on 12/14/06 22:40:23.
version 0.2.2 bugfix
customcontexts-0.3.0.tgz (12.2 kB) - added by naftali5 on 12/16/06 22:51:47.
version 0.3.0 New Features see changelog
customcontexts-0.3.1.tgz (12.5 kB) - added by naftali5 on 12/17/06 01:39:47.
version 0.3.1 minor changes
customcontexts-0.3.2.tgz (13.1 kB) - added by naftali5 on 12/18/06 00:06:34.
version 0.3.2 new features
customcontexts-0.3.3.tgz (14.3 kB) - added by naftali5 on 12/21/06 21:40:51.
version 0.3.3 bugfix and features see changlelog

Change History

11/27/06 01:11:14 changed by naftali5

  • attachment customcontexts-0.0.1.tgz added.

Beta Release - please critique - took me only one day ;)

11/27/06 07:25:47 changed by p_lindheimer

  • version changed from 2.2beta3 to SVN-HEAD.

Someone will have a look.

12/03/06 11:11:30 changed by p_lindheimer

  • milestone changed from 2.2 to 2.3.

12/10/06 22:17:15 changed by naftali5

Ok, maybe if I add some features it will get more attention! ;)

Version 0.1.1 - now has optional Time Groups which allows you to name a set of times to enable the user to not only deny or allow access to certain dialplan contexts, but to control access to each context by time, date or day also.
This would, as a side benefit, take care of #774 (which i was anyhow thinking of implementing as its own module, to allow other modules access to the time conditions of it, but decided against that because I allow multiple time matches per saved time group, which works well for my purpose (includes) but would not work easily with a GotoIfTime?)

BTW: I have a couple more modules up my sleeve, (hint: #691, #1479) but I figured I'd test the waters with this one since it seemed to be the most sought after. I know you guys are busy trying to put out 2.2 final, but what can I do to get this thing into the module repository?

naftali

12/10/06 22:18:44 changed by naftali5

  • attachment customcontexts-0.1.1.tgz added.

Version 0.1.1 Still Beta but fully functional!- Please test and post comments!

(follow-up: ↓ 7 ) 12/10/06 23:21:24 changed by gregmac

I've started to look into this, but it's my opinion that we build this into core, since it's a critical feature that many other modules could use.

We're also still deciding the future of the gui API. At this point, it looks like guielements is going to be replaced by something more well designed, but it's not clear what exactly, just yet. we're trying to limit the use of it right now to avoid reprogramming lots of stuff (just a heads up).

Taking a quick look .. the customcontexts_module table is not needed, that information is already managed by the freepbx module system. I'm also unclear of what the separate *_list tables are for? some functions (with 'admin' in the name) use those, while the other ones use the tables without _list.

12/10/06 23:41:18 changed by naftali5

If you'd like to build it into the core, that's fine, but it seems not to be happening. There have been dozens of feature requests about this point open for months! :(
I do like my implementation, though, as it allows quite a bit of control and flexibility.
If you do build it into the core, feel free to use my ideas/code

I realized already that although gui elements seemed to be the new thing, they were not the solution to everything. It would not take much time though to port my code to any new gui system that is used.

You're right about the version variable, that was added at last minute, but I did want to be able to query for my module name, and display name, neither of which I could access from the modules table.

Sorry if my comments in the file were not enough. In order to make available to the user all of the contexts generally included in from-internal-additional, I had to know them. I did not want to rely on a predefined set of includes which I would ship because I wanted to allow for new modules/features and besides, every outbound route becomes a new context. Therefore I hook the hookGet_config and store all of the contexts I can get my hands on into the table customcontexts_includes_list. The way I know which contexts to parse for includes is the table customcontexts_contexts_list. These 2 tables are ONLY for the purpose of listing available contexts to Alow/Deny!!!!!!

The remaining tables are used to store the actual custom contexts and their includes.
The admin page (and all admin functions) are used to allow the admin to tell me where to look for/parse includes (eg. from-internal-additional, outbound-allroutes, etc.) and to type a simple description for each include so it shows up nicely on the Custom Contexts page for the user. The actual custom contexts are created/filled on the Custom Contexts page not the Admin page.
I put quite a bit of thought into the design, so please comment if you feel something should be done differently. Perhaps it would be lees confusing if the Admin page were under the tools menu... In case you haven't noticed, this module has 3 pages.

12/11/06 06:57:44 changed by rrizzi7210

For help installing read Modules Help.

(in reply to: ↑ 4 ) 12/11/06 07:25:15 changed by rrizzi7210

Notwithstanding that this is a very well done implementation of a much needed feature, I may have found something (a minor bug). I'm running freePBX 2.2.0rc1.

I installed version 0.1.1 and created a Context called "Test" using Custom Contexts option. Then, after saving/submitting and doing backend reload, I removed it, and did a backend reload again.

Next, I created a new context using Custom Contexts option again, but with a different name, and the original now referred to as "ext-test" is still showing up under "Internal Dialplan" with Allow/Deny listbox control to right.

(follow-up: ↓ 9 ) 12/11/06 11:04:44 changed by naftali5

not sure for whom you posted the link to ModulesHelp? ... I just need help getting this into the online repository ;)

what you found is not a bug. it is a feature, and not part of my module at all!

It is part of the Feaure Codes/Core and is used to test your dialplan (inbound routes, fax, etx.) and is as follows.

[ext-test]
include => ext-test-custom
exten => 7777,1,Goto(from-pstn,s,1)
exten => 666,1,Goto(ext-fax,in_fax,1)
exten => h,1,Macro(hangupcall,)

; end of [ext-test]

(in reply to: ↑ 8 ) 12/12/06 12:45:14 changed by rrizzi7210

My comment regarding help installing was for people that might not know exactly how to take your work and put it into production on their machine. I had never installed a module onto a production/development system prior to learning about your module. I did a little research to learn how, and just thought I would save the next person the trouble of doing the research.

BTW...I implemented your module in a multi-tenant production environment for one of my existing customers with great success. It was something I was dreading until I found your module. It makes such much more sense to do it the way you did in the module, so that custom code I normally write can't be lost/overwritten by others, etc.

I haven't had time to play with the other two pages in your module, but I will this weekend on my development system. Great work!!!

Replying to naftali5:

not sure for whom you posted the link to ModulesHelp? ... I just need help getting this into the online repository ;)

what you found is not a bug. it is a feature, and not part of my module at all!

It is part of the Feaure Codes/Core and is used to test your dialplan (inbound routes, fax, etx.) and is as follows. {{{ [ext-test] include => ext-test-custom exten => 7777,1,Goto(from-pstn,s,1) exten => 666,1,Goto(ext-fax,in_fax,1) exten => h,1,Macro(hangupcall,) ; end of [ext-test] }}}

12/13/06 10:36:02 changed by wiseoldowl

This works great except for a bug in version 0.1.1 - if, after this module is installed, you create a new outbound route, and move it up so it's not the last one (thereby changing the sequence of routes), the custom contexts module gets confused and starts displaying both the old and new route sequences. Assuming that can be fixed, I would hope that this module could be included as a standard module soon because it seems really useful, even for small home users that may want to restrict certain extensions either by time or by disallowing certain features (like ChanSpy? and ZapBarge?!), or by the use of certain routes (no calls that cost money from kids' rooms, etc.).

Assuming this does get included, may I suggest that some new system recordings be considered, for the people that would be using this module in real business situations - for home use I'd just record something that says "Hey! Why are you dialing THAT number from YOUR telephone?!" :-)

1) "I'm sorry, the call you have made cannot be completed from the extension you are using." (or "... the number you have dialed cannot ..." or some variation thereof).

2) "If you feel you have reached this recording in error, please contact ..."

3) "... your system administrator." (the alternate ending would be "customer service" which is already an included recording).

12/13/06 11:40:09 changed by wiseoldowl

I decided to try and write some preliminary usage instructions for this module, based on an IRC conversation I had with naftali5 last night (he can correct me if I am wrong about anything, but I figured it might be helpful to at least get something out so people could experiment with this module. I can't write code, but every now and again I can write barely-literate documentation):

Unofficial usage instructions for the Custom Contexts module:

Most users will not need to do anything in the Custom Contexts Admin section - that is for advanced users. When you "add" or "remove" contexts from the Admin, you are not really adding or removing anything, you are just telling the module where to find all of the includes to list. By default there are three includes which should be sufficient for most users: from-internal, from-internal-additional, and outbound-allroutes. So, skip the Custom Contexts Admin section until you feel comfortable making changes there.

The first thing that you will want to create is time groups, if you plan to use those. The reason for doing this first is so that they will become available in the drop down selections when you create your custom contexts. For each group you create, you can decide which times it should be available. You can define multiple times within one named group, and then each named group then becomes available along with allow/deny for each choice under a custom context (this will become clearer further down), so you can allow, deny, or choose your time group to allow only at specific times/dates/days.

One thing to bear in mind when creating time groups is that this module will not forcibly end calls in progress. So if, for example, you have "free" calling on a particular route from 9:00 PM to 7:00 AM, you probably don't want to set the end time right at 7:00 AM, because then someone could make a call at 6:59 and talk for several minutes into the non-free period.

Now, to actually create a Custom Context, you go to the Custom Contexts page, and add a context - note that the context name may NOT contain spaces. Then add a description (spaces are okay here) and submit.

Once the context is created, you can edit it to allow or disallow the features and routes you want a particular extension (or group of extensions) to have access to. Choose "Allow" or "Deny" for each application or route - you may wish to allow all, except for the items you specifically wish to restrict (for example, you probably want to restrict ChanSpy? and ZapBarge?!). If you have created any time conditions, it will also be possible to select those, to allow a feature or route to be accessed only during certain times.

One thing you need to watch out for is that the bottom item in the Internal Dialplan section is outbound-allroutes. If you allow outbound-allroutes, it will override the individual route selections in the following section. So if you want users of this context to have access to all outbound routes, you can just allow outbound-allroutes and ignore the individual route sections (leave them all set to "deny"). But if you want to select routes individually, then make sure that outbound-allroutes is set to "Deny". Of course, you could also use non-overlapping time conditions for outbound-allroutes and individual routes.

Finally, you need to go to your Extensions page and select each extension for which you wish to use a custom context. On each individual extension page, you should now see a dropdown to allow you to select a custom context. This drop-down is simply a convenient way to fill in the correct context in the "context" textbox. When you click on a custom context, it replaces whatever is currently in the "context" textbox with your new selection - if you choose "Default", it resets the extension back to the default "from-internal" context. Don't forget to click "Submit", and then click the red bar when you are all finished making changes.

NOTE that if you disable or uninstall the Custom Contexts module, you MUST reset all the extensions back to the default "from-internal" context. If you delete a time group, anyone who had that time limitation becomes "Allow" with no time restrictions. If you add a new outbound route, by default that route is set as "Deny" in the Custom Contexts, so you should go into each context and set it to "Allow" (or use a time condition) where appropriate.

12/13/06 12:56:25 changed by naftali5

Kudos to you wiseoldowl!!!
You ceratainly made the time I spent with you last night well worthwhile.
I could not have done better myself. :)
hope you dont mind I took the liberty of posting it on the wiki
naftali
p.s. thanks for pointing out that bug. I had it fixed already in my development version, it can simply be put as - deleting a route doesn't remove it from the list.
One more caveat I forgot to mention. After you add an outbound route, it is not available until you reload.
Lastly, I must thank you for one more thing. I read your post, and thought to myself "change the sequence of the routes"!?!? I knew you could change the sequence of trunks used, and wished I could change the sequence of routes! I checked, and it is there! I don't know when this feature was added, but I don't think it was there in AMP.

12/13/06 15:26:20 changed by naftali5

  • attachment customcontexts-0.1.2.tgz added.

version 0.1.2

12/13/06 15:28:50 changed by naftali5

Changelog

*0.1.2* Bugfixes- deleted routes, etc. now are removed.
        Context tests for spaces and illegal chars.
        Moved admin to tools to reduce confusion.
        Added option to allow entire internal dialplan. (Usefull for time limit on everything)
        Made description for outbound-allroutes clearer that allowing overrides to allow all routes.
*0.1.1* Still Beta, added time groups and bugfixes
*0.0.1* Beta release

12/13/06 23:12:34 changed by naftali5

  • attachment customcontexts-0.1.3.tgz added.

version 0.1.3 - new feature

12/13/06 23:13:54 changed by naftali5

version 0.1.3

Changelog'

*0.1.3* Made it obvious when allowing one include may allow another entire context.
*0.1.2* Bugfixes- deleted routes, etc. now are removed.
        Context tests for spaces and illegal chars.
        Moved admin to tools to reduce confusion.
        Added option to allow entire internal dialplan. (Usefull for time limit on everything)
        Made description for outbound-allroutes clearer that allowing overrides to allow all routes.
*0.1.1* Still Beta, added time groups and bugfixes
*0.0.1* Beta release

12/13/06 23:16:23 changed by naftali5

Known Issue

outbound routes are not sorted within your custom contexts as they are normally.

12/14/06 14:41:48 changed by naftali5

  • attachment customcontexts-0.2.0.tgz added.

version 0.2.0 I'm going to call this a new feature, see changelog

12/14/06 14:44:00 changed by naftali5

Changelog

*0.2.0* Added priority feature to allow the user to control in what order the allowed contexts are included.

The feature is optional, you can disable it using a link on the page.

If you do disable it, your previous prioritizing is lost on the next submit.

12/14/06 21:08:46 changed by naftali5

  • attachment customcontexts-0.2.1.tgz added.

version 0.2.1 New Feature

12/14/06 21:09:58 changed by naftali5

Version 0.2.1 Changelog

*0.2.1* Added Duplicate Context option to easily copy an entire set of rules.

12/14/06 22:40:23 changed by naftali5

  • attachment customcontexts-0.2.2.tgz added.

version 0.2.2 bugfix

12/14/06 22:42:54 changed by naftali5

version 0.2.2 Changelog

*0.2.2* Bugfix: Duplicate Context now copies the priority also.

12/14/06 23:40:02 changed by n3glv

I posted the gz files on a web space that I have access to. This centos wget bug is bogus. For some assorted asterisk files go to. http://www.zelie.com/~n3glv/asterisk/

12/16/06 22:51:47 changed by naftali5

  • attachment customcontexts-0.3.0.tgz added.

version 0.3.0 New Features see changelog

12/16/06 22:55:47 changed by naftali5

Version 0.3.0 Changelog

*0.3.0* New Features:
Allow or Deny based on pattern matching.
Failover Destination (one for regular extension, one for failed feature codes)
Bugfixes:
Adjusted Gui, Duplicate context, now duplicates the description too.

code to download...

wget http://www.freepbx.org/trac/attachment/ticket/1447/customcontexts-0.3.0.tgz?format=raw
mv customcontexts-0.3.0.tgz?format=raw customcontexts-0.3.0.tgz
tar -xzvf customcontexts-0.3.0.tgz

12/17/06 01:39:47 changed by naftali5

  • attachment customcontexts-0.3.1.tgz added.

version 0.3.1 minor changes

12/17/06 01:43:46 changed by naftali5

Version 0.3.1 Changelog

*0.3.0* Now prompts on delete. After duplicate you are editing new context.

code to download

wget http://www.freepbx.org/trac/attachment/ticket/1447/customcontexts-0.3.1.tgz?format=raw
mv customcontexts-0.3.1.tgz?format=raw customcontexts-0.3.1.tgz
tar -xzvf customcontexts-0.3.1.tgz

12/17/06 01:45:38 changed by naftali5

Oops. forgot to document the biggest change. you can now rename contexts.

12/17/06 21:05:43 changed by RobThomas

  • owner set to RobThomas.
  • status changed from new to assigned.

I think this is a good one for 2.2 - whilst the guielems rewrite will happen in 2.3, this is a nifty module for 2.2. Any complaints?

12/18/06 00:06:34 changed by naftali5

  • attachment customcontexts-0.3.2.tgz added.

version 0.3.2 new features

12/18/06 00:16:11 changed by naftali5

Version 0.3.2 Changelog

*0.3.2* Optional PIN to protect failover destination.
Contexts can now be used as destinations. An IVR menu, Time Condition, etc. can now send a caller into a custom context.

(This last feature requires a bugfix in 2.2 after rc1. bug #1549)

(the rest of the module will work without it)

code to download

wget http://www.freepbx.org/trac/attachment/ticket/1447/customcontexts-0.3.1.tgz?format=raw
mv customcontexts-0.3.2.tgz?format=raw customcontexts-0.3.1.tgz
tar -xzvf customcontexts-0.3.2.tgz

12/21/06 21:40:51 changed by naftali5

  • attachment customcontexts-0.3.3.tgz added.

version 0.3.3 bugfix and features see changlelog

12/21/06 21:42:32 changed by naftali5

Verision 0.3.3 Changelog

*0.3.3* Added Set All option to quickly allow/deny all.
Fixed bug which caused routes to be denied after rename/sort/or delete other route.

code to download (sorry it was wrong on last verison)

wget http://www.freepbx.org/trac/attachment/ticket/1447/customcontexts-0.3.3.tgz?format=raw
mv customcontexts-0.3.3.tgz?format=raw customcontexts-0.3.3.tgz
tar -xzvf customcontexts-0.3.3.tgz

01/08/07 11:46:49 changed by

  • milestone deleted.

Milestone 2.3 deleted

01/08/07 12:18:02 changed by vgster

  • milestone set to 2.3.

01/15/07 22:24:09 changed by gregmac

  • description changed.
  • svn_rev changed.
  • engine_version changed.

This should be integrated to core: see #1690

03/05/07 03:07:31 changed by pbrufal

There is a bug:

mysql> ALTER IGNORE TABLE customcontexts_contexts ADD dialrules VARCHAR( 1000 ) NULL; ERROR 1074: Too big column length for column 'dialrules' (max = 255). Use BLOB instead mysql> ALTER IGNORE TABLE customcontexts_contexts ADD dialrules VARCHAR( 255 ) NULL; Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0

Varchar only accepts 255 (in mysql 4.0)

(follow-up: ↓ 31 ) 09/19/07 19:42:21 changed by p_lindheimer

  • status changed from assigned to closed.
  • confirmation set to Confirmed.
  • resolution set to fixed.

Moved to Contributed Modules Repository

(in reply to: ↑ 30 ) 05/15/08 09:50:17 changed by orenyny

Replying to p_lindheimer:

Moved to Contributed Modules Repository

Hi,

Is this module still relevant ? Was it incorporated in the FPBX distribution ?

Thanks.

05/15/08 10:02:28 changed by p_lindheimer

It is located in svn under the contributed_modules branch. It is not officially part of FreePBX but you can use it at your own risk. There are not plans to incorporate it at this time because of planned changes that will gain the same functionality but break the way this module expects things.

08/16/08 09:28:37 changed by p_lindheimer

You can get the most updated version of this module (and other contributed modules here):

http://mirror.freepbx.org/modules/release/contributed_modules/

06/10/10 14:37:03 changed by naftali5

(In [9817]) re #1447, re #1690 - simple changes, just enough to make CustomContexts work with 2.8

06/11/10 07:45:06 changed by mbrevda

(In [9818]) re: #1447, #1690; reverting changes to make way for #4335

06/11/10 07:46:57 changed by mbrevda

(In [9819]) re #1447, #1690; reverting r9817 to make way for #4335