login | register
Sat 17 of May, 2008 [12:58 UTC]

voip-info.org

Search with Google
Search this site with Google. Results may not include recent changes.
 
Google Ads
Shoutbox
  • Juan Ortega, Thu 15 of May, 2008 [10:33 UTC]: Hi everybody, I'm Juan, an ITCom student, and I need to know what basic elements I need to create a VoIP network. Can anybody helpme, please?,Thank you very much
  • gineta, Wed 14 of May, 2008 [03:58 UTC]: any here not fine the configuration of firewall juniper -screem for VOIP asterisk????
  • Anoop Prabhakaran, Tue 13 of May, 2008 [12:16 UTC]: I am developing Asterisk IVR, Whenever i make a internation call to the IVR system, the DTMF is not getting detected properly, this happens only for the first time, second call onwards system works fine. why this is happening
  • joe, Mon 12 of May, 2008 [04:27 UTC]: Is there an opensource browser based softphone, or a system like Busta where everything is not manages through their website?
  • Nick Barnes, Fri 09 of May, 2008 [11:36 UTC]: Christopher - yesterday I tried an Asterisk install on a CentOS 5.1 box with stock GUI and it all worked fine. Sorry I can't help.
  • aero, Fri 09 of May, 2008 [08:20 UTC]: can someone help me out on this, i tried to play some sound files on my asterisk box and this is the error message i got. WARNING[4429]: format_wav.c:169 check_header: Unexpected freqency 22050 May 8 11:17:39 WARNING[4433]: codec_gsm.c:194 gsmtolin_fra
  • Christopher Faust, Thu 08 of May, 2008 [14:15 UTC]: I beleive that I may have to change something in the xserver configuration. Please advise
  • Christopher Faust, Thu 08 of May, 2008 [14:14 UTC]: Everything was perfect. In the bios I have increased the memory allocated Still receive input not supported on my display.
  • Christopher Faust, Thu 08 of May, 2008 [14:13 UTC]: This would not be my main box. I am doing some testing to see if I can install zaptel and asterisk 1.4 on a full centos 5.1 box with development software Its bizzare, because before I went through the asterisk and zaptel installation everything was perfe
  • Nick Barnes, Thu 08 of May, 2008 [13:44 UTC]: Christopher - I can't see any way in which an Asterisk installation would muck your GUI, but remember that it is advised not to use a GUI on an Asterisk box anyway.
Server Stats
  • Execution time: 0.44s
  • Memory usage: 2.24MB
  • Database queries: 28
  • GZIP: Disabled
  • Server load: 0.94

Asterisk authenticate using voicemail passwords

I got full of having to tell users that we couldn't use their voicemail password in other
application, so I wrote this simple AGI script that parses voicemail.conf contents and
checks for a match against provided extension and password. It returns 0 on
success or 1 on failure.

Hope it help others to integrate application passwords.


chk_vm_pwd.agi



#!/usr/bin/perl

# AGI script that searchs for a match on an extension and password in 
# a voicemail.conf file
#
# Parameters: <voicemail config file path> | <extension> | <password>
#
#
# Written by: Andre D. Correa <andre(at)pobox.com> (03/jun/2005)
#

# Added by Suretec Systems Ltd - 10/06/2006
use strict;
use warnings;

use Asterisk::AGI;
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();

# Set variables according to supplied arquments
# Variables sanitation is not an issue as it is being run from extentions.conf
$vmconf = $ARGV[0];
$exten = $ARGV[1];
$pwd = $ARGV[2];

# Open VoiceMail configuration file read only
open VMCONF, "<$vmconf";
       @vmconf_lines = <VMCONF>;
close VMCONF;
&error_msg("Cannot open $vmconf file read only.") if $#vmconf_lines eq -1;

foreach (@vmconf_lines){
       next if $_ !~ /^\d/;
       $_ =~ s/\s//iog;
       $_ =~ s/=>/=/iog;
       $_ =~ s/=/\,/;
       (@line_args) = split(/\,/, $_);
       if ($exten eq $line_args[0]){ # We got the right extension
               if ($pwd eq $line_args[1]){ # User provided the right pwd
                       $AGI->set_variable('result','0');
               } else { # Wrong password - bye!
                       $AGI->set_variable('result','1');
               }
       }
}

exit;


