Summary: | ASTERISK-15695: [patch] system() dialplan function does not work | ||
Reporter: | rbosch (rbosch) | Labels: | |
Date Opened: | 2010-02-25 14:51:24.000-0600 | Date Closed: | 2010-03-11 15:08:34.000-0600 |
Priority: | Minor | Regression? | No |
Status: | Closed/Complete | Components: | Applications/app_system |
Versions: | Frequency of Occurrence | ||
Related Issues: | |||
Environment: | Attachments: | ( 0) 20100303__issue16905.diff.txt | |
Description: | You can put any script passed as an argument to the system() command in a dialplan and it will not execute. In my example, I created the following script: #!/bin/bash ls -l /tmp > /usr/src/temp.txt in file /usr/src/temp.sh. temp.sh is 755 so any user can execute it. In the dialplan I put a simple call to system using this dialplan exten => 101,1,Set(__FROM_DID=${EXTEN}) exten => 101,n,system(/usr/src/temp.sh) The asterisk log shows [Feb 25 15:12:11] VERBOSE[23375] pbx.c: -- Executing [101@from-trunk:1] ^[[1;36mSet^[[0m("^[[1;35mSIP/DefaultOut-00000006^[[0m", "^[[1;35m__FROM_DID=[Feb 25 15:12:11] VERBOSE[23375] pbx.c: -- Executing [101@from-trunk:2] ^[[1;36mSystem^[[0m("^[[1;35mSIP/DefaultOut-00000006^[[0m", "^[[1;35m/usr/src/temp.sh^[[0m") in new stack The script does not execute as there is no output file /usr/src/temp.txt. Executing the command from the asterisk command line as "!/usr/src/temp.sh" DOES work without issue. | ||
Comments: | By: Tilghman Lesher (tilghman) 2010-02-28 01:25:16.000-0600 Are you running Asterisk as root or as some other user? If as some other user, does that user have permission to write to the /usr/src/ directory? When you execute a shell command from the CLI using the ! command, it is run by the user running the remote console, NOT by the core Asterisk process. By: rbosch (rbosch) 2010-02-28 07:47:24.000-0600 Yes, it was a permissions issue. I went out of my way to check that before submitting but obviously didn't do the job. How embarrassing. The reason I opened the ticket is fax-process.pl isn't executing as part of the FreePBX dialplan. I can run the command find from the command line as the asterisk user but the command does not seem to execute in the dialplan. I created a simple dialplan like I did for this test and the command ran fine so it must be something in the FreePBX dialplan. Sorry for jumping the gun on this ticket. It can be closed. By: rbosch (rbosch) 2010-02-28 19:19:25.000-0600 I was able to reproduce the problem I am having and it is more specific to ExecIf and the system command. Here are the dialplan lines and the resulting log. The first system() command runs fine and the email generated by the fax-process.pl is received. The second with an ExecIf does not even though the conditions are true. The commands are identical. exten => 9999,n,Set(FAX_RX_EMAIL=test@test.com) exten => 9999,n(process),system(${ASTVARLIBDIR}/bin/fax-process.pl --to ${FAX_RX_EMAIL} --from "testfax@testfax.com" --dest "${FROM_DID}" --subject "New fax from Test 1" --attachment fax_testnum.pdf --type application/pdf --file /var/spool/asterisk/fax/1266605097.367.tif) exten => 9999,n(process),ExecIf($["${FAX_RX_EMAIL}" != ""]?system(${ASTVARLIBDIR}/bin/fax-process.pl --to ${FAX_RX_EMAIL} --from "testfax@testfax.com" --dest "${FROM_DID}" --subject "New fax from Test 2" --attachment fax_testnum.pdf --type application/pdf --file /var/spool/asterisk/fax/1266605097.367.tif)) Resulting log [Feb 28 18:55:06] VERBOSE[10689] pbx.c: -- Executing [9999@from-trunk:3] ^[[1;36mSystem^[[0m("^[[1;35mSIP/DefaultOut-0000005a^[[0m", "^[[1;35m/var/lib/asterisk/bin/fax-process.pl --to myemail --from "testfax@testfax.com" --dest "9999" --subject "New fax from Test 1" --attachment fax_testnum.pdf --type application/pdf --file /var/spool/asterisk/fax/1266605097.367.tif^[[0m") in new stack [Feb 28 18:55:07] VERBOSE[10689] pbx.c: -- Executing [9999@from-trunk:4] ^[[1;36mExecIf^[[0m("^[[1;35mSIP/DefaultOut-0000005a^[[0m", "^[[1;35m1?system(/var/lib/asterisk/bin/fax-process.pl --to myemail --from "testfax@testfax.com" --dest "9999" --subject "New fax from Test 2" --attachment fax_testnum.pdf --type application/pdf --file /var/spool/asterisk/fax/1266605097.367.tif)^[[0m") in new stack By: Tilghman Lesher (tilghman) 2010-02-28 22:51:24.000-0600 What makes you think it isn't executing? Perhaps you should try the same thing you tried before and append output to a logfile in both cases, and check that. From what you have here, I have no indication of any failure. By: rbosch (rbosch) 2010-03-01 07:44:25.000-0600 Please close this ticket. I'm not working on it anymore...and don't care if it works or not. By: rbosch (rbosch) 2010-03-01 18:43:23.000-0600 Additional testing has shown the following: - ExecIf does not always have an issue. Running my previous temp.sh scripts work ok. - The dialplan below will not work. The problem is clearly with the ExecIf since the exact same command will work with a direct System function call. But when ExecIf is added, it does not work. - The condition has been verified to be true. [ext-fax] include => ext-fax-custom exten => s,1,Macro(user-callerid,) exten => s,n,Noop(Receiving Fax for: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}) exten => s,n(receivefax),ReceiveFAX(${ASTSPOOLDIR}/fax/${UNIQUEID}.tif) exten => h,1,GotoIf($["${FAXSTATUS:0:6}" = "FAILED"]?failed) exten => h,n(process),ExecIf($["${FAX_RX_EMAIL}" != ""]?system(${ASTVARLIBDIR}/bin/fax-process.pl --to ${FAX_RX_EMAIL} --from "myfax@freepbx.org" --dest "${FROM_DID}" --subject "New fax from ${URIENCODE(${CALLERID(name)})} ${URIENCODE(<${CALLERID(number)}>)}" --attachment fax_${URIENCODE(${CALLERID(number)})}.pdf --type application/pdf --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif)) exten => h,n(end),Macro(hangupcall,) exten => h,process+101(failed),Noop(FAX ${FAXSTATUS} for: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}) exten => h,n,Macro(hangupcall,) FreePBX has worked around the problem by changing from ExecIf to GotoIf. Several FreePBX users have the same issue on 1.6.2. See http://www.freepbx.org/forum/freepbx/users/fax-process-pl-not-executing-under-1-6-2-2#comment-24434 and http://www.freepbx.org/trac/ticket/4096 By: Tilghman Lesher (tilghman) 2010-03-03 10:15:05.000-0600 Since it was stated in the FreePBX issue that this is an issue with quotes getting removed prematurely, I have produced a patch that should no longer remove those quotes. Please test and report back as to whether this fixes your issue. By: Tilghman Lesher (tilghman) 2010-03-10 00:38:45.000-0600 ip-rob: Please test the attached patch and report back as to whether this fixes your issue. By: rbosch (rbosch) 2010-03-11 10:11:28.000-0600 Patch fixes the issue. Please note that I had applied the patch for ticket 0016842 prior to applying this patch. Then I tested a dialplan with the ExecIf statement above and things worked fine. Patch for ticket 0016842 was for a separate issue so it should not impact the viability of this fix. Thanks! By: Digium Subversion (svnbot) 2010-03-11 15:07:08.000-0600 Repository: asterisk Revision: 251884 U trunk/apps/app_exec.c ------------------------------------------------------------------------ r251884 | tilghman | 2010-03-11 15:07:07 -0600 (Thu, 11 Mar 2010) | 8 lines Because ExecIf needs to reprocess arguments, it's best if we don't remove quotes during parsing. (closes issue ASTERISK-15695) Reported by: ip-rob Patches: 20100303__issue16905.diff.txt uploaded by tilghman (license 14) Tested by: ip-rob ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=251884 By: Digium Subversion (svnbot) 2010-03-11 15:08:15.000-0600 Repository: asterisk Revision: 251885 _U branches/1.6.0/ U branches/1.6.0/apps/app_exec.c ------------------------------------------------------------------------ r251885 | tilghman | 2010-03-11 15:08:15 -0600 (Thu, 11 Mar 2010) | 15 lines Merged revisions 251884 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r251884 | tilghman | 2010-03-11 15:07:07 -0600 (Thu, 11 Mar 2010) | 8 lines Because ExecIf needs to reprocess arguments, it's best if we don't remove quotes during parsing. (closes issue ASTERISK-15695) Reported by: ip-rob Patches: 20100303__issue16905.diff.txt uploaded by tilghman (license 14) Tested by: ip-rob ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=251885 By: Digium Subversion (svnbot) 2010-03-11 15:08:23.000-0600 Repository: asterisk Revision: 251886 _U branches/1.6.1/ U branches/1.6.1/apps/app_exec.c ------------------------------------------------------------------------ r251886 | tilghman | 2010-03-11 15:08:23 -0600 (Thu, 11 Mar 2010) | 15 lines Merged revisions 251884 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r251884 | tilghman | 2010-03-11 15:07:07 -0600 (Thu, 11 Mar 2010) | 8 lines Because ExecIf needs to reprocess arguments, it's best if we don't remove quotes during parsing. (closes issue ASTERISK-15695) Reported by: ip-rob Patches: 20100303__issue16905.diff.txt uploaded by tilghman (license 14) Tested by: ip-rob ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=251886 By: Digium Subversion (svnbot) 2010-03-11 15:08:33.000-0600 Repository: asterisk Revision: 251887 _U branches/1.6.2/ U branches/1.6.2/apps/app_exec.c ------------------------------------------------------------------------ r251887 | tilghman | 2010-03-11 15:08:33 -0600 (Thu, 11 Mar 2010) | 15 lines Merged revisions 251884 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ........ r251884 | tilghman | 2010-03-11 15:07:07 -0600 (Thu, 11 Mar 2010) | 8 lines Because ExecIf needs to reprocess arguments, it's best if we don't remove quotes during parsing. (closes issue ASTERISK-15695) Reported by: ip-rob Patches: 20100303__issue16905.diff.txt uploaded by tilghman (license 14) Tested by: ip-rob ........ ------------------------------------------------------------------------ http://svn.digium.com/view/asterisk?view=rev&revision=251887 |