2009-01-31 10:14:27 +00:00
< ? php
2017-02-18 09:13:08 +00:00
use \LAM\PDF\PDFTable ;
use \LAM\PDF\PDFTableCell ;
use \LAM\PDF\PDFTableRow ;
2009-01-31 10:14:27 +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 / )
2017-02-18 09:13:08 +00:00
Copyright ( C ) 2009 - 2017 Roland Gruber
2009-01-31 10:14:27 +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 entries based on the object class nisNetgroup .
*
* @ package modules
* @ author Roland Gruber
*/
/**
* Manages entries based on the object class nisNetgroup .
*
* @ package modules
*/
class nisnetgroup extends baseModule {
2015-07-11 09:50:00 +00:00
2010-11-20 19:19:03 +00:00
/* caches to reduce LDAP queries */
2012-07-15 12:05:47 +00:00
/** user cache */
2010-11-20 19:19:03 +00:00
private $cachedUserList = null ;
2012-07-15 12:05:47 +00:00
/** host cache */
2010-11-20 19:19:03 +00:00
private $cachedHostList = null ;
2012-07-15 12:05:47 +00:00
/** group cache */
2010-11-20 19:19:03 +00:00
private $cachedGroupList = null ;
2015-07-11 09:50:00 +00:00
2014-04-20 13:00:42 +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 13:00:42 +00:00
* @ return boolean true if module fits
*/
public function can_manage () {
return in_array ( $this -> get_scope (), array ( 'netgroup' ));
}
2009-01-31 10:14:27 +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
*
2009-01-31 10:14:27 +00:00
* @ see baseModule :: get_metaData ()
*/
function get_metaData () {
$return = array ();
// icon
$return [ 'icon' ] = 'groupBig.png' ;
// alias name
$return [ " alias " ] = _ ( " NIS net group " );
// this is a base module
$return [ " is_base " ] = true ;
// LDAP filter
$return [ " ldap_filter " ] = array ( 'or' => " (objectClass=nisNetgroup) " );
// RDN attributes
$return [ " RDN " ] = array ( " cn " => " normal " );
// module dependencies
$return [ 'dependencies' ] = array ( 'depends' => array (), 'conflicts' => array ());
// managed object classes
$return [ 'objectClasses' ] = array ( 'nisNetgroup' );
// managed attributes
$return [ 'attributes' ] = array ( 'cn' , 'description' , 'memberNisNetgroup' , 'nisNetgroupTriple' );
// help Entries
$return [ 'help' ] = array (
'cn' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Group name " ), 'attr' => 'cn' ,
2009-01-31 10:14:27 +00:00
" Text " => _ ( " This is the name of this group. " )
),
'description' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Description " ), 'attr' => 'description' ,
2009-01-31 10:14:27 +00:00
" Text " => _ ( " Here you can enter a description for this group. " )
),
'memberNisNetgroup' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Subgroups " ), 'attr' => 'memberNisNetgroup' ,
2009-01-31 10:14:27 +00:00
" Text " => _ ( " Here you can specify subgroups which are included in this NIS netgroup. All members of the subgroups will be treated as members of this group. " )
2009-02-01 18:57:56 +00:00
),
'members' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Members " ), 'attr' => 'nisNetgroupTriple' ,
2009-02-01 19:04:52 +00:00
" Text " => _ ( " These entries specify the members of the netgroup. You can limit the set to a host name, a user name, a domain name or any combination of them. " )
2009-02-01 18:57:56 +00:00
),
'membersUpload' => array (
2012-02-04 15:56:31 +00:00
" Headline " => _ ( " Members " ), 'attr' => 'nisNetgroupTriple' ,
2009-02-01 19:04:52 +00:00
" Text " => _ ( " These entries specify the members of the netgroup. You can limit the set to a host name, a user name, a domain name or any combination of them. " ) . ' ' .
2009-02-01 18:57:56 +00:00
_ ( " For the upload please specify the entries in the format \" (HOST,USER,DOMAIN) \" . Multiple entries are separated by semicolon. " )
2009-02-04 17:29:13 +00:00
),
'filter' => array (
" Headline " => _ ( " Filter " ),
" Text " => _ ( " Here you can enter a filter value. Only entries which contain the filter text will be shown. " )
2009-01-31 10:14:27 +00:00
)
);
// upload fields
$return [ 'upload_columns' ] = array (
array (
'name' => 'nisnetgroup_cn' ,
'description' => _ ( 'Group name' ),
'help' => 'cn' ,
'example' => _ ( 'adminstrators' ),
'required' => true ,
'unique' => true
),
array (
'name' => 'nisnetgroup_description' ,
'description' => _ ( 'Group description' ),
'help' => 'description' ,
'example' => _ ( 'Administrators group' )
),
array (
'name' => 'nisnetgroup_subgroups' ,
'description' => _ ( 'Subgroups' ),
'help' => 'memberNisNetgroup' ,
'example' => _ ( 'group01,group02' )
2009-02-01 18:57:56 +00:00
),
array (
'name' => 'nisnetgroup_members' ,
'description' => _ ( 'Members' ),
'help' => 'membersUpload' ,
'example' => _ ( '(host1,user1,example.com);(host2,user2,example.com)' )
2009-01-31 10:14:27 +00:00
)
);
// available PDF fields
$return [ 'PDF_fields' ] = array (
2010-04-05 12:38:23 +00:00
'cn' => _ ( 'Group name' ),
'description' => _ ( 'Description' ),
'subgroups' => _ ( 'Subgroups' ),
'members' => _ ( 'Members' )
2009-01-31 10:14:27 +00:00
);
return $return ;
}
/**
* This function fills the $messages variable with output messages from this module .
*/
function load_Messages () {
$this -> messages [ 'cn' ][ 0 ] = array ( 'ERROR' , _ ( 'Group name' ), _ ( 'Group name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'user' ][ 0 ] = array ( 'ERROR' , _ ( 'User name' ), _ ( 'User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'host' ][ 0 ] = array ( 'ERROR' , _ ( 'Host name' ), _ ( 'Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !' ));
$this -> messages [ 'domain' ][ 0 ] = array ( 'ERROR' , _ ( 'Domain name' ), _ ( 'Domain name is invalid!' ));
}
2009-01-31 14:58:58 +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
2011-02-26 13:14:10 +00:00
* < br > " info " are values with informational value ( e . g . to be used later by pre / postModify actions )
2009-01-31 14:58:58 +00:00
*/
function save_attributes () {
$return = $this -> getAccountContainer () -> save_module_attributes ( $this -> attributes , $this -> orig );
// nisNetgroupTriple needs special changing
2011-10-15 09:46:13 +00:00
if ( isset ( $return [ $this -> getAccountContainer () -> dn_orig ][ 'remove' ][ 'nisNetgroupTriple' ])) {
$return [ $this -> getAccountContainer () -> dn_orig ][ 'modify' ][ 'nisNetgroupTriple' ] = $this -> attributes [ 'nisNetgroupTriple' ];
unset ( $return [ $this -> getAccountContainer () -> dn_orig ][ 'remove' ][ 'nisNetgroupTriple' ]);
2009-01-31 14:58:58 +00:00
}
2011-10-15 09:46:13 +00:00
if ( isset ( $return [ $this -> getAccountContainer () -> dn_orig ][ 'add' ][ 'nisNetgroupTriple' ])) {
$return [ $this -> getAccountContainer () -> dn_orig ][ 'modify' ][ 'nisNetgroupTriple' ] = $this -> attributes [ 'nisNetgroupTriple' ];
unset ( $return [ $this -> getAccountContainer () -> dn_orig ][ 'add' ][ 'nisNetgroupTriple' ]);
2009-01-31 14:58:58 +00:00
}
return $return ;
}
2009-01-31 10:14:27 +00:00
/**
* Returns the HTML meta data for the main account page .
2015-07-11 09:50:00 +00:00
*
2010-09-21 17:57:04 +00:00
* @ return htmlElement HTML meta data
2009-01-31 10:14:27 +00:00
*/
function display_html_attributes () {
2010-09-21 17:57:04 +00:00
$return = new htmlTable ();
2009-01-31 10:14:27 +00:00
// user name
$groupName = '' ;
if ( isset ( $this -> attributes [ 'cn' ][ 0 ])) $groupName = $this -> attributes [ 'cn' ][ 0 ];
2010-09-21 17:57:04 +00:00
$nameInput = new htmlTableExtendedInputField ( _ ( " Group name " ), 'cn' , $groupName , 'cn' );
$nameInput -> setRequired ( true );
$nameInput -> setFieldMaxLength ( 20 );
$return -> addElement ( $nameInput , true );
2010-05-19 19:22:29 +00:00
$description = '' ;
if ( isset ( $this -> attributes [ 'description' ][ 0 ])) $description = $this -> attributes [ 'description' ][ 0 ];
2010-09-21 17:57:04 +00:00
$return -> addElement ( new htmlTableExtendedInputField ( _ ( 'Description' ), 'description' , $description , 'description' ), true );
$subgroupsContainer = new htmlTable ();
2009-02-03 19:54:57 +00:00
if ( isset ( $this -> attributes [ 'memberNisNetgroup' ]) && is_array ( $this -> attributes [ 'memberNisNetgroup' ])) {
$membergroups = $this -> attributes [ 'memberNisNetgroup' ];
while ( sizeof ( $membergroups ) > 0 ) {
$parts = array_splice ( $membergroups , 0 , 8 );
2010-09-21 17:57:04 +00:00
$subgroupsContainer -> addElement ( new htmlOutputText ( implode ( ', ' , $parts )), true );
2009-02-03 19:54:57 +00:00
}
}
2010-09-21 17:57:04 +00:00
$subgroupsContainer -> addElement ( new htmlAccountPageButton ( get_class ( $this ), 'group' , 'open' , _ ( 'Edit subgroups' )));
$subgroupsLabel = new htmlOutputText ( _ ( 'Subgroups' ));
$subgroupsLabel -> alignment = htmlElement :: ALIGN_TOP ;
$return -> addElement ( $subgroupsLabel );
$return -> addElement ( $subgroupsContainer );
$return -> addElement ( new htmlHelpLink ( 'memberNisNetgroup' ), true );
$return -> addElement ( new htmlSpacer ( null , '10px' ), true );
2009-01-31 10:14:27 +00:00
// members
2010-09-21 17:57:04 +00:00
$memberTable = new htmlTable ();
$hostLabel = new htmlOutputText ( _ ( 'Host' ));
$hostLabel -> colspan = 2 ;
$memberTable -> addElement ( $hostLabel );
$userLabel = new htmlOutputText ( _ ( 'User' ));
$userLabel -> colspan = 2 ;
$memberTable -> addElement ( $userLabel );
$memberTable -> addElement ( new htmlOutputText ( _ ( 'Domain' )));
$memberTable -> addElement ( new htmlSpacer ( '5px' , null ));
$memberTable -> addElement ( new htmlHelpLink ( 'members' ), true );
2009-01-31 10:14:27 +00:00
if ( isset ( $this -> attributes [ 'nisNetgroupTriple' ]) && ( sizeof ( $this -> attributes [ 'nisNetgroupTriple' ]) > 0 )) {
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'nisNetgroupTriple' ]); $i ++ ) {
$triple = substr ( $this -> attributes [ 'nisNetgroupTriple' ][ $i ], 1 , strlen ( $this -> attributes [ 'nisNetgroupTriple' ][ $i ]) - 2 );
$triple = explode ( ',' , $triple );
2010-10-02 10:41:26 +00:00
if ( isset ( $_POST [ 'form_subpage_nisnetgroup_attributes_select' ]) && ( $_POST [ 'type' ] == 'host' ) && ( $_POST [ 'position' ] == strval ( $i ))) {
2009-01-31 14:58:58 +00:00
$triple [ 0 ] = $_POST [ 'selectBox' ];
}
2010-10-02 10:41:26 +00:00
if ( isset ( $_POST [ 'form_subpage_nisnetgroup_attributes_select' ]) && ( $_POST [ 'type' ] == 'user' ) && ( $_POST [ 'position' ] == strval ( $i ))) {
2009-01-31 14:58:58 +00:00
$triple [ 1 ] = $_POST [ 'selectBox' ];
}
2010-09-21 17:57:04 +00:00
$hostField = new htmlInputField ( 'host_' . $i , $triple [ 0 ]);
$hostField -> setFieldSize ( 20 );
$memberTable -> addElement ( $hostField );
$hostButton = new htmlAccountPageButton ( get_class ( $this ), 'select' , 'host' . $i , 'host.png' , true );
$hostButton -> setTitle ( _ ( 'Select host' ));
$memberTable -> addElement ( $hostButton );
$userField = new htmlInputField ( 'user_' . $i , $triple [ 1 ]);
$userField -> setFieldSize ( 20 );
$memberTable -> addElement ( $userField );
$userButton = new htmlAccountPageButton ( get_class ( $this ), 'select' , 'user' . $i , 'user.png' , true );
$userButton -> setTitle ( _ ( 'Select user' ));
$memberTable -> addElement ( $userButton );
$domainField = new htmlInputField ( 'domain_' . $i , $triple [ 2 ]);
$domainField -> setFieldSize ( 20 );
$memberTable -> addElement ( $domainField );
$memberTable -> addElement ( new htmlSpacer ( '5px' , null ));
$delButton = new htmlButton ( 'del_' . $i , 'del.png' , true );
$delButton -> setTitle ( _ ( 'Delete' ));
$memberTable -> addElement ( $delButton );
$memberTable -> addNewLine ();
2009-01-31 10:14:27 +00:00
}
}
2010-09-21 17:57:04 +00:00
$memberTable -> addElement ( new htmlSpacer ( null , '10px' ), true );
2009-01-31 10:14:27 +00:00
$hostNew = '' ;
$userNew = '' ;
$domainNew = '' ;
if ( isset ( $_POST [ 'host_new' ])) $hostNew = $_POST [ 'host_new' ];
if ( isset ( $_POST [ 'user_new' ])) $userNew = $_POST [ 'user_new' ];
if ( isset ( $_POST [ 'domain_new' ])) $domainNew = $_POST [ 'domain_new' ];
2010-09-21 17:57:04 +00:00
$hostField = new htmlInputField ( 'host_new' , $hostNew );
$hostField -> setFieldSize ( 20 );
$memberTable -> addElement ( $hostField );
$hostButton = new htmlAccountPageButton ( get_class ( $this ), 'select' , 'hostNew' , 'host.png' , true );
$hostButton -> setTitle ( _ ( 'Select host' ));
$memberTable -> addElement ( $hostButton );
$userField = new htmlInputField ( 'user_new' , $userNew );
$userField -> setFieldSize ( 20 );
$memberTable -> addElement ( $userField );
$userButton = new htmlAccountPageButton ( get_class ( $this ), 'select' , 'userNew' , 'user.png' , true );
$userButton -> setTitle ( _ ( 'Select user' ));
$memberTable -> addElement ( $userButton );
$domainField = new htmlInputField ( 'domain_new' , $domainNew );
$domainField -> setFieldSize ( 20 );
$memberTable -> addElement ( $domainField );
$memberTable -> addElement ( new htmlSpacer ( '5px' , null ));
$addButton = new htmlButton ( 'add_new' , 'add.png' , true );
$addButton -> setTitle ( _ ( 'Add' ));
$memberTable -> addElement ( $addButton );
$memberTable -> colspan = 2 ;
2015-07-11 09:50:00 +00:00
2010-09-21 17:57:04 +00:00
$membersLabel = new htmlOutputText ( _ ( 'Members' ));
$membersLabel -> alignment = htmlElement :: ALIGN_TOP ;
$return -> addElement ( $membersLabel );
$return -> addElement ( $memberTable );
2009-01-31 10:14:27 +00:00
return $return ;
}
/**
* 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
*/
function process_attributes () {
$errors = array ();
// user name
$this -> attributes [ 'cn' ][ 0 ] = $_POST [ 'cn' ];
if ( ! get_preg ( $this -> attributes [ 'cn' ][ 0 ], 'groupname' )) {
$errors [] = $this -> messages [ 'cn' ][ 0 ];
}
// description
$this -> attributes [ 'description' ][ 0 ] = $_POST [ 'description' ];
// members
$this -> attributes [ 'nisNetgroupTriple' ] = array ();
$i = 0 ;
while ( isset ( $_POST [ 'host_' . $i ]) || isset ( $_POST [ 'user_' . $i ]) || isset ( $_POST [ 'domain_' . $i ])) {
2009-01-31 14:58:58 +00:00
if ( isset ( $_POST [ 'del_' . $i ])) {
$i ++ ;
continue ;
}
2009-01-31 10:14:27 +00:00
// build NIS triple
$this -> attributes [ 'nisNetgroupTriple' ][] = '(' . $_POST [ 'host_' . $i ] . ',' . $_POST [ 'user_' . $i ] . ',' . $_POST [ 'domain_' . $i ] . ')' ;
// check user input
if (( $_POST [ 'host_' . $i ] != '' ) && ! get_preg ( $_POST [ 'host_' . $i ], 'DNSname' )) {
$message = $this -> messages [ 'host' ][ 0 ];
$message [ 2 ] = $message [ 2 ] . '<br><br>' . $_POST [ 'host_' . $i ];
$errors [] = $message ;
}
if (( $_POST [ 'user_' . $i ] != '' ) && ! get_preg ( $_POST [ 'user_' . $i ], 'username' )) {
$message = $this -> messages [ 'user' ][ 0 ];
$message [ 2 ] = $message [ 2 ] . '<br><br>' . $_POST [ 'user_' . $i ];
$errors [] = $message ;
}
if (( $_POST [ 'domain_' . $i ] != '' ) && ! get_preg ( $_POST [ 'domain_' . $i ], 'DNSname' )) {
$message = $this -> messages [ 'domain' ][ 0 ];
$message [ 2 ] = $message [ 2 ] . '<br><br>' . $_POST [ 'domain_' . $i ];
$errors [] = $message ;
}
$i ++ ;
}
2009-01-31 14:58:58 +00:00
$addNewTriple = isset ( $_POST [ 'add_new' ]);
2009-01-31 10:14:27 +00:00
// check user input
if (( $_POST [ 'host_new' ] != '' ) && ! get_preg ( $_POST [ 'host_new' ], 'DNSname' )) {
$message = $this -> messages [ 'host' ][ 0 ];
$message [ 2 ] = $message [ 2 ] . '<br><br>' . $_POST [ 'host_new' ];
$errors [] = $message ;
2009-01-31 14:58:58 +00:00
$addNewTriple = false ;
2009-01-31 10:14:27 +00:00
}
if (( $_POST [ 'user_new' ] != '' ) && ! get_preg ( $_POST [ 'user_new' ], 'username' )) {
$message = $this -> messages [ 'user' ][ 0 ];
$message [ 2 ] = $message [ 2 ] . '<br><br>' . $_POST [ 'user_new' ];
$errors [] = $message ;
2009-01-31 14:58:58 +00:00
$addNewTriple = false ;
2009-01-31 10:14:27 +00:00
}
if (( $_POST [ 'domain_new' ] != '' ) && ! get_preg ( $_POST [ 'domain_new' ], 'DNSname' )) {
$message = $this -> messages [ 'domain' ][ 0 ];
$message [ 2 ] = $message [ 2 ] . '<br><br>' . $_POST [ 'domain_new' ];
$errors [] = $message ;
2009-01-31 14:58:58 +00:00
$addNewTriple = false ;
}
if ( $addNewTriple ) {
$this -> attributes [ 'nisNetgroupTriple' ][] = '(' . $_POST [ 'host_new' ] . ',' . $_POST [ 'user_new' ] . ',' . $_POST [ 'domain_new' ] . ')' ;
unset ( $_POST [ 'host_new' ]);
unset ( $_POST [ 'user_new' ]);
unset ( $_POST [ 'domain_new' ]);
2009-01-31 10:14:27 +00:00
}
return $errors ;
}
2015-07-11 09:50:00 +00:00
2009-01-31 10:14:27 +00:00
/**
* Displays the group selection .
*
2010-09-21 17:57:04 +00:00
* @ return htmlElement meta HTML code
2009-01-31 10:14:27 +00:00
*/
function display_html_group () {
// load list with all groups
2010-11-20 19:19:03 +00:00
$allGroups = $this -> getGroupList ();
2009-01-31 10:14:27 +00:00
// remove own entry
if ( ! $this -> getAccountContainer () -> isNewAccount ) {
$allGroups = array_delete ( $this -> attributes [ 'cn' ][ 0 ], $allGroups );
}
$subgroups = array ();
if ( is_array ( $this -> attributes [ 'memberNisNetgroup' ])) {
$subgroups = $this -> attributes [ 'memberNisNetgroup' ];
$allGroups = array_delete ( $subgroups , $allGroups );
}
2010-09-21 17:57:04 +00:00
$return = new htmlTable ();
$return -> addElement ( new htmlSubTitle ( _ ( " Subgroups " )), true );
$return -> addElement ( new htmlOutputText ( _ ( " Selected groups " )));
$return -> addElement ( new htmlOutputText ( '' ));
$return -> addElement ( new htmlOutputText ( _ ( " Available groups " )));
$return -> addNewLine ();
$selGroupSelect = new htmlSelect ( 'removegroups' , $subgroups , array (), 15 );
$selGroupSelect -> setMultiSelect ( true );
$return -> addElement ( $selGroupSelect );
$buttonContainer = new htmlTable ();
$buttonContainer -> addElement ( new htmlButton ( 'addgroups_button' , 'back.gif' , true ), true );
$buttonContainer -> addElement ( new htmlButton ( 'removegroups_button' , 'forward.gif' , true ), true );
$buttonContainer -> addElement ( new htmlHelpLink ( 'memberNisNetgroup' ));
$return -> addElement ( $buttonContainer );
$availGroupSelect = new htmlSelect ( 'addgroups' , $allGroups , array (), 15 );
$availGroupSelect -> setMultiSelect ( true );
$return -> addElement ( $availGroupSelect );
$return -> addNewLine ();
$backButton = new htmlAccountPageButton ( get_class ( $this ), 'attributes' , 'back' , _ ( 'Back' ));
$backButton -> colspan = 3 ;
$return -> addElement ( $backButton );
2009-01-31 10:14:27 +00:00
return $return ;
}
/**
* Processes user input of the group selection page .
* It checks if all input values are correct and updates the associated LDAP attributes .
*
* @ return array list of info / error messages
*/
function process_group () {
if ( isset ( $_POST [ 'addgroups' ]) && isset ( $_POST [ 'addgroups_button' ])) { // Add groups to list
if ( ! is_array ( $this -> attributes [ 'memberNisNetgroup' ])) {
$this -> attributes [ 'memberNisNetgroup' ] = array ();
}
// Add new group
$this -> attributes [ 'memberNisNetgroup' ] = @ array_merge ( $this -> attributes [ 'memberNisNetgroup' ], $_POST [ 'addgroups' ]);
}
elseif ( isset ( $_POST [ 'removegroups' ]) && isset ( $_POST [ 'removegroups_button' ])) { // remove groups from list
$this -> attributes [ 'memberNisNetgroup' ] = array_delete ( $_POST [ 'removegroups' ], $this -> attributes [ 'memberNisNetgroup' ]);
}
return array ();
}
2009-01-31 14:58:58 +00:00
/**
* Displays the host / user selection .
*
2010-09-21 17:57:04 +00:00
* @ return htmlElement meta HTML code
2009-01-31 14:58:58 +00:00
*/
function display_html_select () {
2010-09-21 17:57:04 +00:00
$return = new htmlTable ();
2009-01-31 14:58:58 +00:00
$selectHost = true ;
$postKeys = array_keys ( $_POST );
$position = 'New' ;
2009-02-04 17:29:13 +00:00
$filterButtonName = '' ;
$filter = '' ;
if ( isset ( $_POST [ 'filter' ])) {
$filter = $_POST [ 'filter' ];
}
2009-01-31 14:58:58 +00:00
for ( $i = 0 ; $i < sizeof ( $postKeys ); $i ++ ) {
if ( substr ( $postKeys [ $i ], 0 , 36 ) == 'form_subpage_nisnetgroup_select_user' ) {
$selectHost = false ;
$position = substr ( $postKeys [ $i ], 36 );
2009-02-04 17:29:13 +00:00
$filterButtonName = $postKeys [ $i ];
2009-01-31 14:58:58 +00:00
break ;
}
if ( substr ( $postKeys [ $i ], 0 , 36 ) == 'form_subpage_nisnetgroup_select_host' ) {
$position = substr ( $postKeys [ $i ], 36 );
2009-02-04 17:29:13 +00:00
$filterButtonName = $postKeys [ $i ];
2009-01-31 14:58:58 +00:00
break ;
}
}
$options = array ();
if ( $selectHost ) {
// load list with all hosts
2010-11-20 19:19:03 +00:00
$options = $this -> getHostList ();
$count = sizeof ( $options );
for ( $i = 0 ; $i < $count ; $i ++ ) {
if ( ! get_preg ( $options [ $i ], 'DNSname' ) || (( $filter != '' ) && ( strpos ( $options [ $i ], $filter ) === false ))) {
unset ( $options [ $i ]);
2009-01-31 14:58:58 +00:00
}
}
2010-11-20 19:19:03 +00:00
$options = array_values ( $options );
2009-01-31 14:58:58 +00:00
}
else {
// load list with all users
2010-11-20 19:19:03 +00:00
$options = $this -> getUserList ();
$count = sizeof ( $options );
for ( $i = 0 ; $i < $count ; $i ++ ) {
if (( $filter != '' ) && ( strpos ( $options [ $i ], $filter ) === false )) {
unset ( $options [ $i ]);
2009-02-04 17:29:13 +00:00
}
2009-01-31 14:58:58 +00:00
}
2010-11-20 19:19:03 +00:00
$options = array_values ( $options );
2009-01-31 14:58:58 +00:00
}
2010-09-21 17:57:04 +00:00
$return -> addElement ( new htmlOutputText ( _ ( 'Filter' )));
$return -> addElement ( new htmlInputField ( 'filter' , $filter ));
$return -> addElement ( new htmlButton ( $filterButtonName , _ ( 'Ok' )));
$return -> addElement ( new htmlHelpLink ( 'filter' ), true );
2009-01-31 14:58:58 +00:00
$title = _ ( 'Host name' );
if ( ! $selectHost ) $title = _ ( 'User name' );
2010-09-21 17:57:04 +00:00
$return -> addElement ( new htmlOutputText ( $title ));
$return -> addElement ( new htmlSelect ( 'selectBox' , $options ), true );
$return -> addElement ( new htmlSpacer ( null , '10px' ), true );
2009-01-31 14:58:58 +00:00
$type = 'host' ;
if ( ! $selectHost ) $type = 'user' ;
2010-09-21 17:57:04 +00:00
$buttonContainer = new htmlTable ();
$buttonContainer -> addElement ( new htmlAccountPageButton ( get_class ( $this ), 'attributes' , 'select' , _ ( 'Ok' )));
$buttonContainer -> addElement ( new htmlAccountPageButton ( get_class ( $this ), 'attributes' , 'back' , _ ( 'Cancel' )));
$buttonContainer -> colspan = 4 ;
$return -> addElement ( $buttonContainer , true );
$return -> addElement ( new htmlHiddenInput ( 'host_new' , $_POST [ 'host_new' ]));
$return -> addElement ( new htmlHiddenInput ( 'user_new' , $_POST [ 'user_new' ]));
$return -> addElement ( new htmlHiddenInput ( 'domain_new' , $_POST [ 'domain_new' ]));
$return -> addElement ( new htmlHiddenInput ( 'type' , $type ));
$return -> addElement ( new htmlHiddenInput ( 'position' , $position ));
2009-01-31 14:58:58 +00:00
return $return ;
}
2015-07-11 09:50:00 +00:00
2009-01-31 14:58:58 +00:00
/**
* Processes user input of the host / user selection page .
* It checks if all input values are correct and updates the associated LDAP attributes .
*
* @ return array list of info / error messages
*/
function process_select () {
if ( isset ( $_POST [ 'form_subpage_nisnetgroup_attributes_back' ])) {
return array ();
}
if ( $_POST [ 'position' ] == 'New' ) {
$_POST [ $_POST [ 'type' ] . '_new' ] = $_POST [ 'selectBox' ];
}
return array ();
}
2015-07-11 09:50:00 +00:00
2009-01-31 10:14:27 +00:00
/**
2017-05-20 09:46:49 +00:00
* { @ inheritDoc }
* @ see baseModule :: build_uploadAccounts ()
*/
function build_uploadAccounts ( $rawAccounts , $ids , & $partialAccounts , $selectedModules , & $type ) {
2009-01-31 10:14:27 +00:00
$messages = array ();
// get list of existing groups
2010-11-20 19:19:03 +00:00
$existingGroups = $this -> getGroupList ();
2009-01-31 10:14:27 +00:00
for ( $i = 0 ; $i < sizeof ( $rawAccounts ); $i ++ ) {
// add object class
if ( ! in_array ( 'nisNetgroup' , $partialAccounts [ $i ][ 'objectClass' ])) $partialAccounts [ $i ][ 'objectClass' ][] = 'nisNetgroup' ;
// add cn
$partialAccounts [ $i ][ 'cn' ] = $rawAccounts [ $i ][ $ids [ 'nisnetgroup_cn' ]];
// description (UTF-8, no regex check needed)
2014-04-15 19:49:47 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'nisnetgroup_description' , 'description' );
2009-01-31 10:14:27 +00:00
// additional groups
if ( $rawAccounts [ $i ][ $ids [ 'nisnetgroup_subgroups' ]] != " " ) {
$groups = explode ( " , " , $rawAccounts [ $i ][ $ids [ 'nisnetgroup_subgroups' ]]);
$skipSubgroups = false ;
for ( $g = 0 ; $g < sizeof ( $groups ); $g ++ ) {
if ( ! in_array ( $groups [ $g ], $existingGroups )) {
$messages [] = array ( 'ERROR' , _ ( 'Unable to find group in LDAP.' ), $groups [ $g ]);
$skipSubgroups = true ;
}
}
if ( ! $skipSubgroups ) {
$partialAccounts [ $i ][ 'memberNisNetgroup' ] = $groups ;
}
}
2009-02-01 18:57:56 +00:00
// members
2015-08-16 08:47:48 +00:00
$this -> mapSimpleUploadField ( $rawAccounts , $ids , $partialAccounts , $i , 'nisnetgroup_members' , 'nisNetgroupTriple' , null , null , $messages , '/;[ ]*/' );
2009-01-31 10:14:27 +00:00
}
return $messages ;
}
2015-07-11 09:50:00 +00:00
2009-01-31 10:14:27 +00:00
/**
* This functions is used to check if all settings for this module have been made .
*
* @ return boolean true , if settings are complete
*/
function module_complete () {
if ( isset ( $this -> attributes [ 'cn' ]) && ( sizeof ( $this -> attributes [ 'cn' ]) > 0 )) {
return true ;
}
else {
return false ;
}
}
/**
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 ) {
2009-01-31 10:14:27 +00:00
$return = array ();
2013-05-06 19:16:47 +00:00
$this -> addSimplePDFField ( $return , 'cn' , _ ( 'Group name' ));
$this -> addSimplePDFField ( $return , 'description' , _ ( 'Description' ));
$this -> addSimplePDFField ( $return , 'subgroups' , _ ( 'Subgroups' ), 'memberNisNetgroup' );
2009-01-31 10:14:27 +00:00
if ( sizeof ( $this -> attributes [ 'nisNetgroupTriple' ]) > 0 ) {
2015-07-11 09:50:00 +00:00
$pdfTable = new PDFTable ( _ ( 'Members' ));
$pdfRow = new PDFTableRow ();
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'Host' ), '20%' , null , true );
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'User' ), '20%' , null , true );
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'Domain' ), '20%' , null , true );
$pdfTable -> rows [] = $pdfRow ;
2009-02-01 15:56:48 +00:00
for ( $i = 0 ; $i < sizeof ( $this -> attributes [ 'nisNetgroupTriple' ]); $i ++ ) {
$triple = substr ( $this -> attributes [ 'nisNetgroupTriple' ][ $i ], 1 , strlen ( $this -> attributes [ 'nisNetgroupTriple' ][ $i ]) - 2 );
$triple = explode ( ',' , $triple );
2015-07-11 09:50:00 +00:00
$pdfRow = new PDFTableRow ();
$pdfRow -> cells [] = new PDFTableCell ( $triple [ 0 ], '20%' );
$pdfRow -> cells [] = new PDFTableCell ( $triple [ 1 ], '20%' );
$pdfRow -> cells [] = new PDFTableCell ( $triple [ 2 ], '30%' );
$pdfTable -> rows [] = $pdfRow ;
2009-01-31 10:14:27 +00:00
}
2015-07-11 09:50:00 +00:00
$this -> addPDFTable ( $return , 'members' , $pdfTable );
2009-01-31 10:14:27 +00:00
}
return $return ;
}
2015-07-11 09:50:00 +00:00
2010-11-20 19:19:03 +00:00
/**
* Returns a list of existing NIS net groups .
*
* @ return array group names
*/
private function getGroupList () {
if ( $this -> cachedGroupList != null ) {
return $this -> cachedGroupList ;
}
$this -> cachedGroupList = searchLDAPByAttribute ( 'cn' , '*' , 'nisNetgroup' , array ( 'cn' ), array ( 'netgroup' ));
for ( $i = 0 ; $i < s izeof ( $this -> cachedGroupList ); $i ++ ) {
$this -> cachedGroupList [ $i ] = $this -> cachedGroupList [ $i ][ 'cn' ][ 0 ];
}
return $this -> cachedGroupList ;
}
/**
* Returns a list of existing users .
*
* @ return array user names
*/
private function getUserList () {
if ( $this -> cachedUserList != null ) {
return $this -> cachedUserList ;
}
$this -> cachedUserList = searchLDAPByAttribute ( 'uid' , '*' , 'posixAccount' , array ( 'uid' ), array ( 'user' ));
for ( $i = 0 ; $i < sizeof ( $this -> cachedUserList ); $i ++ ) {
$this -> cachedUserList [ $i ] = $this -> cachedUserList [ $i ][ 'uid' ][ 0 ];
}
return $this -> cachedUserList ;
}
/**
* Returns a list of existing hosts .
*
* @ return array host names
*/
private function getHostList () {
if ( $this -> cachedHostList != null ) {
return $this -> cachedHostList ;
}
2014-04-12 12:35:05 +00:00
$this -> cachedHostList = array ();
$list = searchLDAPByFilter ( '(|(objectClass=account)(objectClass=device))' , array ( 'uid' , 'cn' ), array ( 'host' ));
foreach ( $list as $attrs ) {
if ( ! empty ( $attrs [ 'uid' ][ 0 ])) {
$this -> cachedHostList [] = $attrs [ 'uid' ][ 0 ];
}
if ( ! empty ( $attrs [ 'cn' ][ 0 ])) {
$this -> cachedHostList [] = $attrs [ 'cn' ][ 0 ];
}
2010-11-20 19:19:03 +00:00
}
2014-04-12 12:35:05 +00:00
$this -> cachedHostList = array_values ( array_unique ( $this -> cachedHostList ));
2010-11-20 19:19:03 +00:00
return $this -> cachedHostList ;
}
2009-01-31 10:14:27 +00:00
}
?>