2008-09-17 19:44:41 +00:00
|
|
|
<?php
|
2017-02-18 09:13:08 +00:00
|
|
|
use \LAM\PDF\PDFTable;
|
|
|
|
use \LAM\PDF\PDFTableCell;
|
|
|
|
use \LAM\PDF\PDFTableRow;
|
2008-09-17 19:44:41 +00:00
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
2009-10-27 18:47:12 +00:00
|
|
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
2009-11-25 12:08:08 +00:00
|
|
|
Copyright (C) 2008 Thomas Manninger
|
2017-02-18 09:13:08 +00:00
|
|
|
2008 - 2017 Roland Gruber
|
2008-09-17 19:44:41 +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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-08-31 09:33:45 +00:00
|
|
|
* Manages DHCP host entries.
|
2008-09-17 19:44:41 +00:00
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
*
|
|
|
|
* @author Thomas Manninger
|
2008-12-30 15:25:31 +00:00
|
|
|
* @author Roland Gruber
|
2008-09-17 19:44:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-08-31 09:33:45 +00:00
|
|
|
* Manages DHCP host entries.
|
2008-09-17 19:44:41 +00:00
|
|
|
*
|
|
|
|
* @package modules
|
|
|
|
*/
|
|
|
|
|
|
|
|
class fixed_ip extends baseModule {
|
|
|
|
|
2012-07-15 12:05:47 +00:00
|
|
|
/** fixed ips */
|
2014-09-13 14:43:44 +00:00
|
|
|
public $fixed_ip = array();
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2012-07-15 12:05:47 +00:00
|
|
|
/** already processed? */
|
2008-09-17 19:44:41 +00:00
|
|
|
public $processed = false;
|
|
|
|
|
2012-07-15 12:05:47 +00:00
|
|
|
/** for check if IPs overlap */
|
2008-09-17 19:44:41 +00:00
|
|
|
public $overlapd;
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2012-07-15 12:05:47 +00:00
|
|
|
/** original IPs */
|
2008-09-17 19:44:41 +00:00
|
|
|
public $orig_ips = array();
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2012-07-15 12:05:47 +00:00
|
|
|
/** LDAP attributes */
|
2008-09-17 19:44:41 +00:00
|
|
|
public $attributes;
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2014-02-08 15:06:02 +00:00
|
|
|
/** cached host entries (list of array('cn' => ..., 'iphostnumber' => ..., 'macaddress' => ...)) */
|
2014-01-28 20:00:47 +00:00
|
|
|
private $hostCache = null;
|
2008-09-17 19:44:41 +00:00
|
|
|
|
2014-04-20 12:59:36 +00:00
|
|
|
/**
|
|
|
|
* Returns true if this module can manage accounts of the current type, otherwise false.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2014-04-20 12:59:36 +00:00
|
|
|
* @return boolean true if module fits
|
|
|
|
*/
|
|
|
|
public function can_manage() {
|
|
|
|
return in_array($this->get_scope(), array('dhcp'));
|
|
|
|
}
|
|
|
|
|
2010-06-12 17:17:31 +00:00
|
|
|
/**
|
|
|
|
* Returns meta data that is interpreted by parent class
|
|
|
|
*
|
|
|
|
* @return array array with meta data
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2010-06-12 17:17:31 +00:00
|
|
|
* @see baseModule::get_metaData()
|
|
|
|
*/
|
2008-09-17 19:44:41 +00:00
|
|
|
public function get_metaData() {
|
|
|
|
$return = array();
|
|
|
|
// alias name
|
2010-08-21 08:28:13 +00:00
|
|
|
$return["alias"] = _("Hosts");
|
2008-09-17 19:44:41 +00:00
|
|
|
// this is a base module
|
|
|
|
$return["is_base"] = false;
|
2010-02-15 16:56:56 +00:00
|
|
|
// icon
|
2010-02-15 20:31:30 +00:00
|
|
|
$return['icon'] = 'computer.png';
|
2008-09-17 19:44:41 +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-17 19:44:41 +00:00
|
|
|
// managed object classes
|
|
|
|
$return['objectClasses'] = array();
|
|
|
|
// managed attributes
|
2008-12-07 19:13:50 +00:00
|
|
|
$return['attributes'] = array('dhcpOption');
|
2008-09-17 19:44:41 +00:00
|
|
|
// help Entries
|
|
|
|
$return['help'] = array(
|
2013-08-31 09:33:45 +00:00
|
|
|
'pc' => array(
|
|
|
|
"Headline" => _("PC name"), 'attr' => 'dhcpOption, host-name',
|
2008-09-17 19:44:41 +00:00
|
|
|
"Text" => _("The name of the PC.")
|
2013-08-31 09:33:45 +00:00
|
|
|
),
|
|
|
|
'mac' => array(
|
|
|
|
"Headline" => _("MAC address"), 'attr' => 'dhcpHWAddress',
|
2008-09-17 19:44:41 +00:00
|
|
|
"Text" => _("The MAC address of the PC. Example: 11:22:33:44:55:aa")
|
2013-08-31 09:33:45 +00:00
|
|
|
),
|
|
|
|
'ip' => array(
|
|
|
|
"Headline" => _("IP address"), 'attr' => 'dhcpStatements, fixed-address',
|
2008-09-17 19:44:41 +00:00
|
|
|
"Text" => _("The IP address of the PC.")
|
2013-08-31 09:33:45 +00:00
|
|
|
),
|
2014-02-08 15:06:02 +00:00
|
|
|
'description' => array(
|
|
|
|
"Headline" => _("Description"), 'attr' => 'dhcpComments',
|
|
|
|
"Text" => _("Optional description for the PC.")
|
|
|
|
),
|
2013-08-31 09:33:45 +00:00
|
|
|
'active' => array(
|
|
|
|
"Headline" => _("Active"), 'attr' => 'dhcpStatements, booting',
|
|
|
|
"Text" => _("Inactive hosts will not be able to get an address from the DHCP server.")
|
|
|
|
),
|
|
|
|
);
|
2008-09-17 19:44:41 +00:00
|
|
|
// available PDF fields
|
2010-04-05 12:38:23 +00:00
|
|
|
$return['PDF_fields'] = array('IPlist' => _('IP list'));
|
2008-09-17 19:44:41 +00:00
|
|
|
return $return;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2010-06-12 17:17:31 +00:00
|
|
|
/**
|
|
|
|
* This function fills the error message array with messages.
|
|
|
|
*/
|
2008-09-17 19:44:41 +00:00
|
|
|
public function load_Messages() {
|
|
|
|
$this->messages['errors'][0] = array('ERROR', _('One or more errors occured. The invalid fields are marked.'), '');
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
/**
|
|
|
|
* Controls if the module button the account page is visible and activated.
|
|
|
|
*
|
|
|
|
* @return string status ("enabled", "disabled", "hidden")
|
|
|
|
*/
|
|
|
|
public function getButtonStatus() {
|
2017-04-22 13:59:07 +00:00
|
|
|
if ($this->isRootNode()) {
|
|
|
|
return "hidden";
|
|
|
|
}
|
2008-09-17 19:44:41 +00:00
|
|
|
else {
|
2017-04-22 13:59:07 +00:00
|
|
|
return "enabled";
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Checked, if ips are overlapd.
|
|
|
|
*
|
|
|
|
* @param ip
|
|
|
|
*
|
|
|
|
* @return false, if overlapd, else true.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function overlapd_ip($ip) {
|
|
|
|
if (in_array($ip, $this->overlapd)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->overlapd[] = $ip;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Reset the overlapd_range() function
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function reset_overlapd_ip() {
|
|
|
|
$this->overlapd = array();
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check, if a mac address is invalid
|
|
|
|
* @param mac adress
|
|
|
|
*
|
|
|
|
* @return true, if mac is invalid
|
|
|
|
**/
|
|
|
|
public function check_mac($mac) {
|
|
|
|
$ex = explode(":", $mac);
|
|
|
|
$invalid = false;
|
|
|
|
if (count($ex)!=6) {
|
|
|
|
$invalid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($ex AS $value) {
|
2009-08-13 18:57:26 +00:00
|
|
|
if (!preg_match("/[0-9a-fA-F][0-9a-fA-F]/", $value) || strlen($value)!="2") {
|
2008-09-17 19:44:41 +00:00
|
|
|
$invalid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $invalid;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Adapt the fixed ip with the subnet.
|
|
|
|
*
|
|
|
|
* @return true, if ip were edit.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
public function reload_ips() {
|
2013-09-14 15:38:35 +00:00
|
|
|
$ip_edit = false; // IPs were edited?
|
|
|
|
// Only run it, when ranges already exists:
|
2008-09-17 19:44:41 +00:00
|
|
|
if(is_array($this->fixed_ip)) {
|
2009-11-24 18:24:39 +00:00
|
|
|
$ex_subnet = explode(".", $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]);
|
2008-09-17 19:44:41 +00:00
|
|
|
foreach ($this->fixed_ip AS $id=>$arr) {
|
2009-11-24 21:37:36 +00:00
|
|
|
if (!empty($this->fixed_ip[$id]['ip']) && !range::check_subnet_range($this->fixed_ip[$id]['ip'],
|
|
|
|
$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0],
|
|
|
|
$this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'))) {
|
2008-09-17 19:44:41 +00:00
|
|
|
// Range anpassen:
|
|
|
|
$ex = explode(".", $this->fixed_ip[$id]['ip']);
|
|
|
|
$tmp = $this->fixed_ip[$id]['ip'];
|
|
|
|
$this->fixed_ip[$id]['ip'] = $ex_subnet['0'].".".$ex_subnet['1'].".".$ex_subnet['2'].".".$ex['3'];
|
|
|
|
if ($tmp!=$this->fixed_ip[$id]['ip'])
|
|
|
|
$ip_edit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ip_edit;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
/**
|
|
|
|
* This function loads all needed LDAP attributes.
|
|
|
|
*
|
|
|
|
* @param array $attr list of attributes
|
|
|
|
*/
|
|
|
|
function load_attributes($attr) {
|
2017-04-22 13:59:07 +00:00
|
|
|
if (!$this->isRootNode()) {
|
2014-02-08 15:06:02 +00:00
|
|
|
$attributes = array('cn', 'dhcphwaddress', 'dhcpstatements', 'dhcpcomments');
|
|
|
|
$entries = searchLDAP($this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', $attributes);
|
2014-01-28 20:00:47 +00:00
|
|
|
for ($i = 0; $i < sizeof($entries); $i++) {
|
2011-10-20 16:43:42 +00:00
|
|
|
$dhcphwaddress = explode(" ", $entries[$i]['dhcphwaddress'][0]);
|
|
|
|
$dhcphwaddress = array_pop($dhcphwaddress);
|
2013-08-31 09:33:45 +00:00
|
|
|
$dhcpstatements = array();
|
|
|
|
if (isset($entries[$i]['dhcpstatements'][0])) {
|
|
|
|
$dhcpstatements = $entries[$i]['dhcpstatements'];
|
|
|
|
}
|
2010-02-07 14:04:29 +00:00
|
|
|
$this->fixed_ip[$i]['cn'] = $entries[$i]['cn'][0];
|
2011-10-20 16:43:42 +00:00
|
|
|
$this->fixed_ip[$i]['mac'] = $dhcphwaddress;
|
2013-08-31 09:33:45 +00:00
|
|
|
$this->fixed_ip[$i]['ip'] = self::extractIP($dhcpstatements);
|
|
|
|
$this->fixed_ip[$i]['active'] = self::isActive($dhcpstatements);
|
|
|
|
$this->fixed_ip[$i]['dhcpstatements'] = $dhcpstatements;
|
2014-02-08 15:06:02 +00:00
|
|
|
$description = '';
|
|
|
|
if (isset($entries[$i]['dhcpcomments'][0])) {
|
|
|
|
$description = $entries[$i]['dhcpcomments'][0];
|
|
|
|
}
|
|
|
|
$this->fixed_ip[$i]['description'] = $description;
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2010-02-07 14:04:29 +00:00
|
|
|
$this->orig_ips[$i]['cn'] = $entries[$i]['cn'][0];
|
2011-10-20 16:43:42 +00:00
|
|
|
$this->orig_ips[$i]['mac'] = $dhcphwaddress;
|
2013-08-31 09:33:45 +00:00
|
|
|
$this->orig_ips[$i]['ip'] = self::extractIP($dhcpstatements);
|
|
|
|
$this->orig_ips[$i]['active'] = self::isActive($dhcpstatements);
|
|
|
|
$this->orig_ips[$i]['dhcpstatements'] = $dhcpstatements;
|
2014-02-08 15:06:02 +00:00
|
|
|
$this->orig_ips[$i]['description'] = $description;
|
2010-02-07 14:04:29 +00:00
|
|
|
}
|
2014-01-28 20:00:47 +00:00
|
|
|
$this->orderByIP();
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 20:00:47 +00:00
|
|
|
/**
|
|
|
|
* Orders the host entries by IP address.
|
|
|
|
*/
|
|
|
|
private function orderByIP() {
|
|
|
|
// sort by IP
|
|
|
|
$order = array();
|
|
|
|
foreach ($this->fixed_ip as $key => $value) {
|
|
|
|
$order[$key] = '';
|
|
|
|
if (!empty($value['dhcpstatements'])) {
|
|
|
|
$order[$key] = fixed_ip::extractIP($value['dhcpstatements']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
natcasesort($order);
|
|
|
|
$newVal = array();
|
|
|
|
foreach ($order as $index => $sortval) {
|
|
|
|
$newVal[] = $this->fixed_ip[$index];
|
|
|
|
}
|
|
|
|
$this->fixed_ip = $newVal;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +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();
|
2017-04-22 13:59:07 +00:00
|
|
|
if (!$this->isRootNode()) {
|
2008-09-17 19:44:41 +00:00
|
|
|
$this->processed = true;
|
|
|
|
|
|
|
|
$this->reset_overlapd_ip();
|
|
|
|
|
2009-11-24 18:24:39 +00:00
|
|
|
if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]!="") {
|
2008-09-17 19:44:41 +00:00
|
|
|
|
|
|
|
$error = false; // errors by process_attributes()?
|
|
|
|
$pcs = array();
|
|
|
|
foreach($this->fixed_ip AS $id=>$arr) {
|
|
|
|
|
|
|
|
// Check if ip is to drop
|
|
|
|
if (isset($_POST['drop_ip_'.$id])) {
|
|
|
|
// Drop ip:
|
|
|
|
unset($this->fixed_ip[$id]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-05-10 20:24:37 +00:00
|
|
|
// MAC address
|
|
|
|
$_POST['mac_'.$id] = strtolower(trim($_POST['mac_'.$id]));
|
2008-09-17 19:44:41 +00:00
|
|
|
|
2009-05-10 20:24:37 +00:00
|
|
|
$invalid = $this->check_mac($_POST['mac_'.$id]);
|
|
|
|
if ($invalid) {
|
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
$this->fixed_ip[$id]['mac'] = $_POST['mac_'.$id];
|
2008-09-17 19:44:41 +00:00
|
|
|
|
2014-02-08 15:06:02 +00:00
|
|
|
// description
|
|
|
|
if (!get_preg($_POST['description_'.$id], 'ascii')) {
|
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
$this->fixed_ip[$id]['description'] = $_POST['description_'.$id];
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2014-02-08 15:06:02 +00:00
|
|
|
// active
|
|
|
|
$this->fixed_ip[$id]['active'] = (isset($_POST['active_' . $id]) && ($_POST['active_' . $id] == 'on'));
|
|
|
|
|
2009-05-10 20:24:37 +00:00
|
|
|
// Ip address
|
|
|
|
if (!empty($_POST['ip_'.$id])) {
|
|
|
|
$_POST['ip_'.$id] = trim($_POST['ip_'.$id]);
|
|
|
|
}
|
2010-08-21 08:28:13 +00:00
|
|
|
if (!empty($_POST['ip_'.$id]) && !(check_ip($_POST['ip_'.$id]))) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$error = true;
|
|
|
|
$this->fixed_ip[$id]['ip'] = $_POST['ip_'.$id];
|
|
|
|
}
|
2010-08-21 08:28:13 +00:00
|
|
|
elseif (!empty($_POST['ip_'.$id]) && !$this->overlapd_ip($_POST['ip_'.$id])) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$error = true;
|
|
|
|
$this->fixed_ip[$id]['ip'] = $_POST['ip_'.$id];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->fixed_ip[$id]['ip'] = $_POST['ip_'.$id];
|
|
|
|
}
|
2008-09-17 19:44:41 +00:00
|
|
|
|
2009-05-10 20:24:37 +00:00
|
|
|
// Is ip correct with subnet:
|
2010-08-21 08:28:13 +00:00
|
|
|
if (!empty($_POST['ip_'.$id]) && check_ip($_POST['ip_'.$id]) && !range::check_subnet_range($_POST['ip_'.$id],
|
2009-11-24 21:37:36 +00:00
|
|
|
$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0],
|
|
|
|
$this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'))) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$error = true;
|
|
|
|
}
|
2008-09-17 19:44:41 +00:00
|
|
|
|
2009-05-10 20:24:37 +00:00
|
|
|
// cn:
|
|
|
|
if (!empty($_POST['pc_'.$id])) $_POST['pc_'.$id] = trim($_POST['pc_'.$id]);
|
|
|
|
if (!empty($_POST['pc_'.$id])) {
|
2008-09-17 19:44:41 +00:00
|
|
|
|
2009-05-10 20:24:37 +00:00
|
|
|
// Already use?
|
|
|
|
if (in_array($_POST['pc_'.$id], $pcs) ) {
|
2008-09-17 19:44:41 +00:00
|
|
|
$error = true;
|
|
|
|
}
|
2009-05-10 20:24:37 +00:00
|
|
|
else {
|
|
|
|
$pcs[] = $_POST['pc_'.$id];
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-10 20:24:37 +00:00
|
|
|
else {
|
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
if (strlen($_POST['pc_'.$id])>30) {
|
|
|
|
$error = true;
|
|
|
|
}
|
2012-07-15 12:05:47 +00:00
|
|
|
if (!preg_match("/^[A-Za-z0-9\\._-]*$/",$_POST['pc_'.$id])) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
$this->fixed_ip[$id]['cn'] = $_POST['pc_'.$id];
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
if ($error) {
|
|
|
|
$errors[] = $this->messages['errors'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add new IP
|
2012-09-06 13:46:19 +00:00
|
|
|
if (isset($_POST['add_ip']) || ($_POST['pc_add'] != '') || ($_POST['mac_add'] != '')) {
|
2009-05-10 20:24:37 +00:00
|
|
|
// Add IP:
|
2014-02-08 15:06:02 +00:00
|
|
|
$active = (isset($_POST['active_add']) && ($_POST['active_add'] == 'on'));
|
|
|
|
$dhcpstatements = array();
|
|
|
|
$this->setActive($dhcpstatements, $active);
|
|
|
|
$this->setIP($dhcpstatements, $_POST['ip_add']);
|
2013-08-31 09:33:45 +00:00
|
|
|
$this->fixed_ip[] = array(
|
|
|
|
'cn' => $_POST['pc_add'],
|
|
|
|
'mac' => $_POST['mac_add'],
|
2014-02-08 15:06:02 +00:00
|
|
|
'description' => $_POST['description_add'],
|
2013-08-31 09:33:45 +00:00
|
|
|
'ip' => $_POST['ip_add'],
|
2014-02-08 15:06:02 +00:00
|
|
|
'dhcpstatements' => $dhcpstatements,
|
|
|
|
'active' => $active,
|
2013-08-31 09:33:45 +00:00
|
|
|
);
|
2014-01-28 20:00:47 +00:00
|
|
|
$this->orderByIP();
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
return $errors;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2010-06-12 17:17:31 +00:00
|
|
|
/**
|
|
|
|
* Returns the HTML meta data for the main account page.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2010-09-18 11:37:22 +00:00
|
|
|
* @return htmlElement HTML meta data
|
2010-06-12 17:17:31 +00:00
|
|
|
*/
|
2008-09-17 19:44:41 +00:00
|
|
|
public function display_html_attributes() {
|
2010-09-18 11:37:22 +00:00
|
|
|
$return = new htmlTable();
|
2009-11-24 18:24:39 +00:00
|
|
|
if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]=="") {
|
2010-09-18 11:37:22 +00:00
|
|
|
$return->addElement(new htmlStatusMessage('ERROR', _("Please fill out the DHCP settings first.")), true);
|
|
|
|
return $return;
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2009-01-10 17:15:30 +00:00
|
|
|
else {
|
2014-01-28 20:00:47 +00:00
|
|
|
$this->initCache();
|
|
|
|
// auto-completion for host names
|
|
|
|
$autoNames = array();
|
|
|
|
if (!empty($this->hostCache) && (sizeof($this->hostCache) < 200)) {
|
|
|
|
foreach ($this->hostCache as $index => $attrs) {
|
|
|
|
if (!empty($attrs['cn'][0])) {
|
|
|
|
$autoNames[] = $attrs['cn'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$autoNames = array_values(array_unique($autoNames));
|
|
|
|
}
|
2009-05-10 20:24:37 +00:00
|
|
|
// caption
|
2014-01-28 20:00:47 +00:00
|
|
|
$ipContainer = new htmlTable();
|
|
|
|
$ipContainer->addElement(new htmlOutputText(_('IP address')));
|
|
|
|
$ipContainer->addElement(new htmlHelpLink('ip'));
|
|
|
|
$return->addElement($ipContainer);
|
2010-09-18 11:37:22 +00:00
|
|
|
$pcContainer = new htmlTable();
|
2014-01-28 20:00:47 +00:00
|
|
|
$pcContainer->addElement(new htmlOutputText(_('PC name'), true, true));
|
2010-09-18 11:37:22 +00:00
|
|
|
$pcContainer->addElement(new htmlHelpLink('pc'));
|
|
|
|
$return->addElement($pcContainer);
|
|
|
|
$macContainer = new htmlTable();
|
2014-01-28 20:00:47 +00:00
|
|
|
$macContainer->addElement(new htmlOutputText(_('MAC address'), true, true));
|
2010-09-18 11:37:22 +00:00
|
|
|
$macContainer->addElement(new htmlHelpLink('mac'));
|
|
|
|
$return->addElement($macContainer);
|
2014-02-08 15:06:02 +00:00
|
|
|
$commentContainer = new htmlTable();
|
|
|
|
$commentContainer->addElement(new htmlOutputText(_('Description'), true));
|
|
|
|
$commentContainer->addElement(new htmlHelpLink('description'));
|
|
|
|
$return->addElement($commentContainer);
|
2013-08-31 09:33:45 +00:00
|
|
|
$activeContainer = new htmlTable();
|
2014-02-08 15:06:02 +00:00
|
|
|
$activeContainer->colspan = 2;
|
2013-08-31 09:33:45 +00:00
|
|
|
$activeContainer->addElement(new htmlOutputText(_('Active')));
|
|
|
|
$activeContainer->addElement(new htmlHelpLink('active'));
|
|
|
|
$return->addElement($activeContainer, true);
|
2009-05-10 20:24:37 +00:00
|
|
|
// Reset oberlaped ips
|
2008-09-17 19:44:41 +00:00
|
|
|
$this->reset_overlapd_ip();
|
|
|
|
|
2009-05-10 20:24:37 +00:00
|
|
|
// If $ranges is not a array, then create one:
|
2008-09-17 19:44:41 +00:00
|
|
|
if (!is_array($this->fixed_ip)) {
|
2009-11-24 19:13:06 +00:00
|
|
|
$this->fixed_ip = array();
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
$pcs = array();
|
|
|
|
foreach($this->fixed_ip AS $id=>$arr) {
|
|
|
|
// pc name
|
2009-05-10 20:24:37 +00:00
|
|
|
$pcError = "";
|
2008-09-17 19:44:41 +00:00
|
|
|
if (!$this->processed) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$pcError = "";
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
elseif (strlen($this->fixed_ip[$id]['cn'])>20) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$pcError = _("The PC name may not be longer than 20 characters.");
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
elseif (strlen($this->fixed_ip[$id]['cn'])<2) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$pcError = _("The PC name needs to be at least 2 characters long.");
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
elseif (in_array($this->fixed_ip[$id]['cn'], $pcs) ) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$pcError = _("This PC name already exists.");
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2012-07-15 12:05:47 +00:00
|
|
|
elseif (isset($_POST['pc_'.$id]) && !preg_match("/^[A-Za-z0-9\\._-]*$/", $_POST['pc_'.$id])) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$pcError = _("The PC name may only contain A-Z, a-z and 0-9.");
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
$pcs[] = $this->fixed_ip[$id]['cn'];
|
|
|
|
|
|
|
|
// MAC address
|
2009-05-10 20:24:37 +00:00
|
|
|
$macError = "";
|
2008-09-17 19:44:41 +00:00
|
|
|
if (!$this->processed) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$macError = "";
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
elseif ($this->check_mac($this->fixed_ip[$id]['mac'])) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$macError = _("Invalid MAC address.");
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2014-02-08 15:06:02 +00:00
|
|
|
// descripton
|
|
|
|
$descriptionError = "";
|
|
|
|
if (!$this->processed) {
|
|
|
|
$descriptionError = "";
|
|
|
|
}
|
|
|
|
elseif (!get_preg($this->fixed_ip[$id]['description'], 'ascii')) {
|
|
|
|
$descriptionError = _("Invalid description.");
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
// fixed ip
|
2009-05-10 20:24:37 +00:00
|
|
|
$ipError = "";
|
2010-08-21 08:28:13 +00:00
|
|
|
if (!$this->processed || ($this->fixed_ip[$id]['ip'] == '')) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$ipError = "";
|
|
|
|
}
|
2010-08-21 08:28:13 +00:00
|
|
|
elseif (!check_ip($this->fixed_ip[$id]['ip'])) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$ipError = _("The IP address is invalid.");
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
elseif (!range::check_subnet_range($this->fixed_ip[$id]['ip'],
|
2009-11-24 21:37:36 +00:00
|
|
|
$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0],
|
|
|
|
$this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'))) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$ipError = _("The IP address does not match the subnet.");
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
elseif (!$this->overlapd_ip($this->fixed_ip[$id]['ip'])) {
|
2009-05-10 20:24:37 +00:00
|
|
|
$ipError = _("The IP address is already in use.");
|
|
|
|
}
|
|
|
|
$error = '';
|
|
|
|
if ($pcError != '') {
|
|
|
|
$error .= ' ' . $pcError;
|
|
|
|
}
|
|
|
|
if ($macError != '') {
|
|
|
|
$error .= ' ' . $macError;
|
|
|
|
}
|
|
|
|
if ($ipError != '') {
|
|
|
|
$error .= ' ' . $ipError;
|
|
|
|
}
|
2014-02-08 15:06:02 +00:00
|
|
|
if ($descriptionError != '') {
|
|
|
|
$error .= ' ' . $descriptionError;
|
|
|
|
}
|
|
|
|
$return->addElement(new htmlInputField('ip_'.$id, $this->fixed_ip[$id]['ip'], 20));
|
|
|
|
$pcInput = new htmlInputField('pc_'.$id, $this->fixed_ip[$id]['cn'], 20);
|
2014-01-28 20:00:47 +00:00
|
|
|
if (!empty($autoNames)) {
|
|
|
|
$pcInput->enableAutocompletion($autoNames);
|
|
|
|
}
|
|
|
|
$return->addElement($pcInput);
|
2014-02-08 15:06:02 +00:00
|
|
|
$return->addElement(new htmlInputField('mac_'.$id, $this->fixed_ip[$id]['mac'], 20));
|
|
|
|
$return->addElement(new htmlInputField('description_'.$id, $this->fixed_ip[$id]['description'], 20));
|
|
|
|
$return->addElement(new htmlInputCheckbox('active_'.$id, $this->fixed_ip[$id]['active']));
|
2010-09-18 11:37:22 +00:00
|
|
|
$return->addElement(new htmlButton('drop_ip_'.$id, 'del.png', true));
|
|
|
|
$return->addElement(new htmlOutputText($error), true);
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2010-09-18 11:37:22 +00:00
|
|
|
$return->addElement(new htmlSpacer(null, '10px'), true);
|
2014-02-08 15:06:02 +00:00
|
|
|
// add host
|
|
|
|
$return->addElement(new htmlInputField('ip_add', '', 20));
|
|
|
|
$newPCInput = new htmlInputField('pc_add', '', 20);
|
2014-01-28 20:00:47 +00:00
|
|
|
if (!empty($autoNames)) {
|
|
|
|
$newPCInput->enableAutocompletion($autoNames);
|
|
|
|
}
|
|
|
|
$return->addElement($newPCInput);
|
2014-02-08 15:06:02 +00:00
|
|
|
$return->addElement(new htmlInputField('mac_add', '', 20));
|
|
|
|
$return->addElement(new htmlInputField('description_add', '', 20));
|
2013-08-31 09:33:45 +00:00
|
|
|
$return->addElement(new htmlInputCheckbox('active_add', true));
|
2014-02-08 15:06:02 +00:00
|
|
|
$return->addElement(new htmlButton('add_ip', 'add.png', true), true);
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2014-02-08 15:06:02 +00:00
|
|
|
// add existing host entry
|
|
|
|
if (!empty($this->hostCache)) {
|
|
|
|
$return->addVerticalSpace('20px');
|
|
|
|
$addHostButton = new htmlAccountPageButton(get_class($this), 'addHost', 'add', _('Add existing host'));
|
|
|
|
$addHostButton->setIconClass('createButton');
|
|
|
|
$return->addElement($addHostButton , true);
|
|
|
|
}
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2014-02-08 15:06:02 +00:00
|
|
|
/**
|
|
|
|
* Returns the HTML meta data for the add host page.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2014-02-08 15:06:02 +00:00
|
|
|
* @return htmlElement HTML meta data
|
|
|
|
*/
|
|
|
|
public function display_html_addHost() {
|
|
|
|
$return = new htmlTable();
|
|
|
|
$this->initCache();
|
|
|
|
$hostNames = array();
|
|
|
|
$spacer = '####';
|
|
|
|
foreach ($this->hostCache as $host) {
|
|
|
|
if (!empty($host['cn'][0])) {
|
|
|
|
$val = $host['cn'][0];
|
|
|
|
if (!empty($host['iphostnumber'][0])) {
|
|
|
|
$val .= $spacer . $host['iphostnumber'][0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val .= $spacer;
|
|
|
|
}
|
|
|
|
if (!empty($host['macaddress'][0])) {
|
|
|
|
$val .= $spacer . $host['macaddress'][0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val .= $spacer;
|
|
|
|
}
|
|
|
|
$hostNames[$host['cn'][0]] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$select = new htmlTableExtendedSelect('host', $hostNames, array(), _('Host'));
|
|
|
|
$select->setHasDescriptiveElements(true);
|
|
|
|
$return->addElement($select, true);
|
|
|
|
$return->addVerticalSpace('20px');
|
|
|
|
$buttonContainer = new htmlTable();
|
|
|
|
$buttonContainer->colspan = 3;
|
|
|
|
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'addHost', _('Add')));
|
|
|
|
$buttonContainer->addElement(new htmlAccountPageButton(get_class($this), 'attributes', 'cancel', _('Cancel')));
|
|
|
|
$return->addElement($buttonContainer, true);
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes user input of the add host 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_addHost() {
|
|
|
|
$errors = array();
|
|
|
|
if (isset($_POST['form_subpage_fixed_ip_attributes_addHost'])) {
|
|
|
|
$val = explode('####', $_POST['host']);
|
|
|
|
$dhcpstatements = array();
|
|
|
|
$this->setActive($dhcpstatements, true);
|
|
|
|
$this->setIP($dhcpstatements, $val[1]);
|
|
|
|
$this->fixed_ip[] = array(
|
|
|
|
'cn' => $val[0],
|
|
|
|
'mac' => $val[2],
|
|
|
|
'description' => '',
|
|
|
|
'ip' => $val[1],
|
|
|
|
'dhcpstatements' => $dhcpstatements,
|
|
|
|
'active' => true,
|
|
|
|
);
|
|
|
|
$this->orderByIP();
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2010-06-12 17:17:31 +00:00
|
|
|
/**
|
2011-02-26 13:14:10 +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)
|
|
|
|
*/
|
2008-09-17 19:44:41 +00:00
|
|
|
public function save_attributes() {
|
|
|
|
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
/**
|
2009-05-21 16:33:50 +00:00
|
|
|
* This function is overwritten because the fixed IPs are set after the ldap_add command.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2009-05-21 16:33:50 +00:00
|
|
|
* @see baseModule::postModifyActions()
|
|
|
|
*
|
|
|
|
* @param boolean $newAccount
|
|
|
|
* @param array $attributes LDAP attributes of this entry
|
2012-01-04 19:08:19 +00:00
|
|
|
* @return array array which contains status messages. Each entry is an array containing the status message parameters.
|
2009-05-21 16:33:50 +00:00
|
|
|
*/
|
|
|
|
public function postModifyActions($newAccount, $attributes) {
|
2017-04-22 13:59:07 +00:00
|
|
|
if (!$this->isRootNode()) {
|
|
|
|
$ldapSuffix = ',cn=' . $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0] . ',' . $this->getAccountContainer()->get_type()->getSuffix();
|
2008-09-17 19:44:41 +00:00
|
|
|
$add = array();
|
2013-08-31 09:33:45 +00:00
|
|
|
$mod = array(); // DN => array(attr => values)
|
2008-09-17 19:44:41 +00:00
|
|
|
$delete = array();
|
|
|
|
// Which dns are to delete and to add
|
2013-08-31 09:33:45 +00:00
|
|
|
foreach($this->orig_ips AS $id => $arr) {
|
2008-09-17 19:44:41 +00:00
|
|
|
// Exist cn still?
|
|
|
|
$in_arr = false;
|
2013-08-31 09:33:45 +00:00
|
|
|
foreach($this->fixed_ip AS $idB => $arr) {
|
|
|
|
if ($this->orig_ips[$id]['cn'] == $this->fixed_ip[$idB]['cn']) {
|
2008-09-17 19:44:41 +00:00
|
|
|
$in_arr = true;
|
2009-11-25 12:08:08 +00:00
|
|
|
// check if IP changed
|
2013-08-31 09:33:45 +00:00
|
|
|
if($this->orig_ips[$id]['ip'] != $this->fixed_ip[$idB]['ip']) {
|
|
|
|
$this->setIP($this->fixed_ip[$idB]['dhcpstatements'], $this->fixed_ip[$idB]['ip']);
|
|
|
|
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpstatements'] = $this->fixed_ip[$idB]['dhcpstatements'];
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2014-02-08 15:06:02 +00:00
|
|
|
// check if active changed
|
|
|
|
if($this->orig_ips[$id]['active'] != $this->fixed_ip[$idB]['active']) {
|
|
|
|
$this->setActive($this->fixed_ip[$idB]['dhcpstatements'], $this->fixed_ip[$idB]['active']);
|
|
|
|
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpstatements'] = $this->fixed_ip[$idB]['dhcpstatements'];
|
|
|
|
}
|
2009-11-25 12:08:08 +00:00
|
|
|
// check if MAC changed
|
2014-02-08 15:06:02 +00:00
|
|
|
if($this->orig_ips[$id]['mac'] != $this->fixed_ip[$idB]['mac']) {
|
2013-08-31 09:33:45 +00:00
|
|
|
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpHWAddress'] = array('ethernet ' . $this->fixed_ip[$idB]['mac']);
|
2009-11-25 12:08:08 +00:00
|
|
|
}
|
2014-02-08 15:06:02 +00:00
|
|
|
// check if description changed
|
|
|
|
if($this->orig_ips[$id]['description'] != $this->fixed_ip[$idB]['description']) {
|
|
|
|
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpComments'][] = $this->fixed_ip[$idB]['description'];
|
|
|
|
}
|
2013-08-31 09:33:45 +00:00
|
|
|
break;
|
2009-11-25 12:08:08 +00:00
|
|
|
}
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
if (!$in_arr) {
|
|
|
|
$delete[] = $this->orig_ips[$id]['cn'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-25 12:08:08 +00:00
|
|
|
if (!is_array($this->fixed_ip)) {
|
2008-09-17 19:44:41 +00:00
|
|
|
$this->fixed_ip = array();
|
2009-11-25 12:08:08 +00:00
|
|
|
}
|
2008-09-17 19:44:41 +00:00
|
|
|
// Which entrys are new:
|
2013-08-31 09:33:45 +00:00
|
|
|
foreach($this->fixed_ip AS $id => $arr) {
|
2008-09-17 19:44:41 +00:00
|
|
|
$in_arr = false;
|
2013-08-31 09:33:45 +00:00
|
|
|
foreach($this->orig_ips AS $idB => $arr) {
|
|
|
|
if ($this->orig_ips[$idB]['cn'] == $this->fixed_ip[$id]['cn']) {
|
2008-09-17 19:44:41 +00:00
|
|
|
$in_arr = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$in_arr) {
|
|
|
|
$add[] = $this->fixed_ip[$id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-31 09:33:45 +00:00
|
|
|
foreach($delete AS $cn) {
|
|
|
|
ldap_delete($_SESSION['ldap']->server(), 'cn=' . $cn . $ldapSuffix);
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
|
2013-08-31 09:33:45 +00:00
|
|
|
foreach($add AS $id => $arr) {
|
2008-09-17 19:44:41 +00:00
|
|
|
$attr = array();
|
|
|
|
$attr['cn'] = $add[$id]['cn'];
|
|
|
|
$attr['objectClass'][0] = 'top';
|
|
|
|
$attr['objectClass'][1] = 'dhcpHost';
|
2009-11-25 12:08:08 +00:00
|
|
|
$attr['dhcpHWAddress'] = 'ethernet ' . $add[$id]['mac'];
|
2010-08-21 08:28:13 +00:00
|
|
|
if ($add[$id]['ip'] != '') {
|
2013-08-31 09:33:45 +00:00
|
|
|
$attr['dhcpStatements'][] = 'fixed-address ' . $add[$id]['ip'];
|
|
|
|
}
|
|
|
|
if ($add[$id]['active'] === false) {
|
|
|
|
$attr['dhcpStatements'][] = 'deny booting';
|
2010-08-21 08:28:13 +00:00
|
|
|
}
|
2009-11-25 12:08:08 +00:00
|
|
|
$attr['dhcpOption'] = 'host-name "' . $add[$id]['cn'] . '"';
|
2014-02-08 15:06:02 +00:00
|
|
|
if (!empty($arr['description'])) {
|
|
|
|
$attr['dhcpComments'][] = $arr['description'];
|
|
|
|
}
|
|
|
|
if ($attr['cn'] != "") {
|
2013-08-31 09:33:45 +00:00
|
|
|
ldap_add($_SESSION['ldap']->server(), 'cn=' . $add[$id]['cn'] . $ldapSuffix, $attr);
|
2014-02-08 15:06:02 +00:00
|
|
|
}
|
2013-08-31 09:33:45 +00:00
|
|
|
}
|
|
|
|
// entries to modify
|
|
|
|
foreach ($mod as $dn => $attrs) {
|
|
|
|
ldap_modify($_SESSION['ldap']->server(), $dn, $attrs);
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-04 19:08:19 +00:00
|
|
|
return array();
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2008-12-30 15:25:31 +00:00
|
|
|
|
|
|
|
/**
|
2017-02-19 08:14:11 +00:00
|
|
|
* {@inheritDoc}
|
|
|
|
* @see baseModule::get_pdfEntries()
|
2015-01-07 17:16:35 +00:00
|
|
|
*/
|
2017-04-01 07:57:03 +00:00
|
|
|
function get_pdfEntries($pdfKeys, $typeId) {
|
2008-12-30 15:25:31 +00:00
|
|
|
$return = array();
|
|
|
|
if (is_array($this->fixed_ip) && (sizeof($this->fixed_ip) > 0)) {
|
2015-07-11 09:50:00 +00:00
|
|
|
$pdfTable = new PDFTable();
|
|
|
|
$pdfRow = new PDFTableRow();
|
|
|
|
$pdfRow->cells[] = new PDFTableCell(_('PC name'), '20%', null, true);
|
|
|
|
$pdfRow->cells[] = new PDFTableCell(_('IP address'), '20%', null, true);
|
|
|
|
$pdfRow->cells[] = new PDFTableCell(_('MAC address'), '20%', null, true);
|
|
|
|
$pdfRow->cells[] = new PDFTableCell(_('Active'), '10%', null, true);
|
|
|
|
$pdfRow->cells[] = new PDFTableCell(_('Description'), '30%', null, true);
|
|
|
|
$pdfTable->rows[] = $pdfRow;
|
2008-12-30 15:25:31 +00:00
|
|
|
for ($i = 0; $i < sizeof($this->fixed_ip); $i++) {
|
|
|
|
$name = $this->fixed_ip[$i]['cn'];
|
|
|
|
$mac = $this->fixed_ip[$i]['mac'];
|
|
|
|
$ip = $this->fixed_ip[$i]['ip'];
|
2013-08-31 09:33:45 +00:00
|
|
|
$active = _('yes');
|
|
|
|
if (!$this->fixed_ip[$i]['active']) {
|
|
|
|
$active = _('no');
|
|
|
|
}
|
2014-02-08 15:06:02 +00:00
|
|
|
$description = $this->fixed_ip[$i]['description'];
|
2015-07-11 09:50:00 +00:00
|
|
|
$pdfRow = new PDFTableRow();
|
|
|
|
$pdfRow->cells[] = new PDFTableCell($name, '20%');
|
|
|
|
$pdfRow->cells[] = new PDFTableCell($ip, '20%');
|
|
|
|
$pdfRow->cells[] = new PDFTableCell($mac, '20%');
|
|
|
|
$pdfRow->cells[] = new PDFTableCell($active, '10%');
|
|
|
|
$pdfRow->cells[] = new PDFTableCell($description, '30%');
|
|
|
|
$pdfTable->rows[] = $pdfRow;
|
2013-08-31 09:33:45 +00:00
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
$this->addPDFTable($return, 'IPlist', $pdfTable);
|
2013-08-31 09:33:45 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2013-08-31 09:33:45 +00:00
|
|
|
/**
|
|
|
|
* Extracts the IP from a list of DHCP statements.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2013-08-31 09:33:45 +00:00
|
|
|
* @param array $dhcpStatements values of dhcpStatements attribute
|
|
|
|
*/
|
|
|
|
public static function extractIP($dhcpStatements) {
|
|
|
|
$return = null;
|
|
|
|
if (is_array($dhcpStatements)) {
|
|
|
|
for ($i = 0; $i < sizeof($dhcpStatements); $i++) {
|
|
|
|
if (strpos($dhcpStatements[$i], 'fixed-address ') === 0) {
|
|
|
|
$return = substr($dhcpStatements[$i], strlen('fixed-address') + 1);
|
|
|
|
break;
|
|
|
|
}
|
2008-12-30 15:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2013-08-31 09:33:45 +00:00
|
|
|
/**
|
|
|
|
* Sets the IP in a list of DHCP statements.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2013-08-31 09:33:45 +00:00
|
|
|
* @param array $dhcpStatements values of dhcpStatements attribute
|
|
|
|
* @param String $ip new IP
|
|
|
|
*/
|
|
|
|
private function setIP(&$dhcpStatements, $ip) {
|
|
|
|
for ($i = 0; $i < sizeof($dhcpStatements); $i++) {
|
|
|
|
if (strpos($dhcpStatements[$i], 'fixed-address ') === 0) {
|
|
|
|
unset($dhcpStatements[$i]);
|
|
|
|
$dhcpStatements = array_values($dhcpStatements);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($ip)) {
|
|
|
|
$dhcpStatements[] = 'fixed-address ' . $ip;
|
|
|
|
}
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2013-08-31 09:33:45 +00:00
|
|
|
/**
|
|
|
|
* Returns if this host is active.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2013-08-31 09:33:45 +00:00
|
|
|
* @param array $dhcpStatements values of dhcpStatements attribute
|
|
|
|
*/
|
|
|
|
public static function isActive($dhcpStatements) {
|
|
|
|
if (is_array($dhcpStatements)) {
|
|
|
|
for ($i = 0; $i < sizeof($dhcpStatements); $i++) {
|
|
|
|
if (strpos($dhcpStatements[$i], ' booting') === (strlen($dhcpStatements[$i]) - strlen(' booting'))) {
|
|
|
|
$val = substr($dhcpStatements[$i], 0, (strlen($dhcpStatements[$i]) - strlen(' booting')));
|
|
|
|
if ($val == 'deny') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2013-08-31 09:33:45 +00:00
|
|
|
/**
|
|
|
|
* Sets if this host is active.
|
2015-07-11 09:50:00 +00:00
|
|
|
*
|
2013-08-31 09:33:45 +00:00
|
|
|
* @param array $dhcpStatements values of dhcpStatements attribute
|
|
|
|
* @param boolean $active is active
|
|
|
|
*/
|
|
|
|
private function setActive(&$dhcpStatements, $active) {
|
|
|
|
for ($i = 0; $i < sizeof($dhcpStatements); $i++) {
|
2014-02-08 15:06:02 +00:00
|
|
|
if (strpos($dhcpStatements[$i], ' booting') !== false) {
|
2013-08-31 09:33:45 +00:00
|
|
|
unset($dhcpStatements[$i]);
|
|
|
|
$dhcpStatements = array_values($dhcpStatements);
|
|
|
|
}
|
|
|
|
}
|
2014-02-08 15:06:02 +00:00
|
|
|
if ($active) {
|
|
|
|
$dhcpStatements[] = 'allow booting';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dhcpStatements[] = 'deny booting';
|
2013-08-31 09:33:45 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2014-01-28 20:00:47 +00:00
|
|
|
/**
|
|
|
|
* Loads cached host data from LDAP.
|
|
|
|
*/
|
|
|
|
private function initCache() {
|
|
|
|
if ($this->hostCache != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$attrs = array('cn', 'iphostnumber', 'macaddress');
|
|
|
|
$this->hostCache = array();
|
|
|
|
$result = searchLDAPByAttribute('cn', '*', null, $attrs, array('host'));
|
|
|
|
foreach ($result as $attributes) {
|
|
|
|
$this->hostCache[] = $attributes;
|
|
|
|
}
|
|
|
|
}
|
2015-07-11 09:50:00 +00:00
|
|
|
|
2017-04-22 13:59:07 +00:00
|
|
|
/**
|
|
|
|
* Returns if the current DN is the root entry.
|
|
|
|
*
|
|
|
|
* @return bool is root
|
|
|
|
*/
|
|
|
|
private function isRootNode() {
|
|
|
|
$rootSuffix = $this->getAccountContainer()->get_type()->getSuffix();
|
|
|
|
return $this->getAccountContainer()->dn_orig == $rootSuffix;
|
|
|
|
}
|
|
|
|
|
2008-09-17 19:44:41 +00:00
|
|
|
}
|
2008-12-30 15:25:31 +00:00
|
|
|
|
|
|
|
?>
|