refactoring

This commit is contained in:
Roland Gruber 2022-09-10 20:41:16 +02:00
parent 1934e89b53
commit 28033794e0
8 changed files with 38 additions and 15 deletions

View file

@ -5,7 +5,7 @@ use \htmlStatusMessage;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2021 Roland Gruber
Copyright (C) 2003 - 2022 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View file

@ -3,12 +3,13 @@ namespace LAM\INIT;
use LAM\PDF\PdfStructurePersistenceManager;
use LAM\PROFILES\AccountProfilePersistenceManager;
use LAM\TYPES\TypeManager;
use LAMException;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2021 Roland Gruber
Copyright (C) 2003 - 2022 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -74,7 +75,7 @@ if (!$conf->isHidePasswordPromptForExpiredPasswords()) {
// check if all suffixes in conf-file exist
$new_suffs = array();
// get list of active types
$typeManager = new \LAM\TYPES\TypeManager();
$typeManager = new TypeManager();
$types = $typeManager->getConfiguredTypes();
foreach ($types as $type) {
$info = @ldap_read($_SESSION['ldap']->server(), $type->getSuffix(), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
@ -82,10 +83,6 @@ foreach ($types as $type) {
$new_suffs[] = $type->getSuffix();
continue;
}
$res = ldap_get_entries($_SESSION['ldap']->server(), $info);
if (!$res && !in_array($type->getSuffix(), $new_suffs)) {
$new_suffs[] = $type->getSuffix();
}
}
// display page to add suffixes, if needed

View file

@ -405,7 +405,7 @@ class Ajax {
*
* @return string JSON output
*/
private function dnSelection() {
private function dnSelection(): string {
$dn = trim($_POST['dn']);
if (empty($dn) || !get_preg($dn, 'dn')) {
$dnList = $this->getDefaultDns();
@ -415,7 +415,11 @@ class Ajax {
$dnList = $this->getSubDns($dn);
}
$html = $this->buildDnSelectionHtml($dnList, $dn);
return json_encode(array('dialogData' => $html));
$json = json_encode(array('dialogData' => $html));
if ($json === false) {
return '';
}
return $json;
}
/**
@ -499,6 +503,9 @@ class Ajax {
parseHtml(null, $mainRow, array(), false, $tabindex, 'user');
$out = ob_get_contents();
ob_end_clean();
if ($out === false) {
return '';
}
return $out;
}

View file

@ -230,10 +230,16 @@ if (!empty($_POST['export'])) {
if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) {
$file = $_FILES['logoUpload']['tmp_name'];
$handle = fopen($file, "r");
$data = fread($handle, 100000000);
fclose($handle);
$filename = $_FILES['logoUpload']['name'];
try {
if ($handle === false) {
throw new LAMException(_('Unable to create temporary file.'));
}
$data = fread($handle, 100000000);
if ($data === false) {
throw new LAMException(_('Unable to create temporary file.'));
}
fclose($handle);
$filename = $_FILES['logoUpload']['name'];
$pdfStructurePersistenceManager->savePdfLogo($_SESSION['config']->getName(), $filename, $data);
$container->add(new htmlStatusMessage('INFO', _('Uploaded logo file.'), $filename), 12);
}

View file

@ -222,8 +222,8 @@ function lamRunTestSuite($serverName, $serverTitle, $testQuota, $container): voi
$sr = @ldap_read($_SESSION['ldap']->server(), $ldapUser, "objectClass=posixAccount", array('uid'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$entry = @ldap_get_entries($_SESSION['ldap']->server(), $sr);
$userName = $entry[0]['uid'][0];
if ($userName) {
if (($entry !== false) && isset($entry[0]['uid'][0])) {
$userName = $entry[0]['uid'][0];
$unixOk = true;
}
}

View file

@ -233,13 +233,18 @@ function printImportTabProcessing(&$tabindex): void {
*/
function checkImportData(): void {
$source = $_POST['source'];
$ldif = '';
if ($source == 'text') {
$ldif = $_POST['text'];
}
else {
$handle = fopen($_FILES['file']['tmp_name'], "r");
if ($handle === false) {
throw new LAMException(_('Unable to create temporary file.'));
}
$ldif = fread($handle, 100000000);
if ($ldif === false) {
throw new LAMException(_('Unable to create temporary file.'));
}
fclose($handle);
}
if (empty($ldif)) {

1
lam/tmp/.gitignore vendored
View file

@ -3,3 +3,4 @@
/*.log
/*.pdf
/*.tmp
/*.ldif

View file

@ -31,3 +31,10 @@ parameters:
- '#Parameter \#1 \$haystack of function strpos expects string, int\|string given.#'
- '#Argument of an invalid type array\|int supplied for foreach, only iterables are supported.#'
- '#Cannot access offset mixed on non-empty-array\|int.#'
- '#Parameter \#1 \$ldap of function ldap_get_values_len expects LDAP\\Connection, resource given.#'
- '#Parameter \#2 \$result of function ldap_first_entry expects LDAP\\Result, array\|LDAP\\Result given.#'
- '#Parameter \#1 \$ldap of function ldap_first_entry expects LDAP\\Connection, resource given.#'
- '#Parameter \#1 \$ldap of function ldap_read expects array\|LDAP\\Connection, resource given.#'
- '#Parameter \#1 \$ldap of function ldap_get_entries expects LDAP\\Connection, resource given.#'
- '#Parameter \#1 \$string of function htmlspecialchars expects string, array\|string given.#'
- '#Parameter \#1 \$name of function LAM\\ACCOUNTLIST\\search_username expects string, array\|string given.#'