| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\TOOLS\TREEVIEW; |
| 4 |
|
| 5 |
use htmlOutputText; |
| 6 |
use htmlResponsiveInputField; |
| 7 |
use htmlResponsiveRow; |
| 8 |
use htmlElement; |
| 9 |
use LAMTool; |
| 10 |
|
| 11 |
/* |
| 12 |
|
| 13 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 14 |
Copyright (C) 2021 - 2026 Roland Gruber |
| 15 |
|
| 16 |
This program is free software; you can redistribute it and/or modify |
| 17 |
it under the terms of the GNU General Public License as published by |
| 18 |
the Free Software Foundation; either version 2 of the License, or |
| 19 |
(at your option) any later version. |
| 20 |
|
| 21 |
This program is distributed in the hope that it will be useful, |
| 22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
GNU General Public License for more details. |
| 25 |
|
| 26 |
You should have received a copy of the GNU General Public License |
| 27 |
along with this program; if not, write to the Free Software |
| 28 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 |
|
| 30 |
*/ |
| 31 |
|
| 32 |
/** |
| 33 |
* LDAP tree view. |
| 34 |
* |
| 35 |
* @author Roland Gruber |
| 36 |
* @package tools |
| 37 |
*/ |
| 38 |
|
| 39 |
/** |
| 40 |
* LDAP tree view. |
| 41 |
* |
| 42 |
* @package tools |
| 43 |
*/ |
| 44 |
class TreeViewTool extends LAMTool { |
| 45 |
|
| 46 |
private const TREE_SUFFIX_CONFIG = 'treeViewSuffix'; |
| 47 |
|
| 48 |
/** |
| 49 |
* {@inheritDoc} |
| 50 |
*/ |
| 51 |
public function getName(): string { |
| 52 |
return _('Tree view'); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* {@inheritDoc} |
| 57 |
*/ |
| 58 |
public function getDescription(): string { |
| 59 |
return _("This is an LDAP browser to work on raw LDAP data."); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* {@inheritDoc} |
| 64 |
*/ |
| 65 |
public function getLink(): string { |
| 66 |
return "tools/treeView.php"; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* {@inheritDoc} |
| 71 |
*/ |
| 72 |
public function getRequiresWriteAccess(): bool { |
| 73 |
return false; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* {@inheritDoc} |
| 78 |
*/ |
| 79 |
public function getRequiresPasswordChangeRights(): bool { |
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* {@inheritDoc} |
| 85 |
*/ |
| 86 |
public function getImageLink(): string { |
| 87 |
return 'tree.svg'; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* {@inheritDoc} |
| 92 |
*/ |
| 93 |
public function getPosition(): int { |
| 94 |
return 550; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* {@inheritDoc} |
| 99 |
*/ |
| 100 |
public function isVisible(): bool { |
| 101 |
return true; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* {@inheritDoc} |
| 106 |
*/ |
| 107 |
public function getConfigOptions(array $settings): ?htmlElement { |
| 108 |
$row = new htmlResponsiveRow(); |
| 109 |
$row->add(new htmlOutputText(_('Tree view'))); |
| 110 |
$suffix = empty($settings[self::TREE_SUFFIX_CONFIG]) ? '' : $settings[self::TREE_SUFFIX_CONFIG]; |
| 111 |
$row->add(new htmlResponsiveInputField(_('Tree suffix'), self::TREE_SUFFIX_CONFIG, $suffix, '203')); |
| 112 |
$row->addVerticalSpacer('1rem'); |
| 113 |
return $row; |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* {@inheritDoc} |
| 118 |
*/ |
| 119 |
public function checkConfigurationOptions(array $settings): array { |
| 120 |
$errors = []; |
| 121 |
$roots = self::getRootDns($settings); |
| 122 |
foreach ($roots as $root) { |
| 123 |
if (!get_preg($root, 'dn')) { |
| 124 |
$errors[] = ['ERROR', _('Tree suffix is invalid.'), htmlspecialchars($root)]; |
| 125 |
} |
| 126 |
} |
| 127 |
return $errors; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Returns the list of configured root DNs. |
| 132 |
* |
| 133 |
* @param array<string, string>|null $settings tool settings |
| 134 |
* @return string[] root DNs |
| 135 |
*/ |
| 136 |
public static function getRootDns(?array $settings = null): array { |
| 137 |
$roots = []; |
| 138 |
$toolSettings = $settings; |
| 139 |
if ($toolSettings === null) { |
| 140 |
$toolSettings = $_SESSION['config']->getToolSettings(); |
| 141 |
} |
| 142 |
if (!empty($toolSettings[self::TREE_SUFFIX_CONFIG])) { |
| 143 |
$roots = explode(';', $toolSettings[self::TREE_SUFFIX_CONFIG]); |
| 144 |
} |
| 145 |
return $roots; |
| 146 |
} |
| 147 |
|
| 148 |
} |