2003-12-27 11:21:00 +00:00
< ? php
2017-02-18 09:13:08 +00:00
use \LAM\PDF\PDFTable ;
use \LAM\PDF\PDFTableCell ;
use \LAM\PDF\PDFTableRow ;
2003-12-27 11:21:00 +00:00
/*
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager ( http :// www . ldap - account - manager . org / )
2006-03-03 17:30:35 +00:00
Copyright ( C ) 2003 - 2006 Tilo Lutz
2020-03-19 18:48:38 +00:00
2007 - 2020 Roland Gruber
2003-12-27 11:21:00 +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
*/
2005-07-21 10:33:02 +00:00
/**
* Manages quotas for users and groups .
*
* @ package modules
*
* @ author Tilo Lutz
* @ author Roland Gruber
* @ author Michael Duergner
*/
/**
* Manages quotas for users and groups .
*
* @ package modules
*/
2004-06-08 18:54:37 +00:00
class quota extends baseModule {
2015-07-11 09:50:00 +00:00
2012-07-15 12:05:47 +00:00
/** delimiter for lamdaemon commands */
2009-12-12 17:22:14 +00:00
private static $SPLIT_DELIMITER = " ###x##y##x### " ;
2012-07-15 12:05:47 +00:00
/** prefix for lamdaemon results */
2010-05-14 12:57:00 +00:00
private static $QUOTA_PREFIX = 'QUOTA_ENTRY ' ;
2004-06-13 19:58:58 +00:00
2020-02-24 19:08:28 +00:00
/** this function fills the error message array with messages
2004-09-26 13:48:52 +00:00
**/
function load_Messages () {
2009-12-12 17:22:14 +00:00
// error messages for input checks
$this -> messages [ 'softblock' ][ 0 ] = array ( 'ERROR' , _ ( 'Block soft quota' ), _ ( 'Block soft quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'softblock' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' %s' , _ ( 'Block soft quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'hardblock' ][ 0 ] = array ( 'ERROR' , _ ( 'Block hard quota' ), _ ( 'Block hard quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'hardblock' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' %s' , _ ( 'Block hard quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'softinode' ][ 0 ] = array ( 'ERROR' , _ ( 'Inode soft quota' ), _ ( 'Inode soft quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'softinode' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' %s' , _ ( 'Inode soft quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'hardinode' ][ 0 ] = array ( 'ERROR' , _ ( 'Inode hard quota' ), _ ( 'Inode hard quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'hardinode' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' %s' , _ ( 'Inode hard quota contains invalid characters. Only natural numbers are allowed.' ));
$this -> messages [ 'block_cmp' ][ 0 ] = array ( 'ERROR' , _ ( 'Block quota' ), _ ( 'Block soft quota must be smaller than block hard quota.' ));
$this -> messages [ 'block_cmp' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' %s' , _ ( 'Block soft quota must be smaller than block hard quota.' ));
$this -> messages [ 'inode_cmp' ][ 0 ] = array ( 'ERROR' , _ ( 'Inode quota' ), _ ( 'Inode soft quota must be smaller than inode hard quota.' ));
$this -> messages [ 'inode_cmp' ][ 1 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' %s' , _ ( 'Inode soft quota must be smaller than inode hard quota.' ));
$this -> messages [ 'upload' ][ 0 ] = array ( 'ERROR' , _ ( 'Account %s:' ) . ' %s' , _ ( 'Quota has wrong format!' ));
2004-09-26 13:48:52 +00:00
}
2006-08-13 12:58:19 +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 ( 'user' , 'group' ));
}
2004-06-13 19:58:58 +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
*
2008-02-03 14:28:28 +00:00
* @ see baseModule :: get_metaData ()
2004-06-13 19:58:58 +00:00
*/
function get_metaData () {
$return = array ();
2007-11-19 18:42:03 +00:00
// icon
2007-12-01 12:34:52 +00:00
$return [ 'icon' ] = 'hard-driveBig.png' ;
2004-06-14 16:05:36 +00:00
// alias name
$return [ " alias " ] = _ ( 'Quota' );
2004-06-20 17:32:02 +00:00
if ( $this -> get_scope () == 'group' ) {
// module dependencies
2018-03-12 18:22:04 +00:00
$return [ 'dependencies' ] = array ( 'depends' => array ( array ( 'posixGroup' , 'rfc2307bisPosixGroup' , 'windowsPosixGroup' )), 'conflicts' => array ());
2004-06-20 17:32:02 +00:00
}
if ( $this -> get_scope () == 'user' ) {
// module dependencies
$return [ 'dependencies' ] = array ( 'depends' => array ( 'posixAccount' ), 'conflicts' => array ());
}
2007-03-04 16:07:12 +00:00
// managed attributes
2007-10-11 17:51:35 +00:00
$return [ 'attributes' ] = array ( 'uid' , 'cn' );
2004-08-17 15:16:17 +00:00
// available PDF fields
2004-10-30 16:46:06 +00:00
$return [ 'PDF_fields' ] = array (
2010-04-05 12:38:23 +00:00
'quotas' => _ ( 'Quota' )
2004-10-30 16:46:06 +00:00
);
2004-10-02 17:41:42 +00:00
// help entries
2018-03-04 14:42:50 +00:00
$numbersHelp = _ ( 'Symbols K, M, G and T can be appended to numeric value to express kibibytes, mebibytes, gibibytes and tebibytes for blocks.' )
. _ ( ' Symbols k, m, g and t can be appended to numeric value to express multiples of 10^3, 10^6, 10^9 and 10^12 inodes.' );
2004-10-02 17:41:42 +00:00
$return [ 'help' ] = array (
2004-10-30 16:46:06 +00:00
" Mountpoint " => array (
" Headline " => _ ( " Mountpoint " ),
" Text " => _ ( " Mountpoint of device with enabled quotas. " )
),
" UsedBlocks " => array (
" Headline " => _ ( " Used blocks " ),
" Text " => _ ( " Used blocks. 1000 blocks are usually 1MB " )
),
" SoftBlockLimit " => array (
" Headline " => _ ( " Soft block limit " ),
2017-12-20 17:26:12 +00:00
" Text " => _ ( " Soft block limit. " ) . '<br>' . $numbersHelp , " SeeAlso " => array (
2010-09-30 18:57:26 +00:00
'link' => 'http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Quota.html#ss4.4' ,
2007-10-11 17:51:35 +00:00
'text' => 'Quota How-To' )
2004-10-30 16:46:06 +00:00
),
" HardBlockLimit " => array (
" Headline " => _ ( " Hard block limit " ),
2017-12-20 17:26:12 +00:00
" Text " => _ ( " Hard block limit " ) . '<br>' . $numbersHelp , " SeeAlso " => array (
2007-10-12 16:13:11 +00:00
'link' => 'http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Quota.html#ss4.5' ,
'text' => 'Quota How-To' )
2004-10-30 16:46:06 +00:00
),
" GraceBlockPeriod " => array (
" Headline " => _ ( " Grace block period " ),
2007-10-12 16:13:11 +00:00
" Text " => _ ( " Grace block period. Most filesystems use a fixed maximum value of 7 days. " ), " SeeAlso " => array (
'link' => 'http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Quota.html#ss4.6' ,
'text' => 'Quota How-To' )
2004-10-30 16:46:06 +00:00
),
" UsedInodes " => array (
" Headline " => _ ( " Used inodes " ),
" Text " => _ ( " Used inodes (files) " ) . '.'
),
" SoftInodeLimit " => array (
" Headline " => _ ( " Soft inode limit " ),
2017-12-20 17:26:12 +00:00
" Text " => _ ( " Soft inode (files) limit. " ) . '<br>' . $numbersHelp , " SeeAlso " => array (
2007-10-12 16:13:11 +00:00
'link' => 'http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Quota.html#ss4.4' ,
'text' => 'Quota How-To' )
2004-10-30 16:46:06 +00:00
),
" HardInodeLimit " => array (
" Headline " => _ ( " Hard inode limit " ),
2017-12-20 17:26:12 +00:00
" Text " => _ ( " Hard inode (files) limit " ) . '<br>' . $numbersHelp , " SeeAlso " => array (
2007-10-12 16:13:11 +00:00
'link' => 'http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Quota.html#ss4.5' ,
'text' => 'Quota How-To' )
2004-10-30 16:46:06 +00:00
),
" GraceInodePeriod " => array (
" Headline " => _ ( " Grace inode period " ),
2007-10-12 16:13:11 +00:00
" Text " => _ ( " Grace inode (files) period. Most filesystems use a fixed maximum value of 7 days. " ), " SeeAlso " => array (
'link' => 'http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html_single/Quota.html#ss4.6' ,
'text' => 'Quota How-To' )
2005-07-19 12:21:10 +00:00
),
" upload " => array (
" Headline " => _ ( " Quota " ),
" Text " => _ ( " Please enter the quota settings for this mount point. The syntax is: { soft block limit}, { hard block limit}, { soft inode limit}, { hard inode limit} " )
2004-10-30 16:46:06 +00:00
)
2004-10-02 17:41:42 +00:00
);
2004-06-13 19:58:58 +00:00
return $return ;
}
2007-03-04 16:07:12 +00:00
/** Saves the quota settings */
2007-10-13 17:28:37 +00:00
private $quota ;
2015-07-11 09:50:00 +00:00
2007-03-04 16:07:12 +00:00
/**
* Initializes the quota values .
*/
function initQuotas () {
2019-05-12 16:41:52 +00:00
if ( isset ( $this -> quota )) {
return ;
}
2007-03-04 16:07:12 +00:00
$userName = '+' ;
2007-10-03 18:02:10 +00:00
if (( $this -> getAccountContainer () != null ) && ! $this -> getAccountContainer () -> isNewAccount ) {
2007-10-11 17:51:35 +00:00
if ( $this -> get_scope () == 'user' ) {
2019-10-23 19:25:33 +00:00
if ( ! isset ( $this -> attributes [ 'uid' ][ 0 ])) {
return ;
}
2007-10-11 17:51:35 +00:00
$userName = $this -> attributes [ 'uid' ][ 0 ];
}
else if ( $this -> get_scope () == 'group' ) {
2019-10-23 19:25:33 +00:00
if ( ! isset ( $this -> attributes [ 'cn' ][ 0 ])) {
return ;
}
2007-10-11 17:51:35 +00:00
$userName = $this -> attributes [ 'cn' ][ 0 ];
}
2006-09-09 11:46:01 +00:00
}
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
2019-10-17 19:18:13 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
foreach ( $lamdaemonServers as $lamdaemonServer ) {
$server = $lamdaemonServer -> getServer ();
2007-03-04 16:07:12 +00:00
// get quotas
2017-09-17 07:21:37 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:25:33 +00:00
$remote -> connect ( $lamdaemonServer );
2020-03-19 18:48:38 +00:00
$quotas = $remote -> execute ( implode ( self :: $SPLIT_DELIMITER , array ( $userName , " quota " , " get " , $this -> get_scope ())));
2017-09-17 07:21:37 +00:00
$remote -> disconnect ();
2018-05-01 07:41:30 +00:00
if ( empty ( $quotas )) {
2010-10-10 11:51:31 +00:00
continue ;
}
2017-09-17 07:21:37 +00:00
$allQuotas = explode ( " : " , $quotas );
2007-03-04 16:07:12 +00:00
array_pop ( $allQuotas ); // remove empty element at the end
for ( $i = 0 ; $i < sizeof ( $allQuotas ); $i ++ ) {
2020-03-19 18:48:38 +00:00
if ( strpos ( $allQuotas [ $i ], self :: $QUOTA_PREFIX ) !== 0 ) {
2019-05-12 16:41:52 +00:00
continue ;
}
2020-03-19 18:48:38 +00:00
$allQuotas [ $i ] = substr ( $allQuotas [ $i ], strlen ( self :: $QUOTA_PREFIX ));
2007-03-04 16:07:12 +00:00
$singleQuota = explode ( " , " , $allQuotas [ $i ]);
2020-06-14 19:22:50 +00:00
$singleQuota [ 1 ] = $this -> formatBlockUsage ( $singleQuota [ 1 ]);
2020-03-28 17:06:38 +00:00
$singleQuota [ 2 ] = $this -> addBlockUnits ( $singleQuota [ 2 ]);
$singleQuota [ 3 ] = $this -> addBlockUnits ( $singleQuota [ 3 ]);
2020-06-14 19:22:50 +00:00
$singleQuota [ 5 ] = $this -> formatInodeUsage ( $singleQuota [ 5 ]);
2020-03-28 17:06:38 +00:00
$singleQuota [ 6 ] = $this -> addInodeUnits ( $singleQuota [ 6 ]);
$singleQuota [ 7 ] = $this -> addInodeUnits ( $singleQuota [ 7 ]);
2007-03-04 16:07:12 +00:00
$this -> quota [ $server ][ $i ] = $singleQuota ;
2019-05-12 16:41:52 +00:00
if ( $this -> quota [ $server ][ $i ][ 4 ] < time ()) {
$this -> quota [ $server ][ $i ][ 4 ] = '' ;
}
else {
$this -> quota [ $server ][ $i ][ 4 ] = strval ( intval (( $this -> quota [ $server ][ $i ][ 4 ] - time ()) / 3600 )) . ' ' . _ ( 'hours' );
}
if ( $this -> quota [ $server ][ $i ][ 8 ] < time ()) {
$this -> quota [ $server ][ $i ][ 8 ] = '' ;
}
else {
$this -> quota [ $server ][ $i ][ 8 ] = strval ( intval (( $this -> quota [ $server ][ $i ][ 8 ] - time ()) / 3600 )) . ' ' . _ ( 'hours' );
}
2003-12-27 11:21:00 +00:00
}
}
2007-03-04 16:07:12 +00:00
}
2003-12-27 11:21:00 +00:00
2020-03-28 17:06:38 +00:00
/**
* Adds units ( M / G / T ) for block numbers .
*
* @ param int $value raw value
2020-06-14 19:22:50 +00:00
* @ return string value with unit
2020-03-28 17:06:38 +00:00
*/
2020-06-12 07:42:54 +00:00
public function addBlockUnits ( $value ) {
2020-03-28 17:06:38 +00:00
$mebibytes = 1024 ;
$gibibytes = 1024 * $mebibytes ;
$tebibytes = 1024 * $gibibytes ;
if ( empty ( $value ) || ! get_preg ( $value , 'digit' ) || ( $value < $mebibytes )) {
return $value ;
}
if (( $value >= $tebibytes ) && (( $value % $tebibytes ) === 0 )) {
return ( $value / $tebibytes ) . 'T' ;
}
if (( $value >= $gibibytes ) && (( $value % $gibibytes ) === 0 )) {
return ( $value / $gibibytes ) . 'G' ;
}
if (( $value >= $mebibytes ) && (( $value % $mebibytes ) === 0 )) {
return ( $value / $mebibytes ) . 'M' ;
}
2020-06-12 07:42:54 +00:00
return $value ;
2020-03-28 17:06:38 +00:00
}
2020-06-14 19:22:50 +00:00
/**
* Formats block usage .
*
* @ param int $value raw value
*/
public function formatBlockUsage ( $value ) {
$mebibytes = 1024 ;
$gibibytes = 1024 * $mebibytes ;
$tebibytes = 1024 * $gibibytes ;
if ( empty ( $value ) || ! get_preg ( $value , 'digit' ) || ( $value < $mebibytes )) {
return $value ;
}
if ( $value >= $tebibytes ) {
2020-06-15 18:26:33 +00:00
return round ( $value / $tebibytes , 2 ) . 'T' ;
2020-06-14 19:22:50 +00:00
}
if ( $value >= $gibibytes ) {
2020-06-15 18:26:33 +00:00
return round ( $value / $gibibytes , 2 ) . 'G' ;
2020-06-14 19:22:50 +00:00
}
if ( $value >= $mebibytes ) {
2020-06-15 18:26:33 +00:00
return round ( $value / $mebibytes , 2 ) . 'M' ;
2020-06-14 19:22:50 +00:00
}
return $value ;
}
2020-03-28 17:06:38 +00:00
/**
* Adds units ( m / g / t ) for inode numbers .
*
* @ param int $value raw value
2020-06-14 19:22:50 +00:00
* @ return string value with unit
2020-03-28 17:06:38 +00:00
*/
2020-06-12 07:42:54 +00:00
public function addInodeUnits ( $value ) {
2020-03-28 17:06:38 +00:00
$kilo = 1000 ;
$million = 1000 * $kilo ;
$billion = 1000 * $million ;
$trillion = 1000 * $billion ;
2020-06-12 07:42:54 +00:00
if ( empty ( $value ) || ! get_preg ( $value , 'digit' )) {
2020-03-28 17:06:38 +00:00
return $value ;
}
if (( $value >= $trillion ) && (( $value % $trillion ) === 0 )) {
return ( $value / $trillion ) . 't' ;
}
if (( $value >= $billion ) && (( $value % $billion ) === 0 )) {
return ( $value / $billion ) . 'g' ;
}
if (( $value >= $million ) && (( $value % $million ) === 0 )) {
return ( $value / $million ) . 'm' ;
}
if (( $value >= $kilo ) && (( $value % $kilo ) === 0 )) {
return ( $value / $kilo ) . 'k' ;
}
2020-06-12 07:42:54 +00:00
return $value ;
2020-06-14 19:22:50 +00:00
}
/**
* Formats the inode usage .
*
* @ param int $value raw value
* @ return string value with unit
*/
public function formatInodeUsage ( $value ) {
$kilo = 1000 ;
$million = 1000 * $kilo ;
$billion = 1000 * $million ;
$trillion = 1000 * $billion ;
if ( empty ( $value ) || ! get_preg ( $value , 'digit' )) {
return $value ;
}
if ( $value >= $trillion ) {
2020-06-15 18:26:33 +00:00
return round ( $value / $trillion , 2 ) . 't' ;
2020-06-14 19:22:50 +00:00
}
if ( $value >= $billion ) {
2020-06-15 18:26:33 +00:00
return round ( $value / $billion , 2 ) . 'g' ;
2020-06-14 19:22:50 +00:00
}
if ( $value >= $million ) {
2020-06-15 18:26:33 +00:00
return round ( $value / $million , 2 ) . 'm' ;
2020-06-14 19:22:50 +00:00
}
if ( $value >= $kilo ) {
2020-06-15 18:26:33 +00:00
return round ( $value / $kilo , 2 ) . 'k' ;
2020-06-14 19:22:50 +00:00
}
return $value ;
2020-03-28 17:06:38 +00:00
}
2008-12-18 14:59:02 +00:00
/**
* Gets the cn from the Unix group module .
*
* @ return String cn attribute
*/
private function getCn () {
2018-03-12 18:22:04 +00:00
$modules = array ( 'posixGroup' , 'windowsPosixGroup' , 'rfc2307bisPosixGroup' , 'groupOfNames' , 'groupOfUniqueNames' , 'windowsGroup' );
2008-12-18 14:59:02 +00:00
for ( $i = 0 ; $i < sizeof ( $modules ); $i ++ ) {
if ( $this -> getAccountContainer () -> getAccountModule ( $modules [ $i ]) != null ) {
$attrs = $this -> getAccountContainer () -> getAccountModule ( $modules [ $i ]) -> getAttributes ();
if ( isset ( $attrs [ 'cn' ][ 0 ])) {
return $attrs [ 'cn' ][ 0 ];
}
}
}
return null ;
}
2015-07-11 09:50:00 +00:00
2007-11-03 14:17:19 +00:00
/**
* This function is used to check if this module page can be displayed .
* It returns false if a module depends on data from other modules which was not yet entered .
*
* @ return boolean true , if page can be displayed
*/
2003-12-27 11:21:00 +00:00
function module_ready () {
2007-10-10 19:04:39 +00:00
if ( $this -> get_scope () == 'user' ) {
$attrs = $this -> getAccountContainer () -> getAccountModule ( 'posixAccount' ) -> getAttributes ();
2020-03-26 15:47:22 +00:00
if ( empty ( $attrs [ 'uid' ][ 0 ])) {
2008-12-18 14:59:02 +00:00
return false ;
}
2007-10-10 19:04:39 +00:00
}
2019-05-12 16:41:52 +00:00
return ( $this -> get_scope () != 'group' ) || ! empty ( $this -> getCn ());
2005-09-13 17:20:07 +00:00
}
2003-12-27 11:21:00 +00:00
2007-03-04 16:07:12 +00:00
/**
2012-07-15 12:05:47 +00:00
* Quotas are set in postmodify .
2015-07-11 09:50:00 +00:00
*
2009-05-21 16:33:50 +00:00
* @ see baseModule :: postModifyActions ()
2007-03-04 16:07:12 +00:00
*
2012-07-15 12:05:47 +00:00
* @ param boolean $newAccount is new account
2009-05-21 16:33:50 +00:00
* @ 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 .
2007-03-04 16:07:12 +00:00
*/
2009-05-21 16:33:50 +00:00
public function postModifyActions ( $newAccount , $attributes ) {
2012-01-04 19:08:19 +00:00
$messages = array ();
2019-05-12 16:41:52 +00:00
if ( ! isset ( $this -> quota ) || ! is_array ( $this -> quota )) {
return $messages ;
}
2007-03-04 16:07:12 +00:00
// determine if this is a user or group account
2007-10-10 19:04:39 +00:00
if ( $this -> get_scope () == 'user' ) {
$attrs = $this -> getAccountContainer () -> getAccountModule ( 'posixAccount' ) -> getAttributes ();
$id = $attrs [ 'uid' ][ 0 ];
}
if ( $this -> get_scope () == 'group' ) {
2008-12-18 14:59:02 +00:00
$id = $this -> getCn ();
2007-10-10 19:04:39 +00:00
}
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
$servers = array_keys ( $this -> quota );
for ( $q = 0 ; $q < sizeof ( $servers ); $q ++ ) {
$server = $servers [ $q ];
$i = 0 ;
$quotastring = " " ;
for ( $i = 0 ; $i < sizeof ( $this -> quota [ $server ]); $i ++ ) {
2017-10-21 19:37:40 +00:00
$quotastring .= $this -> quota [ $server ][ $i ][ 0 ];
$quotastring .= ',' . $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 2 ]);
$quotastring .= ',' . $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 3 ]);
$quotastring .= ',' . $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 6 ]);
$quotastring .= ',' . $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 7 ]) . ':' ;
2003-12-27 11:21:00 +00:00
}
2017-09-17 07:21:37 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:25:33 +00:00
$remoteServer = $_SESSION [ 'config' ] -> getScriptServerByName ( $server );
$remote -> connect ( $remoteServer );
2020-03-28 17:06:38 +00:00
$output = $remote -> execute ( implode ( self :: $SPLIT_DELIMITER , array ( $id , " quota " , " set " , $this -> get_scope (), " $quotastring\n " )));
if ( strpos ( $output , 'ERROR,' ) === 0 ) {
$messages [] = array ( 'ERROR' , $server , _ ( 'Unable to set quota.' ));
}
2017-09-17 07:21:37 +00:00
$remote -> disconnect ();
2003-12-27 11:21:00 +00:00
}
2012-01-04 19:08:19 +00:00
return $messages ;
2007-03-04 16:07:12 +00:00
}
2003-12-27 11:21:00 +00:00
2017-10-21 19:37:40 +00:00
/**
* Returns the quota value as plain number .
*
* @ param string $quotaInput quota value ( might contain e . g . " K " for KB )
* @ return int quota number
*/
private function getQuotaNumber ( $quotaInput ) {
if ( empty ( $quotaInput ) || ( strlen ( $quotaInput ) < 2 )) {
return $quotaInput ;
}
if ( substr ( $quotaInput , - 1 , 1 ) === 'K' ) {
2017-12-20 17:26:12 +00:00
return substr ( $quotaInput , 0 , - 1 );
2017-10-21 19:37:40 +00:00
}
if ( substr ( $quotaInput , - 1 , 1 ) === 'M' ) {
2017-12-20 17:26:12 +00:00
return 1024 * substr ( $quotaInput , 0 , - 1 );
2017-10-21 19:37:40 +00:00
}
if ( substr ( $quotaInput , - 1 , 1 ) === 'G' ) {
2017-12-20 17:26:12 +00:00
return 1024 * 1024 * substr ( $quotaInput , 0 , - 1 );
2017-10-21 19:37:40 +00:00
}
if ( substr ( $quotaInput , - 1 , 1 ) === 'T' ) {
return 1024 * 1024 * 1024 * 1024 * substr ( $quotaInput , 0 , - 1 );
}
if ( substr ( $quotaInput , - 1 , 1 ) === 'k' ) {
return 1000 * substr ( $quotaInput , 0 , - 1 );
}
if ( substr ( $quotaInput , - 1 , 1 ) === 'm' ) {
return 1000 * 1000 * substr ( $quotaInput , 0 , - 1 );
}
if ( substr ( $quotaInput , - 1 , 1 ) === 'g' ) {
return 1000 * 1000 * 1000 * substr ( $quotaInput , 0 , - 1 );
}
if ( substr ( $quotaInput , - 1 , 1 ) === 't' ) {
return 1000 * 1000 * 1000 * 1000 * substr ( $quotaInput , 0 , - 1 );
}
return $quotaInput ;
}
2007-03-04 16:07:12 +00:00
/**
* Allows the module to run commands before the LDAP entry is deleted .
2015-07-11 09:50:00 +00:00
*
2010-11-26 20:16:14 +00:00
* @ return array Array which contains status messages . Each entry is an array containing the status message parameters .
2007-03-04 16:07:12 +00:00
*/
function preDeleteActions () {
2017-12-13 11:31:26 +00:00
try {
$this -> initQuotas ();
}
catch ( LAMException $e ) {
return array ( array ( 'ERROR' , $e -> getTitle (), $e -> getMessage ()));
}
if ( ! isset ( $this -> quota ) || ! is_array ( $this -> quota )) {
return array ();
}
2007-03-04 16:07:12 +00:00
// determine if this is a user or group account
2007-10-10 19:04:39 +00:00
if ( $this -> get_scope () == 'user' ) {
$attrs = $this -> getAccountContainer () -> getAccountModule ( 'posixAccount' ) -> getAttributes ();
$id = $attrs [ 'uid' ][ 0 ];
}
if ( $this -> get_scope () == 'group' ) {
2008-12-18 14:59:02 +00:00
$id = $this -> getCn ();
2007-10-10 19:04:39 +00:00
}
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
$servers = array_keys ( $this -> quota );
for ( $q = 0 ; $q < sizeof ( $servers ); $q ++ ) {
$server = $servers [ $q ];
$i = 0 ;
$quotastring = " " ;
2013-09-14 16:13:49 +00:00
while ( isset ( $this -> quota [ $server ][ $i ][ 0 ])) {
2007-03-04 16:07:12 +00:00
$quotastring = $quotastring . $this -> quota [ $server ][ $i ][ 0 ] . ',0,0,0,0:' ;
$i ++ ;
}
2017-09-17 07:21:37 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:25:33 +00:00
$remoteServer = $_SESSION [ 'config' ] -> getScriptServerByName ( $server );
$remote -> connect ( $remoteServer );
2020-03-19 18:48:38 +00:00
$remote -> execute ( implode ( self :: $SPLIT_DELIMITER , array ( $id , " quota " , " set " , $this -> get_scope (), " $quotastring\n " )));
2017-09-17 07:21:37 +00:00
$remote -> disconnect ();
2007-03-04 16:07:12 +00:00
}
2010-11-26 20:16:14 +00:00
return array ();
2007-03-04 16:07:12 +00:00
}
2003-12-27 11:21:00 +00:00
2005-09-07 12:58:34 +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
2003-12-27 11:21:00 +00:00
*/
2006-08-13 12:58:19 +00:00
function process_attributes () {
2019-05-12 16:41:52 +00:00
if ( ! isset ( $this -> quota ) || ! is_array ( $this -> quota )) {
return array ();
}
2006-05-17 17:40:42 +00:00
$errors = array ();
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
$servers = array_keys ( $this -> quota );
for ( $q = 0 ; $q < sizeof ( $servers ); $q ++ ) {
$server = $servers [ $q ];
$id = $this -> replaceSpecialChars ( $server );
$i = 0 ;
// loop for every mointpoint with quotas
2007-10-12 16:14:38 +00:00
while ( isset ( $this -> quota [ $server ][ $i ][ 0 ])) {
2007-03-04 16:07:12 +00:00
$this -> quota [ $server ][ $i ][ 2 ] = $_POST [ $i . '_2_' . $id ];
$this -> quota [ $server ][ $i ][ 3 ] = $_POST [ $i . '_3_' . $id ];
$this -> quota [ $server ][ $i ][ 6 ] = $_POST [ $i . '_6_' . $id ];
$this -> quota [ $server ][ $i ][ 7 ] = $_POST [ $i . '_7_' . $id ];
// Check if values are OK and set automatic values. if not error-variable will be set
2019-05-12 16:41:52 +00:00
if ( ! get_preg ( $this -> quota [ $server ][ $i ][ 2 ], 'quotaNumber' )) {
2007-03-04 16:07:12 +00:00
$errors [] = $this -> messages [ 'softblock' ][ 0 ];
2019-05-12 16:41:52 +00:00
}
if ( ! get_preg ( $this -> quota [ $server ][ $i ][ 3 ], 'quotaNumber' )) {
2007-03-04 16:07:12 +00:00
$errors [] = $this -> messages [ 'hardblock' ][ 0 ];
2019-05-12 16:41:52 +00:00
}
if ( ! get_preg ( $this -> quota [ $server ][ $i ][ 6 ], 'quotaNumber' )) {
2007-03-04 16:07:12 +00:00
$errors [] = $this -> messages [ 'softinode' ][ 0 ];
2019-05-12 16:41:52 +00:00
}
if ( ! get_preg ( $this -> quota [ $server ][ $i ][ 7 ], 'quotaNumber' )) {
2007-03-04 16:07:12 +00:00
$errors [] = $this -> messages [ 'hardinode' ][ 0 ];
2019-05-12 16:41:52 +00:00
}
if ( $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 2 ]) > $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 3 ])) {
2007-03-04 16:07:12 +00:00
$errors [] = $this -> messages [ 'block_cmp' ][ 0 ];
2019-05-12 16:41:52 +00:00
}
if ( $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 6 ]) > $this -> getQuotaNumber ( $this -> quota [ $server ][ $i ][ 7 ])) {
2007-03-04 16:07:12 +00:00
$errors [] = $this -> messages [ 'inode_cmp' ][ 0 ];
2019-05-12 16:41:52 +00:00
}
2007-03-04 16:07:12 +00:00
$i ++ ;
}
}
2006-05-17 17:40:42 +00:00
return $errors ;
}
2003-12-27 11:21:00 +00:00
2007-11-03 14:17:19 +00:00
/**
* Returns the HTML meta data for the main account page .
2015-07-11 09:50:00 +00:00
*
2010-09-29 16:47:39 +00:00
* @ return htmlElement HTML meta data
2007-11-03 14:17:19 +00:00
*/
2006-08-13 12:58:19 +00:00
function display_html_attributes () {
2019-09-27 15:16:16 +00:00
$return = new htmlResponsiveRow ();
$return -> setCSSClasses ( array ( 'maxrow' ));
2017-12-13 11:31:26 +00:00
try {
$this -> initQuotas ();
}
catch ( LAMException $e ) {
2019-09-27 15:16:16 +00:00
$return -> add ( new htmlStatusMessage ( 'ERROR' , $e -> getTitle (), $e -> getMessage ()), 12 );
2017-12-13 11:31:26 +00:00
return $return ;
}
if ( ! is_array ( $this -> quota )) {
return $return ;
}
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
$serverDescriptions = array ();
2019-10-17 19:18:13 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2007-03-04 16:07:12 +00:00
for ( $s = 0 ; $s < sizeof ( $lamdaemonServers ); $s ++ ) {
2019-10-17 19:18:13 +00:00
$lamdaemonServer = $lamdaemonServers [ $s ];
$serverDescriptions [ $lamdaemonServer -> getServer ()] = $lamdaemonServer -> getLabel ();
2003-12-27 11:21:00 +00:00
}
2007-03-04 16:07:12 +00:00
$servers = array_keys ( $this -> quota );
for ( $q = 0 ; $q < sizeof ( $servers ); $q ++ ) {
$server = $servers [ $q ];
$id = $this -> replaceSpecialChars ( $server );
2010-09-29 16:47:39 +00:00
$title = $server ;
2019-10-17 19:18:13 +00:00
if ( $serverDescriptions [ $server ] != $server ) {
2010-09-29 16:47:39 +00:00
$title = $serverDescriptions [ $server ] . " ( " . $server . " ) " ;
}
2019-09-27 15:16:16 +00:00
$return -> add ( new htmlSubTitle ( $title ), 12 );
$titles = array (
_ ( 'Mountpoint' ), _ ( 'Used blocks' ), _ ( 'Soft block limit' ), _ ( 'Hard block limit' ), _ ( 'Grace block period' ),
_ ( 'Used inodes' ), _ ( 'Soft inode limit' ), _ ( 'Hard inode limit' ), _ ( 'Grace inode period' )
);
$data = array (
array (
new htmlHelpLink ( 'Mountpoint' ), new htmlHelpLink ( 'UsedBlocks' ), new htmlHelpLink ( 'SoftBlockLimit' ),
new htmlHelpLink ( 'HardBlockLimit' ), new htmlHelpLink ( 'GraceBlockPeriod' ), new htmlHelpLink ( 'UsedInodes' ),
new htmlHelpLink ( 'SoftInodeLimit' ), new htmlHelpLink ( 'HardInodeLimit' ), new htmlHelpLink ( 'GraceInodePeriod' )
)
);
2015-07-11 09:50:00 +00:00
2007-03-04 16:07:12 +00:00
$i = 0 ;
// loop for every mointpoint with enabled quotas
2007-10-12 16:14:38 +00:00
while ( isset ( $this -> quota [ $server ][ $i ][ 0 ])) {
2019-09-27 15:16:16 +00:00
$dataRow = array ();
$dataRow [] = new htmlOutputText ( $this -> quota [ $server ][ $i ][ 0 ]);
$dataRow [] = new htmlOutputText ( $this -> quota [ $server ][ $i ][ 1 ]);
2010-09-29 16:47:39 +00:00
$sbLimitInput = new htmlInputField ( $i . '_2_' . $id , $this -> quota [ $server ][ $i ][ 2 ]);
$sbLimitInput -> setFieldMaxLength ( 20 );
2019-09-27 15:16:16 +00:00
$dataRow [] = $sbLimitInput ;
2010-09-29 16:47:39 +00:00
$hbLimit = new htmlInputField ( $i . '_3_' . $id , $this -> quota [ $server ][ $i ][ 3 ]);
$hbLimit -> setFieldMaxLength ( 20 );
2019-09-27 15:16:16 +00:00
$dataRow [] = $hbLimit ;
$dataRow [] = new htmlOutputText ( $this -> quota [ $server ][ $i ][ 4 ]);
$dataRow [] = new htmlOutputText ( $this -> quota [ $server ][ $i ][ 5 ]);
2010-09-29 16:47:39 +00:00
$siLimit = new htmlInputField ( $i . '_6_' . $id , $this -> quota [ $server ][ $i ][ 6 ]);
$siLimit -> setFieldMaxLength ( 20 );
2019-09-27 15:16:16 +00:00
$dataRow [] = $siLimit ;
2010-09-29 16:47:39 +00:00
$hiLimit = new htmlInputField ( $i . '_7_' . $id , $this -> quota [ $server ][ $i ][ 7 ]);
$hiLimit -> setFieldMaxLength ( 20 );
2019-09-27 15:16:16 +00:00
$dataRow [] = $hiLimit ;
$dataRow [] = new htmlOutputText ( $this -> quota [ $server ][ $i ][ 8 ]);
$data [] = $dataRow ;
2007-03-04 16:07:12 +00:00
$i ++ ;
}
2019-09-27 15:16:16 +00:00
$table = new htmlResponsiveTable ( $titles , $data );
$table -> setWidths ( array ( '20%' , '5%' , '10%' , '10%' , '5%' , '5%' , '10%' , '10%' , '5%' ));
$return -> add ( $table , 12 );
2007-03-04 16:07:12 +00:00
}
return $return ;
}
2015-07-11 09:50:00 +00:00
2007-03-04 16:07:12 +00:00
/**
* Replaces special characters in HTML name values .
*
* @ param string $input input string
* @ return string output string
*/
function replaceSpecialChars ( $input ) {
2019-05-12 16:41:52 +00:00
return str_replace ( " . " , " _ " , $input );
2007-03-04 16:07:12 +00:00
}
2003-12-27 11:21:00 +00:00
2004-09-19 08:34:14 +00:00
/**
2017-03-30 18:39:24 +00:00
* { @ inheritDoc }
2004-09-19 08:34:14 +00:00
*/
2017-03-30 18:39:24 +00:00
function get_profileOptions ( $typeId ) {
2018-05-19 12:00:53 +00:00
$return = new htmlResponsiveRow ();
2010-12-19 13:35:42 +00:00
$optionsAvailable = false ;
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
2019-10-17 19:18:13 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
2017-12-13 09:59:38 +00:00
try {
2019-10-17 19:18:13 +00:00
foreach ( $lamdaemonServers as $lamdaemonServer ) {
$server = $lamdaemonServer -> getServer ();
2017-12-13 09:59:38 +00:00
$id = $this -> replaceSpecialChars ( $server );
2019-10-17 19:18:13 +00:00
$description = $lamdaemonServer -> getLabel ();
if ( $description != $server ) {
$description = $description . ' (' . $server . ')' ;
2017-12-13 09:59:38 +00:00
}
// Get quotas
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:25:33 +00:00
$remote -> connect ( $lamdaemonServer );
2020-03-19 18:48:38 +00:00
$quotas = $remote -> execute ( implode ( self :: $SPLIT_DELIMITER , array ( " + " , " quota " , " get " , $this -> get_scope ())));
2017-12-13 09:59:38 +00:00
$remote -> disconnect ();
if ( empty ( $quotas )) {
2010-05-14 12:57:00 +00:00
continue ;
}
2017-12-13 09:59:38 +00:00
$dirs = explode ( " : " , $quotas );
array_pop ( $dirs ); // remove empty element at the end
2020-04-19 18:49:25 +00:00
if ( empty ( $dirs )) {
continue ;
}
2017-12-13 09:59:38 +00:00
for ( $i = 0 ; $i < sizeof ( $dirs ); $i ++ ) {
2020-03-19 18:48:38 +00:00
if ( strpos ( $dirs [ $i ], self :: $QUOTA_PREFIX ) !== 0 ) {
2017-12-13 09:59:38 +00:00
unset ( $dirs [ $i ]);
$dirs = array_values ( $dirs );
$i -- ;
continue ;
}
2020-03-19 18:48:38 +00:00
$dirs [ $i ] = substr ( $dirs [ $i ], strlen ( self :: $QUOTA_PREFIX ));
2017-12-13 09:59:38 +00:00
$dirs [ $i ] = explode ( " , " , $dirs [ $i ]);
$dirs [ $i ] = $dirs [ $i ][ 0 ];
}
$dirs = array_values ( $dirs );
2019-05-12 16:41:52 +00:00
if ( sizeof ( $dirs ) < 1 ) {
continue ; // stop if no quota directories were found
}
2017-12-13 09:59:38 +00:00
$optionsAvailable = true ;
2018-05-19 12:00:53 +00:00
$return -> add ( new htmlSubTitle ( $description ), 12 );
2017-12-13 09:59:38 +00:00
for ( $i = 0 ; $i < sizeof ( $dirs ); $i ++ ) {
2018-05-19 12:00:53 +00:00
$return -> add ( new htmlOutputText ( $dirs [ $i ]), 12 );
$sbLimit = new htmlResponsiveInputField ( _ ( 'Soft block limit' ), " quota_softblock_ " . $id . " _ " . $dirs [ $i ], null , 'SoftBlockLimit' );
2017-12-13 09:59:38 +00:00
$sbLimit -> setFieldMaxLength ( 20 );
2018-05-19 12:00:53 +00:00
$return -> add ( $sbLimit , 12 );
$hbLimit = new htmlResponsiveInputField ( _ ( 'Hard block limit' ), " quota_hardblock_ " . $id . " _ " . $dirs [ $i ], null , 'HardBlockLimit' );
2017-12-13 09:59:38 +00:00
$hbLimit -> setFieldMaxLength ( 20 );
2018-05-19 12:00:53 +00:00
$return -> add ( $hbLimit , 12 );
$siLimit = new htmlResponsiveInputField ( _ ( 'Soft inode limit' ), " quota_softinode_ " . $id . " _ " . $dirs [ $i ], null , 'SoftInodeLimit' );
2017-12-13 09:59:38 +00:00
$siLimit -> setFieldMaxLength ( 20 );
2018-05-19 12:00:53 +00:00
$return -> add ( $siLimit , 12 );
$hiLimit = new htmlResponsiveInputField ( _ ( 'Hard inode limit' ), " quota_hardinode_ " . $id . " _ " . $dirs [ $i ], null , 'HardInodeLimit' );
2017-12-13 09:59:38 +00:00
$hiLimit -> setFieldMaxLength ( 20 );
2018-05-19 12:00:53 +00:00
$return -> add ( $hiLimit , 12 );
2017-12-13 09:59:38 +00:00
}
2007-03-04 16:07:12 +00:00
}
2004-06-23 19:10:22 +00:00
}
2017-12-13 09:59:38 +00:00
catch ( LAMException $e ) {
2018-05-19 12:00:53 +00:00
$return -> add ( new htmlStatusMessage ( 'WARN' , $e -> getTitle ()), 12 );
2017-12-13 09:59:38 +00:00
return $return ;
}
2010-12-19 13:35:42 +00:00
if ( ! $optionsAvailable ) {
return null ;
}
2004-03-09 12:03:39 +00:00
return $return ;
2003-12-27 11:21:00 +00:00
}
2004-09-19 08:34:14 +00:00
/**
2017-03-30 18:39:24 +00:00
* { @ inheritDoc }
2004-09-19 08:34:14 +00:00
*/
2017-03-30 18:39:24 +00:00
function check_profileOptions ( $options , $typeId ) {
2004-07-02 18:01:44 +00:00
$return = array ();
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
2019-10-17 19:18:13 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
foreach ( $lamdaemonServers as $lamdaemonServer ) {
$server = $lamdaemonServer -> getServer ();
2007-03-04 16:07:12 +00:00
$id = $this -> replaceSpecialChars ( $server );
// Get quotas
2017-09-17 07:21:37 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:25:33 +00:00
$remote -> connect ( $lamdaemonServer );
2020-03-19 18:48:38 +00:00
$quotas = $remote -> execute ( implode ( self :: $SPLIT_DELIMITER , array ( " + " , " quota " , " get " , $this -> get_scope ())));
2017-09-17 07:21:37 +00:00
$remote -> disconnect ();
$dirs = explode ( " : " , $quotas );
2007-03-04 16:07:12 +00:00
array_pop ( $dirs ); // remove empty element at the end
2020-04-19 18:53:56 +00:00
if ( empty ( $dirs )) {
continue ;
}
2020-04-20 19:05:11 +00:00
$quotaDirs = array ();
foreach ( $dirs as $dirString ) {
if ( strpos ( $dirString , self :: $QUOTA_PREFIX ) !== 0 ) {
2010-05-14 12:57:00 +00:00
continue ;
}
2020-04-20 19:05:11 +00:00
$dirData = explode ( " , " , substr ( $dirString , strlen ( self :: $QUOTA_PREFIX )));
$quotaDirs [] = $dirData [ 0 ];
2007-03-04 16:07:12 +00:00
}
2020-04-20 19:05:11 +00:00
foreach ( $quotaDirs as $dirName ) {
if ( ! empty ( $options [ " quota_softblock_ " . $id . " _ " . $dirName ][ 0 ]) && ! get_preg ( $options [ " quota_softblock_ " . $id . " _ " . $dirName ][ 0 ], 'quotaNumber' )) {
2019-05-12 16:41:52 +00:00
$return [] = $this -> messages [ 'softblock' ][ 0 ];
}
2020-04-20 19:05:11 +00:00
if ( ! empty ( $options [ " quota_hardblock_ " . $id . " _ " . $dirName ][ 0 ]) && ! get_preg ( $options [ " quota_hardblock_ " . $id . " _ " . $dirName ][ 0 ], 'quotaNumber' )) {
2019-05-12 16:41:52 +00:00
$return [] = $this -> messages [ 'hardblock' ][ 0 ];
}
2020-04-20 19:05:11 +00:00
if ( ! empty ( $options [ " quota_softinode_ " . $id . " _ " . $dirName ][ 0 ]) && ! get_preg ( $options [ " quota_softinode_ " . $id . " _ " . $dirName ][ 0 ], 'quotaNumber' )) {
2019-05-12 16:41:52 +00:00
$return [] = $this -> messages [ 'softinode' ][ 0 ];
}
2020-04-20 19:05:11 +00:00
if ( ! empty ( $options [ " quota_hardinode_ " . $id . " _ " . $dirName ][ 0 ]) && ! get_preg ( $options [ " quota_hardinode_ " . $id . " _ " . $dirName ][ 0 ], 'quotaNumber' )) {
2019-05-12 16:41:52 +00:00
$return [] = $this -> messages [ 'hardinode' ][ 0 ];
}
2020-04-20 19:05:11 +00:00
if ( ! empty ( $options [ " quota_softblock_ " . $id . " _ " . $dirName ][ 0 ])
&& ! empty ( $options [ " quota_hardblock_ " . $id . " _ " . $dirName ][ 0 ])
&& ( $this -> getQuotaNumber ( $options [ " quota_softblock_ " . $id . " _ " . $dirName ][ 0 ]) > $this -> getQuotaNumber ( $options [ " quota_hardblock_ " . $id . " _ " . $dirName ][ 0 ]))) {
2019-05-12 16:41:52 +00:00
$return [] = $this -> messages [ 'block_cmp' ][ 0 ];
}
2020-04-20 19:05:11 +00:00
if ( ! empty ( $options [ " quota_softinode_ " . $id . " _ " . $dirName ][ 0 ])
&& ! empty ( $options [ " quota_hardinode_ " . $id . " _ " . $dirName ][ 0 ])
&& ( $this -> getQuotaNumber ( $options [ " quota_softinode_ " . $id . " _ " . $dirName ][ 0 ]) > $this -> getQuotaNumber ( $options [ " quota_hardinode_ " . $id . " _ " . $dirName ][ 0 ]))) {
2019-05-12 16:41:52 +00:00
$return [] = $this -> messages [ 'inode_cmp' ][ 0 ];
}
2007-03-04 16:07:12 +00:00
}
2004-07-02 18:01:44 +00:00
}
return $return ;
2004-03-14 17:33:05 +00:00
}
2006-08-13 12:58:19 +00:00
2005-01-22 10:50:10 +00:00
/**
* Loads the values of an account profile into internal variables .
*
* @ param array $profile hash array with profile values ( identifier => value )
*/
function load_profile ( $profile ) {
2017-12-13 09:59:38 +00:00
try {
$this -> initQuotas ();
}
catch ( LAMException $e ) {
logNewMessage ( LOG_ERR , $e -> getTitle (), $e -> getMessage ());
}
2019-05-12 16:41:52 +00:00
if ( ! isset ( $this -> quota ) || ! is_array ( $this -> quota )) {
return ;
}
2007-03-04 16:07:12 +00:00
$servers = array_keys ( $this -> quota );
for ( $s = 0 ; $s < sizeof ( $servers ); $s ++ ) {
$server = $servers [ $s ];
$id = $this -> replaceSpecialChars ( $server );
for ( $i = 0 ; $i < sizeof ( $this -> quota [ $server ]); $i ++ ) {
$dir = $this -> quota [ $server ][ $i ][ 0 ];
2019-05-12 16:41:52 +00:00
if ( isset ( $profile [ " quota_softblock_ " . $id . " _ " . $dir ])) {
$this -> quota [ $server ][ $i ][ 2 ] = $profile [ " quota_softblock_ " . $id . " _ " . $dir ][ 0 ];
}
if ( isset ( $profile [ " quota_hardblock_ " . $id . " _ " . $dir ])) {
$this -> quota [ $server ][ $i ][ 3 ] = $profile [ " quota_hardblock_ " . $id . " _ " . $dir ][ 0 ];
}
if ( isset ( $profile [ " quota_softinode_ " . $id . " _ " . $dir ])) {
$this -> quota [ $server ][ $i ][ 6 ] = $profile [ " quota_softinode_ " . $id . " _ " . $dir ][ 0 ];
}
if ( isset ( $profile [ " quota_hardinode_ " . $id . " _ " . $dir ])) {
$this -> quota [ $server ][ $i ][ 7 ] = $profile [ " quota_hardinode_ " . $id . " _ " . $dir ][ 0 ];
}
2007-03-04 16:07:12 +00:00
}
2005-01-22 10:50:10 +00:00
}
}
2005-10-09 18:05:32 +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 ) {
2017-12-13 11:31:26 +00:00
try {
$this -> initQuotas ();
}
catch ( LAMException $e ) {
logNewMessage ( LOG_ERR , $e -> getTitle (), $e -> getMessage ());
return array ();
}
if ( ! isset ( $this -> quota ) || ! is_array ( $this -> quota )) {
return array ();
}
2005-07-16 12:43:48 +00:00
if ( sizeof ( $this -> quota ) > 0 ) {
2015-07-11 09:50:00 +00:00
$pdfTable = new PDFTable ();
2007-03-04 16:07:12 +00:00
// get list of lamdaemon servers
2019-10-17 19:18:13 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
foreach ( $lamdaemonServers as $lamdaemonServer ) {
$server = $lamdaemonServer -> getServer ();
$description = $lamdaemonServer -> getLabel ();
if ( $description != $server ) {
$description = $description . " ( " . $server . " ) " ;
2019-05-12 16:41:52 +00:00
}
if ( ! isset ( $this -> quota [ $server ]) || ( sizeof ( $this -> quota [ $server ]) < 1 )) {
continue ;
}
2015-07-11 09:50:00 +00:00
$pdfRow = new PDFTableRow ();
$pdfRow -> cells [] = new PDFTableCell ( $description , null , null , true );
$pdfTable -> rows [] = $pdfRow ;
$pdfRow = new PDFTableRow ();
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'Mountpoint' ), '28%' , null , true );
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'Soft block' ), '18%' , null , true );
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'Hard block' ), '18%' , null , true );
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'Soft inode' ), '18%' , null , true );
$pdfRow -> cells [] = new PDFTableCell ( _ ( 'Hard inode' ), '18%' , null , true );
$pdfTable -> rows [] = $pdfRow ;
2007-03-04 16:07:12 +00:00
for ( $i = 0 ; $i < sizeof ( $this -> quota [ $server ]); $i ++ ) {
2015-07-11 09:50:00 +00:00
$pdfRow = new PDFTableRow ();
$pdfRow -> cells [] = new PDFTableCell ( $this -> quota [ $server ][ $i ][ 0 ], '28%' );
$pdfRow -> cells [] = new PDFTableCell ( $this -> quota [ $server ][ $i ][ 2 ], '18%' );
$pdfRow -> cells [] = new PDFTableCell ( $this -> quota [ $server ][ $i ][ 3 ], '18%' );
$pdfRow -> cells [] = new PDFTableCell ( $this -> quota [ $server ][ $i ][ 6 ], '18%' );
$pdfRow -> cells [] = new PDFTableCell ( $this -> quota [ $server ][ $i ][ 7 ], '18%' );
$pdfTable -> rows [] = $pdfRow ;
2007-03-04 16:07:12 +00:00
}
2015-07-11 09:50:00 +00:00
$pdfRow = new PDFTableRow ();
$pdfRow -> cells [] = new PDFTableCell ( ' ' );
$pdfTable -> rows [] = $pdfRow ;
2005-07-16 12:43:48 +00:00
}
2015-07-11 09:50:00 +00:00
$return = array ();
$this -> addPDFTable ( $return , 'quotas' , $pdfTable );
return $return ;
2005-07-16 12:43:48 +00:00
}
2005-09-19 18:43:10 +00:00
else {
return array ();
}
2004-05-24 21:39:57 +00:00
}
2004-03-14 17:33:05 +00:00
2005-07-19 12:21:10 +00:00
/**
2017-05-20 08:55:26 +00:00
* { @ inheritDoc }
* @ see baseModule :: get_uploadColumns ()
*/
function get_uploadColumns ( $selectedModules , & $type ) {
2017-12-13 11:31:26 +00:00
try {
$this -> initQuotas ();
}
catch ( LAMException $e ) {
logNewMessage ( LOG_ERR , $e -> getTitle (), $e -> getMessage ());
return array ();
}
if ( ! isset ( $this -> quota ) || ! is_array ( $this -> quota )) {
return array ();
}
2005-07-19 12:21:10 +00:00
$return = array ();
2007-03-04 16:07:12 +00:00
if ( sizeof ( $this -> quota ) > 0 ) {
// get list of lamdaemon servers
2019-10-17 19:18:13 +00:00
$lamdaemonServers = $_SESSION [ 'config' ] -> getConfiguredScriptServers ();
foreach ( $lamdaemonServers as $lamdaemonServer ) {
$server = $lamdaemonServer -> getServer ();
2007-03-04 16:07:12 +00:00
// Get quotas
2017-09-17 07:21:37 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:25:33 +00:00
$remote -> connect ( $lamdaemonServer );
2020-03-19 18:48:38 +00:00
$quotas = $remote -> execute ( implode ( self :: $SPLIT_DELIMITER , array ( " + " , " quota " , " get " , $this -> get_scope ())));
2017-09-17 07:21:37 +00:00
$remote -> disconnect ();
$dirs = explode ( " : " , $quotas );
2007-03-04 16:07:12 +00:00
array_pop ( $dirs ); // remove empty element at the end
for ( $i = 0 ; $i < sizeof ( $dirs ); $i ++ ) {
2020-03-19 18:48:38 +00:00
if ( strpos ( $dirs [ $i ], self :: $QUOTA_PREFIX ) !== 0 ) {
2010-05-14 12:57:00 +00:00
unset ( $dirs [ $i ]);
$i -- ;
continue ;
}
2020-03-19 18:48:38 +00:00
$dirs [ $i ] = substr ( $dirs [ $i ], strlen ( self :: $QUOTA_PREFIX ));
2009-08-14 20:18:08 +00:00
$dirs [ $i ] = explode ( " , " , $dirs [ $i ]);
2007-03-04 16:07:12 +00:00
$dirs [ $i ] = $dirs [ $i ][ 0 ];
}
2010-05-14 12:57:00 +00:00
$dirs = array_values ( $dirs );
2007-03-04 16:07:12 +00:00
for ( $i = 0 ; $i < sizeof ( $dirs ); $i ++ ) {
$return [] = array (
'name' => 'quota_' . $server . ':' . $dirs [ $i ],
'description' => sprintf ( _ ( 'Quota for %s on %s' ), $dirs [ $i ], $server ),
'help' => 'upload' ,
'example' => '2000,2500,3000,3500' );
}
}
2005-07-19 12:21:10 +00:00
}
return $return ;
}
/**
2017-05-10 17:23:28 +00:00
* { @ inheritDoc }
* @ see baseModule :: doUploadPostActions ()
*/
2017-09-02 11:03:36 +00:00
function doUploadPostActions ( & $data , $ids , $failed , & $temp , & $accounts , $selectedModules , $type ) {
2005-07-19 12:21:10 +00:00
$errors = array ();
// first call, get list of user names and quota values
if ( ! isset ( $temp [ 'counter' ])) {
$temp [ 'counter' ] = 0 ;
// create list of quota columns
$temp [ 'quotas' ] = array ();
$columns = array_keys ( $ids );
for ( $i = 0 ; $i < sizeof ( $columns ); $i ++ ) {
if ( strpos ( $columns [ $i ], 'quota_' ) === 0 ) {
$temp [ 'quotas' ][] = substr ( $columns [ $i ], 6 );
}
}
// select user/group name depending on current scope
$temp [ 'accounts' ] = array ();
$col = 'invalid' ;
2019-05-12 16:41:52 +00:00
if ( $this -> get_scope () == 'user' ) {
$col = $ids [ 'posixAccount_userName' ];
}
elseif ( $this -> get_scope () == 'group' ) {
$col = $ids [ 'posixGroup_cn' ];
}
2005-07-19 12:21:10 +00:00
// create list of account names and their quota values
for ( $i = 0 ; $i < sizeof ( $data ); $i ++ ) {
2019-05-12 16:41:52 +00:00
if ( in_array ( $i , $failed )) {
continue ; // ignore failed accounts
}
2005-07-19 12:21:10 +00:00
$name = $data [ $i ][ $col ];
for ( $m = 0 ; $m < sizeof ( $temp [ 'quotas' ]); $m ++ ) {
if ( $data [ $i ][ $ids [ 'quota_' . $temp [ 'quotas' ][ $m ]]] != '' ) {
$parts = explode ( ',' , $data [ $i ][ $ids [ 'quota_' . $temp [ 'quotas' ][ $m ]]]);
// check syntax
if ( sizeof ( $parts ) != 4 ) {
$errMsg = $this -> messages [ 'upload' ][ 0 ];
array_push ( $errMsg , array ( $i , 'quota_' . $temp [ 'quotas' ][ $m ]));
$errors [] = $errMsg ;
continue ;
}
2017-10-21 19:37:40 +00:00
if ( ! get_preg ( $parts [ 0 ], 'quotaNumber' )) {
2005-07-19 12:21:10 +00:00
$errMsg = $this -> messages [ 'softblock' ][ 1 ];
array_push ( $errMsg , array ( $i , 'quota_' . $temp [ 'quotas' ][ $m ]));
$errors [] = $errMsg ;
continue ;
}
2017-10-21 19:37:40 +00:00
if ( ! get_preg ( $parts [ 1 ], 'quotaNumber' )) {
2005-07-19 12:21:10 +00:00
$errMsg = $this -> messages [ 'hardblock' ][ 1 ];
array_push ( $errMsg , array ( $i , 'quota_' . $temp [ 'quotas' ][ $m ]));
$errors [] = $errMsg ;
continue ;
}
2017-10-21 19:37:40 +00:00
if ( ! get_preg ( $parts [ 2 ], 'quotaNumber' )) {
2005-07-19 12:21:10 +00:00
$errMsg = $this -> messages [ 'softinode' ][ 1 ];
array_push ( $errMsg , array ( $i , 'quota_' . $temp [ 'quotas' ][ $m ]));
$errors [] = $errMsg ;
continue ;
}
2017-10-21 19:37:40 +00:00
if ( ! get_preg ( $parts [ 3 ], 'quotaNumber' )) {
2005-07-19 12:21:10 +00:00
$errMsg = $this -> messages [ 'hardinode' ][ 1 ];
array_push ( $errMsg , array ( $i , 'quota_' . $temp [ 'quotas' ][ $m ]));
$errors [] = $errMsg ;
continue ;
}
2019-05-12 16:41:52 +00:00
if ( $this -> getQuotaNumber ( $parts [ 0 ]) > $this -> getQuotaNumber ( $parts [ 1 ])) {
2005-07-19 12:21:10 +00:00
$errMsg = $this -> messages [ 'block_cmp' ][ 1 ];
array_push ( $errMsg , array ( $i , 'quota_' . $temp [ 'quotas' ][ $m ]));
$errors [] = $errMsg ;
continue ;
}
2019-05-12 16:41:52 +00:00
if ( $this -> getQuotaNumber ( $parts [ 2 ]) > $this -> getQuotaNumber ( $parts [ 3 ])) {
2005-07-19 12:21:10 +00:00
$errMsg = $this -> messages [ 'inode_cmp' ][ 1 ];
array_push ( $errMsg , array ( $i , 'quota_' . $temp [ 'quotas' ][ $m ]));
$errors [] = $errMsg ;
continue ;
}
2017-10-21 19:37:40 +00:00
$parts [ 0 ] = $this -> getQuotaNumber ( $parts [ 0 ]);
$parts [ 1 ] = $this -> getQuotaNumber ( $parts [ 1 ]);
$parts [ 2 ] = $this -> getQuotaNumber ( $parts [ 2 ]);
$parts [ 3 ] = $this -> getQuotaNumber ( $parts [ 3 ]);
2005-07-19 12:21:10 +00:00
// save quota settings
$temp [ 'accounts' ][ $name ][ $temp [ 'quotas' ][ $m ]] = $parts ;
}
}
}
return array ( 'status' => 'inProgress' , 'progress' => 5 , 'errors' => $errors );
}
// quotas are ready to set
elseif ( $temp [ 'counter' ] < sizeof ( $temp [ 'accounts' ])) {
$names = array_keys ( $temp [ 'accounts' ]);
$name = $names [ $temp [ 'counter' ]];
$mountPoints = array_keys ( $temp [ 'accounts' ][ $name ]);
// set quota
for ( $m = 0 ; $m < sizeof ( $mountPoints ); $m ++ ) {
2009-08-14 20:18:08 +00:00
$mpParts = explode ( " : " , $mountPoints [ $m ]);
2007-03-04 16:07:12 +00:00
$server = $mpParts [ 0 ];
$dir = $mpParts [ 1 ];
2020-03-19 18:48:38 +00:00
$quotaString = implode ( self :: $SPLIT_DELIMITER , array ( $name , " quota " , " set " , $this -> get_scope (), $dir . ',' .
2009-12-12 17:22:14 +00:00
implode ( ',' , $temp [ 'accounts' ][ $name ][ $mountPoints [ $m ]]) . " \n " ));
2017-09-17 07:21:37 +00:00
$remote = new \LAM\REMOTE\Remote ();
2019-10-23 19:25:33 +00:00
$remoteServer = $_SESSION [ 'config' ] -> getScriptServerByName ( $server );
$remote -> connect ( $remoteServer );
2017-09-17 07:21:37 +00:00
$result = $remote -> execute ( $quotaString );
$remote -> disconnect ();
if ( ! empty ( $result )) {
$parts = explode ( " , " , $result );
if ( $parts [ 0 ] == 'ERROR' ) {
$errors [] = array ( 'ERROR' , $parts [ 1 ], $parts [ 2 ]);
2007-03-04 16:07:12 +00:00
}
}
2005-07-19 12:21:10 +00:00
}
// set counters to next account/mount point
$temp [ 'counter' ] ++ ;
return array (
'status' => 'inProgress' ,
'progress' => 5 + ( 95 * ( $temp [ 'counter' ] / sizeof ( $temp [ 'accounts' ]))),
'errors' => $errors );
}
return array ( 'status' => 'finished' );
}
2015-07-11 09:50:00 +00:00
2014-04-21 19:21:47 +00:00
/**
* Returns a list of modifications which have to be made to the LDAP account .
2015-07-11 09:50:00 +00:00
*
2014-04-21 19:21:47 +00:00
* Calling this method requires the existence of an enclosing { @ link accountContainer } .< br >
* < br >
*
* < 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 is possible to change several DNs ( e . g . create a new user and add him
* to some groups via attribute memberUid ) < br >
* < br >< b > " add " </ b > are attributes which have to be added to the LDAP entry
* < br >< b > " remove " </ b > are attributes which have to be removed from the LDAP entry
* < br >< b > " modify " </ b > are attributes which have to be modified in the LDAP entry
* < br >< b > " notchanged " </ b > are attributes which stay unchanged
* < br >< b > " info " </ b > values with informational value ( e . g . to be used later by pre / postModify actions )
* < br >
* < br > This builds the required comands from $this - attributes and $this -> orig .
2015-07-11 09:50:00 +00:00
*
2014-04-21 19:21:47 +00:00
* @ return array list of modifications
*/
public function save_attributes () {
// no LDAP changes
return $this -> getAccountContainer () -> save_module_attributes ( array (), array ());
}
2004-03-09 12:03:39 +00:00
}
2003-12-30 15:36:30 +00:00
?>