Re: [asterisk-users] SHELL() function Asterisk 13 - can only accept one paramter in string?

2018-07-30 Thread Stefan Viljoen
Hi Ludovic

 

Thank you very much for replying!

 

Ok, I’ll give up on the dialplan apps then in total and try out AGI.

 

Thanks again,

 



 

From: Ludovic Gasc  
Sent: Friday, 27 July 2018 13:37
To: viljo...@verishare.co.za; Asterisk Users Mailing List - Non-Commercial 
Discussion 
Subject: Re: [asterisk-users] SHELL() function Asterisk 13 - can only accept 
one paramter in string?

 

Hi Stefan,

 

You might use AGI instead of SHELL, it's better because you can interact with 
the call via AGI and you don't have a risk of remote execution you might have 
if you add arguments that come from outside, for example via a SIP header.

 

Regards.


--

Ludovic Gasc (GMLudo)

 

 

Le ven. 27 juil. 2018 à 09:37, Stefan Viljoen mailto:viljo...@verishare.co.za> > a écrit :

Hi all

This is a followup on my post "Asterisk 13 - system() dialplan app cannot call 
bash scripts" from yesterday

I've given up trying to use system() to call BASH scripts with parameters from 
Asterisk 13. 

Turned out under Asterisk 13.22.0 System() DOES work, but only if you do NOT 
attempt to pass any parameters to the called script.

This works, and reliably calls the script:

same=>n,System(/bin/bash /usr/src/bash/setData.sh)

However, the moment you do this:

same=>n,System(/bin/bash /usr/src/bash/setData.sh ${CHANNEL(accountcode)})

you get

WARNING[30982][C-0238] app_system.c: Unable to execute 
'/usr/src/bash/setData.sh'

I therefore tried to use SHELL() to do what I was trying to do with SYSTEM().

This also does not work, as SHELL() apparently can only ever parse ONE asterisk 
parameter in the string sent to it. All the rest are sent as blank.

If I do this:

same=>n,Set(nothing=${SHELL(/usr/src/verdi/bash/verdiLogIncomingCall.sh NA 
201807270838t49hgzs SIP/centra-out-6d9a IN SIP/3027-6db1 
SIP/3027-6db1 ApiLogIncomingCall.java 1)})

The script sees, on dialplan execution:

[root@acasterisk bash]# cat passed_param.txt
http://127.0.0.1/api/logIncomingCall?account_reference=NA 
<http://127.0.0.1/api/logIncomingCall?account_reference=NA_reference=201807270838t49hgzs_channel_id=SIP/centra-out-6d9a=IN_endpoint=SIP/3027-6db1_id=SIP/3027-6db1_from=ApiLogIncomingCall.java_sent_to_server=1>
 
_reference=201807270838t49hgzs_channel_id=SIP/centra-out-6d9a=IN_endpoint=SIP/3027-6db1_id=SIP/3027-6db1_from=ApiLogIncomingCall.java_sent_to_server=1
[root@acasterisk bash]#

E. g. all params present - because no variable references need to be parsed.

If I use this:

[macro-verdianswer]
exten=>s,1,NoOp(Entering Verdi answer macro - picked up by ${CHANNEL})
same=>n,NoOp(Source Channel: ${sourceChannel})
same=>n,NoOp(Answering Channel: ${CHANNEL})
same=>n,NoOp(Lodging CDR accountcode: ${curIncAccCode} as an incoming call from 
${numbersource} with VerDi and answered by ${CHANNEL}...)
same=>n,Set(CHANNEL(accountcode)=${curIncAccCode})
same=>n,Set(nothing=${SHELL(/usr/src/verdi/bash/verdiLogIncomingCall.sh NA 
${curIncAccCode} ${sourceChannel} IN ${CHANNEL} ${numbersource} 
ApiLogIncomingCall.java 1)})
same=>n,MacroExit()

giving this on exection:

