Commit c3aa122f348aed93d19155f7281782f7e46488c9

Authored by Péter Szládovics
0 parents

First public release

Too many changes to show.

To preserve performance only 18 of 86 files are displayed.

INSTALL.md 0 → 100644
  1 +++ a/INSTALL.md
  1 +# SMBind-ng Installation Guide
  2 +
  3 +## Requirements
  4 + * Any kind of webserver with php usage abilities (tested on apache2, lighttpd,
  5 + nginx)
  6 + * php interpreter (5.3 or greater - tested on 5.3)
  7 + * php modules
  8 + * one of mysql, pgsql
  9 + * mdb2
  10 + * mdb2 sql drivers (tested on mysql)
  11 + * cgi
  12 + * smarty (version 2 or newer - tested on v2 and v3)
  13 + * bind (9.3 or newer for dnssec abilities)
  14 + * dnssec-tools (optional for securing dns zones)
  15 + * acl (optional for securing dns zones)
  16 + * SQL server (tested on MySQL)
  17 +
  18 +## Installation
  19 +
  20 +### Bind
  21 +Set up your bind, and configure it to access other masters and enable zone
  22 +transfer for its slaves.
  23 +
  24 +### SMBind-ng PHP code
  25 +Unpack contents to somewhere on your server (eg. /var/www/html/smbind-ng) and
  26 +setup your virtual server to access by default the *index.php*.
  27 +
  28 +Create the following directories beside the *index.php* and make it writable by
  29 +current webserver user:
  30 + *tmp*
  31 + *templates_c*
  32 +
  33 +All other directories and files can be write protected.
  34 +
  35 +### Configuration directories and files
  36 +1. Create a subdirectory with full permission to user of your webserver for
  37 +keeping your zones. You need to make it readable for bind. eg.
  38 + */etc/smbind-ng*
  39 + Recommended solution: owner of directory let the root user and bind group,
  40 +webserver user let the member of the bind group, and the directory let writable
  41 +by owned group.
  42 +2. Create a file with same permissions in this directory for saving zone
  43 +definitions - eg.
  44 + *touch smbind-ng.conf.*
  45 +3. Create a subdirectory for keeping zone files with same permissions at the
  46 +step 1.
  47 +
  48 +### Modify bind configuration
  49 +On your bind options set this folder to use with *directory* option and
  50 +*managed-keys* option (folder created at the step 3 above).
  51 +Include the master and slave configuration files into your bind config - what
  52 +created at the step 2.
  53 +
  54 +Restart your bind daemon.
  55 +
  56 +### Database
  57 +Create a database user with full permission to access a non existing database
  58 +with any name.
  59 +Log in your database server with that user, and create an empty database.
  60 +Take the initial database dump, and load it to this schema with this newly
  61 +created user.
  62 +*mysql.sql* is for MySQL, *pgsql.sql* is for PostrgeSQL eg. for MySQL:
  63 + *mysql -h yourserver -u youruser -pYourP@ssW0rd yourdb <mysql.sql*
  64 +
  65 +### Setup the PHP app
  66 +See configuration parameters below
  67 +
  68 +### DNSSEC related options
  69 +
  70 +#### Bind options
  71 +In your bind configuration set the following options:
  72 +
  73 +*dnssec-enable yes;*
  74 +*dnssec-validation auto;*
  75 +*dnssec-lookaside auto;*
  76 +
  77 +And then restart your bind daemon.
  78 +
  79 +#### Roller daemon
  80 +Create a directory for keeping file of roller daemon, and add write permissions
  81 +for the webserver user group. eg.
  82 +
  83 +*setfacl -b /etc/rollrecdir*
  84 +*setfacl -m 'www-data:rwx' /etc/rollrecdir*
  85 +
  86 +Set up this directory for roller daemon to use this directory for rolling zones.
  87 +eg. in your /etc/default/rollerd file use similar option with this:
  88 +
  89 +*DAEMON_OPTS="-rrfile /etc/smbind-ng/rollrec/zones.rollrec"*
  90 +
  91 +And then reload your roller daemon.
  92 +
  93 +## Configuration parameters
  94 +The application has a *config.php* file in the *config* directory of the root
  95 +of your SMBind-ng webapp directory.
  96 +
  97 +Format: $_CONF['variablename'] = value;
  98 +
  99 +Variables (mark **bold** for the required parameters):
  100 +
  101 +**db_type** - Type of the database (eg. 'mysql')
  102 +**db_user** - Name of the owner of database schema (eg. 'smbind')
  103 +**db_pass** - Password of the user above
  104 +db_host - Resolvable name or IP address of the database host (default:
  105 +'localhost')
  106 +db_port - Port number of the database server (default: 3306 or 5432 depends on
  107 +db_type)
  108 +**db_db** - Name of the database schema
  109 +**smarty_path** - Place of the smarty installation
  110 +**peardb_path** - place of your PEAR db
  111 +tmp_path - Path of your tmp directory (default: install path/tmp)
  112 +roller_conf - Path of your roller daemon config (configured in DAEMON_OPTS).
  113 +Required for DNSSEC abilities.
  114 +isdnssec - enable or disable DNSSEC abilities (true/false)
  115 +recaptcha - enable or disable recaptcha at login screen (true/false)
  116 +rc_pubkey - Your public recaptha key (required for recaptcha)
  117 +rc_privkey - Your private recaptcha key (required for recaptcha)
  118 +nocaptcha - Array of your recaptcha whitelist. If you do not want to recaptcha
  119 +when you access the webapp from specified hosts, you need to set up their IP
  120 +addresses as followings:
  121 +*array(
  122 +'1.2.3.4',
  123 +'2.3.4.5',
  124 +);*
  125 +title - Title string at the top of your SMBind-ng screen (eg. 'My DNS zones')
  126 +footer - Footer string at the bottom of your SMBind-ng screen (eg. 'Company
  127 +Name')
  128 +staticdomain - If you want to access your static files (.css and .js) through
  129 +other virtual host, then you need to configure it in your webserver, and just
  130 +set it (eg. 'static.mydnsservice.local'). There are only two static files in
  131 +your SMBind-ng installation, so I think you don't really need this - but who
  132 +knows?
  133 +template - .css and .js name in static directory. The default values is
  134 +*default*
  135 +path - Where you store your zonefiles. Default: */etc/smbind-ng/zones/*
  136 +conf - Your included config file. Default: */etc/smbind-ng/smbind-ng.conf*
  137 +namedcheckconf - Place of your binary. Default if found: */usr/sbin/named-
  138 +checkconf*
  139 +namedcheckzone - Place of your binary. Default if found: */usr/sbin/named-
  140 +checkzone*
  141 +rndc - Place of your binary. Default if found: */usr/sbin/rndc*
  142 +zonesigner - Place of your binary. Default if found: */usr/sbin/zonesigner*
  143 +rollinit - Place of your binary. Default if found: */usr/sbin/rollinit*
  144 +dig - Place of your binary. Default if found: */usr/bin/dig*
  145 +
  146 +## Access your admin application
  147 +
  148 +http(s)://your.virtualhost.here/path
  149 +
  150 +Global admin username: **admin**
  151 +Initial password: **SMBind-ng2016**
... ...
LICENSE.md 0 → 100644
  1 +++ a/LICENSE.md
  1 +# GNU GENERAL PUBLIC LICENSE
  2 +
  3 +Version 3, 29 June 2007
  4 +
  5 +Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
  6 +
  7 +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
  8 +
  9 +## Preamble
  10 +
  11 +The GNU General Public License is a free, copyleft license for software and other kinds of works.
  12 +
  13 +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.
  14 +
  15 +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.
  16 +
  17 +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.
  18 +
  19 +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.
  20 +
  21 +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.
  22 +
  23 +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.
  24 +
  25 +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.
  26 +
  27 +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.
  28 +
  29 +The precise terms and conditions for copying, distribution and modification follow.
  30 +
  31 +# TERMS AND CONDITIONS
  32 +
  33 +## 0. Definitions.
  34 +
  35 +“This License” refers to version 3 of the GNU General Public License.
  36 +
  37 +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
  38 +
  39 +“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.
  40 +
  41 +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.
  42 +
  43 +A “covered work” means either the unmodified Program or a work based on the Program.
  44 +
  45 +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.
  46 +
  47 +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.
  48 +
  49 +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.
  50 +
  51 +## 1. Source Code.
  52 +
  53 +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.
  54 +
  55 +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.
  56 +
  57 +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.
  58 +
  59 +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.
  60 +
  61 +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
  62 +
  63 +The Corresponding Source for a work in source code form is that same work.
  64 +
  65 +## 2. Basic Permissions.
  66 +
  67 +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.
  68 +
  69 +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.
  70 +
  71 +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
  72 +
  73 +## 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
  74 +
  75 +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.
  76 +
  77 +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.
  78 +
  79 +## 4. Conveying Verbatim Copies.
  80 +
  81 +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.
  82 +
  83 +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.
  84 +
  85 +## 5. Conveying Modified Source Versions.
  86 +
  87 +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:
  88 +
  89 + * a. The work must carry prominent notices stating that you modified it, and giving a relevant date.
  90 + * 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”.
  91 + * 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.
  92 + * 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.
  93 +
  94 +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.
  95 +
  96 +## 6. Conveying Non-Source Forms.
  97 +
  98 +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:
  99 +
  100 + * 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.
  101 + * 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.
  102 + * 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.
  103 + * 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.
  104 + * 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.
  105 +
  106 +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.
  107 +
  108 +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.
  109 +
  110 +“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.
  111 +
  112 +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).
  113 +
  114 +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.
  115 +
  116 +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.
  117 +
  118 +## 7. Additional Terms.
  119 +
  120 +“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.
  121 +
  122 +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.
  123 +
  124 +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:
  125 +
  126 + * a. Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
  127 + * 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
  128 + * 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
  129 + * d. Limiting the use for publicity purposes of names of licensors or authors of the material; or
  130 + * e. Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
  131 + * 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.
  132 +
  133 +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.
  134 +
  135 +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.
  136 +
  137 +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.
  138 +
  139 +## 8. Termination.
  140 +
  141 +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).
  142 +
  143 +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.
  144 +
  145 +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.
  146 +
  147 +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.
  148 +
  149 +## 9. Acceptance Not Required for Having Copies.
  150 +
  151 +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.
  152 +
  153 +## 10. Automatic Licensing of Downstream Recipients.
  154 +
  155 +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.
  156 +
  157 +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.
  158 +
  159 +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.
  160 +
  161 +## 11. Patents.
  162 +
  163 +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”.
  164 +
  165 +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.
  166 +
  167 +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.
  168 +
  169 +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.
  170 +
  171 +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.
  172 +
  173 +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.
  174 +
  175 +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.
  176 +
  177 +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.
  178 +
  179 +## 12. No Surrender of Others' Freedom.
  180 +
  181 +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.
  182 +
  183 +## 13. Use with the GNU Affero General Public License.
  184 +
  185 +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.
  186 +
  187 +## 14. Revised Versions of this License.
  188 +
  189 +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.
  190 +
  191 +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.
  192 +
  193 +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.
  194 +
  195 +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.
  196 +
  197 +## 15. Disclaimer of Warranty.
  198 +
  199 +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.
  200 +
  201 +## 16. Limitation of Liability.
  202 +
  203 +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.
  204 +
  205 +## 17. Interpretation of Sections 15 and 16.
  206 +
  207 +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.
