Debian Codegraph @

templates/config/conflogin.php

raw
1 <?php
2 namespace LAM\CONFIG;
3
4 use htmlStatusMessage;
5 use htmlResponsiveRow;
6 use LAMCfgMain;
7 use htmlButton;
8 use htmlOutputText;
9 use htmlLink;
10 use htmlDiv;
11 use htmlResponsiveSelect;
12 use htmlResponsiveInputField;
13 use htmlHorizontalLine;
14 use LAMException;
15 use ServerProfilePersistenceManager;
16
17 /*
18 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
19 Copyright (C) 2003 - 2026 Roland Gruber
20
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 2 of the License, or
24 (at your option) any later version.
25
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
30
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34
35 */
36
37
38 /**
39 * Login page to change the preferences.
40 *
41 * @package configuration
42 * @author Roland Gruber
43 */
44
45
46 /** Access to config functions */
47 include_once(__DIR__ . '/../../lib/config.inc');
48 /** Used to print status messages */
49 include_once(__DIR__ . '/../../lib/status.inc');
50
51 // start session
52 if (isFileBasedSession()) {
53 session_save_path(__DIR__ . '/../../sess');
54 }
55 lam_start_session();
56 session_regenerate_id(true);
57
58 setlanguage();
59
60 $message = null;
61 // get error message from confmain.php
62 if (isset($_SESSION['conf_message'])) {
63 $message = $_SESSION['conf_message'];
64 }
65
66 // remove settings from session
67 $sessionKeys = array_keys($_SESSION);
68 foreach ($sessionKeys as $sessionKey) {
69 if (str_starts_with($sessionKey, "conf_")) {
70 unset($_SESSION[$sessionKey]);
71 }
72 }
73
74 echo $_SESSION['header'];
75
76 $serverProfilePersistenceManager = new ServerProfilePersistenceManager();
77 $profileNames = [];
78 $profileNamesWithoutPassword = [];
79 try {
80 $profileNames = $serverProfilePersistenceManager->getProfiles();
81 foreach ($profileNames as $profileName) {
82 $profile = $serverProfilePersistenceManager->loadProfile($profileName);
83 if (!$profile->hasPasswordSet()) {
84 $profileNamesWithoutPassword[] = $profileName;
85 }
86 }
87 }
88 catch (LAMException $e) {
89 logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle());
90 }
91 printHeaderContents(_("Login"), '../..');
92
93 if (count($profileNames) < 1) {
94 $message = new htmlStatusMessage('INFO', _("No server profiles found. Please create one."));
95 }
96 if ($profileNamesWithoutPassword !== []) {
97 $message = new htmlStatusMessage('INFO', _("There is at least one server profile without password. Please click on the manage server profiles link to set a password."),
98 htmlspecialchars(implode(', ', $profileNamesWithoutPassword)));
99 }
100 ?>
101 </head>
102 <body>
103 <?php
104 printJsIncludes('../..');
105 ?>
106 <div id="lam-topnav" class="lam-header">
107 <div class="lam-header-left lam-menu-stay">
108 <a href="https://www.ldap-account-manager.org/" target="new_window">
109 <img class="align-middle" width="24" height="24" alt="help" src="../../graphics/logo.svg">
110 <span class="hide-on-mobile">
111 <?php
112 echo getLAMVersionText();
113 ?>
114 </span>
115 </a>
116 </div>
117 <?php
118 if (is_dir(__DIR__ . '/../../docs/manual')) {
119 ?>
120 <a class="lam-header-right lam-menu-icon hide-on-tablet" href="javascript:void(0);" class="icon"
121 onclick="window.lam.topmenu.toggle();">
122 <img class="align-middle" width="16" height="16" alt="menu" src="../../graphics/menu.svg">
123 <span class="padding0">&nbsp;</span>
124 </a>
125 <a class="lam-header-right lam-menu-entry" target="_blank" href="../../docs/manual/index.html">
126 <span class="padding0"><?php echo _("Help") ?></span>
127 </a>
128 <?php
129 }
130 ?>
131 </div>
132 <br><br>
133 <!-- form to change existing profiles -->
134 <form action="confmain.php" method="post" autocomplete="off">
135
136 <?php
137
138 $row = new htmlResponsiveRow();
139
140 // message
141 if ($message !== null) {
142 $row->add($message);
143 $row->addVerticalSpacer('2rem');
144 }
145
146 $box = new htmlResponsiveRow();
147 if (count($profileNames) > 0) {
148 $box->add(new htmlOutputText(_("Please enter your password to change the server preferences:")));
149 $box->addVerticalSpacer('1.5rem');
150 $conf = new LAMCfgMain();
151 $selectedProfile = [];
152 if (!empty($_COOKIE["lam_default_profile"]) && in_array($_COOKIE["lam_default_profile"], $profileNames)) {
153 $selectedProfile[] = $_COOKIE["lam_default_profile"];
154 }
155 else {
156 $selectedProfile[] = $conf->default;
157 }
158 $box->add(new htmlResponsiveSelect('filename', $profileNames, $selectedProfile, _('Profile name')));
159 $passwordInput = new htmlResponsiveInputField(_('Password'), 'passwd', '', '200');
160 $passwordInput->setIsPassword(true);
161 $passwordInput->setCSSClasses(['lam-initial-focus']);
162 $box->add($passwordInput);
163 $box->addVerticalSpacer('1rem');
164 $button = new htmlButton('submit', _("Ok"));
165 $button->setCSSClasses(['lam-primary']);
166 $box->addLabel($button);
167 $box->add(new htmlOutputText(''), 0, 6);
168 $box->addVerticalSpacer('1.5rem');
169 $box->add(new htmlHorizontalLine());
170 $box->addVerticalSpacer('1.5rem');
171 }
172 $manageLink = new htmlLink(_("Manage server profiles"), 'profmanage.php');
173 $box->add($manageLink, 12, 12, 12, 'text-center');
174
175 $boxDiv = new htmlDiv(null, $box);
176 $boxDiv->setCSSClasses(['roundedShadowBox', 'limitWidth', 'text-center']);
177 $row->add($boxDiv);
178
179 // back link
180 $row->addVerticalSpacer('2rem');
181 $backLink = new htmlLink(_("Back to login"), '../login.php');
182 $row->add($backLink, 12, 12, 12, 'text-left');
183
184 parseHtml(null, new htmlDiv(null, $row, ['centeredTable']), [], false, 'user');
185
186 ?>
187 </form>
188
189 <p><br><br></p>
190
191
192 </body>
193 </html>