2008-09-18 18:23:26 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
2009-10-27 18:47:12 +00:00
|
|
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
2009-01-03 19:05:16 +00:00
|
|
|
Copyright (C) 2008 Thomas Manninger
|
2013-02-23 17:10:43 +00:00
|
|
|
2008 - 2013 Roland Gruber
|
2008-09-18 18:23:26 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages DDNS entries.
|
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
*
|
|
|
|
* @author Thomas Manninger
|
2008-12-29 17:39:05 +00:00
|
|
|
* @author Roland Gruber
|
2008-09-18 18:23:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages DDNS entries.
|
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
*/
|
|
|
|
|
|
|
|
class ddns extends baseModule {
|
|
|
|
|
2012-07-15 12:05:47 +00:00
|
|
|
/** standard DDNS settings */
|
2008-09-18 18:23:26 +00:00
|
|
|
public $ddns = array();
|
|
|
|
|
|
|
|
|
2010-06-12 17:17:31 +00:00
|
|
|
/**
|
|
|
|
* Returns meta data that is interpreted by parent class.
|
|
|
|
*
|
|
|
|
* @return array array with meta data
|
|
|
|
*/
|
2008-09-18 18:23:26 +00:00
|
|
|
public function get_metaData() {
|
|
|
|
$return = array();
|
|
|
|
// manages host accounts
|
|
|
|
$return["account_types"] = array("dhcp");
|
|
|
|
// alias name
|
|
|
|
$return["alias"] = _("DDNS");
|
|
|
|
// this is a base module
|
|
|
|
$return["is_base"] = false;
|
2010-02-15 16:56:56 +00:00
|
|
|
// icon
|
|
|
|
$return['icon'] = 'dhcpBig.png';
|
2008-09-18 18:23:26 +00:00
|
|
|
// RDN attribute
|
|
|
|
$return["RDN"] = array("cn" => "high");
|
|
|
|
// LDAP filter
|
|
|
|
$return["ldap_filter"] = array();
|
2008-09-28 14:41:11 +00:00
|
|
|
// module dependencies
|
|
|
|
$return['dependencies'] = array('depends' => array('dhcp_settings'), 'conflicts' => array());
|
2008-09-18 18:23:26 +00:00
|
|
|
// managed object classes
|
|
|
|
$return['objectClasses'] = array();
|
|
|
|
// managed attributes
|
2008-12-07 19:13:50 +00:00
|
|
|
$return['attributes'] = array('dhcpOption', 'dhcpStatements');
|
2008-09-18 18:23:26 +00:00
|
|
|
// help Entries
|
|
|
|
$return['help'] = array(
|
2012-02-04 15:56:31 +00:00
|
|
|
'active' => array(
|
2008-09-18 18:23:26 +00:00
|
|
|
"Headline" => _("Activate DynDNS"),
|
|
|
|
"Text" => _("Should DDNS (Dynamic DNS) be activated?")
|
2012-02-04 15:56:31 +00:00
|
|
|
),
|
|
|
|
'fixed_ips' => array(
|
2008-09-18 18:23:26 +00:00
|
|
|
"Headline" => _("Fix IP addresses"),
|
|
|
|
"Text" => _("Should fix IP addresses be added to the DNS server?")
|
2012-02-04 15:56:31 +00:00
|
|
|
),
|
|
|
|
'client_insert' => array(
|
2008-09-18 18:23:26 +00:00
|
|
|
"Headline" => _("Disable client updates"),
|
|
|
|
"Text" => _("Disables the client to update DNS entries.")
|
2012-02-04 15:56:31 +00:00
|
|
|
),
|
|
|
|
'keypath' => array(
|
2008-09-18 18:23:26 +00:00
|
|
|
"Headline" => _("Path to key for DNS updates"),
|
|
|
|
"Text" => _("The key enables the DHCP server to perform DNS updates." .
|
2008-09-28 12:18:56 +00:00
|
|
|
" " . "The key is generated with \"genDDNSkey\".")
|
2012-02-04 15:56:31 +00:00
|
|
|
),
|
|
|
|
'dns' => array(
|
2008-09-18 18:23:26 +00:00
|
|
|
"Headline" => _("IP address of the DNS server"),
|
|
|
|
"Text" => _("Please enter the IP address of your DNS server.")
|
2012-02-04 15:56:31 +00:00
|
|
|
),
|
|
|
|
'zone' => array(
|
2013-02-24 19:36:10 +00:00
|
|
|
"Headline" => _("Zone name"),
|
|
|
|
"Text" => _("Zone name for the DNS server (e.g. company.local).")
|
2012-02-04 15:56:31 +00:00
|
|
|
),
|
|
|
|
'zone_reverse' => array(
|
2013-02-24 19:36:10 +00:00
|
|
|
"Headline" => _("Reverse zone name"),
|
|
|
|
"Text" => ("Name of the reverse zone of the DNS server (e.g. 0.168.192.in-addr.arpa).")
|
2012-02-04 15:56:31 +00:00
|
|
|
),
|
|
|
|
);
|
2008-12-29 17:39:05 +00:00
|
|
|
// available PDF fields
|
|
|
|
$return['PDF_fields'] = array(
|
2010-04-05 12:38:23 +00:00
|
|
|
'DNSserver' => _('IP address of the DNS server'),
|
2013-02-24 19:36:10 +00:00
|
|
|
'zone' => _('Zone name'),
|
|
|
|
'reverseZone' => _('Reverse zone name'),
|
2008-12-29 17:39:05 +00:00
|
|
|
);
|
2009-03-26 19:51:37 +00:00
|
|
|
// upload fields
|
|
|
|
if (isset($_SESSION['loggedIn']) && $this->check_if_ddns_is_enable()) {
|
|
|
|
$return['upload_columns'] = array(
|
|
|
|
array(
|
|
|
|
'name' => 'ddns_DNSserver',
|
|
|
|
'description' => _('IP address of the DNS server'),
|
|
|
|
'help' => 'dns',
|
|
|
|
'example' => '123.123.123.123',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'ddns_zone',
|
2013-02-24 19:36:10 +00:00
|
|
|
'description' => _('Zone name'),
|
2009-03-26 19:51:37 +00:00
|
|
|
'help' => 'zone',
|
|
|
|
'example' => 'company.local',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'ddns_reverseZone',
|
2013-02-24 19:36:10 +00:00
|
|
|
'description' => _('Reverse zone name'),
|
2009-03-26 19:51:37 +00:00
|
|
|
'help' => 'zone_reverse',
|
|
|
|
'example' => '0.168.192.in-addr.arpa',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function fills the message array.
|
|
|
|
*/
|
|
|
|
public function load_Messages() {
|
|
|
|
$this->messages['key_path'][0] = array('ERROR', 'Please enter the path to the key.', '');
|
|
|
|
$this->messages['key_path'][1] = array('ERROR', 'The key path contains invalid characters.', '');
|
|
|
|
$this->messages['ip'][0] = array('ERROR', 'The IP address of the DNS server is invalid.');
|
2009-03-26 19:51:37 +00:00
|
|
|
$this->messages['ip'][1] = array('ERROR', _('Account %s:') . ' ddns_DNSserver', 'The IP address of the DNS server is invalid.');
|
2008-09-18 18:23:26 +00:00
|
|
|
$this->messages['zone'][0] = array('ERROR', 'Please enter a zone name.');
|
|
|
|
$this->messages['zone_reverse'][0] = array('ERROR', 'Please enter the reverse zone.');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This functions returns true if all needed settings are done.
|
|
|
|
*
|
|
|
|
* @return boolean true if LDAP operation can be done
|
|
|
|
*/
|
|
|
|
public function module_complete() {
|
2013-02-24 11:58:46 +00:00
|
|
|
$this->attributes = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes;
|
|
|
|
$this->orig = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->orig;
|
2009-01-10 17:37:09 +00:00
|
|
|
if ($this->getAccountContainer()->dn_orig==$_SESSION['config']->get_suffix('dhcp')) {
|
|
|
|
// check if DHCP main settings and valid DHCP entry
|
2013-02-23 17:10:43 +00:00
|
|
|
if (!in_array_ignore_case('dhcpService', $this->attributes['objectClass']) && !in_array_ignore_case('dhcpServer', $this->attributes['objectClass'])) {
|
2009-01-10 17:37:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-01-18 18:57:14 +00:00
|
|
|
if (!$this->check_if_ddns_is_enable()) {
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-03 19:05:16 +00:00
|
|
|
// Account settings
|
|
|
|
$ip = $this->getDNSServer();
|
2008-09-18 18:23:26 +00:00
|
|
|
if (!empty($ip) && !check_ip($ip)) return false;
|
|
|
|
|
2009-01-03 19:05:16 +00:00
|
|
|
$zones = $this->getZoneNames();
|
|
|
|
if (sizeof($zones) < 2) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-23 17:10:43 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of modifications which have to be made to the LDAP account.
|
|
|
|
*
|
|
|
|
* @return array list of modifications
|
|
|
|
* <br>This function returns an array with 3 entries:
|
|
|
|
* <br>array( DN1 ('add' => array($attr), 'remove' => array($attr), 'modify' => array($attr)), DN2 .... )
|
|
|
|
* <br>DN is the DN to change. It may be possible to change several DNs (e.g. create a new user and add him to some groups via attribute memberUid)
|
|
|
|
* <br>"add" are attributes which have to be added to LDAP entry
|
|
|
|
* <br>"remove" are attributes which have to be removed from LDAP entry
|
|
|
|
* <br>"modify" are attributes which have to been modified in LDAP entry
|
|
|
|
* <br>"info" are values with informational value (e.g. to be used later by pre/postModify actions)
|
|
|
|
*/
|
|
|
|
public function save_attributes() {
|
|
|
|
// done by dhcp_server object
|
|
|
|
}
|
|
|
|
|
2008-09-18 18:23:26 +00:00
|
|
|
/**
|
|
|
|
* This function check if ddns is enable.
|
|
|
|
*/
|
|
|
|
private function check_if_ddns_is_enable() {
|
2012-02-25 18:40:16 +00:00
|
|
|
if (!in_array('dhcp', $_SESSION['config']->get_ActiveTypes())) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
$ldap = $_SESSION['ldap']->server();
|
|
|
|
$dn = $_SESSION['config']->get_suffix('dhcp');
|
|
|
|
|
2010-02-06 13:38:13 +00:00
|
|
|
$search = @ldap_read($ldap,$dn,"dhcpStatements=ddns-update-style interim", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
|
2009-04-05 19:21:00 +00:00
|
|
|
if ($search) {
|
|
|
|
$info = @ldap_get_entries($ldap,$search);
|
2009-12-19 16:07:10 +00:00
|
|
|
if ($info) {
|
2011-05-21 10:58:22 +00:00
|
|
|
cleanLDAPResult($info);
|
2009-12-19 16:07:10 +00:00
|
|
|
if (sizeof($info) > 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2009-04-05 19:21:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
2009-04-05 19:21:00 +00:00
|
|
|
return false;
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes user input of the primary module page.
|
|
|
|
* It checks if all input values are correct and updates the associated LDAP attributes.
|
|
|
|
*
|
|
|
|
* @return array list of info/error messages
|
|
|
|
*/
|
|
|
|
public function process_attributes() {
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
// Main Settings and Account have to different processes.
|
2009-11-24 18:55:22 +00:00
|
|
|
if ($this->getAccountContainer()->dn_orig==$_SESSION['config']->get_suffix('dhcp')) {
|
2008-09-18 18:23:26 +00:00
|
|
|
// main settings:
|
|
|
|
$errors = $this->process_attributes_mainSettings();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// account
|
|
|
|
if (!$this->check_if_ddns_is_enable()) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$errors = $this->process_attributes_account();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process for mainsettings
|
|
|
|
*/
|
|
|
|
public function process_attributes_mainSettings() {
|
2013-02-23 17:10:43 +00:00
|
|
|
if (!in_array_ignore_case('dhcpService', $this->attributes['objectClass']) && !in_array_ignore_case('dhcpServer', $this->attributes['objectClass'])) {
|
2009-01-10 17:37:09 +00:00
|
|
|
return array();
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
// Is DDNS active?
|
|
|
|
$active = $_POST['active'];
|
|
|
|
|
|
|
|
// Insert fixed IPs into DNS?
|
|
|
|
$insert_fixed = $_POST['insert_fixed'];
|
|
|
|
|
2009-01-03 19:05:16 +00:00
|
|
|
// Client can contribute which is registered into DNS
|
2008-09-18 18:23:26 +00:00
|
|
|
$client_insert = $_POST['client_insert'];
|
|
|
|
|
|
|
|
// The path to the key:
|
|
|
|
$key_path = trim($_POST['key_path']);
|
|
|
|
|
2009-01-03 19:05:16 +00:00
|
|
|
$this->setDynDNSActivated(($active == 'on'));
|
2008-09-18 18:23:26 +00:00
|
|
|
|
2009-01-03 19:05:16 +00:00
|
|
|
$this->setFixIPs(($insert_fixed == 'on'));
|
|
|
|
|
|
|
|
$this->setIgnoreClientUpdates(($client_insert == 'on'));
|
|
|
|
|
|
|
|
$this->setUpdateKey($key_path);
|
2013-02-25 19:29:21 +00:00
|
|
|
if (!empty($key_path)) {
|
2008-09-18 18:23:26 +00:00
|
|
|
if (str_replace("\"","",$_POST['key_path']) != $key_path) {
|
|
|
|
$errors[] = $this->messages['key_path'][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process for account
|
|
|
|
*/
|
|
|
|
public function process_attributes_account() {
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
$ip = trim($_POST['ip']);
|
|
|
|
$zone = trim($_POST['zone']);
|
|
|
|
$zone_reverse = trim($_POST['zone_reverse']);
|
|
|
|
|
|
|
|
// ip correct???
|
|
|
|
if (!empty($ip)) {
|
|
|
|
if (!check_ip($ip)) {
|
|
|
|
$errors[] = $this->messages['ip'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-03 19:05:16 +00:00
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if (substr($this->attributes['dhcpStatements'][$i], 0, 5) == 'zone ') {
|
|
|
|
unset($this->attributes['dhcpStatements'][$i]);
|
2009-01-04 15:32:16 +00:00
|
|
|
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
|
|
|
|
$i--;
|
2009-01-03 19:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
|
|
|
|
// Zone inserted?
|
|
|
|
if (!empty($zone)) {
|
2013-02-24 11:47:16 +00:00
|
|
|
if (!empty($ip)) {
|
|
|
|
$this->attributes['dhcpStatements'][] = "zone {$zone}. { primary {$ip}; key DHCP_UPDATER; }";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->attributes['dhcpStatements'][] = "zone {$zone}. { key DHCP_UPDATER; }";
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!empty($ip)) {
|
|
|
|
$errors[] = $this->messages['zone'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zone reverse inserted?
|
|
|
|
if (!empty($zone_reverse)) {
|
2013-02-24 11:47:16 +00:00
|
|
|
if (!empty($ip)) {
|
|
|
|
$this->attributes['dhcpStatements'][] = "zone {$zone_reverse}. { primary {$ip}; key DHCP_UPDATER; }";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->attributes['dhcpStatements'][] = "zone {$zone_reverse}. { key DHCP_UPDATER; }";
|
|
|
|
}
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!empty($ip)) {
|
|
|
|
$errors[] = $this->messages['zone_reverse'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
2009-01-03 19:05:16 +00:00
|
|
|
/**
|
|
|
|
* Returns the HTML meta data for the main account page.
|
|
|
|
*
|
2010-09-18 11:37:22 +00:00
|
|
|
* @return htmlElement HTML meta data
|
2009-01-03 19:05:16 +00:00
|
|
|
*/
|
2008-09-18 18:23:26 +00:00
|
|
|
public function display_html_attributes() {
|
2013-02-23 17:10:43 +00:00
|
|
|
$this->attributes = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes;
|
|
|
|
$this->orig = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->orig;
|
2010-09-15 19:52:18 +00:00
|
|
|
$return = new htmlTable();
|
2009-01-10 17:37:09 +00:00
|
|
|
// check if DHCP main settings and valid DHCP entry
|
|
|
|
if ($_SESSION['config']->get_suffix('dhcp') == $this->getAccountContainer()->dn_orig) {
|
2013-02-23 17:10:43 +00:00
|
|
|
if (!in_array_ignore_case('dhcpService', $this->attributes['objectClass']) && !in_array_ignore_case('dhcpServer', $this->attributes['objectClass'])) {
|
|
|
|
$return->addElement(new htmlStatusMessage('ERROR', _('Please set your LDAP suffix to an LDAP entry with object class "dhcpService" or "dhcpServer".')));
|
2010-09-15 19:52:18 +00:00
|
|
|
return $return;
|
2009-01-10 17:37:09 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-15 19:52:18 +00:00
|
|
|
if ($this->getAccountContainer()->dn_orig == $_SESSION['config']->get_suffix('dhcp')) {
|
2009-01-03 19:05:16 +00:00
|
|
|
// DHCP main settings
|
2010-09-15 19:52:18 +00:00
|
|
|
$return->addElement(new htmlTableExtendedInputCheckbox('active', $this->isDynDNSActivated(), _('Activate DynDNS'), 'active'), true);
|
|
|
|
$return->addElement(new htmlTableExtendedInputCheckbox('insert_fixed', $this->addFixIPs(), _('Add fix IP addresses to DNS'), 'fixed_ips'), true);
|
|
|
|
$return->addElement(new htmlTableExtendedInputCheckbox('client_insert', $this->isIgnoreClientUpdates(), _('Disable client updates'), 'client_insert'), true);
|
|
|
|
$keyInput = new htmlTableExtendedInputField(_('Path to key for DNS updates'), 'key_path', $this->getUpdateKey(), 'keypath');
|
|
|
|
$return->addElement($keyInput);
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-01-03 19:05:16 +00:00
|
|
|
// Account edit
|
2008-09-18 18:23:26 +00:00
|
|
|
if (!$this->check_if_ddns_is_enable()) {
|
2010-09-15 19:52:18 +00:00
|
|
|
$return->addElement(new htmlOutputText(_("DDNS ist not activated. You can activate it in the DHCP settings (DDNS).")));
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
2010-09-15 19:52:18 +00:00
|
|
|
else {
|
|
|
|
// DNS server
|
|
|
|
$serverInput = new htmlTableExtendedInputField(_('IP address of the DNS server'), 'ip', $this->getDNSServer(), 'dns');
|
|
|
|
$return->addElement($serverInput, true);
|
2008-09-18 18:23:26 +00:00
|
|
|
|
2009-01-03 19:05:16 +00:00
|
|
|
$zones = $this->getZoneNames();
|
|
|
|
$zone = '';
|
|
|
|
$revzone = '';
|
|
|
|
if (isset($zones[0])) {
|
|
|
|
$zone = $zones[0];
|
|
|
|
}
|
|
|
|
if (isset($zones[1])) {
|
|
|
|
$revzone = $zones[1];
|
|
|
|
}
|
2013-02-24 19:36:10 +00:00
|
|
|
// zone name
|
|
|
|
$zoneInput = new htmlTableExtendedInputField(_('Zone name'), 'zone', $zone, 'zone');
|
2010-09-15 19:52:18 +00:00
|
|
|
$return->addElement($zoneInput, true);
|
2013-02-24 19:36:10 +00:00
|
|
|
// reverse zone name
|
|
|
|
$revZoneInput = new htmlTableExtendedInputField(_('Reverse zone name'), 'zone_reverse', $revzone, 'zone_reverse');
|
2010-09-15 19:52:18 +00:00
|
|
|
$return->addElement($revZoneInput);
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-03 19:05:16 +00:00
|
|
|
* Returns the PDF entries for this module.
|
2008-09-18 18:23:26 +00:00
|
|
|
*
|
2009-01-03 19:05:16 +00:00
|
|
|
* @return array list of possible PDF entries
|
2008-09-18 18:23:26 +00:00
|
|
|
*/
|
2009-01-03 19:05:16 +00:00
|
|
|
public function get_pdfEntries() {
|
2013-02-23 17:10:43 +00:00
|
|
|
// attributes are taken from DHCP server object
|
|
|
|
$this->attributes = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes;
|
|
|
|
$this->orig = &$this->getAccountContainer()->getAccountModule('dhcp_settings')->orig;
|
2009-01-03 19:05:16 +00:00
|
|
|
$zones = $this->getZoneNames();
|
|
|
|
$zone = '';
|
|
|
|
$revzone = '';
|
|
|
|
if (isset($zones[0])) {
|
|
|
|
$zone = $zones[0];
|
|
|
|
}
|
|
|
|
if (isset($zones[1])) {
|
|
|
|
$revzone = $zones[1];
|
|
|
|
}
|
|
|
|
return array(
|
|
|
|
get_class($this) . '_DNSserver' => array('<block><key>' . _('IP address of the DNS server') . '</key><value>' . $this->getDNSServer() . '</value></block>'),
|
2013-02-24 19:36:10 +00:00
|
|
|
get_class($this) . '_zone' => array('<block><key>' . _('Zone name') . '</key><value>' . $zone . '</value></block>'),
|
|
|
|
get_class($this) . '_reverseZone' => array('<block><key>' . _('Reverse zone name') . '</key><value>' . $revzone . '</value></block>'),
|
2009-01-03 19:05:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the IP of the DNS server.
|
|
|
|
*
|
|
|
|
* @return String IP address
|
|
|
|
*/
|
|
|
|
private function getDNSServer() {
|
|
|
|
$return = null;
|
2013-02-24 11:47:16 +00:00
|
|
|
if (isset($this->attributes['dhcpStatements'][0])) {
|
2009-01-03 19:05:16 +00:00
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if (substr($this->attributes['dhcpStatements'][$i], 0, 5) == 'zone ') {
|
2013-02-24 11:47:16 +00:00
|
|
|
if (strpos($this->attributes['dhcpStatements'][$i], ' primary ') === false) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-15 19:52:18 +00:00
|
|
|
$parts = explode(". { primary ", $this->attributes['dhcpStatements'][$i]);
|
|
|
|
$temp = array_pop($parts);
|
|
|
|
$temp = explode(";", $temp);
|
|
|
|
return array_shift($temp);
|
2009-01-03 19:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the zone names.
|
|
|
|
*
|
2013-02-24 19:36:10 +00:00
|
|
|
* @return array zone names array(zone, reverse zone)
|
2009-01-03 19:05:16 +00:00
|
|
|
*/
|
|
|
|
private function getZoneNames() {
|
2008-09-18 18:23:26 +00:00
|
|
|
$return = array();
|
2013-02-24 19:36:10 +00:00
|
|
|
$zone = '';
|
|
|
|
$revZone = '';
|
2009-01-03 19:05:16 +00:00
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if (substr($this->attributes['dhcpStatements'][$i], 0, 5) == 'zone ') {
|
2010-09-15 19:52:18 +00:00
|
|
|
$parts = explode(" ",substr($this->attributes['dhcpStatements'][$i],5));
|
2013-02-24 19:36:10 +00:00
|
|
|
$value = substr(array_shift($parts),0,-1);
|
|
|
|
if (strpos($value, 'in-addr.arpa') === false) {
|
|
|
|
$zone = $value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$revZone = $value;
|
|
|
|
}
|
2009-01-03 19:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-24 19:36:10 +00:00
|
|
|
$return[0] = $zone;
|
|
|
|
$return[1] = $revZone;
|
2009-01-03 19:05:16 +00:00
|
|
|
return $return;
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-01-03 19:05:16 +00:00
|
|
|
* Returns if DDNS is activated.
|
|
|
|
*
|
|
|
|
* @return boolean activated
|
|
|
|
*/
|
|
|
|
private function isDynDNSActivated() {
|
|
|
|
$return = false;
|
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if ($this->attributes['dhcpStatements'][$i] == 'ddns-update-style interim') {
|
|
|
|
$return = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
2008-12-29 17:39:05 +00:00
|
|
|
|
|
|
|
/**
|
2009-01-03 19:05:16 +00:00
|
|
|
* Sets if DDNS is activated.
|
|
|
|
*
|
2012-07-15 12:05:47 +00:00
|
|
|
* @param boolean $activated activated
|
2009-01-03 19:05:16 +00:00
|
|
|
*/
|
|
|
|
private function setDynDNSActivated($activated) {
|
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if (substr($this->attributes['dhcpStatements'][$i], 0, 18) == 'ddns-update-style ') {
|
|
|
|
unset($this->attributes['dhcpStatements'][$i]);
|
|
|
|
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($activated) {
|
|
|
|
$this->attributes['dhcpStatements'][] = 'ddns-update-style interim';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->attributes['dhcpStatements'][] = 'ddns-update-style none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if fixed IPs are added to DDNS.
|
|
|
|
*
|
|
|
|
* @return boolean add fixed IPs
|
|
|
|
*/
|
|
|
|
private function addFixIPs() {
|
|
|
|
$return = false;
|
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if ($this->attributes['dhcpStatements'][$i] == 'update-static-leases true') {
|
|
|
|
$return = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if client updates are ignored.
|
|
|
|
*
|
2012-07-15 12:05:47 +00:00
|
|
|
* @param boolean $add add fixed IPs
|
2009-01-03 19:05:16 +00:00
|
|
|
*/
|
|
|
|
private function setFixIPs($add) {
|
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if (substr($this->attributes['dhcpStatements'][$i], 0, 21) == 'update-static-leases ') {
|
|
|
|
unset($this->attributes['dhcpStatements'][$i]);
|
|
|
|
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($add) {
|
|
|
|
$this->attributes['dhcpStatements'][] = 'update-static-leases true';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if client updates are ignored.
|
|
|
|
*
|
|
|
|
* @return boolean ignore client updates
|
|
|
|
*/
|
|
|
|
private function isIgnoreClientUpdates() {
|
|
|
|
$return = false;
|
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
2013-02-24 11:47:16 +00:00
|
|
|
if (preg_replace('/[ ]+/', ' ', $this->attributes['dhcpStatements'][$i]) == 'ignore client-updates') {
|
2009-01-03 19:05:16 +00:00
|
|
|
$return = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets if client updates are ignored.
|
|
|
|
*
|
2012-07-15 12:05:47 +00:00
|
|
|
* @param boolean $ignore ignore client updates
|
2009-01-03 19:05:16 +00:00
|
|
|
*/
|
|
|
|
private function setIgnoreClientUpdates($ignore) {
|
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
2013-02-24 11:47:16 +00:00
|
|
|
if (preg_replace('/[ ]+/', ' ', $this->attributes['dhcpStatements'][$i]) == 'ignore client-updates') {
|
|
|
|
if ($ignore) {
|
|
|
|
return; // option already set, no change
|
|
|
|
}
|
2009-01-03 19:05:16 +00:00
|
|
|
unset($this->attributes['dhcpStatements'][$i]);
|
|
|
|
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($ignore) {
|
|
|
|
$this->attributes['dhcpStatements'][] = 'ignore client-updates';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the key for DNS updates.
|
|
|
|
*
|
|
|
|
* @return String key
|
|
|
|
*/
|
|
|
|
private function getUpdateKey() {
|
|
|
|
$return = null;
|
|
|
|
if (is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if (substr($this->attributes['dhcpStatements'][$i], 0, 8) == 'include ') {
|
|
|
|
$return = substr($this->attributes['dhcpStatements'][$i],9, strlen($this->attributes['dhcpStatements'][$i]) - 10);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the key for DNS updates.
|
|
|
|
*
|
2012-07-15 12:05:47 +00:00
|
|
|
* @param String $key key
|
2009-01-03 19:05:16 +00:00
|
|
|
*/
|
|
|
|
private function setUpdateKey($key) {
|
|
|
|
if (!is_array($this->attributes['dhcpStatements'])) {
|
|
|
|
$this->attributes['dhcpStatements'] = array();
|
|
|
|
}
|
|
|
|
for ($i = 0; $i < sizeof($this->attributes['dhcpStatements']); $i++) {
|
|
|
|
if (substr($this->attributes['dhcpStatements'][$i], 0, 8) == 'include ') {
|
|
|
|
unset($this->attributes['dhcpStatements'][$i]);
|
|
|
|
$this->attributes['dhcpStatements'] = array_values($this->attributes['dhcpStatements']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (($key != null) && ($key != '')) {
|
|
|
|
$this->attributes['dhcpStatements'][] = 'include "' . $key . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function loads the LDAP attributes when an account should be loaded.
|
|
|
|
*
|
|
|
|
* Calling this method requires the existence of an enclosing {@link accountContainer}.<br>
|
|
|
|
* <br>
|
|
|
|
* By default this method loads the object classes and accounts which are specified in {@link getManagedObjectClasses()}
|
|
|
|
* and {@link getManagedAttributes()}.
|
2008-12-29 17:39:05 +00:00
|
|
|
*
|
2009-01-03 19:05:16 +00:00
|
|
|
* @param array $attributes array like the array returned by get_ldap_attributes(dn of account) but without count indices
|
2008-12-29 17:39:05 +00:00
|
|
|
*/
|
2009-01-03 19:05:16 +00:00
|
|
|
public function load_attributes($attributes) {
|
|
|
|
// load nothing, attributes are saved in "dhcp_settings" module
|
2008-12-29 17:39:05 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 19:51:37 +00:00
|
|
|
/**
|
|
|
|
* In this function the LDAP account is built up.
|
|
|
|
*
|
|
|
|
* @param array $rawAccounts list of hash arrays (name => value) from user input
|
|
|
|
* @param array $ids list of IDs for column position (e.g. "posixAccount_uid" => 5)
|
2012-07-15 12:05:47 +00:00
|
|
|
* @param array $partialAccounts list of hash arrays (name => value) which are later added to LDAP
|
2010-02-15 20:21:44 +00:00
|
|
|
* @param array $selectedModules list of selected account modules
|
2009-03-26 19:51:37 +00:00
|
|
|
* @return array list of error messages if any
|
|
|
|
*/
|
2010-02-15 20:21:44 +00:00
|
|
|
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
|
2009-03-26 19:51:37 +00:00
|
|
|
$messages = array();
|
|
|
|
if (!$this->check_if_ddns_is_enable()) {
|
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
|
|
|
// principal name
|
|
|
|
if (!check_ip($rawAccounts[$i][$ids['ddns_DNSserver']])) {
|
|
|
|
$error = $this->messages['ip'][1];
|
|
|
|
array_push($error, $i);
|
|
|
|
$messages[] = $error;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$partialAccounts[$i]['dhcpStatements'][] = "zone {$rawAccounts[$i][$ids['ddns_zone']]}. { primary {$rawAccounts[$i][$ids['ddns_DNSserver']]}; key DHCP_UPDATER; }";
|
|
|
|
$partialAccounts[$i]['dhcpStatements'][] = "zone {$rawAccounts[$i][$ids['ddns_reverseZone']]}. { primary {$rawAccounts[$i][$ids['ddns_DNSserver']]}; key DHCP_UPDATER; }";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $messages;
|
|
|
|
}
|
|
|
|
|
2008-09-18 18:23:26 +00:00
|
|
|
}
|
2009-01-03 19:05:16 +00:00
|
|
|
|
2008-12-29 17:39:05 +00:00
|
|
|
?>
|