getTimestamp() . generateRandomText(); } // cleanup account containers in session $cleanupCandidates = []; foreach ($_SESSION as $key => $value) { if (str_starts_with($key, $sessionAccountPrefix)) { $cleanupCandidates[] = $key; } $candidateCount = count($cleanupCandidates); if ($candidateCount > 100) { $numToDelete = $candidateCount - 100; natsort($cleanupCandidates); for ($i = 0; $i < $numToDelete; $i++) { $toDelete = array_shift($cleanupCandidates); unset($_SESSION[$toDelete]); } } } $typeManager = new TypeManager(); //load account if (!empty($_GET['DN'])) { $type = $typeManager->getConfiguredType($_GET['type']); $dn = cleanDn($_GET['DN']); if (($type === null) || $type->isHidden()) { logNewMessage(LOG_ERR, 'User tried to access hidden account type: ' . $_GET['type']); die(); } $suffix = strtolower($type->getSuffix()); $_SESSION[$sessionKey] = new accountContainer($type, $sessionKey); $result = $_SESSION[$sessionKey]->load_account($dn); if (count($result) > 0) { include __DIR__ . '/../../lib/adminHeader.inc'; foreach ($result as $message) { call_user_func_array(StatusMessage(...), $message); } include __DIR__ . '/../../lib/adminFooter.inc'; die(); } } // new account elseif (empty($_POST)) { $type = $typeManager->getConfiguredType($_GET['type']); if (($type === null) || $type->isHidden()) { logNewMessage(LOG_ERR, 'User tried to access hidden account type: ' . $_GET['type']); die(); } elseif (!checkIfNewEntriesAreAllowed($type->getId())) { logNewMessage(LOG_ERR, 'User tried to create entry of forbidden account type: ' . $type->getId()); die(); } $_SESSION[$sessionKey] = new accountContainer($type, $sessionKey); $_SESSION[$sessionKey]->new_account(); if (!empty($_GET['copyDn'])) { $copyDn = cleanDn($_GET['copyDn']); $copyDnLower = strtolower($copyDn); $suffix = strtolower($type->getSuffix()); if (strpos($copyDnLower, $suffix) !== (strlen($copyDnLower) - strlen($suffix))) { logNewMessage(LOG_ERR, 'User tried to access entry of type ' . $type->getId() . ' outside suffix ' . $suffix); die(); } $_SESSION[$sessionKey]->copyFromExistingAccount($copyDn); } } // show account page $_SESSION[$sessionKey]->continue_main(); /** * Cleans the given DN from GET. * * @param string $dn DN * @return string cleaned DN */ function cleanDn(string $dn) : string { $cleanDn = str_replace("\\'", '', $dn); if ($dn == $cleanDn) { if (str_starts_with($cleanDn, "'")) { $cleanDn = substr($cleanDn, 1); } if (str_ends_with($cleanDn, "'")) { $cleanDn = substr($cleanDn, 0, -1); } } return $cleanDn; }