Create sip account manual

I use centos 6.3, asterisk 11.2.1, freepbx 2.11, linphone.

I want to dynamic create sip account.

First, I create sip account “1000” “1001” by freepbx gui as a template.

I manual create sip account 5079 and 5080.
I manual insert record into table devices, users, sip.
mysql> select * from users;
±----------±---------±-----±----------±----------±---------±----------±------------±--------±-------------±---------±----------------±--------------±----------±-----------------±---------+
| extension | password | name | voicemail | ringtimer | noanswer | recording | outboundcid | sipname | noanswer_cid | busy_cid | chanunavail_cid | noanswer_dest | busy_dest | chanunavail_dest | mohclass |
±----------±---------±-----±----------±----------±---------±----------±------------±--------±-------------±---------±----------------±--------------±----------±-----------------±---------+
| 1000 | | 1000 | novm | 0 | | | | | | | | | | | default |
| 1001 | | 1001 | novm | 0 | | | | | | | | | | | default |
| 2000 | | 2000 | novm | 0 | | | | | | | | | | | default |
| 2001 | | 2001 | novm | 0 | | | | | | | | | | | default |
| 1002 | | 1002 | novm | 0 | | | | | | | | | | | default |
| 3000 | | 3000 | novm | 0 | | | | | | | | | | | default |
| 5079 | | 5079 | novm | 0 | | | | | | | | | | | default |
| 4000 | | 4000 | novm | 0 | | | | | | | | | | | default |
| 5080 | | 5080 | novm | 0 | | | | | | | | | | | default |
| 3001 | | 3001 | novm | 0 | | | | | | | | | | | default |
±----------±---------±-----±----------±----------±---------±----------±------------±--------±-------------±---------±----------------±--------------±----------±-----------------±---------+
mysql> select * from devices;
±-----±-----±---------±-----------±-----±------------±--------------+
| id | tech | dial | devicetype | user | description | emergency_cid |
±-----±-----±---------±-----------±-----±------------±--------------+
| 1000 | sip | SIP/1000 | fixed | 1000 | 1000 | |
| 1001 | sip | SIP/1001 | fixed | 1001 | 1001 | |
| 2000 | sip | SIP/2000 | fixed | 2000 | 2000 | |
| 2001 | sip | SIP/2001 | fixed | 2001 | 2001 | |
| 1002 | sip | SIP/1002 | fixed | 1002 | 1002 | |
| 3000 | sip | SIP/3000 | fixed | 3000 | 3000 | |
| 5079 | sip | SIP/5079 | fixed | 5079 | 5079 | |
| 4000 | sip | SIP/4000 | fixed | 4000 | 4000 | |
| 5080 | sip | SIP/5080 | fixed | 5080 | 5080 | |
| 3001 | sip | SIP/3001 | fixed | 3001 | 3001 | |
±-----±-----±---------±-----------±-----±------------±--------------+
mysql> select * from sip where id=1000 order by flags;
±-----±------------±----------------±------+
| id | keyword | data | flags |
±-----±------------±----------------±------+
| 1000 | secret | 123456 | 2 |
| 1000 | dtmfmode | rfc2833 | 3 |
| 1000 | canreinvite | yes | 4 |
| 1000 | context | from-internal | 5 |
| 1000 | host | dynamic | 6 |
| 1000 | trustrpid | yes | 7 |
| 1000 | sendrpid | no | 8 |
| 1000 | type | friend | 9 |
| 1000 | nat | yes | 10 |
| 1000 | port | 5060 | 11 |
| 1000 | qualify | yes | 12 |
| 1000 | qualifyfreq | 60 | 13 |
| 1000 | transport | udp | 14 |
| 1000 | encryption | no | 15 |
| 1000 | callgroup | | 16 |
| 1000 | pickupgroup | | 17 |
| 1000 | disallow | | 18 |
| 1000 | allow | | 19 |
| 1000 | dial | SIP/1000 | 20 |
| 1000 | accountcode | | 21 |
| 1000 | mailbox | 1000@device | 22 |
| 1000 | deny | 0.0.0.0/0.0.0.0 | 23 |
| 1000 | permit | 0.0.0.0/0.0.0.0 | 24 |
| 1000 | account | 1000 | 25 |
| 1000 | callerid | device <1000> | 26 |
±-----±------------±----------------±------+
mysql> select * from sip where id=5079 order by flags;
±-----±------------±----------------±------+
| id | keyword | data | flags |
±-----±------------±----------------±------+
| 5079 | secret | 123456 | 2 |
| 5079 | dtmfmode | rfc2833 | 3 |
| 5079 | canreinvite | yes | 4 |
| 5079 | context | from-internal | 5 |
| 5079 | host | dynamic | 6 |
| 5079 | trustrpid | yes | 7 |
| 5079 | sendrpid | no | 8 |
| 5079 | type | friend | 9 |
| 5079 | nat | yes | 10 |
| 5079 | port | 5060 | 11 |
| 5079 | qualify | yes | 12 |
| 5079 | qualifyfreq | 60 | 13 |
| 5079 | transport | udp | 14 |
| 5079 | encryption | no | 15 |
| 5079 | callgroup | | 16 |
| 5079 | pickupgroup | | 17 |
| 5079 | disallow | | 18 |
| 5079 | allow | | 19 |
| 5079 | dial | SIP/5079 | 20 |
| 5079 | accountcode | | 21 |
| 5079 | mailbox | 5079@device | 22 |
| 5079 | deny | 0.0.0.0/0.0.0.0 | 23 |
| 5079 | permit | 0.0.0.0/0.0.0.0 | 24 |
| 5079 | account | 5079 | 25 |
| 5079 | callerid | device <5079> | 26 |
±-----±------------±----------------±------+

