Gosubif - compare 2 global variable

hi all

is it possible to make a gosubif not only with comparing a variable with a number?

in an ivr, i save dtmf-inputs in a global variable PIN:
exten=>s,1,Read(GLOBAL(PIN),soundfile,8,2,20)

in an other ivr i want compare the variable PIN with the caller input PININPUT, and if it is the same, gosub pinok
exten=>s,1,Read(GLOBAL(PININPUT),soundfile,8,2,20)
same=>n,GosubIf($[“${PIN}” = “${PININPUT}”]?pinok,s,1)

but no matter if the caller input is (correct pin or wrong pin), it goes to pinok.

if i replace “${PIN}” with a number (1234), it works fine.
if the caller type in the correct PININPUT 1234 it goes to pinok, if the caller type in the wrong PININPUT, it jumps to the next line.
same=>n,GosubIf($[“1234” = “${PININPUT}”]?:pinnotok,s,1)

what do i wrong?
or can someone help me to do this?

thanks and kind regards

Increase asterisk verbosity level and see the dialplan execution. Check if the variables are holding the values you expect them to.

Is PININPUT also defined locally?

the asterisk cli show:

Blockquote
Executing [s@eingabe1:1] Read(“PJSIP/mytrunk95-00000068”, “GLOBAL(PINEINGABE),pinabfrage,8,2,20”) in new stack
– Accepting a maximum of 8 digits.
– <PJSIP/mytrunk95-00000068> Playing ‘pinabfrage.g722’ (language ‘de’)
0x14a95c049bd0 – Strict RTP learning complete - Locking on source address 212.117.203.60:41748
== Setting global variable ‘PINEINGABE’ to ‘444’
– User entered ‘444’
– Executing [s@eingabe1:2] SayDigits(“PJSIP/mytrunk95-00000068”, ““123"”) in new stack
[Dec 4 22:37:45] WARNING[1656][C-00000069]: file.c:824 ast_openstream_full: File does not exist in any format
[Dec 4 22:37:45] WARNING[1656][C-00000069]: file.c:1303 ast_streamfile: Unable to open (format (g722)): No such file or directory
– <PJSIP/mytrunk95-00000068> Playing ‘digits/1.alaw’ (language ‘de’)
– <PJSIP/mytrunk95-00000068> Playing ‘digits/2.alaw’ (language ‘de’)
– <PJSIP/mytrunk95-00000068> Playing ‘digits/3.alaw’ (language ‘de’)
– Executing [s@eingabe1:3] SayDigits(“PJSIP/mytrunk95-00000068”, “444”) in new stack
– <PJSIP/mytrunk95-00000068> Playing ‘digits/4.alaw’ (language ‘de’)
– <PJSIP/mytrunk95-00000068> Playing ‘digits/4.alaw’ (language ‘de’)
– <PJSIP/mytrunk95-00000068> Playing ‘digits/4.alaw’ (language ‘de’)
[Dec 4 22:37:49] WARNING[1656][C-00000069]: ast_expr2.fl:470 ast_yyerror: ast_yyerror(): syntax error: syntax error, unexpected ‘’, expecting $end; Input:
““123"” : “444”
^
[Dec 4 22:37:49] WARNING[1656][C-00000069]: ast_expr2.fl:474 ast_yyerror: If you have questions, please refer to Channel Variables - Asterisk Project - Asterisk Project Wiki
– Executing [s@eingabe1:4] GosubIf(“PJSIP/mytrunk95-00000068”, “””?pinok,s,1”) in new stack
– Executing [s@pinok:1] Playback(“PJSIP/mytrunk95-00000068”, “eintreten”) in new stack

so you can see, it is 123 and 444 but execute pinok

at the moment, both PIN and PININPUT are global variables.
or what you mean?

same=>n,GosubIf($[“${CALLERID(num)}” : “${PININPUT}”]?pinok,s,1)

for testing i compare PININPUT with CALLERID(num) and it works as expected

Your original example used =, but the log and your last posting have : which is a regular expression operator, not an equality one.

I note that you have a syntax error:

You haven’t reproduced the log correctly, as all the quotes should be simple double quote ("). That means it isn’t possible to tell whether there is a real fancy quote in the original which is messing things up.

ah sorry, its because of testing.
i also tested it with = with the same result

Does the same include the equivalent syntax error message?

As it may have got distorted in the forum, under which character is the caret in the message?

sorry my english isn’t the best, can you please explain more detailed what you want know?

and after work i will make a new log with correct syntax, i think it will be better.

but problem is following:
x digits dtmf in variable 1
x digits dtmf in variable 2
gosubif if both variables is the same.
my question is, is it possible to compare 2 variables?

as example if i compare variable with callerid it works correct.
only 2 variables always answer with true, alsi if they are different

Did you get an equivalent of this error?

Exactly where is the “^” in the following, in relation to the preceding line?

Yes, although strictly speaking, the variables are replaced by their values before the expression is parsed, so you only ever compare the values. That is why the syntax error message quotes the values, not the variable names.

sorry this was also a mistake by testing too many variants.

i defined the global variable
PIN = “123”
That’s why it is wrong.

but in the normal process this will be overwritten by dtmf-inputs, as same as the PININPUT will be.
and for comparing i use ${} for both PIN and PININPUT, so i think i can be sure to compare the saved digits in both variables.
or do i understand ${} wrong?

sorry again, i better make new logs after work

I’m pretty sure that there is something wrong with your use of quotes, and in particular, I think one string may be quoted twice, but what you have provided here has invalid quote characters, and I am not sure if that has happened when pasting into the forum, or in the actual files provided to Asterisk.

Your logs contain U+201C and U+201D characters, but all the quotes should be U+0022. (Left Double Quotation Mark, Right Double Quotation Mark, and Quotation Mark)

This is typically the results of using word processing type software.

Agreed with @david551 that the quoting/formatting issues make this tough to grok…

To clarify, in IVR #1, you want some type of administrator to set the PIN eg. once a week they dial in and change the PIN ?

Then, in IVR #2, you want some type of regular user to get that PIN eg. whenever they want to make a call out they have to enter the correct PIN ?

If the above are true, then I would suggest looking into the Asterisk internal database and associated DB functions instead of using GLOBAL.

oh no, i am going crazy like hell.
i really thought i tested it correct, but seems it was too late in the night yesterday.

it seems the problem occures from my global definition:
PIN = “123”

As long as i dont change the global defined “123”, the gosubif is always true, no matter was the PININPUT is.

PIN = 123 works well, only correct PININPUT gives positive feedback.

Thank you all for your inputs, and sorry for wasting your time :wink:

But now i have the question why makes gosubif the result positive not negative?
“123” is also not the same like DTMF inputs 444.

You are right, next step will be integrating the DB functions.
But with only one PIN it is ok with the variable, or is it a security risk to use global variables?

And you are half right, i develop an access system without the needing of an input terminal at the door.
The guest only need to know the number to call and the pin.
The admin can change the pin.
For the door i need only internet and a relaisbox.
Asterisk/VPN in the cloud, or local on a raspberry or something like this.
I like AstLinux :wink:

Minimal security risk in that scenario. Users are not exposed to the contents of your dial plan. Their phone can’t start telling them what global variables are set to unless you configure it that way eg. using Playback() application, allowing some other API access, etc.

The issue is that setting global variables on-the-fly will not persist between restarts (not a new feature, either.)

Try this on the Asterisk CLI:

*CLI> dialplan show globals

    -- 0 variable(s)
*CLI> dialplan set global SOMEPIN 1234

    -- Global variable 'SOMEPIN' set to '1234'
  == Setting global variable 'SOMEPIN' to '1234'
*CLI> dialplan show globals
   SOMEPIN=1234

    -- 1 variable(s)
*CLI> core restart now

Then reconnect to Asterisk CLI aaaaaaaaaaaand it’s gone!

*CLI> dialplan show globals

    -- 0 variable(s)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.