| 1 |
<?php |
| 2 |
/* |
| 3 |
|
| 4 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 5 |
Copyright (C) 2009 - 2026 Roland Gruber |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program; if not, write to the Free Software |
| 19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
|
| 21 |
|
| 22 |
*/ |
| 23 |
|
| 24 |
/** |
| 25 |
* This file includes functions to manage LAM tools. |
| 26 |
* |
| 27 |
* @package tools |
| 28 |
* @author Roland Gruber |
| 29 |
*/ |
| 30 |
|
| 31 |
/** |
| 32 |
* Returns the tools which are available for LAM. |
| 33 |
* |
| 34 |
* @return LAMTool[] list of LAMTool objects |
| 35 |
*/ |
| 36 |
function getTools(): array { |
| 37 |
$toolsDirName = __DIR__ . '/tools'; |
| 38 |
$toolsDir = dir($toolsDirName); |
| 39 |
$entry = $toolsDir->read(); |
| 40 |
// include all files in the tools directory |
| 41 |
while ($entry) { |
| 42 |
if ((substr($entry, strlen($entry) - 4, 4) === '.inc') && is_file($toolsDirName . '/' . $entry)) { |
| 43 |
include_once($toolsDirName . '/' . $entry); |
| 44 |
} |
| 45 |
$entry = $toolsDir->read(); |
| 46 |
} |
| 47 |
// find tools classes |
| 48 |
$classList = get_declared_classes(); |
| 49 |
$return = []; |
| 50 |
foreach ($classList as $classCandidate) { |
| 51 |
if (in_array('LAMTool', class_parents($classCandidate))) { |
| 52 |
$return[] = new $classCandidate(); |
| 53 |
} |
| 54 |
} |
| 55 |
return $return; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Represents a tool. |
| 60 |
* LAM will scan lib/tools/*.inc for classes which implement this interface. This allows to |
| 61 |
* dynamically plugin additional tools. There will be an entry on the tools page inside LAM |
| 62 |
* for each found class (if it matches the security level). |
| 63 |
* A LAMTool only specifies name, description and location of a tool. The tool functionality |
| 64 |
* is provided by the tool's target page. |
| 65 |
* |
| 66 |
* @author Roland Gruber |
| 67 |
* @package tools |
| 68 |
*/ |
| 69 |
abstract class LAMTool { |
| 70 |
|
| 71 |
/** |
| 72 |
* Returns the name of the tool. |
| 73 |
* |
| 74 |
* @return string name |
| 75 |
*/ |
| 76 |
abstract public function getName(): string; |
| 77 |
|
| 78 |
/** |
| 79 |
* returns a description text for the tool. |
| 80 |
* |
| 81 |
* @return string description |
| 82 |
*/ |
| 83 |
abstract public function getDescription(): string; |
| 84 |
|
| 85 |
/** |
| 86 |
* Returns a link to the tool page (relative to templates/). |
| 87 |
* |
| 88 |
* @return string link |
| 89 |
*/ |
| 90 |
abstract public function getLink(): string; |
| 91 |
|
| 92 |
/** |
| 93 |
* Returns if the tool requires write access to LDAP. |
| 94 |
* |
| 95 |
* @return bool true if write access is needed |
| 96 |
*/ |
| 97 |
abstract public function getRequiresWriteAccess(): bool; |
| 98 |
|
| 99 |
/** |
| 100 |
* Returns if the tool requires password change rights. |
| 101 |
* |
| 102 |
* @return bool true if password change rights are needed |
| 103 |
*/ |
| 104 |
abstract public function getRequiresPasswordChangeRights(): bool; |
| 105 |
|
| 106 |
/** |
| 107 |
* Returns the link to the tool image (relative to graphics/) |
| 108 |
* |
| 109 |
* @return string image URL |
| 110 |
*/ |
| 111 |
abstract public function getImageLink(): string; |
| 112 |
|
| 113 |
/** |
| 114 |
* Returns the preferred position of this tool on the tools page. |
| 115 |
* The position may be between 0 and 1000. 0 is the top position. |
| 116 |
* |
| 117 |
* @return int preferred position |
| 118 |
*/ |
| 119 |
abstract public function getPosition(): int; |
| 120 |
|
| 121 |
/** |
| 122 |
* Returns if the tool is visible in the menu. |
| 123 |
* |
| 124 |
* @return bool visible |
| 125 |
*/ |
| 126 |
abstract public function isVisible(): bool; |
| 127 |
|
| 128 |
/** |
| 129 |
* Returns if a tool may be hidden by configuration in the LAM server profile. |
| 130 |
* |
| 131 |
* @return bool hideable |
| 132 |
*/ |
| 133 |
public function isHideable(): bool { |
| 134 |
return true; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Returns the configuration options for this tool. |
| 139 |
* |
| 140 |
* @param array<string, string> $settings current tool settings |
| 141 |
* @return htmlElement|null configuration options |
| 142 |
*/ |
| 143 |
public function getConfigOptions(array $settings): ?htmlElement { |
| 144 |
return null; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Checks the configuration options. |
| 149 |
* |
| 150 |
* @param array<string, string> $settings hash array (option name => value) that contains the input. The option values are all arrays containing one or more elements. |
| 151 |
* @return string[][] list of error messages |
| 152 |
*/ |
| 153 |
public function checkConfigurationOptions(array $settings): array { |
| 154 |
return []; |
| 155 |
} |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Represents a subtool. |
| 161 |
* |
| 162 |
* @author Roland Gruber |
| 163 |
* @package tools |
| 164 |
*/ |
| 165 |
class LAMSubTool { |
| 166 |
|
| 167 |
/** @var string $name visible tool name */ |
| 168 |
public string $name = ''; |
| 169 |
/** @var string $description tool description */ |
| 170 |
public string $description = ''; |
| 171 |
/** @var string $link tool link (relative to templates/) */ |
| 172 |
public string $link = ''; |
| 173 |
/** @var string $image image URL (relative to graphics/) */ |
| 174 |
public string $image = ''; |
| 175 |
|
| 176 |
} |