I manual append content into sip_additional.conf.
[1000]
deny=0.0.0.0/0.0.0.0
secret=123456
dtmfmode=rfc2833
canreinvite=yes
context=from-internal
host=dynamic
trustrpid=yes
sendrpid=no
type=friend
nat=yes
port=5060
qualify=yes
qualifyfreq=60
transport=udp
encryption=no
callgroup=
pickupgroup=
dial=SIP/1000
mailbox=1000@device
permit=0.0.0.0/0.0.0.0
callerid=1000 <1000>
callcounter=yes
faxdetect=no

[1001]

[5079]
deny=0.0.0.0/0.0.0.0
secret=123456
dtmfmode=rfc2833
canreinvite=yes
context=from-internal
host=dynamic
trustrpid=yes
sendrpid=no
type=friend
nat=yes
port=5060
qualify=yes
qualifyfreq=60
transport=udp
encryption=no
callgroup=
pickupgroup=
dial=SIP/5079
mailbox=5079@device
permit=0.0.0.0/0.0.0.0
callerid=5079 <5079>
callcounter=yes
faxdetect=no

[5080]

I manual append content into extensions_additional.conf.
[ext-local]
include => ext-local-custom

exten => 1000,1,Set(__RINGTIMER=${IF($[${DB(AMPUSER/1000/ringtimer)} > 0]?${DB(AMPUSER/1000/ringtimer)}:${RINGTIMER_DEFAULT})})
exten => 1000,n,Macro(exten-vm,novm,1000,0,0,0)
exten => 1000,n(dest),Set(__PICKUPMARK=)
exten => 1000,n,Goto(${IVR_CONTEXT},return,1)
exten => 1000,hint,SIP/1000

1001…

exten => 5079,1,Set(__RINGTIMER=${IF($[${DB(AMPUSER/5079/ringtimer)} > 0]?${DB(AMPUSER/5079/ringtimer)}:${RINGTIMER_DEFAULT})})
exten => 5079,n,Macro(exten-vm,novm,5079,0,0,0)
exten => 5079,n(dest),Set(__PICKUPMARK=)
exten => 5079,n,Goto(${IVR_CONTEXT},return,1)
exten => 5079,hint,SIP/5079

5080…

[from-did-direct-ivr]
include => from-did-direct-ivr-custom

exten => 1000,1,Macro(blkvm-clr,)
exten => 1000,n,Set(__NODEST=)
exten => 1000,n,Goto(from-did-direct,1000,1)

1001…

exten => 5079,1,Macro(blkvm-clr,)
exten => 5079,n,Set(__NODEST=)
exten => 5079,n,Goto(from-did-direct,5079,1)

5080…

and then I execute “sip reload” in asterisk-cli.
I don’t execute “amportal restart”.
asterisk*CLI> sip show peers
Name/username Host Dyn Forcerport ACL Port Status Description
1000/1000 (Unspecified) D N A 0 UNKNOWN
1001 (Unspecified) D N A 0 UNKNOWN
1002/1002 (Unspecified) D N A 0 UNKNOWN
2000/2000 140.206.255.186 D N A 37142 UNREACHABLE
2001/2001 172.16.3.41 D N A 52375 UNREACHABLE
3000 (Unspecified) D N A 0 UNKNOWN
3001/3001 140.206.88.176 D N A 14545 UNREACHABLE
4000 (Unspecified) D N A 0 UNKNOWN
5079/5079 (Unspecified) D N A 0 UNKNOWN
5080/5080 116.227.121.205 D N A 9164 UNREACHABLE

I use linphone login with 5079 is ok.
but 5079 call 5080 is return error code 503.
req: invite
res: 401 unauthorized
req: ack
req: invite
res: 100 trying
res: 503 service unavailable

why?
Can someone help me?

Pretty well that won’t work.

I manual create sip account 5079 and 5080.

I thought you wanted to do that programatically … .

I manual insert record into table devices, users, sip.

good but you don’t say how you did that for 5079 and 5080. .

I manual append content into sip_additional.conf

well a simple :-
head -5 /etc/asterisk/sip_additional.conf

will show you the error of your ways.

things like

rasterisk -rx ‘database show’|grep 1000

mysql -h yourserver -u youruser -pyourpassword -D asterisk -e ‘select * from sip where id=1000’

mysql -h yourserver -u youruser -pyourpassword -D asterisk -e ‘select * from users where extension=0555’

mysql -h yourserver -u youruser -pyourpassword -D asterisk -e ‘select * from devices where id=0555’

with a bit of effort you will get there.

then you need to

asterisk -rx ‘database show’ |grep 1000

and add the appropriate elemments of your new extension. Either in the raw database or more generically with a lot of :-

asterisk -rx “database put ”

then

amportal a r

to load all your hard work you did into the FreePBX framework.

See it’s really not that simple . . .

I according to your method to test successfully.
Thank you very much!

I hate to rain on everyone’s parade but if you look at the bulk extension module the API to do this within FreePBX is documented enough that a non-programmer such as myself has a good idea of what is going on.

but i can not successful?can you give me some opinions

???

I have a same problem ,can you say it plentiful

I have the same problme .can you tell much more about this theme?

I Give this comand asterisk -rx “database put” and the output is
asterisk -rx "database put"
Privilege escalation protection disabled!
See https://wiki.asterisk.org/wiki/x/1gKfAQ for more details.
Usage: database put
Adds or updates an entry in the Asterisk database for
a given family, key, and value.
I do not know what value to give family, key, and value for my sip can you help please?