| 1 |
<?php |
| 2 |
namespace LAM\TOOLS\TREEVIEW; |
| 3 |
use htmlDiv; |
| 4 |
use htmlForm; |
| 5 |
use htmlInputField; |
| 6 |
use htmlJavaScript; |
| 7 |
use htmlOutputText; |
| 8 |
use htmlResponsiveInputField; |
| 9 |
use htmlResponsiveRow; |
| 10 |
use htmlGroup; |
| 11 |
|
| 12 |
/* |
| 13 |
|
| 14 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 15 |
Copyright (C) 2021 - 2025 Roland Gruber |
| 16 |
|
| 17 |
This program is free software; you can redistribute it and/or modify |
| 18 |
it under the terms of the GNU General Public License as published by |
| 19 |
the Free Software Foundation; either version 2 of the License, or |
| 20 |
(at your option) any later version. |
| 21 |
|
| 22 |
This program is distributed in the hope that it will be useful, |
| 23 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 |
GNU General Public License for more details. |
| 26 |
|
| 27 |
You should have received a copy of the GNU General Public License |
| 28 |
along with this program; if not, write to the Free Software |
| 29 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 30 |
|
| 31 |
*/ |
| 32 |
|
| 33 |
/** |
| 34 |
* LDAP tree view. |
| 35 |
* |
| 36 |
* @author Roland Gruber |
| 37 |
* @package tools |
| 38 |
*/ |
| 39 |
|
| 40 |
/** security functions */ |
| 41 |
include_once(__DIR__ . "/../../lib/security.inc"); |
| 42 |
/** access to configuration options */ |
| 43 |
include_once(__DIR__ . "/../../lib/config.inc"); |
| 44 |
|
| 45 |
// start session |
| 46 |
startSecureSession(); |
| 47 |
enforceUserIsLoggedIn(); |
| 48 |
validateSecurityToken(); |
| 49 |
|
| 50 |
checkIfToolIsActive('TreeViewTool'); |
| 51 |
|
| 52 |
setlanguage(); |
| 53 |
|
| 54 |
include __DIR__ . '/../../lib/adminHeader.inc'; |
| 55 |
echo '<link rel="stylesheet" href="../../style/wunderbaum/wunderbaum.css" />'; |
| 56 |
echo '<script src="../lib/extra/wunderbaum/wunderbaum.umd.js"></script>'; |
| 57 |
echo '<link rel="stylesheet" href="../../style/bootstrap-icons/bootstrap-icons.css" />'; |
| 58 |
echo '<div class="smallPaddingContent">'; |
| 59 |
|
| 60 |
$roots = TreeViewTool::getRootDns(); |
| 61 |
if (empty($roots)) { |
| 62 |
StatusMessage('ERROR', _('Please configure the tree suffix in your LAM server profile settings.')); |
| 63 |
} |
| 64 |
else { |
| 65 |
showTree(); |
| 66 |
} |
| 67 |
|
| 68 |
echo '</div>'; |
| 69 |
include __DIR__ . '/../../lib/adminFooter.inc'; |
| 70 |
|
| 71 |
function showTree(): void { |
| 72 |
$openInitial = []; |
| 73 |
if (isset($_GET['dn'])) { |
| 74 |
$initialDn = base64_decode($_GET['dn']); |
| 75 |
$roots = TreeViewTool::getRootDns(); |
| 76 |
foreach ($roots as $rootDn) { |
| 77 |
if ((strlen($initialDn) > strlen($rootDn)) && str_ends_with($initialDn, $rootDn)) { |
| 78 |
$extraDnPart = substr($initialDn, 0, (-1 * strlen($rootDn)) - 1); |
| 79 |
$dnParts = ldap_explode_dn($extraDnPart, 0); |
| 80 |
if ($dnParts !== false) { |
| 81 |
unset($dnParts['count']); |
| 82 |
$dnPartsCount = count($dnParts); |
| 83 |
for ($i = 0; $i < $dnPartsCount; $i++) { |
| 84 |
$currentParts = array_slice($dnParts, $dnPartsCount - ($i + 1)); |
| 85 |
$openInitial[] = '"' . base64_encode(implode(',', $currentParts) . ',' . $rootDn) . '"'; |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
$openInitialJsArray = '[' . implode(', ', $openInitial) . ']'; |
| 92 |
$row = new htmlResponsiveRow(); |
| 93 |
$row->setCSSClasses(['maxrow']); |
| 94 |
$row->add(new htmlDiv('ldap_tree', new htmlOutputText(''), ['tree-view--tree']), 12, 4, 4, 'tree-left-area'); |
| 95 |
$row->add(new htmlDiv('ldap_actionarea', new htmlOutputText(''), ['tree-view--actionarea']), 12, 8, 8, 'tree-right-area'); |
| 96 |
$treeScript = new htmlJavaScript(' |
| 97 |
window.lam.utility.documentReady(function() { |
| 98 |
window.sessionStorage.removeItem("LAM_COPY_PASTE_ACTION"); |
| 99 |
window.sessionStorage.removeItem("LAM_COPY_PASTE_DN"); |
| 100 |
var maxHeight = document.documentElement.scrollHeight - (document.querySelector("#ldap_tree").getBoundingClientRect().top - window.scrollY) - 50; |
| 101 |
document.getElementById("ldap_tree").style.maxHeight = maxHeight; |
| 102 |
document.getElementById("ldap_actionarea").style.maxHeight = maxHeight; |
| 103 |
const tree = new mar10.Wunderbaum({ |
| 104 |
element: document.getElementById("ldap_tree"), |
| 105 |
id: "ldap_tree", |
| 106 |
strings: { |
| 107 |
loading: "' . addslashes(_('Loading')) . '", |
| 108 |
loadError: "' . addslashes(_('Error')) . '", |
| 109 |
noData: "' . addslashes(_('No objects found!')) . '" |
| 110 |
}, |
| 111 |
debugLevel: 2, |
| 112 |
source: "../misc/ajax.php?function=treeview&command=getRootNodes", |
| 113 |
init: (e) => { |
| 114 |
tree.expandAll(true, {depth: 1, }); |
| 115 |
window.lam.treeview.openInitial(tree, ' . $openInitialJsArray . '); |
| 116 |
}, |
| 117 |
lazyLoad: function(e) { |
| 118 |
return {url: "../misc/ajax.php?function=treeview&command=getNodes&dn=" + e.node.key}; |
| 119 |
}, |
| 120 |
iconBadge: (e) => { |
| 121 |
if (e.node.data.badge) { |
| 122 |
const badgeSpan = document.createElement("span"); |
| 123 |
badgeSpan.className = "tree-badge"; |
| 124 |
const badgeImg = document.createElement("img"); |
| 125 |
badgeImg.src = e.node.data.badge; |
| 126 |
badgeSpan.appendChild(badgeImg); |
| 127 |
return badgeSpan; |
| 128 |
} |
| 129 |
}, |
| 130 |
activate: function(e) { |
| 131 |
const node = e.node; |
| 132 |
window.lam.treeview.getNodeContent("' . getSecurityTokenName() . '", "' . getSecurityTokenValue() . '", node.key); |
| 133 |
} |
| 134 |
}); |
| 135 |
}); |
| 136 |
'); |
| 137 |
$row->add($treeScript); |
| 138 |
|
| 139 |
$deleteDialogContent = new htmlResponsiveRow(); |
| 140 |
$deleteDialogContent->add(new htmlOutputText(_('Do you really want to delete this entry?'))); |
| 141 |
$deleteDialogContent->addVerticalSpacer('0.5rem'); |
| 142 |
$deleteDialogEntryText = new htmlOutputText(''); |
| 143 |
$deleteDialogEntryText->setCSSClasses(['treeview-delete-entry']); |
| 144 |
$deleteDialogContent->add($deleteDialogEntryText); |
| 145 |
$deleteDialogDiv = new htmlDiv('treeview_delete_dlg', $deleteDialogContent, ['hidden']); |
| 146 |
$row->add($deleteDialogDiv); |
| 147 |
|
| 148 |
$restoreDialogContent = new htmlResponsiveRow(); |
| 149 |
$restoreDialogContent->add(new htmlOutputText(_('Do you really want to restore this entry?'))); |
| 150 |
$restoreDialogContent->addVerticalSpacer('0.5rem'); |
| 151 |
$restoreDialogEntryText = new htmlOutputText(''); |
| 152 |
$restoreDialogEntryText->setCSSClasses(['treeview-restore-entry']); |
| 153 |
$restoreDialogContent->add($restoreDialogEntryText); |
| 154 |
$restoreDialogDiv = new htmlDiv('treeview_restore_dlg', $restoreDialogContent, ['hidden']); |
| 155 |
$row->add($restoreDialogDiv); |
| 156 |
|
| 157 |
$errorDialogContent = new htmlResponsiveRow(); |
| 158 |
$errorDialogEntryTitle = new htmlOutputText(''); |
| 159 |
$errorDialogEntryTitle->setCSSClasses(['treeview-error-title']); |
| 160 |
$errorDialogContent->add($errorDialogEntryTitle); |
| 161 |
$errorDialogContent->addVerticalSpacer('0.5rem'); |
| 162 |
$errorDialogEntryText = new htmlOutputText(''); |
| 163 |
$errorDialogEntryText->setCSSClasses(['treeview-error-text']); |
| 164 |
$errorDialogContent->add($errorDialogEntryText); |
| 165 |
$errorDialogDiv = new htmlDiv('treeview_error_dlg', $errorDialogContent, ['hidden']); |
| 166 |
$row->add($errorDialogDiv); |
| 167 |
|
| 168 |
$pwdCheckRow = new htmlResponsiveRow(); |
| 169 |
$pwdCheckInput = new htmlResponsiveInputField(_('Password'), 'lam_pwd_check'); |
| 170 |
$pwdCheckInput->setIsPassword(true); |
| 171 |
$pwdCheckInput->setCSSClasses(['lam_pwd_check']); |
| 172 |
$pwdCheckRow->add($pwdCheckInput); |
| 173 |
$pwdCheckRow->addVerticalSpacer('1rem'); |
| 174 |
$pwdCheckRow->add(new htmlDiv('lam-pwd-check-dialog-result', new htmlGroup())); |
| 175 |
$pwdCheckDiv = new htmlDiv('lam-pwd-check-dialog', $pwdCheckRow, ['hidden']); |
| 176 |
$row->add($pwdCheckDiv); |
| 177 |
|
| 178 |
$form = new htmlForm('actionarea', 'treeView.php', $row); |
| 179 |
parseHtml(null, $form, [], true, null); |
| 180 |
} |