--- vmail.cgi.orig 2004-05-27 16:27:11.000000000 -0500 +++ vmail.cgi 2004-06-16 15:56:31.000000000 -0500 @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # # Web based Voicemail for Asterisk # @@ -10,12 +10,32 @@ # # (icky, I know.... if you know better perl please help!) # +# -------------------------------------------------------------------------------------------------------------- +# 20040614 wwarneck (wwarneck@scc.net) / Eric Osterberg (ejo1@scc.net) - Sound Choice Communications LLC - MN,US +# added support for db or flat file authentication schemes +# -------------------------------------------------------------------------------------------------------------- # use CGI qw/:standard/; use Carp::Heavy; use CGI::Carp qw(fatalsToBrowser); +# -- customizable stuff here ----------------------------------------------------------------------------------- + +# call custom authentication routine +%db = ( + hostname => "localhost", + username => "ast33isk", + password => "aSsew0", + database => "voicemail", + users => "users" +); +authentication_mysql(); + +$context = "default"; # Define here your by default context (so you dont need to put voicemail@context in the login @validfolders = ( "INBOX", "Old", "Work", "Family", "Friends", "Cust1", "Cust2", "Cust3", "Cust4", "Cust5" ); +$footer = "
\n";
-#$footer = " The Asterisk Open Source PBX Copyright 2002, Digium, Inc."; -$footer = " Sound Choice Communications"; $stdcontainerend = " |
$footer |
Mailbox is $1\n"; + #print "
Mailbox is $1\n"; if (($mbox eq $1) && ($pass eq $fields[0]) && ($context eq $category)) { + #print $fields[1] . " <- f1 and stringy thing -> Extension $mbox in $context cat -> $category"; return ($fields[1] ? $fields[1] : "Extension $mbox in $context", $category); } } @@ -115,6 +135,109 @@ return ("", $category); } +sub authentication_mysql() +{ + # voodoo magic + if(\&check_login != \&mysql_check_login) { + undef &check_login; + *check_login = \&mysql_check_login; + } + if(\&validmailbox != \&mysql_validmailbox) { + undef &validmailbox; + *validmailbox = \&mysql_validmailbox; + } + if(\&mailbox_list != \&mysql_mailbox_list) { + undef &mailbox_list; + *mailbox_list = \&mysql_mailbox_list; + } +} + +sub mysql_check_login() +{ + use DBI; + use DBD::mysql; + + local $sql; + local ($mbox, $context) = split(/\@/, param('mailbox')); + local $pass = param('password'); + + if (!$context) { + $context = "default"; + } + + $dbh = DBI->connect("dbi:mysql:$db{database}:$db{hostname}:","$db{username}","$db{password}"); + if (!$dbh) { + die("could not connect to $db{database}"); + } + + $sql = "SELECT * FROM $db{users} WHERE mailbox=? AND password=? AND context=?"; + $sth = $dbh->prepare($sql); + $rc = $sth->execute($mbox,$pass,$context); + if(!$rc) { die("bad db return value"); } + $row = $sth->fetchrow_hashref; + #print "sql: $sql :: mbox: $mbox :: pass: $pass"; + return($row->{fullname}); + +} + +sub mysql_validmailbox() +{ + use DBI; + use DBD::mysql; + + local $sql; + local ($mbox, $context) = split(/\@/, param('mailbox')); + local $pass = param('password'); + + if (!$context) { + $context = "default"; + } + + $dbh = DBI->connect("dbi:mysql:$db{database}:$db{hostname}:","$db{username}","$db{password}"); + if (!$dbh) { + die("could not connect to $db{database}"); + } + + $sql = "SELECT * FROM $db{users} WHERE mailbox=? AND context=?"; + $sth = $dbh->prepare($sql); + $rc = $sth->execute($mbox,$context); + if(!$rc) { die("bad db return value"); } + $row = $sth->fetchrow_hashref; + return($row->{email} ? $row->{email} : "unknown"); +} + +sub mysql_mailbox_list() +{ + use DBI; + use DBD::mysql; + + local ($name, $context, $current) = @_; + + local $sql; + local ($mbox, $context) = split(/\@/, param('mailbox')); + local $pass = param('password'); + + if (!$context) { + $context = "default"; + } + + $dbh = DBI->connect("dbi:mysql:$db{database}:$db{hostname}:","$db{username}","$db{password}"); + if (!$dbh) { + die("could not connect to $db{database}"); + } + + $sql = "SELECT * FROM $db{users}"; + $sth = $dbh->prepare($sql); + $rc = $sth->execute(); + if(!$rc) { die("bad db return value"); } + $ret = ""; + return($ret); +} + sub validmailbox() { local ($context, $mbox, $filename, $startcat) = @_; @@ -143,7 +266,7 @@ } } elsif (/\[(.*)\]/) { $category = $1; - } elsif (($category ne "general") && ($category eq $context)) { + } elsif (($category ne "general") && ($category ne "zonemessages") && ($category eq $context)) { if (/([^\s]+)\s*\=\>?\s*(.*)/) { @fields = split(/\,\s*/, $2); if (($mbox eq $1) && ($context eq $category)) { @@ -179,11 +302,11 @@ $tmp .= $tmp2; } elsif (/\[(.*)\]/) { $category = $1; - } elsif ($category ne "general") { + } elsif (($category ne "general") && ($category ne "zonemessages")) { if (/([^\s]+)\s*\=\>?\s*(.*)/) { @fields = split(/\,\s*/, $2); $text = "$1"; - if ($fields[2]) { + if ($fields[1]) { $text .= " ($fields[1])"; } if ($1 eq $current) { @@ -286,6 +409,7 @@ my ($nextaction, $msgid) = @_; my $folder = param('folder'); my $mbox = param('mailbox'); + my $context = param('context'); my $passwd = param('password'); my $format = param('format'); if (!$format) { @@ -374,7 +498,7 @@
$folder $msgid | |
Message: | $msgid |
Mailbox: | $mbox |
Mailbox: | $mbox\@$context |
Folder: | $folder |
From: | $fields->{callerid} |
Duration: | $duration |
Caller Channel: | $fields->{callerchan} |
-
+ - $mailboxes + $mailboxes $folders | |
- + |