⬆️ ⬇️

Asterisk + Lua + regular update of DEF codes

I welcome everyone again. After writing the last article about using lua in an asterisk, I got a thought about a small explanation about the use of DEF codes together with lua. Previously, an article about the generation of codes using a php script flew here. I have successfully used and use this script, but with small (not very large) modifications.





I will not list the script itself; you can read it here:

habrahabr.ru/post/150793

I will only mention the improvements themselves.



First, we need to generate the code on lua and save it via the standard “library” path (/usr/lib/lua/5.1 or for 64bit systems /usr/lib64/lua/5.1). To do this, in the above mentioned script at the very beginning we make an entry:

')

$dp = fopen('/usr/lib/lua/5.1/mphonetable.lua','w'); //lua dialplan 


I inserted this line right after
 $defs = array(); 




Further, at the end of the original script, after the foreach loop, I added the following entry, which generates code on lua:



 #        9 $linecode = '98'; fwrite($dp,"extensions.mobile_out={\n"); foreach($regs as $op => $reg) { foreach($reg as $r) { fwrite($dp,"\t[\"_"); echo "\t[\"_"; echo $linecode.$r.'"]=call_mobile;'."\n"; $line = $linecode.$r.'"]=call_mobile;'."\n"; fwrite($dp,$line); } } #        9 $linecode = '8'; foreach($regs as $op => $reg) { foreach($reg as $r) { fwrite($dp,"\t[\"_"); echo "\t[\"_"; echo $linecode.$r.'"]=call_mobile;'."\n"; $line = $linecode.$r.'"]=call_mobile;'."\n"; fwrite($dp,$line); } } fwrite($dp,"\tinclude = {\"out_trunk\"};\n"); fwrite($dp,"}\n"); fclose($dp); 




call_mobile is a function that handles cellular exit events.



Second, we need to apply the changes in Asterisk:



 #-------------------------------------------------------- ob_implicit_flush(true); set_time_limit(0); #  $host="192.168.xxx.xxx"; #    $port="5038"; $user="login"; $pass="password"; $wrets=""; #  $socket = fsockopen("$host","$port"); if (!$socket) exit("no connect to ats"); # fputs($socket, "Action: login\r\n"); fputs($socket, "Events: off\r\n"); fputs($socket, "UserName: $user\r\n"); fputs($socket, "Secret: $pass\r\n\r\n"); fputs($socket, "Action: command\r\n"); fputs($socket, "command: module reload pbx_lua\r\n\r\n"); fputs($socket, "Action: logoff\r\n\r\n"); #  while (!feof($socket)) { $line = fread($socket,8192); echo $line; } fclose($socket); #       ... 




Thirdly, the script itself is hung up in crone and we forget about its existence :) My script was executed once a day.



In fact, you can avoid the cumbersome recording of the extension and implement parsing of the exit to the external via the function, but the controversial issue here is not the fact that it will be optimal. The description of events is all done not exactly by hand, but automatically, so you can forget about this problem after writing.



About the routes of the calls themselves themselves (which directions you should pass through what or whom) then you can decide for yourself. I had about 8 gsm gateways. Two cellular operators with interesting tariffs were used to access the cellular ones. Ekonimiya should be economical :).



Everything. Goodbye!

Source: https://habr.com/ru/post/243213/



All Articles