There are numerous ways to stimulate outbound whitelisting on asterisk, but I needed a solution where the terminate user could exactly ftp a text file to the server to update the whitelist.
You volition ask to practise the next files:
/etc/asterisk/checkwhitelist.sh
/etc/asterisk/whitelist.txt
Start with:
#vim /etc/asterisk/checkwhitelist.sh
too add together the next contents:
if grep -q $1 "/etc/asterisk/whitelist.txt"; then
echo "1"
else
echo "0"
fi
After creating the file, larn far executable amongst the next command:echo "1"
else
echo "0"
fi
chmod a+x /etc/asterisk/checkwhitelist.sh
Also practise the next file:
#vim /etc/asterisk/whitelist.txt
You tin too thus add together the allowed numbers to this text file, i per line. eg: 0123456789
0124567890
0126789012
0124567890
0126789012
I volition drib dead on the illustration dialplan unproblematic for illustrative purposes:
#vim /etc/asterisk/extensions.conf:
Place the next code inwards you lot outbound context:
[outgoing]
include => internal
exten => _XXX.,1,NoOp(Going Out)
same => n,Macro(whitelist,${EXTEN})
same => n,HangUp()
[macro-whitelist]
exten => s,1,GotoIf(${SHELL(/etc/asterisk/checkwhitelist.sh ${ARG1}):0:-1})?allowed:notallowed)
same => n(allowed),NoOp(You may telephone telephone ${ARG1})
same => n,Dial(SIP/upstream/${ARG1})
same => n,HangUp()
same => n(notallowed),NoOp(YOU ARE NOT ALLOWED TO CALL ${ARG1})
same => n,HangUp()
include => internal
exten => _XXX.,1,NoOp(Going Out)
same => n,Macro(whitelist,${EXTEN})
same => n,HangUp()
[macro-whitelist]
exten => s,1,GotoIf(${SHELL(/etc/asterisk/checkwhitelist.sh ${ARG1}):0:-1})?allowed:notallowed)
same => n(allowed),NoOp(You may telephone telephone ${ARG1})
same => n,Dial(SIP/upstream/${ARG1})
same => n,HangUp()
same => n(notallowed),NoOp(YOU ARE NOT ALLOWED TO CALL ${ARG1})
same => n,HangUp()
The get-go business matches whatever outgoing telephone telephone amongst to a greater extent than than iv digits
The minute business passes it to the whitelist macro
The get-go business inwards the macro calls a musical rhythm out script amongst the dialed publish every bit the exclusively argument. The sript returns a nil if the publish is non found, too a i if it is found. If the publish is institute it is passed to "(allowed)" which places the call. If it is non institute it is passed to "(notallowed)" which exactly ends the call.
Do a "dialplan reload" in Asterisk. Any phones inwards the [outgoing] context volition exclusively last able to dial numbers inwards the whitelist.