Asterisk and PHP Remote Dialing
From RADION OpenLab
<html> <head> <title>RADION Web-Dial Status</title> <script language='javascript'> if (window.external.menuArguments != undefined) { var defLocation = "http://192.168.1.1/dial.php" ; var objSelection = window.external.menuArguments.document.selection ; var objSelectionRange = objSelection.createRange() ; var strSelectedNumber = objSelectionRange.text ; // since a plus (+49...) will be transformed into a blank we have to escape it var strSafeNumber = strSelectedNumber.replace(/\+/, "%2B") ; if (strSafeNumber.length > 0) { windowDialer = window.open (defLocation +"?n="+ strSafeNumber +"&x=<?=$_REQUEST['x']?>", "AsteriskDialer" , "width=400,height=200,left=150,top=150") ; windowDialer.focus () ; } } </script> </head> <body style="font: 12pt bold arial;"> <? if (( !empty( $_REQUEST['n'] ) ) && ( !empty( $_REQUEST['x'] ) ) ) { $ext = trim ($_REQUEST['x']) ; $num = trim ($_REQUEST['n']) ; if ($num{0} == "+") { $strNatNum = stristr ($num, '+49') ; if ($strNatNum === FALSE) { $num = strchr ( $num, "+" ) ; $num = "00".$num ; } else { $strNatNum = substr ($strNatNum,3) ; $num = "0".$strNatNum ; } } $num = preg_replace ( "/[^\d]/", "", $num ) ; if ( ! empty( $num ) ) { $timeout = 10 ; $strAstHost = "192.168.1.1" ; $intAstPort = 5038 ; $socket = fsockopen ($strAstHost, $intAstPort, $errno, $errstr, $timeout) ; fputs ($socket, "Action: Login\r\n") ; fputs ($socket, "UserName: rdial\r\n") ; fputs ($socket, "Secret: yourpassword\r\n\r\n") ; $wrets = fgets ($socket,128) ; fputs ($socket, "Action: Originate\r\n" ) ; fputs ($socket, "Channel: IAX2/$ext\r\n" ) ; fputs ($socket, "Channel: Zap/g2/1\r\n" ) ; fputs ($socket, "Exten: 0$num\r\n" ) ; fputs ($socket, "Context: nt-bri-muc\r\n" ) ; fputs ($socket, "Priority: 1\r\n" ) ; fputs ($socket, "Async: yes\r\n\r\n" ) ; $wrets = fgets ($socket,128) ; if (stristr($wrets, 'success') === FALSE) { echo " an error occured "; } else { print ("<table border='0' cellpadding='2' cellspacing='2' width='380'>"); printf ("<tr><td height='25' style='font-family: arial' bgcolor='#e5e5e5'> Originate dialing request from %s connecting to</td></tr>", $ext ); printf ("<tr><td height='65' style='font-family: arial; color: #c70000; font-size: 36px' bgcolor='#fafafa' align='center'>%s</td></tr>", $_REQUEST['n'] ); printf ("<tr><td height='45' style='font-family: arial; color: #282828; font-size: 24px' bgcolor='#fafafa' align='center'>%s</td></tr>", $num ); print ("<tr><td height='25' style='font-family: arial' bgcolor='#e5e5e5'> Please pick up your phone now ...</td></tr>"); print ("</table>"); } } else { echo "Unable to determine number from (" . $_REQUEST['n'] . ")\r\n"; } } else {?> <?} ?> </body> </html>
also, on each windows client you can dial comfortably via Internet Explorer right-click menu extension :
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\&Dial] @="http://192.168.1.1/dial.php?x=sales1" "Contexts"=dword:00000010
also, create an account in your manager.conf :
[rdial] secret = yourpassword permit = 192.168.1.0/255.255.255.0 read = system,call,log,verbose,command,agent,user write = system,call,log,verbose,command,agent,user