0 208 \ No newline at end of file
... ...
README.md 0 → 100644
  1 +++ a/README.md
  1 +# SMBind-ng
  2 +This is a forked project from [smbind](http://sourceforge.net/projects/smbind/).
  3 +
  4 +This fork has many improvements, security changes and new features
  5 +
  6 +## Improvements
  7 + * New design (css based, customizable)
  8 + * New .js library
  9 + * Fully separated parts (one .js, one .css and the HTML part)
  10 + * No inline CSS and JS (except the login captcha)
  11 + * Key bindings
  12 + * CSS based inline graphical elements
  13 +
  14 +## Security changes
  15 + * Login with Google ReCaptcha validation
  16 + * Password policy (JS based checking)
  17 + * No password traffic in HTTP channel (JS based encryption)
  18 + * Strict login and session checking
  19 +
  20 +## New features
  21 + * Master and slave zones handling in one application
  22 + * Zone preview
  23 + * Zone checking before commit
  24 + * Users can commit only their checked zones, no others
  25 + * Admins can commit all checked zones (except deleted zones)
  26 + * DNSSEC capabilities - it generetes automatically
  27 + * Roller daemon handling
  28 + * viewing zones with/without DNSSEC encryption
  29 + * Import master zones from many bind sources
  30 + * Check slave zones with zonetransfer
  31 + * IDN capabilities - you just use UTF-8 characters
0 32 \ No newline at end of file
... ...
config/config.php 0 → 100644
  1 +++ a/config/config.php
  1 +<?php
  2 +$_CONF['db_type'] = '';
  3 +$_CONF['db_user'] = '';
  4 +$_CONF['db_pass'] = '';
  5 +$_CONF['db_host'] = '';
  6 +$_CONF['db_port'] = '';
  7 +$_CONF['db_db'] = '';
  8 +$_CONF['smarty_path'] = '';
  9 +$_CONF['peardb_path'] = '';
  10 +?>
... ...
index.php 0 → 100644
  1 +++ a/index.php
  1 +<?php
  2 +require_once "src/include.php";
  3 +
  4 +$smarty->assign("pagetitle", "Main");
  5 +$smarty->assign("user", $user->getFullName());
  6 +$smarty->assign("zones", sizeof($user->getMasters('live')));
  7 +$smarty->assign("slave_zones", sizeof($user->getSlaves('live')));
  8 +$smarty->assign("status", rndc_status());
  9 +$smarty->assign("bad", $user->getUnvalidatedZones('master'));
  10 +$smarty->assign("bad_slaves", $user->getUnvalidatedZones('slave'));
  11 +$smarty->assign("comm", $user->getCommitableZones('master'));
  12 +$smarty->assign("comm_slaves", $user->getCommitableZones('slave'));
  13 +$smarty->assign("del", $user->getDeletedZones('master'));
  14 +$smarty->assign("del_slaves", $user->getDeletedZones('slave'));
  15 +$smarty->assign("template", "mainpage.tpl");
  16 +$smarty->assign("help", help("mainpage"));
  17 +$smarty->assign("menu_button", menu_buttons());
  18 +$smarty->display("main.tpl");
  19 +?>
... ...
lib/punycode.class.php 0 → 100644
  1 +++ a/lib/punycode.class.php
  1 +<?php
  2 +/**
  3 + * The MIT License (MIT)
  4 + *
  5 + * Copyright (c) 2013 mk-j, zedwood.com
  6 + *
  7 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  8 + * of this software and associated documentation files (the "Software"), to deal
  9 + * in the Software without restriction, including without limitation the rights
  10 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11 + * copies of the Software, and to permit persons to whom the Software is
  12 + * furnished to do so, subject to the following conditions:
  13 + *
  14 + * The above copyright notice and this permission notice shall be included in all
  15 + * copies or substantial portions of the Software.
  16 + *
  17 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23 + * SOFTWARE.
  24 + */
  25 +function_exists('mb_internal_encoding') or die('unsupported dependency, mbstring');
  26 +class Punycode
  27 +{
  28 + const TMIN = 1;
  29 + const TMAX = 26;
  30 + const BASE = 36;
  31 + const INITIAL_N = 128;
  32 + const INITIAL_BIAS = 72;
  33 + const DAMP = 700;
  34 + const SKEW = 38;
  35 + const DELIMITER = '-';
  36 + //Punycode::::encodeHostName() corresponds to idna_toASCII('xärg.örg');
  37 + public static function encodeHostName($hostname)
  38 + {
  39 + if (!self::is_valid_utf8($hostname))
  40 + {
  41 + return $hostname;//invalid
  42 + }
  43 + if (function_exists('idn_to_ascii') && 0)
  44 + {
  45 + return idn_to_ascii($hostname);//php 5.3+
  46 + }
  47 + $old_encoding = mb_internal_encoding();
  48 + mb_internal_encoding("UTF-8");
  49 + $pieces = explode(".", self::mb_strtolower($hostname) );
  50 + $punycode_pieces = array();
  51 + foreach($pieces as $piece)
  52 + {
  53 + if (preg_match("/[\x{80}-\x{FFFF}]/u", $piece))//is multi byte utf8
  54 + {
  55 + $punycode_pieces[] = "xn--".self::encode($piece);
  56 + }
  57 + else if (preg_match('/^[a-z\d][a-z\d-]{0,62}$/i', $piece) && !preg_match('/-$/', $piece) )//is valid ascii hostname
  58 + {
  59 + $punycode_pieces[] = $piece;
  60 + }
  61 + else
  62 + {
  63 + mb_internal_encoding($old_encoding);
  64 + return $hostname;//invalid domain
  65 + }
  66 + }
  67 + mb_internal_encoding($old_encoding);
  68 + return implode(".", $punycode_pieces);
  69 + }
  70 + //Punycode::::decodeHostName() corresponds to idna_toUnicode('xn--xrg-9ka.xn--rg-eka');
  71 + public static function decodeHostName($encoded_hostname)
  72 + {
  73 + if (!preg_match('/[a-z\d.-]{1,255}/', $encoded_hostname))
  74 + {
  75 + return false;
  76 + }
  77 + if (function_exists('idn_to_utf8') && 0)
  78 + {
  79 + return idn_to_utf8($encoded_hostname);
  80 + }
  81 + $old_encoding = mb_internal_encoding();
  82 + mb_internal_encoding("UTF-8");
  83 + $pieces = explode(".", strtolower($encoded_hostname));
  84 + foreach($pieces as $piece)
  85 + {
  86 + if (!preg_match('/^[a-z\d][a-z\d-]{0,62}$/i', $piece) || preg_match('/-$/', $piece) )
  87 + {
  88 + mb_internal_encoding($old_encoding);
  89 + return $encoded_hostname;//invalid
  90 + }
  91 + $punycode_pieces[] = strpos($piece, "xn--")===0 ? self::decode(substr($piece,4)) : $piece;
  92 + }
  93 + mb_internal_encoding($old_encoding);
  94 + return implode(".", $punycode_pieces);
  95 + }
  96 + protected static function encode($input)
  97 + {
  98 + try
  99 + {
  100 + $n = self::INITIAL_N;
  101 + $delta = 0;
  102 + $bias = self::INITIAL_BIAS;
  103 + $output='';
  104 + $input_length = self::mb_strlen($input);
  105 + $b=0;
  106 + for($i=0; $i<$input_length; $i++)
  107 + {
  108 + $chr = self::mb_substr($input,$i,1);
  109 + $c = self::uniord( $chr );//autoloaded class
  110 + if ($c < self::INITIAL_N)
  111 + {
  112 + $output.= $chr;
  113 + $b++;
  114 + }
  115 + }
  116 +
  117 + if ($b==$input_length)//no international chars to convert to punycode here
  118 + {
  119 + throw new Exception("PunycodeException.BAD_INPUT");
  120 + }
  121 + else if ($b>0)
  122 + {
  123 + $output.= self::DELIMITER;
  124 + }
  125 + $h = $b;
  126 + while($h < $input_length)
  127 + {
  128 + $m = PHP_INT_MAX;
  129 + // Find the minimum code point >= n
  130 + for($i=0; $i<$input_length; $i++)
  131 + {
  132 + $chr = self::mb_substr($input,$i,1);
  133 + $c = self::uniord( $chr );
  134 + if ($c >= $n && $c < $m)
  135 + {
  136 + $m = $c;
  137 + }
  138 + }
  139 +
  140 +
  141 + if (($m - $n) > (PHP_INT_MAX - $delta) / ($h+1))
  142 + {
  143 + throw new Exception("PunycodeException.OVERFLOW");
  144 + }
  145 + $delta = $delta + ($m - $n) * ($h + 1);
  146 + $n = $m;
  147 +
  148 + for($j=0; $j<$input_length; $j++)
  149 + {
  150 + $chr = self::mb_substr($input,$j,1);
  151 + $c = self::uniord( $chr );
  152 + if ($c < $n)
  153 + {
  154 + $delta++;
  155 + if (0==$delta)
  156 + {
  157 + throw new Exception("PunycodeException.OVERFLOW");
  158 + }
  159 + }
  160 +
  161 + if ($c == $n)
  162 + {
  163 + $q = $delta;
  164 + for($k= self::BASE;; $k+=self::BASE)
  165 + {
  166 + $t=0;
  167 + if ($k <= $bias)
  168 + {
  169 + $t= self::TMIN;
  170 + } else if ($k >= $bias + self::TMAX) {
  171 + $t= self::TMAX;
  172 + } else {
  173 + $t = $k - $bias;
  174 + }
  175 + if ($q < $t)
  176 + {
  177 + break;
  178 + }
  179 + $output.= chr( self::digit2codepoint($t + ($q - $t) % (self::BASE - $t)) );
  180 + $q = floor( ($q-$t) / (self::BASE - $t) );//integer division
  181 + }
  182 + $output.= chr( self::digit2codepoint($q) );
  183 + $bias = self::adapt($delta, $h+1, $h==$b);
  184 + $delta=0;
  185 + $h++;
  186 + }
  187 + }
  188 + $delta++;
  189 + $n++;
  190 + }
  191 + }
  192 + catch (Exception $e)
  193 + {
  194 + error_log("[PUNYCODE] error ".$e->getMessage());
  195 + return $input;
  196 + }
  197 + return $output;
  198 + }
  199 + protected static function decode($input)
  200 + {
  201 + try
  202 + {
  203 + $n = self::INITIAL_N;
  204 + $i = 0;
  205 + $bias = self::INITIAL_BIAS;
  206 + $output = '';
  207 + $d = self::rstrpos($input, self::DELIMITER);
  208 + if ($d>0) {
  209 + for($j=0; $j<$d; $j++) {
  210 + $chr = self::mb_substr($input,$j,1);
  211 + $c = self::uniord( $chr );
  212 + if ($c>=self::INITIAL_N) {
  213 + throw new Exception("PunycodeException.BAD_INPUT");
  214 + }
  215 + $output.=$chr;
  216 + }
  217 + $d++;
  218 + } else {
  219 + $d = 0;
  220 + }
  221 + $input_length = self::mb_strlen($input);
  222 + while ($d < $input_length) {
  223 + $oldi = $i;
  224 + $w = 1;
  225 + for($k= self::BASE;; $k += self::BASE) {
  226 + if ($d == $input_length) {
  227 + throw new Exception("PunycodeException.BAD_INPUT");
  228 + }
  229 + $chr = self::mb_substr($input,$d++,1);
  230 + $c = self::uniord( $chr );
  231 + $digit = self::codepoint2digit($c);
  232 + if ($digit > (PHP_INT_MAX - $i) / $w) {
  233 + throw new Exception("PunycodeException.OVERFLOW");
  234 + }
  235 + $i = $i + $digit * $w;
  236 + $t=0;
  237 + if ($k <= $bias) {
  238 + $t = self::TMIN;
  239 + } else if ($k >= $bias + self::TMAX) {
  240 + $t = self::TMAX;
  241 + } else {
  242 + $t = $k - $bias;
  243 + }
  244 + if ($digit < $t) {
  245 + break;
  246 + }
  247 + $w = $w * (self::BASE - $t);
  248 + }
  249 + $output_length = self::mb_strlen($output);
  250 + $bias = self::adapt($i - $oldi, $output_length + 1, $oldi == 0);
  251 + if ($i / ($output_length + 1) > PHP_INT_MAX - $n) {
  252 + throw new Exception("PunycodeException.OVERFLOW");
  253 + }
  254 + $n = floor($n + $i / ($output_length + 1));
  255 + $i = $i % ($output_length + 1);
  256 + $output = self::mb_strinsert($output, self::utf8($n), $i);
  257 + $i++;
  258 + }
  259 + }
  260 + catch(Exception $e)
  261 + {
  262 + error_log("[PUNYCODE] error ".$e->getMessage());
  263 + return $input;
  264 + }
  265 + return $output;
  266 + }
  267 +//adapt patched from:
  268 +//https://github.com/takezoh/php-PunycodeEncoder/blob/master/punycode.php
  269 + protected static function adapt($delta, $numpoints, $firsttime)
  270 + {
  271 + $delta = (int)($firsttime ? $delta / self::DAMP : $delta / 2);
  272 + $delta += (int)($delta / $numpoints);
  273 + $k = 0;
  274 + while ($delta > (((self::BASE - self::TMIN) * self::TMAX) / 2)) {
  275 + $delta = (int)($delta / (self::BASE - self::TMIN));
  276 + $k += self::BASE;
  277 + }
  278 + return $k + (int)((self::BASE - self::TMIN + 1) * $delta / ($delta + self::SKEW));
  279 + }
  280 + protected static function digit2codepoint($d)
  281 + {
  282 + if ($d < 26) {
  283 + // 0..25 : 'a'..'z'
  284 + return $d + ord('a');
  285 + } else if ($d < 36) {
  286 + // 26..35 : '0'..'9';
  287 + return $d - 26 + ord('0');
  288 + } else {
  289 + throw new Exception("PunycodeException.BAD_INPUT");
  290 + }
  291 + }
  292 + protected static function codepoint2digit($c)
  293 + {
  294 + if ($c - ord('0') < 10) {
  295 + // '0'..'9' : 26..35
  296 + return $c - ord('0') + 26;
  297 + } else if ($c - ord('a') < 26) {
  298 + // 'a'..'z' : 0..25
  299 + return $c - ord('a');
  300 + } else {
  301 + throw new Exception("PunycodeException.BAD_INPUT");
  302 + }
  303 + }
  304 + protected static function rstrpos($haystack, $needle)
  305 + {
  306 + $pos = strpos (strrev($haystack), $needle);
  307 + if ($pos === false)
  308 + return false;
  309 + return strlen ($haystack)-1 - $pos;
  310 + }
  311 + protected static function mb_strinsert($haystack, $needle, $position)
  312 + {
  313 + $old_encoding = mb_internal_encoding();
  314 + mb_internal_encoding("UTF-8");
  315 + $r = mb_substr($haystack,0,$position).$needle.mb_substr($haystack,$position);
  316 + mb_internal_encoding($old_encoding);
  317 + return $r;
  318 + }
  319 +
  320 + protected static function mb_substr($str,$start,$length)
  321 + {
  322 + $old_encoding = mb_internal_encoding();
  323 + mb_internal_encoding("UTF-8");
  324 + $r = mb_substr($str,$start,$length);
  325 + mb_internal_encoding($old_encoding);
  326 + return $r;
  327 + }
  328 + protected static function mb_strlen($str)
  329 + {
  330 + $old_encoding = mb_internal_encoding();
  331 + mb_internal_encoding("UTF-8");
  332 + $r = mb_strlen($str);
  333 + mb_internal_encoding($old_encoding);
  334 + return $r;
  335 + }
  336 + protected static function mb_strtolower($str)
  337 + {
  338 + $old_encoding = mb_internal_encoding();
  339 + mb_internal_encoding("UTF-8");
  340 + $r = mb_strtolower($str);
  341 + mb_internal_encoding($old_encoding);
  342 + return $r;
  343 + }
  344 +
  345 + public static function uniord($c)//cousin of ord() but for unicode
  346 + {
  347 + $ord0 = ord($c{0}); if ($ord0>=0 && $ord0<=127) return $ord0;
  348 + $ord1 = ord($c{1}); if ($ord0>=192 && $ord0<=223) return ($ord0-192)*64 + ($ord1-128);
  349 + if ($ord0==0xed && ($ord1 & 0xa0) == 0xa0) return false; //code points, 0xd800 to 0xdfff
  350 + $ord2 = ord($c{2}); if ($ord0>=224 && $ord0<=239) return ($ord0-224)*4096 + ($ord1-128)*64 + ($ord2-128);
  351 + $ord3 = ord($c{3}); if ($ord0>=240 && $ord0<=247) return ($ord0-240)*262144 + ($ord1-128)*4096 + ($ord2-128)*64 + ($ord3-128);
  352 + return false;
  353 + }
  354 + public static function utf8($num)//cousin of ascii() but for utf8
  355 + {
  356 + if($num<=0x7F) return chr($num);
  357 + if($num<=0x7FF) return chr(($num>>6)+192).chr(($num&63)+128);
  358 + if(0xd800<=$num && $num<=0xdfff) return '';//invalid block of utf8
  359 + if($num<=0xFFFF) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
  360 + if($num<=0x10FFFF) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128).chr(($num&63)+128);
  361 + return '';
  362 + }
  363 +
  364 + public static function is_valid_utf8($string)
  365 + {
  366 + for ($i=0, $ix=strlen($string); $i < $ix; $i++)
  367 + {
  368 + $c = ord($string{$i});
  369 + if ($c==0x09 || $c==0x0a || $c==0x0d || (0x20 <= $c && $c < 0x7e) ) $n = 0; # 0bbbbbbb
  370 + else if (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb
  371 + else if ($c==0xed && (ord($string{$i+1}) & 0xa0)==0xa0) return false; //code points, 0xd800 to 0xdfff
  372 + else if (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb
  373 + else if (($c & 0xF8) == 0xF0) $n=3; # 11110bbb
  374 + //else if (($c & 0xFC) == 0xF8) $n=4; # 111110bb //byte 5, unnecessary in 4 byte UTF-8
  375 + //else if (($c & 0xFE) == 0xFC) $n=5; # 1111110b //byte 6, unnecessary in 4 byte UTF-8
  376 + else return false;
  377 + for ($j=0; $j<$n; $j++) { // n bytes matching 10bbbbbb follow ?
  378 + if ((++$i == $ix) || ((ord($string{$i}) & 0xC0) != 0x80))
  379 + return false;
  380 + }
  381 + }
  382 + return true;
  383 + }
  384 +}
  385 +
... ...
lib/recaptchalib.php 0 → 100644
  1 +++ a/lib/recaptchalib.php
  1 +<?php
  2 +/*
  3 + * This is a PHP library that handles calling reCAPTCHA.
  4 + * - Documentation and latest version
  5 + * http://recaptcha.net/plugins/php/
  6 + * - Get a reCAPTCHA API Key
  7 + * https://www.google.com/recaptcha/admin/create
  8 + * - Discussion group
  9 + * http://groups.google.com/group/recaptcha
  10 + *
  11 + * Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net
  12 + * AUTHORS:
  13 + * Mike Crawford
  14 + * Ben Maurer
  15 + *
  16 + * Permission is hereby granted, free of charge, to any person obtaining a copy
  17 + * of this software and associated documentation files (the "Software"), to deal
  18 + * in the Software without restriction, including without limitation the rights
  19 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  20 + * copies of the Software, and to permit persons to whom the Software is
  21 + * furnished to do so, subject to the following conditions:
  22 + *
  23 + * The above copyright notice and this permission notice shall be included in
  24 + * all copies or substantial portions of the Software.
  25 + *
  26 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  29 + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  30 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  31 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  32 + * THE SOFTWARE.
  33 + */
  34 +
  35 +/**
  36 + * The reCAPTCHA server URL's
  37 + */
  38 +define("RECAPTCHA_API_SERVER", "http://www.google.com/recaptcha/api");
  39 +define("RECAPTCHA_API_SECURE_SERVER", "https://www.google.com/recaptcha/api");
  40 +define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
  41 +
  42 +/**
  43 + * Encodes the given data into a query string format
  44 + * @param $data - array of string elements to be encoded
  45 + * @return string - encoded request
  46 + */
  47 +function _recaptcha_qsencode ($data) {
  48 + $req = "";
  49 + foreach ( $data as $key => $value )
  50 + $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
  51 +
  52 + // Cut the last '&'
  53 + $req=substr($req,0,strlen($req)-1);
  54 + return $req;
  55 +}
  56 +
  57 +
  58 +
  59 +/**
  60 + * Submits an HTTP POST to a reCAPTCHA server
  61 + * @param string $host
  62 + * @param string $path
  63 + * @param array $data
  64 + * @param int port
  65 + * @return array response
  66 + */
  67 +function _recaptcha_http_post($host, $path, $data, $port = 80) {
  68 +
  69 + $req = _recaptcha_qsencode ($data);
  70 +
  71 + $http_request = "POST $path HTTP/1.0\r\n";
  72 + $http_request .= "Host: $host\r\n";
  73 + $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
  74 + $http_request .= "Content-Length: " . strlen($req) . "\r\n";
  75 + $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
  76 + $http_request .= "\r\n";
  77 + $http_request .= $req;
  78 +
  79 + $response = '';
  80 + if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
  81 + die ('Could not open socket');
  82 + }
  83 +
  84 + fwrite($fs, $http_request);
  85 +
  86 + while ( !feof($fs) )
  87 + $response .= fgets($fs, 1160); // One TCP-IP packet
  88 + fclose($fs);
  89 + $response = explode("\r\n\r\n", $response, 2);
  90 +
  91 + return $response;
  92 +}
  93 +
  94 +
  95 +
  96 +/**
  97 + * Gets the challenge HTML (javascript and non-javascript version).
  98 + * This is called from the browser, and the resulting reCAPTCHA HTML widget
  99 + * is embedded within the HTML form it was called from.
  100 + * @param string $pubkey A public key for reCAPTCHA
  101 + * @param string $error The error given by reCAPTCHA (optional, default is null)
  102 + * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
  103 +
  104 + * @return string - The HTML to be embedded in the user's form.
  105 + */
  106 +function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
  107 +{
  108 + if ($pubkey == null || $pubkey == '') {
  109 + die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
  110 + }
  111 +
  112 + if ($use_ssl) {
  113 + $server = RECAPTCHA_API_SECURE_SERVER;
  114 + } else {
  115 + $server = RECAPTCHA_API_SERVER;
  116 + }
  117 +
  118 + $errorpart = "";
  119 + if ($error) {
  120 + $errorpart = "&amp;error=" . $error;
  121 + }
  122 + return '<script type="text/javascript" src="'. $server . '/challenge?k=' . $pubkey . $errorpart . '"></script>
  123 +
  124 + <noscript>
  125 + <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart . '" height="300" width="500" frameborder="0"></iframe><br/>
  126 + <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
  127 + <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
  128 + </noscript>';
  129 +}
  130 +
  131 +
  132 +
  133 +
  134 +/**
  135 + * A ReCaptchaResponse is returned from recaptcha_check_answer()
  136 + */
  137 +class ReCaptchaResponse {
  138 + var $is_valid;
  139 + var $error;
  140 +}
  141 +
  142 +
  143 +/**
  144 + * Calls an HTTP POST function to verify if the user's guess was correct
  145 + * @param string $privkey
  146 + * @param string $remoteip
  147 + * @param string $challenge
  148 + * @param string $response
  149 + * @param array $extra_params an array of extra variables to post to the server
  150 + * @return ReCaptchaResponse
  151 + */
  152 +function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
  153 +{
  154 + if ($privkey == null || $privkey == '') {
  155 + die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
  156 + }
  157 +
  158 + if ($remoteip == null || $remoteip == '') {
  159 + die ("For security reasons, you must pass the remote ip to reCAPTCHA");
  160 + }
  161 +
  162 +
  163 +
  164 + //discard spam submissions
  165 + if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
  166 + $recaptcha_response = new ReCaptchaResponse();
  167 + $recaptcha_response->is_valid = false;
  168 + $recaptcha_response->error = 'incorrect-captcha-sol';
  169 + return $recaptcha_response;
  170 + }
  171 +
  172 + $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
  173 + array (
  174 + 'privatekey' => $privkey,
  175 + 'remoteip' => $remoteip,
  176 + 'challenge' => $challenge,
  177 + 'response' => $response
  178 + ) + $extra_params
  179 + );
  180 +
  181 + $answers = explode ("\n", $response [1]);
  182 + $recaptcha_response = new ReCaptchaResponse();
  183 +
  184 + if (trim ($answers [0]) == 'true') {
  185 + $recaptcha_response->is_valid = true;
  186 + }
  187 + else {
  188 + $recaptcha_response->is_valid = false;
  189 + $recaptcha_response->error = $answers [1];
  190 + }
  191 + return $recaptcha_response;
  192 +
  193 +}
  194 +
  195 +/**
  196 + * gets a URL where the user can sign up for reCAPTCHA. If your application
  197 + * has a configuration page where you enter a key, you should provide a link
  198 + * using this function.
  199 + * @param string $domain The domain where the page is hosted
  200 + * @param string $appname The name of your application
  201 + */
  202 +function recaptcha_get_signup_url ($domain = null, $appname = null) {
  203 + return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
  204 +}
  205 +
  206 +function _recaptcha_aes_pad($val) {
  207 + $block_size = 16;
  208 + $numpad = $block_size - (strlen ($val) % $block_size);
  209 + return str_pad($val, strlen ($val) + $numpad, chr($numpad));
  210 +}
  211 +
  212 +/* Mailhide related code */
  213 +
  214 +function _recaptcha_aes_encrypt($val,$ky) {
  215 + if (! function_exists ("mcrypt_encrypt")) {
  216 + die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
  217 + }
  218 + $mode=MCRYPT_MODE_CBC;
  219 + $enc=MCRYPT_RIJNDAEL_128;
  220 + $val=_recaptcha_aes_pad($val);
  221 + return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
  222 +}
  223 +
  224 +
  225 +function _recaptcha_mailhide_urlbase64 ($x) {
  226 + return strtr(base64_encode ($x), '+/', '-_');
  227 +}
  228 +
  229 +/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
  230 +function recaptcha_mailhide_url($pubkey, $privkey, $email) {
  231 + if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
  232 + die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
  233 + "you can do so at <a href='http://www.google.com/recaptcha/mailhide/apikey'>http://www.google.com/recaptcha/mailhide/apikey</a>");
  234 + }
  235 +
  236 +
  237 + $ky = pack('H*', $privkey);
  238 + $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
  239 +
  240 + return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
  241 +}
  242 +
  243 +/**
  244 + * gets the parts of the email to expose to the user.
  245 + * eg, given johndoe@example,com return ["john", "example.com"].
  246 + * the email is then displayed as john...@example.com
  247 + */
  248 +function _recaptcha_mailhide_email_parts ($email) {
  249 + $arr = preg_split("/@/", $email );
  250 +
  251 + if (strlen ($arr[0]) <= 4) {
  252 + $arr[0] = substr ($arr[0], 0, 1);
  253 + } else if (strlen ($arr[0]) <= 6) {
  254 + $arr[0] = substr ($arr[0], 0, 3);
  255 + } else {
  256 + $arr[0] = substr ($arr[0], 0, 4);
  257 + }
  258 + return $arr;
  259 +}
  260 +
  261 +/**
  262 + * Gets html to display an email address given a public an private key.
  263 + * to get a key, go to:
  264 + *
  265 + * http://www.google.com/recaptcha/mailhide/apikey
  266 + */
  267 +function recaptcha_mailhide_html($pubkey, $privkey, $email) {
  268 + $emailparts = _recaptcha_mailhide_email_parts ($email);
  269 + $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
  270 +
  271 + return htmlentities($emailparts[0]) . "<a href='" . htmlentities ($url) .
  272 + "' onclick=\"window.open('" . htmlentities ($url) . "', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;\" title=\"Reveal this e-mail address\">...</a>@" . htmlentities ($emailparts [1]);
  273 +
  274 +}
  275 +
  276 +
  277 +?>
