diff options
author | James Bottomley <JBottomley@Parallels.com> | 2013-05-01 23:19:27 -0700 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-05-01 23:22:07 -0700 |
commit | d3a081b062198a8b843b86f9e8ccc332b517422f (patch) | |
tree | 2614fef73b4857e27492e4673b90bcb75ec5a552 | |
parent | 1ffd06749871587fef73a4f4188fc24aadd928da (diff) | |
download | asterisk-aastra-d3a081b062198a8b843b86f9e8ccc332b517422f.tar.gz |
Voicemail: initial implementation
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | etc/extensions-voicemail.conf | 7 | ||||
-rw-r--r-- | include/Voicemail.class.php | 105 | ||||
-rw-r--r-- | include/VoicemailListManager.class.php | 46 | ||||
-rw-r--r-- | voicemail.php | 5 |
5 files changed, 177 insertions, 2 deletions
@@ -46,11 +46,18 @@ blacklist-files = \ include/Blacklist.class.php \ include/BlacklistManager.class.php +blacklist-doc-files = \ + etc/extensions-blacklist.conf + actionuri-files = \ include/ActionURIHandler.class.php -blacklist-doc-files = \ - etc/extensions-blacklist.conf +voicemail-files = \ + include/Voicemail.class.php \ + include/VoicemailListManager.class.php + +voicemail-doc-files = \ + etc/extensions-voicemail.conf packages := blacklist actionuri @@ -82,3 +89,8 @@ install-blacklist: install-php install-web install-actionuri: install-php install-web install -m 0644 $(actionuri-files) $(php_prefix) install -m 0644 actionuri.php $(web_prefix) + +install-voicemail: install-php install-web + install -m 0644 $(voicemail-files) $(php_prefix) + install -m 0644 voicemail.php $(web_prefix) + install -m 0644 $(voicemail-doc-files) $(doc_prefix) diff --git a/etc/extensions-voicemail.conf b/etc/extensions-voicemail.conf new file mode 100644 index 0000000..68563b6 --- /dev/null +++ b/etc/extensions-voicemail.conf @@ -0,0 +1,7 @@ +; +; vmail is a private extension used by the Aastra XML system to play +; individual messages +; +exten => vmail,1,Set(file=${DB(vmail/${CALLERID(num)})}) +exten => vmail,n,ControlPlayback(${file}) +exten => vmail,n,Hangup diff --git a/include/Voicemail.class.php b/include/Voicemail.class.php new file mode 100644 index 0000000..01def46 --- /dev/null +++ b/include/Voicemail.class.php @@ -0,0 +1,105 @@ +<?php +require_once('BaseAastra.class.php'); +require_once('AastraIPPhoneTextScreen.class.php'); +require_once('VoicemailListManager.class.php'); + +class Voicemail extends BaseAastra { + + var $mapping = array ( + 'INBOX' => 'new messages', + 'Old' => 'old messages', + 'Work' => 'work messages', + 'Family' => 'family messages', + 'Friends' => 'friends messages', + ); + + var $mailbox; + var $path = '/var/spool/asterisk/voicemail/default'; #fixme + var $box; + + private function __readbox($box) { + $this->box[$box] = array(); + + if (!file_exists($this->path.'/'.$box)) { + return; + } + + $d = dir($this->path.'/'.$box); + if (!$d) { + return; + } + while (false !== ($entry = $d->read())) { + if (preg_match('/(.*)\.txt$/', $entry, $m)) { + $this->box[$box][] = $m[1]; + } + } + $d->close(); + } + + private function __initvar() { + $this->mailbox = $this->asm->database_get('mboxmap', $this->user); + if ($this->mailbox == '') { + throw new Exception('You have no configured mailbox'); + } + $this->path .= '/'.$this->mailbox; + $this->box = array(); + foreach($this->mapping as $k => $v) { + $this->__readbox($k); + } + $this->title = 'Voicemail Box '.$this->mailbox; + } + + function __construct() { + parent::__construct(); + $this->__initvar(); + } + + function message() { + $box = $_GET['box']; + $msg = $_GET['msg']; + if (isset($_GET['play'])) { + $this->asm->database_put('vmail', $this->user, $this->path.'/'.$box.'/'.$msg); + require_once('AastraIPPhoneExecute.class.php'); + $this->displayObject( new AastraIPPhoneExecute()); + $this->do->addEntry('Dial:vmail'); + $this->setActionHandler('outgoing',$this->url.'?action=message&box='.$box.'&msg='.$msg.'&playing=1'); + return; + } + + $this->back = $this->url.'?action=mailbox&box='.$box; + preg_match('/^msg(\d*)$/', $msg, $m); + $i = intval($m[1]) + 1; + $c = new ConfigFile($this->path.'/'.$box.'/'.$msg.'.txt'); + $m = $c->section('message'); + $this->title = 'Mailbox '.$box.' Message: '.$i; + $this->displayObject(new AastraIPPhoneTextScreen()); + $this->do->setText('Received: '.$m['origdate'].' From: '.$m['callerid'].' length '.$m['duration'].' seconds'); + $this->do->addSoftkey(1, 'Play', $this->url.'?action=message&box='.$box.'&msg='.$msg.'&play=1'); + if (isset($_GET['playing'])) { + $this->do->addSoftkey(2, 'Stop', $this->url.'?action=message&box='.$box.'&msg='.$msg.'&play=1'); + } + } + + function mailbox() { + $box = $_GET['box']; + $this->title = $this->mapping[$box]; + $list = new VoicemailListManager($this, $this->url.'?action=mailbox&box='.$box); + $list->manager($box, $this->url.'?action=message&box='.$box.'&msg='); + } + + function start() { + $text = 'Voicemail has'; + $this->displayObject(new AastraIPPhoneTextScreen()); + $softkey = 1; + foreach ($this->mapping as $k => $v) { + $c = count($this->box[$k]); + $text .= ' '.$c.' '.$v; + if ($c) { + $this->do->addSoftkey($softkey, $v, $this->url.'?action=mailbox&box='.$k); + } + $softkey++; + } + $this->do->setText($text); + } +} +?> diff --git a/include/VoicemailListManager.class.php b/include/VoicemailListManager.class.php new file mode 100644 index 0000000..c94d7b6 --- /dev/null +++ b/include/VoicemailListManager.class.php @@ -0,0 +1,46 @@ +<?php +## +# Copyright 2013 by James Bottomley +## +# Class implementing a wrapper for managing lists in the database +## +require_once('BaseList.class.php'); +require_once('ConfigFile.class.php'); + +class VoicemailListManager extends BaseList { + ## + # hacking inner classes. This list manager should really be + # the inner class of the overall object, so it has access + # to the known BaseAastra functions. However, hack it like this + # so $this->outer is a pointer to the outer class + ## + var $outer; + + function __construct($outer, $url) { + $this->outer = $outer; + parent::__construct($url); + } + + ## + # The manager() function takes the name of the database list + # the + function manager($box, $selecturl) { + $this->data = array(); + $this->files = $this->outer->box[$box]; + $this->path = $this->outer->path.'/'.$box; + sort($this->files); + foreach($this->files as $v) { + preg_match('/^msg(\d*)$/', $v, $m); + $i = intval($m[1]) + 1; + $c = new ConfigFile($this->path.'/'.$v.'.txt'); + $m = $c->section('message'); + $a = array(); + $a[0] = $i.': '.$m['origdate']; + $a[1] = $selecturl.$v; + $this->data[] = $a; + } + $this->outer->displayObject($this); + $this->build(); + } +} +?> diff --git a/voicemail.php b/voicemail.php new file mode 100644 index 0000000..56c1665 --- /dev/null +++ b/voicemail.php @@ -0,0 +1,5 @@ +<?php + require_once('asterisk-aastra/Voicemail.class.php'); + $c = new Voicemail(); + $c->init(); +?> |