summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-pbx
diff options
context:
space:
mode:
Diffstat (limited to 'applications/luci-pbx')
-rw-r--r--applications/luci-pbx/COPYING674
-rw-r--r--applications/luci-pbx/Makefile4
-rw-r--r--applications/luci-pbx/luasrc/controller/pbx.lua29
-rw-r--r--applications/luci-pbx/luasrc/model/cbi/pbx-advanced.lua284
-rw-r--r--applications/luci-pbx/luasrc/model/cbi/pbx-calls.lua359
-rw-r--r--applications/luci-pbx/luasrc/model/cbi/pbx-google.lua120
-rw-r--r--applications/luci-pbx/luasrc/model/cbi/pbx-users.lua148
-rw-r--r--applications/luci-pbx/luasrc/model/cbi/pbx-voip.lua116
-rw-r--r--applications/luci-pbx/luasrc/model/cbi/pbx.lua116
-rw-r--r--applications/luci-pbx/root/etc/config/pbx1
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-advanced1
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-calls7
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-google0
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-users1
-rw-r--r--applications/luci-pbx/root/etc/config/pbx-voip0
-rw-r--r--applications/luci-pbx/root/etc/init.d/pbx-asterisk638
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE17
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE30
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE3
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE4
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE11
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE9
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE9
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE8
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE1
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE3
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE10
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE733
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE4
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE8
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE7
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE7
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE31
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE6
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE37
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE13
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE2
-rw-r--r--applications/luci-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE11
50 files changed, 3479 insertions, 0 deletions
diff --git a/applications/luci-pbx/COPYING b/applications/luci-pbx/COPYING
new file mode 100644
index 000000000..94a9ed024
--- /dev/null
+++ b/applications/luci-pbx/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, 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
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If 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 convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU 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
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/applications/luci-pbx/Makefile b/applications/luci-pbx/Makefile
new file mode 100644
index 000000000..9a720f0d2
--- /dev/null
+++ b/applications/luci-pbx/Makefile
@@ -0,0 +1,4 @@
+PO = pbx
+
+include ../../build/config.mk
+include ../../build/module.mk
diff --git a/applications/luci-pbx/luasrc/controller/pbx.lua b/applications/luci-pbx/luasrc/controller/pbx.lua
new file mode 100644
index 000000000..127b40705
--- /dev/null
+++ b/applications/luci-pbx/luasrc/controller/pbx.lua
@@ -0,0 +1,29 @@
+--[[
+ Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+
+ This file is part of luci-pbx.
+
+ luci-pbx is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ luci-pbx is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+]]--
+
+module("luci.controller.pbx", package.seeall)
+
+function index()
+ entry({"admin", "services", "pbx"}, cbi("pbx"), "PBX", 80)
+ entry({"admin", "services", "pbx", "pbx-google"}, cbi("pbx-google"), "Google Accounts", 1)
+ entry({"admin", "services", "pbx", "pbx-voip"}, cbi("pbx-voip"), "SIP Accounts", 2)
+ entry({"admin", "services", "pbx", "pbx-users"}, cbi("pbx-users"), "User Accounts", 3)
+ entry({"admin", "services", "pbx", "pbx-calls"}, cbi("pbx-calls"), "Call Routing", 4)
+ entry({"admin", "services", "pbx", "pbs-advanced"}, cbi("pbx-advanced"), "Advanced Settings", 5)
+end
diff --git a/applications/luci-pbx/luasrc/model/cbi/pbx-advanced.lua b/applications/luci-pbx/luasrc/model/cbi/pbx-advanced.lua
new file mode 100644
index 000000000..061982543
--- /dev/null
+++ b/applications/luci-pbx/luasrc/model/cbi/pbx-advanced.lua
@@ -0,0 +1,284 @@
+--[[
+ Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+
+ This file is part of luci-pbx.
+
+ luci-pbx is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ luci-pbx is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+]]--
+
+if nixio.fs.access("/etc/init.d/asterisk") then
+ server = "asterisk"
+elseif nixio.fs.access("/etc/init.d/freeswitch") then
+ server = "freeswitch"
+else
+ server = ""
+end
+
+appname = "PBX"
+modulename = "pbx-advanced"
+defaultbindport = 5060
+defaultrtpstart = 19850
+defaultrtpend = 19900
+
+-- Returns all the network related settings, including a constructed RTP range
+function get_network_info()
+ externhost = m.uci:get(modulename, "advanced", "externhost")
+ ipaddr = m.uci:get("network", "lan", "ipaddr")
+ bindport = m.uci:get(modulename, "advanced", "bindport")
+ rtpstart = m.uci:get(modulename, "advanced", "rtpstart")
+ rtpend = m.uci:get(modulename, "advanced", "rtpend")
+
+ if bindport == nil then bindport = defaultbindport end
+ if rtpstart == nil then rtpstart = defaultrtpstart end
+ if rtpend == nil then rtpend = defaultrtpend end
+
+ if rtpstart == nil or rtpend == nil then
+ rtprange = nil
+ else
+ rtprange = rtpstart .. "-" .. rtpend
+ end
+
+ return bindport, rtprange, ipaddr, externhost
+end
+
+-- If not present, insert empty rules in the given config & section named PBX-SIP and PBX-RTP
+function insert_empty_sip_rtp_rules(config, section)
+
+ -- Add rules named PBX-SIP and PBX-RTP if not existing
+ found_sip_rule = false
+ found_rtp_rule = false
+ m.uci:foreach(config, section,
+ function(s1)
+ if s1._name == 'PBX-SIP' then
+ found_sip_rule = true
+ elseif s1._name == 'PBX-RTP' then
+ found_rtp_rule = true
+ end
+ end)
+
+ if found_sip_rule ~= true then
+ newrule=m.uci:add(config, section)
+ m.uci:set(config, newrule, '_name', 'PBX-SIP')
+ end
+ if found_rtp_rule ~= true then
+ newrule=m.uci:add(config, section)
+ m.uci:set(config, newrule, '_name', 'PBX-RTP')
+ end
+end
+
+-- Delete rules in the given config & section named PBX-SIP and PBX-RTP
+function delete_sip_rtp_rules(config, section)
+
+ -- Remove rules named PBX-SIP and PBX-RTP
+ commit = false
+ m.uci:foreach(config, section,
+ function(s1)
+ if s1._name == 'PBX-SIP' or s1._name == 'PBX-RTP' then
+ m.uci:delete(config, s1['.name'])
+ commit = true
+ end
+ end)
+
+ -- If something changed, then we commit the config.
+ if commit == true then m.uci:commit(config) end
+end
+
+-- Deletes QoS rules associated with this PBX.
+function delete_qos_rules()
+ delete_sip_rtp_rules ("qos", "classify")
+end
+
+
+function insert_qos_rules()
+ -- Insert empty PBX-SIP and PBX-RTP rules if not present.
+ insert_empty_sip_rtp_rules ("qos", "classify")
+
+ -- Get the network information
+ bindport, rtprange, ipaddr, externhost = get_network_info()
+
+ -- Iterate through the QoS rules, and if there is no other rule with the same port
+ -- range at the express service level, insert this rule.
+ commit = false
+ m.uci:foreach("qos", "classify",
+ function(s1)
+ if s1._name == 'PBX-SIP' then
+ if s1.ports ~= bindport or s1.target ~= "Express" or s1.proto ~= "udp" then
+ m.uci:set("qos", s1['.name'], "ports", bindport)
+ m.uci:set("qos", s1['.name'], "proto", "udp")
+ m.uci:set("qos", s1['.name'], "target", "Express")
+ commit = true
+ end
+ elseif s1._name == 'PBX-RTP' then
+ if s1.ports ~= rtprange or s1.target ~= "Express" or s1.proto ~= "udp" then
+ m.uci:set("qos", s1['.name'], "ports", rtprange)
+ m.uci:set("qos", s1['.name'], "proto", "udp")
+ m.uci:set("qos", s1['.name'], "target", "Express")
+ commit = true
+ end
+ end
+ end)
+
+ -- If something changed, then we commit the qos config.
+ if commit == true then m.uci:commit("qos") end
+end
+
+-- This function is a (so far) unsuccessful attempt to manipulate the firewall rules from here
+-- Need to do more testing and eventually move to this mode.
+function maintain_firewall_rules()
+ -- Get the network information
+ bindport, rtprange, ipaddr, externhost = get_network_info()
+
+ commit = false
+ -- Only if externhost is set, do we control firewall rules.
+ if externhost ~= nil and bindport ~= nil and rtprange ~= nil then
+ -- Insert empty PBX-SIP and PBX-RTP rules if not present.
+ insert_empty_sip_rtp_rules ("firewall", "rule")
+
+ -- Iterate through the firewall rules, and if the dest_port and dest_ip setting of the\
+ -- SIP and RTP rule do not match what we want configured, set all the entries in the rule\
+ -- appropriately.
+ m.uci:foreach("firewall", "rule",
+ function(s1)
+ if s1._name == 'PBX-SIP' then
+ if s1.dest_port ~= bindport then
+ m.uci:set("firewall", s1['.name'], "dest_port", bindport)
+ m.uci:set("firewall", s1['.name'], "src", "wan")
+ m.uci:set("firewall", s1['.name'], "proto", "udp")
+ m.uci:set("firewall", s1['.name'], "target", "ACCEPT")
+ commit = true
+ end
+ elseif s1._name == 'PBX-RTP' then
+ if s1.dest_port ~= rtprange then
+ m.uci:set("firewall", s1['.name'], "dest_port", rtprange)
+ m.uci:set("firewall", s1['.name'], "src", "wan")
+ m.uci:set("firewall", s1['.name'], "proto", "udp")
+ m.uci:set("firewall", s1['.name'], "target", "ACCEPT")
+ commit = true
+ end
+ end
+ end)
+ else
+ -- We delete the firewall rules if one or more of the necessary parameters are not set.
+ sip_rule_name=nil
+ rtp_rule_name=nil
+
+ -- First discover the configuration names of the rules.
+ m.uci:foreach("firewall", "rule",
+ function(s1)
+ if s1._name == 'PBX-SIP' then
+ sip_rule_name = s1['.name']
+ elseif s1._name == 'PBX-RTP' then
+ rtp_rule_name = s1['.name']
+ end
+ end)
+
+ -- Then, using the names, actually delete the rules.
+ if sip_rule_name ~= nil then
+ m.uci:delete("firewall", sip_rule_name)
+ commit = true
+ end
+ if rtp_rule_name ~= nil then
+ m.uci:delete("firewall", rtp_rule_name)
+ commit = true
+ end
+ end
+
+ -- If something changed, then we commit the firewall config.
+ if commit == true then m.uci:commit("firewall") end
+end
+
+m = Map (modulename, translate("Advanced Settings"),
+ translate("This section contains settings which do not need to be changed under\
+ normal circumstances. In addition, here you can configure your system\
+ for use with remote SIP devices, and resolve call quality issues by enabling\
+ the insertion of QoS rules."))
+
+-- Recreate the voip server config, and restart necessary services after changes are commited
+-- to the advanced configuration. The firewall must restart because of "Remote Usage".
+function m.on_after_commit(self)
+
+ -- Make sure firewall rules are in place
+ maintain_firewall_rules()
+
+ -- If insertion of QoS rules is enabled
+ if m.uci:get(modulename, "advanced", "qos_enabled") == "yes" then
+ insert_qos_rules()
+ else
+ delete_qos_rules()
+ end
+
+ luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+ luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+ luci.sys.call("/etc/init.d/firewall restart 1\>/dev/null 2\>/dev/null")
+end
+
+-----------------------------------------------------------------------------
+s = m:section(NamedSection, "advanced", "settings", translate("Advanced Settings"))
+s.anonymous = true
+
+s:tab("general", translate("General Settings"))
+s:tab("remote_usage", translate("Remote Usage"),
+ translatef("You can use your SIP devices/softphones with this system from a remote location\
+ as well, as long as your Internet Service Provider gives you a public IP.\
+ You will be able to call other local users for free (e.g. other Analog Telephone Adapters (ATAs))\
+ and use your VoIP providers to make calls as if you were at local to the PBX.\
+ After configuring this tab, go back to where users are configured and see the new\
+ Server and Port setting you need to configure the SIP devices with. Please note that by default\
+ %s uses UDP port range %d to %d for RTP traffic (which carries voice), in case you need to configure\
+ NAT or QoS on another device.", appname, defaultrtpstart, defaultrtpend))
+
+s:tab("qos", translate("QoS Settings"),
+ translate("If you experience jittery or high latency audio during heavy downloads, you may want to enable QoS.\
+ QoS prioritizes traffic to and from your network for specified ports and IP addresses, resulting in\
+ better latency and throughput for sound in our case. If enabled below, a QoS rule for this service will\
+ be configured by the PBX automatically, but you must visit the QoS configuration page (Network->QoS) to\
+ configure other critical QoS settings like Download and Upload speed."))
+
+ua = s:taboption("general", Value, "useragent", translate("User Agent String"),
+ translate("This is the name that the VoIP server will use to identify itself when\
+ registering to VoIP (SIP) providers. Some providers require this to a specific\
+ string matching a hardware SIP device."))
+ua.default = appname
+
+h = s:taboption("remote_usage", Value, "externhost", translate("Domain Name/Dynamic Domain Name"),
+ translate("You should either have registered a domain name and have a static IP\
+ address, or have configured Dynamic DNS on this router. Enter a\
+ domain name which resolves to your external IP address."))
+h.datatype = "hostname"
+
+p = s:taboption("remote_usage", Value, "bindport", translate("External SIP Port"),
+ translate("Pick a random port number between 6500 and 9500 for the service to listen on.\
+ Do not pick the standard 5060, because it is often subject to brute-force attacks.\
+ When finished, (1) click \"Save and Apply\", and (2) click the \"Restart VoIP Service\"\
+ button above. Finally, (3) look in the \"SIP Device/Softphone Accounts\" section for\
+ updated Server and Port settings for your SIP Devices/Softphones."))
+p.datatype = "port"
+
+p = s:taboption("remote_usage", Value, "rtpstart", translate("RTP Port Range Start"),
+ translate("RTP traffic carries actual voice packets. This is the start of the port range\
+ which will be used for setting up RTP communication. It's usually OK to leave this\
+ at the default value."))
+p.datatype = "port"
+p.default = defaultrtpstart
+
+p = s:taboption("remote_usage", Value, "rtpend", translate("RTP Port Range End"))
+p.datatype = "port"
+p.default = defaultrtpend
+
+p = s:taboption("qos", ListValue, "qos_enabled", translate("Insert QoS Rules"))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+return m
diff --git a/applications/luci-pbx/luasrc/model/cbi/pbx-calls.lua b/applications/luci-pbx/luasrc/model/cbi/pbx-calls.lua
new file mode 100644
index 000000000..029c5b06a
--- /dev/null
+++ b/applications/luci-pbx/luasrc/model/cbi/pbx-calls.lua
@@ -0,0 +1,359 @@
+--[[
+ Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+
+ This file is part of luci-pbx.
+
+ luci-pbx is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ luci-pbx is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+]]--
+
+if nixio.fs.access("/etc/init.d/asterisk") then
+ server = "asterisk"
+elseif nixio.fs.access("/etc/init.d/freeswitch") then
+ server = "freeswitch"
+else
+ server = ""
+end
+
+modulename = "pbx-calls"
+voipmodulename = "pbx-voip"
+googlemodulename = "pbx-google"
+usersmodulename = "pbx-users"
+
+-- This function builds and returns a table with all the entries in a given "module" and "section".
+function get_existing_entries(module, section)
+ i = 1
+ existing_entries = {}
+ m.uci:foreach(module, section,
+ function(s1)
+ existing_entries[i] = s1
+ i = i + 1
+ end)
+ return existing_entries
+end
+
+-- This function is used to build and return a table where the name field for
+-- every element in a table entries are the indexes to the table (used to check
+-- validity of user input.
+function get_valid_names(entries)
+ validnames={}
+ for index,value in ipairs(entries) do
+ validnames[entries[index].name] = true
+ end
+ return validnames
+end
+
+-- This function is used to build and return a table where the defaultuser field for
+-- every element in a table entries are the indexes to the table (used to check
+-- validity of user input.
+function get_valid_defaultusers(entries)
+ validnames={}
+ for index,value in ipairs(entries) do
+ validnames[entries[index].defaultuser] = true
+ end
+ return validnames
+end
+
+function is_valid_extension(exten)
+ return (exten:match("[#*+0-9NXZ]+$") ~= nil)
+end
+
+m = Map (modulename, translate("Call Routing"),
+ translate("This is where you indicate which Google/SIP accounts are used to call what \
+ country/area codes, which users can use which SIP/Google accounts, how incoming\
+ calls are routed, what numbers can get into this PBX with a password, and what\
+ numbers are blacklisted."))
+
+-- Recreate the config, and restart services after changes are commited to the configuration.
+function m.on_after_commit(self)
+ luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+ luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+end
+
+----------------------------------------------------------------------------------------------------
+s = m:section(NamedSection, "outgoing_calls", "call_routing", translate("Outgoing Calls"),
+ translate("If you have more than one account which can make outgoing calls, you\
+ should enter a list of phone numbers and prefixes in the following fields for each\
+ provider listed. Invalid prefixes are removed silently, and only 0-9, X, Z, N, #, *,\
+ and + are valid characters. The letter X matches 0-9, Z matches 1-9, and N matches 2-9.\
+ For example to make calls to Germany through a provider, you can enter 49. To make calls\
+ to North America, you can enter 1NXXNXXXXXX. If one of your providers can make \"local\"\
+ calls to an area code like New York's 646, you can enter 646NXXXXXX for that\
+ provider. You should leave one account with an empty list to make calls with\
+ it by default, if no other provider's prefixes match. The system will automatically\
+ replace an empty list with a message that the provider dials all numbers. Be as specific as\
+ possible (i.e. 1NXXNXXXXXX is better than 1). Please note all international dial codes\
+ are discarded (e.g. 00, 011, 010, 0011). Entries can be made in a\
+ space-separated list, and/or one per line by hitting enter after every one."))
+s.anonymous = true
+
+m.uci:foreach(googlemodulename, "gtalk_jabber",
+ function(s1)
+ if s1.username ~= nil and s1.name ~= nil and
+ s1.make_outgoing_calls == "yes" then
+ patt = s:option(DynamicList, s1.name, s1.username)
+
+ -- If the saved field is empty, we return a string
+ -- telling the user that this account would dial any exten.
+ function patt.cfgvalue(self, section)
+ value = self.map:get(section, self.option)
+
+ if value == nil then
+ return {"Dials any number"}
+ else
+ return value
+ end
+ end
+
+ -- Write only valid extensions into the config file.
+ function patt.write(self, section, value)
+ newvalue = {}
+ nindex = 1
+ for index, field in ipairs(value) do
+ if is_valid_extension(value[index]) == true then
+ newvalue[nindex] = value[index]
+ nindex = nindex + 1
+ end
+ end
+ DynamicList.write(self, section, newvalue)
+ end
+ end
+ end)
+
+m.uci:foreach(voipmodulename, "voip_provider",
+ function(s1)
+ if s1.defaultuser ~= nil and s1.host ~= nil and
+ s1.name ~= nil and s1.make_outgoing_calls == "yes" then
+ patt = s:option(DynamicList, s1.name, s1.defaultuser .. "@" .. s1.host)
+
+ -- If the saved field is empty, we return a string
+ -- telling the user that this account would dial any exten.
+ function patt.cfgvalue(self, section)
+ value = self.map:get(section, self.option)
+
+ if value == nil then
+ return {"Dials any number"}
+ else
+ return value
+ end
+ end
+
+ -- Write only valid extensions into the config file.
+ function patt.write(self, section, value)
+ newvalue = {}
+ nindex = 1
+ for index, field in ipairs(value) do
+ if is_valid_extension(value[index]) == true then
+ newvalue[nindex] = value[index]
+ nindex = nindex + 1
+ end
+ end
+ DynamicList.write(self, section, newvalue)
+ end
+ end
+ end)
+
+----------------------------------------------------------------------------------------------------
+s = m:section(NamedSection, "incoming_calls", "call_routing", translate("Incoming Calls"),
+ translate("For each provider that receives calls, here you can restrict which users to ring\
+ on incoming calls. If the list is empty, the system will indicate that all users\
+ which are enabled for incoming calls will ring. Invalid usernames will be rejected\
+ silently. Also, entering a username here overrides the user's setting to not receive\
+ incoming calls, so this way, you can make users ring only for select providers.\
+ Entries can be made in a space-separated list, and/or one per\
+ line by hitting enter after every one."))
+s.anonymous = true
+
+m.uci:foreach(googlemodulename, "gtalk_jabber",
+ function(s1)
+ if s1.username ~= nil and s1.register == "yes" then
+ field_name=string.gsub(s1.username, "%W", "_")
+ gtalkaccts = s:option(DynamicList, field_name, s1.username)
+
+ -- If the saved field is empty, we return a string
+ -- telling the user that this account would dial any exten.
+ function gtalkaccts.cfgvalue(self, section)
+ value = self.map:get(section, self.option)
+
+ if value == nil then
+ return {"Rings all users"}
+ else
+ return value
+ end
+ end
+
+ -- Write only valid user names.
+ function gtalkaccts.write(self, section, value)
+ users=get_valid_defaultusers(get_existing_entries(usersmodulename, "local_user"))
+ newvalue = {}
+ nindex = 1
+ for index, field in ipairs(value) do
+ if users[value[index]] == true then
+ newvalue[nindex] = value[index]
+ nindex = nindex + 1
+ end
+ end
+ DynamicList.write(self, section, newvalue)
+ end
+ end
+ end)
+
+
+m.uci:foreach(voipmodulename, "voip_provider",
+ function(s1)
+ if s1.defaultuser ~= nil and s1.host ~= nil and s1.register == "yes" then
+ field_name=string.gsub(s1.defaultuser .. "_" .. s1.host, "%W", "_")
+ voipaccts = s:option(DynamicList, field_name, s1.defaultuser .. "@" .. s1.host)
+
+ -- If the saved field is empty, we return a string
+ -- telling the user that this account would dial any exten.
+ function voipaccts.cfgvalue(self, section)
+ value = self.map:get(section, self.option)
+
+ if value == nil then
+ return {"Rings all users"}
+ else
+ return value
+ end
+ end
+
+ -- Write only valid user names.
+ function voipaccts.write(self, section, value)
+ users=get_valid_defaultusers(get_existing_entries(usersmodulename, "local_user"))
+ newvalue = {}
+ nindex = 1
+ for index, field in ipairs(value) do
+ if users[value[index]] == true then
+ newvalue[nindex] = value[index]
+ nindex = nindex + 1
+ end
+ end
+ DynamicList.write(self, section, newvalue)
+ end
+ end
+ end)
+
+----------------------------------------------------------------------------------------------------
+s = m:section(NamedSection, "providers_user_can_use", "call_routing",
+ translate("Providers Used for Outgoing Calls"),
+ translate("If you would like, you could restrict which providers users are allowed to use for outgoing\
+ calls. By default all users can use all providers. To show up in the list below the user should\
+ be allowed to make outgoing calls in the \"User Accounts\" page. Enter VoIP providers in the format\
+ username@some.host.name, as listed in \"Outgoing Calls\" above. It's easiest to copy and paste\
+ the providers from above. Invalid entries will be rejected silently. Also, any entries automatically\
+ change to this PBX's internal naming scheme, with \"_\" replacing all non-alphanumeric characters.\
+ Entries can be made in a space-separated list, and/or one per line by hitting enter after every\
+ one."))
+s.anonymous = true
+
+m.uci:foreach(usersmodulename, "local_user",
+ function(s1)
+ if s1.defaultuser ~= nil and s1.can_call == "yes" then
+ providers = s:option(DynamicList, s1.defaultuser, s1.defaultuser)
+
+ -- If the saved field is empty, we return a string
+ -- telling the user that this account would dial any exten.
+ function providers.cfgvalue(self, section)
+ value = self.map:get(section, self.option)
+
+ if value == nil then
+ return {"Uses all provider accounts"}
+ else
+ return value
+ end
+ end
+
+ -- Cook the new values prior to entering them into the config file.
+ -- Also, enter them only if they are valid.
+ function providers.write(self, section, value)
+ validvoip=get_valid_names(get_existing_entries(voipmodulename, "voip_provider"))
+ validgoog=get_valid_names(get_existing_entries(googlemodulename, "gtalk_jabber"))
+ cookedvalue = {}
+ cindex = 1
+ for index, field in ipairs(value) do
+ cooked = string.gsub(value[index], "%W", "_")
+ if validvoip[cooked] == true or validgoog[cooked] == true then
+ cookedvalue[cindex] = string.gsub(value[index], "%W", "_")
+ cindex = cindex + 1
+ end
+ end
+ DynamicList.write(self, section, cookedvalue)
+ end
+ end
+ end)
+
+----------------------------------------------------------------------------------------------------
+s = m:section(TypedSection, "callthrough_numbers", translate("Call-through Numbers"),
+ translate("Designate numbers which will be allowed to call through this system and which user's\
+ privileges it will have."))
+s.anonymous = true
+s.addremove = true
+
+num = s:option(DynamicList, "callthrough_number_list", translate("Call-through Numbers"))
+num.datatype = "uinteger"
+
+p = s:option(ListValue, "enabled", translate("Enabled"))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+user = s:option(Value, "defaultuser", translate("User Name"),
+ translate("The number(s) specified above will be able to dial outwith this user's providers.\
+ Invalid usernames are dropped silently, please verify that the entry was accepted."))
+function user.write(self, section, value)
+ users=get_valid_defaultusers(get_existing_entries(usersmodulename, "local_user"))
+ if users[value] == true then
+ Value.write(self, section, value)
+ end
+end
+
+pwd = s:option(Value, "pin", translate("PIN"),
+ translate("Your PIN disappears when saved for your protection. It will be changed\
+ only when you enter a value different from the saved one. Leaving the PIN\
+ empty is possible, but please beware of the security implications."))
+pwd.password = true
+pwd.rmempty = false
+
+-- We skip reading off the saved value and return nothing.
+function pwd.cfgvalue(self, section)
+ return ""
+end
+
+-- We check the entered value against the saved one, and only write if the entered value is
+-- something other than the empty string, and it differes from the saved value.
+function pwd.write(self, section, value)
+ local orig_pwd = m:get(section, self.option)
+ if value and #value > 0 and orig_pwd ~= value then
+ Value.write(self, section, value)
+ end
+end
+
+----------------------------------------------------------------------------------------------------
+s = m:section(NamedSection, "blacklisting", "call_routing", translate("Blacklisted Numbers"),
+ translate("Enter phone numbers that you want to decline calls from automatically.\
+ You should probably omit the country code and any leading\
+ zeroes, but please experiment to make sure you are blocking numbers from your\
+ desired area successfully."))
+s.anonymous = true
+
+b = s:option(DynamicList, "blacklist1", translate("Dynamic List of Blacklisted Numbers"),
+ translate("Specify numbers individually here. Press enter to add more numbers."))
+b.cast = "string"
+b.datatype = "uinteger"
+
+b = s:option(Value, "blacklist2", translate("Space-Separated List of Blacklisted Numbers"),
+ translate("Copy-paste large lists of numbers here."))
+b.template = "cbi/tvalue"
+b.rows = 3
+
+return m
diff --git a/applications/luci-pbx/luasrc/model/cbi/pbx-google.lua b/applications/luci-pbx/luasrc/model/cbi/pbx-google.lua
new file mode 100644
index 000000000..128c7a307
--- /dev/null
+++ b/applications/luci-pbx/luasrc/model/cbi/pbx-google.lua
@@ -0,0 +1,120 @@
+--[[
+ Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+
+ This file is part of luci-pbx.
+
+ luci-pbx is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ luci-pbx is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+]]--
+
+if nixio.fs.access("/etc/init.d/asterisk") then
+ server = "asterisk"
+elseif nixio.fs.access("/etc/init.d/freeswitch") then
+ server = "freeswitch"
+else
+ server = ""
+end
+
+modulename = "pbx-google"
+googlemodulename = "pbx-google"
+defaultstatus = "dnd"
+defaultstatusmessage = "PBX online, may lose messages"
+
+m = Map (modulename, translate("Google Accounts"),
+ translate("This is where you set up your Google (Talk and Voice) Accounts, in order to start\
+ using them for dialing and receiving calls (voice chat and real phone calls). Click \"Add\"\
+ to add as many accounts as you wish."))
+
+-- Recreate the config, and restart services after changes are commited to the configuration.
+function m.on_after_commit(self)
+ -- Create a field "name" for each account which identifies the account in the backend.
+ commit = false
+ m.uci:foreach(modulename, "gtalk_jabber",
+ function(s1)
+ if s1.username ~= nil then
+ name=string.gsub(s1.username, "%W", "_")
+ if s1.name ~= name then
+ m.uci:set(modulename, s1['.name'], "name", name)
+ commit = true
+ end
+ end
+ end)
+ if commit == true then m.uci:commit(modulename) end
+
+ luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+ luci.sys.call("/etc/init.d/asterisk restart 1\>/dev/null 2\>/dev/null")
+end
+
+-----------------------------------------------------------------------------
+s = m:section(TypedSection, "gtalk_jabber", translate("Google Voice/Talk Accounts"))
+s.anonymous = true
+s.addremove = true
+
+s:option(Value, "username", translate("Email"))
+
+pwd = s:option(Value, "secret", translate("Password"),
+ translate("When your password is saved, it disappears from this field and is not displayed\
+ for your protection. The previously saved password will be changed only when you\
+ enter a value different from the saved one."))
+pwd.password = true
+pwd.rmempty = false
+
+-- We skip reading off the saved value and return nothing.
+function pwd.cfgvalue(self, section)
+ return ""
+end
+
+-- We check the entered value against the saved one, and only write if the entered value is
+-- something other than the empty string, and it differes from the saved value.
+function pwd.write(self, section, value)
+ local orig_pwd = m:get(section, self.option)
+ if value and #value > 0 and orig_pwd ~= value then
+ Value.write(self, section, value)
+ end
+end
+
+
+p = s:option(ListValue, "register",
+ translate("Enable Incoming Calls (See Status, Message below)"),
+ translate("When somebody starts voice chat with your GTalk account or calls the GVoice,\
+ number (if you have Google Voice), the call will be forwarded to any users\
+ that are online (registered using a SIP device or softphone) and permitted to\
+ receive the call. If you have Google Voice, you must go to your GVoice settings and\
+ forward calls to Google chat in order to actually receive calls made to your\
+ GVoice number. If you have trouble receiving calls from GVoice, experiment\
+ with the Call Screening option in your GVoice Settings. Finally, make sure no other\
+ client is online with this account (browser in gmail, mobile/desktop Google Talk\
+ App) as it may interfere."))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+p = s:option(ListValue, "make_outgoing_calls", translate("Enable Outgoing Calls"),
+ translate("Use this account to make outgoing calls as configured in the \"Call Routing\" section."))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+st = s:option(ListValue, "status", translate("Account Status"))
+st:depends("register", "yes")
+st:value("dnd", translate("Do Not Disturb"))
+st:value("away", translate("Away"))
+st:value("available", translate("Available"))
+st.default = defaultstatus
+
+stm = s:option(Value, "statusmessage", translate("Account Status Message"),
+ translate("Avoid using anything but alpha-numeric characters, space, comma, and period."))
+stm:depends("register", "yes")
+stm.default = defaultstatusmessage
+
+return m
diff --git a/applications/luci-pbx/luasrc/model/cbi/pbx-users.lua b/applications/luci-pbx/luasrc/model/cbi/pbx-users.lua
new file mode 100644
index 000000000..7c25308cd
--- /dev/null
+++ b/applications/luci-pbx/luasrc/model/cbi/pbx-users.lua
@@ -0,0 +1,148 @@
+--[[
+ Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+
+ This file is part of luci-pbx.
+
+ luci-pbx is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ luci-pbx is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+]]--
+
+if nixio.fs.access("/etc/init.d/asterisk") then
+ server = "asterisk"
+elseif nixio.fs.access("/etc/init.d/freeswitch") then
+ server = "freeswitch"
+else
+ server = ""
+end
+
+modulename = "pbx-users"
+modulenamecalls = "pbx-calls"
+modulenameadvanced = "pbx-advanced"
+
+m = Map (modulename, translate("User Accounts"),
+ translate("Here you must configure at least one SIP account, which you\
+ will use to register with this service. Use this account either in an analog telephony\
+ adapter (ATA), or in a SIP softphone like CSipSimple, Linphone, or Sipdroid on your\
+ Android smartphone, or X-lite or Ekiga on your computer. By default, all SIP accounts\
+ will ring simultaneously if a call is made to one of your VoIP provider accounts or GV\
+ numbers."))
+
+-- Recreate the config, and restart services after changes are commited to the configuration.
+function m.on_after_commit(self)
+ --allusers = ""
+ --ringusers = ""
+ --
+ ---- Create two lists of users - one of all users and one of users enabled for incoming calls.
+ --m.uci:foreach(modulename, "local_user",
+ -- function(s1)
+ -- allusers = allusers .. " " .. s1.defaultuser
+ -- if s1.ring == "yes" then
+ -- ringusers = ringusers .. " " .. s1.defaultuser
+ -- end
+ -- end)
+ --
+ --m.uci:set (modulenamecalls, "valid_users", "allusers", allusers)
+ --m.uci:set (modulenamecalls, "valid_users", "ringusers", ringusers)
+ --m.uci:commit (modulenamecalls)
+
+ luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+ luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+end
+
+externhost = m.uci:get(modulenameadvanced, "advanced", "externhost")
+bindport = m.uci:get(modulenameadvanced, "advanced", "bindport")
+ipaddr = m.uci:get("network", "lan", "ipaddr")
+
+-----------------------------------------------------------------------------
+s = m:section(NamedSection, "server", "user", translate("Server Setting"))
+s.anonymous = true
+
+if ipaddr == nil or ipaddr == "" then
+ ipaddr = "(IP address not static)"
+end
+
+if bindport ~= nil then
+ just_ipaddr = ipaddr
+ ipaddr = ipaddr .. ":" .. bindport
+end
+
+s:option(DummyValue, "ipaddr", translate("Server Setting for Local SIP Devices"),
+ translate("Enter this IP (or IP:port) in the Server/Registrar setting of SIP devices you will\
+ use ONLY locally and never from a remote location.")).default = ipaddr
+
+if externhost ~= nil then
+ if bindport ~= nil then
+ just_externhost = externhost
+ externhost = externhost .. ":" .. bindport
+ end
+ s:option(DummyValue, "externhost", translate("Server Setting for Remote SIP Devices"),
+ translate("Enter this hostname (or hostname:port) in the Server/Registrar setting of SIP\
+ devices you will use from a remote location (they will work locally too).")
+ ).default = externhost
+end
+
+if bindport ~= nil then
+ s:option(DummyValue, "bindport", translate("Port Setting for SIP Devices"),
+ translatef("If setting Server/Registrar to %s or %s does not work for you, try setting\
+ it to %s or %s and entering this port number in a separate field which specifies the\
+ Server/Registrar port number. Beware that some devices have a confusing\
+ setting which sets the port where SIP requests originate from on the SIP\
+ device itself (bind port). The port specified on this page is NOT this bind port\
+ but the this service listens on.",
+ ipaddr, externhost, just_ipaddr, just_externhost)).default = bindport
+end
+
+-----------------------------------------------------------------------------
+s = m:section(TypedSection, "local_user", translate("SIP Device/Softphone Accounts"))
+s.anonymous = true
+s.addremove = true
+
+s:option(Value, "fullname", translate("Full Name"),
+ translate("You can specify a real name to show up in the Caller ID here."))
+
+du = s:option(Value, "defaultuser", translate("User Name"),
+ translate("Use (four to five digit) numeric user name if you are connecting normal telephones\
+ with ATAs to this system (so they can dial user names)."))
+du.datatype = "uciname"
+
+pwd = s:option(Value, "secret", translate("Password"),
+ translate("Your password disappears when saved for your protection. It will be changed\
+ only when you enter a value different from the saved one."))
+pwd.password = true
+pwd.rmempty = false
+
+-- We skip reading off the saved value and return nothing.
+function pwd.cfgvalue(self, section)
+ return ""
+end
+
+-- We check the entered value against the saved one, and only write if the entered value is
+-- something other than the empty string, and it differes from the saved value.
+function pwd.write(self, section, value)
+ local orig_pwd = m:get(section, self.option)
+ if value and #value > 0 and orig_pwd ~= value then
+ Value.write(self, section, value)
+ end
+end
+
+p = s:option(ListValue, "ring", translate("Receives Incoming Calls"))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+p = s:option(ListValue, "can_call", translate("Makes Outgoing Calls"))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+return m
diff --git a/applications/luci-pbx/luasrc/model/cbi/pbx-voip.lua b/applications/luci-pbx/luasrc/model/cbi/pbx-voip.lua
new file mode 100644
index 000000000..0be3deab6
--- /dev/null
+++ b/applications/luci-pbx/luasrc/model/cbi/pbx-voip.lua
@@ -0,0 +1,116 @@
+--[[
+ Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+
+ This file is part of luci-pbx.
+
+ luci-pbx is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ luci-pbx is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+]]--
+
+if nixio.fs.access("/etc/init.d/asterisk") then
+ server = "asterisk"
+elseif nixio.fs.access("/etc/init.d/freeswitch") then
+ server = "freeswitch"
+else
+ server = ""
+end
+
+modulename = "pbx-voip"
+
+m = Map (modulename, translate("SIP Accounts"),
+ translate("This is where you set up your SIP (VoIP) accounts ts like Sipgate, SipSorcery,\
+ the popular Betamax providers, and any other providers with SIP settings in order to start \
+ using them for dialing and receiving calls (SIP uri and real phone calls). Click \"Add\" to\
+ add as many accounts as you wish."))
+
+-- Recreate the config, and restart services after changes are commited to the configuration.
+function m.on_after_commit(self)
+ commit = false
+ -- Create a field "name" for each account which identifies the account in the backend.
+ m.uci:foreach(modulename, "voip_provider",
+ function(s1)
+ if s1.defaultuser ~= nil and s1.host ~= nil then
+ name=string.gsub(s1.defaultuser.."_"..s1.host, "%W", "_")
+ if s1.name ~= name then
+ m.uci:set(modulename, s1['.name'], "name", name)
+ commit = true
+ end
+ end
+ end)
+ if commit == true then m.uci:commit(modulename) end
+
+ luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+ luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
+end
+
+-----------------------------------------------------------------------------
+s = m:section(TypedSection, "voip_provider", translate("SIP Provider Accounts"))
+s.anonymous = true
+s.addremove = true
+
+s:option(Value, "defaultuser", translate("User Name"))
+pwd = s:option(Value, "secret", translate("Password"),
+ translate("When your password is saved, it disappears from this field and is not displayed\
+ for your protection. The previously saved password will be changed only when you\
+ enter a value different from the saved one."))
+
+
+
+pwd.password = true
+pwd.rmempty = false
+
+-- We skip reading off the saved value and return nothing.
+function pwd.cfgvalue(self, section)
+ return ""
+end
+
+-- We check the entered value against the saved one, and only write if the entered value is
+-- something other than the empty string, and it differes from the saved value.
+function pwd.write(self, section, value)
+ local orig_pwd = m:get(section, self.option)
+ if value and #value > 0 and orig_pwd ~= value then
+ Value.write(self, section, value)
+ end
+end
+
+h = s:option(Value, "host", translate("SIP Server/Registrar"))
+h.datatype = "host"
+
+p = s:option(ListValue, "register", translate("Enable Incoming Calls (Register via SIP)"),
+ translate("This option should be set to \"Yes\" if you have a DID \(real telephone number\)\
+ associated with this SIP account or want to receive SIP uri calls through this\
+ provider."))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+p = s:option(ListValue, "make_outgoing_calls", translate("Enable Outgoing Calls"),
+ translate("Use this account to make outgoing calls."))
+p:value("yes", translate("Yes"))
+p:value("no", translate("No"))
+p.default = "yes"
+
+from = s:option(Value, "fromdomain",
+ translate("SIP Realm (needed by some providers)"))
+from.optional = true
+from.datatype = "host"
+
+port = s:option(Value, "port", translate("SIP Server/Registrar Port"))
+port.optional = true
+port.datatype = "port"
+
+op = s:option(Value, "outboundproxy", translate("Outbound Proxy"))
+op.optional = true
+op.datatype = "host"
+
+return m
diff --git a/applications/luci-pbx/luasrc/model/cbi/pbx.lua b/applications/luci-pbx/luasrc/model/cbi/pbx.lua
new file mode 100644
index 000000000..f73930eee
--- /dev/null
+++ b/applications/luci-pbx/luasrc/model/cbi/pbx.lua
@@ -0,0 +1,116 @@
+--[[
+ Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+
+ This file is part of luci-pbx.
+
+ luci-pbx is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ luci-pbx is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+]]--
+
+if nixio.fs.access("/etc/init.d/asterisk") then
+ server = "asterisk"
+elseif nixio.fs.access("/etc/init.d/freeswitch") then
+ server = "freeswitch"
+else
+ server = ""
+end
+
+modulename = "pbx"
+
+function mysplit(inputstr, sep)
+ if sep == nil then
+ sep = "%s"
+ end
+ t={} ; i=1
+ for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+ t[i] = str
+ i = i + 1
+ end
+ return t
+end
+
+function format_two_indices(string, ind1, ind2)
+ lines=mysplit(string, "\n")
+
+ words={}
+ for index,value in ipairs(lines) do
+ words[index]=mysplit(value)
+ end
+
+ output = ""
+ for index,value in ipairs(words) do
+ if value[ind1] ~= nil and value[ind2] ~= nil then
+ output = output .. string.format("%-40s \t %-20s\n", value[ind1], value[ind2])
+ end
+ end
+ return output
+end
+
+function format_one_index(string, ind1)
+ lines=mysplit(string, "\n")
+
+ words={}
+ for index,value in ipairs(lines) do
+ words[index]=mysplit(value)
+ end
+
+ output = ""
+ for index,value in ipairs(words) do
+ if value[ind1] ~= nil then
+ output = output .. string.format("%-40s\n", value[ind1])
+ end
+ end
+ return output
+end
+
+m = Map (modulename, translate("PBX Main Page"),
+ translate("This configuration page allows you to configure a phone system (PBX) service which\
+ permits making phone calls with, and sharing multiple Google and SIP (like Sipgate,\
+ SipSorcery, and Betamax) accounts among many SIP devices. Note that Google\
+ accounts, SIP accounts, and local user accounts are configured in the\
+ \"Google Accounts\", \"SIP Accounts\", and \"User Accounts\" sub-sections.\
+ You must configure at least one local SIP account\
+ on this PBX, to make and receive calls with your Google/SIP accounts.\
+ Configuring multiple users will allow you to make free calls between users, and share the configured\
+ Google and SIP accounts. If you have more than one Google and SIP accounts set up,\
+ you should probably configure how calls to and from them are routed in the \"Call Routing\" page.\
+ If you're interested in using your own PBX from anywhere in the world,\
+ then visit the \"Remote Usage\" section in the \"Advanced Settings\" page."))
+
+----------------------------------------------------------------------------------------------------
+s = m:section(NamedSection, "connection_status", "main", translate("Service Control and Connection Status"))
+s.anonymous = true
+
+s:option (DummyValue, "status", translate("Service Status"))
+
+sts = s:option(DummyValue, "_sts")
+sts.template = "cbi/tvalue"
+sts.rows = 20
+
+function sts.cfgvalue(self, section)
+
+ if server == "asterisk" then
+ reg = luci.sys.exec("asterisk -rx 'sip show registry' | sed 's/peer-//'")
+ jab = luci.sys.exec("asterisk -rx 'jabber show connections' | grep onnected")
+ usrs = luci.sys.exec("asterisk -rx 'sip show users'")
+ chan = luci.sys.exec("asterisk -rx 'core show channels'")
+ return format_two_indices(reg, 1, 5) .. format_two_indices(jab, 2, 4) .. "\n"
+ .. format_one_index(usrs,1) .. "\n" .. chan
+ elseif server == "freeswitch" then
+ return "Freeswitch is not supported yet.\n"
+ else
+ return "Neither Asterisk nor FreeSwitch discovered, please install Asterisk, as Freeswitch is not supported yet.\n"
+ end
+end
+
+return m
diff --git a/applications/luci-pbx/root/etc/config/pbx b/applications/luci-pbx/root/etc/config/pbx
new file mode 100644
index 000000000..ca7c1669d
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx
@@ -0,0 +1 @@
+config 'main' 'connection_status'
diff --git a/applications/luci-pbx/root/etc/config/pbx-advanced b/applications/luci-pbx/root/etc/config/pbx-advanced
new file mode 100644
index 000000000..e7ac0e221
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-advanced
@@ -0,0 +1 @@
+config 'settings' 'advanced'
diff --git a/applications/luci-pbx/root/etc/config/pbx-calls b/applications/luci-pbx/root/etc/config/pbx-calls
new file mode 100644
index 000000000..822bd4a1b
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-calls
@@ -0,0 +1,7 @@
+config 'call_routing' 'outgoing_calls'
+
+config 'call_routing' 'incoming_calls'
+
+config 'call_routing' 'providers_user_can_use'
+
+config 'call_routing' 'blacklisting'
diff --git a/applications/luci-pbx/root/etc/config/pbx-google b/applications/luci-pbx/root/etc/config/pbx-google
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-google
diff --git a/applications/luci-pbx/root/etc/config/pbx-users b/applications/luci-pbx/root/etc/config/pbx-users
new file mode 100644
index 000000000..a4277b1bf
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-users
@@ -0,0 +1 @@
+config 'user' 'server'
diff --git a/applications/luci-pbx/root/etc/config/pbx-voip b/applications/luci-pbx/root/etc/config/pbx-voip
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/applications/luci-pbx/root/etc/config/pbx-voip
diff --git a/applications/luci-pbx/root/etc/init.d/pbx-asterisk b/applications/luci-pbx/root/etc/init.d/pbx-asterisk
new file mode 100644
index 000000000..d96eb4f08
--- /dev/null
+++ b/applications/luci-pbx/root/etc/init.d/pbx-asterisk
@@ -0,0 +1,638 @@
+#!/bin/sh /etc/rc.common
+#
+# Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
+#
+# This file is part of luci-pbx.
+#
+# luci-pbx is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# luci-pbx is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with luci-pbx. If not, see <http://www.gnu.org/licenses/>.
+
+. /etc/functions.sh
+
+START=60
+
+# Some global variables
+MODULENAME=pbx
+USERAGENT="PBX"
+DEFAULTOUTCNTXT=default-outgoing-call-context
+HANGUPCNTXT=hangup
+GTALKUNVL=unavailable
+
+ASTUSER=nobody
+ASTGROUP=nogroup
+ASTDIRSRECURSIVE="/var/run/asterisk /var/log/asterisk /var/spool/asterisk"
+ASTDIRS="/usr/lib/asterisk"
+
+FIREWALL_PATH="/etc/asterisk/firewall.$MODULENAME"
+
+TEMPLATEDIR=/etc/${MODULENAME}-asterisk
+ASTERISKDIR=/etc/asterisk
+WORKDIR=/tmp/$MODULENAME.$$
+MD5SUMSFILE=/tmp/$MODULENAME-sums.$$
+
+TMPL_ASTERISK=$TEMPLATEDIR/asterisk.conf.TEMPLATE
+TMPL_GTALK=$TEMPLATEDIR/gtalk.conf.TEMPLATE
+TMPL_INDICATIONS=$TEMPLATEDIR/indications.conf.TEMPLATE
+TMPL_LOGGER=$TEMPLATEDIR/logger.conf.TEMPLATE
+TMPL_MANAGER=$TEMPLATEDIR/manager.conf.TEMPLATE
+TMPL_MODULES=$TEMPLATEDIR/modules.conf.TEMPLATE
+TMPL_RTP=$TEMPLATEDIR/rtp.conf.TEMPLATE
+
+TMPL_EXTCTHRUCHECKHDR=$TEMPLATEDIR/extensions_disa-check_header.conf.TEMPLATE
+TMPL_EXTCTHRUCHECK=$TEMPLATEDIR/extensions_disa-check.conf.TEMPLATE
+TMPL_EXTCTHRUCHECKFTR=$TEMPLATEDIR/extensions_disa-check_footer.conf.TEMPLATE
+TMPL_EXTCTHRUHDR=$TEMPLATEDIR/extensions_disa_header.conf.TEMPLATE
+TMPL_EXTCTHRU=$TEMPLATEDIR/extensions_disa.conf.TEMPLATE
+
+TMPL_EXTENSIONS=$TEMPLATEDIR/extensions.conf.TEMPLATE
+
+TMPL_EXTBLKLIST=$TEMPLATEDIR/extensions_blacklist.conf.TEMPLATE
+TMPL_EXTBLKLISTFTR=$TEMPLATEDIR/extensions_blacklist_footer.conf.TEMPLATE
+TMPL_EXTBLKLISTHDR=$TEMPLATEDIR/extensions_blacklist_header.conf.TEMPLATE
+
+TMPL_EXTINCNTXTSIP=$TEMPLATEDIR/extensions_incoming_context_sip.conf.TEMPLATE
+TMPL_EXTINCNTXTGTALKHDR=$TEMPLATEDIR/extensions_incoming_context_gtalk_header.conf.TEMPLATE
+TMPL_EXTINCNTXTGTALK=$TEMPLATEDIR/extensions_incoming_context_gtalk.conf.TEMPLATE
+
+TMPL_EXTUSERCNTXT=$TEMPLATEDIR/extensions_user_context.conf.TEMPLATE
+TMPL_EXTUSERCNTXTFTR=$TEMPLATEDIR/extensions_user_context_footer.conf.TEMPLATE
+TMPL_EXTUSERCNTXTHDR=$TEMPLATEDIR/extensions_user_context_header.conf.TEMPLATE
+
+TMPL_EXTOUTHDR=$TEMPLATEDIR/extensions_default_outgoing_header.conf.TEMPLATE
+TMPL_EXTOUTGTALK=$TEMPLATEDIR/extensions_outgoing_gtalk.conf.TEMPLATE
+TMPL_EXTOUTLOCAL=$TEMPLATEDIR/extensions_outgoing_dial_local_user.conf.TEMPLATE
+TMPL_EXTOUTSIP=$TEMPLATEDIR/extensions_outgoing_sip.conf.TEMPLATE
+
+TMPL_FIREWALL=$TEMPLATEDIR/firewall.$MODULENAME.TEMPLATE
+TMPL_JABBER=$TEMPLATEDIR/jabber.conf.TEMPLATE
+TMPL_JABBERUSER=$TEMPLATEDIR/jabber_users.conf.TEMPLATE
+TMPL_SIP=$TEMPLATEDIR/sip.conf.TEMPLATE
+TMPL_SIPPEER=$TEMPLATEDIR/sip_peer.TEMPLATE
+TMPL_SIPREG=$TEMPLATEDIR/sip_registration.TEMPLATE
+TMPL_SIPUSR=$TEMPLATEDIR/sip_user.TEMPLATE
+
+INCLUDED_FILES="$WORKDIR/extensions_blacklist.conf $WORKDIR/extensions_callthrough.conf\
+ $WORKDIR/extensions_incoming.conf $WORKDIR/extensions_incoming_gtalk.conf\
+ $WORKDIR/extensions_user.conf $WORKDIR/jabber_users.conf\
+ $WORKDIR/sip_peers.conf $WORKDIR/sip_registrations.conf\
+ $WORKDIR/sip_users.conf"
+
+
+# In this string, we concatenate all local users enabled to receive calls
+# readily formatted for the Dial command.
+localusers_to_ring=""
+# In this string, we keep a list of all users that are enabled for outgoing
+# calls. It is used at the end to create the user contexts.
+localusers_can_dial=""
+
+# In this string, we put together a space-separated list of provider names
+# (alphanumeric, with all non-alpha characters replaced with underscores),
+# which will be used to dial out by default (whose outgoing contexts will
+# be included in users' contexts by default.
+outbound_providers=""
+
+# Copies the template files which we don't edit.
+copy_unedited_templates_over()
+{
+ cp $TMPL_ASTERISK $WORKDIR/asterisk.conf
+ cp $TMPL_GTALK $WORKDIR/gtalk.conf
+ cp $TMPL_INDICATIONS $WORKDIR/indications.conf
+ cp $TMPL_LOGGER $WORKDIR/logger.conf
+ cp $TMPL_MANAGER $WORKDIR/manager.conf
+ cp $TMPL_MODULES $WORKDIR/modules.conf
+}
+
+# Touches all the included files, to prevent asterisk from refusing to
+# start if a config item is missing and an included config file isn't created.
+create_included_files()
+{
+ touch $INCLUDED_FILES
+}
+
+# Puts together all the extensions.conf related configuration.
+pbx_create_extensions_config()
+{
+ sed "s/|LOCALUSERS|/$localusers_to_ring/g" $TMPL_EXTENSIONS > $WORKDIR/extensions.conf
+ mv $WORKDIR/inext.TMP $WORKDIR/extensions_incoming.conf
+ cp $TMPL_EXTINCNTXTGTALKHDR $WORKDIR/extensions_incoming_gtalk.conf
+ cat $WORKDIR/outextgtalk.TMP >> $WORKDIR/extensions_incoming_gtalk.conf 2>/dev/null
+ rm -f $WORKDIR/outextgtalk.TMP
+ mv $WORKDIR/blacklist.TMP $WORKDIR/extensions_blacklist.conf
+ mv $WORKDIR/userext.TMP $WORKDIR/extensions_user.conf
+ cp $TMPL_EXTCTHRUHDR $WORKDIR/extensions_callthrough.conf
+ cat $WORKDIR/callthrough.TMP >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+ rm -f $WORKDIR/callthrough.TMP
+ cat $TMPL_EXTCTHRUCHECKHDR >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+ cat $WORKDIR/callthroughcheck.TMP >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+ rm -f $WORKDIR/callthroughcheck.TMP
+ cat $TMPL_EXTCTHRUCHECKFTR >> $WORKDIR/extensions_callthrough.conf 2>/dev/null
+ rm -f $WORKDIR/outext-*.TMP
+ rm -f $WORKDIR/localext.TMP
+}
+
+# Puts together all the sip.conf related configuration.
+pbx_create_sip_config()
+{
+ mv $WORKDIR/sip_regs.TMP $WORKDIR/sip_registrations.conf
+ mv $WORKDIR/sip_peers.TMP $WORKDIR/sip_peers.conf
+ mv $WORKDIR/sip_users.TMP $WORKDIR/sip_users.conf
+}
+
+# Creates the jabber.conf related config
+pbx_create_jabber_config()
+{
+ cp $TMPL_JABBER $WORKDIR/jabber.conf
+ mv $WORKDIR/jabber.TMP $WORKDIR/jabber_users.conf
+}
+
+# Gets rid of any config files from $ASTERISKDIR not found in $WORKDIR.
+clean_up_asterisk_config_dir()
+{
+ for f in $ASTERISKDIR/* ; do
+ basef="`basename $f`"
+ if [ ! -e "$WORKDIR/$basef" ] ; then
+ rm -rf "$f"
+ fi
+ done
+}
+
+# Compares md5sums of the config files in $WORKDIR to those
+# in $ASTERISKDIR, and copies only changed files over to reduce
+# wear on flash in embedded devices.
+compare_configs_and_copy_changed()
+{
+ # First, compute md5sums of the config files in $WORKDIR.
+ cd $WORKDIR/
+ md5sum * > $MD5SUMSFILE
+
+ # Now, check the files in $ASTERISKDIR against the md5sums.
+ cd $ASTERISKDIR/
+ changed_files="`md5sum -c $MD5SUMSFILE 2>/dev/null | fgrep ": FAILED" | awk -F: '{print $1}'`"
+
+ rm -f $MD5SUMSFILE
+
+ [ -z "$changed_files" ] && return
+
+ # Now copy over the changed files.
+ for f in $changed_files ; do
+ cp "$WORKDIR/$f" "$ASTERISKDIR/$f"
+ done
+}
+
+# Calls the functions that create the final config files
+# Calls the function which compares which files have changed
+# Puts the final touches on $ASTERISKDIR
+# Gets rid of $WORKDIR
+pbx_assemble_and_copy_config()
+{
+ mkdir -p $ASTERISKDIR
+
+ copy_unedited_templates_over
+ create_included_files
+ pbx_create_extensions_config
+ pbx_create_sip_config
+ pbx_create_jabber_config
+
+ touch $WORKDIR/features.conf
+
+ # At this point, $WORKDIR should contain a complete, working config.
+ clean_up_asterisk_config_dir
+
+ compare_configs_and_copy_changed
+
+ [ ! -d $ASTERISKDIR/manager.d ] && mkdir -p $ASTERISKDIR/manager.d/
+
+ # Get rid of the working directory
+ rm -rf $WORKDIR/
+}
+
+# Creates configuration for a user and adds it to the temporary file that holds
+# all users configured so far.
+pbx_add_user()
+{
+ local fullname
+ local defaultuser
+ local secret
+ local ring
+ local can_call
+
+ config_get fullname $1 fullname
+ config_get defaultuser $1 defaultuser
+ config_get secret $1 secret
+ config_get ring $1 ring
+ config_get can_call $1 can_call
+
+ [ -z "$defaultuser" -o -z "$secret" ] && return
+ [ -z "$fullname" ] && fullname="$defaultuser"
+
+ sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPUSR > $WORKDIR/sip_user.tmp
+
+ if [ "$can_call" = "yes" ] ; then
+ # Add user to list of all users that are allowed to make calls.
+ localusers_can_dial="$localusers_can_dial $defaultuser"
+ sed -i "s/|CONTEXTNAME|/$defaultuser/g" $WORKDIR/sip_user.tmp
+ else
+ sed -i "s/|CONTEXTNAME|/$HANGUPCNTXT/g" $WORKDIR/sip_user.tmp
+ fi
+
+ # Add this user's configuration to the temp file containing all user configs.
+ sed "s/|FULLNAME|/$fullname/" $WORKDIR/sip_user.tmp |\
+ sed "s/|SECRET|/$secret/g" >> $WORKDIR/sip_users.TMP
+
+ if [ "$ring" = "yes" ] ; then
+ if [ -z "$localusers_to_ring" ] ; then
+ localusers_to_ring="SIP\/$defaultuser"
+ else
+ localusers_to_ring="$localusers_to_ring\&SIP\/$defaultuser"
+ fi
+ fi
+
+ # Add configuration which allows local users to call each other.
+ sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_EXTOUTLOCAL >> $WORKDIR/localext.TMP
+
+ rm -f $WORKDIR/sip_user.tmp
+}
+
+# Creates configuration for a Google account, and adds it to the temporary file that holds
+# all accounts configured so far.
+# Also creates the outgoing extensions which are used in users' outgoing contexts.
+pbx_add_jabber()
+{
+ local username
+ local secret
+ local numprefix
+ local register
+ local make_outgoing_calls
+ local name
+ local users_to_ring
+ local status
+ local statusmessage
+
+ config_get username $1 username
+ config_get secret $1 secret
+ config_get numprefix $1 numprefix
+ config_get register $1 register
+ config_get make_outgoing_calls $1 make_outgoing_calls
+ config_get name $1 name
+ config_get status $1 status
+ config_get statusmessage $1 statusmessage
+
+ [ -z "$username" -o -z "$secret" ] && return
+
+ # Construct a jabber entry for this provider.
+ sed "s/|USERNAME|/$username/g" $TMPL_JABBERUSER |\
+ sed "s/|NAME|/$name/g" > $WORKDIR/jabber.tmp
+
+ if [ "$register" = yes ] ; then
+ # If this provider is enabled for incoming calls, we need to set the
+ # status of the user to something other than unavailable in order to receive calls.
+ sed -i "s/|STATUS|/$status/g" $WORKDIR/jabber.tmp
+ sed -i "s/|STATUSMESSAGE|/\"$statusmessage\"/g" $WORKDIR/jabber.tmp
+
+ users_to_ring="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
+ # If no users have been specified to ring, we ring all users enabled for incoming calls.
+ if [ -z "$users_to_ring" ] ; then
+ users_to_ring=$localusers_to_ring
+ else
+ # Else, we cook up a string formatted for the Dial command
+ # with the specified users (SIP/user1&SIP/user2&...). We do it
+ # with set, shift and a loop in order to be more tolerant of ugly whitespace
+ # messes entered by users.
+ set $users_to_ring
+ users_to_ring="SIP\/$1" && shift
+ for u in $@ ; do users_to_ring=$users_to_ring\\\&SIP\\\/$u ; done
+ fi
+
+ # Now, we add this account to the gtalk incoming context.
+ sed "s/|USERNAME|/$username/g" $TMPL_EXTINCNTXTGTALK |\
+ sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/outextgtalk.TMP
+ else
+ sed -i "s/|STATUS|/$GTALKUNVL/g" $WORKDIR/jabber.tmp
+ sed -i "s/|STATUSMESSAGE|/\"\"/g" $WORKDIR/jabber.tmp
+ fi
+
+ # Add this account's configuration to the temp file containing all account configs.
+ sed "s/|SECRET|/$secret/g" $WORKDIR/jabber.tmp >> $WORKDIR/jabber.TMP
+
+ # If this provider is enabled for outgoing calls.
+ if [ "$make_outgoing_calls" = "yes" ] ; then
+
+ numprefix="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
+
+ # If no prefixes are specified, then we use "X" which matches any prefix.
+ [ -z "$numprefix" ] && numprefix="X"
+
+ for p in $numprefix ; do
+ sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTGTALK |\
+ sed "s/|NAME|/$name/g" >> $WORKDIR/outext-$name.TMP
+ done
+
+ # Add this provider to the list of enabled outbound providers.
+ if [ -z "$outbound_providers" ] ; then
+ outbound_providers="$name"
+ else
+ outbound_providers="$outbound_providers $name"
+ fi
+ fi
+
+ rm -f $WORKDIR/jabber.tmp
+}
+
+# Creates configuration for a SIP provider account, and adds it to the temporary file that holds
+# all accounts configured so far.
+# Also creates the outgoing extensions which are used in users' outgoing contexts.
+pbx_add_peer()
+{
+ local defaultuser
+ local secret
+ local host
+ local fromdomain
+ local register
+ local numprefix
+ local make_outgoing_calls
+ local name
+ local users_to_ring
+ local port
+ local outboundproxy
+
+ config_get defaultuser $1 defaultuser
+ config_get secret $1 secret
+ config_get host $1 host
+ config_get port $1 port
+ config_get outbountproxy $1 outboundproxy
+ config_get fromdomain $1 fromdomain
+ config_get register $1 register
+ config_get numprefix $1 numprefix
+ config_get make_outgoing_calls $1 make_outgoing_calls
+ config_get name $1 name
+
+ [ -z "$defaultuser" -o -z "$secret" -o -z "$host" ] && return
+ [ -z "$fromdomain" ] && fromdomain=$host
+ [ -n "$port" ] && port="port=$port"
+ [ -n "$outboundproxy" ] && outboundproxy="outboundproxy=$outboundproxy"
+
+ # Construct a sip peer entry for this provider.
+ sed "s/|DEFAULTUSER|/$defaultuser/" $TMPL_SIPPEER > $WORKDIR/sip_peer.tmp
+ sed -i "s/|NAME|/$name/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|FROMUSER|/$defaultuser/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|SECRET|/$secret/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|HOST|/$host/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|PORT|/$port/" $WORKDIR/sip_peer.tmp
+ sed -i "s/|OUTBOUNDPROXY|/$outboundproxy/" $WORKDIR/sip_peer.tmp
+ # Add this account's configuration to the temp file containing all account configs.
+ sed "s/|FROMDOMAIN|/$host/" $WORKDIR/sip_peer.tmp >> $WORKDIR/sip_peers.TMP
+
+ # If this provider is enabled for incoming calls.
+ if [ "$register" = "yes" ] ; then
+ # Then we create a registration string for this provider.
+ sed "s/|DEFAULTUSER|/$defaultuser/g" $TMPL_SIPREG > $WORKDIR/sip_reg.tmp
+ sed -i "s/|SECRET|/$secret/g" $WORKDIR/sip_reg.tmp
+ sed "s/|NAME|/$name/g" $WORKDIR/sip_reg.tmp >> $WORKDIR/sip_regs.TMP
+
+ users_to_ring="`uci -q get ${MODULENAME}-calls.incoming_calls.$name`"
+ # If no users have been specified to ring, we ring all users enabled for incoming calls.
+ if [ -z "$users_to_ring" ] ; then
+ users_to_ring=$localusers_to_ring
+ else
+ # Else, we cook up a string formatted for the Dial command
+ # with the specified users (SIP/user1&SIP/user2&...). We do it
+ # with set, shift and a loop in order to be more tolerant of ugly whitespace
+ # messes entered by users.
+ set $users_to_ring
+ users_to_ring="SIP\/$1" && shift
+ for u in $@ ; do users_to_ring=$users_to_ring\\\&SIP\\\/$u ; done
+ fi
+
+ # And we create an incoming calls context for this provider.
+ sed "s/|NAME|/$name/g" $TMPL_EXTINCNTXTSIP |\
+ sed "s/|LOCALUSERS|/$users_to_ring/g" >> $WORKDIR/inext.TMP
+ fi
+
+ # If this provider is enabled for outgoing calls.
+ if [ "$make_outgoing_calls" = "yes" ] ; then
+
+ numprefix="`uci -q get ${MODULENAME}-calls.outgoing_calls.$name`"
+ # If no prefixes are specified, then we use "X" which matches any prefix.
+ [ -z "$numprefix" ] && numprefix="X"
+ for p in $numprefix ; do
+ sed "s/|NUMPREFIX|/$p/g" $TMPL_EXTOUTSIP |\
+ sed "s/|NAME|/$name/g" >> $WORKDIR/outext-$name.TMP
+ done
+
+ # Add this provider to the list of enabled outbound providers.
+ if [ -z "$outbound_providers" ] ; then
+ outbound_providers="$name"
+ else
+ outbound_providers="$outbound_providers $name"
+ fi
+ fi
+
+ rm -f $WORKDIR/sip_peer.tmp
+ rm -f $WORKDIR/sip_reg.tmp
+}
+
+# For all local users enabled for outbound calls, creates a context
+# containing the extensions for Google and SIP accounts this user is
+# allowed to use.
+pbx_create_user_contexts()
+{
+ local providers
+
+ for u in $localusers_can_dial ; do
+ sed "s/|DEFAULTUSER|/$u/g" $TMPL_EXTUSERCNTXTHDR >> $WORKDIR/userext.TMP
+ cat $WORKDIR/localext.TMP >> $WORKDIR/userext.TMP
+ providers="`uci -q get ${MODULENAME}-calls.providers_user_can_use.$u`"
+ [ -z "$providers" ] && providers="$outbound_providers"
+
+ # For each provider, cat the contents of outext-$name.TMP into the user's outgoing calls extension
+ for p in $providers ; do
+ [ -f $WORKDIR/outext-$p.TMP ] && cat $WORKDIR/outext-$p.TMP >> $WORKDIR/userext.TMP
+ done
+ cat $TMPL_EXTUSERCNTXTFTR >> $WORKDIR/userext.TMP
+ done
+}
+
+# Creates the blacklist context which hangs up on blacklisted numbers.
+pbx_add_blacklist()
+{
+ local blacklist1
+ local blacklist2
+
+ config_get blacklist1 blacklisting blacklist1
+ config_get blacklist2 blacklisting blacklist2
+
+ # We create the blacklist context no matter whether the blacklist
+ # actually contains entries or not, since the PBX will send calls
+ # to the context for a check against the list anyway.
+ cp $TMPL_EXTBLKLISTHDR $WORKDIR/blacklist.TMP
+ for n in $blacklist1 $blacklist2 ; do
+ sed "s/|BLACKLISTITEM|/$n/g" $TMPL_EXTBLKLIST >> $WORKDIR/blacklist.TMP
+ done
+ cat $TMPL_EXTBLKLISTFTR >> $WORKDIR/blacklist.TMP
+}
+
+# Creates the callthrough context which allows specified numbers to get
+# into the PBX and dial out as the configured user.
+pbx_add_callthrough()
+{
+ local callthrough_number_list
+ local defaultuser
+ local pin
+ local enabled
+
+ config_get callthrough_number_list $1 callthrough_number_list
+ config_get defaultuser $1 defaultuser
+ config_get pin $1 pin
+ config_get enabled $1 enabled
+
+ [ "$enabled" = "no" ] && return
+ [ "$defaultuser" = "" ] && return
+
+ for callthrough_number in $callthrough_number_list ; do
+ sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRUCHECK >> $WORKDIR/callthroughcheck.TMP
+
+ sed "s/|NUMBER|/$callthrough_number/g" $TMPL_EXTCTHRU |\
+ sed "s/|DEFAULTUSER|/$defaultuser/" |\
+ sed "s/|PIN|/$pin/" >> $WORKDIR/callthrough.TMP
+ done
+}
+
+# Creates sip.conf from its template.
+pbx_cook_sip_template()
+{
+ local useragent
+ local externhost
+ local bindport
+
+ config_get useragent advanced useragent
+ config_get externhost advanced externhost
+ config_get bindport advanced bindport
+
+ [ -z "$useragent" ] && useragent="$USERAGENT"
+
+ sed "s/|USERAGENT|/$useragent/g" $TMPL_SIP > $WORKDIR/sip.conf
+
+ if [ -z "$externhost" ] ; then
+ sed -i "s/externhost=|EXTERNHOST|//g" $WORKDIR/sip.conf
+ else
+ sed -i "s/|EXTERNHOST|/$externhost/g" $WORKDIR/sip.conf
+ fi
+
+ if [ -z "$bindport" ] ; then
+ sed -i "s/bindport=|BINDPORT|//g" $WORKDIR/sip.conf
+ else
+ sed -i "s/|BINDPORT|/$bindport/g" $WORKDIR/sip.conf
+ fi
+
+
+}
+
+# Creates rtp.conf from its template.
+pbx_cook_rtp_template()
+{
+ local rtpstart
+ local rtpend
+
+ config_get rtpstart advanced rtpstart
+ config_get rtpend advanced rtpend
+
+ sed "s/|RTPSTART|/$rtpstart/" $TMPL_RTP |\
+ sed "s/|RTPEND|/$rtpend/" > $WORKDIR/rtp.conf
+}
+
+# Makes sure the ownership of specified directories is proper.
+pbx_fix_ownership()
+{
+ chown $ASTUSER:$ASTGROUP $ASTDIRS
+ chown $ASTUSER:$ASTGROUP -R $ASTDIRSRECURSIVE
+}
+
+# Creates firewall configuration. However, since this functionality is now
+# taken over by pbx-advanced.lua, this function is unused.
+create_firewall_config()
+{
+ local bindport
+ local rtpstart
+ local rtpend
+ local externhost
+
+ config_get bindport advanced bindport
+ config_get externhost advanced externhost
+ config_get rtpstart advanced rtpstart
+ config_get rtpend advanced rtpend
+
+ # We need all of these parameters to be set in order to consider inserting firewall rules.
+ if [ -z "$externhost" -o -z "$bindport" -o -z "$rtpstart" -o -z "$rtpend" ] ; then
+ rm -f $FIREWALL_PATH
+ return
+ fi
+
+ sed "s/|SIPPORT|/$bindport/g" $TMPL_FIREWALL |\
+ sed "s/|RTPRANGE|/$rtpstart:$rtpend/g" > $WORKDIR/firewall.$MODULENAME
+
+ # Make sure there is an include section in the firewall configuration
+ # to include the file we just created.
+ i=0 ; found_path=0
+ while p=`uci get firewall.@include[$i].path 2>/dev/null` ; do
+ if [ "$p" = "$FIREWALL_PATH" ] ; then
+ found_path=1
+ break
+ fi
+ i=`expr $i + 1`
+ done
+
+ # If no include section was found which mentions $FIREWALL_PATH, add one.
+ if [ $found_path -eq 0 ] ; then
+ uci add firewall include 1>/dev/null 2>/dev/null
+ uci set firewall.@include[-1].path="$FIREWALL_PATH"
+ uci commit firewall
+ fi
+}
+
+start() {
+ mkdir -p $WORKDIR
+
+ # Create the users.
+ config_load ${MODULENAME}-users
+ config_foreach pbx_add_user local_user
+
+ # Create configuration for each google account.
+ config_unset
+ config_load ${MODULENAME}-google
+ config_foreach pbx_add_jabber gtalk_jabber
+
+ # Create configuration for each voip provider.
+ config_unset
+ config_load ${MODULENAME}-voip
+ config_foreach pbx_add_peer voip_provider
+
+ # Create the user contexts, and phone blacklist.
+ config_unset
+ config_load ${MODULENAME}-calls
+ pbx_create_user_contexts
+ pbx_add_blacklist
+ config_foreach pbx_add_callthrough callthrough_numbers
+
+ # Prepare sip.conf using settings from the "advanced" section.
+ config_unset
+ config_load ${MODULENAME}-advanced
+ pbx_cook_sip_template
+ pbx_cook_rtp_template
+
+ # Assemble the configuration, and copy changed files over.
+ pbx_assemble_and_copy_config
+
+ # Enforce ownership of specified files and directories.
+ pbx_fix_ownership
+}
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE
new file mode 100644
index 000000000..ae6340af8
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/asterisk.conf.TEMPLATE
@@ -0,0 +1,17 @@
+[directories]
+astetcdir => /etc/asterisk
+astmoddir => /usr/lib/asterisk/modules
+astvarlibdir => /var/lib/asterisk
+astdbdir => /usr/lib/asterisk
+astkeydir => /var/lib/asterisk
+astdatadir => /usr/share/asterisk
+astagidir => /usr/share/asterisk/agi-bin
+astspooldir => /var/spool/asterisk
+astrundir => /var/run/asterisk
+astlogdir => /var/log/asterisk
+
+[options]
+languageprefix = yes
+dumpcore = no
+runuser = nobody
+rungroup = nogroup
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE
new file mode 100644
index 000000000..f3edac384
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions.conf.TEMPLATE
@@ -0,0 +1,30 @@
+[general]
+static = yes
+writeprotect = yes
+clearglobalvars = no
+
+[globals]
+
+[default]
+
+[context-user-hangup]
+exten => s,1,Hangup()
+exten => _X.,1,Hangup()
+
+[context-catch-all]
+exten => _[!-~].,1,Dial(SIP/${EXTEN},60,r)
+
+[default-incoming-call-context]
+exten => s,1,NoOp(${CALLERID})
+exten => s,n,Set(SOURCECONTEXT=default-incoming-call-context)
+exten => s,n,Set(SOURCEEXTEN=s)
+exten => s,n,Goto(blacklist-call-context,s,1)
+exten => s,n(doneblacklist),NoOp()
+exten => s,n,Goto(disa-check-call-context,s,1)
+exten => s,n(donedisacheck),Dial(|LOCALUSERS|,60,r)
+
+#include extensions_incoming.conf
+#include extensions_incoming_gtalk.conf
+#include extensions_blacklist.conf
+#include extensions_callthrough.conf
+#include extensions_user.conf
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE
new file mode 100644
index 000000000..54ee989b0
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => s,n,Gotoif($[ "${CALLERID(NUM)}" = "|BLACKLISTITEM|" ]?context-user-hangup,s,1)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE
new file mode 100644
index 000000000..da964f238
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_footer.conf.TEMPLATE
@@ -0,0 +1,2 @@
+exten => s,n,Goto(${SOURCECONTEXT},${SOURCEEXTEN},doneblacklist)
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE
new file mode 100644
index 000000000..de0e98465
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_blacklist_header.conf.TEMPLATE
@@ -0,0 +1,3 @@
+
+[blacklist-call-context]
+exten => s,1,Noop()
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE
new file mode 100644
index 000000000..ba2379b73
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => s,n,Gotoif($[ "${CALLERID(NUM)}" =~ ".*|NUMBER|" ]?disa-call-context,|NUMBER|,1)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE
new file mode 100644
index 000000000..74056fa01
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_footer.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => s,n,Goto(${SOURCECONTEXT},${SOURCEEXTEN},donedisacheck)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE
new file mode 100644
index 000000000..e0d67b802
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa-check_header.conf.TEMPLATE
@@ -0,0 +1,2 @@
+[disa-check-call-context]
+exten => s,1,Noop()
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE
new file mode 100644
index 000000000..e799d5210
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa.conf.TEMPLATE
@@ -0,0 +1,4 @@
+exten => |NUMBER|,1,Noop()
+exten => |NUMBER|,n,Authenticate(|PIN|)
+exten => |NUMBER|,n,DISA(no-password,context-user-|DEFAULTUSER|)
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE
new file mode 100644
index 000000000..a74227114
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_disa_header.conf.TEMPLATE
@@ -0,0 +1 @@
+[disa-call-context]
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..dc0c68add
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk.conf.TEMPLATE
@@ -0,0 +1,11 @@
+exten => |USERNAME|,1,NoOp(${CALLERID})
+same => n,Set(CALLERID(name)=${CUT(CALLERID(name),@,1)})
+same => n,GotoIf($["${CALLERID(name):0:2}" != "+1"]?notrim)
+same => n,Set(CALLERID(name)=${CALLERID(name):2})
+same => n(notrim),Set(CALLERID(number)=${CALLERID(name)})
+same => n,Set(SOURCECONTEXT=context-incoming-gtalk)
+same => n,Set(SOURCEEXTEN=|USERNAME|)
+same => n,Goto(blacklist-call-context,s,1)
+same => n(doneblacklist),NoOp()
+same => n,Goto(disa-check-call-context,s,1)
+same => n(donedisacheck),Dial(|LOCALUSERS|,60,D(:w11111111))
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE
new file mode 100644
index 000000000..f6e44a5bf
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_gtalk_header.conf.TEMPLATE
@@ -0,0 +1 @@
+[context-incoming-gtalk]
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE
new file mode 100644
index 000000000..12ecefc80
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_incoming_context_sip.conf.TEMPLATE
@@ -0,0 +1,9 @@
+
+[context-incoming-|NAME|]
+exten => s,1,NoOp(${CALLERID})
+exten => s,n,Set(SOURCECONTEXT=context-incoming-|NAME|)
+exten => s,n,Set(SOURCEEXTEN=s)
+exten => s,n,Goto(blacklist-call-context,s,1)
+exten => s,n(doneblacklist),NoOp()
+exten => s,n,Goto(disa-check-call-context,s,1)
+exten => s,n(donedisacheck),Dial(|LOCALUSERS|,60,r)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE
new file mode 100644
index 000000000..a7f36cf91
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_context_header.conf.TEMPLATE
@@ -0,0 +1,2 @@
+
+[context-outgoing-|NAME|]
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE
new file mode 100644
index 000000000..b81da9eab
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_dial_local_user.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => |DEFAULTUSER|,1,Dial(SIP/|DEFAULTUSER|,60,r)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..259c2ceaa
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_gtalk.conf.TEMPLATE
@@ -0,0 +1,9 @@
+exten => _|NUMPREFIX|,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN}@voice.google.com,60)
+exten => _+|NUMPREFIX|,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:1}@voice.google.com,60)
+exten => _|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN}@voice.google.com,60)
+exten => _+|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:1}@voice.google.com,60)
+exten => _00|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:2}@voice.google.com,60)
+exten => _011|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:3}@voice.google.com,60)
+exten => _010|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:3}@voice.google.com,60)
+exten => _0011|NUMPREFIX|.,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN:4}@voice.google.com,60)
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..1fa7713e2
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_gtalk.conf.TEMPLATE
@@ -0,0 +1,2 @@
+exten => |PATTERN|,1,Dial(Gtalk/gtalk-|NAME|/${EXTEN|SYMBOLSTOREMOVE|}@voice.google.com,60)
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE
new file mode 100644
index 000000000..178b6deaa
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_pattern_sip.conf.TEMPLATE
@@ -0,0 +1 @@
+exten => |PATTERN|,1,Dial(SIP/${EXTEN|SYMBOLSTOREMOVE|}@peer-|NAME|,60,r)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE
new file mode 100644
index 000000000..9b1d9addc
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_outgoing_sip.conf.TEMPLATE
@@ -0,0 +1,8 @@
+exten => _|NUMPREFIX|,1,Dial(SIP/${EXTEN}@peer-|NAME|,60,r)
+exten => _+|NUMPREFIX|,1,Dial(SIP/${EXTEN}@peer-|NAME|,60,r)
+exten => _|NUMPREFIX|.,1,Dial(SIP/${EXTEN}@peer-|NAME|,60,r)
+exten => _+|NUMPREFIX|.,1,Dial(SIP/${EXTEN:1}@peer-|NAME|,60,r)
+exten => _00|NUMPREFIX|.,1,Dial(SIP/${EXTEN:2}@peer-|NAME|,60,r)
+exten => _011|NUMPREFIX|.,1,Dial(SIP/${EXTEN:3}@peer-|NAME|,60,r)
+exten => _010|NUMPREFIX|.,1,Dial(SIP/${EXTEN:3}@peer-|NAME|,60,r)
+exten => _0011|NUMPREFIX|.,1,Dial(SIP/${EXTEN:4}@peer-|NAME|,60,r)
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE
new file mode 100644
index 000000000..7ce1060dc
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_footer.conf.TEMPLATE
@@ -0,0 +1 @@
+include => context-catch-all
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE
new file mode 100644
index 000000000..5931eaf28
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/extensions_user_context_header.conf.TEMPLATE
@@ -0,0 +1,3 @@
+
+[context-user-|DEFAULTUSER|]
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE
new file mode 100644
index 000000000..91e9f66d8
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/firewall.home-pbx.TEMPLATE
@@ -0,0 +1,2 @@
+iptables -I INPUT 3 -p udp -s 0/0 -d 0/0 --dport |SIPPORT| -j ACCEPT
+iptables -I INPUT 3 -p udp -s 0/0 -d 0/0 --dport |RTPRANGE| -j ACCEPT
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE
new file mode 100644
index 000000000..4f07a7166
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/gtalk.conf.TEMPLATE
@@ -0,0 +1,10 @@
+[general]
+context=context-incoming-gtalk
+allowguest=yes
+allowguests=yes
+bindaddr=0.0.0.0
+
+[guest]
+disallow=all
+allow=ulaw
+context=context-incoming-gtalk
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE
new file mode 100644
index 000000000..d7088db7c
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/indications.conf.TEMPLATE
@@ -0,0 +1,733 @@
+; indications.conf
+; Configuration file for location specific tone indications
+; used by the pbx_indications module.
+;
+; NOTE:
+; When adding countries to this file, please keep them in alphabetical
+; order according to the 2-character country codes!
+;
+; The [general] category is for certain global variables.
+; All other categories are interpreted as location specific indications
+;
+;
+[general]
+country=us ; default location
+
+
+; [example]
+; description = string
+; The full name of your country, in English.
+; alias = iso[,iso]*
+; List of other countries 2-letter iso codes, which have the same
+; tone indications.
+; ringcadence = num[,num]*
+; List of durations the physical bell rings.
+; dial = tonelist
+; Set of tones to be played when one picks up the hook.
+; busy = tonelist
+; Set of tones played when the receiving end is busy.
+; congestion = tonelist
+; Set of tones played when there is some congestion (on the network?)
+; callwaiting = tonelist
+; Set of tones played when there is a call waiting in the background.
+; dialrecall = tonelist
+; Not well defined; many phone systems play a recall dial tone after hook
+; flash.
+; record = tonelist
+; Set of tones played when call recording is in progress.
+; info = tonelist
+; Set of tones played with special information messages (e.g., "number is
+; out of service")
+; 'name' = tonelist
+; Every other variable will be available as a shortcut for the "PlayList" command
+; but will not be used automatically by Asterisk.
+;
+;
+; The tonelist itself is defined by a comma-separated sequence of elements.
+; Each element consist of a frequency (f) with an optional duration (in ms)
+; attached to it (f/duration). The frequency component may be a mixture of two
+; frequencies (f1+f2) or a frequency modulated by another frequency (f1*f2).
+; The implicit modulation depth is fixed at 90%, though.
+; If the list element starts with a !, that element is NOT repeated,
+; therefore, only if all elements start with !, the tonelist is time-limited,
+; all others will repeat indefinitely.
+;
+; concisely:
+; element = [!]freq[+|*freq2][/duration]
+; tonelist = element[,element]*
+;
+; Please note that SPACES ARE NOT ALLOWED in tone lists!
+;
+
+[at]
+description = Austria
+ringcadence = 1000,5000
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+dial = 420
+busy = 420/400,0/400
+ring = 420/1000,0/5000
+congestion = 420/200,0/200
+callwaiting = 420/40,0/1960
+dialrecall = 420
+; RECORDTONE - not specified
+record = 1400/80,0/14920
+info = 950/330,1450/330,1850/330,0/1000
+stutter = 380+420
+
+[au]
+description = Australia
+; Reference http://www.acif.org.au/__data/page/3303/S002_2001.pdf
+; Normal Ring
+ringcadence = 400,200,400,2000
+; Distinctive Ring 1 - Forwarded Calls
+; 400,400,200,200,400,1400
+; Distinctive Ring 2 - Selective Ring 2 + Operator + Recall
+; 400,400,200,2000
+; Distinctive Ring 3 - Multiple Subscriber Number 1
+; 200,200,400,2200
+; Distinctive Ring 4 - Selective Ring 1 + Centrex
+; 400,2600
+; Distinctive Ring 5 - Selective Ring 3
+; 400,400,200,400,200,1400
+; Distinctive Ring 6 - Multiple Subscriber Number 2
+; 200,400,200,200,400,1600
+; Distinctive Ring 7 - Multiple Subscriber Number 3 + Data Privacy
+; 200,400,200,400,200,1600
+; Tones
+dial = 413+438
+busy = 425/375,0/375
+ring = 413+438/400,0/200,413+438/400,0/2000
+; XXX Congestion: Should reduce by 10 db every other cadence XXX
+congestion = 425/375,0/375,420/375,0/375
+callwaiting = 425/200,0/200,425/200,0/4400
+dialrecall = 413+438
+; Record tone used for Call Intrusion/Recording or Conference
+record = !425/1000,!0/15000,425/360,0/15000
+info = 425/2500,0/500
+; Other Australian Tones
+; The STD "pips" indicate the call is not an untimed local call
+std = !525/100,!0/100,!525/100,!0/100,!525/100,!0/100,!525/100,!0/100,!525/100
+; Facility confirmation tone (eg. Call Forward Activated)
+facility = 425
+; Message Waiting "stutter" dialtone
+stutter = 413+438/100,0/40
+; Ringtone for calls to Telstra mobiles
+ringmobile = 400+450/400,0/200,400+450/400,0/2000
+
+[bg]
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+description = Bulgaria
+ringcadence = 1000,4000
+;
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 425/150,0/150,425/150,0/4000
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+record = 1400/425,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425/1500,0/100
+
+[br]
+description = Brazil
+ringcadence = 1000,4000
+dial = 425
+busy = 425/250,0/250
+ring = 425/1000,0/4000
+congestion = 425/250,0/250,425/750,0/250
+callwaiting = 425/50,0/1000
+; Dialrecall not used in Brazil standard (using UK standard)
+dialrecall = 350+440
+; Record tone is not used in Brazil, use busy tone
+record = 425/250,0/250
+; Info not used in Brazil standard (using UK standard)
+info = 950/330,1400/330,1800/330
+stutter = 350+440
+
+[be]
+description = Belgium
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,3000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/3000
+congestion = 425/167,0/167
+callwaiting = 1400/175,0/175,1400/175,0/3500
+; DIALRECALL - not specified
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440"
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = 900/330,1400/330,1800/330,0/1000
+stutter = 425/1000,0/250
+
+[ch]
+description = Switzerland
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/200,0/200,425/200,0/4000
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; RECORDTONE - not specified
+record = 1400/80,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425+340/1100,0/1100
+
+[cl]
+description = Chile
+; According to specs from Telefonica CTC Chile
+ringcadence = 1000,3000
+dial = 400
+busy = 400/500,0/500
+ring = 400/1000,0/3000
+congestion = 400/200,0/200
+callwaiting = 400/250,0/8750
+dialrecall = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
+record = 1400/500,0/15000
+info = 950/333,1400/333,1800/333,0/1000
+stutter = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
+
+[cn]
+description = China
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 450
+busy = 450/350,0/350
+ring = 450/1000,0/4000
+congestion = 450/700,0/700
+callwaiting = 450/400,0/4000
+dialrecall = 450
+record = 950/400,0/10000
+info = 450/100,0/100,450/100,0/100,450/100,0/100,450/400,0/400
+; STUTTER - not specified
+stutter = 450+425
+
+[cz]
+description = Czech Republic
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425/330,0/330,425/660,0/660
+busy = 425/330,0/330
+ring = 425/1000,0/4000
+congestion = 425/165,0/165
+callwaiting = 425/330,0/9000
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425/330,0/330,425/660,0/660
+; RECORDTONE - not specified
+record = 1400/500,0/14000
+info = 950/330,0/30,1400/330,0/30,1800/330,0/1000
+; STUTTER - not specified
+stutter = 425/450,0/50
+
+[de]
+description = Germany
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/480,0/480
+ring = 425/1000,0/4000
+congestion = 425/240,0/240
+callwaiting = !425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,!0/5000,!425/200,!0/200,!425/200,0
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; RECORDTONE - not specified
+record = 1400/80,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425+400
+
+[dk]
+description = Denmark
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = !425/200,!0/600,!425/200,!0/3000,!425/200,!0/200,!425/200,0
+; DIALRECALL - not specified
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; RECORDTONE - not specified
+record = 1400/80,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+; STUTTER - not specified
+stutter = 425/450,0/50
+
+[ee]
+description = Estonia
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425
+busy = 425/300,0/300
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+; CALLWAIT not in accordance to ITU
+callwaiting = 950/650,0/325,950/325,0/30,1400/1300,0/2600
+; DIALRECALL - not specified
+dialrecall = 425/650,0/25
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; INFO not in accordance to ITU
+info = 950/650,0/325,950/325,0/30,1400/1300,0/2600
+; STUTTER not specified
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[es]
+description = Spain
+ringcadence = 1500,3000
+dial = 425
+busy = 425/200,0/200
+ring = 425/1500,0/3000
+congestion = 425/200,0/200,425/200,0/200,425/200,0/600
+callwaiting = 425/175,0/175,425/175,0/3500
+dialrecall = !425/200,!0/200,!425/200,!0/200,!425/200,!0/200,425
+record = 1400/500,0/15000
+info = 950/330,0/1000
+dialout = 500
+
+
+[fi]
+description = Finland
+ringcadence = 1000,4000
+dial = 425
+busy = 425/300,0/300
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/150,0/150,425/150,0/8000
+dialrecall = 425/650,0/25
+record = 1400/500,0/15000
+info = 950/650,0/325,950/325,0/30,1400/1300,0/2600
+stutter = 425/650,0/25
+
+[fr]
+description = France
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1500,3500
+; Dialtone can also be 440+330
+dial = 440
+busy = 440/500,0/500
+ring = 440/1500,0/3500
+; CONGESTION - not specified
+congestion = 440/250,0/250
+callwait = 440/300,0/10000
+; DIALRECALL - not specified
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330
+stutter = !440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,!440/100,!0/100,440
+
+[gr]
+description = Greece
+ringcadence = 1000,4000
+dial = 425/200,0/300,425/700,0/800
+busy = 425/300,0/300
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/150,0/150,425/150,0/8000
+dialrecall = 425/650,0/25
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 425/650,0/25
+
+[hu]
+description = Hungary
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1250,3750
+dial = 425
+busy = 425/300,0/300
+ring = 425/1250,0/3750
+congestion = 425/300,0/300
+callwaiting = 425/40,0/1960
+dialrecall = 425+450
+; RECORDTONE - not specified
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 350+375+400
+
+[il]
+description = Israel
+ringcadence = 1000,3000
+dial = 414
+busy = 414/500,0/500
+ring = 414/1000,0/3000
+congestion = 414/250,0/250
+callwaiting = 414/100,0/100,414/100,0/100,414/600,0/3000
+dialrecall = !414/100,!0/100,!414/100,!0/100,!414/100,!0/100,414
+record = 1400/500,0/15000
+info = 1000/330,1400/330,1800/330,0/1000
+stutter = !414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,!414/160,!0/160,414
+
+
+[in]
+description = India
+ringcadence = 400,200,400,2000
+dial = 400*25
+busy = 400/750,0/750
+ring = 400*25/400,0/200,400*25/400,0/2000
+congestion = 400/250,0/250
+callwaiting = 400/200,0/100,400/200,0/7500
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0/1000
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[it]
+description = Italy
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+dial = 425/200,0/200,425/600,0/1000
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/400,0/100,425/250,0/100,425/150,0/14000
+dialrecall = 470/400,425/400
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 470/400,425/400
+
+[lt]
+description = Lithuania
+ringcadence = 1000,4000
+dial = 425
+busy = 425/350,0/350
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/150,0/150,425/150,0/4000
+; DIALRECALL - not specified
+dialrecall = 425/500,0/50
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+; STUTTER - not specified
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[jp]
+description = Japan
+ringcadence = 1000,2000
+dial = 400
+busy = 400/500,0/500
+ring = 400+15/1000,0/2000
+congestion = 400/500,0/500
+callwaiting = 400+16/500,0/8000
+dialrecall = !400/200,!0/200,!400/200,!0/200,!400/200,!0/200,400
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,!400/100,!0/100,400
+
+[mx]
+description = Mexico
+ringcadence = 2000,4000
+dial = 425
+busy = 425/250,0/250
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 425/200,0/600,425/200,0/10000
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+record = 1400/500,0/15000
+info = 950/330,0/30,1400/330,0/30,1800/330,0/1000
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[my]
+description = Malaysia
+ringcadence = 2000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/400,0/200
+congestion = 425/500,0/500
+
+[nl]
+description = Netherlands
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+ringcadence = 1000,4000
+; Most of these 425's can also be 450's
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 425/500,0/9500
+; DIALRECALL - not specified
+dialrecall = 425/500,0/50
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = 425/500,0/50
+
+[no]
+description = Norway
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/200,0/200
+callwaiting = 425/200,0/600,425/200,0/10000
+dialrecall = 470/400,425/400
+record = 1400/400,0/15000
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,0
+stutter = 470/400,425/400
+
+[nz]
+description = New Zealand
+;NOTE - the ITU has different tonesets for NZ, but according to some residents there,
+; this is, indeed, the correct way to do it.
+ringcadence = 400,200,400,2000
+dial = 400
+busy = 400/250,0/250
+ring = 400+450/400,0/200,400+450/400,0/2000
+congestion = 400/375,0/375
+callwaiting = !400/200,!0/3000,!400/200,!0/3000,!400/200,!0/3000,!400/200
+dialrecall = !400/100!0/100,!400/100,!0/100,!400/100,!0/100,400
+record = 1400/425,0/15000
+info = 400/750,0/100,400/750,0/100,400/750,0/100,400/750,0/400
+stutter = !400/100!0/100,!400/100,!0/100,!400/100,!0/100,!400/100!0/100,!400/100,!0/100,!400/100,!0/100,400
+unobtainable = 400/75,0/100,400/75,0/100,400/75,0/100,400/75,0/400
+
+[ph]
+
+; reference http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+
+description = Philippines
+ringcadence = 1000,4000
+dial = 425
+busy = 480+620/500,0/500
+ring = 425+480/1000,0/4000
+congestion = 480+620/250,0/250
+callwaiting = 440/300,0/10000
+; DIALRECALL - not specified
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; INFO - not specified
+info = !950/330,!1400/330,!1800/330,0
+; STUTTER - not specified
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+
+[pl]
+description = Poland
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/500,0/500
+callwaiting = 425/150,0/150,425/150,0/4000
+; DIALRECALL - not specified
+dialrecall = 425/500,0/50
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; 950/1400/1800 3x0.33 on 1.0 off repeated 3 times
+info = !950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000,!950/330,!1400/330,!1800/330,!0/1000
+; STUTTER - not specified
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[pt]
+description = Portugal
+ringcadence = 1000,5000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/5000
+congestion = 425/200,0/200
+callwaiting = 440/300,0/10000
+dialrecall = 425/1000,0/200
+record = 1400/500,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[ru]
+; References:
+; http://www.minsvyaz.ru/site.shtml?id=1806
+; http://www.aboutphone.info/lib/gost/45-223-2001.html
+description = Russian Federation / ex Soviet Union
+ringcadence = 1000,4000
+dial = 425
+busy = 425/350,0/350
+ring = 425/1000,0/4000
+congestion = 425/175,0/175
+callwaiting = 425/200,0/5000
+record = 1400/400,0/15000
+info = 950/330,1400/330,1800/330,0/1000
+dialrecall = 425/400,0/40
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+
+[se]
+description = Sweden
+ringcadence = 1000,5000
+dial = 425
+busy = 425/250,0/250
+ring = 425/1000,0/5000
+congestion = 425/250,0/750
+callwaiting = 425/200,0/500,425/200,0/9100
+dialrecall = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+record = 1400/500,0/15000
+info = !950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,!0/2024,!950/332,!0/24,!1400/332,!0/24,!1800/332,0
+stutter = !425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,!425/100,!0/100,425
+; stutter = 425/320,0/20 ; Real swedish standard, not used for now
+
+[sg]
+description = Singapore
+; Singapore
+; Reference: http://www.ida.gov.sg/idaweb/doc/download/I397/ida_ts_pstn1_i4r2.pdf
+; Frequency specs are: 425 Hz +/- 20Hz; 24 Hz +/- 2Hz; modulation depth 100%; SIT +/- 50Hz
+ringcadence = 400,200,400,2000
+dial = 425
+ring = 425*24/400,0/200,425*24/400,0/2000 ; modulation should be 100%, not 90%
+busy = 425/750,0/750
+congestion = 425/250,0/250
+callwaiting = 425*24/300,0/200,425*24/300,0/3200
+stutter = !425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,!425/200,!0/200,!425/600,!0/200,425
+info = 950/330,1400/330,1800/330,0/1000 ; not currently in use acc. to reference
+dialrecall = 425*24/500,0/500,425/500,0/2500 ; unspecified in IDA reference, use repeating Holding Tone A,B
+record = 1400/500,0/15000 ; unspecified in IDA reference, use 0.5s tone every 15s
+; additionally defined in reference
+nutone = 425/2500,0/500
+intrusion = 425/250,0/2000
+warning = 425/624,0/4376 ; end of period tone, warning
+acceptance = 425/125,0/125
+holdinga = !425*24/500,!0/500 ; followed by holdingb
+holdingb = !425/500,!0/2500
+
+[th]
+description = Thailand
+ringcadence = 1000,4000
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+dial = 400*50
+busy = 400/500,0/500
+ring = 420/1000,0/5000
+congestion = 400/300,0/300
+callwaiting = 1000/400,10000/400,1000/400
+; DIALRECALL - not specified - use special dial tone instead.
+dialrecall = 400*50/400,0/100,400*50/400,0/100
+; RECORDTONE - not specified
+record = 1400/500,0/15000
+; INFO - specified as an announcement - use special information tones instead
+info = 950/330,1400/330,1800/330
+; STUTTER - not specified
+stutter = !400/200,!0/200,!400/600,!0/200,!400/200,!0/200,!400/600,!0/200,!400/200,!0/200,!400/600,!0/200,!400/200,!0/200,!400/600,!0/200,400
+
+[uk]
+description = United Kingdom
+ringcadence = 400,200,400,2000
+; These are the official tones taken from BT SIN350. The actual tones
+; used by BT include some volume differences so sound slightly different
+; from Asterisk-generated ones.
+dial = 350+440
+; Special dial is the intermittent dial tone heard when, for example,
+; you have a divert active on the line
+specialdial = 350+440/750,440/750
+; Busy is also called "Engaged"
+busy = 400/375,0/375
+; "Congestion" is the Beep-bip engaged tone
+congestion = 400/400,0/350,400/225,0/525
+; "Special Congestion" is not used by BT very often if at all
+specialcongestion = 400/200,1004/300
+unobtainable = 400
+ring = 400+450/400,0/200,400+450/400,0/2000
+callwaiting = 400/100,0/4000
+; BT seem to use "Special Call Waiting" rather than just "Call Waiting" tones
+specialcallwaiting = 400/250,0/250,400/250,0/250,400/250,0/5000
+; "Pips" used by BT on payphones. (Sounds wrong, but this is what BT claim it
+; is and I've not used a payphone for years)
+creditexpired = 400/125,0/125
+; These two are used to confirm/reject service requests on exchanges that
+; don't do voice announcements.
+confirm = 1400
+switching = 400/200,0/400,400/2000,0/400
+; This is the three rising tones Doo-dah-dee "Special Information Tone",
+; usually followed by the BT woman saying an appropriate message.
+info = 950/330,0/15,1400/330,0/15,1800/330,0/1000
+; Not listed in SIN350
+record = 1400/500,0/60000
+stutter = 350+440/750,440/750
+
+[us]
+description = United States / North America
+ringcadence = 2000,4000
+dial = 350+440
+busy = 480+620/500,0/500
+ring = 440+480/2000,0/4000
+congestion = 480+620/250,0/250
+callwaiting = 440/300,0/10000
+dialrecall = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[us-old]
+description = United States Circa 1950/ North America
+ringcadence = 2000,4000
+dial = 600*120
+busy = 500*100/500,0/500
+ring = 420*40/2000,0/4000
+congestion = 500*100/250,0/250
+callwaiting = 440/300,0/10000
+dialrecall = !600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,!600*120/100,!0/100,600*120
+
+[tw]
+description = Taiwan
+; http://nemesis.lonestar.org/reference/telecom/signaling/dialtone.html
+; http://nemesis.lonestar.org/reference/telecom/signaling/busy.html
+; http://www.iproducts.com.tw/ee/kylink/06ky-1000a.htm
+; http://www.pbx-manufacturer.com/ky120dx.htm
+; http://www.nettwerked.net/tones.txt
+; http://www.cisco.com/univercd/cc/td/doc/product/tel_pswt/vco_prod/taiw_sup/taiw2.htm
+;
+; busy tone 480+620Hz 0.5 sec. on ,0.5 sec. off
+; reorder tone 480+620Hz 0.25 sec. on,0.25 sec. off
+; ringing tone 440+480Hz 1 sec. on ,2 sec. off
+;
+ringcadence = 1000,4000
+dial = 350+440
+busy = 480+620/500,0/500
+ring = 440+480/1000,0/2000
+congestion = 480+620/250,0/250
+callwaiting = 350+440/250,0/250,350+440/250,0/3250
+dialrecall = 300/1500,0/500
+record = 1400/500,0/15000
+info = !950/330,!1400/330,!1800/330,0
+stutter = !350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,!350+440/100,!0/100,350+440
+
+[ve]
+; Tone definition source for ve found on
+; Reference: http://www.itu.int/ITU-T/inr/forms/files/tones-0203.pdf
+description = Venezuela / South America
+ringcadence = 1000,4000
+dial = 425
+busy = 425/500,0/500
+ring = 425/1000,0/4000
+congestion = 425/250,0/250
+callwaiting = 400+450/300,0/6000
+dialrecall = 425
+record = 1400/500,0/15000
+info = !950/330,!1440/330,!1800/330,0/1000
+
+
+[za]
+description = South Africa
+; http://www.cisco.com/univercd/cc/td/doc/product/tel_pswt/vco_prod/safr_sup/saf02.htm
+; (definitions for other countries can also be found there)
+; Note, though, that South Africa uses two switch types in their network --
+; Alcatel switches -- mainly in the Western Cape, and Siemens elsewhere.
+; The former use 383+417 in dial, ringback etc. The latter use 400*33
+; I've provided both, uncomment the ones you prefer
+ringcadence = 400,200,400,2000
+; dial/ring/callwaiting for the Siemens switches:
+dial = 400*33
+ring = 400*33/400,0/200,400*33/400,0/2000
+callwaiting = 400*33/250,0/250,400*33/250,0/250,400*33/250,0/250,400*33/250,0/250
+; dial/ring/callwaiting for the Alcatel switches:
+; dial = 383+417
+; ring = 383+417/400,0/200,383+417/400,0/2000
+; callwaiting = 383+417/250,0/250,383+417/250,0/250,383+417/250,0/250,383+417/250,0/250
+congestion = 400/250,0/250
+busy = 400/500,0/500
+dialrecall = 350+440
+; XXX Not sure about the RECORDTONE
+record = 1400/500,0/10000
+info = 950/330,1400/330,1800/330,0/330
+stutter = !400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,!400*33/100,!0/100,400*33
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE
new file mode 100644
index 000000000..cf71e1f8f
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/jabber.conf.TEMPLATE
@@ -0,0 +1,4 @@
+[general]
+autoregister=yes
+
+#include jabber_users.conf
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE
new file mode 100644
index 000000000..3ee2463ed
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/jabber_users.conf.TEMPLATE
@@ -0,0 +1,8 @@
+[gtalk-|NAME|]
+type=client
+serverhost=talk.google.com
+username=|USERNAME|/Talk
+secret=|SECRET|
+timeout=150
+status=|STATUS|
+statusmessage=|STATUSMESSAGE|
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE
new file mode 100644
index 000000000..e57325013
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/logger.conf.TEMPLATE
@@ -0,0 +1,7 @@
+[general]
+queue_log = no
+event_log = no
+
+[logfiles]
+console => notice,warning,error
+messages => error
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE
new file mode 100644
index 000000000..2ac2f0033
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/manager.conf.TEMPLATE
@@ -0,0 +1,7 @@
+[general]
+enabled = no
+
+port = 5038
+bindaddr = 0.0.0.0
+
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE
new file mode 100644
index 000000000..3594dad43
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/modules.conf.TEMPLATE
@@ -0,0 +1,31 @@
+[modules]
+autoload=no
+load => res_jabber.so ; Used for Gtalk
+load => res_clioriginate.so ; originate calls from commandline
+load => res_rtp_asterisk.so ; rtp "engine" is now a loadable module in asterisk 1.8
+load => pbx_config.so ; Text Extension Configuration Requires N/A
+load => func_callerid.so ; Gets or sets Caller*ID data on the channel. - Requires ?
+load => func_channel.so
+load => func_logic.so ; Logic functions (if, etc.)
+load => func_strings.so ; string manipulation functions
+load => cdr_manager.so ; Asterisk Call Manager CDR Backend - Requires N/A
+load => chan_local.so ; Show status of local channels- Requires N/A
+load => chan_gtalk.so ; Use gtalk
+load => chan_sip.so ; Session Initiation Protocol (SIP) - Requires res_features.so
+load => codec_alaw.so ; A-law Coder/Decoder - Requires N/A
+load => codec_a_mu.so ; A-law and Mulaw direct Coder/Decoder - Requires N/A
+load => codec_gsm.so ; GSM/PCM16 (signed linear) Codec Translat - Requires N/A
+load => codec_ulaw.so ; Mu-law Coder/Decoder - Requires N/A
+load => format_gsm.so ; Raw GSM data - Requires N/A
+load => format_pcm.so ; Raw uLaw 8khz Audio support (PCM) - Requires N/A
+load => app_dial.so ; Dialing Application - Requires res_features.so, res_musiconhold.so
+load => app_parkandannounce.so ; Call Parking and Announce Application - Requires res_features.so
+load => app_playback.so ; Sound File Playback Application - Requires N/A
+load => app_system.so ; Execute a system command - Requires N/A
+load => app_disa.so ; Direct Inward System Access
+load => app_authenticate.so ; Authenticate via pin
+load => app_senddtmf.so ; Ability to send DTMF tones on the line.
+load => func_cut.so ; To manipulate strings
+
+[global]
+chan_modem.so=no
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE
new file mode 100644
index 000000000..10d577d3a
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/rtp.conf.TEMPLATE
@@ -0,0 +1,6 @@
+[general]
+rtpstart=|RTPSTART|
+rtpend=|RTPEND|
+rtpchecksums=no
+dtmftimeout=3000
+rtcpinterval = 2000
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE
new file mode 100644
index 000000000..6069554e0
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/sip.conf.TEMPLATE
@@ -0,0 +1,37 @@
+[general]
+context=default-incoming-call-context
+allowoverlap=yes
+allowtransfer=yes
+realm=asterisk
+bindaddr=0.0.0.0
+srvlookup=yes
+maxexpiry=600
+minexpiry=60
+defaultexpiry=300
+qualifyfreq=55
+disallow=all
+allow=ulaw
+allow=alaw
+dtmfmode = inband
+alwaysauthreject = yes
+t1min=100
+timert1=500
+timerb=16000
+rtptimeout=600
+rtpkeepalive=30
+useragent=|USERAGENT|
+localnet=192.168.0.0/16
+localnet=10.0.0.0/8
+localnet=172.16.0.0/12
+nat=yes
+directmedia=no
+sipdebug=no
+bindport=|BINDPORT|
+externhost=|EXTERNHOST|
+
+#include sip_registrations.conf
+
+[authentication]
+
+#include sip_peers.conf
+#include sip_users.conf
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE
new file mode 100644
index 000000000..30abaadd5
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/sip_peer.TEMPLATE
@@ -0,0 +1,13 @@
+
+[peer-|NAME|]
+type = peer
+defaultuser = |DEFAULTUSER|
+fromuser = |FROMUSER|
+secret = |SECRET|
+host = |HOST|
+fromdomain = |FROMDOMAIN|
+context = context-incoming-|NAME|
+insecure = port,invite
+qualify = 2000
+|PORT|
+|OUTBOUNDPROXY|
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE
new file mode 100644
index 000000000..e139d43f0
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/sip_registration.TEMPLATE
@@ -0,0 +1,2 @@
+register => |DEFAULTUSER|:|SECRET|@peer-|NAME|
+
diff --git a/applications/luci-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE b/applications/luci-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE
new file mode 100644
index 000000000..61a8b0b86
--- /dev/null
+++ b/applications/luci-pbx/root/etc/pbx-asterisk/sip_user.TEMPLATE
@@ -0,0 +1,11 @@
+
+[|DEFAULTUSER|]
+fullname = |FULLNAME|
+defaultuser = |DEFAULTUSER|
+secret = |SECRET|
+hassip = yes
+hasvoicemail = no
+host = dynamic
+type = friend
+context = context-user-|CONTEXTNAME|
+qualify = no \ No newline at end of file