diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..3b20440 --- /dev/null +++ b/COPYING @@ -0,0 +1,458 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/README b/README new file mode 100644 index 0000000..91bedab --- /dev/null +++ b/README @@ -0,0 +1,52 @@ +PHPAGI README + $Id$ +--------------------------------------- + +Welcome to PHPAGI. + +phpagi is a set of PHP classes for use in developing applications with +the Asterisk Gateway Interface, and is licensed under the GNU Lesser +General Public License (see COPYING for terms). + +This release (version 2) of the phpagi classes is a significant overhaul +from the old version 1 library. API functions have been renamed and +restructured. + +Version 1 of phpagi is no longer supported, but will continue to be +available for historical purposes. We strongly encourage you to migrate +to this new version. + +If you have developed software based around phpagi, we'd like to hear from +you! Drop us a note, and indicate whether you'd like us to list your +application on our website. + +FILES +----- + phpagi.php - The main phpagi class. + phpagi-asmanager.php - The Asterisk Manager class. + phpagi-fastagi.php - FastAGI class. + phpagi_1.php - Compatability class for 1.12 release + + docs/ - README files for the classes. + api-docs/ - API Documentation (html) + +DOCS +---- + README.phpagi - The main phpagi README + README.phpagi-asmanager - The phpagi asterisk manager README + README.phpagi-fastagi - phpagi fastagi README + + CHANGELOG - Change Log. + + phpagi.conf - An example configuration file for phpagi. + fastagi.xinetd - xinetd.conf sample configuration for fastagi + + +SUPPORT +------- + +Support for phpagi is available from the project website. + + * http://phpagi.sourceforge.net + * http://sourceforge.net/projects/phpagi/ + diff --git a/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_docs_fastagi.xinetd_750f88ce8a86107b5750fc01e3777cad.html b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_docs_fastagi.xinetd_750f88ce8a86107b5750fc01e3777cad.html new file mode 100644 index 0000000..86ba8a1 --- /dev/null +++ b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_docs_fastagi.xinetd_750f88ce8a86107b5750fc01e3777cad.html @@ -0,0 +1,32 @@ + + + + + + Example xinetd config file + + + + +

Example xinetd config file

+
+
  1. # default: off
  2. +
  3. # description: fastagi is a remote AGI interface
  4. +
  5. service fastagi
  6. +
  7. {
  8. +
  9.         socket_type  = stream
  10. +
  11.         user         = root
  12. +
  13.         group        = nobody
  14. +
  15.         server       = /var/lib/asterisk/agi-bin/phpagi/phpagi-fastagi.php
  16. +
  17.         wait         = no
  18. +
  19.         protocol     = tcp
  20. +
  21.         bind         = 127.0.0.1
  22. +
  23.         disable      = no
  24. +
  25. }
  26. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:21:49 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_dtmf.php_eb30ab5fd2d98b4b41f251416fc7ed37.html b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_dtmf.php_eb30ab5fd2d98b4b41f251416fc7ed37.html new file mode 100644 index 0000000..112b330 --- /dev/null +++ b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_dtmf.php_eb30ab5fd2d98b4b41f251416fc7ed37.html @@ -0,0 +1,40 @@ + + + + + + Get DTMF tones from the user and say the digits + + + + +

Get DTMF tones from the user and say the digits

+
+
  1. #!/usr/local/bin/php -q
  2. +
  3. <?php
  4. +
  5. +
  6.   require('phpagi.php');
  7. +
  8.   error_reporting(E_ALL);
  9. +
  10.  
  11. +
  12.   $agi new AGI();
  13. +
  14.   $agi->answer();
  15. +
  16.  
  17. +
  18.   $cid $agi->parse_callerid();
  19. +
  20.   $agi->text2wav("Hello, {$cid['name']}.");
  21. +
  22.   do
  23. +
  24.   {
  25. +
  26.     $agi->text2wav('Enter some numbers and then press the pound key. Press 1 1 1 followed by the pound key to quit.');
  27. +
  28.     $result $agi->get_data('beep'300020);
  29. +
  30.     $keys $result['result'];
  31. +
  32.     $agi->text2wav("You entered $keys");
  33. +
  34.   while($keys != '111');
  35. +
  36.   $agi->text2wav('Goodbye');
  37. +
  38.   $agi->hangup();
  39. +
  40. ?>
  41. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:22:03 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_input.php_2a77295d6494c9179dee4f5b0e65eac4.html b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_input.php_2a77295d6494c9179dee4f5b0e65eac4.html new file mode 100644 index 0000000..fdeeb8f --- /dev/null +++ b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_input.php_2a77295d6494c9179dee4f5b0e65eac4.html @@ -0,0 +1,33 @@ + + + + + + Get text input from the user and say it back + + + + +

Get text input from the user and say it back

+
+
  1. #!/usr/local/bin/php -q
  2. +
  3. <?php
  4. +
  5. +
  6.   require('phpagi.php');
  7. +
  8.  
  9. +
  10.   $agi new AGI();
  11. +
  12.   $agi->answer();
  13. +
  14.   $cid $agi->parse_callerid();
  15. +
  16.   $agi->text2wav("Hello, {$cid['name']}.  Let's enter some text.");
  17. +
  18.   $text $agi->text_input('UPPERCASE');
  19. +
  20.   $agi->text2wav("You entered $text");
  21. +
  22.   $agi->text2wav('Goodbye');
  23. +
  24.   $agi->hangup();
  25. +
  26. ?>
  27. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:22:03 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_ping.php_a8afcfe0902072cc636965d2b445e3fc.html b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_ping.php_a8afcfe0902072cc636965d2b445e3fc.html new file mode 100644 index 0000000..c7cf943 --- /dev/null +++ b/api-docs/__examplesource/exsource__home_phpagi_devel_phpagi_examples_ping.php_a8afcfe0902072cc636965d2b445e3fc.html @@ -0,0 +1,67 @@ + + + + + + Ping an IP address + + + + +

Ping an IP address

+
+
  1. #!/usr/local/bin/php -q
  2. +
  3. <?php
  4. +
  5. +
  6.   require('phpagi.php');
  7. +
  8.  
  9. +
  10.   $agi new AGI();
  11. +
  12.  
  13. +
  14.   $agi->answer();
  15. +
  16.  
  17. +
  18.  
  19. +
  20.   // Play the "Enter the host you wish to ping, followed by the pound sign" prompt
  21. +
  22.   // and then play the beep.   
  23. +
  24.   $agi->stream_file('ping');
  25. +
  26.   $result $agi->get_data('beep'300020);
  27. +
  28.   $ip str_replace('*''.'$result['result']);
  29. +
  30.  
  31. +
  32.   /* Danger Will Robinson!  This does NOT properly escape the ping command!
  33. +
  34.    * Someone could subvert your system if you don't fix this! - NO WARRANTY :P */
  35. +
  36.   $execstr "/bin/ping -c 5 -q -w 9 $ip|grep transmitted";
  37. +
  38.     
  39. +
  40.   // be polite.
  41. +
  42.   $agi->stream_file('thanks''#');
  43. +
  44.     
  45. +
  46.   $p popen($execstr'r');
  47. +
  48.   if($p == FALSE)
  49. +
  50.   {
  51. +
  52.     $agi->text2wav("Failed to ping $ip");
  53. +
  54.     $agi->conlog("Failed to ping $execstr");
  55. +
  56.   }
  57. +
  58.   else
  59. +
  60.   {
  61. +
  62.     $str '';
  63. +
  64.     while(!feof($p))
  65. +
  66.     {
  67. +
  68.       $r fgets($p1024);
  69. +
  70.       if(!$rbreak;
  71. +
  72.       $str .= $r;
  73. +
  74.     }
  75. +
  76.  
  77. +
  78.     // a minor hack.
  79. +
  80.     $str str_replace('ms''milli-seconds'$str);
  81. +
  82.     
  83. +
  84.     // have festival read back the ping results.
  85. +
  86.     $agi->text2wav("$ip - $str");
  87. +
  88.   }
  89. +
  90.  
  91. +
  92.   $agi->hangup();
  93. +
  94. ?>
  95. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:22:03 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__examplesource/exsource_ome_phpagi_devel_phpagi_examples_sip_show_peer.php_a884030dbf98b0261079f0d0ff35ab7b.html b/api-docs/__examplesource/exsource_ome_phpagi_devel_phpagi_examples_sip_show_peer.php_a884030dbf98b0261079f0d0ff35ab7b.html new file mode 100644 index 0000000..8218dc0 --- /dev/null +++ b/api-docs/__examplesource/exsource_ome_phpagi_devel_phpagi_examples_sip_show_peer.php_a884030dbf98b0261079f0d0ff35ab7b.html @@ -0,0 +1,48 @@ + + + + + + Get information about a sip peer + + + + +

Get information about a sip peer

+
+
  1. <?php
  2. +
  3.   require_once('../phpagi-asmanager.php');
  4. +
  5.  
  6. +
  7.   if(!isset($_SERVER['argv'][1]))
  8. +
  9.   {
  10. +
  11.     echo "Usage:\t{$_SERVER['_']} {$_SERVER['argv'][0]} peer\n\n";
  12. +
  13.     exit;
  14. +
  15.   }
  16. +
  17.  
  18. +
  19.   $asm new AGI_AsteriskManager();
  20. +
  21.   if($asm->connect())
  22. +
  23.   {
  24. +
  25.     $peer $asm->command("sip show peer {$_SERVER['argv'][1]}");
  26. +
  27.     if(!strpos($peer['data']':'))
  28. +
  29.       echo $peer['data'];
  30. +
  31.     else
  32. +
  33.     {
  34. +
  35.       $data array();
  36. +
  37.       foreach(explode("\n"$peer['data']as $line)
  38. +
  39.       {
  40. +
  41.         $a strpos('z'.$line':'1;
  42. +
  43.         if($a >= 0$data[trim(substr($line0$a))trim(substr($line$a 1));
  44. +
  45.       }
  46. +
  47.       print_r($data);
  48. +
  49.     }
  50. +
  51.  
  52. +
  53.     $asm->disconnect();
  54. +
  55.   }
  56. +
  57. ?>
  58. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:22:07 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__filesource/fsource_phpAGI__phpagi-asmanager.php.html b/api-docs/__filesource/fsource_phpAGI__phpagi-asmanager.php.html new file mode 100644 index 0000000..90a478c --- /dev/null +++ b/api-docs/__filesource/fsource_phpAGI__phpagi-asmanager.php.html @@ -0,0 +1,843 @@ + + + + + + File Source for phpagi-asmanager.php + + + + +

Source for file phpagi-asmanager.php

+

Documentation is available at phpagi-asmanager.php

+
+
  1. <?php
  2. +
  3.  /**
  4. +
  5.   * phpagi-asmanager.php : PHP Asterisk Manager functions
  6. +
  7.   * Website: http://phpagi.sourceforge.net
  8. +
  9.   *
  10. +
  11.   * $Id$
  12. +
  13.   *
  14. +
  15.   * Copyright (c) 2004 - 2010 Matthew Asham <matthew@ochrelabs.com>, David Eder <david@eder.us> and others
  16. +
  17.   * All Rights Reserved.
  18. +
  19.   *
  20. +
  21.   * This software is released under the terms of the GNU Lesser General Public License v2.1
  22. +
  23.   *  A copy of which is available from http://www.gnu.org/copyleft/lesser.html
  24. +
  25.   * 
  26. +
  27.   * We would be happy to list your phpagi based application on the phpagi
  28. +
  29.   * website.  Drop me an Email if you'd like us to list your program.
  30. +
  31.   *
  32. +
  33.   * @package phpAGI
  34. +
  35.   * @version 2.0
  36. +
  37.   */
  38. +
  39.  
  40. +
  41.  
  42. +
  43.  /**
  44. +
  45.   * Written for PHP 4.3.4, should work with older PHP 4.x versions.
  46. +
  47.   * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
  48. +
  49.   * Gracias. :)
  50. +
  51.   *
  52. +
  53.   */
  54. +
  55.  
  56. +
  57.   if(!class_exists('AGI'))
  58. +
  59.   {
  60. +
  61.     require_once(dirname(__FILE__DIRECTORY_SEPARATOR 'phpagi.php');
  62. +
  63.   }
  64. +
  65.  
  66. +
  67.  /**
  68. +
  69.   * Asterisk Manager class
  70. +
  71.   *
  72. +
  73.   * @link http://www.voip-info.org/wiki-Asterisk+config+manager.conf
  74. +
  75.   * @link http://www.voip-info.org/wiki-Asterisk+manager+API
  76. +
  77.   * @example examples/sip_show_peer.php Get information about a sip peer
  78. +
  79.   * @package phpAGI
  80. +
  81.   */
  82. +
  83. +
  84.   {
  85. +
  86.    /**
  87. +
  88.     * Config variables
  89. +
  90.     *
  91. +
  92.     * @var array 
  93. +
  94.     * @access public
  95. +
  96.     */
  97. +
  98.     public $config;
  99. +
  100.  
  101. +
  102.    /**
  103. +
  104.     * Socket
  105. +
  106.     *
  107. +
  108.     * @access public
  109. +
  110.     */
  111. +
  112.     public $socket = NULL;
  113. +
  114.  
  115. +
  116.    /**
  117. +
  118.     * Server we are connected to
  119. +
  120.     *
  121. +
  122.     * @access public
  123. +
  124.     * @var string 
  125. +
  126.     */
  127. +
  128.     public $server;
  129. +
  130.  
  131. +
  132.    /**
  133. +
  134.     * Port on the server we are connected to
  135. +
  136.     *
  137. +
  138.     * @access public
  139. +
  140.     * @var integer 
  141. +
  142.     */
  143. +
  144.     public $port;
  145. +
  146.  
  147. +
  148.    /**
  149. +
  150.     * Parent AGI
  151. +
  152.     *
  153. +
  154.     * @access private
  155. +
  156.     * @var AGI 
  157. +
  158.     */
  159. +
  160.     private $pagi;
  161. +
  162.  
  163. +
  164.    /**
  165. +
  166.     * Event Handlers
  167. +
  168.     *
  169. +
  170.     * @access private
  171. +
  172.     * @var array 
  173. +
  174.     */
  175. +
  176.     private $event_handlers;
  177. +
  178.  
  179. +
  180.     /**
  181. +
  182.      * Whether we're successfully logged in
  183. +
  184.      *
  185. +
  186.      * @access private
  187. +
  188.      * @var boolean 
  189. +
  190.      */
  191. +
  192.     private $_logged_in = FALSE;
  193. +
  194.     
  195. +
  196.    /**
  197. +
  198.     * Constructor
  199. +
  200.     *
  201. +
  202.     * @param string $config is the name of the config file to parse or a parent agi from which to read the config
  203. +
  204.     * @param array $optconfig is an array of configuration vars and vals, stuffed into $this->config['asmanager']
  205. +
  206.     */
  207. +
  208.     function AGI_AsteriskManager($config=NULL$optconfig=array())
  209. +
  210.     {
  211. +
  212.       // load config
  213. +
  214.       if(!is_null($config&& file_exists($config))
  215. +
  216.         $this->config = parse_ini_file($configtrue);
  217. +
  218.       elseif(file_exists(DEFAULT_PHPAGI_CONFIG))
  219. +
  220.         $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIGtrue);
  221. +
  222.  
  223. +
  224.       // If optconfig is specified, stuff vals and vars into 'asmanager' config array.
  225. +
  226.       foreach($optconfig as $var=>$val)
  227. +
  228.         $this->config['asmanager'][$var$val;
  229. +
  230.  
  231. +
  232.       // add default values to config for uninitialized values
  233. +
  234.       if(!isset($this->config['asmanager']['server'])) $this->config['asmanager']['server''localhost';
  235. +
  236.       if(!isset($this->config['asmanager']['port'])) $this->config['asmanager']['port'5038;
  237. +
  238.       if(!isset($this->config['asmanager']['username'])) $this->config['asmanager']['username''phpagi';
  239. +
  240.       if(!isset($this->config['asmanager']['secret'])) $this->config['asmanager']['secret''phpagi';
  241. +
  242.     }
  243. +
  244.  
  245. +
  246.    /**
  247. +
  248.     * Send a request
  249. +
  250.     *
  251. +
  252.     * @param string $action 
  253. +
  254.     * @param array $parameters 
  255. +
  256.     * @return array of parameters
  257. +
  258.     */
  259. +
  260.     function send_request($action$parameters=array())
  261. +
  262.     {
  263. +
  264.       $req "Action: $action\r\n";
  265. +
  266.       foreach($parameters as $var=>$val)
  267. +
  268.         $req .= "$var$val\r\n";
  269. +
  270.       $req .= "\r\n";
  271. +
  272.       fwrite($this->socket$req);
  273. +
  274.       return $this->wait_response();
  275. +
  276.     }
  277. +
  278.  
  279. +
  280.    /**
  281. +
  282.     * Wait for a response
  283. +
  284.     *
  285. +
  286.     * If a request was just sent, this will return the response.
  287. +
  288.     * Otherwise, it will loop forever, handling events.
  289. +
  290.     *
  291. +
  292.     * @param boolean $allow_timeout if the socket times out, return an empty array
  293. +
  294.     * @return array of parameters, empty on timeout
  295. +
  296.     */
  297. +
  298.     function wait_response($allow_timeout=false)
  299. +
  300.     {
  301. +
  302.       $timeout false;
  303. +
  304.       do
  305. +
  306.       {
  307. +
  308.         $type NULL;
  309. +
  310.         $parameters array();
  311. +
  312.  
  313. +
  314.         $buffer trim(fgets($this->socket4096));
  315. +
  316.         while($buffer != '')
  317. +
  318.         {
  319. +
  320.           $a strpos($buffer':');
  321. +
  322.           if($a)
  323. +
  324.           {
  325. +
  326.             if(!count($parameters)) // first line in a response?
  327. +
  328.             {
  329. +
  330.               $type strtolower(substr($buffer0$a));
  331. +
  332.               if(substr($buffer$a 2== 'Follows')
  333. +
  334.               {
  335. +
  336.                 // A follows response means there is a miltiline field that follows.
  337. +
  338.                 $parameters['data''';
  339. +
  340.                 $buff fgets($this->socket4096);
  341. +
  342.                 while(substr($buff06!= '--END ')
  343. +
  344.                 {
  345. +
  346.                   $parameters['data'.= $buff;
  347. +
  348.                   $buff fgets($this->socket4096);
  349. +
  350.                 }
  351. +
  352.               }
  353. +
  354.             }
  355. +
  356.  
  357. +
  358.             // store parameter in $parameters
  359. +
  360.             $parameters[substr($buffer0$a)substr($buffer$a 2);
  361. +
  362.           }
  363. +
  364.           $buffer trim(fgets($this->socket4096));
  365. +
  366.         }
  367. +
  368.  
  369. +
  370.         // process response
  371. +
  372.         switch($type)
  373. +
  374.         {
  375. +
  376.           case ''// timeout occured
  377. +
  378.             $timeout $allow_timeout;
  379. +
  380.             break;
  381. +
  382.           case 'event':
  383. +
  384.             $this->process_event($parameters);
  385. +
  386.             break;
  387. +
  388.           case 'response':
  389. +
  390.             break;
  391. +
  392.           default:
  393. +
  394.             $this->log('Unhandled response packet from Manager: ' print_r($parameterstrue));
  395. +
  396.             break;
  397. +
  398.         }
  399. +
  400.       while($type != 'response' && !$timeout);
  401. +
  402.       return $parameters;
  403. +
  404.     }
  405. +
  406.  
  407. +
  408.    /**
  409. +
  410.     * Connect to Asterisk
  411. +
  412.     *
  413. +
  414.     * @example examples/sip_show_peer.php Get information about a sip peer
  415. +
  416.     *
  417. +
  418.     * @param string $server 
  419. +
  420.     * @param string $username 
  421. +
  422.     * @param string $secret 
  423. +
  424.     * @return boolean true on success
  425. +
  426.     */
  427. +
  428.     function connect($server=NULL$username=NULL$secret=NULL)
  429. +
  430.     {
  431. +
  432.       // use config if not specified
  433. +
  434.       if(is_null($server)) $server $this->config['asmanager']['server'];
  435. +
  436.       if(is_null($username)) $username $this->config['asmanager']['username'];
  437. +
  438.       if(is_null($secret)) $secret $this->config['asmanager']['secret'];
  439. +
  440.  
  441. +
  442.       // get port from server if specified
  443. +
  444.       if(strpos($server':'!== false)
  445. +
  446.       {
  447. +
  448.         $c explode(':'$server);
  449. +
  450.         $this->server = $c[0];
  451. +
  452.         $this->port = $c[1];
  453. +
  454.       }
  455. +
  456.       else
  457. +
  458.       {
  459. +
  460.         $this->server = $server;
  461. +
  462.         $this->port = $this->config['asmanager']['port'];
  463. +
  464.       }
  465. +
  466.  
  467. +
  468.       // connect the socket
  469. +
  470.       $errno $errstr NULL;
  471. +
  472.       $this->socket = @fsockopen($this->server$this->port$errno$errstr);
  473. +
  474.       if($this->socket == false)
  475. +
  476.       {
  477. +
  478.         $this->log("Unable to connect to manager {$this->server}:{$this->port} ($errno): $errstr");
  479. +
  480.         return false;
  481. +
  482.       }
  483. +
  484.  
  485. +
  486.       // read the header
  487. +
  488.       $str = fgets($this->socket);
  489. +
  490.       if($str == false)
  491. +
  492.       {
  493. +
  494.         // a problem.
  495. +
  496.         $this->log("Asterisk Manager header not received.");
  497. +
  498.         return false;
  499. +
  500.       }
  501. +
  502.       else
  503. +
  504.       {
  505. +
  506.         // note: don't $this->log($str) until someone looks to see why it mangles the logging
  507. +
  508.       }
  509. +
  510.  
  511. +
  512.       // login
  513. +
  514.       $res = $this->send_request('login'array('Username'=>$username'Secret'=>$secret));
  515. +
  516.       if($res['Response'!= 'Success')
  517. +
  518.       {
  519. +
  520.         $this->_logged_in = FALSE;
  521. +
  522.         $this->log("Failed to login.");
  523. +
  524.         $this->disconnect();
  525. +
  526.         return false;
  527. +
  528.       }
  529. +
  530.       $this->_logged_in = TRUE;
  531. +
  532.       return true;
  533. +
  534.     }
  535. +
  536.  
  537. +
  538.    /**
  539. +
  540.     * Disconnect
  541. +
  542.     *
  543. +
  544.     * @example examples/sip_show_peer.php Get information about a sip peer
  545. +
  546.     */
  547. +
  548.     function disconnect()
  549. +
  550.     {
  551. +
  552.       if($this->_logged_in==TRUE)
  553. +
  554.         $this->logoff();
  555. +
  556.       fclose($this->socket);
  557. +
  558.     }
  559. +
  560.  
  561. +
  562.    // *********************************************************************************************************
  563. +
  564.    // **                       COMMANDS                                                                      **
  565. +
  566.    // *********************************************************************************************************
  567. +
  568. +
  569.    /**
  570. +
  571.     * Set Absolute Timeout
  572. +
  573.     *
  574. +
  575.     * Hangup a channel after a certain time.
  576. +
  577.     *
  578. +
  579.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+AbsoluteTimeout
  580. +
  581.     * @param string $channel Channel name to hangup
  582. +
  583.     * @param integer $timeout Maximum duration of the call (sec)
  584. +
  585.     */
  586. +
  587.     function AbsoluteTimeout($channel, $timeout)
  588. +
  589.     {
  590. +
  591.       return $this->send_request('AbsoluteTimeout'array('Channel'=>$channel'Timeout'=>$timeout));
  592. +
  593.     }
  594. +
  595.  
  596. +
  597.    /**
  598. +
  599.     * Change monitoring filename of a channel
  600. +
  601.     *
  602. +
  603.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ChangeMonitor
  604. +
  605.     * @param string $channel the channel to record.
  606. +
  607.     * @param string $file the new name of the file created in the monitor spool directory.
  608. +
  609.     */
  610. +
  611.     function ChangeMonitor($channel, $file)
  612. +
  613.     {
  614. +
  615.       return $this->send_request('ChangeMontior'array('Channel'=>$channel'File'=>$file));
  616. +
  617.     }
  618. +
  619.  
  620. +
  621.    /**
  622. +
  623.     * Execute Command
  624. +
  625.     *
  626. +
  627.     * @example examples/sip_show_peer.php Get information about a sip peer
  628. +
  629.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Command
  630. +
  631.     * @link http://www.voip-info.org/wiki-Asterisk+CLI
  632. +
  633.     * @param string $command
  634. +
  635.     * @param string $actionid message matching variable
  636. +
  637.     */
  638. +
  639.     function Command($command, $actionid=NULL)
  640. +
  641.     {
  642. +
  643.       $parameters = array('Command'=>$command);
  644. +
  645.       if($actionid) $parameters['ActionID'] = $actionid;
  646. +
  647.       return $this->send_request('Command'$parameters);
  648. +
  649.     }
  650. +
  651.  
  652. +
  653.    /**
  654. +
  655.     * Enable/Disable sending of events to this manager
  656. +
  657.     *
  658. +
  659.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Events
  660. +
  661.     * @param string $eventmask is either 'on', 'off', or 'system,call,log'
  662. +
  663.     */
  664. +
  665.     function Events($eventmask)
  666. +
  667.     {
  668. +
  669.       return $this->send_request('Events'array('EventMask'=>$eventmask));
  670. +
  671.     }
  672. +
  673.  
  674. +
  675.    /**
  676. +
  677.     * Check Extension Status
  678. +
  679.     *
  680. +
  681.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ExtensionState
  682. +
  683.     * @param string $exten Extension to check state on
  684. +
  685.     * @param string $context Context for extension
  686. +
  687.     * @param string $actionid message matching variable
  688. +
  689.     */
  690. +
  691.     function ExtensionState($exten, $context, $actionid=NULL)
  692. +
  693.     {
  694. +
  695.       $parameters = array('Exten'=>$exten, 'Context'=>$context);
  696. +
  697.       if($actionid) $parameters['ActionID'] = $actionid;
  698. +
  699.       return $this->send_request('ExtensionState'$parameters);
  700. +
  701.     }
  702. +
  703.  
  704. +
  705.    /**
  706. +
  707.     * Gets a Channel Variable
  708. +
  709.     *
  710. +
  711.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+GetVar
  712. +
  713.     * @link http://www.voip-info.org/wiki-Asterisk+variables
  714. +
  715.     * @param string $channel Channel to read variable from
  716. +
  717.     * @param string $variable
  718. +
  719.     * @param string $actionid message matching variable
  720. +
  721.     */
  722. +
  723.     function GetVar($channel, $variable, $actionid=NULL)
  724. +
  725.     {
  726. +
  727.       $parameters = array('Channel'=>$channel, 'Variable'=>$variable);
  728. +
  729.       if($actionid) $parameters['ActionID'] = $actionid;
  730. +
  731.       return $this->send_request('GetVar'$parameters);
  732. +
  733.     }
  734. +
  735.  
  736. +
  737.    /**
  738. +
  739.     * Hangup Channel
  740. +
  741.     *
  742. +
  743.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Hangup
  744. +
  745.     * @param string $channel The channel name to be hungup
  746. +
  747.     */
  748. +
  749.     function Hangup($channel)
  750. +
  751.     {
  752. +
  753.       return $this->send_request('Hangup'array('Channel'=>$channel));
  754. +
  755.     }
  756. +
  757.  
  758. +
  759.    /**
  760. +
  761.     * List IAX Peers
  762. +
  763.     *
  764. +
  765.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+IAXpeers
  766. +
  767.     */
  768. +
  769.     function IAXPeers()
  770. +
  771.     {
  772. +
  773.       return $this->send_request('IAXPeers');
  774. +
  775.     }
  776. +
  777.  
  778. +
  779.    /**
  780. +
  781.     * List available manager commands
  782. +
  783.     *
  784. +
  785.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ListCommands
  786. +
  787.     * @param string $actionid message matching variable
  788. +
  789.     */
  790. +
  791.     function ListCommands($actionid=NULL)
  792. +
  793.     {
  794. +
  795.       if($actionid)
  796. +
  797.         return $this->send_request('ListCommands'array('ActionID'=>$actionid));
  798. +
  799.       else
  800. +
  801.         return $this->send_request('ListCommands');
  802. +
  803.     }
  804. +
  805.  
  806. +
  807.    /**
  808. +
  809.     * Logoff Manager
  810. +
  811.     *
  812. +
  813.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Logoff
  814. +
  815.     */
  816. +
  817.     function Logoff()
  818. +
  819.     {
  820. +
  821.       return $this->send_request('Logoff');
  822. +
  823.     }
  824. +
  825.  
  826. +
  827.    /**
  828. +
  829.     * Check Mailbox Message Count
  830. +
  831.     *
  832. +
  833.     * Returns number of new and old messages.
  834. +
  835.     *   Message: Mailbox Message Count
  836. +
  837.     *   Mailbox: <mailboxid>
  838. +
  839.     *   NewMessages: <count>
  840. +
  841.     *   OldMessages: <count>
  842. +
  843.     *
  844. +
  845.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxCount
  846. +
  847.     * @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
  848. +
  849.     * @param string $actionid message matching variable
  850. +
  851.     */
  852. +
  853.     function MailboxCount($mailbox, $actionid=NULL)
  854. +
  855.     {
  856. +
  857.       $parameters = array('Mailbox'=>$mailbox);
  858. +
  859.       if($actionid) $parameters['ActionID'] = $actionid;
  860. +
  861.       return $this->send_request('MailboxCount'$parameters);
  862. +
  863.     }
  864. +
  865.  
  866. +
  867.    /**
  868. +
  869.     * Check Mailbox
  870. +
  871.     *
  872. +
  873.     * Returns number of messages.
  874. +
  875.     *   Message: Mailbox Status
  876. +
  877.     *   Mailbox: <mailboxid>
  878. +
  879.     *   Waiting: <count>
  880. +
  881.     *
  882. +
  883.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxStatus
  884. +
  885.     * @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
  886. +
  887.     * @param string $actionid message matching variable
  888. +
  889.     */
  890. +
  891.     function MailboxStatus($mailbox, $actionid=NULL)
  892. +
  893.     {    
  894. +
  895.       $parameters = array('Mailbox'=>$mailbox);
  896. +
  897.       if($actionid) $parameters['ActionID'] = $actionid;
  898. +
  899.       return $this->send_request('MailboxStatus'$parameters);
  900. +
  901.     }
  902. +
  903.  
  904. +
  905.    /**
  906. +
  907.     * Monitor a channel
  908. +
  909.     *
  910. +
  911.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Monitor
  912. +
  913.     * @param string $channel
  914. +
  915.     * @param string $file
  916. +
  917.     * @param string $format
  918. +
  919.     * @param boolean $mix
  920. +
  921.     */
  922. +
  923.     function Monitor($channel, $file=NULL, $format=NULL, $mix=NULL)
  924. +
  925.     {
  926. +
  927.       $parameters = array('Channel'=>$channel);
  928. +
  929.       if($file) $parameters['File'] = $file;
  930. +
  931.       if($format) $parameters['Format'] = $format;
  932. +
  933.       if(!is_null($file)) $parameters['Mix'] = ($mix) ? 'true' : 'false';
  934. +
  935.       return $this->send_request('Monitor'$parameters);
  936. +
  937.     }
  938. +
  939.  
  940. +
  941.    /**
  942. +
  943.     * Originate Call
  944. +
  945.     *
  946. +
  947.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Originate
  948. +
  949.     * @param string $channel Channel name to call
  950. +
  951.     * @param string $exten Extension to use (requires 'Context' and 'Priority')
  952. +
  953.     * @param string $context Context to use (requires 'Exten' and 'Priority')
  954. +
  955.     * @param string $priority Priority to use (requires 'Exten' and 'Context')
  956. +
  957.     * @param string $application Application to use
  958. +
  959.     * @param string $data Data to use (requires 'Application')
  960. +
  961.     * @param integer $timeout How long to wait for call to be answered (in ms)
  962. +
  963.     * @param string $callerid Caller ID to be set on the outgoing channel
  964. +
  965.     * @param string $variable Channel variable to set (VAR1=value1|VAR2=value2)
  966. +
  967.     * @param string $account Account code
  968. +
  969.     * @param boolean $async true fast origination
  970. +
  971.     * @param string $actionid message matching variable
  972. +
  973.     */
  974. +
  975.     function Originate($channel,
  976. +
  977.                        $exten=NULL, $context=NULL, $priority=NULL,
  978. +
  979.                        $application=NULL, $data=NULL,
  980. +
  981.                        $timeout=NULL, $callerid=NULL, $variable=NULL, $account=NULL, $async=NULL, $actionid=NULL)
  982. +
  983.     {
  984. +
  985.       $parameters = array('Channel'=>$channel);
  986. +
  987.  
  988. +
  989.       if($exten) $parameters['Exten'] = $exten;
  990. +
  991.       if($context) $parameters['Context'] = $context;
  992. +
  993.       if($priority) $parameters['Priority'] = $priority;
  994. +
  995.  
  996. +
  997.       if($application) $parameters['Application'] = $application;
  998. +
  999.       if($data) $parameters['Data'] = $data;
  1000. +
  1001.  
  1002. +
  1003.       if($timeout) $parameters['Timeout'] = $timeout;
  1004. +
  1005.       if($callerid) $parameters['CallerID'] = $callerid;
  1006. +
  1007.       if($variable) $parameters['Variable'] = $variable;
  1008. +
  1009.       if($account) $parameters['Account'] = $account;
  1010. +
  1011.       if(!is_null($async)) $parameters['Async'] = ($async) ? 'true' : 'false';
  1012. +
  1013.       if($actionid) $parameters['ActionID'] = $actionid;
  1014. +
  1015.  
  1016. +
  1017.       return $this->send_request('Originate'$parameters);
  1018. +
  1019.     }    
  1020. +
  1021.  
  1022. +
  1023.    /**
  1024. +
  1025.     * List parked calls
  1026. +
  1027.     *
  1028. +
  1029.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ParkedCalls
  1030. +
  1031.     * @param string $actionid message matching variable
  1032. +
  1033.     */
  1034. +
  1035.     function ParkedCalls($actionid=NULL)
  1036. +
  1037.     {
  1038. +
  1039.       if($actionid)
  1040. +
  1041.         return $this->send_request('ParkedCalls'array('ActionID'=>$actionid));
  1042. +
  1043.       else
  1044. +
  1045.         return $this->send_request('ParkedCalls');
  1046. +
  1047.     }
  1048. +
  1049.  
  1050. +
  1051.    /**
  1052. +
  1053.     * Ping
  1054. +
  1055.     *
  1056. +
  1057.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Ping
  1058. +
  1059.     */
  1060. +
  1061.     function Ping()
  1062. +
  1063.     {
  1064. +
  1065.       return $this->send_request('Ping');
  1066. +
  1067.     }
  1068. +
  1069.  
  1070. +
  1071.    /**
  1072. +
  1073.     * Queue Add
  1074. +
  1075.     *
  1076. +
  1077.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueAdd
  1078. +
  1079.     * @param string $queue
  1080. +
  1081.     * @param string $interface
  1082. +
  1083.     * @param integer $penalty
  1084. +
  1085.     */
  1086. +
  1087.     function QueueAdd($queue, $interface, $penalty=0)
  1088. +
  1089.     {
  1090. +
  1091.       $parameters = array('Queue'=>$queue, 'Interface'=>$interface);
  1092. +
  1093.       if($penalty) $parameters['Penalty'] = $penalty;
  1094. +
  1095.       return $this->send_request('QueueAdd'$parameters);
  1096. +
  1097.     }
  1098. +
  1099.  
  1100. +
  1101.    /**
  1102. +
  1103.     * Queue Remove
  1104. +
  1105.     *
  1106. +
  1107.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueRemove
  1108. +
  1109.     * @param string $queue
  1110. +
  1111.     * @param string $interface
  1112. +
  1113.     */
  1114. +
  1115.     function QueueRemove($queue, $interface)
  1116. +
  1117.     {
  1118. +
  1119.       return $this->send_request('QueueRemove'array('Queue'=>$queue'Interface'=>$interface));
  1120. +
  1121.     }
  1122. +
  1123.  
  1124. +
  1125.    /**
  1126. +
  1127.     * Queues
  1128. +
  1129.     *
  1130. +
  1131.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Queues
  1132. +
  1133.     */
  1134. +
  1135.     function Queues()
  1136. +
  1137.     {
  1138. +
  1139.       return $this->send_request('Queues');
  1140. +
  1141.     }
  1142. +
  1143.  
  1144. +
  1145.    /**
  1146. +
  1147.     * Queue Status
  1148. +
  1149.     *
  1150. +
  1151.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueStatus
  1152. +
  1153.     * @param string $actionid message matching variable
  1154. +
  1155.     */
  1156. +
  1157.     function QueueStatus($actionid=NULL)
  1158. +
  1159.     {
  1160. +
  1161.       if($actionid)
  1162. +
  1163.         return $this->send_request('QueueStatus'array('ActionID'=>$actionid));
  1164. +
  1165.       else
  1166. +
  1167.         return $this->send_request('QueueStatus');
  1168. +
  1169.     }
  1170. +
  1171.  
  1172. +
  1173.    /**
  1174. +
  1175.     * Redirect
  1176. +
  1177.     *
  1178. +
  1179.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Redirect
  1180. +
  1181.     * @param string $channel
  1182. +
  1183.     * @param string $extrachannel
  1184. +
  1185.     * @param string $exten
  1186. +
  1187.     * @param string $context
  1188. +
  1189.     * @param string $priority
  1190. +
  1191.     */
  1192. +
  1193.     function Redirect($channel, $extrachannel, $exten, $context, $priority)
  1194. +
  1195.     {
  1196. +
  1197.       return $this->send_request('Redirect'array('Channel'=>$channel'ExtraChannel'=>$extrachannel'Exten'=>$exten,
  1198. +
  1199.                                                    'Context'=>$context'Priority'=>$priority));
  1200. +
  1201.     }
  1202. +
  1203.  
  1204. +
  1205.    /**
  1206. +
  1207.     * Set the CDR UserField
  1208. +
  1209.     *
  1210. +
  1211.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetCDRUserField
  1212. +
  1213.     * @param string $userfield
  1214. +
  1215.     * @param string $channel
  1216. +
  1217.     * @param string $append
  1218. +
  1219.     */
  1220. +
  1221.     function SetCDRUserField($userfield, $channel, $append=NULL)
  1222. +
  1223.     {
  1224. +
  1225.       $parameters = array('UserField'=>$userfield, 'Channel'=>$channel);
  1226. +
  1227.       if($append) $parameters['Append'] = $append;
  1228. +
  1229.       return $this->send_request('SetCDRUserField'$parameters);
  1230. +
  1231.     }
  1232. +
  1233.  
  1234. +
  1235.    /**
  1236. +
  1237.     * Set Channel Variable
  1238. +
  1239.     *
  1240. +
  1241.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetVar
  1242. +
  1243.     * @param string $channel Channel to set variable for
  1244. +
  1245.     * @param string $variable name
  1246. +
  1247.     * @param string $value
  1248. +
  1249.     */
  1250. +
  1251.     function SetVar($channel, $variable, $value)
  1252. +
  1253.     {
  1254. +
  1255.       return $this->send_request('SetVar'array('Channel'=>$channel'Variable'=>$variable'Value'=>$value));
  1256. +
  1257.     }
  1258. +
  1259.  
  1260. +
  1261.    /**
  1262. +
  1263.     * Channel Status
  1264. +
  1265.     *
  1266. +
  1267.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Status
  1268. +
  1269.     * @param string $channel
  1270. +
  1271.     * @param string $actionid message matching variable
  1272. +
  1273.     */
  1274. +
  1275.     function Status($channel, $actionid=NULL)
  1276. +
  1277.     {
  1278. +
  1279.       $parameters = array('Channel'=>$channel);
  1280. +
  1281.       if($actionid) $parameters['ActionID'] = $actionid;
  1282. +
  1283.       return $this->send_request('Status'$parameters);
  1284. +
  1285.     }
  1286. +
  1287.  
  1288. +
  1289.    /**
  1290. +
  1291.     * Stop monitoring a channel
  1292. +
  1293.     *
  1294. +
  1295.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+StopMonitor
  1296. +
  1297.     * @param string $channel
  1298. +
  1299.     */
  1300. +
  1301.     function StopMonitor($channel)
  1302. +
  1303.     {
  1304. +
  1305.       return $this->send_request('StopMonitor'array('Channel'=>$channel));
  1306. +
  1307.     }
  1308. +
  1309.  
  1310. +
  1311.    /**
  1312. +
  1313.     * Dial over Zap channel while offhook
  1314. +
  1315.     *
  1316. +
  1317.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDialOffhook
  1318. +
  1319.     * @param string $zapchannel
  1320. +
  1321.     * @param string $number
  1322. +
  1323.     */
  1324. +
  1325.     function ZapDialOffhook($zapchannel, $number)
  1326. +
  1327.     {
  1328. +
  1329.       return $this->send_request('ZapDialOffhook'array('ZapChannel'=>$zapchannel'Number'=>$number));
  1330. +
  1331.     }
  1332. +
  1333.  
  1334. +
  1335.    /**
  1336. +
  1337.     * Toggle Zap channel Do Not Disturb status OFF
  1338. +
  1339.     *
  1340. +
  1341.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDoff
  1342. +
  1343.     * @param string $zapchannel
  1344. +
  1345.     */
  1346. +
  1347.     function ZapDNDoff($zapchannel)
  1348. +
  1349.     {
  1350. +
  1351.       return $this->send_request('ZapDNDoff'array('ZapChannel'=>$zapchannel));
  1352. +
  1353.     }
  1354. +
  1355.  
  1356. +
  1357.    /**
  1358. +
  1359.     * Toggle Zap channel Do Not Disturb status ON
  1360. +
  1361.     *
  1362. +
  1363.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDon
  1364. +
  1365.     * @param string $zapchannel
  1366. +
  1367.     */
  1368. +
  1369.     function ZapDNDon($zapchannel)
  1370. +
  1371.     {
  1372. +
  1373.       return $this->send_request('ZapDNDon'array('ZapChannel'=>$zapchannel));
  1374. +
  1375.     }
  1376. +
  1377.  
  1378. +
  1379.    /**
  1380. +
  1381.     * Hangup Zap Channel
  1382. +
  1383.     *
  1384. +
  1385.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapHangup
  1386. +
  1387.     * @param string $zapchannel
  1388. +
  1389.     */
  1390. +
  1391.     function ZapHangup($zapchannel)
  1392. +
  1393.     {
  1394. +
  1395.       return $this->send_request('ZapHangup'array('ZapChannel'=>$zapchannel));
  1396. +
  1397.     }
  1398. +
  1399.  
  1400. +
  1401.    /**
  1402. +
  1403.     * Transfer Zap Channel
  1404. +
  1405.     *
  1406. +
  1407.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapTransfer
  1408. +
  1409.     * @param string $zapchannel
  1410. +
  1411.     */
  1412. +
  1413.     function ZapTransfer($zapchannel)
  1414. +
  1415.     {
  1416. +
  1417.       return $this->send_request('ZapTransfer'array('ZapChannel'=>$zapchannel));
  1418. +
  1419.     }
  1420. +
  1421.  
  1422. +
  1423.    /**
  1424. +
  1425.     * Zap Show Channels
  1426. +
  1427.     *
  1428. +
  1429.     * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapShowChannels
  1430. +
  1431.     * @param string $actionid message matching variable
  1432. +
  1433.     */
  1434. +
  1435.     function ZapShowChannels($actionid=NULL)
  1436. +
  1437.     {
  1438. +
  1439.       if($actionid)
  1440. +
  1441.         return $this->send_request('ZapShowChannels'array('ActionID'=>$actionid));
  1442. +
  1443.       else
  1444. +
  1445.         return $this->send_request('ZapShowChannels');
  1446. +
  1447.     }
  1448. +
  1449.  
  1450. +
  1451.    // *********************************************************************************************************
  1452. +
  1453.    // **                       MISC                                                                          **
  1454. +
  1455.    // *********************************************************************************************************
  1456. +
  1457. +
  1458.    /*
  1459. +
  1460.     * Log a message
  1461. +
  1462.     *
  1463. +
  1464.     * @param string $message
  1465. +
  1466.     * @param integer $level from 1 to 4
  1467. +
  1468.     */
  1469. +
  1470.     function log($message, $level=1)
  1471. +
  1472.     {
  1473. +
  1474.       if($this->pagi != false)
  1475. +
  1476.         $this->pagi->conlog($message$level);
  1477. +
  1478.       else
  1479. +
  1480.         error_log(date('r'' - ' $message);
  1481. +
  1482.     }
  1483. +
  1484.  
  1485. +
  1486.    /**
  1487. +
  1488.     * Add event handler
  1489. +
  1490.     *
  1491. +
  1492.     * Known Events include ( http://www.voip-info.org/wiki-asterisk+manager+events )
  1493. +
  1494.     *   Link - Fired when two voice channels are linked together and voice data exchange commences.
  1495. +
  1496.     *   Unlink - Fired when a link between two voice channels is discontinued, for example, just before call completion.
  1497. +
  1498.     *   Newexten -
  1499. +
  1500.     *   Hangup -
  1501. +
  1502.     *   Newchannel -
  1503. +
  1504.     *   Newstate -
  1505. +
  1506.     *   Reload - Fired when the "RELOAD" console command is executed.
  1507. +
  1508.     *   Shutdown -
  1509. +
  1510.     *   ExtensionStatus -
  1511. +
  1512.     *   Rename -
  1513. +
  1514.     *   Newcallerid -
  1515. +
  1516.     *   Alarm -
  1517. +
  1518.     *   AlarmClear -
  1519. +
  1520.     *   Agentcallbacklogoff -
  1521. +
  1522.     *   Agentcallbacklogin -
  1523. +
  1524.     *   Agentlogoff -
  1525. +
  1526.     *   MeetmeJoin -
  1527. +
  1528.     *   MessageWaiting -
  1529. +
  1530.     *   join -
  1531. +
  1532.     *   leave -
  1533. +
  1534.     *   AgentCalled -
  1535. +
  1536.     *   ParkedCall - Fired after ParkedCalls
  1537. +
  1538.     *   Cdr -
  1539. +
  1540.     *   ParkedCallsComplete -
  1541. +
  1542.     *   QueueParams -
  1543. +
  1544.     *   QueueMember -
  1545. +
  1546.     *   QueueStatusEnd -
  1547. +
  1548.     *   Status -
  1549. +
  1550.     *   StatusComplete -
  1551. +
  1552.     *   ZapShowChannels - Fired after ZapShowChannels
  1553. +
  1554.     *   ZapShowChannelsComplete -
  1555. +
  1556.     *
  1557. +
  1558.     * @param string $event type or * for default handler
  1559. +
  1560.     * @param string $callback function
  1561. +
  1562.     * @return boolean sucess
  1563. +
  1564.     */
  1565. +
  1566.     function add_event_handler($event, $callback)
  1567. +
  1568.     {
  1569. +
  1570.       $event = strtolower($event);
  1571. +
  1572.       if(isset($this->event_handlers[$event]))
  1573. +
  1574.       {
  1575. +
  1576.         $this->log("$event handler is already defined, not over-writing.");
  1577. +
  1578.         return false;
  1579. +
  1580.       }
  1581. +
  1582.       $this->event_handlers[$event$callback;
  1583. +
  1584.       return true;
  1585. +
  1586.     }
  1587. +
  1588.  
  1589. +
  1590.    /**
  1591. +
  1592.     * Process event
  1593. +
  1594.     *
  1595. +
  1596.     * @access private
  1597. +
  1598.     * @param array $parameters
  1599. +
  1600.     * @return mixed result of event handler or false if no handler was found
  1601. +
  1602.     */
  1603. +
  1604.     function process_event($parameters)
  1605. +
  1606.     {
  1607. +
  1608.       $ret = false;
  1609. +
  1610.       $e = strtolower($parameters['Event']);
  1611. +
  1612.       $this->log("Got event.. $e");        
  1613. +
  1614.  
  1615. +
  1616.       $handler = '';
  1617. +
  1618.       if(isset($this->event_handlers[$e])) $handler $this->event_handlers[$e];
  1619. +
  1620.       elseif(isset($this->event_handlers['*'])) $handler $this->event_handlers['*'];
  1621. +
  1622.  
  1623. +
  1624.       if(function_exists($handler))
  1625. +
  1626.       {
  1627. +
  1628.         $this->log("Execute handler $handler");
  1629. +
  1630.         $ret = $handler($e, $parameters, $this->server$this->port);
  1631. +
  1632.       }
  1633. +
  1634.       else
  1635. +
  1636.         $this->log("No event handler for event '$e'");
  1637. +
  1638.       return $ret;
  1639. +
  1640.     }
  1641. +
  1642.   }
  1643. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:21:47 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__filesource/fsource_phpAGI__phpagi-fastagi.php.html b/api-docs/__filesource/fsource_phpAGI__phpagi-fastagi.php.html new file mode 100644 index 0000000..ca46e94 --- /dev/null +++ b/api-docs/__filesource/fsource_phpAGI__phpagi-fastagi.php.html @@ -0,0 +1,99 @@ + + + + + + File Source for phpagi-fastagi.php + + + + +

Source for file phpagi-fastagi.php

+

Documentation is available at phpagi-fastagi.php

+
+
  1. #!/usr/local/bin/php -q
  2. +
  3. <?php
  4. +
  5.  /**
  6. +
  7.   * phpagi-fastagi.php : PHP FastAGI bootstrap
  8. +
  9.   * Website: http://phpagi.sourceforge.net
  10. +
  11.   *
  12. +
  13.   * $Id$
  14. +
  15.   *
  16. +
  17.   * Copyright (c) 2004, 2005 Matthew Asham <matthewa@bcwireless.net>, David Eder <david@eder.us>
  18. +
  19.   * All Rights Reserved.
  20. +
  21.   *
  22. +
  23.   * This software is released under the terms of the GNU Lesser General Public License v2.1
  24. +
  25.   * A copy of which is available from http://www.gnu.org/copyleft/lesser.html
  26. +
  27.   *
  28. +
  29.   * We would be happy to list your phpagi based application on the phpagi
  30. +
  31.   * website.  Drop me an Email if you'd like us to list your program.
  32. +
  33.   *
  34. +
  35.   * @package phpAGI
  36. +
  37.   * @version 2.0
  38. +
  39.   * @example docs/fastagi.xinetd Example xinetd config file
  40. +
  41.   */
  42. +
  43.  
  44. +
  45.  /**
  46. +
  47.   * Written for PHP 4.3.4, should work with older PHP 4.x versions.
  48. +
  49.   * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
  50. +
  51.   * Gracias. :)
  52. +
  53.   *
  54. +
  55.   */
  56. +
  57.  
  58. +
  59.   require_once(dirname(__FILE__DIRECTORY_SEPARATOR 'phpagi.php');
  60. +
  61.  
  62. +
  63.   $fastagi new AGI();
  64. +
  65.  
  66. +
  67.   $fastagi->verbose(print_r($fastagitrue));
  68. +
  69.  
  70. +
  71.   if(!isset($fastagi->config['fastagi']['basedir']))
  72. +
  73.     $fastagi->config['fastagi']['basedir'dirname(__FILE__);
  74. +
  75.  
  76. +
  77.   // perform some security checks
  78. +
  79.  
  80. +
  81.   $script $fastagi->config['fastagi']['basedir'DIRECTORY_SEPARATOR $fastagi->request['agi_network_script'];
  82. +
  83.  
  84. +
  85.   // in the same directory (or subdirectory)
  86. +
  87.   $mydir dirname($fastagi->config['fastagi']['basedir']DIRECTORY_SEPARATOR;
  88. +
  89.   $dir dirname($scriptDIRECTORY_SEPARATOR;
  90. +
  91.   if(substr($dir0strlen($mydir)) != $mydir)
  92. +
  93.   {
  94. +
  95.     $fastagi->conlog("$script is not allowed to execute.");
  96. +
  97.     exit;
  98. +
  99.   }
  100. +
  101.  
  102. +
  103.   // make sure it exists
  104. +
  105.   if(!file_exists($script))
  106. +
  107.   {
  108. +
  109.     $fastagi->conlog("$script does not exist.");
  110. +
  111.     exit;
  112. +
  113.   }
  114. +
  115.  
  116. +
  117.   // drop privileges
  118. +
  119.   if(isset($fastagi->config['fastagi']['setuid']&& $fastagi->config['fastagi']['setuid'])
  120. +
  121.   {
  122. +
  123.     $owner fileowner($script);
  124. +
  125.     $group filegroup($script);
  126. +
  127.     if(!posix_setgid($group|| !posix_setegid($group|| !posix_setuid($owner|| !posix_seteuid($owner))
  128. +
  129.     {
  130. +
  131.       $fastagi->conlog("failed to lower privileges.");
  132. +
  133.       exit;      
  134. +
  135.     }
  136. +
  137.   }
  138. +
  139.  
  140. +
  141.   // make sure script is still readable
  142. +
  143.   if(!is_readable($script))
  144. +
  145.   {
  146. +
  147.     $fastagi->conlog("$script is not readable.");
  148. +
  149.     exit;
  150. +
  151.   }
  152. +
  153.  
  154. +
  155.   require_once($script);
  156. +
  157. ?>
  158. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:21:49 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__filesource/fsource_phpAGI__phpagi.php.html b/api-docs/__filesource/fsource_phpAGI__phpagi.php.html new file mode 100644 index 0000000..fa2f9ff --- /dev/null +++ b/api-docs/__filesource/fsource_phpAGI__phpagi.php.html @@ -0,0 +1,1845 @@ + + + + + + File Source for phpagi.php + + + + +

Source for file phpagi.php

+

Documentation is available at phpagi.php

+
+
  1. <?php
  2. +
  3.  
  4. +
  5. /**
  6. +
  7. * phpagi.php : PHP AGI Functions for Asterisk
  8. +
  9. * Website: http://phpagi.sourceforge.net/
  10. +
  11. *
  12. +
  13. * $Id$
  14. +
  15. *
  16. +
  17. * Copyright (c) 2003 - 2010 Matthew Asham <matthew@ochrelabs.com>, David Eder <david@eder.us> and others
  18. +
  19. * All Rights Reserved.
  20. +
  21. *
  22. +
  23. * This software is released under the terms of the GNU Lesser General Public License v2.1
  24. +
  25. * A copy of which is available from http://www.gnu.org/copyleft/lesser.html
  26. +
  27. *
  28. +
  29. * We would be happy to list your phpagi based application on the phpagi
  30. +
  31. * website.  Drop me an Email if you'd like us to list your program.
  32. +
  33. +
  34. *
  35. +
  36. * Written for PHP 4.3.4, should work with older PHP 4.x versions.
  37. +
  38. *
  39. +
  40. * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
  41. +
  42. * Gracias. :)
  43. +
  44. *
  45. +
  46. *
  47. +
  48. @package phpAGI
  49. +
  50. @version 2.0
  51. +
  52. */
  53. +
  54.  
  55. +
  56. if (!class_exists('AGI_AsteriskManager'))
  57. +
  58. {
  59. +
  60.     require_once(dirname(__FILE__DIRECTORY_SEPARATOR 'phpagi-asmanager.php');
  61. +
  62. }
  63. +
  64.  
  65. +
  66. define('AST_CONFIG_DIR''/etc/asterisk/');
  67. +
  68. define('AST_SPOOL_DIR''/var/spool/asterisk/');
  69. +
  70. define('AST_TMP_DIR'AST_SPOOL_DIR '/tmp/');
  71. +
  72. define('DEFAULT_PHPAGI_CONFIG'AST_CONFIG_DIR '/phpagi.conf');
  73. +
  74.  
  75. +
  76. define('AST_DIGIT_ANY''0123456789#*');
  77. +
  78.  
  79. +
  80. define('AGIRES_OK'200);
  81. +
  82.  
  83. +
  84. define('AST_STATE_DOWN'0);
  85. +
  86. define('AST_STATE_RESERVED'1);
  87. +
  88. define('AST_STATE_OFFHOOK'2);
  89. +
  90. define('AST_STATE_DIALING'3);
  91. +
  92. define('AST_STATE_RING'4);
  93. +
  94. define('AST_STATE_RINGING'5);
  95. +
  96. define('AST_STATE_UP'6);
  97. +
  98. define('AST_STATE_BUSY'7);
  99. +
  100. define('AST_STATE_DIALING_OFFHOOK'8);
  101. +
  102. define('AST_STATE_PRERING'9);
  103. +
  104.  
  105. +
  106. define('AUDIO_FILENO'3)// STDERR_FILENO + 1
  107. +
  108.  
  109. +
  110. /**
  111. +
  112. * AGI class
  113. +
  114. *
  115. +
  116. @package phpAGI
  117. +
  118. @link http://www.voip-info.org/wiki-Asterisk+agi
  119. +
  120. @example examples/dtmf.php Get DTMF tones from the user and say the digits
  121. +
  122. @example examples/input.php Get text input from the user and say it back
  123. +
  124. @example examples/ping.php Ping an IP address
  125. +
  126. */
  127. +
  128. class AGI
  129. +
  130. {
  131. +
  132.     /**
  133. +
  134.     * Request variables read in on initialization.
  135. +
  136.     *
  137. +
  138.     * Often contains any/all of the following:
  139. +
  140.     *   agi_request - name of agi script
  141. +
  142.     *   agi_channel - current channel
  143. +
  144.     *   agi_language - current language
  145. +
  146.     *   agi_type - channel type (SIP, ZAP, IAX, ...)
  147. +
  148.     *   agi_uniqueid - unique id based on unix time
  149. +
  150.     *   agi_callerid - callerID string
  151. +
  152.     *   agi_dnid - dialed number id
  153. +
  154.     *   agi_rdnis - referring DNIS number
  155. +
  156.     *   agi_context - current context
  157. +
  158.     *   agi_extension - extension dialed
  159. +
  160.     *   agi_priority - current priority
  161. +
  162.     *   agi_enhanced - value is 1.0 if started as an EAGI script
  163. +
  164.     *   agi_accountcode - set by SetAccount in the dialplan
  165. +
  166.     *   agi_network - value is yes if this is a fastagi
  167. +
  168.     *   agi_network_script - name of the script to execute
  169. +
  170.     *
  171. +
  172.     * NOTE: program arguments are still in $_SERVER['argv'].
  173. +
  174.     *
  175. +
  176.     * @var array 
  177. +
  178.     * @access public
  179. +
  180.     */
  181. +
  182.     var $request;
  183. +
  184.  
  185. +
  186.     /**
  187. +
  188.     * Config variables
  189. +
  190.     *
  191. +
  192.     * @var array 
  193. +
  194.     * @access public
  195. +
  196.     */
  197. +
  198.     var $config;
  199. +
  200.  
  201. +
  202.     /**
  203. +
  204.     * Asterisk Manager
  205. +
  206.     *
  207. +
  208.     * @var AGI_AsteriskManager 
  209. +
  210.     * @access public
  211. +
  212.     */
  213. +
  214.     var $asmanager;
  215. +
  216.  
  217. +
  218.     /**
  219. +
  220.     * Input Stream
  221. +
  222.     *
  223. +
  224.     * @access private
  225. +
  226.     */
  227. +
  228.     var $in = NULL;
  229. +
  230.  
  231. +
  232.     /**
  233. +
  234.     * Output Stream
  235. +
  236.     *
  237. +
  238.     * @access private
  239. +
  240.     */
  241. +
  242.     var $out = NULL;
  243. +
  244.  
  245. +
  246.     /**
  247. +
  248.     * Audio Stream
  249. +
  250.     *
  251. +
  252.     * @access public
  253. +
  254.     */
  255. +
  256.     var $audio = NULL;
  257. +
  258.  
  259. +
  260.  
  261. +
  262.     /**
  263. +
  264.     * Application option delimiter
  265. +
  266.     * 
  267. +
  268.     * @access public
  269. +
  270.     */
  271. +
  272.     public $option_delim = ",";
  273. +
  274.     
  275. +
  276.     /**
  277. +
  278.     * Constructor
  279. +
  280.     *
  281. +
  282.     * @param string $config is the name of the config file to parse
  283. +
  284.     * @param array $optconfig is an array of configuration vars and vals, stuffed into $this->config['phpagi']
  285. +
  286.     */
  287. +
  288.     function __construct($config=NULL$optconfig=array())
  289. +
  290.     {
  291. +
  292.         // load config
  293. +
  294.         if(!is_null($config&& file_exists($config))
  295. +
  296.           $this->config = parse_ini_file($configtrue);
  297. +
  298.         elseif(file_exists(DEFAULT_PHPAGI_CONFIG))
  299. +
  300.           $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIGtrue);
  301. +
  302.  
  303. +
  304.         // If optconfig is specified, stuff vals and vars into 'phpagi' config array.
  305. +
  306.         foreach($optconfig as $var=>$val)
  307. +
  308.           $this->config['phpagi'][$var$val;
  309. +
  310.  
  311. +
  312.         // add default values to config for uninitialized values
  313. +
  314.         if(!isset($this->config['phpagi']['error_handler'])) $this->config['phpagi']['error_handler'true;
  315. +
  316.         if(!isset($this->config['phpagi']['debug'])) $this->config['phpagi']['debug'false;
  317. +
  318.         if(!isset($this->config['phpagi']['admin'])) $this->config['phpagi']['admin'NULL;
  319. +
  320.         if(!isset($this->config['phpagi']['tempdir'])) $this->config['phpagi']['tempdir'AST_TMP_DIR;
  321. +
  322.  
  323. +
  324.         // festival TTS config
  325. +
  326.         if(!isset($this->config['festival']['text2wave'])) $this->config['festival']['text2wave'$this->which('text2wave');
  327. +
  328.  
  329. +
  330.         // swift TTS config
  331. +
  332.         if(!isset($this->config['cepstral']['swift'])) $this->config['cepstral']['swift'$this->which('swift');
  333. +
  334.  
  335. +
  336.         ob_implicit_flush(true);
  337. +
  338.  
  339. +
  340.         // open stdin & stdout
  341. +
  342.         $this->in = defined('STDIN'STDIN fopen('php://stdin''r');
  343. +
  344.         $this->out = defined('STDOUT'STDOUT fopen('php://stdout''w');
  345. +
  346.  
  347. +
  348.         // initialize error handler
  349. +
  350.         if($this->config['phpagi']['error_handler'== true)
  351. +
  352.         {
  353. +
  354.           set_error_handler('phpagi_error_handler');
  355. +
  356.           global $phpagi_error_handler_email;
  357. +
  358.           $phpagi_error_handler_email $this->config['phpagi']['admin'];
  359. +
  360.           error_reporting(E_ALL);
  361. +
  362.         }
  363. +
  364.  
  365. +
  366.         // make sure temp folder exists
  367. +
  368.         $this->make_folder($this->config['phpagi']['tempdir']);
  369. +
  370.  
  371. +
  372.         // read the request
  373. +
  374.         $str fgets($this->in);
  375. +
  376.         while($str != "\n")
  377. +
  378.         {
  379. +
  380.           $this->request[substr($str0strpos($str':'))trim(substr($strstrpos($str':'1));
  381. +
  382.           $str fgets($this->in);
  383. +
  384.         }
  385. +
  386.  
  387. +
  388.         // open audio if eagi detected
  389. +
  390.         if($this->request['agi_enhanced'== '1.0')
  391. +
  392.         {
  393. +
  394.           if(file_exists('/proc/' getmypid('/fd/3'))
  395. +
  396.             $this->audio = fopen('/proc/' getmypid('/fd/3''r');
  397. +
  398.           elseif(file_exists('/dev/fd/3'))
  399. +
  400.           {
  401. +
  402.             // may need to mount fdescfs
  403. +
  404.             $this->audio = fopen('/dev/fd/3''r');
  405. +
  406.           }
  407. +
  408.           else
  409. +
  410.             $this->conlog('Unable to open audio stream');
  411. +
  412.  
  413. +
  414.           if($this->audiostream_set_blocking($this->audio0);
  415. +
  416.         }
  417. +
  418.  
  419. +
  420.         $this->conlog('AGI Request:');
  421. +
  422.         $this->conlog(print_r($this->requesttrue));
  423. +
  424.         $this->conlog('PHPAGI internal configuration:');
  425. +
  426.         $this->conlog(print_r($this->configtrue));
  427. +
  428.     }
  429. +
  430.  
  431. +
  432.     // *********************************************************************************************************
  433. +
  434.     // **                             COMMANDS                                                                                            **
  435. +
  436.     // *********************************************************************************************************
  437. +
  438.  
  439. +
  440.     /**
  441. +
  442.     * Answer channel if not already in answer state.
  443. +
  444.     *
  445. +
  446.     * @link http://www.voip-info.org/wiki-answer
  447. +
  448.     * @example examples/dtmf.php Get DTMF tones from the user and say the digits
  449. +
  450.     * @example examples/input.php Get text input from the user and say it back
  451. +
  452.     * @example examples/ping.php Ping an IP address
  453. +
  454.     *
  455. +
  456.     * @return array, see evaluate for return information.  ['result'] is 0 on success, -1 on failure.
  457. +
  458.     */
  459. +
  460.     function answer()
  461. +
  462.     {
  463. +
  464.         return $this->evaluate('ANSWER');
  465. +
  466.     }
  467. +
  468.  
  469. +
  470.     /**
  471. +
  472.     * Get the status of the specified channel. If no channel name is specified, return the status of the current channel.
  473. +
  474.     *
  475. +
  476.     * @link http://www.voip-info.org/wiki-channel+status
  477. +
  478.     * @param string $channel 
  479. +
  480.     * @return array, see evaluate for return information. ['data'] contains description.
  481. +
  482.     */
  483. +
  484.     function channel_status($channel='')
  485. +
  486.     {
  487. +
  488.         $ret $this->evaluate("CHANNEL STATUS $channel");
  489. +
  490.         switch($ret['result'])
  491. +
  492.         {
  493. +
  494.           case -1$ret['data'trim("There is no channel that matches $channel")break;
  495. +
  496.           case AST_STATE_DOWN$ret['data''Channel is down and available'break;
  497. +
  498.           case AST_STATE_RESERVED$ret['data''Channel is down, but reserved'break;
  499. +
  500.           case AST_STATE_OFFHOOK$ret['data''Channel is off hook'break;
  501. +
  502.           case AST_STATE_DIALING$ret['data''Digits (or equivalent) have been dialed'break;
  503. +
  504.           case AST_STATE_RING$ret['data''Line is ringing'break;
  505. +
  506.           case AST_STATE_RINGING$ret['data''Remote end is ringing'break;
  507. +
  508.           case AST_STATE_UP$ret['data''Line is up'break;
  509. +
  510.           case AST_STATE_BUSY$ret['data''Line is busy'break;
  511. +
  512.           case AST_STATE_DIALING_OFFHOOK$ret['data''Digits (or equivalent) have been dialed while offhook'break;
  513. +
  514.           case AST_STATE_PRERING$ret['data''Channel has detected an incoming call and is waiting for ring'break;
  515. +
  516.           default$ret['data'"Unknown ({$ret['result']})"break;
  517. +
  518.         }
  519. +
  520.         return $ret;
  521. +
  522.     }
  523. +
  524.  
  525. +
  526.     /**
  527. +
  528.     * Deletes an entry in the Asterisk database for a given family and key.
  529. +
  530.     *
  531. +
  532.     * @link http://www.voip-info.org/wiki-database+del
  533. +
  534.     * @param string $family 
  535. +
  536.     * @param string $key 
  537. +
  538.     * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise.
  539. +
  540.     */
  541. +
  542.     function database_del($family$key)
  543. +
  544.     {
  545. +
  546.         return $this->evaluate("DATABASE DEL \"$family\" \"$key\"");
  547. +
  548.     }
  549. +
  550.  
  551. +
  552.     /**
  553. +
  554.     * Deletes a family or specific keytree within a family in the Asterisk database.
  555. +
  556.     *
  557. +
  558.     * @link http://www.voip-info.org/wiki-database+deltree
  559. +
  560.     * @param string $family 
  561. +
  562.     * @param string $keytree 
  563. +
  564.     * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise.
  565. +
  566.     */
  567. +
  568.     function database_deltree($family$keytree='')
  569. +
  570.     {
  571. +
  572.         $cmd "DATABASE DELTREE \"$family\"";
  573. +
  574.         if($keytree != ''$cmd .= " \"$keytree\"";
  575. +
  576.         return $this->evaluate($cmd);
  577. +
  578.     }
  579. +
  580.  
  581. +
  582.     /**
  583. +
  584.     * Retrieves an entry in the Asterisk database for a given family and key.
  585. +
  586.     *
  587. +
  588.     * @link http://www.voip-info.org/wiki-database+get
  589. +
  590.     * @param string $family 
  591. +
  592.     * @param string $key 
  593. +
  594.     * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 failure. ['data'] holds the value
  595. +
  596.     */
  597. +
  598.     function database_get($family$key)
  599. +
  600.     {
  601. +
  602.         return $this->evaluate("DATABASE GET \"$family\" \"$key\"");
  603. +
  604.     }
  605. +
  606.  
  607. +
  608.     /**
  609. +
  610.     * Adds or updates an entry in the Asterisk database for a given family, key, and value.
  611. +
  612.     *
  613. +
  614.     * @param string $family 
  615. +
  616.     * @param string $key 
  617. +
  618.     * @param string $value 
  619. +
  620.     * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise
  621. +
  622.     */
  623. +
  624.     function database_put($family$key$value)
  625. +
  626.     {
  627. +
  628.         $value str_replace("\n"'\n'addslashes($value));
  629. +
  630.         return $this->evaluate("DATABASE PUT \"$family\" \"$key\" \"$value\"");
  631. +
  632.     }
  633. +
  634.  
  635. +
  636.  
  637. +
  638.     /**
  639. +
  640.     * Sets a global variable, using Asterisk 1.6 syntax.
  641. +
  642.     *
  643. +
  644.     * @link http://www.voip-info.org/wiki/view/Asterisk+cmd+Set
  645. +
  646.     *
  647. +
  648.     * @param string $pVariable 
  649. +
  650.     * @param string|int|float$pValue 
  651. +
  652.     * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise
  653. +
  654.     */
  655. +
  656.     function set_global_var($pVariable$pValue)
  657. +
  658.     {
  659. +
  660.         if (is_numeric($pValue))
  661. +
  662.             return $this->evaluate("Set({$pVariable}={$pValue},g);");
  663. +
  664.         else
  665. +
  666.             return $this->evaluate("Set({$pVariable}=\"{$pValue}\",g);");
  667. +
  668.     }
  669. +
  670.  
  671. +
  672.  
  673. +
  674.     /**
  675. +
  676.     * Sets a variable, using Asterisk 1.6 syntax.
  677. +
  678.     *
  679. +
  680.     * @link http://www.voip-info.org/wiki/view/Asterisk+cmd+Set
  681. +
  682.     *
  683. +
  684.     * @param string $pVariable 
  685. +
  686.     * @param string|int|float$pValue 
  687. +
  688.     * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise
  689. +
  690.     */
  691. +
  692.     function set_var($pVariable$pValue)
  693. +
  694.     {
  695. +
  696.         if (is_numeric($pValue))
  697. +
  698.             return $this->evaluate("Set({$pVariable}={$pValue});");
  699. +
  700.         else
  701. +
  702.             return $this->evaluate("Set({$pVariable}=\"{$pValue}\");");
  703. +
  704.     }
  705. +
  706.  
  707. +
  708.  
  709. +
  710.     /**
  711. +
  712.     * Executes the specified Asterisk application with given options.
  713. +
  714.     *
  715. +
  716.     * @link http://www.voip-info.org/wiki-exec
  717. +
  718.     * @link http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands
  719. +
  720.     * @param string $application 
  721. +
  722.     * @param mixed $options 
  723. +
  724.     * @return array, see evaluate for return information. ['result'] is whatever the application returns, or -2 on failure to find application
  725. +
  726.     */
  727. +
  728.     function exec($application$options)
  729. +
  730.     {
  731. +
  732.         if(is_array($options)) $options join('|'$options);
  733. +
  734.         return $this->evaluate("EXEC $application $options");
  735. +
  736.     }
  737. +
  738.  
  739. +
  740.     /**
  741. +
  742.     * Plays the given file and receives DTMF data.
  743. +
  744.     *
  745. +
  746.     * This is similar to STREAM FILE, but this command can accept and return many DTMF digits,
  747. +
  748.     * while STREAM FILE returns immediately after the first DTMF digit is detected.
  749. +
  750.     *
  751. +
  752.     * Asterisk looks for the file to play in /var/lib/asterisk/sounds by default.
  753. +
  754.     *
  755. +
  756.     * If the user doesn't press any keys when the message plays, there is $timeout milliseconds
  757. +
  758.     * of silence then the command ends.
  759. +
  760.     *
  761. +
  762.     * The user has the opportunity to press a key at any time during the message or the
  763. +
  764.     * post-message silence. If the user presses a key while the message is playing, the
  765. +
  766.     * message stops playing. When the first key is pressed a timer starts counting for
  767. +
  768.     * $timeout milliseconds. Every time the user presses another key the timer is restarted.
  769. +
  770.     * The command ends when the counter goes to zero or the maximum number of digits is entered,
  771. +
  772.     * whichever happens first.
  773. +
  774.     *
  775. +
  776.     * If you don't specify a time out then a default timeout of 2000 is used following a pressed
  777. +
  778.     * digit. If no digits are pressed then 6 seconds of silence follow the message.
  779. +
  780.     *
  781. +
  782.     * If you don't specify $max_digits then the user can enter as many digits as they want.
  783. +
  784.     *
  785. +
  786.     * Pressing the # key has the same effect as the timer running out: the command ends and
  787. +
  788.     * any previously keyed digits are returned. A side effect of this is that there is no
  789. +
  790.     * way to read a # key using this command.
  791. +
  792.     *
  793. +
  794.     * @example examples/ping.php Ping an IP address
  795. +
  796.     *
  797. +
  798.     * @link http://www.voip-info.org/wiki-get+data
  799. +
  800.     * @param string $filename file to play. Do not include file extension.
  801. +
  802.     * @param integer $timeout milliseconds
  803. +
  804.     * @param integer $max_digits 
  805. +
  806.     * @return array, see evaluate for return information. ['result'] holds the digits and ['data'] holds the timeout if present.
  807. +
  808.     *
  809. +
  810.     *  This differs from other commands with return DTMF as numbers representing ASCII characters.
  811. +
  812.     */
  813. +
  814.     function get_data($filename$timeout=NULL$max_digits=NULL)
  815. +
  816.     {
  817. +
  818.         return $this->evaluate(rtrim("GET DATA $filename $timeout $max_digits"));
  819. +
  820.     }
  821. +
  822.  
  823. +
  824.     /**
  825. +
  826.     * Fetch the value of a variable.
  827. +
  828.     *
  829. +
  830.     * Does not work with global variables. Does not work with some variables that are generated by modules.
  831. +
  832.     *
  833. +
  834.     * @link http://www.voip-info.org/wiki-get+variable
  835. +
  836.     * @link http://www.voip-info.org/wiki-Asterisk+variables
  837. +
  838.     * @param string $variable name
  839. +
  840.     * @param boolean $getvalue return the value only
  841. +
  842.     * @return array, see evaluate for return information. ['result'] is 0 if variable hasn't been set, 1 if it has. ['data'] holds the value. returns value if $getvalue is TRUE
  843. +
  844.     */
  845. +
  846.     function get_variable($variable,$getvalue=FALSE)
  847. +
  848.     {
  849. +
  850.         $res=$this->evaluate("GET VARIABLE $variable");
  851. +
  852.  
  853. +
  854.         if($getvalue==FALSE)
  855. +
  856.           return($res);
  857. +
  858.  
  859. +
  860.         return($res['data']);
  861. +
  862.     }
  863. +
  864.  
  865. +
  866.  
  867. +
  868.     /**
  869. +
  870.     * Fetch the value of a full variable.
  871. +
  872.     *
  873. +
  874.     *
  875. +
  876.     * @link http://www.voip-info.org/wiki/view/get+full+variable
  877. +
  878.     * @link http://www.voip-info.org/wiki-Asterisk+variables
  879. +
  880.     * @param string $variable name
  881. +
  882.     * @param string $channel channel
  883. +
  884.     * @param boolean $getvalue return the value only
  885. +
  886.     * @return array, see evaluate for return information. ['result'] is 0 if variable hasn't been set, 1 if it has. ['data'] holds the value.  returns value if $getvalue is TRUE
  887. +
  888.     */
  889. +
  890.     function get_fullvariable($variable,$channel=FALSE,$getvalue=FALSE)
  891. +
  892.     {
  893. +
  894.       if($channel==FALSE){
  895. +
  896.         $req $variable;
  897. +
  898.       else {
  899. +
  900.         $req $variable.' '.$channel;
  901. +
  902.       }
  903. +
  904.       
  905. +
  906.       $res=$this->evaluate('GET VARIABLE FULL '.$req);
  907. +
  908.       
  909. +
  910.       if($getvalue==FALSE)
  911. +
  912.         return($res);
  913. +
  914.       
  915. +
  916.       return($res['data']);
  917. +
  918.       
  919. +
  920.     }
  921. +
  922.  
  923. +
  924.     /**
  925. +
  926.     * Hangup the specified channel. If no channel name is given, hang up the current channel.
  927. +
  928.     *
  929. +
  930.     * With power comes responsibility. Hanging up channels other than your own isn't something
  931. +
  932.     * that is done routinely. If you are not sure why you are doing so, then don't.
  933. +
  934.     *
  935. +
  936.     * @link http://www.voip-info.org/wiki-hangup
  937. +
  938.     * @example examples/dtmf.php Get DTMF tones from the user and say the digits
  939. +
  940.     * @example examples/input.php Get text input from the user and say it back
  941. +
  942.     * @example examples/ping.php Ping an IP address
  943. +
  944.     *
  945. +
  946.     * @param string $channel 
  947. +
  948.     * @return array, see evaluate for return information. ['result'] is 1 on success, -1 on failure.
  949. +
  950.     */
  951. +
  952.     function hangup($channel='')
  953. +
  954.     {
  955. +
  956.         return $this->evaluate("HANGUP $channel");
  957. +
  958.     }
  959. +
  960.  
  961. +
  962.     /**
  963. +
  964.     * Does nothing.
  965. +
  966.     *
  967. +
  968.     * @link http://www.voip-info.org/wiki-noop
  969. +
  970.     * @return array, see evaluate for return information.
  971. +
  972.     */
  973. +
  974.     function noop($string="")
  975. +
  976.     {
  977. +
  978.         return $this->evaluate("NOOP \"$string\"");
  979. +
  980.     }
  981. +
  982.  
  983. +
  984.     /**
  985. +
  986.     * Receive a character of text from a connected channel. Waits up to $timeout milliseconds for
  987. +
  988.     * a character to arrive, or infinitely if $timeout is zero.
  989. +
  990.     *
  991. +
  992.     * @link http://www.voip-info.org/wiki-receive+char
  993. +
  994.     * @param integer $timeout milliseconds
  995. +
  996.     * @return array, see evaluate for return information. ['result'] is 0 on timeout or not supported, -1 on failure. Otherwise
  997. +
  998.     *  it is the decimal value of the DTMF tone. Use chr() to convert to ASCII.
  999. +
  1000.     */
  1001. +
  1002.     function receive_char($timeout=-1)
  1003. +
  1004.     {
  1005. +
  1006.         return $this->evaluate("RECEIVE CHAR $timeout");
  1007. +
  1008.     }
  1009. +
  1010.  
  1011. +
  1012.     /**
  1013. +
  1014.     * Record sound to a file until an acceptable DTMF digit is received or a specified amount of
  1015. +
  1016.     * time has passed. Optionally the file BEEP is played before recording begins.
  1017. +
  1018.     *
  1019. +
  1020.     * @link http://www.voip-info.org/wiki-record+file
  1021. +
  1022.     * @param string $file to record, without extension, often created in /var/lib/asterisk/sounds
  1023. +
  1024.     * @param string $format of the file. GSM and WAV are commonly used formats. MP3 is read-only and thus cannot be used.
  1025. +
  1026.     * @param string $escape_digits 
  1027. +
  1028.     * @param integer $timeout is the maximum record time in milliseconds, or -1 for no timeout.
  1029. +
  1030.     * @param integer $offset to seek to without exceeding the end of the file.
  1031. +
  1032.     * @param boolean $beep 
  1033. +
  1034.     * @param integer $silence number of seconds of silence allowed before the function returns despite the
  1035. +
  1036.     *  lack of dtmf digits or reaching timeout.
  1037. +
  1038.     * @return array, see evaluate for return information. ['result'] is -1 on error, 0 on hangup, otherwise a decimal value of the
  1039. +
  1040.     *  DTMF tone. Use chr() to convert to ASCII.
  1041. +
  1042.     */
  1043. +
  1044.     function record_file($file$format$escape_digits=''$timeout=-1$offset=NULL$beep=false$silence=NULL)
  1045. +
  1046.     {
  1047. +
  1048.         $cmd trim("RECORD FILE $file $format \"$escape_digits\" $timeout $offset");
  1049. +
  1050.         if($beep$cmd .= ' BEEP';
  1051. +
  1052.         if(!is_null($silence)) $cmd .= " s=$silence";
  1053. +
  1054.         return $this->evaluate($cmd);
  1055. +
  1056.     }
  1057. +
  1058.  
  1059. +
  1060.     /**
  1061. +
  1062.     * Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.
  1063. +
  1064.     *
  1065. +
  1066.     * @link http://www.voip-info.org/wiki-say+digits
  1067. +
  1068.     * @param integer $digits 
  1069. +
  1070.     * @param string $escape_digits 
  1071. +
  1072.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1073. +
  1074.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1075. +
  1076.     */
  1077. +
  1078.     function say_digits($digits$escape_digits='')
  1079. +
  1080.     {
  1081. +
  1082.         return $this->evaluate("SAY DIGITS $digits \"$escape_digits\"");
  1083. +
  1084.     }
  1085. +
  1086.  
  1087. +
  1088.     /**
  1089. +
  1090.     * Say the given number, returning early if any of the given DTMF escape digits are received on the channel.
  1091. +
  1092.     *
  1093. +
  1094.     * @link http://www.voip-info.org/wiki-say+number
  1095. +
  1096.     * @param integer $number 
  1097. +
  1098.     * @param string $escape_digits 
  1099. +
  1100.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1101. +
  1102.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1103. +
  1104.     */
  1105. +
  1106.     function say_number($number$escape_digits='')
  1107. +
  1108.     {
  1109. +
  1110.         return $this->evaluate("SAY NUMBER $number \"$escape_digits\"");
  1111. +
  1112.     }
  1113. +
  1114.  
  1115. +
  1116.     /**
  1117. +
  1118.     * Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.
  1119. +
  1120.     *
  1121. +
  1122.     * @link http://www.voip-info.org/wiki-say+phonetic
  1123. +
  1124.     * @param string $text 
  1125. +
  1126.     * @param string $escape_digits 
  1127. +
  1128.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1129. +
  1130.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1131. +
  1132.     */
  1133. +
  1134.     function say_phonetic($text$escape_digits='')
  1135. +
  1136.     {
  1137. +
  1138.         return $this->evaluate("SAY PHONETIC $text \"$escape_digits\"");
  1139. +
  1140.     }
  1141. +
  1142.  
  1143. +
  1144.     /**
  1145. +
  1146.     * Say a given time, returning early if any of the given DTMF escape digits are received on the channel.
  1147. +
  1148.     *
  1149. +
  1150.     * @link http://www.voip-info.org/wiki-say+time
  1151. +
  1152.     * @param integer $time number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
  1153. +
  1154.     * @param string $escape_digits 
  1155. +
  1156.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1157. +
  1158.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1159. +
  1160.     */
  1161. +
  1162.     function say_time($time=NULL$escape_digits='')
  1163. +
  1164.     {
  1165. +
  1166.         if(is_null($time)) $time time();
  1167. +
  1168.         return $this->evaluate("SAY TIME $time \"$escape_digits\"");
  1169. +
  1170.     }
  1171. +
  1172.  
  1173. +
  1174.     /**
  1175. +
  1176.     * Send the specified image on a channel.
  1177. +
  1178.     *
  1179. +
  1180.     * Most channels do not support the transmission of images.
  1181. +
  1182.     *
  1183. +
  1184.     * @link http://www.voip-info.org/wiki-send+image
  1185. +
  1186.     * @param string $image without extension, often in /var/lib/asterisk/images
  1187. +
  1188.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the image is sent or
  1189. +
  1190.     *  channel does not support image transmission.
  1191. +
  1192.     */
  1193. +
  1194.     function send_image($image)
  1195. +
  1196.     {
  1197. +
  1198.         return $this->evaluate("SEND IMAGE $image");
  1199. +
  1200.     }
  1201. +
  1202.  
  1203. +
  1204.     /**
  1205. +
  1206.     * Send the given text to the connected channel.
  1207. +
  1208.     *
  1209. +
  1210.     * Most channels do not support transmission of text.
  1211. +
  1212.     *
  1213. +
  1214.     * @link http://www.voip-info.org/wiki-send+text
  1215. +
  1216.     * @param $text 
  1217. +
  1218.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the text is sent or
  1219. +
  1220.     *  channel does not support text transmission.
  1221. +
  1222.     */
  1223. +
  1224.     function send_text($text)
  1225. +
  1226.     {
  1227. +
  1228.         return $this->evaluate("SEND TEXT \"$text\"");
  1229. +
  1230.     }
  1231. +
  1232.  
  1233. +
  1234.     /**
  1235. +
  1236.     * Cause the channel to automatically hangup at $time seconds in the future.
  1237. +
  1238.     * If $time is 0 then the autohangup feature is disabled on this channel.
  1239. +
  1240.     *
  1241. +
  1242.     * If the channel is hungup prior to $time seconds, this setting has no effect.
  1243. +
  1244.     *
  1245. +
  1246.     * @link http://www.voip-info.org/wiki-set+autohangup
  1247. +
  1248.     * @param integer $time until automatic hangup
  1249. +
  1250.     * @return array, see evaluate for return information.
  1251. +
  1252.     */
  1253. +
  1254.     function set_autohangup($time=0)
  1255. +
  1256.     {
  1257. +
  1258.         return $this->evaluate("SET AUTOHANGUP $time");
  1259. +
  1260.     }
  1261. +
  1262.  
  1263. +
  1264.     /**
  1265. +
  1266.     * Changes the caller ID of the current channel.
  1267. +
  1268.     *
  1269. +
  1270.     * @link http://www.voip-info.org/wiki-set+callerid
  1271. +
  1272.     * @param string $cid example: "John Smith"<1234567>
  1273. +
  1274.     *  This command will let you take liberties with the <caller ID specification> but the format shown in the example above works
  1275. +
  1276.     *  well: the name enclosed in double quotes followed immediately by the number inside angle brackets. If there is no name then
  1277. +
  1278.     *  you can omit it. If the name contains no spaces you can omit the double quotes around it. The number must follow the name
  1279. +
  1280.     *  immediately; don't put a space between them. The angle brackets around the number are necessary; if you omit them the
  1281. +
  1282.     *  number will be considered to be part of the name.
  1283. +
  1284.     * @return array, see evaluate for return information.
  1285. +
  1286.     */
  1287. +
  1288.     function set_callerid($cid)
  1289. +
  1290.     {
  1291. +
  1292.         return $this->evaluate("SET CALLERID $cid");
  1293. +
  1294.     }
  1295. +
  1296.  
  1297. +
  1298.     /**
  1299. +
  1300.     * Sets the context for continuation upon exiting the application.
  1301. +
  1302.     *
  1303. +
  1304.     * Setting the context does NOT automatically reset the extension and the priority; if you want to start at the top of the new
  1305. +
  1306.     * context you should set extension and priority yourself.
  1307. +
  1308.     *
  1309. +
  1310.     * If you specify a non-existent context you receive no error indication (['result'] is still 0) but you do get a
  1311. +
  1312.     * warning message on the Asterisk console.
  1313. +
  1314.     *
  1315. +
  1316.     * @link http://www.voip-info.org/wiki-set+context
  1317. +
  1318.     * @param string $context 
  1319. +
  1320.     * @return array, see evaluate for return information.
  1321. +
  1322.     */
  1323. +
  1324.     function set_context($context)
  1325. +
  1326.     {
  1327. +
  1328.         return $this->evaluate("SET CONTEXT $context");
  1329. +
  1330.     }
  1331. +
  1332.  
  1333. +
  1334.     /**
  1335. +
  1336.     * Set the extension to be used for continuation upon exiting the application.
  1337. +
  1338.     *
  1339. +
  1340.     * Setting the extension does NOT automatically reset the priority. If you want to start with the first priority of the
  1341. +
  1342.     * extension you should set the priority yourself.
  1343. +
  1344.     *
  1345. +
  1346.     * If you specify a non-existent extension you receive no error indication (['result'] is still 0) but you do
  1347. +
  1348.     * get a warning message on the Asterisk console.
  1349. +
  1350.     *
  1351. +
  1352.     * @link http://www.voip-info.org/wiki-set+extension
  1353. +
  1354.     * @param string $extension 
  1355. +
  1356.     * @return array, see evaluate for return information.
  1357. +
  1358.     */
  1359. +
  1360.     function set_extension($extension)
  1361. +
  1362.     {
  1363. +
  1364.         return $this->evaluate("SET EXTENSION $extension");
  1365. +
  1366.     }
  1367. +
  1368.  
  1369. +
  1370.     /**
  1371. +
  1372.     * Enable/Disable Music on hold generator.
  1373. +
  1374.     *
  1375. +
  1376.     * @link http://www.voip-info.org/wiki-set+music
  1377. +
  1378.     * @param boolean $enabled 
  1379. +
  1380.     * @param string $class 
  1381. +
  1382.     * @return array, see evaluate for return information.
  1383. +
  1384.     */
  1385. +
  1386.     function set_music($enabled=true$class='')
  1387. +
  1388.     {
  1389. +
  1390.         $enabled ($enabled'ON' 'OFF';
  1391. +
  1392.         return $this->evaluate("SET MUSIC $enabled $class");
  1393. +
  1394.     }
  1395. +
  1396.  
  1397. +
  1398.     /**
  1399. +
  1400.     * Set the priority to be used for continuation upon exiting the application.
  1401. +
  1402.     *
  1403. +
  1404.     * If you specify a non-existent priority you receive no error indication (['result'] is still 0)
  1405. +
  1406.     * and no warning is issued on the Asterisk console.
  1407. +
  1408.     *
  1409. +
  1410.     * @link http://www.voip-info.org/wiki-set+priority
  1411. +
  1412.     * @param integer $priority 
  1413. +
  1414.     * @return array, see evaluate for return information.
  1415. +
  1416.     */
  1417. +
  1418.     function set_priority($priority)
  1419. +
  1420.     {
  1421. +
  1422.         return $this->evaluate("SET PRIORITY $priority");
  1423. +
  1424.     }
  1425. +
  1426.  
  1427. +
  1428.     /**
  1429. +
  1430.     * Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>}
  1431. +
  1432.     * in the dialplan.
  1433. +
  1434.     *
  1435. +
  1436.     * These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary.
  1437. +
  1438.     * Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted
  1439. +
  1440.     * and any variables in that channel are deleted as well.
  1441. +
  1442.     *
  1443. +
  1444.     * @link http://www.voip-info.org/wiki-set+variable
  1445. +
  1446.     * @param string $variable is case sensitive
  1447. +
  1448.     * @param string $value 
  1449. +
  1450.     * @return array, see evaluate for return information.
  1451. +
  1452.     */
  1453. +
  1454.     function set_variable($variable$value)
  1455. +
  1456.     {
  1457. +
  1458.         $value str_replace("\n"'\n'addslashes($value));
  1459. +
  1460.         return $this->evaluate("SET VARIABLE $variable \"$value\"");
  1461. +
  1462.     }
  1463. +
  1464.  
  1465. +
  1466.     /**
  1467. +
  1468.     * Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA
  1469. +
  1470.     * command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of
  1471. +
  1472.     * digits before returning.
  1473. +
  1474.     *
  1475. +
  1476.     * @example examples/ping.php Ping an IP address
  1477. +
  1478.     *
  1479. +
  1480.     * @link http://www.voip-info.org/wiki-stream+file
  1481. +
  1482.     * @param string $filename without extension, often in /var/lib/asterisk/sounds
  1483. +
  1484.     * @param string $escape_digits 
  1485. +
  1486.     * @param integer $offset 
  1487. +
  1488.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1489. +
  1490.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1491. +
  1492.     */
  1493. +
  1494.     function stream_file($filename$escape_digits=''$offset=0)
  1495. +
  1496.     {
  1497. +
  1498.         return $this->evaluate("STREAM FILE $filename \"$escape_digits\" $offset");
  1499. +
  1500.     }
  1501. +
  1502.  
  1503. +
  1504.     /**
  1505. +
  1506.     * Enable or disable TDD transmission/reception on the current channel.
  1507. +
  1508.     *
  1509. +
  1510.     * @link http://www.voip-info.org/wiki-tdd+mode
  1511. +
  1512.     * @param string $setting can be on, off or mate
  1513. +
  1514.     * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 if the channel is not TDD capable.
  1515. +
  1516.     */
  1517. +
  1518.     function tdd_mode($setting)
  1519. +
  1520.     {
  1521. +
  1522.         return $this->evaluate("TDD MODE $setting");
  1523. +
  1524.     }
  1525. +
  1526.  
  1527. +
  1528.     /**
  1529. +
  1530.     * Sends $message to the Asterisk console via the 'verbose' message system.
  1531. +
  1532.     *
  1533. +
  1534.     * If the Asterisk verbosity level is $level or greater, send $message to the console.
  1535. +
  1536.     *
  1537. +
  1538.     * The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later
  1539. +
  1540.     * using the console 'set verbose' command. Messages are displayed on the console if their verbose level is less than or equal
  1541. +
  1542.     * to desired verbosity set by the user. More important messages should have a low verbose level; less important messages
  1543. +
  1544.     * should have a high verbose level.
  1545. +
  1546.     *
  1547. +
  1548.     * @link http://www.voip-info.org/wiki-verbose
  1549. +
  1550.     * @param string $message 
  1551. +
  1552.     * @param integer $level from 1 to 4
  1553. +
  1554.     * @return array, see evaluate for return information.
  1555. +
  1556.     */
  1557. +
  1558.     function verbose($message$level=1)
  1559. +
  1560.     {
  1561. +
  1562.         foreach(explode("\n"str_replace("\r\n""\n"print_r($messagetrue))) as $msg)
  1563. +
  1564.         {
  1565. +
  1566.           @syslog(LOG_WARNING$msg);
  1567. +
  1568.           $ret $this->evaluate("VERBOSE \"$msg\" $level");
  1569. +
  1570.         }
  1571. +
  1572.         return $ret;
  1573. +
  1574.     }
  1575. +
  1576.  
  1577. +
  1578.     /**
  1579. +
  1580.     * Waits up to $timeout milliseconds for channel to receive a DTMF digit.
  1581. +
  1582.     *
  1583. +
  1584.     * @link http://www.voip-info.org/wiki-wait+for+digit
  1585. +
  1586.     * @param integer $timeout in millisecons. Use -1 for the timeout value if you want the call to wait indefinitely.
  1587. +
  1588.     * @return array, see evaluate for return information. ['result'] is 0 if wait completes with no
  1589. +
  1590.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1591. +
  1592.     */
  1593. +
  1594.     function wait_for_digit($timeout=-1)
  1595. +
  1596.     {
  1597. +
  1598.         return $this->evaluate("WAIT FOR DIGIT $timeout");
  1599. +
  1600.     }
  1601. +
  1602.  
  1603. +
  1604.  
  1605. +
  1606.     // *********************************************************************************************************
  1607. +
  1608.     // **                             APPLICATIONS                                                                                        **
  1609. +
  1610.     // *********************************************************************************************************
  1611. +
  1612.  
  1613. +
  1614.     /**
  1615. +
  1616.     * Set absolute maximum time of call.
  1617. +
  1618.     *
  1619. +
  1620.     * Note that the timeout is set from the current time forward, not counting the number of seconds the call has already been up.
  1621. +
  1622.     * Each time you call AbsoluteTimeout(), all previous absolute timeouts are cancelled.
  1623. +
  1624.     * Will return the call to the T extension so that you can playback an explanatory note to the calling party (the called party
  1625. +
  1626.     * will not hear that)
  1627. +
  1628.     *
  1629. +
  1630.     * @link http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands
  1631. +
  1632.     * @link http://www.dynx.net/ASTERISK/AGI/ccard/agi-ccard.agi
  1633. +
  1634.     * @param $seconds allowed, 0 disables timeout
  1635. +
  1636.     * @return array, see evaluate for return information.
  1637. +
  1638.     */
  1639. +
  1640.     function exec_absolutetimeout($seconds=0)
  1641. +
  1642.     {
  1643. +
  1644.         return $this->exec('AbsoluteTimeout'$seconds);
  1645. +
  1646.     }
  1647. +
  1648.  
  1649. +
  1650.     /**
  1651. +
  1652.     * Executes an AGI compliant application.
  1653. +
  1654.     *
  1655. +
  1656.     * @param string $command 
  1657. +
  1658.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or if application requested hangup, or 0 on non-hangup exit.
  1659. +
  1660.     * @param string $args 
  1661. +
  1662.     */
  1663. +
  1664.     function exec_agi($command$args)
  1665. +
  1666.     {
  1667. +
  1668.         return $this->exec("AGI $command"$args);
  1669. +
  1670.     }
  1671. +
  1672.  
  1673. +
  1674.     /**
  1675. +
  1676.     * Set Language.
  1677. +
  1678.     *
  1679. +
  1680.     * @param string $language code
  1681. +
  1682.     * @return array, see evaluate for return information.
  1683. +
  1684.     */
  1685. +
  1686.     function exec_setlanguage($language='en')
  1687. +
  1688.     {
  1689. +
  1690.         return $this->exec('Set''CHANNEL(language)='$language);
  1691. +
  1692.     }
  1693. +
  1694.  
  1695. +
  1696.     /**
  1697. +
  1698.     * Do ENUM Lookup.
  1699. +
  1700.     *
  1701. +
  1702.     * Note: to retrieve the result, use
  1703. +
  1704.     *   get_variable('ENUM');
  1705. +
  1706.     *
  1707. +
  1708.     * @param $exten 
  1709. +
  1710.     * @return array, see evaluate for return information.
  1711. +
  1712.     */
  1713. +
  1714.     function exec_enumlookup($exten)
  1715. +
  1716.     {
  1717. +
  1718.         return $this->exec('EnumLookup'$exten);
  1719. +
  1720.     }
  1721. +
  1722.  
  1723. +
  1724.     /**
  1725. +
  1726.     * Dial.
  1727. +
  1728.     *
  1729. +
  1730.     * Dial takes input from ${VXML_URL} to send XML Url to Cisco 7960
  1731. +
  1732.     * Dial takes input from ${ALERT_INFO} to set ring cadence for Cisco phones
  1733. +
  1734.     * Dial returns ${CAUSECODE}: If the dial failed, this is the errormessage.
  1735. +
  1736.     * Dial returns ${DIALSTATUS}: Text code returning status of last dial attempt.
  1737. +
  1738.     *
  1739. +
  1740.     * @link http://www.voip-info.org/wiki-Asterisk+cmd+Dial
  1741. +
  1742.     * @param string $type 
  1743. +
  1744.     * @param string $identifier 
  1745. +
  1746.     * @param integer $timeout 
  1747. +
  1748.     * @param string $options 
  1749. +
  1750.     * @param string $url 
  1751. +
  1752.     * @return array, see evaluate for return information.
  1753. +
  1754.     */
  1755. +
  1756.     function exec_dial($type$identifier$timeout=NULL$options=NULL$url=NULL)
  1757. +
  1758.     {
  1759. +
  1760.         return $this->exec('Dial'trim("$type/$identifier".$this->option_delim.$timeout.$this->option_delim.$options.$this->option_delim.$url$this->option_delim));
  1761. +
  1762.     }
  1763. +
  1764.  
  1765. +
  1766.     /**
  1767. +
  1768.     * Goto.
  1769. +
  1770.     *
  1771. +
  1772.     * This function takes three arguments: context,extension, and priority, but the leading arguments
  1773. +
  1774.     * are optional, not the trailing arguments.  Thuse goto($z) sets the priority to $z.
  1775. +
  1776.     *
  1777. +
  1778.     * @param string $a 
  1779. +
  1780.     * @param string $b; 
  1781. +
  1782.     * @param string $c; 
  1783. +
  1784.     * @return array, see evaluate for return information.
  1785. +
  1786.     */
  1787. +
  1788.     function exec_goto($a$b=NULL$c=NULL)
  1789. +
  1790.     {
  1791. +
  1792.         return $this->exec('Goto'trim($a.$this->option_delim.$b.$this->option_delim.$c$this->option_delim));
  1793. +
  1794.     }
  1795. +
  1796.  
  1797. +
  1798.  
  1799. +
  1800.     // *********************************************************************************************************
  1801. +
  1802.     // **                             FAST PASSING                                                                                        **
  1803. +
  1804.     // *********************************************************************************************************
  1805. +
  1806.  
  1807. +
  1808.     /**
  1809. +
  1810.     * Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.
  1811. +
  1812.     * Return early if $buffer is adequate for request.
  1813. +
  1814.     *
  1815. +
  1816.     * @link http://www.voip-info.org/wiki-say+digits
  1817. +
  1818.     * @param string $buffer 
  1819. +
  1820.     * @param integer $digits 
  1821. +
  1822.     * @param string $escape_digits 
  1823. +
  1824.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1825. +
  1826.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1827. +
  1828.     */
  1829. +
  1830.     function fastpass_say_digits(&$buffer$digits$escape_digits='')
  1831. +
  1832.     {
  1833. +
  1834.      $proceed false;
  1835. +
  1836.      if($escape_digits != '' && $buffer != '')
  1837. +
  1838.      {
  1839. +
  1840.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  1841. +
  1842.            $proceed true;
  1843. +
  1844.      }
  1845. +
  1846.      if($buffer == '' || $proceed)
  1847. +
  1848.      {
  1849. +
  1850.          $res $this->say_digits($digits$escape_digits);
  1851. +
  1852.          if($res['code'== AGIRES_OK && $res['result'0)
  1853. +
  1854.            $buffer .= chr($res['result']);
  1855. +
  1856.          return $res;
  1857. +
  1858.      }
  1859. +
  1860.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1}));
  1861. +
  1862.     }
  1863. +
  1864.  
  1865. +
  1866.     /**
  1867. +
  1868.     * Say the given number, returning early if any of the given DTMF escape digits are received on the channel.
  1869. +
  1870.     * Return early if $buffer is adequate for request.
  1871. +
  1872.     *
  1873. +
  1874.     * @link http://www.voip-info.org/wiki-say+number
  1875. +
  1876.     * @param string $buffer 
  1877. +
  1878.     * @param integer $number 
  1879. +
  1880.     * @param string $escape_digits 
  1881. +
  1882.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1883. +
  1884.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1885. +
  1886.     */
  1887. +
  1888.     function fastpass_say_number(&$buffer$number$escape_digits='')
  1889. +
  1890.     {
  1891. +
  1892.      $proceed false;
  1893. +
  1894.      if($escape_digits != '' && $buffer != '')
  1895. +
  1896.      {
  1897. +
  1898.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  1899. +
  1900.            $proceed true;
  1901. +
  1902.      }
  1903. +
  1904.      if($buffer == '' || $proceed)
  1905. +
  1906.      {
  1907. +
  1908.          $res $this->say_number($number$escape_digits);
  1909. +
  1910.          if($res['code'== AGIRES_OK && $res['result'0)
  1911. +
  1912.            $buffer .= chr($res['result']);
  1913. +
  1914.          return $res;
  1915. +
  1916.      }
  1917. +
  1918.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1}));
  1919. +
  1920.     }
  1921. +
  1922.  
  1923. +
  1924.     /**
  1925. +
  1926.     * Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.
  1927. +
  1928.     * Return early if $buffer is adequate for request.
  1929. +
  1930.     *
  1931. +
  1932.     * @link http://www.voip-info.org/wiki-say+phonetic
  1933. +
  1934.     * @param string $buffer 
  1935. +
  1936.     * @param string $text 
  1937. +
  1938.     * @param string $escape_digits 
  1939. +
  1940.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1941. +
  1942.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  1943. +
  1944.     */
  1945. +
  1946.     function fastpass_say_phonetic(&$buffer$text$escape_digits='')
  1947. +
  1948.     {
  1949. +
  1950.      $proceed false;
  1951. +
  1952.      if($escape_digits != '' && $buffer != '')
  1953. +
  1954.      {
  1955. +
  1956.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  1957. +
  1958.            $proceed true;
  1959. +
  1960.      }
  1961. +
  1962.      if($buffer == '' || $proceed)
  1963. +
  1964.      {
  1965. +
  1966.          $res $this->say_phonetic($text$escape_digits);
  1967. +
  1968.          if($res['code'== AGIRES_OK && $res['result'0)
  1969. +
  1970.            $buffer .= chr($res['result']);
  1971. +
  1972.          return $res;
  1973. +
  1974.      }
  1975. +
  1976.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1}));
  1977. +
  1978.     }
  1979. +
  1980.  
  1981. +
  1982.     /**
  1983. +
  1984.     * Say a given time, returning early if any of the given DTMF escape digits are received on the channel.
  1985. +
  1986.     * Return early if $buffer is adequate for request.
  1987. +
  1988.     *
  1989. +
  1990.     * @link http://www.voip-info.org/wiki-say+time
  1991. +
  1992.     * @param string $buffer 
  1993. +
  1994.     * @param integer $time number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
  1995. +
  1996.     * @param string $escape_digits 
  1997. +
  1998.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  1999. +
  2000.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  2001. +
  2002.     */
  2003. +
  2004.     function fastpass_say_time(&$buffer$time=NULL$escape_digits='')
  2005. +
  2006.     {
  2007. +
  2008.      $proceed false;
  2009. +
  2010.      if($escape_digits != '' && $buffer != '')
  2011. +
  2012.      {
  2013. +
  2014.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  2015. +
  2016.            $proceed true;
  2017. +
  2018.      }
  2019. +
  2020.      if($buffer == '' || $proceed)
  2021. +
  2022.      {
  2023. +
  2024.          $res $this->say_time($time$escape_digits);
  2025. +
  2026.          if($res['code'== AGIRES_OK && $res['result'0)
  2027. +
  2028.            $buffer .= chr($res['result']);
  2029. +
  2030.          return $res;
  2031. +
  2032.      }
  2033. +
  2034.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1}));
  2035. +
  2036.     }
  2037. +
  2038.  
  2039. +
  2040.     /**
  2041. +
  2042.     * Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA
  2043. +
  2044.     * command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of
  2045. +
  2046.     * digits before returning.
  2047. +
  2048.     * Return early if $buffer is adequate for request.
  2049. +
  2050.     *
  2051. +
  2052.     * @link http://www.voip-info.org/wiki-stream+file
  2053. +
  2054.     * @param string $buffer 
  2055. +
  2056.     * @param string $filename without extension, often in /var/lib/asterisk/sounds
  2057. +
  2058.     * @param string $escape_digits 
  2059. +
  2060.     * @param integer $offset 
  2061. +
  2062.     * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
  2063. +
  2064.     *  digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
  2065. +
  2066.     */
  2067. +
  2068.     function fastpass_stream_file(&$buffer$filename$escape_digits=''$offset=0)
  2069. +
  2070.     {
  2071. +
  2072.      $proceed false;
  2073. +
  2074.      if($escape_digits != '' && $buffer != '')
  2075. +
  2076.      {
  2077. +
  2078.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  2079. +
  2080.            $proceed true;
  2081. +
  2082.      }
  2083. +
  2084.      if($buffer == '' || $proceed)
  2085. +
  2086.      {
  2087. +
  2088.          $res $this->stream_file($filename$escape_digits$offset);
  2089. +
  2090.          if($res['code'== AGIRES_OK && $res['result'0)
  2091. +
  2092.            $buffer .= chr($res['result']);
  2093. +
  2094.          return $res;
  2095. +
  2096.      }
  2097. +
  2098.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1})'endpos'=>0);
  2099. +
  2100.     }
  2101. +
  2102.  
  2103. +
  2104.     /**
  2105. +
  2106.     * Use festival to read text.
  2107. +
  2108.     * Return early if $buffer is adequate for request.
  2109. +
  2110.     *
  2111. +
  2112.     * @link http://www.cstr.ed.ac.uk/projects/festival/
  2113. +
  2114.     * @param string $buffer 
  2115. +
  2116.     * @param string $text 
  2117. +
  2118.     * @param string $escape_digits 
  2119. +
  2120.     * @param integer $frequency 
  2121. +
  2122.     * @return array, see evaluate for return information.
  2123. +
  2124.     */
  2125. +
  2126.     function fastpass_text2wav(&$buffer$text$escape_digits=''$frequency=8000)
  2127. +
  2128.     {
  2129. +
  2130.      $proceed false;
  2131. +
  2132.      if($escape_digits != '' && $buffer != '')
  2133. +
  2134.      {
  2135. +
  2136.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  2137. +
  2138.            $proceed true;
  2139. +
  2140.      }
  2141. +
  2142.      if($buffer == '' || $proceed)
  2143. +
  2144.      {
  2145. +
  2146.          $res $this->text2wav($text$escape_digits$frequency);
  2147. +
  2148.          if($res['code'== AGIRES_OK && $res['result'0)
  2149. +
  2150.            $buffer .= chr($res['result']);
  2151. +
  2152.          return $res;
  2153. +
  2154.      }
  2155. +
  2156.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1})'endpos'=>0);
  2157. +
  2158.     }
  2159. +
  2160.  
  2161. +
  2162.     /**
  2163. +
  2164.     * Use Cepstral Swift to read text.
  2165. +
  2166.     * Return early if $buffer is adequate for request.
  2167. +
  2168.     *
  2169. +
  2170.     * @link http://www.cepstral.com/
  2171. +
  2172.     * @param string $buffer 
  2173. +
  2174.     * @param string $text 
  2175. +
  2176.     * @param string $escape_digits 
  2177. +
  2178.     * @param integer $frequency 
  2179. +
  2180.     * @return array, see evaluate for return information.
  2181. +
  2182.     */
  2183. +
  2184.     function fastpass_swift(&$buffer$text$escape_digits=''$frequency=8000$voice=NULL)
  2185. +
  2186.     {
  2187. +
  2188.      $proceed false;
  2189. +
  2190.      if($escape_digits != '' && $buffer != '')
  2191. +
  2192.      {
  2193. +
  2194.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  2195. +
  2196.            $proceed true;
  2197. +
  2198.      }
  2199. +
  2200.      if($buffer == '' || $proceed)
  2201. +
  2202.      {
  2203. +
  2204.          $res $this->swift($text$escape_digits$frequency$voice);
  2205. +
  2206.          if($res['code'== AGIRES_OK && $res['result'0)
  2207. +
  2208.            $buffer .= chr($res['result']);
  2209. +
  2210.          return $res;
  2211. +
  2212.      }
  2213. +
  2214.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1})'endpos'=>0);
  2215. +
  2216.     }
  2217. +
  2218.  
  2219. +
  2220.     /**
  2221. +
  2222.     * Say Puncutation in a string.
  2223. +
  2224.     * Return early if $buffer is adequate for request.
  2225. +
  2226.     *
  2227. +
  2228.     * @param string $buffer 
  2229. +
  2230.     * @param string $text 
  2231. +
  2232.     * @param string $escape_digits 
  2233. +
  2234.     * @param integer $frequency 
  2235. +
  2236.     * @return array, see evaluate for return information.
  2237. +
  2238.     */
  2239. +
  2240.     function fastpass_say_punctuation(&$buffer$text$escape_digits=''$frequency=8000)
  2241. +
  2242.     {
  2243. +
  2244.      $proceed false;
  2245. +
  2246.      if($escape_digits != '' && $buffer != '')
  2247. +
  2248.      {
  2249. +
  2250.          if(!strpos(chr(255$escape_digits$buffer{strlen($buffer)-1}))
  2251. +
  2252.            $proceed true;
  2253. +
  2254.      }
  2255. +
  2256.      if($buffer == '' || $proceed)
  2257. +
  2258.      {
  2259. +
  2260.          $res $this->say_punctuation($text$escape_digits$frequency);
  2261. +
  2262.          if($res['code'== AGIRES_OK && $res['result'0)
  2263. +
  2264.            $buffer .= chr($res['result']);
  2265. +
  2266.          return $res;
  2267. +
  2268.      }
  2269. +
  2270.      return array('code'=>AGIRES_OK'result'=>ord($buffer{strlen($buffer)-1}));
  2271. +
  2272.     }
  2273. +
  2274.  
  2275. +
  2276.     /**
  2277. +
  2278.     * Plays the given file and receives DTMF data.
  2279. +
  2280.     * Return early if $buffer is adequate for request.
  2281. +
  2282.     *
  2283. +
  2284.     * This is similar to STREAM FILE, but this command can accept and return many DTMF digits,
  2285. +
  2286.     * while STREAM FILE returns immediately after the first DTMF digit is detected.
  2287. +
  2288.     *
  2289. +
  2290.     * Asterisk looks for the file to play in /var/lib/asterisk/sounds by default.
  2291. +
  2292.     *
  2293. +
  2294.     * If the user doesn't press any keys when the message plays, there is $timeout milliseconds
  2295. +
  2296.     * of silence then the command ends.
  2297. +
  2298.     *
  2299. +
  2300.     * The user has the opportunity to press a key at any time during the message or the
  2301. +
  2302.     * post-message silence. If the user presses a key while the message is playing, the
  2303. +
  2304.     * message stops playing. When the first key is pressed a timer starts counting for
  2305. +
  2306.     * $timeout milliseconds. Every time the user presses another key the timer is restarted.
  2307. +
  2308.     * The command ends when the counter goes to zero or the maximum number of digits is entered,
  2309. +
  2310.     * whichever happens first.
  2311. +
  2312.     *
  2313. +
  2314.     * If you don't specify a time out then a default timeout of 2000 is used following a pressed
  2315. +
  2316.     * digit. If no digits are pressed then 6 seconds of silence follow the message.
  2317. +
  2318.     *
  2319. +
  2320.     * If you don't specify $max_digits then the user can enter as many digits as they want.
  2321. +
  2322.     *
  2323. +
  2324.     * Pressing the # key has the same effect as the timer running out: the command ends and
  2325. +
  2326.     * any previously keyed digits are returned. A side effect of this is that there is no
  2327. +
  2328.     * way to read a # key using this command.
  2329. +
  2330.     *
  2331. +
  2332.     * @link http://www.voip-info.org/wiki-get+data
  2333. +
  2334.     * @param string $buffer 
  2335. +
  2336.     * @param string $filename file to play. Do not include file extension.
  2337. +
  2338.     * @param integer $timeout milliseconds
  2339. +
  2340.     * @param integer $max_digits 
  2341. +
  2342.     * @return array, see evaluate for return information. ['result'] holds the digits and ['data'] holds the timeout if present.
  2343. +
  2344.     *
  2345. +
  2346.     *  This differs from other commands with return DTMF as numbers representing ASCII characters.
  2347. +
  2348.     */
  2349. +
  2350.     function fastpass_get_data(&$buffer$filename$timeout=NULL$max_digits=NULL)
  2351. +
  2352.     {
  2353. +
  2354.      if(is_null($max_digits|| strlen($buffer$max_digits)
  2355. +
  2356.      {
  2357. +
  2358.          if($buffer == '')
  2359. +
  2360.          {
  2361. +
  2362.            $res $this->get_data($filename$timeout$max_digits);
  2363. +
  2364.            if($res['code'== AGIRES_OK)
  2365. +
  2366.              $buffer .= $res['result'];
  2367. +
  2368.            return $res;
  2369. +
  2370.          }
  2371. +
  2372.          else
  2373. +
  2374.          {
  2375. +
  2376.            while(is_null($max_digits|| strlen($buffer$max_digits)
  2377. +
  2378.            {
  2379. +
  2380.              $res $this->wait_for_digit();
  2381. +
  2382.              if($res['code'!= AGIRES_OKreturn $res;
  2383. +
  2384.              if($res['result'== ord('#')) break;
  2385. +
  2386.              $buffer .= chr($res['result']);
  2387. +
  2388.            }
  2389. +
  2390.          }
  2391. +
  2392.      }
  2393. +
  2394.      return array('code'=>AGIRES_OK'result'=>$buffer);
  2395. +
  2396.     }
  2397. +
  2398.  
  2399. +
  2400.     // *********************************************************************************************************
  2401. +
  2402.     // **                             DERIVED                                                                                             **
  2403. +
  2404.     // *********************************************************************************************************
  2405. +
  2406.  
  2407. +
  2408.     /**
  2409. +
  2410.     * Menu.
  2411. +
  2412.     *
  2413. +
  2414.     * This function presents the user with a menu and reads the response
  2415. +
  2416.     *
  2417. +
  2418.     * @param array $choices has the following structure:
  2419. +
  2420.     *    array('1'=>'*Press 1 for this', // festival reads if prompt starts with *
  2421. +
  2422.     *            '2'=>'some-gsm-without-extension',
  2423. +
  2424.     *            '*'=>'*Press star for help');
  2425. +
  2426.     * @return mixed key pressed on sucess, -1 on failure
  2427. +
  2428.     */
  2429. +
  2430.     function menu($choices$timeout=2000)
  2431. +
  2432.     {
  2433. +
  2434.         $keys join(''array_keys($choices));
  2435. +
  2436.         $choice NULL;
  2437. +
  2438.         while(is_null($choice))
  2439. +
  2440.         {
  2441. +
  2442.           foreach($choices as $prompt)
  2443. +
  2444.           {
  2445. +
  2446.             if($prompt{0== '*')
  2447. +
  2448.                 $ret $this->text2wav(substr($prompt1)$keys);
  2449. +
  2450.             else
  2451. +
  2452.                 $ret $this->stream_file($prompt$keys);
  2453. +
  2454.  
  2455. +
  2456.             if($ret['code'!= AGIRES_OK || $ret['result'== -1)
  2457. +
  2458.             {
  2459. +
  2460.                 $choice = -1;
  2461. +
  2462.                 break;
  2463. +
  2464.             }
  2465. +
  2466.  
  2467. +
  2468.             if($ret['result'!= 0)
  2469. +
  2470.             {
  2471. +
  2472.                 $choice chr($ret['result']);
  2473. +
  2474.                 break;
  2475. +
  2476.             }
  2477. +
  2478.           }
  2479. +
  2480.  
  2481. +
  2482.           if(is_null($choice))
  2483. +
  2484.           {
  2485. +
  2486.             $ret $this->get_data('beep'$timeout1);
  2487. +
  2488.             if($ret['code'!= AGIRES_OK || $ret['result'== -1)
  2489. +
  2490.                 $choice = -1;
  2491. +
  2492.             elseif($ret['result'!= '' && strpos(' '.$keys$ret['result']))
  2493. +
  2494.                 $choice $ret['result'];
  2495. +
  2496.           }
  2497. +
  2498.         }
  2499. +
  2500.         return $choice;
  2501. +
  2502.     }
  2503. +
  2504.  
  2505. +
  2506.     /**
  2507. +
  2508.     * setContext - Set context, extension and priority.
  2509. +
  2510.     *
  2511. +
  2512.     * @param string $context 
  2513. +
  2514.     * @param string $extension 
  2515. +
  2516.     * @param string $priority 
  2517. +
  2518.     */
  2519. +
  2520.     function setContext($context$extension='s'$priority=1)
  2521. +
  2522.     {
  2523. +
  2524.         $this->set_context($context);
  2525. +
  2526.         $this->set_extension($extension);
  2527. +
  2528.         $this->set_priority($priority);
  2529. +
  2530.     }
  2531. +
  2532.  
  2533. +
  2534.     /**
  2535. +
  2536.     * Parse caller id.
  2537. +
  2538.     *
  2539. +
  2540.     * @example examples/dtmf.php Get DTMF tones from the user and say the digits
  2541. +
  2542.     * @example examples/input.php Get text input from the user and say it back
  2543. +
  2544.     *
  2545. +
  2546.     *  "name" <proto:user@server:port>
  2547. +
  2548.     *
  2549. +
  2550.     * @param string $callerid 
  2551. +
  2552.     * @return array('Name'=>$name, 'Number'=>$number)
  2553. +
  2554.     */
  2555. +
  2556.     function parse_callerid($callerid=NULL)
  2557. +
  2558.     {
  2559. +
  2560.         if(is_null($callerid))
  2561. +
  2562.           $callerid $this->request['agi_callerid'];
  2563. +
  2564.  
  2565. +
  2566.         $ret array('name'=>'''protocol'=>'''username'=>'''host'=>'''port'=>'');
  2567. +
  2568.         $callerid trim($callerid);
  2569. +
  2570.  
  2571. +
  2572.         if($callerid{0== '"' || $callerid{0== "'")
  2573. +
  2574.         {
  2575. +
  2576.           $d $callerid{0};
  2577. +
  2578.           $callerid explode($dsubstr($callerid1));
  2579. +
  2580.           $ret['name'array_shift($callerid);
  2581. +
  2582.           $callerid join($d$callerid);
  2583. +
  2584.         }
  2585. +
  2586.  
  2587. +
  2588.         $callerid explode('@'trim($callerid'<> '));
  2589. +
  2590.         $username  explode(':'array_shift($callerid));
  2591. +
  2592.         if(count($username== 1)
  2593. +
  2594.           $ret['username'$username[0];
  2595. +
  2596.         else
  2597. +
  2598.         {
  2599. +
  2600.           $ret['protocol'array_shift($username);
  2601. +
  2602.           $ret['username'join(':'$username);
  2603. +
  2604.         }
  2605. +
  2606.  
  2607. +
  2608.         $callerid join('@'$callerid);
  2609. +
  2610.         $host explode(':'$callerid);
  2611. +
  2612.         if(count($host== 1)
  2613. +
  2614.           $ret['host'=  $host[0];
  2615. +
  2616.         else
  2617. +
  2618.         {
  2619. +
  2620.           $ret['host'array_shift($host);
  2621. +
  2622.           $ret['port'join(':'$host);
  2623. +
  2624.         }
  2625. +
  2626.  
  2627. +
  2628.         return $ret;
  2629. +
  2630.     }
  2631. +
  2632.  
  2633. +
  2634.     /**
  2635. +
  2636.     * Use festival to read text.
  2637. +
  2638.     *
  2639. +
  2640.     * @example examples/dtmf.php Get DTMF tones from the user and say the digits
  2641. +
  2642.     * @example examples/input.php Get text input from the user and say it back
  2643. +
  2644.     * @example examples/ping.php Ping an IP address
  2645. +
  2646.     *
  2647. +
  2648.     * @link http://www.cstr.ed.ac.uk/projects/festival/
  2649. +
  2650.     * @param string $text 
  2651. +
  2652.     * @param string $escape_digits 
  2653. +
  2654.     * @param integer $frequency 
  2655. +
  2656.     * @return array, see evaluate for return information.
  2657. +
  2658.     */
  2659. +
  2660.     function text2wav($text$escape_digits=''$frequency=8000)
  2661. +
  2662.     {
  2663. +
  2664.         $text trim($text);
  2665. +
  2666.         if($text == ''return true;
  2667. +
  2668.  
  2669. +
  2670.         $hash md5($text);
  2671. +
  2672.         $fname $this->config['phpagi']['tempdir'DIRECTORY_SEPARATOR;
  2673. +
  2674.         $fname .= 'text2wav_' $hash;
  2675. +
  2676.  
  2677. +
  2678.         // create wave file
  2679. +
  2680.         if(!file_exists("$fname.wav"))
  2681. +
  2682.         {
  2683. +
  2684.           // write text file
  2685. +
  2686.           if(!file_exists("$fname.txt"))
  2687. +
  2688.           {
  2689. +
  2690.             $fp fopen("$fname.txt"'w');
  2691. +
  2692.             fputs($fp$text);
  2693. +
  2694.             fclose($fp);
  2695. +
  2696.           }
  2697. +
  2698.  
  2699. +
  2700.           shell_exec("{$this->config['festival']['text2wave']} -F $frequency -o $fname.wav $fname.txt");
  2701. +
  2702.         }
  2703. +
  2704.         else
  2705. +
  2706.         {
  2707. +
  2708.           touch("$fname.txt");
  2709. +
  2710.           touch("$fname.wav");
  2711. +
  2712.         }
  2713. +
  2714.  
  2715. +
  2716.         // stream it
  2717. +
  2718.         $ret $this->stream_file($fname$escape_digits);
  2719. +
  2720.  
  2721. +
  2722.         // clean up old files
  2723. +
  2724.         $delete time(2592000// 1 month
  2725. +
  2726.         foreach(glob($this->config['phpagi']['tempdir'DIRECTORY_SEPARATOR 'text2wav_*'as $file)
  2727. +
  2728.           if(filemtime($file$delete)
  2729. +
  2730.             unlink($file);
  2731. +
  2732.  
  2733. +
  2734.         return $ret;
  2735. +
  2736.     }
  2737. +
  2738.  
  2739. +
  2740.     /**
  2741. +
  2742.     * Use Cepstral Swift to read text.
  2743. +
  2744.     *
  2745. +
  2746.     * @link http://www.cepstral.com/
  2747. +
  2748.     * @param string $text 
  2749. +
  2750.     * @param string $escape_digits 
  2751. +
  2752.     * @param integer $frequency 
  2753. +
  2754.     * @return array, see evaluate for return information.
  2755. +
  2756.     */
  2757. +
  2758.     function swift($text$escape_digits=''$frequency=8000$voice=NULL)
  2759. +
  2760.     {
  2761. +
  2762.         if(!is_null($voice))
  2763. +
  2764.           $voice "-n $voice";
  2765. +
  2766.         elseif(isset($this->config['cepstral']['voice']))
  2767. +
  2768.           $voice "-n {$this->config['cepstral']['voice']}";
  2769. +
  2770.  
  2771. +
  2772.         $text trim($text);
  2773. +
  2774.         if($text == ''return true;
  2775. +
  2776.  
  2777. +
  2778.         $hash md5($text);
  2779. +
  2780.         $fname $this->config['phpagi']['tempdir'DIRECTORY_SEPARATOR;
  2781. +
  2782.         $fname .= 'swift_' $hash;
  2783. +
  2784.  
  2785. +
  2786.         // create wave file
  2787. +
  2788.         if(!file_exists("$fname.wav"))
  2789. +
  2790.         {
  2791. +
  2792.           // write text file
  2793. +
  2794.           if(!file_exists("$fname.txt"))
  2795. +
  2796.           {
  2797. +
  2798.             $fp fopen("$fname.txt"'w');
  2799. +
  2800.             fputs($fp$text);
  2801. +
  2802.             fclose($fp);
  2803. +
  2804.           }
  2805. +
  2806.  
  2807. +
  2808.           shell_exec("{$this->config['cepstral']['swift']} -p audio/channels=1,audio/sampling-rate=$frequency $voice -o $fname.wav -f $fname.txt");
  2809. +
  2810.         }
  2811. +
  2812.  
  2813. +
  2814.         // stream it
  2815. +
  2816.         $ret $this->stream_file($fname$escape_digits);
  2817. +
  2818.  
  2819. +
  2820.         // clean up old files
  2821. +
  2822.         $delete time(2592000// 1 month
  2823. +
  2824.         foreach(glob($this->config['phpagi']['tempdir'DIRECTORY_SEPARATOR 'swift_*'as $file)
  2825. +
  2826.           if(filemtime($file$delete)
  2827. +
  2828.             unlink($file);
  2829. +
  2830.  
  2831. +
  2832.         return $ret;
  2833. +
  2834.     }
  2835. +
  2836.  
  2837. +
  2838.     /**
  2839. +
  2840.     * Text Input.
  2841. +
  2842.     *
  2843. +
  2844.     * Based on ideas found at http://www.voip-info.org/wiki-Asterisk+cmd+DTMFToText
  2845. +
  2846.     *
  2847. +
  2848.     * Example:
  2849. +
  2850.     *                  UC   H     LC   i        ,     SP   h     o        w    SP   a    r        e     SP   y        o        u     ?
  2851. +
  2852.     *   $string = '*8'.'44*'.'*5'.'444*'.'00*'.'0*'.'44*'.'666*'.'9*'.'0*'.'2*'.'777*'.'33*'.'0*'.'999*'.'666*'.'88*'.'0000*';
  2853. +
  2854.     *
  2855. +
  2856.     * @link http://www.voip-info.org/wiki-Asterisk+cmd+DTMFToText
  2857. +
  2858.     * @example examples/input.php Get text input from the user and say it back
  2859. +
  2860.     *
  2861. +
  2862.     * @return string 
  2863. +
  2864.     */
  2865. +
  2866.     function text_input($mode='NUMERIC')
  2867. +
  2868.     {
  2869. +
  2870.         $alpha array'k0'=>' ''k00'=>',''k000'=>'.''k0000'=>'?''k00000'=>'0',
  2871. +
  2872.                             'k1'=>'!''k11'=>':''k111'=>';''k1111'=>'#''k11111'=>'1',
  2873. +
  2874.                             'k2'=>'A''k22'=>'B''k222'=>'C''k2222'=>'2',
  2875. +
  2876.                             'k3'=>'D''k33'=>'E''k333'=>'F''k3333'=>'3',
  2877. +
  2878.                             'k4'=>'G''k44'=>'H''k444'=>'I''k4444'=>'4',
  2879. +
  2880.                             'k5'=>'J''k55'=>'K''k555'=>'L''k5555'=>'5',
  2881. +
  2882.                             'k6'=>'M''k66'=>'N''k666'=>'O''k6666'=>'6',
  2883. +
  2884.                             'k7'=>'P''k77'=>'Q''k777'=>'R''k7777'=>'S''k77777'=>'7',
  2885. +
  2886.                             'k8'=>'T''k88'=>'U''k888'=>'V''k8888'=>'8',
  2887. +
  2888.                             'k9'=>'W''k99'=>'X''k999'=>'Y''k9999'=>'Z''k99999'=>'9');
  2889. +
  2890.         $symbol array('k0'=>'=',
  2891. +
  2892.                             'k1'=>'<''k11'=>'(''k111'=>'[''k1111'=>'{''k11111'=>'1',
  2893. +
  2894.                             'k2'=>'@''k22'=>'$''k222'=>'&''k2222'=>'%''k22222'=>'2',
  2895. +
  2896.                             'k3'=>'>''k33'=>')''k333'=>']''k3333'=>'}''k33333'=>'3',
  2897. +
  2898.                             'k4'=>'+''k44'=>'-''k444'=>'*''k4444'=>'/''k44444'=>'4',
  2899. +
  2900.                             'k5'=>"'"'k55'=>'`''k555'=>'5',
  2901. +
  2902.                             'k6'=>'"''k66'=>'6',
  2903. +
  2904.                             'k7'=>'^''k77'=>'7',
  2905. +
  2906.                             'k8'=>"\\",'k88'=>'|''k888'=>'8',
  2907. +
  2908.                             'k9'=>'_''k99'=>'~''k999'=>'9');
  2909. +
  2910.         $text '';
  2911. +
  2912.         do
  2913. +
  2914.         {
  2915. +
  2916.           $command false;
  2917. +
  2918.           $result $this->get_data('beep');
  2919. +
  2920.           foreach(explode('*'$result['result']as $code)
  2921. +
  2922.           {
  2923. +
  2924.             if($command)
  2925. +
  2926.             {
  2927. +
  2928.                 switch($code{0})
  2929. +
  2930.                 {
  2931. +
  2932.                   case '2'$text substr($text0strlen($text1)break// backspace
  2933. +
  2934.                   case '5'$mode 'LOWERCASE'break;
  2935. +
  2936.                   case '6'$mode 'NUMERIC'break;
  2937. +
  2938.                   case '7'$mode 'SYMBOL'break;
  2939. +
  2940.                   case '8'$mode 'UPPERCASE'break;
  2941. +
  2942.                   case '9'$text explode(' '$text)unset($text[count($text)-1])$text join(' '$text)break// backspace a word
  2943. +
  2944.                 }
  2945. +
  2946.                 $code substr($code1);
  2947. +
  2948.                 $command false;
  2949. +
  2950.             }
  2951. +
  2952.             if($code == '')
  2953. +
  2954.                 $command true;
  2955. +
  2956.             elseif($mode == 'NUMERIC')
  2957. +
  2958.                 $text .= $code;
  2959. +
  2960.             elseif($mode == 'UPPERCASE' && isset($alpha['k'.$code]))
  2961. +
  2962.                 $text .= $alpha['k'.$code];
  2963. +
  2964.             elseif($mode == 'LOWERCASE' && isset($alpha['k'.$code]))
  2965. +
  2966.                 $text .= strtolower($alpha['k'.$code]);
  2967. +
  2968.             elseif($mode == 'SYMBOL' && isset($symbol['k'.$code]))
  2969. +
  2970.                 $text .= $symbol['k'.$code];
  2971. +
  2972.           }
  2973. +
  2974.           $this->say_punctuation($text);
  2975. +
  2976.         while(substr($result['result']-2== '**');
  2977. +
  2978.         return $text;
  2979. +
  2980.     }
  2981. +
  2982.  
  2983. +
  2984.     /**
  2985. +
  2986.     * Say Puncutation in a string.
  2987. +
  2988.     *
  2989. +
  2990.     * @param string $text 
  2991. +
  2992.     * @param string $escape_digits 
  2993. +
  2994.     * @param integer $frequency 
  2995. +
  2996.     * @return array, see evaluate for return information.
  2997. +
  2998.     */
  2999. +
  3000.     function say_punctuation($text$escape_digits=''$frequency=8000)
  3001. +
  3002.     {
  3003. +
  3004.         $ret="";
  3005. +
  3006.         for($i 0$i strlen($text)$i++)
  3007. +
  3008.         {
  3009. +
  3010.           switch($text{$i})
  3011. +
  3012.           {
  3013. +
  3014.             case ' '$ret .= 'SPACE ';
  3015. +
  3016.             case ','$ret .= 'COMMA 'break;
  3017. +
  3018.             case '.'$ret .= 'PERIOD 'break;
  3019. +
  3020.             case '?'$ret .= 'QUESTION MARK 'break;
  3021. +
  3022.             case '!'$ret .= 'EXPLANATION POINT 'break;
  3023. +
  3024.             case ':'$ret .= 'COLON 'break;
  3025. +
  3026.             case ';'$ret .= 'SEMICOLON 'break;
  3027. +
  3028.             case '#'$ret .= 'POUND 'break;
  3029. +
  3030.             case '='$ret .= 'EQUALS 'break;
  3031. +
  3032.             case '<'$ret .= 'LESS THAN 'break;
  3033. +
  3034.             case '('$ret .= 'LEFT PARENTHESIS 'break;
  3035. +
  3036.             case '['$ret .= 'LEFT BRACKET 'break;
  3037. +
  3038.             case '{'$ret .= 'LEFT BRACE 'break;
  3039. +
  3040.             case '@'$ret .= 'AT 'break;
  3041. +
  3042.             case '$'$ret .= 'DOLLAR SIGN 'break;
  3043. +
  3044.             case '&'$ret .= 'AMPERSAND 'break;
  3045. +
  3046.             case '%'$ret .= 'PERCENT 'break;
  3047. +
  3048.             case '>'$ret .= 'GREATER THAN 'break;
  3049. +
  3050.             case ')'$ret .= 'RIGHT PARENTHESIS 'break;
  3051. +
  3052.             case ']'$ret .= 'RIGHT BRACKET 'break;
  3053. +
  3054.             case '}'$ret .= 'RIGHT BRACE 'break;
  3055. +
  3056.             case '+'$ret .= 'PLUS 'break;
  3057. +
  3058.             case '-'$ret .= 'MINUS 'break;
  3059. +
  3060.             case '*'$ret .= 'ASTERISK 'break;
  3061. +
  3062.             case '/'$ret .= 'SLASH 'break;
  3063. +
  3064.             case "'"$ret .= 'SINGLE QUOTE 'break;
  3065. +
  3066.             case '`'$ret .= 'BACK TICK 'break;
  3067. +
  3068.             case '"'$ret .= 'QUOTE 'break;
  3069. +
  3070.             case '^'$ret .= 'CAROT 'break;
  3071. +
  3072.             case "\\"$ret .= 'BACK SLASH 'break;
  3073. +
  3074.             case '|'$ret .= 'BAR 'break;
  3075. +
  3076.             case '_'$ret .= 'UNDERSCORE 'break;
  3077. +
  3078.             case '~'$ret .= 'TILDE 'break;
  3079. +
  3080.             default$ret .= $text{$i' 'break;
  3081. +
  3082.           }
  3083. +
  3084.         }
  3085. +
  3086.         return $this->text2wav($ret$escape_digits$frequency);
  3087. +
  3088.     }
  3089. +
  3090.  
  3091. +
  3092.     /**
  3093. +
  3094.     * Create a new AGI_AsteriskManager.
  3095. +
  3096.     */
  3097. +
  3098.     function &new_AsteriskManager()
  3099. +
  3100.     {
  3101. +
  3102.         $this->asm new AGI_AsteriskManager(NULL$this->config);
  3103. +
  3104.         $this->asm->pagi =$this;
  3105. +
  3106.         $this->config =$this->asm->config;
  3107. +
  3108.         return $this->asm;
  3109. +
  3110.     }
  3111. +
  3112.  
  3113. +
  3114.  
  3115. +
  3116.     // *********************************************************************************************************
  3117. +
  3118.     // **                             PRIVATE                                                                                             **
  3119. +
  3120.     // *********************************************************************************************************
  3121. +
  3122.  
  3123. +
  3124.  
  3125. +
  3126.     /**
  3127. +
  3128.     * Evaluate an AGI command.
  3129. +
  3130.     *
  3131. +
  3132.     * @access private
  3133. +
  3134.     * @param string $command 
  3135. +
  3136.     * @return array ('code'=>$code, 'result'=>$result, 'data'=>$data)
  3137. +
  3138.     */
  3139. +
  3140.     function evaluate($command)
  3141. +
  3142.     {
  3143. +
  3144.         $broken array('code'=>500'result'=>-1'data'=>'');
  3145. +
  3146.  
  3147. +
  3148.         // write command
  3149. +
  3150.         if(!@fwrite($this->outtrim($command"\n")) return $broken;
  3151. +
  3152.         fflush($this->out);
  3153. +
  3154.  
  3155. +
  3156.         // Read result.  Occasionally, a command return a string followed by an extra new line.
  3157. +
  3158.         // When this happens, our script will ignore the new line, but it will still be in the
  3159. +
  3160.         // buffer.  So, if we get a blank line, it is probably the result of a previous
  3161. +
  3162.         // command.  We read until we get a valid result or asterisk hangs up.  One offending
  3163. +
  3164.         // command is SEND TEXT.
  3165. +
  3166.         $count 0;
  3167. +
  3168.         do
  3169. +
  3170.         {
  3171. +
  3172.           $str trim(fgets($this->in4096));
  3173. +
  3174.         while($str == '' && $count++ < 5);
  3175. +
  3176.  
  3177. +
  3178.         if($count >= 5)
  3179. +
  3180.         {
  3181. +
  3182.     //          $this->conlog("evaluate error on read for $command");
  3183. +
  3184.           return $broken;
  3185. +
  3186.         }
  3187. +
  3188.  
  3189. +
  3190.         // parse result
  3191. +
  3192.         $ret['code'substr($str03);
  3193. +
  3194.         $str trim(substr($str3));
  3195. +
  3196.  
  3197. +
  3198.         if($str{0== '-'// we have a multiline response!
  3199. +
  3200.         {
  3201. +
  3202.           $count 0;
  3203. +
  3204.           $str substr($str1"\n";
  3205. +
  3206.           $line fgets($this->in4096);
  3207. +
  3208.           while(substr($line03!= $ret['code'&& $count 5)
  3209. +
  3210.           {
  3211. +
  3212.             $str .= $line;
  3213. +
  3214.             $line fgets($this->in4096);
  3215. +
  3216.             $count (trim($line== ''$count 0;
  3217. +
  3218.           }
  3219. +
  3220.           if($count >= 5)
  3221. +
  3222.           {
  3223. +
  3224.     //            $this->conlog("evaluate error on multiline read for $command");
  3225. +
  3226.             return $broken;
  3227. +
  3228.           }
  3229. +
  3230.         }
  3231. +
  3232.  
  3233. +
  3234.         $ret['result'NULL;
  3235. +
  3236.         $ret['data''';
  3237. +
  3238.         if($ret['code'!= AGIRES_OK// some sort of error
  3239. +
  3240.         {
  3241. +
  3242.           $ret['data'$str;
  3243. +
  3244.           $this->conlog(print_r($rettrue));
  3245. +
  3246.         }
  3247. +
  3248.         else // normal AGIRES_OK response
  3249. +
  3250.         {
  3251. +
  3252.           $parse explode(' 'trim($str));
  3253. +
  3254.           $in_token false;
  3255. +
  3256.           foreach($parse as $token)
  3257. +
  3258.           {
  3259. +
  3260.             if($in_token// we previously hit a token starting with ')' but not ending in ')'
  3261. +
  3262.             {
  3263. +
  3264.                 $ret['data'.= ' ' trim($token'() ');
  3265. +
  3266.                 if($token{strlen($token)-1== ')'$in_token false;
  3267. +
  3268.             }
  3269. +
  3270.             elseif($token{0== '(')
  3271. +
  3272.             {
  3273. +
  3274.                 if($token{strlen($token)-1!= ')'$in_token true;
  3275. +
  3276.                 $ret['data'.= ' ' trim($token'() ');
  3277. +
  3278.             }
  3279. +
  3280.             elseif(strpos($token'='))
  3281. +
  3282.             {
  3283. +
  3284.                 $token explode('='$token);
  3285. +
  3286.                 $ret[$token[0]] $token[1];
  3287. +
  3288.             }
  3289. +
  3290.             elseif($token != '')
  3291. +
  3292.                 $ret['data'.= ' ' $token;
  3293. +
  3294.           }
  3295. +
  3296.           $ret['data'trim($ret['data']);
  3297. +
  3298.         }
  3299. +
  3300.  
  3301. +
  3302.         // log some errors
  3303. +
  3304.         if($ret['result'0)
  3305. +
  3306.           $this->conlog("$command returned {$ret['result']}");
  3307. +
  3308.  
  3309. +
  3310.         return $ret;
  3311. +
  3312.     }
  3313. +
  3314.  
  3315. +
  3316.     /**
  3317. +
  3318.     * Log to console if debug mode.
  3319. +
  3320.     *
  3321. +
  3322.     * @example examples/ping.php Ping an IP address
  3323. +
  3324.     *
  3325. +
  3326.     * @param string $str 
  3327. +
  3328.     * @param integer $vbl verbose level
  3329. +
  3330.     */
  3331. +
  3332.     function conlog($str$vbl=1)
  3333. +
  3334.     {
  3335. +
  3336.         static $busy false;
  3337. +
  3338.  
  3339. +
  3340.         if($this->config['phpagi']['debug'!= false)
  3341. +
  3342.         {
  3343. +
  3344.           if(!$busy// no conlogs inside conlog!!!
  3345. +
  3346.           {
  3347. +
  3348.             $busy true;
  3349. +
  3350.             $this->verbose($str$vbl);
  3351. +
  3352.             $busy false;
  3353. +
  3354.           }
  3355. +
  3356.         }
  3357. +
  3358.     }
  3359. +
  3360.  
  3361. +
  3362.     /**
  3363. +
  3364.     * Find an execuable in the path.
  3365. +
  3366.     *
  3367. +
  3368.     * @access private
  3369. +
  3370.     * @param string $cmd command to find
  3371. +
  3372.     * @param string $checkpath path to check
  3373. +
  3374.     * @return string the path to the command
  3375. +
  3376.     */
  3377. +
  3378.     function which($cmd$checkpath=NULL)
  3379. +
  3380.     {
  3381. +
  3382.         global $_ENV;
  3383. +
  3384.         $chpath is_null($checkpath$_ENV['PATH'$checkpath;
  3385. +
  3386.  
  3387. +
  3388.         foreach(explode(':'$chpathas $path)
  3389. +
  3390.           if(is_executable("$path/$cmd"))
  3391. +
  3392.             return "$path/$cmd";
  3393. +
  3394.  
  3395. +
  3396.         if(is_null($checkpath))
  3397. +
  3398.           return $this->which($cmd'/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:'.
  3399. +
  3400.                                             '/usr/X11R6/bin:/usr/local/apache/bin:/usr/local/mysql/bin');
  3401. +
  3402.         return false;
  3403. +
  3404.     }
  3405. +
  3406.  
  3407. +
  3408.     /**
  3409. +
  3410.     * Make a folder recursively.
  3411. +
  3412.     *
  3413. +
  3414.     * @access private
  3415. +
  3416.     * @param string $folder 
  3417. +
  3418.     * @param integer $perms 
  3419. +
  3420.     * @return boolean 
  3421. +
  3422.     */
  3423. +
  3424.     function make_folder($folder$perms=0755)
  3425. +
  3426.     {
  3427. +
  3428.         $f explode(DIRECTORY_SEPARATOR$folder);
  3429. +
  3430.         $base '';
  3431. +
  3432.         for($i 0$i count($f)$i++)
  3433. +
  3434.         {
  3435. +
  3436.           $base .= $f[$i];
  3437. +
  3438.           if($f[$i!= '' && !file_exists($base)) {
  3439. +
  3440.             if(mkdir($base$perms)==FALSE){
  3441. +
  3442.               return(FALSE);
  3443. +
  3444.             }
  3445. +
  3446.           }
  3447. +
  3448.           $base .= DIRECTORY_SEPARATOR;
  3449. +
  3450.         }
  3451. +
  3452.         return(TRUE);
  3453. +
  3454.     }    
  3455. +
  3456.  
  3457. +
  3458. }
  3459. +
  3460.  
  3461. +
  3462.  
  3463. +
  3464. /**
  3465. +
  3466.  * error handler for phpagi.
  3467. +
  3468.  *
  3469. +
  3470.  * @param integer $level PHP error level
  3471. +
  3472.  * @param string $message error message
  3473. +
  3474.  * @param string $file path to file
  3475. +
  3476.  * @param integer $line line number of error
  3477. +
  3478.  * @param array $context variables in the current scope
  3479. +
  3480.  */
  3481. +
  3482.   function phpagi_error_handler($level$message$file$line$context)
  3483. +
  3484.   {
  3485. +
  3486.     if(ini_get('error_reporting'== 0return// this happens with an @
  3487. +
  3488.  
  3489. +
  3490.     @syslog(LOG_WARNING$file '[' $line ']: ' $message);
  3491. +
  3492.  
  3493. +
  3494.     global $phpagi_error_handler_email;
  3495. +
  3496.     if(function_exists('mail'&& !is_null($phpagi_error_handler_email)) // generate email debugging information
  3497. +
  3498.     {
  3499. +
  3500.         // decode error level
  3501. +
  3502.         switch($level)
  3503. +
  3504.         {
  3505. +
  3506.           case E_WARNING:
  3507. +
  3508.           case E_USER_WARNING:
  3509. +
  3510.             $level "Warning";
  3511. +
  3512.             break;
  3513. +
  3514.           case E_NOTICE:
  3515. +
  3516.           case E_USER_NOTICE:
  3517. +
  3518.             $level "Notice";
  3519. +
  3520.             break;
  3521. +
  3522.           case E_USER_ERROR:
  3523. +
  3524.             $level "Error";
  3525. +
  3526.             break;
  3527. +
  3528.         }
  3529. +
  3530.  
  3531. +
  3532.         // build message
  3533. +
  3534.         $basefile basename($file);
  3535. +
  3536.         $subject "$basefile/$line/$level$message";
  3537. +
  3538.         $message "$level$message in $file on line $line\n\n";
  3539. +
  3540.  
  3541. +
  3542.         if(function_exists('mysql_errno'&& strpos(' '.strtolower($message)'mysql'))
  3543. +
  3544.           $message .= 'MySQL error ' mysql_errno(": " mysql_error("\n\n";
  3545. +
  3546.  
  3547. +
  3548.         // figure out who we are
  3549. +
  3550.         if(function_exists('socket_create'))
  3551. +
  3552.         {
  3553. +
  3554.           $addr NULL;
  3555. +
  3556.           $port 80;
  3557. +
  3558.           $socket @socket_create(AF_INETSOCK_DGRAMSOL_UDP);
  3559. +
  3560.           @socket_connect($socket'64.0.0.0'$port);
  3561. +
  3562.           @socket_getsockname($socket$addr$port);
  3563. +
  3564.           @socket_close($socket);
  3565. +
  3566.           $message .= "\n\nIP Address: $addr\n";
  3567. +
  3568.         }
  3569. +
  3570.  
  3571. +
  3572.         // include variables
  3573. +
  3574.         $message .= "\n\nContext:\n" print_r($contexttrue);
  3575. +
  3576.         $message .= "\n\nGLOBALS:\n" print_r($GLOBALStrue);
  3577. +
  3578.         $message .= "\n\nBacktrace:\n" print_r(debug_backtrace()true);
  3579. +
  3580.  
  3581. +
  3582.         // include code fragment
  3583. +
  3584.         if(file_exists($file))
  3585. +
  3586.         {
  3587. +
  3588.           $message .= "\n\n$file:\n";
  3589. +
  3590.           $code @file($file);
  3591. +
  3592.           for($i max(0$line 10)$i min($line 10count($code))$i++)
  3593. +
  3594.             $message .= ($i 1)."\t$code[$i]";
  3595. +
  3596.         }
  3597. +
  3598.  
  3599. +
  3600.         // make sure message is fully readable (convert unprintable chars to hex representation)
  3601. +
  3602.         $ret '';
  3603. +
  3604.         for($i 0$i strlen($message)$i++)
  3605. +
  3606.         {
  3607. +
  3608.           $c ord($message{$i});
  3609. +
  3610.           if($c == 10 || $c == 13 || $c == 9)
  3611. +
  3612.             $ret .= $message{$i};
  3613. +
  3614.           elseif($c 16)
  3615. +
  3616.             $ret .= '\x0' dechex($c);
  3617. +
  3618.           elseif($c 32 || $c 127)
  3619. +
  3620.             $ret .= '\x' dechex($c);
  3621. +
  3622.           else
  3623. +
  3624.             $ret .= $message{$i};
  3625. +
  3626.         }
  3627. +
  3628.         $message $ret;
  3629. +
  3630.  
  3631. +
  3632.         // send the mail if less than 5 errors
  3633. +
  3634.         static $mailcount 0;
  3635. +
  3636.         if($mailcount 5)
  3637. +
  3638.           @mail($phpagi_error_handler_email$subject$message);
  3639. +
  3640.         $mailcount++;
  3641. +
  3642.     }
  3643. +
  3644.   }
  3645. +
  3646.  
  3647. +
  3648.   $phpagi_error_handler_email NULL;
  3649. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:21:59 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/__filesource/fsource_phpAGI__phpagi_1.php.html b/api-docs/__filesource/fsource_phpAGI__phpagi_1.php.html new file mode 100644 index 0000000..577ee2f --- /dev/null +++ b/api-docs/__filesource/fsource_phpAGI__phpagi_1.php.html @@ -0,0 +1,676 @@ + + + + + + File Source for phpagi_1.php + + + + +

Source for file phpagi_1.php

+

Documentation is available at phpagi_1.php

+
+
  1. <?php
  2. +
  3. /**
  4. +
  5.   * phpagi-asmanager.php : PHP Asterisk Manager functions
  6. +
  7.   * Website: http://phpagi.sourceforge.net
  8. +
  9.   *
  10. +
  11.   * $Id$
  12. +
  13.   *
  14. +
  15.   * Copyright (c) 2004, 2005 Matthew Asham <matthewa@bcwireless.net>, David Eder <david@eder.us>
  16. +
  17.   * All Rights Reserved.
  18. +
  19.   *
  20. +
  21.   * This software is released under the terms of the GNU Lesser General Public License v2.1
  22. +
  23.   *  A copy of which is available from http://www.gnu.org/copyleft/lesser.html
  24. +
  25.   *
  26. +
  27.   * We would be happy to list your phpagi based application on the phpagi
  28. +
  29.   * website.  Drop me an Email if you'd like us to list your program.
  30. +
  31.   *
  32. +
  33.   * @package phpAGI
  34. +
  35.   * @version 2.0
  36. +
  37.   */
  38. +
  39.  
  40. +
  41.  
  42. +
  43.  /**
  44. +
  45.   * Written for PHP 4.3.4, should work with older PHP 4.x versions.
  46. +
  47.   * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/
  48. +
  49.   * Gracias. :)
  50. +
  51.   *
  52. +
  53.   */
  54. +
  55.  
  56. +
  57.   if(!class_exists('AGI'))
  58. +
  59.   {
  60. +
  61.     require_once(dirname(__FILE__DIRECTORY_SEPARATOR 'phpagi.php');
  62. +
  63.   }
  64. +
  65.  
  66. +
  67.  /**
  68. +
  69.   * Asterisk Manager class
  70. +
  71.   *
  72. +
  73.   * @link http://www.voip-info.org/wiki-Asterisk+config+manager.conf
  74. +
  75.   * @link http://www.voip-info.org/wiki-Asterisk+manager+API
  76. +
  77.   * @example examples/sip_show_peer.php Get information about a sip peer
  78. +
  79.   * @package phpAGI
  80. +
  81.   */
  82. +
  83.   class AGI_1 extends AGI
  84. +
  85.   {
  86. +
  87.    /**
  88. +
  89.     * Response structure
  90. +
  91.     *
  92. +
  93.     * array('code'=>$code, 'result'=>$result, 'data'=>$data)
  94. +
  95.     *
  96. +
  97.     * @var array 
  98. +
  99.     * @access public
  100. +
  101.     */
  102. +
  103.     var $response;
  104. +
  105.  
  106. +
  107.    /**
  108. +
  109.     * Constructor
  110. +
  111.     *
  112. +
  113.     * @param string $config is the name of the config file to parse
  114. +
  115.     * @param array $optconfig is an array of configuration vars and vals, stuffed into $this->config['phpagi']
  116. +
  117.     */
  118. +
  119.     function AGI_1($config=false$optconfig=false)
  120. +
  121.     {
  122. +
  123.       if(!$config$config NULL;
  124. +
  125.       if(!$optconfig$optconfig array();
  126. +
  127.       parent::AGI($config$optconfig);
  128. +
  129.     }
  130. +
  131.  
  132. +
  133.    /**
  134. +
  135.     * Evaluate an AGI command
  136. +
  137.     *
  138. +
  139.     * @access private
  140. +
  141.     * @param string $command 
  142. +
  143.     * @return array ('code'=>$code, 'result'=>$result, 'data'=>$data)
  144. +
  145.     */
  146. +
  147.     function evalutate($command)
  148. +
  149.     {
  150. +
  151.       $this->response = parent::evalute($command);
  152. +
  153.       return $this->response;
  154. +
  155.     }
  156. +
  157.  
  158. +
  159.    /**
  160. +
  161.     * Execute an AGI command
  162. +
  163.     *
  164. +
  165.     * @access private
  166. +
  167.     * @param string $str 
  168. +
  169.     * @return array ('code'=>$code, 'result'=>$result, 'data'=>$data)
  170. +
  171.     */
  172. +
  173.     function agi_exec($str)
  174. +
  175.     {
  176. +
  177.       return $this->evaluate($str);
  178. +
  179.     }
  180. +
  181.  
  182. +
  183.    /**
  184. +
  185.     * Check for error in result structure
  186. +
  187.     *
  188. +
  189.     * @param array $retarr 
  190. +
  191.     * @return boolean true on error
  192. +
  193.     */
  194. +
  195.     function agi_is_error($retarr)
  196. +
  197.     {
  198. +
  199.       // Returns TRUE if the command returned an error.
  200. +
  201.  
  202. +
  203.       if($retarr['code'!= AGIRES_OK)
  204. +
  205.       {
  206. +
  207.         $this->conlog("DEBUG:  Bad command?  Returned code is {$retarr['code']} result={$retarr['result']}");
  208. +
  209.         return true;
  210. +
  211.       }
  212. +
  213.  
  214. +
  215.       if(!isset($retarr['result']))
  216. +
  217.       {
  218. +
  219.         $this->conlog("DEBUG:  No 'result' value returned from asterisk!  Eww!");
  220. +
  221.         return true;
  222. +
  223.       }
  224. +
  225.  
  226. +
  227.       if($retarr['result'== -1)
  228. +
  229.         return true;
  230. +
  231.  
  232. +
  233.       return false;
  234. +
  235.     }
  236. +
  237.  
  238. +
  239.    /**
  240. +
  241.     * Read the result from Asterisk
  242. +
  243.     *
  244. +
  245.     * @return array 
  246. +
  247.     */
  248. +
  249.     function agi_readresult()
  250. +
  251.     {
  252. +
  253.       return $this->response;
  254. +
  255.     }
  256. +
  257.  
  258. +
  259.    /**
  260. +
  261.     * Sends $message to the Asterisk console via the 'verbose' message system.
  262. +
  263.     *
  264. +
  265.     * If the Asterisk verbosity level is $vbl or greater, send $str to the console.
  266. +
  267.     *
  268. +
  269.     * The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later
  270. +
  271.     * using the console 'set verbose' command. Messages are displayed on the console if their verbose level is less than or equal
  272. +
  273.     * to desired verbosity set by the user. More important messages should have a low verbose level; less important messages
  274. +
  275.     * should have a high verbose level.
  276. +
  277.     *
  278. +
  279.     * @link http://www.voip-info.org/wiki-verbose
  280. +
  281.     * @param string $str 
  282. +
  283.     * @param integer $vbl from 1 to 4
  284. +
  285.     */
  286. +
  287.     function agi_verbose($str$vbl=1)
  288. +
  289.     {
  290. +
  291.       $this->verbose($str$vbl);
  292. +
  293.     }
  294. +
  295.  
  296. +
  297.    /**
  298. +
  299.     * Get the response code from the last command
  300. +
  301.     *
  302. +
  303.     * @return integer 
  304. +
  305.     */
  306. +
  307.     function agi_response_code()
  308. +
  309.     {
  310. +
  311.       return $this->response['code'];
  312. +
  313.     }
  314. +
  315.  
  316. +
  317.    /**
  318. +
  319.     * Get the result code from the last command
  320. +
  321.     *
  322. +
  323.     * @return integer 
  324. +
  325.     */
  326. +
  327.     function agi_response_result()
  328. +
  329.     {
  330. +
  331.       $this->conlog("result is {$this->response['result']}");
  332. +
  333.       return $this->response['result'];
  334. +
  335.     }
  336. +
  337.  
  338. +
  339.    /**
  340. +
  341.     * Get the response data from the last command
  342. +
  343.     *
  344. +
  345.     * @return string 
  346. +
  347.     */
  348. +
  349.     function agi_response_data()
  350. +
  351.     {
  352. +
  353.       return $this->response['data'];
  354. +
  355.     }
  356. +
  357.  
  358. +
  359.    /**
  360. +
  361.     * Get the response variable from the last command
  362. +
  363.     *
  364. +
  365.     * @param string $var 
  366. +
  367.     * @return mixed 
  368. +
  369.     */
  370. +
  371.     function agi_response_var($var)
  372. +
  373.     {
  374. +
  375.       if(!isset($this->response[$var]))
  376. +
  377.         return false;
  378. +
  379.       return $this->response[$var];
  380. +
  381.     }
  382. +
  383.  
  384. +
  385.    /**
  386. +
  387.     * Check for error in response
  388. +
  389.     *
  390. +
  391.     * @return boolean true on error
  392. +
  393.     */
  394. +
  395.     function agi_response_is_error()
  396. +
  397.     {
  398. +
  399.       return $this->agi_is_error($this->response);
  400. +
  401.     }
  402. +
  403.  
  404. +
  405.    /**
  406. +
  407.     * Log to console if debug mode
  408. +
  409.     *
  410. +
  411.     * @param array $arr to print
  412. +
  413.     * @param string $label 
  414. +
  415.     * @param integer $vbl verbose level
  416. +
  417.     */
  418. +
  419.     function con_print_r($arr$label=''$lvl=0)
  420. +
  421.     {
  422. +
  423.       if($lvl == && $label != '')
  424. +
  425.         $this->conlog("debug: $label");
  426. +
  427.  
  428. +
  429.       $this->conlog(print_r($arrtrue)$lvl);
  430. +
  431.     }
  432. +
  433.  
  434. +
  435.  
  436. +
  437.    /**
  438. +
  439.     * Plays the given file and receives DTMF data.
  440. +
  441.     *
  442. +
  443.     * This is similar to STREAM FILE, but this command can accept and return many DTMF digits,
  444. +
  445.     * while STREAM FILE returns immediately after the first DTMF digit is detected.
  446. +
  447.     *
  448. +
  449.     * Asterisk looks for the file to play in /var/lib/asterisk/sounds by default.
  450. +
  451.     *
  452. +
  453.     * If the user doesn't press any keys when the message plays, there is $timeout milliseconds
  454. +
  455.     * of silence then the command ends.
  456. +
  457.     *
  458. +
  459.     * The user has the opportunity to press a key at any time during the message or the
  460. +
  461.     * post-message silence. If the user presses a key while the message is playing, the
  462. +
  463.     * message stops playing. When the first key is pressed a timer starts counting for
  464. +
  465.     * $timeout milliseconds. Every time the user presses another key the timer is restarted.
  466. +
  467.     * The command ends when the counter goes to zero or the maximum number of digits is entered,
  468. +
  469.     * whichever happens first.
  470. +
  471.     *
  472. +
  473.     * Pressing the # key has the same effect as the timer running out: the command ends and
  474. +
  475.     * any previously keyed digits are returned. A side effect of this is that there is no
  476. +
  477.     * way to read a # key using this command.
  478. +
  479.     *
  480. +
  481.     * @link http://www.voip-info.org/wiki-get+data
  482. +
  483.     * @param integer $len number of digits to read
  484. +
  485.     * @param integer $timeout milliseconds
  486. +
  487.     * @param string $terminator character on which to quit
  488. +
  489.     * @param string $prompt file to play. Do not include file extension.
  490. +
  491.     * @return array of characters
  492. +
  493.     */
  494. +
  495.     function agi_getdtmf($len$timeout$terminator=false$prompt=false)
  496. +
  497.     {
  498. +
  499.       if($prompt)
  500. +
  501.       {
  502. +
  503.         if(!is_array($prompt)) $prompt array($prompt);
  504. +
  505.  
  506. +
  507.         foreach($prompt as $p)
  508. +
  509.         {
  510. +
  511.           if($p[0== '$')
  512. +
  513.           {
  514. +
  515.             $this->text2wav(substr($p1));
  516. +
  517.           }
  518. +
  519.           else
  520. +
  521.           {
  522. +
  523.             $this->stream_file($p'#');
  524. +
  525.           }                
  526. +
  527.         }
  528. +
  529.       }
  530. +
  531.  
  532. +
  533.       $ret array();
  534. +
  535.       for($i 0$i $len$i++)
  536. +
  537.       {
  538. +
  539.         $res $this->wait_for_digit($timeout);
  540. +
  541.         $this->con_print_r($res);
  542. +
  543.         if($this->agi_response_is_error())
  544. +
  545.         {
  546. +
  547.           $this->conlog('error?');
  548. +
  549.       return false;
  550. +
  551.         }
  552. +
  553.         $ch chr($res['result']);
  554. +
  555.         $this->conlog("got $ch");
  556. +
  557.         if($terminator && $ch == $terminator)
  558. +
  559.       return $ret;
  560. +
  561.  
  562. +
  563.         $ret[$i$ch;
  564. +
  565.       }
  566. +
  567.       return($ret);
  568. +
  569.     }
  570. +
  571.  
  572. +
  573.    /**
  574. +
  575.     * Read $len characters as DTMF codes
  576. +
  577.     *
  578. +
  579.     * @param integer $len 
  580. +
  581.     * @return string 
  582. +
  583.     */
  584. +
  585.     function agi_dtmf2text($len)
  586. +
  587.     {
  588. +
  589.       $numbers=array('1'=>'1''2'=>'2abc''3'=>'3def''4'=>'4ghi''5'=>'5jkl''6'=>'6mno',
  590. +
  591.                      '7'=>'7pqrs''8'=>'8tuv''9'=>'9wxyz''0'=>'0');
  592. +
  593.  
  594. +
  595.       $last false;
  596. +
  597.       $i $times 0;
  598. +
  599.       $abort 0;
  600. +
  601.  
  602. +
  603.       $char '';
  604. +
  605.       do
  606. +
  607.       {
  608. +
  609.         $res $this->agi_getdtmf(14000);
  610. +
  611.         $res $res[0];
  612. +
  613.  
  614. +
  615.         if($res == falsebreak;
  616. +
  617.  
  618. +
  619.         if($last == false)
  620. +
  621.           $last $res;
  622. +
  623.         elseif($last != $res || $res == false)
  624. +
  625.         {
  626. +
  627.           $ret[$i$char;
  628. +
  629.           $this->conlog("Character $i is $char");
  630. +
  631. //          $this->text2wav($char);                    
  632. +
  633.           $times 0;
  634. +
  635.           $i++;
  636. +
  637.         }
  638. +
  639.  
  640. +
  641.         $char $numbers[$res][$times++];
  642. +
  643.         $this->conlog("Number $res is '$char'");
  644. +
  645.  
  646. +
  647.         if(strlen($numbers[$res]== $times$times 0;
  648. +
  649.  
  650. +
  651.         $last $res;
  652. +
  653.       while($i $len && !$abort);
  654. +
  655.  
  656. +
  657.       $str '';
  658. +
  659.       foreach($ret as $k$str .= $k ' ';
  660. +
  661.  
  662. +
  663.       $this->text2wav($str);
  664. +
  665.       return($str);
  666. +
  667.     }    
  668. +
  669.  
  670. +
  671.    /**
  672. +
  673.     * Alias of PHP join function
  674. +
  675.     *
  676. +
  677.     * @param array $arr 
  678. +
  679.     * @return string 
  680. +
  681.     */
  682. +
  683.     function arr2str($arr)
  684. +
  685.     {
  686. +
  687.       return trim(join(' '$arr));
  688. +
  689.     }
  690. +
  691.  
  692. +
  693.    /**
  694. +
  695.     * Retrieves an entry in the Asterisk database for a given family and key.
  696. +
  697.     *
  698. +
  699.     * @link http://www.voip-info.org/wiki-database+get
  700. +
  701.     * @param string $family 
  702. +
  703.     * @param string $key 
  704. +
  705.     * @return string 
  706. +
  707.     */
  708. +
  709.     function db_get($family$key)
  710. +
  711.     {
  712. +
  713.       $res $this->database_get($family$key);
  714. +
  715.       if($res['code'!= AGIRES_OK || $res['result'== 0return false;
  716. +
  717.       return $res['data'];
  718. +
  719.     }
  720. +
  721.  
  722. +
  723.    /**
  724. +
  725.     * Adds or updates an entry in the Asterisk database for a given family, key, and value.
  726. +
  727.     *
  728. +
  729.     * @param string $family 
  730. +
  731.     * @param string $key 
  732. +
  733.     * @param string $val 
  734. +
  735.     * @return integer result code
  736. +
  737.     */
  738. +
  739.     function db_put($family$key$val)
  740. +
  741.     {
  742. +
  743.       $res $this->database_put($family$key$val);
  744. +
  745.       return $res['code'];
  746. +
  747.     }
  748. +
  749.  
  750. +
  751.    /**
  752. +
  753.     * Deletes an entry in the Asterisk database for a given family and key.
  754. +
  755.     *
  756. +
  757.     * @link http://www.voip-info.org/wiki-database+del
  758. +
  759.     * @param string $family 
  760. +
  761.     * @param string $key 
  762. +
  763.     * @return integer result code
  764. +
  765.     */
  766. +
  767.     function db_del($family$key)
  768. +
  769.     {
  770. +
  771.       $res $this->database_del($family$key);
  772. +
  773.       return $res['code'];
  774. +
  775.     }
  776. +
  777.  
  778. +
  779.    /**
  780. +
  781.     * Fetch the value of a variable.
  782. +
  783.     *
  784. +
  785.     * Does not work with global variables. Does not work with some variables that are generated by modules.
  786. +
  787.     *
  788. +
  789.     * @link http://www.voip-info.org/wiki-get+variable
  790. +
  791.     * @link http://www.voip-info.org/wiki-Asterisk+variables
  792. +
  793.     * @param string $var variable name
  794. +
  795.     * @return string 
  796. +
  797.     */
  798. +
  799.     function get_var($var)
  800. +
  801.     {
  802. +
  803.       $res $this->get_variable($var);
  804. +
  805.       if($res['code'!= AGIRES_OK || $res['result'== 0return false;
  806. +
  807.       return $res['data'];
  808. +
  809.     }
  810. +
  811.  
  812. +
  813.    /**
  814. +
  815.     * Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>}
  816. +
  817.     * in the dialplan.
  818. +
  819.     *
  820. +
  821.     * These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary.
  822. +
  823.     * Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted
  824. +
  825.     * and any variables in that channel are deleted as well.
  826. +
  827.     *
  828. +
  829.     * @link http://www.voip-info.org/wiki-set+variable
  830. +
  831.     * @param string $var is case sensitive
  832. +
  833.     * @param string $val 
  834. +
  835.     * @return integer result code
  836. +
  837.     */
  838. +
  839.     function set_var($var$val)
  840. +
  841.     {
  842. +
  843.       $res $this->set_variable($var$val);
  844. +
  845.       return $res['code'];
  846. +
  847.     }
  848. +
  849.  
  850. +
  851.    /**
  852. +
  853.     * Hangup the current channel.
  854. +
  855.     *
  856. +
  857.     * @link http://www.voip-info.org/wiki-hangup
  858. +
  859.     * @param string $channel 
  860. +
  861.     */
  862. +
  863.     function agi_hangup()
  864. +
  865.     {
  866. +
  867.       $this->hangup();
  868. +
  869.     }
  870. +
  871.  
  872. +
  873.    /**
  874. +
  875.     * Get the status of the specified channel.
  876. +
  877.     *
  878. +
  879.     * @link http://www.voip-info.org/wiki-channel+status
  880. +
  881.     * @param string $channel 
  882. +
  883.     * @return array, ('status'=>$res['result'], 'description'=>$res['data'])
  884. +
  885.     */
  886. +
  887.     function agi_channel_status($channel)
  888. +
  889.     {
  890. +
  891.       $res $this->channel_status($channel);
  892. +
  893.       return array('status'=>$res['result']'description'=>$res['data']);
  894. +
  895.     }
  896. +
  897.  
  898. +
  899.    /**
  900. +
  901.     * Record sound to a file until an acceptable DTMF digit is received or a specified amount of
  902. +
  903.     * time has passed. Optionally the file BEEP is played before recording begins.
  904. +
  905.     *
  906. +
  907.     * @link http://www.voip-info.org/wiki-record+file
  908. +
  909.     * @param string $file to record, without extension, often created in /var/lib/asterisk/sounds
  910. +
  911.     * @param string $format of the file. GSM and WAV are commonly used formats. MP3 is read-only and thus cannot be used.
  912. +
  913.     * @param integer $timeout is the maximum record time in milliseconds, or -1 for no timeout.
  914. +
  915.     * @param string $prompt to play
  916. +
  917.     */
  918. +
  919.     function agi_recordfile($file$format$timeout=5000$prompt=FALSE)
  920. +
  921.     {
  922. +
  923.       if($prompt$this->stream_file($prompt);
  924. +
  925.       $this->record_file($file$format'#'$timeouttrue);
  926. +
  927.     }
  928. +
  929.  
  930. +
  931.    /**
  932. +
  933.     * Play the given audio file, allowing playback to be interrupted by a #. This command is similar to the GET DATA
  934. +
  935.     * command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of
  936. +
  937.     * digits before returning.
  938. +
  939.     *
  940. +
  941.     * @link http://www.voip-info.org/wiki-stream+file
  942. +
  943.     * @param string $file filename without extension, often in /var/lib/asterisk/sounds
  944. +
  945.     */
  946. +
  947.     function agi_play($file)
  948. +
  949.     {
  950. +
  951.       $this->stream_file($file'#');
  952. +
  953.     }
  954. +
  955.  
  956. +
  957.    /**
  958. +
  959.     * Goto - Set context, extension and priority
  960. +
  961.     *
  962. +
  963.     * @param string $con context
  964. +
  965.     * @param string $ext extension
  966. +
  967.     * @param string $pri priority
  968. +
  969.     */
  970. +
  971.     function agi_goto($con,$ext='s',$pri=1)
  972. +
  973.     {
  974. +
  975.       $this->goto($con$ext$pri);
  976. +
  977.     }
  978. +
  979.  
  980. +
  981.    /**
  982. +
  983.     * Say the given digit string, returning early if # is received on the channel.
  984. +
  985.     *
  986. +
  987.     * @link http://www.voip-info.org/wiki-say+digits
  988. +
  989.     * @param integer $digits 
  990. +
  991.     */
  992. +
  993.     function agi_saydigits($digits)
  994. +
  995.     {
  996. +
  997.       $this->say_digits($digits'#');
  998. +
  999.     }
  1000. +
  1001.  
  1002. +
  1003.    /**
  1004. +
  1005.     * Say the given number, returning early if # is received on the channel.
  1006. +
  1007.     *
  1008. +
  1009.     * @link http://www.voip-info.org/wiki-say+number
  1010. +
  1011.     * @param integer $number 
  1012. +
  1013.     */
  1014. +
  1015.     function agi_saynumber($number)
  1016. +
  1017.     {
  1018. +
  1019.       $this->say_number($number'#');
  1020. +
  1021.     }
  1022. +
  1023.  
  1024. +
  1025.    /**
  1026. +
  1027.     * Say a given time, returning early if # is received on the channel.
  1028. +
  1029.     *
  1030. +
  1031.     * @link http://www.voip-info.org/wiki-say+time
  1032. +
  1033.     * @param integer $time number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
  1034. +
  1035.     */
  1036. +
  1037.     function agi_saytime($time='')
  1038. +
  1039.     {
  1040. +
  1041.       if($time == ''$time time();
  1042. +
  1043.       $this->say_time($time'#');
  1044. +
  1045.     }
  1046. +
  1047.  
  1048. +
  1049.    /**
  1050. +
  1051.     * Set Language
  1052. +
  1053.     *
  1054. +
  1055.     * @param string $language code
  1056. +
  1057.     */
  1058. +
  1059.     function agi_setlanguage($language='en')
  1060. +
  1061.     {
  1062. +
  1063.       $this->exec_setlanguage($language);
  1064. +
  1065.     }
  1066. +
  1067.  
  1068. +
  1069.    /**
  1070. +
  1071.     * Perform enum lookup
  1072. +
  1073.     *
  1074. +
  1075.     * @param string $telnumber 
  1076. +
  1077.     * @param string $rDNS 
  1078. +
  1079.     * @return array 
  1080. +
  1081.     */
  1082. +
  1083.     function enum_lookup($telnumber$rDNS='e164.org')
  1084. +
  1085.     {
  1086. +
  1087.       // returns a sorted array of enum records 
  1088. +
  1089.  
  1090. +
  1091.       if($telnumber[0== '+')
  1092. +
  1093.         $telnumber substr($telnumber1);
  1094. +
  1095.  
  1096. +
  1097.       for($i 0$i strlen($telnumber)$i++)
  1098. +
  1099.         $rDNS $telnumber[$i'.' $rDNS;
  1100. +
  1101.  
  1102. +
  1103.       if(!isset($this->config['phpagi']['dig'])) $this->config['phpagi']['dig'$this->which('dig');
  1104. +
  1105.       $dig=trim($this->config['phpagi']['dig']);
  1106. +
  1107.  
  1108. +
  1109.       $execstr$dig " +short " escapeshellarg($rDNS" NAPTR";
  1110. +
  1111.       $lines trim(`$execstr`);
  1112. +
  1113.  
  1114. +
  1115.       $lines explode("\n"$lines);
  1116. +
  1117.       $arr array();
  1118. +
  1119.       foreach($lines as $line)
  1120. +
  1121.       {
  1122. +
  1123.         $line trim($line);
  1124. +
  1125.         $line str_replace("\t"' '$line);
  1126. +
  1127.         while(strstr($line'  '))
  1128. +
  1129.           $line str_replace('  '' '$line);
  1130. +
  1131.         $line str_replace("\""''$line);
  1132. +
  1133.         $line str_replace("\'"''$line);
  1134. +
  1135.         $line str_replace(' ''|'$line);
  1136. +
  1137.         $bits explode('|'$line);
  1138. +
  1139.         $bit explode('!'stripslashes($bits[4]));
  1140. +
  1141.         $URI @ereg_replace($bit[1]$bit[2]'+' $telnumber);
  1142. +
  1143.         if($URI[3== ':'$URI[3'/';
  1144. +
  1145.         if($URI[4== ':'$URI[4'/';
  1146. +
  1147.         $arr[array('order'=>$bits[0]'prio'=>$bits[1]'tech'=>$bits[3]'URI'=>$URI);
  1148. +
  1149.       }
  1150. +
  1151.  
  1152. +
  1153.       foreach($arr as $key=>$row)
  1154. +
  1155.       {
  1156. +
  1157.         $order[$key$row['order'];
  1158. +
  1159.         $prio[$key$row['prio'];
  1160. +
  1161.       }
  1162. +
  1163.  
  1164. +
  1165.       array_multisort($orderSORT_ASC$prioSORT_ASC$arr);
  1166. +
  1167.       return($arr);
  1168. +
  1169.     }
  1170. +
  1171.  
  1172. +
  1173.    /**
  1174. +
  1175.     * Perform enum txt lookup
  1176. +
  1177.     *
  1178. +
  1179.     * @param string $telnumber 
  1180. +
  1181.     * @param string $rDNS 
  1182. +
  1183.     * @return string 
  1184. +
  1185.     */
  1186. +
  1187.     function enum_txtlookup($telnumber$rDNS='e164.org')
  1188. +
  1189.     {
  1190. +
  1191.       // returns the contents of a TXT record associated with an ENUM dns record.
  1192. +
  1193.       // ala reverse caller ID lookup.
  1194. +
  1195.       if($telnumber[0== '+')
  1196. +
  1197.         $telnumber substr($telnumber1);
  1198. +
  1199.  
  1200. +
  1201.       for($i 0$i strlen($telnumber)$i++)
  1202. +
  1203.         $rDNS $telnumber[$i'.' $rDNS;
  1204. +
  1205.  
  1206. +
  1207.       if(!isset($this->config['phpagi']['dig'])) $this->config['phpagi']['dig'$this->which('dig');
  1208. +
  1209.       $dig=trim($this->config['phpagi']['dig']);
  1210. +
  1211.  
  1212. +
  1213.       $execstr $dig ' +short ' escapeshellarg($rDNS' TXT';
  1214. +
  1215.       $lines trim(`$execstr`);
  1216. +
  1217.  
  1218. +
  1219.       $lines explode("\n"$lines);
  1220. +
  1221.       foreach($lines as $line)
  1222. +
  1223.       {
  1224. +
  1225.         $line str_replace("\t"' 'trim($line));
  1226. +
  1227.         while(strstr($line'  ')) $line str_replace('  '' '$line);
  1228. +
  1229.         $line str_replace("\""''$line);
  1230. +
  1231.         $line str_replace("\'"''$line);
  1232. +
  1233.         $ret .= $line;
  1234. +
  1235.       }
  1236. +
  1237.       $ret trim($ret);
  1238. +
  1239.       if($ret == ''return false;
  1240. +
  1241.       return $ret;
  1242. +
  1243.     }
  1244. +
  1245.  
  1246. +
  1247.    /**
  1248. +
  1249.     * Send the given text to the connected channel.
  1250. +
  1251.     *
  1252. +
  1253.     * Most channels do not support transmission of text.
  1254. +
  1255.     *
  1256. +
  1257.     * @link http://www.voip-info.org/wiki-send+text
  1258. +
  1259.     * @param $text 
  1260. +
  1261.     * @return boolean true on success
  1262. +
  1263.     */
  1264. +
  1265.     function send_text($txt)
  1266. +
  1267.     {
  1268. +
  1269.       $res parent::send_text($txt);
  1270. +
  1271.       if($res['code'!= AGIRES_OK || $res['result'== -1return false;
  1272. +
  1273.       return true;
  1274. +
  1275.     }
  1276. +
  1277.  
  1278. +
  1279.    /**
  1280. +
  1281.     * Send the specified image on a channel.
  1282. +
  1283.     *
  1284. +
  1285.     * Most channels do not support the transmission of images.
  1286. +
  1287.     *
  1288. +
  1289.     * @link http://www.voip-info.org/wiki-send+image
  1290. +
  1291.     * @param string $image without extension, often in /var/lib/asterisk/images
  1292. +
  1293.     * @return boolean true on success
  1294. +
  1295.     */
  1296. +
  1297.     function send_image($image)
  1298. +
  1299.     {
  1300. +
  1301.       $res parent::send_image($image);
  1302. +
  1303.       if($res['code'!= AGIRES_OK || $res['result'== -1return false;
  1304. +
  1305.       return true;
  1306. +
  1307.     }    
  1308. +
  1309.   }
  1310. +
  1311. ?>
  1312. +
+
+

+ Documentation generated on Thu, 30 Sep 2010 02:22:07 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/blank.html b/api-docs/blank.html new file mode 100644 index 0000000..417cc44 --- /dev/null +++ b/api-docs/blank.html @@ -0,0 +1,13 @@ + + + phpAGI + + + + +

phpAGI

+Welcome to phpAGI!
+
+This documentation was generated by phpDocumentor v1.4.2
+ + \ No newline at end of file diff --git a/api-docs/classtrees_phpAGI.html b/api-docs/classtrees_phpAGI.html new file mode 100644 index 0000000..57ca5e8 --- /dev/null +++ b/api-docs/classtrees_phpAGI.html @@ -0,0 +1,30 @@ + + + + + + + + + + + + +

+ +

+

Root class AGI

+ + +

Root class AGI_AsteriskManager

+ + +

+ Documentation generated on Thu, 30 Sep 2010 02:21:44 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/elementindex.html b/api-docs/elementindex.html new file mode 100644 index 0000000..f23522f --- /dev/null +++ b/api-docs/elementindex.html @@ -0,0 +1,1596 @@ + + + + + + + + + + + +

Full index

+

Package indexes

+ +
+
+ a + c + d + e + f + g + h + i + l + m + n + o + p + q + r + s + t + v + w + z + _ +
+ + +
+
a
+
top
+
+
+
+
+ Variable + $asmanager +
+
+
AGI::$asmanager in phpagi.php
+
Asterisk Manager
+
+
+ Variable + $audio +
+
+
AGI::$audio in phpagi.php
+
Audio Stream
+
+
+ Method + AbsoluteTimeout +
+
+ +
Set Absolute Timeout
+
+
+ Method + add_event_handler +
+
+ +
Add event handler
+
+
+ Class + AGI +
+
+
AGI in phpagi.php
+
AGI class
+
+
+ Constant + AGIRES_OK +
+
+
AGIRES_OK in phpagi.php
+
+
+ Class + AGI_1 +
+
+
AGI_1 in phpagi_1.php
+
Asterisk Manager class
+
+
+ Method + AGI_1 +
+
+
AGI_1::AGI_1() in phpagi_1.php
+
Constructor
+
+
+ Class + AGI_AsteriskManager +
+
+
AGI_AsteriskManager in phpagi-asmanager.php
+
Asterisk Manager class
+
+
+ Method + AGI_AsteriskManager +
+
+ +
Constructor
+
+
+ Method + agi_channel_status +
+
+ +
Get the status of the specified channel.
+
+
+ Method + agi_dtmf2text +
+
+
AGI_1::agi_dtmf2text() in phpagi_1.php
+
Read $len characters as DTMF codes
+
+
+ Method + agi_exec +
+
+
AGI_1::agi_exec() in phpagi_1.php
+
Execute an AGI command
+
+
+ Method + agi_getdtmf +
+
+
AGI_1::agi_getdtmf() in phpagi_1.php
+
Plays the given file and receives DTMF data.
+
+
+ Method + agi_goto +
+
+
AGI_1::agi_goto() in phpagi_1.php
+
Goto - Set context, extension and priority
+
+
+ Method + agi_hangup +
+
+
AGI_1::agi_hangup() in phpagi_1.php
+
Hangup the current channel.
+
+
+ Method + agi_is_error +
+
+
AGI_1::agi_is_error() in phpagi_1.php
+
Check for error in result structure
+
+
+ Method + agi_play +
+
+
AGI_1::agi_play() in phpagi_1.php
+
Play the given audio file, allowing playback to be interrupted by a #. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.
+
+
+ Method + agi_readresult +
+
+
AGI_1::agi_readresult() in phpagi_1.php
+
Read the result from Asterisk
+
+
+ Method + agi_recordfile +
+
+
AGI_1::agi_recordfile() in phpagi_1.php
+
Record sound to a file until an acceptable DTMF digit is received or a specified amount of time has passed. Optionally the file BEEP is played before recording begins.
+
+
+ Method + agi_response_code +
+
+ +
Get the response code from the last command
+
+
+ Method + agi_response_data +
+
+ +
Get the response data from the last command
+
+
+ Method + agi_response_is_error +
+
+ +
Check for error in response
+
+
+ Method + agi_response_result +
+
+ +
Get the result code from the last command
+
+
+ Method + agi_response_var +
+
+ +
Get the response variable from the last command
+
+
+ Method + agi_saydigits +
+
+
AGI_1::agi_saydigits() in phpagi_1.php
+
Say the given digit string, returning early if # is received on the channel.
+
+
+ Method + agi_saynumber +
+
+
AGI_1::agi_saynumber() in phpagi_1.php
+
Say the given number, returning early if # is received on the channel.
+
+
+ Method + agi_saytime +
+
+
AGI_1::agi_saytime() in phpagi_1.php
+
Say a given time, returning early if # is received on the channel.
+
+
+ Method + agi_setlanguage +
+
+
AGI_1::agi_setlanguage() in phpagi_1.php
+
Set Language
+
+
+ Method + agi_verbose +
+
+
AGI_1::agi_verbose() in phpagi_1.php
+
Sends $message to the Asterisk console via the 'verbose' message system.
+
+
+ Method + answer +
+
+
AGI::answer() in phpagi.php
+
Answer channel if not already in answer state.
+
+
+ Method + arr2str +
+
+
AGI_1::arr2str() in phpagi_1.php
+
Alias of PHP join function
+
+
+ Constant + AST_CONFIG_DIR +
+
+
AST_CONFIG_DIR in phpagi.php
+
+
+ Constant + AST_DIGIT_ANY +
+
+
AST_DIGIT_ANY in phpagi.php
+
+
+ Constant + AST_SPOOL_DIR +
+
+
AST_SPOOL_DIR in phpagi.php
+
+
+ Constant + AST_STATE_BUSY +
+
+
AST_STATE_BUSY in phpagi.php
+
+
+ Constant + AST_STATE_DIALING +
+
+
AST_STATE_DIALING in phpagi.php
+
+
+ Constant + AST_STATE_DIALING_OFFHOOK +
+
+ +
+
+ Constant + AST_STATE_DOWN +
+
+
AST_STATE_DOWN in phpagi.php
+
+
+ Constant + AST_STATE_OFFHOOK +
+
+
AST_STATE_OFFHOOK in phpagi.php
+
+
+ Constant + AST_STATE_PRERING +
+
+
AST_STATE_PRERING in phpagi.php
+
+
+ Constant + AST_STATE_RESERVED +
+
+
AST_STATE_RESERVED in phpagi.php
+
+
+ Constant + AST_STATE_RING +
+
+
AST_STATE_RING in phpagi.php
+
+
+ Constant + AST_STATE_RINGING +
+
+
AST_STATE_RINGING in phpagi.php
+
+
+ Constant + AST_STATE_UP +
+
+
AST_STATE_UP in phpagi.php
+
+
+ Constant + AST_TMP_DIR +
+
+
AST_TMP_DIR in phpagi.php
+
+
+ Constant + AUDIO_FILENO +
+
+
AUDIO_FILENO in phpagi.php
+
+
+ +
+
c
+
top
+
+
+
+
+ Variable + $config +
+
+
AGI::$config in phpagi.php
+
Config variables
+
+
+ Variable + $config +
+
+
AGI_AsteriskManager::$config in phpagi-asmanager.php
+
Config variables
+
+
+ Method + ChangeMonitor +
+
+
AGI_AsteriskManager::ChangeMonitor() in phpagi-asmanager.php
+
Change monitoring filename of a channel
+
+
+ Method + channel_status +
+
+
AGI::channel_status() in phpagi.php
+
Get the status of the specified channel. If no channel name is specified, return the status of the current channel.
+
+
+ Method + Command +
+
+
AGI_AsteriskManager::Command() in phpagi-asmanager.php
+
Execute Command
+
+
+ Method + conlog +
+
+
AGI::conlog() in phpagi.php
+
Log to console if debug mode.
+
+
+ Method + connect +
+
+
AGI_AsteriskManager::connect() in phpagi-asmanager.php
+
Connect to Asterisk
+
+
+ Method + con_print_r +
+
+
AGI_1::con_print_r() in phpagi_1.php
+
Log to console if debug mode
+
+
+ +
+
d
+
top
+
+
+
+
+ Method + database_del +
+
+
AGI::database_del() in phpagi.php
+
Deletes an entry in the Asterisk database for a given family and key.
+
+
+ Method + database_deltree +
+
+ +
Deletes a family or specific keytree within a family in the Asterisk database.
+
+
+ Method + database_get +
+
+
AGI::database_get() in phpagi.php
+
Retrieves an entry in the Asterisk database for a given family and key.
+
+
+ Method + database_put +
+
+
AGI::database_put() in phpagi.php
+
Adds or updates an entry in the Asterisk database for a given family, key, and value.
+
+
+ Method + db_del +
+
+
AGI_1::db_del() in phpagi_1.php
+
Deletes an entry in the Asterisk database for a given family and key.
+
+
+ Method + db_get +
+
+
AGI_1::db_get() in phpagi_1.php
+
Retrieves an entry in the Asterisk database for a given family and key.
+
+
+ Method + db_put +
+
+
AGI_1::db_put() in phpagi_1.php
+
Adds or updates an entry in the Asterisk database for a given family, key, and value.
+
+
+ Constant + DEFAULT_PHPAGI_CONFIG +
+
+
DEFAULT_PHPAGI_CONFIG in phpagi.php
+
+
+ Method + disconnect +
+
+
AGI_AsteriskManager::disconnect() in phpagi-asmanager.php
+
Disconnect
+
+
+ +
+
e
+
top
+
+
+
+
+ Variable + $event_handlers +
+
+
AGI_AsteriskManager::$event_handlers in phpagi-asmanager.php
+
Event Handlers
+
+
+ Method + enum_lookup +
+
+
AGI_1::enum_lookup() in phpagi_1.php
+
Perform enum lookup
+
+
+ Method + enum_txtlookup +
+
+
AGI_1::enum_txtlookup() in phpagi_1.php
+
Perform enum txt lookup
+
+
+ Method + evaluate +
+
+
AGI::evaluate() in phpagi.php
+
Evaluate an AGI command.
+
+
+ Method + evalutate +
+
+
AGI_1::evalutate() in phpagi_1.php
+
Evaluate an AGI command
+
+
+ Method + Events +
+
+
AGI_AsteriskManager::Events() in phpagi-asmanager.php
+
Enable/Disable sending of events to this manager
+
+
+ Method + exec +
+
+
AGI::exec() in phpagi.php
+
Executes the specified Asterisk application with given options.
+
+
+ Method + exec_absolutetimeout +
+
+ +
Set absolute maximum time of call.
+
+
+ Method + exec_agi +
+
+
AGI::exec_agi() in phpagi.php
+
Executes an AGI compliant application.
+
+
+ Method + exec_dial +
+
+
AGI::exec_dial() in phpagi.php
+
Dial.
+
+
+ Method + exec_enumlookup +
+
+ +
Do ENUM Lookup.
+
+
+ Method + exec_goto +
+
+
AGI::exec_goto() in phpagi.php
+
Goto.
+
+
+ Method + exec_setlanguage +
+
+ +
Set Language.
+
+
+ Method + ExtensionState +
+
+ +
Check Extension Status
+
+
+ +
+
f
+
top
+
+
+
+
+ Method + fastpass_get_data +
+
+ +
Plays the given file and receives DTMF data.
+
+
+ Method + fastpass_say_digits +
+
+ +
Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_say_number +
+
+ +
Say the given number, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_say_phonetic +
+
+ +
Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_say_punctuation +
+
+ +
Say Puncutation in a string.
+
+
+ Method + fastpass_say_time +
+
+ +
Say a given time, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_stream_file +
+
+ +
Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.
+
+
+ Method + fastpass_swift +
+
+
AGI::fastpass_swift() in phpagi.php
+
Use Cepstral Swift to read text.
+
+
+ Method + fastpass_text2wav +
+
+ +
Use festival to read text.
+
+
+ +
+
g
+
top
+
+
+
+
+ Method + GetVar +
+
+
AGI_AsteriskManager::GetVar() in phpagi-asmanager.php
+
Gets a Channel Variable
+
+
+ Method + get_data +
+
+
AGI::get_data() in phpagi.php
+
Plays the given file and receives DTMF data.
+
+
+ Method + get_fullvariable +
+
+ +
Fetch the value of a full variable.
+
+
+ Method + get_var +
+
+
AGI_1::get_var() in phpagi_1.php
+
Fetch the value of a variable.
+
+
+ Method + get_variable +
+
+
AGI::get_variable() in phpagi.php
+
Fetch the value of a variable.
+
+
+ +
+
h
+
top
+
+
+
+
+ Method + hangup +
+
+
AGI::hangup() in phpagi.php
+
Hangup the specified channel. If no channel name is given, hang up the current channel.
+
+
+ Method + Hangup +
+
+
AGI_AsteriskManager::Hangup() in phpagi-asmanager.php
+
Hangup Channel
+
+
+ +
+
i
+
top
+
+
+
+
+ Variable + $in +
+
+
AGI::$in in phpagi.php
+
Input Stream
+
+
+ Method + IAXPeers +
+
+
AGI_AsteriskManager::IAXPeers() in phpagi-asmanager.php
+
List IAX Peers
+
+
+ +
+
l
+
top
+
+
+
+
+ Method + ListCommands +
+
+
AGI_AsteriskManager::ListCommands() in phpagi-asmanager.php
+
List available manager commands
+
+
+ Method + log +
+
+
AGI_AsteriskManager::log() in phpagi-asmanager.php
+
+
+ Method + Logoff +
+
+
AGI_AsteriskManager::Logoff() in phpagi-asmanager.php
+
Logoff Manager
+
+
+ +
+
m
+
top
+
+
+
+
+ Method + MailboxCount +
+
+
AGI_AsteriskManager::MailboxCount() in phpagi-asmanager.php
+
Check Mailbox Message Count
+
+
+ Method + MailboxStatus +
+
+
AGI_AsteriskManager::MailboxStatus() in phpagi-asmanager.php
+
Check Mailbox
+
+
+ Method + make_folder +
+
+
AGI::make_folder() in phpagi.php
+
Make a folder recursively.
+
+
+ Method + menu +
+
+
AGI::menu() in phpagi.php
+
Menu.
+
+
+ Method + Monitor +
+
+
AGI_AsteriskManager::Monitor() in phpagi-asmanager.php
+
Monitor a channel
+
+
+ +
+
n
+
top
+
+
+
+
+ Method + new_AsteriskManager +
+
+ +
Create a new AGI_AsteriskManager.
+
+
+ Method + noop +
+
+
AGI::noop() in phpagi.php
+
Does nothing.
+
+
+ +
+
o
+
top
+
+
+
+
+ Variable + $option_delim +
+
+
AGI::$option_delim in phpagi.php
+
Application option delimiter
+
+
+ Variable + $out +
+
+
AGI::$out in phpagi.php
+
Output Stream
+
+
+ Method + Originate +
+
+
AGI_AsteriskManager::Originate() in phpagi-asmanager.php
+
Originate Call
+
+
+ +
+
p
+
top
+
+
+
+
+ Variable + $pagi +
+
+
AGI_AsteriskManager::$pagi in phpagi-asmanager.php
+
Parent AGI
+
+
+ Variable + $port +
+
+
AGI_AsteriskManager::$port in phpagi-asmanager.php
+
Port on the server we are connected to
+
+
+ Method + ParkedCalls +
+
+
AGI_AsteriskManager::ParkedCalls() in phpagi-asmanager.php
+
List parked calls
+
+
+ Method + parse_callerid +
+
+
AGI::parse_callerid() in phpagi.php
+
Parse caller id.
+
+
+ Page + phpagi-asmanager.php +
+
+
phpagi-asmanager.php in phpagi-asmanager.php
+
+
+ Page + phpagi-fastagi.php +
+
+
phpagi-fastagi.php in phpagi-fastagi.php
+
+
+ Page + phpagi.php +
+
+
phpagi.php in phpagi.php
+
+
+ Page + phpagi_1.php +
+
+
phpagi_1.php in phpagi_1.php
+
+
+ Function + phpagi_error_handler +
+
+ +
error handler for phpagi.
+
+
+ Method + Ping +
+
+
AGI_AsteriskManager::Ping() in phpagi-asmanager.php
+
Ping
+
+
+ Method + process_event +
+
+
AGI_AsteriskManager::process_event() in phpagi-asmanager.php
+
Process event
+
+
+ +
+
q
+
top
+
+
+
+
+ Method + QueueAdd +
+
+
AGI_AsteriskManager::QueueAdd() in phpagi-asmanager.php
+
Queue Add
+
+
+ Method + QueueRemove +
+
+
AGI_AsteriskManager::QueueRemove() in phpagi-asmanager.php
+
Queue Remove
+
+
+ Method + Queues +
+
+
AGI_AsteriskManager::Queues() in phpagi-asmanager.php
+
Queues
+
+
+ Method + QueueStatus +
+
+
AGI_AsteriskManager::QueueStatus() in phpagi-asmanager.php
+
Queue Status
+
+
+ +
+
r
+
top
+
+
+
+
+ Variable + $request +
+
+
AGI::$request in phpagi.php
+
Request variables read in on initialization.
+
+
+ Variable + $response +
+
+
AGI_1::$response in phpagi_1.php
+
Response structure
+
+
+ Method + receive_char +
+
+
AGI::receive_char() in phpagi.php
+
Receive a character of text from a connected channel. Waits up to $timeout milliseconds for a character to arrive, or infinitely if $timeout is zero.
+
+
+ Method + record_file +
+
+
AGI::record_file() in phpagi.php
+
Record sound to a file until an acceptable DTMF digit is received or a specified amount of time has passed. Optionally the file BEEP is played before recording begins.
+
+
+ Method + Redirect +
+
+
AGI_AsteriskManager::Redirect() in phpagi-asmanager.php
+
Redirect
+
+
+ +
+
s
+
top
+
+
+
+
+ Variable + $server +
+
+
AGI_AsteriskManager::$server in phpagi-asmanager.php
+
Server we are connected to
+
+
+ Variable + $socket +
+
+
AGI_AsteriskManager::$socket in phpagi-asmanager.php
+
Socket
+
+
+ Method + say_digits +
+
+
AGI::say_digits() in phpagi.php
+
Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + say_number +
+
+
AGI::say_number() in phpagi.php
+
Say the given number, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + say_phonetic +
+
+
AGI::say_phonetic() in phpagi.php
+
Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + say_punctuation +
+
+ +
Say Puncutation in a string.
+
+
+ Method + say_time +
+
+
AGI::say_time() in phpagi.php
+
Say a given time, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + send_image +
+
+
AGI_1::send_image() in phpagi_1.php
+
Send the specified image on a channel.
+
+
+ Method + send_image +
+
+
AGI::send_image() in phpagi.php
+
Send the specified image on a channel.
+
+
+ Method + send_request +
+
+
AGI_AsteriskManager::send_request() in phpagi-asmanager.php
+
Send a request
+
+
+ Method + send_text +
+
+
AGI::send_text() in phpagi.php
+
Send the given text to the connected channel.
+
+
+ Method + send_text +
+
+
AGI_1::send_text() in phpagi_1.php
+
Send the given text to the connected channel.
+
+
+ Method + SetCDRUserField +
+
+ +
Set the CDR UserField
+
+
+ Method + setContext +
+
+
AGI::setContext() in phpagi.php
+
setContext - Set context, extension and priority.
+
+
+ Method + SetVar +
+
+
AGI_AsteriskManager::SetVar() in phpagi-asmanager.php
+
Set Channel Variable
+
+
+ Method + set_autohangup +
+
+
AGI::set_autohangup() in phpagi.php
+
Cause the channel to automatically hangup at $time seconds in the future.
+
+
+ Method + set_callerid +
+
+
AGI::set_callerid() in phpagi.php
+
Changes the caller ID of the current channel.
+
+
+ Method + set_context +
+
+
AGI::set_context() in phpagi.php
+
Sets the context for continuation upon exiting the application.
+
+
+ Method + set_extension +
+
+
AGI::set_extension() in phpagi.php
+
Set the extension to be used for continuation upon exiting the application.
+
+
+ Method + set_global_var +
+
+
AGI::set_global_var() in phpagi.php
+
Sets a global variable, using Asterisk 1.6 syntax.
+
+
+ Method + set_music +
+
+
AGI::set_music() in phpagi.php
+
Enable/Disable Music on hold generator.
+
+
+ Method + set_priority +
+
+
AGI::set_priority() in phpagi.php
+
Set the priority to be used for continuation upon exiting the application.
+
+
+ Method + set_var +
+
+
AGI::set_var() in phpagi.php
+
Sets a variable, using Asterisk 1.6 syntax.
+
+
+ Method + set_var +
+
+
AGI_1::set_var() in phpagi_1.php
+
Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>} in the dialplan.
+
+
+ Method + set_variable +
+
+
AGI::set_variable() in phpagi.php
+
Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>} in the dialplan.
+
+
+ Method + Status +
+
+
AGI_AsteriskManager::Status() in phpagi-asmanager.php
+
Channel Status
+
+
+ Method + StopMonitor +
+
+
AGI_AsteriskManager::StopMonitor() in phpagi-asmanager.php
+
Stop monitoring a channel
+
+
+ Method + stream_file +
+
+
AGI::stream_file() in phpagi.php
+
Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.
+
+
+ Method + swift +
+
+
AGI::swift() in phpagi.php
+
Use Cepstral Swift to read text.
+
+
+ +
+
t
+
top
+
+
+
+
+ Method + tdd_mode +
+
+
AGI::tdd_mode() in phpagi.php
+
Enable or disable TDD transmission/reception on the current channel.
+
+
+ Method + text2wav +
+
+
AGI::text2wav() in phpagi.php
+
Use festival to read text.
+
+
+ Method + text_input +
+
+
AGI::text_input() in phpagi.php
+
Text Input.
+
+
+ +
+
v
+
top
+
+
+
+
+ Method + verbose +
+
+
AGI::verbose() in phpagi.php
+
Sends $message to the Asterisk console via the 'verbose' message system.
+
+
+ +
+
w
+
top
+
+
+
+
+ Method + wait_for_digit +
+
+
AGI::wait_for_digit() in phpagi.php
+
Waits up to $timeout milliseconds for channel to receive a DTMF digit.
+
+
+ Method + wait_response +
+
+
AGI_AsteriskManager::wait_response() in phpagi-asmanager.php
+
Wait for a response
+
+
+ Method + which +
+
+
AGI::which() in phpagi.php
+
Find an execuable in the path.
+
+
+ +
+
z
+
top
+
+
+
+
+ Method + ZapDialOffhook +
+
+ +
Dial over Zap channel while offhook
+
+
+ Method + ZapDNDoff +
+
+
AGI_AsteriskManager::ZapDNDoff() in phpagi-asmanager.php
+
Toggle Zap channel Do Not Disturb status OFF
+
+
+ Method + ZapDNDon +
+
+
AGI_AsteriskManager::ZapDNDon() in phpagi-asmanager.php
+
Toggle Zap channel Do Not Disturb status ON
+
+
+ Method + ZapHangup +
+
+
AGI_AsteriskManager::ZapHangup() in phpagi-asmanager.php
+
Hangup Zap Channel
+
+
+ Method + ZapShowChannels +
+
+ +
Zap Show Channels
+
+
+ Method + ZapTransfer +
+
+
AGI_AsteriskManager::ZapTransfer() in phpagi-asmanager.php
+
Transfer Zap Channel
+
+
+ +
+
_
+
top
+
+
+
+
+ Variable + $_logged_in +
+
+
AGI_AsteriskManager::$_logged_in in phpagi-asmanager.php
+
Whether we're successfully logged in
+
+
+ Method + __construct +
+
+
AGI::__construct() in phpagi.php
+
Constructor
+
+
+ +
+ a + c + d + e + f + g + h + i + l + m + n + o + p + q + r + s + t + v + w + z + _ +
+ \ No newline at end of file diff --git a/api-docs/elementindex_phpAGI.html b/api-docs/elementindex_phpAGI.html new file mode 100644 index 0000000..0283b74 --- /dev/null +++ b/api-docs/elementindex_phpAGI.html @@ -0,0 +1,1593 @@ + + + + + + + + + + + +

[phpAGI] element index

+All elements +
+
+ a + c + d + e + f + g + h + i + l + m + n + o + p + q + r + s + t + v + w + z + _ +
+ + +
+
_
+
top
+
+
+
+
+ Variable + $_logged_in +
+
+
AGI_AsteriskManager::$_logged_in in phpagi-asmanager.php
+
Whether we're successfully logged in
+
+
+ Method + __construct +
+
+
AGI::__construct() in phpagi.php
+
Constructor
+
+
+ +
+
a
+
top
+
+
+
+
+ Variable + $asmanager +
+
+
AGI::$asmanager in phpagi.php
+
Asterisk Manager
+
+
+ Variable + $audio +
+
+
AGI::$audio in phpagi.php
+
Audio Stream
+
+
+ Method + AbsoluteTimeout +
+
+ +
Set Absolute Timeout
+
+
+ Method + add_event_handler +
+
+ +
Add event handler
+
+
+ Class + AGI +
+
+
AGI in phpagi.php
+
AGI class
+
+
+ Constant + AGIRES_OK +
+
+
AGIRES_OK in phpagi.php
+
+
+ Class + AGI_1 +
+
+
AGI_1 in phpagi_1.php
+
Asterisk Manager class
+
+
+ Method + AGI_1 +
+
+
AGI_1::AGI_1() in phpagi_1.php
+
Constructor
+
+
+ Class + AGI_AsteriskManager +
+
+
AGI_AsteriskManager in phpagi-asmanager.php
+
Asterisk Manager class
+
+
+ Method + AGI_AsteriskManager +
+
+ +
Constructor
+
+
+ Method + agi_channel_status +
+
+ +
Get the status of the specified channel.
+
+
+ Method + agi_dtmf2text +
+
+
AGI_1::agi_dtmf2text() in phpagi_1.php
+
Read $len characters as DTMF codes
+
+
+ Method + agi_exec +
+
+
AGI_1::agi_exec() in phpagi_1.php
+
Execute an AGI command
+
+
+ Method + agi_getdtmf +
+
+
AGI_1::agi_getdtmf() in phpagi_1.php
+
Plays the given file and receives DTMF data.
+
+
+ Method + agi_goto +
+
+
AGI_1::agi_goto() in phpagi_1.php
+
Goto - Set context, extension and priority
+
+
+ Method + agi_hangup +
+
+
AGI_1::agi_hangup() in phpagi_1.php
+
Hangup the current channel.
+
+
+ Method + agi_is_error +
+
+
AGI_1::agi_is_error() in phpagi_1.php
+
Check for error in result structure
+
+
+ Method + agi_play +
+
+
AGI_1::agi_play() in phpagi_1.php
+
Play the given audio file, allowing playback to be interrupted by a #. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.
+
+
+ Method + agi_readresult +
+
+
AGI_1::agi_readresult() in phpagi_1.php
+
Read the result from Asterisk
+
+
+ Method + agi_recordfile +
+
+
AGI_1::agi_recordfile() in phpagi_1.php
+
Record sound to a file until an acceptable DTMF digit is received or a specified amount of time has passed. Optionally the file BEEP is played before recording begins.
+
+
+ Method + agi_response_code +
+
+ +
Get the response code from the last command
+
+
+ Method + agi_response_data +
+
+ +
Get the response data from the last command
+
+
+ Method + agi_response_is_error +
+
+ +
Check for error in response
+
+
+ Method + agi_response_result +
+
+ +
Get the result code from the last command
+
+
+ Method + agi_response_var +
+
+ +
Get the response variable from the last command
+
+
+ Method + agi_saydigits +
+
+
AGI_1::agi_saydigits() in phpagi_1.php
+
Say the given digit string, returning early if # is received on the channel.
+
+
+ Method + agi_saynumber +
+
+
AGI_1::agi_saynumber() in phpagi_1.php
+
Say the given number, returning early if # is received on the channel.
+
+
+ Method + agi_saytime +
+
+
AGI_1::agi_saytime() in phpagi_1.php
+
Say a given time, returning early if # is received on the channel.
+
+
+ Method + agi_setlanguage +
+
+
AGI_1::agi_setlanguage() in phpagi_1.php
+
Set Language
+
+
+ Method + agi_verbose +
+
+
AGI_1::agi_verbose() in phpagi_1.php
+
Sends $message to the Asterisk console via the 'verbose' message system.
+
+
+ Method + answer +
+
+
AGI::answer() in phpagi.php
+
Answer channel if not already in answer state.
+
+
+ Method + arr2str +
+
+
AGI_1::arr2str() in phpagi_1.php
+
Alias of PHP join function
+
+
+ Constant + AST_CONFIG_DIR +
+
+
AST_CONFIG_DIR in phpagi.php
+
+
+ Constant + AST_DIGIT_ANY +
+
+
AST_DIGIT_ANY in phpagi.php
+
+
+ Constant + AST_SPOOL_DIR +
+
+
AST_SPOOL_DIR in phpagi.php
+
+
+ Constant + AST_STATE_BUSY +
+
+
AST_STATE_BUSY in phpagi.php
+
+
+ Constant + AST_STATE_DIALING +
+
+
AST_STATE_DIALING in phpagi.php
+
+
+ Constant + AST_STATE_DIALING_OFFHOOK +
+
+ +
+
+ Constant + AST_STATE_DOWN +
+
+
AST_STATE_DOWN in phpagi.php
+
+
+ Constant + AST_STATE_OFFHOOK +
+
+
AST_STATE_OFFHOOK in phpagi.php
+
+
+ Constant + AST_STATE_PRERING +
+
+
AST_STATE_PRERING in phpagi.php
+
+
+ Constant + AST_STATE_RESERVED +
+
+
AST_STATE_RESERVED in phpagi.php
+
+
+ Constant + AST_STATE_RING +
+
+
AST_STATE_RING in phpagi.php
+
+
+ Constant + AST_STATE_RINGING +
+
+
AST_STATE_RINGING in phpagi.php
+
+
+ Constant + AST_STATE_UP +
+
+
AST_STATE_UP in phpagi.php
+
+
+ Constant + AST_TMP_DIR +
+
+
AST_TMP_DIR in phpagi.php
+
+
+ Constant + AUDIO_FILENO +
+
+
AUDIO_FILENO in phpagi.php
+
+
+ +
+
c
+
top
+
+
+
+
+ Variable + $config +
+
+
AGI::$config in phpagi.php
+
Config variables
+
+
+ Variable + $config +
+
+
AGI_AsteriskManager::$config in phpagi-asmanager.php
+
Config variables
+
+
+ Method + ChangeMonitor +
+
+
AGI_AsteriskManager::ChangeMonitor() in phpagi-asmanager.php
+
Change monitoring filename of a channel
+
+
+ Method + channel_status +
+
+
AGI::channel_status() in phpagi.php
+
Get the status of the specified channel. If no channel name is specified, return the status of the current channel.
+
+
+ Method + Command +
+
+
AGI_AsteriskManager::Command() in phpagi-asmanager.php
+
Execute Command
+
+
+ Method + conlog +
+
+
AGI::conlog() in phpagi.php
+
Log to console if debug mode.
+
+
+ Method + connect +
+
+
AGI_AsteriskManager::connect() in phpagi-asmanager.php
+
Connect to Asterisk
+
+
+ Method + con_print_r +
+
+
AGI_1::con_print_r() in phpagi_1.php
+
Log to console if debug mode
+
+
+ +
+
d
+
top
+
+
+
+
+ Method + database_del +
+
+
AGI::database_del() in phpagi.php
+
Deletes an entry in the Asterisk database for a given family and key.
+
+
+ Method + database_deltree +
+
+ +
Deletes a family or specific keytree within a family in the Asterisk database.
+
+
+ Method + database_get +
+
+
AGI::database_get() in phpagi.php
+
Retrieves an entry in the Asterisk database for a given family and key.
+
+
+ Method + database_put +
+
+
AGI::database_put() in phpagi.php
+
Adds or updates an entry in the Asterisk database for a given family, key, and value.
+
+
+ Method + db_del +
+
+
AGI_1::db_del() in phpagi_1.php
+
Deletes an entry in the Asterisk database for a given family and key.
+
+
+ Method + db_get +
+
+
AGI_1::db_get() in phpagi_1.php
+
Retrieves an entry in the Asterisk database for a given family and key.
+
+
+ Method + db_put +
+
+
AGI_1::db_put() in phpagi_1.php
+
Adds or updates an entry in the Asterisk database for a given family, key, and value.
+
+
+ Constant + DEFAULT_PHPAGI_CONFIG +
+
+
DEFAULT_PHPAGI_CONFIG in phpagi.php
+
+
+ Method + disconnect +
+
+
AGI_AsteriskManager::disconnect() in phpagi-asmanager.php
+
Disconnect
+
+
+ +
+
e
+
top
+
+
+
+
+ Variable + $event_handlers +
+
+
AGI_AsteriskManager::$event_handlers in phpagi-asmanager.php
+
Event Handlers
+
+
+ Method + enum_lookup +
+
+
AGI_1::enum_lookup() in phpagi_1.php
+
Perform enum lookup
+
+
+ Method + enum_txtlookup +
+
+
AGI_1::enum_txtlookup() in phpagi_1.php
+
Perform enum txt lookup
+
+
+ Method + evaluate +
+
+
AGI::evaluate() in phpagi.php
+
Evaluate an AGI command.
+
+
+ Method + evalutate +
+
+
AGI_1::evalutate() in phpagi_1.php
+
Evaluate an AGI command
+
+
+ Method + Events +
+
+
AGI_AsteriskManager::Events() in phpagi-asmanager.php
+
Enable/Disable sending of events to this manager
+
+
+ Method + exec +
+
+
AGI::exec() in phpagi.php
+
Executes the specified Asterisk application with given options.
+
+
+ Method + exec_absolutetimeout +
+
+ +
Set absolute maximum time of call.
+
+
+ Method + exec_agi +
+
+
AGI::exec_agi() in phpagi.php
+
Executes an AGI compliant application.
+
+
+ Method + exec_dial +
+
+
AGI::exec_dial() in phpagi.php
+
Dial.
+
+
+ Method + exec_enumlookup +
+
+ +
Do ENUM Lookup.
+
+
+ Method + exec_goto +
+
+
AGI::exec_goto() in phpagi.php
+
Goto.
+
+
+ Method + exec_setlanguage +
+
+ +
Set Language.
+
+
+ Method + ExtensionState +
+
+ +
Check Extension Status
+
+
+ +
+
f
+
top
+
+
+
+
+ Method + fastpass_get_data +
+
+ +
Plays the given file and receives DTMF data.
+
+
+ Method + fastpass_say_digits +
+
+ +
Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_say_number +
+
+ +
Say the given number, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_say_phonetic +
+
+ +
Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_say_punctuation +
+
+ +
Say Puncutation in a string.
+
+
+ Method + fastpass_say_time +
+
+ +
Say a given time, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + fastpass_stream_file +
+
+ +
Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.
+
+
+ Method + fastpass_swift +
+
+
AGI::fastpass_swift() in phpagi.php
+
Use Cepstral Swift to read text.
+
+
+ Method + fastpass_text2wav +
+
+ +
Use festival to read text.
+
+
+ +
+
g
+
top
+
+
+
+
+ Method + GetVar +
+
+
AGI_AsteriskManager::GetVar() in phpagi-asmanager.php
+
Gets a Channel Variable
+
+
+ Method + get_data +
+
+
AGI::get_data() in phpagi.php
+
Plays the given file and receives DTMF data.
+
+
+ Method + get_fullvariable +
+
+ +
Fetch the value of a full variable.
+
+
+ Method + get_var +
+
+
AGI_1::get_var() in phpagi_1.php
+
Fetch the value of a variable.
+
+
+ Method + get_variable +
+
+
AGI::get_variable() in phpagi.php
+
Fetch the value of a variable.
+
+
+ +
+
h
+
top
+
+
+
+
+ Method + hangup +
+
+
AGI::hangup() in phpagi.php
+
Hangup the specified channel. If no channel name is given, hang up the current channel.
+
+
+ Method + Hangup +
+
+
AGI_AsteriskManager::Hangup() in phpagi-asmanager.php
+
Hangup Channel
+
+
+ +
+
i
+
top
+
+
+
+
+ Variable + $in +
+
+
AGI::$in in phpagi.php
+
Input Stream
+
+
+ Method + IAXPeers +
+
+
AGI_AsteriskManager::IAXPeers() in phpagi-asmanager.php
+
List IAX Peers
+
+
+ +
+
l
+
top
+
+
+
+
+ Method + ListCommands +
+
+
AGI_AsteriskManager::ListCommands() in phpagi-asmanager.php
+
List available manager commands
+
+
+ Method + log +
+
+
AGI_AsteriskManager::log() in phpagi-asmanager.php
+
+
+ Method + Logoff +
+
+
AGI_AsteriskManager::Logoff() in phpagi-asmanager.php
+
Logoff Manager
+
+
+ +
+
m
+
top
+
+
+
+
+ Method + MailboxCount +
+
+
AGI_AsteriskManager::MailboxCount() in phpagi-asmanager.php
+
Check Mailbox Message Count
+
+
+ Method + MailboxStatus +
+
+
AGI_AsteriskManager::MailboxStatus() in phpagi-asmanager.php
+
Check Mailbox
+
+
+ Method + make_folder +
+
+
AGI::make_folder() in phpagi.php
+
Make a folder recursively.
+
+
+ Method + menu +
+
+
AGI::menu() in phpagi.php
+
Menu.
+
+
+ Method + Monitor +
+
+
AGI_AsteriskManager::Monitor() in phpagi-asmanager.php
+
Monitor a channel
+
+
+ +
+
n
+
top
+
+
+
+
+ Method + new_AsteriskManager +
+
+ +
Create a new AGI_AsteriskManager.
+
+
+ Method + noop +
+
+
AGI::noop() in phpagi.php
+
Does nothing.
+
+
+ +
+
o
+
top
+
+
+
+
+ Variable + $option_delim +
+
+
AGI::$option_delim in phpagi.php
+
Application option delimiter
+
+
+ Variable + $out +
+
+
AGI::$out in phpagi.php
+
Output Stream
+
+
+ Method + Originate +
+
+
AGI_AsteriskManager::Originate() in phpagi-asmanager.php
+
Originate Call
+
+
+ +
+
p
+
top
+
+
+
+
+ Variable + $pagi +
+
+
AGI_AsteriskManager::$pagi in phpagi-asmanager.php
+
Parent AGI
+
+
+ Variable + $port +
+
+
AGI_AsteriskManager::$port in phpagi-asmanager.php
+
Port on the server we are connected to
+
+
+ Method + ParkedCalls +
+
+
AGI_AsteriskManager::ParkedCalls() in phpagi-asmanager.php
+
List parked calls
+
+
+ Method + parse_callerid +
+
+
AGI::parse_callerid() in phpagi.php
+
Parse caller id.
+
+
+ Page + phpagi-asmanager.php +
+
+
phpagi-asmanager.php in phpagi-asmanager.php
+
+
+ Page + phpagi-fastagi.php +
+
+
phpagi-fastagi.php in phpagi-fastagi.php
+
+
+ Page + phpagi.php +
+
+
phpagi.php in phpagi.php
+
+
+ Page + phpagi_1.php +
+
+
phpagi_1.php in phpagi_1.php
+
+
+ Function + phpagi_error_handler +
+
+ +
error handler for phpagi.
+
+
+ Method + Ping +
+
+
AGI_AsteriskManager::Ping() in phpagi-asmanager.php
+
Ping
+
+
+ Method + process_event +
+
+
AGI_AsteriskManager::process_event() in phpagi-asmanager.php
+
Process event
+
+
+ +
+
q
+
top
+
+
+
+
+ Method + QueueAdd +
+
+
AGI_AsteriskManager::QueueAdd() in phpagi-asmanager.php
+
Queue Add
+
+
+ Method + QueueRemove +
+
+
AGI_AsteriskManager::QueueRemove() in phpagi-asmanager.php
+
Queue Remove
+
+
+ Method + Queues +
+
+
AGI_AsteriskManager::Queues() in phpagi-asmanager.php
+
Queues
+
+
+ Method + QueueStatus +
+
+
AGI_AsteriskManager::QueueStatus() in phpagi-asmanager.php
+
Queue Status
+
+
+ +
+
r
+
top
+
+
+
+
+ Variable + $request +
+
+
AGI::$request in phpagi.php
+
Request variables read in on initialization.
+
+
+ Variable + $response +
+
+
AGI_1::$response in phpagi_1.php
+
Response structure
+
+
+ Method + receive_char +
+
+
AGI::receive_char() in phpagi.php
+
Receive a character of text from a connected channel. Waits up to $timeout milliseconds for a character to arrive, or infinitely if $timeout is zero.
+
+
+ Method + record_file +
+
+
AGI::record_file() in phpagi.php
+
Record sound to a file until an acceptable DTMF digit is received or a specified amount of time has passed. Optionally the file BEEP is played before recording begins.
+
+
+ Method + Redirect +
+
+
AGI_AsteriskManager::Redirect() in phpagi-asmanager.php
+
Redirect
+
+
+ +
+
s
+
top
+
+
+
+
+ Variable + $server +
+
+
AGI_AsteriskManager::$server in phpagi-asmanager.php
+
Server we are connected to
+
+
+ Variable + $socket +
+
+
AGI_AsteriskManager::$socket in phpagi-asmanager.php
+
Socket
+
+
+ Method + say_digits +
+
+
AGI::say_digits() in phpagi.php
+
Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + say_number +
+
+
AGI::say_number() in phpagi.php
+
Say the given number, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + say_phonetic +
+
+
AGI::say_phonetic() in phpagi.php
+
Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + say_punctuation +
+
+ +
Say Puncutation in a string.
+
+
+ Method + say_time +
+
+
AGI::say_time() in phpagi.php
+
Say a given time, returning early if any of the given DTMF escape digits are received on the channel.
+
+
+ Method + send_image +
+
+
AGI_1::send_image() in phpagi_1.php
+
Send the specified image on a channel.
+
+
+ Method + send_image +
+
+
AGI::send_image() in phpagi.php
+
Send the specified image on a channel.
+
+
+ Method + send_request +
+
+
AGI_AsteriskManager::send_request() in phpagi-asmanager.php
+
Send a request
+
+
+ Method + send_text +
+
+
AGI::send_text() in phpagi.php
+
Send the given text to the connected channel.
+
+
+ Method + send_text +
+
+
AGI_1::send_text() in phpagi_1.php
+
Send the given text to the connected channel.
+
+
+ Method + SetCDRUserField +
+
+ +
Set the CDR UserField
+
+
+ Method + setContext +
+
+
AGI::setContext() in phpagi.php
+
setContext - Set context, extension and priority.
+
+
+ Method + SetVar +
+
+
AGI_AsteriskManager::SetVar() in phpagi-asmanager.php
+
Set Channel Variable
+
+
+ Method + set_autohangup +
+
+
AGI::set_autohangup() in phpagi.php
+
Cause the channel to automatically hangup at $time seconds in the future.
+
+
+ Method + set_callerid +
+
+
AGI::set_callerid() in phpagi.php
+
Changes the caller ID of the current channel.
+
+
+ Method + set_context +
+
+
AGI::set_context() in phpagi.php
+
Sets the context for continuation upon exiting the application.
+
+
+ Method + set_extension +
+
+
AGI::set_extension() in phpagi.php
+
Set the extension to be used for continuation upon exiting the application.
+
+
+ Method + set_global_var +
+
+
AGI::set_global_var() in phpagi.php
+
Sets a global variable, using Asterisk 1.6 syntax.
+
+
+ Method + set_music +
+
+
AGI::set_music() in phpagi.php
+
Enable/Disable Music on hold generator.
+
+
+ Method + set_priority +
+
+
AGI::set_priority() in phpagi.php
+
Set the priority to be used for continuation upon exiting the application.
+
+
+ Method + set_var +
+
+
AGI::set_var() in phpagi.php
+
Sets a variable, using Asterisk 1.6 syntax.
+
+
+ Method + set_var +
+
+
AGI_1::set_var() in phpagi_1.php
+
Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>} in the dialplan.
+
+
+ Method + set_variable +
+
+
AGI::set_variable() in phpagi.php
+
Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>} in the dialplan.
+
+
+ Method + Status +
+
+
AGI_AsteriskManager::Status() in phpagi-asmanager.php
+
Channel Status
+
+
+ Method + StopMonitor +
+
+
AGI_AsteriskManager::StopMonitor() in phpagi-asmanager.php
+
Stop monitoring a channel
+
+
+ Method + stream_file +
+
+
AGI::stream_file() in phpagi.php
+
Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.
+
+
+ Method + swift +
+
+
AGI::swift() in phpagi.php
+
Use Cepstral Swift to read text.
+
+
+ +
+
t
+
top
+
+
+
+
+ Method + tdd_mode +
+
+
AGI::tdd_mode() in phpagi.php
+
Enable or disable TDD transmission/reception on the current channel.
+
+
+ Method + text2wav +
+
+
AGI::text2wav() in phpagi.php
+
Use festival to read text.
+
+
+ Method + text_input +
+
+
AGI::text_input() in phpagi.php
+
Text Input.
+
+
+ +
+
v
+
top
+
+
+
+
+ Method + verbose +
+
+
AGI::verbose() in phpagi.php
+
Sends $message to the Asterisk console via the 'verbose' message system.
+
+
+ +
+
w
+
top
+
+
+
+
+ Method + wait_for_digit +
+
+
AGI::wait_for_digit() in phpagi.php
+
Waits up to $timeout milliseconds for channel to receive a DTMF digit.
+
+
+ Method + wait_response +
+
+
AGI_AsteriskManager::wait_response() in phpagi-asmanager.php
+
Wait for a response
+
+
+ Method + which +
+
+
AGI::which() in phpagi.php
+
Find an execuable in the path.
+
+
+ +
+
z
+
top
+
+
+
+
+ Method + ZapDialOffhook +
+
+ +
Dial over Zap channel while offhook
+
+
+ Method + ZapDNDoff +
+
+
AGI_AsteriskManager::ZapDNDoff() in phpagi-asmanager.php
+
Toggle Zap channel Do Not Disturb status OFF
+
+
+ Method + ZapDNDon +
+
+
AGI_AsteriskManager::ZapDNDon() in phpagi-asmanager.php
+
Toggle Zap channel Do Not Disturb status ON
+
+
+ Method + ZapHangup +
+
+
AGI_AsteriskManager::ZapHangup() in phpagi-asmanager.php
+
Hangup Zap Channel
+
+
+ Method + ZapShowChannels +
+
+ +
Zap Show Channels
+
+
+ Method + ZapTransfer +
+
+
AGI_AsteriskManager::ZapTransfer() in phpagi-asmanager.php
+
Transfer Zap Channel
+
+
+ +
+ a + c + d + e + f + g + h + i + l + m + n + o + p + q + r + s + t + v + w + z + _ +
+ \ No newline at end of file diff --git a/api-docs/errors.html b/api-docs/errors.html new file mode 100644 index 0000000..da40f5f --- /dev/null +++ b/api-docs/errors.html @@ -0,0 +1,20 @@ + + + + + + phpDocumentor Parser Errors and Warnings + + + + + Post-parsing
+ +

phpagi.php

+

Warnings:


+Warning on line 30 - Page-level DocBlock precedes "require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'phpagi-asmanager.php'", use another DocBlock to document the source element
+

+ Documentation generated on Thu, 30 Sep 2010 02:22:10 -0700 by phpDocumentor 1.4.2 +

+ + \ No newline at end of file diff --git a/api-docs/index.html b/api-docs/index.html new file mode 100644 index 0000000..024b0fa --- /dev/null +++ b/api-docs/index.html @@ -0,0 +1,24 @@ + + + + + + phpAGI + + + + + + + + + + + <H2>Frame Alert</H2> + <P>This document is designed to be viewed using the frames feature. + If you see this message, you are using a non-frame-capable web client.</P> + + + \ No newline at end of file diff --git a/api-docs/li_phpAGI.html b/api-docs/li_phpAGI.html new file mode 100644 index 0000000..893fcea --- /dev/null +++ b/api-docs/li_phpAGI.html @@ -0,0 +1,41 @@ + + + + + + + + + + +
phpAGI
+
+ +
+ +
Description
+
+ Class trees
+ Index of elements
+
+ + + +
 Classes
+
ClassAGI
+
ClassAGI_1
+
ClassAGI_AsteriskManager
+
 Functions
+
Functionphpagi_error_handler
+
 Files
+
Filephpagi-asmanager.php
+
Filephpagi-fastagi.php
+
Filephpagi.php
+
Filephpagi_1.php
+ + +
+
+

phpDocumentor v 1.4.2

+ + \ No newline at end of file diff --git a/api-docs/media/banner.css b/api-docs/media/banner.css new file mode 100644 index 0000000..032b037 --- /dev/null +++ b/api-docs/media/banner.css @@ -0,0 +1,33 @@ +body +{ + background-color: #EEEEEE; + margin: 0px; + padding: 0px; +} + +/* Banner (top bar) classes */ + +.banner { } + +.banner-menu +{ + text-align: right; + clear: both; + padding: .5em; + border-top: 2px solid #AAAAAA; +} + +.banner-title +{ + text-align: right; + font-size: 20pt; + font-weight: bold; + margin: .2em; +} + +.package-selector +{ + background-color: #DDDDDD; + border: 1px solid #AAAAAA; + color: #000090; +} diff --git a/api-docs/media/images/AbstractClass.png b/api-docs/media/images/AbstractClass.png new file mode 100644 index 0000000..afa9d1d --- /dev/null +++ b/api-docs/media/images/AbstractClass.png Binary files differ diff --git a/api-docs/media/images/AbstractClass_logo.png b/api-docs/media/images/AbstractClass_logo.png new file mode 100644 index 0000000..8f65c39 --- /dev/null +++ b/api-docs/media/images/AbstractClass_logo.png Binary files differ diff --git a/api-docs/media/images/AbstractMethod.png b/api-docs/media/images/AbstractMethod.png new file mode 100644 index 0000000..605ccbe --- /dev/null +++ b/api-docs/media/images/AbstractMethod.png Binary files differ diff --git a/api-docs/media/images/AbstractPrivateClass.png b/api-docs/media/images/AbstractPrivateClass.png new file mode 100644 index 0000000..53d76c6 --- /dev/null +++ b/api-docs/media/images/AbstractPrivateClass.png Binary files differ diff --git a/api-docs/media/images/AbstractPrivateClass_logo.png b/api-docs/media/images/AbstractPrivateClass_logo.png new file mode 100644 index 0000000..4e68f57 --- /dev/null +++ b/api-docs/media/images/AbstractPrivateClass_logo.png Binary files differ diff --git a/api-docs/media/images/AbstractPrivateMethod.png b/api-docs/media/images/AbstractPrivateMethod.png new file mode 100644 index 0000000..41cc9f0 --- /dev/null +++ b/api-docs/media/images/AbstractPrivateMethod.png Binary files differ diff --git a/api-docs/media/images/Class.png b/api-docs/media/images/Class.png new file mode 100644 index 0000000..cf548d2 --- /dev/null +++ b/api-docs/media/images/Class.png Binary files differ diff --git a/api-docs/media/images/Class_logo.png b/api-docs/media/images/Class_logo.png new file mode 100644 index 0000000..6f223c4 --- /dev/null +++ b/api-docs/media/images/Class_logo.png Binary files differ diff --git a/api-docs/media/images/Constant.png b/api-docs/media/images/Constant.png new file mode 100644 index 0000000..a9c6f28 --- /dev/null +++ b/api-docs/media/images/Constant.png Binary files differ diff --git a/api-docs/media/images/Constructor.png b/api-docs/media/images/Constructor.png new file mode 100644 index 0000000..3f16222 --- /dev/null +++ b/api-docs/media/images/Constructor.png Binary files differ diff --git a/api-docs/media/images/Destructor.png b/api-docs/media/images/Destructor.png new file mode 100644 index 0000000..f28528f --- /dev/null +++ b/api-docs/media/images/Destructor.png Binary files differ diff --git a/api-docs/media/images/Function.png b/api-docs/media/images/Function.png new file mode 100644 index 0000000..902fe25 --- /dev/null +++ b/api-docs/media/images/Function.png Binary files differ diff --git a/api-docs/media/images/Global.png b/api-docs/media/images/Global.png new file mode 100644 index 0000000..7281bd2 --- /dev/null +++ b/api-docs/media/images/Global.png Binary files differ diff --git a/api-docs/media/images/I.png b/api-docs/media/images/I.png new file mode 100644 index 0000000..e8512fb --- /dev/null +++ b/api-docs/media/images/I.png Binary files differ diff --git a/api-docs/media/images/Index.png b/api-docs/media/images/Index.png new file mode 100644 index 0000000..6558ec3 --- /dev/null +++ b/api-docs/media/images/Index.png Binary files differ diff --git a/api-docs/media/images/Interface.png b/api-docs/media/images/Interface.png new file mode 100644 index 0000000..e6cd51e --- /dev/null +++ b/api-docs/media/images/Interface.png Binary files differ diff --git a/api-docs/media/images/Interface_logo.png b/api-docs/media/images/Interface_logo.png new file mode 100644 index 0000000..6f223c4 --- /dev/null +++ b/api-docs/media/images/Interface_logo.png Binary files differ diff --git a/api-docs/media/images/L.png b/api-docs/media/images/L.png new file mode 100644 index 0000000..eb334ed --- /dev/null +++ b/api-docs/media/images/L.png Binary files differ diff --git a/api-docs/media/images/Lminus.png b/api-docs/media/images/Lminus.png new file mode 100644 index 0000000..f7c43c0 --- /dev/null +++ b/api-docs/media/images/Lminus.png Binary files differ diff --git a/api-docs/media/images/Lplus.png b/api-docs/media/images/Lplus.png new file mode 100644 index 0000000..848ec2f --- /dev/null +++ b/api-docs/media/images/Lplus.png Binary files differ diff --git a/api-docs/media/images/Method.png b/api-docs/media/images/Method.png new file mode 100644 index 0000000..9b21578 --- /dev/null +++ b/api-docs/media/images/Method.png Binary files differ diff --git a/api-docs/media/images/Page.png b/api-docs/media/images/Page.png new file mode 100644 index 0000000..ffe7986 --- /dev/null +++ b/api-docs/media/images/Page.png Binary files differ diff --git a/api-docs/media/images/Page_logo.png b/api-docs/media/images/Page_logo.png new file mode 100644 index 0000000..44ce0b3 --- /dev/null +++ b/api-docs/media/images/Page_logo.png Binary files differ diff --git a/api-docs/media/images/PrivateClass.png b/api-docs/media/images/PrivateClass.png new file mode 100644 index 0000000..470e6d5 --- /dev/null +++ b/api-docs/media/images/PrivateClass.png Binary files differ diff --git a/api-docs/media/images/PrivateClass_logo.png b/api-docs/media/images/PrivateClass_logo.png new file mode 100644 index 0000000..590e006 --- /dev/null +++ b/api-docs/media/images/PrivateClass_logo.png Binary files differ diff --git a/api-docs/media/images/PrivateMethod.png b/api-docs/media/images/PrivateMethod.png new file mode 100644 index 0000000..d01f2b3 --- /dev/null +++ b/api-docs/media/images/PrivateMethod.png Binary files differ diff --git a/api-docs/media/images/PrivateVariable.png b/api-docs/media/images/PrivateVariable.png new file mode 100644 index 0000000..d76b21d --- /dev/null +++ b/api-docs/media/images/PrivateVariable.png Binary files differ diff --git a/api-docs/media/images/StaticMethod.png b/api-docs/media/images/StaticMethod.png new file mode 100644 index 0000000..9b21578 --- /dev/null +++ b/api-docs/media/images/StaticMethod.png Binary files differ diff --git a/api-docs/media/images/StaticVariable.png b/api-docs/media/images/StaticVariable.png new file mode 100644 index 0000000..8e82019 --- /dev/null +++ b/api-docs/media/images/StaticVariable.png Binary files differ diff --git a/api-docs/media/images/T.png b/api-docs/media/images/T.png new file mode 100644 index 0000000..3017325 --- /dev/null +++ b/api-docs/media/images/T.png Binary files differ diff --git a/api-docs/media/images/Tminus.png b/api-docs/media/images/Tminus.png new file mode 100644 index 0000000..2260e42 --- /dev/null +++ b/api-docs/media/images/Tminus.png Binary files differ diff --git a/api-docs/media/images/Tplus.png b/api-docs/media/images/Tplus.png new file mode 100644 index 0000000..2c8d8f4 --- /dev/null +++ b/api-docs/media/images/Tplus.png Binary files differ diff --git a/api-docs/media/images/Variable.png b/api-docs/media/images/Variable.png new file mode 100644 index 0000000..8e82019 --- /dev/null +++ b/api-docs/media/images/Variable.png Binary files differ diff --git a/api-docs/media/images/blank.png b/api-docs/media/images/blank.png new file mode 100644 index 0000000..cee9cd3 --- /dev/null +++ b/api-docs/media/images/blank.png Binary files differ diff --git a/api-docs/media/images/class_folder.png b/api-docs/media/images/class_folder.png new file mode 100644 index 0000000..84e9587 --- /dev/null +++ b/api-docs/media/images/class_folder.png Binary files differ diff --git a/api-docs/media/images/empty.png b/api-docs/media/images/empty.png new file mode 100644 index 0000000..d568386 --- /dev/null +++ b/api-docs/media/images/empty.png Binary files differ diff --git a/api-docs/media/images/file.png b/api-docs/media/images/file.png new file mode 100644 index 0000000..0bb2427 --- /dev/null +++ b/api-docs/media/images/file.png Binary files differ diff --git a/api-docs/media/images/folder.png b/api-docs/media/images/folder.png new file mode 100644 index 0000000..a2d79f8 --- /dev/null +++ b/api-docs/media/images/folder.png Binary files differ diff --git a/api-docs/media/images/function_folder.png b/api-docs/media/images/function_folder.png new file mode 100644 index 0000000..8b3d6e3 --- /dev/null +++ b/api-docs/media/images/function_folder.png Binary files differ diff --git a/api-docs/media/images/next_button.png b/api-docs/media/images/next_button.png new file mode 100644 index 0000000..cdbc615 --- /dev/null +++ b/api-docs/media/images/next_button.png Binary files differ diff --git a/api-docs/media/images/next_button_disabled.png b/api-docs/media/images/next_button_disabled.png new file mode 100644 index 0000000..4a11780 --- /dev/null +++ b/api-docs/media/images/next_button_disabled.png Binary files differ diff --git a/api-docs/media/images/package.png b/api-docs/media/images/package.png new file mode 100644 index 0000000..b04cf56 --- /dev/null +++ b/api-docs/media/images/package.png Binary files differ diff --git a/api-docs/media/images/package_folder.png b/api-docs/media/images/package_folder.png new file mode 100644 index 0000000..6162baf --- /dev/null +++ b/api-docs/media/images/package_folder.png Binary files differ diff --git a/api-docs/media/images/previous_button.png b/api-docs/media/images/previous_button.png new file mode 100644 index 0000000..327fdbc --- /dev/null +++ b/api-docs/media/images/previous_button.png Binary files differ diff --git a/api-docs/media/images/previous_button_disabled.png b/api-docs/media/images/previous_button_disabled.png new file mode 100644 index 0000000..c02ff64 --- /dev/null +++ b/api-docs/media/images/previous_button_disabled.png Binary files differ diff --git a/api-docs/media/images/private_class_logo.png b/api-docs/media/images/private_class_logo.png new file mode 100644 index 0000000..590e006 --- /dev/null +++ b/api-docs/media/images/private_class_logo.png Binary files differ diff --git a/api-docs/media/images/tutorial.png b/api-docs/media/images/tutorial.png new file mode 100644 index 0000000..bc19737 --- /dev/null +++ b/api-docs/media/images/tutorial.png Binary files differ diff --git a/api-docs/media/images/tutorial_folder.png b/api-docs/media/images/tutorial_folder.png new file mode 100644 index 0000000..2a468b2 --- /dev/null +++ b/api-docs/media/images/tutorial_folder.png Binary files differ diff --git a/api-docs/media/images/up_button.png b/api-docs/media/images/up_button.png new file mode 100644 index 0000000..ff36c59 --- /dev/null +++ b/api-docs/media/images/up_button.png Binary files differ diff --git a/api-docs/media/stylesheet.css b/api-docs/media/stylesheet.css new file mode 100644 index 0000000..96729b6 --- /dev/null +++ b/api-docs/media/stylesheet.css @@ -0,0 +1,146 @@ +a { color: #000090; text-decoration: none; } +a:hover, a:active, a:focus { color: highlighttext; background-color: highlight; text-decoration: none; } + +body { background: #FFFFFF; } +body, table { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; } + +a img { border: 0px; } + +/* Page layout/boxes */ + +.info-box { } +.info-box-title { margin: 1em 0em 0em 0em; font-weight: normal; font-size: 14pt; color: #999999; border-bottom: 2px solid #999999; } +.info-box-body { border: 1px solid #999999; padding: .5em; } +.nav-bar { font-size: 8pt; white-space: nowrap; text-align: right; padding: .2em; margin: 0em 0em 1em 0em; } + +.oddrow { background-color: #F8F8F8; border: 1px solid #AAAAAA; padding: .5em; margin-bottom: 1em} +.evenrow { border: 1px solid #AAAAAA; padding: .5em; margin-bottom: 1em} + +.page-body { max-width: 800px; margin: auto; } +.tree { white-space: nowrap; font: icon } +.tree dd { margin-left: 19px } +.tree dl { margin: 0px } +.tree-icon { vertical-align: middle; border: 0px; margin-right: 3px } + +/* Index formatting classes */ + +.index-item-body { margin-top: .5em; margin-bottom: .5em} +.index-item-description { margin-top: .25em } +.index-item-details { font-weight: normal; font-style: italic; font-size: 8pt } +.index-letter-section { background-color: #EEEEEE; border: 1px dotted #999999; padding: .5em; margin-bottom: 1em} +.index-letter-title { font-size: 12pt; font-weight: bold } +.index-letter-menu { text-align: center; margin: 1em } +.index-letter { font-size: 12pt } + +/* Docbook classes */ + +.description {} +.short-description { font-weight: bold; color: #666666; } +.tags { padding-left: 0em; margin-left: 3em; color: #666666; list-style-type: square; } +.parameters { padding-left: 0em; margin-left: 3em; color: #014fbe; list-style-type: square; } +.redefinitions { font-size: 8pt; padding-left: 0em; margin-left: 2em; } +.package { font-weight: bold; } +.package-title { font-weight: bold; font-size: 14pt; border-bottom: 1px solid black } +.package-details { font-size: 85%; } +.sub-package { font-weight: bold; } +.tutorial { border-width: thin; border-color: #0066ff; } +.tutorial-nav-box { width: 100%; border: 1px solid #999999; background-color: #F8F8F8; } +.folder-title { font-style: italic; font-family: Verdana, Arial, Helvetica, sans-serif } + +/* Generic formatting */ + +.field { font-weight: bold; } +.detail { font-size: 8pt; } +.notes { font-style: italic; font-size: 8pt; } +.separator { background-color: #999999; height: 2px; } +.warning { color: #FF6600; } +.disabled { font-style: italic; color: #999999; } + +/* Code elements */ + +.line-number { } + +.class-table { width: 100%; } +.class-table-header { border-bottom: 1px dotted #666666; text-align: left} +.class-name { color: #0000AA; font-weight: bold; } + +.method-summary { color: #009000; padding-left: 1em; font-size: 8pt; } +.method-header { } +.method-definition { margin-bottom: .2em } +.method-title { color: #009000; font-weight: bold; } +.method-name { font-weight: bold; } +.method-signature { font-size: 85%; color: #666666; margin: .5em 0em } +.method-result { font-style: italic; } + +.var-summary { padding-left: 1em; font-size: 8pt; } +.var-header { } +.var-title { color: #014fbe; margin-bottom: .3em } +.var-type { font-style: italic; } +.var-name { font-weight: bold; } +.var-default {} +.var-description { font-weight: normal; color: #000000; } + +.include-title { color: #014fbe;} +.include-type { font-style: italic; } +.include-name { font-weight: bold; } + +.const-title { color: #FF6600; } +.const-name { font-weight: bold; } + +/* Syntax highlighting */ + +.src-code { font-family: 'Courier New', Courier, monospace; font-weight: normal; } +.src-line { font-family: 'Courier New', Courier, monospace; font-weight: normal; } + +.src-code a:link { padding: 1px; text-decoration: underline; color: #0000DD; } +.src-code a:visited { text-decoration: underline; color: #0000DD; } +.src-code a:active { background-color: #FFFF66; color: #008000; } +.src-code a:hover { background-color: #FFFF66; text-decoration: overline underline; color: #008000; } + +.src-comm { color: #666666; } +.src-id { color: #FF6600; font-style: italic; } +.src-inc { color: #0000AA; font-weight: bold; } +.src-key { color: #0000AA; font-weight: bold; } +.src-num { color: #CC0000; } +.src-str { color: #CC0000; } +.src-sym { } +.src-var { } + +.src-php { font-weight: bold; } + +.src-doc { color: #666666; } +.src-doc-close-template { color: #666666 } +.src-doc-coretag { color: #008000; } +.src-doc-inlinetag {} +.src-doc-internal {} +.src-doc-tag { color: #0080CC; } +.src-doc-template { color: #666666 } +.src-doc-type { font-style: italic; color: #444444 } +.src-doc-var { color: #444444 } + +.tute-tag { color: #009999 } +.tute-attribute-name { color: #0000FF } +.tute-attribute-value { color: #0099FF } +.tute-entity { font-weight: bold; } +.tute-comment { font-style: italic } +.tute-inline-tag { color: #636311; font-weight: bold } + +/* tutorial */ + +.authors { } +.author { font-style: italic; font-weight: bold } +.author-blurb { margin: .5em 0em .5em 2em; font-size: 85%; font-weight: normal; font-style: normal } +.example { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; } +*[class="example"] { line-height : 1.0em; } +.listing { border: 1px dashed #999999; background-color: #EEEEEE; padding: .5em; white-space: nowrap; } +*[class="listing"] { line-height : 1.0em; } +.release-info { font-size: 85%; font-style: italic; margin: 1em 0em } +.ref-title-box { } +.ref-title { } +.ref-purpose { font-style: italic; color: #666666 } +.ref-synopsis { } +.title { font-weight: bold; border-bottom: 1px solid #999999; color: #999999; } +.cmd-synopsis { margin: 1em 0em } +.cmd-title { font-weight: bold } +.toc { margin-left: 2em; padding-left: 0em } + diff --git a/api-docs/packages.html b/api-docs/packages.html new file mode 100644 index 0000000..c249963 --- /dev/null +++ b/api-docs/packages.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api-docs/phpAGI/AGI.html b/api-docs/phpAGI/AGI.html new file mode 100644 index 0000000..4ad1546 --- /dev/null +++ b/api-docs/phpAGI/AGI.html @@ -0,0 +1,2893 @@ + + + + + + Docs For Class AGI + + + + +
+

 Class AGI

+ + +
+
Description
+ + +
+ + +
+
Direct descendents
+ +
+ + + + + + + + + +
ClassDescription
+  class + AGI_1 + + Asterisk Manager class +
+
+
+ + + +
+
Variable Summary
+ +
+
+ +
+  + mixed + $audio +
+
+  + array + $config +
+
+  + mixed + $in +
+
+  + mixed + $option_delim +
+
+  + mixed + $out +
+
+  + array + $request +
+
+
+
+ + +
+
Method Summary
+ +
+
+
+  + AGI + __construct + ([string $config = NULL], [array $optconfig = array()]) +
+
+  + array, + answer + () +
+
+  + array, + channel_status + ([string $channel = '']) +
+
+  + void + conlog + (string $str, [integer $vbl = 1]) +
+
+  + array, + database_del + (string $family, string $key) +
+
+  + array, + database_deltree + (string $family, [string $keytree = '']) +
+
+  + array, + database_get + (string $family, string $key) +
+
+  + array, + database_put + (string $family, string $key, string $value) +
+
+  + array + evaluate + (string $command) +
+
+  + array, + exec + (string $application, mixed $options) +
+
+  + array, + exec_absolutetimeout + ([$seconds $seconds = 0]) +
+
+  + array, + exec_agi + (string $command, string $args) +
+
+  + array, + exec_dial + (string $type, string $identifier, [integer $timeout = NULL], [string $options = NULL], [string $url = NULL]) +
+
+  + array, + exec_enumlookup + ($exten $exten) +
+
+  + array, + exec_goto + (string $a, [ $b = NULL], [ $c = NULL], string $b;, string $c;) +
+
+  + array, + exec_setlanguage + ([string $language = 'en']) +
+
+  + array, + fastpass_get_data + ( &$buffer, string $filename, [integer $timeout = NULL], [integer $max_digits = NULL], string $buffer) +
+
+  + array, + fastpass_say_digits + ( &$buffer, integer $digits, [string $escape_digits = ''], string $buffer) +
+
+  + array, + fastpass_say_number + ( &$buffer, integer $number, [string $escape_digits = ''], string $buffer) +
+
+  + array, + fastpass_say_phonetic + ( &$buffer, string $text, [string $escape_digits = ''], string $buffer) +
+
+  + array, + fastpass_say_punctuation + ( &$buffer, string $text, [string $escape_digits = ''], [integer $frequency = 8000], string $buffer) +
+
+  + array, + fastpass_say_time + ( &$buffer, [integer $time = NULL], [string $escape_digits = ''], string $buffer) +
+
+  + array, + fastpass_stream_file + ( &$buffer, string $filename, [string $escape_digits = ''], [integer $offset = 0], string $buffer) +
+
+  + array, + fastpass_swift + ( &$buffer, string $text, [string $escape_digits = ''], [integer $frequency = 8000], [ $voice = NULL], string $buffer) +
+
+  + array, + fastpass_text2wav + ( &$buffer, string $text, [string $escape_digits = ''], [integer $frequency = 8000], string $buffer) +
+
+  + array, + get_data + (string $filename, [integer $timeout = NULL], [integer $max_digits = NULL]) +
+
+  + array, + get_fullvariable + (string $variable, [string $channel = FALSE], [boolean $getvalue = FALSE]) +
+
+  + array, + get_variable + (string $variable, [boolean $getvalue = FALSE]) +
+
+  + array, + hangup + ([string $channel = '']) +
+
+  + boolean + make_folder + (string $folder, [integer $perms = 0755]) +
+
+  + mixed + menu + (array $choices, [ $timeout = 2000]) +
+
+  + void + &new_AsteriskManager + () +
+
+  + array, + noop + ([ $string = ""]) +
+
+  + array('Name'=>$name, + parse_callerid + ([string $callerid = NULL]) +
+
+  + array, + receive_char + ([integer $timeout = -1]) +
+
+  + array, + record_file + (string $file, string $format, [string $escape_digits = ''], [integer $timeout = -1], [integer $offset = NULL], [boolean $beep = false], [integer $silence = NULL]) +
+
+  + array, + say_digits + (integer $digits, [string $escape_digits = '']) +
+
+  + array, + say_number + (integer $number, [string $escape_digits = '']) +
+
+  + array, + say_phonetic + (string $text, [string $escape_digits = '']) +
+
+  + array, + say_punctuation + (string $text, [string $escape_digits = ''], [integer $frequency = 8000]) +
+
+  + array, + say_time + ([integer $time = NULL], [string $escape_digits = '']) +
+
+  + array, + send_image + (string $image) +
+
+  + array, + send_text + ($text $text) +
+
+  + void + setContext + (string $context, [string $extension = 's'], [string $priority = 1]) +
+
+  + array, + set_autohangup + ([integer $time = 0]) +
+
+  + array, + set_callerid + (string $cid) +
+
+  + array, + set_context + (string $context) +
+
+  + array, + set_extension + (string $extension) +
+
+  + array, + set_global_var + (string $pVariable, string|int|float $pValue) +
+
+  + array, + set_music + ([boolean $enabled = true], [string $class = '']) +
+
+  + array, + set_priority + (integer $priority) +
+
+  + array, + set_var + (string $pVariable, string|int|float $pValue) +
+
+  + array, + set_variable + (string $variable, string $value) +
+
+  + array, + stream_file + (string $filename, [string $escape_digits = ''], [integer $offset = 0]) +
+
+  + array, + swift + (string $text, [string $escape_digits = ''], [integer $frequency = 8000], [ $voice = NULL]) +
+
+  + array, + tdd_mode + (string $setting) +
+
+  + array, + text2wav + (string $text, [string $escape_digits = ''], [integer $frequency = 8000]) +
+
+  + string + text_input + ([ $mode = 'NUMERIC']) +
+
+  + array, + verbose + (string $message, [integer $level = 1]) +
+
+  + array, + wait_for_digit + ([integer $timeout = -1]) +
+
+  + string + which + (string $cmd, [string $checkpath = NULL]) +
+
+
+
+ + +
+
Variables
+ +
+ + +
+ +
+ + + AGI_AsteriskManager + $asmanager + (line 108) + +
+ + +

Asterisk Manager

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + mixed + $audio + = NULL (line 129) + +
+ + +

Audio Stream

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + array + $config + (line 100) + +
+ + +

Config variables

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + mixed + $in + = NULL (line 115) + +
+ + +

Input Stream

+
    +
  • access: private
  • +
+ + + + + +
+ +
+ +
+ + + mixed + $option_delim + = "," (line 137) + +
+ + +

Application option delimiter

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + mixed + $out + = NULL (line 122) + +
+ + +

Output Stream

+
    +
  • access: private
  • +
+ + + + + +
+ +
+ +
+ + + array + $request + (line 92) + +
+ + +

Request variables read in on initialization.

+

Often contains any/all of the following: agi_request - name of agi script agi_channel - current channel agi_language - current language agi_type - channel type (SIP, ZAP, IAX, ...) agi_uniqueid - unique id based on unix time agi_callerid - callerID string agi_dnid - dialed number id agi_rdnis - referring DNIS number agi_context - current context agi_extension - extension dialed agi_priority - current priority agi_enhanced - value is 1.0 if started as an EAGI script agi_accountcode - set by SetAccount in the dialplan agi_network - value is yes if this is a fastagi agi_network_script - name of the script to execute

NOTE: program arguments are still in $_SERVER['argv'].

+
    +
  • access: public
  • +
+ + + + + +
+ +
+
+ + +
+
Methods
+ +
+ + +
+ +
+ + Constructor __construct (line 145) +
+ + +

Constructor

+ +
+ AGI + + __construct + + ([string $config = NULL], [array $optconfig = array()]) +
+ +
    +
  • + string + $config: is the name of the config file to parse
  • +
  • + array + $optconfig: is an array of configuration vars and vals, stuffed into $this->config['phpagi']
  • +
+ + +
+ +
+ +
+ + answer (line 231) +
+ + +

Answer channel if not already in answer state.

+ + +
+ array, + + answer + + () +
+ + + +
+ +
+ +
+ + channel_status (line 243) +
+ + +

Get the status of the specified channel. If no channel name is specified, return the status of the current channel.

+ + +
+ array, + + channel_status + + ([string $channel = '']) +
+ +
    +
  • + string + $channel
  • +
+ + +
+ +
+ +
+ + conlog (line 1667) +
+ + +

Log to console if debug mode.

+ + +
+ void + + conlog + + (string $str, [integer $vbl = 1]) +
+ +
    +
  • + string + $str
  • +
  • + integer + $vbl: verbose level
  • +
+ + +
+ +
+ +
+ + database_del (line 272) +
+ + +

Deletes an entry in the Asterisk database for a given family and key.

+ + +
+ array, + + database_del + + (string $family, string $key) +
+ +
    +
  • + string + $family
  • +
  • + string + $key
  • +
+ + +
+ +
+ +
+ + database_deltree (line 285) +
+ + +

Deletes a family or specific keytree within a family in the Asterisk database.

+ + +
+ array, + + database_deltree + + (string $family, [string $keytree = '']) +
+ +
    +
  • + string + $family
  • +
  • + string + $keytree
  • +
+ + +
+ +
+ +
+ + database_get (line 300) +
+ + +

Retrieves an entry in the Asterisk database for a given family and key.

+ + +
+ array, + + database_get + + (string $family, string $key) +
+ +
    +
  • + string + $family
  • +
  • + string + $key
  • +
+ + +
+ +
+ +
+ + database_put (line 313) +
+ + +

Adds or updates an entry in the Asterisk database for a given family, key, and value.

+
    +
  • return: see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise
  • +
+ +
+ array, + + database_put + + (string $family, string $key, string $value) +
+ +
    +
  • + string + $family
  • +
  • + string + $key
  • +
  • + string + $value
  • +
+ + +
+ +
+ +
+ + evaluate (line 1571) +
+ + +

Evaluate an AGI command.

+
    +
  • return: ('code'=>$code, 'result'=>$result, 'data'=>$data)
  • +
  • access: private
  • +
+ +
+ array + + evaluate + + (string $command) +
+ +
    +
  • + string + $command
  • +
+ + +
+ +
+ +
+ + exec (line 365) +
+ + +

Executes the specified Asterisk application with given options.

+ + +
+ array, + + exec + + (string $application, mixed $options) +
+ +
    +
  • + string + $application
  • +
  • + mixed + $options
  • +
+ + +
+ +
+ +
+ + exec_absolutetimeout (line 821) +
+ + +

Set absolute maximum time of call.

+

Note that the timeout is set from the current time forward, not counting the number of seconds the call has already been up. Each time you call AbsoluteTimeout(), all previous absolute timeouts are cancelled. Will return the call to the T extension so that you can playback an explanatory note to the calling party (the called party will not hear that)

+ + +
+ array, + + exec_absolutetimeout + + ([$seconds $seconds = 0]) +
+ +
    +
  • + $seconds + $seconds: allowed, 0 disables timeout
  • +
+ + +
+ +
+ +
+ + exec_agi (line 833) +
+ + +

Executes an AGI compliant application.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or if application requested hangup, or 0 on non-hangup exit.
  • +
+ +
+ array, + + exec_agi + + (string $command, string $args) +
+ +
    +
  • + string + $command
  • +
  • + string + $args
  • +
+ + +
+ +
+ +
+ + exec_dial (line 879) +
+ + +

Dial.

+

Dial takes input from ${VXML_URL} to send XML Url to Cisco 7960 Dial takes input from ${ALERT_INFO} to set ring cadence for Cisco phones Dial returns ${CAUSECODE}: If the dial failed, this is the errormessage. Dial returns ${DIALSTATUS}: Text code returning status of last dial attempt.

+ + +
+ array, + + exec_dial + + (string $type, string $identifier, [integer $timeout = NULL], [string $options = NULL], [string $url = NULL]) +
+ +
    +
  • + string + $type
  • +
  • + string + $identifier
  • +
  • + integer + $timeout
  • +
  • + string + $options
  • +
  • + string + $url
  • +
+ + +
+ +
+ +
+ + exec_enumlookup (line 858) +
+ + +

Do ENUM Lookup.

+

Note: to retrieve the result, use get_variable('ENUM');

+
    +
  • return: see evaluate for return information.
  • +
+ +
+ array, + + exec_enumlookup + + ($exten $exten) +
+ +
    +
  • + $exten + $exten
  • +
+ + +
+ +
+ +
+ + exec_goto (line 895) +
+ + +

Goto.

+

This function takes three arguments: context,extension, and priority, but the leading arguments are optional, not the trailing arguments. Thuse goto($z) sets the priority to $z.

+
    +
  • return: see evaluate for return information.
  • +
+ +
+ array, + + exec_goto + + (string $a, [ $b = NULL], [ $c = NULL], string $b;, string $c;) +
+ +
    +
  • + string + $a
  • +
  • + string + $b;
  • +
  • + string + $c;
  • +
  • + + $b
  • +
  • + + $c
  • +
+ + +
+ +
+ +
+ + exec_setlanguage (line 844) +
+ + +

Set Language.

+
    +
  • return: see evaluate for return information.
  • +
+ +
+ array, + + exec_setlanguage + + ([string $language = 'en']) +
+ +
    +
  • + string + $language: code
  • +
+ + +
+ +
+ +
+ + fastpass_get_data (line 1176) +
+ + +

Plays the given file and receives DTMF data.

+

Return early if $buffer is adequate for request.

This is similar to STREAM FILE, but this command can accept and return many DTMF digits, while STREAM FILE returns immediately after the first DTMF digit is detected.

Asterisk looks for the file to play in /var/lib/asterisk/sounds by default.

If the user doesn't press any keys when the message plays, there is $timeout milliseconds of silence then the command ends.

The user has the opportunity to press a key at any time during the message or the post-message silence. If the user presses a key while the message is playing, the message stops playing. When the first key is pressed a timer starts counting for $timeout milliseconds. Every time the user presses another key the timer is restarted. The command ends when the counter goes to zero or the maximum number of digits is entered, whichever happens first.

If you don't specify a time out then a default timeout of 2000 is used following a pressed digit. If no digits are pressed then 6 seconds of silence follow the message.

If you don't specify $max_digits then the user can enter as many digits as they want.

Pressing the # key has the same effect as the timer running out: the command ends and any previously keyed digits are returned. A side effect of this is that there is no way to read a # key using this command.

+
    +
  • return:

    see evaluate for return information. ['result'] holds the digits and ['data'] holds the timeout if present.

    This differs from other commands with return DTMF as numbers representing ASCII characters.

  • +
  • link: http://www.voip-info.org/wiki-get+data
  • +
+ +
+ array, + + fastpass_get_data + + ( &$buffer, string $filename, [integer $timeout = NULL], [integer $max_digits = NULL], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + string + $filename: file to play. Do not include file extension.
  • +
  • + integer + $timeout: milliseconds
  • +
  • + integer + $max_digits
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + fastpass_say_digits (line 916) +
+ + +

Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.

+

Return early if $buffer is adequate for request.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+digits
  • +
+ +
+ array, + + fastpass_say_digits + + ( &$buffer, integer $digits, [string $escape_digits = ''], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + integer + $digits
  • +
  • + string + $escape_digits
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + fastpass_say_number (line 945) +
+ + +

Say the given number, returning early if any of the given DTMF escape digits are received on the channel.

+

Return early if $buffer is adequate for request.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+number
  • +
+ +
+ array, + + fastpass_say_number + + ( &$buffer, integer $number, [string $escape_digits = ''], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + integer + $number
  • +
  • + string + $escape_digits
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + fastpass_say_phonetic (line 974) +
+ + +

Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.

+

Return early if $buffer is adequate for request.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+phonetic
  • +
+ +
+ array, + + fastpass_say_phonetic + + ( &$buffer, string $text, [string $escape_digits = ''], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + fastpass_say_punctuation (line 1121) +
+ + +

Say Puncutation in a string.

+

Return early if $buffer is adequate for request.

+
    +
  • return: see evaluate for return information.
  • +
+ +
+ array, + + fastpass_say_punctuation + + ( &$buffer, string $text, [string $escape_digits = ''], [integer $frequency = 8000], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
  • + integer + $frequency
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + fastpass_say_time (line 1003) +
+ + +

Say a given time, returning early if any of the given DTMF escape digits are received on the channel.

+

Return early if $buffer is adequate for request.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+time
  • +
+ +
+ array, + + fastpass_say_time + + ( &$buffer, [integer $time = NULL], [string $escape_digits = ''], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + integer + $time: number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
  • +
  • + string + $escape_digits
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + fastpass_stream_file (line 1035) +
+ + +

Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.

+

Return early if $buffer is adequate for request.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-stream+file
  • +
+ +
+ array, + + fastpass_stream_file + + ( &$buffer, string $filename, [string $escape_digits = ''], [integer $offset = 0], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + string + $filename: without extension, often in /var/lib/asterisk/sounds
  • +
  • + string + $escape_digits
  • +
  • + integer + $offset
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + fastpass_swift (line 1093) +
+ + +

Use Cepstral Swift to read text.

+

Return early if $buffer is adequate for request.

+ + +
+ array, + + fastpass_swift + + ( &$buffer, string $text, [string $escape_digits = ''], [integer $frequency = 8000], [ $voice = NULL], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
  • + integer + $frequency
  • +
  • + + &$buffer
  • +
  • + + $voice
  • +
+ + +
+ +
+ +
+ + fastpass_text2wav (line 1064) +
+ + +

Use festival to read text.

+

Return early if $buffer is adequate for request.

+ + +
+ array, + + fastpass_text2wav + + ( &$buffer, string $text, [string $escape_digits = ''], [integer $frequency = 8000], string $buffer) +
+ +
    +
  • + string + $buffer
  • +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
  • + integer + $frequency
  • +
  • + + &$buffer
  • +
+ + +
+ +
+ +
+ + get_data (line 408) +
+ + +

Plays the given file and receives DTMF data.

+

This is similar to STREAM FILE, but this command can accept and return many DTMF digits, while STREAM FILE returns immediately after the first DTMF digit is detected.

Asterisk looks for the file to play in /var/lib/asterisk/sounds by default.

If the user doesn't press any keys when the message plays, there is $timeout milliseconds of silence then the command ends.

The user has the opportunity to press a key at any time during the message or the post-message silence. If the user presses a key while the message is playing, the message stops playing. When the first key is pressed a timer starts counting for $timeout milliseconds. Every time the user presses another key the timer is restarted. The command ends when the counter goes to zero or the maximum number of digits is entered, whichever happens first.

If you don't specify a time out then a default timeout of 2000 is used following a pressed digit. If no digits are pressed then 6 seconds of silence follow the message.

If you don't specify $max_digits then the user can enter as many digits as they want.

Pressing the # key has the same effect as the timer running out: the command ends and any previously keyed digits are returned. A side effect of this is that there is no way to read a # key using this command.

+
    +
  • return:

    see evaluate for return information. ['result'] holds the digits and ['data'] holds the timeout if present.

    This differs from other commands with return DTMF as numbers representing ASCII characters.

  • +
  • link: http://www.voip-info.org/wiki-get+data
  • +
  • example: Ping an IP address
  • +
+ +
+ array, + + get_data + + (string $filename, [integer $timeout = NULL], [integer $max_digits = NULL]) +
+ +
    +
  • + string + $filename: file to play. Do not include file extension.
  • +
  • + integer + $timeout: milliseconds
  • +
  • + integer + $max_digits
  • +
+ + +
+ +
+ +
+ + get_fullvariable (line 446) +
+ + +

Fetch the value of a full variable.

+ + +
+ array, + + get_fullvariable + + (string $variable, [string $channel = FALSE], [boolean $getvalue = FALSE]) +
+ +
    +
  • + string + $variable: name
  • +
  • + string + $channel: channel
  • +
  • + boolean + $getvalue: return the value only
  • +
+ + +
+ +
+ +
+ + get_variable (line 424) +
+ + +

Fetch the value of a variable.

+

Does not work with global variables. Does not work with some variables that are generated by modules.

+ + +
+ array, + + get_variable + + (string $variable, [boolean $getvalue = FALSE]) +
+ +
    +
  • + string + $variable: name
  • +
  • + boolean + $getvalue: return the value only
  • +
+ + +
+ +
+ +
+ + hangup (line 477) +
+ + +

Hangup the specified channel. If no channel name is given, hang up the current channel.

+

With power comes responsibility. Hanging up channels other than your own isn't something that is done routinely. If you are not sure why you are doing so, then don't.

+ + +
+ array, + + hangup + + ([string $channel = '']) +
+ +
    +
  • + string + $channel
  • +
+ + +
+ +
+ +
+ + make_folder (line 1713) +
+ + +

Make a folder recursively.

+
    +
  • access: private
  • +
+ +
+ boolean + + make_folder + + (string $folder, [integer $perms = 0755]) +
+ +
    +
  • + string + $folder
  • +
  • + integer + $perms
  • +
+ + +
+ +
+ +
+ + menu (line 1216) +
+ + +

Menu.

+

This function presents the user with a menu and reads the response

+
    +
  • return: key pressed on sucess, -1 on failure
  • +
+ +
+ mixed + + menu + + (array $choices, [ $timeout = 2000]) +
+ +
    +
  • + array + $choices: has the following structure: array('1'=>'*Press 1 for this', // festival reads if prompt starts with * '2'=>'some-gsm-without-extension', '*'=>'*Press star for help');
  • +
  • + + $timeout
  • +
+ + +
+ +
+ +
+ + new_AsteriskManager (line 1550) +
+ + +

Create a new AGI_AsteriskManager.

+ +
+ void + + &new_AsteriskManager + + () +
+ + + +
+ +
+ +
+ + noop (line 488) +
+ + +

Does nothing.

+ + +
+ array, + + noop + + ([ $string = ""]) +
+ +
    +
  • + + $string
  • +
+ + +
+ +
+ +
+ + parse_callerid (line 1279) +
+ + +

Parse caller id.

+ + +
+ array('Name'=>$name, + + parse_callerid + + ([string $callerid = NULL]) +
+ +
    +
  • + string + $callerid
  • +
+ + +
+ +
+ +
+ + receive_char (line 502) +
+ + +

Receive a character of text from a connected channel. Waits up to $timeout milliseconds for a character to arrive, or infinitely if $timeout is zero.

+
    +
  • return: see evaluate for return information. ['result'] is 0 on timeout or not supported, -1 on failure. Otherwise it is the decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-receive+char
  • +
+ +
+ array, + + receive_char + + ([integer $timeout = -1]) +
+ +
    +
  • + integer + $timeout: milliseconds
  • +
+ + +
+ +
+ +
+ + record_file (line 523) +
+ + +

Record sound to a file until an acceptable DTMF digit is received or a specified amount of time has passed. Optionally the file BEEP is played before recording begins.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on error, 0 on hangup, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-record+file
  • +
+ +
+ array, + + record_file + + (string $file, string $format, [string $escape_digits = ''], [integer $timeout = -1], [integer $offset = NULL], [boolean $beep = false], [integer $silence = NULL]) +
+ +
    +
  • + string + $file: to record, without extension, often created in /var/lib/asterisk/sounds
  • +
  • + string + $format: of the file. GSM and WAV are commonly used formats. MP3 is read-only and thus cannot be used.
  • +
  • + string + $escape_digits
  • +
  • + integer + $timeout: is the maximum record time in milliseconds, or -1 for no timeout.
  • +
  • + integer + $offset: to seek to without exceeding the end of the file.
  • +
  • + boolean + $beep
  • +
  • + integer + $silence: number of seconds of silence allowed before the function returns despite the lack of dtmf digits or reaching timeout.
  • +
+ + +
+ +
+ +
+ + say_digits (line 540) +
+ + +

Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+digits
  • +
+ +
+ array, + + say_digits + + (integer $digits, [string $escape_digits = '']) +
+ +
    +
  • + integer + $digits
  • +
  • + string + $escape_digits
  • +
+ + +
+ +
+ +
+ + say_number (line 554) +
+ + +

Say the given number, returning early if any of the given DTMF escape digits are received on the channel.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+number
  • +
+ +
+ array, + + say_number + + (integer $number, [string $escape_digits = '']) +
+ +
    +
  • + integer + $number
  • +
  • + string + $escape_digits
  • +
+ + +
+ +
+ +
+ + say_phonetic (line 568) +
+ + +

Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+phonetic
  • +
+ +
+ array, + + say_phonetic + + (string $text, [string $escape_digits = '']) +
+ +
    +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
+ + +
+ +
+ +
+ + say_punctuation (line 1501) +
+ + +

Say Puncutation in a string.

+
    +
  • return: see evaluate for return information.
  • +
+ +
+ array, + + say_punctuation + + (string $text, [string $escape_digits = ''], [integer $frequency = 8000]) +
+ +
    +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
  • + integer + $frequency
  • +
+ + +
+ +
+ +
+ + say_time (line 582) +
+ + +

Say a given time, returning early if any of the given DTMF escape digits are received on the channel.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-say+time
  • +
+ +
+ array, + + say_time + + ([integer $time = NULL], [string $escape_digits = '']) +
+ +
    +
  • + integer + $time: number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
  • +
  • + string + $escape_digits
  • +
+ + +
+ +
+ +
+ + send_image (line 598) +
+ + +

Send the specified image on a channel.

+

Most channels do not support the transmission of images.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the image is sent or channel does not support image transmission.
  • +
  • link: http://www.voip-info.org/wiki-send+image
  • +
+ +
+ array, + + send_image + + (string $image) +
+ +
    +
  • + string + $image: without extension, often in /var/lib/asterisk/images
  • +
+ + +
+
Redefined in descendants as:
+ +
+ +
+ +
+ + send_text (line 613) +
+ + +

Send the given text to the connected channel.

+

Most channels do not support transmission of text.

+
    +
  • return: see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the text is sent or channel does not support text transmission.
  • +
  • link: http://www.voip-info.org/wiki-send+text
  • +
+ +
+ array, + + send_text + + ($text $text) +
+ +
    +
  • + $text + $text
  • +
+ + +
+
Redefined in descendants as:
+ +
+ +
+ +
+ + setContext (line 1261) +
+ + +

setContext - Set context, extension and priority.

+ +
+ void + + setContext + + (string $context, [string $extension = 's'], [string $priority = 1]) +
+ +
    +
  • + string + $context
  • +
  • + string + $extension
  • +
  • + string + $priority
  • +
+ + +
+ +
+ +
+ + set_autohangup (line 628) +
+ + +

Cause the channel to automatically hangup at $time seconds in the future.

+

If $time is 0 then the autohangup feature is disabled on this channel.

If the channel is hungup prior to $time seconds, this setting has no effect.

+ + +
+ array, + + set_autohangup + + ([integer $time = 0]) +
+ +
    +
  • + integer + $time: until automatic hangup
  • +
+ + +
+ +
+ +
+ + set_callerid (line 645) +
+ + +

Changes the caller ID of the current channel.

+ + +
+ array, + + set_callerid + + (string $cid) +
+ +
    +
  • + string + $cid: example: "John Smith"<1234567> This command will let you take liberties with the <caller ID specification> but the format shown in the example above works well: the name enclosed in double quotes followed immediately by the number inside angle brackets. If there is no name then you can omit it. If the name contains no spaces you can omit the double quotes around it. The number must follow the name immediately; don't put a space between them. The angle brackets around the number are necessary; if you omit them the number will be considered to be part of the name.
  • +
+ + +
+ +
+ +
+ + set_context (line 663) +
+ + +

Sets the context for continuation upon exiting the application.

+

Setting the context does NOT automatically reset the extension and the priority; if you want to start at the top of the new context you should set extension and priority yourself.

If you specify a non-existent context you receive no error indication (['result'] is still 0) but you do get a warning message on the Asterisk console.

+ + +
+ array, + + set_context + + (string $context) +
+ +
    +
  • + string + $context
  • +
+ + +
+ +
+ +
+ + set_extension (line 681) +
+ + +

Set the extension to be used for continuation upon exiting the application.

+

Setting the extension does NOT automatically reset the priority. If you want to start with the first priority of the extension you should set the priority yourself.

If you specify a non-existent extension you receive no error indication (['result'] is still 0) but you do get a warning message on the Asterisk console.

+ + +
+ array, + + set_extension + + (string $extension) +
+ +
    +
  • + string + $extension
  • +
+ + +
+ +
+ +
+ + set_global_var (line 329) +
+ + +

Sets a global variable, using Asterisk 1.6 syntax.

+ + +
+ array, + + set_global_var + + (string $pVariable, string|int|float $pValue) +
+ +
    +
  • + string + $pVariable
  • +
  • + string|int|float + $pValue
  • +
+ + +
+ +
+ +
+ + set_music (line 694) +
+ + +

Enable/Disable Music on hold generator.

+ + +
+ array, + + set_music + + ([boolean $enabled = true], [string $class = '']) +
+ +
    +
  • + boolean + $enabled
  • +
  • + string + $class
  • +
+ + +
+ +
+ +
+ + set_priority (line 710) +
+ + +

Set the priority to be used for continuation upon exiting the application.

+

If you specify a non-existent priority you receive no error indication (['result'] is still 0) and no warning is issued on the Asterisk console.

+ + +
+ array, + + set_priority + + (integer $priority) +
+ +
    +
  • + integer + $priority
  • +
+ + +
+ +
+ +
+ + set_var (line 347) +
+ + +

Sets a variable, using Asterisk 1.6 syntax.

+ + +
+ array, + + set_var + + (string $pVariable, string|int|float $pValue) +
+ +
    +
  • + string + $pVariable
  • +
  • + string|int|float + $pValue
  • +
+ + +
+
Redefined in descendants as:
+
    +
  • + AGI_1::set_var() + : Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>} in the dialplan. +
  • +
+
+ +
+ +
+ + set_variable (line 728) +
+ + +

Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>} in the dialplan.

+

These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary. Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted and any variables in that channel are deleted as well.

+ + +
+ array, + + set_variable + + (string $variable, string $value) +
+ +
    +
  • + string + $variable: is case sensitive
  • +
  • + string + $value
  • +
+ + +
+ +
+ +
+ + stream_file (line 748) +
+ + +

Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.

+ + +
+ array, + + stream_file + + (string $filename, [string $escape_digits = ''], [integer $offset = 0]) +
+ +
    +
  • + string + $filename: without extension, often in /var/lib/asterisk/sounds
  • +
  • + string + $escape_digits
  • +
  • + integer + $offset
  • +
+ + +
+ +
+ +
+ + swift (line 1380) +
+ + +

Use Cepstral Swift to read text.

+ + +
+ array, + + swift + + (string $text, [string $escape_digits = ''], [integer $frequency = 8000], [ $voice = NULL]) +
+ +
    +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
  • + integer + $frequency
  • +
  • + + $voice
  • +
+ + +
+ +
+ +
+ + tdd_mode (line 760) +
+ + +

Enable or disable TDD transmission/reception on the current channel.

+ + +
+ array, + + tdd_mode + + (string $setting) +
+ +
    +
  • + string + $setting: can be on, off or mate
  • +
+ + +
+ +
+ +
+ + text2wav (line 1331) +
+ + +

Use festival to read text.

+ + +
+ array, + + text2wav + + (string $text, [string $escape_digits = ''], [integer $frequency = 8000]) +
+ +
    +
  • + string + $text
  • +
  • + string + $escape_digits
  • +
  • + integer + $frequency
  • +
+ + +
+ +
+ +
+ + text_input (line 1434) +
+ + +

Text Input.

+

Based on ideas found at http://www.voip-info.org/wiki-Asterisk+cmd+DTMFToText

Example: UC H LC i , SP h o w SP a r e SP y o u ? $string = '*8'.'44*'.'*5'.'444*'.'00*'.'0*'.'44*'.'666*'.'9*'.'0*'.'2*'.'777*'.'33*'.'0*'.'999*'.'666*'.'88*'.'0000*';

+ + +
+ string + + text_input + + ([ $mode = 'NUMERIC']) +
+ +
    +
  • + + $mode
  • +
+ + +
+ +
+ +
+ + verbose (line 780) +
+ + +

Sends $message to the Asterisk console via the 'verbose' message system.

+

If the Asterisk verbosity level is $level or greater, send $message to the console.

The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later using the console 'set verbose' command. Messages are displayed on the console if their verbose level is less than or equal to desired verbosity set by the user. More important messages should have a low verbose level; less important messages should have a high verbose level.

+ + +
+ array, + + verbose + + (string $message, [integer $level = 1]) +
+ +
    +
  • + string + $message
  • +
  • + integer + $level: from 1 to 4
  • +
+ + +
+ +
+ +
+ + wait_for_digit (line 798) +
+ + +

Waits up to $timeout milliseconds for channel to receive a DTMF digit.

+
    +
  • return: see evaluate for return information. ['result'] is 0 if wait completes with no digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
  • +
  • link: http://www.voip-info.org/wiki-wait+for+digit
  • +
+ +
+ array, + + wait_for_digit + + ([integer $timeout = -1]) +
+ +
    +
  • + integer + $timeout: in millisecons. Use -1 for the timeout value if you want the call to wait indefinitely.
  • +
+ + +
+ +
+ +
+ + which (line 1690) +
+ + +

Find an execuable in the path.

+
    +
  • return: the path to the command
  • +
  • access: private
  • +
+ +
+ string + + which + + (string $cmd, [string $checkpath = NULL]) +
+ +
    +
  • + string + $cmd: command to find
  • +
  • + string + $checkpath: path to check
  • +
+ + +
+ +
+
+ + +

+ Documentation generated on Thu, 30 Sep 2010 02:21:59 -0700 by phpDocumentor 1.4.2 +

+
+ \ No newline at end of file diff --git a/api-docs/phpAGI/AGI_1.html b/api-docs/phpAGI/AGI_1.html new file mode 100644 index 0000000..4d2d9c8 --- /dev/null +++ b/api-docs/phpAGI/AGI_1.html @@ -0,0 +1,1525 @@ + + + + + + Docs For Class AGI_1 + + + + +
+

 Class AGI_1

+ + +
+
Description
+ +
+ +

Asterisk Manager class

+ +

+ Located in /phpagi_1.php (line 42) +

+ + +
AGI
+   |
+   --AGI_1
+ +
+
+ + + + +
+
Variable Summary
+ +
+
+
+  + array + $response +
+
+
+
+ + +
+
Method Summary
+ +
+
+
+  + AGI_1 + AGI_1 + ([string $config = false], [array $optconfig = false]) +
+
+  + array, + agi_channel_status + (string $channel) +
+
+  + string + agi_dtmf2text + (integer $len) +
+
+  + array + agi_exec + (string $str) +
+
+  + array + agi_getdtmf + (integer $len, integer $timeout, [string $terminator = false], [string $prompt = false]) +
+
+  + void + agi_goto + (string $con, [string $ext = 's'], [string $pri = 1]) +
+
+  + void + agi_hangup + (string $channel) +
+
+  + boolean + agi_is_error + (array $retarr) +
+
+  + void + agi_play + (string $file) +
+
+  + array + agi_readresult + () +
+
+  + void + agi_recordfile + (string $file, string $format, [integer $timeout = 5000], [string $prompt = FALSE]) +
+
+  + integer + agi_response_code + () +
+
+  + string + agi_response_data + () +
+
+  + boolean + agi_response_is_error + () +
+
+  + integer + agi_response_result + () +
+
+  + mixed + agi_response_var + (string $var) +
+
+  + void + agi_saydigits + (integer $digits) +
+
+  + void + agi_saynumber + (integer $number) +
+
+  + void + agi_saytime + ([integer $time = '']) +
+
+  + void + agi_setlanguage + ([string $language = 'en']) +
+
+  + void + agi_verbose + (string $str, [integer $vbl = 1]) +
+
+  + string + arr2str + (array $arr) +
+
+  + void + con_print_r + (array $arr, [string $label = ''], [ $lvl = 0], integer $vbl) +
+
+  + integer + db_del + (string $family, string $key) +
+
+  + string + db_get + (string $family, string $key) +
+
+  + integer + db_put + (string $family, string $key, string $val) +
+
+  + array + enum_lookup + (string $telnumber, [string $rDNS = 'e164.org']) +
+
+  + string + enum_txtlookup + (string $telnumber, [string $rDNS = 'e164.org']) +
+
+  + array + evalutate + (string $command) +
+
+  + string + get_var + (string $var) +
+
+  + boolean + send_image + (string $image) +
+
+  + boolean + send_text + ($text $txt) +
+
+  + integer + set_var + (string $var, string $val) +
+
+
+
+ + +
+
Variables
+ +
+ + +
+ +
+ + + array + $response + (line 52) + +
+ + +

Response structure

+

array('code'=>$code, 'result'=>$result, 'data'=>$data)

+
    +
  • access: public
  • +
+ + + + + +
+

Inherited Variables

+ +

Inherited from AGI

+
+ + + AGI::$asmanager
+
+ + + AGI::$audio
+
+ + + AGI::$config
+
+ + + AGI::$in
+
+ + + AGI::$option_delim
+
+ + + AGI::$out
+
+ + + AGI::$request
+
+
+ +
+
+ + +
+
Methods
+ +
+ + +
+ +
+ + Constructor AGI_1 (line 60) +
+ + +

Constructor

+ +
+ AGI_1 + + AGI_1 + + ([string $config = false], [array $optconfig = false]) +
+ +
    +
  • + string + $config: is the name of the config file to parse
  • +
  • + array + $optconfig: is an array of configuration vars and vals, stuffed into $this->config['phpagi']
  • +
+ + +
+ +
+ +
+ + agi_channel_status (line 444) +
+ + +

Get the status of the specified channel.

+ + +
+ array, + + agi_channel_status + + (string $channel) +
+ +
    +
  • + string + $channel
  • +
+ + +
+ +
+ +
+ + agi_dtmf2text (line 293) +
+ + +

Read $len characters as DTMF codes

+ +
+ string + + agi_dtmf2text + + (integer $len) +
+ +
    +
  • + integer + $len
  • +
+ + +
+ +
+ +
+ + agi_exec (line 87) +
+ + +

Execute an AGI command

+
    +
  • return: ('code'=>$code, 'result'=>$result, 'data'=>$data)
  • +
  • access: private
  • +
+ +
+ array + + agi_exec + + (string $str) +
+ +
    +
  • + string + $str
  • +
+ + +
+ +
+ +
+ + agi_getdtmf (line 248) +
+ + +

Plays the given file and receives DTMF data.

+

This is similar to STREAM FILE, but this command can accept and return many DTMF digits, while STREAM FILE returns immediately after the first DTMF digit is detected.

Asterisk looks for the file to play in /var/lib/asterisk/sounds by default.

If the user doesn't press any keys when the message plays, there is $timeout milliseconds of silence then the command ends.

The user has the opportunity to press a key at any time during the message or the post-message silence. If the user presses a key while the message is playing, the message stops playing. When the first key is pressed a timer starts counting for $timeout milliseconds. Every time the user presses another key the timer is restarted. The command ends when the counter goes to zero or the maximum number of digits is entered, whichever happens first.

Pressing the # key has the same effect as the timer running out: the command ends and any previously keyed digits are returned. A side effect of this is that there is no way to read a # key using this command.

+ + +
+ array + + agi_getdtmf + + (integer $len, integer $timeout, [string $terminator = false], [string $prompt = false]) +
+ +
    +
  • + integer + $len: number of digits to read
  • +
  • + integer + $timeout: milliseconds
  • +
  • + string + $terminator: character on which to quit
  • +
  • + string + $prompt: file to play. Do not include file extension.
  • +
+ + +
+ +
+ +
+ + agi_goto (line 486) +
+ + +

Goto - Set context, extension and priority

+ +
+ void + + agi_goto + + (string $con, [string $ext = 's'], [string $pri = 1]) +
+ +
    +
  • + string + $con: context
  • +
  • + string + $ext: extension
  • +
  • + string + $pri: priority
  • +
+ + +
+ +
+ +
+ + agi_hangup (line 432) +
+ + +

Hangup the current channel.

+ + +
+ void + + agi_hangup + + (string $channel) +
+ +
    +
  • + string + $channel
  • +
+ + +
+ +
+ +
+ + agi_is_error (line 98) +
+ + +

Check for error in result structure

+
    +
  • return: true on error
  • +
+ +
+ boolean + + agi_is_error + + (array $retarr) +
+ +
    +
  • + array + $retarr
  • +
+ + +
+ +
+ +
+ + agi_play (line 474) +
+ + +

Play the given audio file, allowing playback to be interrupted by a #. This command is similar to the GET DATA command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of digits before returning.

+ + +
+ void + + agi_play + + (string $file) +
+ +
    +
  • + string + $file: filename without extension, often in /var/lib/asterisk/sounds
  • +
+ + +
+ +
+ +
+ + agi_readresult (line 125) +
+ + +

Read the result from Asterisk

+ +
+ array + + agi_readresult + + () +
+ + + +
+ +
+ +
+ + agi_recordfile (line 460) +
+ + +

Record sound to a file until an acceptable DTMF digit is received or a specified amount of time has passed. Optionally the file BEEP is played before recording begins.

+ + +
+ void + + agi_recordfile + + (string $file, string $format, [integer $timeout = 5000], [string $prompt = FALSE]) +
+ +
    +
  • + string + $file: to record, without extension, often created in /var/lib/asterisk/sounds
  • +
  • + string + $format: of the file. GSM and WAV are commonly used formats. MP3 is read-only and thus cannot be used.
  • +
  • + integer + $timeout: is the maximum record time in milliseconds, or -1 for no timeout.
  • +
  • + string + $prompt: to play
  • +
+ + +
+ +
+ +
+ + agi_response_code (line 154) +
+ + +

Get the response code from the last command

+ +
+ integer + + agi_response_code + + () +
+ + + +
+ +
+ +
+ + agi_response_data (line 175) +
+ + +

Get the response data from the last command

+ +
+ string + + agi_response_data + + () +
+ + + +
+ +
+ +
+ + agi_response_is_error (line 198) +
+ + +

Check for error in response

+
    +
  • return: true on error
  • +
+ +
+ boolean + + agi_response_is_error + + () +
+ + + +
+ +
+ +
+ + agi_response_result (line 164) +
+ + +

Get the result code from the last command

+ +
+ integer + + agi_response_result + + () +
+ + + +
+ +
+ +
+ + agi_response_var (line 186) +
+ + +

Get the response variable from the last command

+ +
+ mixed + + agi_response_var + + (string $var) +
+ +
    +
  • + string + $var
  • +
+ + +
+ +
+ +
+ + agi_saydigits (line 497) +
+ + +

Say the given digit string, returning early if # is received on the channel.

+ + +
+ void + + agi_saydigits + + (integer $digits) +
+ +
    +
  • + integer + $digits
  • +
+ + +
+ +
+ +
+ + agi_saynumber (line 508) +
+ + +

Say the given number, returning early if # is received on the channel.

+ + +
+ void + + agi_saynumber + + (integer $number) +
+ +
    +
  • + integer + $number
  • +
+ + +
+ +
+ +
+ + agi_saytime (line 519) +
+ + +

Say a given time, returning early if # is received on the channel.

+ + +
+ void + + agi_saytime + + ([integer $time = '']) +
+ +
    +
  • + integer + $time: number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
  • +
+ + +
+ +
+ +
+ + agi_setlanguage (line 530) +
+ + +

Set Language

+ +
+ void + + agi_setlanguage + + ([string $language = 'en']) +
+ +
    +
  • + string + $language: code
  • +
+ + +
+ +
+ +
+ + agi_verbose (line 144) +
+ + +

Sends $message to the Asterisk console via the 'verbose' message system.

+

If the Asterisk verbosity level is $vbl or greater, send $str to the console.

The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later using the console 'set verbose' command. Messages are displayed on the console if their verbose level is less than or equal to desired verbosity set by the user. More important messages should have a low verbose level; less important messages should have a high verbose level.

+ + +
+ void + + agi_verbose + + (string $str, [integer $vbl = 1]) +
+ +
    +
  • + string + $str
  • +
  • + integer + $vbl: from 1 to 4
  • +
+ + +
+ +
+ +
+ + arr2str (line 342) +
+ + +

Alias of PHP join function

+ +
+ string + + arr2str + + (array $arr) +
+ +
    +
  • + array + $arr
  • +
+ + +
+ +
+ +
+ + con_print_r (line 210) +
+ + +

Log to console if debug mode

+ +
+ void + + con_print_r + + (array $arr, [string $label = ''], [ $lvl = 0], integer $vbl) +
+ +
    +
  • + array + $arr: to print
  • +
  • + string + $label
  • +
  • + integer + $vbl: verbose level
  • +
  • + + $lvl
  • +
+ + +
+ +
+ +
+ + db_del (line 384) +
+ + +

Deletes an entry in the Asterisk database for a given family and key.

+ + +
+ integer + + db_del + + (string $family, string $key) +
+ +
    +
  • + string + $family
  • +
  • + string + $key
  • +
+ + +
+ +
+ +
+ + db_get (line 355) +
+ + +

Retrieves an entry in the Asterisk database for a given family and key.

+ + +
+ string + + db_get + + (string $family, string $key) +
+ +
    +
  • + string + $family
  • +
  • + string + $key
  • +
+ + +
+ +
+ +
+ + db_put (line 370) +
+ + +

Adds or updates an entry in the Asterisk database for a given family, key, and value.

+
    +
  • return: result code
  • +
+ +
+ integer + + db_put + + (string $family, string $key, string $val) +
+ +
    +
  • + string + $family
  • +
  • + string + $key
  • +
  • + string + $val
  • +
+ + +
+ +
+ +
+ + enum_lookup (line 542) +
+ + +

Perform enum lookup

+ +
+ array + + enum_lookup + + (string $telnumber, [string $rDNS = 'e164.org']) +
+ +
    +
  • + string + $telnumber
  • +
  • + string + $rDNS
  • +
+ + +
+ +
+ +
+ + enum_txtlookup (line 594) +
+ + +

Perform enum txt lookup

+ +
+ string + + enum_txtlookup + + (string $telnumber, [string $rDNS = 'e164.org']) +
+ +
    +
  • + string + $telnumber
  • +
  • + string + $rDNS
  • +
+ + +
+ +
+ +
+ + evalutate (line 74) +
+ + +

Evaluate an AGI command

+
    +
  • return: ('code'=>$code, 'result'=>$result, 'data'=>$data)
  • +
  • access: private
  • +
+ +
+ array + + evalutate + + (string $command) +
+ +
    +
  • + string + $command
  • +
+ + +
+ +
+ +
+ + get_var (line 400) +
+ + +

Fetch the value of a variable.

+

Does not work with global variables. Does not work with some variables that are generated by modules.

+ + +
+ string + + get_var + + (string $var) +
+ +
    +
  • + string + $var: variable name
  • +
+ + +
+ +
+ +
+ + send_image (line 649) +
+ + +

Send the specified image on a channel.

+

Most channels do not support the transmission of images.

+ + +
+ boolean + + send_image + + (string $image) +
+ +
    +
  • + string + $image: without extension, often in /var/lib/asterisk/images
  • +
+ +
+
Redefinition of:
+
+
AGI::send_image()
+
Send the specified image on a channel.
+
+ +
+ +
+ +
+ + send_text (line 633) +
+ + +

Send the given text to the connected channel.

+

Most channels do not support transmission of text.

+ + +
+ boolean + + send_text + + ($text $txt) +
+ +
    +
  • + $text + $txt
  • +
+ +
+
Redefinition of:
+
+
AGI::send_text()
+
Send the given text to the connected channel.
+
+ +
+ +
+ +
+ + set_var (line 420) +
+ + +

Sets a variable to the specified value. The variables so created can later be used by later using ${<variablename>} in the dialplan.

+

These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary. Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted and any variables in that channel are deleted as well.

+ + +
+ integer + + set_var + + (string $var, string $val) +
+ +
    +
  • + string + $var: is case sensitive
  • +
  • + string + $val
  • +
+ +
+
Redefinition of:
+
+
AGI::set_var()
+
Sets a variable, using Asterisk 1.6 syntax.
+
+ +
+

Inherited Methods

+ + +

Inherited From AGI

+
+  + AGI::__construct()
+  + AGI::answer()
+  + AGI::channel_status()
+  + AGI::conlog()
+  + AGI::database_del()
+  + AGI::database_deltree()
+  + AGI::database_get()
+  + AGI::database_put()
+  + AGI::evaluate()
+  + AGI::exec()
+  + AGI::exec_absolutetimeout()
+  + AGI::exec_agi()
+  + AGI::exec_dial()
+  + AGI::exec_enumlookup()
+  + AGI::exec_goto()
+  + AGI::exec_setlanguage()
+  + AGI::fastpass_get_data()
+  + AGI::fastpass_say_digits()
+  + AGI::fastpass_say_number()
+  + AGI::fastpass_say_phonetic()
+  + AGI::fastpass_say_punctuation()
+  + AGI::fastpass_say_time()
+  + AGI::fastpass_stream_file()
+  + AGI::fastpass_swift()
+  + AGI::fastpass_text2wav()
+  + AGI::get_data()
+  + AGI::get_fullvariable()
+  + AGI::get_variable()
+  + AGI::hangup()
+  + AGI::make_folder()
+  + AGI::menu()
+  + AGI::new_AsteriskManager()
+  + AGI::noop()
+  + AGI::parse_callerid()
+  + AGI::receive_char()
+  + AGI::record_file()
+  + AGI::say_digits()
+  + AGI::say_number()
+  + AGI::say_phonetic()
+  + AGI::say_punctuation()
+  + AGI::say_time()
+  + AGI::send_image()
+  + AGI::send_text()
+  + AGI::setContext()
+  + AGI::set_autohangup()
+  + AGI::set_callerid()
+  + AGI::set_context()
+  + AGI::set_extension()
+  + AGI::set_global_var()
+  + AGI::set_music()
+  + AGI::set_priority()
+  + AGI::set_var()
+  + AGI::set_variable()
+  + AGI::stream_file()
+  + AGI::swift()
+  + AGI::tdd_mode()
+  + AGI::text2wav()
+  + AGI::text_input()
+  + AGI::verbose()
+  + AGI::wait_for_digit()
+  + AGI::which()
+
+ +
+
+ + +

+ Documentation generated on Thu, 30 Sep 2010 02:22:07 -0700 by phpDocumentor 1.4.2 +

+
+ \ No newline at end of file diff --git a/api-docs/phpAGI/AGI_AsteriskManager.html b/api-docs/phpAGI/AGI_AsteriskManager.html new file mode 100644 index 0000000..b85fb19 --- /dev/null +++ b/api-docs/phpAGI/AGI_AsteriskManager.html @@ -0,0 +1,1820 @@ + + + + + + Docs For Class AGI_AsteriskManager + + + + +
+

 Class AGI_AsteriskManager

+ + +
+
Description
+ + +
+ + + + +
+
Variable Summary
+ +
+
+
+  + array + $config +
+
+  + array + $event_handlers +
+
+  + AGI + $pagi +
+
+  + integer + $port +
+
+  + string + $server +
+
+  + mixed + $socket +
+
+  + boolean + $_logged_in +
+
+
+
+ + +
+
Method Summary
+ +
+
+
+  + AGI_AsteriskManager + AGI_AsteriskManager + ([string $config = NULL], [array $optconfig = array()]) +
+
+  + void + AbsoluteTimeout + (string $channel, integer $timeout) +
+
+  + boolean + add_event_handler + (string $event, string $callback) +
+
+  + void + ChangeMonitor + (string $channel, string $file) +
+
+  + void + Command + (string $command, [string $actionid = NULL]) +
+
+  + boolean + connect + ([string $server = NULL], [string $username = NULL], [string $secret = NULL]) +
+
+  + void + disconnect + () +
+
+  + void + Events + (string $eventmask) +
+
+  + void + ExtensionState + (string $exten, string $context, [string $actionid = NULL]) +
+
+  + void + GetVar + (string $channel, string $variable, [string $actionid = NULL]) +
+
+  + void + Hangup + (string $channel) +
+
+  + void + IAXPeers + () +
+
+  + void + ListCommands + ([string $actionid = NULL]) +
+
+  + void + log + ( $message, [ $level = 1]) +
+
+  + void + Logoff + () +
+
+  + void + MailboxCount + (string $mailbox, [string $actionid = NULL]) +
+
+  + void + MailboxStatus + (string $mailbox, [string $actionid = NULL]) +
+
+  + void + Monitor + (string $channel, [string $file = NULL], [string $format = NULL], [boolean $mix = NULL]) +
+
+  + void + Originate + (string $channel, [string $exten = NULL], [string $context = NULL], [string $priority = NULL], [string $application = NULL], [string $data = NULL], [integer $timeout = NULL], [string $callerid = NULL], [string $variable = NULL], [string $account = NULL], [boolean $async = NULL], [string $actionid = NULL]) +
+
+  + void + ParkedCalls + ([string $actionid = NULL]) +
+
+  + void + Ping + () +
+
+  + mixed + process_event + (array $parameters) +
+
+  + void + QueueAdd + (string $queue, string $interface, [integer $penalty = 0]) +
+
+  + void + QueueRemove + (string $queue, string $interface) +
+
+  + void + Queues + () +
+
+  + void + QueueStatus + ([string $actionid = NULL]) +
+
+  + void + Redirect + (string $channel, string $extrachannel, string $exten, string $context, string $priority) +
+
+  + array + send_request + (string $action, [array $parameters = array()]) +
+
+  + void + SetCDRUserField + (string $userfield, string $channel, [string $append = NULL]) +
+
+  + void + SetVar + (string $channel, string $variable, string $value) +
+
+  + void + Status + (string $channel, [string $actionid = NULL]) +
+
+  + void + StopMonitor + (string $channel) +
+
+  + array + wait_response + ([boolean $allow_timeout = false]) +
+
+  + void + ZapDialOffhook + (string $zapchannel, string $number) +
+
+  + void + ZapDNDoff + (string $zapchannel) +
+
+  + void + ZapDNDon + (string $zapchannel) +
+
+  + void + ZapHangup + (string $zapchannel) +
+
+  + void + ZapShowChannels + ([string $actionid = NULL]) +
+
+  + void + ZapTransfer + (string $zapchannel) +
+
+
+
+ + +
+
Variables
+ +
+ + +
+ +
+ + + array + $config + (line 50) + +
+ + +

Config variables

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + array + $event_handlers + (line 89) + +
+ + +

Event Handlers

+
    +
  • access: private
  • +
+ + + + + +
+ +
+ +
+ + + AGI + $pagi + (line 81) + +
+ + +

Parent AGI

+
    +
  • access: private
  • +
+ + + + + +
+ +
+ +
+ + + integer + $port + (line 73) + +
+ + +

Port on the server we are connected to

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + string + $server + (line 65) + +
+ + +

Server we are connected to

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + mixed + $socket + = NULL (line 57) + +
+ + +

Socket

+
    +
  • access: public
  • +
+ + + + + +
+ +
+ +
+ + + boolean + $_logged_in + = FALSE (line 97) + +
+ + +

Whether we're successfully logged in

+
    +
  • access: private
  • +
+ + + + + +
+ +
+
+ + +
+
Methods
+ +
+ + +
+ +
+ + Constructor AGI_AsteriskManager (line 105) +
+ + +

Constructor

+ +
+ AGI_AsteriskManager + + AGI_AsteriskManager + + ([string $config = NULL], [array $optconfig = array()]) +
+ +
    +
  • + string + $config: is the name of the config file to parse or a parent agi from which to read the config
  • +
  • + array + $optconfig: is an array of configuration vars and vals, stuffed into $this->config['asmanager']
  • +
+ + +
+ +
+ +
+ + AbsoluteTimeout (line 295) +
+ + +

Set Absolute Timeout

+

Hangup a channel after a certain time.

+ + +
+ void + + AbsoluteTimeout + + (string $channel, integer $timeout) +
+ +
    +
  • + string + $channel: Channel name to hangup
  • +
  • + integer + $timeout: Maximum duration of the call (sec)
  • +
+ + +
+ +
+ +
+ + add_event_handler (line 785) +
+ + +

Add event handler

+

Known Events include ( http://www.voip-info.org/wiki-asterisk+manager+events ) Link - Fired when two voice channels are linked together and voice data exchange commences. Unlink - Fired when a link between two voice channels is discontinued, for example, just before call completion. Newexten - Hangup - Newchannel - Newstate - Reload - Fired when the "RELOAD" console command is executed. Shutdown - ExtensionStatus - Rename - Newcallerid - Alarm - AlarmClear - Agentcallbacklogoff - Agentcallbacklogin - Agentlogoff - MeetmeJoin - MessageWaiting - join - leave - AgentCalled - ParkedCall - Fired after ParkedCalls Cdr - ParkedCallsComplete - QueueParams - QueueMember - QueueStatusEnd - Status - StatusComplete - ZapShowChannels - Fired after ZapShowChannels ZapShowChannelsComplete -

+
    +
  • return: sucess
  • +
+ +
+ boolean + + add_event_handler + + (string $event, string $callback) +
+ +
    +
  • + string + $event: type or * for default handler
  • +
  • + string + $callback: function
  • +
+ + +
+ +
+ +
+ + ChangeMonitor (line 307) +
+ + +

Change monitoring filename of a channel

+ + +
+ void + + ChangeMonitor + + (string $channel, string $file) +
+ +
    +
  • + string + $channel: the channel to record.
  • +
  • + string + $file: the new name of the file created in the monitor spool directory.
  • +
+ + +
+ +
+ +
+ + Command (line 321) +
+ + +

Execute Command

+ + +
+ void + + Command + + (string $command, [string $actionid = NULL]) +
+ +
    +
  • + string + $command
  • +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + connect (line 215) +
+ + +

Connect to Asterisk

+ + +
+ boolean + + connect + + ([string $server = NULL], [string $username = NULL], [string $secret = NULL]) +
+ +
    +
  • + string + $server
  • +
  • + string + $username
  • +
  • + string + $secret
  • +
+ + +
+ +
+ +
+ + disconnect (line 275) +
+ + +

Disconnect

+ + +
+ void + + disconnect + + () +
+ + + +
+ +
+ +
+ + Events (line 334) +
+ + +

Enable/Disable sending of events to this manager

+ + +
+ void + + Events + + (string $eventmask) +
+ +
    +
  • + string + $eventmask: is either 'on', 'off', or 'system,call,log'
  • +
+ + +
+ +
+ +
+ + ExtensionState (line 347) +
+ + +

Check Extension Status

+ + +
+ void + + ExtensionState + + (string $exten, string $context, [string $actionid = NULL]) +
+ +
    +
  • + string + $exten: Extension to check state on
  • +
  • + string + $context: Context for extension
  • +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + GetVar (line 363) +
+ + +

Gets a Channel Variable

+ + +
+ void + + GetVar + + (string $channel, string $variable, [string $actionid = NULL]) +
+ +
    +
  • + string + $channel: Channel to read variable from
  • +
  • + string + $variable
  • +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + Hangup (line 376) +
+ + +

Hangup Channel

+ + +
+ void + + Hangup + + (string $channel) +
+ +
    +
  • + string + $channel: The channel name to be hungup
  • +
+ + +
+ +
+ +
+ + IAXPeers (line 386) +
+ + +

List IAX Peers

+ + +
+ void + + IAXPeers + + () +
+ + + +
+ +
+ +
+ + ListCommands (line 397) +
+ + +

List available manager commands

+ + +
+ void + + ListCommands + + ([string $actionid = NULL]) +
+ +
    +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + log (line 737) +
+ + + +
+ void + + log + + ( $message, [ $level = 1]) +
+ +
    +
  • + + $message
  • +
  • + + $level
  • +
+ + +
+ +
+ +
+ + Logoff (line 410) +
+ + +

Logoff Manager

+ + +
+ void + + Logoff + + () +
+ + + +
+ +
+ +
+ + MailboxCount (line 428) +
+ + +

Check Mailbox Message Count

+

Returns number of new and old messages. Message: Mailbox Message Count Mailbox: <mailboxid> NewMessages: <count> OldMessages: <count>

+ + +
+ void + + MailboxCount + + (string $mailbox, [string $actionid = NULL]) +
+ +
    +
  • + string + $mailbox: Full mailbox ID <mailbox>@<vm-context>
  • +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + MailboxStatus (line 447) +
+ + +

Check Mailbox

+

Returns number of messages. Message: Mailbox Status Mailbox: <mailboxid> Waiting: <count>

+ + +
+ void + + MailboxStatus + + (string $mailbox, [string $actionid = NULL]) +
+ +
    +
  • + string + $mailbox: Full mailbox ID <mailbox>@<vm-context>
  • +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + Monitor (line 463) +
+ + +

Monitor a channel

+ + +
+ void + + Monitor + + (string $channel, [string $file = NULL], [string $format = NULL], [boolean $mix = NULL]) +
+ +
    +
  • + string + $channel
  • +
  • + string + $file
  • +
  • + string + $format
  • +
  • + boolean + $mix
  • +
+ + +
+ +
+ +
+ + Originate (line 489) +
+ + +

Originate Call

+ + +
+ void + + Originate + + (string $channel, [string $exten = NULL], [string $context = NULL], [string $priority = NULL], [string $application = NULL], [string $data = NULL], [integer $timeout = NULL], [string $callerid = NULL], [string $variable = NULL], [string $account = NULL], [boolean $async = NULL], [string $actionid = NULL]) +
+ +
    +
  • + string + $channel: Channel name to call
  • +
  • + string + $exten: Extension to use (requires 'Context' and 'Priority')
  • +
  • + string + $context: Context to use (requires 'Exten' and 'Priority')
  • +
  • + string + $priority: Priority to use (requires 'Exten' and 'Context')
  • +
  • + string + $application: Application to use
  • +
  • + string + $data: Data to use (requires 'Application')
  • +
  • + integer + $timeout: How long to wait for call to be answered (in ms)
  • +
  • + string + $callerid: Caller ID to be set on the outgoing channel
  • +
  • + string + $variable: Channel variable to set (VAR1=value1|VAR2=value2)
  • +
  • + string + $account: Account code
  • +
  • + boolean + $async: true fast origination
  • +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + ParkedCalls (line 519) +
+ + +

List parked calls

+ + +
+ void + + ParkedCalls + + ([string $actionid = NULL]) +
+ +
    +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + Ping (line 532) +
+ + +

Ping

+ + +
+ void + + Ping + + () +
+ + + +
+ +
+ +
+ + process_event (line 804) +
+ + +

Process event

+
    +
  • return: result of event handler or false if no handler was found
  • +
  • access: private
  • +
+ +
+ mixed + + process_event + + (array $parameters) +
+ +
    +
  • + array + $parameters
  • +
+ + +
+ +
+ +
+ + QueueAdd (line 545) +
+ + +

Queue Add

+ + +
+ void + + QueueAdd + + (string $queue, string $interface, [integer $penalty = 0]) +
+ +
    +
  • + string + $queue
  • +
  • + string + $interface
  • +
  • + integer + $penalty
  • +
+ + +
+ +
+ +
+ + QueueRemove (line 559) +
+ + +

Queue Remove

+ + +
+ void + + QueueRemove + + (string $queue, string $interface) +
+ +
    +
  • + string + $queue
  • +
  • + string + $interface
  • +
+ + +
+ +
+ +
+ + Queues (line 569) +
+ + +

Queues

+ + +
+ void + + Queues + + () +
+ + + +
+ +
+ +
+ + QueueStatus (line 580) +
+ + +

Queue Status

+ + +
+ void + + QueueStatus + + ([string $actionid = NULL]) +
+ +
    +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + Redirect (line 598) +
+ + +

Redirect

+ + +
+ void + + Redirect + + (string $channel, string $extrachannel, string $exten, string $context, string $priority) +
+ +
    +
  • + string + $channel
  • +
  • + string + $extrachannel
  • +
  • + string + $exten
  • +
  • + string + $context
  • +
  • + string + $priority
  • +
+ + +
+ +
+ +
+ + send_request (line 131) +
+ + +

Send a request

+
    +
  • return: of parameters
  • +
+ +
+ array + + send_request + + (string $action, [array $parameters = array()]) +
+ +
    +
  • + string + $action
  • +
  • + array + $parameters
  • +
+ + +
+ +
+ +
+ + SetCDRUserField (line 612) +
+ + +

Set the CDR UserField

+ + +
+ void + + SetCDRUserField + + (string $userfield, string $channel, [string $append = NULL]) +
+ +
    +
  • + string + $userfield
  • +
  • + string + $channel
  • +
  • + string + $append
  • +
+ + +
+ +
+ +
+ + SetVar (line 627) +
+ + +

Set Channel Variable

+ + +
+ void + + SetVar + + (string $channel, string $variable, string $value) +
+ +
    +
  • + string + $channel: Channel to set variable for
  • +
  • + string + $variable: name
  • +
  • + string + $value
  • +
+ + +
+ +
+ +
+ + Status (line 639) +
+ + +

Channel Status

+ + +
+ void + + Status + + (string $channel, [string $actionid = NULL]) +
+ +
    +
  • + string + $channel
  • +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + StopMonitor (line 652) +
+ + +

Stop monitoring a channel

+ + +
+ void + + StopMonitor + + (string $channel) +
+ +
    +
  • + string + $channel
  • +
+ + +
+ +
+ +
+ + wait_response (line 150) +
+ + +

Wait for a response

+

If a request was just sent, this will return the response. Otherwise, it will loop forever, handling events.

+
    +
  • return: of parameters, empty on timeout
  • +
+ +
+ array + + wait_response + + ([boolean $allow_timeout = false]) +
+ +
    +
  • + boolean + $allow_timeout: if the socket times out, return an empty array
  • +
+ + +
+ +
+ +
+ + ZapDialOffhook (line 664) +
+ + +

Dial over Zap channel while offhook

+ + +
+ void + + ZapDialOffhook + + (string $zapchannel, string $number) +
+ +
    +
  • + string + $zapchannel
  • +
  • + string + $number
  • +
+ + +
+ +
+ +
+ + ZapDNDoff (line 675) +
+ + +

Toggle Zap channel Do Not Disturb status OFF

+ + +
+ void + + ZapDNDoff + + (string $zapchannel) +
+ +
    +
  • + string + $zapchannel
  • +
+ + +
+ +
+ +
+ + ZapDNDon (line 686) +
+ + +

Toggle Zap channel Do Not Disturb status ON

+ + +
+ void + + ZapDNDon + + (string $zapchannel) +
+ +
    +
  • + string + $zapchannel
  • +
+ + +
+ +
+ +
+ + ZapHangup (line 697) +
+ + +

Hangup Zap Channel

+ + +
+ void + + ZapHangup + + (string $zapchannel) +
+ +
    +
  • + string + $zapchannel
  • +
+ + +
+ +
+ +
+ + ZapShowChannels (line 719) +
+ + +

Zap Show Channels

+ + +
+ void + + ZapShowChannels + + ([string $actionid = NULL]) +
+ +
    +
  • + string + $actionid: message matching variable
  • +
+ + +
+ +
+ +
+ + ZapTransfer (line 708) +
+ + +

Transfer Zap Channel

+ + +
+ void + + ZapTransfer + + (string $zapchannel) +
+ +
    +
  • + string + $zapchannel
  • +
+ + +
+ +
+
+ + +

+ Documentation generated on Thu, 30 Sep 2010 02:21:47 -0700 by phpDocumentor 1.4.2 +

+
+ \ No newline at end of file diff --git a/api-docs/phpAGI/_phpagi-asmanager.php.html b/api-docs/phpAGI/_phpagi-asmanager.php.html new file mode 100644 index 0000000..01eb46d --- /dev/null +++ b/api-docs/phpAGI/_phpagi-asmanager.php.html @@ -0,0 +1,99 @@ + + + + + + Docs for page phpagi-asmanager.php + + + + +
+

File/phpagi-asmanager.php

+ + +
+
Description
+ +
+ +

phpagi-asmanager.php : PHP Asterisk Manager functions Website: http://phpagi.sourceforge.net

+

$Id$

Copyright (c) 2004 - 2010 Matthew Asham <matthew@ochrelabs.com>, David Eder <david@eder.us> and others All Rights Reserved.

This software is released under the terms of the GNU Lesser General Public License v2.1 A copy of which is available from http://www.gnu.org/copyleft/lesser.html

We would be happy to list your phpagi based application on the phpagi website. Drop me an Email if you'd like us to list your program.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+  class + AGI_AsteriskManager + + Asterisk Manager class +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+  + + require_once + (dirname(__FILE__).DIRECTORY_SEPARATOR.'phpagi.php') + (line 31) + +
+ + +

Written for PHP 4.3.4, should work with older PHP 4.x versions.

+

Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ Gracias. :)

+ +
+
+
+ + + + +

+ Documentation generated on Thu, 30 Sep 2010 02:21:44 -0700 by phpDocumentor 1.4.2 +

+
+ \ No newline at end of file diff --git a/api-docs/phpAGI/_phpagi-fastagi.php.html b/api-docs/phpAGI/_phpagi-fastagi.php.html new file mode 100644 index 0000000..a1a90db --- /dev/null +++ b/api-docs/phpAGI/_phpagi-fastagi.php.html @@ -0,0 +1,85 @@ + + + + + + Docs for page phpagi-fastagi.php + + + + +
+

File/phpagi-fastagi.php

+ + +
+
Description
+ +
+ +

phpagi-fastagi.php : PHP FastAGI bootstrap Website: http://phpagi.sourceforge.net

+

$Id$

Copyright (c) 2004, 2005 Matthew Asham <matthewa@bcwireless.net>, David Eder <david@eder.us> All Rights Reserved.

This software is released under the terms of the GNU Lesser General Public License v2.1 A copy of which is available from http://www.gnu.org/copyleft/lesser.html

We would be happy to list your phpagi based application on the phpagi website. Drop me an Email if you'd like us to list your program.

+ + +
+
+ + + +
+
Includes
+ +
+ +
+ +
+  + + require_once + (dirname(__FILE__).DIRECTORY_SEPARATOR.'phpagi.php') + (line 30) + +
+ + +

Written for PHP 4.3.4, should work with older PHP 4.x versions.

+

Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ Gracias. :)

+ +
+ +
+ +
+  + + require_once + ($script) + (line 78) + +
+ + + +
+
+
+ + + + +

+ Documentation generated on Thu, 30 Sep 2010 02:21:49 -0700 by phpDocumentor 1.4.2 +

+
+ \ No newline at end of file diff --git a/api-docs/phpAGI/_phpagi.php.html b/api-docs/phpAGI/_phpagi.php.html new file mode 100644 index 0000000..a5d54db --- /dev/null +++ b/api-docs/phpAGI/_phpagi.php.html @@ -0,0 +1,422 @@ + + + + + + Docs for page phpagi.php + + + + +
+

File/phpagi.php

+ + +
+
Description
+ +
+ +

phpagi.php : PHP AGI Functions for Asterisk Website: http://phpagi.sourceforge.net/

+

$Id$

Copyright (c) 2003 - 2010 Matthew Asham <matthew@ochrelabs.com>, David Eder <david@eder.us> and others All Rights Reserved.

This software is released under the terms of the GNU Lesser General Public License v2.1 A copy of which is available from http://www.gnu.org/copyleft/lesser.html

We would be happy to list your phpagi based application on the phpagi website. Drop me an Email if you'd like us to list your program.

Written for PHP 4.3.4, should work with older PHP 4.x versions.

Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ Gracias. :)

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+  class + AGI + + AGI class +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+  + + require_once + (dirname(__FILE__).DIRECTORY_SEPARATOR.'phpagi-asmanager.php') + (line 31) + +
+ + + +
+
+
+ + +
+
Constants
+ +
+ +
+ +
+ + + AGIRES_OK = 200 + (line 41) + +
+ + + + +
+ +
+ +
+ + + AST_CONFIG_DIR = '/etc/asterisk/' + (line 34) + +
+ + + + +
+ +
+ +
+ + + AST_DIGIT_ANY = '0123456789#*' + (line 39) + +
+ + + + +
+ +
+ +
+ + + AST_SPOOL_DIR = '/var/spool/asterisk/' + (line 35) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_BUSY = 7 + (line 50) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_DIALING = 3 + (line 46) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_DIALING_OFFHOOK = 8 + (line 51) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_DOWN = 0 + (line 43) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_OFFHOOK = 2 + (line 45) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_PRERING = 9 + (line 52) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_RESERVED = 1 + (line 44) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_RING = 4 + (line 47) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_RINGING = 5 + (line 48) + +
+ + + + +
+ +
+ +
+ + + AST_STATE_UP = 6 + (line 49) + +
+ + + + +
+ +
+ +
+ + + AST_TMP_DIR = AST_SPOOL_DIR.'/tmp/' + (line 36) + +
+ + + + +
+ +
+ +
+ + + AUDIO_FILENO = 3 + (line 54) + +
+ + + + +
+ +
+ +
+ + + DEFAULT_PHPAGI_CONFIG = AST_CONFIG_DIR.'/phpagi.conf' + (line 37) + +
+ + + + +
+
+
+ + + +
+
Functions
+ +
+ +
+ +
+ + phpagi_error_handler (line 1742) +
+ + +

error handler for phpagi.

+
+ void + + phpagi_error_handler + + (integer $level, string $message, string $file, integer $line, array $context) +
+ +
    +
  • + integer + $level: PHP error level
  • +
  • + string + $message: error message
  • +
  • + string + $file: path to file
  • +
  • + integer + $line: line number of error
  • +
  • + array + $context: variables in the current scope
  • +
+ + +
+
+
+ +

+ Documentation generated on Thu, 30 Sep 2010 02:21:49 -0700 by phpDocumentor 1.4.2 +

+
+ \ No newline at end of file diff --git a/api-docs/phpAGI/_phpagi_1.php.html b/api-docs/phpAGI/_phpagi_1.php.html new file mode 100644 index 0000000..cdf1ddc --- /dev/null +++ b/api-docs/phpAGI/_phpagi_1.php.html @@ -0,0 +1,99 @@ + + + + + + Docs for page phpagi_1.php + + + + +
+

File/phpagi_1.php

+ + +
+
Description
+ +
+ +

phpagi-asmanager.php : PHP Asterisk Manager functions Website: http://phpagi.sourceforge.net

+

$Id$

Copyright (c) 2004, 2005 Matthew Asham <matthewa@bcwireless.net>, David Eder <david@eder.us> All Rights Reserved.

This software is released under the terms of the GNU Lesser General Public License v2.1 A copy of which is available from http://www.gnu.org/copyleft/lesser.html

We would be happy to list your phpagi based application on the phpagi website. Drop me an Email if you'd like us to list your program.

+ + +
+
+ + +
+
Classes
+ +
+ + + + + + + + + +
ClassDescription
+  class + AGI_1 + + Asterisk Manager class +
+
+
+ + +
+
Includes
+ +
+ +
+ +
+  + + require_once + (dirname(__FILE__).DIRECTORY_SEPARATOR.'phpagi.php') + (line 31) + +
+ + +

Written for PHP 4.3.4, should work with older PHP 4.x versions.

+

Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ Gracias. :)

+ +
+
+
+ + + + +

+ Documentation generated on Thu, 30 Sep 2010 02:22:04 -0700 by phpDocumentor 1.4.2 +

+
+ \ No newline at end of file diff --git a/docs/CHANGELOG b/docs/CHANGELOG new file mode 100644 index 0000000..c279fe8 --- /dev/null +++ b/docs/CHANGELOG @@ -0,0 +1,181 @@ +---------- +CHANGES +---------- +Sep 18, 2010 - Matthew Asham + * Add option_delim to AGI to specify application option delimiter + * Changed constructor method to __construct + +Sep 17, 2010 - Matthew Asham + * BACKWARDS COMPATABILITY WARNING: renamed goto() method to setContext() to address PHP 5.3 reserved keyword. tracker #3031708 + * add get_fullvariable to AGI class + * add boolean flag to get_variable and get_fullvariable methods to + return only the value - tracker #1736629 + * initialize $ret variable in say_punctuation + * add string parameter to noop + * fix escape issue in database_get + * make_folder now returns true or false depending on success + * update exec_setlanguage to use asterisk 1.6+ language + +May 19, 2010 - Roland Hu + * new methods: set_var(), set_global_var() + * dialplan bug (using pipe instead of comma) is fixed in exec_dial() and exec_goto() + * code formatting + +June 8, 2010 - Matthew Asham + * move to svn from cvs + +May 25, 2005 - David Eder + * Added fastpass support. + +May 18, 2005 - David Eder + * Added phpagi_1.php as a wrapper class for 1.12 compatibility. + +March 25, 2005 - David Eder + * Changed the way text2wave and swift are executed for better compatibility. + * Added caching to text2wav and swift. + +March 12, 2005 - David Eder + * fixed autohangup in phpagi-asmanager.php, renamed to set_autohangup. + * Added more documentation to phpagi-asmanager.php. + * Added weather example. + +March 4, 2005 - David Eder + * FastAGI via xinetd + +February 17, 2005 - David Eder + * Fixed bugs with error handler. + +February 16, 2005 - David Eder + * Added Cepstral swift TTS patch from C. Arbusti of Soluzioni Vocali ( http://soluzionivocali.it ). + * Extended swift TTS functionality. + * Moved tempdir from [festival] to [phpagi] so that it can be shared with other extensions. + +February 2, 2005 - David Eder + * More documentation. + * Reworked and reintegrated AGI_AsteriskManager class. + +January 21, 2005 - David Eder + * Added exec_dial($type, $identifier, $timeout=NULL, $options=NULL, $url=NULL). + * Added exec_goto($a, $b=NULL, $c=NULL). + * Fixed bugs in evaluate, better support of multiline and closed input and output. + * Fixed bugs in config initialization. + +January 19, 2005 - David Eder + * SUMMARY: + * Massive restructuring! + * Updated to use more PHP internal functions. + * Updated function arguments to represent their AGI function's arguments. + * Functions now return a consistent result array. + * Added phpdoc documentation. + * Removed functions that can be done with internal PHP or AGI functions. + * Enhanced error handler. + * + * Goals of changes: + * + * It is important for a language API to not wander too far from the general + * API. Functions that are named differently have been updated. Function + * arguments that do not match the AGI API have been updated. Underscores + * have been substituted for spaces to make them compatible with PHP function + * names. Optional arguments in AGI should remain optional if possible. Return + * values should be consistent. Functions need to be better documented. + * + * Result: + * + * The return from most functions is now + * array('code'=>$code, 'result'=>$result, 'data'=>$data) + * ['data'] still needs some work. + * + * removed class variables: + * $response - It was no longer used with the new return structure. + * + * removed functions: + * agi_is_error($retarr) - It was no longer used with the new return + * structure. Each function has it's own result that must be evalutated + * by the programmer, as the return values are often specific to the function. + * agi_readresult($str=FALSE) - It was no longer used with the new return structure. + * agi_response_code() - It was no longer used with the new return structure. + * agi_response_result() - It was no longer used with the new return structure. + * agi_response_data() - It was no longer used with the new return structure. + * agi_response_var($var) - It was no longer used with the new return structure. + * agi_response_is_error() - see agi_is_error + * agi_read() - It was deprecated + * con_print_r($arr,$label='',$lvl=0) - Use print_r($arr, true) in conjunction with conlog + * agi_getdtmf($len,$timeout,$terminator=FALSE,$prompt=FALSE) - use get_data + * agi_dtmf2text($len,$timeout,$terminator=FALSE,$prompt=FALSE) - use text_input + * arr2str($arr) - use PHP function join + * config_load($file) - use PHP function parse_ini_file + * enum_lookup($telnumber,$rDNS="e164.org") - use exec_enumlookup + * enum_txtlookup($telnumber,$rDNS="e164.org") - use exec_enumlookup + * + * added functions: + * answer() + * autohangup($time=0) + * exec($application, $options) + * get_data($filename, $timeout=NULL, $max_digits=NULL) + * receive_char($timeout=-1) + * say_phonetic($text, $escape_digits='') + * set_context($context) + * set_extension($extension) + * set_priority($priority) + * tdd_mode($setting) + * wait_for_digit($timeout=-1) + * database_deltree($family, $keytree='') + * noop() + * set_music($enabled=true, $class='') + * exec_absolutetimeout($seconds=0) + * exec_agi($command, $args) + * exec_enumlookup($exten) + * text_input($mode='NUMERIC') + * say_punctuation($text, $escape_digits='', $frequency=8000) + * which($cmd, $checkpath=NULL) + * make_folder($folder, $perms=0755) + * updated functions: + * agi_exec($str) -> evaluate($command) - exec is an AGI function + * agi_verbose($str,$vbl=1) -> verbose($message, $level=1) - consistency with AGI + * db_get($family,$key) -> database_get($family, $key) - consistency with AGI + * db_put($family,$key,$val) -> database_put($family, $key, $value) - consistency with AGI + * db_del($family,$key) -> database_del($family, $key) - consistency with AGI + * get_var($var) -> get_variable($variable) - consistency with AGI + * set_var($var,$val) -> set_variable($variable, $value) - consistency with AGI + * agi_hangup() -> hangup($channel='') - consistency with AGI + * agi_channel_status($channel) -> channel_status($channel='') - consistency with AGI + * agi_recordfile($file,$format,$timeout=5000,$prompt=FALSE) -> record_file($file, $format, $escape_digits='', $timeout=-1, $beep=false, $silence=NULL) - consistency with AGI + * agi_play($file) -> stream_file($filename, $escape_digits='', $offset=0) - consistency with AGI + * agi_goto($con,$ext='s',$pri=1) -> goto($context, $extension='s', $priority=1) - consistency with AGI + * agi_saydigits($digits) -> say_digits($digits, $escape_digits='') - consistency with AGI + * agi_saynumber($number) -> say_number($number, $escape_digits='') - consistency with AGI + * agi_saytime($time="") -> say_time($time=NULL, $escape_digits='') - consistency with AGI + * agi_setlanguage($language="en") -> exec_setlanguage($language='en') - consistency with AGI + * text2wav($text) -> text2wav($text, $escape_digits='', $frequency=8000) - consistency with AGI + * phpagi_error_handler($errno, $errstr, $errfile, $errline) -> phpagi_error_handler($level, $message, $file, $line, $context) - I needed better error handling + +August 29, 2004 - + * Fixed db_get now returns a value + * Fixed db_put now stores a value + * Added enum_lookup, requires external "dig" utility. + * Tweak con_print_r now dumps arrays, displays variable type. + * Added enum_txtlookup, requires external "dig" utility". + * Added parse_callerid, thanks to http://www.sbuehl.com/projects/asterisk/asterisk-howto-3.html + +August 26, 2004 - + * Added agi_verbose + * Added debug config-option to shut conlog up + * Added agi_saydigits, agi_saynumber, agi_saytime, agi_setlanguage + +April 8, 2004 - v1.5 internal + * Added agi_goto - David Croft + * Added this changelog (maintain it eh?) - Matthew Asham + * Added quote fixing to conlog - David Croft + * Added new parameter to AGI constructor, $configopt array - Matthew Asham + - Added phpagi_error_handler - David Croft + + + +March 20, 2004 - v1.5 + * Fixed buffering bugs - David Croft + * added demo app. - Matthew Asham + * misc stuff. - Matthew Asham + +November 2003 + * Initial version + diff --git a/docs/README.phpagi b/docs/README.phpagi new file mode 100644 index 0000000..6e1a1a4 --- /dev/null +++ b/docs/README.phpagi @@ -0,0 +1,96 @@ +phpagi: an AGI class written in PHP + + Matthew Asham + http://phpagi.sourceforge.net + +Contributions by: + Florian Overkamp + David Eder + Roland Hu + Others + +OVERVIEW +-------- + +Include it: + +require 'phpagi.php'; + +Construct it: + +$agi = new AGI(); + +This creates a new AGI object with all the agi vars read in, you're now ready +to rock and roll. + +Answer the line. + +$agi->answer(); + +Play a file. + +$agi->stream_file('somefile.gsm'); + +Record a file. + +$agi->record_file($file, $format, $escape_digits='', $timeout=-1, $beep=false, $silence=NULL) + +There's more, read the class or refer to the PHPAGI website for more information. + + This README is seriousley lacking. + +CONFIGURATION +------------- + +phpagi supports an ini style configuration file, and run time configuration. + +By default the class reads in the contents of /etc/asterisk/phpagi.conf into +$this->config. The format of the ini file is as follows: + +[examplesection] +foo=bar +bar=dew +dew=pale ale + +This is read into $this->config as: + +$this->config['examplesection']['foo']='bar'; +$this->config['examplesection']['bar]='dew'; +$this->config['examplesection']['dew']='pale ale'; + + +Run time configuration is also supported. Pass an array of variables and values as the +second parameter to the AGI constructor, these fields are stored in $this->config['phpagi']. + +ie: + +$myconfig=array( + "error_handler"="true" +); + + $agi=new AGI("/etc/asterisk/phpagi.conf",$myconfig); + + +The following run-time configuration options are used by the phpagi class to change behaviour. They +are all contained in the $this->config['phpagi'] array. + + * error_handler - set to "true" (string) to enable php debugging + + +EXAMPLE APPLICATION +------------------- + +ping.php is an example phpagi application. it asks for an IP address to be +entered, and reads back the results of a "ping" summary. + +to use it, you'll need festival installed. see http://www.voip-info.org/tiki-index.php?page=Asterisk+festival+installation +for all the groovy bits to get festival working with asterisk, then configure +phpagi to use it too: + +in /etc/asterisk/phpagi.conf: + +[festival] +text2wave=/usr/src/festival/bin/text2wave +tempdir=/var/lib/asterisk/sounds/tmp/ + + diff --git a/docs/README.phpagi-asmanager b/docs/README.phpagi-asmanager new file mode 100644 index 0000000..173ffcd --- /dev/null +++ b/docs/README.phpagi-asmanager @@ -0,0 +1,218 @@ +phpagi-asmanager: an Asterisk Manager class written in PHP + + Matthew Asham + http://phpagi.sourceforge.net +------------------------------------------------------------------------------ + +------------------------------------------------------------------------------ +SECURITY +------------------------------------------------------------------------------ + +Validation: + +******If asterisk is running as root, the manager interface may allow the +execution of arbitrary shell commands as root. If the user can update any +configuration file that can execute arbitrary command (like the dialplan), +the system may be compromised. + +Also, look out for command injection. Consider the following example: + + $as->Events($_POST['events_status']); + +We expect either 'on' or 'off', but the attacker uses: + + "\r\n\r\nAction: Command\r\nCommand: database put forward 54321 19005551212"; + + +Validation is a *must* for all user data. + + +Username and Secret: + +Storing the username and secret in the config file will isolate them from your +code. + +Isolation of username and secret in the config file does not mean that the +script cannot simple read the config file. The config file must be readable +by the script. + + +CREATING A NEW INSTANCE OF THE CLASS +------------------------------------------------------------------------------ + +The class can be created standalone of phpagi.php, or through phpagi. + +STANDALONE: + +require "phpagi-asmanager.php"; + +$as = new AGI_AsteriskManager(); + +FROM PHPAGI: + +require "phpagi.php"; + +$agi = new AGI(); +$as = $agi->new_AsteriskManager(); + +Notes: + +* If the class is created using $agi->new_AsteriskManager(), + AGI_AsteriskManager will use the parent phpagi for logging to the Asterisk + console. + +* phpagi.php will include phpagi-asmanager.php by itself. + * If phpagi-asmanager.php is included _before_ phpagi.php, phpagi.php will + not attempt to re-include it. + * If phpagi.php tries to include phpagi-asmanager.php but is unable to do + so, an error will be echoed to the asterisk console and the script will + continue running normally. in this case the return value of + new_AsteriskManager() will be FALSE. + +------------------------------------------------------------------------------ +CONFIGURATION +------------------------------------------------------------------------------ + +phpagi-asmanager uses the same configuration file as phpagi.conf (usually +/etc/asterisk/phpagi.conf). All configuration information specific to +phpagi-asmanager is contained in the [asmanager] section of the .conf file. + +supported directives: + +[asmanager] +# server to connect to +server=localhost + +# default manager port +port=5038 + +#username for login +username=me_and_only_me + +#password for login +secret=i_am_not_telling + + + +------------------------------------------------------------------------------ +CONNECTING +------------------------------------------------------------------------------ + + $res = $as->connect("localhost", "username", "password"); + if($res == FALSE) { + echo "Connection failed.\n"; + } + elseif($res == TRUE){ + echo "Connection established.\n"; + } + +A port can also be specified for the hostname. eg: + + $res = $as->connect("my.asterisk.server:1234", "username", "port"); + +If the no parameters are specified, the defaults from the config will be used. + + +------------------------------------------------------------------------------ +DISCONNECTING +------------------------------------------------------------------------------ + + $as->disconnect(); + +------------------------------------------------------------------------------ +SENDING REQUESTS +------------------------------------------------------------------------------ + + $as->send_request($eventname, $arrayofparameterstopass); + +send_request() calls wait_request and returns an array of returned data from +the manager. If something went wrong, it returns false. + +wait_request() shouldn't need to be called from a script directly unless you +are implementing merely an event listener. + +wait_request() will also detect events and dispatch any registered event +handlers for the event. + +examples: + + $res = $as->send_request('EventName', + array('Channel'=>'Zap/1/16045551212', + 'SomeParameter'=>'data')); + echo "Dump of returned data:\n"; + foreach($res as $var=>$val) + echo "$var = $val\n"; + + +$res['Response'] will generally be 'Success' on success and 'Error' on +failure. But this is not always true. If $res['Response'] == 'Follows', a +multi-line response will be stored in $res['data']. + +Several manager commands have been aliased for convenience. See below. + +------------------------------------------------------------------------------ +EVENTS +------------------------------------------------------------------------------ + +TODO: non-blocking socket i/o. + +The class uses event callbacks to process events received from the manager. + +The event callback prototype looks like: + + function dump_event($ecode, $data, $server, $port) + { + echo "received event '$ecode' from $server:$port\n"; + print_r($data); + } + +To register an event call back: + + $as->add_event_handler('eventname', 'eventfunction'); + +eg: + + $as->add_event_handler('registry', 'dump_event'); + + +The special eventname "*" can also be registered. any eventname not +specifically registered will be handled by the "*" handler. If no "*" handler +is defined, the event will be silently ignored. + + +------------------------------------------------------------------------------ +PRECANNED FUNCTIONS +------------------------------------------------------------------------------ + +The following Manager functions have been aliased for convenience: + +AbsoluteTimeout +ChangeMonitor +Command +Events +ExtensionState +GetVar +Hangup +IAXPeers +ListCommands +Logoff +MailboxCount +MailboxStatus +Monitor +Originate +ParkedCalls +Ping +Queues +QueueStatus +Redirect +SetCDRUserField +SetVar +SIPpeers +Status +StopMontor +ZapDialOffhook +ZapDNDoff +ZapDNDon +ZapHangup +ZapTransfer + diff --git a/docs/README.phpagi-fastagi b/docs/README.phpagi-fastagi new file mode 100644 index 0000000..176f4fc --- /dev/null +++ b/docs/README.phpagi-fastagi @@ -0,0 +1,46 @@ +First, in /etc/services, at this line: + +fastagi 4573/tcp # Asterisk AGI + + + +Second, create /etc/xnetd.d/fastagi with: + +# default: off +# description: fastagi is a remote AGI interface +service fastagi +{ + socket_type = stream + user = root + group = nobody + server = + wait = no + protocol = tcp + bind = 127.0.0.1 + disable = no +} + +Make sure you set the path to the phpagi-fastagi.php script. Set the user +and group to a non-root user if none of your scripts need root access. You +might consider using posix_setuid and friends to reduce privileges. Change +the bind address to your outbound IP address or to 0.0.0.0 to allow anyone +to connect. Be sure to read up about xinetd and take advantage of security +features it provides. Fast AGI doesn't provide authentification. It's up +to you to keep unwanted visitors from extracting information from your AGI +implementation. + + +Third, write your code. + +Take special notice of how fastagi.php works: + + 1. $fastagi is initialized as a new AGI. + 2. The script determines which script was requested. + 3. The script is called using + reqire_once($fastagi->request['agi_request']). + 4. Your script takes over. You must not create a new AGI, but + insead use the $fastagi instance that has already been created. + +In your dialplan: + +exten => 5551212, 1, Agi(agi://127.0.0.1/myscript.php) diff --git a/docs/fastagi.xinetd b/docs/fastagi.xinetd new file mode 100644 index 0000000..3ebf37b --- /dev/null +++ b/docs/fastagi.xinetd @@ -0,0 +1,14 @@ +# default: off +# description: fastagi is a remote AGI interface +service fastagi +{ + socket_type = stream + user = root + group = nobody + server = /var/lib/asterisk/agi-bin/phpagi/phpagi-fastagi.php + wait = no + protocol = tcp + bind = 127.0.0.1 + disable = no +} + diff --git a/docs/phpagi.example.conf b/docs/phpagi.example.conf new file mode 100644 index 0000000..ee34cb7 --- /dev/null +++ b/docs/phpagi.example.conf @@ -0,0 +1,26 @@ +; example phpagi.conf + +[phpagi] +debug=true ; enable debuging +error_handler=true ; use internal error handler +admin=errors@mydomain.com ; mail errors to +hostname=sip.mydomain.com ; host name of this server +tempdir=/var/spool/asterisk/tmp/ ; temporary directory for storing temporary output + +[asmanager] +server=localhost ; server to connect to +port=5038 ; default manager port +username=me_and_only_me ; username for login +secret=i_am_not_telling ; password for login + +[fastagi] +setuid=true ; drop privileges to owner of script +basedir=/var/lib/asterisk/agi-bin/ ; path to script folder + +[festival] ; text to speech engine +text2wave=/usr/bin/text2wave ; path to text2wave binary + +[cepstral] ; alternate text to speech engine +swift=/opt/swift/bin/swift ; path to switft binary +voice=David ; default voice + diff --git a/mkdocs.php b/mkdocs.php new file mode 100755 index 0000000..9620255 --- /dev/null +++ b/mkdocs.php @@ -0,0 +1,7 @@ +#!/usr/local/bin/php -q + + + diff --git a/phpagi-asmanager.php b/phpagi-asmanager.php new file mode 100644 index 0000000..b6d751d --- /dev/null +++ b/phpagi-asmanager.php @@ -0,0 +1,824 @@ +, David Eder and others + * All Rights Reserved. + * + * This software is released under the terms of the GNU Lesser General Public License v2.1 + * A copy of which is available from http://www.gnu.org/copyleft/lesser.html + * + * We would be happy to list your phpagi based application on the phpagi + * website. Drop me an Email if you'd like us to list your program. + * + * @package phpAGI + * @version 2.0 + */ + + + /** + * Written for PHP 4.3.4, should work with older PHP 4.x versions. + * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ + * Gracias. :) + * + */ + + if(!class_exists('AGI')) + { + require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php'); + } + + /** + * Asterisk Manager class + * + * @link http://www.voip-info.org/wiki-Asterisk+config+manager.conf + * @link http://www.voip-info.org/wiki-Asterisk+manager+API + * @example examples/sip_show_peer.php Get information about a sip peer + * @package phpAGI + */ + class AGI_AsteriskManager + { + /** + * Config variables + * + * @var array + * @access public + */ + public $config; + + /** + * Socket + * + * @access public + */ + public $socket = NULL; + + /** + * Server we are connected to + * + * @access public + * @var string + */ + public $server; + + /** + * Port on the server we are connected to + * + * @access public + * @var integer + */ + public $port; + + /** + * Parent AGI + * + * @access private + * @var AGI + */ + private $pagi; + + /** + * Event Handlers + * + * @access private + * @var array + */ + private $event_handlers; + + /** + * Whether we're successfully logged in + * + * @access private + * @var boolean + */ + private $_logged_in = FALSE; + + /** + * Constructor + * + * @param string $config is the name of the config file to parse or a parent agi from which to read the config + * @param array $optconfig is an array of configuration vars and vals, stuffed into $this->config['asmanager'] + */ + function AGI_AsteriskManager($config=NULL, $optconfig=array()) + { + // load config + if(!is_null($config) && file_exists($config)) + $this->config = parse_ini_file($config, true); + elseif(file_exists(DEFAULT_PHPAGI_CONFIG)) + $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true); + + // If optconfig is specified, stuff vals and vars into 'asmanager' config array. + foreach($optconfig as $var=>$val) + $this->config['asmanager'][$var] = $val; + + // add default values to config for uninitialized values + if(!isset($this->config['asmanager']['server'])) $this->config['asmanager']['server'] = 'localhost'; + if(!isset($this->config['asmanager']['port'])) $this->config['asmanager']['port'] = 5038; + if(!isset($this->config['asmanager']['username'])) $this->config['asmanager']['username'] = 'phpagi'; + if(!isset($this->config['asmanager']['secret'])) $this->config['asmanager']['secret'] = 'phpagi'; + } + + /** + * Send a request + * + * @param string $action + * @param array $parameters + * @return array of parameters + */ + function send_request($action, $parameters=array()) + { + $req = "Action: $action\r\n"; + foreach($parameters as $var=>$val) + $req .= "$var: $val\r\n"; + $req .= "\r\n"; + fwrite($this->socket, $req); + return $this->wait_response(); + } + + /** + * Wait for a response + * + * If a request was just sent, this will return the response. + * Otherwise, it will loop forever, handling events. + * + * @param boolean $allow_timeout if the socket times out, return an empty array + * @return array of parameters, empty on timeout + */ + function wait_response($allow_timeout=false) + { + $timeout = false; + do + { + $type = NULL; + $parameters = array(); + + $buffer = trim(fgets($this->socket, 4096)); + while($buffer != '') + { + $a = strpos($buffer, ':'); + if($a) + { + if(!count($parameters)) // first line in a response? + { + $type = strtolower(substr($buffer, 0, $a)); + if(substr($buffer, $a + 2) == 'Follows') + { + // A follows response means there is a miltiline field that follows. + $parameters['data'] = ''; + $buff = fgets($this->socket, 4096); + while(substr($buff, 0, 6) != '--END ') + { + $parameters['data'] .= $buff; + $buff = fgets($this->socket, 4096); + } + } + } + + // store parameter in $parameters + $parameters[substr($buffer, 0, $a)] = substr($buffer, $a + 2); + } + $buffer = trim(fgets($this->socket, 4096)); + } + + // process response + switch($type) + { + case '': // timeout occured + $timeout = $allow_timeout; + break; + case 'event': + $this->process_event($parameters); + break; + case 'response': + break; + default: + $this->log('Unhandled response packet from Manager: ' . print_r($parameters, true)); + break; + } + } while($type != 'response' && !$timeout); + return $parameters; + } + + /** + * Connect to Asterisk + * + * @example examples/sip_show_peer.php Get information about a sip peer + * + * @param string $server + * @param string $username + * @param string $secret + * @return boolean true on success + */ + function connect($server=NULL, $username=NULL, $secret=NULL) + { + // use config if not specified + if(is_null($server)) $server = $this->config['asmanager']['server']; + if(is_null($username)) $username = $this->config['asmanager']['username']; + if(is_null($secret)) $secret = $this->config['asmanager']['secret']; + + // get port from server if specified + if(strpos($server, ':') !== false) + { + $c = explode(':', $server); + $this->server = $c[0]; + $this->port = $c[1]; + } + else + { + $this->server = $server; + $this->port = $this->config['asmanager']['port']; + } + + // connect the socket + $errno = $errstr = NULL; + $this->socket = @fsockopen($this->server, $this->port, $errno, $errstr); + if($this->socket == false) + { + $this->log("Unable to connect to manager {$this->server}:{$this->port} ($errno): $errstr"); + return false; + } + + // read the header + $str = fgets($this->socket); + if($str == false) + { + // a problem. + $this->log("Asterisk Manager header not received."); + return false; + } + else + { + // note: don't $this->log($str) until someone looks to see why it mangles the logging + } + + // login + $res = $this->send_request('login', array('Username'=>$username, 'Secret'=>$secret)); + if($res['Response'] != 'Success') + { + $this->_logged_in = FALSE; + $this->log("Failed to login."); + $this->disconnect(); + return false; + } + $this->_logged_in = TRUE; + return true; + } + + /** + * Disconnect + * + * @example examples/sip_show_peer.php Get information about a sip peer + */ + function disconnect() + { + if($this->_logged_in==TRUE) + $this->logoff(); + fclose($this->socket); + } + + // ********************************************************************************************************* + // ** COMMANDS ** + // ********************************************************************************************************* + + /** + * Set Absolute Timeout + * + * Hangup a channel after a certain time. + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+AbsoluteTimeout + * @param string $channel Channel name to hangup + * @param integer $timeout Maximum duration of the call (sec) + */ + function AbsoluteTimeout($channel, $timeout) + { + return $this->send_request('AbsoluteTimeout', array('Channel'=>$channel, 'Timeout'=>$timeout)); + } + + /** + * Change monitoring filename of a channel + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ChangeMonitor + * @param string $channel the channel to record. + * @param string $file the new name of the file created in the monitor spool directory. + */ + function ChangeMonitor($channel, $file) + { + return $this->send_request('ChangeMontior', array('Channel'=>$channel, 'File'=>$file)); + } + + /** + * Execute Command + * + * @example examples/sip_show_peer.php Get information about a sip peer + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Command + * @link http://www.voip-info.org/wiki-Asterisk+CLI + * @param string $command + * @param string $actionid message matching variable + */ + function Command($command, $actionid=NULL) + { + $parameters = array('Command'=>$command); + if($actionid) $parameters['ActionID'] = $actionid; + return $this->send_request('Command', $parameters); + } + + /** + * Enable/Disable sending of events to this manager + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Events + * @param string $eventmask is either 'on', 'off', or 'system,call,log' + */ + function Events($eventmask) + { + return $this->send_request('Events', array('EventMask'=>$eventmask)); + } + + /** + * Check Extension Status + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ExtensionState + * @param string $exten Extension to check state on + * @param string $context Context for extension + * @param string $actionid message matching variable + */ + function ExtensionState($exten, $context, $actionid=NULL) + { + $parameters = array('Exten'=>$exten, 'Context'=>$context); + if($actionid) $parameters['ActionID'] = $actionid; + return $this->send_request('ExtensionState', $parameters); + } + + /** + * Gets a Channel Variable + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+GetVar + * @link http://www.voip-info.org/wiki-Asterisk+variables + * @param string $channel Channel to read variable from + * @param string $variable + * @param string $actionid message matching variable + */ + function GetVar($channel, $variable, $actionid=NULL) + { + $parameters = array('Channel'=>$channel, 'Variable'=>$variable); + if($actionid) $parameters['ActionID'] = $actionid; + return $this->send_request('GetVar', $parameters); + } + + /** + * Hangup Channel + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Hangup + * @param string $channel The channel name to be hungup + */ + function Hangup($channel) + { + return $this->send_request('Hangup', array('Channel'=>$channel)); + } + + /** + * List IAX Peers + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+IAXpeers + */ + function IAXPeers() + { + return $this->send_request('IAXPeers'); + } + + /** + * List available manager commands + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ListCommands + * @param string $actionid message matching variable + */ + function ListCommands($actionid=NULL) + { + if($actionid) + return $this->send_request('ListCommands', array('ActionID'=>$actionid)); + else + return $this->send_request('ListCommands'); + } + + /** + * Logoff Manager + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Logoff + */ + function Logoff() + { + return $this->send_request('Logoff'); + } + + /** + * Check Mailbox Message Count + * + * Returns number of new and old messages. + * Message: Mailbox Message Count + * Mailbox: + * NewMessages: + * OldMessages: + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxCount + * @param string $mailbox Full mailbox ID @ + * @param string $actionid message matching variable + */ + function MailboxCount($mailbox, $actionid=NULL) + { + $parameters = array('Mailbox'=>$mailbox); + if($actionid) $parameters['ActionID'] = $actionid; + return $this->send_request('MailboxCount', $parameters); + } + + /** + * Check Mailbox + * + * Returns number of messages. + * Message: Mailbox Status + * Mailbox: + * Waiting: + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxStatus + * @param string $mailbox Full mailbox ID @ + * @param string $actionid message matching variable + */ + function MailboxStatus($mailbox, $actionid=NULL) + { + $parameters = array('Mailbox'=>$mailbox); + if($actionid) $parameters['ActionID'] = $actionid; + return $this->send_request('MailboxStatus', $parameters); + } + + /** + * Monitor a channel + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Monitor + * @param string $channel + * @param string $file + * @param string $format + * @param boolean $mix + */ + function Monitor($channel, $file=NULL, $format=NULL, $mix=NULL) + { + $parameters = array('Channel'=>$channel); + if($file) $parameters['File'] = $file; + if($format) $parameters['Format'] = $format; + if(!is_null($file)) $parameters['Mix'] = ($mix) ? 'true' : 'false'; + return $this->send_request('Monitor', $parameters); + } + + /** + * Originate Call + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Originate + * @param string $channel Channel name to call + * @param string $exten Extension to use (requires 'Context' and 'Priority') + * @param string $context Context to use (requires 'Exten' and 'Priority') + * @param string $priority Priority to use (requires 'Exten' and 'Context') + * @param string $application Application to use + * @param string $data Data to use (requires 'Application') + * @param integer $timeout How long to wait for call to be answered (in ms) + * @param string $callerid Caller ID to be set on the outgoing channel + * @param string $variable Channel variable to set (VAR1=value1|VAR2=value2) + * @param string $account Account code + * @param boolean $async true fast origination + * @param string $actionid message matching variable + */ + function Originate($channel, + $exten=NULL, $context=NULL, $priority=NULL, + $application=NULL, $data=NULL, + $timeout=NULL, $callerid=NULL, $variable=NULL, $account=NULL, $async=NULL, $actionid=NULL) + { + $parameters = array('Channel'=>$channel); + + if($exten) $parameters['Exten'] = $exten; + if($context) $parameters['Context'] = $context; + if($priority) $parameters['Priority'] = $priority; + + if($application) $parameters['Application'] = $application; + if($data) $parameters['Data'] = $data; + + if($timeout) $parameters['Timeout'] = $timeout; + if($callerid) $parameters['CallerID'] = $callerid; + if($variable) $parameters['Variable'] = $variable; + if($account) $parameters['Account'] = $account; + if(!is_null($async)) $parameters['Async'] = ($async) ? 'true' : 'false'; + if($actionid) $parameters['ActionID'] = $actionid; + + return $this->send_request('Originate', $parameters); + } + + /** + * List parked calls + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ParkedCalls + * @param string $actionid message matching variable + */ + function ParkedCalls($actionid=NULL) + { + if($actionid) + return $this->send_request('ParkedCalls', array('ActionID'=>$actionid)); + else + return $this->send_request('ParkedCalls'); + } + + /** + * Ping + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Ping + */ + function Ping() + { + return $this->send_request('Ping'); + } + + /** + * Queue Add + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueAdd + * @param string $queue + * @param string $interface + * @param integer $penalty + */ + function QueueAdd($queue, $interface, $penalty=0) + { + $parameters = array('Queue'=>$queue, 'Interface'=>$interface); + if($penalty) $parameters['Penalty'] = $penalty; + return $this->send_request('QueueAdd', $parameters); + } + + /** + * Queue Remove + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueRemove + * @param string $queue + * @param string $interface + */ + function QueueRemove($queue, $interface) + { + return $this->send_request('QueueRemove', array('Queue'=>$queue, 'Interface'=>$interface)); + } + + /** + * Queues + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Queues + */ + function Queues() + { + return $this->send_request('Queues'); + } + + /** + * Queue Status + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueStatus + * @param string $actionid message matching variable + */ + function QueueStatus($actionid=NULL) + { + if($actionid) + return $this->send_request('QueueStatus', array('ActionID'=>$actionid)); + else + return $this->send_request('QueueStatus'); + } + + /** + * Redirect + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Redirect + * @param string $channel + * @param string $extrachannel + * @param string $exten + * @param string $context + * @param string $priority + */ + function Redirect($channel, $extrachannel, $exten, $context, $priority) + { + return $this->send_request('Redirect', array('Channel'=>$channel, 'ExtraChannel'=>$extrachannel, 'Exten'=>$exten, + 'Context'=>$context, 'Priority'=>$priority)); + } + + /** + * Set the CDR UserField + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetCDRUserField + * @param string $userfield + * @param string $channel + * @param string $append + */ + function SetCDRUserField($userfield, $channel, $append=NULL) + { + $parameters = array('UserField'=>$userfield, 'Channel'=>$channel); + if($append) $parameters['Append'] = $append; + return $this->send_request('SetCDRUserField', $parameters); + } + + /** + * Set Channel Variable + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetVar + * @param string $channel Channel to set variable for + * @param string $variable name + * @param string $value + */ + function SetVar($channel, $variable, $value) + { + return $this->send_request('SetVar', array('Channel'=>$channel, 'Variable'=>$variable, 'Value'=>$value)); + } + + /** + * Channel Status + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Status + * @param string $channel + * @param string $actionid message matching variable + */ + function Status($channel, $actionid=NULL) + { + $parameters = array('Channel'=>$channel); + if($actionid) $parameters['ActionID'] = $actionid; + return $this->send_request('Status', $parameters); + } + + /** + * Stop monitoring a channel + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+StopMonitor + * @param string $channel + */ + function StopMonitor($channel) + { + return $this->send_request('StopMonitor', array('Channel'=>$channel)); + } + + /** + * Dial over Zap channel while offhook + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDialOffhook + * @param string $zapchannel + * @param string $number + */ + function ZapDialOffhook($zapchannel, $number) + { + return $this->send_request('ZapDialOffhook', array('ZapChannel'=>$zapchannel, 'Number'=>$number)); + } + + /** + * Toggle Zap channel Do Not Disturb status OFF + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDoff + * @param string $zapchannel + */ + function ZapDNDoff($zapchannel) + { + return $this->send_request('ZapDNDoff', array('ZapChannel'=>$zapchannel)); + } + + /** + * Toggle Zap channel Do Not Disturb status ON + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDon + * @param string $zapchannel + */ + function ZapDNDon($zapchannel) + { + return $this->send_request('ZapDNDon', array('ZapChannel'=>$zapchannel)); + } + + /** + * Hangup Zap Channel + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapHangup + * @param string $zapchannel + */ + function ZapHangup($zapchannel) + { + return $this->send_request('ZapHangup', array('ZapChannel'=>$zapchannel)); + } + + /** + * Transfer Zap Channel + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapTransfer + * @param string $zapchannel + */ + function ZapTransfer($zapchannel) + { + return $this->send_request('ZapTransfer', array('ZapChannel'=>$zapchannel)); + } + + /** + * Zap Show Channels + * + * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapShowChannels + * @param string $actionid message matching variable + */ + function ZapShowChannels($actionid=NULL) + { + if($actionid) + return $this->send_request('ZapShowChannels', array('ActionID'=>$actionid)); + else + return $this->send_request('ZapShowChannels'); + } + + // ********************************************************************************************************* + // ** MISC ** + // ********************************************************************************************************* + + /* + * Log a message + * + * @param string $message + * @param integer $level from 1 to 4 + */ + function log($message, $level=1) + { + if($this->pagi != false) + $this->pagi->conlog($message, $level); + else + error_log(date('r') . ' - ' . $message); + } + + /** + * Add event handler + * + * Known Events include ( http://www.voip-info.org/wiki-asterisk+manager+events ) + * Link - Fired when two voice channels are linked together and voice data exchange commences. + * Unlink - Fired when a link between two voice channels is discontinued, for example, just before call completion. + * Newexten - + * Hangup - + * Newchannel - + * Newstate - + * Reload - Fired when the "RELOAD" console command is executed. + * Shutdown - + * ExtensionStatus - + * Rename - + * Newcallerid - + * Alarm - + * AlarmClear - + * Agentcallbacklogoff - + * Agentcallbacklogin - + * Agentlogoff - + * MeetmeJoin - + * MessageWaiting - + * join - + * leave - + * AgentCalled - + * ParkedCall - Fired after ParkedCalls + * Cdr - + * ParkedCallsComplete - + * QueueParams - + * QueueMember - + * QueueStatusEnd - + * Status - + * StatusComplete - + * ZapShowChannels - Fired after ZapShowChannels + * ZapShowChannelsComplete - + * + * @param string $event type or * for default handler + * @param string $callback function + * @return boolean sucess + */ + function add_event_handler($event, $callback) + { + $event = strtolower($event); + if(isset($this->event_handlers[$event])) + { + $this->log("$event handler is already defined, not over-writing."); + return false; + } + $this->event_handlers[$event] = $callback; + return true; + } + + /** + * Process event + * + * @access private + * @param array $parameters + * @return mixed result of event handler or false if no handler was found + */ + function process_event($parameters) + { + $ret = false; + $e = strtolower($parameters['Event']); + $this->log("Got event.. $e"); + + $handler = ''; + if(isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e]; + elseif(isset($this->event_handlers['*'])) $handler = $this->event_handlers['*']; + + if(function_exists($handler)) + { + $this->log("Execute handler $handler"); + $ret = $handler($e, $parameters, $this->server, $this->port); + } + else + $this->log("No event handler for event '$e'"); + return $ret; + } + } +?> diff --git a/phpagi-fastagi.php b/phpagi-fastagi.php new file mode 100755 index 0000000..7297626 --- /dev/null +++ b/phpagi-fastagi.php @@ -0,0 +1,79 @@ +#!/usr/local/bin/php -q +, David Eder + * All Rights Reserved. + * + * This software is released under the terms of the GNU Lesser General Public License v2.1 + * A copy of which is available from http://www.gnu.org/copyleft/lesser.html + * + * We would be happy to list your phpagi based application on the phpagi + * website. Drop me an Email if you'd like us to list your program. + * + * @package phpAGI + * @version 2.0 + * @example docs/fastagi.xinetd Example xinetd config file + */ + + /** + * Written for PHP 4.3.4, should work with older PHP 4.x versions. + * Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ + * Gracias. :) + * + */ + + require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi.php'); + + $fastagi = new AGI(); + + $fastagi->verbose(print_r($fastagi, true)); + + if(!isset($fastagi->config['fastagi']['basedir'])) + $fastagi->config['fastagi']['basedir'] = dirname(__FILE__); + + // perform some security checks + + $script = $fastagi->config['fastagi']['basedir'] . DIRECTORY_SEPARATOR . $fastagi->request['agi_network_script']; + + // in the same directory (or subdirectory) + $mydir = dirname($fastagi->config['fastagi']['basedir']) . DIRECTORY_SEPARATOR; + $dir = dirname($script) . DIRECTORY_SEPARATOR; + if(substr($dir, 0, strlen($mydir)) != $mydir) + { + $fastagi->conlog("$script is not allowed to execute."); + exit; + } + + // make sure it exists + if(!file_exists($script)) + { + $fastagi->conlog("$script does not exist."); + exit; + } + + // drop privileges + if(isset($fastagi->config['fastagi']['setuid']) && $fastagi->config['fastagi']['setuid']) + { + $owner = fileowner($script); + $group = filegroup($script); + if(!posix_setgid($group) || !posix_setegid($group) || !posix_setuid($owner) || !posix_seteuid($owner)) + { + $fastagi->conlog("failed to lower privileges."); + exit; + } + } + + // make sure script is still readable + if(!is_readable($script)) + { + $fastagi->conlog("$script is not readable."); + exit; + } + + require_once($script); +?> diff --git a/phpagi.php b/phpagi.php new file mode 100644 index 0000000..3441d34 --- /dev/null +++ b/phpagi.php @@ -0,0 +1,1826 @@ +, David Eder and others +* All Rights Reserved. +* +* This software is released under the terms of the GNU Lesser General Public License v2.1 +* A copy of which is available from http://www.gnu.org/copyleft/lesser.html +* +* We would be happy to list your phpagi based application on the phpagi +* website. Drop me an Email if you'd like us to list your program. +* +* +* Written for PHP 4.3.4, should work with older PHP 4.x versions. +* +* Please submit bug reports, patches, etc to http://sourceforge.net/projects/phpagi/ +* Gracias. :) +* +* +* @package phpAGI +* @version 2.20 +*/ + +if (!class_exists('AGI_AsteriskManager')) +{ + require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'phpagi-asmanager.php'); +} + +define('AST_CONFIG_DIR', '/etc/asterisk/'); +define('AST_SPOOL_DIR', '/var/spool/asterisk/'); +define('AST_TMP_DIR', AST_SPOOL_DIR . '/tmp/'); +define('DEFAULT_PHPAGI_CONFIG', AST_CONFIG_DIR . '/phpagi.conf'); + +define('AST_DIGIT_ANY', '0123456789#*'); + +define('AGIRES_OK', 200); + +define('AST_STATE_DOWN', 0); +define('AST_STATE_RESERVED', 1); +define('AST_STATE_OFFHOOK', 2); +define('AST_STATE_DIALING', 3); +define('AST_STATE_RING', 4); +define('AST_STATE_RINGING', 5); +define('AST_STATE_UP', 6); +define('AST_STATE_BUSY', 7); +define('AST_STATE_DIALING_OFFHOOK', 8); +define('AST_STATE_PRERING', 9); + +define('AUDIO_FILENO', 3); // STDERR_FILENO + 1 + +/** +* AGI class +* +* @package phpAGI +* @link http://www.voip-info.org/wiki-Asterisk+agi +* @example examples/dtmf.php Get DTMF tones from the user and say the digits +* @example examples/input.php Get text input from the user and say it back +* @example examples/ping.php Ping an IP address +*/ +class AGI +{ + /** + * Request variables read in on initialization. + * + * Often contains any/all of the following: + * agi_request - name of agi script + * agi_channel - current channel + * agi_language - current language + * agi_type - channel type (SIP, ZAP, IAX, ...) + * agi_uniqueid - unique id based on unix time + * agi_callerid - callerID string + * agi_dnid - dialed number id + * agi_rdnis - referring DNIS number + * agi_context - current context + * agi_extension - extension dialed + * agi_priority - current priority + * agi_enhanced - value is 1.0 if started as an EAGI script + * agi_accountcode - set by SetAccount in the dialplan + * agi_network - value is yes if this is a fastagi + * agi_network_script - name of the script to execute + * + * NOTE: program arguments are still in $_SERVER['argv']. + * + * @var array + * @access public + */ + var $request; + + /** + * Config variables + * + * @var array + * @access public + */ + var $config; + + /** + * Asterisk Manager + * + * @var AGI_AsteriskManager + * @access public + */ + var $asmanager; + + /** + * Input Stream + * + * @access private + */ + var $in = NULL; + + /** + * Output Stream + * + * @access private + */ + var $out = NULL; + + /** + * Audio Stream + * + * @access public + */ + var $audio = NULL; + + + /** + * Application option delimiter + * + * @access public + */ + public $option_delim = ","; + + /** + * Constructor + * + * @param string $config is the name of the config file to parse + * @param array $optconfig is an array of configuration vars and vals, stuffed into $this->config['phpagi'] + */ + function __construct($config=NULL, $optconfig=array()) + { + // load config + if(!is_null($config) && file_exists($config)) + $this->config = parse_ini_file($config, true); + elseif(file_exists(DEFAULT_PHPAGI_CONFIG)) + $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true); + + // If optconfig is specified, stuff vals and vars into 'phpagi' config array. + foreach($optconfig as $var=>$val) + $this->config['phpagi'][$var] = $val; + + // add default values to config for uninitialized values + if(!isset($this->config['phpagi']['error_handler'])) $this->config['phpagi']['error_handler'] = true; + if(!isset($this->config['phpagi']['debug'])) $this->config['phpagi']['debug'] = false; + if(!isset($this->config['phpagi']['admin'])) $this->config['phpagi']['admin'] = NULL; + if(!isset($this->config['phpagi']['tempdir'])) $this->config['phpagi']['tempdir'] = AST_TMP_DIR; + + // festival TTS config + if(!isset($this->config['festival']['text2wave'])) $this->config['festival']['text2wave'] = $this->which('text2wave'); + + // swift TTS config + if(!isset($this->config['cepstral']['swift'])) $this->config['cepstral']['swift'] = $this->which('swift'); + + ob_implicit_flush(true); + + // open stdin & stdout + $this->in = defined('STDIN') ? STDIN : fopen('php://stdin', 'r'); + $this->out = defined('STDOUT') ? STDOUT : fopen('php://stdout', 'w'); + + // initialize error handler + if($this->config['phpagi']['error_handler'] == true) + { + set_error_handler('phpagi_error_handler'); + global $phpagi_error_handler_email; + $phpagi_error_handler_email = $this->config['phpagi']['admin']; + error_reporting(E_ALL); + } + + // make sure temp folder exists + $this->make_folder($this->config['phpagi']['tempdir']); + + // read the request + $str = fgets($this->in); + while($str != "\n") + { + $this->request[substr($str, 0, strpos($str, ':'))] = trim(substr($str, strpos($str, ':') + 1)); + $str = fgets($this->in); + } + + // open audio if eagi detected + if($this->request['agi_enhanced'] == '1.0') + { + if(file_exists('/proc/' . getmypid() . '/fd/3')) + $this->audio = fopen('/proc/' . getmypid() . '/fd/3', 'r'); + elseif(file_exists('/dev/fd/3')) + { + // may need to mount fdescfs + $this->audio = fopen('/dev/fd/3', 'r'); + } + else + $this->conlog('Unable to open audio stream'); + + if($this->audio) stream_set_blocking($this->audio, 0); + } + + $this->conlog('AGI Request:'); + $this->conlog(print_r($this->request, true)); + $this->conlog('PHPAGI internal configuration:'); + $this->conlog(print_r($this->config, true)); + } + + // ********************************************************************************************************* + // ** COMMANDS ** + // ********************************************************************************************************* + + /** + * Answer channel if not already in answer state. + * + * @link http://www.voip-info.org/wiki-answer + * @example examples/dtmf.php Get DTMF tones from the user and say the digits + * @example examples/input.php Get text input from the user and say it back + * @example examples/ping.php Ping an IP address + * + * @return array, see evaluate for return information. ['result'] is 0 on success, -1 on failure. + */ + function answer() + { + return $this->evaluate('ANSWER'); + } + + /** + * Get the status of the specified channel. If no channel name is specified, return the status of the current channel. + * + * @link http://www.voip-info.org/wiki-channel+status + * @param string $channel + * @return array, see evaluate for return information. ['data'] contains description. + */ + function channel_status($channel='') + { + $ret = $this->evaluate("CHANNEL STATUS $channel"); + switch($ret['result']) + { + case -1: $ret['data'] = trim("There is no channel that matches $channel"); break; + case AST_STATE_DOWN: $ret['data'] = 'Channel is down and available'; break; + case AST_STATE_RESERVED: $ret['data'] = 'Channel is down, but reserved'; break; + case AST_STATE_OFFHOOK: $ret['data'] = 'Channel is off hook'; break; + case AST_STATE_DIALING: $ret['data'] = 'Digits (or equivalent) have been dialed'; break; + case AST_STATE_RING: $ret['data'] = 'Line is ringing'; break; + case AST_STATE_RINGING: $ret['data'] = 'Remote end is ringing'; break; + case AST_STATE_UP: $ret['data'] = 'Line is up'; break; + case AST_STATE_BUSY: $ret['data'] = 'Line is busy'; break; + case AST_STATE_DIALING_OFFHOOK: $ret['data'] = 'Digits (or equivalent) have been dialed while offhook'; break; + case AST_STATE_PRERING: $ret['data'] = 'Channel has detected an incoming call and is waiting for ring'; break; + default: $ret['data'] = "Unknown ({$ret['result']})"; break; + } + return $ret; + } + + /** + * Deletes an entry in the Asterisk database for a given family and key. + * + * @link http://www.voip-info.org/wiki-database+del + * @param string $family + * @param string $key + * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise. + */ + function database_del($family, $key) + { + return $this->evaluate("DATABASE DEL \"$family\" \"$key\""); + } + + /** + * Deletes a family or specific keytree within a family in the Asterisk database. + * + * @link http://www.voip-info.org/wiki-database+deltree + * @param string $family + * @param string $keytree + * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise. + */ + function database_deltree($family, $keytree='') + { + $cmd = "DATABASE DELTREE \"$family\""; + if($keytree != '') $cmd .= " \"$keytree\""; + return $this->evaluate($cmd); + } + + /** + * Retrieves an entry in the Asterisk database for a given family and key. + * + * @link http://www.voip-info.org/wiki-database+get + * @param string $family + * @param string $key + * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 failure. ['data'] holds the value + */ + function database_get($family, $key) + { + return $this->evaluate("DATABASE GET \"$family\" \"$key\""); + } + + /** + * Adds or updates an entry in the Asterisk database for a given family, key, and value. + * + * @param string $family + * @param string $key + * @param string $value + * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise + */ + function database_put($family, $key, $value) + { + $value = str_replace("\n", '\n', addslashes($value)); + return $this->evaluate("DATABASE PUT \"$family\" \"$key\" \"$value\""); + } + + + /** + * Sets a global variable, using Asterisk 1.6 syntax. + * + * @link http://www.voip-info.org/wiki/view/Asterisk+cmd+Set + * + * @param string $pVariable + * @param string|int|float $pValue + * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise + */ + function set_global_var($pVariable, $pValue) + { + if (is_numeric($pValue)) + return $this->evaluate("Set({$pVariable}={$pValue},g);"); + else + return $this->evaluate("Set({$pVariable}=\"{$pValue}\",g);"); + } + + + /** + * Sets a variable, using Asterisk 1.6 syntax. + * + * @link http://www.voip-info.org/wiki/view/Asterisk+cmd+Set + * + * @param string $pVariable + * @param string|int|float $pValue + * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise + */ + function set_var($pVariable, $pValue) + { + if (is_numeric($pValue)) + return $this->evaluate("Set({$pVariable}={$pValue});"); + else + return $this->evaluate("Set({$pVariable}=\"{$pValue}\");"); + } + + + /** + * Executes the specified Asterisk application with given options. + * + * @link http://www.voip-info.org/wiki-exec + * @link http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands + * @param string $application + * @param mixed $options + * @return array, see evaluate for return information. ['result'] is whatever the application returns, or -2 on failure to find application + */ + function exec($application, $options) + { + if(is_array($options)) $options = join('|', $options); + return $this->evaluate("EXEC $application $options"); + } + + /** + * Plays the given file and receives DTMF data. + * + * This is similar to STREAM FILE, but this command can accept and return many DTMF digits, + * while STREAM FILE returns immediately after the first DTMF digit is detected. + * + * Asterisk looks for the file to play in /var/lib/asterisk/sounds by default. + * + * If the user doesn't press any keys when the message plays, there is $timeout milliseconds + * of silence then the command ends. + * + * The user has the opportunity to press a key at any time during the message or the + * post-message silence. If the user presses a key while the message is playing, the + * message stops playing. When the first key is pressed a timer starts counting for + * $timeout milliseconds. Every time the user presses another key the timer is restarted. + * The command ends when the counter goes to zero or the maximum number of digits is entered, + * whichever happens first. + * + * If you don't specify a time out then a default timeout of 2000 is used following a pressed + * digit. If no digits are pressed then 6 seconds of silence follow the message. + * + * If you don't specify $max_digits then the user can enter as many digits as they want. + * + * Pressing the # key has the same effect as the timer running out: the command ends and + * any previously keyed digits are returned. A side effect of this is that there is no + * way to read a # key using this command. + * + * @example examples/ping.php Ping an IP address + * + * @link http://www.voip-info.org/wiki-get+data + * @param string $filename file to play. Do not include file extension. + * @param integer $timeout milliseconds + * @param integer $max_digits + * @return array, see evaluate for return information. ['result'] holds the digits and ['data'] holds the timeout if present. + * + * This differs from other commands with return DTMF as numbers representing ASCII characters. + */ + function get_data($filename, $timeout=NULL, $max_digits=NULL) + { + return $this->evaluate(rtrim("GET DATA $filename $timeout $max_digits")); + } + + /** + * Fetch the value of a variable. + * + * Does not work with global variables. Does not work with some variables that are generated by modules. + * + * @link http://www.voip-info.org/wiki-get+variable + * @link http://www.voip-info.org/wiki-Asterisk+variables + * @param string $variable name + * @param boolean $getvalue return the value only + * @return array, see evaluate for return information. ['result'] is 0 if variable hasn't been set, 1 if it has. ['data'] holds the value. returns value if $getvalue is TRUE + */ + function get_variable($variable,$getvalue=FALSE) + { + $res=$this->evaluate("GET VARIABLE $variable"); + + if($getvalue==FALSE) + return($res); + + return($res['data']); + } + + + /** + * Fetch the value of a full variable. + * + * + * @link http://www.voip-info.org/wiki/view/get+full+variable + * @link http://www.voip-info.org/wiki-Asterisk+variables + * @param string $variable name + * @param string $channel channel + * @param boolean $getvalue return the value only + * @return array, see evaluate for return information. ['result'] is 0 if variable hasn't been set, 1 if it has. ['data'] holds the value. returns value if $getvalue is TRUE + */ + function get_fullvariable($variable,$channel=FALSE,$getvalue=FALSE) + { + if($channel==FALSE){ + $req = $variable; + } else { + $req = $variable.' '.$channel; + } + + $res=$this->evaluate('GET VARIABLE FULL '.$req); + + if($getvalue==FALSE) + return($res); + + return($res['data']); + + } + + /** + * Hangup the specified channel. If no channel name is given, hang up the current channel. + * + * With power comes responsibility. Hanging up channels other than your own isn't something + * that is done routinely. If you are not sure why you are doing so, then don't. + * + * @link http://www.voip-info.org/wiki-hangup + * @example examples/dtmf.php Get DTMF tones from the user and say the digits + * @example examples/input.php Get text input from the user and say it back + * @example examples/ping.php Ping an IP address + * + * @param string $channel + * @return array, see evaluate for return information. ['result'] is 1 on success, -1 on failure. + */ + function hangup($channel='') + { + return $this->evaluate("HANGUP $channel"); + } + + /** + * Does nothing. + * + * @link http://www.voip-info.org/wiki-noop + * @return array, see evaluate for return information. + */ + function noop($string="") + { + return $this->evaluate("NOOP \"$string\""); + } + + /** + * Receive a character of text from a connected channel. Waits up to $timeout milliseconds for + * a character to arrive, or infinitely if $timeout is zero. + * + * @link http://www.voip-info.org/wiki-receive+char + * @param integer $timeout milliseconds + * @return array, see evaluate for return information. ['result'] is 0 on timeout or not supported, -1 on failure. Otherwise + * it is the decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function receive_char($timeout=-1) + { + return $this->evaluate("RECEIVE CHAR $timeout"); + } + + /** + * Record sound to a file until an acceptable DTMF digit is received or a specified amount of + * time has passed. Optionally the file BEEP is played before recording begins. + * + * @link http://www.voip-info.org/wiki-record+file + * @param string $file to record, without extension, often created in /var/lib/asterisk/sounds + * @param string $format of the file. GSM and WAV are commonly used formats. MP3 is read-only and thus cannot be used. + * @param string $escape_digits + * @param integer $timeout is the maximum record time in milliseconds, or -1 for no timeout. + * @param integer $offset to seek to without exceeding the end of the file. + * @param boolean $beep + * @param integer $silence number of seconds of silence allowed before the function returns despite the + * lack of dtmf digits or reaching timeout. + * @return array, see evaluate for return information. ['result'] is -1 on error, 0 on hangup, otherwise a decimal value of the + * DTMF tone. Use chr() to convert to ASCII. + */ + function record_file($file, $format, $escape_digits='', $timeout=-1, $offset=NULL, $beep=false, $silence=NULL) + { + $cmd = trim("RECORD FILE $file $format \"$escape_digits\" $timeout $offset"); + if($beep) $cmd .= ' BEEP'; + if(!is_null($silence)) $cmd .= " s=$silence"; + return $this->evaluate($cmd); + } + + /** + * Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel. + * + * @link http://www.voip-info.org/wiki-say+digits + * @param integer $digits + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function say_digits($digits, $escape_digits='') + { + return $this->evaluate("SAY DIGITS $digits \"$escape_digits\""); + } + + /** + * Say the given number, returning early if any of the given DTMF escape digits are received on the channel. + * + * @link http://www.voip-info.org/wiki-say+number + * @param integer $number + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function say_number($number, $escape_digits='') + { + return $this->evaluate("SAY NUMBER $number \"$escape_digits\""); + } + + /** + * Say the given character string, returning early if any of the given DTMF escape digits are received on the channel. + * + * @link http://www.voip-info.org/wiki-say+phonetic + * @param string $text + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function say_phonetic($text, $escape_digits='') + { + return $this->evaluate("SAY PHONETIC $text \"$escape_digits\""); + } + + /** + * Say a given time, returning early if any of the given DTMF escape digits are received on the channel. + * + * @link http://www.voip-info.org/wiki-say+time + * @param integer $time number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC). + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function say_time($time=NULL, $escape_digits='') + { + if(is_null($time)) $time = time(); + return $this->evaluate("SAY TIME $time \"$escape_digits\""); + } + + /** + * Send the specified image on a channel. + * + * Most channels do not support the transmission of images. + * + * @link http://www.voip-info.org/wiki-send+image + * @param string $image without extension, often in /var/lib/asterisk/images + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the image is sent or + * channel does not support image transmission. + */ + function send_image($image) + { + return $this->evaluate("SEND IMAGE $image"); + } + + /** + * Send the given text to the connected channel. + * + * Most channels do not support transmission of text. + * + * @link http://www.voip-info.org/wiki-send+text + * @param $text + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if the text is sent or + * channel does not support text transmission. + */ + function send_text($text) + { + return $this->evaluate("SEND TEXT \"$text\""); + } + + /** + * Cause the channel to automatically hangup at $time seconds in the future. + * If $time is 0 then the autohangup feature is disabled on this channel. + * + * If the channel is hungup prior to $time seconds, this setting has no effect. + * + * @link http://www.voip-info.org/wiki-set+autohangup + * @param integer $time until automatic hangup + * @return array, see evaluate for return information. + */ + function set_autohangup($time=0) + { + return $this->evaluate("SET AUTOHANGUP $time"); + } + + /** + * Changes the caller ID of the current channel. + * + * @link http://www.voip-info.org/wiki-set+callerid + * @param string $cid example: "John Smith"<1234567> + * This command will let you take liberties with the but the format shown in the example above works + * well: the name enclosed in double quotes followed immediately by the number inside angle brackets. If there is no name then + * you can omit it. If the name contains no spaces you can omit the double quotes around it. The number must follow the name + * immediately; don't put a space between them. The angle brackets around the number are necessary; if you omit them the + * number will be considered to be part of the name. + * @return array, see evaluate for return information. + */ + function set_callerid($cid) + { + return $this->evaluate("SET CALLERID $cid"); + } + + /** + * Sets the context for continuation upon exiting the application. + * + * Setting the context does NOT automatically reset the extension and the priority; if you want to start at the top of the new + * context you should set extension and priority yourself. + * + * If you specify a non-existent context you receive no error indication (['result'] is still 0) but you do get a + * warning message on the Asterisk console. + * + * @link http://www.voip-info.org/wiki-set+context + * @param string $context + * @return array, see evaluate for return information. + */ + function set_context($context) + { + return $this->evaluate("SET CONTEXT $context"); + } + + /** + * Set the extension to be used for continuation upon exiting the application. + * + * Setting the extension does NOT automatically reset the priority. If you want to start with the first priority of the + * extension you should set the priority yourself. + * + * If you specify a non-existent extension you receive no error indication (['result'] is still 0) but you do + * get a warning message on the Asterisk console. + * + * @link http://www.voip-info.org/wiki-set+extension + * @param string $extension + * @return array, see evaluate for return information. + */ + function set_extension($extension) + { + return $this->evaluate("SET EXTENSION $extension"); + } + + /** + * Enable/Disable Music on hold generator. + * + * @link http://www.voip-info.org/wiki-set+music + * @param boolean $enabled + * @param string $class + * @return array, see evaluate for return information. + */ + function set_music($enabled=true, $class='') + { + $enabled = ($enabled) ? 'ON' : 'OFF'; + return $this->evaluate("SET MUSIC $enabled $class"); + } + + /** + * Set the priority to be used for continuation upon exiting the application. + * + * If you specify a non-existent priority you receive no error indication (['result'] is still 0) + * and no warning is issued on the Asterisk console. + * + * @link http://www.voip-info.org/wiki-set+priority + * @param integer $priority + * @return array, see evaluate for return information. + */ + function set_priority($priority) + { + return $this->evaluate("SET PRIORITY $priority"); + } + + /** + * Sets a variable to the specified value. The variables so created can later be used by later using ${} + * in the dialplan. + * + * These variables live in the channel Asterisk creates when you pickup a phone and as such they are both local and temporary. + * Variables created in one channel can not be accessed by another channel. When you hang up the phone, the channel is deleted + * and any variables in that channel are deleted as well. + * + * @link http://www.voip-info.org/wiki-set+variable + * @param string $variable is case sensitive + * @param string $value + * @return array, see evaluate for return information. + */ + function set_variable($variable, $value) + { + $value = str_replace("\n", '\n', addslashes($value)); + return $this->evaluate("SET VARIABLE $variable \"$value\""); + } + + /** + * Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA + * command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of + * digits before returning. + * + * @example examples/ping.php Ping an IP address + * + * @link http://www.voip-info.org/wiki-stream+file + * @param string $filename without extension, often in /var/lib/asterisk/sounds + * @param string $escape_digits + * @param integer $offset + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function stream_file($filename, $escape_digits='', $offset=0) + { + return $this->evaluate("STREAM FILE $filename \"$escape_digits\" $offset"); + } + + /** + * Enable or disable TDD transmission/reception on the current channel. + * + * @link http://www.voip-info.org/wiki-tdd+mode + * @param string $setting can be on, off or mate + * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 if the channel is not TDD capable. + */ + function tdd_mode($setting) + { + return $this->evaluate("TDD MODE $setting"); + } + + /** + * Sends $message to the Asterisk console via the 'verbose' message system. + * + * If the Asterisk verbosity level is $level or greater, send $message to the console. + * + * The Asterisk verbosity system works as follows. The Asterisk user gets to set the desired verbosity at startup time or later + * using the console 'set verbose' command. Messages are displayed on the console if their verbose level is less than or equal + * to desired verbosity set by the user. More important messages should have a low verbose level; less important messages + * should have a high verbose level. + * + * @link http://www.voip-info.org/wiki-verbose + * @param string $message + * @param integer $level from 1 to 4 + * @return array, see evaluate for return information. + */ + function verbose($message, $level=1) + { + foreach(explode("\n", str_replace("\r\n", "\n", print_r($message, true))) as $msg) + { + @syslog(LOG_WARNING, $msg); + $ret = $this->evaluate("VERBOSE \"$msg\" $level"); + } + return $ret; + } + + /** + * Waits up to $timeout milliseconds for channel to receive a DTMF digit. + * + * @link http://www.voip-info.org/wiki-wait+for+digit + * @param integer $timeout in millisecons. Use -1 for the timeout value if you want the call to wait indefinitely. + * @return array, see evaluate for return information. ['result'] is 0 if wait completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function wait_for_digit($timeout=-1) + { + return $this->evaluate("WAIT FOR DIGIT $timeout"); + } + + + // ********************************************************************************************************* + // ** APPLICATIONS ** + // ********************************************************************************************************* + + /** + * Set absolute maximum time of call. + * + * Note that the timeout is set from the current time forward, not counting the number of seconds the call has already been up. + * Each time you call AbsoluteTimeout(), all previous absolute timeouts are cancelled. + * Will return the call to the T extension so that you can playback an explanatory note to the calling party (the called party + * will not hear that) + * + * @link http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands + * @link http://www.dynx.net/ASTERISK/AGI/ccard/agi-ccard.agi + * @param $seconds allowed, 0 disables timeout + * @return array, see evaluate for return information. + */ + function exec_absolutetimeout($seconds=0) + { + return $this->exec('AbsoluteTimeout', $seconds); + } + + /** + * Executes an AGI compliant application. + * + * @param string $command + * @return array, see evaluate for return information. ['result'] is -1 on hangup or if application requested hangup, or 0 on non-hangup exit. + * @param string $args + */ + function exec_agi($command, $args) + { + return $this->exec("AGI $command", $args); + } + + /** + * Set Language. + * + * @param string $language code + * @return array, see evaluate for return information. + */ + function exec_setlanguage($language='en') + { + return $this->exec('Set', 'CHANNEL(language)='. $language); + } + + /** + * Do ENUM Lookup. + * + * Note: to retrieve the result, use + * get_variable('ENUM'); + * + * @param $exten + * @return array, see evaluate for return information. + */ + function exec_enumlookup($exten) + { + return $this->exec('EnumLookup', $exten); + } + + /** + * Dial. + * + * Dial takes input from ${VXML_URL} to send XML Url to Cisco 7960 + * Dial takes input from ${ALERT_INFO} to set ring cadence for Cisco phones + * Dial returns ${CAUSECODE}: If the dial failed, this is the errormessage. + * Dial returns ${DIALSTATUS}: Text code returning status of last dial attempt. + * + * @link http://www.voip-info.org/wiki-Asterisk+cmd+Dial + * @param string $type + * @param string $identifier + * @param integer $timeout + * @param string $options + * @param string $url + * @return array, see evaluate for return information. + */ + function exec_dial($type, $identifier, $timeout=NULL, $options=NULL, $url=NULL) + { + return $this->exec('Dial', trim("$type/$identifier".$this->option_delim.$timeout.$this->option_delim.$options.$this->option_delim.$url, $this->option_delim)); + } + + /** + * Goto. + * + * This function takes three arguments: context,extension, and priority, but the leading arguments + * are optional, not the trailing arguments. Thuse goto($z) sets the priority to $z. + * + * @param string $a + * @param string $b; + * @param string $c; + * @return array, see evaluate for return information. + */ + function exec_goto($a, $b=NULL, $c=NULL) + { + return $this->exec('Goto', trim($a.$this->option_delim.$b.$this->option_delim.$c, $this->option_delim)); + } + + + // ********************************************************************************************************* + // ** FAST PASSING ** + // ********************************************************************************************************* + + /** + * Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel. + * Return early if $buffer is adequate for request. + * + * @link http://www.voip-info.org/wiki-say+digits + * @param string $buffer + * @param integer $digits + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function fastpass_say_digits(&$buffer, $digits, $escape_digits='') + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->say_digits($digits, $escape_digits); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); + } + + /** + * Say the given number, returning early if any of the given DTMF escape digits are received on the channel. + * Return early if $buffer is adequate for request. + * + * @link http://www.voip-info.org/wiki-say+number + * @param string $buffer + * @param integer $number + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function fastpass_say_number(&$buffer, $number, $escape_digits='') + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->say_number($number, $escape_digits); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); + } + + /** + * Say the given character string, returning early if any of the given DTMF escape digits are received on the channel. + * Return early if $buffer is adequate for request. + * + * @link http://www.voip-info.org/wiki-say+phonetic + * @param string $buffer + * @param string $text + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function fastpass_say_phonetic(&$buffer, $text, $escape_digits='') + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->say_phonetic($text, $escape_digits); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); + } + + /** + * Say a given time, returning early if any of the given DTMF escape digits are received on the channel. + * Return early if $buffer is adequate for request. + * + * @link http://www.voip-info.org/wiki-say+time + * @param string $buffer + * @param integer $time number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC). + * @param string $escape_digits + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function fastpass_say_time(&$buffer, $time=NULL, $escape_digits='') + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->say_time($time, $escape_digits); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); + } + + /** + * Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA + * command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of + * digits before returning. + * Return early if $buffer is adequate for request. + * + * @link http://www.voip-info.org/wiki-stream+file + * @param string $buffer + * @param string $filename without extension, often in /var/lib/asterisk/sounds + * @param string $escape_digits + * @param integer $offset + * @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no + * digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII. + */ + function fastpass_stream_file(&$buffer, $filename, $escape_digits='', $offset=0) + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->stream_file($filename, $escape_digits, $offset); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0); + } + + /** + * Use festival to read text. + * Return early if $buffer is adequate for request. + * + * @link http://www.cstr.ed.ac.uk/projects/festival/ + * @param string $buffer + * @param string $text + * @param string $escape_digits + * @param integer $frequency + * @return array, see evaluate for return information. + */ + function fastpass_text2wav(&$buffer, $text, $escape_digits='', $frequency=8000) + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->text2wav($text, $escape_digits, $frequency); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0); + } + + /** + * Use Cepstral Swift to read text. + * Return early if $buffer is adequate for request. + * + * @link http://www.cepstral.com/ + * @param string $buffer + * @param string $text + * @param string $escape_digits + * @param integer $frequency + * @return array, see evaluate for return information. + */ + function fastpass_swift(&$buffer, $text, $escape_digits='', $frequency=8000, $voice=NULL) + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->swift($text, $escape_digits, $frequency, $voice); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0); + } + + /** + * Say Puncutation in a string. + * Return early if $buffer is adequate for request. + * + * @param string $buffer + * @param string $text + * @param string $escape_digits + * @param integer $frequency + * @return array, see evaluate for return information. + */ + function fastpass_say_punctuation(&$buffer, $text, $escape_digits='', $frequency=8000) + { + $proceed = false; + if($escape_digits != '' && $buffer != '') + { + if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1})) + $proceed = true; + } + if($buffer == '' || $proceed) + { + $res = $this->say_punctuation($text, $escape_digits, $frequency); + if($res['code'] == AGIRES_OK && $res['result'] > 0) + $buffer .= chr($res['result']); + return $res; + } + return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1})); + } + + /** + * Plays the given file and receives DTMF data. + * Return early if $buffer is adequate for request. + * + * This is similar to STREAM FILE, but this command can accept and return many DTMF digits, + * while STREAM FILE returns immediately after the first DTMF digit is detected. + * + * Asterisk looks for the file to play in /var/lib/asterisk/sounds by default. + * + * If the user doesn't press any keys when the message plays, there is $timeout milliseconds + * of silence then the command ends. + * + * The user has the opportunity to press a key at any time during the message or the + * post-message silence. If the user presses a key while the message is playing, the + * message stops playing. When the first key is pressed a timer starts counting for + * $timeout milliseconds. Every time the user presses another key the timer is restarted. + * The command ends when the counter goes to zero or the maximum number of digits is entered, + * whichever happens first. + * + * If you don't specify a time out then a default timeout of 2000 is used following a pressed + * digit. If no digits are pressed then 6 seconds of silence follow the message. + * + * If you don't specify $max_digits then the user can enter as many digits as they want. + * + * Pressing the # key has the same effect as the timer running out: the command ends and + * any previously keyed digits are returned. A side effect of this is that there is no + * way to read a # key using this command. + * + * @link http://www.voip-info.org/wiki-get+data + * @param string $buffer + * @param string $filename file to play. Do not include file extension. + * @param integer $timeout milliseconds + * @param integer $max_digits + * @return array, see evaluate for return information. ['result'] holds the digits and ['data'] holds the timeout if present. + * + * This differs from other commands with return DTMF as numbers representing ASCII characters. + */ + function fastpass_get_data(&$buffer, $filename, $timeout=NULL, $max_digits=NULL) + { + if(is_null($max_digits) || strlen($buffer) < $max_digits) + { + if($buffer == '') + { + $res = $this->get_data($filename, $timeout, $max_digits); + if($res['code'] == AGIRES_OK) + $buffer .= $res['result']; + return $res; + } + else + { + while(is_null($max_digits) || strlen($buffer) < $max_digits) + { + $res = $this->wait_for_digit(); + if($res['code'] != AGIRES_OK) return $res; + if($res['result'] == ord('#')) break; + $buffer .= chr($res['result']); + } + } + } + return array('code'=>AGIRES_OK, 'result'=>$buffer); + } + + // ********************************************************************************************************* + // ** DERIVED ** + // ********************************************************************************************************* + + /** + * Menu. + * + * This function presents the user with a menu and reads the response + * + * @param array $choices has the following structure: + * array('1'=>'*Press 1 for this', // festival reads if prompt starts with * + * '2'=>'some-gsm-without-extension', + * '*'=>'*Press star for help'); + * @return mixed key pressed on sucess, -1 on failure + */ + function menu($choices, $timeout=2000) + { + $keys = join('', array_keys($choices)); + $choice = NULL; + while(is_null($choice)) + { + foreach($choices as $prompt) + { + if($prompt{0} == '*') + $ret = $this->text2wav(substr($prompt, 1), $keys); + else + $ret = $this->stream_file($prompt, $keys); + + if($ret['code'] != AGIRES_OK || $ret['result'] == -1) + { + $choice = -1; + break; + } + + if($ret['result'] != 0) + { + $choice = chr($ret['result']); + break; + } + } + + if(is_null($choice)) + { + $ret = $this->get_data('beep', $timeout, 1); + if($ret['code'] != AGIRES_OK || $ret['result'] == -1) + $choice = -1; + elseif($ret['result'] != '' && strpos(' '.$keys, $ret['result'])) + $choice = $ret['result']; + } + } + return $choice; + } + + /** + * setContext - Set context, extension and priority. + * + * @param string $context + * @param string $extension + * @param string $priority + */ + function setContext($context, $extension='s', $priority=1) + { + $this->set_context($context); + $this->set_extension($extension); + $this->set_priority($priority); + } + + /** + * Parse caller id. + * + * @example examples/dtmf.php Get DTMF tones from the user and say the digits + * @example examples/input.php Get text input from the user and say it back + * + * "name" + * + * @param string $callerid + * @return array('Name'=>$name, 'Number'=>$number) + */ + function parse_callerid($callerid=NULL) + { + if(is_null($callerid)) + $callerid = $this->request['agi_callerid']; + + $ret = array('name'=>'', 'protocol'=>'', 'username'=>'', 'host'=>'', 'port'=>''); + $callerid = trim($callerid); + + if($callerid{0} == '"' || $callerid{0} == "'") + { + $d = $callerid{0}; + $callerid = explode($d, substr($callerid, 1)); + $ret['name'] = array_shift($callerid); + $callerid = join($d, $callerid); + } + + $callerid = explode('@', trim($callerid, '<> ')); + $username = explode(':', array_shift($callerid)); + if(count($username) == 1) + $ret['username'] = $username[0]; + else + { + $ret['protocol'] = array_shift($username); + $ret['username'] = join(':', $username); + } + + $callerid = join('@', $callerid); + $host = explode(':', $callerid); + if(count($host) == 1) + $ret['host'] = $host[0]; + else + { + $ret['host'] = array_shift($host); + $ret['port'] = join(':', $host); + } + + return $ret; + } + + /** + * Use festival to read text. + * + * @example examples/dtmf.php Get DTMF tones from the user and say the digits + * @example examples/input.php Get text input from the user and say it back + * @example examples/ping.php Ping an IP address + * + * @link http://www.cstr.ed.ac.uk/projects/festival/ + * @param string $text + * @param string $escape_digits + * @param integer $frequency + * @return array, see evaluate for return information. + */ + function text2wav($text, $escape_digits='', $frequency=8000) + { + $text = trim($text); + if($text == '') return true; + + $hash = md5($text); + $fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR; + $fname .= 'text2wav_' . $hash; + + // create wave file + if(!file_exists("$fname.wav")) + { + // write text file + if(!file_exists("$fname.txt")) + { + $fp = fopen("$fname.txt", 'w'); + fputs($fp, $text); + fclose($fp); + } + + shell_exec("{$this->config['festival']['text2wave']} -F $frequency -o $fname.wav $fname.txt"); + } + else + { + touch("$fname.txt"); + touch("$fname.wav"); + } + + // stream it + $ret = $this->stream_file($fname, $escape_digits); + + // clean up old files + $delete = time() - 2592000; // 1 month + foreach(glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'text2wav_*') as $file) + if(filemtime($file) < $delete) + unlink($file); + + return $ret; + } + + /** + * Use Cepstral Swift to read text. + * + * @link http://www.cepstral.com/ + * @param string $text + * @param string $escape_digits + * @param integer $frequency + * @return array, see evaluate for return information. + */ + function swift($text, $escape_digits='', $frequency=8000, $voice=NULL) + { + if(!is_null($voice)) + $voice = "-n $voice"; + elseif(isset($this->config['cepstral']['voice'])) + $voice = "-n {$this->config['cepstral']['voice']}"; + + $text = trim($text); + if($text == '') return true; + + $hash = md5($text); + $fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR; + $fname .= 'swift_' . $hash; + + // create wave file + if(!file_exists("$fname.wav")) + { + // write text file + if(!file_exists("$fname.txt")) + { + $fp = fopen("$fname.txt", 'w'); + fputs($fp, $text); + fclose($fp); + } + + shell_exec("{$this->config['cepstral']['swift']} -p audio/channels=1,audio/sampling-rate=$frequency $voice -o $fname.wav -f $fname.txt"); + } + + // stream it + $ret = $this->stream_file($fname, $escape_digits); + + // clean up old files + $delete = time() - 2592000; // 1 month + foreach(glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'swift_*') as $file) + if(filemtime($file) < $delete) + unlink($file); + + return $ret; + } + + /** + * Text Input. + * + * Based on ideas found at http://www.voip-info.org/wiki-Asterisk+cmd+DTMFToText + * + * Example: + * UC H LC i , SP h o w SP a r e SP y o u ? + * $string = '*8'.'44*'.'*5'.'444*'.'00*'.'0*'.'44*'.'666*'.'9*'.'0*'.'2*'.'777*'.'33*'.'0*'.'999*'.'666*'.'88*'.'0000*'; + * + * @link http://www.voip-info.org/wiki-Asterisk+cmd+DTMFToText + * @example examples/input.php Get text input from the user and say it back + * + * @return string + */ + function text_input($mode='NUMERIC') + { + $alpha = array( 'k0'=>' ', 'k00'=>',', 'k000'=>'.', 'k0000'=>'?', 'k00000'=>'0', + 'k1'=>'!', 'k11'=>':', 'k111'=>';', 'k1111'=>'#', 'k11111'=>'1', + 'k2'=>'A', 'k22'=>'B', 'k222'=>'C', 'k2222'=>'2', + 'k3'=>'D', 'k33'=>'E', 'k333'=>'F', 'k3333'=>'3', + 'k4'=>'G', 'k44'=>'H', 'k444'=>'I', 'k4444'=>'4', + 'k5'=>'J', 'k55'=>'K', 'k555'=>'L', 'k5555'=>'5', + 'k6'=>'M', 'k66'=>'N', 'k666'=>'O', 'k6666'=>'6', + 'k7'=>'P', 'k77'=>'Q', 'k777'=>'R', 'k7777'=>'S', 'k77777'=>'7', + 'k8'=>'T', 'k88'=>'U', 'k888'=>'V', 'k8888'=>'8', + 'k9'=>'W', 'k99'=>'X', 'k999'=>'Y', 'k9999'=>'Z', 'k99999'=>'9'); + $symbol = array('k0'=>'=', + 'k1'=>'<', 'k11'=>'(', 'k111'=>'[', 'k1111'=>'{', 'k11111'=>'1', + 'k2'=>'@', 'k22'=>'$', 'k222'=>'&', 'k2222'=>'%', 'k22222'=>'2', + 'k3'=>'>', 'k33'=>')', 'k333'=>']', 'k3333'=>'}', 'k33333'=>'3', + 'k4'=>'+', 'k44'=>'-', 'k444'=>'*', 'k4444'=>'/', 'k44444'=>'4', + 'k5'=>"'", 'k55'=>'`', 'k555'=>'5', + 'k6'=>'"', 'k66'=>'6', + 'k7'=>'^', 'k77'=>'7', + 'k8'=>"\\",'k88'=>'|', 'k888'=>'8', + 'k9'=>'_', 'k99'=>'~', 'k999'=>'9'); + $text = ''; + do + { + $command = false; + $result = $this->get_data('beep'); + foreach(explode('*', $result['result']) as $code) + { + if($command) + { + switch($code{0}) + { + case '2': $text = substr($text, 0, strlen($text) - 1); break; // backspace + case '5': $mode = 'LOWERCASE'; break; + case '6': $mode = 'NUMERIC'; break; + case '7': $mode = 'SYMBOL'; break; + case '8': $mode = 'UPPERCASE'; break; + case '9': $text = explode(' ', $text); unset($text[count($text)-1]); $text = join(' ', $text); break; // backspace a word + } + $code = substr($code, 1); + $command = false; + } + if($code == '') + $command = true; + elseif($mode == 'NUMERIC') + $text .= $code; + elseif($mode == 'UPPERCASE' && isset($alpha['k'.$code])) + $text .= $alpha['k'.$code]; + elseif($mode == 'LOWERCASE' && isset($alpha['k'.$code])) + $text .= strtolower($alpha['k'.$code]); + elseif($mode == 'SYMBOL' && isset($symbol['k'.$code])) + $text .= $symbol['k'.$code]; + } + $this->say_punctuation($text); + } while(substr($result['result'], -2) == '**'); + return $text; + } + + /** + * Say Puncutation in a string. + * + * @param string $text + * @param string $escape_digits + * @param integer $frequency + * @return array, see evaluate for return information. + */ + function say_punctuation($text, $escape_digits='', $frequency=8000) + { + $ret=""; + for($i = 0; $i < strlen($text); $i++) + { + switch($text{$i}) + { + case ' ': $ret .= 'SPACE '; + case ',': $ret .= 'COMMA '; break; + case '.': $ret .= 'PERIOD '; break; + case '?': $ret .= 'QUESTION MARK '; break; + case '!': $ret .= 'EXPLANATION POINT '; break; + case ':': $ret .= 'COLON '; break; + case ';': $ret .= 'SEMICOLON '; break; + case '#': $ret .= 'POUND '; break; + case '=': $ret .= 'EQUALS '; break; + case '<': $ret .= 'LESS THAN '; break; + case '(': $ret .= 'LEFT PARENTHESIS '; break; + case '[': $ret .= 'LEFT BRACKET '; break; + case '{': $ret .= 'LEFT BRACE '; break; + case '@': $ret .= 'AT '; break; + case '$': $ret .= 'DOLLAR SIGN '; break; + case '&': $ret .= 'AMPERSAND '; break; + case '%': $ret .= 'PERCENT '; break; + case '>': $ret .= 'GREATER THAN '; break; + case ')': $ret .= 'RIGHT PARENTHESIS '; break; + case ']': $ret .= 'RIGHT BRACKET '; break; + case '}': $ret .= 'RIGHT BRACE '; break; + case '+': $ret .= 'PLUS '; break; + case '-': $ret .= 'MINUS '; break; + case '*': $ret .= 'ASTERISK '; break; + case '/': $ret .= 'SLASH '; break; + case "'": $ret .= 'SINGLE QUOTE '; break; + case '`': $ret .= 'BACK TICK '; break; + case '"': $ret .= 'QUOTE '; break; + case '^': $ret .= 'CAROT '; break; + case "\\": $ret .= 'BACK SLASH '; break; + case '|': $ret .= 'BAR '; break; + case '_': $ret .= 'UNDERSCORE '; break; + case '~': $ret .= 'TILDE '; break; + default: $ret .= $text{$i} . ' '; break; + } + } + return $this->text2wav($ret, $escape_digits, $frequency); + } + + /** + * Create a new AGI_AsteriskManager. + */ + function &new_AsteriskManager() + { + $this->asm = new AGI_AsteriskManager(NULL, $this->config); + $this->asm->pagi =& $this; + $this->config =& $this->asm->config; + return $this->asm; + } + + + // ********************************************************************************************************* + // ** PRIVATE ** + // ********************************************************************************************************* + + + /** + * Evaluate an AGI command. + * + * @access private + * @param string $command + * @return array ('code'=>$code, 'result'=>$result, 'data'=>$data) + */ + function evaluate($command) + { + $broken = array('code'=>500, 'result'=>-1, 'data'=>''); + + // write command + if(!@fwrite($this->out, trim($command) . "\n")) return $broken; + fflush($this->out); + + // Read result. Occasionally, a command return a string followed by an extra new line. + // When this happens, our script will ignore the new line, but it will still be in the + // buffer. So, if we get a blank line, it is probably the result of a previous + // command. We read until we get a valid result or asterisk hangs up. One offending + // command is SEND TEXT. + $count = 0; + do + { + $str = trim(fgets($this->in, 4096)); + } while($str == '' && $count++ < 5); + + if($count >= 5) + { + // $this->conlog("evaluate error on read for $command"); + return $broken; + } + + // parse result + $ret['code'] = substr($str, 0, 3); + $str = trim(substr($str, 3)); + + if($str{0} == '-') // we have a multiline response! + { + $count = 0; + $str = substr($str, 1) . "\n"; + $line = fgets($this->in, 4096); + while(substr($line, 0, 3) != $ret['code'] && $count < 5) + { + $str .= $line; + $line = fgets($this->in, 4096); + $count = (trim($line) == '') ? $count + 1 : 0; + } + if($count >= 5) + { + // $this->conlog("evaluate error on multiline read for $command"); + return $broken; + } + } + + $ret['result'] = NULL; + $ret['data'] = ''; + if($ret['code'] != AGIRES_OK) // some sort of error + { + $ret['data'] = $str; + $this->conlog(print_r($ret, true)); + } + else // normal AGIRES_OK response + { + $parse = explode(' ', trim($str)); + $in_token = false; + foreach($parse as $token) + { + if($in_token) // we previously hit a token starting with ')' but not ending in ')' + { + $ret['data'] .= ' ' . trim($token, '() '); + if($token{strlen($token)-1} == ')') $in_token = false; + } + elseif($token{0} == '(') + { + if($token{strlen($token)-1} != ')') $in_token = true; + $ret['data'] .= ' ' . trim($token, '() '); + } + elseif(strpos($token, '=')) + { + $token = explode('=', $token); + $ret[$token[0]] = $token[1]; + } + elseif($token != '') + $ret['data'] .= ' ' . $token; + } + $ret['data'] = trim($ret['data']); + } + + // log some errors + if($ret['result'] < 0) + $this->conlog("$command returned {$ret['result']}"); + + return $ret; + } + + /** + * Log to console if debug mode. + * + * @example examples/ping.php Ping an IP address + * + * @param string $str + * @param integer $vbl verbose level + */ + function conlog($str, $vbl=1) + { + static $busy = false; + + if($this->config['phpagi']['debug'] != false) + { + if(!$busy) // no conlogs inside conlog!!! + { + $busy = true; + $this->verbose($str, $vbl); + $busy = false; + } + } + } + + /** + * Find an execuable in the path. + * + * @access private + * @param string $cmd command to find + * @param string $checkpath path to check + * @return string the path to the command + */ + function which($cmd, $checkpath=NULL) + { + global $_ENV; + $chpath = is_null($checkpath) ? $_ENV['PATH'] : $checkpath; + + foreach(explode(':', $chpath) as $path) + if(is_executable("$path/$cmd")) + return "$path/$cmd"; + + if(is_null($checkpath)) + return $this->which($cmd, '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:'. + '/usr/X11R6/bin:/usr/local/apache/bin:/usr/local/mysql/bin'); + return false; + } + + /** + * Make a folder recursively. + * + * @access private + * @param string $folder + * @param integer $perms + * @return boolean + */ + function make_folder($folder, $perms=0755) + { + $f = explode(DIRECTORY_SEPARATOR, $folder); + $base = ''; + for($i = 0; $i < count($f); $i++) + { + $base .= $f[$i]; + if($f[$i] != '' && !file_exists($base)) { + if(mkdir($base, $perms)==FALSE){ + return(FALSE); + } + } + $base .= DIRECTORY_SEPARATOR; + } + return(TRUE); + } + +} + + +/** + * error handler for phpagi. + * + * @param integer $level PHP error level + * @param string $message error message + * @param string $file path to file + * @param integer $line line number of error + * @param array $context variables in the current scope + */ + function phpagi_error_handler($level, $message, $file, $line, $context) + { + if(ini_get('error_reporting') == 0) return; // this happens with an @ + + @syslog(LOG_WARNING, $file . '[' . $line . ']: ' . $message); + + global $phpagi_error_handler_email; + if(function_exists('mail') && !is_null($phpagi_error_handler_email)) // generate email debugging information + { + // decode error level + switch($level) + { + case E_WARNING: + case E_USER_WARNING: + $level = "Warning"; + break; + case E_NOTICE: + case E_USER_NOTICE: + $level = "Notice"; + break; + case E_USER_ERROR: + $level = "Error"; + break; + } + + // build message + $basefile = basename($file); + $subject = "$basefile/$line/$level: $message"; + $message = "$level: $message in $file on line $line\n\n"; + + if(function_exists('mysql_errno') && strpos(' '.strtolower($message), 'mysql')) + $message .= 'MySQL error ' . mysql_errno() . ": " . mysql_error() . "\n\n"; + + // figure out who we are + if(function_exists('socket_create')) + { + $addr = NULL; + $port = 80; + $socket = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); + @socket_connect($socket, '64.0.0.0', $port); + @socket_getsockname($socket, $addr, $port); + @socket_close($socket); + $message .= "\n\nIP Address: $addr\n"; + } + + // include variables + $message .= "\n\nContext:\n" . print_r($context, true); + $message .= "\n\nGLOBALS:\n" . print_r($GLOBALS, true); + $message .= "\n\nBacktrace:\n" . print_r(debug_backtrace(), true); + + // include code fragment + if(file_exists($file)) + { + $message .= "\n\n$file:\n"; + $code = @file($file); + for($i = max(0, $line - 10); $i < min($line + 10, count($code)); $i++) + $message .= ($i + 1)."\t$code[$i]"; + } + + // make sure message is fully readable (convert unprintable chars to hex representation) + $ret = ''; + for($i = 0; $i < strlen($message); $i++) + { + $c = ord($message{$i}); + if($c == 10 || $c == 13 || $c == 9) + $ret .= $message{$i}; + elseif($c < 16) + $ret .= '\x0' . dechex($c); + elseif($c < 32 || $c > 127) + $ret .= '\x' . dechex($c); + else + $ret .= $message{$i}; + } + $message = $ret; + + // send the mail if less than 5 errors + static $mailcount = 0; + if($mailcount < 5) + @mail($phpagi_error_handler_email, $subject, $message); + $mailcount++; + } + } + + $phpagi_error_handler_email = NULL; +