Debian Codegraph @

templates/lists/userlink.php

raw
1 <?php
2 namespace LAM\ACCOUNTLIST;
3 use htmlLink;
4 use \htmlResponsiveRow;
5 use \htmlStatusMessage;
6 /*
7
8 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
9 Copyright (C) 2003 - 2025 Roland Gruber
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more detaexils.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25 */
26
27 /**
28 * This page will redirect to account/edit.php if the given user is valid.
29 *
30 * It is called from listgroups.php via the memberUID links.
31 *
32 * @package lists
33 * @author Roland Gruber
34 */
35
36 /** security functions */
37 include_once(__DIR__ . "/../../lib/security.inc");
38 /** Needed to find DNs of users */
39 include_once(__DIR__ . "/../../lib/ldap.inc");
40 /** Used to display error messages */
41 include_once(__DIR__ . "/../../lib/status.inc");
42
43 // start session
44 startSecureSession();
45 enforceUserIsLoggedIn();
46
47 setlanguage();
48
49 // get username
50 $user = $_GET['user'];
51 $user = str_replace("\\", '',$user);
52 $user = str_replace("'", '',$user);
53
54 // get DN of user
55 $dn = search_username($user);
56
57 if ($dn !== null) {
58 // redirect to account/edit.php
59 metaRefresh("../account/edit.php?type=user&DN='" . rawurlencode($dn) . "'");
60
61 }
62 else {
63 // print error message if user was not found
64 include __DIR__ . '/../../lib/adminHeader.inc';
65 $container = new htmlResponsiveRow();
66 $container->addVerticalSpacer('1rem');
67 $container->add(new htmlStatusMessage("ERROR", _("This user was not found!"), htmlspecialchars($user)), 12);
68 $container->addVerticalSpacer('1rem');
69 $container->add(new htmlLink(_("Back to group list"), 'javascript:history.back()'), 12);
70 parseHtml(null, $container, [], false, 'user');
71 include __DIR__ . '/../../lib/adminFooter.inc';
72 }
73
74
75 /**
76 * Searches LDAP for a specific username (uid attribute) and returns its DN entry
77 *
78 * @param string $name user name
79 * @return string|null DN
80 */
81 function search_username(string $name): ?string {
82 $entries = searchLDAPByAttribute('uid', $name, null, ['dn'], ['user']);
83 if (count($entries) > 0 ) {
84 return $entries[0]['dn'];
85 }
86 else {
87 return null;
88 }
89 }