Re: [asterisk-users] How to run a remote PHP script and still have access to audio stream?
On Wed, Feb 10, 2010 at 2:13 PM, Leo Burd l...@media.mit.edu wrote: Hello David, Thanks so much for your message! Please check my comments inline below... David Backeberg wrote: On Sun, Feb 7, 2010 at 9:54 PM, Leo Burd l...@media.mit.edu wrote: Hello there, I'm trying to figure out how to run a PHP script on a remote machine and still have access to the audio stream associated with the call. Ideally, I'd love to play/record audio files directly from/to the remote server without having to copy them back and forth to the Asterisk server. What is the best way to do this? 1) recordings, with a side order of distributing those to another machine 2) remote shell scripting What would be the asterisk way of recording part of the call from a remote server? I'm not sure I can do that (the remote connection) with EAGI, can I? The 'asterisk way' of recording part of a call needs to be done on the asterisk system where the call is taking place. Or, if the call is actually between two asterisk systems, the call can be recorded directly on one or the other or both asterisk systems. The asterisk dialplan feature is called Monitor() or MixMonitor(), and you can refer to the documentation for the differences. The AGI and remote connection comes in when the recording (call) completes, and in the h (hangup) context for this dialplan context, you would do the remote file copy so your call would now be copied off somewhere else. Do you know of any examples that use ssh from inside Asterisk calls? Sure, here's an example from one of my dialplans. exten = s,1,Answer exten = s,n,Set(CDR(userfield)=faxsample) exten = s,n,Set(LOCALSTATIONID=FaxSample) exten = s,n,Set(LOCALPATH=/var/spool/fax/recvq/${LOCALSTATIONID}/) exten = s,n,Set(MYDATE=${STRFTIME(${EPOCH},,%C%y-%m-%d-%H%M)}) exten = s,n,Set(MYFILENAME=${LOCALSTATIONID}-${MYDATE}-${CDR(uniqueid)}) exten = s,n,Set(MYFULLPATH=${LOCALPATH}${MYFILENAME}) exten = s,n,Set(KEYFULLPATH=/var/spool/fax/ssh_key_for_remote_copy) exten = s,n,Set(SCPUSER=filecopyuser) exten = s,n,Set(FILESERVER=fileserver.domain.com) exten = s,n,Set(REMOTEPATH=/path/to/where/it/should/go/${LOCALSTATIONID}) exten = s,n,Set(RECORDING=${LOCALPATH}recording/${MYFILENAME}.gsm) exten = s,n,MixMonitor(${RECORDING}) exten = s,n,Playback(silence/1) exten = s,n,ReceiveFax(${MYFULLPATH}.tif) ; log what happened with the fax transmission exten = h,1,System(/bin/echo ${MYFULLPATH},${CALLERID(num)},${CALLERID(name)},$ {FAXSTATUS},${FAXERROR},${FAXMODE},${FAXPAGES},${REMOTESTATIONID} ${LOCALPATH}fax.log) ; ; if fax is salvageable, a tif will exist. exten = h,n,System(test -e ${MYFULLPATH}.tif) ;exten = h,n,Verbose(System call result was ${SYSTEMSTATUS}) ; ; try to turn any file that exists into a pdf exten = h,n,ExecIf($[${SYSTEMSTATUS} = SUCCESS]?System(/usr/bin/tiff2pdf -pletter ${MYFULLPATH}.tif -o ${MYFULLPATH}.pdf)) ; ; check if pdf exists. If the fax was too incomplete to process, no file will exist. ; If yes, send it off to H drive exten = h,n,System(test -e ${MYFULLPATH}.pdf) ;exten = h,n,Verbose(System call result was ${SYSTEMSTATUS}) exten = h,n,ExecIf($[${SYSTEMSTATUS} = SUCCESS]?System(/usr/bin/scp -i ${KEYFULLPATH} ${MYFULLPATH}.pdf ${scpus...@${fileserver}:${REMOTEPATH})) ; if tiff file exists from good fax, name it one thing exten = h,n,ExecIf($[${FAXSTATUS} = SUCCESS]?System(/bin/mv ${MYFULLPATH}.tif /var/spool/fax/recvq/processed)) ; if fax was bad, check if we still have tif. If so, move it out exten = h,n,System(test -e ${MYFULLPATH}.tif) ;exten = h,n,Verbose(System call result was ${SYSTEMSTATUS}) exten = h,n,ExecIf($[${SYSTEMSTATUS} = SUCCESS]?System(/bin/mv ${MYFULLPATH}.tif /var/spool/fax/recvq/processed/${MYFILENAME}-FAILED.tif)) exten = h,n,Hangup How much control do the ssh processes have over the call, if any? As you can see in that particular example, I was using scp to do a remote file copy of the received fax. I also setup MixMonitor() against the channel with a filename that would match the cdr of the call in case I ever needed to go back and troubleshoot a particular fax. Is that comparable to Fast_AGI? Or EAGI? Ummm, kindof. My example shows doing everything directly in asterisk dialplan. AGI let's you use the language you prefer to do arbitrary things with calls, using the AGI library for that language. Some people prefer AGI, some people prefer dialplan. They both have their strengths, and drawbacks. Strength of dialplan is it's extremely debuggable. Strength of AGI is that you get to leverage the syntax and libraries in a language you already use, but when you want to debug, you have (in my opinion) less introspection into what's going on unless you use the innate debugging native to your language of choice. ('agi set debug on' helps). My personal experience has been that I really prefer AGI when I need to make lots of database calls, as that's where I much prefer Perl, and much dislike the asterisk syntax. So I have a set of AGIs that use the
Re: [asterisk-users] How to run a remote PHP script and still have access to audio stream?
On Wed, Feb 10, 2010 at 2:13 PM, Leo Burd l...@media.mit.edu wrote: How much control do the ssh processes have over the call, if any? It occurred to me that I might be answering this backwards. So from the perspective of server A, trying to talk to a remote system B running asterisk, server A can invoke: asterisk -rx do something on the asterisk cli and it will be done to asterisk on that system. So for example, I have built a nifty web gui that displays current call status in the system, along with a bunch of buttons. Among those buttons, is one that will hangup a call, on an appropriate channel, as corresponds to the database state I've been maintaining. And this does happen to have been done in PHP. And to do this hangup, I actually do NOT run ssh with keys, but rather I use asterisk manager. And send I use a nice PHP Asterisk manager library that somebody else wrote to manage the connection, then I send the Hangup() command on the appropriate channel, and the PHP Asterisk manager takes care of the dirty work of closing and cleaning up the connection. I chose to use PHP and asterisk manager, but I could have done the same thing with ssh keys and asterisk -rx '' approach. Hopefully that helps. -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] How to run a remote PHP script and still have access to audio stream?
Hello Ben, thanks for your message! I'm implementing a framework to integrate Asterisk and Drupal (a powerful tool for the creation of social- and media-rich websites). Since the voip and the web components of the system are likely to run on separate servers owned by different organizations, I don't think I could rely on a shared filesystem solution. Currently, I save Asterisk audio files on the Asterisk server, convert them to MP3, upload them to the Drupal server, and display them on the website. This process takes time and ends up duplicating a lot of content. That's why I was exploring ways of doing all the audio processing on the Drupal server with FastAGI and EAGI. Is there any easy way for Asterisk to play audio files located in remote servers? Another alternative would be to get Drupal to play audio files directly from the Asterisk server. Would you have any suggestions for that? Thanks once again for all your support! Leo Ben Dinnerville wrote: There is the EAGI protocol that will allow this but the easiest way I find to do this sort of thing is to have a shared file system between the app / web server and the asterisk server(s). We run a clustered setup with 12 asterisk systems and a clustered jboss environment with a NFS mount shared between all the systems. For applications such as call recording asterisk does the monitor into the NSF mounted share / directory which is also visible on the jboss servers (mainly for permission checks / security etc) and the web server (for download etc). As long as you have a scheme that ensures you do not have duplicate file names (which can be controlled by a central database and via your php script) then you will not have any issues. There are a number of other file system alternatives out there that will achieve the same thing but NFS seems to be proven and stable and we have not any issues with it to date. Your php script can then be a simple AGI / FastAGI that simply executes a Playback(path/to/nfs/directory/file) - you can also incorporate things like checking if the file exists in your PHP script and implementing access restrictions etc. We also share our sounds directory between systems this way so that all our sounds only have to reside in one place but are visible across all the systems. Cheers, Ben Leo Burd wrote: Hello there, I'm trying to figure out how to run a PHP script on a remote machine and still have access to the audio stream associated with the call. Ideally, I'd love to play/record audio files directly from/to the remote server without having to copy them back and forth to the Asterisk server. What is the best way to do this? Is it possible to combine EAGI with FastAGI in PHP? Thanks in advance, Leo -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] How to run a remote PHP script and still have access to audio stream?
On Wed, 2010-02-10 at 13:47 -0500, Leo Burd wrote: Is there any easy way for Asterisk to play audio files located in remote servers? If you can mount it, Asterisk will happily read from it. Perhaps you can run a an ssh/ftp/smb/nfs server deamon on the webserver and mount it on the filesystem on the Asterisk box? I'd probably want to store them locally and have a script check the remote storage is online and then move them. A simple FTP script may be the easiest way to achieve this. Another alternative would be to get Drupal to play audio files directly from the Asterisk server. Would you have any suggestions for that? Host them both on the same machine :-) Der dum chishh. I'll get my coat. -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] How to run a remote PHP script and still have access to audio stream?
Hello David, Thanks so much for your message! Please check my comments inline below... David Backeberg wrote: On Sun, Feb 7, 2010 at 9:54 PM, Leo Burd l...@media.mit.edu wrote: Hello there, I'm trying to figure out how to run a PHP script on a remote machine and still have access to the audio stream associated with the call. Ideally, I'd love to play/record audio files directly from/to the remote server without having to copy them back and forth to the Asterisk server. What is the best way to do this? Is it possible to combine EAGI with FastAGI in PHP? You don't specify how often / what proportion of the recordings need to be on a remote machine versus on the asterisk server. So you have two main things going on: 1) recordings, with a side order of distributing those to another machine 2) remote shell scripting First, the recordings can be done directly on a channel where the call is taking place. If this is one call, that's not so bad, but there get to be I/O contention issues when you try to record 'a lot' of calls simultaneously. Some people endorse working around that by writing recordings to a ramdisk, and then occasionally flushing those off to a real hard disk. What would be the asterisk way of recording part of the call from a remote server? I'm not sure I can do that (the remote connection) with EAGI, can I? You may prefer an alternate approach, which is that taken by commercial recording solutions. Oreka (which can be grabbed from sourceforge), and pretty much every commercial voip recording solution I've investigated, works by having you use libpcap (used in Ethereal/Wireshark) to watch ethernet device(s) where voip calls are taking place, grab the SIP headers that set up the RTP stream, and then write those recordings to disk on a dedicated recordings server. This requires explicit ethernet support by doing things like port mirroring, or using an old-school hub, etc. This has an advantage for you of providing a way to do recording directly on a machine that is NOT the asterisk server. No copying required as the recording is already where you want it. Second, the remote shell isn't so hard. ssh with keys, problem solved. You can do that directly from the asterisk dialplan using the System() command. This let's you tie the remote shell directly to a given call, where you can tune arguments accordingly. Do you know of any examples that use ssh from inside Asterisk calls? How much control do the ssh processes have over the call, if any? Is that comparable to Fast_AGI? Or EAGI? Of course, you can also do #1 with scripting and remote shell, or rsync with keys. If you don't need 'a lot' of simultaneous channels recorded, this may be more straightforward. You only have to learn asterisk, rather than asterisk and Oreka. I'm intrigued about the remote shell idea... please let me know if you have additional information about it, ok? Thanks once again, Leo -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] How to run a remote PHP script and still have access to audio stream?
Leo Burd wrote: Hello there, I'm trying to figure out how to run a PHP script on a remote machine and still have access to the audio stream associated with the call. Ideally, I'd love to play/record audio files directly from/to the remote server without having to copy them back and forth to the Asterisk server. What is the best way to do this? Is it possible to combine EAGI with FastAGI in PHP? Thanks in advance, Leo There is the EAGI protocol that will allow this but the easiest way I find to do this sort of thing is to have a shared file system between the app / web server and the asterisk server(s). We run a clustered setup with 12 asterisk systems and a clustered jboss environment with a NFS mount shared between all the systems. For applications such as call recording asterisk does the monitor into the NSF mounted share / directory which is also visible on the jboss servers (mainly for permission checks / security etc) and the web server (for download etc). As long as you have a scheme that ensures you do not have duplicate file names (which can be controlled by a central database and via your php script) then you will not have any issues. There are a number of other file system alternatives out there that will achieve the same thing but NFS seems to be proven and stable and we have not any issues with it to date. Your php script can then be a simple AGI / FastAGI that simply executes a Playback(path/to/nfs/directory/file) - you can also incorporate things like checking if the file exists in your PHP script and implementing access restrictions etc. We also share our sounds directory between systems this way so that all our sounds only have to reside in one place but are visible across all the systems. Cheers, Ben -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] How to run a remote PHP script and still have access to audio stream?
On Sun, Feb 7, 2010 at 9:54 PM, Leo Burd l...@media.mit.edu wrote: Hello there, I'm trying to figure out how to run a PHP script on a remote machine and still have access to the audio stream associated with the call. Ideally, I'd love to play/record audio files directly from/to the remote server without having to copy them back and forth to the Asterisk server. What is the best way to do this? Is it possible to combine EAGI with FastAGI in PHP? You don't specify how often / what proportion of the recordings need to be on a remote machine versus on the asterisk server. So you have two main things going on: 1) recordings, with a side order of distributing those to another machine 2) remote shell scripting First, the recordings can be done directly on a channel where the call is taking place. If this is one call, that's not so bad, but there get to be I/O contention issues when you try to record 'a lot' of calls simultaneously. Some people endorse working around that by writing recordings to a ramdisk, and then occasionally flushing those off to a real hard disk. You may prefer an alternate approach, which is that taken by commercial recording solutions. Oreka (which can be grabbed from sourceforge), and pretty much every commercial voip recording solution I've investigated, works by having you use libpcap (used in Ethereal/Wireshark) to watch ethernet device(s) where voip calls are taking place, grab the SIP headers that set up the RTP stream, and then write those recordings to disk on a dedicated recordings server. This requires explicit ethernet support by doing things like port mirroring, or using an old-school hub, etc. This has an advantage for you of providing a way to do recording directly on a machine that is NOT the asterisk server. No copying required as the recording is already where you want it. Second, the remote shell isn't so hard. ssh with keys, problem solved. You can do that directly from the asterisk dialplan using the System() command. This let's you tie the remote shell directly to a given call, where you can tune arguments accordingly. Of course, you can also do #1 with scripting and remote shell, or rsync with keys. If you don't need 'a lot' of simultaneous channels recorded, this may be more straightforward. You only have to learn asterisk, rather than asterisk and Oreka. -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users