diff --git a/lam/lib/import.inc b/lam/lib/import.inc
index 2a45977e8..651449b16 100644
--- a/lam/lib/import.inc
+++ b/lam/lib/import.inc
@@ -2,8 +2,8 @@
namespace LAM\TOOLS\IMPORT_EXPORT;
-use \htmlStatusMessage;
-use \LAMException;
+use htmlStatusMessage;
+use LAMException;
/*
@@ -44,16 +44,16 @@ include_once('ldap.inc');
*/
class Importer {
- const SESSION_KEY_TASKS = 'import_tasks';
- const SESSION_KEY_COUNT = 'import_count';
- const SESSION_KEY_STOP_ON_ERROR = 'import_stop_on_error';
- const STATUS = 'status';
- const PROGRESS = 'progress';
- const DATA = 'data';
+ public const SESSION_KEY_TASKS = 'import_tasks';
+ public const SESSION_KEY_COUNT = 'import_count';
+ public const SESSION_KEY_STOP_ON_ERROR = 'import_stop_on_error';
+ public const STATUS = 'status';
+ public const PROGRESS = 'progress';
+ public const DATA = 'data';
private const TIME_LIMIT = 10;
- const KEY = 0;
- const VALUE = 1;
- const CHANGETYPE = 'changetype';
+ public const KEY = 0;
+ public const VALUE = 1;
+ private const CHANGETYPE = 'changetype';
/**
* Extracts the single entries in the file.
@@ -67,7 +67,7 @@ class Importer {
$currentEntry = [];
foreach ($lines as $line) {
$trimmedLine = trim($line);
- if (substr($trimmedLine, 0, 1) === '#') {
+ if (str_starts_with($trimmedLine, '#')) {
// skip comments
continue;
}
@@ -78,7 +78,7 @@ class Importer {
$currentEntry = [];
}
}
- elseif (substr($line, 0, 1) === ' ') {
+ elseif (str_starts_with($line, ' ')) {
// append to last line if starting with a space
if (empty($currentEntry)) {
throw new LAMException(_('Invalid data'), htmlspecialchars($line));
@@ -246,7 +246,7 @@ class Importer {
private function processVersion($entry) {
$keyValue = $this->getLineKeyValue($entry[0]);
if (($keyValue[Importer::VALUE] != '1') || (sizeof($entry) > 1)) {
- $escapedLines = array_map('htmlspecialchars', $entry);
+ $escapedLines = array_map(htmlspecialchars(...), $entry);
throw new LAMException(_('LDIF import only supports version 1'), implode('
', $escapedLines));
}
}
@@ -267,7 +267,7 @@ class Importer {
}
$firstAttributeLine = array_shift($entry);
$firstAttribute = $this->getLineKeyValue($firstAttributeLine);
- if ($firstAttribute[Importer::KEY] != Importer::CHANGETYPE) {
+ if ($firstAttribute[Importer::KEY] != self::CHANGETYPE) {
// complete DN
$attributes = [
$firstAttribute[Importer::KEY] => [$firstAttribute[Importer::VALUE]]
@@ -332,7 +332,7 @@ class Importer {
}
$newRdnData = $this->getLineKeyValue($entry[0]);
if ($newRdnData[Importer::KEY] !== 'newrdn') {
- throw new LAMException(_('Invalid data'), htmlspecialchars($dn) . '
' . $newRdnData);
+ throw new LAMException(_('Invalid data'), htmlspecialchars($dn) . '
' . print_r($newRdnData, true));
}
$newRdn = $newRdnData[Importer::VALUE];
$delOldRdnData = $this->getLineKeyValue($entry[1]);
@@ -403,7 +403,7 @@ class Importer {
if (sizeof($parts) !== 2) {
throw new LAMException(_('Invalid data'), htmlspecialchars($line));
}
- if (substr($parts[Importer::VALUE], 0, 1) == ':') {
+ if (str_starts_with($parts[Importer::VALUE], ':')) {
$value = base64_decode(trim(substr($parts[Importer::VALUE], 1)));
}
else {
@@ -453,7 +453,7 @@ class AddEntryTask implements ImporterTask {
/**
* {@inheritDoc}
- * @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
+ * @see ImporterTask::run
*/
public function run() {
$ldap = $_SESSION['ldap']->server();
@@ -492,7 +492,7 @@ class RenameEntryTask implements ImporterTask {
/**
* {@inheritDoc}
- * @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
+ * @see ImporterTask::run
*/
public function run() {
$ldap = $_SESSION['ldap']->server();
@@ -525,7 +525,7 @@ class DeleteEntryTask implements ImporterTask {
/**
* {@inheritDoc}
- * @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
+ * @see ImporterTask::run
*/
public function run() {
$ldap = $_SESSION['ldap']->server();
@@ -567,7 +567,7 @@ class MultiTask implements ImporterTask {
/**
* {@inheritDoc}
- * @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
+ * @see ImporterTask::run
*/
public function run() {
foreach ($this->tasks as $task) {
@@ -610,7 +610,7 @@ class AddAttributesTask implements ImporterTask {
/**
* {@inheritDoc}
- * @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
+ * @see ImporterTask::run
*/
public function run() {
$ldap = $_SESSION['ldap']->server();
@@ -667,7 +667,7 @@ class DeleteAttributesTask implements ImporterTask {
/**
* {@inheritDoc}
- * @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
+ * @see ImporterTask::run
*/
public function run() {
$ldap = $_SESSION['ldap']->server();
@@ -735,7 +735,7 @@ class ReplaceAttributesTask implements ImporterTask {
/**
* {@inheritDoc}
- * @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
+ * @see ImporterTask::run
*/
public function run() {
$ldap = $_SESSION['ldap']->server();
@@ -746,31 +746,4 @@ class ReplaceAttributesTask implements ImporterTask {
throw new LAMException(sprintf(_('Was unable to create DN: %s.'), $this->dn), getExtendedLDAPErrorMessage($ldap));
}
- /**
- * Returns the DN.
- *
- * @return string DN
- */
- public function getDn() {
- return $this->dn;
- }
-
- /**
- * Returns the attributes to add.
- *
- * @return string[] attributes (array('attr' => array('val1', 'val2')))
- */
- public function getAttributes() {
- return $this->attributes;
- }
-
- /**
- * Returns the attributes name.
- *
- * @return string name
- */
- public function getAttributeName() {
- return $this->attributeName;
- }
-
}
diff --git a/lam/lib/ldap.inc b/lam/lib/ldap.inc
index 806de08ad..8eb8003bd 100644
--- a/lam/lib/ldap.inc
+++ b/lam/lib/ldap.inc
@@ -96,14 +96,13 @@ class Ldap {
// return error number
$errorNumber = ldap_errno($this->server);
$clientSource = empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR'];
- if (($errorNumber === False)
- || ($errorNumber == 81)) {
+ if ($errorNumber == 81) {
// connection failed
logNewMessage(LOG_ERR, 'User ' . $user . ' (' . $clientSource . ') failed to log in (LDAP error: ' . getDefaultLDAPErrorString($this->server) . ').');
throw new LAMException(_("Cannot connect to specified LDAP server. Please try again."), null, null, $errorNumber);
}
elseif ($errorNumber == 49) {
- // user name/password invalid. Return to login page.
+ // username/password invalid. Return to login page.
logNewMessage(LOG_ERR, 'User ' . $user . ' (' . $clientSource . ') failed to log in (wrong password). ' . getDefaultLDAPErrorString($this->server));
throw new LAMException(_("Wrong password/user name combination. Please try again."), getDefaultLDAPErrorString($this->server), null, $errorNumber);
}
@@ -177,7 +176,7 @@ class Ldap {
$file = @readdir($dir);
while ($file) {
$path = $tmpDir . $file;
- if ((substr($file, 0, 1) != '.')
+ if ((!str_starts_with($file, '.'))
&& !is_dir($path)
&& ($time - filemtime($path) > 900)) {
@unlink($path);
@@ -191,7 +190,7 @@ class Ldap {
$dir = @opendir($tmpDir);
$file = @readdir($dir);
while ($file) {
- if (substr($file, -4) == '.tmp') {
+ if (str_ends_with($file, '.tmp')) {
$path = $tmpDir . $file;
if ($time - filemtime($path) > (3600 * 24)) {
@unlink($path);
@@ -215,7 +214,7 @@ class Ldap {
}
/**
- * Returns the LDAP user name.
+ * Returns the LDAP username.
*
* @return string user name
*/