Restricting extensions access to routes
(Note. This is called 'RestrictedTrunk', but it actually restricts access to ROUTES, where you allocate which trunks you allow the user to use.)
This is so you can set up a range of extensions, and allocate trunk access per extension.
There are a couple of ways to do this, but as I'm a lazy bugger, I'd like to do this as easily as possible. This means having various outbound routes, and allowing extensions to only access some of them.
I probably should be able to mark an outbound route as 'Emergency' so it's applied to EVERY extension, and can not be disabled.
NOTE: This WILL require live access to a database, as trying to store all this in astdb will get too messy I believe.
Lets assume that people normally dial 0 for an outside line, and then the number. A standard dialplan match for this trunk would be "0|.". I'll be using Australian dialplans, feel free to convert this to your own local dialing patterns.
In this, all oubound calls go via trunk Zap/g0, except for mobile calls (04XXXXXXXX) which goes via IAX/VoipProvider
Emergency - Dialplan 0|000 Send to Zap/g0 Freecalls - Dialplan 0|1800XXXXXX Send to Zap/g0 LocalOnly - Diaplan 0|000 0|XXXXXXXX 0|07XXXXXXXX 0|13[1-9]XXX 0|130XXXXXXX Send to Zap/g0 AllAust 0|0XXXXXXXX Send to Zap/g0 Mobile 0|04XXXXXXXX Send to IAX/VoipProvider with a secondary trunk of Zap/g0 MobileZap 0|04XXXXXXXX Send to Zap/g0
Now you've split up your dialplans, you go into the Route Restrictions module.
In there you can do broad mappings - enter a range of extensions and apply or remove changes. To do fine tunings, you do that IN the extension. There'll be checkboxes with the outbound routes that it's allowed to access.
How is this done?
A modification to macro-dialout-trunk to check to see if that extension has permission to use that trunk.
Continuing on with our exampe above... We have extensions 600 to 699. Most extensions are only allowed to make free calls, and calls to local numbers. A considerable chunk are allowed mobile access, but their calls go through an IAX provider. Two people require Zaptel access to mobiles, so they are granted MobileZap?, and denied Mobile.
The exectives get all access, so they get International and AllAust?.
When you enable the module it goes through and creates and propogates a database (if it doesn't already exist) allowing access to all trunks from all extensions.
CREATE TABLE `routepermissions` ( `exten` int(11) NOT NULL, `trunkname` varchar(25) NOT NULL, `allowed` varchar(3) default 'YES', KEY `exten` (`exten`) )
FreePBX only cares about the priority of the trunk, not the name of the trunk. As there's no unique trunk identifier (which needs to be fixed, too), we can only rely on the name of it. This is currently not in the dialplan, so we need to add the trunk name when generating the routes. (Was a simple change, added in r7558 to core)