-- SIP/3002-70c2 answered SIP/centra-out-70bf
-- Executing [s@macro-verdianswer:1] NoOp("SIP/3002-70c2", "Entering 
Verdi answer macro - picked up by SIP/3002-70c2") in new stack
-- Executing [s@macro-verdianswer:2] NoOp("SIP/3002-70c2", "Source 
Channel: SIP/centra-out-70bf") in new stack
-- Executing [s@macro-verdianswer:3] NoOp("SIP/3002-70c2", "Answering 
Channel: SIP/3002-70c2") in new stack
-- Executing [s@macro-verdianswer:4] NoOp("SIP/3002-70c2", "Lodging CDR 
accountcode: 2018072709061hrriyu
--  as an incoming call from 27182941000 with VerDi and answered by 
SIP/3002-70c2...") in new stack
-- Executing [s@macro-verdianswer:7] Set("SIP/3002-70c2", 
"nothing=Incoming call NOT stored. Contact software support.
-- ") in new stack

e. g. my variables ARE populated, and if I NoOp them, they have values.

In this situation, the script called via SHELL() sees:

[root@acasterisk bash]# cat passed_param.txt
http://127.0.0.1/api/logIncomingCall?account_reference=NA 
<http://127.0.0.1/api/logIncomingCall?account_reference=NA_reference=2018072709061hrriyu_channel_id==_endpoint=_id=_from=_sent_to_server=>
 
_reference=2018072709061hrriyu_channel_id==_endpoint=_id=_from=_sent_to_server=

E. g. SHELL() apparently only ever parses the FIRST Asterisk variable passed 
into it as a string, and never parses subsequent variable references.

Can anybody confirm or suggest a solution?

I desperately need to be able to execute external BASH scripts and pass 
multiple parameters to them, somehow. Nothing that worked in 1.8 for this works 
in 13...

Thanks!

Stefan


-- 
_
-- Bandw

Re: [asterisk-users] SHELL() function Asterisk 13 - can only accept one paramter in string?

2018-07-27 Thread Stefan Viljoen
With thanks to Ludovic Gasc

---

Turns out there is nothing wrong with the SYSTEM() or SHELL() dialplan 
functions in Asterisk 13.22.0.

After several hours of painstaking debugging, the problem turned out to be a 
linefeed (\n character, 0x0a hex) in the first parameter passed from Asterisk 
to the bash script in the call to the SYSTEM() or SHELL() applications.

Ludovic's suggestion to try AGI revealed the issue - it has nothing to do with 
AGI or SYSTEM() but rather my data for one parameter passed through system 
containing a linefeed (\n)

E. g. I was calling this:

same=>n,System(/usr/src/verdi/bash/verdiLogIncomingCall.sh NA ${curIncAccCode} 
${sourceChannel} IN ${CHANNEL} ${numbersource} ApiLogIncomingCall.java 1)

but

${curIncAccCode}

appeared to contain a UUID I generate in a JAVA application.

In fact it contained

uuidtexthere\n

instead of just

uuidtexthere

E. g. it had an appended \n (hex 0a) linefeed character appended.

My script that generated this UUID looked like this:

---
#!/bin/bash
function jsonval {
temp=`echo $jsonResult | sed 's/\//\//g' | sed 's/[{}]//g' | awk -v 
k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 
's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g'`
echo ${temp##*|}
}

baseUrl=http://127.0.0.1/api/getVerdiUUID

jsonResult=$(curl --connect-timeout 16 --max-time 32 -s -X GET $baseUrl)

uuid=`jsonval`

echo $uuid
---

So all that I actually needed to fix was to change

echo $uuid

to

echo -n $uuid

and all my problems were solved, SYSTEM() started working perfectly everywhere 
in the dialplan as the script wasn't emitting a trailing \n anymore.

So the germane difference between Asterisk 1.8 and Asterisk  13 / 12 / 11 / 10 
in this case was that SYSTEM() and SHELL() in the later versions are sensitive 
to \n being passed in inside any of the Asterisk variables passed into those 
applications' parameter string.

Maybe this helps somebody else.

Regards

Stefan


-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] SHELL() function Asterisk 13 - can only accept one paramter in string?

2018-07-27 Thread Ludovic Gasc
Hi Stefan,

You might use AGI instead of SHELL, it's better because you can interact
with the call via AGI and you don't have a risk of remote execution you
might have if you add arguments that come from outside, for example via a
SIP header.

Regards.
--
Ludovic Gasc (GMLudo)


Le ven. 27 juil. 2018 à 09:37, Stefan Viljoen  a
écrit :

> Hi all
>
> This is a followup on my post "Asterisk 13 - system() dialplan app cannot
> call bash scripts" from yesterday
>
> I've given up trying to use system() to call BASH scripts with parameters
> from Asterisk 13.
>
> Turned out under Asterisk 13.22.0 System() DOES work, but only if you do
> NOT attempt to pass any parameters to the called script.
>
> This works, and reliably calls the script:
>
> same=>n,System(/bin/bash /usr/src/bash/setData.sh)
>
> However, the moment you do this:
>
> same=>n,System(/bin/bash /usr/src/bash/setData.sh ${CHANNEL(accountcode)})
>
> you get
>
> WARNING[30982][C-0238] app_system.c: Unable to execute
> '/usr/src/bash/setData.sh'
>
> I therefore tried to use SHELL() to do what I was trying to do with
> SYSTEM().
>
> This also does not work, as SHELL() apparently can only ever parse ONE
> asterisk parameter in the string sent to it. All the rest are sent as blank.
>
> If I do this:
>
> same=>n,Set(nothing=${SHELL(/usr/src/verdi/bash/verdiLogIncomingCall.sh NA
> 201807270838t49hgzs SIP/centra-out-6d9a IN SIP/3027-6db1
> SIP/3027-6db1 ApiLogIncomingCall.java 1)})
>
> The script sees, on dialplan execution:
>
> [root@acasterisk bash]# cat passed_param.txt
>
> http://127.0.0.1/api/logIncomingCall?account_reference=NA_reference=201807270838t49hgzs_channel_id=SIP/centra-out-6d9a=IN_endpoint=SIP/3027-6db1_id=SIP/3027-6db1_from=ApiLogIncomingCall.java_sent_to_server=1
> [root@acasterisk bash]#
>
> E. g. all params present - because no variable references need to be
> parsed.
>
> If I use this:
>
> [macro-verdianswer]
> exten=>s,1,NoOp(Entering Verdi answer macro - picked up by ${CHANNEL})
> same=>n,NoOp(Source Channel: ${sourceChannel})
> same=>n,NoOp(Answering Channel: ${CHANNEL})
> same=>n,NoOp(Lodging CDR accountcode: ${curIncAccCode} as an incoming call
> from ${numbersource} with VerDi and answered by ${CHANNEL}...)
> same=>n,Set(CHANNEL(accountcode)=${curIncAccCode})
> same=>n,Set(nothing=${SHELL(/usr/src/verdi/bash/verdiLogIncomingCall.sh NA
> ${curIncAccCode} ${sourceChannel} IN ${CHANNEL} ${numbersource}
> ApiLogIncomingCall.java 1)})
> same=>n,MacroExit()
>
> giving this on exection:
>
> -- SIP/3002-70c2 answered SIP/centra-out-70bf
> -- Executing [s@macro-verdianswer:1] NoOp("SIP/3002-70c2",
> "Entering Verdi answer macro - picked up by SIP/3002-70c2") in new stack
> -- Executing [s@macro-verdianswer:2] NoOp("SIP/3002-70c2",
> "Source Channel: SIP/centra-out-70bf") in new stack
> -- Executing [s@macro-verdianswer:3] NoOp("SIP/3002-70c2",
> "Answering Channel: SIP/3002-70c2") in new stack
> -- Executing [s@macro-verdianswer:4] NoOp("SIP/3002-70c2",
> "Lodging CDR accountcode: 2018072709061hrriyu
> --  as an incoming call from 27182941000 with VerDi and answered by
> SIP/3002-70c2...") in new stack
> -- Executing [s@macro-verdianswer:7] Set("SIP/3002-70c2",
> "nothing=Incoming call NOT stored. Contact software support.
> -- ") in new stack
>
> e. g. my variables ARE populated, and if I NoOp them, they have values.
>
> In this situation, the script called via SHELL() sees:
>
> [root@acasterisk bash]# cat passed_param.txt
>
> http://127.0.0.1/api/logIncomingCall?account_reference=NA_reference=2018072709061hrriyu_channel_id==_endpoint=_id=_from=_sent_to_server=
>
> E. g. SHELL() apparently only ever parses the FIRST Asterisk variable
> passed into it as a string, and never parses subsequent variable references.
>
> Can anybody confirm or suggest a solution?
>
> I desperately need to be able to execute external BASH scripts and pass
> multiple parameters to them, somehow. Nothing that worked in 1.8 for this
> works in 13...
>
> Thanks!
>
> Stefan
>
>
> --
> _
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Check out the new Asterisk community forum at:
> https://community.asterisk.org/
>
> New to Asterisk? Start here:
>   https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>http://lists.digium.com/mailman/listinfo/asterisk-users
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   

Re: [asterisk-users] SHELL() function Asterisk 13 - can only accept one paramter in string?

2018-07-27 Thread Administrator TOOTAI

Le 27/07/2018 à 09:36, Stefan Viljoen a écrit :

Hi all

This is a followup on my post "Asterisk 13 - system() dialplan app cannot call bash 
scripts" from yesterday

I've given up trying to use system() to call BASH scripts with parameters from 
Asterisk 13.

Turned out under Asterisk 13.22.0 System() DOES work, but only if you do NOT 
attempt to pass any parameters to the called script.


[...]

*CLI> core show version
Asterisk 13.22.0 built by root @ pabx on a x86_64 running Linux on 
2018-07-14 13:36:49 UTC


This works for us

same = n,system(/bin/echo "To: ${CALLED_CHANNEL}   From: ${ORI_CALL}" | 
/usr/bin/mail -s "TOOTAiAudio - Congestion Gateway ${CONGESTION_GW} 
used" ${AUDIO_ADMIN})


--
Daniel

--
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
 https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users