Freepbx Two Companies

Hi guys,

I have found a number of articles on this but I do not seem to be able to find a solution.
In short I have two companies that I wish to run on the same PBX. Therefore I need one company to use one trunk and one to use another.

I understand that custom contexts can be used by editing extensions_custom.conf. What I would like is that from-internal blocks all calls and say company1 uses trunk 1 and company2 uses trunk2. I want extensions to be completely blocked unless the context is changed to either company1 or company2 to avoid mistakes.
I need this for all extensions.

An alternative which I wouldn’t mind knowing is say, company1 has extensions with 3 digits and company2 has 4 digits. Could you potentially also say use pattern matching to check the amount of digits and redirect t to a specific trunk depending on this?

Any info you can give me would be much appreciated, I am struggling to wrap my head round this.

The proper way to do this is to ise virtual machines anD give each their own instance. You can do sewerage routing, ranges, etc but that is not secure nor is it truly segregated

Particularly useful in my day job, I do a lot of EoIP (effluent over IP)

Finally go round to a solution for this after reading every bit of documentation I could get my hands on.

I used the following code in extensions_custom.conf:

include => from-internal
exten => _X.,1,Set(_COMPANY=company1)
include => macro-dialout-trunk-predial-hook

include => from-internal
exten => _X.,1,Set(_COMPANY=company2)
include => macro-dialout-trunk-predial-hook

I used the following code in extensions.conf

exten => s,1,Set(PREDIAL_HOOK_RET=)
exten => s,n,Set(DIAL_TRUNK=${IF($[ ${COMPANY} = company2]?2:${IF($[ ${COMPANY} = company1]?1:99)})})
exten => s,n,Set(OUTBOUND_GROUP=${IF($[ ${COMPANY} = company2]?2:${IF($[ ${COMPANY} = company1]?1:99)})})
exten => s,n,ExecIf($[${ISNULL(${COMPANY})}]?Hangup())
exten => s,n,MacroExit()

I am sure this could be tidied and improved, but for now, I have the solution I need. Hopefully this will help someone else.