[Asterisk-cvs] asterisk/contrib/scripts vmail.cgi,1.12,1.13
markster at lists.digium.com
markster at lists.digium.com
Wed Sep 15 01:10:10 CDT 2004
Update of /usr/cvsroot/asterisk/contrib/scripts
In directory mongoose.digium.com:/tmp/cvs-serv23895/contrib/scripts
Modified Files:
vmail.cgi
Log Message:
Support both MySQL and traditional mailboxes in vmail.cgi (bug #2297)
Index: vmail.cgi
===================================================================
RCS file: /usr/cvsroot/asterisk/contrib/scripts/vmail.cgi,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- vmail.cgi 6 Sep 2004 06:19:17 -0000 1.12
+++ vmail.cgi 15 Sep 2004 05:11:41 -0000 1.13
@@ -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 at context in the login
@@ -103,6 +104,28 @@
}
} 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 @@
}
} 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 @@
$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);
More information about the svn-commits
mailing list