I have a project where I need to add, remove, edit peers in pjsip.conf. I started off using PHP and then realized AMI supported updating config files through the UpdateConfig action. I’m able to delete and edit peers without issue but can’t seem to get adding working properly.
See my ami actions below but the problems I’m encountering are when the peer gets added, it adds to the end of the file but doesn’t put spaces between the contexts/categories. Not a show stopper but formatting looks terrible.
The other issue is with the below actions, for some reason the username and password get added to both the abc-defaults and the abc-defaults-auth categories which shouldn’t be added to the abc-defaults.
Any help would be appreciated.
Action: UpdateConfig
SrcFilename: pjsip.conf
DstFilename: pjsip.conf
Action-000000: NewCat
Cat-000000: abc6789
Options-000000: inherit='abc-defaults'
Action-000001: Append
Cat-000001: abc6789
Var-000001: set_var
Value-000001: CIDOUT=1234566789
Action-000002: Append
Cat-000002: abc6789
Var-000002: callerid
Value-000002: "The Dude" <6789>
Action-000003: Append
Cat-000003: abc6789
Var-000003: mailboxes
Value-000003: 6789@abc
Action-000004: Append
Cat-000004: abc6789
Var-000004: auth
Value-000004: abc6789
Action-000005: Append
Cat-000005: abc6789
Var-000005: aors
Value-000005: abc6789
Action-000006: NewCat
Cat-000006: abc6789
Options-000006: allowdups,inherit='abc-defaults-auth'
Action-000007: Append
Cat-000007: abc6789
Var-000007: username
Value-000007: abc6789
Action-000008: Append
Cat-000008: abc6789
Var-000008: password
Value-000008: theDudesPassword
Action-000009: NewCat
Cat-000009: abc6789
Options-000009: allowdups,inherit='abc-defaults-aor'
Here’s the desired formatting:
[abc6789](abc-defaults)
set_var = CIDOUT=1234566789
callerid = "The Dude" <6789>
mailboxes = 6789@abc
auth = abc6789
aors = abc6789
[abc6789](abc-defaults-auth)
username = abc6789
password = theDudesPassword
[abc6789](abc-defaults-aor)
But here’s what I get:
[abc6789](abc-defaults)
set_var = CIDOUT=8642996789
callerid = "The Dude" <6789>
mailboxes = 6789@abc
auth = abc6789
aors = abc6789
username = abc6789
password = theDudesPassword
[abc6789](abc-defaults-auth)
username = abc6789
password = theDudesPassword
[abc6789](abc-defaults-aor)