Need some help with some dialplan logic

I use this piece of logic to generate passwords and such. I was curious if someone could help point out some of the errors in it. I pretty much play with this stuff for fun, any pointers would be appreciated.

Thanx

[random]

exten => 7263,1,Answer()
exten => 7263,n,Background(welcome&and-prs-pound-whn-finished)
exten => 7263,n,WaitExten(1.5)
exten => 7263,n,Background(press-1&for&/var/lib/asterisk/sounds/letters/a&/var/lib/asterisk/sounds/digits/10&digit&number)
exten => 7263,n,WaitExten(1.5)
exten => 7263,n,Background(press-2&for&/var/lib/asterisk/sounds/letters/a&/var/lib/asterisk/sounds/digits/12&digit&number)
exten => 7263,n,WaitExten(1.5)
exten => 7263,n,Background(press-3&for&/var/lib/asterisk/sounds/letters/a&/var/lib/asterisk/sounds/digits/16&digit&number)
exten => 7263,n,WaitExten(1.5)
exten => 7263,n,Background(press-4&for&/var/lib/asterisk/sounds/letters/a&/var/lib/asterisk/sounds/digits/30&/var/lib/asterisk/sounds/digits/2&digit&number)
exten => 7263,n,Goto(7263,1)

exten => 1,1,System(openssl rand -out /var/tmp/rand.txt -base64 7)
exten => 1,n,ReadFile(NUM=/var/tmp/rand.txt)
exten => 1,n,Sayalpha(${NUM})
exten => 1,n,WaitExten(1)
exten => 1,n,Goto(1,2)

exten => 2,1,System(openssl rand -out /var/tmp/rand.txt -base64 9)
exten => 2,n,ReadFile(NUM=/var/tmp/rand.txt)
exten => 2,n,Sayalpha(${NUM})
exten => 2,n,WaitExten(1)
exten => 2,n,Goto(2,2)

exten => 3,1,System(openssl rand -out /var/tmp/rand.txt -base64 12.5)
exten => 3,n,ReadFile(NUM=/var/tmp/rand.txt)
exten => 3,n,Sayalpha(${NUM})
exten => 3,n,WaitExten(1)
exten => 3,n,Goto(3,2)

exten => 4,1,System(openssl rand -out /var/tmp/rand.txt -base64 24)
exten => 4,n,ReadFile(NUM=/var/tmp/rand.txt)
exten => 4,n,Sayalpha(${NUM})
exten => 4,n,WaitExten(1)
exten => 4,n,Goto(4,2)

exten => #,1,System(rm /var/tmp/rand.txt)
exten => #,n,Playback(thank-you-cooperation)
exten => #,n,Hangup()

exten => h,1,System(rm /var/tmp/rand.txt)

are you having any problems with it? Coding dialplan logic is like anything else…everyone has their own way of doing things. So my way is different but not necessarily better than your way.

But some things that I would do different…are:

  1. Since random is a context, in my dialplan I would have a line for whatever number you dial to go to random.
    exten => 7263,1,Goto(Random,s,1)
    then I would change the references in random for 7263 to s.

  2. This routine since you use a specific file name would have problems if more than one person tried to do it at the same time. Make your filename have something unique in it, like the channel being used.

  3. You probably could use a macro for the call to the openssl code.

exten => 1,1,Macro(openssl,7)
exten => 2,1,Macro(openssl,9)
exten => 3,1,Macro(openssl,12.5)
exten => 4,1,Macro(openssl,24)

[macro-openssl]
exten => s,1,System(openssl rand -out /var/tmp/rand.txt -base64 ${ARG1})
exten => s,n,ReadFile(NUM=/var/tmp/rand.txt)
exten => s,n,Sayalpha(${NUM})
exten => s,n,WaitExten(1)
exten => s,n,Goto(s,2)

Thank you very much, That is exactly the kind of help I was looking for. I had realised shortly after my posting, the shortcomings of the filename being static. It causes a very strange effect on the call when two people access it. I will learn alot about using macros from your post for sure. Asterisk is really my first forray into programming of any sort, as im really a hardware hacking kind a guy. I must say its very fun. That previous example is my “hello world” program, I wanted my first piece of logic to be about a pseudo random feature of sorts.