aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-09-15 05:11:41 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-09-15 05:11:41 +0000
commiteb16af0cddd9859eef9113ff4540cd3e9be93673 (patch)
tree02af0471d880115e081d406d96ac4e5a23853b50
parent8565872fce68f0c733490a6f1000691a7c56558b (diff)
Support both MySQL and traditional mailboxes in vmail.cgi (bug #2297)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@3781 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xcontrib/scripts/vmail.cgi76
1 files changed, 76 insertions, 0 deletions
diff --git a/contrib/scripts/vmail.cgi b/contrib/scripts/vmail.cgi
index e398ec93f..8f98111e7 100755
--- a/contrib/scripts/vmail.cgi
+++ b/contrib/scripts/vmail.cgi
@@ -14,6 +14,7 @@
use CGI qw/:standard/;
use Carp::Heavy;
use CGI::Carp qw(fatalsToBrowser);
+use DBI;
$context=""; # Define here your by default context (so you dont need to put voicemail@context in the login
@@ -103,6 +104,28 @@ sub check_login()
}
} elsif (/\[(.*)\]/) {
$category = $1;
+ } elsif ($category eq "general") {
+ if (/([^\s]+)\s*\=\s*(.*)/) {
+ if ($1 eq "dbname") {
+ $dbname = $2;
+ } elsif ($1 eq "dbpass") {
+ $dbpass = $2;
+ } elsif ($1 eq "dbhost") {
+ $dbhost = $2;
+ } elsif ($1 eq "dbuser") {
+ $dbuser = $2;
+ }
+ }
+ if ($dbname and $dbpass and $dbhost and $dbuser) {
+
+ # db variables are present. Use db for authentication.
+ my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
+ my $sth = $dbh->prepare(qq{select fullname,context from users where mailbox='$mbox' and password='$pass' and context='$context'});
+ $sth->execute();
+ if (($fullname, $category) = $sth->fetchrow_array()) {;
+ return ($fullname ? $fullname : "Extension $mbox in $context",$category);
+ }
+ }
} elsif (($category ne "general") && ($category ne "zonemessages")) {
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
@fields = split(/\,\s*/, $2);
@@ -145,6 +168,28 @@ sub validmailbox()
}
} elsif (/\[(.*)\]/) {
$category = $1;
+ } elsif ($category eq "general") {
+ if (/([^\s]+)\s*\=\s*(.*)/) {
+ if ($1 eq "dbname") {
+ $dbname = $2;
+ } elsif ($1 eq "dbpass") {
+ $dbpass = $2;
+ } elsif ($1 eq "dbhost") {
+ $dbhost = $2;
+ } elsif ($1 eq "dbuser") {
+ $dbuser = $2;
+ }
+ }
+ if ($dbname and $dbpass and $dbhost and $dbuser) {
+
+ # db variables are present. Use db for authentication.
+ my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
+ my $sth = $dbh->prepare(qq{select fullname,context from users where mailbox='$mbox' and password='$pass' and context='$context'});
+ $sth->execute();
+ if (($fullname, $category) = $sth->fetchrow_array()) {;
+ return ($fullname ? $fullname : "unknown", $category);
+ }
+ }
} elsif (($category ne "general") && ($category ne "zonemessages") && ($category eq $context)) {
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
@fields = split(/\,\s*/, $2);
@@ -181,6 +226,37 @@ sub mailbox_options()
$tmp .= $tmp2;
} elsif (/\[(.*)\]/) {
$category = $1;
+ } elsif ($category eq "general") {
+ if (/([^\s]+)\s*\=\s*(.*)/) {
+ if ($1 eq "dbname") {
+ $dbname = $2;
+ } elsif ($1 eq "dbpass") {
+ $dbpass = $2;
+ } elsif ($1 eq "dbhost") {
+ $dbhost = $2;
+ } elsif ($1 eq "dbuser") {
+ $dbuser = $2;
+ }
+ }
+ if ($dbname and $dbpass and $dbhost and $dbuser) {
+
+ # db variables are present. Use db for authentication.
+ my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost",$dbuser,$dbpass);
+ my $sth = $dbh->prepare(qq{select mailbox,fullname,context from users where context='$context' order by mailbox});
+ $sth->execute();
+ while (($mailbox, $fullname, $category) = $sth->fetchrow_array()) {
+ $text = $mailbox;
+ if ($fullname) {
+ $text .= " (".$fullname.")";
+ }
+ if ($mailbox eq $current) {
+ $tmp .= "<OPTION SELECTED>$text</OPTION>\n";
+ } else {
+ $tmp .= "<OPTION>$text</OPTION>\n";
+ }
+ }
+ return ($tmp, $category);
+ }
} elsif (($category ne "general") && ($category ne "zonemessages")) {
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
@fields = split(/\,\s*/, $2);