... ...
lib/smbind.class.php 0 → 100644
  1 +++ a/lib/smbind.class.php
  1 +<?php
  2 +
  3 + require_once 'MDB2.php';
  4 + require_once 'punycode.class.php';
  5 +
  6 + $db = array();
  7 +
  8 + define('COMMENT_PATTERN', '/(\s+;|^;)[^\n]*/i');
  9 + define('ORIGIN_PATTERN', '/^\$ORIGIN\s+(.+)\.\s*/msi');
  10 + define('SOA_BEGINS_PATTERN', '/^([^\s]+)?(\s+[\d\w]+)?\s+IN\s+SOA\s+/msi');
  11 + define('FULL_SOA_PATTERN', '/^([^\s]+)?(\s+[\d\w]+)?\s+IN\s+SOA\s+([-\w\d.]*)\.\s+([-\w\d.]*)\s+\((.*)\)/msi');
  12 + define('TIMES_PATTERN', '/\s*(\d+\w?)\s+(\d+\w?)\s+(\d+\w?)\s+(\d+\w?)\s+(\d+\w?)/msi');
  13 + define('TXT_PATTERN', '/^\"(.*)\"/msi');
  14 + define('MX_PATTERN', '/^(\d+)\s+([^\s]*)/msi');
  15 + define('TYPE_PATTERN', '(A|A6|AAAA|AFSDB|APL|ATMA|AXFR|CERT|CNAME|DNAME|DNSKEY|DS|EID|GPOS|HINFO|ISDN|IXFR|KEY|KX|LOC|MAILB|MINFO|MX|NAPTR|NIMLOC|NS|NSAP|NSAP-PTR|NSEC|NXT|OPT|PTR|PX|RP|RRSIG|RT|SIG|SINK|SRV|SSHFP|TKEY|TSIG|TXT|WKS|X25)');
  16 + define('RECORD_PATTERN', '/^([^\s]+)?(\s+[\d][\d\w]*)?(\s+IN)?\s+'.TYPE_PATTERN.'\s+([^\s].*$)/msi');
  17 + define('BIND_TIME_PATTERN', '/^(\d+)([smhdw])/');
  18 + define('IDN_PUNY_PATTERN', '/[^a-z0-9-]/i');
  19 + define('IDN_UTF_PATTERN', '/[^a-z0-9\x80-\xFF-]/i');
  20 + define('BIND_ZONENAME_PATTERN', '/zone\s+"([^"]+)".*$/msi');
  21 + define('BIND_ZONEDATA_PATTERN', '/^([^\s]+)\s+"?([^"]+)"?$/');
  22 + define('BIND_SLAVEMASTER_PATTERN', '/^\{([^\};]+);}$/');
  23 +
  24 + function idnToHost($idn) {
  25 + preg_match(IDN_UTF_PATTERN, $idn, $match);
  26 + if (count($match) == 0) {
  27 + $out = ($idn > '') ? Punycode::encodeHostName($idn) : '';
  28 + return ((strlen($out) > 4) && (substr($out, 0, 4) == 'xn--')) ? $out : $idn;
  29 + }
  30 + $tags = explode($match[0], $idn);
  31 + $ret = array();
  32 + foreach ($tags as $tag) {
  33 + $ret[] = ($tag == '') ? '' : idnToHost($tag);
  34 + }
  35 + return implode($match[0], $ret);
  36 + }
  37 +
  38 + function hostToIdn($host) {
  39 + preg_match(IDN_PUNY_PATTERN, $host, $match);
  40 + if (count($match) == 0) {
  41 + return ((strlen($host) > 4) && (substr($host, 0, 4) == 'xn--')) ? Punycode::decodeHostName($host) : $host;
  42 + }
  43 + $tags = explode($match[0], $host);
  44 + $ret = array();
  45 + foreach ($tags as $tag) {
  46 + $ret[] = ($tag == '') ? '' : hostToIdn($tag, $match[0]);
  47 + }
  48 + return implode($match[0], $ret);
  49 + }
  50 +
  51 + class bindConfig {
  52 +
  53 + private $zonedef = array();
  54 + private $err = '';
  55 +
  56 + public function __debugInfo() {
  57 + return array(
  58 + 'zonedef' => $this->zonedef,
  59 + 'err' => $this->err,
  60 + );
  61 + }
  62 +
  63 + public function __construct($file = NULL) {
  64 + if (!is_null($file)) {
  65 + return $this->loadConfig($file);
  66 + } else {
  67 + $this->zonedef = array();
  68 + return true;
  69 + }
  70 + }
  71 +
  72 + public function getErr() {
  73 + return $this->err;
  74 + }
  75 +
  76 + public function loadConfig($fpath) {
  77 + if (!is_string($fpath)) {
  78 + $this->err .= "Only string parameter accepted\n";
  79 + error_log($this->err);
  80 + return false;
  81 + }
  82 + if ($fpath == '') {
  83 + $this->err .= "Given string is empty\n";
  84 + error_log($this->err);
  85 + return false;
  86 + }
  87 + if (!file_exists($fpath)) {
  88 + $this->err .= "File doesn't exist: '" . $fpath . "'\n";
  89 + error_log($this->err);
  90 + return false;
  91 + }
  92 + $conf = file($fpath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  93 + $one = array();
  94 + $name = '';
  95 + foreach ($conf as $line) {
  96 + $line = preg_replace('/(\/\/.*|;)$/', '', trim($line));
  97 + if ($line == '') {
  98 + continue;
  99 + }
  100 + if ($name == '') {
  101 + preg_match(BIND_ZONENAME_PATTERN, $line, $match);
  102 + if (!isset($match[1])) {
  103 + $this->err .= "Read config error\n";
  104 + error_log($this->err);
  105 + return false;
  106 + }
  107 + $name = $match[1];
  108 + } else {
  109 + if ($line == '}') {
  110 + $this->zonedef[$name] = $one;
  111 + $one = array();
  112 + $name = '';
  113 + } else {
  114 + preg_match(BIND_ZONEDATA_PATTERN, $line, $match);
  115 + if ((!isset($match[1])) ||
  116 + (!isset($match[2]))) {
  117 + $this->err .= "Read config error\n";
  118 + error_log($this->err);
  119 + return false;
  120 + }
  121 + $key = $match[1];
  122 + $data = $match[2];
  123 + if ($key == 'masters') {
  124 + preg_match(BIND_SLAVEMASTER_PATTERN, $data, $match);
  125 + if (!isset($match[1])) {
  126 + $this->err .= "Read config error\n";
  127 + error_log($this->err);
  128 + return false;
  129 + }
  130 + $data = $match[1];
  131 + }
  132 + $one[$key] = $data;
  133 + }
  134 + }
  135 + }
  136 + return true;
  137 + }
  138 +
  139 + public function addConfig($name, $data) {
  140 + $name = strval($name);
  141 + if (($name == '') ||
  142 + (!is_array($data))) {
  143 + $this->err .= "Cannot set configset\n";
  144 + error_log($this->err);
  145 + return false;
  146 + }
  147 + $this->zonedef[$name] = $data;
  148 + return true;
  149 + }
  150 +
  151 + public function eraseConfig($name) {
  152 + $name = strval($name);
  153 + if ($name == '') {
  154 + $this->err .= "Cannot set configset\n";
  155 + error_log($this->err);
  156 + return false;
  157 + }
  158 + $this->zonedef[$name] = array();
  159 + return true;
  160 + }
  161 +
  162 + public function saveConfig($fname) {
  163 + if (!is_string($fname)) {
  164 + $this->err .= "Only string parameter accepted\n";
  165 + error_log($this->err);
  166 + return false;
  167 + }
  168 + if ($fname == '') {
  169 + $this->err .= "Given string is empty\n";
  170 + error_log($this->err);
  171 + return false;
  172 + }
  173 + $fh = fopen($fname,'w');
  174 + fwrite($fh, "// SMbind-ng configuration\n\n");
  175 + foreach($this->zonedef as $zone => $def) {
  176 + if (count($def) == 0) {
  177 + continue;
  178 + }
  179 + fwrite($fh, "// Zone " . hostToIdn($zone) . " (" . $def['type'] . ")\n");
  180 + fwrite($fh, "zone \"" . $zone . "\" {\n");
  181 + foreach ($def as $key => $param) {
  182 + switch ($key) {
  183 + case 'file':
  184 + $data = "\"" . $param . "\"";
  185 + break;
  186 + case 'masters':
  187 + $data = "{" . $param . ";}";
  188 + break;
  189 + default:
  190 + $data = $param;
  191 + }
  192 + fwrite($fh, str_pad($key, 10, " ", STR_PAD_LEFT) . " " . $data . ";\n");
  193 + }
  194 + fwrite($fh,"};\n\n");
  195 + }
  196 + fclose($fh);
  197 + return true;
  198 + }
  199 + }
  200 +
  201 + class Configuration {
  202 +
  203 + private $info = array();
  204 +
  205 + public function __debugInfo() {
  206 + return $this->info;
  207 + }
  208 +
  209 + public function __construct($path) {
  210 + global $db;
  211 + if (is_string($path)) {
  212 + $_CONF['smbind_ng'] = $path;
  213 + $_CONF['title'] = "SMBind-ng";
  214 + $_CONF['footer'] = $_CONF['title'] . " v0.91b";
  215 + $_CONF['marker'] = "Forked by PtY 2015(GPL)";
  216 + $_CONF['template'] = "default";
  217 + $_CONF['recaptcha'] = false;
  218 + $_CONF['tmp_path'] = $path . "tmp";
  219 + $_CONF['nocaptcha'] = array();
  220 + $_CONF['path'] = "/etc/smbind-ng/zones/";
  221 + $_CONF['conf'] = "/etc/smbind-ng/smbind-ng.conf";
  222 + $_CONF['namedcheckconf'] = (is_executable("/usr/sbin/named-checkconf")) ? "/usr/sbin/named-checkconf" : "";
  223 + $_CONF['namedcheckzone'] = (is_executable("/usr/sbin/named-checkzone")) ? "/usr/sbin/named-checkzone" : "";
  224 + $_CONF['rndc'] = (is_executable("/usr/sbin/rndc")) ? "/usr/sbin/rndc" : "";
  225 + $_CONF['zonesigner'] = "/usr/sbin/zonesigner";
  226 + $_CONF['rollinit'] = "/usr/sbin/rollinit";
  227 + $_CONF['isdnssec'] = false;
  228 + $_CONF['dig'] = (is_executable("/usr/bin/dig")) ? "/usr/bin/dig" : "";
  229 + include $path . 'config/config.php';
  230 + $_CONF['zonesigner'] = (is_executable($_CONF['zonesigner'])) ? $_CONF['zonesigner'] : "";
  231 + $_CONF['rollinit'] = (is_executable($_CONF['rollinit'])) ? $_CONF['rollinit'] : "";
  232 + $_CONF['isdnssec'] = (($_CONF['isdnssec'] === true) && ($_CONF['zonesigner'] != "") && ($_CONF['rollinit'] != "")) ? true : false;
  233 + $_CONF['recaptcha'] = (($_CONF['recaptcha'] === true) && (strlen($_CONF['rc_pubkey']) > 0) && (strlen($_CONF['rc_privkey']) > 0)) ? true : false;
  234 + if(!isset($_CONF['db_host'])) {
  235 + $_CONF['db_host'] = 'localhost';
  236 + }
  237 + if(!isset($_CONF['db_port'])) {
  238 + switch ($_CONF['db_type']) {
  239 + case 'mysql':
  240 + case 'mysqli':
  241 + $_CONF['db_port'] = '3306';
  242 + break;
  243 + case 'pgsql':
  244 + $_CONF['db_port'] = '5432';
  245 + break;
  246 + }
  247 + }
  248 + $dsn = array (
  249 + 'phptype' => $_CONF['db_type'],
  250 + 'username' => $_CONF['db_user'],
  251 + 'password' => $_CONF['db_pass'],
  252 + 'database' => $_CONF['db_db'],
  253 + 'hostspec' => $_CONF['db_host'],
  254 + 'port' => $_CONF['db_port'],
  255 + 'charset' => 'utf8',
  256 + );
  257 + $dbopt = array('persistent' => true,);
  258 + $db = MDB2::factory($dsn, $dbopt);
  259 + if (MDB2::isError($db)) {
  260 + die("Database error: " . MDB2::errorMessage($dbconnect));
  261 + } else {
  262 + $db->setFetchMode(MDB2_FETCHMODE_ASSOC);
  263 + }
  264 + $query = $db->query("SELECT prefkey, prefval FROM options WHERE preftype = 'normal'");
  265 + if (MDB2::isError($query)) {
  266 + $err = $query->getMessage() . "\n" . $query->getDebugInfo();
  267 + error_log($err);
  268 + die($err);
  269 + }
  270 + while ($res = $query->fetchRow()) {
  271 + $key = $res['prefkey'];
  272 + switch ($key) {
  273 + case 'prins':
  274 + case 'secns':
  275 + $keyparam = substr($key, 0, 3) . '_d' . substr($key, -2);
  276 + break;
  277 + default:
  278 + $keyparam = $key;
  279 + }
  280 + $_CONF[$keyparam] = $res['prefval'];
  281 + }
  282 + $query = $db->query("SELECT prefkey FROM options WHERE prefval = 'on' AND preftype = 'record' ORDER BY prefkey");
  283 + $_CONF['parameters'] = array();
  284 + while ($res = $query->fetchRow()) {
  285 + $_CONF['parameters'][] = $res['prefkey'];
  286 + }
  287 + $query = $db->query("SELECT DISTINCT type FROM records");
  288 + while ($res = $query->fetchRow()) {
  289 + $_CONF['parameters'][] = $res['type'];
  290 + }
  291 + $_CONF['parameters'] = array_unique($_CONF['parameters']);
  292 + $_CONF['dsn'] = $dsn;
  293 + $this->info = $_CONF;
  294 + }
  295 + }
  296 +
  297 + public function __call($method, $args) {
  298 + if (is_string($method)) {
  299 + $m = $this->from_CC(substr($method, 3, strlen($method) - 3));
  300 + return array_key_exists($m, $this->info) ? $this->info[$m] : false;
  301 + }
  302 + }
  303 +
  304 + public function __set($param, $arg) {
  305 + return true;
  306 + }
  307 +
  308 + public function __get($param) {
  309 + $name = strtolower($param);
  310 + $return = (array_key_exists($name, $this->info)) ? $this->info[$name] : NULL;
  311 + if (is_null($return)) {
  312 + switch ($name) {
  313 + case 'range':
  314 + $return = 10;
  315 + break;
  316 + default:
  317 + $return = '';
  318 + }
  319 + }
  320 + return $return;
  321 + }
  322 +
  323 + private function from_CC($str) {
  324 + $str = strtolower($str);
  325 + $func = create_function('$c', 'return "_" . strtolower($c[1]);');
  326 + return preg_replace_callback('/([A-Z])/', $func, $str);
  327 + }
  328 +
  329 + public function isExists($id) {
  330 + return isset($this->info[strtolower($id)]);
  331 + }
  332 +
  333 + }
  334 +
  335 + class Session {
  336 +
  337 + private $usr = '';
  338 + private $psw = '';
  339 + private $inc = NULL;
  340 +
  341 + public function __debugInfo() {
  342 + return array(
  343 + 'usr' => $this->usr,
  344 + 'psw' => $this->psw,
  345 + 'inc' => $this->inc,
  346 + );
  347 + }
  348 +
  349 + public function __construct() {
  350 + session_start();
  351 + if ((isset($_SESSION['i'])) && (is_numeric($_SESSION['i'])) && ($_SESSION['i'] > 0)) {
  352 + $this->inc = $_SESSION['i'];
  353 + $this->inc++;
  354 + if ((isset($_SESSION['p'])) && (is_string($_SESSION['p']))) {
  355 + $this->psw = $_SESSION['p'];
  356 + if ((isset($_SESSION['u'])) && (is_string($_SESSION['u']))) {
  357 + $this->usr = $_SESSION['u'];
  358 + } else {
  359 + $this->psw = '';
  360 + }
  361 + }
  362 + } else {
  363 + $this->inc = 1;
  364 + }
  365 + $_SESSION['i'] = $this->inc;
  366 + }
  367 +
  368 + public function login($user, $pass) {
  369 + $_SESSION['u'] = $user;
  370 + $_SESSION['p'] = $pass;
  371 + $usr = $user;
  372 + $psw = $pass;
  373 + }
  374 +
  375 + public function destroy() {
  376 + $this->usr = '';
  377 + $this->psw = '';
  378 + $this->inc = 0;
  379 + $_SESSION = array();
  380 + session_destroy();
  381 + }
  382 +
  383 + public function isEnoughOld() {
  384 + return $this->inc > 3;
  385 + }
  386 + }
  387 +
  388 + class User {
  389 + private $data = array(
  390 + 'id' => 0,
  391 + 'username' => '',
  392 + 'realname' => '',
  393 + 'password' => '',
  394 + 'admin' => false,
  395 + );
  396 + private $mzones = array();
  397 + private $szones = array();
  398 + private $err = '';
  399 + private $db = array();
  400 +
  401 + public function __debugInfo() {
  402 + return array(
  403 + 'data' => $this->data,
  404 + 'mzones' => $this->mzones,
  405 + 'szones' => $this->szones,
  406 + 'err' => $this->err,
  407 + 'db' => NULL,
  408 + );
  409 + }
  410 +
  411 + public function __construct($uid = NULL) {
  412 + global $db;
  413 + $this->db = &$db;
  414 + if ((is_null($uid)) &&
  415 + (isset($_SESSION['i'])) &&
  416 + ($_SESSION['i'] > 1) &&
  417 + (isset($_SESSION['u'])) &&
  418 + ($_SESSION['p'])) {
  419 + $user = $_SESSION['u'];
  420 + $pass = $_SESSION['p'];
  421 + if (is_object($db)) {
  422 + if ((is_string($user)) && (is_string($pass))) {
  423 + $res = $this->db->query("SELECT * FROM users WHERE username ='" . $user . "' AND password = '" . $pass . "'");
  424 + if (MDB2::isError($res)) {
  425 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  426 + error_log($this->err);
  427 + return false;
  428 + } elseif ($res->numRows() == 0) {
  429 + $this->err .= "Username or password does not match";
  430 + error_log($this->err);
  431 + return false;
  432 + } else {
  433 + $row = $res->fetchRow();
  434 + foreach ($row as $key => $value) {
  435 + switch ($key) {
  436 + case 'id':
  437 + $this->data[$key] = intval($value);
  438 + break;
  439 + case 'admin':
  440 + $this->data[$key] = ($value == 'yes');
  441 + break;
  442 + default:
  443 + $this->data[$key] = strval($value);
  444 + }
  445 + }
  446 + $this->loadUserZones();
  447 + return true;
  448 + }
  449 + }
  450 + }
  451 + } elseif (((is_array($uid)) &&
  452 + (is_numeric($uid['id']))) ||
  453 + (is_numeric($uid))) {
  454 + $aid = (is_array($uid)) ? $uid : array('id' => $uid);
  455 + if ($aid['id'] == 0) {
  456 + foreach ($aid as $key => $value) {
  457 + $this->data[$key] = $value;
  458 + }
  459 + $this->data['username'] = ((isset($aid['username'])) && ($aid['username'] > '')) ? $aid['username'] : 'NONE';
  460 + $this->data['realname'] = ((isset($aid['realname'])) && ($aid['realname'] > '')) ? $aid['realname'] : $this->data['username'];
  461 + $this->data['password'] = ((isset($aid['password'])) && ($aid['password'] > '')) ? $aid['password'] : 'NONE';
  462 + $this->data['admin'] = ((isset($aid['admin'])) && ($aid['admin'] > '') && (($aid['admin'] == 'yes') || ($aid['admin'] == 'no'))) ? $aid['admin'] : 'no';
  463 + $res = $this->db->query("SELECT * FROM users WHERE username='" . $this->data['username'] . "'");
  464 + if (MDB2::isError($res)) {
  465 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  466 + error_log($this->err);
  467 + return false;
  468 + }
  469 + if ($res->numRows() > 0) {
  470 + $this->err .= ($this->data['username'] == 'NONE') ? "Previous error cause a problem\n" : "User already exists\n";
  471 + error_log($this->err);
  472 + return false;
  473 + }
  474 + $res = $this->db->query("INSERT INTO users (username, realname, admin, password) VALUES ('" .
  475 + $this->data['username'] . "', '" .
  476 + $this->data['realname'] . "', '" .
  477 + $this->data['admin'] . "', '" .
  478 + $this->data['password'] . "')");
  479 + if (MDB2::isError($res)) {
  480 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  481 + error_log($this->err);
  482 + return false;
  483 + }
  484 + $res = $this->db->query("SELECT id FROM users WHERE username='" .
  485 + $this->data['username'] . "' AND realname='" .
  486 + $this->data['realname'] . "' AND password='" .
  487 + $this->data['password'] . "'");
  488 + if (MDB2::isError($res)) {
  489 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  490 + error_log($this->err);
  491 + return false;
  492 + }
  493 + $ret = $res->fetchRow();
  494 + $this->data['id'] = $ret['id'];
  495 + return true;
  496 + } else {
  497 + $self->data['id'] = $aid['id'];
  498 + $res = $this->db->query("SELECT * FROM users WHERE id = '" . $self->data['id'] . "'");
  499 + if (MDB2::isError($res)) {
  500 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  501 + error_log($this->err);
  502 + return false;
  503 + } elseif ($res->numRows() == 0) {
  504 + $this->err .= "User not found with this id = " . $self->data['id'];
  505 + error_log($this->err);
  506 + return false;
  507 + } else {
  508 + $row = $res->fetchRow();
  509 + foreach ($row as $key => $value) {
  510 + switch ($key) {
  511 + case 'id':
  512 + $this->data[$key] = intval($value);
  513 + break;
  514 + case 'admin':
  515 + $this->data[$key] = ($value == 'yes');
  516 + break;
  517 + default:
  518 + $this->data[$key] = strval($value);
  519 + }
  520 + }
  521 + }
  522 + }
  523 + }
  524 + }
  525 +
  526 + public function loadUserZones() {
  527 + $WHERE = '';
  528 + if (!$this->isAdmin()) {
  529 + $WHERE .= "WHERE owner = '" . $this->getId() . "' ";
  530 + }
  531 + $res = $this->db->query("SELECT id FROM zones " . $WHERE . "ORDER BY name");
  532 + if (MDB2::isError($res)) {
  533 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  534 + error_log($this->err);
  535 + return false;
  536 + } else {
  537 + $this->mzones = array();
  538 + while ($rec = $res->fetchRow()) {
  539 + $this->mzones[] = $rec['id'];
  540 + }
  541 + $res = $this->db->query("SELECT id FROM slave_zones " . $WHERE . "ORDER BY name");
  542 + if (MDB2::isError($res)) {
  543 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  544 + error_log($this->err);
  545 + return false;
  546 + } else {
  547 + $this->szones = array();
  548 + while ($rec = $res->fetchRow()) {
  549 + $this->szones[] = $rec['id'];
  550 + }
  551 + }
  552 + }
  553 + return true;
  554 + }
  555 +
  556 + public function getUnvalidatedZones($zonetype = NULL) {
  557 + $ret = array();
  558 + if (is_string($zonetype)) {
  559 + $tag = '';
  560 + $db = NULL;
  561 + switch ($zonetype) {
  562 + case 'slave':
  563 + $tag = 'slave_';
  564 + $cnt = sizeof($this->szones);
  565 + $lst = implode(',', $this->szones);
  566 + break;
  567 + case 'master':
  568 + $cnt = sizeof($this->mzones);
  569 + $lst = implode(',', $this->mzones);
  570 + break;
  571 + }
  572 + if ($cnt > 0) {
  573 + $res = $this->db->query("SELECT id, name FROM " . $tag . "zones WHERE id IN (" . $lst . ") AND valid <> 'yes' and updated <> 'del'");
  574 + if (MDB2::isError($res)) {
  575 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  576 + error_log($this->err);
  577 + return false;
  578 + } else {
  579 + while ($recd = $res->fetchRow()) {
  580 + $recd['name'] = hostToIdn($recd['name']);
  581 + $ret[] = $recd;
  582 + }
  583 + }
  584 + }
  585 + }
  586 + return $ret;
  587 + }
  588 + public function getDeletedZones($zonetype = NULL) {
  589 + $ret = array();
  590 + if (is_string($zonetype)) {
  591 + $tag = '';
  592 + $db = NULL;
  593 + switch ($zonetype) {
  594 + case 'slave':
  595 + $tag = 'slave_';
  596 + $cnt = sizeof($this->szones);
  597 + $lst = implode(',', $this->szones);
  598 + break;
  599 + case 'master':
  600 + $cnt = sizeof($this->mzones);
  601 + $lst = implode(',', $this->mzones);
  602 + break;
  603 + }
  604 + if ($cnt > 0) {
  605 + $res = $this->db->query("SELECT id, name FROM " . $tag . "zones WHERE owner = " . $this->data['id'] . " AND updated = 'del'");
  606 + if (MDB2::isError($res)) {
  607 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  608 + error_log($this->err);
  609 + return false;
  610 + } else {
  611 + while ($recd = $res->fetchRow()) {
  612 + $recd['name'] = hostToIdn($recd['name']);
  613 + $ret[] = $recd;
  614 + }
  615 + }
  616 + }
  617 + }
  618 + return $ret;
  619 + }
  620 +
  621 + public function getCommitableZones($zonetype = NULL) {
  622 + $ret = array();
  623 + if (is_string($zonetype)) {
  624 + $tag = '';
  625 + $db = NULL;
  626 + switch ($zonetype) {
  627 + case 'slave':
  628 + $tag = 'slave_';
  629 + $cnt = sizeof($this->szones);
  630 + $lst = implode(',', $this->szones);
  631 + break;
  632 + case 'master':
  633 + $cnt = sizeof($this->mzones);
  634 + $lst = implode(',', $this->mzones);
  635 + break;
  636 + }
  637 + if ($cnt > 0) {
  638 + $res = $this->db->query("SELECT id, name FROM " . $tag . "zones WHERE id IN (" . $lst . ") AND valid = 'yes' AND updated = 'yes'");
  639 + if (MDB2::isError($res)) {
  640 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  641 + error_log($this->err);
  642 + return false;
  643 + } else {
  644 + while ($recd = $res->fetchRow()) {
  645 + $recd['name'] = hostToIdn($recd['name']);
  646 + $ret[] = $recd;
  647 + }
  648 + }
  649 + }
  650 + }
  651 + return $ret;
  652 + }
  653 +
  654 + public function eraseUser() {
  655 + $this->loadUserZones();
  656 + $mz =array();
  657 + foreach ($this->mzones as $master) {
  658 + $mz = new masterRecord($master);
  659 + $mz->loadZoneHead();
  660 + $mzh = $mz->getZoneHead();
  661 + $mzh['owner'] = 1;
  662 + $mz->setZoneHead($mzh);
  663 + $mz->saveZoneHead();
  664 + }
  665 + $mz =array();
  666 + $sz =array();
  667 + foreach ($this->szones as $slave) {
  668 + $sz = new slaveRecord($slave);
  669 + $sz->loadZoneHead();
  670 + $szh = $sz->getZoneHead();
  671 + $szh['owner'] = 1;
  672 + $sz->setZoneHead($szh);
  673 + $sz->saveZoneHead();
  674 + }
  675 + $sz =array();
  676 + $res = $this->db->query("DELETE FROM users WHERE id = " . $this->data['id']);
  677 + if (MDB2::isError($res)) {
  678 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  679 + error_log($this->err);
  680 + return false;
  681 + }
  682 + return true;
  683 + }
  684 +
  685 + public function getMasters($type = 'all') {
  686 + $out = array();
  687 + if ($type == 'live') {
  688 + foreach ($this->mzones as $zoneid) {
  689 + $zone = new masterZone(array('id' => intval($zoneid)));
  690 + $zone->loadZoneHead();
  691 + $head = $zone->getZoneHeadRaw();
  692 + if ($head['updated'] != 'del') {
  693 + $out[] = intval($zoneid);
  694 + }
  695 + }
  696 + } else {
  697 + $out = $this->mzones;
  698 + }
  699 + return $out;
  700 + }
  701 +
  702 + public function getSlaves($type = 'all') {
  703 + $out = array();
  704 + if ($type == 'live') {
  705 + foreach ($this->szones as $zoneid) {
  706 + $zone = new slaveZone(array('id' => intval($zoneid)));
  707 + $zone->loadZoneHead();
  708 + $head = $zone->getZoneHeadRaw();
  709 + if ($head['updated'] != 'del') {
  710 + $out[] = intval($zoneid);
  711 + }
  712 + }
  713 + } else {
  714 + $out = $this->szones;
  715 + }
  716 + return $out;
  717 + }
  718 +
  719 + public function isOwned($id, $type, $state = 'all') {
  720 + $zarr = array();
  721 + switch ($type) {
  722 + case 'master':
  723 + $zarr = $this->getMasters($state);
  724 + break;
  725 + case 'slave':
  726 + $zarr = $this->getSlaves($state);
  727 + break;
  728 + }
  729 + foreach ($zarr as $zid) {
  730 + if ($zid == $id) {
  731 + return true;
  732 + }
  733 + }
  734 + return false;
  735 + }
  736 +
  737 + public function getName() {
  738 + return $this->data['username'];
  739 + }
  740 +
  741 + public function getErr() {
  742 + return $this->err;
  743 + }
  744 +
  745 + public function getFullName() {
  746 + return $this->data['realname'];
  747 + }
  748 +
  749 + public function isAdmin() {
  750 + return $this->data['admin'];
  751 + }
  752 +
  753 + public function getId() {
  754 + return $this->data['id'];
  755 + }
  756 +
  757 + public function getPasswordHash() {
  758 + return $this->data['password'];
  759 + }
  760 +
  761 + public function getUser() {
  762 + $arr = array();
  763 + foreach (array('id', 'username', 'realname', 'admin') as $key) {
  764 + $arr[$key] = $this->data[$key];
  765 + }
  766 + return $arr;
  767 + }
  768 +
  769 + public function getAllusers() {
  770 + $out = array();
  771 + $res = $this->db->query("SELECT id, username, realname, admin FROM users ORDER BY realname");
  772 + if (MDB2::isError($res)) {
  773 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  774 + error_log($this->err);
  775 + } else {
  776 + while ($row = $res->fetchRow()) {
  777 + $out[] = $row;
  778 + }
  779 + }
  780 + return $out;
  781 + }
  782 +
  783 + public function loadUserById() {
  784 + $res = $this->db->query("SELECT * FROM users WHERE id = " . $this->data['id']);
  785 + if (MDB2::isError($res)) {
  786 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  787 + error_log($this->err);
  788 + return false;
  789 + } elseif ($res->numRows() == 0) {
  790 + $this->err .= "User not found";
  791 + error_log($this->err);
  792 + return false;
  793 + } else {
  794 + $row = $res->fetchRow();
  795 + foreach ($row as $key => $value) {
  796 + switch ($key) {
  797 + case 'id':
  798 + $this->data[$key] = intval($value);
  799 + break;
  800 + case 'admin':
  801 + $this->data[$key] = ($value == 'yes');
  802 + break;
  803 + default:
  804 + $this->data[$key] = strval($value);
  805 + }
  806 + }
  807 + return true;
  808 + }
  809 + }
  810 +
  811 + public function set($rname = NULL, $pass = NULL, $adm = NULL) {
  812 + if ((isset($pass)) || (isset($adm)) || (isset($rname))) {
  813 + $pstr = ((is_null($pass)) || (strlen($pass) != 32)) ? "" : "password = '" . $pass . "'";
  814 + $astr = ((is_null($adm)) || (($adm != 'yes') && ($adm != 'no'))) ? "" : "admin = '" . $adm . "'";
  815 + $rnstr = ((is_null($rname)) || ($rname == '')) ? "" : "realname = '" . $rname . "'";
  816 + $setstr = $pstr;
  817 + if ($astr > '') {
  818 + $setstr .= ($setstr != "") ? ", " . $astr : $astr;
  819 + }
  820 + if ($rnstr > '') {
  821 + $setstr .= ($setstr != "") ? ", " . $rnstr : $rnstr;
  822 + }
  823 + if ($setstr > "") {
  824 + $res = $this->db->query("UPDATE users SET " . $setstr . " WHERE id = " . $this->data['id']);
  825 + if (MDB2::isError($res)) {
  826 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  827 + error_log($this->err);
  828 + return false;
  829 + }
  830 + return $this->loadUserById();
  831 + } else {
  832 + return true;
  833 + }
  834 + } else {
  835 + return false;
  836 + }
  837 + }
  838 + }
  839 +
  840 + class masterRecord {
  841 +
  842 + private $record = array(
  843 + 'id' => NULL,
  844 + 'zone' => NULL,
  845 + 'host' => '',
  846 + 'type' => '',
  847 + 'pri' => 0,
  848 + 'destination' => '',
  849 + 'ttl' => 0,
  850 + );
  851 + private $db = NULL;
  852 + private $err = '';
  853 +
  854 + public function __debugInfo() {
  855 + return array(
  856 + 'record' => $this->record,
  857 + 'err' => $this->err,
  858 + 'db' => NULL,
  859 + );
  860 + }
  861 +
  862 + public function __construct($param = NULL) {
  863 + global $db;
  864 + if (is_object($db)) {
  865 + $this->db = &$db;
  866 + }
  867 + if (!is_null($param)) {
  868 + return $this->setRecord($param);
  869 + }
  870 + return true;
  871 + }
  872 +
  873 + public function getId() {
  874 + return $this->record['id'];
  875 + }
  876 +
  877 + private function fill_record($param) {
  878 + foreach ($param as $key => $value) {
  879 + switch ($key) {
  880 + case 'id':
  881 + case 'pri':
  882 + case 'ttl':
  883 + case 'zone':
  884 + $this->record[$key] = intval($value);
  885 + break;
  886 + case 'host':
  887 + $this->record[$key] = idnToHost($value);
  888 + break;
  889 + case 'type':
  890 + $this->record[$key] = strtoupper($value);
  891 + break;
  892 + case 'destination':
  893 + switch ($this->record['type']) {
  894 + case 'MX':
  895 + case 'CNAME':
  896 + case 'SRV':
  897 + case 'PTR':
  898 + case 'NS':
  899 + $this->record[$key] = idnToHost($value);
  900 + break;
  901 + default:
  902 + $this->record[$key] = strval($value);
  903 + }
  904 + break;
  905 + default:
  906 + $this->record[$key] = $value;
  907 + }
  908 + }
  909 + }
  910 +
  911 + public function setRecord($param) {
  912 + if (is_string($param)) {
  913 + if (!$this->parseRecord($param)) {
  914 + return false;
  915 + }
  916 + } elseif (is_numeric($param)) {
  917 + $this->record['id'] = $param;
  918 + } elseif (is_array($param)) {
  919 + $this->fill_record($param);
  920 + } else {
  921 + ob_start();
  922 + var_dump($param);
  923 + $this->err .= "Unidentified parameter" . "\n" . ob_get_clean();
  924 + error_log($this->err);
  925 + return false;
  926 + }
  927 + return true;
  928 + }
  929 +
  930 + private function bind_time_format($value) {
  931 + if (preg_match(BIND_TIME_PATTERN, strtolower($value), $match)) {
  932 + $value = $match[1];
  933 + switch ($match[2]) {
  934 + case "s":
  935 + $multiplier = 1;
  936 + break;
  937 + case "m":
  938 + $multiplier = 60;
  939 + break;
  940 + case "h":
  941 + $multiplier = 3600;
  942 + break;
  943 + case "d":
  944 + $multiplier = 86400;
  945 + break;
  946 + case "w":
  947 + $multiplier = 604800;
  948 + break;
  949 + }
  950 + $value = $value*$multiplier;
  951 + }
  952 + return $value;
  953 + }
  954 +
  955 + private function parseRecord($buffer) {
  956 + if (preg_match(RECORD_PATTERN, $buffer, $match)) {
  957 + $this->record['host'] = $match[1];
  958 + if ($this->record['host'] == '') {
  959 + $this->record['host'] = '@';
  960 + }
  961 + $this->record['type'] = strtoupper($match[4]);
  962 + if (isset($match[2])) {
  963 + $this->record['ttl'] = intval($this->bind_time_format($match[2]));
  964 + } else {
  965 + $this->record['ttl'] = 0;
  966 + }
  967 + switch ($this->record['type']) {
  968 + case 'MX':
  969 + if (preg_match(MX_PATTERN, $match[5], $match)) {
  970 + $this->record['pri'] = intval($match[1]);
  971 + $this->record['destination'] = idnToHost($match[2]);
  972 + } else {
  973 + ob_start();
  974 + var_dump($buffer);
  975 + $this->err .= "MX cannot be parsed" . "\n" . ob_get_clean();
  976 + error_log($this->err);
  977 + return NULL;
  978 + }
  979 + break;
  980 + case 'SRV':
  981 + case 'CNAME':
  982 + case 'NS':
  983 + case 'PTR':
  984 + $this->record['destination'] = idnToHost($match[5]);
  985 + break;
  986 + case 'TXT':
  987 + $this->record['destination'] = idnToHost(preg_replace('/(^"+|"+$|"+\s*"+)/msi', '', trim($match[5])));
  988 + break;
  989 + default:
  990 + $this->record['destination'] = $match[5];
  991 + }
  992 + return true;
  993 + } else {
  994 + ob_start();
  995 + var_dump($buffer);
  996 + $this->err .= "Record cannot be parsed" . "\n" . ob_get_clean();
  997 + error_log($this->err);
  998 + return false;
  999 + }
  1000 + }
  1001 +
  1002 + public function getRecordRaw() {
  1003 + return $this->record;
  1004 + }
  1005 +
  1006 + public function getRecord() {
  1007 + $out = $this->record;
  1008 + $out['host'] = hostToIdn($out['host']);
  1009 + switch ($out['type']) {
  1010 + case 'MX':
  1011 + case 'SRV':
  1012 + case 'NS':
  1013 + case 'CNAME':
  1014 + case 'PTR':
  1015 + $out['destination'] = hostToIdn($out['destination']);
  1016 + }
  1017 + return $out;
  1018 + }
  1019 +
  1020 + private function is_identified() {
  1021 + return (is_numeric($this->record['id']) && ($this->record['id'] > 0));
  1022 + }
  1023 +
  1024 + public function loadRecord() {
  1025 + if ($this->is_identified()) {
  1026 + $res = $this->db->query('SELECT * FROM records WHERE id =' . $this->record['id']);
  1027 + if (MDB2::isError($res)) {
  1028 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1029 + error_log($this->err);
  1030 + return false;
  1031 + } else {
  1032 + $row = $res->fetchRow();
  1033 + if (is_array($row)) {
  1034 + $this->fill_record($row);
  1035 + return true;
  1036 + } else {
  1037 + return NULL;
  1038 + }
  1039 + }
  1040 + } else {
  1041 + ob_start();
  1042 + var_dump($this-record);
  1043 + $this->err .= "Record is not identified" . "\n" . ob_get_clean();
  1044 + error_log($this->err);
  1045 + return false;
  1046 + }
  1047 + }
  1048 +
  1049 + public function getErr() {
  1050 + return $this->err;
  1051 + }
  1052 +
  1053 + private function is_complete() {
  1054 + return (($this->record['zone'] > 0) &&
  1055 + ($this->record['type'] > '') &&
  1056 + (
  1057 + ($this->record['host'] > '') ||
  1058 + ($this->record['destination'] > '')
  1059 + ));
  1060 + }
  1061 +
  1062 + private function find_record() {
  1063 + $res = $this->db->query("SELECT id FROM records WHERE " .
  1064 + "zone = " . $this->record['zone'] . " AND " .
  1065 + "host = '" . $this->record['host'] . "' AND " .
  1066 + "ttl = " . $this->record['ttl'] . " AND " .
  1067 + "type = '" . $this->record['type'] . "' AND " .
  1068 + "pri = " . $this->record['pri'] . " AND " .
  1069 + "destination = '" . $this->record['destination'] . "'"
  1070 + );
  1071 + if (MDB2::isError($res)) {
  1072 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1073 + error_log($this->err);
  1074 + return 0;
  1075 + } else {
  1076 + $value = $res->fetchRow();
  1077 + return $value['id'];
  1078 + }
  1079 + }
  1080 +
  1081 + public function saveRecord() {
  1082 + if ($this->is_complete()) {
  1083 + if ($this->record['host'] == '') {
  1084 + $this->record['host'] = '@';
  1085 + } elseif ($this->record['destination'] == '') {
  1086 + $this->record['destination'] = '@';
  1087 + }
  1088 + if ($this->record['type'] == 'MX') {
  1089 + $this->record['pri'] = ($this->record['pri'] == 0) ? 10 : $this->record['pri'];
  1090 + } else {
  1091 + $this->record['pri'] = 0;
  1092 + }
  1093 + if ((is_numeric($this->record['id'])) && ($this->record['id'] > 0)) {
  1094 + $res = $this->db->query("UPDATE records SET " .
  1095 + "zone = " . $this->record['zone'] . ", " .
  1096 + "host = '" . $this->record['host'] . "', " .
  1097 + "ttl = " . $this->record['ttl'] . ", " .
  1098 + "type = '" . $this->record['type'] . "', " .
  1099 + "pri = " . $this->record['pri'] . ", " .
  1100 + "destination = '" . $this->record['destination'] .
  1101 + "' WHERE id = " . $this->record['id']
  1102 + );
  1103 + if (MDB2::isError($res)) {
  1104 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1105 + error_log($this->err);
  1106 + return false;
  1107 + } else {
  1108 + return $this->loadRecord();
  1109 + }
  1110 + } else {
  1111 + $id = $this->find_record();
  1112 + if ($id > 0) {
  1113 + $this->record['id'] = $id;
  1114 + return true;
  1115 + } else {
  1116 + $res = $this->db->query("INSERT INTO records (zone, host, ttl, type, pri, destination) VALUES (" .
  1117 + $this->record['zone'] . ", '" .
  1118 + $this->record['host'] . "', " .
  1119 + $this->record['ttl'] . ", '" .
  1120 + $this->record['type'] . "', " .
  1121 + $this->record['pri'] . ", '" .
  1122 + $this->record['destination'] . "')"
  1123 + );
  1124 + if (MDB2::isError($res)) {
  1125 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1126 + error_log($this->err);
  1127 + return false;
  1128 + } else {
  1129 + $id = $this->find_record();
  1130 + if ($id > 0) {
  1131 + $this->record['id'] = $id;
  1132 + return true;
  1133 + } else {
  1134 + if ($this->err == '') {
  1135 + ob_start();
  1136 + var_dump($this->record);
  1137 + $this->err .= "Unknown write error" . "\n" . ob_get_clean();
  1138 + error_log($this->err);
  1139 + }
  1140 + return false;
  1141 + }
  1142 + }
  1143 + }
  1144 + }
  1145 + } else {
  1146 + ob_start();
  1147 + var_dump($this->record);
  1148 + $this->err .= "Record is not complete" . "\n" . ob_get_clean();
  1149 + error_log($this->err);
  1150 + return false;
  1151 + }
  1152 + }
  1153 +
  1154 + public function eraseRecord() {
  1155 + if ($this->is_identified()) {
  1156 + $res = $this->db->query("DELETE FROM records WHERE id = " . $this->record['id']);
  1157 + if (MDB2::isError($res)) {
  1158 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1159 + error_log($this->err);
  1160 + return false;
  1161 + } else {
  1162 + return true;
  1163 + }
  1164 + } else {
  1165 + ob_start();
  1166 + var_dump($this->record);
  1167 + $this->err .= "Record is not set" . "\n" . ob_get_clean();
  1168 + error_log($this->err);
  1169 + return false;
  1170 + }
  1171 + }
  1172 + }
  1173 +
  1174 + class slaveZone {
  1175 + private $head = array(
  1176 + 'id' => NULL,
  1177 + 'name' => '',
  1178 + 'master' => '',
  1179 + 'owner' => 0,
  1180 + 'updated' => 'no',
  1181 + 'valid' => 'may',
  1182 + );
  1183 + private $db = NULL;
  1184 + private $err = '';
  1185 +
  1186 + public function __debugInfo() {
  1187 + return array(
  1188 + 'head' => $this->head,
  1189 + 'err' => $this->err,
  1190 + 'db' => NULL,
  1191 + );
  1192 + }
  1193 +
  1194 + public function __construct($param = NULL) {
  1195 + global $db;
  1196 + if (is_object($db)) {
  1197 + $this->db = &$db;
  1198 + }
  1199 + if (!is_null($param)) {
  1200 + return $this->setZoneHead($param);
  1201 + }
  1202 + return true;
  1203 + }
  1204 +
  1205 + public function setZoneHead($param) {
  1206 + if (is_string($param)) {
  1207 + $this->head['name'] = idnToHost($param);
  1208 + } elseif (is_numeric($param)) {
  1209 + $this->head['id'] = $param;
  1210 + } elseif (is_array($param)) {
  1211 + $this->fill_head($param);
  1212 + } else {
  1213 + ob_start();
  1214 + var_dump($param);
  1215 + $this->err .= "Unidentified parameter" . "\n" . ob_get_clean();
  1216 + error_log($this->err);
  1217 + return false;
  1218 + }
  1219 + return true;
  1220 + }
  1221 +
  1222 + private function fill_head($param) {
  1223 + foreach ($param as $key => $value) {
  1224 + switch ($key) {
  1225 + case 'id':
  1226 + case 'owner':
  1227 + $this->head[$key] = intval($value);
  1228 + break;
  1229 + case 'master':
  1230 + case 'name':
  1231 + $this->head[$key] = idnToHost($value);
  1232 + break;
  1233 + default:
  1234 + $this->head[$key] = $value;
  1235 + }
  1236 + }
  1237 + }
  1238 +
  1239 + private function is_identified() {
  1240 + return ((isset($this->head['id'])) || ($this->head['name'] > ''));
  1241 + }
  1242 +
  1243 + private function notIdent($complete = false) {
  1244 + ob_start();
  1245 + var_dump($this->head);
  1246 + $head = ob_get_clean();
  1247 + if ($complete) {
  1248 + $this->err .= "Zone is not complete" . "\n" . $head;
  1249 + error_log($this->err);
  1250 + } else {
  1251 + $this->err .= "Unidentified zone" . "\n" . $head;
  1252 + error_log($this->err);
  1253 + }
  1254 + }
  1255 +
  1256 + public function loadZoneHead() {
  1257 + if ($this->is_identified()) {
  1258 + $where = ' WHERE ';
  1259 + if (isset($this->head['id'])) {
  1260 + $where .= "id = " . $this->head['id'];
  1261 + } else {
  1262 + $where .= "name = '" . $this->head['name'] . "'";
  1263 + }
  1264 + $res = $this->db->query("SELECT * FROM slave_zones" . $where);
  1265 + if (MDB2::isError($res)) {
  1266 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1267 + error_log($this->err);
  1268 + return false;
  1269 + } else {
  1270 + $row = $res->fetchRow();
  1271 + if (is_array($row)) {
  1272 + $this->fill_head($row);
  1273 + return true;
  1274 + } else {
  1275 + return NULL;
  1276 + }
  1277 + }
  1278 + } else {
  1279 + notIdent();
  1280 + return false;
  1281 + }
  1282 + }
  1283 +
  1284 + public function eraseZone() {
  1285 + if (!$this->is_identified()) {
  1286 + ob_start();
  1287 + var_dump($this->head);
  1288 + $this->err .= "Zone head is not complete" . "\n" . ob_get_clean();
  1289 + error_log($this->err);
  1290 + return false;
  1291 + } else {
  1292 + $where = ' WHERE ';
  1293 + if ($this->head['id'] >>= 0) {
  1294 + $where .= "id = " . $this->head['id'];
  1295 + } else {
  1296 + $where .= "name = '" . $this->head['name'] . "'";
  1297 + }
  1298 + $res = $this->db->query("DELETE FROM slave_zones " . $where);
  1299 + if (MDB2::isError($res)) {
  1300 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1301 + error_log($this->err);
  1302 + return false;
  1303 + }
  1304 + $this->clearZone();
  1305 + return true;
  1306 + }
  1307 + }
  1308 +
  1309 + public function clearZone() {
  1310 +
  1311 + $hd = array(
  1312 + 'id' => NULL,
  1313 + 'name' => '',
  1314 + 'master' => '',
  1315 + 'owner' => 0,
  1316 + 'updated' => 'no',
  1317 + 'valid' => 'may',
  1318 + );
  1319 + }
  1320 +
  1321 + public function dumpZone($dig) {
  1322 + if ($this->is_identified()) {
  1323 + if (!$this->is_complete()) {
  1324 + $this->loadZoneHead();
  1325 + }
  1326 + $cmd = $dig . " axfr @" . $this->head['master'] . " " . $this->head['name'] . ". +time=2 +tries=2 +retry=1 2>/dev/null";
  1327 + unset($coutput);
  1328 + exec($cmd, $coutput, $exit);
  1329 + $out = '';
  1330 + foreach ($coutput as $line) {
  1331 + $val = preg_replace('/(^;.*$|\r|\n)/', '', $line);
  1332 + $out .= ($val > '') ? $val . "\n" : '';
  1333 + }
  1334 + return $out;
  1335 + } else {
  1336 + $this->err .= "Zone identification failed\n";
  1337 + error_log($this->err);
  1338 + return false;
  1339 + }
  1340 + }
  1341 +
  1342 + public function validateZone($dig) {
  1343 + $out = $this->dumpZone($dig);
  1344 + if ((isset($out)) && ($out > '')) {
  1345 + return true;
  1346 + } elseif (isset($out)) {
  1347 + $err = "Zone transfer failed\n";
  1348 + error_log($err);
  1349 + $this->err .= $err;
  1350 + }
  1351 + return false;
  1352 + }
  1353 +
  1354 + public function getZoneHeadRaw() {
  1355 + return $this->head;
  1356 + }
  1357 +
  1358 + public function getZoneHead() {
  1359 + $out = array();
  1360 + foreach ($this->head as $key => $value) {
  1361 + switch ($key) {
  1362 + case 'master':
  1363 + case 'name':
  1364 + $out[$key] = hostToIdn($value);
  1365 + break;
  1366 + default:
  1367 + $out[$key] = $value;
  1368 + }
  1369 + }
  1370 + return $out;
  1371 + }
  1372 +
  1373 + public function getErr() {
  1374 + return $this->err;
  1375 + }
  1376 +
  1377 + private function is_complete() {
  1378 + return (($this->head['name'] > '') && ($this->head['master'] > '') && ($this->head['owner'] >0));
  1379 + }
  1380 +
  1381 + public function doCommit() {
  1382 + if (!$this->is_complete()) {
  1383 + ob_start();
  1384 + var_dump($this->head);
  1385 + $this->err .= "Zone head is not complete" . "\n" . ob_get_clean();
  1386 + error_log($this->err);
  1387 + return false;
  1388 + }
  1389 + $res = $this->db->query("UPDATE slave_zones SET " .
  1390 + "updated = 'no' " .
  1391 + "WHERE id = " . $this->head['id']);
  1392 + if (MDB2::isError($res)) {
  1393 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1394 + error_log($this->err);
  1395 + return false;
  1396 + }
  1397 + return $this->loadZoneHead();
  1398 + }
  1399 +
  1400 + public function saveZoneHead() {
  1401 + if (!$this->is_complete()) {
  1402 + ob_start();
  1403 + var_dump($this->head);
  1404 + $this->err .= "Zone head is not complete" . "\n" . ob_get_clean();
  1405 + error_log($this->err);
  1406 + return false;
  1407 + }
  1408 + if (!isset($this->head['id'])) {
  1409 + $vld = (isset($this->head['valid'])) ? $this->head['valid'] : 'may';
  1410 + $upd = 'yes';
  1411 + $res = $this->db->query("INSERT INTO slave_zones " .
  1412 + "(name, master, valid, owner, updated) " .
  1413 + "VALUES ('" . $this->head['name'] .
  1414 + "', '" . $this->head['master'] .
  1415 + "', '" . $vld .
  1416 + "', " . $this->head['owner'] .
  1417 + ", '" . $upd .
  1418 + "')");
  1419 + if (MDB2::isError($res)) {
  1420 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1421 + error_log($this->err);
  1422 + return false;
  1423 + }
  1424 + return $this->loadZoneHead();
  1425 + } else {
  1426 + $vld = (($this->head['valid'] == 'yes') || ($this->head['valid'] == 'no')) ? $this->head['valid'] : 'may';
  1427 + $upd = ((isset($this->head['updated'])) && ($this->head['updated'] != 'del')) ? 'yes' : $this->head['updated'];
  1428 + $res = $this->db->query("UPDATE slave_zones SET " .
  1429 + "name = '" . $this->head['name'] . "', " .
  1430 + "master = '" . $this->head['master'] . "', " .
  1431 + "valid = '" . $vld . "', " .
  1432 + "owner = " . $this->head['owner'] . ", " .
  1433 + "updated = '" . $upd . "' " .
  1434 + "WHERE id = " . $this->head['id']);
  1435 + if (MDB2::isError($res)) {
  1436 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1437 + error_log($this->err);
  1438 + return false;
  1439 + }
  1440 + return $this->loadZoneHead();
  1441 + }
  1442 + }
  1443 +
  1444 + }
  1445 +
  1446 + class masterZone {
  1447 +
  1448 + private $head = array(
  1449 + 'id' => NULL,
  1450 + 'name' => '',
  1451 + 'pri_dns' => '',
  1452 + 'sec_dns' => '',
  1453 + 'serial' => 0,
  1454 + 'refresh' => 0,
  1455 + 'retry' => 0,
  1456 + 'expire' => 0,
  1457 + 'ttl' => 0,
  1458 + 'valid' => 'may',
  1459 + 'owner' => 0,
  1460 + 'updated' => 'no',
  1461 + 'secured' => 'no',
  1462 + );
  1463 + private $db = NULL;
  1464 + private $records = array();
  1465 + private $err = '';
  1466 + private $isloaded = FALSE;
  1467 + private $msg = '';
  1468 +
  1469 + public function __debugInfo() {
  1470 + return array(
  1471 + 'head' => $this->head,
  1472 + 'records' => $this->records,
  1473 + 'err' => $this->err,
  1474 + 'isloaded' => $this->isloaded,
  1475 + 'msg' => $this->msg,
  1476 + 'db' => NULL,
  1477 + );
  1478 + }
  1479 +
  1480 + public function __construct($param = NULL) {
  1481 + global $db;
  1482 + if (is_object($db)) {
  1483 + $this->db = &$db;
  1484 + }
  1485 + if (!is_null($param)) {
  1486 + return $this->setZoneHead($param);
  1487 + }
  1488 + return true;
  1489 + }
  1490 +
  1491 + public function getZoneHeadRaw() {
  1492 + return $this->head;
  1493 + }
  1494 +
  1495 + private function tab_to_space($line, $tab = 8, $nbsp = FALSE) {
  1496 + while (($t = mb_strpos($line,"\t")) !== FALSE) {
  1497 + $preTab = $t ? mb_substr($line, 0, $t) : '';
  1498 + $line = $preTab . str_repeat($nbsp?chr(7):' ', $tab-(mb_strlen($preTab)%$tab)) . mb_substr($line, $t+1);
  1499 + }
  1500 + return $nbsp ? str_replace($nbsp?chr(7):' ', '&nbsp;', $line) : $line;
  1501 + }
  1502 +
  1503 + private function split_text_record($line, $length = 76) {
  1504 + $line = $this->tab_to_space($line);
  1505 + $slices = $line;
  1506 + if(strlen($line) > $length) {
  1507 + $pos = stripos($line, "\"");
  1508 + if ($pos !== false) {
  1509 + if($pos>$length-2) {
  1510 + $slices = substr($line, 0, $pos) . "(\n";
  1511 + $line = $this->tab_to_space("\t\t\t\t\t" . substr($line,$pos) . " )");
  1512 + } else {
  1513 + $allline = substr($line,0,$pos) . "( " . substr($line,$pos) . " )";
  1514 + $slices = substr($allline,0,$length-1) . "\"\n";
  1515 + $line = $this->tab_to_space("\t\t\t\t\t\t \"" . substr($allline,$length-1));
  1516 + }
  1517 + while (strlen($line) > $length) {
  1518 + $slices .= substr($line, 0, $length-1) . "\"\n";
  1519 + $line = $this->tab_to_space("\t\t\t\t\t\t \"" . substr($line,$length-1));
  1520 + }
  1521 + if(strlen($line) > 0) { $slices .= $line; }
  1522 + }
  1523 + }
  1524 + return $slices;
  1525 + }
  1526 +
  1527 + private function prettyer($name,$ttl,$type,$pri,$target) {
  1528 + $line = str_pad($name, 31) . " " . $ttl . "\t" . "IN " . "$type";
  1529 + if (strlen($type)<5) {
  1530 + $line .= "\t";
  1531 + }
  1532 + $line .= " " . $pri;
  1533 + if (strlen($pri) > 0){
  1534 + $line .= " ";
  1535 + }
  1536 + if ($type == "TXT"){
  1537 + $target = "\"" . $target . "\"";
  1538 + }
  1539 + return $this->split_text_record($line . $target, 116);
  1540 + }
  1541 +
  1542 +
  1543 + public function getConf($hostmaster) {
  1544 + $out = "\$TTL " . $this->head['ttl'] . "\n";
  1545 + $out .= $this->prettyer("@", "", "SOA", "", $this->head['pri_dns'] . ". " . $hostmaster . ".") . " (\n";
  1546 + $out .= $this->tab_to_space("\t\t\t\t\t" . $this->head['serial'] . "\t; Serial\n") .
  1547 + $this->tab_to_space("\t\t\t\t\t" . $this->head['refresh'] . "\t\t; Refresh\n") .
  1548 + $this->tab_to_space("\t\t\t\t\t" . $this->head['retry'] . "\t\t; Retry\n") .
  1549 + $this->tab_to_space("\t\t\t\t\t" . $this->head['expire'] . "\t\t; Expire\n") .
  1550 + $this->tab_to_space("\t\t\t\t\t" . $this->head['ttl'] . ")\t\t; Negative Cache TTL\n;\n");
  1551 + foreach (array('pri_dns', 'sec_dns') as $ns) {
  1552 + $out .= ($this->head[$ns] != '') ? $this->prettyer("@",'','NS','',$this->head[$ns] . ".") . "\n" : "";
  1553 + }
  1554 + foreach ($this->getRecordsRaw() as $record) {
  1555 + $row = $record->getRecordRaw();
  1556 + $pri = ($row['type'] == 'MX') ? $row['pri'] : '';
  1557 + $ttl = ($row['ttl'] > 0) ? $row['ttl'] : '';
  1558 + $out .= $this->prettyer($row['host'],$ttl,$row['type'],$pri,$row['destination']) . "\n";
  1559 + }
  1560 + return $out;
  1561 + }
  1562 +
  1563 + public function getMsg() {
  1564 + return $this->msg;
  1565 + }
  1566 +
  1567 + public function writeZone($file, $hostmaster) {
  1568 + if (!$this->isloaded) {
  1569 + if (!$this->loadZone()) {
  1570 + $this->err .= "Unable to load zone\n";
  1571 + error_log ($this->err);
  1572 + return false;
  1573 + }
  1574 + }
  1575 + $zonedata = $this->getConf($hostmaster);
  1576 + $fh = fopen($file, "w");
  1577 + fwrite($fh, $zonedata . "\n");
  1578 + fclose($fh);
  1579 + return true;
  1580 + }
  1581 +
  1582 + public function validateZone($file, $hostmaster, $checkzonecmd) {
  1583 + if ($this->writeZone($file, $hostmaster)) {
  1584 + $cmd = $checkzonecmd . " -i local " . $this->head['name'] . " " . $file . " 2>/dev/stdout";
  1585 + unset($coutput);
  1586 + exec($cmd, $coutput, $exit);
  1587 + $rows = sizeof($coutput);
  1588 + $return[0] = ($coutput[$rows-1] == 'OK');
  1589 + if (($return[0]) && ($exit == 0)) {
  1590 + $rows--;
  1591 + $return[1] = '';
  1592 + } else {
  1593 + $return[1] = 'Exitcode: ' . $exit . "\n";
  1594 + }
  1595 + $return[1] .= implode("<br />", $coutput);
  1596 + if (!$return[0]) {
  1597 + $this->err = $return[1];
  1598 + error_log("ERROR\nCMD: " . $cmd . "\nExit: " . $exit . "\n" . implode("\n", $coutput));
  1599 + $this->head['valid'] = 'no';
  1600 + } else {
  1601 + $this->head['valid'] = 'yes';
  1602 + }
  1603 + $this->saveZoneHead();
  1604 + return $return;
  1605 + }
  1606 + $log = "Zone cannot be validate\n";
  1607 + $this->err .= $log;
  1608 + error_log($log);
  1609 + return array(false,"Problem in prerequisites\n");
  1610 + }
  1611 +
  1612 + public function getZoneHead() {
  1613 + $out = array();
  1614 + foreach ($this->head as $key => $value) {
  1615 + switch ($key) {
  1616 + case 'pri_dns':
  1617 + case 'sec_dns':
  1618 + case 'name':
  1619 + $out[$key] = hostToIdn($value);
  1620 + break;
  1621 + default:
  1622 + $out[$key] = $value;
  1623 + }
  1624 + }
  1625 + return $out;
  1626 + }
  1627 +
  1628 + public function getErr() {
  1629 + return $this->err;
  1630 + }
  1631 +
  1632 + public function getId() {
  1633 + return $this->head['id'];
  1634 + }
  1635 +
  1636 + private function fill_head($param) {
  1637 + foreach ($param as $key => $value) {
  1638 + switch ($key) {
  1639 + case 'id':
  1640 + case 'serial':
  1641 + case 'retry':
  1642 + case 'refresh':
  1643 + case 'expire':
  1644 + case 'ttl':
  1645 + case 'owner':
  1646 + $this->head[$key] = intval($value);
  1647 + break;
  1648 + case 'pri_dns':
  1649 + case 'sec_dns':
  1650 + case 'name':
  1651 + $this->head[$key] = idnToHost($value);
  1652 + break;
  1653 + default:
  1654 + $this->head[$key] = $value;
  1655 + }
  1656 + }
  1657 + }
  1658 +
  1659 + public function setZoneHead($param) {
  1660 + if (is_string($param)) {
  1661 + $this->head['name'] = idnToHost($param);
  1662 + } elseif (is_numeric($param)) {
  1663 + $this->head['id'] = $param;
  1664 + } elseif (is_array($param)) {
  1665 + $this->fill_head($param);
  1666 + } else {
  1667 + ob_start();
  1668 + var_dump($param);
  1669 + $this->err .= "Unidentified parameter" . "\n" . ob_get_clean();
  1670 + error_log($this->err);
  1671 + return false;
  1672 + }
  1673 + return true;
  1674 + }
  1675 +
  1676 + private function is_identified() {
  1677 + return ((isset($this->head['id'])) || ($this->head['name'] > ''));
  1678 + }
  1679 +
  1680 + private function notIdent($complete = false) {
  1681 + ob_start();
  1682 + var_dump($this->head);
  1683 + $head = ob_get_clean();
  1684 + if ($complete) {
  1685 + $this->err .= "Zone is not complete" . "\n" . $head;
  1686 + error_log($this->err);
  1687 + } else {
  1688 + $this->err .= "Unidentified zone" . "\n" . $head;
  1689 + error_log($this->err);
  1690 + }
  1691 + }
  1692 +
  1693 + public function loadZoneHead() {
  1694 + if ($this->is_identified()) {
  1695 + $where = ' WHERE ';
  1696 + if (isset($this->head['id'])) {
  1697 + $where .= "id = " . $this->head['id'];
  1698 + } else {
  1699 + $where .= "name = '" . $this->head['name'] . "'";
  1700 + }
  1701 + $res = $this->db->query("SELECT * FROM zones" . $where);
  1702 + if (MDB2::isError($res)) {
  1703 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1704 + error_log($this->err);
  1705 + return false;
  1706 + } else {
  1707 + $row = $res->fetchRow();
  1708 + if (is_array($row)) {
  1709 + $this->fill_head($row);
  1710 + return true;
  1711 + } else {
  1712 + return NULL;
  1713 + }
  1714 + }
  1715 + } else {
  1716 + $this->notIdent();
  1717 + return false;
  1718 + }
  1719 + }
  1720 +
  1721 + public function loadZoneRecords() {
  1722 + if ($this->is_complete()) {
  1723 + $res = $this->db->query("SELECT id FROM records WHERE zone = " . $this->head['id']);
  1724 + if (MDB2::isError($res)) {
  1725 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  1726 + error_log($this->err);
  1727 + return false;
  1728 + } else {
  1729 + while ($row = $res->fetchRow()) {
  1730 + $id = intval($row['id']);
  1731 + $this->records[$id] = new masterRecord($row);
  1732 + if (!$this->records[$id]->loadRecord()) {
  1733 + $this->err .= $this->records[$id]->getErr();
  1734 + error_log($this->err);
  1735 + return false;
  1736 + }
  1737 + }
  1738 + return true;
  1739 + }
  1740 + } else {
  1741 + notIdent(true);
  1742 + return false;
  1743 + }
  1744 + }
  1745 +
  1746 + public function eraseRecord($id) {
  1747 + $found = false;
  1748 + foreach ($this->records as $key => $entry) {
  1749 + if ($key == $id) {
  1750 + $found = true;
  1751 + if (!$entry->eraseRecord()) {
  1752 + $this->err .= $entry->getErr();
  1753 + error_log($this->err);
  1754 + return false;
  1755 + }
  1756 + }
  1757 + }
  1758 + if ($found) {
  1759 + $this->head['valid'] = 'may';
  1760 + $this->saveZoneHead();
  1761 + $this->records = array();
  1762 + $this->loadZoneRecords();
  1763 + return true;
  1764 + }
  1765 + $this->err .= "Record id not found" . "\n" . $id;
  1766 + error_log($this->err);
  1767 + return false;
  1768 + }
  1769 +
  1770 + public function addRecord($param = NULL) {
  1771 + if ((is_numeric($this->head['id'])) && ($this->head['id'] > 0)) {
  1772 + $nrec = new masterRecord($param);
  1773 + $nrec->setRecord(array( 'zone' => $this->head['id']));
  1774 + $urec = $nrec->getRecord();
  1775 + if ((
  1776 + ($urec['host'] > '') ||
  1777 + ($urec['destination'] > '')
  1778 + ) &&
  1779 + ($urec['host'] != $urec['destination']) &&
  1780 + ($urec['type'] > '')) {
  1781 + $this->records[] = $nrec;
  1782 + $this->head['valid'] = 'may';
  1783 + return true;
  1784 + } else {
  1785 + ob_start();
  1786 + var_dump($param);
  1787 + $this->err .= "Record is empty" . "\n" . ob_get_clean();
  1788 + error_log($this->err);
  1789 + return false;
  1790 + }
  1791 + } else {
  1792 + ob_start();
  1793 + var_dump($this->head);
  1794 + $this->err .= "Zone has not defined yet" . "\n" . ob_get_clean();
  1795 + error_log($this->err);
  1796 + return false;
  1797 + }
  1798 + }
  1799 +
  1800 + private function bind_time_format($value) {
  1801 + if (preg_match(BIND_TIME_PATTERN, strtolower($value), $match)) {
  1802 + $value = $match[1];
  1803 + switch ($match[2]) {
  1804 + case "s":
  1805 + $multiplier = 1;
  1806 + break;
  1807 + case "m":
  1808 + $multiplier = 60;
  1809 + break;
  1810 + case "h":
  1811 + $multiplier = 3600;
  1812 + break;
  1813 + case "d":
  1814 + $multiplier = 86400;
  1815 + break;
  1816 + case "w":
  1817 + $multiplier = 604800;
  1818 + break;
  1819 + }
  1820 + $value = $value*$multiplier;
  1821 + }
  1822 + return $value;
  1823 + }
  1824 +
  1825 +
  1826 + public function parseZone($rows, $zonename, $owner = 1) {
  1827 + if (!is_array($rows)) {
  1828 + ob_start();
  1829 + var_dump($rows);
  1830 + $this->err .= "Zone can be parsed from an array only" . "\n" . ob_get_clean();
  1831 + error_log($this->err);
  1832 + return false;
  1833 + } else {
  1834 + $this->clearZone();
  1835 + $this->head['name'] = idnToHost($zonename);
  1836 + $soafound = false;
  1837 + $soabegins = false;
  1838 + $soadata = '';
  1839 + $recrow = '';
  1840 + foreach ($rows as $row) {
  1841 + $row = preg_replace(COMMENT_PATTERN, ' ', trim($row));
  1842 + $row = ($row == " ") ? '' : $row;
  1843 + if ($soafound === false) {
  1844 + if (preg_match(ORIGIN_PATTERN, $row, $match)) {
  1845 + $zone = strtolower($match[1]);
  1846 + if ($zone != $expectedname) {
  1847 + $this->clearZone();
  1848 + $this->err .= "Given zone not matches with the expected (" . $zone . "<=>" . $expectedzone . ")";
  1849 + error_log($this->err);
  1850 + return false;
  1851 + }
  1852 + }
  1853 + if (preg_match(SOA_BEGINS_PATTERN, $row, $match)) {
  1854 + $soabegins = true;
  1855 + }
  1856 + if ($soabegins) {
  1857 + $soadata .= $row;
  1858 + }
  1859 + if (preg_match(FULL_SOA_PATTERN, $soadata, $match)) {
  1860 + $prins = $match[3];
  1861 + if(preg_match(TIMES_PATTERN, $match[5], $match2)) {
  1862 + $soafound = true;
  1863 + $serial = $match2[1];
  1864 + $refresh = $this->bind_time_format($match2[2]);
  1865 + $retry = $this->bind_time_format($match2[3]);
  1866 + $expire = $this->bind_time_format($match2[4]);
  1867 + $ttl = $this->bind_time_format($match2[5]);
  1868 + if (($this->setZoneHead(
  1869 + array(
  1870 + 'serial' => intval($serial),
  1871 + 'refresh' => intval($refresh),
  1872 + 'retry' => intval($retry),
  1873 + 'expire' => intval($expire),
  1874 + 'ttl' => intval($ttl),
  1875 + 'owner' => intval($owner),
  1876 + 'pri_dns' => strval($prins),
  1877 + 'sec_dns' => '##EMPTY##',
  1878 + ))) && ($this->saveZoneHead())) {
  1879 + $soafound = true;
  1880 + } else {
  1881 + $this->err .= "Head cannot be set" . "\n" . $soadata;
  1882 + $this->clearZone();
  1883 + return false;
  1884 + }
  1885 + } else {
  1886 + $this->err .= "SOA record cannot be parsed" . "\n" . $soadata;
  1887 + error_log($this->err);
  1888 + return false;
  1889 + }
  1890 + }
  1891 + } else {
  1892 + if ($recrow != '') {
  1893 + $rowpart = trim($row);
  1894 + $recrow .= $rowpart;
  1895 + $end = strpos($recrow, ')');
  1896 + if ($end > 0) {
  1897 + $recrow = substr($recrow, 0, $end);
  1898 + $recd = new masterRecord(array('zone' => $this->head['id']));
  1899 + if ($recd->setRecord($recrow)) {
  1900 + $parsed = $recd->getRecordRaw();
  1901 + if (
  1902 + ($this->head['sec_dns'] == '##EMPTY##') &&
  1903 + ($parsed['type'] == 'NS') &&
  1904 + ($parsed['destination'] != $self->head['pri_dns']) &&
  1905 + (
  1906 + ($parsed['host'] == '@') ||
  1907 + ($parsed['host'] == '')
  1908 + )
  1909 + ) {
  1910 + $self->head['sec_dns'] == $parsed['destination'];
  1911 + }
  1912 + $this->records[] = $recd;
  1913 + $recrow = '';
  1914 + } else {
  1915 + $this->err .= $recd->getErr();
  1916 + return false;
  1917 + }
  1918 + }
  1919 + } elseif ($row > '') {
  1920 + $end = strpos($row, '(');
  1921 + if ($end > 0) {
  1922 + $row = preg_replace('/\(/', '', $row);
  1923 + $recrow = $row;
  1924 + }
  1925 + $end = strpos($recrow, ')');
  1926 + if ($end > 0) {
  1927 + $recrow = substr($recrow, 0, $end);
  1928 + $recd = new masterRecord(array('zone' => $this->head['id']));
  1929 + if ($recd->setRecord($recrow, $this->head['name'])) {
  1930 + $this->records[] = $recd;
  1931 + $recrow = '';
  1932 + } else {
  1933 + $this->err .= $recd->getErr();
  1934 + return false;
  1935 + }
  1936 + } elseif ($recrow == '') {
  1937 + $recd = new masterRecord(array('zone' => $this->head['id']));
  1938 + if ($recd->setRecord($row, $this->head['name'])) {
  1939 + $this->records[] = $recd;
  1940 + } else {
  1941 + $this->err .= $recd->getErr();
  1942 + return false;
  1943 + }
  1944 + }
  1945 + }
  1946 + }
  1947 + }
  1948 + $recs = array();
  1949 + foreach ($this->records as $each) {
  1950 + $rhd = $each->getRecordRaw();
  1951 + if (($rhd['type'] == 'NS')) {
  1952 + if (($rhd['host'] == '@') && ($rhd['destination'] == $this->head['pri_dns'] . '.')) {
  1953 + continue;
  1954 + } elseif ($rhd['host'] == '@') {
  1955 + $this->head['sec_dns'] = ($this->head['sec_dns'] == '##EMPTY##') ? preg_replace('/\.$/', '', $rhd['destination']) : $this->head['sec_dns'];
  1956 + continue;
  1957 + }
  1958 + }
  1959 + $recs[] = $each;
  1960 + }
  1961 + $this->records = $recs;
  1962 + $this->saveZone();
  1963 + }
  1964 + return true;
  1965 + }
  1966 +
  1967 + public function loadZone() {
  1968 + $ret = $this->loadZoneHead();
  1969 + if (($ret) && (!is_null($this->head['id']))) {
  1970 + $this->isloaded = $this->loadZoneRecords();
  1971 + return $this->isloaded;
  1972 + } elseif (is_null($ret)) {
  1973 + return NULL;
  1974 + } else {
  1975 + return false;
  1976 + }
  1977 + }
  1978 +
  1979 + public function getRecordsRaw() {
  1980 + return $this->records;
  1981 + }
  1982 +
  1983 + public function getRecords($ordered = false) {
  1984 + $out = array();
  1985 + foreach ($this->records as $key => $each) {
  1986 + if ($ordered) {
  1987 + $out[] = $each->getRecord();
  1988 + } else {
  1989 + $out[$key] = $each->getRecord();
  1990 + }
  1991 + }
  1992 + return $out;
  1993 + }
  1994 +
  1995 + public function getZoneRaw() {
  1996 + $out = array();
  1997 + $out[] = $this->getZoneHeadRaw();
  1998 + $out[] = $this->getRecordsRaw();
  1999 + }
  2000 +
  2001 + public function getZone() {
  2002 + $out = array();
  2003 + $out[] = $this->getZoneHead();
  2004 + $out[] = $this->getRecords();
  2005 + return $out;
  2006 + }
  2007 +
  2008 + public function refresh_secure($zonedir) {
  2009 +
  2010 + $files = glob($zonedir . "{K,dsset-,}" . $this->head['name'] . ".{*private,*key,krf,}", GLOB_BRACE);
  2011 + $hit = 0;
  2012 + $names = array();
  2013 + foreach ($files as $key => $file) {
  2014 + $name = basename($file);
  2015 + switch ($name) {
  2016 + case $this->head['name'] . '.krf':
  2017 + case 'dsset-' . $this->head['name'] . '.':
  2018 + $hit++;
  2019 + break;
  2020 + default:
  2021 + $pattern = '/^K' . $this->head['name'] . '\.\+\d+\+\d+\.(private|key)/';
  2022 + preg_match($pattern, $name, $match);
  2023 + $hit += ($match[0] == $name) ? 1 : 0;
  2024 + }
  2025 + $names[$key] = $name;
  2026 + }
  2027 + $filesok = ($hit >= 8);
  2028 + $res = $this->db->query("SELECT id, dsset, krf FROM dnssec_zones WHERE zone = " . $this->head['id']);
  2029 + if (MDB2::isError($res)) {
  2030 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2031 + error_log($this->err);
  2032 + return false;
  2033 + }
  2034 + $dbok = ($res->numRows() == 1);
  2035 + if ($dbok) {
  2036 + $sel = $res->fetchRow();
  2037 + $id = $sel['id'];
  2038 + $dsset = $sel['dsset'];
  2039 + $krf = $sel['krf'];
  2040 + if ($filesok) {
  2041 + $dssetf = file_get_contents($zonedir . "dsset-" . $this->head['name'] . '.');
  2042 + $krff = file_get_contents($zonedir . $this->head['name'] . '.krf');
  2043 + if (($dsset != $dssetf) || ($krf != $krff)) {
  2044 + $res = $this->db->query("UPDATE dnssec_zones SET " .
  2045 + "dsset = '" . $dssetf . "', " .
  2046 + "krf = '" . $krff . "' WHERE id = " . $id
  2047 + );
  2048 + if (MDB2::isError($res)) {
  2049 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2050 + error_log($this->err);
  2051 + return false;
  2052 + }
  2053 + }
  2054 + $skeys = array();
  2055 + $keys = array();
  2056 + foreach ($names as $name) {
  2057 + $bn = basename($name, '.key');
  2058 + if ($bn . '.key' == $name) {
  2059 + $keys[] = $bn;
  2060 + $skeys[] = "'" . $bn . "'";
  2061 + }
  2062 + }
  2063 + $res = $this->db->query("UPDATE dnssec_keys SET archive = 'yes' WHERE " .
  2064 + "dszone = " . $id . " AND " .
  2065 + "archive = 'no'");
  2066 + if (MDB2::isError($res)) {
  2067 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2068 + error_log($this->err);
  2069 + return false;
  2070 + }
  2071 + $res = $this->db->query("UPDATE dnssec_keys SET archive = 'no' WHERE " .
  2072 + "dszone = " . $id . " AND " .
  2073 + "filename IN (" . implode(",", $skeys) . ")");
  2074 + if (MDB2::isError($res)) {
  2075 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2076 + error_log($this->err);
  2077 + return false;
  2078 + }
  2079 + foreach ($keys as $keyf) {
  2080 + $res = $this->db->query("SELECT id, fkey, fprivate FROM dnssec_keys WHERE filename = '" . $keyf . "' AND dszone = " . $id . " AND archive = 'no'");
  2081 + if (MDB2::isError($res)) {
  2082 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2083 + error_log($this->err);
  2084 + return false;
  2085 + }
  2086 + $kfile = file_get_contents($zonedir . $keyf . '.key');
  2087 + $pfile = file_get_contents($zonedir . $keyf . '.private');
  2088 + if ($res->numRows() == 0) {
  2089 + $this->db->query("INSERT INTO dnssec_keys (dszone, filename, fkey, fprivate, archive) VALUES ('" . $id . "','" .
  2090 + $keyf . "', '" . $kfile . "', '" .
  2091 + $pfile . "', 'no');"
  2092 + );
  2093 + if (MDB2::isError($res)) {
  2094 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2095 + error_log($this->err);
  2096 + return false;
  2097 + }
  2098 + } else {
  2099 + $row = $res->fetchRow();
  2100 + if (($kfile != $row['fkey']) || ($pfile != $row['fprivate'])) {
  2101 + $res = $this->db->query("UPDATE dnssec_keys SET " .
  2102 + "fkey = '" . $kfile . "', " .
  2103 + "fprivate = '" . $pfile .
  2104 + "' WHERE dszone = " . $id .
  2105 + " AND filename = '" . $keyf .
  2106 + "' AND archive = 'no'"
  2107 + );
  2108 + if (MDB2::isError($res)) {
  2109 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2110 + error_log($this->err);
  2111 + return false;
  2112 + }
  2113 + }
  2114 + }
  2115 + }
  2116 + } else {
  2117 + $fh = fopen($zonedir . "dsset-" . $this->head['name'] . ".", 'w');
  2118 + fwrite($fh, $sel['dsset']);
  2119 + fclose($fh);
  2120 + $fh = fopen($zonedir . $this->head['name'] . ".krf", 'w');
  2121 + fwrite($fh, $sel['krf'] . "\n\n");
  2122 + fclose($fh);
  2123 + $id = $sel['id'];
  2124 + $res = $this->db->query("SELECT * FROM dnssec_keys WHERE " .
  2125 + " dszone = " . $id . " AND " .
  2126 + " archive = 'no'"
  2127 + );
  2128 + if (MDB2::isError($res)) {
  2129 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2130 + error_log($this->err);
  2131 + return false;
  2132 + }
  2133 + if ($res->numRows() < 3) {
  2134 + $this->err .= "Missing key records\n";
  2135 + error_log($this->err);
  2136 + return false;
  2137 + }
  2138 + while ($rec = $res->fetchRow()) {
  2139 + foreach (array('private', 'key') as $ext) {
  2140 + $fh = fopen($zonedir . $rec['filename'] . "." . $ext, 'w');
  2141 + fwrite($fh, $rec['f' . $ext] . "\n");
  2142 + fclose($fh);
  2143 + }
  2144 + }
  2145 + }
  2146 + } elseif ($filesok) {
  2147 + $dsset = '';
  2148 + $krf = '';
  2149 + $keyset = array();
  2150 + foreach ($names as $name) {
  2151 + switch ($name) {
  2152 + case 'dsset-' . $this->head['name'] . '.':
  2153 + $dsset = file_get_contents($zonedir . $name);
  2154 + break;
  2155 + case $this->head['name'] . '.krf':
  2156 + $krf = file_get_contents($zonedir . $name);
  2157 + break;
  2158 + default:
  2159 + $ext = (basename($name, '.key') == $name) ? 'private' : 'key';
  2160 + $base = basename($name, '.' . $ext);
  2161 + $keyset[$base][$ext] = file_get_contents($zonedir . $name);
  2162 + }
  2163 + }
  2164 + if (($krf == '') || ($dsset == '')) {
  2165 + $this->err .= "Incomplete DSSET\n";
  2166 + error_log($this->err);
  2167 + return false;
  2168 + } else {
  2169 + $res = $this->db->query("INSERT INTO dnssec_zones (zone, krf, dsset) VALUES ('" .
  2170 + $this->head['id'] . "', '" .
  2171 + $krf . "', '" .
  2172 + $dsset . "')"
  2173 + );
  2174 + if (MDB2::isError($res)) {
  2175 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2176 + error_log($this->err);
  2177 + return false;
  2178 + }
  2179 + $res = $this->db->query("SELECT id FROM dnssec_zones WHERE zone = " . $this->head['id']);
  2180 + if (MDB2::isError($res)) {
  2181 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2182 + error_log($this->err);
  2183 + return false;
  2184 + }
  2185 + $rec = $res->fetchRow();
  2186 + $id = $rec['id'];
  2187 + $ok = 0;
  2188 + foreach ($keyset as $name => $arr) {
  2189 + $key = $arr['key'];
  2190 + $private = $arr['private'];
  2191 + if (($key == '') || ($private == '')) {
  2192 + $this->err .= "Incomplete KEYSET\n";
  2193 + error_log($this->err);
  2194 + return false;
  2195 + }
  2196 + $res = $this->db->query("INSERT INTO dnssec_keys (dszone, filename, fkey, fprivate, archive) VALUES (" .
  2197 + $id . ", '" .
  2198 + $name . "', '" .
  2199 + $key . "', '" .
  2200 + $private . "', 'no')"
  2201 + );
  2202 + if (MDB2::isError($res)) {
  2203 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2204 + error_log($this->err);
  2205 + return false;
  2206 + }
  2207 + $ok++;
  2208 + }
  2209 + if ($ok < 3) {
  2210 + $this->err .= "Not enough KEYSET\n";
  2211 + error_log($this->err);
  2212 + return false;
  2213 + }
  2214 + }
  2215 + } else {
  2216 + return false;
  2217 + }
  2218 + return true;
  2219 + }
  2220 +
  2221 + public function doSecure($zonedir, $zonesigner, $rollinit, $rollerconf) {
  2222 + if (!$this->is_complete()) {
  2223 + ob_start();
  2224 + var_dump($this->head);
  2225 + $this->err .= "Zone head is not complete" . "\n" . ob_get_clean();
  2226 + error_log($this->err);
  2227 + return false;
  2228 + }
  2229 + $err = $this->err;
  2230 + $param = (($this->refresh_secure($zonedir)) && ($err == $this->err)) ? '' : ' -genkeys -usensec3';
  2231 + if ($err != $this->err) return false;
  2232 + $cmd = $zonesigner . $param . " -zone " . $this->head['name'] . " " . $zonedir . $this->head['name'] . " 2>/dev/stdout";
  2233 + unset($coutput);
  2234 + $currpath = getcwd();
  2235 + chdir($zonedir);
  2236 + exec($cmd, $coutput, $signexit);
  2237 + chdir($currpath);
  2238 + if ($signexit != 0) {
  2239 + $this->err .= "Zonesigner error (" . $signexit . "):\n" . implode("\n",$coutput);
  2240 + error_log($this->err);
  2241 + return false;
  2242 + } else {
  2243 + $this->msg .= "Zonesigner output (" . $signexit . "):\n " . implode("\n ",$coutput) . "\n";
  2244 + }
  2245 + if (!$this->refresh_secure($zonedir)) return false;
  2246 + $rollf = file($rollerconf, FILE_IGNORE_NEW_LINES );
  2247 + $noroll = false;
  2248 + foreach ($rollf as $row) {
  2249 + preg_match('/^\s*roll\s+"' . $this->head['name'] . '"\s*/', $row, $match);
  2250 + $noroll = (isset($match[0]) && ($row == $match[0]));
  2251 + if ($noroll) break;
  2252 + }
  2253 + if (!$noroll) {
  2254 + $cmd = $rollinit . " " . $this->head['name'] .
  2255 + " -zone " . $zonedir . $this->head['name'] . '.signed' .
  2256 + " -keyrec " . $zonedir . $this->head['name'] . ".krf " .
  2257 + " -directory " . $zonedir . " 2>/dev/stdout";
  2258 + unset($coutput);
  2259 + exec($cmd, $coutput, $exit);
  2260 + if ($exit != 0) {
  2261 + $this->err .= "Rollerd error(" . $exit . "):\n" . implode("\n ",$coutput) . "\n";
  2262 + error_log($this->err);
  2263 + return false;
  2264 + } else {
  2265 + $fh = fopen($rollerconf, "a+");
  2266 + fwrite($fh, "\n# rollinit config for zone " . hostToIdn($this->head['name']) . ":\n" . implode("\n", $coutput) . "\n");
  2267 + fclose($fh);
  2268 + $this->msg .= "\n Rollerd for zone " . hostToIdn($this->head['name']) . " is configured now\n";
  2269 + }
  2270 + } else {
  2271 + $this->msg .= "\n Rollerd for zone " . hostToIdn($this->head['name']) . " has already set\n";
  2272 + }
  2273 + return true;
  2274 + }
  2275 +
  2276 + private function is_complete() {
  2277 + return (($this->head['name'] > '') &&
  2278 + ($this->head['pri_dns'] > '') &&
  2279 + ($this->head['sec_dns'] > '') &&
  2280 + ($this->head['refresh'] > 0) &&
  2281 + ($this->head['retry'] > 0) &&
  2282 + ($this->head['expire'] > 0) &&
  2283 + ($this->head['ttl'] > 0) &&
  2284 + ($this->head['owner'] > 0));
  2285 + }
  2286 +
  2287 + public function doCommit() {
  2288 + if (!$this->is_complete()) {
  2289 + ob_start();
  2290 + var_dump($this->head);
  2291 + $this->err .= "Zone head is not complete" . "\n" . ob_get_clean();
  2292 + error_log($this->err);
  2293 + return false;
  2294 + }
  2295 + $res = $this->db->query("UPDATE zones SET " .
  2296 + "updated = 'no' " .
  2297 + "WHERE id = " . $this->head['id']);
  2298 + if (MDB2::isError($res)) {
  2299 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2300 + error_log($this->err);
  2301 + return false;
  2302 + }
  2303 + return $this->loadZoneHead();
  2304 + }
  2305 +
  2306 + public function saveZoneHead() {
  2307 + if (!$this->is_complete()) {
  2308 + ob_start();
  2309 + var_dump($this->head);
  2310 + $this->err .= "Zone head is not complete" . "\n" . ob_get_clean();
  2311 + error_log($this->err);
  2312 + return false;
  2313 + }
  2314 + if (!isset($this->head['id'])) {
  2315 + $srl =intval(date('Ymd') . '01');
  2316 + $vld = (isset($this->head['valid'])) ? $this->head['valid'] : 'may';
  2317 + $upd = 'yes';
  2318 + $res = $this->db->query("INSERT INTO zones " .
  2319 + "(name, pri_dns, sec_dns, serial, refresh, retry, expire, ttl, valid, owner, updated, secured) " .
  2320 + "VALUES ('" . $this->head['name'] .
  2321 + "', '" . $this->head['pri_dns'] .
  2322 + "', '" . $this->head['sec_dns'] .
  2323 + "', " . $srl .
  2324 + ", " . $this->head['refresh'] .
  2325 + ", " . $this->head['retry'] .
  2326 + ", " . $this->head['expire'] .
  2327 + ", " . $this->head['ttl'] .
  2328 + ", '" . $vld .
  2329 + "', " . $this->head['owner'] .
  2330 + ", '" . $upd .
  2331 + "', '" . $this->head['secured'] . "')");
  2332 + if (MDB2::isError($res)) {
  2333 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2334 + error_log($this->err);
  2335 + return false;
  2336 + }
  2337 + return $this->loadZone();
  2338 + } else {
  2339 + $srl = ($this->head['updated'] == 'no') ? intval(date('Ymd') . '01') : $this->head['serial'];
  2340 + if ($srl <= $this->head['serial']) {
  2341 + $srl = ($this->head['updated'] == 'no') ? $this->head['serial'] + 1 : $this->head['serial'];
  2342 + }
  2343 + $vld = (($this->head['valid'] == 'yes') || ($this->head['valid'] == 'no')) ? $this->head['valid'] : 'may';
  2344 + $upd = ((isset($this->head['updated'])) && ($this->head['updated'] != 'del')) ? 'yes' : $this->head['updated'];
  2345 + $res = $this->db->query("UPDATE zones SET " .
  2346 + "name = '" . $this->head['name'] . "', " .
  2347 + "pri_dns = '" . $this->head['pri_dns'] . "', " .
  2348 + "sec_dns = '" . $this->head['sec_dns'] . "', " .
  2349 + "serial = " . $srl . ", " .
  2350 + "refresh = " . $this->head['refresh'] . ", " .
  2351 + "retry = " . $this->head['retry'] . ", " .
  2352 + "expire = " . $this->head['expire'] . ", " .
  2353 + "ttl = " . $this->head['ttl'] . ", " .
  2354 + "valid = '" . $vld . "', " .
  2355 + "owner = " . $this->head['owner'] . ", " .
  2356 + "updated = '" . $upd . "', " .
  2357 + "secured = '" . $this->head['secured'] . "' " .
  2358 + "WHERE id = " . $this->head['id']);
  2359 + if (MDB2::isError($res)) {
  2360 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2361 + error_log($this->err);
  2362 + return false;
  2363 + }
  2364 + return $this->loadZoneHead();
  2365 + }
  2366 + }
  2367 +
  2368 + public function saveZone() {
  2369 + if ($this->saveZoneHead()) {
  2370 + foreach ($this->records as $each) {
  2371 + if (!$each->saveRecord()) {
  2372 + $this->err = $each->getErr();
  2373 + return false;
  2374 + }
  2375 + }
  2376 + return true;
  2377 + } else {
  2378 + return false;
  2379 + }
  2380 + }
  2381 +
  2382 + public function eraseZone() {
  2383 + if (!$this->is_identified()) {
  2384 + ob_start();
  2385 + var_dump($this->head);
  2386 + $this->err .= "Zone head is not complete" . "\n" . ob_get_clean();
  2387 + error_log($this->err);
  2388 + return false;
  2389 + } else {
  2390 + $where = ' WHERE ';
  2391 + if ($this->head['id'] >>= 0) {
  2392 + $where .= "id = " . $this->head['id'];
  2393 + } else {
  2394 + $where .= "name = '" . $this->head['name'] . "'";
  2395 + }
  2396 + $res = $this->db->query("DELETE FROM zones " . $where);
  2397 + if (MDB2::isError($res)) {
  2398 + $this->err .= $res->getMessage() . "\n" . $res->getDebugInfo();
  2399 + error_log($this->err);
  2400 + return false;
  2401 + }
  2402 + $this->clearZone();
  2403 + return true;
  2404 + }
  2405 + }
  2406 +
  2407 + public function clearZone() {
  2408 + $id = $this->head['id'];
  2409 + $head = array(
  2410 + 'id' => $id,
  2411 + 'name' => '',
  2412 + 'pri_dns' => '',
  2413 + 'sec_dns' => '',
  2414 + 'serial' => 0,
  2415 + 'refresh' => 0,
  2416 + 'retry' => 0,
  2417 + 'expire' => 0,
  2418 + 'ttl' => 0,
  2419 + 'valid' => 'may',
  2420 + 'owner' => 0,
  2421 + 'updated' => 'no',
  2422 + 'secured' => 'no',
  2423 + );
  2424 + $this->head = $head;
  2425 + $this->records = array();
  2426 + $this->isloaded = FALSE;
  2427 + }
  2428 + }
... ...
mysql.sql 0 → 100644
  1 +++ a/mysql.sql
  1 +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  2 +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  3 +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  4 +/*!40101 SET NAMES utf8 */;
  5 +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
  6 +/*!40103 SET TIME_ZONE='+00:00' */;
  7 +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
  8 +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
  9 +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
  10 +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
  11 +
  12 +--
  13 +-- Table structure for table `dnssec_keys`
  14 +--
  15 +
  16 +DROP TABLE IF EXISTS `dnssec_keys`;
  17 +/*!40101 SET @saved_cs_client = @@character_set_client */;
  18 +/*!40101 SET character_set_client = utf8 */;
  19 +CREATE TABLE `dnssec_keys` (
  20 + `id` int(11) NOT NULL AUTO_INCREMENT,
  21 + `dszone` int(11) NOT NULL,
  22 + `filename` varchar(50) NOT NULL,
  23 + `fkey` text,
  24 + `fprivate` text,
  25 + `archive` varchar(3) DEFAULT NULL,
  26 + `refresh` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  27 + UNIQUE KEY `id` (`id`),
  28 + KEY `keyzon` (`dszone`),
  29 + KEY `arch` (`archive`),
  30 + KEY `filen` (`filename`),
  31 + CONSTRAINT `fkdskeys` FOREIGN KEY (`dszone`) REFERENCES `dnssec_zones` (`id`) ON DELETE CASCADE
  32 +) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8;
  33 +/*!40101 SET character_set_client = @saved_cs_client */;
  34 +
  35 +--
  36 +-- Dumping data for table `dnssec_keys`
  37 +--
  38 +
  39 +LOCK TABLES `dnssec_keys` WRITE;
  40 +/*!40000 ALTER TABLE `dnssec_keys` DISABLE KEYS */;
  41 +/*!40000 ALTER TABLE `dnssec_keys` ENABLE KEYS */;
  42 +UNLOCK TABLES;
  43 +
  44 +--
  45 +-- Table structure for table `dnssec_zones`
  46 +--
  47 +
  48 +DROP TABLE IF EXISTS `dnssec_zones`;
  49 +/*!40101 SET @saved_cs_client = @@character_set_client */;
  50 +/*!40101 SET character_set_client = utf8 */;
  51 +CREATE TABLE `dnssec_zones` (
  52 + `id` int(11) NOT NULL AUTO_INCREMENT,
  53 + `zone` int(11) NOT NULL,
  54 + `krf` text NOT NULL,
  55 + `dsset` text NOT NULL,
  56 + UNIQUE KEY `id` (`id`),
  57 + KEY `dsnam` (`zone`),
  58 + CONSTRAINT `fkdszones` FOREIGN KEY (`zone`) REFERENCES `zones` (`id`) ON DELETE CASCADE
  59 +) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
  60 +/*!40101 SET character_set_client = @saved_cs_client */;
  61 +
  62 +--
  63 +-- Dumping data for table `dnssec_zones`
  64 +--
  65 +
  66 +LOCK TABLES `dnssec_zones` WRITE;
  67 +/*!40000 ALTER TABLE `dnssec_zones` DISABLE KEYS */;
  68 +/*!40000 ALTER TABLE `dnssec_zones` ENABLE KEYS */;
  69 +UNLOCK TABLES;
  70 +
  71 +--
  72 +-- Table structure for table `options`
  73 +--
  74 +
  75 +DROP TABLE IF EXISTS `options`;
  76 +/*!40101 SET @saved_cs_client = @@character_set_client */;
  77 +/*!40101 SET character_set_client = utf8 */;
  78 +CREATE TABLE `options` (
  79 + `prefkey` varchar(20) NOT NULL,
  80 + `preftype` varchar(6) NOT NULL DEFAULT '',
  81 + `prefval` varchar(255) DEFAULT NULL,
  82 + UNIQUE KEY `prefkey` (`prefkey`),
  83 + KEY `ptype` (`preftype`),
  84 + KEY `pval` (`prefval`)
  85 +) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  86 +/*!40101 SET character_set_client = @saved_cs_client */;
  87 +
  88 +--
  89 +-- Dumping data for table `options`
  90 +--
  91 +
  92 +LOCK TABLES `options` WRITE;
  93 +/*!40000 ALTER TABLE `options` DISABLE KEYS */;
  94 +INSERT INTO `options` VALUES ('A','record','on'),('A6','record','off'),('AAAA','record','off'),('AFSDB','record','off'),('APL','record','off'),('ATMA','record','off'),('AXFR','record','off'),('CERT','record','off'),('CNAME','record','on'),('DNAME','record','off'),('DNSKEY','record','off'),('DS','record','off'),('EID','record','off'),('GPOS','record','off'),('HINFO','record','off'),('hostmaster','normal','postmaster.your.ns'),('ISDN','record','off'),('IXFR','record','off'),('KEY','record','off'),('KX','record','off'),('LOC','record','off'),('MAILB','record','off'),('master','normal','0.0.0.0'),('MINFO','record','off'),('MX','record','on'),('NAPTR','record','off'),('NIMLOC','record','off'),('NS','record','on'),('NSAP','record','off'),('NSAP-PTR','record','off'),('NSEC','record','off'),('NXT','record','off'),('OPT','record','off'),('prins','normal','your.master.ns'),('PTR','record','off'),('PX','record','off'),('range','normal','10'),('RP','record','off'),('RRSIG','record','off'),('RT','record','off'),('secns','normal','your.sec.ns'),('SIG','record','off'),('SINK','record','off'),('SRV','record','on'),('SSHFP','record','off'),('TKEY','record','off'),('TSIG','record','off'),('TXT','record','on'),('WKS','record','off'),('X25','record','off');
  95 +/*!40000 ALTER TABLE `options` ENABLE KEYS */;
  96 +UNLOCK TABLES;
  97 +
  98 +--
  99 +-- Table structure for table `records`
  100 +--
  101 +
  102 +DROP TABLE IF EXISTS `records`;
  103 +/*!40101 SET @saved_cs_client = @@character_set_client */;
  104 +/*!40101 SET character_set_client = utf8 */;
  105 +CREATE TABLE `records` (
  106 + `id` int(11) NOT NULL AUTO_INCREMENT,
  107 + `zone` int(11) NOT NULL DEFAULT '0',
  108 + `host` varchar(128) NOT NULL,
  109 + `ttl` int(11) DEFAULT NULL,
  110 + `type` varchar(8) NOT NULL,
  111 + `pri` int(11) NOT NULL DEFAULT '0',
  112 + `destination` varchar(4096) DEFAULT NULL,
  113 + UNIQUE KEY `id` (`id`),
  114 + KEY `reczone` (`zone`),
  115 + KEY `rech` (`host`),
  116 + CONSTRAINT `fkrecords` FOREIGN KEY (`zone`) REFERENCES `zones` (`id`) ON DELETE CASCADE
  117 +) ENGINE=InnoDB AUTO_INCREMENT=765 DEFAULT CHARSET=utf8;
  118 +/*!40101 SET character_set_client = @saved_cs_client */;
  119 +
  120 +--
  121 +-- Dumping data for table `records`
  122 +--
  123 +
  124 +LOCK TABLES `records` WRITE;
  125 +/*!40000 ALTER TABLE `records` DISABLE KEYS */;
  126 +/*!40000 ALTER TABLE `records` ENABLE KEYS */;
  127 +UNLOCK TABLES;
  128 +
  129 +--
  130 +-- Table structure for table `slave_zones`
  131 +--
  132 +
  133 +DROP TABLE IF EXISTS `slave_zones`;
  134 +/*!40101 SET @saved_cs_client = @@character_set_client */;
  135 +/*!40101 SET character_set_client = utf8 */;
  136 +CREATE TABLE `slave_zones` (
  137 + `id` int(11) NOT NULL AUTO_INCREMENT,
  138 + `name` varchar(128) NOT NULL,
  139 + `master` varchar(128) DEFAULT NULL,
  140 + `owner` int(11) NOT NULL DEFAULT '0',
  141 + `updated` varchar(3) NOT NULL DEFAULT 'yes',
  142 + `valid` varchar(3) NOT NULL DEFAULT 'may',
  143 + UNIQUE KEY `id` (`id`),
  144 + UNIQUE KEY `sznam` (`name`),
  145 + KEY `szupd` (`updated`),
  146 + KEY `szow` (`owner`)
  147 +) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
  148 +/*!40101 SET character_set_client = @saved_cs_client */;
  149 +
  150 +--
  151 +-- Dumping data for table `slave_zones`
  152 +--
  153 +
  154 +LOCK TABLES `slave_zones` WRITE;
  155 +/*!40000 ALTER TABLE `slave_zones` DISABLE KEYS */;
  156 +/*!40000 ALTER TABLE `slave_zones` ENABLE KEYS */;
  157 +UNLOCK TABLES;
  158 +
  159 +--
  160 +-- Table structure for table `users`
  161 +--
  162 +
  163 +DROP TABLE IF EXISTS `users`;
  164 +/*!40101 SET @saved_cs_client = @@character_set_client */;
  165 +/*!40101 SET character_set_client = utf8 */;
  166 +CREATE TABLE `users` (
  167 + `id` int(11) NOT NULL AUTO_INCREMENT,
  168 + `username` varchar(32) NOT NULL,
  169 + `realname` varchar(50) DEFAULT NULL,
  170 + `password` varchar(32) NOT NULL,
  171 + `admin` varchar(3) NOT NULL DEFAULT 'no',
  172 + UNIQUE KEY `id` (`id`),
  173 + UNIQUE KEY `usnam` (`username`),
  174 + KEY `uspass` (`password`),
  175 + KEY `admin` (`admin`)
  176 +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
  177 +/*!40101 SET character_set_client = @saved_cs_client */;
  178 +
  179 +--
  180 +-- Dumping data for table `users`
  181 +--
  182 +
  183 +LOCK TABLES `users` WRITE;
  184 +/*!40000 ALTER TABLE `users` DISABLE KEYS */;
  185 +INSERT INTO `users` VALUES (1,'admin','Administrator','3c99cbdb5c15684e4fc190f4f17e443c','yes');
  186 +/*!40000 ALTER TABLE `users` ENABLE KEYS */;
  187 +UNLOCK TABLES;
  188 +
  189 +--
  190 +-- Table structure for table `zones`
  191 +--
  192 +
  193 +DROP TABLE IF EXISTS `zones`;
  194 +/*!40101 SET @saved_cs_client = @@character_set_client */;
  195 +/*!40101 SET character_set_client = utf8 */;
  196 +CREATE TABLE `zones` (
  197 + `id` int(11) NOT NULL AUTO_INCREMENT,
  198 + `name` varchar(64) NOT NULL,
  199 + `pri_dns` varchar(128) DEFAULT NULL,
  200 + `sec_dns` varchar(128) DEFAULT NULL,
  201 + `serial` int(11) NOT NULL DEFAULT '0',
  202 + `refresh` int(11) NOT NULL DEFAULT '604800',
  203 + `retry` int(11) NOT NULL DEFAULT '86400',
  204 + `expire` int(11) NOT NULL DEFAULT '2419200',
  205 + `ttl` int(11) NOT NULL DEFAULT '604800',
  206 + `owner` int(11) NOT NULL DEFAULT '1',
  207 + `valid` varchar(3) NOT NULL DEFAULT 'may',
  208 + `updated` varchar(3) NOT NULL DEFAULT 'yes',
  209 + `secured` varchar(3) NOT NULL DEFAULT 'no',
  210 + UNIQUE KEY `id` (`id`),
  211 + UNIQUE KEY `zonnam` (`name`),
  212 + KEY `zonval` (`valid`),
  213 + KEY `zonow` (`owner`),
  214 + KEY `zonupd` (`updated`)
  215 +) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8;
  216 +/*!40101 SET character_set_client = @saved_cs_client */;
  217 +
  218 +--
  219 +-- Dumping data for table `zones`
  220 +--
  221 +
  222 +LOCK TABLES `zones` WRITE;
  223 +/*!40000 ALTER TABLE `zones` DISABLE KEYS */;
  224 +/*!40000 ALTER TABLE `zones` ENABLE KEYS */;
  225 +UNLOCK TABLES;
  226 +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
  227 +
  228 +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
  229 +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
  230 +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
  231 +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  232 +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  233 +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  234 +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
  235 +
  236 +-- Dump completed on 2015-12-26 22:28:06
... ...
pgsql.sql 0 → 100644
  1 +++ a/pgsql.sql
  1 +START TRANSACTION;
  2 +SET standard_conforming_strings=off;
  3 +SET escape_string_warning=off;
  4 +SET CONSTRAINTS ALL DEFERRED;
  5 +
  6 +CREATE TABLE "dnssec_keys" (
  7 + "id" integer NOT NULL,
  8 + "dszone" integer NOT NULL,
  9 + "filename" varchar(100) NOT NULL,
  10 + "fkey" text ,
  11 + "fprivate" text ,
  12 + "archive" varchar(6) DEFAULT NULL,
  13 + "refresh" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  14 + UNIQUE ("id")
  15 +);
  16 +
  17 +CREATE TABLE "dnssec_zones" (
  18 + "id" integer NOT NULL,
  19 + "zone" integer NOT NULL,
  20 + "krf" text NOT NULL,
  21 + "dsset" text NOT NULL,
  22 + UNIQUE ("id")
  23 +);
  24 +
  25 +CREATE TABLE "options" (
  26 + "prefkey" varchar(40) NOT NULL,
  27 + "preftype" varchar(12) NOT NULL DEFAULT '',
  28 + "prefval" varchar(510) DEFAULT NULL,
  29 + UNIQUE ("prefkey")
  30 +);
  31 +
  32 +INSERT INTO "options" VALUES ('A','record','on'),('A6','record','off'),('AAAA','record','off'),('AFSDB','record','off'),('APL','record','off'),('ATMA','record','off'),('AXFR','record','off'),('CERT','record','off'),('CNAME','record','on'),('DNAME','record','off'),('DNSKEY','record','off'),('DS','record','off'),('EID','record','off'),('GPOS','record','off'),('HINFO','record','off'),('hostmaster','normal','postmaster.your.ns'),('ISDN','record','off'),('IXFR','record','off'),('KEY','record','off'),('KX','record','off'),('LOC','record','off'),('MAILB','record','off'),('master','normal','0.0.0.0'),('MINFO','record','off'),('MX','record','on'),('NAPTR','record','off'),('NIMLOC','record','off'),('NS','record','on'),('NSAP','record','off'),('NSAP-PTR','record','off'),('NSEC','record','off'),('NXT','record','off'),('OPT','record','off'),('prins','normal','your.master.ns'),('PTR','record','off'),('PX','record','off'),('range','normal','10'),('RP','record','off'),('RRSIG','record','off'),('RT','record','off'),('secns','normal','your.sec.ns'),('SIG','record','off'),('SINK','record','off'),('SRV','record','on'),('SSHFP','record','off'),('TKEY','record','off'),('TSIG','record','off'),('TXT','record','on'),('WKS','record','off'),('X25','record','off');
  33 +CREATE TABLE "records" (
  34 + "id" integer NOT NULL,
  35 + "zone" integer NOT NULL DEFAULT '0',
  36 + "host" varchar(256) NOT NULL,
  37 + "ttl" integer DEFAULT NULL,
  38 + "type" varchar(16) NOT NULL,
  39 + "pri" integer NOT NULL DEFAULT '0',
  40 + "destination" varchar(8192) DEFAULT NULL,
  41 + UNIQUE ("id")
  42 +);
  43 +
  44 +CREATE TABLE "slave_zones" (
  45 + "id" integer NOT NULL,
  46 + "name" varchar(256) NOT NULL,
  47 + "master" varchar(256) DEFAULT NULL,
  48 + "owner" integer NOT NULL DEFAULT '0',
  49 + "updated" varchar(6) NOT NULL DEFAULT 'yes',
  50 + "valid" varchar(6) NOT NULL DEFAULT 'may',
  51 + UNIQUE ("id"),
  52 + UNIQUE ("name")
  53 +);
  54 +
  55 +CREATE TABLE "users" (
  56 + "id" integer NOT NULL,
  57 + "username" varchar(64) NOT NULL,
  58 + "realname" varchar(100) DEFAULT NULL,
  59 + "password" varchar(64) NOT NULL,
  60 + "admin" varchar(6) NOT NULL DEFAULT 'no',
  61 + UNIQUE ("id"),
  62 + UNIQUE ("username")
  63 +);
  64 +
  65 +INSERT INTO "users" VALUES (1,'admin','Administrator','3c99cbdb5c15684e4fc190f4f17e443c','yes');
  66 +CREATE TABLE "zones" (
  67 + "id" integer NOT NULL,
  68 + "name" varchar(128) NOT NULL,
  69 + "pri_dns" varchar(256) DEFAULT NULL,
  70 + "sec_dns" varchar(256) DEFAULT NULL,
  71 + "serial" integer NOT NULL DEFAULT '0',
  72 + "refresh" integer NOT NULL DEFAULT '604800',
  73 + "retry" integer NOT NULL DEFAULT '86400',
  74 + "expire" integer NOT NULL DEFAULT '2419200',
  75 + "ttl" integer NOT NULL DEFAULT '604800',
  76 + "owner" integer NOT NULL DEFAULT '1',
  77 + "valid" varchar(6) NOT NULL DEFAULT 'may',
  78 + "updated" varchar(6) NOT NULL DEFAULT 'yes',
  79 + "secured" varchar(6) NOT NULL DEFAULT 'no',
  80 + UNIQUE ("id"),
  81 + UNIQUE ("name")
  82 +);
  83 +
  84 +
  85 +-- Post-data save --
  86 +COMMIT;
  87 +START TRANSACTION;
  88 +
  89 +-- Typecasts --
  90 +
  91 +-- Foreign keys --
  92 +ALTER TABLE "dnssec_keys" ADD CONSTRAINT "fkdskeys" FOREIGN KEY ("dszone") REFERENCES "dnssec_zones" ("id") ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
  93 +CREATE INDEX ON "dnssec_keys" ("dszone");
  94 +ALTER TABLE "dnssec_zones" ADD CONSTRAINT "fkdszones" FOREIGN KEY ("zone") REFERENCES "zones" ("id") ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
  95 +CREATE INDEX ON "dnssec_zones" ("zone");
  96 +ALTER TABLE "records" ADD CONSTRAINT "fkrecords" FOREIGN KEY ("zone") REFERENCES "zones" ("id") ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
  97 +CREATE INDEX ON "records" ("zone");
  98 +
  99 +-- Sequences --
  100 +CREATE SEQUENCE dnssec_keys_id_seq;
  101 +SELECT setval('dnssec_keys_id_seq', max(id)) FROM dnssec_keys;
  102 +ALTER TABLE "dnssec_keys" ALTER COLUMN "id" SET DEFAULT nextval('dnssec_keys_id_seq');
  103 +CREATE SEQUENCE dnssec_zones_id_seq;
  104 +SELECT setval('dnssec_zones_id_seq', max(id)) FROM dnssec_zones;
  105 +ALTER TABLE "dnssec_zones" ALTER COLUMN "id" SET DEFAULT nextval('dnssec_zones_id_seq');
  106 +CREATE SEQUENCE records_id_seq;
  107 +SELECT setval('records_id_seq', max(id)) FROM records;
  108 +ALTER TABLE "records" ALTER COLUMN "id" SET DEFAULT nextval('records_id_seq');
  109 +CREATE SEQUENCE slave_zones_id_seq;
  110 +SELECT setval('slave_zones_id_seq', max(id)) FROM slave_zones;
  111 +ALTER TABLE "slave_zones" ALTER COLUMN "id" SET DEFAULT nextval('slave_zones_id_seq');
  112 +CREATE SEQUENCE users_id_seq;
  113 +SELECT setval('users_id_seq', max(id)) FROM users;
  114 +ALTER TABLE "users" ALTER COLUMN "id" SET DEFAULT nextval('users_id_seq');
  115 +CREATE SEQUENCE zones_id_seq;
  116 +SELECT setval('zones_id_seq', max(id)) FROM zones;
  117 +ALTER TABLE "zones" ALTER COLUMN "id" SET DEFAULT nextval('zones_id_seq');
  118 +
  119 +-- Full Text keys --
  120 +
  121 +COMMIT;
... ...
src/chpass.php 0 → 100644
  1 +++ a/src/chpass.php
  1 +<?php
  2 +/*
  3 + * chpass.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + *********************************************************************
  23 + *
  24 + * Provides the ligin form
  25 + *
  26 + *
  27 + */
  28 +
  29 +require_once "include.php";
  30 +
  31 +$smarty->assign("pagetitle", "Change password");
  32 +$smarty->assign("template", "chpass.tpl");
  33 +$smarty->assign("help", help("chpass"));
  34 +$smarty->assign("menu_button", menu_buttons());
  35 +$smarty->display("main.tpl");
  36 +?>
... ...
src/commit.php 0 → 100644
  1 +++ a/src/commit.php
  1 +<?php
  2 +/*
  3 + * commit.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + **********************************************************************
  23 + *
  24 + * Applies the zone/record changes to the system
  25 + *
  26 + */
  27 +
  28 +require_once "include.php";
  29 +
  30 +$dslave = array();
  31 +$dmaster = array();
  32 +
  33 +$dslave = $user->getDeletedZones('slave');
  34 +$dmaster = $user->getDeletedZones('master');
  35 +$cslave = $user->getCommitableZones('slave');
  36 +$cmaster = $user->getCommitableZones('master');
  37 +$allz = count($dmaster) + count($dslave) + count($cmaster) + count($cslave);
  38 +$done = 0;
  39 +
  40 +if (isset($_SERVER['HTTP_REFERER']) &&
  41 + (preg_replace('/https?:\/\/[^\/]+/', '', $_SERVER['HTTP_REFERER']) != $_SERVER['PHP_SELF']) &&
  42 + (!isset($_GET['commit'])) &&
  43 + ($allz >0)) {
  44 + $smarty->assign("pagetitle", "Commit changes");
  45 + $smarty->assign("template", "commit.tpl");
  46 + $smarty->assign("help", help("precommit"));
  47 + $smarty->assign("menu_button", menu_buttons());
  48 + $smarty->display("main.tpl");
  49 + die();
  50 +} elseif ((isset($_GET['commit'])) && ($_GET['commit'] != 'y')) {
  51 + problem();
  52 +} elseif (count($dmaster) +
  53 + count($dslave) +
  54 + count($cmaster) +
  55 + count($cslave) == 0) {
  56 + problem("nocommit");
  57 +}
  58 +
  59 +$bind = new bindConfig($conf->conf);
  60 +
  61 +$deleted = '';
  62 +$commited = '';
  63 +$error = '';
  64 +
  65 +$delm = (count($dmaster) > 0) ? "<strong>" . "Deleting master records" . "</strong>\n\n" : '';
  66 +
  67 +foreach ($dmaster as $master) {
  68 + $dmz = new masterZone(intval($master['id']));
  69 + $dmz->loadZoneHead();
  70 + $hd = $dmz->getZoneHead();
  71 + $hdr = $dmz->getZoneHeadRaw();
  72 + $dmz->eraseZone();
  73 + $err = $dmz->getErr();
  74 + if ($err > '') {
  75 + $error .= "<u>" . $hd['name'] . ":</u> " . "Error in deleting" . "\n" . $err . '\n\n';
  76 + } else {
  77 + $deleted .= "<u>" . $hd['name'] . ":</u> Deleting success.\n\n";
  78 + $bind->eraseConfig($hdr['name']);
  79 + $done++;
  80 + }
  81 +}
  82 +
  83 +$error = ($error > '') ? $delm . $error : '';
  84 +$deleted = ($deleted > '') ? $delm . $deleted : '';
  85 +
  86 +$errors = '';
  87 +$deleteds = '';
  88 +$delm .= (count($dslave) > 0) ? "<strong>" . "Deleting slave records" . "</strong>\n\n" : '';
  89 +$delm = ($deleted > '') ? "\n" . $delm : $delm;
  90 +
  91 +foreach ($dslave as $slave) {
  92 + $dsz = new slaveZone(intval($slave['id']));
  93 + $dsz->loadZoneHead();
  94 + $hd = $dsz->getZoneHead();
  95 + $hdr = $dsz->getZoneHeadRaw();
  96 + $dsz->eraseZone();
  97 + $err = $dsz->getErr();
  98 + if ($err > '') {
  99 + $errors .= "<u>" . $hd['name'] . ":</u> Error in deleting\n" . $err . '\n\n';
  100 + } else {
  101 + $deleteds .= "<u>" . $hd['name'] . "</u>: Deleting success.\n\n";
  102 + $bind->eraseConfig($hdr['name']);
  103 + $done++;
  104 + }
  105 +}
  106 +
  107 +$error .= ($errors > '') ? $delm . $errors : '';
  108 +$deleted .= ($deleteds > '') ? $delm . $deleteds : '';
  109 +$errors = '';
  110 +
  111 +$comm = (count($cmaster) > 0) ? "<strong>" . "Committing master records" . "</strong>\n\n" : '';
  112 +$mcomm = '';
  113 +
  114 +foreach ($cmaster as $master) {
  115 + $cmz = new masterZone(intval($master['id']));
  116 + $cmz->loadZoneHead();
  117 + $hd = $cmz->getZoneHead();
  118 + $hdr = $cmz->getZoneHeadRaw();
  119 + $cmz->writeZone($conf->path . $hdr['name'], $conf->hostMaster);
  120 + $zarray = array(
  121 + 'type' => 'master',
  122 + 'file' => $hdr['name'],
  123 + );
  124 + $zarray['file'] .= (($hd['secured'] == 'yes') && ($cmz->doSecure($conf->path, $conf->zoneSigner, $conf->rollInit, $conf->rollerConf))) ? ".signed" : "";
  125 + $cmz->doCommit();
  126 + $err = $cmz->getErr();
  127 + if ($err > '') {
  128 + $errors .= "<u>" . $hd['name'] . ":</u> Error in committing\n" . $err . '\n\n';
  129 + } else {
  130 + $mcomm .= "<u>" . $hd['name'] . "</u>: Committing success.\n" . $cmz->getMsg() . "\n";
  131 + $bind->addConfig($hdr['name'], $zarray);
  132 + $done++;
  133 + }
  134 +}
  135 +
  136 +$error .= ($errors > '') ? $comm . $errors : '';
  137 +$commited .= ($mcomm > '') ? $comm . $mcomm: '';
  138 +$errors = '';
  139 +
  140 +$comm = (count($cslave) > 0) ? "<strong>" . "Committing slave records" . "</strong>\n\n" : '';
  141 +$commited .= ($comm > '') ? "\n" : '';
  142 +$scomm = '';
  143 +
  144 +foreach ($cslave as $slave) {
  145 + $csz = new slaveZone(intval($slave['id']));
  146 + $csz->loadZoneHead();
  147 + $hd = $csz->getZoneHead();
  148 + $hdr = $csz->getZoneHeadRaw();
  149 + $err = $csz->getErr();
  150 + if ($err > '') {
  151 + $errors .= "<u>" . $hd['name'] . ":</u> Error in committing\n" . $err . '\n\n';
  152 + } else {
  153 + $csz->doCommit();
  154 + $scomm .= "<u>" . $hd['name'] . "</u>: Committing success.\n\n";
  155 + $bind->addConfig($hdr['name'], array (
  156 + 'type' => 'slave',
  157 + 'masters' => $hdr['master'],
  158 + 'file' => $hdr['name'],
  159 + ));
  160 + $done++;
  161 + }
  162 +}
  163 +
  164 +$error .= ($errors > '') ? $comm . $errors : '';
  165 +$commited .= ($scomm > '') ? $comm . $scomm : '';
  166 +$bind->saveConfig($conf->conf);
  167 +
  168 +if ($done > 0) {
  169 + $cmd = $conf->rndc . " reload 2> /dev/stdout";
  170 + unset($coutput);
  171 + exec($cmd, $coutput, $exit);
  172 + if ($exit != 0) {
  173 + $error .= "Rndc error(" . $exit . "):\n" . implode("\n", $coutput);
  174 + } else {
  175 + $multi = ($done > 1) ? "zones" : "zone";
  176 + $commited .= "<b>" . $done . " " . $multi . " has been commited and reloaded:" . "</b>\n " . implode("\n ", $coutput) . "\n";
  177 + }
  178 +} else {
  179 + $commited .= "<b>" . "There wasn't commited zone" . "</b>";
  180 +}
  181 +
  182 +$error = implode("<br />", explode("\n", $error));
  183 +
  184 +$smarty->assign("popuperror", $error);
  185 +$smarty->assign("success", $deleted . $commited);
  186 +$smarty->assign("pagetitle", "Commit changes");
  187 +$smarty->assign("template", "commitdone.tpl");
  188 +$smarty->assign("help", help("commit"));
  189 +$smarty->assign("menu_button", menu_buttons());
  190 +$smarty->display("main.tpl");
  191 +?>
... ...
src/convert.php 0 → 100644
  1 +++ a/src/convert.php
  1 +<?php
  2 +/*
  3 + * convert.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + *********************************************************************
  23 + *
  24 + * Processes the inport form and do the import.
  25 + *
  26 + */
  27 +
  28 +require_once "include.php";
  29 +
  30 +$out = array();
  31 +
  32 +if($user->isAdmin()) {
  33 + if(($_SERVER['REQUEST_METHOD'] == 'POST') && (isset($_POST['method']))) {
  34 + $method = $_POST['method'];
  35 + $valid = true;
  36 + $problem = '';
  37 + $zone = '';
  38 + $content = array();
  39 + $temp = '';
  40 + switch ($method) {
  41 + case "file":
  42 + $zone = ((isset($_POST['fil_domain'])) && (isset($_FILES['fil']['tmp_name']))) ? $zone = $_POST['fil_domain'] : '';
  43 + $content = ($zone > '') ? file($_FILES['fil']['tmp_name']) :array();
  44 + $smarty->assign("method", "Upload from file");
  45 + break;
  46 + case "list":
  47 + $zone = ((isset($_POST['sel_domain'])) && ($_POST['sel'] != '- select file -')) ? $_POST['sel_domain'] : '';
  48 + $content = ($zone > '') ? file($conf->path . idnToHost($_POST['sel'])) : array();
  49 + $smarty->assign("method", "Select orphan file from list");
  50 + break;
  51 + case "text":
  52 + $zone = ((isset($_POST['txt_domain'])) && (isset($_POST['txt']))) ? $_POST['txt_domain'] : '';
  53 + $content = ($zone > '') ? explode("\n", $_POST['txt']) : array();
  54 + $smarty->assign("method", "Write zone manually or pasted from clipboard");
  55 + break;
  56 + default:
  57 + problem();
  58 + }
  59 + if (count($content) < 4) {
  60 + problem("nocontent");
  61 + }
  62 + $gzone = $zone;
  63 + $zone = hostToIdn($zone);
  64 + if ($method != 'list') {
  65 + $temp = tempnam($conf->tmp_path, "$zone");
  66 + $fh = fopen($temp, "w");
  67 + fwrite($fh, implode("\n", $content));
  68 + fclose($fh);
  69 + $check = checkZoneFile($temp, $zone);
  70 + unlink($temp);
  71 + if (!$check) {
  72 + problem("nocontent");
  73 + }
  74 + }
  75 + $mz = new masterZone($gzone);
  76 + $sz = new slaveZone($gzone);
  77 + if (($mz->loadZoneHead()) || ($sz->loadZoneHead())) {
  78 + $mz = array();
  79 + $sz = array();
  80 + problem("existzone");
  81 + }
  82 + $smarty->assign("zone", $gzone);
  83 + $nz = new masterZone();
  84 + if (($nz->parseZone($content, $zone, $user->getId())) && ($nz->getId() > 0)) {
  85 + $smarty->assign("pagetitle", "Review imported records");
  86 + $smarty->assign("template", "uploadreview.tpl");
  87 + $smarty->assign("output", explode("\n", $nz->getConf($conf->hostMaster)));
  88 + $smarty->assign("help", help("uploadreview"));
  89 + $smarty->assign("menu_button", menu_buttons());
  90 + } else {
  91 + $smarty->assign("problem", explode("\n", $nz->getErr()));
  92 + $smarty->assign("pagetitle", "Import error");
  93 + $smarty->assign("template", "uploadproblem.tpl");
  94 + $smarty->assign("help", help("uploadproblem"));
  95 + $smarty->assign("menu_button", menu_buttons());
  96 + }
  97 + $smarty->display("main.tpl");
  98 + } else {
  99 + problem();
  100 + }
  101 +} else {
  102 + access_denied();
  103 +}
  104 +?>
... ...
src/deleteuser.php 0 → 100644
  1 +++ a/src/deleteuser.php
  1 +<?php
  2 +/*
  3 + * deleteuser.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + *********************************************************************
  23 + *
  24 + * Check what need to delete and provides info for confirmation
  25 + *
  26 + */
  27 +
  28 +require_once "include.php";
  29 +
  30 +if($user->isAdmin()) {
  31 + $num = intval($_GET['i']);
  32 + switch ($num) {
  33 + case 0:
  34 + case 1:
  35 + problem("deleteadmin");
  36 + break;
  37 + case $user->getId();
  38 + problem("deleteys");
  39 + break;
  40 + default:
  41 + $smarty->assign("pagetitle", "Delete user");
  42 + $duser = new User($num);
  43 + $smarty->assign("user", $duser->getUser());
  44 + $smarty->assign("template", "deleteuser.tpl");
  45 + $smarty->assign("help", help("deleteuser"));
  46 + $smarty->assign("menu_button", menu_buttons());
  47 + $smarty->display("main.tpl");
  48 + }
  49 +} else {
  50 + access_denied();
  51 +}
  52 +?>
... ...
src/deletezone.php 0 → 100644
  1 +++ a/src/deletezone.php
  1 +<?php
  2 +/*
  3 + * deletezone.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + *
  23 + **********************************************************************
  24 + *
  25 + * Check what need to delete and provides info for confirmation
  26 + *
  27 + */
  28 +
  29 +require_once "include.php";
  30 +
  31 +$zoneid = intval($_GET['i']);
  32 +
  33 +if ($zoneid > 0) {
  34 + if ($user->isOwned($zoneid, 'master')) {
  35 + $smarty->assign("pagetitle", "Delete master zone");
  36 + $zone = new masterZone($zoneid);
  37 + $zone->loadZoneHead();
  38 + $res = $zone->getZoneHead();
  39 + $smarty->assign("zone", $res['name']);
  40 + $smarty->assign("zoneid", $zoneid);
  41 + $smarty->assign("template", "deletezone.tpl");
  42 + $smarty->assign("help", help("deletezone"));
  43 + $smarty->assign("menu_button", menu_buttons());
  44 + $smarty->display("main.tpl");
  45 + } else {
  46 + problem('notown');
  47 + }
  48 +} else {
  49 + problem();
  50 +}
  51 +
  52 +?>
... ...
src/end.php 0 → 100644
  1 +++ a/src/end.php
  1 +<?php
  2 +/*
  3 + * end.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + **********************************************************************
  23 + *
  24 + * Destroy the session
  25 + *
  26 + */
  27 +
  28 +require_once "include.php";
  29 +
  30 +$session->destroy();
  31 +die();
  32 +
  33 +?>
... ...
src/include.php 0 → 100644
  1 +++ a/src/include.php
  1 +<?php
  2 +/*
  3 + * include.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + **********************************************************************
  23 + *
  24 + * Contains the main definitions, functions and elements
  25 + *
  26 + */
  27 +
  28 +define('PATH_PATTERN','#(src/|)[^\./]+\.php$#');
  29 +
  30 +$docroot = preg_replace(PATH_PATTERN, '', $_SERVER['SCRIPT_FILENAME']);
  31 +$base = preg_replace(PATH_PATTERN, '', $_SERVER['PHP_SELF']);
  32 +$src = $base . 'src/';
  33 +
  34 +set_include_path(get_include_path() . ":" . $docroot . 'lib/');
  35 +require_once("smbind.class.php");
  36 +$conf = new Configuration($docroot);
  37 +$session = new Session();
  38 +
  39 +if ($conf->ReCaptcha) {
  40 + require_once("recaptchalib.php");
  41 +}
  42 +
  43 +set_include_path(get_include_path() . ":" . $conf->Smarty_Path);
  44 +
  45 +header("Content-Type: text/html; charset=UTF-8");
  46 +header("X-Content-Security-Policy: default-src 'self'; script-src 'self' self www.gstatic.com www.google.com google.com; img-src 'self' data: www.gstatic.com www.google.com google.com; style-src 'self'; font-src 'self'; frame-src 'self'; connect-src 'self' apis.google.com; object-src 'self'");
  47 +
  48 +require_once("Smarty.class.php");
  49 +$smarty = new Smarty;
  50 +$smarty->assign('TITLE',$var = $conf->Title);
  51 +$smarty->assign('footerleft',$conf->Footer);
  52 +$smarty->assign('footerright',$conf->Marker);
  53 +$smarty->assign('sdomain',$conf->StaticDomain);
  54 +$smarty->assign('skin',$conf->Template);
  55 +$smarty->template_dir = $conf->Smbind_Ng . "templates";
  56 +$smarty->compile_dir = $conf->Smbind_Ng . "templates_c";
  57 +$smarty->assign("base", $base);
  58 +$smarty->assign("static", $base . "static/");
  59 +$smarty->assign("src", $src);
  60 +$smarty->assign("captcha","no");
  61 +$smarty->assign("recaptcha","");
  62 +$smarty->assign("menu_button","");
  63 +$smarty->assign("donotcommit","no");
  64 +$smarty->assign('sec', ($conf->IsDNSSec) ? "yes" : "no");
  65 +$smarty->assign('popuperror',NULL);
  66 +
  67 +$cap_rsp = NULL;
  68 +if(isset($_POST["recaptcha_response_field"])){
  69 + if ($_POST["recaptcha_response_field"]!=''){
  70 + $rsp = recaptcha_check_answer (
  71 + $conf->RC_PrivKey,
  72 + $_SERVER["REMOTE_ADDR"],
  73 + $_POST["recaptcha_challenge_field"],
  74 + $_POST["recaptcha_response_field"]
  75 + );
  76 + if(!$rsp->is_valid) {
  77 + $cap_rsp = $rsp->error;
  78 + }
  79 + } else {
  80 + $cap_rsp = 'incorrect-captcha-sol';
  81 + }
  82 +}
  83 +
  84 +if (isset($_POST['username']) && isset($_POST['password']) && ($cap_rsp == NULL)) {
  85 + $session->login($_POST['username'], $_POST['password']);
  86 +}
  87 +
  88 +$user = new User();
  89 +$smarty->assign("loggedinuser",$user->getFullName());
  90 +
  91 +if ($user->getId() == 0) {
  92 + login_page($smarty);
  93 +}
  94 +
  95 +if ((isset($_SERVER['PHP_SELF'])) && (basename($_SERVER['PHP_SELF']) != 'index.php')) {
  96 + $smarty->assign("menu_current", $src . basename($_SERVER['PHP_SELF']));
  97 +} else {
  98 + $smarty->assign("menu_current", $base);
  99 +}
  100 +
  101 +if($user->isAdmin()) {
  102 + $smarty->assign("admin", "yes");
  103 +} else {
  104 + $smarty->assign("admin", "no");
  105 +}
  106 +
  107 +/*
  108 + *
  109 + * name: debug
  110 + * @param variable type a count of parameters for dumping it to the
  111 + * error_log
  112 + *
  113 + * @return <empty>
  114 + *
  115 + */
  116 +function debug() {
  117 + for($i = 0 ; $i < func_num_args(); $i++) {
  118 + $param = func_get_arg($i);
  119 + $dump = '';
  120 + if ((is_array($param)) || (is_object($param))) {
  121 + ob_start();
  122 + if (is_object($param)) {
  123 + $phpv = explode('.', phpversion());
  124 + if (intval($phpv[0] . $phpv[1]) < 56) {
  125 + var_dump($param->__debugInfo());
  126 + } else {
  127 + var_dump($param);
  128 + }
  129 + } else {
  130 + var_dump($param);
  131 + }
  132 + $dump .= ob_get_clean();
  133 + } else {
  134 + $dump .= $param;
  135 + }
  136 + $bt = debug_backtrace();
  137 + error_log($bt[0]['file'] . "(" . $bt[0]['line'] . "):\n" . $dump);
  138 + }
  139 +}
  140 +
  141 +/*
  142 + *
  143 + * name: makePart
  144 + *
  145 + * Creates paging feature
  146 + *
  147 + * @param
  148 + * $all -> lentgt of the listed elements
  149 + * $page -> actual page count
  150 + *
  151 + * @return range for this page
  152 + *
  153 + */
  154 +function makePart($all, $page) {
  155 + global $smarty;
  156 + global $conf;
  157 + $from = 0;
  158 + $to = $all;
  159 + $pages = 0;
  160 + $max = 0;
  161 + if ($conf->isExists('range')) {
  162 + $max = $conf->Range;
  163 + }
  164 + if ($max > 0) {
  165 + $pages = (int)($all/$max);
  166 + $mod = $all % $max;
  167 + if ($mod > 0) {
  168 + $pages++;
  169 + }
  170 + if ($pages < $page) {
  171 + $page = $pages;
  172 + }
  173 + $from = ($page-1) * $max;
  174 + $to = $from;
  175 + if (($page == $pages) && ($mod > 0)) {
  176 + $to += $mod;
  177 + } else {
  178 + $to += $max;
  179 + }
  180 + $from = ($from < 0) ? 0 : $from;
  181 + }
  182 + $pagelist = array();
  183 + for ($i=1;$i<=$pages;$i++) {
  184 + $pagelist[] = $i;
  185 + }
  186 + $pagelist = (sizeof($pagelist) > 1) ? $pagelist : NULL;
  187 + $smarty->assign("current_page", $page);
  188 + $smarty->assign("pages", $pagelist);
  189 + return array($from, $to);
  190 +}
  191 +
  192 +/*
  193 + *
  194 + * name: rndc_status
  195 + * @param no
  196 + * @return the status of rndc command
  197 + *
  198 + */
  199 +function rndc_status() {
  200 + global $conf;
  201 + $cmd = $conf->Rndc . " status > /dev/null";
  202 + system($cmd, $exit);
  203 + return $exit;
  204 +}
  205 +
  206 +/*
  207 + *
  208 + * name: logout
  209 + * @param no
  210 + * @return no
  211 + *
  212 + * Displays the logout page and destroy the http session
  213 + *
  214 + */
  215 +function logout() {
  216 + global $smarty;
  217 + global $session;
  218 + $session->destroy();
  219 + $smarty->assign("menu_button", array());
  220 + $smarty->assign("pagetitle", "Logout");
  221 + $smarty->assign("template", "logout.tpl");
  222 + $smarty->assign("help", help("logout"));
  223 + $smarty->display("main.tpl");
  224 +}
  225 +
  226 +/*
  227 + *
  228 + * name: login_page
  229 + * @param Smarty object
  230 + * @return no
  231 + *
  232 + * Checks the captcha requirements and provides the login page
  233 + *
  234 + */
  235 +function login_page($smarty) {
  236 + global $cap_rsp;
  237 + global $base;
  238 + global $conf;
  239 +
  240 + if($conf->ReCaptcha) {
  241 + $nocap = false;
  242 + foreach ($conf->NoCaptcha as $ip) {
  243 + $nocap = ($nocap or ($ip == $_SERVER['REMOTE_ADDR']));
  244 + }
  245 + if(!$nocap) {
  246 + $smarty->assign("captcha","yes");
  247 + $smarty->assign("recaptcha",recaptcha_get_html($conf->Rc_Pubkey,$cap_rsp,true));
  248 + }
  249 + }
  250 + $smarty->assign("action", $base);
  251 + $smarty->assign("pagetitle", "Login");
  252 + $smarty->assign("template", "login.tpl");
  253 + $smarty->assign("help", help("login"));
  254 + $smarty->display("main.tpl");
  255 + die();
  256 +}
  257 +
  258 +/*
  259 + *
  260 + * name: problem
  261 + * @param
  262 + * $reason -> short tag for the problem
  263 + * $title -> header title
  264 + *
  265 + * @return no
  266 + *
  267 + * Provides a kind of error page
  268 + *
  269 + */
  270 +function problem($reason = NULL, $title = NULL) {
  271 + global $smarty;
  272 + $tit = (isset($title)) ? $title : title($reason);
  273 + $smarty->assign("pagetitle", $tit);
  274 + $smarty->assign("template", "accessdenied.tpl");
  275 + $smarty->assign("reason", reason($reason));
  276 + $smarty->assign("help", help("accessdenied"));
  277 + $smarty->assign("menu_button", menu_buttons());
  278 + $smarty->display("main.tpl");
  279 + die();
  280 +}
  281 +
  282 +/*
  283 + *
  284 + * name: access_denied
  285 + * @param no
  286 + * @return no
  287 + *
  288 + * Generates the access denied problem
  289 + *
  290 + */
  291 +function access_denied() {
  292 + problem("notadmin");
  293 +}
  294 +
  295 +/*
  296 + *
  297 + * name: reason
  298 + * @param optional
  299 + * $reason -> short tag of the problem
  300 + *
  301 + * @return description string
  302 + *
  303 + * Generates description string for the known reason
  304 + *
  305 + */
  306 +function reason($reason = '') {
  307 + switch ($reason) {
  308 + case "notown":
  309 + return "You don't own this zone.";
  310 + case "unauth":
  311 + return "You are not authorized for this procedure";
  312 + case "notadmin":
  313 + return "You are not an administrator.";
  314 + case "noslave":
  315 + return "The slave zone hasn't replicated yet. Try again later.";
  316 + case "existzone":
  317 + return "The zone already exists in the database.";
  318 + case "existfile":
  319 + return "The zonefile already exists on the system.";
  320 + case "existuser":
  321 + return "The user already exists in the database.";
  322 + case "nozonename":
  323 + return "That's not much of a zone name.";
  324 + case "deleteadmin":
  325 + return "You may not delete the default admin user.";
  326 + case "deleteys":
  327 + return "You may not delete yourself.";
  328 + case "nocontent":
  329 + return "The given content empty or invalid.";
  330 + case "nocommit":
  331 + return "There is no commitable content.";
  332 + default:
  333 + return "Unknown error. Please it report to your administrator";
  334 + }
  335 +}
  336 +
  337 +/*
  338 + *
  339 + * name: title
  340 + * @param optional
  341 + * $reason -> short tag of the problem
  342 + *
  343 + * @return title string
  344 + *
  345 + * Generates title string for the known reason
  346 + *
  347 + */
  348 + function title($reason = '') {
  349 + switch ($reason) {
  350 + case "notown":
  351 + case "notadmin":
  352 + case "deleteadmin":
  353 + case "deleteys":
  354 + case "unauth":
  355 + return "Access denied";
  356 + case "noslave":
  357 + case "nocontent":
  358 + return "No data";
  359 + case "nocommit":
  360 + case "existzone":
  361 + case "existfile":
  362 + case "existuser":
  363 + case "nozonename":
  364 + return "Error in process";
  365 + default:
  366 + return "Something wrong happened";
  367 + }
  368 +}
  369 +
  370 +/*
  371 + *
  372 + * name: help
  373 + * @param
  374 + * $help tag for the info footer
  375 + *
  376 + * @return the info footer
  377 + *
  378 + * Generates the info footer
  379 + *
  380 + */
  381 +function help($help) {
  382 + switch ($help) {
  383 + case "login":
  384 + return "Please log in.";
  385 + case "mainpage":
  386 + return "User status and Server status are displayed, along with any zone informations.";
  387 + case "zoneview":
  388 + return "Your zone is dumped. Here you can view the zone in bind syntax.<small><br />" .
  389 + "<span class=attention>You cannot edit the zonefile directly!</span></small>";
  390 + case "zonepview":
  391 + return "Your zone will look like as above. You can view it in bind syntax.<small><br />" .
  392 + "<span class=attention>This zone hasn't commited yet!</span></small>";
  393 + case "zoneread":
  394 + return "Your zones are displayed. Here you can create a zone, edit a zone, view a zone, or delete a zone.";
  395 + case "newzone":
  396 + return "Enter your new zone's domain name, name servers and smbind-ng owner. " .
  397 + "This will create a new zone with a SOA and NS record.<small><br />" .
  398 + "The Web/Mail/FTP fields will create these A, CNAME, and MX template records for you. " .
  399 + "Otherwise, leave them blank.<br />In these fields you can use IP addresses or hostnames too. In this case you need to take care of the trailing dots.</small>";
  400 + case "newslavezone":
  401 + return "Enter your new slave zone's domain name, address of the master server and smbind-ng owner.";
  402 + case "recordread":
  403 + return "Here you can modify your zone's SOA record, or add, edit, or delete resource records.";
  404 + case "userlistread":
  405 + return "Here you can add, edit, or delete smbind-ng users.";
  406 + case "commit":
  407 + return "Your zone files are commited to disk, error checked, and reloaded.";
  408 + case "precommit":
  409 + return "Your modifications will be applied to the system, and the related services will notified about the changes.";
  410 + case "optionsread":
  411 + return "Here you can change options that define how smbind-ng works.";
  412 + case "deletezone":
  413 + return "Please confirm.";
  414 + case "uploadreview":
  415 + return "Please confirm your uploaded data. Some records may be missig basad on your handled record-type options";
  416 + case "uploadproblem":
  417 + return "Please fix the errors. The file output of namedcheckzone has errors.";
  418 + case "upload":
  419 + return "Here you can import a zone what is in legal bind zonefile format. Choose import method!" .
  420 + " Available methods:<small><br /><strong>Orphan files:</strong>(maybe disabled) Some file in" .
  421 + " your config directory without database records. <strong>Browse:</strong> Zone file upload" .
  422 + " from your computer. <strong>Edit:</strong> Paste contents into the box from your clipboard.</small>";
  423 + case "deleteuser":
  424 + return "Please confirm.";
  425 + case "newuser":
  426 + return "Here can you add a new user.<br />" .
  427 + "<span class=attention>Password requirements:</span> You must use letters (both upper- and lowercase), numbers and symols. Minimum length is 8 characters. " .
  428 + "10 charachers length, and using more uppercase letters and numbers is recommended.";
  429 + case "userread":
  430 + return "Here can you change the user's properties. If you don't want to change the password, leave it empty." .
  431 + "<br /><span class=attention>Password requirements:</span> You must use letters (both upper- and lowercase), numbers and symols. Minimum length is 8 characters. " .
  432 + "10 charachers length, and using more uppercase letters and numbers is recommended.";
  433 + case "chpass":
  434 + return "Here can you change your password. <small>You need to give your current password before the new!</small><br />" .
  435 + "<span class=attention>Password requirements:</span> You must use letters (both upper- and lowercase), numbers and symols. Minimum length is 8 characters. " .
  436 + "10 charachers length, and using more uppercase letters and numbers is recommended.";
  437 + case "savepass":
  438 + return "Login using your new password." .
  439 + "<small><br />This page automatically open it within 10 seconds</small>";
  440 + case "accessdenied":
  441 + return "<span class=attention>Access denied.</span><br />This procedure not allowed with your privileges.";
  442 + case "problem":
  443 + return "A problem has occurred.";
  444 + case "logout":
  445 + return "You have been successfully logged out. Click <a class=attention id=reload href=\"../\">here</a> if you wish to log in again." .
  446 + "<small><br />This page automatically open it within <span id=counter>10</span> seconds</small>";
  447 + default:
  448 + return "";
  449 + }
  450 +}
  451 +
  452 +/*
  453 + *
  454 + * name: getorphan
  455 + * @param no
  456 + * @return an array with found filenames
  457 + *
  458 + * Find and check local files for importing
  459 + *
  460 + */
  461 +function getorphan() {
  462 + global $conf;
  463 + global $user;
  464 +
  465 + $files = ' ' . implode(' ', scandir($conf->Path)) . ' ';
  466 + $mzones = $user->getMasters();
  467 + $szones = $user->getSlaves();
  468 + foreach ($mzones as $id) {
  469 + $z = new masterZone(intval($id));
  470 + $z->loadZoneHead();
  471 + $zone = $z->getZoneHeadRaw();
  472 + $files = str_replace(' ' . $zone['name'] . ' ', ' ', $files);
  473 + }
  474 + foreach ($szones as $id) {
  475 + $z = new slaveZone(intval($id));
  476 + $z->loadZoneHead();
  477 + $zone = $z->getZoneHeadRaw();
  478 + $files = str_replace(' ' . $zone['name'] . ' ', ' ', $files);
  479 + }
  480 + $vzf = array();
  481 + foreach (explode(' ', trim($files)) as $entry) {
  482 + if ((is_file($conf->Path . $entry)) && (preg_replace('/\.(signed|private|key|krf|jnl|bind)$/', '', $entry) == $entry)) {
  483 + if (checkZoneFile($conf->Path . $entry, $entry)) {
  484 + $vzf[] = hostToIdn($entry);
  485 + }
  486 + }
  487 + }
  488 +
  489 + return $vzf;
  490 +}
  491 +
  492 +/*
  493 + *
  494 + * name: checkZoneFile
  495 + * @param
  496 + * $file -> path the file
  497 + * $zone -> zonename
  498 + *
  499 + * @return true/false (aftert chacking the zoneile)
  500 + *
  501 + */
  502 +function checkZoneFile($file, $zone) {
  503 + global $conf;
  504 +
  505 + $cmd = $conf->namedCheckZone . " -i local " . $zone. " " . $file . " 2>/dev/stdout";
  506 + unset($coutput);
  507 + exec($cmd, $coutput, $exit);
  508 + return ($coutput[sizeof($coutput)-1] == 'OK');
  509 +}
  510 +
  511 +/*
  512 + *
  513 + * name: menu_buttons
  514 + * @param no
  515 + * @return no
  516 + *
  517 + * Generates the menu entries
  518 + *
  519 + */
  520 +function menu_buttons() {
  521 + global $user;
  522 + global $smarty;
  523 + global $src;
  524 + global $base;
  525 +
  526 + $cmasters = $user->getCommitableZones('master');
  527 + $cmc = (is_array($cmasters)) ? sizeof($cmasters) : 0;
  528 + $cslaves = intval($user->getCommitableZones('slave'));
  529 + $csc = (is_array($cslaves)) ? sizeof($cslaves) : 0;
  530 + $commitables = $cmc + $csc;
  531 + if($commitables == 0) {
  532 + $committext = "";
  533 + $smarty->assign("donotcommit","yes");
  534 + }
  535 + else {
  536 + $committext = "\" id=\"commitable\" class=\"attention";
  537 + }
  538 +
  539 + if (sizeof($user->getUnvalidatedZones('master')) +
  540 + sizeof($user->getUnvalidatedZones('slave')) +
  541 + sizeof($user->getDeletedZones('slave')) +
  542 + sizeof($user->getDeletedZones('master')) > 0) {
  543 + $maintext = "\" class=\"attention";
  544 + }
  545 + else {
  546 + $maintext = "";
  547 + }
  548 +
  549 + return array(
  550 + array("title" => "Main", "link" => $base . $maintext),
  551 + array("title" => "Master zones", "link" => $src . "zonelist.php"),
  552 + array("title" => "Slave zones", "link" => $src . "slave_zonelist.php"),
  553 + array("title" => "Import zones", "link" => $src . "upload.php"),
  554 + array("title" => "Users", "link" => $src . "userlist.php"),
  555 + array("title" => "Change password", "link" => $src . "chpass.php"),
  556 + array("title" => "Commit changes", "link" => $src . "commit.php" . $committext),
  557 + array("title" => "Options", "link" => $src . "options.php"),
  558 + array("title" => "Log out", "link" => $src . "logout.php")
  559 + );
  560 +}
  561 +
  562 +?>
... ...
src/logout.php 0 → 100644
  1 +++ a/src/logout.php
  1 +<?php
  2 +/*
  3 + * logout.php
  4 + *
  5 + * Copyright 2015 Péter Szládovics <peti@szladovics.hu>
  6 + *
  7 + * This program is free software; you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation; either version 2 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20 + * MA 02110-1301, USA.
  21 + *
  22 + **********************************************************************
  23 + *
  24 + * Call the logout
  25 + *
  26 + */
  27 +
  28 +require_once "include.php";
  29 +
  30 +logout();
  31 +
  32 +?>
... ...