refactoring

This commit is contained in:
Roland Gruber 2024-06-11 19:28:49 +02:00
parent 03c7e0868d
commit 22e0f49efb
4 changed files with 548 additions and 545 deletions

View file

@ -2,7 +2,7 @@
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2009 - 2022 Roland Gruber Copyright (C) 2009 - 2024 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -20,29 +20,29 @@
*/ */
/** /**
* Manages the eduPerson extension for user accounts. * Manages the eduPerson extension for user accounts.
* *
* @package modules * @package modules
* @author Roland Gruber * @author Roland Gruber
*/ */
use LAM\TYPES\ConfiguredType; use LAM\TYPES\ConfiguredType;
/** /**
* Manages the eduPerson extension for user accounts. * Manages the eduPerson extension for user accounts.
* *
* @package modules * @package modules
*/ */
class eduPerson extends baseModule { class eduPerson extends baseModule {
/** /**
* These attributes will be ignored by default if a new account is copied from an existing one. * These attributes will be ignored by default if a new account is copied from an existing one.
*/ */
const ATTRIBUTES_TO_IGNORE_ON_COPY = array('eduPersonNickname', 'eduPersonPrincipalName'); const ATTRIBUTES_TO_IGNORE_ON_COPY = ['eduPersonNickname', 'eduPersonPrincipalName'];
/** possible affiliation types */ /** possible affiliation types */
private $affiliationTypes = array('faculty', 'student', 'staff', 'alum', private $affiliationTypes = ['faculty', 'student', 'staff', 'alum',
'member', 'affiliate', 'employee', 'library-walk-in'); 'member', 'affiliate', 'employee', 'library-walk-in'];
/** /**
* Creates a new eduPerson object. * Creates a new eduPerson object.
@ -60,7 +60,7 @@ class eduPerson extends baseModule {
* @return boolean true if module fits * @return boolean true if module fits
*/ */
public function can_manage() { public function can_manage() {
return in_array($this->get_scope(), array('user')); return in_array($this->get_scope(), ['user']);
} }
/** /**
@ -77,157 +77,157 @@ class eduPerson extends baseModule {
// alias name // alias name
$return["alias"] = _("EDU person"); $return["alias"] = _("EDU person");
// module dependencies // module dependencies
$return['dependencies'] = array('depends' => [], 'conflicts' => []); $return['dependencies'] = ['depends' => [], 'conflicts' => []];
// managed object classes // managed object classes
$return['objectClasses'] = array('eduPerson'); $return['objectClasses'] = ['eduPerson'];
// managed attributes // managed attributes
$return['attributes'] = array('eduPersonAffiliation', 'eduPersonNickname', $return['attributes'] = ['eduPersonAffiliation', 'eduPersonNickname',
'eduPersonOrgDN', 'eduPersonOrgUnitDN', 'eduPersonOrgDN', 'eduPersonOrgUnitDN',
'eduPersonPrimaryAffiliation', 'eduPersonPrincipalName', 'eduPersonPrimaryAffiliation', 'eduPersonPrincipalName',
'eduPersonEntitlement', 'eduPersonPrimaryOrgUnitDN', 'eduPersonEntitlement', 'eduPersonPrimaryOrgUnitDN',
'eduPersonScopedAffiliation', 'eduPersonAssurance'); 'eduPersonScopedAffiliation', 'eduPersonAssurance'];
// RDN attribute // RDN attribute
$return["RDN"] = array('eduPersonPrincipalName' => 'low'); $return["RDN"] = ['eduPersonPrincipalName' => 'low'];
// help Entries // help Entries
$return['help'] = array( $return['help'] = [
'primaryAffiliation' => array( 'primaryAffiliation' => [
"Headline" => _("Primary affiliation"), 'attr' => 'eduPersonPrimaryAffiliation', "Headline" => _("Primary affiliation"), 'attr' => 'eduPersonPrimaryAffiliation',
"Text" => _("Specifies the person's primary relationship to the institution in broad categories such as student, faculty, staff, alum, etc.") "Text" => _("Specifies the person's primary relationship to the institution in broad categories such as student, faculty, staff, alum, etc.")
), ],
'scopedAffiliation' => array( 'scopedAffiliation' => [
"Headline" => _("Scoped affiliations"), 'attr' => 'eduPersonScopedAffiliation', "Headline" => _("Scoped affiliations"), 'attr' => 'eduPersonScopedAffiliation',
"Text" => _("Specifies the person's affiliation within a particular security domain in broad categories such as student, faculty, staff, alum, etc.") "Text" => _("Specifies the person's affiliation within a particular security domain in broad categories such as student, faculty, staff, alum, etc.")
), ],
'scopedAffiliationUpload' => array( 'scopedAffiliationUpload' => [
"Headline" => _("Scoped affiliations"), 'attr' => 'eduPersonScopedAffiliation', "Headline" => _("Scoped affiliations"), 'attr' => 'eduPersonScopedAffiliation',
"Text" => _("Specifies the person's affiliation within a particular security domain in broad categories such as student, faculty, staff, alum, etc.") . " " . "Text" => _("Specifies the person's affiliation within a particular security domain in broad categories such as student, faculty, staff, alum, etc.") . " " .
_('Multiple values are separated by comma.') _('Multiple values are separated by comma.')
), ],
'eduPersonNickname' => array( 'eduPersonNickname' => [
"Headline" => _("Nick names"), 'attr' => 'eduPersonNickname', "Headline" => _("Nick names"), 'attr' => 'eduPersonNickname',
"Text" => _("This is a list of nick names for this user.") "Text" => _("This is a list of nick names for this user.")
), ],
'affiliation' => array( 'affiliation' => [
"Headline" => _("Affiliations"), 'attr' => 'eduPersonAffiliation', "Headline" => _("Affiliations"), 'attr' => 'eduPersonAffiliation',
"Text" => _("Specifies the person's relationships to the institution in broad categories such as student, faculty, staff, alum, etc.") "Text" => _("Specifies the person's relationships to the institution in broad categories such as student, faculty, staff, alum, etc.")
), ],
'affiliationUpload' => array( 'affiliationUpload' => [
"Headline" => _("Affiliations"), 'attr' => 'eduPersonAffiliation', "Headline" => _("Affiliations"), 'attr' => 'eduPersonAffiliation',
"Text" => _("Specifies the person's relationships to the institution in broad categories such as student, faculty, staff, alum, etc.") . " " . "Text" => _("Specifies the person's relationships to the institution in broad categories such as student, faculty, staff, alum, etc.") . " " .
_('Multiple values are separated by comma.') _('Multiple values are separated by comma.')
), ],
'eduPersonPrincipalName' => array( 'eduPersonPrincipalName' => [
"Headline" => _("Principal name"), 'attr' => 'eduPersonPrincipalName', "Headline" => _("Principal name"), 'attr' => 'eduPersonPrincipalName',
"Text" => _("The \"NetID\" of the person for the purposes of inter-institutional authentication. It should be represented in the form \"user@scope\" where scope defines a local security domain.") "Text" => _("The \"NetID\" of the person for the purposes of inter-institutional authentication. It should be represented in the form \"user@scope\" where scope defines a local security domain.")
), ],
'eduPersonEntitlement' => array( 'eduPersonEntitlement' => [
"Headline" => _("Entitlements"), 'attr' => 'eduPersonEntitlement', "Headline" => _("Entitlements"), 'attr' => 'eduPersonEntitlement',
"Text" => _("URI (either URN or URL) that indicates a set of rights to specific resources.") "Text" => _("URI (either URN or URL) that indicates a set of rights to specific resources.")
), ],
'entitlementUpload' => array( 'entitlementUpload' => [
"Headline" => _("Entitlements"), 'attr' => 'eduPersonEntitlement', "Headline" => _("Entitlements"), 'attr' => 'eduPersonEntitlement',
"Text" => _("URI (either URN or URL) that indicates a set of rights to specific resources.") . " " . _('Multiple values are separated by comma.') "Text" => _("URI (either URN or URL) that indicates a set of rights to specific resources.") . " " . _('Multiple values are separated by comma.')
), ],
'eduPersonOrgDN' => array( 'eduPersonOrgDN' => [
"Headline" => _("Organisation"), 'attr' => 'eduPersonOrgDN', "Headline" => _("Organisation"), 'attr' => 'eduPersonOrgDN',
"Text" => _("The DN of the directory entry representing the institution with which the person is associated.") "Text" => _("The DN of the directory entry representing the institution with which the person is associated.")
), ],
'eduPersonPrimaryOrgUnitDN' => array( 'eduPersonPrimaryOrgUnitDN' => [
"Headline" => _("Primary organisational unit"), 'attr' => 'eduPersonPrimaryOrgUnitDN', "Headline" => _("Primary organisational unit"), 'attr' => 'eduPersonPrimaryOrgUnitDN',
"Text" => _("The DN of the directory entry representing the person's primary organisational unit.") "Text" => _("The DN of the directory entry representing the person's primary organisational unit.")
), ],
'eduPersonOrgUnitDN' => array( 'eduPersonOrgUnitDN' => [
"Headline" => _("Organisational units"), 'attr' => 'eduPersonOrgUnitDN', "Headline" => _("Organisational units"), 'attr' => 'eduPersonOrgUnitDN',
"Text" => _("The DNs of the directory entries representing the person's organisational units.") "Text" => _("The DNs of the directory entries representing the person's organisational units.")
), ],
'orgUnitDNUpload' => array( 'orgUnitDNUpload' => [
"Headline" => _("Organisational units"), 'attr' => 'eduPersonOrgUnitDN', "Headline" => _("Organisational units"), 'attr' => 'eduPersonOrgUnitDN',
"Text" => _("The DNs of the directory entries representing the person's organisational units.") . ' ' . _('Multiple values are separated by comma.') "Text" => _("The DNs of the directory entries representing the person's organisational units.") . ' ' . _('Multiple values are separated by comma.')
), ],
'eduPersonAssurance' => array( 'eduPersonAssurance' => [
"Headline" => _('Assurance profiles'), 'attr' => 'eduPersonAssurance', "Headline" => _('Assurance profiles'), 'attr' => 'eduPersonAssurance',
"Text" => _('Assurance profiles are the set of standards that are met by an identity assertion.') "Text" => _('Assurance profiles are the set of standards that are met by an identity assertion.')
), ],
'eduPersonAssuranceUpload' => array( 'eduPersonAssuranceUpload' => [
"Headline" => _('Assurance profiles'), 'attr' => 'eduPersonAssurance', "Headline" => _('Assurance profiles'), 'attr' => 'eduPersonAssurance',
"Text" => _('Assurance profiles are the set of standards that are met by an identity assertion.') . " " . _('Multiple values are separated by comma.') "Text" => _('Assurance profiles are the set of standards that are met by an identity assertion.') . " " . _('Multiple values are separated by comma.')
), ],
'autoAdd' => array( 'autoAdd' => [
"Headline" => _("Automatically add this extension"), "Headline" => _("Automatically add this extension"),
"Text" => _("This will enable the extension automatically if this profile is loaded.") "Text" => _("This will enable the extension automatically if this profile is loaded.")
)); ]];
// profile options // profile options
$profileContainer = new htmlResponsiveRow(); $profileContainer = new htmlResponsiveRow();
$profileContainer->add(new htmlResponsiveInputCheckbox('eduPerson_addExt', false, _('Automatically add this extension'), 'autoAdd'), 12); $profileContainer->add(new htmlResponsiveInputCheckbox('eduPerson_addExt', false, _('Automatically add this extension'), 'autoAdd'), 12);
$return['profile_options'] = $profileContainer; $return['profile_options'] = $profileContainer;
// upload fields // upload fields
$return['upload_columns'] = array( $return['upload_columns'] = [
array( [
'name' => 'eduPerson_principalName', 'name' => 'eduPerson_principalName',
'description' => _('Principal name'), 'description' => _('Principal name'),
'help' => 'eduPersonPrincipalName', 'help' => 'eduPersonPrincipalName',
'example' => _('user@company.com'), 'example' => _('user@company.com'),
'unique' => true 'unique' => true
), ],
array( [
'name' => 'eduPerson_primaryAffiliation', 'name' => 'eduPerson_primaryAffiliation',
'description' => _('Primary affiliation'), 'description' => _('Primary affiliation'),
'help' => 'primaryAffiliation', 'help' => 'primaryAffiliation',
'example' => 'student', 'example' => 'student',
'values' => implode(", ", $this->affiliationTypes) 'values' => implode(", ", $this->affiliationTypes)
), ],
array( [
'name' => 'eduPerson_scopedAffiliation', 'name' => 'eduPerson_scopedAffiliation',
'description' => _('Scoped affiliations'), 'description' => _('Scoped affiliations'),
'help' => 'scopedAffiliationUpload', 'help' => 'scopedAffiliationUpload',
'example' => 'student@domain, student@domain2' 'example' => 'student@domain, student@domain2'
), ],
array( [
'name' => 'eduPerson_affiliation', 'name' => 'eduPerson_affiliation',
'description' => _('Affiliations'), 'description' => _('Affiliations'),
'help' => 'affiliationUpload', 'help' => 'affiliationUpload',
'example' => 'student, employee', 'example' => 'student, employee',
'values' => implode(", ", $this->affiliationTypes) 'values' => implode(", ", $this->affiliationTypes)
), ],
array( [
'name' => 'eduPerson_nickname', 'name' => 'eduPerson_nickname',
'description' => _('Nick names'), 'description' => _('Nick names'),
'help' => 'eduPersonNickname', 'help' => 'eduPersonNickname',
'example' => _('Steve, Stevo') 'example' => _('Steve, Stevo')
), ],
array( [
'name' => 'eduPerson_entitlement', 'name' => 'eduPerson_entitlement',
'description' => _('Entitlements'), 'description' => _('Entitlements'),
'help' => 'entitlementUpload', 'help' => 'entitlementUpload',
'example' => 'http://xstor.com/contracts/HEd123' 'example' => 'http://xstor.com/contracts/HEd123'
), ],
array( [
'name' => 'eduPerson_orgDN', 'name' => 'eduPerson_orgDN',
'description' => _('Organisation'), 'description' => _('Organisation'),
'help' => 'eduPersonOrgDN', 'help' => 'eduPersonOrgDN',
'example' => _('ou=accounts,dc=yourdomain,dc=org') 'example' => _('ou=accounts,dc=yourdomain,dc=org')
), ],
array( [
'name' => 'eduPerson_primaryOrgUnitDN', 'name' => 'eduPerson_primaryOrgUnitDN',
'description' => _('Primary organisational unit'), 'description' => _('Primary organisational unit'),
'help' => 'eduPersonPrimaryOrgUnitDN', 'help' => 'eduPersonPrimaryOrgUnitDN',
'example' => _('ou=accounts,dc=yourdomain,dc=org') 'example' => _('ou=accounts,dc=yourdomain,dc=org')
), ],
array( [
'name' => 'eduPerson_orgUnitDN', 'name' => 'eduPerson_orgUnitDN',
'description' => _('Organisational units'), 'description' => _('Organisational units'),
'help' => 'orgUnitDNUpload', 'help' => 'orgUnitDNUpload',
'example' => _('ou=accounts,dc=yourdomain,dc=org') 'example' => _('ou=accounts,dc=yourdomain,dc=org')
), ],
array( [
'name' => 'eduPerson_assurance', 'name' => 'eduPerson_assurance',
'description' => _('Assurance profiles'), 'description' => _('Assurance profiles'),
'help' => 'eduPersonAssuranceUpload', 'help' => 'eduPersonAssuranceUpload',
'example' => 'urn:mace:incommon:IAQ:sample, http://idm.example.org/LOA#sample' 'example' => 'urn:mace:incommon:IAQ:sample, http://idm.example.org/LOA#sample'
), ],
); ];
// available PDF fields // available PDF fields
$return['PDF_fields'] = array( $return['PDF_fields'] = [
'affiliation' => _('Affiliations'), 'affiliation' => _('Affiliations'),
'nickname' => _('Nick names'), 'nickname' => _('Nick names'),
'orgDN' => _('Organisation'), 'orgDN' => _('Organisation'),
@ -238,7 +238,7 @@ class eduPerson extends baseModule {
'primaryOrgUnitDN' => _('Primary organisational unit'), 'primaryOrgUnitDN' => _('Primary organisational unit'),
'scopedAffiliation' => _('Scoped affiliations'), 'scopedAffiliation' => _('Scoped affiliations'),
'eduPersonAssurance' => _('Assurance profiles'), 'eduPersonAssurance' => _('Assurance profiles'),
); ];
return $return; return $return;
} }
@ -246,23 +246,23 @@ class eduPerson extends baseModule {
* This function fills the error message array with messages * This function fills the error message array with messages
*/ */
function load_Messages() { function load_Messages() {
$this->messages['eduPersonPrincipalName'][0] = array('ERROR', _('Principal name is invalid!')); $this->messages['eduPersonPrincipalName'][0] = ['ERROR', _('Principal name is invalid!')];
$this->messages['eduPersonPrincipalName'][1] = array('ERROR', _('Account %s:') . ' eduPerson_principalName', _('Principal name is invalid!')); $this->messages['eduPersonPrincipalName'][1] = ['ERROR', _('Account %s:') . ' eduPerson_principalName', _('Principal name is invalid!')];
$this->messages['eduPersonOrgDN'][0] = array('ERROR', _('Please enter a valid DN in the field:') . ' ' . _("Organisation")); $this->messages['eduPersonOrgDN'][0] = ['ERROR', _('Please enter a valid DN in the field:') . ' ' . _("Organisation")];
$this->messages['eduPersonOrgDN'][1] = array('ERROR', _('Account %s:') . ' eduPerson_orgDN', _('This is not a valid DN!')); $this->messages['eduPersonOrgDN'][1] = ['ERROR', _('Account %s:') . ' eduPerson_orgDN', _('This is not a valid DN!')];
$this->messages['eduPersonPrimaryOrgUnitDN'][0] = array('ERROR', _('Please enter a valid DN in the field:') . ' ' . _("Primary organisational unit")); $this->messages['eduPersonPrimaryOrgUnitDN'][0] = ['ERROR', _('Please enter a valid DN in the field:') . ' ' . _("Primary organisational unit")];
$this->messages['eduPersonPrimaryOrgUnitDN'][1] = array('ERROR', _('Account %s:') . ' eduPerson_primaryOrgUnitDN', _('This is not a valid DN!')); $this->messages['eduPersonPrimaryOrgUnitDN'][1] = ['ERROR', _('Account %s:') . ' eduPerson_primaryOrgUnitDN', _('This is not a valid DN!')];
$this->messages['eduPersonOrgUnitDN'][0] = array('ERROR', _('Organisational units contains an invalid entry.')); $this->messages['eduPersonOrgUnitDN'][0] = ['ERROR', _('Organisational units contains an invalid entry.')];
$this->messages['eduPersonOrgUnitDN'][1] = array('ERROR', _('Account %s:') . ' eduPerson_orgUnitDN', _('This is not a valid list of DNs!')); $this->messages['eduPersonOrgUnitDN'][1] = ['ERROR', _('Account %s:') . ' eduPerson_orgUnitDN', _('This is not a valid list of DNs!')];
$this->messages['primaryAffiliation'][0] = array('ERROR', _('Account %s:') . ' eduPerson_primaryAffiliation', _('Please enter a valid primary affiliation.')); $this->messages['primaryAffiliation'][0] = ['ERROR', _('Account %s:') . ' eduPerson_primaryAffiliation', _('Please enter a valid primary affiliation.')];
$this->messages['scopedAffiliation'][0] = array('ERROR', _('Account %s:') . ' eduPerson_scopedAffiliation', _('Please enter a valid scoped affiliation.')); $this->messages['scopedAffiliation'][0] = ['ERROR', _('Account %s:') . ' eduPerson_scopedAffiliation', _('Please enter a valid scoped affiliation.')];
$this->messages['affiliation'][0] = array('ERROR', _('Account %s:') . ' eduPerson_affiliation', _('Please enter a valid list of affiliations.')); $this->messages['affiliation'][0] = ['ERROR', _('Account %s:') . ' eduPerson_affiliation', _('Please enter a valid list of affiliations.')];
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []) : void { public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void {
$attributesToIgnore = array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY); $attributesToIgnore = array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY);
parent::loadAttributesFromAccountCopy($ldapAttributes, $attributesToIgnore); parent::loadAttributesFromAccountCopy($ldapAttributes, $attributesToIgnore);
} }
@ -292,7 +292,7 @@ class eduPerson extends baseModule {
// primary affiliation // primary affiliation
$primaryAffiliation = []; $primaryAffiliation = [];
if (isset($this->attributes['eduPersonPrimaryAffiliation'][0])) { if (isset($this->attributes['eduPersonPrimaryAffiliation'][0])) {
$primaryAffiliation = array($this->attributes['eduPersonPrimaryAffiliation'][0]); $primaryAffiliation = [$this->attributes['eduPersonPrimaryAffiliation'][0]];
} }
$return->add(new htmlResponsiveSelect('primaryAffiliation', $this->affiliationTypes, $primaryAffiliation, _('Primary affiliation'), 'primaryAffiliation'), 12); $return->add(new htmlResponsiveSelect('primaryAffiliation', $this->affiliationTypes, $primaryAffiliation, _('Primary affiliation'), 'primaryAffiliation'), 12);
// scoped affiliations // scoped affiliations
@ -303,7 +303,7 @@ class eduPerson extends baseModule {
if (isset($this->attributes['eduPersonScopedAffiliation'][0])) { if (isset($this->attributes['eduPersonScopedAffiliation'][0])) {
for ($i = 0; $i < sizeof($this->attributes['eduPersonScopedAffiliation']); $i++) { for ($i = 0; $i < sizeof($this->attributes['eduPersonScopedAffiliation']); $i++) {
$parts = explode('@', $this->attributes['eduPersonScopedAffiliation'][$i]); $parts = explode('@', $this->attributes['eduPersonScopedAffiliation'][$i]);
$scopedAffiliationPrefix = array($parts[0]); $scopedAffiliationPrefix = [$parts[0]];
$scopedAffiliation = substr($this->attributes['eduPersonScopedAffiliation'][$i], strlen($parts[0]) + 1); $scopedAffiliation = substr($this->attributes['eduPersonScopedAffiliation'][$i], strlen($parts[0]) + 1);
$scopedAffiliationContainer = new htmlTable(); $scopedAffiliationContainer = new htmlTable();
$scopedAffiliationContainer->addElement(new htmlSelect('scopedAffiliationPrefix' . $i, $this->affiliationTypes, $scopedAffiliationPrefix)); $scopedAffiliationContainer->addElement(new htmlSelect('scopedAffiliationPrefix' . $i, $this->affiliationTypes, $scopedAffiliationPrefix));
@ -329,7 +329,7 @@ class eduPerson extends baseModule {
$affiliations = new htmlTable(); $affiliations = new htmlTable();
if (isset($this->attributes['eduPersonAffiliation'][0])) { if (isset($this->attributes['eduPersonAffiliation'][0])) {
for ($i = 0; $i < sizeof($this->attributes['eduPersonAffiliation']); $i++) { for ($i = 0; $i < sizeof($this->attributes['eduPersonAffiliation']); $i++) {
$affiliations->addElement(new htmlSelect('affiliation' . $i, $this->affiliationTypes, array($this->attributes['eduPersonAffiliation'][$i]))); $affiliations->addElement(new htmlSelect('affiliation' . $i, $this->affiliationTypes, [$this->attributes['eduPersonAffiliation'][$i]]));
$affiliationButton = new htmlButton('delAffiliation' . $i, 'del.svg', true); $affiliationButton = new htmlButton('delAffiliation' . $i, 'del.svg', true);
$affiliations->addElement($affiliationButton); $affiliations->addElement($affiliationButton);
if ($i === 0) { if ($i === 0) {
@ -364,7 +364,7 @@ class eduPerson extends baseModule {
// remove button // remove button
$return->addVerticalSpacer('2rem'); $return->addVerticalSpacer('2rem');
$remButton = new htmlButton('remObjectClass', _('Remove EDU person extension')); $remButton = new htmlButton('remObjectClass', _('Remove EDU person extension'));
$remButton->setCSSClasses(array('lam-danger')); $remButton->setCSSClasses(['lam-danger']);
$return->add($remButton, 12, 12, 12, 'text-center'); $return->add($remButton, 12, 12, 12, 'text-center');
} }
else { else {
@ -385,7 +385,7 @@ class eduPerson extends baseModule {
return []; return [];
} }
elseif (isset($_POST['remObjectClass'])) { elseif (isset($_POST['remObjectClass'])) {
$this->attributes['objectClass'] = array_delete(array('eduPerson'), $this->attributes['objectClass']); $this->attributes['objectClass'] = array_delete(['eduPerson'], $this->attributes['objectClass']);
for ($i = 0; $i < sizeof($this->meta['attributes']); $i++) { for ($i = 0; $i < sizeof($this->meta['attributes']); $i++) {
if (isset($this->attributes[$this->meta['attributes'][$i]])) { if (isset($this->attributes[$this->meta['attributes'][$i]])) {
unset($this->attributes[$this->meta['attributes'][$i]]); unset($this->attributes[$this->meta['attributes'][$i]]);
@ -474,7 +474,9 @@ class eduPerson extends baseModule {
$messages = []; $messages = [];
for ($i = 0; $i < sizeof($rawAccounts); $i++) { for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class // add object class
if (!in_array("eduPerson", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "eduPerson"; if (!in_array("eduPerson", $partialAccounts[$i]['objectClass'])) {
$partialAccounts[$i]['objectClass'][] = "eduPerson";
}
// principal name // principal name
if ($rawAccounts[$i][$ids['eduPerson_principalName']] != "") { if ($rawAccounts[$i][$ids['eduPerson_principalName']] != "") {
if (!preg_match('/^[0-9a-z_\\.@-]+$/i', $rawAccounts[$i][$ids['eduPerson_principalName']])) { if (!preg_match('/^[0-9a-z_\\.@-]+$/i', $rawAccounts[$i][$ids['eduPerson_principalName']])) {
@ -570,7 +572,7 @@ class eduPerson extends baseModule {
* @inheritDoc * @inheritDoc
*/ */
public function getListAttributeDescriptions(ConfiguredType $type): array { public function getListAttributeDescriptions(ConfiguredType $type): array {
return array( return [
'edupersonaffiliation' => _('Affiliations'), 'edupersonaffiliation' => _('Affiliations'),
'edupersonnickname' => _('Nick names'), 'edupersonnickname' => _('Nick names'),
'edupersonorgdn' => _('Organisation'), 'edupersonorgdn' => _('Organisation'),
@ -581,7 +583,7 @@ class eduPerson extends baseModule {
'edupersonprimaryorgunitdn' => _('Primary organisational unit'), 'edupersonprimaryorgunitdn' => _('Primary organisational unit'),
'edupersonscopedaffiliation' => _('Scoped affiliations'), 'edupersonscopedaffiliation' => _('Scoped affiliations'),
'edupersonassurance' => _('Assurance profiles'), 'edupersonassurance' => _('Assurance profiles'),
); ];
} }
} }

View file

@ -1,4 +1,5 @@
<?php <?php
use \LAM\PDF\PDFTable; use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell; use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow; use \LAM\PDF\PDFTableRow;
@ -8,7 +9,7 @@ use LAM\TYPES\ConfiguredType;
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2008 Thomas Manninger Copyright (C) 2008 Thomas Manninger
2008 - 2023 Roland Gruber 2008 - 2024 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -28,20 +29,19 @@ use LAM\TYPES\ConfiguredType;
/** /**
* Manages DHCP host entries. * Manages DHCP host entries.
* *
* @package modules * @package modules
* *
* @author Thomas Manninger * @author Thomas Manninger
* @author Roland Gruber * @author Roland Gruber
*/ */
/** /**
* Manages DHCP host entries. * Manages DHCP host entries.
* *
* @package modules * @package modules
*/ */
class fixed_ip extends baseModule { class fixed_ip extends baseModule {
/** fixed ips */ /** fixed ips */
@ -71,7 +71,7 @@ class fixed_ip extends baseModule {
* @return boolean true if module fits * @return boolean true if module fits
*/ */
public function can_manage() { public function can_manage() {
return in_array($this->get_scope(), array('dhcp')); return in_array($this->get_scope(), ['dhcp']);
} }
/** /**
@ -90,40 +90,40 @@ class fixed_ip extends baseModule {
// icon // icon
$return['icon'] = 'computer.svg'; $return['icon'] = 'computer.svg';
// RDN attribute // RDN attribute
$return["RDN"] = array("cn" => "high"); $return["RDN"] = ["cn" => "high"];
// LDAP filter // LDAP filter
$return["ldap_filter"] = []; $return["ldap_filter"] = [];
// module dependencies // module dependencies
$return['dependencies'] = array('depends' => array('dhcp_settings'), 'conflicts' => []); $return['dependencies'] = ['depends' => ['dhcp_settings'], 'conflicts' => []];
// managed object classes // managed object classes
$return['objectClasses'] = []; $return['objectClasses'] = [];
// managed attributes // managed attributes
$return['attributes'] = array('dhcpOption'); $return['attributes'] = ['dhcpOption'];
// help Entries // help Entries
$return['help'] = array( $return['help'] = [
'pc' => array( 'pc' => [
"Headline" => _("PC name"), 'attr' => 'dhcpOption, host-name', "Headline" => _("PC name"), 'attr' => 'dhcpOption, host-name',
"Text" => _("The name of the PC.") "Text" => _("The name of the PC.")
), ],
'mac' => array( 'mac' => [
"Headline" => _("MAC address"), 'attr' => 'dhcpHWAddress', "Headline" => _("MAC address"), 'attr' => 'dhcpHWAddress',
"Text" => _("The MAC address of the PC. Example: 11:22:33:44:55:aa") "Text" => _("The MAC address of the PC. Example: 11:22:33:44:55:aa")
), ],
'ip' => array( 'ip' => [
"Headline" => _("IP address"), 'attr' => 'dhcpStatements, fixed-address', "Headline" => _("IP address"), 'attr' => 'dhcpStatements, fixed-address',
"Text" => _("The IP address of the PC.") "Text" => _("The IP address of the PC.")
), ],
'description' => array( 'description' => [
"Headline" => _("Description"), 'attr' => 'dhcpComments', "Headline" => _("Description"), 'attr' => 'dhcpComments',
"Text" => _("Optional description for the PC.") "Text" => _("Optional description for the PC.")
), ],
'active' => array( 'active' => [
"Headline" => _("Active"), 'attr' => 'dhcpStatements, booting', "Headline" => _("Active"), 'attr' => 'dhcpStatements, booting',
"Text" => _("Inactive hosts will not be able to get an address from the DHCP server.") "Text" => _("Inactive hosts will not be able to get an address from the DHCP server.")
), ],
); ];
// available PDF fields // available PDF fields
$return['PDF_fields'] = array('IPlist' => _('IP list')); $return['PDF_fields'] = ['IPlist' => _('IP list')];
return $return; return $return;
} }
@ -131,7 +131,7 @@ class fixed_ip extends baseModule {
* This function fills the error message array with messages. * This function fills the error message array with messages.
*/ */
public function load_Messages() { public function load_Messages() {
$this->messages['errors'][0] = array('ERROR', _('One or more errors occurred. The invalid fields are marked.'), ''); $this->messages['errors'][0] = ['ERROR', _('One or more errors occurred. The invalid fields are marked.'), ''];
} }
/** /**
@ -184,7 +184,7 @@ class fixed_ip extends baseModule {
$invalid = true; $invalid = true;
} }
foreach($ex AS $value) { foreach ($ex as $value) {
if (!preg_match("/[0-9a-fA-F][0-9a-fA-F]/", $value) || strlen($value) != "2") { if (!preg_match("/[0-9a-fA-F][0-9a-fA-F]/", $value) || strlen($value) != "2") {
$invalid = true; $invalid = true;
} }
@ -202,17 +202,17 @@ class fixed_ip extends baseModule {
public function reload_ips() { public function reload_ips() {
$ip_edit = false; // IPs were edited? $ip_edit = false; // IPs were edited?
// Only run it, when ranges already exists: // Only run it, when ranges already exists:
if(is_array($this->fixed_ip)) { if (is_array($this->fixed_ip)) {
$ex_subnet = explode(".", $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]); $ex_subnet = explode(".", $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]);
foreach ($this->fixed_ip AS $id=>$arr) { foreach ($this->fixed_ip as $id => $arr) {
if (!empty($this->fixed_ip[$id]['ip']) && !range::check_subnet_range($this->fixed_ip[$id]['ip'], if (!empty($this->fixed_ip[$id]['ip']) && !range::check_subnet_range($this->fixed_ip[$id]['ip'],
$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0], $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0],
$this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'))) { $this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'))) {
// Range anpassen: // Range anpassen:
$ex = explode(".", $this->fixed_ip[$id]['ip']); $ex = explode(".", $this->fixed_ip[$id]['ip']);
$tmp = $this->fixed_ip[$id]['ip']; $tmp = $this->fixed_ip[$id]['ip'];
$this->fixed_ip[$id]['ip'] = $ex_subnet['0'].".".$ex_subnet['1'].".".$ex_subnet['2'].".".$ex['3']; $this->fixed_ip[$id]['ip'] = $ex_subnet['0'] . "." . $ex_subnet['1'] . "." . $ex_subnet['2'] . "." . $ex['3'];
if ($tmp!=$this->fixed_ip[$id]['ip']) { if ($tmp != $this->fixed_ip[$id]['ip']) {
$ip_edit = true; $ip_edit = true;
} }
} }
@ -228,7 +228,7 @@ class fixed_ip extends baseModule {
*/ */
function load_attributes($attr) { function load_attributes($attr) {
if (!$this->isRootNode()) { if (!$this->isRootNode()) {
$searchAttributes = array('cn', 'dhcphwaddress', 'dhcpstatements', 'dhcpcomments'); $searchAttributes = ['cn', 'dhcphwaddress', 'dhcpstatements', 'dhcpcomments'];
$entries = searchLDAP($this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', $searchAttributes); $entries = searchLDAP($this->getAccountContainer()->dn_orig, '(objectClass=dhcpHost)', $searchAttributes);
for ($i = 0; $i < sizeof($entries); $i++) { for ($i = 0; $i < sizeof($entries); $i++) {
$dhcphwaddress = explode(" ", $entries[$i]['dhcphwaddress'][0]); $dhcphwaddress = explode(" ", $entries[$i]['dhcphwaddress'][0]);
@ -294,14 +294,14 @@ class fixed_ip extends baseModule {
$this->reset_overlapped_ip(); $this->reset_overlapped_ip();
if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]!="") { if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0] != "") {
$error = false; // errors by process_attributes()? $error = false; // errors by process_attributes()?
$pcs = []; $pcs = [];
foreach($this->fixed_ip AS $id=>$arr) { foreach ($this->fixed_ip as $id => $arr) {
// Check if ip is to drop // Check if ip is to drop
if (isset($_POST['drop_ip_'.$id])) { if (isset($_POST['drop_ip_' . $id])) {
// Drop ip: // Drop ip:
unset($this->fixed_ip[$id]); unset($this->fixed_ip[$id]);
continue; continue;
@ -314,61 +314,61 @@ class fixed_ip extends baseModule {
if ($invalid) { if ($invalid) {
$error = true; $error = true;
} }
$this->fixed_ip[$id]['mac'] = $_POST['mac_'.$id]; $this->fixed_ip[$id]['mac'] = $_POST['mac_' . $id];
// description // description
if (!get_preg($_POST['description_'.$id], 'ascii')) { if (!get_preg($_POST['description_' . $id], 'ascii')) {
$error = true; $error = true;
} }
$this->fixed_ip[$id]['description'] = $_POST['description_'.$id]; $this->fixed_ip[$id]['description'] = $_POST['description_' . $id];
// active // active
$this->fixed_ip[$id]['active'] = (isset($_POST['active_' . $id]) && ($_POST['active_' . $id] == 'on')); $this->fixed_ip[$id]['active'] = (isset($_POST['active_' . $id]) && ($_POST['active_' . $id] == 'on'));
// Ip address // Ip address
if (!empty($_POST['ip_'.$id])) { if (!empty($_POST['ip_' . $id])) {
$_POST['ip_'.$id] = trim($_POST['ip_'.$id]); $_POST['ip_' . $id] = trim($_POST['ip_' . $id]);
} }
if ((!empty($_POST['ip_'.$id]) && !(check_ip($_POST['ip_'.$id]))) if ((!empty($_POST['ip_' . $id]) && !(check_ip($_POST['ip_' . $id])))
|| (!empty($_POST['ip_'.$id]) && !$this->isNotOverlappedIp($_POST['ip_'.$id]))) { || (!empty($_POST['ip_' . $id]) && !$this->isNotOverlappedIp($_POST['ip_' . $id]))) {
$error = true; $error = true;
$this->fixed_ip[$id]['ip'] = $_POST['ip_'.$id]; $this->fixed_ip[$id]['ip'] = $_POST['ip_' . $id];
} }
else { else {
$this->fixed_ip[$id]['ip'] = $_POST['ip_'.$id]; $this->fixed_ip[$id]['ip'] = $_POST['ip_' . $id];
} }
// Is ip correct with subnet: // Is ip correct with subnet:
if (!empty($_POST['ip_'.$id]) && check_ip($_POST['ip_'.$id]) && !range::check_subnet_range($_POST['ip_'.$id], if (!empty($_POST['ip_' . $id]) && check_ip($_POST['ip_' . $id]) && !range::check_subnet_range($_POST['ip_' . $id],
$this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0], $this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0],
$this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'))) { $this->getAccountContainer()->getAccountModule('dhcp_settings')->getDHCPOption('subnet-mask'))) {
$error = true; $error = true;
} }
// cn: // cn:
if (!empty($_POST['pc_'.$id])) { if (!empty($_POST['pc_' . $id])) {
$_POST['pc_'.$id] = trim($_POST['pc_'.$id]); $_POST['pc_' . $id] = trim($_POST['pc_' . $id]);
} }
if (!empty($_POST['pc_'.$id])) { if (!empty($_POST['pc_' . $id])) {
// name already in use // name already in use
if (in_array($_POST['pc_'.$id], $pcs) ) { if (in_array($_POST['pc_' . $id], $pcs)) {
$error = true; $error = true;
} }
else { else {
$pcs[] = $_POST['pc_'.$id]; $pcs[] = $_POST['pc_' . $id];
} }
} }
else { else {
$error = true; $error = true;
} }
if (strlen($_POST['pc_'.$id])>30) { if (strlen($_POST['pc_' . $id]) > 30) {
$error = true; $error = true;
} }
if (!preg_match("/^[A-Za-z0-9\\._-]*$/",$_POST['pc_'.$id])) { if (!preg_match("/^[A-Za-z0-9\\._-]*$/", $_POST['pc_' . $id])) {
$error = true; $error = true;
} }
$this->fixed_ip[$id]['cn'] = $_POST['pc_'.$id]; $this->fixed_ip[$id]['cn'] = $_POST['pc_' . $id];
} }
if ($error) { if ($error) {
$errors[] = $this->messages['errors'][0]; $errors[] = $this->messages['errors'][0];
@ -382,14 +382,14 @@ class fixed_ip extends baseModule {
$dhcpstatements = []; $dhcpstatements = [];
$this->setActive($dhcpstatements, $active); $this->setActive($dhcpstatements, $active);
$this->setIP($dhcpstatements, $_POST['ip_add']); $this->setIP($dhcpstatements, $_POST['ip_add']);
$this->fixed_ip[] = array( $this->fixed_ip[] = [
'cn' => $_POST['pc_add'], 'cn' => $_POST['pc_add'],
'mac' => $_POST['mac_add'], 'mac' => $_POST['mac_add'],
'description' => $_POST['description_add'], 'description' => $_POST['description_add'],
'ip' => $_POST['ip_add'], 'ip' => $_POST['ip_add'],
'dhcpstatements' => $dhcpstatements, 'dhcpstatements' => $dhcpstatements,
'active' => $active, 'active' => $active,
); ];
$this->orderByIP(); $this->orderByIP();
} }
@ -403,7 +403,7 @@ class fixed_ip extends baseModule {
*/ */
public function display_html_attributes() { public function display_html_attributes() {
$return = new htmlResponsiveRow(); $return = new htmlResponsiveRow();
if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0]=="") { if ($this->getAccountContainer()->getAccountModule('dhcp_settings')->attributes['cn'][0] == "") {
$return->add(new htmlStatusMessage('ERROR', _("Please fill out the DHCP settings first.")), 12); $return->add(new htmlStatusMessage('ERROR', _("Please fill out the DHCP settings first.")), 12);
return $return; return $return;
} }
@ -418,7 +418,7 @@ class fixed_ip extends baseModule {
} }
$autoNames = array_values(array_unique($autoNames)); $autoNames = array_values(array_unique($autoNames));
} }
$titles = array(_('IP address'), _('PC name'), _('MAC address'), _('Description'), _('Active'), ' '); $titles = [_('IP address'), _('PC name'), _('MAC address'), _('Description'), _('Active'), ' '];
$data = []; $data = [];
// Reset oberlaped ips // Reset oberlaped ips
$this->reset_overlapped_ip(); $this->reset_overlapped_ip();
@ -429,7 +429,7 @@ class fixed_ip extends baseModule {
} }
$pcs = []; $pcs = [];
$messages = []; $messages = [];
foreach($this->fixed_ip AS $id => $arr) { foreach ($this->fixed_ip as $id => $arr) {
// pc name // pc name
$existsInDifferentDn = false; $existsInDifferentDn = false;
if (!empty($_POST['pc_' . $id])) { if (!empty($_POST['pc_' . $id])) {
@ -442,7 +442,7 @@ class fixed_ip extends baseModule {
elseif (strlen($this->fixed_ip[$id]['cn']) < 2) { elseif (strlen($this->fixed_ip[$id]['cn']) < 2) {
$messages[] = new htmlStatusMessage('ERROR', _("The PC name needs to be at least 2 characters long."), htmlspecialchars($this->fixed_ip[$id]['cn'])); $messages[] = new htmlStatusMessage('ERROR', _("The PC name needs to be at least 2 characters long."), htmlspecialchars($this->fixed_ip[$id]['cn']));
} }
elseif (in_array($this->fixed_ip[$id]['cn'], $pcs) ) { elseif (in_array($this->fixed_ip[$id]['cn'], $pcs)) {
$messages[] = new htmlStatusMessage('ERROR', _("This PC name already exists."), htmlspecialchars($this->fixed_ip[$id]['cn'])); $messages[] = new htmlStatusMessage('ERROR', _("This PC name already exists."), htmlspecialchars($this->fixed_ip[$id]['cn']));
} }
elseif (isset($_POST['pc_' . $id]) && !preg_match("/^[A-Za-z0-9\\._-]*$/", $_POST['pc_' . $id])) { elseif (isset($_POST['pc_' . $id]) && !preg_match("/^[A-Za-z0-9\\._-]*$/", $_POST['pc_' . $id])) {
@ -479,16 +479,16 @@ class fixed_ip extends baseModule {
} }
} }
$entry = []; $entry = [];
$entry[] = new htmlInputField('ip_'.$id, $this->fixed_ip[$id]['ip']); $entry[] = new htmlInputField('ip_' . $id, $this->fixed_ip[$id]['ip']);
$pcInput = new htmlInputField('pc_'.$id, $this->fixed_ip[$id]['cn']); $pcInput = new htmlInputField('pc_' . $id, $this->fixed_ip[$id]['cn']);
if (!empty($autoNames)) { if (!empty($autoNames)) {
$pcInput->enableAutocompletion($autoNames); $pcInput->enableAutocompletion($autoNames);
} }
$entry[] = $pcInput; $entry[] = $pcInput;
$entry[] = new htmlInputField('mac_'.$id, $this->fixed_ip[$id]['mac']); $entry[] = new htmlInputField('mac_' . $id, $this->fixed_ip[$id]['mac']);
$entry[] = new htmlInputField('description_'.$id, $this->fixed_ip[$id]['description']); $entry[] = new htmlInputField('description_' . $id, $this->fixed_ip[$id]['description']);
$entry[] = new htmlInputCheckbox('active_'.$id, $this->fixed_ip[$id]['active']); $entry[] = new htmlInputCheckbox('active_' . $id, $this->fixed_ip[$id]['active']);
$entry[] = new htmlButton('drop_ip_'.$id, 'del.svg', true); $entry[] = new htmlButton('drop_ip_' . $id, 'del.svg', true);
$data[] = $entry; $data[] = $entry;
} }
// add host // add host
@ -506,7 +506,7 @@ class fixed_ip extends baseModule {
$data[] = $newEntry; $data[] = $newEntry;
$table = new htmlResponsiveTable($titles, $data); $table = new htmlResponsiveTable($titles, $data);
$table->setWidths(array('20%', '20%', '20%', '25%', '10%', '5%')); $table->setWidths(['20%', '20%', '20%', '25%', '10%', '5%']);
$table->colspan = 100; $table->colspan = 100;
$return->add($table, 12); $return->add($table, 12);
@ -535,7 +535,7 @@ class fixed_ip extends baseModule {
if ($name === $host['name']) { if ($name === $host['name']) {
$dn = $host['dn']; $dn = $host['dn'];
if ($this->getAccountContainer()->isNewAccount || strpos($dn, $this->getAccountContainer()->dn_orig) === false) { if ($this->getAccountContainer()->isNewAccount || strpos($dn, $this->getAccountContainer()->dn_orig) === false) {
return array($dn, $this->getHostNameSuggestion($name)); return [$dn, $this->getHostNameSuggestion($name)];
} }
} }
} }
@ -622,14 +622,14 @@ class fixed_ip extends baseModule {
$dhcpstatements = []; $dhcpstatements = [];
$this->setActive($dhcpstatements, true); $this->setActive($dhcpstatements, true);
$this->setIP($dhcpstatements, $val[1]); $this->setIP($dhcpstatements, $val[1]);
$this->fixed_ip[] = array( $this->fixed_ip[] = [
'cn' => $val[0], 'cn' => $val[0],
'mac' => $val[2], 'mac' => $val[2],
'description' => '', 'description' => '',
'ip' => $val[1], 'ip' => $val[1],
'dhcpstatements' => $dhcpstatements, 'dhcpstatements' => $dhcpstatements,
'active' => true, 'active' => true,
); ];
$this->orderByIP(); $this->orderByIP();
} }
return $errors; return $errors;
@ -654,11 +654,11 @@ class fixed_ip extends baseModule {
/** /**
* This function is overwritten because the fixed IPs are set after the ldap_add command. * This function is overwritten because the fixed IPs are set after the ldap_add command.
* *
* @see baseModule::postModifyActions()
*
* @param boolean $newAccount * @param boolean $newAccount
* @param array $attributes LDAP attributes of this entry * @param array $attributes LDAP attributes of this entry
* @return array array which contains status messages. Each entry is an array containing the status message parameters. * @return array array which contains status messages. Each entry is an array containing the status message parameters.
* @see baseModule::postModifyActions()
*
*/ */
public function postModifyActions($newAccount, $attributes) { public function postModifyActions($newAccount, $attributes) {
if (!$this->isRootNode()) { if (!$this->isRootNode()) {
@ -667,28 +667,28 @@ class fixed_ip extends baseModule {
$mod = []; // DN => array(attr => values) $mod = []; // DN => array(attr => values)
$delete = []; $delete = [];
// Which dns are to delete and to add // Which dns are to delete and to add
foreach($this->orig_ips AS $id => $arr) { foreach ($this->orig_ips as $id => $arr) {
// Exist cn still? // Exist cn still?
$in_arr = false; $in_arr = false;
foreach($this->fixed_ip AS $idB => $arr) { foreach ($this->fixed_ip as $idB => $arr) {
if ($this->orig_ips[$id]['cn'] == $this->fixed_ip[$idB]['cn']) { if ($this->orig_ips[$id]['cn'] == $this->fixed_ip[$idB]['cn']) {
$in_arr = true; $in_arr = true;
// check if IP changed // check if IP changed
if($this->orig_ips[$id]['ip'] != $this->fixed_ip[$idB]['ip']) { if ($this->orig_ips[$id]['ip'] != $this->fixed_ip[$idB]['ip']) {
$this->setIP($this->fixed_ip[$idB]['dhcpstatements'], $this->fixed_ip[$idB]['ip']); $this->setIP($this->fixed_ip[$idB]['dhcpstatements'], $this->fixed_ip[$idB]['ip']);
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpstatements'] = $this->fixed_ip[$idB]['dhcpstatements']; $mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpstatements'] = $this->fixed_ip[$idB]['dhcpstatements'];
} }
// check if active changed // check if active changed
if($this->orig_ips[$id]['active'] != $this->fixed_ip[$idB]['active']) { if ($this->orig_ips[$id]['active'] != $this->fixed_ip[$idB]['active']) {
$this->setActive($this->fixed_ip[$idB]['dhcpstatements'], $this->fixed_ip[$idB]['active']); $this->setActive($this->fixed_ip[$idB]['dhcpstatements'], $this->fixed_ip[$idB]['active']);
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpstatements'] = $this->fixed_ip[$idB]['dhcpstatements']; $mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpstatements'] = $this->fixed_ip[$idB]['dhcpstatements'];
} }
// check if MAC changed // check if MAC changed
if($this->orig_ips[$id]['mac'] != $this->fixed_ip[$idB]['mac']) { if ($this->orig_ips[$id]['mac'] != $this->fixed_ip[$idB]['mac']) {
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpHWAddress'] = array('ethernet ' . $this->fixed_ip[$idB]['mac']); $mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpHWAddress'] = ['ethernet ' . $this->fixed_ip[$idB]['mac']];
} }
// check if description changed // check if description changed
if($this->orig_ips[$id]['description'] != $this->fixed_ip[$idB]['description']) { if ($this->orig_ips[$id]['description'] != $this->fixed_ip[$idB]['description']) {
$mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpComments'][] = $this->fixed_ip[$idB]['description']; $mod['cn=' . $this->orig_ips[$id]['cn'] . $ldapSuffix]['dhcpComments'][] = $this->fixed_ip[$idB]['description'];
} }
break; break;
@ -703,9 +703,9 @@ class fixed_ip extends baseModule {
$this->fixed_ip = []; $this->fixed_ip = [];
} }
// Which entries are new: // Which entries are new:
foreach($this->fixed_ip AS $id => $arr) { foreach ($this->fixed_ip as $id => $arr) {
$in_arr = false; $in_arr = false;
foreach($this->orig_ips AS $idB => $arr) { foreach ($this->orig_ips as $idB => $arr) {
if ($this->orig_ips[$idB]['cn'] == $this->fixed_ip[$id]['cn']) { if ($this->orig_ips[$idB]['cn'] == $this->fixed_ip[$id]['cn']) {
$in_arr = true; $in_arr = true;
} }
@ -715,11 +715,11 @@ class fixed_ip extends baseModule {
} }
} }
foreach($delete AS $cn) { foreach ($delete as $cn) {
ldap_delete($_SESSION['ldap']->server(), 'cn=' . $cn . $ldapSuffix); ldap_delete($_SESSION['ldap']->server(), 'cn=' . $cn . $ldapSuffix);
} }
foreach($add AS $id => $arr) { foreach ($add as $id => $arr) {
$attr = []; $attr = [];
$attr['cn'] = $add[$id]['cn']; $attr['cn'] = $add[$id]['cn'];
$attr['objectClass'][0] = 'top'; $attr['objectClass'][0] = 'top';
@ -868,9 +868,9 @@ class fixed_ip extends baseModule {
if ($this->hostCache != null) { if ($this->hostCache != null) {
return; return;
} }
$attrs = array('cn', 'iphostnumber', 'macaddress'); $attrs = ['cn', 'iphostnumber', 'macaddress'];
$this->hostCache = []; $this->hostCache = [];
$result = searchLDAPByAttribute('cn', '*', null, $attrs, array('host')); $result = searchLDAPByAttribute('cn', '*', null, $attrs, ['host']);
foreach ($result as $attributes) { foreach ($result as $attributes) {
$this->hostCache[] = $attributes; $this->hostCache[] = $attributes;
} }
@ -893,13 +893,13 @@ class fixed_ip extends baseModule {
if ($this->existingDhcpHostsCache != null) { if ($this->existingDhcpHostsCache != null) {
return $this->existingDhcpHostsCache; return $this->existingDhcpHostsCache;
} }
$entries = searchLDAPByAttribute('cn', '*', 'dhcpHost', array('cn'), array('dhcp')); $entries = searchLDAPByAttribute('cn', '*', 'dhcpHost', ['cn'], ['dhcp']);
$this->existingDhcpHostsCache = []; $this->existingDhcpHostsCache = [];
foreach ($entries as $entry) { foreach ($entries as $entry) {
$this->existingDhcpHostsCache[] = array( $this->existingDhcpHostsCache[] = [
'dn' => $entry['dn'], 'dn' => $entry['dn'],
'name' => $entry['cn'][0] 'name' => $entry['cn'][0]
); ];
} }
} }
@ -907,9 +907,9 @@ class fixed_ip extends baseModule {
* @inheritDoc * @inheritDoc
*/ */
public function getListAttributeDescriptions(ConfiguredType $type): array { public function getListAttributeDescriptions(ConfiguredType $type): array {
return array( return [
"fixed_ips" => _("IP address") . ' / ' . _('MAC address') . ' / ' . _("Description") "fixed_ips" => _("IP address") . ' / ' . _('MAC address') . ' / ' . _("Description")
); ];
} }
/** /**
@ -919,7 +919,7 @@ class fixed_ip extends baseModule {
if ($attributeName === 'fixed_ips') { if ($attributeName === 'fixed_ips') {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): ?htmlElement {
// find all fixed addresses: // find all fixed addresses:
$entries = searchLDAP($entry['dn'], 'objectClass=dhcpHost', array('dhcpstatements', 'dhcphwaddress', 'cn')); $entries = searchLDAP($entry['dn'], 'objectClass=dhcpHost', ['dhcpstatements', 'dhcphwaddress', 'cn']);
if (sizeof($entries) > 0) { if (sizeof($entries) > 0) {
// sort by IP // sort by IP
$order = []; $order = [];
@ -936,11 +936,11 @@ class fixed_ip extends baseModule {
if (isset($entries[$i]['dhcpstatements'][0])) { if (isset($entries[$i]['dhcpstatements'][0])) {
$dhcpstatements = $entries[$i]['dhcpstatements']; $dhcpstatements = $entries[$i]['dhcpstatements'];
} }
$cssClasses = array('nowrap'); $cssClasses = ['nowrap'];
if (!fixed_ip::isActive($dhcpstatements)) { if (!fixed_ip::isActive($dhcpstatements)) {
$cssClasses[] = 'strike-through'; $cssClasses[] = 'strike-through';
} }
$dhcphwaddress = explode(" ",$entries[$i]['dhcphwaddress'][0]); $dhcphwaddress = explode(" ", $entries[$i]['dhcphwaddress'][0]);
$ipAddress = fixed_ip::extractIP($dhcpstatements); $ipAddress = fixed_ip::extractIP($dhcpstatements);
$ip = new htmlOutputText($ipAddress); $ip = new htmlOutputText($ipAddress);
$ip->setCSSClasses($cssClasses); $ip->setCSSClasses($cssClasses);

View file

@ -20,30 +20,30 @@
*/ */
/** /**
* Manages FreeRadius accounts. * Manages FreeRadius accounts.
* *
* @package modules * @package modules
* @author Roland Gruber * @author Roland Gruber
*/ */
use LAM\TYPES\ConfiguredType; use LAM\TYPES\ConfiguredType;
/** /**
* Manages FreeRadius accounts. * Manages FreeRadius accounts.
* *
* @package modules * @package modules
*/ */
class freeRadius extends baseModule { class freeRadius extends baseModule {
/** /**
* These attributes will be ignored by default if a new account is copied from an existing one. * These attributes will be ignored by default if a new account is copied from an existing one.
*/ */
const ATTRIBUTES_TO_IGNORE_ON_COPY = array('radiusFramedIPAddress'); const ATTRIBUTES_TO_IGNORE_ON_COPY = ['radiusFramedIPAddress'];
/** list of possible months */ /** list of possible months */
private static $monthList = array('01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', private static $monthList = ['01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May',
'06' => 'Jun', '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec' '06' => 'Jun', '07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'
); ];
/** cache for profile DNs */ /** cache for profile DNs */
private $profileCache; private $profileCache;
@ -65,7 +65,7 @@ class freeRadius extends baseModule {
* @return boolean true if module fits * @return boolean true if module fits
*/ */
public function can_manage() { public function can_manage() {
return in_array($this->get_scope(), array('user')); return in_array($this->get_scope(), ['user']);
} }
/** /**
@ -82,81 +82,81 @@ class freeRadius extends baseModule {
// alias name // alias name
$return["alias"] = _("FreeRadius"); $return["alias"] = _("FreeRadius");
// module dependencies // module dependencies
$return['dependencies'] = array('depends' => array(array('posixAccount', 'inetOrgPerson')), 'conflicts' => []); $return['dependencies'] = ['depends' => [['posixAccount', 'inetOrgPerson']], 'conflicts' => []];
// managed object classes // managed object classes
$return['objectClasses'] = array('radiusprofile'); $return['objectClasses'] = ['radiusprofile'];
// managed attributes // managed attributes
$return['attributes'] = array('radiusFramedIPAddress', 'radiusFramedIPNetmask', 'radiusRealm', 'radiusGroupName', $return['attributes'] = ['radiusFramedIPAddress', 'radiusFramedIPNetmask', 'radiusRealm', 'radiusGroupName',
'radiusExpiration', 'radiusIdleTimeout', 'dialupAccess', 'radiusProfileDn'); 'radiusExpiration', 'radiusIdleTimeout', 'dialupAccess', 'radiusProfileDn'];
// help Entries // help Entries
$return['help'] = array( $return['help'] = [
'radiusFramedIPAddress' => array( 'radiusFramedIPAddress' => [
"Headline" => _("IP address"), 'attr' => 'radiusFramedIPAddress', "Headline" => _("IP address"), 'attr' => 'radiusFramedIPAddress',
"Text" => _("This is the IP address for the user (e.g. 123.123.123.123).") "Text" => _("This is the IP address for the user (e.g. 123.123.123.123).")
), ],
'radiusFramedIPNetmask' => array( 'radiusFramedIPNetmask' => [
"Headline" => _("Net mask"), 'attr' => 'radiusFramedIPNetmask', "Headline" => _("Net mask"), 'attr' => 'radiusFramedIPNetmask',
"Text" => _("The net mask for the IP address.") "Text" => _("The net mask for the IP address.")
), ],
'radiusRealm' => array( 'radiusRealm' => [
"Headline" => _("Realm"), 'attr' => 'radiusRealm', "Headline" => _("Realm"), 'attr' => 'radiusRealm',
"Text" => _("The Radius realm of this account.") "Text" => _("The Radius realm of this account.")
), ],
'radiusGroupName' => array( 'radiusGroupName' => [
"Headline" => _("Group names"), 'attr' => 'radiusGroupName', "Headline" => _("Group names"), 'attr' => 'radiusGroupName',
"Text" => _("The group names for this account.") "Text" => _("The group names for this account.")
), ],
'radiusGroupNameList' => array( 'radiusGroupNameList' => [
"Headline" => _("Group names"), 'attr' => 'radiusGroupName', "Headline" => _("Group names"), 'attr' => 'radiusGroupName',
"Text" => _("The group names for this account.") . ' ' . _("Multiple values are separated by semicolon.") "Text" => _("The group names for this account.") . ' ' . _("Multiple values are separated by semicolon.")
), ],
'radiusExpiration' => array( 'radiusExpiration' => [
"Headline" => _("Expiration date"), 'attr' => 'radiusExpiration', "Headline" => _("Expiration date"), 'attr' => 'radiusExpiration',
"Text" => _("The account will be locked after this date.") "Text" => _("The account will be locked after this date.")
), ],
'radiusIdleTimeout' => array( 'radiusIdleTimeout' => [
"Headline" => _("Idle timeout"), 'attr' => 'radiusIdleTimeout', "Headline" => _("Idle timeout"), 'attr' => 'radiusIdleTimeout',
"Text" => _("Specifies the maximum number of seconds that a connection can be idle before the session is terminated.") "Text" => _("Specifies the maximum number of seconds that a connection can be idle before the session is terminated.")
), ],
'dialupAccess' => array( 'dialupAccess' => [
"Headline" => _("Enabled"), 'attr' => 'dialupAccess', "Headline" => _("Enabled"), 'attr' => 'dialupAccess',
"Text" => _("Specifies if the user may authenticate with FreeRadius.") "Text" => _("Specifies if the user may authenticate with FreeRadius.")
), ],
'profileDN' => array( 'profileDN' => [
"Headline" => _("Profile DN"), 'attr' => 'radiusProfileDn', "Headline" => _("Profile DN"), 'attr' => 'radiusProfileDn',
"Text" => _('DN where Radius profile templates are stored.') "Text" => _('DN where Radius profile templates are stored.')
), ],
'radiusProfileDn' => array( 'radiusProfileDn' => [
"Headline" => _("Profile"), 'attr' => 'radiusProfileDn', "Headline" => _("Profile"), 'attr' => 'radiusProfileDn',
"Text" => _('Radius profile for this user.') "Text" => _('Radius profile for this user.')
), ],
'hiddenOptions' => array( 'hiddenOptions' => [
"Headline" => _("Hidden options"), "Headline" => _("Hidden options"),
"Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.") "Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.")
), ],
'autoAdd' => array( 'autoAdd' => [
"Headline" => _("Automatically add this extension"), "Headline" => _("Automatically add this extension"),
"Text" => _("This will enable the extension automatically if this profile is loaded.") "Text" => _("This will enable the extension automatically if this profile is loaded.")
), ],
); ];
// profile settings // profile settings
$profileElements = []; $profileElements = [];
// auto add extension // auto add extension
$profileElements[] = new htmlResponsiveInputCheckbox('freeRadius_addExt', false, _('Automatically add this extension'), 'autoAdd'); $profileElements[] = new htmlResponsiveInputCheckbox('freeRadius_addExt', false, _('Automatically add this extension'), 'autoAdd');
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) {
$profileElements[] = new htmlResponsiveInputField(_('Net mask'), 'freeRadius_radiusFramedIPNetmask', null, 'radiusFramedIPNetmask'); $profileElements[] = new htmlResponsiveInputField(_('Net mask'), 'freeRadius_radiusFramedIPNetmask', null, 'radiusFramedIPNetmask');
$return['profile_checks']['freeRadius_radiusFramedIPNetmask'] = array( $return['profile_checks']['freeRadius_radiusFramedIPNetmask'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'ip', 'regex' => 'ip',
'error_message' => $this->messages['radiusFramedIPNetmask'][0]); 'error_message' => $this->messages['radiusFramedIPNetmask'][0]];
$return['profile_mappings']['freeRadius_radiusFramedIPNetmask'] = 'radiusFramedIPNetmask'; $return['profile_mappings']['freeRadius_radiusFramedIPNetmask'] = 'radiusFramedIPNetmask';
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) {
$profileElements[] = new htmlResponsiveInputField(_('Realm'), 'freeRadius_radiusRealm', null, 'radiusRealm'); $profileElements[] = new htmlResponsiveInputField(_('Realm'), 'freeRadius_radiusRealm', null, 'radiusRealm');
$return['profile_checks']['freeRadius_radiusRealm'] = array( $return['profile_checks']['freeRadius_radiusRealm'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'DNSname', 'regex' => 'DNSname',
'error_message' => $this->messages['radiusRealm'][0]); 'error_message' => $this->messages['radiusRealm'][0]];
$return['profile_mappings']['freeRadius_radiusRealm'] = 'radiusRealm'; $return['profile_mappings']['freeRadius_radiusRealm'] = 'radiusRealm';
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusGroupName')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusGroupName')) {
@ -164,25 +164,25 @@ class freeRadius extends baseModule {
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusIdleTimeout')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusIdleTimeout')) {
$profileElements[] = new htmlResponsiveInputField(_('Idle timeout'), 'freeRadius_radiusIdleTimeout', null, 'radiusIdleTimeout'); $profileElements[] = new htmlResponsiveInputField(_('Idle timeout'), 'freeRadius_radiusIdleTimeout', null, 'radiusIdleTimeout');
$return['profile_checks']['freeRadius_radiusIdleTimeout'] = array( $return['profile_checks']['freeRadius_radiusIdleTimeout'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => $this->messages['radiusIdleTimeout'][0]); 'error_message' => $this->messages['radiusIdleTimeout'][0]];
$return['profile_mappings']['freeRadius_radiusIdleTimeout'] = 'radiusIdleTimeout'; $return['profile_mappings']['freeRadius_radiusIdleTimeout'] = 'radiusIdleTimeout';
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
$enabledOptions = array('-' => '', _('Yes') => 'true', _('No') => 'false'); $enabledOptions = ['-' => '', _('Yes') => 'true', _('No') => 'false'];
$dialupAccessSelect = new htmlResponsiveSelect('freeRadius_dialupAccess', $enabledOptions, array('true'), _('Enabled'), 'dialupAccess'); $dialupAccessSelect = new htmlResponsiveSelect('freeRadius_dialupAccess', $enabledOptions, ['true'], _('Enabled'), 'dialupAccess');
$dialupAccessSelect->setHasDescriptiveElements(true); $dialupAccessSelect->setHasDescriptiveElements(true);
$profileElements[] = $dialupAccessSelect; $profileElements[] = $dialupAccessSelect;
$return['profile_mappings']['freeRadius_dialupAccess'] = 'dialupAccess'; $return['profile_mappings']['freeRadius_dialupAccess'] = 'dialupAccess';
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn') && isLoggedIn()) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn') && isLoggedIn()) {
$profileOptions = array('-' => ''); $profileOptions = ['-' => ''];
foreach ($this->getProfiles() as $dn) { foreach ($this->getProfiles() as $dn) {
$profileOptions[getAbstractDN($dn)] = $dn; $profileOptions[getAbstractDN($dn)] = $dn;
} }
$profileSelect = new htmlResponsiveSelect('freeRadius_radiusProfileDn', $profileOptions, array(''), _('Profile'), 'radiusProfileDn'); $profileSelect = new htmlResponsiveSelect('freeRadius_radiusProfileDn', $profileOptions, [''], _('Profile'), 'radiusProfileDn');
$profileSelect->setHasDescriptiveElements(true); $profileSelect->setHasDescriptiveElements(true);
$profileElements[] = $profileSelect; $profileElements[] = $profileSelect;
$return['profile_mappings']['freeRadius_radiusProfileDn'] = 'radiusProfileDn'; $return['profile_mappings']['freeRadius_radiusProfileDn'] = 'radiusProfileDn';
@ -195,69 +195,69 @@ class freeRadius extends baseModule {
// upload fields // upload fields
$return['upload_columns'] = []; $return['upload_columns'] = [];
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusRealm')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_radiusRealm', 'name' => 'freeRadius_radiusRealm',
'description' => _('Realm'), 'description' => _('Realm'),
'help' => 'radiusRealm', 'help' => 'radiusRealm',
'example' => _('company.com') 'example' => _('company.com')
); ];
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusGroupName')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusGroupName')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_radiusGroupName', 'name' => 'freeRadius_radiusGroupName',
'description' => _('Group names'), 'description' => _('Group names'),
'help' => 'radiusGroupNameList', 'help' => 'radiusGroupNameList',
'example' => _('group01;group02') 'example' => _('group01;group02')
); ];
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPAddress')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPAddress')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_radiusFramedIPAddress', 'name' => 'freeRadius_radiusFramedIPAddress',
'description' => _('IP address'), 'description' => _('IP address'),
'help' => 'radiusFramedIPAddress', 'help' => 'radiusFramedIPAddress',
'example' => '123.123.123.123', 'example' => '123.123.123.123',
); ];
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusFramedIPNetmask')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_radiusFramedIPNetmask', 'name' => 'freeRadius_radiusFramedIPNetmask',
'description' => _('Net mask'), 'description' => _('Net mask'),
'help' => 'radiusFramedIPNetmask', 'help' => 'radiusFramedIPNetmask',
'example' => '255.255.255.0' 'example' => '255.255.255.0'
); ];
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusExpiration')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusExpiration')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_radiusExpiration', 'name' => 'freeRadius_radiusExpiration',
'description' => _('Expiration date'), 'description' => _('Expiration date'),
'help' => 'radiusExpiration', 'help' => 'radiusExpiration',
'example' => '2035-11-22 00:00' 'example' => '2035-11-22 00:00'
); ];
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusIdleTimeout')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusIdleTimeout')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_radiusIdleTimeout', 'name' => 'freeRadius_radiusIdleTimeout',
'description' => _('Idle timeout'), 'description' => _('Idle timeout'),
'help' => 'radiusIdleTimeout', 'help' => 'radiusIdleTimeout',
'example' => '3600' 'example' => '3600'
); ];
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_dialupAccess', 'name' => 'freeRadius_dialupAccess',
'description' => _('Enabled'), 'description' => _('Enabled'),
'help' => 'dialupAccess', 'help' => 'dialupAccess',
'example' => 'true', 'example' => 'true',
'values' => 'true, false' 'values' => 'true, false'
); ];
} }
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) {
$return['upload_columns'][] = array( $return['upload_columns'][] = [
'name' => 'freeRadius_radiusProfileDn', 'name' => 'freeRadius_radiusProfileDn',
'description' => _('Profile'), 'description' => _('Profile'),
'help' => 'radiusProfileDn', 'help' => 'radiusProfileDn',
'example' => 'cn=profile,ou=radiusProfile,dc=example,dc=com' 'example' => 'cn=profile,ou=radiusProfile,dc=example,dc=com'
); ];
} }
// available PDF fields // available PDF fields
$return['PDF_fields'] = []; $return['PDF_fields'] = [];
@ -326,26 +326,26 @@ class freeRadius extends baseModule {
* This function fills the error message array with messages * This function fills the error message array with messages
*/ */
function load_Messages() { function load_Messages() {
$this->messages['radiusFramedIPAddress'][0] = array('ERROR', _('The IP address is invalid.')); $this->messages['radiusFramedIPAddress'][0] = ['ERROR', _('The IP address is invalid.')];
$this->messages['radiusFramedIPAddress'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusFramedIPAddress', _('The IP address is invalid.')); $this->messages['radiusFramedIPAddress'][1] = ['ERROR', _('Account %s:') . ' freeRadius_radiusFramedIPAddress', _('The IP address is invalid.')];
$this->messages['radiusFramedIPNetmask'][0] = array('ERROR', _('The net mask is invalid.')); $this->messages['radiusFramedIPNetmask'][0] = ['ERROR', _('The net mask is invalid.')];
$this->messages['radiusFramedIPNetmask'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusFramedIPNetmask', _('The net mask is invalid.')); $this->messages['radiusFramedIPNetmask'][1] = ['ERROR', _('Account %s:') . ' freeRadius_radiusFramedIPNetmask', _('The net mask is invalid.')];
$this->messages['radiusRealm'][0] = array('ERROR', _('Please enter a valid realm.')); $this->messages['radiusRealm'][0] = ['ERROR', _('Please enter a valid realm.')];
$this->messages['radiusRealm'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusRealm', _('Please enter a valid realm.')); $this->messages['radiusRealm'][1] = ['ERROR', _('Account %s:') . ' freeRadius_radiusRealm', _('Please enter a valid realm.')];
$this->messages['radiusGroupName'][0] = array('ERROR', _('Please enter a valid list of group names.')); $this->messages['radiusGroupName'][0] = ['ERROR', _('Please enter a valid list of group names.')];
$this->messages['radiusGroupName'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusGroupName', _('Please enter a valid list of group names.')); $this->messages['radiusGroupName'][1] = ['ERROR', _('Account %s:') . ' freeRadius_radiusGroupName', _('Please enter a valid list of group names.')];
$this->messages['radiusExpiration'][0] = array('ERROR', _('The expiration date must be in format DD.MM.YYYY HH:MM.')); $this->messages['radiusExpiration'][0] = ['ERROR', _('The expiration date must be in format DD.MM.YYYY HH:MM.')];
$this->messages['radiusExpiration'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusExpiration', _('The expiration date must be in format DD.MM.YYYY HH:MM.')); $this->messages['radiusExpiration'][1] = ['ERROR', _('Account %s:') . ' freeRadius_radiusExpiration', _('The expiration date must be in format DD.MM.YYYY HH:MM.')];
$this->messages['radiusIdleTimeout'][0] = array('ERROR', _('Please enter a numeric value for the idle timeout.')); $this->messages['radiusIdleTimeout'][0] = ['ERROR', _('Please enter a numeric value for the idle timeout.')];
$this->messages['radiusIdleTimeout'][1] = array('ERROR', _('Account %s:') . ' freeRadius_radiusIdleTimeout', _('Please enter a numeric value for the idle timeout.')); $this->messages['radiusIdleTimeout'][1] = ['ERROR', _('Account %s:') . ' freeRadius_radiusIdleTimeout', _('Please enter a numeric value for the idle timeout.')];
$this->messages['dialupAccess'][0] = array('ERROR', _('Account %s:') . ' freeRadius_dialupAccess', _('This value can only be "true" or "false".')); $this->messages['dialupAccess'][0] = ['ERROR', _('Account %s:') . ' freeRadius_dialupAccess', _('This value can only be "true" or "false".')];
$this->messages['radiusProfileDn'][0] = array('ERROR', _('Account %s:') . ' freeRadius_radiusProfileDn', _('This is not a valid DN!')); $this->messages['radiusProfileDn'][0] = ['ERROR', _('Account %s:') . ' freeRadius_radiusProfileDn', _('This is not a valid DN!')];
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []) : void { public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void {
$attributesToIgnore = array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY); $attributesToIgnore = array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY);
parent::loadAttributesFromAccountCopy($ldapAttributes, $attributesToIgnore); parent::loadAttributesFromAccountCopy($ldapAttributes, $attributesToIgnore);
} }
@ -394,7 +394,7 @@ class freeRadius extends baseModule {
} }
// profile DN // profile DN
if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideRadiusProfileDn')) {
$profiles = array('-' => '-'); $profiles = ['-' => '-'];
foreach ($this->getProfiles() as $dn) { foreach ($this->getProfiles() as $dn) {
$profiles[getAbstractDN($dn)] = $dn; $profiles[getAbstractDN($dn)] = $dn;
} }
@ -411,15 +411,15 @@ class freeRadius extends baseModule {
} }
// enabled // enabled
if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) { if (!$this->isBooleanConfigOptionSet('freeRadius_hideDialupAccess')) {
$enabled = array(''); $enabled = [''];
if (!empty($this->attributes['dialupAccess'][0])) { if (!empty($this->attributes['dialupAccess'][0])) {
$enabled = array($this->attributes['dialupAccess'][0]); $enabled = [$this->attributes['dialupAccess'][0]];
// value in LDAP may be anything other than "false" to count as "true" // value in LDAP may be anything other than "false" to count as "true"
if (!in_array($this->attributes['dialupAccess'][0], array('true', 'false', 'TRUE', 'FALSE'))) { if (!in_array($this->attributes['dialupAccess'][0], ['true', 'false', 'TRUE', 'FALSE'])) {
$enabled = array('true'); $enabled = ['true'];
} }
} }
$enabledOptions = array('-' => '', _('Yes') => 'true', _('No') => 'false'); $enabledOptions = ['-' => '', _('Yes') => 'true', _('No') => 'false'];
$enabledSelect = new htmlResponsiveSelect('dialupAccess', $enabledOptions, $enabled, _('Enabled'), 'dialupAccess'); $enabledSelect = new htmlResponsiveSelect('dialupAccess', $enabledOptions, $enabled, _('Enabled'), 'dialupAccess');
$enabledSelect->setHasDescriptiveElements(true); $enabledSelect->setHasDescriptiveElements(true);
$return->add($enabledSelect, 12); $return->add($enabledSelect, 12);
@ -427,7 +427,7 @@ class freeRadius extends baseModule {
// button to remove extension // button to remove extension
$return->addVerticalSpacer('2rem'); $return->addVerticalSpacer('2rem');
$remButton = new htmlButton('remObjectClass', _('Remove FreeRadius extension')); $remButton = new htmlButton('remObjectClass', _('Remove FreeRadius extension'));
$remButton->setCSSClasses(array('lam-danger')); $remButton->setCSSClasses(['lam-danger']);
$return->add($remButton, 12, 12, 12, 'text-center'); $return->add($remButton, 12, 12, 12, 'text-center');
} }
else { else {
@ -448,7 +448,7 @@ class freeRadius extends baseModule {
return []; return [];
} }
elseif (isset($_POST['remObjectClass'])) { elseif (isset($_POST['remObjectClass'])) {
$this->attributes['objectClass'] = array_delete(array('radiusprofile'), $this->attributes['objectClass']); $this->attributes['objectClass'] = array_delete(['radiusprofile'], $this->attributes['objectClass']);
for ($i = 0; $i < sizeof($this->meta['attributes']); $i++) { for ($i = 0; $i < sizeof($this->meta['attributes']); $i++) {
if (isset($this->attributes[$this->meta['attributes'][$i]])) { if (isset($this->attributes[$this->meta['attributes'][$i]])) {
unset($this->attributes[$this->meta['attributes'][$i]]); unset($this->attributes[$this->meta['attributes'][$i]]);
@ -525,10 +525,9 @@ class freeRadius extends baseModule {
function display_html_expiration() { function display_html_expiration() {
$return = new htmlResponsiveRow(); $return = new htmlResponsiveRow();
$attr = 'radiusExpiration'; $attr = 'radiusExpiration';
// TODO display in local time $date = new DateTime('@' . (time() + 3600 * 24 * 365), getTimeZone());
$date = new DateTime('@' . (time() + 3600*24*365), getTimeZone());
if (!empty($this->attributes[$attr][0])) { if (!empty($this->attributes[$attr][0])) {
$date = DateTime::createFromFormat('d M Y H:i',$this->attributes[$attr][0], new DateTimeZone('UTC')); $date = DateTime::createFromFormat('d M Y H:i', $this->attributes[$attr][0], new DateTimeZone('UTC'));
$date->setTimezone(getTimeZone()); $date->setTimezone(getTimeZone());
} }
$dateInput = new htmlResponsiveInputField(_('Expiration date'), 'expirationTime', $date->format('Y-m-d H:i'), 'radiusExpiration'); $dateInput = new htmlResponsiveInputField(_('Expiration date'), 'expirationTime', $date->format('Y-m-d H:i'), 'radiusExpiration');
@ -616,7 +615,9 @@ class freeRadius extends baseModule {
$errors = []; $errors = [];
for ($i = 0; $i < sizeof($rawAccounts); $i++) { for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class // add object class
if (!in_array("radiusprofile", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "radiusprofile"; if (!in_array("radiusprofile", $partialAccounts[$i]['objectClass'])) {
$partialAccounts[$i]['objectClass'][] = "radiusprofile";
}
// IP address // IP address
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'freeRadius_radiusFramedIPAddress', 'radiusFramedIPAddress', $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'freeRadius_radiusFramedIPAddress', 'radiusFramedIPAddress',
'ip', $this->messages['radiusFramedIPAddress'][1], $errors); 'ip', $this->messages['radiusFramedIPAddress'][1], $errors);
@ -637,7 +638,7 @@ class freeRadius extends baseModule {
} }
else { else {
$errMsg = $this->messages['radiusExpiration'][1]; $errMsg = $this->messages['radiusExpiration'][1];
array_push($errMsg, array($i)); array_push($errMsg, [$i]);
$errors[] = $errMsg; $errors[] = $errMsg;
} }
} }
@ -646,12 +647,12 @@ class freeRadius extends baseModule {
'digit', $this->messages['radiusIdleTimeout'][1], $errors); 'digit', $this->messages['radiusIdleTimeout'][1], $errors);
// enabled // enabled
if (!empty($rawAccounts[$i][$ids['freeRadius_dialupAccess']])) { if (!empty($rawAccounts[$i][$ids['freeRadius_dialupAccess']])) {
if (in_array($rawAccounts[$i][$ids['freeRadius_dialupAccess']], array('true', 'false'))) { if (in_array($rawAccounts[$i][$ids['freeRadius_dialupAccess']], ['true', 'false'])) {
$partialAccounts[$i]['dialupAccess'] = $rawAccounts[$i][$ids['freeRadius_dialupAccess']]; $partialAccounts[$i]['dialupAccess'] = $rawAccounts[$i][$ids['freeRadius_dialupAccess']];
} }
else { else {
$errMsg = $this->messages['dialupAccess'][0]; $errMsg = $this->messages['dialupAccess'][0];
array_push($errMsg, array($i)); array_push($errMsg, [$i]);
$errors[] = $errMsg; $errors[] = $errMsg;
} }
} }
@ -678,7 +679,7 @@ class freeRadius extends baseModule {
} }
if (isset($this->attributes['dialupAccess'][0])) { if (isset($this->attributes['dialupAccess'][0])) {
$enabled = _('Yes'); $enabled = _('Yes');
if (in_array($this->attributes['dialupAccess'][0], array('false', 'FALSE'))) { if (in_array($this->attributes['dialupAccess'][0], ['false', 'FALSE'])) {
$enabled = _('No'); $enabled = _('No');
} }
$this->addPDFKeyValue($return, 'dialupAccess', _('Enabled'), $enabled); $this->addPDFKeyValue($return, 'dialupAccess', _('Enabled'), $enabled);
@ -754,7 +755,7 @@ class freeRadius extends baseModule {
if (empty($this->moduleSettings['freeRadius_profileDN'][0])) { if (empty($this->moduleSettings['freeRadius_profileDN'][0])) {
return []; return [];
} }
$list = searchLDAP($this->moduleSettings['freeRadius_profileDN'][0], '(objectClass=radiusProfile)', array('dn')); $list = searchLDAP($this->moduleSettings['freeRadius_profileDN'][0], '(objectClass=radiusProfile)', ['dn']);
if (empty($list)) { if (empty($list)) {
return []; return [];
} }
@ -772,17 +773,17 @@ class freeRadius extends baseModule {
* @return array list of jobs * @return array list of jobs
*/ */
public function getSupportedJobs(&$config) { public function getSupportedJobs(&$config) {
return array( return [
new FreeRadiusAccountExpirationCleanupJob(), new FreeRadiusAccountExpirationCleanupJob(),
new FreeRadiusAccountExpirationNotifyJob() new FreeRadiusAccountExpirationNotifyJob()
); ];
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getListAttributeDescriptions(ConfiguredType $type): array { public function getListAttributeDescriptions(ConfiguredType $type): array {
return array( return [
'radiusframedipaddress' => _('IP address'), 'radiusframedipaddress' => _('IP address'),
'radiusframedipnetmask' => _('Net mask'), 'radiusframedipnetmask' => _('Net mask'),
'radiusrealm' => _('Realm'), 'radiusrealm' => _('Realm'),
@ -791,7 +792,7 @@ class freeRadius extends baseModule {
'radiusidletimeout' => _('Idle timeout'), 'radiusidletimeout' => _('Idle timeout'),
'dialupaccess' => _('Enabled'), 'dialupaccess' => _('Enabled'),
'radiusprofiledn' => _('Profile'), 'radiusprofiledn' => _('Profile'),
); ];
} }
} }
@ -834,8 +835,8 @@ if (interface_exists('\LAM\JOB\Job', false)) {
*/ */
protected function findUsers($jobID, $options) { protected function findUsers($jobID, $options) {
// read users // read users
$attrs = array('radiusExpiration'); $attrs = ['radiusExpiration'];
return searchLDAPByFilter('(radiusExpiration=*)', $attrs, array('user')); return searchLDAPByFilter('(radiusExpiration=*)', $attrs, ['user']);
} }
/** /**
@ -898,10 +899,10 @@ if (interface_exists('\LAM\JOB\Job', false)) {
*/ */
protected function findUsers($jobID, $options) { protected function findUsers($jobID, $options) {
// read users // read users
$sysattrs = array('radiusExpiration', $_SESSION['cfgMain']->getMailAttribute()); $sysattrs = ['radiusExpiration', $_SESSION['cfgMain']->getMailAttribute()];
$attrs = $this->getAttrWildcards($jobID, $options); $attrs = $this->getAttrWildcards($jobID, $options);
$attrs = array_values(array_unique(array_merge($attrs, $sysattrs))); $attrs = array_values(array_unique(array_merge($attrs, $sysattrs)));
return searchLDAPByFilter('(&(radiusExpiration=*)(' . $_SESSION['cfgMain']->getMailAttribute() . '=*))', $attrs, array('user')); return searchLDAPByFilter('(&(radiusExpiration=*)(' . $_SESSION['cfgMain']->getMailAttribute() . '=*))', $attrs, ['user']);
} }
/** /**

View file

@ -2,7 +2,7 @@
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2011 - 2022 Roland Gruber Copyright (C) 2011 - 2024 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -20,20 +20,20 @@
*/ */
/** /**
* Shows general information like the creation time of an account. * Shows general information like the creation time of an account.
* *
* @package modules * @package modules
* @author Roland Gruber * @author Roland Gruber
*/ */
use LAM\TYPES\ConfiguredType; use LAM\TYPES\ConfiguredType;
use LAM\TYPES\TypeManager; use LAM\TYPES\TypeManager;
/** /**
* Shows general information like the creation time of an account. * Shows general information like the creation time of an account.
* *
* @package modules * @package modules
*/ */
class generalInformation extends baseModule { class generalInformation extends baseModule {
/** /**
@ -59,12 +59,12 @@ class generalInformation extends baseModule {
// alias name // alias name
$return["alias"] = _("General information"); $return["alias"] = _("General information");
// module dependencies // module dependencies
$return['dependencies'] = array('depends' => [], 'conflicts' => []); $return['dependencies'] = ['depends' => [], 'conflicts' => []];
// managed attributes // managed attributes
$return['attributes'] = array('creatorsname', 'createtimestamp', 'modifiersname', $return['attributes'] = ['creatorsname', 'createtimestamp', 'modifiersname',
'modifytimestamp', 'hassubordinates', 'memberof'); 'modifytimestamp', 'hassubordinates', 'memberof'];
$return['hiddenAttributes'] = array('creatorsname', 'createtimestamp', 'modifiersname', $return['hiddenAttributes'] = ['creatorsname', 'createtimestamp', 'modifiersname',
'modifytimestamp', 'hassubordinates'); 'modifytimestamp', 'hassubordinates'];
return $return; return $return;
} }
@ -112,7 +112,7 @@ class generalInformation extends baseModule {
// group memberships // group memberships
if (isset($this->attributes['memberof'][0])) { if (isset($this->attributes['memberof'][0])) {
$typeManager = new TypeManager(); $typeManager = new TypeManager();
$scopes = array('gon', 'group'); $scopes = ['gon', 'group'];
$types = $typeManager->getConfiguredTypesForScopes($scopes); $types = $typeManager->getConfiguredTypesForScopes($scopes);
$suffixList = []; $suffixList = [];
foreach ($types as $type) { foreach ($types as $type) {
@ -158,7 +158,7 @@ class generalInformation extends baseModule {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []) : void { public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void {
// no action for this module // no action for this module
} }
@ -166,14 +166,14 @@ class generalInformation extends baseModule {
* @inheritDoc * @inheritDoc
*/ */
public function getListAttributeDescriptions(ConfiguredType $type): array { public function getListAttributeDescriptions(ConfiguredType $type): array {
return array( return [
'creatorsname' => _('Created by'), 'creatorsname' => _('Created by'),
'createtimestamp' => _('Creation time'), 'createtimestamp' => _('Creation time'),
'modifiersname' => _('Modified by'), 'modifiersname' => _('Modified by'),
'modifytimestamp' => _('Modification time'), 'modifytimestamp' => _('Modification time'),
'hassubordinates' => _('Has subentries'), 'hassubordinates' => _('Has subentries'),
'memberof' => _('Groups') 'memberof' => _('Groups')
); ];
} }
} }