2008-08-05 19:17:15 +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/)
|
2010-02-06 12:59:56 +00:00
|
|
|
Copyright (C) 2008 Thomas Manninger
|
|
|
|
2009 - 2010 Roland Gruber
|
2008-08-05 19:17:15 +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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The account type for DHCP
|
|
|
|
*
|
|
|
|
* @package types
|
|
|
|
* @author Thomas Manninger
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The account type for DHCP
|
|
|
|
*
|
|
|
|
* @package types
|
|
|
|
**/
|
|
|
|
|
|
|
|
class dhcp extends baseType {
|
2009-02-18 19:15:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new DHCP type object.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another DHCP entry');
|
|
|
|
$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to DHCP list');
|
|
|
|
}
|
|
|
|
|
2008-08-05 19:17:15 +00:00
|
|
|
/**
|
|
|
|
* Returns the alias name of this account type.
|
|
|
|
*
|
|
|
|
* @return string alias name
|
|
|
|
*/
|
|
|
|
public function getAlias() {
|
|
|
|
return _("DHCP");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the description of this account type.
|
|
|
|
*
|
|
|
|
* @return string description
|
|
|
|
*/
|
|
|
|
public function getDescription() {
|
|
|
|
return _("DHCP administration");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the class name for the list object.
|
|
|
|
*
|
|
|
|
* @return string class name
|
|
|
|
*/
|
|
|
|
public function getListClassName() {
|
|
|
|
return "lamDHCPList";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the default attribute list for this account type.
|
|
|
|
*
|
|
|
|
* @return string attribute list
|
|
|
|
*/
|
|
|
|
public function getDefaultListAttributes() {
|
|
|
|
return "#cn;#dhcpRange;#fixed_ips";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of attributes which have a translated description.
|
|
|
|
* This is used for the head row in the list view.
|
|
|
|
*
|
|
|
|
* @return array list of descriptions
|
|
|
|
*/
|
|
|
|
public function getListAttributeDescriptions() {
|
|
|
|
return array (
|
|
|
|
"cn" => ("Subnet"),
|
|
|
|
"dhcprange" => ("IP range"),
|
|
|
|
"fixed_ips" => ("Fixed IP address / MAC address / description")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the list view.
|
|
|
|
*
|
|
|
|
* @package lists
|
|
|
|
* @author Thomas Manninger
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class lamDHCPList extends lamList {
|
|
|
|
|
|
|
|
// A array with all fixed ips, mac adresses and descriptions
|
|
|
|
var $fixed;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $type account type
|
|
|
|
* @return lamList list object
|
|
|
|
*/
|
|
|
|
public function __construct($type) {
|
|
|
|
parent::__construct($type);
|
|
|
|
$this->labels = array(
|
|
|
|
'nav' => _("%s DHCP(s) found"),
|
|
|
|
'error_noneFound' => _("No DHCPs found!"),
|
|
|
|
'newEntry' => _("New DHCP"),
|
|
|
|
'dhcpDefaults' => _("DHCP settings"),
|
|
|
|
'deleteEntry' => _("Delete DHCP(s)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints the content of a cell in the account list for a given LDAP entry and attribute.
|
|
|
|
*
|
|
|
|
* @param array $entry LDAP attributes
|
|
|
|
* @param string $attribute attribute name
|
|
|
|
*/
|
|
|
|
public function listPrintTableCellContent(&$entry, &$attribute) {
|
2010-02-07 14:04:29 +00:00
|
|
|
// Fixed IPs
|
2008-08-05 19:17:15 +00:00
|
|
|
if ($attribute=="fixed_ips") {
|
|
|
|
// find all fixed addresses:
|
2010-02-07 14:04:29 +00:00
|
|
|
$entries = searchLDAP($entry['dn'], 'objectClass=dhcpHost', array('dhcpstatements', 'dhcphwaddress', 'cn'));
|
|
|
|
if (sizeof($entries) > 0) {
|
2009-01-10 17:36:31 +00:00
|
|
|
echo "<table border=\"0\" width=\"100%\">";
|
2010-02-07 14:04:29 +00:00
|
|
|
for ($i = 0; $i < sizeof($entries); $i++) {
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td width=\"25%\">".array_pop(explode(" ",$entries[$i]['dhcpstatements'][0]))."</td>";
|
|
|
|
echo "<td width=\"35%\">".array_pop(explode(" ",$entries[$i]['dhcphwaddress'][0]))."</td>";
|
|
|
|
echo "<td width=\"40%\">".$entries[$i]['cn'][0]."</td>";
|
|
|
|
echo "</tr>";
|
|
|
|
}
|
|
|
|
echo "</table>";
|
|
|
|
}
|
2008-08-05 19:17:15 +00:00
|
|
|
}
|
|
|
|
// fixed ip address
|
|
|
|
elseif ($attribute=="dhcpstatements") {
|
|
|
|
// Search after the fixed ip entry
|
|
|
|
if (is_array($entry['dhcpstatements'])) {
|
|
|
|
foreach($entry['dhcpstatements'] AS $id=>$value) {
|
|
|
|
|
|
|
|
if (!is_array($value) && array_shift( explode(" ", $value) ) == "fixed-address") {
|
|
|
|
$ip = explode(" ", $value);
|
|
|
|
echo $ip['1'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($attribute=="dhcprange") { // DHCP Range
|
|
|
|
if (is_array($entry['dhcprange'])) {
|
|
|
|
echo"<table cellspacing=\"0\">";
|
|
|
|
foreach($entry['dhcprange'] AS $id=>$value) {
|
|
|
|
if (!is_numeric($value)) {
|
|
|
|
$ex = explode(" ", $value);
|
|
|
|
echo "<tr><td>".$ex[0]."</td><td width=\"20\"><center>-</center></td><td>".$ex[1]."</td></tr>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo"</table>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parent::listPrintTableCellContent($entry, $attribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prints the create, delete and PDF buttons.
|
|
|
|
*
|
|
|
|
* @param boolean $createOnly true if only the create button should be displayed
|
|
|
|
*/
|
|
|
|
function listPrintButtons($createOnly) {
|
|
|
|
echo "<table border=0 width=\"100%\">\n";
|
|
|
|
echo "<tr>\n";
|
|
|
|
echo "<td align=\"left\">\n";
|
|
|
|
// add/delete/PDF buttons
|
|
|
|
echo ("<input class=\"" . $this->type . "\" type=\"submit\" name=\"new\" value=\"" . $this->labels['newEntry'] . "\">\n");
|
|
|
|
if (!$createOnly) {
|
|
|
|
echo ("<input class=\"" . $this->type . "\" type=\"submit\" name=\"del\" value=\"" . $this->labels['deleteEntry'] . "\">\n");
|
|
|
|
}
|
|
|
|
echo ("<input class=\"" . $this->type . "\" type=\"submit\" name=\"dhcpDefaults\" value=\"" . $this->labels['dhcpDefaults'] . "\">\n");
|
|
|
|
echo "</td>\n";
|
|
|
|
echo "<td align=\"right\">\n";
|
|
|
|
$this->listShowOUSelection();
|
|
|
|
echo "</td>\n";
|
|
|
|
echo "</tr>\n";
|
|
|
|
echo "</table>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages all POST actions (e.g. button pressed) for the account lists.
|
|
|
|
*/
|
|
|
|
function listDoPost() {
|
|
|
|
parent::listDoPost();
|
|
|
|
if (isset($_POST['dhcpDefaults'])) {
|
|
|
|
metaRefresh("../account/edit.php?type=dhcp&DN='".$_SESSION['config']->get_suffix('dhcp')."'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|