2006-01-01 16:30:05 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
2006-03-03 17:30:35 +00:00
|
|
|
Copyright (C) 2005 - 2006 Roland Gruber
|
2006-01-01 16:30:05 +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 user accounts (e.g. Unix, Samba and Kolab).
|
|
|
|
*
|
|
|
|
* @package types
|
|
|
|
* @author Roland Gruber
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The account type for user accounts (e.g. Unix, Samba and Kolab).
|
2006-02-07 16:05:37 +00:00
|
|
|
*
|
|
|
|
* @package types
|
2006-01-01 16:30:05 +00:00
|
|
|
*/
|
|
|
|
class user extends baseType {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the alias name of this account type.
|
|
|
|
*
|
|
|
|
* @return string alias name
|
|
|
|
*/
|
|
|
|
function getAlias() {
|
|
|
|
return _("Users");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the description of this account type.
|
|
|
|
*
|
|
|
|
* @return string description
|
|
|
|
*/
|
|
|
|
function getDescription() {
|
|
|
|
return _("User accounts (e.g. Unix, Samba and Kolab)");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the class name for the list object.
|
|
|
|
*
|
|
|
|
* @return string class name
|
|
|
|
*/
|
|
|
|
function getListClassName() {
|
|
|
|
return "lamUserList";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the default attribute list for this account type.
|
|
|
|
*
|
|
|
|
* @return string attribute list
|
|
|
|
*/
|
|
|
|
function getDefaultListAttributes() {
|
|
|
|
return "#uid;#givenName;#sn;#uidNumber;#gidNumber";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
function getListAttributeDescriptions() {
|
|
|
|
return array (
|
|
|
|
"uid" => _("User ID"),
|
|
|
|
"uidnumber" => _("UID number"),
|
|
|
|
"gidnumber" => _("GID number"),
|
|
|
|
"cn" => _("User name"),
|
|
|
|
"host" => _("Allowed hosts"),
|
|
|
|
"givenname" => _("First name"),
|
|
|
|
"sn" => _("Last name"),
|
|
|
|
"homedirectory" => _("Home directory"),
|
|
|
|
"loginshell" => _("Login shell"),
|
|
|
|
"mail" => _("E-Mail"),
|
2007-02-17 16:26:08 +00:00
|
|
|
"gecos" => _("Description"),
|
|
|
|
"jpegphoto" => _('Photo')
|
2006-01-01 16:30:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the list view.
|
|
|
|
*
|
|
|
|
* @package lists
|
|
|
|
* @author Roland Gruber
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class lamUserList extends lamList {
|
|
|
|
|
|
|
|
/** Controls if GID number is translated to group name */
|
2007-10-13 17:28:37 +00:00
|
|
|
private $trans_primary = false;
|
2006-01-01 16:30:05 +00:00
|
|
|
|
|
|
|
/** translates GID to group name */
|
2007-10-13 17:28:37 +00:00
|
|
|
private $trans_primary_hash = array();
|
2006-01-01 16:30:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $type account type
|
|
|
|
* @return lamList list object
|
|
|
|
*/
|
|
|
|
function lamUserList($type) {
|
|
|
|
parent::lamList($type);
|
|
|
|
$this->labels = array(
|
|
|
|
'nav' => _("%s user(s) found"),
|
|
|
|
'error_noneFound' => _("No users found!"),
|
|
|
|
'newEntry' => _("New user"),
|
2007-02-17 16:26:08 +00:00
|
|
|
'deleteEntry' => _("Delete user(s)"),
|
2006-01-01 16:30:05 +00:00
|
|
|
'createPDF' => _("Create PDF for selected user(s)"),
|
|
|
|
'createPDFAll' => _("Create PDF for all users"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages all POST actions (e.g. button pressed) for the account lists.
|
|
|
|
*/
|
|
|
|
function listDoPost() {
|
2006-04-27 14:26:43 +00:00
|
|
|
parent::listDoPost();
|
2006-01-01 16:30:05 +00:00
|
|
|
// check if primary group should be translated
|
|
|
|
if (isset($_POST['apply_trans_primary'])) {
|
|
|
|
$this->trans_primary = $_POST['trans_primary'];
|
|
|
|
}
|
2007-06-01 17:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets some internal parameters.
|
|
|
|
*/
|
|
|
|
function listGetParams() {
|
|
|
|
parent::listGetParams();
|
2006-01-01 16:30:05 +00:00
|
|
|
// generate hash table for group translation
|
2007-06-01 17:25:07 +00:00
|
|
|
if ($this->trans_primary == "on" && !$this->refresh && (sizeof($this->trans_primary_hash) == 0)) {
|
|
|
|
$this->refreshPrimaryGroupTranslation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rereads the entries from LDAP.
|
|
|
|
*/
|
|
|
|
function listRefreshData() {
|
|
|
|
parent::listRefreshData();
|
|
|
|
if ($this->trans_primary == "on") {
|
|
|
|
$this->refreshPrimaryGroupTranslation();
|
2006-01-01 16:30:05 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-01 17:25:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Refreshes the GID to group name cache.
|
|
|
|
*/
|
|
|
|
function refreshPrimaryGroupTranslation() {
|
|
|
|
$this->trans_primary_hash = array();
|
|
|
|
$grp_suffix = $_SESSION['config']->get_Suffix('group');
|
|
|
|
$filter = "objectClass=posixGroup";
|
|
|
|
$attrs = array("cn", "gidNumber");
|
|
|
|
$sr = @ldap_search($_SESSION["ldap"]->server(), $grp_suffix, $filter, $attrs);
|
|
|
|
if ($sr) {
|
|
|
|
$info = @ldap_get_entries($_SESSION["ldap"]->server(), $sr);
|
|
|
|
unset($info['count']); // delete count entry
|
|
|
|
for ($i = 0; $i < sizeof($info); $i++) {
|
|
|
|
$this->trans_primary_hash[$info[$i]['gidnumber'][0]] = $info[$i]['cn'][0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-01 16:30:05 +00:00
|
|
|
|
|
|
|
/**
|
2007-02-17 16:26:08 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
function listPrintTableCellContent(&$entry, &$attribute) {
|
|
|
|
// check if there is something to display at all
|
2007-10-05 18:09:49 +00:00
|
|
|
if (!isset($entry[$attribute]) || !is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1)) return;
|
2007-02-17 16:26:08 +00:00
|
|
|
if (isset($entry[$attribute]['count'])) unset($entry[$attribute]['count']);
|
|
|
|
// translate GID to group name
|
|
|
|
if (($attribute == "gidnumber") && ($this->trans_primary == "on")) {
|
|
|
|
if (isset($this->trans_primary_hash[$entry[$attribute][0]])) {
|
|
|
|
echo $this->trans_primary_hash[$entry[$attribute][0]];
|
2006-01-01 16:30:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-02-17 16:26:08 +00:00
|
|
|
parent::listPrintTableCellContent($entry, $attribute);
|
2006-01-01 16:30:05 +00:00
|
|
|
}
|
2007-02-17 16:26:08 +00:00
|
|
|
}
|
|
|
|
// show user photos
|
|
|
|
elseif ($attribute == "jpegphoto") {
|
|
|
|
if (sizeof($entry[$attribute][0]) < 100) {
|
|
|
|
// looks like we have read broken binary data, reread photo
|
2007-02-18 18:35:25 +00:00
|
|
|
$result = @ldap_search($_SESSION['ldap']->server(), $entry['dn'], $attribute . "=*", array($attribute));
|
2007-02-17 16:26:08 +00:00
|
|
|
if ($result) {
|
|
|
|
$tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
|
2007-02-18 18:35:25 +00:00
|
|
|
if ($tempEntry) {
|
|
|
|
$binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute);
|
|
|
|
if (isset($binData['count'])) unset($binData['count']);
|
|
|
|
$entry[$attribute] = $binData;
|
|
|
|
}
|
2006-01-01 16:30:05 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-17 16:26:08 +00:00
|
|
|
$jpeg_filename = 'jpg' . $_SESSION['ldap']->new_rand() . '.jpg';
|
|
|
|
$outjpeg = @fopen($_SESSION['lampath'] . 'tmp/' . $jpeg_filename, "wb");
|
|
|
|
fwrite($outjpeg, $entry[$attribute][0]);
|
|
|
|
fclose ($outjpeg);
|
|
|
|
$photoFile = '../../tmp/' . $jpeg_filename;
|
|
|
|
echo "<img src=\"" . $photoFile . "\" alt=\"" . _('Photo') . "\">";
|
|
|
|
}
|
|
|
|
// print all other attributes
|
|
|
|
else {
|
|
|
|
parent::listPrintTableCellContent($entry, $attribute);
|
2006-01-01 16:30:05 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-17 16:26:08 +00:00
|
|
|
|
2006-01-01 16:30:05 +00:00
|
|
|
/**
|
2007-02-11 18:06:42 +00:00
|
|
|
* Prints additional option fields for specific object types.
|
2006-01-01 16:30:05 +00:00
|
|
|
*/
|
2007-02-11 18:06:42 +00:00
|
|
|
function listPrintAdditionalOptions() {
|
2006-01-01 16:30:05 +00:00
|
|
|
// show translate GID to group name box if there is a column with gidnumber
|
|
|
|
if (in_array("gidnumber", $this->attrArray)) {
|
|
|
|
echo "<p align=\"left\">\n";
|
|
|
|
echo "<b>" . _("Translate GID number to group name") . ": </b>";
|
|
|
|
if ($this->trans_primary == "on") {
|
2007-02-11 14:23:44 +00:00
|
|
|
echo "<input class=\"" . $this->type . "\" type=\"checkbox\" name=\"trans_primary\" checked>";
|
2006-01-01 16:30:05 +00:00
|
|
|
}
|
2007-02-11 14:23:44 +00:00
|
|
|
else echo "<input class=\"" . $this->type . "\" type=\"checkbox\" name=\"trans_primary\">";
|
|
|
|
echo (" <input class=\"" . $this->type . "\" type=\"submit\" name=\"apply_trans_primary\" value=\"" . _("Apply") . "\">");
|
2006-01-01 16:30:05 +00:00
|
|
|
echo "</p>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|