sub error_msg() {
       my($err_msg) = @_;
       $AGI->verbose($err_msg);
       $AGI->hangup();
       die $err_msg;
}



To use it I make sonething like this in my extensions.conf file:

 exten => *122,1,Answer()
 exten => *122,2,Read(ext_num,vm-extension)
 exten => *122,3,Wait(1)
 exten => *122,4,Read(ext_pwd,vm-password)
 exten => *122,5,Wait(1)
 exten => *122,6,agi,chk_vm_pwd.agi|/etc/asterisk/voicemail.conf|${ext_num}|${ext_pwd}
 exten => *122,7,GotoIf($[["${result}" = "0"]?20:30)
 exten => *122,20,Playback(agent-loginok)
 exten => *122,21,Hangup()
 exten => *122,30,PlayBack(invalid)
 exten => *122,31,Hangup()

With this you can make all of your applications authenticate with the voicemail password. For sure a more robust authentication scheme is needed to Asterisk, meanwhile this will do the job.

I hope to make the script work looking on a MySQL database. I'll update this page if and when I have it done. Have fun!


Again, in PHP format

Another version, slightly simpler use written by Corey Frang. Uses PHP.


vm-pw.agi

#!/usr/bin/php -q
<?
 ob_implicit_flush(false);
 error_reporting(0);
 set_time_limit(5);

 $stdin = fopen('php://stdin', 'r');
 $stdlog = fopen('/var/log/asterisk/agitest.log', 'a');
 $debug = 0;

function read() { 
 global $stdin; 
 $input = str_replace("\n", "", fgets($stdin, 4096)); 
 dlog("read: $input\n"); 
 return $input; 


function write($line) { 
 dlog("write: $line\n"); 
 echo $line."\n"; 


function dlog($line) {
 global $debug, $stdlog;
 if ($debug) fputs($stdlog, $line);
}

// parse agi headers into array 
while ($env=read()) { 
 $s = split(": ",$env); 
 $agi[str_replace("agi_","",$s0)] = trim($s1);
 if (($env == "") || ($env == "\n")) { 
   break; 
 } 


$vmbox = $_SERVER["argv"][1];
$vmbox = trim($vmbox);
$parts = split("@",$vmbox);


$pwauth = 0;

$fp = fopen("/etc/asterisk/voicemail.conf","r");
while ($s = fgets($fp))
{
 if ($s{0} == ";") continue;
 $s = trim($s);
if (preg_match("/^\[(.*)\]/i", $s, $match))
 {
  if (strtolower($match[1]) == strtolower($parts[1]))
  {
    $right = 1; dlog($s."\n");
  } else {
    $right = 0;
  }
 }
if ($right && preg_match("/^(".$parts[0].")\s*\=\>\s*(\d*)/",$s,$match))
 {
   if (strtolower($match[1]) == strtolower($parts[0]))
   {
     $pwauth = $match[2]; dlog($pwauth."\n");
     fclose($fp);
   }
 }
}

if ($pwauth) {
  write("EXEC Authenticate $pwauth");
  $result = read();
  $resultcode = split("=", $result);
  if ($resultcode[1] == -1)
  {
    write("Hangup");
    read();
  }
} else {
  write("Hangup");
  read();
}

// clean up file handlers etc. 
fclose($in); 
fclose($stdlog); 
exit;  
 
?>


extensions.conf - example

exten => 120,1,Answer()
exten => 120,2,AGI(vm-pw.agi,2205@pstn)
exten => 120,3,Playback(lots-o-monkeys)

The only argument to this AGI is the extension and voicemail context to use. It uses "Authenticate" to get the password.
Created by Andre_C10002, Last modification by Gavin Henry on Sat 10 of Jun, 2006 [07:44 UTC]

Comments Filter

VMAuthenticate is a better command

by Michael Cargile on Tuesday 03 of October, 2006 [21:21:18 UTC]
Rather than using these agi scripts people really should use the command VMAuthenticate(). It does the same thing. I know the command is in version 1.2.7 and it was first posted on voip-info.org in Aug. of 2005.

http://www.voip-info.org/wiki/index.php?page=Asterisk%20cmd%20VMAuthenticate

Help please

by Teresa on Wednesday 05 of July, 2006 [21:19:42 UTC]
My agents cannot seem to login to their queue correctly. Is there a way I can restrict invalid logins to the queue so that my system doesn't go beserk when they put in *20 or 20221? any help greatly appreciated, I have searched all boards and read thru the guides and seem to be stuck. Thank you so much.. Teresa

email
teresa@expressautotransport.com

Help please

by Teresa on Wednesday 05 of July, 2006 [21:19:31 UTC]
My agents cannot seem to login to their queue correctly. Is there a way I can restrict invalid logins to the queue so that my system doesn't go beserk when they put in *20 or 20221? any help greatly appreciated, I have searched all boards and read thru the guides and seem to be stuck. Thank you so much.. Teresa

email
teresa@expressautotransport.com

Help please

by Teresa on Wednesday 05 of July, 2006 [21:18:57 UTC]
My agents cannot seem to login to their queue correctly. Is there a way I can restrict invalid logins to the queue so that my system doesn't go beserk when they put in *20 or 20221? any help greatly appreciated, I have searched all boards and read thru the guides and seem to be stuck. Thank you so much.. Teresa

email
teresa@expressautotransport.com

having problems with this

by vonageref on Thursday 01 of December, 2005 [21:11:08 UTC]
Hi,
I tried using the agi but it never seems to be able to set the result. hence it always goes to invalid can you please tell me what I'm doing wrong?
see my cli output:
   — Executing AGI("Zap/1-1", "chk_vm_pwd.agi|/etc/asterisk/voicemail.conf|70103|1234") in new stack
   — Launched AGI Script /var/lib/asterisk/agi-bin/chk_vm_pwd.agi
   — AGI Script chk_vm_pwd.agi completed, returning 0
   — Executing GotoIf("Zap/1-1", "0?20:30") in new stack


Also my extension.conf is below:

exten => s,5,Read(ext_pwd,vm-password)
exten => s,6,Wait(1)
exten => s,7,agi,chk_vm_pwd.agi|/etc/asterisk/voicemail.conf|${ext_num}|${ext_pwd}
exten => s,8,GotoIf($${result} : 1?20:30)

is doesn't seem to parse result back to the extension?
Any help will be appreciated

Re: Yep :-)

by hfwang on Wednesday 29 of June, 2005 [17:57:13 UTC]
even my quote about the brackets is missing in this post ;-)

Yep :-)

by hfwang on Wednesday 29 of June, 2005 [17:56:28 UTC]
Thanks for your last post, I just found out together with a friend that the wiki syntax 'f******' your script due to the missing ' '

I changed the returning value to 1 being positive and 0 for being negative. Just seemed more logical to me.

As for the script functinality itself... It simply works beautifully!!
I have created a 'HotDesk' dialplan, where there are no (visible device-extensions numbers, but just user numbers. User number are mapped to the device onto wich the user logges on to.

Simply put, walk to a phone, login and that phone is your extension, including voicemail and all other goodies. No need to inform anybody where 'you are at'. Walk to anohter phone and login, you will be automagically logged out of the other device. Logoff ll together and all goes to VM until the next time you login on a device.

Thanks for you great script, it was my missing puzzle piece!

Re: Typo??

by kumar_birju on Tuesday 28 of June, 2005 [08:28:43 UTC]
Hi , i also have a problem in passing the arg in agi script and accessing the passed value in the agi script for the calculation as if it be an integer. have u any way to solve the problem?



                           Thanks in advance

ARGV problem fixed

by Andre_C10002 on Wednesday 22 of June, 2005 [16:46:21 UTC]
I found a way to fix the ARGV[] issue. The script should be fine now. Sorry for the inconvenience. Hopefully I'll find time to review the script regarding user suggestions.

tks

As I said...

by Andre_C10002 on Wednesday 22 of June, 2005 [15:07:26 UTC]
As I said before this is my quick and dirty solution to a problem I faced. For sure there are lots of options and improvements like: environ variables, no args, don't parsing the whole file, etc... I didn't gave myself the time to think about then. Please contribute to the community.

The real issue here is that Tiki evaluated my ARGV as a web link which is wrong. I don't know how to fix this, it should be easy. If anybody know please fix it. Meanwhile, please get the script from the tiki source. Sorry for that.

I'll try to find time to think about the sugestions and post a revised script later.

Please update this page with new information, just login and click on the "Edit" or "Add Comment" button above. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

Sponsored by:

Terms of Service Privacy Policy
© 2003-2008 VOIP-Info.org LLC

Powered by bitweaver