2003-12-12 00:52:35 +00:00
< ? php
/*
$Id $
This code is part of LDAP Account Manager ( http :// www . sourceforge . net / projects / lam )
Copyright ( C ) 2003 Tilo Lutz
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
*/
/*
* Variables in basearray which are no objects :
2003-12-27 11:21:00 +00:00
* type : Type of account . Can be user , group , host , domain
2003-12-12 00:52:35 +00:00
* attributes : List of all attributes , how to get them and are theiy required or optional
* dn : current DN without uid = or cn =
* dn_orig : old DN if account was loaded with uid = or cn =
*/
2003-12-27 11:21:00 +00:00
/* This class contains all account LDAP attributes
2003-12-12 00:52:35 +00:00
* and funtioncs required to deal with inetOrgPerson
* inetOrgPerson can only be created when it should be added
* to an array .
2003-12-27 11:21:00 +00:00
* $base is the name of account_container in session
2003-12-12 00:52:35 +00:00
*/
class inetOrgPerson {
// Constructor
2003-12-19 12:45:23 +00:00
function inetOrgPerson ( $base ) {
2003-12-27 11:21:00 +00:00
// Get local copy of name of account_container in session
$this -> base = $base ;
// Do some error checks
2003-12-19 12:45:23 +00:00
if ( ! $base ) trigger_error ( _ ( 'Please create a base object with $var = new accountContainer();' ), E_USER_ERROR );
if ( ! is_string ( $base )) trigger_error ( _ ( 'Please create a new module object with $accountContainer->add_objectClass(\'inetOrgPerson\');' ), E_USER_ERROR );
2003-12-27 11:21:00 +00:00
if ( $_SESSION [ $this -> base ] -> type != 'user' ) trigger_error ( _ ( 'inetOrgPerson can only be used for users.' ), E_USER_WARNING );
// load attribtues which are used in inetOrgPerson objectClass
2003-12-20 19:24:01 +00:00
$this -> attributes = $_SESSION [ $this -> base ] -> get_module_attributes ( 'inetOrgPerson' );
2003-12-27 11:21:00 +00:00
// Create copy of attributes
2003-12-12 18:21:15 +00:00
$this -> orig = $this -> attributes ;
2003-12-27 11:21:00 +00:00
// Add objectClass to attributes
2003-12-19 12:45:23 +00:00
$this -> attributes [ 'objectClass' ][ 0 ] = 'inetOrgPerson' ;
2003-12-27 11:21:00 +00:00
// Set aliasname
2003-12-12 00:52:35 +00:00
$this -> alias = _ ( 'inetOrgPerson' );
}
// Variables
// Alias Name. This name is shown in the menu instead of posixAccount
var $alias ;
2003-12-27 11:21:00 +00:00
// name of account_container in session so we can read other classes in account_container
2003-12-12 00:52:35 +00:00
var $base ;
2003-12-12 18:21:15 +00:00
// This variable contains all inetOrgPerson attributes
2003-12-12 11:52:52 +00:00
var $attributes ;
2003-12-12 00:52:35 +00:00
/* If an account was loaded all attributes are kept in this array
* to compare it with new changed attributes
*/
var $orig ;
2003-12-20 19:24:01 +00:00
2003-12-12 00:52:35 +00:00
/* This function returns a list with all required modules
*/
function dependencies () {
2003-12-15 15:11:44 +00:00
return array ( 'main' );
2003-12-12 00:52:35 +00:00
}
2003-12-27 11:21:00 +00:00
/* This function returns true if all required attributes from other
* modules are set . This is required to prevent undefined states
*/
2003-12-20 19:24:01 +00:00
function module_ready () {
return true ;
}
2003-12-27 11:21:00 +00:00
/* This function returns a list of all html - pages in module
* This is usefull for mass upload and pdf - files
* because lam can walk trough all pages itself and do some
* error checkings
*/
function pages () {
return array ( 'attributes' );
}
2003-12-12 00:52:35 +00:00
/* Write variables into object and do some regexp checks
*/
2003-12-19 12:45:23 +00:00
function proccess_attributes ( $post ) {
2003-12-12 00:52:35 +00:00
// Load attributes
2003-12-19 12:45:23 +00:00
$this -> attributes [ 'description' ][ 0 ] = $post [ 'form_inetOrgPerson_description' ];
$this -> attributes [ 'sn' ][ 0 ] = $post [ 'form_inetOrgPerson_sn' ];
$this -> attributes [ 'givenName' ][ 0 ] = $post [ 'form_inetOrgPerson_givenName' ];
$this -> attributes [ 'title' ][ 0 ] = $post [ 'form_inetOrgPerson_title' ];
$this -> attributes [ 'mail' ][ 0 ] = $post [ 'form_inetOrgPerson_mail' ];
$this -> attributes [ 'telephoneNumber' ][ 0 ] = $post [ 'form_inetOrgPerson_telephoneNumber' ];
$this -> attributes [ 'mobileTelephoneNumber' ][ 0 ] = $post [ 'form_inetOrgPerson_mobileTelephoneNumber' ];
$this -> attributes [ 'facsimileTelephoneNumber' ][ 0 ] = $post [ 'form_inetOrgPerson_facsimileTelephoneNumber' ];
$this -> attributes [ 'street' ][ 0 ] = $post [ 'form_inetOrgPerson_street' ];
$this -> attributes [ 'postalCode' ][ 0 ] = $post [ 'form_inetOrgPerson_postalCode' ];
$this -> attributes [ 'postalAddress' ][ 0 ] = $post [ 'form_inetOrgPerson_postalAddress' ];
$this -> attributes [ 'employeeType' ][ 0 ] = $post [ 'form_inetOrgPerson_employeeType' ];
2003-12-12 18:21:15 +00:00
2003-12-27 11:21:00 +00:00
// handle host-attribute in on epice because it's not set by default
2003-12-20 19:24:01 +00:00
if ( isset ( $this -> attributes [ 'host' ])) {
$host = $post [ 'form_inetOrgPerson_host' ];
if (( ! $host == '' ) && ! ereg ( '^([a-z]|[A-Z]|[0-9]|[.]|[-])+(([,])+([ ])*([a-z]|[A-Z]|[0-9]|[.]|[-])+)*$' , $host ))
2003-12-27 11:21:00 +00:00
$errors [] = array ( 'ERROR' , _ ( 'Unix workstations' ), _ ( 'Unix workstations is invalid.' ), 'host' );
2003-12-20 19:24:01 +00:00
$hosts = explode ( " " , $host );
$this -> attributes [ 'host' ] = array ();
foreach ( $hosts as $host )
if ( $host != " " ) $this -> attributes [ 'host' ][] = $host ;
}
2003-12-27 11:21:00 +00:00
// Do some regex-checks and return error if attributes are set to wrong values
if ( ! ereg ( '^([a-z]|[A-Z]|[-]|[ ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])+$' , $this -> attributes [ 'givenName' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Given name' ), _ ( 'Given name contains invalid characters' ), 'givenname' );
if ( ! ereg ( '^([a-z]|[A-Z]|[-]|[ ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])+$' , $this -> attributes [ 'sn' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Surname' ), _ ( 'Surname contains invalid characters' ), 'sn' );
if ( ! ereg ( '^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/]|[-])*$' , $this -> attributes [ 'telephoneNumber' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Telephone number' ), _ ( 'Please enter a valid telephone number!' ), 'telephoneNumber' );
if ( ! ereg ( '^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/]|[-])*$' , $this -> attributes [ 'mobileTelephoneNumber' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Mobile number' ), _ ( 'Please enter a valid mobile number!' ), 'mobileTelephoneNumber' );
if ( ! ereg ( '^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/]|[-])*$' , $this -> attributes [ 'facsimileTelephoneNumber' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Fax number' ), _ ( 'Please enter a valid fax number!' ), 'facsimileTelephoneNumber' );
if ( ! ereg ( '^(([0-9]|[A-Z]|[a-z]|[.]|[-]|[_])+[@]([0-9]|[A-Z]|[a-z]|[-])+([.]([0-9]|[A-Z]|[a-z]|[-])+)*)*$' , $this -> attributes [ 'mail' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'eMail address' ), _ ( 'Please enter a valid eMail address!' ), 'mail' );
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[-]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $this -> attributes [ 'street' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Street' ), _ ( 'Please enter a valid street name!' ), 'street' );
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $this -> attributes [ 'postalAddress' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Postal address' ), _ ( 'Please enter a valid postal address!' ), 'postalAdress' );
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[-]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $this -> attributes [ 'title' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Title' ), _ ( 'Please enter a valid title!' ), 'title' );
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ]|[<5B> ])*$' , $this -> attributes [ 'employeeType' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Employee type' ), _ ( 'Please enter a valid employee type!' ), 'employeeType' );
if ( ! ereg ( '^([0-9]|[A-Z]|[a-z])*$' , $this -> attributes [ 'personal_postalCode' ][ 0 ])) $errors [] = array ( 'ERROR' , _ ( 'Postal code' ), _ ( 'Please enter a valid postal code!' ), 'personal_postalCode' );
2003-12-12 00:52:35 +00:00
// Return error-messages
if ( is_array ( $errors )) return $errors ;
return 0 ;
}
/* This function loads all attributes into the object
* $attr is an array as it ' s retured from ldap_get_attributes
*/
function load_attributes ( $attr ) {
2003-12-12 18:21:15 +00:00
// unset count entries
unset ( $attr [ 'count' ]);
$attributes = array_keys ( $attr );
foreach ( $attributes as $attribute ) unset ( $attr [ $attribute ][ 'count' ]);
// unset double entries
for ( $i = 0 ; $i < count ( $attr ); $i ++ )
if ( isset ( $attr [ $i ])) unset ( $attr [ $i ]);
2003-12-27 11:21:00 +00:00
// load attribtues
2003-12-12 18:21:15 +00:00
foreach ( $attributes as $attribute ) {
2003-12-19 12:45:23 +00:00
if ( isset ( $this -> orig [ $attribute ])) {
$this -> orig [ $attribute ] = $attr [ $attribute ];
2003-12-12 18:21:15 +00:00
// decode as unicode
2003-12-19 12:45:23 +00:00
for ( $i = 0 ; $i < count ( $this -> orig [ $attribute ]); $i ++ ) $this -> orig [ $attribute ][ $i ] = utf8_decode ( $this -> orig [ $attribute ][ $i ]);
2003-12-12 18:21:15 +00:00
}
}
2003-12-27 11:21:00 +00:00
// Add objectClass to orig because we don't want to add objectClass if it's already set
2003-12-19 12:45:23 +00:00
$this -> orig [ 'objectClass' ][ 0 ] = 'inetOrgPerson' ;
2003-12-27 11:21:00 +00:00
// Values are kept as copy so we can compare old attributes with new attributes
2003-12-19 12:45:23 +00:00
$this -> attributes = $this -> orig ;
2003-12-12 18:21:15 +00:00
return 0 ;
2003-12-12 00:52:35 +00:00
}
2003-12-27 11:21:00 +00:00
/* This function returns an array with 4 entries :
* array ( DN1 ( 'add' => array ( $attr ), 'remove' => array ( $attr ), 'modify' => array ( $attr ), 'lamdaemon' => array ( cmds )), DN2 .... )
2003-12-12 00:52:35 +00:00
* 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
* add are attributes which have to be added to ldap entry
* remove are attributes which have to be removed from ldap entry
2003-12-27 11:21:00 +00:00
* lamdaemon are lamdaemon commands to modify homedir , quotas , ...
2003-12-12 00:52:35 +00:00
*/
function save_attributes () {
2003-12-27 11:21:00 +00:00
// Get easy attributes
2003-12-20 19:24:01 +00:00
$return = $_SESSION [ $this -> base ] -> save_module_attributes ( $this -> attributes , $this -> orig );
2003-12-27 11:21:00 +00:00
// unset password. First we hanlde userPassword with posixAccount, second we hanlde it completly separat
// because it en/decrypted in session
2003-12-20 21:42:52 +00:00
if ( isset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ]))
unset ( $return [ $_SESSION [ $this -> base ] -> dn ][ 'modify' ][ 'userPassword' ]);
2003-12-27 11:21:00 +00:00
// Return attributes
2003-12-15 15:11:44 +00:00
return $return ;
2003-12-12 00:52:35 +00:00
}
/* This function returns all ldap attributes
2003-12-12 18:21:15 +00:00
* which are part of inetOrgPerson and returns
2003-12-12 00:52:35 +00:00
* also their values .
*/
function get_attributes () {
2003-12-21 14:52:23 +00:00
return $this -> attributes ;
2003-12-12 00:52:35 +00:00
}
/* This function will create the html - page
* to show a page with all attributes .
* It will output a complete html - table
*/
2003-12-19 12:45:23 +00:00
function display_html_attributes ( $post ) {
2003-12-12 00:52:35 +00:00
2003-12-21 14:52:23 +00:00
echo " <table border=0 width= \" 100% \" > \n " ;
2003-12-12 00:52:35 +00:00
echo " <tr> \n " ;
2003-12-12 18:21:15 +00:00
echo " <td> " . _ ( 'Description' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_description \" type= \" text \" size= \" 30 \" maxlength= \" 255 \" value= \" " . $this -> attributes [ 'description' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=404 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
2003-12-12 00:52:35 +00:00
echo " </tr> \n " ;
2003-12-20 19:24:01 +00:00
if ( isset ( $this -> attributes [ 'host' ])) {
echo " <tr> \n " ;
echo " <td> " . _ ( 'Unix workstations' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_host \" type= \" text \" size= \" 20 \" maxlength= \" 80 \" value= \" " ;
if ( is_array ( $this -> attributes [ 'host' ]))
foreach ( $this -> attributes [ 'host' ] as $host ) echo $host . " " ;
echo " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=466 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
}
2003-12-12 18:21:15 +00:00
echo " <tr> \n " ;
echo " <td> " . _ ( 'Title' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_title \" type= \" text \" size= \" 10 \" maxlength= \" 10 \" value= \" " . $this -> attributes [ 'title' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=448 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'First name' ) . " *</td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_givenName \" type= \" text \" size= \" 20 \" maxlength= \" 20 \" value= \" " . $this -> attributes [ 'givenName' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=425 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Last name' ) . " *</td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_sn \" type= \" text \" size= \" 20 \" maxlength= \" 50 \" value= \" " . $this -> attributes [ 'sn' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=424 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Employee type' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_employeeType \" type= \" text \" size= \" 30 \" maxlength= \" 30 \" value= \" " . $this -> attributes [ 'employeeType' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=449 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Street' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_street \" type= \" text \" size= \" 30 \" maxlength= \" 50 \" value= \" " . $this -> attributes [ 'street' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=450 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Postal code' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_postalCode \" type= \" text \" size= \" 5 \" maxlength= \" 5 \" value= \" " . $this -> attributes [ 'postalCode' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=451 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Postal address' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_postalAddress \" type= \" text \" size= \" 30 \" maxlength= \" 80 \" value= \" " . $this -> attributes [ 'postalAddress' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=452 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Telephone number' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_telephoneNumber \" type= \" text \" size= \" 30 \" maxlength= \" 30 \" value= \" " . $this -> attributes [ 'telephoneNumber' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=453 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Mobile number' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_mobileTelephoneNumber \" type= \" text \" size= \" 30 \" maxlength= \" 30 \" value= \" " . $this -> attributes [ 'mobileTelephoneNumber' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=454 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'Fax number' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_facsimileTelephoneNumber \" type= \" text \" size= \" 30 \" maxlength= \" 30 \" value= \" " . $this -> attributes [ 'facsimileTelephoneNumber' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=455 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td> " . _ ( 'eMail address' ) . " </td> \n " ;
echo " <td><input name= \" form_inetOrgPerson_mail \" type= \" text \" size= \" 30 \" maxlength= \" 80 \" value= \" " . $this -> attributes [ 'mail' ][ 0 ] . " \" ></td> \n " ;
echo " <td><a href= \" ../help.php?HelpNumber=456 \" target= \" lamhelp \" > " . _ ( 'Help' ) . " </a></td> \n " ;
2003-12-12 00:52:35 +00:00
echo " </tr> \n " ;
echo " </table> \n " ;
return 0 ;
}
}
?>