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