zentyal-dhcp-2.3.8+quantal1/0000775000000000000000000000000012017140107012531 5ustar zentyal-dhcp-2.3.8+quantal1/COPYING0000664000000000000000000004311012017140107013563 0ustar GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. 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. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE 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. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. zentyal-dhcp-2.3.8+quantal1/debian/0000775000000000000000000000000012017140107013753 5ustar zentyal-dhcp-2.3.8+quantal1/debian/compat0000664000000000000000000000000212017140107015151 0ustar 5 zentyal-dhcp-2.3.8+quantal1/debian/copyright0000664000000000000000000000214112017140107015704 0ustar This package was debianized by Zentyal Packaging Maintainers Fri, 20 Feb 2005 15:13:22 +0100. It was downloaded from http://www.zentyal.org/ Files: * Upstream Author: eBox Technologies S.L. Copyright (C) 2004-2012 eBox Technologies S.L. License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2 file. The Debian packaging is: (C) 2004-2011, Zentyal Packaging Maintainers and is licensed under the GPL, see `/usr/share/common-licenses/GPL-2'. zentyal-dhcp-2.3.8+quantal1/debian/zentyal-dhcp.postrm0000664000000000000000000000033012017140107017617 0ustar #!/bin/bash set -e #DEBHELPER case "$1" in purge) # purge configuration /usr/share/zentyal/purge-module dhcp ;; remove) dpkg-trigger --no-await zentyal-core ;; esac exit 0 zentyal-dhcp-2.3.8+quantal1/debian/control0000664000000000000000000000212112017140107015352 0ustar Source: zentyal-dhcp Section: web Priority: optional Maintainer: Zentyal Packaging Maintainers Uploaders: Jorge Salamero Sanz Build-Depends: zbuildtools Standards-Version: 3.9.2 Homepage: http://www.zentyal.org/ Vcs-Browser: http://git.zentyal.org/zentyal.git/tree/quantal:/main/dhcp Vcs-Git: git://git.zentyal.org/zentyal.git Package: zentyal-dhcp Architecture: all Replaces: ebox-dhcp (<< 2.0.100) Breaks: ebox-dhcp (<< 2.0.100) Depends: zentyal-core (>= 2.3), zentyal-core (<< 2.3.100), zentyal-firewall, zentyal-services, isc-dhcp-server, tftpd-hpa, libtext-dhcpleases-perl, ${misc:Depends} Suggests: pxe, etherboot Description: Zentyal - DHCP Service Zentyal is a Linux small business server that can act as a Gateway, Unified Threat Manager, Office Server, Infrastructure Manager, Unified Communications Server or a combination of them. One single, easy-to-use platform to manage all your network services. . This module adds a DHCP server to your Zentyal installation, allowing your network clients to get network configuration automatically. zentyal-dhcp-2.3.8+quantal1/debian/source/0000775000000000000000000000000012017140107015253 5ustar zentyal-dhcp-2.3.8+quantal1/debian/source/format0000664000000000000000000000001512017140107016462 0ustar 3.0 (native) zentyal-dhcp-2.3.8+quantal1/debian/rules0000775000000000000000000000010612017140107015030 0ustar #!/usr/bin/make -f include /usr/share/zbuildtools/1/rules/zentyal.mk zentyal-dhcp-2.3.8+quantal1/debian/zentyal-dhcp.postinst0000664000000000000000000000044112017140107020161 0ustar #!/bin/bash set -e #DEBHELPER# case "$1" in configure) # initial setup /usr/share/zentyal/initial-setup --no-restart dhcp $2 # restart module invoke-rc.d zentyal dhcp restart || true dpkg-trigger --no-await zentyal-core ;; esac exit 0 zentyal-dhcp-2.3.8+quantal1/debian/changelog0000664000000000000000000001360612017140107015633 0ustar zentyal-dhcp (2.3.8+quantal1) quantal; urgency=low * New upstream release for Quantal -- Jorge Salamero Sanz Tue, 28 Aug 2012 14:54:46 +0200 zentyal-dhcp (2.3.8) precise; urgency=low * New upstream release -- José A. Calvo Thu, 23 Aug 2012 02:26:54 +0200 zentyal-dhcp (2.3.7) precise; urgency=low * New upstream release -- José A. Calvo Thu, 21 Jun 2012 12:40:33 +0200 zentyal-dhcp (2.3.6) precise; urgency=low * New upstream release -- José A. Calvo Thu, 14 Jun 2012 04:50:23 +0200 zentyal-dhcp (2.3.5) precise; urgency=low * New upstream release -- José A. Calvo Mon, 02 Apr 2012 17:52:02 +0200 zentyal-dhcp (2.3.4) precise; urgency=low * New upstream release -- José A. Calvo Fri, 30 Mar 2012 11:30:22 +0200 zentyal-dhcp (2.3.3) precise; urgency=low * New upstream release -- José A. Calvo Tue, 20 Mar 2012 02:57:15 +0100 zentyal-dhcp (2.3.2) precise; urgency=low * New upstream release -- José A. Calvo Tue, 06 Mar 2012 11:57:31 +0100 zentyal-dhcp (2.3.1) precise; urgency=low * New upstream release -- José A. Calvo Tue, 14 Feb 2012 20:54:38 +0100 zentyal-dhcp (2.3) precise; urgency=low * New upstream release -- José A. Calvo Mon, 30 Jan 2012 01:42:41 +0100 zentyal-dhcp (2.2.1) lucid; urgency=low * New upstream release -- José A. Calvo Tue, 25 Oct 2011 21:31:27 +0200 zentyal-dhcp (2.2) lucid; urgency=low * New upstream release -- José A. Calvo Tue, 13 Sep 2011 04:40:18 +0200 zentyal-dhcp (2.1.6) lucid; urgency=low * New upstream release -- José A. Calvo Wed, 24 Aug 2011 03:18:58 +0200 zentyal-dhcp (2.1.5) lucid; urgency=low * New upstream release -- José A. Calvo Thu, 14 Jul 2011 22:45:21 +0200 zentyal-dhcp (2.1.4) lucid; urgency=low * New upstream release -- José A. Calvo Thu, 30 Jun 2011 00:28:44 +0200 zentyal-dhcp (2.1.3) lucid; urgency=low * New upstream release -- José A. Calvo Tue, 10 May 2011 22:43:59 +0200 zentyal-dhcp (2.1.2) lucid; urgency=low * New upstream release -- José A. Calvo Mon, 14 Mar 2011 11:01:46 +0100 zentyal-dhcp (2.1.1) lucid; urgency=low * New upstream release -- José A. Calvo Sun, 13 Mar 2011 18:36:21 +0100 zentyal-dhcp (2.1) lucid; urgency=low * New upstream release -- José A. Calvo Tue, 22 Feb 2011 03:11:52 +0100 ebox-dhcp (2.0.2) lucid; urgency=low * New upstream release -- José A. Calvo Sat, 04 Dec 2010 14:06:25 +0100 ebox-dhcp (2.0.1) lucid; urgency=low * New upstream release -- José A. Calvo Wed, 29 Sep 2010 19:18:55 +0200 ebox-dhcp (2.0) lucid; urgency=low * New upstream release -- José A. Calvo Mon, 30 Aug 2010 21:49:02 +0200 ebox-dhcp (1.5.4-0ubuntu1~ppa1~lucid1) lucid; urgency=low * New upstream release -- José A. Calvo Mon, 23 Aug 2010 02:14:41 +0200 ebox-dhcp (1.5.3-0ubuntu1~ppa1~lucid1) lucid; urgency=low * New upstream release -- José A. Calvo Wed, 04 Aug 2010 15:49:40 +0200 ebox-dhcp (1.5.2-0ubuntu1~ppa1~lucid1) lucid; urgency=low * New upstream release -- José A. Calvo Wed, 16 Jun 2010 21:00:52 +0200 ebox-dhcp (1.5.1-0ubuntu1~ppa1~lucid1) lucid; urgency=low * New upstream release -- José A. Calvo Thu, 13 May 2010 01:34:59 +0200 ebox-dhcp (1.5-0ubuntu1) lucid; urgency=low [Javier Uruen Val] * New upstream release (LP: #521804) * debian/control - Bump eBox dependency - Update description -- Javier Uruen Val Sun, 07 Feb 2010 18:51:11 +0100 ebox-dhcp (1.3.5-0ubuntu1) karmic; urgency=low [Javier Uruen Val] * New upstream release [LP: 411546] * cdbs/ebox.mk - GConf schemas are not used anymore - Remove SCHEMASPATH variable - Remove schemadir variable - Use new upstart directory and file naming convention * debian/control - Bump standards version - Bump eBox depenency - Add dependency on libtext-dhcpleases-perl * debian/ebox-dhcp.postinst - Fix indentation - Do not pkill gconfd as it's not necessary anymore - Run ebox trigger - Add set -e - Add || true * debian/ebox-dhcp.postrm - Run eobx trigger - Add set -e * debian/rules - Do not include debian/cdbs/gnome.mk * debian/watch - Change URL -- Javier Uruen Val Wed, 05 Aug 2009 12:29:43 +0200 ebox-dhcp (0.12.2-0ubuntu1) jaunty; urgency=low [ Javier Uruen Val ] * New upstream release. (LP: #321940) * debian/control: - Bump standards version. - Remove dpatch from Build-Depends - Add homepage * debian/patches - Remove all patches as they are already included in upstream * debian/copyright - Update upstream URL * debian/watch: - Add watch file. * debian/ebox-dhcp.postinst - Fix indentation - Do not restart apache, ebox trigger takes care of it * debian/ebox-dhcp.postrm - Purge ebox-dhcp configuration [ Iain Lane ] * debian/watch: Fix to work with current upstream tarballs * debian/changelog: Remove entries that never entered Ubuntu -- Javier Uruen Val Sun, 18 Jan 2009 18:19:19 +0100 ebox-dhcp (0.11.99-0ubuntu2) hardy; urgency=low * debian/patches/01_is_running_interface - Checks for a running interface. -- Chuck Short Mon, 31 Mar 2008 08:35:04 -0400 ebox-dhcp (0.11.99-0ubuntu1) hardy; urgency=low * New upstream version. -- Chuck Short Wed, 27 Feb 2008 13:12:36 -0500 zentyal-dhcp-2.3.8+quantal1/src/0000775000000000000000000000000012017140107013320 5ustar zentyal-dhcp-2.3.8+quantal1/src/scripts/0000775000000000000000000000000012017140107015007 5ustar zentyal-dhcp-2.3.8+quantal1/src/scripts/enable-module0000775000000000000000000000011312017140107017441 0ustar #!/bin/bash # disable isc-dhcp-server update-rc.d isc-dhcp-server disable zentyal-dhcp-2.3.8+quantal1/src/EBox/0000775000000000000000000000000012017140107014155 5ustar zentyal-dhcp-2.3.8+quantal1/src/EBox/Composite/0000775000000000000000000000000012017140107016117 5ustar zentyal-dhcp-2.3.8+quantal1/src/EBox/Composite/OptionsTab.pm0000664000000000000000000000261212017140107020540 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Composite::OptionsTab # # This class is used to manage dhcp server general options # configuration on a given interface. It stores three models for # simple options, dynamic DNS ones and advanced ones indexed by interface # package EBox::DHCP::Composite::OptionsTab; use base 'EBox::Model::Composite'; use strict; use warnings; use EBox::Gettext; use EBox::Global; # Group: Protected methods # Method: _description # # Overrides: # # # sub _description { my ($self) = @_; my $description = { layout => 'tabbed', name => 'OptionsTab', compositeDomain => 'DHCP', }; return $description; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Composite/InterfaceConfiguration.pm0000664000000000000000000000364612017140107023116 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Composite::InterfaceConfiguration # # This class is used to manage dhcp server configuration on a given # interface. It stores four models indexed by interface this # composite does # package EBox::DHCP::Composite::InterfaceConfiguration; use base 'EBox::Model::Composite'; use strict; use warnings; use EBox::Gettext; use EBox::Global; # Group: Protected methods # Method: _description # # Overrides: # # # sub _description { my ($self) = @_; my $description = { layout => 'top-bottom', name => 'InterfaceConfiguration', printableName => __('DHCP Configuration'), compositeDomain => 'DHCP', help => __('In order to serve IP addresses on an interface, ' . 'it is required to set at least a range or a ' . 'fixed address.'), }; return $description; } sub HTMLTitle { my ($self) = @_; return ([ { title => 'DHCP', link => '/DHCP/View/Interfaces', }, { title => $self->parentRow()->valueByName('iface'), link => '', }, ]); } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Composite/General.pm0000664000000000000000000000435312017140107020037 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Composite::General # # This class is used to display the ebox dhcp module as in a whole # allowing configure a DHCP server to configure in every static # interface # package EBox::DHCP::Composite::General; use base 'EBox::Model::Composite'; use strict; use warnings; use EBox::Gettext; use EBox::Global; # Group: Public methods # Method: precondition # # Overrides: # # # sub precondition { my $netMod = EBox::Global->modInstance('network'); my @allIfaces = @{$netMod->allIfaces()}; my $nStatic = grep { $netMod->ifaceMethod($_) eq 'static' } @allIfaces; return ($nStatic > 0); } # Method: preconditionFailMsg # # Overrides: # # # sub preconditionFailMsg { return __x('An interface must set as static ' . 'to configure the DHCP service on it. To ' . 'do so, change {openhref}interfaces ' . 'configuration{closehref} in network module', openhref => '', closehref => ''); } # Method: pageTitle # # Overrides: # # # sub pageTitle { return 'DHCP'; } # Group: Protected methods # Method: _description # # Overrides: # # # sub _description { my $description = { layout => 'top-bottom', name => 'General', printableName => 'DHCP', compositeDomain => 'DHCP', }; return $description; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Composite/AdvancedOptions.pm0000664000000000000000000000326512017140107021544 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Composite::AdvancedOptions # # This class is used to manage advanced options from a dhcp # server. It stores two models, the former is the LeaseTime model # which stores the lease times configuration, and the latter the # thin client model that stores the thin client configuration # package EBox::DHCP::Composite::AdvancedOptions; use base 'EBox::Model::Composite'; use strict; use warnings; use EBox::Gettext; use EBox::Global; # Group: Public methods # Method: pageTitle # # Overrides: # # # # Returns: # # undef # sub pageTitle { return undef; } # Group: Protected methods # Method: _description # # Overrides: # # # sub _description { my ($self) = @_; my $description = { layout => 'top-bottom', name => 'AdvancedOptions', compositeDomain => 'DHCP', printableName => __('Advanced options'), }; return $description; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/DHCP.pm0000664000000000000000000014663012017140107015243 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package EBox::DHCP; use strict; use warnings; use base qw(EBox::Module::Service EBox::NetworkObserver EBox::LogObserver); use EBox::Config; use EBox::Exceptions::InvalidData; use EBox::Exceptions::Internal; use EBox::Exceptions::DataNotFound; use EBox::Gettext; use EBox::Global; use EBox::Menu::Item; use EBox::Menu::Folder; use EBox::Objects; use EBox::Validate qw(:all); use EBox::Sudo; use EBox::NetWrappers qw(:all); use EBox::Service; use EBox::DHCPLogHelper; use EBox::Dashboard::Section; use EBox::Dashboard::List; use Net::IP; use Error qw(:try); use Perl6::Junction qw(any); use Text::DHCPLeases; # Module local conf stuff # FIXME: extract this from somewhere to support multi-distro? #use constant DHCPCONFFILE => "@DHCPDCONF@"; #use constant LEASEFILE => "@DHCPDLEASES@"; #use constant PIDFILE => "@DHCPDPID@"; #use constant DHCP_SERVICE => "@DHCPD_SERVICE@"; use constant DHCPCONFFILE => "/etc/dhcp/dhcpd.conf"; use constant LEASEFILE => "/var/lib/dhcp/dhcpd.leases"; use constant PIDFILE => "/var/run/dhcp-server/dhcpd.pid"; use constant DHCP_SERVICE => "isc-dhcp-server"; use constant TFTP_SERVICE => "tftpd-hpa"; use constant CONF_DIR => EBox::Config::conf() . 'dhcp/'; use constant PLUGIN_CONF_SUBDIR => 'plugins/'; use constant TFTPD_CONF_DIR => '/var/lib/tftpboot/'; use constant INCLUDE_DIR => EBox::Config::etc() . 'dhcp/'; use constant APPARMOR_DHCPD => '/etc/apparmor.d/local/usr.sbin.dhcpd'; # Group: Public and protected methods # Constructor: _create # # Create the zentyal-dhcp module # # Overrides: # # # sub _create { my $class = shift; my $self = $class->SUPER::_create(name => 'dhcp', printableName => 'DHCP', @_); bless ($self, $class); return $self; } # Method: usedFiles # # Override EBox::Module::Service::usedFiles # sub usedFiles { return [ { 'file' => DHCPCONFFILE, 'module' => 'dhcp', 'reason' => __x('{server} configuration file', server => 'dhcpd'), }, { 'file' => APPARMOR_DHCPD, 'module' => 'dhcp', 'reason' => __x('AppArmor profile for {server} daemon', server => 'dhcpd'), }, ]; } # Method: initialSetup # # Overrides: # EBox::Module::Base::initialSetup # sub initialSetup { my ($self, $version) = @_; # Create default services, rules and conf dir # only if installing the first time unless ($version) { my $services = $self->global()->modInstance('services'); my $firewall = $self->global()->modInstance('firewall'); my $serviceName = 'tftp'; unless ($services->serviceExists(name => $serviceName)) { $services->addMultipleService( 'name' => $serviceName, 'printableName' => 'TFTP', 'description' => __('Trivial File Transfer Protocol'), 'readOnly' => 1, 'services' => [ { protocol => 'udp', sourcePort => 'any', destinationPort => 69 } ] ); $firewall->setInternalService($serviceName, 'accept'); } $serviceName = 'dhcp'; unless ($services->serviceExists(name => $serviceName)) { $services->addMultipleService( 'name' => $serviceName, 'printableName' => 'DHCP', 'description' => __('Dynamic Host Configuration Protocol'), 'readOnly' => 1, 'services' => [ { protocol => 'udp', sourcePort => '67:68', destinationPort => '67:68' } ] ); $firewall->setInternalService($serviceName, 'accept'); } $firewall->saveConfigRecursive(); mkdir (CONF_DIR, 0755); } } # Method: appArmorProfiles # # Overrides to set the own AppArmor profile to allow Dynamic DNS to # work and LSTP configuration using /etc/zentyal/dhcp/... # # Overrides: # # # sub appArmorProfiles { my ($self) = @_; my @params = ( 'keysFile' => $self->_keysFile(), 'confDir' => $self->IncludeDir() ); return [ { 'binary' => 'usr.sbin.dhcpd', 'local' => 1, 'file' => 'dhcp/apparmor-dhcpd.local.mas', 'params' => \@params } ]; } # Method: actions # # Override EBox::Module::Service::actions # sub actions { return [ { 'action' => __x('Disable {server} init script', server => 'dhcpd'), 'reason' => __('Zentyal will take care of start and stop ' . 'the service'), 'module' => 'dhcp', } ]; } # Method: _daemons # # Overrides: # # # sub _daemons { return [ { 'name' => DHCP_SERVICE } ]; } # Method: _setConf # # Writes the configuration files # # Overrides: # # # sub _setConf { my ($self) = @_; $self->_setDHCPConf(); $self->_setTFTPDConf(); } # Method: menu # # Overrides: # # # # sub menu { my ($self, $root) = @_; $root->add(new EBox::Menu::Item('url' => 'DHCP/View/Interfaces', 'text' => $self->printableName(), 'separator' => 'Infrastructure', 'order' => 410)); } # Method: depends # # DHCP depends on DNS configuration only if the Dynamic DNS # feature is done. # # Overrides: # # # sub depends { my ($self) = @_; my $dependsList = $self->SUPER::depends(); if ( $self->_dynamicDNSEnabled() ) { push(@{$dependsList}, 'dns'); } return $dependsList; } # Method: initRange # # Return the initial host address range for a given interface # # Parameters: # # iface - String interface name # # Returns: # # String - containing the initial range # sub initRange # (interface) { my ($self, $iface) = @_; my $net = $self->global()->modInstance('network'); my $address = $net->ifaceAddress($iface); my $netmask = $net->ifaceNetmask($iface); my $network = ip_network($address, $netmask); my ($first, $last) = $network =~ /(.*)\.(\d+)$/; my $init_range = $first . "." . ($last+1); return $init_range; } # Method: endRange # # Return the final host address range for a given interface # # Parameters: # # iface - String interface name # # Returns: # # string - containing the final range # sub endRange # (interface) { my ($self, $iface) = @_; my $net = $self->global()->modInstance('network'); my $address = $net->ifaceAddress($iface); my $netmask = $net->ifaceNetmask($iface); my $broadcast = ip_broadcast($address, $netmask); my ($first, $last) = $broadcast =~ /(.*)\.(\d+)$/; my $end_range = $first . "." . ($last-1); return $end_range; } # Method: defaultGateway # # Get the default gateway that will be sent to DHCP clients for a # given interface # # Parameters: # # iface - interface name # # Returns: # # string - the default gateway in a IP address form # # Exceptions: # # - thrown if the interface is not # static or the given type is none of the suggested ones # # - thrown if the interface is # not found # sub defaultGateway # (iface) { my ($self, $iface) = @_; my $network = $self->global()->modInstance('network'); #if iface doesn't exists throw exception if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound(data => __('Interface'), value => $iface); } #if iface is not static, throw exception if($network->ifaceMethod($iface) ne 'static') { throw EBox::Exceptions::External(__x("{iface} is not static", iface => $iface)); } return $self->_getModel('Options', $iface)->defaultGateway(); } # Method: searchDomain # # Get the search domain that will be sent to DHCP clients for a # given interface # # Parameters: # # iface - String interface name # # Returns: # # String - the search domain # # undef - if the none search domain has been set # sub searchDomain # (iface) { my ($self, $iface) = @_; my $network = $self->global()->modInstance('network'); #if iface doesn't exists throw exception if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound(data => __('Interface'), value => $iface); } #if iface is not static, throw exception if($network->ifaceMethod($iface) ne 'static') { throw EBox::Exceptions::External(__x("{iface} is not static", iface => $iface)); } # $self->get_string("$iface/search"); return $self->_getModel('Options', $iface)->searchDomain(); } # Method: nameserver # # Get the nameserver that will be sent to DHCP clients for a # given interface # # Parameters: # # iface - String interface name # number - Int nameserver number (1 or 2) # # Returns: # # string - the nameserver or undef if there is no # # Exceptions: # # - thrown if the interface is not # static or the given type is none of the suggested ones # # - thrown if the interface is # not found # # - thrown if any compulsory # argument is missing # sub nameserver # (iface,number) { my ($self, $iface, $number) = @_; if ( not defined ( $number )) { throw EBox::Exceptions::MissingArgument('number'); } my $network = $self->global()->modInstance('network'); #if iface doesn't exists throw exception if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound(data => __('Interface'), value => $iface); } #if iface is not static, throw exception if($network->ifaceMethod($iface) ne 'static') { throw EBox::Exceptions::External(__x("{iface} is not static", iface => $iface)); } # $self->get_string("$iface/nameserver$number"); return $self->_getModel('Options', $iface)->nameserver($number); } # Method: ntpServer # # Get the NTP server that will be sent to DHCP clients for a # given interface # # Parameters: # # iface - String the interface name # # Returns: # # String - the IP address for the NTP server, undef if no # NTP server has been configured # # Exceptions: # # - thrown if the interface is not # static or the given type is none of the suggested ones # # - thrown if the interface is # not found # # - thrown if any compulsory # argument is missing # sub ntpServer # (iface) { my ($self, $iface) = @_; my $network = $self->global()->modInstance('network'); #if iface doesn't exists throw exception if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound(data => __('Interface'), value => $iface); } #if iface is not static, throw exception if($network->ifaceMethod($iface) ne 'static') { throw EBox::Exceptions::External(__x("{iface} is not static", iface => $iface)); } return $self->_getModel('Options', $iface)->ntpServer(); } # Method: winsServer # # Get the WINS server that will be sent to DHCP clients for a # given interface # # Parameters: # # iface - String the interface name # # Returns: # # String - the IP address for the WINS server, undef if no # WINS server has been configured # # Exceptions: # # - thrown if the interface is not # static or the given type is none of the suggested ones # # - thrown if the interface is # not found # # - thrown if any compulsory # argument is missing # sub winsServer # (iface) { my ($self, $iface) = @_; my $network = $self->global()->modInstance('network'); #if iface doesn't exists throw exception if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound(data => __('Interface'), value => $iface); } #if iface is not static, throw exception if($network->ifaceMethod($iface) ne 'static') { throw EBox::Exceptions::External(__x("{iface} is not static", iface => $iface)); } return $self->_getModel('Options', $iface)->winsServer(); } # Method: staticRoutes # # Get the static routes. It polls the Zentyal modules which # implements # # Returns: # # hash ref - contating the static toutes in hash references. The # key is the subnet in CIDR notation that denotes where is # appliable the new route. The values are hash reference with # the keys 'destination', 'netmask' and 'gw' # sub staticRoutes { my ($self) = @_; my %staticRoutes = (); my @modules = @{ $self->global()->modInstancesOfType('EBox::DHCP::StaticRouteProvider') }; foreach my $mod (@modules) { my @modStaticRoutes = @{ $mod->staticRoutes() }; while (@modStaticRoutes) { my $net = shift @modStaticRoutes; my $route = shift @modStaticRoutes; if (exists $staticRoutes{$net}) { push @{$staticRoutes{$net}}, $route; } else { $staticRoutes{$net} = [$route]; } } } return \%staticRoutes; } sub notifyStaticRoutesChange { my ($self) = @_; $self->setAsChanged(); } # Method: rangeAction # # Set/add a range for a given interface # # Parameters: # # iface - String Interface name # action - String to perform (add/set/del) # # indexValue - String index to use to set a new value, it can be a # name, a from IP addr or a to IP addr. # # indexField - String the field name to use as index # # name - String the range name # from - String start of range, an ip address # to - String end of range, an ip address # # - Named parameters # # Exceptions: # # - Interface does not exist # - interface is not static # global()->modInstance('network'); #if iface doesn't exists throw exception if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound(data => __('Interface'), value => $iface); } #if iface is not static, throw exception if($network->ifaceMethod($iface) ne 'static') { throw EBox::Exceptions::External(__x("{iface} is not static", iface => $iface)); } my $rangeModel = $self->_getModel('RangeTable', $iface); if ( $action eq 'add' ) { $rangeModel->add( name => $args{name}, from => $args{from}, to => $args{to}); } elsif ( $action eq 'set' ) { my $index = delete ( $args{indexValue} ); my $indexField = delete ( $args{indexField} ); my @args = map { $_ => $args{$_} } keys (%args); $rangeModel->setIndexField($indexField); $rangeModel->set( $index, @args ); } elsif ( $action eq 'del' ) { my $index = delete ( $args{indexValue} ); my $indexField = delete ( $args{indexField} ); $rangeModel->setIndexField($indexField); $rangeModel->del( $index ); } } # Method: ranges # # Return all the set ranges for a given interface # # Parameters: # # iface - String interface name # # Returns: # # array ref - contating the ranges in hash references. Each hash holds # the keys 'name', 'from' and 'to' # # Exceptions: # # - Interface does not exist # sub ranges # (iface) { my ($self, $iface) = @_; my $network = $self->global()->modInstance('network'); if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound('data' => __('Interface'), 'value' => $iface); } my $model = $self->_getModel('RangeTable', $iface); my @ranges; for my $id (@{$model->ids()}) { my $row = $model->row($id); push (@ranges, { name => $row->valueByName('name'), from => $row->valueByName('from'), to => $row->valueByName('to'), # TODO: Restore this when more than one config per interface is possible options => {}, #$self->_thinClientOptions($iface, $row->valueByName('name')) }); } return \@ranges; } # Method: fixedAddresses # # Return the list of fixed addreses # # Parameters: # # iface - String interface name # # readonly - Boolean indicate to get the information from # readonly backend or current one # *(Optional)* Default value: False # # Returns: # # array ref - contating the fixed addresses in hash refereces. # Each hash holds the keys 'mac', 'ip' and 'name' # # hash ref - if you set readOnly parameter, then it returns # two keys: # options - hash ref containing the PXE options # members - array ref containing the members of this # objects as it does if readOnly is set to false # # Exceptions: # # - Interface does not exist # # - Interface is not static # sub fixedAddresses { my ($self,$iface, $readOnly) = @_; $readOnly = 0 unless ($readOnly); my $global = EBox::Global->getInstance($readOnly); my $network = $global->modInstance('network'); #if iface doesn't exists throw exception if (not $iface or not $network->ifaceExists($iface)) { throw EBox::Exceptions::DataNotFound(data => __('Interface'), value => $iface); } #if iface is not static, throw exception if ($network->ifaceMethod($iface) ne 'static') { throw EBox::Exceptions::External(__x("{iface} is not static", iface => $iface)); } my $ifaceModel = $self->model('Interfaces'); my $ifaceRow = $ifaceModel->findRow(iface => $iface); my $ifaceConf = $ifaceRow->subModel('configuration'); my $model = $ifaceConf->componentByName('FixedAddressTable'); my %addrs; my $objMod = $global->modInstance('objects'); for my $id (@{$model->ids()}) { my $row = $model->row($id); my $objId = $row->valueByName('object'); my $mbs = $objMod->objectMembers($objId); # TODO: Restore this when more than one config per interface is possible $addrs{$objId} = { options => {},#$self->_thinClientOptions($iface, $objId), members => [] }; foreach my $member (@{$mbs}) { # use only IP address member type if ($member->{type} ne 'ipaddr') { next; } # Filter out the ones which does not have a MAC address # and a mask of 32, it does not belong to the given # interface and member name is unique within the fixed # addresses realm if ( $self->_allowedMemberInFixedAddress($iface, $member, $objId, $readOnly) ) { push (@{$addrs{$objId}->{members}}, { name => $member->{name}, ip => $member->{ip}, mac => $member->{macaddr}, }); } } } if ( $readOnly ) { # The returned value is grouped by object id return \%addrs; } else { my @mbs = (); foreach my $obj (values %addrs) { push(@mbs, @{$obj->{members}}); } return \@mbs; } } # Group: Static or class methods # Method: ConfDir # # Get the DHCP configuration directory where to store the user # defined configuration files # # Parameters: # # iface - String the interface which the user configuration file # is within # # Returns: # # String - the configuration path # sub ConfDir { my ($class, $iface) = @_; # Create directory unless it already exists unless ( -d CONF_DIR . $iface ) { mkdir ( CONF_DIR . $iface, 0755 ); } my $pluginDir = CONF_DIR . $iface . '/' . PLUGIN_CONF_SUBDIR; unless ( -d $pluginDir ) { mkdir ( $pluginDir, 0755 ); } return CONF_DIR . "$iface/"; } # Method: TftpdRootDir # # Get the default Tftpd root directory to store the firmwares # uploaded by our users # # Returns: # # String - the tftpd root directory path # sub TftpdRootDir { my ($class) = @_; # Create directory unless it already exists unless ( -d TFTPD_CONF_DIR ) { mkdir ( TFTPD_CONF_DIR, 0755 ); } return TFTPD_CONF_DIR; } # Method: PluginConfDir # # Get the DHCP plugin configuration directory where to store the user # defined configuration files # # Parameters: # # iface - String the interface which the user configuration file # is within # # Returns: # # String - the configuration path # sub PluginConfDir { my ($class, $iface) = @_; my $pluginDir = CONF_DIR . $iface . '/' . PLUGIN_CONF_SUBDIR; unless ( -d $pluginDir ) { mkdir ( $pluginDir, 0755 ); } return $pluginDir; } # Method: userConfDir # # Returns: # path to the user configuration dir sub userConfDir { return CONF_DIR; } # Method: IncludeDir # # Path to the directory to include custom configuration # # Returns: # # String - the path to the directory # sub IncludeDir { return INCLUDE_DIR; } # Group: Network observer implementations # Method: ifaceMethodChanged # # Implements: # # # # Returns: # # true - if the old method is 'static' and there are configured # ranges or fixed addresses attached to this interface # false - otherwise # sub ifaceMethodChanged # (iface, old_method, new_method) { my ($self, $iface, $old_method, $new_method) = @_; if ($old_method eq 'static' and $new_method ne 'static') { my $rangeModel = $self->_getModel('RangeTable', $iface); if ( defined ( $rangeModel )) { return 1 if ( $rangeModel->size() > 0); } my $fixedAddrModel = $self->_getModel('FixedAddressTable', $iface); if ( defined ( $fixedAddrModel )) { return 1 if ( $fixedAddrModel->size() > 0); } } return 0; } # Method: vifaceAdded # # # Implements: # # # # Exceptions: # # - thrown *if*: # # - New Virtual interface IP overlaps any configured range # - New Virtual interface IP is a fixed IP address # sub vifaceAdded # (iface, viface, address, netmask) { my ( $self, $iface, $viface, $address, $netmask) = @_; my $net = $self->global()->modInstance('network'); my $ip = new Net::IP($address); my @rangeModels = @{$self->_getAllModelInstances('RangeTable')}; # Check that the new IP for the virtual interface isn't in any range foreach my $rangeModel (@rangeModels) { foreach my $id (@{$rangeModel->ids()}) { my $rangeRow = $rangeModel->row($id); my $from = $rangeRow->valueByName('from'); my $to = $rangeRow->valueByName('to'); my $range = new Net::IP($from . ' - ' . $to); unless ( $ip->overlaps($range) == $IP_NO_OVERLAP ) { throw EBox::Exceptions::External( __x('The IP address of the virtual interface ' . 'you are trying to add is already used by the ' . "DHCP range '{range}' in the interface " . "'{iface}'. Please, remove it before trying " . 'to add a virtual interface using it.', range => $rangeRow->valueByName('name'), iface => $rangeModel->index())); } } my @fixedAddrModels = @{$self->_getAllModelInstances('FixedAddressTable')}; # Check the new IP for the virtual interface is not a fixed address foreach my $model (@fixedAddrModels) { next unless ($model->size() > 0); my $iface = $model->index(); foreach my $fixedAddr ( @{$self->fixedAddresses($iface, 0)} ) { my $fixedIP = new Net::IP($fixedAddr->{'ip'}); unless ( $ip->overlaps($fixedIP) == $IP_NO_OVERLAP ) { throw EBox::Exceptions::External( __x('The IP address of the virtual interface ' . 'you are trying to add is already used by a ' . "DHCP fixed address from object member " . "'{fixed}' in the " . "interface '{iface}'. Please, remove it " . 'before trying to add a virtual interface ' . 'using it.', fixed => $fixedAddr->{'name'}, iface => $iface)); } } } } } # Method: vifaceDelete # # Implements: # # # # Returns: # # true - if there are any configured range or fixed address for # this interface # false - otherwise # sub vifaceDelete # (iface, viface) { my ($self, $iface, $viface) = @_; foreach my $modelName (qw(RangeTable FixedAddressTable Options)) { my $model = $self->_getModel($modelName, "$iface:$viface"); my $nr = $model->size(); if ( $nr > 0 ) { return 1; } } return 0; } # Method: staticIfaceAddressChanged # # Return true *unless*: # # - all ranges are still in the network # - new IP is not in any range # - all fixed addresses are still in the network # - new IP is not any fixed IP address # # Implements: # # # sub staticIfaceAddressChanged # (iface, old_addr, old_mask, new_addr, new_mask) { my ( $self, $iface, $old_addr, $old_mask, $new_addr, $new_mask) = @_; # my $nr = @{$self->ranges($iface)}; # my $nf = @{$self->fixedAddresses($iface)}; # if(($nr == 0) and ($nf == 0)){ # return 0; # } my $ip = new Net::IP($new_addr); my $network = ip_network($new_addr, $new_mask); my $bits = bits_from_mask($new_mask); my $netIP = new Net::IP("$network/$bits"); # Check ranges my $rangeModel = $self->_getModel('RangeTable', $iface); foreach my $id (@{$rangeModel->ids()}) { my $rangeRow = $rangeModel->row($id); my $range = new Net::IP($rangeRow->valueByName('from') . ' - ' . $rangeRow->valueByName('to')); # Check the range is still in the network unless ($range->overlaps($netIP) == $IP_A_IN_B_OVERLAP){ return 1; } # Check the new IP isn't in any range unless($ip->overlaps($range) == $IP_NO_OVERLAP ){ return 1; } } my $fixedAddrs = $self->fixedAddresses($iface, 0); foreach my $fixedAddr (@{$fixedAddrs}) { my $fixedIP = new Net::IP( $fixedAddr->{'ip'} ); # Check the fixed address is still in the network unless($fixedIP->overlaps($netIP) == $IP_A_IN_B_OVERLAP){ return 1; } # Check the new IP isn't in any fixed address unless( $ip->overlaps($fixedIP) == $IP_NO_OVERLAP){ return 1; } } return 0; } # Function: freeIface # # Delete every single row from the models attached to this # interface # # Implements: # # # # sub freeIface #( self, iface ) { my ( $self, $iface ) = @_; # $self->delete_dir("$iface"); $self->_removeDataModelsAttached($iface); my $net = $self->global()->modInstance('network'); if ($net->ifaceMethod($iface) eq 'static') { $self->_checkStaticIfaces(-1); } } # Method: freeViface # # Delete every single row from the models attached to this virtual # interface # # Implements: # # # # sub freeViface #( self, iface, viface ) { my ( $self, $iface, $viface ) = @_; # $self->delete_dir("$iface:$viface"); $self->_removeDataModelsAttached("$iface:$viface"); # my $net = $self->global()->modInstance('network'); # if ($net->ifaceMethod($viface) eq 'static') { $self->_checkStaticIfaces(-1); # } } # Group: Private methods # Impelment LogHelper interface sub tableInfo { my ($self) = @_; my $titles = { 'timestamp' => __('Date'), 'interface' => __('Interface'), 'mac' => __('MAC address'), 'ip' => __('IP'), 'event' => __('Event') }; my @order = ('timestamp', 'ip', 'mac', 'interface', 'event'); my $events = {'leased' => __('Leased'), 'released' => __('Released') }; return [{ 'name' => __('DHCP'), 'tablename' => 'leases', 'titles' => $titles, 'order' => \@order, 'timecol' => 'timestamp', 'filter' => ['interface', 'mac', 'ip'], 'types' => { 'ip' => 'IPAddr', 'mac' => 'MACAddr' }, 'events' => $events, 'eventcol' => 'event', }]; } sub logHelper { my $self = shift; return (new EBox::DHCPLogHelper); } sub _leaseIDFromIP { my ($ip) = @_; my $id = 'a'; #force every byte to use 3 digits to make sorting trivial my @bytes = split('\.', $ip); for my $byte (@bytes) { $id .= sprintf("%03d", $byte); } return $id; } sub _dhcpLeases { my ($self) = @_; my @stats = stat LEASEFILE; @stats or return {}; my $mtime = $stats[9]; my $refresh = 0; if (defined $self->{leases} and (defined $self->{leasesMTime})) { $refresh = $mtime ne $self->{leasesMTime}; } else { $refresh = 1; } if ($refresh) { $self->{'leases'} = {}; my $leases; try { $leases = Text::DHCPLeases->new(file => LEASEFILE); } otherwise { my $ex = shift; EBox::error('Error parsing DHCP leases file (' . LEASEFILE . "): $ex"); }; if (not $leases) { return $self->{'leases'}; } foreach my $lease ($leases->get_objects()) { my $id = _leaseIDFromIP($lease->ip_address()); $self->{'leases'}->{$id} = $lease; } $self->{leasesMTime} = $mtime; } return $self->{'leases'}; } sub _leaseFromIP { my ($self, $ip) = @_; my $leases = $self->_dhcpLeases(); my $id = _leaseIDFromIP($ip); return $leases->{$id}; } sub dhcpLeasesWidget { my ($self, $widget) = @_; my $section = new EBox::Dashboard::Section('dhcpleases'); $widget->add($section); my $titles = [__('IP address'),__('MAC address'), __('Host name')]; my $leases = $self->_dhcpLeases(); my $ids = []; my $rows = {}; foreach my $id (sort keys (%{$leases})) { my $lease = $leases->{$id}; if($lease->binding_state() eq 'active') { my $hostname = $lease->client_hostname(); $hostname =~ s/"//g; push(@{$ids}, $id); $rows->{$id} = [$lease->ip_address(),$lease->mac_address(), $hostname]; } } $section->add(new EBox::Dashboard::List(undef, $titles, $ids, $rows)); } ### Method: widgets # # Overrides # sub widgets { return { 'dhcpleases' => { 'title' => __("DHCP leases"), 'widget' => \&dhcpLeasesWidget, 'order' => 5, 'default' => 1 } }; } # Group: Private methods # Method: _setDHCPConf # # Updates the dhcpd.conf file # sub _setDHCPConf { my ($self) = @_; # Write general configuration my $net = $self->global()->modInstance('network'); my $staticRoutes_r = $self->staticRoutes(); my $ifacesInfo = $self->_ifacesInfo($staticRoutes_r); my @params = (); push @params, ('dnsone' => $net->nameserverOne()); push @params, ('dnstwo' => $net->nameserverTwo()); push @params, ('thinClientOption' => $self->_areThereThinClientOptions($ifacesInfo)); push @params, ('ifaces' => $ifacesInfo); push @params, ('real_ifaces' => $self->_realIfaces()); my $dynamicDNSEnabled = $self->_dynamicDNSEnabled($ifacesInfo); if ( $dynamicDNSEnabled ) { push @params, ('dynamicDNSEnabled' => $dynamicDNSEnabled); push @params, ('keysFile' => $self->_keysFile()); EBox::Sudo::root('adduser dhcpd bind'); } push(@params, ('pidFile' => PIDFILE)); $self->writeConfFile(DHCPCONFFILE, "dhcp/dhcpd.conf.mas", \@params); } # Method: _setTFTPDConf # # Set the proper files on the TFTPD root dir # sub _setTFTPDConf { } # Method: _ifacesInfo # # Return a well structure to configure dhcp3-server using the # data installed in the module as well as the static routes # provided by modules # # Parameters: # # staticRouters - hash ref containing those static routes to add # to a network which acts as key and the routes as value. # # Returns: # # hash ref - an structure storing the required information for # dhcpd configuration # sub _ifacesInfo { my ($self, $staticRoutes_r) = @_; my $roGlobal = EBox::Global->getInstance('readonly'); my $net = $roGlobal->modInstance('network'); my $ifaces = $net->allIfaces(); my %iflist; foreach my $iface (@{$ifaces}) { if ($net->ifaceMethod($iface) eq 'static') { my $address = $net->ifaceAddress($iface); my $netmask = $net->ifaceNetmask($iface); my $network = ip_network($address, $netmask); $iflist{$iface}->{'net'} = $network; $iflist{$iface}->{'address'} = $address; $iflist{$iface}->{'netmask'} = $netmask; $iflist{$iface}->{'ranges'} = $self->ranges($iface); $iflist{$iface}->{'fixed'} = $self->fixedAddresses($iface, 'readonly'); # look if we have static routes for this network my $netWithMask = EBox::NetWrappers::to_network_with_mask($network, $netmask); if (exists $staticRoutes_r->{$netWithMask}) { $iflist{$iface}->{'staticRoutes'} = $staticRoutes_r->{$netWithMask}; } my $gateway = $self->defaultGateway($iface); if (defined ($gateway)) { if ($gateway) { $iflist{$iface}->{'gateway'} = $gateway; } } else { $iflist{$iface}->{'gateway'} = $address; } my $search = $self->searchDomain($iface); $iflist{$iface}->{'search'} = $search; my $nameserver1 = $self->nameserver($iface,1); if (defined($nameserver1) and $nameserver1 ne "") { $iflist{$iface}->{'nameserver1'} = $nameserver1; } my $nameserver2 = $self->nameserver($iface,2); if (defined($nameserver2) and $nameserver2 ne "") { $iflist{$iface}->{'nameserver2'} = $nameserver2; } # NTP option my $ntpServer = $self->ntpServer($iface); if ( defined($ntpServer) and $ntpServer ne "") { $iflist{$iface}->{'ntpServer'} = $ntpServer; } # WINS/Netbios server option my $winsServer = $self->winsServer($iface); if ( defined($winsServer) and $winsServer ne "") { $iflist{$iface}->{'winsServer'} = $winsServer; } # Leased times my $defaultLeasedTime = $self->_leasedTime('default', $iface); if (defined($defaultLeasedTime)) { $iflist{$iface}->{'defaultLeasedTime'} = $defaultLeasedTime; } my $maxLeasedTime = $self->_leasedTime('max', $iface); if (defined($maxLeasedTime)) { $iflist{$iface}->{'maxLeasedTime'} = $maxLeasedTime; } # Dynamic DNS options my $dynamicDomain = $self->_dynamicDNS('dynamic', $iface); if (defined($dynamicDomain)) { $iflist{$iface}->{'dynamicDomain'} = $dynamicDomain; $iflist{$iface}->{'staticDomain'} = $self->_dynamicDNS('static', $iface); $iflist{$iface}->{'reverseZones'} = $self->_reverseZones($iface); } # TODO: Remove this when more than one config per interface is possible $iflist{$iface}->{'options'} = $self->_thinClientOptions($iface); } } return \%iflist; } # Method: _realIfaces # # Get those interfaces which are real static ones containing the # virtual interfaces names which contain the real static interface # # Returns: # # hash ref - containing interface name as key and an array ref # containing the virtual interface names as value # sub _realIfaces { my ($self) = @_; my $net = $self->global()->modInstance('network'); my $real_ifaces = $net->ifaces(); my %realifs; foreach my $iface (@{$real_ifaces}) { if ($net->ifaceMethod($iface) eq 'static') { $realifs{$iface} = $net->vifaceNames($iface); } } return \%realifs; } # Method: _areThereThinClientOptions # # Check if there are thin client options in order to allow DHCP # server acting as a boot server by setting these options on the # configuration file # # Parameters: # # ifacesInfo - hash ref every static interface is the key and the # value contains every single parameter required to be written on # the configuration file # # Returns: # # Boolean - true if there are thin client options in at least one # iface, false otherwise # sub _areThereThinClientOptions { my ($self, $ifacesInfo) = @_; # TODO: Restore this when more than one config per interface is possible # foreach my $ifaceInfo (values %{$ifacesInfo}) { # foreach my $range (@{$ifaceInfo->{ranges}}) { # if ( values %{$range->{options}} > 0 ) { # return 1; # } # } # foreach my $objFixed (values %{$ifaceInfo->{fixed}}) { # if ( values %{$objFixed->{options}} > 0 ) { # return 1; # } # } # } foreach my $ifaceInfo (values %{$ifacesInfo}) { if ( values %{$ifaceInfo->{options}} > 0 ) { return 1; } } return 0; } # Method: _leasedTime # # Get the leased time (default or maximum) in seconds if any # sub _leasedTime # (which, iface) { my ($self, $which, $iface) = @_; my $advOptionsModel = $self->_getModel('LeaseTimes', $iface); my $fieldName = $which . '_leased_time'; return $advOptionsModel->row()->valueByName($fieldName); } # Method: _thinClientOptions # # Get the thin client options # sub _thinClientOptions # (iface, element) { my ($self, $iface, $element) = @_; my $thinClientModel = $self->_getModel('ThinClientOptions', $iface); my $ret = {}; # TODO: Restore this when more than one config per interface is possible # my $row = $thinClientModel->findValue(hosts => $element); # if ( defined($row) ) { if ($thinClientModel->row()->valueByName('nextServer') ne 'none') { $ret->{nextServerIsZentyal} = $thinClientModel->nextServerIsZentyal();#$row->id()); $ret->{nextServer} = $thinClientModel->nextServer();#$row->id()); $ret->{filename} = $thinClientModel->remoteFilename();#$row->id()); $ret->{architecture} = $thinClientModel->architecture();#$row->id()); $ret->{fat} = $thinClientModel->fat();#$row->id()); } return $ret; } # Method: _dynamicDNS # # Get the domains to be updated by DHCP server (dynamic or statics) # # Returns: # # undef - if the dynamic DNS feature is not enabled # sub _dynamicDNS # (which, iface) { my ($self, $which, $iface) = @_; return undef unless (EBox::Global->modExists('dns')); my $dynamicDNSModel = $self->_getModel('DynamicDNS', $iface); my $dynamicOptionsRow = $dynamicDNSModel->row(); if ($dynamicOptionsRow->valueByName('enabled')) { if ($which eq 'dynamic') { return $dynamicOptionsRow->printableValueByName('dynamic_domain'); } elsif ($which eq 'static') { my $staticOption = $dynamicOptionsRow->elementByName('static_domain'); if ($staticOption->selectedType() eq 'same') { return $dynamicOptionsRow->printableValueByName('dynamic_domain'); } elsif ($staticOption->selectedType() eq 'custom') { return $dynamicOptionsRow->printableValueByName('static_domain'); } } } return undef; } # Return the reverse zones for the given interface sub _reverseZones { my ($self, $iface) = @_; my $initRange = $self->initRange($iface); $initRange =~ s/1$/0/; # To make a network interface my $endRange = $self->endRange($iface); my @revZones; my $ip = new Net::IP("$initRange - $endRange"); do { my $rev = Net::IP->new($ip->ip())->reverse_ip(); if ( defined($rev) ) { # It returns 0.netaddr.in-addr.arpa so we need to remove it # to make it compilant with bind zone definition $rev =~ s/^0\.//; push(@revZones, $rev); } } while ( $ip += 256 ); return \@revZones; } # Return the key file to update DNS sub _keysFile { my ($self) = @_; my $gl = $self->global(); if ( $gl->modExists('dns') ) { my $dnsMod = $gl->modInstance('dns'); if ( $dnsMod->configured() ) { return $dnsMod->keysFile(); } } return ''; } # Return if the dynamic DNS feature is enabled for this DHCP server or # not given the iface list info sub _dynamicDNSEnabled # (ifacesInfo) { my ($self, $ifacesInfo) = @_; return 0 unless ( EBox::Global->modExists('dns') ); if ( defined($ifacesInfo) ) { my $nDynamicOptionsOn = grep { defined($ifacesInfo->{$_}->{'dynamicDomain'}) } keys %{$ifacesInfo}; return ($nDynamicOptionsOn > 0); } else { my $net = $self->global()->modInstance('network'); my $ifaces = $net->allIfaces(); foreach my $iface (@{$ifaces}) { if ( $net->ifaceMethod($iface) eq 'static' ) { my $mod = $self->_getModel('DynamicDNS', $iface); if ( $mod->row()->valueByName('enabled') ) { return 1; } } } return 0; } } # Returns those model instances attached to the given interface sub _removeDataModelsAttached { my ($self, $iface) = @_; my $ifacesModel = $self->model('Interfaces'); my $rowId = $ifacesModel->findId(iface => $iface); $ifacesModel->removeRow($rowId, 1); # # RangeTable/Options/FixedAddressTable # foreach my $modelName (qw(LeaseTimes ThinClientOptions Options RangeTable FixedAddressTable)) { # my $model = $self->_getModel($modelName, $iface); # if ( defined ( $model )) { # $model->removeAll(1); # } # } } # Model getter, check if there are any model with the given # description, if not returns undef sub _getModel { my ($self, $modelName, $iface) = @_; my $row = $self->model('Interfaces')->findRow(iface => $iface); if (not $row) { throw EBox::Exceptions::Internal("Inexistent row for iface $iface") } my $configuration = $row->subModel('configuration'); return $configuration->componentByName($modelName, 1); } sub _getAllModelInstances { my ($self, $modelName) = @_; my @models; my $interfaces = $self->model('Interfaces'); foreach my $id (@{ $interfaces->ids() }) { my $row = $interfaces->row($id); my $configuration = $row->subModel('configuration'); my $model = $configuration->componentByName($modelName, 1); push @models, $model if $model; } return \@models; } # return the Dynamic DNS configutation row for the given iface sub dynamicDNSDomains { my ($self, $iface) = @_; my $ddModel= $self->_getModel('DynamicDNS', $iface); return $ddModel->row(); } # Check there are enough static interfaces to have DHCP service enabled sub _checkStaticIfaces { my ($self, $adjustNumber) = @_; defined $adjustNumber or $adjustNumber = 0; my $nStaticIfaces = $self->_nStaticIfaces() + $adjustNumber; if ($nStaticIfaces == 0) { if ($self->isEnabled()) { $self->enableService(0); EBox::info('DHCP service was deactivated because there was not any static interface left'); } } } # Return the current number of static interfaces sub _nStaticIfaces { my ($self) = @_; my $net = $self->global()->modInstance('network'); my $ifaces = $net->allIfaces(); my $staticIfaces = grep { $net->ifaceMethod($_) eq 'static' } @{$ifaces}; return $staticIfaces; } # Check if the given member is allowed to be a fixed address in the # given interface # It should match the following criteria: # * The member name must be a valid hostname # - If not, then the member name is become to a valid one # * Be a valid host IP address # * Have a valid MAC address # * The IP address must be in range available for the given interface # * It must be not used by in the range for the given interface # * It must be not the interface address # * The member name must be unique in the object realm # * The MAC address must be unique for subnet # sub _allowedMemberInFixedAddress { my ($self, $iface, $member, $objId, $readOnly) = @_; unless (EBox::Validate::checkDomainName($member->{'name'})) { $member->{'name'} = lc($member->{'name'}); $member->{'name'} =~ s/[^a-z0-9\-]/-/g; } if ($member->{mask} != 32 or (not defined($member->{macaddr}))) { return 0; } my $memberIP = new Net::IP($member->{ip}); my $gl = EBox::Global->getInstance($readOnly); my $net = $gl->modInstance('network'); my $objs = $gl->modInstance('objects'); my $netIP = new Net::IP($self->initRange($iface) . '-' . $self->endRange($iface)); # Check if the IP address is within the network unless ($memberIP->overlaps($netIP) == $IP_A_IN_B_OVERLAP) { # The IP address from the member is not in the network EBox::debug('IP address ' . $memberIP->print() . ' is not in the ' . 'network ' . $netIP->print()); return 0; } # Check the IP address is not the interface address my $ifaceIP = new Net::IP($net->ifaceAddress($iface)); unless ( $memberIP->overlaps($ifaceIP) == $IP_NO_OVERLAP ) { # The IP address is the interface IP address EBox::debug('IP address ' . $memberIP->print() . " is the $iface interface address"); return 0; } # Check the member IP address is not within any given range by # RangeTable model my $rangeModel = $self->_getModel('RangeTable', $iface); foreach my $id (@{$rangeModel->ids()}) { my $rangeRow = $rangeModel->row($id); my $from = $rangeRow->valueByName('from'); my $to = $rangeRow->valueByName('to'); my $range = new Net::IP( $from . '-' . $to); unless ( $memberIP->overlaps($range) == $IP_NO_OVERLAP ) { # The IP address is in the range EBox::debug('IP address ' . $memberIP->print() . ' is in range ' . $rangeRow->valueByName('name') . ": $from-$to"); return 0; } } # Check the given member is unique within the object realm my $network = $self->global()->modInstance('network'); my @otherDHCPIfaces = grep { my $other = $_; ($network->ifaceMethod($other) eq 'static') and ($other ne $iface) } @{ $network->InternalIfaces() }; my @fixedAddressTables = map { $self->_getModel('FixedAddressTable', $_) } @otherDHCPIfaces; foreach my $model (@fixedAddressTables) { my $ids = $model->ids(); foreach my $id (@{$ids}) { my $row = $model->row($id); my $otherObjId = $row->valueByName('object'); my $mbs = $objs->objectMembers($otherObjId); next if ( $otherObjId eq $objId); # If they are the same object # Check for the same member name in other object my @matches = grep { $_->{name} eq $member->{name} } @{$mbs}; foreach my $match (@matches) { next unless ( $match->{mask} == 32 and defined($match->{macaddr})); EBox::warn('IP address ' . $memberIP->print() . ' not added ' . 'because there are two members with the same name ' . $member->{name} . ' in other fixed address table'); return 0; } } } # Check for the same MAC address my $fixedAddrModel = $self->_getModel('FixedAddressTable', $iface); my $ids = $fixedAddrModel->ids(); foreach my $id ( @{$ids} ) { my $row = $fixedAddrModel->row($id); my $otherObjId = $row->valueByName('object'); next if ( $otherObjId eq $objId ); # Check done by unique MAC address property my $mbs = $objs->objectMembers($otherObjId); my @matches = grep { defined($_->{macaddr}) and ($_->{macaddr} eq $member->{macaddr}) and ($_->{name} ne $member->{name}) } @{$mbs}; if ( @matches > 0 ) { EBox::warn('MAC address ' . $member->{macaddr} . ' is being ' . 'used by ' . $member->{name} . ' and, at least, ' . $matches[0]->{name}); return 0; } } return 1; } # Method: gatewayDelete # # Overrides: # EBox::NetworkObserver::gatewayDelete sub gatewayDelete { my ($self, $gwName) = @_; my $global = EBox::Global->getInstance($self->{ro}); my $network = $global->modInstance('network'); foreach my $iface (@{$network->allIfaces()}) { next unless ($network->ifaceMethod($iface) eq 'static'); my $options = $self->_getModel('Options', $iface); my $optionsGwName = $options->gatewayName(); if ($gwName eq $optionsGwName) { return 1; } } return 0; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/rootTests/0000775000000000000000000000000012017140107016163 5ustar zentyal-dhcp-2.3.8+quantal1/src/EBox/rootTests/DaemonTest.t0000664000000000000000000000017512017140107020416 0ustar package main; # Description: use strict; use warnings; use lib qw(lib ../..); use DaemonTest; DaemonTest->runtests(); 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/rootTests/lib/0000775000000000000000000000000012017140107016731 5ustar zentyal-dhcp-2.3.8+quantal1/src/EBox/rootTests/lib/DaemonTest.pm0000664000000000000000000001306112017140107021333 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package DaemonTest; use base 'EBox::Test::Class'; use strict; use warnings; use Test::More; use Test::Exception; use Test::MockObject; use EBox::Global::TestStub; use EBox::Module::Config::TestStub; use EBox::Config::TestStub; use EBox::NetWrappers::TestStub; use EBox::TestStubs ('fakeEBoxModule'); use EBox::Service; use lib '../../..'; use EBox::DHCP; my $TEST_IFACE = 'eth1'; my $TEST_ADDRESS = '192.168.32.1'; my $TEST_NETMASK = '255.255.255.0'; sub notice : Test(startup) { diag "This test is designed to be run as root. That is neccesary for try the openvpn daemon execution but it may be a security risk"; diag "We need a dhcp3 server installed with runsysv support for executing this test"; diag "We need a network interface for the test. Now is $TEST_IFACE but it can changed giving another value to \$TEST_IFACE variable"; diag "The given network interface will given a IP address of $TEST_ADDRESS/$TEST_NETMASK; please make sure that the ip and the subnet is available in your system"; system "ifconfig $TEST_IFACE"; die "No $TEST_IFACE interface found" if ($? != 0); } sub testDir { return '/tmp/ebox.dhcp.daemon.test'; } sub _confDir { my ($self) = @_; return $self->testDir . '/conf'; } sub _setupEBoxConf : Test(setup) { my ($self) = @_; my $confDir = $self->_confDir(); my @config = ( '/ebox/modules/dhcp/active' => 0, ); EBox::Module::Config::TestStub::setConfig(@config); EBox::Global::TestStub::setEBoxModule('dhcp' => 'EBox::DHCP'); EBox::Global::TestStub::setEBoxModule('network' => 'EBox::Network'); EBox::Config::TestStub::setConfigKeys(tmp => $self->testDir); Test::MockObject->fake_module('EBox::DHCP', _configureFirewall => sub {$TEST_IFACE => { }}, ); } sub setupFiles : Test(setup) { my ($self) = @_; my $confDir = $self->_confDir(); system "/bin/mkdir -p $confDir"; ($? == 0) or die "mkdir -p $confDir: $!"; } sub setupStubDir : Test(setup) { my ($self) = @_; my $stubDir = $self->testDir() . '/stubs'; system ("/bin/mkdir -p $stubDir/dhcp"); ($? == 0) or die "Error creating temp test subdir $stubDir: $!"; system "/bin/cp ../../../stubs/*.mas $stubDir/dhcp"; ($? ==0 ) or die "Can not copy templates to stub mock dir"; EBox::Config::TestStub::setConfigKeys('stubs' => $stubDir); } sub killDaemons : Test(setup) { EBox::Service::manage('dhcpd3', 'stop'); } sub clearStubDir : Test(teardown) { my ($self) = @_; my $stubDir = $self->testDir() . '/stubs'; system ("/bin/rm -rf $stubDir"); ($? == 0) or die "Error removing temp test subdir $stubDir: $!"; } sub clearConfiguration : Test(teardown) { EBox::Module::Config::TestStub::setConfig(); } sub clearFiles : Test(teardown) { my ($self) = @_; my $confDir = $self->_confDir(); system "/bin/rm -rf $confDir"; if ($? != 0) { die "Can not clear test dir $confDir: $!"; } } sub setupNetwork : Test(setup) { EBox::NetWrappers::TestStub::setFakeIfaces( { $TEST_IFACE => { up => 1, address => $TEST_ADDRESS, netmask => $TEST_NETMASK } } ); EBox::Global::TestStub::setEBoxModule('network' => 'EBox::Network'); my $net = EBox::Global->modInstance('network'); $net->setIfaceStatic($TEST_IFACE, $TEST_ADDRESS, $TEST_NETMASK, 0, 0); } sub daemonTest : Test(10) { diag "Testing dhcp server with simple configuration"; my $dhcp = EBox::Global->modInstance('dhcp'); _checkService($dhcp); } sub daemonTestWithStaticRoutes : Test(10) { diag "Testing dhcp server with static routes"; # setup static route provider modules.. my @macacoStaticRoutes = ( '192.168.32.0/24' => { network => '192.168.4.0', netmask => '255.255.255.0', gateway => '192.168.32.4' }, '10.0.4.0/8' => { network => '192.168.4.0', netmask => '255.0.0.0', gateway => '192.168.30.15' }, ); my @gibonStaticRoutes = ( '192.168.32.0/24' => { network => '192.168.4.0', netmask => '255.255.255.0', gateway => '192.168.32.5' }, ); fakeEBoxModule(name => 'macacoStaticRoutes', isa => ['EBox::DHCP::StaticRouteProvider'], subs => [ staticRoutes => sub { return [@macacoStaticRoutes] } ]); fakeEBoxModule(name => 'gibonStaticRoutes', isa => ['EBox::DHCP::StaticRouteProvider'], subs => [ staticRoutes => sub { return [@gibonStaticRoutes] } ]); fakeEBoxModule(name => 'titiNoStaticRoutes'); fakeEBoxModule(name => 'mandrillNoStaticRoutes'); # run the service test my $dhcp = EBox::Global->modInstance('dhcp'); _checkService($dhcp); } sub _checkService { my ($dhcp) = @_; my @serviceSequences = qw(0 0 1 1 0); foreach my $service (@serviceSequences) { $dhcp->setService($service); lives_ok { $dhcp->restartService() } 'Regenerating configuration for dhcp server'; sleep 1; # avoid race problems my $actualService = EBox::Service::running('dhcpd3') ? 1 : 0; is $actualService, $service, 'Checking if service is the expected'; } } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/DHCPLogHelper.pm0000664000000000000000000000477312017140107017046 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCPLogHelper; package EBox::DHCPLogHelper; use base 'EBox::LogHelper'; use strict; use warnings; use EBox; use EBox::Config; use EBox::Gettext; use constant DHCPLOGFILE => '/var/log/syslog'; sub new { my $class = shift; my $self = {}; bless($self, $class); return $self; } # Method: logFiles # # This function must return the file or files to be read from. # # Returns: # # array ref - containing the whole paths # sub logFiles { return [DHCPLOGFILE]; } # Method: processLine # # This fucntion will be run every time a new line is recieved in # the associated file. You must parse the line, and generate # the messages which will be logged to ebox through an object # implementing EBox::AbstractLogger interface. # # Parameters: # # file - file name # line - string containing the log line # dbengine- An instance of class implemeting AbstractDBEngineinterface # sub processLine # (file, line, logger) { my ($self, $file, $line, $dbengine) = @_; return unless ($line =~ /^(\w+\s+\d+ \d\d:\d\d:\d\d) \S+ dhcpd:.*/); my $date = $1 . ' ' . (${[localtime(time)]}[5] + 1900); my ($ip, $mac, $iface, $event); if ($line =~ /^.*DHCPACK on ([\d.]+) to ([\d:a-f]{17}).*?via (\w+)/) { $ip = $1; $mac = $2; $iface =$3; $event = 'leased'; } elsif ($line =~ /^.*DHCPRELEASE of ([\d.]+) from ([\d:a-f]{17}).*?via (\w+)/) { $ip = $1; $mac = $2; $iface =$3; $event = 'released'; } else { return; } my $timestamp = $self->_convertTimestamp('%b %e %H:%M:%S %Y', $date); my $data = { 'timestamp' => $timestamp, 'ip' => $ip, 'mac' => $mac, 'interface' => $iface, 'event' => $event }; $dbengine->insert('leases', $data); } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/DHCP/0000775000000000000000000000000012017140107014673 5ustar zentyal-dhcp-2.3.8+quantal1/src/EBox/DHCP/StaticRouteProvider.pm0000664000000000000000000000266012017140107021216 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package EBox::DHCP::StaticRouteProvider; use strict; use warnings; use EBox::Global; # Method: staticRoutes # # The static routes provider must use this method to return the static routes which must be pushed out by the dhcp server # # Returns: # the reference to a list with net and routes pairs. The net is provided in CIDR notation and the route is a hash reference with the following fields: network, dnetmask, gatewat sub staticRoutes { throw EBox::Exceptions::Internal ('staticRoutes not implemented'); } # Method: notifyStaticRoutesChange # # This must be called by the static routes providers when their routes change sub notifyStaticRoutesChange { my $dhcp = EBox::Global->modInstance('dhcp'); $dhcp->notifyStaticRoutesChange(); } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/DHCP/Types/0000775000000000000000000000000012017140107015777 5ustar zentyal-dhcp-2.3.8+quantal1/src/EBox/DHCP/Types/Group.pm0000664000000000000000000000433312017140107017434 0ustar # Copyright (C) 2011-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Types::Group # # This class implements an object within the DHCP realm with an # index in the constructor to be able to select the objects used # by FixedAddressTable model package EBox::DHCP::Types::Group; use strict; use warnings; use base 'EBox::Types::Select'; # uses use EBox::Exceptions::MissingArgument; use EBox::Model::Manager; # Group: Public methods # Constructor: new # sub new { my ($class, %opts) = @_; my $self = $class->SUPER::new(%opts); foreach my $opt (qw(index foreignModelName)) { unless (exists $self->{$opt} ) { throw EBox::Exceptions::MissingArgument($opt); } } return $self; } # Method: options # # Return the options manually # # Overrides: # # # sub options { my ($self) = @_; if ((not exists $self->{'options'}) or $self->disableCache()) { $self->{'options'} = $self->_options(); } return $self->{'options'}; } # Group: Private methods # Get the objects from the FixedAddressTable sub _options { my ($self) = @_; my $modelName = $self->{foreignModelName}; my $iface = $self->{index}; my $model = EBox::Model::Manager->instance()->model("/dhcp/$modelName/$iface"); my @options; foreach my $id (@{$model->ids()}) { my $row = $model->row($id); push(@options, { value => $row->valueByName($self->{foreignField}), printableValue => $row->printableValueByName($self->{foreignField}) }); } return \@options; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/DHCP/Test.pm0000664000000000000000000001160212017140107016150 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package EBox::DHCP::Test; use base 'EBox::Test::Class'; # Description: use strict; use warnings; use Test::More; use Test::Exception; use EBox::Global; use EBox::Test qw(checkModuleInstantiation); use EBox::TestStubs qw(fakeEBoxModule); use Test::MockObject::Extends; use Test::Differences; use lib '../..'; my $nStaticIfacesReturnValue = 1; # this controls the output of EBox::DHCP::nStaticIfaces sub _moduleInstantiationTest : Test { checkModuleInstantiation('dhcp', 'EBox::DHCP'); Test::MockObject->fake_module('EBox::DHCP', nStaticIfaces => sub { return $nStaticIfacesReturnValue }, _configureFirewall => sub {}, ); } sub setDHCPEBoxModule : Test(setup) { EBox::Global::TestStub::setEBoxModule('dhcp' => 'EBox::DHCP'); EBox::Module::Config::TestStub::setEntry('/ebox/modules/dhcp/active', 0); EBox::Module::Config::TestStub::setEntry('/ebox/modules/global/modules/dhcp/depends', ['network']); } sub clearEBoxModules : Test(teardown) { EBox::Global::TestStub::setAllEBoxModules(); } sub setServiceTest : Test(6) { my $dhcp = EBox::Global->modInstance('dhcp'); $nStaticIfacesReturnValue = 1; lives_ok { $dhcp->setService(1) } 'Setting active service with static ifaces'; ok $dhcp->isEnabled(), 'Checking that server is now active'; lives_ok { $dhcp->setService(0) } 'Unsetting service'; ok !$dhcp->isEnabled(), 'Checking that server is now inactive'; $nStaticIfacesReturnValue = 0; dies_ok { $dhcp->setService(1) } 'Attempt to set the server active without static ifaces must raise error'; ok !$dhcp->isEnabled(), 'Checking that server state remains inactive'; } sub ifaceMethodChangedTest : Test(32) { my @problematicChanges = (['static', 'dhcp'], ['static', 'notset'], ['static', 'trunk']); my @harmlessChanges = ( ['static', 'static'], ['dhcp', 'static'], ['dhcp', 'dhcp'], ['dhcp', 'notset' ], ['dhcp', 'trunk'], ['notset', 'static'], ['notset', 'dhcp'], ['notset', 'notset' ], ['notset', 'trunk'], ['trunk', 'static'], ['trunk', 'dhcp'], ['trunk', 'notset' ], ['trunk', 'trunk'], ); my $dhcp = EBox::Global->modInstance('dhcp'); ok !$dhcp->ifaceMethodChanged('eth0', @{ $_ }), 'Testing if dhcp inactive server allows a harmless change in network interface IP method' foreach @harmlessChanges; ok !$dhcp->ifaceMethodChanged('eth0', @{ $_ }), 'Testing if dhcp inactive server allows a change in network interface IP method' foreach @problematicChanges; $nStaticIfacesReturnValue = 10; $dhcp->setService(1); ok !$dhcp->ifaceMethodChanged('eth0', @{ $_ }), 'Testing if dhcp server allows a harmless change in network interface IP method' foreach @harmlessChanges; ok $dhcp->ifaceMethodChanged('eth0', @{ $_ }), 'Testing if dhcp server disallows a problematic change in network interface IP method' foreach @problematicChanges; } sub staticRoutes : Test(2) { my @macacoStaticRoutes = ( '192.168.30.0/24' => { network => '192.168.4.0', netmask => '255.255.255.0', gateway => '192.168.30.4' }, '10.0.0.8/8' => { network => '192.168.4.0', netmask => '255.255.254.0', gateway => '10.0.10.5' }, ); my @gibonStaticRoutes = ( '192.168.30.0/24' => { network => '192.168.4.0', netmask => '255.0.0.0', gateway => '192.168.30.15' }, ); fakeEBoxModule(name => 'macacoStaticRoutes', isa => ['EBox::DHCP::StaticRouteProvider'], subs => [ staticRoutes => sub { return [@macacoStaticRoutes] } ]); fakeEBoxModule(name => 'gibonStaticRoutes', isa => ['EBox::DHCP::StaticRouteProvider'], subs => [ staticRoutes => sub { return [@gibonStaticRoutes] } ]); fakeEBoxModule(name => 'titiNoStaticRoutes'); fakeEBoxModule(name => 'mandrillNoStaticRoutes'); my $dhcp = EBox::Global->modInstance('dhcp'); my $staticRoutes_r; my %expectedRoutes = ( '192.168.30.0/24' => [ { network => '192.168.4.0', netmask => '255.255.255.0', gateway => '192.168.30.4' }, { network => '192.168.4.0', netmask => '255.0.0.0', gateway => '192.168.30.15' }, ], '10.0.0.8/8' => [ { network => '192.168.4.0', netmask => '255.255.254.0', gateway => '10.0.10.5' } ], ); lives_ok { $staticRoutes_r = $dhcp->staticRoutes() } 'Calling staticRoutes'; eq_or_diff $staticRoutes_r, \%expectedRoutes, 'Checking staticRoutes result'; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/0000775000000000000000000000000012017140107015215 5ustar zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/FixedAddressTable.pm0000664000000000000000000002054112017140107021072 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::FixedAddressTable # # This class is used to set the fixed addresses on a dhcp server # attached to an interface. The fields are the following: # # - object: Network Object (Foreign model) # - description : Text # package EBox::DHCP::Model::FixedAddressTable; use strict; use warnings; use EBox::Exceptions::External; use EBox::Global; use EBox::Gettext; use EBox::NetWrappers; use EBox::Types::Text; use EBox::Types::Select; use base 'EBox::Model::DataTable'; # Constructor: new # # Constructor for Rule table # # Returns : # # A recently created object # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless($self, $class); return $self; } # Method: validateTypedRow # # Overrides: # # # sub validateTypedRow { my ($self, $action, $changedFields, $allFields) = @_; # # Check the given fixed address is not in any user given # # range, it is within the available range and it cannot be the # # interface address # if ( exists ( $changedFields->{ip} )) { # my $newIP = new Net::IP($changedFields->{ip}->value()); # my $net = EBox::Global->modInstance('network'); # my $dhcp = $self->{confmodule}; # my $netIP = new Net::IP( $dhcp->initRange($self->{interface}) . '-' # . $dhcp->endRange($self->{interface})); # # Check if the ip address is within the network # unless ( $newIP->overlaps($netIP) == $IP_A_IN_B_OVERLAP ) { # throw EBox::Exceptions::External(__x('IP address {ip} is not in ' # . 'network {net}', # ip => $newIP->print(), # net => EBox::NetWrappers::to_network_with_mask( # $net->ifaceNetwork($self->{interface}), # $net->ifaceNetmask($self->{interface})) # )); # } # # Check the ip address is not the interface address # my $ifaceIP = new Net::IP($net->ifaceAddress($self->{interface})); # unless ( $newIP->overlaps($ifaceIP) == $IP_NO_OVERLAP ) { # throw EBox::Exceptions::External(__x('The selected IP is the ' # . 'interface IP address: ' # . '{ifaceIP}', # ifaceIP => $ifaceIP->print() # )); # } # # Check the new IP is not within any given range by RangeTable model # # FIXME: When #847 is done # # my $rangeModel = $dhcp->model('RangeTable'); # my $rangeModel = EBox::Model::Manager->instance()->model('/dhcp/RangeTable/' # . $self->{interface}); # foreach my $id (@{$rangeModel->ids()}) { # my $rangeRow = $rangeModel->row($id); # my $from = $rangeRow->valueByName('from'); # my $to = $rangeRow->valueByName('to'); # my $range = new Net::IP( $from . '-' . $to); # unless ( $newIP->overlaps($range) == $IP_NO_OVERLAP ) { # throw EBox::Exceptions::External(__x('IP address {ip} is in range ' # . "'{range}': {from}-{to}", # ip => $newIP->print(), # range => $rangeRow->valueByName('range'), # from => $from, to => $to)); # } # } # } # if ( exists ( $changedFields->{name} )) { # my $newName = $changedFields->{name}->value(); # # Check remainder FixedAddressTable models uniqueness since # # the dhcpd.conf may confuse those name repetition # my @fixedAddressTables = @{EBox::Model::Manager->instance()->model( # '/dhcp/FixedAddressTable/*' # )}; # # Delete the self model # @fixedAddressTables = grep { $_->index() ne $self->index() } # @fixedAddressTables; # my $row = grep { $_->findValue( name => $newName ) } # @fixedAddressTables; # if ( $row ) { # my $i18nAction = ''; # if ( $action eq 'update' ) { # $i18nAction = __('update'); # } else { # $i18nAction = __('add'); # } # throw EBox::Exceptions::External(__x('You cannot {action} a fixed address with a ' # . 'name which is already used in other fixed ' # . 'address table', # action => $i18nAction)); # } # } } # Method: viewCustomizer # # Overrides this to warn the user only those members with an IP # address within the valid range and a MAC address and not in the # range. # # Overrides: # # # sub viewCustomizer { my ($self) = @_; my $customizer = new EBox::View::Customizer(); $customizer->setModel($self); $customizer->setPermanentMessage(_message()); $customizer->setHTMLTitle([]); return $customizer; } # Group: Protected methods # Method: _table # # Describe the DHCP ranges table # # Returns: # # hash ref - table's description # sub _table { my ($self) = @_; my @tableDesc = ( new EBox::Types::Select( fieldName => 'object', foreignModel => $self->objectModelGetter(), foreignField => 'name', foreignNextPageField => 'members', printableName => __('Object'), unique => 1, editable => 1, optional => 0, ), new EBox::Types::Text( fieldName => 'description', printableName => __('Description'), editable => 1, optional => 1, ), ); my $dataTable = { 'tableName' => 'FixedAddressTable', 'printableTableName' => __('Fixed addresses'), 'defaultActions' => [ 'add', 'del', 'editField', 'changeView' ], 'modelDomain' => 'DHCP', 'tableDescription' => \@tableDesc, 'class' => 'dataTable', 'rowUnique' => 1, # Set each row is unique 'printableRowName' => __('fixed address'), 'order' => 0, # Ordered by tailoredOrder 'sortedBy' => 'object', }; return $dataTable; } sub objectModelGetter { my ($self) = @_; my $global = $self->global(); return sub { return $global->modInstance('objects')->model('ObjectTable'); }; } sub _message { return __('Only those object members whose IP address is a host (/32), a ' . 'valid MAC, the IP address is not used by the available range ' . 'and whose name is unique as fixed address will be used') . '. ' . __('Members whose name is not a valid hostname will be modified to ' . 'become a valid domain name.'); } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/LeaseTimes.pm0000664000000000000000000001363712017140107017620 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::LeaseTimes # # This class is the model to configurate lease times for the dhcp # server on a static interface. The fields are the following: # # - default leased time # - maximum leased time # package EBox::DHCP::Model::LeaseTimes; use base 'EBox::Model::DataForm'; use strict; use warnings; use EBox::Exceptions::External; use EBox::Exceptions::InvalidData; use EBox::Exceptions::MissingArgument; use EBox::Gettext; use EBox::Global; use EBox::Types::Int; use EBox::Validate; # Constants use constant DEFAULT_LEASED_TIME => 1800; use constant MAX_LEASED_TIME => 7200; # Group: Public methods # Constructor: new # # Create the lease times to the dhcp server # # Overrides: # # # # Returns: # # # # Exceptions: # # - thrown if any compulsory # argument is missing # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless ($self, $class); return $self; } # Method: validateTypedRow # # Overrides: # # # sub validateTypedRow { my ($self, $action, $changedFields, $allFields) = @_; # Validate leased times if ( exists $changedFields->{default_leased_time} ) { # Check if the default time is lower than maximum my $defaultTime = $changedFields->{default_leased_time}->value(); if ( $defaultTime < 0 ) { throw EBox::Exceptions::External(__('Default leased time must be ' . 'higher than 0 seconds')); } if ( defined($allFields->{max_leased_time}) ) { my $maxTime = $allFields->{max_leased_time}->value(); if ( $defaultTime > $maxTime ) { throw EBox::Exceptions::External(__x('Default leased time {default} ' . 'must be lower than maximum ' . 'one {max}', default => $defaultTime, max => $maxTime)); } } } if ( exists $changedFields->{max_leased_time} ) { # Check if the default time is lower than maximum my $maxTime = $changedFields->{max_leased_time}->value(); if ( $maxTime < 0 ) { throw EBox::Exceptions::External(__('Maximum leased time must be ' . 'higher than 0 seconds')); } if (defined($allFields->{default_leased_time})) { my $defaultTime = $allFields->{default_leased_time}->value(); if ( $maxTime < $defaultTime ) { throw EBox::Exceptions::External(__x('Maximum leased time {max} ' . 'must be higher than default ' . 'one {default}', max => $maxTime, default => $defaultTime)); } } } } # Method: formSubmitted # # When the form is submitted, the model must set up the jabber # dispatcher client service and sets the output rule in the # firewall # # Overrides: # # # sub formSubmitted { my ($self, $oldRow) = @_; } # Group: Protected methods # Method: _table # # Overrides: # # # sub _table { my ($self) = @_; my @tableDesc = ( new EBox::Types::Int( fieldName => 'default_leased_time', printableName => __('Default leased time'), editable => 1, defaultValue => DEFAULT_LEASED_TIME, trailingText => __('seconds'), ), new EBox::Types::Int( fieldName => 'max_leased_time', printableName => __('Maximum leased time'), editable => 1, defaultValue => MAX_LEASED_TIME, trailingText => __('seconds'), ), ); my $dataForm = { tableName => 'LeaseTimes', printableTableName => __('Lease times'), modelDomain => 'DHCP', defaultActions => [ 'editField', 'changeView' ], tableDescription => \@tableDesc, class => 'dataForm', help => __('Leased time is the time which a given ' . 'IP address is valid by the DHCP server'), }; return $dataForm; } # Method: viewCustomizer # # Overrides # # sub viewCustomizer { my ($self) = @_; my $customizer = new EBox::View::Customizer(); $customizer->setModel($self); $customizer->setHTMLTitle([]); return $customizer; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/DynamicDNS.pm0000664000000000000000000002446212017140107017514 0ustar # Copyright (C) 2009-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::DynamicDNS # # This class is the model to configurate dynamic DNS options for DHCP # server and DNS server on a static interface. The fields are the following: # # - enabled # - dynamic domain # - static domain # package EBox::DHCP::Model::DynamicDNS; use base 'EBox::Model::DataForm'; use strict; use warnings; use EBox::Exceptions::External; use EBox::Gettext; use EBox::Global; use EBox::Types::Select; use EBox::Types::Union; use EBox::Types::Union::Text; use EBox::View::Customizer; # Dependencies # Group: Public methods # Constructor: new # # Create the dynamic DNS options to the dhcp server # # Overrides: # # # # Returns: # # # # Exceptions: # # - thrown if any compulsory # argument is missing # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless ($self, $class); return $self; } # Method: formSubmitted # # When the form is submitted, do something # # Overrides: # # # sub formSubmitted { my ($self, $oldRow) = @_; # We assume the DNS module exists and is configured my $newRow = $self->row(); my $dnsMod = EBox::Global->modInstance('dns'); my $msg = ''; if ($newRow->valueByName('enabled')) { # Manage dynamic domain $msg .= $self->_manageZone(newDomain => $newRow->valueByName('dynamic_domain'), oldDomain => $oldRow->valueByName('dynamic_domain'), dns => $dnsMod); # Manage static domain my ($newDomain, $oldDomain) = ($newRow->valueByName('static_domain'), $oldRow->valueByName('static_domain')); if ( $newRow->elementByName('static_domain')->selectedType() eq 'same' ) { $newDomain = undef; } if ( $oldRow->elementByName('static_domain')->selectedType() eq 'same' ) { $oldDomain = undef; } if ( $msg ) { $msg .= '. '; } $msg .= $self->_manageZone(newDomain => $newDomain, oldDomain => $oldDomain, dns => $dnsMod); # Enable again if necessary for notifying other models using # the same previous domain my $currentRow = $self->row(); $currentRow->elementByName('enabled')->setValue(1); $currentRow->store(); } elsif ( $oldRow->valueByName('enabled') ) { # If it was enabled, remove old domains $msg .= $self->_manageZone(newDomain => undef, oldDomain => $oldRow->valueByName('dynamic_domain'), dns => $dnsMod); # Delete the static if it is different than dynamic if ( $oldRow->elementByName('static_domain')->selectedType() eq 'custom' ) { if ( $msg ) { $msg .= '. '; } $msg .= $self->_manageZone(newDomain => undef, oldDomain => $oldRow->valueByName('static_domain'), dns => $dnsMod); } } EBox::debug("message: $msg"); $self->setMessage($msg) if ( $msg ); } # Method: precondition # # Overrides: # # # sub precondition { my $gl = EBox::Global->getInstance(); if ( $gl->modExists('dns') ) { my $dns = $gl->modInstance('dns'); return $dns->configured(); } return 0; } # Method: preconditionFailMsg # # Overrides: # # # sub preconditionFailMsg { my $gl = EBox::Global->getInstance(); if ( $gl->modExists('dns') ) { my $dns = $gl->modInstance('dns'); unless ( $dns->configured() ) { return __('DNS module must be configured to work with this feature'); } } else { return __x('{pkg} must be installed to use this feature', pkg => 'zentyal-dns'); } } # Method: viewCustomizer # # Overrides this to warn the user about the usage of this feature # depends on ebox-dns module to work and it has to be enabled to work. # # Overrides: # # # sub viewCustomizer { my ($self) = @_; my $customizer = new EBox::View::Customizer(); $customizer->setModel($self); my $gl = EBox::Global->getInstance(); if ( $gl->modExists('dns') ) { my $dns = $gl->modInstance('dns'); unless ( $dns->isEnabled() ) { my $msg = __('DNS module must be enabled to make this feature work.'); $customizer->setPermanentMessage($msg); } } $customizer->setHTMLTitle([]); return $customizer; } # Method: notifyForeignModelAction # # Disable DynamicDNS configuration for this model if the domain is # deleted from the interface or from another interface in DHCP # configuration # # Overrides: # # # sub notifyForeignModelAction { my ($self, $model, $action, $row) = @_; # TODO: update action is not yet supported, since we do not have # the old row to check the usage of the domain, currently, it is # not possible to edit a dynamic domain if ($action eq 'del') { if ( $row->id() eq $self->row()->valueByName('dynamic_domain') or $row->id() eq $self->row()->valueByName('static_domain') ) { # Disable the dynamic DNS feature, in formSubmitted we # have to enable again (:-S) my $row = $self->row(); if ( $row->valueByName('enabled') ) { $row->elementByName('enabled')->setValue(0); $row->store(); return __x('Dynamic DNS feature has been disabled in DHCP module ' . 'in {iface} interface.', iface => $self->index()); } } } return ''; } # Group: Protected methods # Method: _table # # Overrides: # # # sub _table { my ($self) = @_; my @tableDesc = ( new EBox::Types::Select( fieldName => 'dynamic_domain', printableName => __('Dynamic domain'), editable => 1, help => __('Domain name appended to the hostname from those clients ' . 'whose leased IP address comes from a range'), foreignModel => \&_domainModel, foreignField => 'domain', ), new EBox::Types::Union( fieldName => 'static_domain', printableName => __('Static domain'), editable => 1, help => __('Domain name appended to the hostname from those clients ' . 'with a fixed address mapping'), subtypes => [ new EBox::Types::Union::Text( fieldName => 'same', printableName => __('Same as Dynamic Domain'), ), new EBox::Types::Select( fieldName => 'custom', printableName => __('Custom'), editable => 1, foreignModel => \&_domainModel, foreignField => 'domain', ), ]), ); my $dataForm = { tableName => 'DynamicDNS', printableTableName => __('Dynamic DNS Options'), modelDomain => 'DHCP', defaultActions => [ 'editField', 'changeView' ], tableDescription => \@tableDesc, class => 'dataForm', help => __('The domains will be added automatically to ' . 'DNS module in read-only mode'), # The support may be enabled or not enableProperty => 1, # Notify when changes in DomainTable notifyActions => [ 'DomainTable' ], }; return $dataForm; } # Group: Private methods # Add/remove the zone/domain from DNS # Returns a message to inform the user sub _manageZone { my ($self, %args) = @_; my $msg = ""; if ( defined($args{newDomain}) ) { my $domainRow = $args{dns}->model('DomainTable')->row($args{newDomain}); if ( defined($domainRow) ) { $domainRow->elementByName('dynamic')->setValue(1); $domainRow->store(); $msg = __x('Domain "{domain}" set as dynamic in DNS section', domain => $domainRow->printableValueByName('domain')); } else { throw EBox::Exceptions::Internal('Trying to modify a not valid domain from dhcp module'); } } if (defined($args{oldDomain}) and ($args{oldDomain} ne $args{newDomain})) { my $domainRow = $args{dns}->model('DomainTable')->row($args{oldDomain}); if ( defined($domainRow) ) { $domainRow->elementByName('dynamic')->setValue(0); $domainRow->store(); if ( $msg ) { $msg .= '. '; } $msg .= __x('Domain "{domain}" set as static in DNS section', domain => $domainRow->printableValueByName('domain')); } # else already remove by previous caller (delete a domain from DNS) } return $msg; } # Get the domain model sub _domainModel { if ( EBox::Global->modExists('dns') ) { return EBox::Global->modInstance('dns')->model('DomainTable'); } else { return undef; } } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/Interfaces.pm0000664000000000000000000001036712017140107017645 0ustar # Copyright (C) 2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::Interfaces # # This class is used to display in a select form those interface # configuration composites to configure the DHCP server. This # composite is just a container for # composites indexed by # interface's name # package EBox::DHCP::Model::Interfaces; use base 'EBox::Model::DataTable'; use strict; use warnings; use EBox::Gettext; use EBox::Types::Boolean; use EBox::Types::Text; use EBox::Types::HasMany; # Group: Public methods # Constructor: new # # Constructor for the dhcp interfaces model # # Returns: # # - a # interfaces dhcp composite # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless($self, $class); return $self; } sub precondition { my ($self) = @_; my $global = EBox::Global->getInstance($self->parentModule->isReadOnly()); my $net = $global->modInstance('network'); my @ifaces = @{$net->allIfaces()}; foreach my $iface (@ifaces) { if ($net->ifaceMethod($iface) eq 'static') { return 1; } } return 0; } sub preconditionFailMsg { my ($self) = @_; return __('You need at least one static interface to serve DHCP'); } # Method: syncRows # # Overrides # sub syncRows { my ($self, $currentRows) = @_; my $global = EBox::Global->getInstance($self->parentModule()->isReadOnly()); my $net = $global->modInstance('network'); my @ifaces = @{$net->allIfaces()}; @ifaces = grep { $net->ifaceMethod($_) eq 'static' } @ifaces; my %newIfaces = map { $_ => 1 } @ifaces; my %currentIfaces = map { $self->row($_)->valueByName('iface') => 1 } @{$currentRows}; my $modified = 0; my @ifacesToAdd = grep { not exists $currentIfaces{$_} } @ifaces; foreach my $iface (@ifacesToAdd) { $self->add(iface => $iface); $modified = 1; } # Remove old rows foreach my $id (@{$currentRows}) { my $row = $self->row($id); my $ifaceName = $row->valueByName('iface'); next if exists $newIfaces{$ifaceName}; $self->removeRow($id); $modified = 1; } return $modified; } # Group: Protected methods sub _table { my @tableDesc = ( new EBox::Types::Text( fieldName => 'iface', printableName => __('Interface'), editable => 0, optional => 0, ), new EBox::Types::HasMany( fieldName => 'configuration', printableName => __('Configuration'), foreignModel => 'InterfaceConfiguration', foreignModelIsComposite => 1, view => '/DHCP/Composite/InterfaceConfiguration', backView => '/DHCP/View/Interfaces', ), ); my $dataTable = { tableName => 'Interfaces', modelDomain => 'DHCP', pageTitle => 'DHCP', printableTableName => __('Interfaces'), tableDescription => \@tableDesc, defaultActions => [ 'changeView', 'editField' ], enableProperty => 1, defaultEnabledValue => 1, help => __('Here you can configure the DHCP server for each internal interface, and enable or disable them'), printableRowName => __('interface'), }; return $dataTable; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/Options.pm0000664000000000000000000004554012017140107017216 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::Options # # This class is the model to configurate general options for the dhcp # server on a static interface. The fields are the following: # # - default gateway # - search domain # - primary nameserver # - second nameserver # package EBox::DHCP::Model::Options; use base 'EBox::Model::DataForm'; use strict; use warnings; use EBox::Exceptions::External; use EBox::Exceptions::InvalidData; use EBox::Exceptions::MissingArgument; use EBox::Gettext; use EBox::Global; use EBox::NetWrappers; use EBox::Types::DomainName; use EBox::Types::HostIP; use EBox::Types::Select; use EBox::Types::Union; use EBox::Types::Union::Text; use EBox::Validate; # Dependencies use Net::IP; # Group: Public methods # Constructor: new # # Create the general options to the dhcp server # # Overrides: # # # # Returns: # # # # Exceptions: # # - thrown if any compulsory # argument is missing # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless ( $self, $class); $self->{netMod} = EBox::Global->modInstance('network'); return $self; } # Method: validateTypedRow # # Overrides: # # # sub validateTypedRow { my ($self, $action, $changedFields, $allFields) = @_; my $interface = $self->_interface(); # Validate default gateway if ( exists $changedFields->{default_gateway} ) { # Check the given gateway is in the current network my $networkCIDR = EBox::NetWrappers::to_network_with_mask( $self->{netMod}->ifaceNetwork($interface), $self->{netMod}->ifaceNetmask($interface), ); my $networkIP = new Net::IP($networkCIDR); my $defaultGwType = $changedFields->{default_gateway}; my $selectedTypeName = $defaultGwType->selectedType(); my ($defaultGwIP, $gwName); if ($selectedTypeName eq 'ip') { $defaultGwIP = new Net::IP($defaultGwType->value()); $gwName = $defaultGwIP->print(); } elsif ($selectedTypeName eq 'name') { my $gwModel = $defaultGwType->foreignModel(); my $row = $gwModel->row( $defaultGwType->value() ); $defaultGwIP = new Net::IP($row->{plainValueHash}->{ip}); $gwName = $defaultGwType->printableValue(); } if (defined ($defaultGwIP)) { unless ($defaultGwIP->overlaps($networkIP) == $IP_A_IN_B_OVERLAP ) { throw EBox::Exceptions::External(__x('{gateway} is not in the ' . 'current network', gateway => $gwName)); } } } # Validate primary Nameserver if (exists $changedFields->{primary_ns}) { # Check if chosen is DNS to check if it's enabled if ($changedFields->{primary_ns}->selectedType() eq 'eboxDNS') { my $dns = EBox::Global->modInstance('dns'); unless ($dns->isEnabled()) { throw EBox::Exceptions::External(__('DNS module must be enabled to be able to select Zentyal as primary DNS server')); } } } # Validate NTP server if ( exists $changedFields->{ntp_server} ) { # Check if chosen is NTP to check if it is enabled if ( $changedFields->{ntp_server}->selectedType() eq 'eboxNTP' ) { my $ntp = EBox::Global->modInstance('ntp'); unless ( $ntp->isEnabled() ) { throw EBox::Exceptions::External(__('NTP module must be enabled to be able to select Zentyal as NTP server')); } } } # Validate WINS server if ( exists $changedFields->{wins_server} ) { # Check if chosen is WINS to check if it is enabled if ( $changedFields->{wins_server}->selectedType() eq 'eboxWINS' ) { my $sambaMod = EBox::Global->modInstance('samba'); unless ( $sambaMod->isEnabled() ) { throw EBox::Exceptions::External( __('Samba module must be enabled to be able to select Zentyal as WINS server') ); } } } } # Method: defaultGateway # # Get the current default gateway # # Returns: # # String - the current default gateway in a IP address form # sub defaultGateway { my ($self) = @_; my $row = $self->row(); my $gwType = $row->elementByName('default_gateway'); my $selectedTypeName = $gwType->selectedType(); if ( $selectedTypeName eq 'ip' ) { return $gwType->subtype->value(); } elsif ( $selectedTypeName eq 'name' ) { my $gwModel = $gwType->subtype()->foreignModel(); my $row = $gwModel->row( $gwType->subtype()->value() ); return $row->valueByName('ip'); } elsif ( $selectedTypeName eq 'none' ) { return ''; } elsif ( $selectedTypeName eq 'ebox' ) { return $self->{netMod}->ifaceAddress($self->_interface()); } } # Method: gatewayName # # If gateway is set to a 'configured gateway' it returns it name. If gateway is # set to another type, returns undef sub gatewayName { my ($self) = @_; my $row = $self->row(); my $gw = $row->elementByName('default_gateway'); if ($gw->selectedType() eq 'name') { my $gwModel = $gw->subtype()->foreignModel(); my $gwName = $gwModel->row( $gw->subtype()->value())->valueByName('name'); return $gwName } return undef; } # Method: searchDomain # # Get the current search domain # # Returns: # # String - the current search domain if any, otherwise undef # sub searchDomain { my ($self) = @_; my $row = $self->row(); my $selectedType = $row->elementByName('search_domain')->selectedType(); if ( $selectedType eq 'none' ) { return undef; } else { return $row->elementByName('search_domain')->subtype()->printableValue(); } } # Method: nameserver # # Get the primary or secondary nameserver for this options interface # # Parameters: # # number - Int 1 or 2 # # Returns: # # String - the current nameserver IP if any, otherwise undef # sub nameserver { my ($self, $number) = @_; my $row = $self->row(); my $selectedType; if ( $number == 1 ) { $selectedType = $row->elementByName('primary_ns')->selectedType(); if ( $selectedType eq 'none' ) { return undef; } elsif ( $selectedType eq 'eboxDNS' ) { my $ifaceAddr = $self->{netMod}->ifaceAddress($self->_interface()); return $ifaceAddr; } else { return $row->elementByName('primary_ns')->subtype()->printableValue(); } } else { return $row->printableValueByName('secondary_ns'); } } # Method: ntpServer # # Get the current IP address from the NTP server # # Returns: # # String - the current NTP server if any, otherwise undef is returned # sub ntpServer { my ($self) = @_; my $row = $self->row(); my $selectedType = $row->elementByName('ntp_server')->selectedType(); if ($selectedType eq 'none') { return undef; } elsif ($selectedType eq 'eboxNTP') { my $ifaceAddr = $self->{netMod}->ifaceAddress($self->_interface()); return $ifaceAddr; } elsif ($selectedType eq 'custom_ntp') { return $row->valueByName('custom_ntp'); } } # Method: winsServer # # Get the current IP address from the WINS server # # Returns: # # String - the current WINS server if any, otherwise undef is returned # sub winsServer { my ($self) = @_; my $row = $self->row(); my $selectedType = $row->elementByName('wins_server')->selectedType(); if ($selectedType eq 'none') { return undef; } elsif ($selectedType eq 'eboxWINS') { my $ifaceAddr = $self->{netMod}->ifaceAddress($self->_interface()); return $ifaceAddr; } elsif ($selectedType eq 'custom_wins') { return $row->valueByName('custom_wins'); } } # Group: Protected methods # Method: _table # # Overrides: # # # sub _table { my ($self) = @_; my $gl = EBox::Global->getInstance(); my (@searchDomainSubtypes, @primaryNSSubtypes) = ( (), () ); push ( @searchDomainSubtypes, new EBox::Types::Union::Text( fieldName => 'none', printableName => __('None'), )); push ( @searchDomainSubtypes, new EBox::Types::DomainName( fieldName => 'custom', printableName => __('Custom'), editable => 1, )); # Set the subtypes associated to DNS module if ( $gl->modExists('dns') ) { push( @searchDomainSubtypes, new EBox::Types::Select( fieldName => 'ebox', printableName => __(q{Zentyal domain}), editable => 1, foreignModel => \&_domainModel, foreignField => 'domain', )); push ( @primaryNSSubtypes, new EBox::Types::Union::Text( fieldName => 'eboxDNS', printableName => __('local Zentyal DNS') )); } push ( @primaryNSSubtypes, new EBox::Types::HostIP( fieldName => 'custom_ns', printableName => __('Custom'), editable => 1, defaultValue => $self->_fetchPrimaryNS(), ), new EBox::Types::Union::Text( fieldName => 'none', printableName => __('None'), )); my @ntpSubtypes = ( new EBox::Types::Union::Text(fieldName => 'none', printableName => __('None'))); if ( $gl->modExists('ntp') ) { push(@ntpSubtypes, new EBox::Types::Union::Text(fieldName => 'eboxNTP', printableName => __('local Zentyal NTP'))); } push(@ntpSubtypes, new EBox::Types::HostIP(fieldName => 'custom_ntp', printableName => __('Custom'), editable => 1) ); my @winsSubtypes = ( new EBox::Types::Union::Text(fieldName => 'none', printableName => __('None'))); if ( $gl->modExists('samba') ) { push(@winsSubtypes, new EBox::Types::Union::Text(fieldName => 'eboxWINS', printableName => __('local Zentyal'))); } push(@winsSubtypes, new EBox::Types::HostIP(fieldName => 'custom_wins', printableName => __('Custom'), editable => 1) ); my @tableDesc = ( new EBox::Types::Union( fieldName => 'default_gateway', printableName => __('Default gateway'), editable => 1, subtypes => [ new EBox::Types::Union::Text( fieldName => 'ebox', printableName => __('Zentyal'), ), new EBox::Types::HostIP( fieldName => 'ip', printableName => __('Custom IP address'), editable => 1, #defaultValue => $self->_fetchIfaceAddress(), ), new EBox::Types::Union::Text( fieldName => 'none', printableName => __('None'), ), new EBox::Types::Select( fieldName => 'name', printableName => __('Configured ones'), editable => 1, foreignModel => \&_gatewayModel, foreignField => 'name' ), ], help => __('Setting "Zentyal" as default gateway will set the interface ' . 'IP address as gateway'), ), new EBox::Types::Union( fieldName => 'search_domain', printableName => __('Search domain'), editable => 1, subtypes => \@searchDomainSubtypes, help => __('The selected domain will complete on your clients ' . 'those DNS queries which are not fully qualified'), ), new EBox::Types::Union( fieldName => 'primary_ns', printableName => __('Primary nameserver'), editable => 1, subtypes => \@primaryNSSubtypes, help => __('If "Zentyal DNS" is present and selected, the Zentyal server will act ' . 'as cache DNS server'), ), new EBox::Types::HostIP( fieldName => 'secondary_ns', printableName => __('Secondary nameserver'), editable => 1, optional => 1, ), new EBox::Types::Union( fieldName => 'ntp_server', printableName => __('NTP server'), editable => 1, subtypes => \@ntpSubtypes, help => __('If "Zentyal NTP" is present and selected, ' . 'Zentyal will be the NTP server for DHCP clients'), ), new EBox::Types::Union( fieldName => 'wins_server', printableName => __('WINS server'), editable => 1, subtypes => \@winsSubtypes, help => __('If "Zentyal Samba" is present and selected, ' . 'Zentyal will be the WINS server for DHCP clients'), ), ); my $dataForm = { tableName => 'Options', printableTableName => __('Common options'), modelDomain => 'DHCP', defaultActions => [ 'editField', 'changeView' ], tableDescription => \@tableDesc, class => 'dataForm', help => __('If you set a "configured ones" as default gateway, ' . 'you may choose one the configured gateways. As ' . '"search domain" value, one of the configured ' . 'DNS domains on Zentyal might be chosen. ' . 'All fields are optionals setting ' . 'its value as "None" or leaving blank.'), }; return $dataForm; } # Group: Private methods # Get the object model from Objects module sub _domainModel { # FIXME: when model works with old fashioned return EBox::Global->modInstance('dns')->model('DomainTable'); } # Get the object model from Service module sub _gatewayModel { # FIXME: when model works with old fashioned return EBox::Global->modInstance('network')->model('GatewayTable'); } # Fetch ip address from current interface sub _fetchIfaceAddress { my ($self) = @_; my $ifaceAddr = $self->{netMod}->ifaceAddress($self->_interface()); ($ifaceAddr) or return undef; return $ifaceAddr; } # Fetch primary nameserver from Network module sub _fetchPrimaryNS { my ($self) = @_; my $nsOne = $self->{netMod}->nameserverOne(); ($nsOne) or return undef; return $nsOne; } # Fetch secondary nameserver from Network module sub _fetchSecondaryNS { my ($self) = @_; my $nsTwo = $self->{netMod}->nameserverTwo(); ($nsTwo) or return undef; return $nsTwo; } sub _interface { my ($self) = @_; return $self->parentRow()->valueByName('iface'); } # Method: viewCustomizer # # Overrides # # sub viewCustomizer { my ($self) = @_; my $customizer = new EBox::View::Customizer(); $customizer->setModel($self); $customizer->setHTMLTitle([]); return $customizer; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/RangeTable.pm0000664000000000000000000001764312017140107017572 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::RangeTable # # This class is used to set the DHCP ranges available in a dhcp server # attached to an interface. The fields are the following: # # - name : Text # - from : HostIP # - to : HostIP # package EBox::DHCP::Model::RangeTable; use strict; use warnings; use EBox::Global; use EBox::Gettext; use EBox::Model::Manager; use EBox::Types::Text; use EBox::Types::HostIP; use base 'EBox::Model::DataTable'; ################ # Dependencies ################ use Net::IP; # Constructor: new # # Constructor for Rule table # # Returns : # # A recently created object # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless($self, $class); return $self; } # Method: validateTypedRow # # Overrides: # # # sub validateTypedRow { my ($self, $action, $changedFields, $allFields) = @_; if ((exists $changedFields->{from}) or (exists $changedFields->{to})) { my $from = $allFields->{from}->value(); my $to = $allFields->{to}->value(); # Check the range is correct my $range = new Net::IP($from . ' - ' . $to); unless ( defined ( $range )) { throw EBox::Exceptions::External(__x('{from} - {to} is an invalid range', from => $from, to => $to, )); } # Check the range is within the available range my $dhcp = $self->{confmodule}; my $net = EBox::Global->modInstance('network'); my $interface = $self->parentRow()->valueByName('iface'); my $availableRange = new Net::IP($dhcp->initRange($interface) . '-' . $dhcp->endRange($interface)); unless ( $range->overlaps($availableRange) == $IP_A_IN_B_OVERLAP ) { throw EBox::Exceptions::External(__x('Range {from}-{to} is not in ' . 'network {net}', from => $from, to => $to, net => EBox::NetWrappers::to_network_with_mask( $net->ifaceNetwork($interface), $net->ifaceNetmask($interface)) )); } # Check the range does not contain the interface address my $ifaceAddr = $net->ifaceAddress($interface); my $ifaceIPObj = new Net::IP($ifaceAddr); unless ( $ifaceIPObj->overlaps($range) == $IP_NO_OVERLAP ) { throw EBox::Exceptions::External(__x('Range {from}-{to} includes interface ' . 'with IP address: {ifaceIP}', from => $from, to => $to, ifaceIP => $ifaceAddr)); } # Check the other ranges my $currentId; if ( $action eq 'update' ) { $currentId = $allFields->{name}->row()->id(); } foreach my $id ( @{$self->ids()} ) { my $row = $self->row($id); my $compareId = $row->id(); # If the action is an update, does not check the same row if ( $action eq 'update' and $compareId eq $currentId ) { next; } my $compareFrom = $row->valueByName('from'); my $compareTo = $row->valueByName('to'); my $compareRange = new Net::IP( $compareFrom . '-' . $compareTo); unless ( $compareRange->overlaps($range) == $IP_NO_OVERLAP ) { throw EBox::Exceptions::External(__x('Range {newFrom}-{newTo} overlaps ' . "with range '{range}': {oldFrom}-{oldTo}", newFrom => $from, newTo => $to, range => $row->valueByName('name'), oldFrom => $compareFrom, oldTo => $compareTo)); } } # Check fixed addresses my $fixedAddresses = $self->{confmodule}->fixedAddresses($interface, 0); foreach my $fixedAddr (@{$fixedAddresses}) { my $fixedIP = new Net::IP($fixedAddr->{ip}); unless ( $fixedIP->overlaps($range) == $IP_NO_OVERLAP ) { throw EBox::Exceptions::External(__x('Range {from}-{to} includes ' . 'fixed address from the ' . 'object member "{name}": ' . '{fixedIP}', from => $from, to => $to, name => $fixedAddr->{name}, fixedIP => $fixedAddr->{ip} )); } } } } # Group: Protected methods # Method: _table # # Describe the DHCP ranges table # # Returns: # # hash ref - table's description # sub _table { my ($self) = @_; my @tableDesc = ( new EBox::Types::Text( fieldName => 'name', printableName => __('Name'), unique => 1, editable => 1, ), new EBox::Types::HostIP( fieldName => 'from', printableName => __('From'), unique => 1, editable => 1, ), new EBox::Types::HostIP( fieldName => 'to', printableName => __('To'), unique => 1, editable => 1, ), ); my $dataTable = { 'tableName' => 'RangeTable', 'printableTableName' => __('Ranges'), 'defaultActions' => [ 'add', 'del', 'editField', 'changeView' ], 'modelDomain' => 'DHCP', 'tableDescription' => \@tableDesc, 'class' => 'dataTable', 'rowUnique' => 1, # Set each row is unique 'printableRowName' => __('range'), 'sortedBy' => 'from', }; return $dataTable; } # Method: viewCustomizer # # Overrides # # sub viewCustomizer { my ($self) = @_; my $customizer = new EBox::View::Customizer(); $customizer->setModel($self); $customizer->setHTMLTitle([]); return $customizer; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/RangeInfo.pm0000664000000000000000000000737212017140107017434 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::Options # # This class is the model to configurate general options for the dhcp # server on a static interface. The fields are the following: # # - default gateway # - search domain # - primary nameserver # - second nameserver # package EBox::DHCP::Model::RangeInfo; use base 'EBox::Model::DataForm::ReadOnly'; use EBox::Gettext; use EBox::Global; use EBox::NetWrappers; use EBox::Types::IPAddr; use EBox::Types::Text; # Group: Public methods # Constructor: new # # Create the general options to the dhcp server # # Overrides: # # # # Returns: # # # # Exceptions: # # - thrown if any compulsory # argument is missing # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless ( $self, $class); return $self; } # Group: Protected methods # Method: _table # # Overrides: # # # sub _table { my @tableDesc = ( new EBox::Types::HostIP( fieldName => 'iface_address', printableName => __('Interface IP address'), ), new EBox::Types::IPAddr( fieldName => 'subnet', printableName => __('Subnet'), ), new EBox::Types::Text( fieldName => 'available_range', printableName => __('Available range'), ), ); my $dataForm = { tableName => 'RangeInfo', printableTableName => __('DHCP ranges'), modelDomain => 'DHCP', tableDescription => \@tableDesc, class => 'dataForm', }; return $dataForm; } # Group: Protected methods # Method: _content # # Overrides: # # # sub _content { my ($self) = @_; my $dhcp = $self->{confmodule}; my $net = EBox::Global->modInstance('network'); my $interface = $self->parentRow()->valueByName('iface'); my $ifaceAddr = $net->ifaceAddress($interface); my $subnet = EBox::NetWrappers::to_network_with_mask( $net->ifaceNetwork($interface), $net->ifaceNetmask($interface) ); my $availableRange = $dhcp->initRange($interface) . ' - ' . $dhcp->endRange($interface); return { iface_address => $ifaceAddr, subnet => $subnet, available_range => $availableRange, }; } # Method: viewCustomizer # # Overrides # # sub viewCustomizer { my ($self) = @_; my $customizer = new EBox::View::Customizer(); $customizer->setModel($self); $customizer->setHTMLTitle([]); return $customizer; } 1; zentyal-dhcp-2.3.8+quantal1/src/EBox/Model/ThinClientOptions.pm0000664000000000000000000003473712017140107021206 0ustar # Copyright (C) 2008-2012 eBox Technologies S.L. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Class: EBox::DHCP::Model::ThinClientOptions # # This class is the model to configurate thin client options for the dhcp # server on a static interface. The fields are the following: # # - next server, which tells dhcp client where to search the # terminal server # # - filename, which indicates the firmware to load when the DHCP # client loads # package EBox::DHCP::Model::ThinClientOptions; # TODO: Restore this when more than one config per interface is possible #use base 'EBox::Model::DataTable'; use base 'EBox::Model::DataForm'; use strict; use warnings; use feature 'switch'; use EBox::DHCP; use EBox::DHCP::Types::Group; use EBox::Exceptions::DataNotFound; use EBox::Exceptions::External; use EBox::Exceptions::InvalidData; use EBox::Exceptions::MissingArgument; use EBox::Gettext; use EBox::Global; use EBox::NetWrappers; use EBox::Types::File; use EBox::Types::Union; use EBox::Types::Union::Text; use EBox::Types::Host; use EBox::Types::Select; use EBox::Types::Boolean; use EBox::Validate; use EBox::View::Customizer; # Group: Public methods # Constructor: new # # Create the thin client options to the dhcp server # # Overrides: # # # # Returns: # # # # Exceptions: # # - thrown if any compulsory # argument is missing # sub new { my $class = shift; my %opts = @_; my $self = $class->SUPER::new(@_); bless ($self, $class); return $self; } # Method: notifyForeignModelAction # # Remove rows when a range or fixed address is removed from the # same interface and applies to this model and object. # # Do this because of framework limitation. # # Overrides: # # # # TODO: Restore this when more than one config per interface is possible # sub notifyForeignModelAction # { # my ($self, $model, $action, $row) = @_; # # if ( $action eq 'del' ) { # my $idToRemove; # given ( $model ) { # when ( 'FixedAddressTable' ) { # $idToRemove = $row->valueByName('object'); # } # when ( 'RangeTable' ) { # $idToRemove = $row->valueByName('name'); # } # default { return ""; } # } # my $matchedRow = $self->findValue(hosts => $idToRemove); # if ( $matchedRow ) { # $self->removeRow($matchedRow->id(), 1); # return __x('Remove thin client options from {model}{br}', # model => $self->printableContextName(), # br => '
'); # } # } # return ""; # # } # Method: nextServerIsZentyal # # Finds out whether the next server the next server is Zentyal or not # # Parameters: # # id - String the row identifier # # Returns: # # Boolean - if Zentyal is the next server for the given row # # Exceptions: # # - thrown if the given id is not # from this model # sub nextServerIsZentyal { my ($self, $id) = @_; # TODO: Restore this when more than one config per interface is possible # my $row = $self->row($id); my $row = $self->row(); unless ( defined($row) ) { throw EBox::Exceptions::DataNotFound(data => 'id', value => $id); } return ( $row->valueByName('nextServer') eq 'nextServerEBox' ); } # Method: nextServer # # Get the next server (name or IP address) in an string form to # tell the DHCP clients which is the next server to ask for # terminal # # Parameters: # # id - String the row identifier # # Returns: # # String - a name or an IP address # # Exceptions: # # - thrown if the given id is not # from this model # sub nextServer { my ($self, $id) = @_; # TODO: Restore this when more than one config per interface is possible # my $row = $self->row($id); my $row = $self->row(); unless ( defined($row) ) { throw EBox::Exceptions::DataNotFound(data => 'id', value => $id); } return $row->valueByName('nextServerHost'); } # Method: remoteFilename # # Get the remote filename in an string form to tell the DHCP clients which # is the file to ask for to the server # # Parameters: # # id - String the row identifier # # Returns: # # String - a filename # # Exceptions: # # - thrown if the given id is not # from this model # sub remoteFilename { my ($self, $id) = @_; # TODO: Restore this when more than one config per interface is possible # my $row = $self->row($id); my $row = $self->row(); unless ( defined($row) ) { throw EBox::Exceptions::DataNotFound(data => 'id', value => $id); } my $nextServerType = $row->valueByName('nextServer'); given ( $nextServerType ) { when ('nextServerHost' ) { return $row->valueByName('remoteFilename'); } default { return ''; } } } # Method: architecture # # Get the architecture in an string form to tell the DHCP clients which is # the architecture of the thin clients # # Parameters: # # id - String the row identifier # # Returns: # # String - architecture # # Exceptions: # # - thrown if the given id is not # from this model # sub architecture { my ($self, $id) = @_; # TODO: Restore this when more than one config per interface is possible # my $row = $self->row($id); my $row = $self->row(); unless ( defined($row) ) { throw EBox::Exceptions::DataNotFound(data => 'id', value => $id); } return $row->valueByName('architecture'); } # Method: fat # # Return true if the image is a fat image # # Parameters: # # id - String the row identifier # # Returns: # # Boolean - True if the image is fat # # Exceptions: # # - thrown if the given id is not # from this model # sub fat { my ($self, $id) = @_; # TODO: Restore this when more than one config per interface is possible # my $row = $self->row($id); my $row = $self->row(); unless ( defined($row) ) { throw EBox::Exceptions::DataNotFound(data => 'id', value => $id); } return $row->valueByName('fat'); } # Group: Protected methods # # Callback function to fill out the values that can # be picked from the field module # # Returns: # # Array ref of hash refs containing the 'value' and the 'printableValue' for # each select option # sub _select_options { # TODO: Restore this when more than one config per interface is possible # my @ltspSubtypes; my @ltspSubtypes = ({ value => 'none', printableValue => __('None'), },); my $gl = EBox::Global->getInstance(); if ( $gl->modExists('ltsp') ) { push(@ltspSubtypes, { value => 'nextServerEBox', printableValue => __('Zentyal LTSP'), } ); } push(@ltspSubtypes, { value => 'nextServerHost', printableValue => __('Host'), }, ); return \@ltspSubtypes; } # # Callback function to fill out the values that can # be picked from the field module # # Returns: # # Array ref of hash refs containing the 'value' and the 'printableValue' for # each select option # sub _select_architecture { my $gl = EBox::Global->getInstance(); if ( $gl->modExists('ltsp') ) { return [ { value => 'i386', printableValue => __('32 bits'), }, { value => 'amd64', printableValue => __('64 bits'), }, ]; } else { return []; } } # Method: _table # # Overrides: # # # sub _table { my ($self) = @_; my @tableDesc = ( new EBox::Types::Select( fieldName => 'nextServer', printableName => __('Next server'), populate => \&_select_options, editable => 1, help => __('If "Zentyal LTSP" is present and selected, ' . 'Zentyal will be the LTSP server.' . ' You will need to enable and configure the LTSP module.'),), new EBox::Types::Host(fieldName => 'nextServerHost', printableName => __('Host'), editable => 1, optional => 1, help => __('Thin Client server as seen by the clients.'), ), new EBox::Types::Text( fieldName => 'remoteFilename', printableName => __('File path'), editable => 1, optional => 1, help => __('Thin client file path'), ), # TODO: Restore this when more than one config per interface is possible # new EBox::Types::Union( # fieldName => 'hosts', # printableName => __('Clients'), # editable => 1, # subtypes => [ # new EBox::DHCP::Types::Group( # fieldName => 'object', # printableName => __('Object'), # index => $self->index(), # foreignModelName => 'FixedAddressTable', # foreignField => 'object', # unique => 1, # editable => 1 # ), # new EBox::DHCP::Types::Group( # fieldName => 'range', # printableName => __('Range'), # index => $self->index(), # foreignModelName => 'RangeTable', # foreignField => 'name', # unique => 1, # editable => 1) # ]), new EBox::Types::Select( fieldName => 'architecture', printableName => __('Architecture'), populate => \&_select_architecture, editable => 1, hiddenOnViewer => 1, help => __('Architecture of the LTSP clients. The LTSP image for that architecture must exist in order to boot the clients.'),), new EBox::Types::Boolean( fieldName => 'fat', printableName => __('Fat Client'), defaultValue => 0, editable => 1, hiddenOnViewer => 1, help => __('Whether the clients are fat clients or not.'),), ); # FIXME: parentRow() is undefined when _table is called #my $interface = $self->parentRow()->valueByName('iface'); my $interface = 'eth0'; my $dataTable = { tableName => 'ThinClientOptions', printableTableName => __('Thin client'), modelDomain => 'DHCP', defaultActions => [ 'add', 'del', 'editField', 'changeView' ], tableDescription => \@tableDesc, class => 'dataTable', help => __x('You may want to customise your thin client options.' . 'To do so, you may include all the files you require ' . 'under {path} directory', path => EBox::DHCP->PluginConfDir($interface)), sortedBy => 'hosts', printableRowName => __('thin client option'), }; return $dataTable; } # Method: viewCustomizer # # Overrides: # # # sub viewCustomizer { my ($self) = @_; my $customizer = new EBox::View::Customizer(); $customizer->setModel($self); my %actions = ( 'nextServer' => { # TODO: Remove this when more than one config per interface is possible 'none' => { show => [], hide => ['nextServerHost', 'architecture','remoteFilename','fat'], }, 'nextServerEBox' => { # TODO: Restore this when more than one config per interface is possible # show => ['hosts', 'nextServerHost', 'architecture', 'fat'], show => ['nextServerHost', 'architecture', 'fat'], hide => ['remoteFilename'], }, 'nextServerHost' => { # TODO: Restore this when more than one config per interface is possible # show => ['remoteFilename', 'nextServerHost', 'hosts'], show => ['remoteFilename', 'nextServerHost'], hide => ['architecture', 'fat'], }, }, ); $customizer->setOnChangeActions( \%actions ); $customizer->setHTMLTitle([]); return $customizer; } 1; zentyal-dhcp-2.3.8+quantal1/stubs/0000775000000000000000000000000012017140107013671 5ustar zentyal-dhcp-2.3.8+quantal1/stubs/staticRoutes.mas0000664000000000000000000000274112017140107017070 0ustar <%args> @routes $defaultGw => undef <%init> use EBox::NetWrappers; <& .msStaticRoutes, routes => \@routes &> <& .rfc3442StaticRoutes, routes => \@routes, defaultGw => $defaultGw &> <%def .msStaticRoutes> <%args> @routes option ms-classless-static-routes % while (my $r = pop @routes) { % my $last = @routes == 0; <& .route, destination => $r->{network}, gateway => $r->{gateway}, netmask => $r->{netmask}, last => $last &> % } <%def .rfc3442StaticRoutes> <%args> $defaultGw @routes option rfc3442-classless-static-routes % foreach my $r (@routes) { <& .route, destination => $r->{network}, gateway => $r->{gateway}, netmask => $r->{netmask} &> % } <& .route, destination => 'default', gateway => $defaultGw, last => 1&> <%def .route> <%args> $destination $gateway $netmask => undef $last => 0 <%init> my $route = ''; if ($destination eq 'default') { # netmask and destination portion $route .= '0,'; } else { # netmask portion $route .= EBox::NetWrappers::bits_from_mask( $netmask ); $route .= ','; # destination portion $destination =~ s/(\.0)+$//; $destination =~ tr/\./,/; $destination .= ',' unless $destination =~ m/,$/; $route .= $destination ; } # gateway portion $gateway =~ tr/\./,/; $route .= $gateway; # add comma or semicolomn depending wether this is the last route or not if ($last) { $route .= ';'; } else { $route .= ','; } <% $route %> zentyal-dhcp-2.3.8+quantal1/stubs/includes.mas0000664000000000000000000000105012017140107016175 0ustar <%doc> This template is done in order to add include statements to the dhcp server. Parameters: iface - String the iface to search for <%args> $iface <%init> use EBox::DHCP; my $dirName = EBox::DHCP->PluginConfDir($iface); opendir ( my $dirHandle, $dirName); my @files = (); while ( defined(my $fileName = readdir ($dirHandle))) { next unless -f "$dirName$fileName"; push ( @files, "$dirName$fileName" ); } closedir ($dirHandle); % foreach my $includeFile (@files) { include "<% $includeFile %>"; % }zentyal-dhcp-2.3.8+quantal1/stubs/subnet.mas0000664000000000000000000001302512017140107015674 0ustar <%doc> This template dumps the configuration for every shared network including ranges and fixed IP adresses. <%args> %info % if (exists $info{'staticRoutes'} ) { <& staticRoutes.mas, routes => $info{'staticRoutes'}, defaultGw => $info{'gateway'} &> % } subnet <% $info{'net'} %> netmask <% $info{'netmask'} %> { <& .options, info => \%info &> % my $ranges = $info{'ranges'}; % foreach my $range (@{$ranges}) { pool { <& .include, name => $range->{'name'} &> <& .thin_client_options, options => $range->{'options'} &> range <% $range->{'from'} %> <% $range->{'to'} %>; } % } } group { <& .options, info => \%info, fixed => 1 &> % foreach my $groupFixed (values %{$info{'fixed'}}) { group { <& .thin_client_options, options => $groupFixed->{options} &> % foreach my $fixed (@{$groupFixed->{members}}) { host <% $fixed->{'name'} %> { hardware ethernet <% $fixed->{'mac'} %>; fixed-address <% $fixed->{'ip'} %>; <& .include, name => $fixed->{'name'} &> } % } } % } } <%doc> Print out the route options <%def .options> <%args> %info $fixed => 0 % # Common options for the shared network % if (exists $info{'gateway'}) { option routers <% $info{'gateway'} %>; % } % if(defined($info{'search'})) { option domain-name "<% $info{'search'} %>"; % } % if(exists $info{'nameserver1'} and length($info{'nameserver1'}) > 0) { option domain-name-servers <% $info{'nameserver1'} %>\ % if(exists $info{'nameserver2'} and length($info{'nameserver2'}) > 0) { , <% $info{'nameserver2'} %>; % }else{ ; % } % } % if ( defined($info{'ntpServer'}) ) { option ntp-servers <% $info{'ntpServer'} %>; % } % if ( defined($info{'winsServer'}) ) { option netbios-name-servers <% $info{'winsServer'} %>; option netbios-node-type 8; % } % if(defined($info{'defaultLeasedTime'})) { default-lease-time <% $info{'defaultLeasedTime'} %>; % } % if(defined($info{'maxLeasedTime'})) { max-lease-time <% $info{'maxLeasedTime'} %>; % } % if( defined($info{'dynamicDomain'}) ) { option host-name = config-option server.ddns-hostname; % if ( $fixed ) { <%doc> Check dhcp-eval and dhcp-options to know what this function does to add A record to DNS server ddns-hostname = pick-first-value ( host-decl-name, option fqdn.hostname, concat("static-", binary-to-ascii(10, 8, "-", leased-address))); ddns-domainname "<% $info{'staticDomain'} %>."; zone <% $info{'staticDomain'} %>. { primary 127.0.0.1; key <% $info{'staticDomain'} %>.; } % foreach my $revZone (@{$info{'reverseZones'}}) { zone <% $revZone %> { primary 127.0.0.1; key <% $info{'dynamicDomain'} %>.; } % } % } else { <%doc> This ignores the data sent by the DHCP client and always set dhcp-leased-IP.domain name ddns-hostname = pick-first-value( option fqdn.hostname, option host-name, concat("dhcp-", binary-to-ascii(10, 8, "-", leased-address))); ddns-domainname "<% $info{'dynamicDomain'} %>."; zone <% $info{'dynamicDomain'} %>. { primary 127.0.0.1; key <% $info{'dynamicDomain'} %>.; } % foreach my $revZone (@{$info{'reverseZones'}}) { zone <% $revZone %> { primary 127.0.0.1; key <% $info{'dynamicDomain'} %>.; } % } % } % } <%doc> If there is any file with the given name, then include it in the configuration name - String to include <%def .include> <%args> $name <%init> use EBox::DHCP; my $dirName = EBox::DHCP->IncludeDir(); my $fileName = $dirName . $name; % if ( -r $fileName ) { include "<% $fileName %>"; % } <%doc> Print out the thin client options <%def .thin_client_options> <%args> %options % if (values(%options) > 0) { % if ($options{nextServerIsZentyal}) { % if ($options{nextServer}) { next-server <% $options{nextServer} %>; option tftp-server-name "<% $options{nextServer} %>"; % } option root-path "/opt/ltsp/<% ($options{fat}?'fat-':'') %><% $options{architecture} %>"; if substring( option vendor-class-identifier, 0, 9 ) = "PXEClient" { filename "/ltsp/<% ($options{fat}?'fat-':'') %><% $options{architecture} %>/pxelinux.0"; } else { filename "/ltsp/<% ($options{fat}?'fat-':'') %><% $options{architecture} %>/nbi.img"; } % } % else { % if ($options{nextServer}) { next-server <% $options{nextServer} %>; option tftp-server-name "<% $options{nextServer} %>"; % } % if ( $options{filename} ) { filename "<% $options{filename} %>"; % } % } % } zentyal-dhcp-2.3.8+quantal1/stubs/shared-network.mas0000664000000000000000000000310412017140107017326 0ustar <%args> $iface %ifaces @vifaces shared-network <% $iface %> { <& includes.mas, iface => $iface &> %# TODO: Remove this when more than one config per interface is possible <& .thin_client_options, options => $ifaces{$iface}->{'options'} &> <& subnet.mas, info => $ifaces{$iface} &> % foreach my $viface (@vifaces) { <& includes.mas, iface => $viface &> <& subnet.mas, info => $ifaces{$viface} &> % } } <%doc> Print out the thin client options # TODO: Restore this when more than one config per interface is possible <%def .thin_client_options> <%args> %options % if (values(%options) > 0) { % if ($options{nextServerIsZentyal}) { % if ($options{nextServer}) { next-server <% $options{nextServer} %>; option tftp-server-name "<% $options{nextServer} %>"; % } option root-path "/opt/ltsp/<% ($options{fat}?'fat-':'') %><% $options{architecture} %>"; if substring( option vendor-class-identifier, 0, 9 ) = "PXEClient" { filename "/ltsp/<% ($options{fat}?'fat-':'') %><% $options{architecture} %>/pxelinux.0"; } else { filename "/ltsp/<% ($options{fat}?'fat-':'') %><% $options{architecture} %>/nbi.img"; } % } % else { % if ($options{nextServer}) { next-server <% $options{nextServer} %>; option tftp-server-name "<% $options{nextServer} %>"; % } % if ( $options{filename} ) { filename "<% $options{filename} %>"; % } % } % } zentyal-dhcp-2.3.8+quantal1/stubs/apparmor-dhcpd.local.mas0000664000000000000000000000060512017140107020366 0ustar <%args> $keysFile $confDir # Site-specific additions and overrides for usr.sbin.dhcpd. # For more details, please see /etc/apparmor.d/local/README. # This profile has been modified by Zentyal Server to provide Dynamic # DNS feature % if ( $keysFile ) { # For dynamic DNS (Zentyal) <% $keysFile %> r, % } # For allowing custom tweaking (Zentyal) <% $confDir %>* r, zentyal-dhcp-2.3.8+quantal1/stubs/dhcpd.conf.mas0000664000000000000000000000413312017140107016402 0ustar <%doc> This stub writes the DHCP server configuration file Parameters: ifaces - Hash real_ifaces - Hash containing the interface name as key and an array ref containing the virtual interface names as value thinClientOption - Boolean indicating whether the thin client options have been used or not dnsone - String the default primary DNS server dnstwo - String the default secondary DNS server dynamicDNSEnabled - Boolean indicating whether the dynamic DNS feature is on or not keysFile - String with the file path to shared secret keys to update DNS server pidFile - String the path to the file which stores the daemon PID <%args> %ifaces %real_ifaces $thinClientOption => 0 $dnsone => "" $dnstwo => "" $dynamicDNSEnabled => 0 $keysFile => "" $pidFile # DHCP server is authoritative for all networks authoritative; # extra options # RFC3442 routes option rfc3442-classless-static-routes code 121 = array of integer 8; # MS routes option ms-classless-static-routes code 249 = array of integer 8; pid-file-name "<% $pidFile %>"; % if ( $dynamicDNSEnabled ) { ddns-update-style interim; ddns-updates on; update-static-leases on; % } else { ddns-update-style none; % } % if(length($dnsone) != 0) { option domain-name-servers <% $dnsone %>\ % if(length($dnstwo) != 0) { , <% $dnstwo %>; % }else{ ; % } % } % if($thinClientOption) { allow booting; allow bootp; % } default-lease-time 1800; max-lease-time 7200; % if ($keysFile) { include "<% $keysFile %>"; % } <%perl> foreach my $iface (keys(%real_ifaces)) { # Write configuration if there are any range or fixed addresses my @ifacesToCheck = @{$real_ifaces{$iface}}; push(@ifacesToCheck, $iface); my $nIfaceToWrite = grep { @{$ifaces{$_}->{ranges}} > 0 or values(%{$ifaces{$_}->{fixed}}) > 0 } @ifacesToCheck; if ( $nIfaceToWrite > 0) { <& dhcp/shared-network.mas, iface => $iface, ifaces => \%ifaces, vifaces => $real_ifaces{$iface} &> % } % } zentyal-dhcp-2.3.8+quantal1/ChangeLog0000664000000000000000000001572212017140107014312 0ustar HEAD + Add dhcpd to the bind group if DynamicDNS is enabled + Use isc-dhcp-server upstart script 2.3.8 + Added modeldepends to yaml schema 2.3.7 + Adapted reverse zones to reverse ip fix in Net::IP + Added missing dynamicDNSDomains() method + Removed deprecated calls to EBox::Model::Manager::model with wildcards 2.3.6 + Remove old workarounds in viewCustomizers no longer necessary with foreign in yaml schema + Use a regular model instead of a select composite which is going to be deprecated + Adapted to new Model management framework + Use new services API 2.3.5 + Create tables with MyISAM engine by default 2.3.4 + Packaging fixes for precise 2.3.3 + Recover from excepcion when parsing leases file + Modifications in the Thin Client options to allow an easy configuration of Zentyal LTSP 2.3.2 + Service descriptions are now translatable and added printableNames 2.3.1 + Updated Standards-Version to 3.9.2 2.3 + Adapted to new MySQL logs backend + Use apparmor local profile instead of overwritting the shipped one + Replace dhcp3-server with new isc-dhcp-server name + Replaced autotools with zbuildtools + Implemented gatewayDelete method from NetworkObserver 2.2.1 + Set always five subdomains to reverse zones to avoid problems with some networks like 10.0.0.0/24 + Fixed problem with cache of dhcp leases widget. Now it updates correctly + Lowercase the members in fixed address prior to substituing characters to become host in a valid domain name + Fixed non-translatable string 2.1.6 + Do not check fixed addresses of unconfigured vifaces + Removed /zentyal prefix from URLs + Avoid duplicated restart during postinst 2.1.5 + Use the new "Add new..." option in the object selectors 2.1.4 + Make TFPT path optional + Add option tftp-server-name if next-server is defined + Use new AppArmor profile management by the framework + Apparmor profile now works without DNS module installed + Transform member names in fixed address to avoid user confusion + Do not check for MAC unity for the same object in fixed address since it is already done by the member model 2.1.3 + Do not fail if the DNS module is not installed + Fixed 'routers' option when gateway is set to 'none' + Object members without a valid hostname are no longer used as fixed addresses, IP ranges are also skipped 2.1.2 + Use EBox::Types::Host to simplify UI in Thin Clients + Fixed regression with new autotools paths 2.1.1 + Bugfix: dhcp module never fail to save changes when a change in network interface is done + Use a select to choose the dynamic domains instead of adding manually using a Text box + Added support to add DNS reverse resolution for DHCP clients + Added dynamicDNSDomains exposed method to be used by dns module + Now it is possible to tweak DHCP configuration for an specific host or range using /etc/ebox/dhcp/ or /etc/ebox/dhcp/ configuration file + Thin client options are now working for objects and ranges + Fixed addresses are now managed by network objects + Dynamic IP address leases now got the hostname from the DHCP client, if given + Define dhcpd paths using autotools for flexible use with isc-dhcp-server (>4). 2.1 + Use new standard enable-module script + Replace services migration with initialSetup and delete the obsolete one + Bugfix: MAC addresses are now parsed correctly in LogHelper 2.0.2 + DHCP init.d script is disabled when enabling the module + Set default order for dashboard widgets 2.0.1 + Bugfix: Add to apparmor profile the bind keys file to read it to make dynamic DNS feature work again + Bugfix: Comply apparmor profile by setting pid file as /var/run/dhcp3-server/dhcpd.pid 1.5.4 + Zentyal rebrand 1.5.3 + Added missing NetBIOS node type when setting the WINS server 1.5.2 + Improved usability using None search domain by default. 1.5.1 + Bugfix: DHCP log works now if the dhcp client sends a host name as suggested + Bugfix: Fixed address names must be valid domain names to enable dynamic DNS feature. 1.4 + Bug fix: i18n 1.3.13 + Added WINS server configuration setting to DHCP common options, you may use eBox as PDC or any other WINS server + Added description optional field to fixed address table + Added NTP server configuration setting to DHCP common options, you may use eBox or any other NTP server + Added Dynamic DNS update feature to set a domain for ranges and a domain for fixed addresses when an IP address is leased. The hostname for ranges is set following a expression (dynamic-) and fixed addresses will use the declared name from eBox interface. 1.3.9 + Bugfix: Do not set configuration for those interfaces which do not have ranges nor fixed address mapping configured 1.1.20 + New release 1.1.10 + New release 1.1 + Use the new ids() and row() API + Bugfix: Set "authoritative" statement to DHCP configuration 0.12.101 + Bugfix: Use the new API for services 0.12.100 + Bugfix: two wrong calls to EBox::Model::Row API fixed 0.12.99 + New release 0.12.1 + Bug fix: use the new EBox::Model::Row API for DHCP options 0.12 + Make default and max leasing time mandatory fields + Add field help to model + Make custom_ns field required + Bugfix: Mark managers as changed every time they ask to change from/to static method because some models may appear/disappear because of modifying configuration method in interfaces 0.11.102 + Bugfix. Logging were not working with hostnames with characters different from alphanumeric plus '_' 0.11.101 + Bugfix. Secondary nameserver in options does not fill a default value when setting as undef by user + Added 'setLeases' method to set lease times from module API + Bugfix: Virtual interface options do not override real interface options anymore 0.11.100 + onInstall() functionality moved to migration script + Do not remove dhcpd3 rc links + Stop dhcpd3 in pre-start in upstart script 0.11.99 + Added thin client general options: filename and next-server + Added include files to use by user in ${EBOX_HOME}/conf/dhcp/${iface}/plugins subdir + Bugfix. Check fixed mapping names not to collide with other mappings in other models and make dhcpd crash + Bugfix. Fixed mapping names cannot contain spaces 0.10.99 + Use the new model/view framework. UI uses Ajax. + Show eBox domain server if DNS is installed + Show eBox IPs on default gateway selection 0.9.100 + Use new services API 0.9.99 + New release 0.9.3 + New release 0.9.2 + Check fixed ip's name against domain name syntax 0.9.1 + New release 0.9 + Added Polish translation + Added Aragonese translation + Added German translation 0.8.99 + New release 0.8.1 + New release 0.8 + New release 0.7.99 + Add Portuguese translation 0.7.1 + Add search domain to options + Use of ebox-sudoers-friendly 0.7 + First public release + Log leases/releases 0.6 + API documented using naturaldocs + move to client + Use NetworkObserver 0.5.2 + Fix some packaging issues 0.5.1 + Convert module to new menu system 0.5 + Initial release zentyal-dhcp-2.3.8+quantal1/AUTHORS0000664000000000000000000000024012017140107013575 0ustar Copyright (C) 2004-2012 eBox Technologies S.L. For an updated list of the current and past developers please visit: http://trac.zentyal.org/wiki/Contributors zentyal-dhcp-2.3.8+quantal1/schemas/0000775000000000000000000000000012017140107014154 5ustar zentyal-dhcp-2.3.8+quantal1/schemas/dhcp.yaml0000664000000000000000000000144312017140107015760 0ustar class: 'EBox::DHCP' depends: - network - objects enabledepends: - network models: - Interfaces - DynamicDNS - LeaseTimes - RangeInfo - FixedAddressTable - Options - RangeTable - ThinClientOptions composites: InterfaceConfiguration: [OptionsTab, RangeInfo, RangeTable, FixedAddressTable] OptionsTab: [Options, DynamicDNS, AdvancedOptions] AdvancedOptions: [LeaseTimes, ThinClientOptions] modeldepends: DynamicDNS: dns/DomainTable: [dynamic_domain, custom] FixedAddressTable: objects/ObjectTable: [object] Options: dns/DomainTable: [ebox] network/GatewayTable: [name] foreign: Interfaces: [InterfaceConfiguration] notifyactions: ThinClientOptions: [dhcp/FixedAddressTable, dhcp/RangeTable] zentyal-dhcp-2.3.8+quantal1/schemas/sql/0000775000000000000000000000000012017140107014753 5ustar zentyal-dhcp-2.3.8+quantal1/schemas/sql/leases.sql0000664000000000000000000000027412017140107016753 0ustar CREATE TABLE IF NOT EXISTS leases( interface CHAR(16), mac BINARY(6), ip INT UNSIGNED, timestamp TIMESTAMP, event VARCHAR(255), INDEX(timestamp) ) ENGINE = MyISAM; zentyal-dhcp-2.3.8+quantal1/www/0000775000000000000000000000000012017140107013355 5ustar zentyal-dhcp-2.3.8+quantal1/www/images/0000775000000000000000000000000012017140107014622 5ustar zentyal-dhcp-2.3.8+quantal1/www/images/green.gif0000664000000000000000000000207112017140107016411 0ustar GIF89a (!!!666???jnprtvxz|}/J//O/?Z??_?HHHVVVXXXYYY[[[\\\]]]___```aaaccceee!=, {HuTa :E" ǏQL!(Sad,bʜ p=J~pի*H`ׯ6JJX`ի6