[BUGFIX] Using datetime field with datepicker the time information gets lost
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_superadmin.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Super Admin class has functions for the administration of multiple TYPO3 sites in folders
29 * See 'misc/superadmin.php' for details on how to use!
30 *
31 * $Id$
32 * Revised for TYPO3 3.6 February/2004 by Kasper Skårhøj
33 * XHTML Compliant
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 * 120: function debug($p1,$p2='')
41 *
42 *
43 * 134: class t3lib_superadmin
44 *
45 * SECTION: Initialize stuff
46 * 180: function t3lib_superadmin()
47 * 192: function init($parentDirs)
48 *
49 * SECTION: Main functions
50 * 215: function defaultSet()
51 * 271: function make()
52 *
53 * SECTION: Output preparation
54 * 376: function setMenuItem($code,$label)
55 * 390: function error($str)
56 * 401: function headerParentDir($str)
57 * 412: function headerSiteDir($str)
58 *
59 * SECTION: Collection information
60 * 444: function initProcess()
61 * 482: function processSiteDir($path,$dir)
62 * 524: function includeLocalconf($localconf)
63 * 554: function connectToDatabase($siteInfo)
64 * 576: function getDBInfo($key)
65 *
66 * SECTION: Content: Installation Overview
67 * 626: function makeTable()
68 *
69 * SECTION: Content: Local extensions
70 * 729: function localExtensions()
71 * 902: function getExtensionInfo($path,$extKey,$k)
72 * 956: function getAllFilesAndFoldersInPath($fileArr,$extPath,$extList='',$regDirs=0)
73 * 978: function findMostRecent($fileArr,$extPath)
74 * 996: function removePrefixPathFromList($fileArr,$extPath)
75 *
76 * SECTION: Content: Other
77 * 1033: function singleSite($exp)
78 * 1064: function loginLog($DB)
79 * 1102: function log_getDetails($text,$data)
80 * 1116: function rmCachedFiles($exp)
81 * 1149: function menuContent($exp)
82 * 1221: function makeAdminLogin()
83 * 1295: function changeAdminPasswordsForm()
84 * 1330: function setNewPasswords()
85 *
86 * TOTAL FUNCTIONS: 28
87 * (This index is automatically created/updated by the extension "extdeveval")
88 *
89 */
90
91
92 // *******************************
93 // Set error reporting
94 // *******************************
95 if (defined('E_DEPRECATED')) {
96 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
97 } else {
98 error_reporting(E_ALL ^ E_NOTICE);
99 }
100
101 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
102
103
104 // Dependency:
105 $path_t3lib = './typo3_src/t3lib/';
106 include_once($path_t3lib . 'class.t3lib_div.php');
107 include_once($path_t3lib . 'class.t3lib_db.php');
108 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
109
110
111 t3lib_div::deprecationLog('class.t3lib_superadmin.php is deprecated since TYPO3 4.5, this file will be removed in TYPO3 4.7.');
112
113
114 /**
115 * Debug function. Substitute since no config_default.php file is included anywhere
116 *
117 * @param mixed Debug var
118 * @param string Header string
119 * @return void
120 */
121 function debug($p1, $p2 = '') {
122 t3lib_div::debug($p1, $p2);
123 }
124
125
126 /**
127 * Super Admin class has functions for the administration of multiple TYPO3 sites in folders
128 * NOTICE: Only compliant with single MySQL database usage per installation!
129 *
130 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
131 * @package TYPO3
132 * @subpackage t3lib
133 */
134 class t3lib_superadmin {
135
136 // External, static:
137 var $targetWindow = 'superAdminWindow';
138 var $targetWindowAdmin = 'superAdminWindowAdmin';
139 var $targetWindowInstall = 'superAdminWindowInstall';
140 var $scriptName = 'superadmin.php';
141
142 // GP vars:
143 var $show; // "menu", "all", "admin", "info", "rmTempCached", "localext"
144 var $type; // "phpinfo", "page" - default renders a frameset
145 var $exp; // Additional parameter, typically a md5-hash pointing to an installation of TYPO3
146
147 // Internal, static:
148 var $parentDirs = array(); // Configured directories to search
149 var $globalSiteInfo = array(); // Array with information about found TYPO3 installations
150
151 var $currentUrl = '';
152 var $mapDBtoKey = array();
153 var $collectAdminPasswords = array();
154 var $changeAdminPasswords = array();
155 var $collectInstallPasswords = array();
156
157 // Control:
158 var $full = 0; // If set, the full information array per site is printed.
159
160 var $noCVS = 0; // See tools/em/index.php....
161
162
163 /**********************************
164 *
165 * Initialize stuff
166 *
167 **********************************/
168
169 /**
170 * Constructor, setting GP vars
171 *
172 * @return void
173 */
174 function t3lib_superadmin() {
175 $this->show = t3lib_div::_GP('show');
176 $this->type = t3lib_div::_GP('type');
177 $this->exp = t3lib_div::_GP('exp');
178 }
179
180 /**
181 * Initialize with configuration - from the 'superadmin.php' script. See misc/superadmin.php for example.
182 *
183 * @param array Numerical array with arrays having two keys, 'dir' and 'url' where 'dir' is the absolute path to a directory with TYPO3 installations inside.
184 * @return void
185 */
186 function init($parentDirs) {
187 $this->parentDirs = $parentDirs;
188 }
189
190
191 /**************************
192 *
193 * Main functions
194 *
195 **************************/
196
197 /**
198 * Main function, creating HTML content; frameset, menu, content frames.
199 * Outputs the full HTML to browser.
200 *
201 * @return void
202 */
203 function defaultSet() {
204
205 // Creating content based on "type" variable:
206 switch ($this->type) {
207 case 'phpinfo':
208 phpinfo();
209 break;
210 case 'page':
211 ?>
212 <!DOCTYPE html
213 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
214 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
215 <html>
216 <head>
217 <style type="text/css">
218 .redclass {
219 color: red;
220 }
221
222 P {
223 font-family: Verdana, Arial, Helvetica, sans-serif;
224 font-size: 11px
225 }
226
227 BODY {
228 font-family: Verdana, Arial, Helvetica, sans-serif;
229 font-size: 10px
230 }
231
232 H1 {
233 font-family: Verdana, Arial, Helvetica, sans-serif;
234 font-size: 20px;
235 color: #000066;
236 }
237
238 H2 {
239 font-family: Verdana, Arial, Helvetica, sans-serif;
240 font-size: 17px;
241 color: #000066;
242 }
243
244 H3 {
245 font-family: Verdana, Arial, Helvetica, sans-serif;
246 font-size: 14px;
247 color: #000066;
248 }
249
250 H4 {
251 font-family: Verdana, Arial, Helvetica, sans-serif;
252 font-size: 11px;
253 color: maroon;
254 }
255
256 TD {
257 font-family: Verdana, Arial, Helvetica, sans-serif;
258 font-size: 10px
259 }
260 </style>
261 <title>TYPO3 Super Admin</title>
262 </head>
263 <body>
264 <?php
265 echo $this->make();
266 ?>
267 </body>
268 </html>
269 <?php
270 break;
271 default:
272 ?>
273 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
274 <html>
275 <head>
276 <title>TYPO3 Super Admin</title>
277 </head>
278 <frameset cols="250,*">
279 <frame name="TSAmenu" src="superadmin.php?type=page&show=menu" marginwidth="10" marginheight="10"
280 scrolling="auto" frameborder="0">
281 <frame name="TSApage" src="superadmin.php?type=page" marginwidth="10" marginheight="10"
282 scrolling="auto" frameborder="0">
283 </frameset>
284 </html>
285 <?php
286 break;
287 }
288 }
289
290 /**
291 * Main function, creating page content.
292 *
293 * @return string HTML content.
294 */
295 function make() {
296
297 $retVal = '';
298
299 // Creating information about the sites found:
300 $content = $this->initProcess();
301
302 // Output mode:
303 switch ($this->show) {
304 case 'menu':
305 $lines = array();
306 $lines[] = $this->setMenuItem('info', 'INFO');
307 $lines[] = $this->setMenuItem('update', 'UPDATE');
308 $lines[] = '';
309 $lines[] = '<a href="' . htmlspecialchars($this->scriptName . '?type=page') . '" target="TSApage">Default</a>';
310 $lines[] = '<a href="' . htmlspecialchars($this->scriptName . '?type=page&show=all') . '" target="TSApage">All details</a>';
311 $lines[] = '<a href="' . htmlspecialchars($this->scriptName . '?type=page&show=admin') . '" target="TSApage">Admin logins</a>';
312 $lines[] = '<a href="' . htmlspecialchars($this->scriptName . '?type=phpinfo') . '" target="TSApage">phpinfo()</a>';
313 $lines[] = '<a href="' . htmlspecialchars($this->scriptName . '?type=page&show=localext') . '" target="TSApage">Local extensions</a>';
314 $lines[] = '';
315 $content = implode('<br />', $lines);
316 $content .= '<hr />';
317 $content .= $this->menuContent($this->exp);
318 $retVal = '<h2 align="center">TYPO3<br />Super Admin</h2>' . $content;
319 break;
320 case 'all':
321 $retVal = '
322 <h1>All details:</h1>
323 <h2>Overview:</h2>
324 ' . $this->makeTable() . '
325 <br /><hr /><br />
326 <h1>Details per site:</h1>
327 ' . $content;
328 break;
329 case 'admin':
330 $content = $this->setNewPasswords();
331 $this->makeTable();
332 $retVal = $content . '
333 <h1>Admin options:</h1>
334
335 <h2>Admin logins:</h2>
336 ' . $this->makeAdminLogin() . '
337 <br /><hr /><br />
338
339 <h2>TBE Admin Passwords:</h2>
340 ' . t3lib_div::view_array($this->collectAdminPasswords) . '
341 <br /><hr /><br />
342
343 <h2>Install Tool Passwords:</h2>
344 ' . t3lib_div::view_array($this->collectInstallPasswords) . '
345 <br /><hr /><br />
346
347 <h2>Change TBE Admin Passwords:</h2>
348 ' . $this->changeAdminPasswordsForm() . '
349 <br /><hr /><br />';
350 break;
351 case 'info':
352 $retVal = '
353 <h1>Single site details</h1>
354 ' . $this->singleSite($this->exp) .
355 '<br />';
356 break;
357 case 'rmTempCached':
358 $retVal = '
359 <h1>Removing temp_CACHED_*.php files</h1>
360 ' . $this->rmCachedFiles($this->exp) .
361 '<br />';
362 break;
363 case 'localext':
364 $retVal = '
365 <h1>Local Extensions Found:</h1>
366 ' . $this->localExtensions() .
367 '<br />';
368 break;
369 default:
370 $retVal = '
371 <h1>Default info:</h1>' .
372 $content;
373 break;
374 }
375 return $retVal;
376 }
377
378
379 /********************************
380 *
381 * Output preparation
382 *
383 *******************************/
384
385 /**
386 * Creates menu item from input.
387 *
388 * @param string Value for "&exp" parameter
389 * @param string The label
390 * @return string Wrapped value
391 */
392 function setMenuItem($code, $label) {
393 $out = '<a href="' . htmlspecialchars($this->scriptName . '?type=page&show=menu&exp=' . $code) . '" target="TSAmenu">' . htmlspecialchars($label) . '</a>';
394 if ($code == $this->exp) {
395 $out = '<span style="color:red;">&gt;&gt;</span>' . $out;
396 }
397 return $out;
398 }
399
400 /**
401 * Wrap string in red span tag (for errors)
402 *
403 * @param string Input string
404 * @return string Output string
405 */
406 function error($str) {
407 $out = '<span style="color:red; font-size: 14px; font-weight: bold;">' . htmlspecialchars($str) . '</span>';
408 return $out;
409 }
410
411 /**
412 * Wraps input string in <h2>
413 *
414 * @param string Input string
415 * @return string Output string, wrapped in <h2>
416 */
417 function headerParentDir($str) {
418 $out = '<h2>' . htmlspecialchars($str) . '</h2>';
419 return $out;
420 }
421
422 /**
423 * Wraps input string in <h3>
424 *
425 * @param string Input string
426 * @return string Output string, wrapped in <h3>
427 */
428 function headerSiteDir($str) {
429 $out = '<h3>' . htmlspecialchars($str) . '</h3>';
430 return $out;
431 }
432
433
434 /********************************
435 *
436 * Collection information
437 *
438 *******************************/
439
440 /**
441 * Traverses the parent dirs, collecting the list of TYPO3 installations into $this->globalSiteInfo
442 *
443 * @return string HTML content (The default view seen when starting the superadmin.php script)
444 */
445 function initProcess() {
446 $content = '';
447
448 foreach ($this->parentDirs as $k => $v) {
449 $dir = rtrim($v['dir'], '/');
450 $baseUrl = rtrim($v['url'], '/');
451 $content .= '<br /><br /><br />';
452 $content .= $this->headerParentDir($dir);
453 if (@is_dir($dir)) {
454 $in_dirs = t3lib_div::get_dirs($dir);
455 asort($in_dirs);
456 $dirArr = array();
457 foreach ($in_dirs as $k => $v) {
458 if (substr($v, 0, 9) != 'typo3_src') {
459 $this->currentUrl = $baseUrl . '/' . $v;
460 $content .= $this->headerSiteDir($v);
461 $content .= $this->processSiteDir($dir . '/' . $v, $dir);
462 }
463 }
464 } else {
465 $content .= $this->error('"' . $dir . '" was not a directory!');
466 }
467 }
468
469 return $content;
470 }
471
472 /**
473 * Creating information array for a specific TYPO3 installation
474 * Information about site is stored in ->globalSiteInfo array
475 *
476 * @param string Absolute path to installation (PATH_site)
477 * @param string Directory of main directory (level under PATH_site)
478 * @return string HTML content with information about the site.
479 * @access private
480 * @see initProcess()
481 */
482 function processSiteDir($path, $dir) {
483 $out = '';
484 if (@is_dir($path)) {
485 $localconf = $path . '/typo3conf/localconf.php';
486 if (@is_file($localconf)) {
487 $key = md5($localconf);
488 $this->includeLocalconf($localconf);
489
490 $this->mapDBtoKey[$this->globalSiteInfo[$key]['siteInfo']['TYPO3_db']] = $key;
491 $this->globalSiteInfo[$key]['siteInfo']['MAIN_DIR'] = $dir;
492 $this->globalSiteInfo[$key]['siteInfo']['SA_PATH'] = $path;
493 $this->globalSiteInfo[$key]['siteInfo']['URL'] = $this->currentUrl . '/';
494 $this->globalSiteInfo[$key]['siteInfo']['ADMIN_URL'] = $this->currentUrl . '/' . TYPO3_mainDir;
495 $this->globalSiteInfo[$key]['siteInfo']['INSTALL_URL'] = $this->currentUrl . '/' . TYPO3_mainDir . 'install/';
496
497 // Connect to database:
498 $conMsg = $this->connectToDatabase($this->globalSiteInfo[$key]['siteInfo']);
499 if (!$conMsg) {
500 $this->getDBInfo($key);
501 $out .= '';
502 } else {
503 $out = $conMsg;
504 }
505
506 // Show details:
507 if ($this->full) {
508 $out .= t3lib_div::view_array($this->globalSiteInfo[$key]);
509 } else {
510 $out .= t3lib_div::view_array($this->globalSiteInfo[$key]['siteInfo']);
511 }
512 } else {
513 $out = $this->error($localconf . ' is not a file!');
514 }
515 } else {
516 $out = $this->error($path . ' is not a directory!');
517 }
518 return $out;
519 }
520
521 /**
522 * Includes "localconf" of a TYPO3 installation an loads $this->globalSiteInfo with this information.
523 *
524 * @param string Absolute path to localconf.php file to include.
525 * @return array Array with information about the site.
526 * @access private
527 * @see processSiteDir()
528 */
529 function includeLocalconf($localconf) {
530 $TYPO3_CONF_VARS = array();
531 $typo_db = '';
532 $typo_db_username = '';
533 $typo_db_password = '';
534 $typo_db_host = '';
535
536 include($localconf);
537
538 $siteInfo = array();
539 $siteInfo['sitename'] = $TYPO3_CONF_VARS['SYS']['sitename'];
540 $siteInfo['TYPO3_db'] = $typo_db;
541 $siteInfo['TYPO3_db_username'] = $typo_db_username;
542 $siteInfo['TYPO3_db_password'] = $typo_db_password;
543 $siteInfo['TYPO3_db_host'] = $typo_db_host;
544 $siteInfo['installToolPassword'] = $TYPO3_CONF_VARS['BE']['installToolPassword'];
545 $siteInfo['warningEmailAddress'] = $TYPO3_CONF_VARS['BE']['warning_email_addr'];
546 $siteInfo['warningMode'] = $TYPO3_CONF_VARS['BE']['warning_mode'];
547
548 $this->globalSiteInfo[md5($localconf)] = array('siteInfo' => $siteInfo, 'TYPO3_CONF_VARS' => $TYPO3_CONF_VARS);
549 return $siteInfo;
550 }
551
552 /**
553 * Connects to a MySQL database with the TYPO3 db host/username/password and database as found in the localconf.php file!
554 * This is NOT compatible with DBAL and connection will obviously just fail with an error message if it turns out that the _DEFAULT handler of a site is not in a MySQL database
555 *
556 * @param array $siteInfo array, containing username/password/host/database values.
557 * @return string Array message if any
558 */
559 function connectToDatabase($siteInfo) {
560 if (@mysql_pconnect($siteInfo['TYPO3_db_host'], $siteInfo['TYPO3_db_username'], $siteInfo['TYPO3_db_password'])) {
561 if (!$siteInfo['TYPO3_db']) {
562 return $this->error('No database selected');
563 } elseif (!mysql_select_db($siteInfo['TYPO3_db'])) {
564 return $this->error('Cannot connect to the current database, "' . $siteInfo['TYPO3_db'] . '"');
565 }
566 } else {
567 return $this->error('The current username, password or host was not accepted when the connection to the database was attempted to be established!');
568 }
569 }
570
571
572 /**
573 * Get database information, assuming standard tables like "be_users"
574 * Adding the information to ->globalSiteInfo
575 *
576 * @param string Key for site in ->globalSiteInfo
577 * @return void
578 * @access private
579 * @see processSiteDir()
580 */
581 function getDBInfo($key) {
582 $DB = $this->globalSiteInfo[$key]['siteInfo']['TYPO3_db'];
583
584 // Non-admin users
585 $query = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', 'be_users', 'admin=0 AND deleted=0');
586 $res = mysql($DB, $query);
587 $row = mysql_fetch_row($res);
588 $this->globalSiteInfo[$key]['siteInfo']['BE_USERS_NONADMIN'] = $row[0];
589
590 // Admin users
591 $query = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', 'be_users', 'admin!=0 AND deleted=0');
592 $res = mysql($DB, $query);
593 $row = mysql_fetch_row($res);
594 $this->globalSiteInfo[$key]['siteInfo']['BE_USERS_ADMIN'] = $row[0];
595
596 // Select Admin users
597 $query = $GLOBALS['TYPO3_DB']->SELECTquery('uid,username,password,email,realName,disable', 'be_users', 'admin!=0 AND deleted=0');
598 $res = mysql($DB, $query);
599 while ($row = mysql_fetch_assoc($res)) {
600 $this->globalSiteInfo[$key]['siteInfo']['ADMINS'][] = $row;
601 }
602 }
603
604
605 /******************************
606 *
607 * Content: Installation Overview
608 *
609 ******************************/
610
611 /**
612 * Creates big table with information about all installations in ->globalSiteInfo
613 *
614 * @return string HTML table
615 */
616 function makeTable() {
617
618 // Header row
619 $info = array();
620 $info[] = 'Site:';
621 $info[] = 'Path:';
622 $info[] = 'Database:';
623 $info[] = 'Username';
624 $info[] = 'Password';
625 $info[] = 'Host';
626 $info[] = 'Links (new win)';
627 $info[] = '#Users NA/A';
628 $info[] = 'Admin be_users Info';
629 $info[] = 'Install Tool Password';
630 $info[] = 'Warning email address';
631 $info[] = 'W.mode';
632 $mainArrRows[] = '
633 <tr bgcolor="#eeeeee">
634 <td nowrap="nowrap" valign="top">' . implode('</td>
635 <td nowrap="nowrap" valign="top">', $info) . '</td>
636 </tr>';
637
638 // Traverse globalSiteInfo for each site:
639 foreach ($this->globalSiteInfo as $k => $all) {
640 $info = array();
641
642 // Sitename and Database details:
643 $info[] = htmlspecialchars($all['siteInfo']['sitename']);
644 $info[] = '<span style="color:#666666;">' . htmlspecialchars($all['siteInfo']['MAIN_DIR']) . '</span>' . htmlspecialchars(substr($all['siteInfo']['SA_PATH'], strlen($all['siteInfo']['MAIN_DIR'])));
645 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db']);
646 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db_username']);
647 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db_password']);
648 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db_host']);
649
650 // URL
651 $info[] = '<a href="' . htmlspecialchars($all['siteInfo']['URL']) . '" target="' . $this->targetWindow . '">Site</a>' .
652 ' / <a href="' . htmlspecialchars($all['siteInfo']['ADMIN_URL']) . '" target="' . $this->targetWindowAdmin . '">Admin</a>' .
653 ' / <a href="' . htmlspecialchars($all['siteInfo']['INSTALL_URL']) . '" target="' . $this->targetWindowInstall . '">Install</a>';
654 $info[] = htmlspecialchars($all['siteInfo']['BE_USERS_NONADMIN'] . '/' . $all['siteInfo']['BE_USERS_ADMIN']);
655
656 // Admin
657 if (is_array($all['siteInfo']['ADMINS'])) {
658 $lines = array();
659 foreach ($all['siteInfo']['ADMINS'] as $vArr) {
660 $lines[] = htmlspecialchars($vArr['password'] . ' - ' . $vArr['username'] . ' (' . $vArr['realName'] . ', ' . $vArr['email'] . ')');
661 $this->collectAdminPasswords[$vArr['password']][] = array(
662 'path' => $all['siteInfo']['SA_PATH'],
663 'site' => $all['siteInfo']['sitename'],
664 'database' => $all['siteInfo']['TYPO3_db'],
665 'user' => $vArr['username'],
666 'name_email' => $vArr['realName'] . ', ' . $vArr['email']
667 );
668 $this->changeAdminPasswords[$vArr['password']][] = $all['siteInfo']['TYPO3_db'] . ':' . $vArr['uid'] . ':' . $vArr['username'];
669 }
670 $info[] = implode('<br />', $lines);
671 } else {
672 $info[] = $this->error('No DB connection!');
673 }
674 // Install
675 $info[] = htmlspecialchars($all['siteInfo']['installToolPassword']);
676 $this->collectInstallPasswords[$all['siteInfo']['installToolPassword']][] = $all['siteInfo']['SA_PATH'] . ' - ' . $all['siteInfo']['sitename'] . ' - (' . $all['siteInfo']['TYPO3_db'] . ')';
677
678 $info[] = htmlspecialchars($all['siteInfo']['warningEmailAddress']);
679 $info[] = htmlspecialchars($all['siteInfo']['warningMode']);
680
681 // compile
682 $mainArrRows[] = '
683 <tr>
684 <td nowrap="nowrap" valign="top">' . implode('</td>
685 <td nowrap="nowrap" valign="top">', $info) . '</td>
686 </tr>';
687 }
688
689 // Compile / return table finally:
690 $table = '<table border="1" cellpadding="1" cellspacing="1">' . implode('', $mainArrRows) . '</table>';
691 return $table;
692 }
693
694
695 /******************************
696 *
697 * Content: Local extensions
698 *
699 ******************************/
700
701 /**
702 * Based on the globalSiteInfo array, this prints information about local extensions for each site.
703 * In particular version number and most recent mod-time is interesting!
704 *
705 * @return string HTML
706 */
707 function localExtensions() {
708 $this->extensionInfoArray = array();
709
710 // Traverse $this->globalSiteInfo for local extensions:
711 foreach ($this->globalSiteInfo as $k => $all) {
712 if ($all['siteInfo']['SA_PATH']) {
713 $extDir = $all['siteInfo']['SA_PATH'] . '/typo3conf/ext/';
714 if (@is_dir($extDir)) {
715 $this->extensionInfoArray['site'][$k] = array();
716
717 // Get extensions in local directory
718 $extensions = t3lib_div::get_dirs($extDir);
719 if (is_array($extensions)) {
720 foreach ($extensions as $extKey) {
721 // Getting and setting information for extension:
722 $eInfo = $this->getExtensionInfo($extDir, $extKey, $k);
723 $this->extensionInfoArray['site'][$k][$extKey] = $eInfo;
724 $this->extensionInfoArray['ext'][$extKey][$k] = $eInfo;
725 }
726 }
727 }
728 }
729 }
730
731 // Display results:
732 $out = '';
733 $headerRow = '
734 <tr bgcolor="#ccccee" style="font-weight:bold;">
735 <td>Extension key</td>
736 <td>Path</td>
737 <td>Title</td>
738 <td>Ver.</td>
739 <td>Files</td>
740 <td><span title="If M, then there is a manual.">M</span></td>
741 <td>Last mod. time</td>
742 <td>Hash off all file mod. times:</td>
743 <td>TYPO3 ver. req.</td>
744 <td>CGL compliance</td>
745 </tr>
746 ';
747
748 // PER EXTENSION:
749 if (is_array($this->extensionInfoArray['ext'])) {
750 $extensionKeysCollect = array();
751
752 ksort($this->extensionInfoArray['ext']);
753 reset($this->extensionInfoArray['ext']);
754 $rows = array(
755 'reg' => array(),
756 'user' => array()
757 );
758
759 foreach ($this->extensionInfoArray['ext'] as $extKey => $instances) {
760 $mtimes = array();
761
762 // Find most recent mtime of the options:
763 foreach ($instances as $k => $eInfo) {
764 $mtimes[] = $eInfo['mtime'];
765 }
766 // Max mtime:
767 $maxMtime = max($mtimes);
768 $c = 0;
769
770 // So, traverse all sites with the extension present:
771 foreach ($instances as $k => $eInfo) {
772 // Set background color if mtime matches
773 if ($maxMtime == $eInfo['mtime']) {
774 $this->extensionInfoArray['site'][$k][$extKey]['_highlight'] = 1;
775 $bgCol = $eInfo['dirtype'] == 'link' ? ' bgcolor="#ffcccc"' : ' bgcolor="#eeeeee"';
776 } else {
777 $bgCol = ' style="color: #999999; font-style: italic;"';
778 }
779
780 // Make row:
781 $type = substr($extKey, 0, 5) != 'user_' ? 'reg' : 'user';
782 if ($type == 'reg') {
783 $extensionKeysCollect[] = $extKey;
784 }
785
786 if (!is_array($eInfo)) {
787 // Standard listing:
788 $rows[$type][] = '
789 <tr>
790 ' . (!$c ? '<td rowspan="' . count($instances) . '">' . htmlspecialchars($extKey) . '</td>' : '') . '
791 <td nowrap="nowrap" bgcolor="#ccddcc">' . htmlspecialchars($this->globalSiteInfo[$k]['siteInfo']['SA_PATH']) . '</td>
792 <td nowrap="nowrap" bgcolor="#ccddcc" colspan="8"><em>' . htmlspecialchars($eInfo) . '</em></td>
793 </tr>
794 ';
795 } else {
796 // Standard listing:
797 $rows[$type][] = '
798 <tr>
799 ' . (!$c ? '<td rowspan="' . count($instances) . '">' . htmlspecialchars($extKey) . '</td>' : '') . '
800 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($this->globalSiteInfo[$k]['siteInfo']['SA_PATH']) . '</td>
801 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['title']) . '</td>
802 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['version']) . '</td>
803 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['numberfiles']) . '</td>
804 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['manual'] ? 'M' : '-') . '</td>
805 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['mtime'] ? date('d-m-y H:i:s', $eInfo['mtime']) : '') . '</td>
806 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['mtime_hash']) . '</td>
807
808 <td' . $bgCol . '>' . htmlspecialchars($eInfo['TYPO3_version']) . '</td>
809 <td' . $bgCol . '><img src="clear.gif" width="150" height="1" alt="" /><br />' . htmlspecialchars($eInfo['CGLcompliance'] . ($eInfo['CGLcompliance_note'] ? ' - ' . $eInfo['CGLcompliance_note'] : '')) . '</td>
810 </tr>
811 ';
812 }
813 $c++;
814 }
815 }
816
817 // Extensions with registered extension keys:
818 $out .= '
819 <h3>Registered extensions:</h3>
820 <table border="1">' . $headerRow . implode('', $rows['reg']) . '</table>';
821
822 // List of those extension keys in a form field:
823 $extensionKeysCollect = array_unique($extensionKeysCollect);
824 asort($extensionKeysCollect);
825 $out .= '<form action=""><textarea cols="80" rows="10">' . implode(LF, $extensionKeysCollect) . '</textarea></form>';
826
827 // USER extension (prefixed "user_")
828 $out .= '<br />
829 <h3>User extensions:</h3>
830 <table border="1">' . $headerRow . implode('', $rows['user']) . '</table>';
831 }
832
833 // PER SITE:
834 if (is_array($this->extensionInfoArray['site'])) {
835 $rows = array();
836 foreach ($this->extensionInfoArray['site'] as $k => $extensions) {
837
838 // So, traverse all sites with the extension present:
839 $c = 0;
840 foreach ($extensions as $extKey => $eInfo) {
841
842 // Set background color if mtime matches
843 if ($eInfo['_highlight']) {
844 $bgCol = $eInfo['dirtype'] == 'link' ? ' bgcolor="#ffcccc"' : ' bgcolor="#eeeeee"';
845 } else {
846 $bgCol = ' style="color: #999999; font-style: italic;"';
847 }
848
849 // Make row:
850 $rows[] = '
851 <tr>
852 ' . (!$c ? '<td rowspan="' . count($extensions) . '">' . htmlspecialchars($this->globalSiteInfo[$k]['siteInfo']['SA_PATH']) . '</td>' : '') . '
853 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($extKey) . '</td>
854 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['title']) . '</td>
855 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['version']) . '</td>
856 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['numberfiles']) . '</td>
857 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['mtime'] ? date('d-m-y H:i:s', $eInfo['mtime']) : '') . '</td>
858 <td nowrap="nowrap"' . $bgCol . '>' . htmlspecialchars($eInfo['mtime_hash']) . '</td>
859 </tr>
860 ';
861 $c++;
862 }
863 }
864 $out .= '<br />
865 <h3>Sites:</h3>
866 <table border="1">' . implode('', $rows) . '</table>';
867 }
868
869 // Return content
870 return $out;
871 }
872
873 /**
874 * Gets information for an extension, eg. version and most-recently-edited-script
875 *
876 * @param string Path to local extension folder
877 * @param string Extension key
878 * @param string Key to globalSiteInformation array
879 * @return array Information array (unless an error occured)
880 */
881 function getExtensionInfo($path, $extKey, $k) {
882 $file = $path . $extKey . '/ext_emconf.php';
883 if (@is_file($file)) {
884 $_EXTKEY = $extKey;
885 $EM_CONF = array();
886 include($file);
887
888 $eInfo = array();
889 // Info from emconf:
890 $eInfo['title'] = $EM_CONF[$extKey]['title'];
891 $eInfo['version'] = $EM_CONF[$extKey]['version'];
892 $eInfo['CGLcompliance'] = $EM_CONF[$extKey]['CGLcompliance'];
893 $eInfo['CGLcompliance_note'] = $EM_CONF[$extKey]['CGLcompliance_note'];
894 $eInfo['TYPO3_version'] = $EM_CONF[$extKey]['TYPO3_version'];
895 $filesHash = unserialize($EM_CONF[$extKey]['_md5_values_when_last_written']);
896
897 if (!is_array($filesHash) || count($filesHash) < 500) {
898
899 // Get all files list (may take LOONG time):
900 $extPath = $path . $extKey . '/';
901 $fileArr = array();
902 $fileArr = $this->removePrefixPathFromList($this->getAllFilesAndFoldersInPath($fileArr, $extPath), $extPath);
903
904 if (!is_array($fileArr)) {
905 debug(array($fileArr, $extKey, $extPath, $this->getAllFilesAndFoldersInPath(array(), $extPath)), 'ERROR');
906 }
907
908 // Number of files:
909 $eInfo['numberfiles'] = count($fileArr);
910 $eInfo['dirtype'] = filetype($path . $extKey);
911
912 // Most recent modification:
913 $eInfo['mtime_files'] = $this->findMostRecent($fileArr, $extPath);
914 if (count($eInfo['mtime_files'])) {
915 $eInfo['mtime'] = max($eInfo['mtime_files']);
916 }
917 $eInfo['mtime_hash'] = md5(implode(',', $eInfo['mtime_files']));
918 } else {
919 $eInfo['mtime_hash'] = 'No calculation done, too many files in extension: ' . count($filesHash);
920 }
921
922 $eInfo['manual'] = @is_file($path . $extKey . '/doc/manual.sxw');
923
924 return $eInfo;
925 } else {
926 return 'ERROR: No emconf.php file: ' . $file;
927 }
928 }
929
930 /**
931 * Recursively gather all files and folders of extension path.
932 *
933 * @param array Array of files to which new files are added
934 * @param string Path to look up files in
935 * @param string List of file extensions to include. Blank = all
936 * @param boolean If set, directories are included as well.
937 * @return array $fileArr with new entries added.
938 */
939 function getAllFilesAndFoldersInPath($fileArr, $extPath, $extList = '', $regDirs = 0) {
940 if ($regDirs) {
941 $fileArr[] = $extPath;
942 }
943 $fileArr = array_merge($fileArr, t3lib_div::getFilesInDir($extPath, $extList, 1, 1));
944
945 $dirs = t3lib_div::get_dirs($extPath);
946 if (is_array($dirs)) {
947 foreach ($dirs as $subdirs) {
948 if ($subdirs && (strcmp($subdirs, 'CVS') || !$this->noCVS)) {
949 $fileArr = $this->getAllFilesAndFoldersInPath($fileArr, $extPath . $subdirs . '/', $extList, $regDirs);
950 }
951 }
952 }
953 return $fileArr;
954 }
955
956 /**
957 * Creates an array with modification times of all files in $fileArr
958 *
959 * @param array Files in extension (rel path)
960 * @param string Abs path prefix for files.
961 * @return array Array with modification times of files (filenames are keys)
962 */
963 function findMostRecent($fileArr, $extPath) {
964 $mtimeArray = array();
965 foreach ($fileArr as $fN) {
966 if ($fN != 'ext_emconf.php') {
967 $mtime = filemtime($extPath . $fN);
968 $mtimeArray[$fN] = $mtime;
969 }
970 }
971 return $mtimeArray;
972 }
973
974 /**
975 * Removes the absolute part of all files/folders in fileArr
976 *
977 * @param array File array
978 * @param string Prefix to remove
979 * @return array Modified file array (or error string)
980 */
981 function removePrefixPathFromList($fileArr, $extPath) {
982 foreach ($fileArr as $k => $absFileRef) {
983 if (t3lib_div::isFirstPartOfStr($absFileRef, $extPath)) {
984 $fileArr[$k] = substr($absFileRef, strlen($extPath));
985 } else {
986 return 'ERROR: One or more of the files was NOT prefixed with the prefix-path!';
987 }
988 }
989 return $fileArr;
990 }
991
992
993 /******************************
994 *
995 * Content: Other
996 *
997 ******************************/
998
999 /**
1000 * Shows detailed information for a single installation of TYPO3
1001 *
1002 * @param string KEY pointing to installation
1003 * @return string HTML content
1004 */
1005 function singleSite($exp) {
1006 $all = $this->globalSiteInfo[$exp];
1007
1008 // General information:
1009 $content = '
1010 <h2>' . htmlspecialchars($all['siteInfo']['sitename'] . ' (DB: ' . $all['siteInfo']['TYPO3_db']) . ')</h2>
1011 <hr />
1012
1013 <h3>Main details:</h3>
1014
1015 LINKS: <a href="' . htmlspecialchars($all['siteInfo']['URL']) . '" target="' . $this->targetWindow . '">Site</a> / <a href="' . htmlspecialchars($all['siteInfo']['ADMIN_URL']) . '" target="' . $this->targetWindowAdmin . '">Admin</a> / <a href="' . htmlspecialchars($all['siteInfo']['INSTALL_URL']) . '" target="' . $this->targetWindowInstall . '">Install</a>
1016 <br /><br />';
1017
1018 // Add all information in globalSiteInfo array:
1019 $content .= t3lib_div::view_array($all);
1020
1021 // Last-login:
1022 $content .= '
1023 <h3>Login-Log for last month:</h3>';
1024 $content .= $this->loginLog($all['siteInfo']['TYPO3_db']);
1025
1026 // Return content
1027 return $content;
1028 }
1029
1030 /**
1031 * Get last-login log for database.
1032 *
1033 * @param string Database
1034 * @return string HTML
1035 */
1036 function loginLog($DB) {
1037 // Non-admin users
1038 //1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent
1039 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
1040 'sys_log.*, be_users.username AS username, be_users.admin AS admin',
1041 'sys_log,be_users',
1042 'be_users.uid=sys_log.userid AND sys_log.type=255 AND sys_log.tstamp > ' . ($GLOBALS['EXEC_TIME'] - (60 * 60 * 24 * 30)),
1043 '',
1044 'sys_log.tstamp DESC'
1045 );
1046 $res = mysql($DB, $query);
1047
1048 $dayRef = '';
1049 $lines = array();
1050
1051 while ($row = mysql_fetch_assoc($res)) {
1052 $day = date('d-m-Y', $row['tstamp']);
1053 if ($dayRef != $day) {
1054 $lines[] = '
1055 <h4>' . $day . ':</h4>';
1056 $dayRef = $day;
1057 }
1058 $theLine = date('H:i', $row['tstamp']) . ': ' . str_pad(substr($row['username'], 0, 10), 10) . ' ' . $this->log_getDetails($row['details'], unserialize($row['log_data']));
1059 $theLine = htmlspecialchars($theLine);
1060 $lines[] = $row['admin'] ? '<span class="redclass">' . $theLine . '</span>' : $theLine;
1061 }
1062 return '<pre>' . implode(LF, $lines) . '</pre>';
1063 }
1064
1065 /**
1066 * Compile log details into template string
1067 *
1068 * @param string Log message (template)
1069 * @param array Data array to insert in log message
1070 * @return string Log details.
1071 */
1072 function log_getDetails($text, $data) {
1073 // $code is used later on to substitute errormessages with language-corrected values...
1074 if (is_array($data)) {
1075 return sprintf($text, $data[0], $data[1], $data[2], $data[3], $data[4]);
1076 } else {
1077 return $text;
1078 }
1079 }
1080
1081
1082 /**
1083 * Removing temp_CACHED files for installation
1084 *
1085 * @param string KEY pointing to installation
1086 * @return string HTML content
1087 */
1088 function rmCachedFiles($exp) {
1089 $all = $this->globalSiteInfo[$exp];
1090 $content = '
1091 <h2>' . htmlspecialchars($all['siteInfo']['sitename'] . ' (DB: ' . $all['siteInfo']['TYPO3_db']) . ')</h2>
1092 <hr />
1093 <h3>typo3conf/temp_CACHED_* files:</h3>';
1094
1095 $path = $all['siteInfo']['SA_PATH'] . '/typo3conf/';
1096 if (@is_dir($path)) {
1097 $filesInDir = t3lib_div::getFilesInDir($path, 'php', 1);
1098
1099 foreach ($filesInDir as $kk => $vv) {
1100 if (t3lib_div::isFirstPartOfStr(basename($vv), 'temp_CACHED_')) {
1101 if (strstr(basename($vv), 'ext_localconf.php') || strstr(basename($vv), 'ext_tables.php')) {
1102 $content .= 'REMOVED: ' . $vv . '<br />';
1103 unlink($vv);
1104 if (file_exists($vv)) {
1105 $content .= $this->error('ERROR: File still exists, so could not be removed anyways!') . '<br />';
1106 }
1107 }
1108 }
1109 }
1110 } else {
1111 $content .= $this->error('ERROR: ' . $path . ' was not a directory!');
1112 }
1113
1114 return $content;
1115 }
1116
1117 /**
1118 * Menu for either update/information, showing links for each installation found
1119 *
1120 * @param string Action key "update" or "info"
1121 * @return string HTML output.
1122 */
1123 function menuContent($exp) {
1124 if ($exp) {
1125
1126 // Initialize:
1127 $lines = array();
1128 $head = '';
1129
1130 foreach ($this->globalSiteInfo as $k => $all) {
1131
1132 // Setting section header, if needed.
1133 if ($head != $all['siteInfo']['MAIN_DIR']) {
1134 $lines[] = '
1135 <h4 style="white-space: nowrap;">' . htmlspecialchars(t3lib_div::fixed_lgd_cs($all['siteInfo']['MAIN_DIR'], -18)) . '</h4>';
1136 $head = $all['siteInfo']['MAIN_DIR']; // Set new head...
1137 }
1138
1139 // Display mode:
1140 switch ($exp) {
1141 case 'update':
1142
1143 // Label:
1144 $label = $all['siteInfo']['sitename'] ? $all['siteInfo']['sitename'] : '(DB: ' . $all['siteInfo']['TYPO3_db'] . ')';
1145 $lines[] = '
1146 <hr />
1147 <strong>' . htmlspecialchars($label) . '</strong> (' . htmlspecialchars(substr($all['siteInfo']['SA_PATH'], strlen($all['siteInfo']['MAIN_DIR']) + 1)) . ')<br />';
1148
1149 // To avoid "visited links" display on next hit:
1150 $tempVal = '&_someUniqueValue=' . $GLOBALS['EXEC_TIME'];
1151
1152 // Add links for update:
1153 $url = $this->scriptName . '?type=page&show=rmTempCached&exp=' . $k . $tempVal;
1154 $lines[] = '<span style="white-space: nowrap;"><a href="' . htmlspecialchars($url) . '" target="TSApage">Remove temp_CACHED files</a></span>';
1155
1156 $url = $all['siteInfo']['INSTALL_URL'] . 'index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=import|CURRENT_STATIC' . "&presetWholeTable=1" . $tempVal . '#bottom';
1157 $lines[] = '<span style="white-space: nowrap;"><a href="' . htmlspecialchars($url) . '" target="TSApage">CURRENT_STATIC</a></span>';
1158
1159 $url = $all['siteInfo']['INSTALL_URL'] . 'index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=cmpFile|CURRENT_TABLES' . $tempVal . '#bottom';
1160 $lines[] = '<span style="white-space: nowrap;"><a href="' . htmlspecialchars($url) . '" target="TSApage">CURRENT_TABLES</a></span>';
1161
1162 // Cache
1163 $url = $all['siteInfo']['INSTALL_URL'] . 'index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=cache|' .
1164 "&PRESET[database_clearcache][cache_pages]=1" .
1165 '&PRESET[database_clearcache][cache_pagesection]=1' .
1166 "&PRESET[database_clearcache][cache_hash]=1" .
1167 $tempVal .
1168 '#bottom';
1169 $lines[] = '<span style="white-space: nowrap;"><a href="' . htmlspecialchars($url) . '" target="TSApage">Clear cache</a></span>';
1170
1171 // Admin link
1172 $url = $all['siteInfo']['ADMIN_URL'] . 'index.php';
1173 $lines[] = '<span style="white-space: nowrap;"><a href="' . htmlspecialchars($url) . '" target="' . $this->targetWindowAdmin . '">Admin -></a></span>';
1174 break;
1175 case 'info':
1176 // item
1177 $label = $all['siteInfo']['sitename'] ? $all['siteInfo']['sitename'] : '(DB: ' . $all['siteInfo']['TYPO3_db'] . ')';
1178
1179 $url = $this->scriptName . '?type=page&show=info&exp=' . $k;
1180 $lines[] = '<span style="white-space: nowrap;"><a href="' . htmlspecialchars($url) . '" target="TSApage">' . htmlspecialchars($label) . '</a> (' . htmlspecialchars(substr($all['siteInfo']['SA_PATH'], strlen($all['siteInfo']['MAIN_DIR']) + 1)) . '/)</span>';
1181 break;
1182 }
1183 }
1184
1185 // Return result.
1186 return implode('<br />', $lines) . '<br />';
1187 }
1188 }
1189
1190 /**
1191 * Create list of admin logins.
1192 *
1193 * @return string HTML table
1194 */
1195 function makeAdminLogin() {
1196
1197 // Initialize:
1198 $lines = array();
1199 $head = '';
1200
1201 // Traverse installations found:
1202 foreach ($this->globalSiteInfo as $k => $all) {
1203
1204 // Setting section header, if needed.
1205 if ($head != $all['siteInfo']['MAIN_DIR']) {
1206 $lines[] = '
1207 <tr>
1208 <td colspan="2"><br />
1209 <h4>' . htmlspecialchars($all['siteInfo']['MAIN_DIR']) . '</h4>
1210 </td>
1211 </tr>';
1212 $head = $all['siteInfo']['MAIN_DIR'];
1213 }
1214
1215 // item
1216 $label = $all['siteInfo']['sitename'] ? $all['siteInfo']['sitename'] : '(DB: ' . $all['siteInfo']['TYPO3_db'] . ')';
1217 $unique = md5(microtime());
1218
1219 $opts = array();
1220 $defUName = '';
1221
1222 if (is_array($all['siteInfo']['ADMINS'])) {
1223
1224 foreach ($all['siteInfo']['ADMINS'] as $vArr) {
1225 $chalVal = md5($vArr['username'] . ':' . $vArr['password'] . ':' . $unique);
1226 $opts[] = '<option value="' . $chalVal . '">' . htmlspecialchars($vArr['username'] . ($vArr['disable'] ? ' [DISABLED]' : '')) . '</option>';
1227 if (!$defUName) {
1228 $defUName = $vArr['username'];
1229 }
1230 }
1231 }
1232 if (count($opts) > 1) {
1233 $userident = '
1234 <select name="userident" onchange="document[\'' . $k . '\'].username.value=this.options[this.selectedIndex].text;">
1235 ' . implode('
1236 ', $opts) . '
1237 </select>
1238 ';
1239 } else {
1240 $userident = '
1241 (' . $defUName . ')<br />
1242 <input type="hidden" name="userident" value="' . $chalVal . '" />';
1243 }
1244
1245 $form = '
1246 <form name="' . $k . '" action="' . $all['siteInfo']['ADMIN_URL'] . 'index.php" target="EXTERnalWindow" method="post">
1247 <input type="submit" name="submit" value="Login" />
1248 <input type="hidden" name="username" value="' . $defUName . '" />
1249 <input type="hidden" name="challenge" value="' . $unique . '" />
1250 <input type="hidden" name="redirect_url" value="" />
1251 <input type="hidden" name="login_status" value="login" />
1252 ' . trim($userident) . '
1253 </form>';
1254
1255 $lines[] = '
1256 <tr>
1257 <td><strong>' . htmlspecialchars($label) . '</strong></td>
1258 <td nowrap="nowrap">' . trim($form) . '</td>
1259 </tr>';
1260 }
1261
1262 // Return login table:
1263 return '<table border="1" cellpadding="5" cellspacing="1">' . implode('', $lines) . '</table>';
1264 }
1265
1266 /**
1267 * For for changing admin passwords
1268 *
1269 * @return string Form content.
1270 */
1271 function changeAdminPasswordsForm() {
1272 $content = '';
1273
1274 foreach ($this->changeAdminPasswords as $k => $p) {
1275 $content .= '
1276 <h3>' . $k . '</h3>';
1277
1278 foreach ($p as $kk => $pp) {
1279 $content .= '<span style="white-space: nowrap;">';
1280 $content .= '<input type="checkbox" name="SETFIELDS[]" value="' . $pp . '" /> ' . $pp . ' - ';
1281 $content .= htmlspecialchars(implode(' - ', $this->collectAdminPasswords[$k][$kk]));
1282 $content .= '</span><br />';
1283 }
1284 }
1285
1286 $content .= 'New password: <input type="text" name="NEWPASS" /><br />';
1287 $content .= 'New password (md5): <input type="text" name="NEWPASS_md5" /><br />
1288 (This overrules any plain password above!)
1289 <br />';
1290 $content = '
1291 <form action="' . htmlspecialchars($this->scriptName . '?type=page&show=admin') . '" method="post">
1292 ' . $content . '
1293 <input type="submit" name="Set" />
1294 </form>
1295 ';
1296
1297 return $content;
1298 }
1299
1300 /**
1301 * Setting new passwords
1302 *
1303 * @return string Status
1304 * @see changeAdminPasswordsForm()
1305 */
1306 function setNewPasswords() {
1307 $whichFields = t3lib_div::_POST('SETFIELDS');
1308 $pass = trim(t3lib_div::_POST('NEWPASS'));
1309 $passMD5 = t3lib_div::_POST('NEWPASS_md5');
1310
1311 $content = '';
1312 $updatedFlag = 0;
1313 if (($pass || $passMD5) && is_array($whichFields)) {
1314 $pass = $passMD5 ? $passMD5 : md5($pass);
1315
1316 foreach ($whichFields as $values) {
1317 $parts = explode(':', $values);
1318 if (count($parts) > 2) {
1319 $key = $this->mapDBtoKey[$parts[0]];
1320 if ($key && isset($this->globalSiteInfo[$key]['siteInfo'])) {
1321 $error = $this->connectToDatabase($this->globalSiteInfo[$key]['siteInfo']);
1322 if (!$error) {
1323 $DB = $this->globalSiteInfo[$key]['siteInfo']['TYPO3_db'];
1324 $content .= '<h3>Updating ' . $DB . ':</h3>';
1325
1326 $query = $GLOBALS['TYPO3_DB']->UPDATEquery(
1327 'be_users',
1328 'uid=' . intval($parts[1]) . ' AND username="' . addslashes($parts[2]) . '" AND admin!=0',
1329 array('password' => $pass)
1330 ); // username/admin are added to security. But they are certainly redundant!!
1331 mysql($DB, $query);
1332
1333 $content .= 'Affected rows: ' . mysql_affected_rows() . '<br /><hr />';
1334 $updatedFlag = '1';
1335 }
1336 }
1337 }
1338 }
1339 }
1340
1341 $this->initProcess();
1342 return $content;
1343 }
1344 }
1345
1346 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_superadmin.php'])) {
1347 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_superadmin.php']);
1348 }
1349
1350 ?>