Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Nov 2, 2023
1 parent ea5c367 commit fb438ed
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 73 deletions.
23 changes: 8 additions & 15 deletions lam/lib/modules/posixAccount.inc
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ class posixAccount extends baseModule implements passwordService,AccountStatusPr
/** lamdaemon servers */
private $lamdaemonServers = array();
/** cache for group objects */
private $groupCache = null;
private $groupCache;
/** cache for group of names objects */
private $gonCache = null;
private $gonCache;
/** clear text password */
private $clearTextPassword;
/** caches the list of known UIDs */
private $cachedUIDList = null;
private $cachedUIDList;
/** caches the list of known user names */
private $cachedUserNameList = null;
private $cachedUserNameList;

/** replacements for common umlauts */
private $umlautReplacements = array(
Expand Down Expand Up @@ -634,8 +634,7 @@ class posixAccount extends baseModule implements passwordService,AccountStatusPr
for ($i = 0; $i < sizeof($gonList); $i++) {
$userGoNs[] = $gonList[$i]['dn'];
}
$userGoNs = array_values(array_unique($userGoNs));
return $userGoNs;
return array_values(array_unique($userGoNs));
}

/**
Expand Down Expand Up @@ -1065,11 +1064,9 @@ class posixAccount extends baseModule implements passwordService,AccountStatusPr
// lamdaemon results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
$return[] = $singleresult;
}
}
}
}
}
Expand Down Expand Up @@ -1656,11 +1653,9 @@ class posixAccount extends baseModule implements passwordService,AccountStatusPr
// lamdaemon results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
$return[] = $singleresult;
}
}
}
}
elseif (isset($_POST['form_subpage_' . get_class($this) . '_homedir_delete_' . $i])) {
Expand All @@ -1687,11 +1682,9 @@ class posixAccount extends baseModule implements passwordService,AccountStatusPr
// lamdaemon results
if (!empty($result)) {
$singleresult = explode(",", $result);
if (is_array($singleresult)) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
$return[] = $singleresult;
}
}
}
}
}
Expand Down
31 changes: 14 additions & 17 deletions lam/lib/modules/posixGroup.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use LAM\TYPES\ConfiguredType;
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2007 - 2022 Roland Gruber
2007 - 2023 Roland Gruber
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
Expand Down Expand Up @@ -46,11 +46,11 @@ class posixGroup extends baseModule implements passwordService {
/** password attribute */
protected $passwordAttrName = 'userPassword';
/** cache for existing GID numbers */
private $cachedGIDList = null;
private $cachedGIDList;
/** cache for existing users and their GIDs */
private $cachedUserToGIDList = null;
private $cachedUserToGIDList;
/** cache for existing groups */
private $cachedGroupNameList = null;
private $cachedGroupNameList;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -864,18 +864,15 @@ class posixGroup extends baseModule implements passwordService {
}
}
}
// $uids is always an array but not if no entries were found
if (is_array($gids)) {
// id-number is in use and account is a new account
if ((in_array($this->attributes['gidNumber'][0], $gids)) && $this->orig['gidNumber'][0]=='') {
$errors[] = $this->messages['gidNumber'][4];
unset($this->attributes['gidNumber'][0]);
}
// id-number is in use, account is existing account and id-number is not used by itself
if ((in_array($this->attributes['gidNumber'][0], $gids)) && $this->orig['gidNumber'][0]!='' && ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0]) ) {
$errors[] = $this->messages['gidNumber'][4];
$this->attributes['gidNumber'][0] = $this->orig['gidNumber'][0];
}
// id-number is in use and account is a new account
if ((in_array($this->attributes['gidNumber'][0], $gids)) && ($this->orig['gidNumber'][0] == '')) {
$errors[] = $this->messages['gidNumber'][4];
unset($this->attributes['gidNumber'][0]);
}
// id-number is in use, account is existing account and id-number is changed
if ((in_array($this->attributes['gidNumber'][0], $gids)) && ($this->orig['gidNumber'][0] != '') && ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0]) ) {
$errors[] = $this->messages['gidNumber'][4];
$this->attributes['gidNumber'][0] = $this->orig['gidNumber'][0];
}
}
}
Expand Down Expand Up @@ -1302,7 +1299,7 @@ class posixGroup extends baseModule implements passwordService {
* @param ConfiguredType $type account type
* @return array list of GID numbers
*/
private function getGIDs($type) {
private function getGIDs(ConfiguredType $type): array {
if ($this->cachedGIDList != null) {
return $this->cachedGIDList;
}
Expand Down
11 changes: 4 additions & 7 deletions lam/lib/modules/puppetClient.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use LAM\TYPES\ConfiguredType;
/*
This code is not yet part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2012 - 2022 Roland Gruber
Copyright (C) 2012 - 2023 Roland Gruber
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
Expand Down Expand Up @@ -41,9 +41,9 @@ use LAM\TYPES\ConfiguredType;
class puppetClient extends baseModule {

/** cache for classes */
private $classCache = null;
private $classCache;
/** cache for variables */
private $variablesCache = null;
private $variablesCache;

/**
* Creates a new authorizedServiceObject object.
Expand Down Expand Up @@ -430,9 +430,7 @@ class puppetClient extends baseModule {
$possibleParentNodes = $this->getPossibleParentNodes();
array_unshift($possibleParentNodes, '-');
$possibleParentNodes = array_values($possibleParentNodes);
if (sizeof($possibleParentNodes) > 0) {
$return->add(new htmlResponsiveSelect('puppetClient_parentnode', $possibleParentNodes, array(), _('Parent node'), 'parentnode'), 12);
}
$return->add(new htmlResponsiveSelect('puppetClient_parentnode', $possibleParentNodes, array(), _('Parent node'), 'parentnode'));
return $return;
}

Expand Down Expand Up @@ -470,7 +468,6 @@ class puppetClient extends baseModule {
* @return array parent nodes (e.g. array('node1', 'node2'))
*/
private function getPossibleParentNodes() {
$possibleParentNodes = array();
$searchResult = searchLDAPByAttribute('cn', '*', 'puppetClient', array('cn'), array('host'));
$possibleParentNodes = array();
for ($i = 0; $i < sizeof($searchResult); $i++) {
Expand Down
4 changes: 2 additions & 2 deletions lam/lib/modules/pykotaBillingCode.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2022 Roland Gruber
Copyright (C) 2013 - 2023 Roland Gruber
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
Expand Down Expand Up @@ -41,7 +41,7 @@ class pykotaBillingCode extends baseModule {
const ATTRIBUTES_TO_IGNORE_ON_COPY = array('pykotaBalance', 'pykotaPageCounter', 'pykotaBillingCode');

/** cache for existing codes (array(dn1 => pykotaBillingCode1, dn2 => pykotaBillingCode2)) */
private $codeCache = null;
private $codeCache;

/**
* Returns true if this module can manage accounts of the current type, otherwise false.
Expand Down
6 changes: 3 additions & 3 deletions lam/lib/modules/pykotaGroup.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use \LAM\TYPES\TypeManager;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2022 Roland Gruber
Copyright (C) 2013 - 2023 Roland Gruber
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
Expand Down Expand Up @@ -42,9 +42,9 @@ class pykotaGroup extends baseModule {
const ATTRIBUTES_TO_IGNORE_ON_COPY = array('pykotaGroupName');

/** cache for cn attribute */
private $cnCache = null;
private $cnCache;
/** cache for pykotaGroupName attribute */
private $pykotaGroupNameCache = null;
private $pykotaGroupNameCache;
/** list of limit options label => value */
private $limitOptions;

Expand Down
6 changes: 3 additions & 3 deletions lam/lib/modules/pykotaPrinter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2022 Roland Gruber
Copyright (C) 2013 - 2023 Roland Gruber
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
Expand Down Expand Up @@ -41,9 +41,9 @@ class pykotaPrinter extends baseModule {
const ATTRIBUTES_TO_IGNORE_ON_COPY = array('pykotaPrinterName');

/** cache for existing printers (array(dn => array(cn => ..., description => ...))) */
private $printerCache = null;
private $printerCache;
/** printer group cache */
private $groupCache = null;
private $groupCache;
/** list of pass through options: label => value */
private $passThroughOptions;

Expand Down
6 changes: 3 additions & 3 deletions lam/lib/modules/pykotaUser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use \LAM\TYPES\TypeManager;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2022 Roland Gruber
Copyright (C) 2013 - 2023 Roland Gruber
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
Expand Down Expand Up @@ -45,9 +45,9 @@ class pykotaUser extends baseModule {
'pykotaPayments');

/** cache for uid attribute */
private $uidCache = null;
private $uidCache;
/** cache for pykotaUserName attribute */
private $pykotaUserNameCache = null;
private $pykotaUserNameCache;
/** list of limit options label => value */
private $limitOptions;

Expand Down
6 changes: 3 additions & 3 deletions lam/lib/modules/sambaGroupMapping.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use \LAM\TYPES\TypeManager;
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2007 - 2022 Roland Gruber
2007 - 2023 Roland Gruber
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
Expand Down Expand Up @@ -52,9 +52,9 @@ class sambaGroupMapping extends baseModule {
/** Array of sambaGroupTypes */
private $sambaGroupTypes;
/** cache for domain list */
private $cachedDomainList = null;
private $cachedDomainList;
/** cache for existing Samba entries (array(dn => cn)) */
private $sidCache = null;
private $sidCache;

/**
* Creates a new module for Samba 3 groups.
Expand Down
6 changes: 3 additions & 3 deletions lam/lib/modules/sambaSamAccount.inc
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class sambaSamAccount extends baseModule implements passwordService,AccountStatu
/** specifies if the password should be expired */
private $expirePassword = false;
/** host cache to reduce LDAP queries */
private $cachedHostList = null;
private $cachedHostList;
/** group cache to reduce LDAP queries */
private $cachedGroupSIDList = null;
private $cachedGroupSIDList;
/** cache for domain list */
private $cachedDomainList = null;
private $cachedDomainList;
/** delimiter for remote commands */
private static $SPLIT_DELIMITER = "###x##y##x###";

Expand Down
31 changes: 14 additions & 17 deletions lam/lib/modules/windowsUser.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,32 @@ class windowsUser extends baseModule implements passwordService,AccountStatusPro
/** original group list */
private $groupList_orig = array();
/** cache for groups */
private $groupCache = null;
private $groupCache;
/** host cache to reduce LDAP queries */
private $cachedHostList = null;
private $cachedHostList;
/** option for forcing password change, used in postModifyActions */
private $pwdLastSet = null;
private $pwdLastSet;
/** clear text password */
private $clearTextPassword;
/** cache for departments */
private $departmentCache = null;
private $departmentCache;
/** cache for department numbers */
private $departmentNumberCache = null;
private $departmentNumberCache;
/** organization cache */
private $oCache = null;
private $oCache;
/** organizational unit cache */
private $ouCache = null;
private $ouCache;
/** title cache */
private $titleCache = null;
private $titleCache;
/** employee type cache */
private $employeeTypeCache = null;
private $employeeTypeCache;
/** business category cache */
private $businessCategoryCache = null;
private $businessCategoryCache;

/** cache for user name */
private $cachedUserNameList = null;
private $cachedUserNameList;
/** cache for cn */
private $cachedCnList = null;
private $cachedCnList;


/**
Expand Down Expand Up @@ -1638,11 +1638,9 @@ class windowsUser extends baseModule implements passwordService,AccountStatusPro
switch ($mode) {
case self::DISPLAY_GROUPS_CN:
return $cn;
break;
case self::DISPLAY_GROUPS_DN:
default:
return getAbstractDN($dn);
break;
}
}

Expand Down Expand Up @@ -4945,7 +4943,7 @@ if (interface_exists('\LAM\JOB\Job', false)) {
$now = new DateTime('now', getTimeZone());
$baseDate = $this->getBaseDate($now);
$monthInterval = $this->getMonthInterval($options, $jobID);
if (!$this->shouldRun($pdo, $options, $jobID, $baseDate, $monthInterval)) {
if (!$this->shouldRun($pdo, $jobID, $baseDate, $monthInterval)) {
$this->jobResultLog->logDebug('No run needed yet');
return;
}
Expand Down Expand Up @@ -4975,13 +4973,12 @@ if (interface_exists('\LAM\JOB\Job', false)) {
* Returns if the job should run.
*
* @param $pdo PDO
* @param $options job options
* @param $jobId job id
* @param DateTime $baseDate base date
* @param int $monthInterval month interval
* @return bool should run
*/
private function shouldRun(&$pdo, $options, $jobId, $baseDate, $monthInterval) {
private function shouldRun(&$pdo, $jobId, $baseDate, $monthInterval) {
$dbLastChange = $this->getDBLastPwdChangeTime($jobId, $pdo, $jobId);
if (empty($dbLastChange)) {
return true;
Expand Down

0 comments on commit fb438ed

Please sign in to comment.