mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
Make vmail handle things properly in the case of included contexts
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1021 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -197,6 +197,8 @@ int ast_channel_register_ex(char *type, char *description, int capabilities,
|
|||||||
|
|
||||||
char *ast_state2str(int state)
|
char *ast_state2str(int state)
|
||||||
{
|
{
|
||||||
|
/* XXX Not reentrant XXX */
|
||||||
|
static char localtmp[256];
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case AST_STATE_DOWN:
|
case AST_STATE_DOWN:
|
||||||
return "Down";
|
return "Down";
|
||||||
@@ -215,7 +217,8 @@ char *ast_state2str(int state)
|
|||||||
case AST_STATE_BUSY:
|
case AST_STATE_BUSY:
|
||||||
return "Busy";
|
return "Busy";
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
snprintf(localtmp, sizeof(localtmp), "Unknown (%d)\n", state);
|
||||||
|
return localtmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
use CGI qw/:standard/;
|
use CGI qw/:standard/;
|
||||||
|
use Carp::Heavy;
|
||||||
use CGI::Carp qw(fatalsToBrowser);
|
use CGI::Carp qw(fatalsToBrowser);
|
||||||
|
|
||||||
@validfolders = ( "INBOX", "Old", "Work", "Family", "Friends", "Cust1", "Cust2", "Cust3", "Cust4", "Cust5" );
|
@validfolders = ( "INBOX", "Old", "Work", "Family", "Friends", "Cust1", "Cust2", "Cust3", "Cust4", "Cust5" );
|
||||||
@@ -67,64 +68,115 @@ _EOH
|
|||||||
|
|
||||||
sub check_login()
|
sub check_login()
|
||||||
{
|
{
|
||||||
my ($mbox, $context) = split(/\@/, param('mailbox'));
|
local ($filename, $startcat) = @_;
|
||||||
my $pass = param('password');
|
local ($mbox, $context) = split(/\@/, param('mailbox'));
|
||||||
my $category = "general";
|
local $pass = param('password');
|
||||||
my @fields;
|
local $category = $startcat;
|
||||||
|
local @fields;
|
||||||
|
local $tmp;
|
||||||
|
local (*VMAIL);
|
||||||
|
if (!$category) {
|
||||||
|
$category = "general";
|
||||||
|
}
|
||||||
if (!$context) {
|
if (!$context) {
|
||||||
$context = param('context');
|
$context = param('context');
|
||||||
}
|
}
|
||||||
if (!$context) {
|
if (!$context) {
|
||||||
$context = "default";
|
$context = "default";
|
||||||
}
|
}
|
||||||
open(VMAIL, "</etc/asterisk/voicemail.conf") || die("Bleh, no voicemail.conf");
|
if (!$filename) {
|
||||||
|
$filename = "/etc/asterisk/voicemail.conf";
|
||||||
|
}
|
||||||
|
# print header;
|
||||||
|
# print "Including <h2>$filename</h2> while in <h2>$category</h2>...\n";
|
||||||
|
open(VMAIL, "<$filename") || die("Bleh, no $filename");
|
||||||
while(<VMAIL>) {
|
while(<VMAIL>) {
|
||||||
chomp;
|
chomp;
|
||||||
if (/\[(.*)\]/) {
|
if (/include\s\"([^\"]+)\"$/) {
|
||||||
|
($tmp, $category) = &check_login("/etc/asterisk/$1", $category);
|
||||||
|
if (length($tmp)) {
|
||||||
|
# print "Got '$tmp'\n";
|
||||||
|
return ($tmp, $category);
|
||||||
|
}
|
||||||
|
} elsif (/\[(.*)\]/) {
|
||||||
$category = $1;
|
$category = $1;
|
||||||
} elsif ($category ne "general") {
|
} elsif ($category ne "general") {
|
||||||
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
||||||
@fields = split(/\,\s*/, $2);
|
@fields = split(/\,\s*/, $2);
|
||||||
|
# print "<p>Mailbox is $1\n";
|
||||||
if (($mbox eq $1) && ($pass eq $fields[0]) && ($context eq $category)) {
|
if (($mbox eq $1) && ($pass eq $fields[0]) && ($context eq $category)) {
|
||||||
return $fields[1] ? $fields[1] : "Extension $mbox in $context";
|
return ($fields[1] ? $fields[1] : "Extension $mbox in $context", $category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(VMAIL);
|
||||||
|
return ("", $category);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub validmailbox()
|
sub validmailbox()
|
||||||
{
|
{
|
||||||
my ($context, $mbox) = @_;
|
local ($context, $mbox, $filename, $startcat) = @_;
|
||||||
my $category = "general";
|
local $category = $startcat;
|
||||||
my @fields;
|
local @fields;
|
||||||
open(VMAIL, "</etc/asterisk/voicemail.conf") || die("Bleh, no voicemail.conf");
|
local (*VMAIL);
|
||||||
|
if (!$context) {
|
||||||
|
$context = param('context');
|
||||||
|
}
|
||||||
|
if (!$context) {
|
||||||
|
$context = "default";
|
||||||
|
}
|
||||||
|
if (!$filename) {
|
||||||
|
$filename = "/etc/asterisk/voicemail.conf";
|
||||||
|
}
|
||||||
|
if (!$category) {
|
||||||
|
$category = "general";
|
||||||
|
}
|
||||||
|
open(VMAIL, "<$filename") || die("Bleh, no $filename");
|
||||||
while(<VMAIL>) {
|
while(<VMAIL>) {
|
||||||
chomp;
|
chomp;
|
||||||
if (/\[(.*)\]/) {
|
if (/include\s\"([^\"]+)\"$/) {
|
||||||
|
($tmp, $category) = &validmailbox($mbox, $context, "/etc/asterisk/$1");
|
||||||
|
if ($tmp) {
|
||||||
|
return ($tmp, $category);
|
||||||
|
}
|
||||||
|
} elsif (/\[(.*)\]/) {
|
||||||
$category = $1;
|
$category = $1;
|
||||||
} elsif (($category ne "general") && ($category eq $context)) {
|
} elsif (($category ne "general") && ($category eq $context)) {
|
||||||
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
||||||
@fields = split(/\,\s*/, $2);
|
@fields = split(/\,\s*/, $2);
|
||||||
if ($mbox eq $1) {
|
if (($mbox eq $1) && ($context eq $category)) {
|
||||||
return $fields[2] ? $fields[2] : "unknown";
|
return ($fields[2] ? $fields[2] : "unknown", $category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ("", $category);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub mailbox_list()
|
sub mailbox_options()
|
||||||
{
|
{
|
||||||
my ($name, $context, $current) = @_;
|
local($context, $current, $filename, $category) = @_;
|
||||||
my $tmp;
|
local (*VMAIL);
|
||||||
my $text;
|
local $tmp2;
|
||||||
$tmp = "<SELECT name=\"$name\">\n";
|
local $tmp;
|
||||||
open(VMAIL, "</etc/asterisk/voicemail.conf") || die("Bleh, no voicemail.conf");
|
if (!$filename) {
|
||||||
|
$filename = "/etc/asterisk/voicemail.conf";
|
||||||
|
}
|
||||||
|
if (!$category) {
|
||||||
|
$category = "general";
|
||||||
|
}
|
||||||
|
# print header;
|
||||||
|
# print "Including <h2>$filename</h2> while in <h2>$category</h2>...\n";
|
||||||
|
open(VMAIL, "<$filename") || die("Bleh, no voicemail.conf");
|
||||||
while(<VMAIL>) {
|
while(<VMAIL>) {
|
||||||
chomp;
|
chomp;
|
||||||
s/\;.*$//;
|
s/\;.*$//;
|
||||||
if (/\[(.*)\]/) {
|
if (/include\s\"([^\"]+)\"$/) {
|
||||||
|
($tmp2, $category) = &mailbox_options($context, $current, "/etc/asterisk/$1", $category);
|
||||||
|
# print "Got '$tmp2'...\n";
|
||||||
|
$tmp .= $tmp2;
|
||||||
|
} elsif (/\[(.*)\]/) {
|
||||||
$category = $1;
|
$category = $1;
|
||||||
} elsif ($category ne "general") {
|
} elsif ($category ne "general") {
|
||||||
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
||||||
@@ -139,12 +191,26 @@ sub mailbox_list()
|
|||||||
$tmp .= "<OPTION>$text</OPTION>\n";
|
$tmp .= "<OPTION>$text</OPTION>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($mbox eq $1) && ($pass eq $fields[0])) {
|
|
||||||
return $fields[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(VMAIL);
|
||||||
|
return ($tmp, $category);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub mailbox_list()
|
||||||
|
{
|
||||||
|
local ($name, $context, $current) = @_;
|
||||||
|
local $tmp;
|
||||||
|
local $text;
|
||||||
|
local $tmp;
|
||||||
|
local $opts;
|
||||||
|
if (!$context) {
|
||||||
|
$context = "default";
|
||||||
|
}
|
||||||
|
$tmp = "<SELECT name=\"$name\">\n";
|
||||||
|
($opts) = &mailbox_options($context, $current);
|
||||||
|
$tmp .= $opts;
|
||||||
$tmp .= "</SELECT>\n";
|
$tmp .= "</SELECT>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -811,8 +877,8 @@ if (param()) {
|
|||||||
@msgs = param('msgselect');
|
@msgs = param('msgselect');
|
||||||
@msgs = ($msgid) unless @msgs;
|
@msgs = ($msgid) unless @msgs;
|
||||||
{
|
{
|
||||||
$mailbox = check_login();
|
($mailbox) = &check_login();
|
||||||
if ($mailbox) {
|
if (length($mailbox)) {
|
||||||
if ($action eq 'login') {
|
if ($action eq 'login') {
|
||||||
&message_index($folder, "Welcome, $mailbox");
|
&message_index($folder, "Welcome, $mailbox");
|
||||||
} elsif (($action eq 'refresh') || ($action eq 'index')) {
|
} elsif (($action eq 'refresh') || ($action eq 'index')) {
|
||||||
|
118
vmail.cgi
118
vmail.cgi
@@ -12,6 +12,7 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
use CGI qw/:standard/;
|
use CGI qw/:standard/;
|
||||||
|
use Carp::Heavy;
|
||||||
use CGI::Carp qw(fatalsToBrowser);
|
use CGI::Carp qw(fatalsToBrowser);
|
||||||
|
|
||||||
@validfolders = ( "INBOX", "Old", "Work", "Family", "Friends", "Cust1", "Cust2", "Cust3", "Cust4", "Cust5" );
|
@validfolders = ( "INBOX", "Old", "Work", "Family", "Friends", "Cust1", "Cust2", "Cust3", "Cust4", "Cust5" );
|
||||||
@@ -67,64 +68,115 @@ _EOH
|
|||||||
|
|
||||||
sub check_login()
|
sub check_login()
|
||||||
{
|
{
|
||||||
my ($mbox, $context) = split(/\@/, param('mailbox'));
|
local ($filename, $startcat) = @_;
|
||||||
my $pass = param('password');
|
local ($mbox, $context) = split(/\@/, param('mailbox'));
|
||||||
my $category = "general";
|
local $pass = param('password');
|
||||||
my @fields;
|
local $category = $startcat;
|
||||||
|
local @fields;
|
||||||
|
local $tmp;
|
||||||
|
local (*VMAIL);
|
||||||
|
if (!$category) {
|
||||||
|
$category = "general";
|
||||||
|
}
|
||||||
if (!$context) {
|
if (!$context) {
|
||||||
$context = param('context');
|
$context = param('context');
|
||||||
}
|
}
|
||||||
if (!$context) {
|
if (!$context) {
|
||||||
$context = "default";
|
$context = "default";
|
||||||
}
|
}
|
||||||
open(VMAIL, "</etc/asterisk/voicemail.conf") || die("Bleh, no voicemail.conf");
|
if (!$filename) {
|
||||||
|
$filename = "/etc/asterisk/voicemail.conf";
|
||||||
|
}
|
||||||
|
# print header;
|
||||||
|
# print "Including <h2>$filename</h2> while in <h2>$category</h2>...\n";
|
||||||
|
open(VMAIL, "<$filename") || die("Bleh, no $filename");
|
||||||
while(<VMAIL>) {
|
while(<VMAIL>) {
|
||||||
chomp;
|
chomp;
|
||||||
if (/\[(.*)\]/) {
|
if (/include\s\"([^\"]+)\"$/) {
|
||||||
|
($tmp, $category) = &check_login("/etc/asterisk/$1", $category);
|
||||||
|
if (length($tmp)) {
|
||||||
|
# print "Got '$tmp'\n";
|
||||||
|
return ($tmp, $category);
|
||||||
|
}
|
||||||
|
} elsif (/\[(.*)\]/) {
|
||||||
$category = $1;
|
$category = $1;
|
||||||
} elsif ($category ne "general") {
|
} elsif ($category ne "general") {
|
||||||
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
||||||
@fields = split(/\,\s*/, $2);
|
@fields = split(/\,\s*/, $2);
|
||||||
|
# print "<p>Mailbox is $1\n";
|
||||||
if (($mbox eq $1) && ($pass eq $fields[0]) && ($context eq $category)) {
|
if (($mbox eq $1) && ($pass eq $fields[0]) && ($context eq $category)) {
|
||||||
return $fields[1] ? $fields[1] : "Extension $mbox in $context";
|
return ($fields[1] ? $fields[1] : "Extension $mbox in $context", $category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(VMAIL);
|
||||||
|
return ("", $category);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub validmailbox()
|
sub validmailbox()
|
||||||
{
|
{
|
||||||
my ($context, $mbox) = @_;
|
local ($context, $mbox, $filename, $startcat) = @_;
|
||||||
my $category = "general";
|
local $category = $startcat;
|
||||||
my @fields;
|
local @fields;
|
||||||
open(VMAIL, "</etc/asterisk/voicemail.conf") || die("Bleh, no voicemail.conf");
|
local (*VMAIL);
|
||||||
|
if (!$context) {
|
||||||
|
$context = param('context');
|
||||||
|
}
|
||||||
|
if (!$context) {
|
||||||
|
$context = "default";
|
||||||
|
}
|
||||||
|
if (!$filename) {
|
||||||
|
$filename = "/etc/asterisk/voicemail.conf";
|
||||||
|
}
|
||||||
|
if (!$category) {
|
||||||
|
$category = "general";
|
||||||
|
}
|
||||||
|
open(VMAIL, "<$filename") || die("Bleh, no $filename");
|
||||||
while(<VMAIL>) {
|
while(<VMAIL>) {
|
||||||
chomp;
|
chomp;
|
||||||
if (/\[(.*)\]/) {
|
if (/include\s\"([^\"]+)\"$/) {
|
||||||
|
($tmp, $category) = &validmailbox($mbox, $context, "/etc/asterisk/$1");
|
||||||
|
if ($tmp) {
|
||||||
|
return ($tmp, $category);
|
||||||
|
}
|
||||||
|
} elsif (/\[(.*)\]/) {
|
||||||
$category = $1;
|
$category = $1;
|
||||||
} elsif (($category ne "general") && ($category eq $context)) {
|
} elsif (($category ne "general") && ($category eq $context)) {
|
||||||
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
||||||
@fields = split(/\,\s*/, $2);
|
@fields = split(/\,\s*/, $2);
|
||||||
if ($mbox eq $1) {
|
if (($mbox eq $1) && ($context eq $category)) {
|
||||||
return $fields[2] ? $fields[2] : "unknown";
|
return ($fields[2] ? $fields[2] : "unknown", $category);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ("", $category);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub mailbox_list()
|
sub mailbox_options()
|
||||||
{
|
{
|
||||||
my ($name, $context, $current) = @_;
|
local($context, $current, $filename, $category) = @_;
|
||||||
my $tmp;
|
local (*VMAIL);
|
||||||
my $text;
|
local $tmp2;
|
||||||
$tmp = "<SELECT name=\"$name\">\n";
|
local $tmp;
|
||||||
open(VMAIL, "</etc/asterisk/voicemail.conf") || die("Bleh, no voicemail.conf");
|
if (!$filename) {
|
||||||
|
$filename = "/etc/asterisk/voicemail.conf";
|
||||||
|
}
|
||||||
|
if (!$category) {
|
||||||
|
$category = "general";
|
||||||
|
}
|
||||||
|
# print header;
|
||||||
|
# print "Including <h2>$filename</h2> while in <h2>$category</h2>...\n";
|
||||||
|
open(VMAIL, "<$filename") || die("Bleh, no voicemail.conf");
|
||||||
while(<VMAIL>) {
|
while(<VMAIL>) {
|
||||||
chomp;
|
chomp;
|
||||||
s/\;.*$//;
|
s/\;.*$//;
|
||||||
if (/\[(.*)\]/) {
|
if (/include\s\"([^\"]+)\"$/) {
|
||||||
|
($tmp2, $category) = &mailbox_options($context, $current, "/etc/asterisk/$1", $category);
|
||||||
|
# print "Got '$tmp2'...\n";
|
||||||
|
$tmp .= $tmp2;
|
||||||
|
} elsif (/\[(.*)\]/) {
|
||||||
$category = $1;
|
$category = $1;
|
||||||
} elsif ($category ne "general") {
|
} elsif ($category ne "general") {
|
||||||
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
if (/([^\s]+)\s*\=\>?\s*(.*)/) {
|
||||||
@@ -139,12 +191,26 @@ sub mailbox_list()
|
|||||||
$tmp .= "<OPTION>$text</OPTION>\n";
|
$tmp .= "<OPTION>$text</OPTION>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($mbox eq $1) && ($pass eq $fields[0])) {
|
|
||||||
return $fields[1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(VMAIL);
|
||||||
|
return ($tmp, $category);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub mailbox_list()
|
||||||
|
{
|
||||||
|
local ($name, $context, $current) = @_;
|
||||||
|
local $tmp;
|
||||||
|
local $text;
|
||||||
|
local $tmp;
|
||||||
|
local $opts;
|
||||||
|
if (!$context) {
|
||||||
|
$context = "default";
|
||||||
|
}
|
||||||
|
$tmp = "<SELECT name=\"$name\">\n";
|
||||||
|
($opts) = &mailbox_options($context, $current);
|
||||||
|
$tmp .= $opts;
|
||||||
$tmp .= "</SELECT>\n";
|
$tmp .= "</SELECT>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -811,8 +877,8 @@ if (param()) {
|
|||||||
@msgs = param('msgselect');
|
@msgs = param('msgselect');
|
||||||
@msgs = ($msgid) unless @msgs;
|
@msgs = ($msgid) unless @msgs;
|
||||||
{
|
{
|
||||||
$mailbox = check_login();
|
($mailbox) = &check_login();
|
||||||
if ($mailbox) {
|
if (length($mailbox)) {
|
||||||
if ($action eq 'login') {
|
if ($action eq 'login') {
|
||||||
&message_index($folder, "Welcome, $mailbox");
|
&message_index($folder, "Welcome, $mailbox");
|
||||||
} elsif (($action eq 'refresh') || ($action eq 'index')) {
|
} elsif (($action eq 'refresh') || ($action eq 'index')) {
|
||||||
|
Reference in New Issue
Block a user