
Sobre o que realmente se trata?
Trabalhando em uma grande empresa, e em uma empresa de médio porte com poucos filiais, cada vez mais se pensa em otimizar recursos, simplificar a administração e padronizar tudo e todos.
Por exemplo, temos vários (bem, não poucos) do mesmo tipo de filiais para 10-100 funcionários. A telefonia pode ser organizada de diferentes maneiras:
Pegue uma solução pronta na nuvem do provedor
Instale seu próprio mini-servidor e asterisco em cada filial
Faça um único asterisco no centro
As 2 primeiras opções, é claro, ocorrem, mas têm desvantagens suficientes. Esta não é a conveniência de manter várias pequenas instâncias, é também uma questão financeira e alguns outros pontos.
, , , , . , , . , , 3 , 6 . - 6 ("6 ! !"), 6 .
, - SIP . , -, .
, . , - , -. . ? , - , , - .
18.1 PJSIP .
? , . - . , " ".
(Numbers), . , ?
, (Number)
- ? (Secret)
- , , (domain)
CID -
: , DTMF, -
Flags - -, . , , .

, . ? , , . - , , VIEW. , , . 3 :
Endpoints (ps_endpoints)
(ps_auths)
Aors (ps_aors)
, , "" PJSIP. SQL:
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `ps_aors` AS select concat(`Numbers`.`Number`,if(`Numbers`.`domain` is not null,concat('@',`Numbers`.`domain`),'')) AS `id`,180 AS `default_expiration`,2 AS `max_contacts`,30 AS `minimum_expiration`,'yes' AS `remove_existing`,'' AS `contact` from `Numbers`;
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `ps_auths` AS select concat(`Numbers`.`Number`,if(`Numbers`.`domain` is not null,concat('@',`Numbers`.`domain`),'')) AS `id`,'userpass' AS `auth_type`,3600 AS `nonce_lifetime`,`Numbers`.`Secret` AS `password`,`Numbers`.`Number` AS `username`,`Numbers`.`domain` AS `realm` from `Numbers` where `Numbers`.`Secret` <> '';
CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW `ps_endpoints` AS select concat(`Numbers`.`Number`,if(`Numbers`.`domain` is not null,concat('@',`Numbers`.`domain`),'')) AS `id`,concat('transport-',lcase(`Numbers`.`Protocol`)) AS `transport`,concat(`Numbers`.`Number`,if(`Numbers`.`domain` is not null,concat('@',`Numbers`.`domain`),'')) AS `aors`,if(`Numbers`.`Secret` <> '',concat(`Numbers`.`Number`,if(`Numbers`.`domain` is not null,concat('@',`Numbers`.`domain`),'')),NULL) AS `auth`,'SIP' AS `context`,'all' AS `disallow`,concat('ulaw,alaw,opus',if(find_in_set('Video',`Numbers`.`Flags`),',h263,h261,h263p,h264','')) AS `allow`,concat(`Numbers`.`Number`,if(`Numbers`.`domain` is not null,concat('@',`Numbers`.`domain`),'')) AS `outbound_auth`,concat(`Numbers`.`CID`,' <',`Numbers`.`Number`,'>') AS `callerid`,if(`Numbers`.`Protocol` = 'TLS','sdes','no') AS `media_encryption`,`Numbers`.`PickupGroup` AS `named_pickup_group`,2 AS `device_state_busy_at`,concat('vRecord=',if(find_in_set('Record',`Numbers`.`Flags`) > 0,'yes','no'),';','vRussia=',if(find_in_set('Russia',`Numbers`.`Flags`) > 0,'yes','no'),';','vAbroad=',if(find_in_set('Abroad',`Numbers`.`Flags`) > 0,'yes','no'),';','vVoicemail=',if(find_in_set('Voicemail',`Numbers`.`Flags`) > 0,'yes','no'),';','vFilterCID=no') AS `set_var`,`Numbers`.`NumberID` AS `callerid_tag`,'username,auth_username,ip' AS `identify_by` from `Numbers`;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
. - - "" "":
, 5 . , . , .
, 3 , , , , , 101, 102, "" 007 ..
, Numbers .
Numbers:

, " " , , .
ps_endpoints

, - Numbers.
ps_auth

ps_aors

, . , Numbers, .
, . - id. 5 , - . 3 @ . , , - .
. , . AOR endpointa , .. @, . , (id) , AOR . . - AOR , . , .
, , .
pjsip.conf

, .
disable multi domain
, no. , . - . , , yes. 2 . .
endpoint identifier order
, , . = ip,username. , , .. IP . , username, endpoint .
, .
res config mysql.conf
, - :

extconfig.conf

, .
ps_contacts , astdb.
Spoiler
sorcery.conf
. , , .

.
, ?
, endpoint :

, . " " . " " .
, . .., 5 :
Dial(PJSIP/19960)
3
Dial(PJSIP/123@test3)
, , .
?
Microsip, :

101 . ?

PS:
- .
- , , . , .
domains:
domain (VARCHAR) | code (VARCHAR)
Preenchemos, por exemplo, assim:
test2 | 01
test3 | 02
Claro, você pode pegar qualquer código de branch - até mesmo 1 caractere. Estamos determinados com acesso a agências. Por exemplo, eu tenho acesso à "cidade" depois das 9, e vou levar 8 para as filiais. Você pega o que for conveniente para você. Pelo menos * (asterisco).
Ligar a domínios mesa com os domínios identificador em extconfig.conf . Escrevemos um dialplan:
exten => _8XXXXX,1,NoOp(Call from ${CALLERID(all)} to filial ${EXTEN:1:2})
same => n, Set(domain=${REALTIME_FIELD(domains,code,${EXTEN:1:2},domain)})
same => n, GotoIF($[ "${domain}" = "" ]?GotoError) ;
same => n, Dial(PJSIP/${EXTEN:3}@${domain})
same => n, Hangip
No total, nós discamos 801123 no telefone e chegamos à filial test2 em 123
Para facilitar a administração, você pode adicionar outra restrição de chave:
Números .domain - CHAVE ESTRANGEIRA -> domínios .domain
Isso impedirá que você perca domínios durante a edição.