Freepbx:以编程方式添加扩展

Freepbx: Add Extension Programmatically

我试图以编程方式添加扩展。在那里我遇到了一些问题。我的代码是

<?php
$bootstrap_settings = array();
$bootstrap_settings['freepbx_auth'] = false;
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { 
  include_once('/etc/asterisk/freepbx.conf'); 
}

$vars = array(
"extension" => 9876543200,
    "name" => "Test",
    "devinfo_secret" => "testing",
    "devinfo_mediaencryption" => "sdes",
);

core_users_add($vars);
core_devices_add(9876543200,'pjsip','PJSIP/9876543200','fixed',9876543200,'Test');

并输出

[root@sg html]# php a.php
[FATAL] Fields are empty

Trace Back:

/var/www/html/admin/modules/core/Core.class.php:1389 die_freepbx()
 [0]: Fields are empty

/var/www/html/admin/modules/core/functions.inc.php:4227 FreePBX\modules\Core->convertRequest2Array()
 [0]: 9876543200
 [1]: pjsip
 [2]: 2

/var/www/html/a.php:18 core_devices_add()
 [0]: 9876543200
 [1]: pjsip
 [2]: PJSIP/9876543200
 [3]: fixed
 [4]: 9876543200
 [5]: Test

我尝试添加 PJSIP 扩展,但在 GUI 中我添加了 虚拟设备。我还需要添加媒体加密。谁能指导我?

我发现直接进入数据库更容易做到这一点。我没有对 pjsip 做任何事情,但这就是我创建 sip 扩展的方式。要弄清楚,最简单的方法是在创建用户时启用 general log in MySQL 并记录查询。之后,确保重新加载。

INSERT INTO users (
    extension, password, name, voicemail, ringtimer, noanswer, recording,
    outboundcid, sipname, noanswer_cid, busy_cid, chanunavail_cid,
    noanswer_dest, busy_dest, chanunavail_dest, mohclass, auditor_exttype
)
VALUES (
    '12345', '', 'Test', 'novm', '0', '', '', '',
    'test', '', '', '', '', '', '', 'default', 99
);

INSERT INTO devices (
    id, tech, dial, devicetype, user, description, emergency_cid
)
VALUES
    ('12345', 'sip', 'SIP/12345', 'fixed', '12345', 'Test', '')
;

INSERT INTO sip (
    id, keyword, data, flags
)
VALUES
    ('12345', 'secret', 'supersecre†', 2),
    ('12345', 'dtmfmode', 'rfc2833', 3),
    ('12345', 'canreinvite', 'no', 4),
    ('12345', 'context', 'from-internal', 5),
    ('12345', 'host', 'dynamic', 6),
    ('12345', 'trustrpid', 'yes', 7),
    ('12345', 'sendrpid', 'yes', 8),
    ('12345', 'type', 'friend', 9),
    ('12345', 'nat', 'yes', 10),
    ('12345', 'port', '5060', 11),
    ('12345', 'qualify', 'yes', 12),
    ('12345', 'qualifyfreq', '60', 13),
    ('12345', 'transport', 'udp', 14),
    ('12345', 'avpf', 'no', 15),
    ('12345', 'icesupport', 'no', 16),
    ('12345', 'encryption', 'yes', 17),
    ('12345', 'callgroup', '', 18),
    ('12345', 'pickupgroup', '', 19),
    ('12345', 'disallow', '', 20),
    ('12345', 'allow', '', 21),
    ('12345', 'dial', 'SIP/12345', 22),
    ('12345', 'mailbox', '12345@device', 23),
    ('12345', 'deny', '0.0.0.0/0.0.0.0', 24),
    ('12345', 'permit', '0.0.0.0/0.0.0.0', 25),
    ('12345', 'account', '12345', 26),
    ('12345', 'callerid', 'device <12345>', 27)
;