2 /***************************************************************
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
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!
32 * Revised for TYPO3 3.6 February/2004 by Kasper Skaarhoj
35 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
38 * [CLASS/FUNCTION INDEX of SCRIPT]
40 * 120: function debug($p1,$p2='')
43 * 134: class t3lib_superadmin
45 * SECTION: Initialize stuff
46 * 180: function t3lib_superadmin()
47 * 192: function init($parentDirs)
49 * SECTION: Main functions
50 * 215: function defaultSet()
51 * 271: function make()
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)
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)
66 * SECTION: Content: Installation Overview
67 * 626: function makeTable()
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)
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()
87 * (This index is automatically created/updated by the extension "extdeveval")
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.
107 $path_t3lib = './typo3_src/t3lib/';
108 include_once($path_t3lib.'class.t3lib_div.php');
109 include_once($path_t3lib.'class.t3lib_db.php');
110 $TYPO3_DB = t3lib_div
::makeInstance('t3lib_DB');
114 * Debug function. Substitute since no config_default.php file is included anywhere
116 * @param mixed Debug var
117 * @param string Header string
120 function debug($p1,$p2='') {
121 t3lib_div
::debug($p1,$p2);
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!
130 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
134 class t3lib_superadmin
{
137 var $targetWindow = 'superAdminWindow';
138 var $targetWindowAdmin = 'superAdminWindowAdmin';
139 var $targetWindowInstall = 'superAdminWindowInstall';
140 var $scriptName = 'superadmin.php';
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
148 var $parentDirs = array(); // Configured directories to search
149 var $globalSiteInfo = array(); // Array with information about found TYPO3 installations
151 var $currentUrl = '';
152 var $mapDBtoKey = array();
153 var $collectAdminPasswords = array();
154 var $changeAdminPasswords = array();
155 var $collectInstallPasswords = array();
158 var $full = 0; // If set, the full information array per site is printed.
160 var $noCVS = 0; // See tools/em/index.php....
169 /**********************************
173 **********************************/
176 * Constructor, setting GP vars
180 function t3lib_superadmin() {
181 $this->show
= t3lib_div
::_GP('show');
182 $this->type
= t3lib_div
::_GP('type');
183 $this->exp
= t3lib_div
::_GP('exp');
187 * Initialize with configuration - from the 'superadmin.php' script. See misc/superadmin.php for example.
189 * @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.
192 function init($parentDirs) {
193 $this->parentDirs
= $parentDirs;
203 /**************************
207 **************************/
210 * Main function, creating HTML content; frameset, menu, content frames.
211 * Outputs the full HTML to browser.
215 function defaultSet() {
217 // Creating content based on "type" variable:
218 switch($this->type
) {
225 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
226 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
229 <style type
="text/css">
230 .redclass
{color
: red
;}
231 P
{font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
; font
-size
: 11px
}
232 BODY
{font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
; font
-size
: 10px
}
233 H1
{font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
; font
-size
: 20px
; color
: #000066;}
234 H2
{font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
; font
-size
: 17px
; color
: #000066;}
235 H3
{font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
; font
-size
: 14px
; color
: #000066;}
236 H4
{font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
; font
-size
: 11px
; color
: maroon
;}
237 TD
{font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
; font
-size
: 10px
}
239 <title
>TYPO3 Super Admin
</title
>
251 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
254 <title
>TYPO3 Super Admin
</title
>
256 <frameset cols
="250,*">
257 <frame name
="TSAmenu" src
="superadmin.php?type=page&show=menu" marginwidth
="10" marginheight
="10" scrolling
="auto" frameborder
="0">
258 <frame name
="TSApage" src
="superadmin.php?type=page" marginwidth
="10" marginheight
="10" scrolling
="auto" frameborder
="0">
267 * Main function, creating page content.
269 * @return string HTML content.
275 // Creating information about the sites found:
276 $content = $this->initProcess();
279 switch($this->show
) {
282 $lines[]=$this->setMenuItem('info','INFO');
283 $lines[]=$this->setMenuItem('update','UPDATE');
285 $lines[]='<a href="'.htmlspecialchars($this->scriptName
.'?type=page').'" target="TSApage">Default</a>';
286 $lines[]='<a href="'.htmlspecialchars($this->scriptName
.'?type=page&show=all').'" target="TSApage">All details</a>';
287 $lines[]='<a href="'.htmlspecialchars($this->scriptName
.'?type=page&show=admin').'" target="TSApage">Admin logins</a>';
288 $lines[]='<a href="'.htmlspecialchars($this->scriptName
.'?type=phpinfo').'" target="TSApage">phpinfo()</a>';
289 $lines[]='<a href="'.htmlspecialchars($this->scriptName
.'?type=page&show=localext').'" target="TSApage">Local extensions</a>';
291 $content = implode('<br />',$lines);
293 $content.=$this->menuContent($this->exp
);
294 $retVal = '<h2 align="center">TYPO3<br />Super Admin</h2>'.$content;
298 <h1>All details:</h1>
300 '.$this->makeTable().'
302 <h1>Details per site:</h1>
306 $content = $this->setNewPasswords();
309 <h1>Admin options:</h1>
311 <h2>Admin logins:</h2>
312 '.$this->makeAdminLogin().'
315 <h2>TBE Admin Passwords:</h2>
316 '.t3lib_div
::view_array($this->collectAdminPasswords
).'
319 <h2>Install Tool Passwords:</h2>
320 '.t3lib_div
::view_array($this->collectInstallPasswords
).'
323 <h2>Change TBE Admin Passwords:</h2>
324 '.$this->changeAdminPasswordsForm().'
329 <h1>Single site details</h1>
330 '.$this->singleSite($this->exp
).
335 <h1>Removing temp_CACHED_*.php files</h1>
336 '.$this->rmCachedFiles($this->exp
).
341 <h1>Local Extensions Found:</h1>
342 '.$this->localExtensions().
347 <h1>Default info:</h1>'.
363 /********************************
367 *******************************/
370 * Creates menu item from input.
372 * @param string Value for "&exp" parameter
373 * @param string The label
374 * @return string Wrapped value
376 function setMenuItem($code,$label) {
377 $out = '<a href="'.htmlspecialchars($this->scriptName
.'?type=page&show=menu&exp='.$code).'" target="TSAmenu">'.htmlspecialchars($label).'</a>';
378 if ($code==$this->exp
) {
379 $out = '<span style="color:red;">>></span>'.$out;
385 * Wrap string in red span tag (for errors)
387 * @param string Input string
388 * @return string Output string
390 function error($str) {
391 $out = '<span style="color:red; font-size: 14px; font-weight: bold;">'.htmlspecialchars($str).'</span>';
396 * Wraps input string in <h2>
398 * @param string Input string
399 * @return string Output string, wrapped in <h2>
401 function headerParentDir($str) {
402 $out = '<h2>'.htmlspecialchars($str).'</h2>';
407 * Wraps input string in <h3>
409 * @param string Input string
410 * @return string Output string, wrapped in <h3>
412 function headerSiteDir($str) {
413 $out = '<h3>'.htmlspecialchars($str).'</h3>';
433 /********************************
435 * Collection information
437 *******************************/
440 * Traverses the parent dirs, collecting the list of TYPO3 installations into $this->globalSiteInfo
442 * @return string HTML content (The default view seen when starting the superadmin.php script)
444 function initProcess() {
447 foreach($this->parentDirs
as $k => $v) {
448 $dir = rtrim($v['dir'], '/');
449 $baseUrl=rtrim($v['url'], '/');
450 $content.='<br /><br /><br />';
451 $content.=$this->headerParentDir($dir);
453 $in_dirs = t3lib_div
::get_dirs($dir);
457 while(list($k,$v)=each($in_dirs)) {
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);
465 $content.=$this->error('"'.$dir.'" was not a directory!');
473 * Creating information array for a specific TYPO3 installation
474 * Information about site is stored in ->globalSiteInfo array
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.
482 function processSiteDir($path,$dir) {
483 if (@is_dir
($path)) {
484 $localconf = $path.'/typo3conf/localconf.php';
485 if (@is_file
($localconf)) {
486 $key = md5($localconf);
487 $this->includeLocalconf($localconf);
489 $this->mapDBtoKey
[$this->globalSiteInfo
[$key]['siteInfo']['TYPO3_db']] = $key;
490 $this->globalSiteInfo
[$key]['siteInfo']['MAIN_DIR'] = $dir;
491 $this->globalSiteInfo
[$key]['siteInfo']['SA_PATH'] = $path;
492 $this->globalSiteInfo
[$key]['siteInfo']['URL'] = $this->currentUrl
.'/';
493 $this->globalSiteInfo
[$key]['siteInfo']['ADMIN_URL'] = $this->currentUrl
.'/'.TYPO3_mainDir
;
494 $this->globalSiteInfo
[$key]['siteInfo']['INSTALL_URL'] = $this->currentUrl
.'/'.TYPO3_mainDir
.'install/';
496 // Connect to database:
497 $conMsg = $this->connectToDatabase($this->globalSiteInfo
[$key]['siteInfo']);
499 $this->getDBInfo($key);
507 $out.=t3lib_div
::view_array($this->globalSiteInfo
[$key]);
509 $out.=t3lib_div
::view_array($this->globalSiteInfo
[$key]['siteInfo']);
511 } else $out = $this->error($localconf.' is not a file!');
512 } else $out = $this->error($path.' is not a directory!');
517 * Includes "localconf" of a TYPO3 installation an loads $this->globalSiteInfo with this information.
519 * @param string Absolute path to localconf.php file to include.
520 * @return array Array with information about the site.
522 * @see processSiteDir()
524 function includeLocalconf($localconf) {
525 $TYPO3_CONF_VARS = array();
527 $typo_db_username = '';
528 $typo_db_password = '';
534 $siteInfo['sitename'] = $TYPO3_CONF_VARS['SYS']['sitename'];
535 $siteInfo['TYPO3_db'] = $typo_db;
536 $siteInfo['TYPO3_db_username'] = $typo_db_username;
537 $siteInfo['TYPO3_db_password'] = $typo_db_password;
538 $siteInfo['TYPO3_db_host'] = $typo_db_host;
539 $siteInfo['installToolPassword'] = $TYPO3_CONF_VARS['BE']['installToolPassword'];
540 $siteInfo['warningEmailAddress'] = $TYPO3_CONF_VARS['BE']['warning_email_addr'];
541 $siteInfo['warningMode'] = $TYPO3_CONF_VARS['BE']['warning_mode'];
543 $this->globalSiteInfo
[md5($localconf)] = array('siteInfo'=>$siteInfo,'TYPO3_CONF_VARS'=>$TYPO3_CONF_VARS);
548 * Connects to a MySQL database with the TYPO3 db host/username/password and database as found in the localconf.php file!
549 * 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
551 * @param array $siteInfo array, containing username/password/host/database values.
552 * @return string Array message if any
554 function connectToDatabase($siteInfo) {
555 if (@mysql_pconnect
($siteInfo['TYPO3_db_host'], $siteInfo['TYPO3_db_username'], $siteInfo['TYPO3_db_password'])) {
556 if (!$siteInfo['TYPO3_db']) {
557 return $this->error('No database selected');
558 } elseif (!mysql_select_db($siteInfo['TYPO3_db'])) {
559 return $this->error('Cannot connect to the current database, "'.$siteInfo['TYPO3_db'].'"');
562 return $this->error('The current username, password or host was not accepted when the connection to the database was attempted to be established!');
568 * Get database information, assuming standard tables like "be_users"
569 * Adding the information to ->globalSiteInfo
571 * @param string Key for site in ->globalSiteInfo
574 * @see processSiteDir()
576 function getDBInfo($key) {
577 $DB = $this->globalSiteInfo
[$key]['siteInfo']['TYPO3_db'];
580 $query = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', 'be_users', 'admin=0 AND deleted=0');
581 $res = mysql($DB, $query);
582 $row = mysql_fetch_row($res);
583 $this->globalSiteInfo
[$key]['siteInfo']['BE_USERS_NONADMIN'] = $row[0];
586 $query = $GLOBALS['TYPO3_DB']->SELECTquery('count(*)', 'be_users', 'admin!=0 AND deleted=0');
587 $res = mysql($DB, $query);
588 $row = mysql_fetch_row($res);
589 $this->globalSiteInfo
[$key]['siteInfo']['BE_USERS_ADMIN'] = $row[0];
591 // Select Admin users
592 $query = $GLOBALS['TYPO3_DB']->SELECTquery('uid,username,password,email,realName,disable', 'be_users', 'admin!=0 AND deleted=0');
593 $res = mysql($DB, $query);
594 while($row = mysql_fetch_assoc($res)) {
595 $this->globalSiteInfo
[$key]['siteInfo']['ADMINS'][] = $row;
615 /******************************
617 * Content: Installation Overview
619 ******************************/
622 * Creates big table with information about all installations in ->globalSiteInfo
624 * @return string HTML table
626 function makeTable() {
632 $info[] = 'Database:';
633 $info[] = 'Username';
634 $info[] = 'Password';
636 $info[] = 'Links (new win)';
637 $info[] = '#Users NA/A';
638 $info[] = 'Admin be_users Info';
639 $info[] = 'Install Tool Password';
640 $info[] = 'Warning email address';
643 <tr bgcolor="#eeeeee">
644 <td nowrap="nowrap" valign="top">'.implode('</td>
645 <td nowrap="nowrap" valign="top">',$info).'</td>
648 // Traverse globalSiteInfo for each site:
649 foreach($this->globalSiteInfo
as $k => $all) {
652 // Sitename and Database details:
653 $info[] = htmlspecialchars($all['siteInfo']['sitename']);
654 $info[] = '<span style="color:#666666;">'.htmlspecialchars($all['siteInfo']['MAIN_DIR']).'</span>'.htmlspecialchars(substr($all['siteInfo']['SA_PATH'],strlen($all['siteInfo']['MAIN_DIR'])));
655 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db']);
656 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db_username']);
657 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db_password']);
658 $info[] = htmlspecialchars($all['siteInfo']['TYPO3_db_host']);
661 $info[] = '<a href="'.htmlspecialchars($all['siteInfo']['URL']).'" target="'.$this->targetWindow
.'">Site</a>'.
662 ' / <a href="'.htmlspecialchars($all['siteInfo']['ADMIN_URL']).'" target="'.$this->targetWindowAdmin
.'">Admin</a>'.
663 ' / <a href="'.htmlspecialchars($all['siteInfo']['INSTALL_URL']).'" target="'.$this->targetWindowInstall
.'">Install</a>';
664 $info[] = htmlspecialchars($all['siteInfo']['BE_USERS_NONADMIN'].'/'.$all['siteInfo']['BE_USERS_ADMIN']);
667 if (is_array($all['siteInfo']['ADMINS'])) {
669 foreach($all['siteInfo']['ADMINS'] as $vArr) {
670 $lines[] = htmlspecialchars($vArr['password'].' - '.$vArr['username'].' ('.$vArr['realName'].', '.$vArr['email'].')');
671 $this->collectAdminPasswords
[$vArr['password']][] = array(
672 'path' => $all['siteInfo']['SA_PATH'],
673 'site' => $all['siteInfo']['sitename'],
674 'database' => $all['siteInfo']['TYPO3_db'],
675 'user' => $vArr['username'],
676 'name_email' => $vArr['realName'].', '.$vArr['email']
678 $this->changeAdminPasswords
[$vArr['password']][] = $all['siteInfo']['TYPO3_db'].':'.$vArr['uid'].':'.$vArr['username'];
680 $info[] = implode('<br />',$lines);
682 $info[] = $this->error('No DB connection!');
685 $info[] = htmlspecialchars($all['siteInfo']['installToolPassword']);
686 $this->collectInstallPasswords
[$all['siteInfo']['installToolPassword']][] = $all['siteInfo']['SA_PATH'].' - '.$all['siteInfo']['sitename'].' - ('.$all['siteInfo']['TYPO3_db'].')';
688 $info[] = htmlspecialchars($all['siteInfo']['warningEmailAddress']);
689 $info[] = htmlspecialchars($all['siteInfo']['warningMode']);
694 <td nowrap="nowrap" valign="top">'.implode('</td>
695 <td nowrap="nowrap" valign="top">',$info).'</td>
699 // Compile / return table finally:
700 $table = '<table border="1" cellpadding="1" cellspacing="1">'.implode('',$mainArrRows).'</table>';
717 /******************************
719 * Content: Local extensions
721 ******************************/
724 * Based on the globalSiteInfo array, this prints information about local extensions for each site.
725 * In particular version number and most recent mod-time is interesting!
727 * @return string HTML
729 function localExtensions() {
730 $this->extensionInfoArray
=array();
732 // Traverse $this->globalSiteInfo for local extensions:
733 foreach($this->globalSiteInfo
as $k => $all) {
734 if ($all['siteInfo']['SA_PATH']) {
735 $extDir = $all['siteInfo']['SA_PATH'].'/typo3conf/ext/';
736 if (@is_dir
($extDir)) {
737 $this->extensionInfoArray
['site'][$k] = array();
739 // Get extensions in local directory
740 $extensions=t3lib_div
::get_dirs($extDir);
741 if (is_array($extensions)) {
742 foreach($extensions as $extKey) {
743 // Getting and setting information for extension:
744 $eInfo = $this->getExtensionInfo($extDir,$extKey,$k);
745 $this->extensionInfoArray
['site'][$k][$extKey] = $eInfo;
746 $this->extensionInfoArray
['ext'][$extKey][$k] = $eInfo;
756 <tr bgcolor="#ccccee" style="font-weight:bold;">
757 <td>Extension key</td>
762 <td><span title="If M, then there is a manual.">M</span></td>
763 <td>Last mod. time</td>
764 <td>Hash off all file mod. times:</td>
765 <td>TYPO3 ver. req.</td>
766 <td>CGL compliance</td>
771 if (is_array($this->extensionInfoArray
['ext'])) {
772 $extensionKeysCollect=array();
774 ksort($this->extensionInfoArray
['ext']);
775 reset($this->extensionInfoArray
['ext']);
781 foreach($this->extensionInfoArray
['ext'] as $extKey => $instances) {
784 // Find most recent mtime of the options:
786 while(list($k,$eInfo)=each($instances)) {
787 $mtimes[] = $eInfo['mtime'];
790 $maxMtime = max($mtimes);
793 // So, traverse all sites with the extension present:
794 foreach($instances as $k => $eInfo) {
795 // Set background color if mtime matches
796 if ($maxMtime==$eInfo['mtime']) {
797 $this->extensionInfoArray
['site'][$k][$extKey]['_highlight']=1;
798 $bgCol = $eInfo['dirtype']=='link' ?
' bgcolor="#ffcccc"' : ' bgcolor="#eeeeee"';
800 $bgCol = ' style="color: #999999; font-style: italic;"';
804 $type = substr($extKey,0,5)!='user_' ?
'reg' : 'user';
805 if ($type=='reg') $extensionKeysCollect[] = $extKey;
807 if (!is_array($eInfo)) {
811 '.(!$c?
'<td rowspan="'.count($instances).'">'.htmlspecialchars($extKey).'</td>':'').'
812 <td nowrap="nowrap" bgcolor="#ccddcc">'.htmlspecialchars($this->globalSiteInfo
[$k]['siteInfo']['SA_PATH']).'</td>
813 <td nowrap="nowrap" bgcolor="#ccddcc" colspan="8"><em>'.htmlspecialchars($eInfo).'</em></td>
820 '.(!$c?
'<td rowspan="'.count($instances).'">'.htmlspecialchars($extKey).'</td>':'').'
821 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($this->globalSiteInfo
[$k]['siteInfo']['SA_PATH']).'</td>
822 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['title']).'</td>
823 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['version']).'</td>
824 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['numberfiles']).'</td>
825 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['manual']?
'M':'-').'</td>
826 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['mtime']?
date('d-m-y H:i:s',$eInfo['mtime']):'').'</td>
827 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['mtime_hash']).'</td>
829 <td'.$bgCol.'>'.htmlspecialchars($eInfo['TYPO3_version']).'</td>
830 <td'.$bgCol.'><img src="clear.gif" width="150" height="1" alt="" /><br />'.htmlspecialchars($eInfo['CGLcompliance'].($eInfo['CGLcompliance_note'] ?
' - '.$eInfo['CGLcompliance_note'] : '')).'</td>
838 // Extensions with registered extension keys:
840 <h3>Registered extensions:</h3>
841 <table border="1">'.$headerRow.implode('',$rows['reg']).'</table>';
843 // List of those extension keys in a form field:
844 $extensionKeysCollect = array_unique($extensionKeysCollect);
845 asort($extensionKeysCollect);
846 $out.='<form action=""><textarea cols="80" rows="10">'.implode(chr(10),$extensionKeysCollect).'</textarea></form>';
848 // USER extension (prefixed "user_")
850 <h3>User extensions:</h3>
851 <table border="1">'.$headerRow.implode('',$rows['user']).'</table>';
855 if (is_array($this->extensionInfoArray
['site'])) {
857 foreach($this->extensionInfoArray
['site'] as $k => $extensions) {
859 // So, traverse all sites with the extension present:
861 foreach($extensions as $extKey => $eInfo) {
863 // Set background color if mtime matches
864 if ($eInfo['_highlight']) {
865 $bgCol = $eInfo['dirtype']=='link' ?
' bgcolor="#ffcccc"' : ' bgcolor="#eeeeee"';
867 $bgCol = ' style="color: #999999; font-style: italic;"';
873 '.(!$c?
'<td rowspan="'.count($extensions).'">'.htmlspecialchars($this->globalSiteInfo
[$k]['siteInfo']['SA_PATH']).'</td>':'').'
874 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($extKey).'</td>
875 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['title']).'</td>
876 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['version']).'</td>
877 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['numberfiles']).'</td>
878 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['mtime']?
date('d-m-y H:i:s',$eInfo['mtime']):'').'</td>
879 <td nowrap="nowrap"'.$bgCol.'>'.htmlspecialchars($eInfo['mtime_hash']).'</td>
887 <table border="1">'.implode('',$rows).'</table>';
895 * Gets information for an extension, eg. version and most-recently-edited-script
897 * @param string Path to local extension folder
898 * @param string Extension key
899 * @param string Key to globalSiteInformation array
900 * @return array Information array (unless an error occured)
902 function getExtensionInfo($path,$extKey,$k) {
903 $file = $path.$extKey.'/ext_emconf.php';
904 if (@is_file
($file)) {
911 $eInfo['title'] = $EM_CONF[$extKey]['title'];
912 $eInfo['version'] = $EM_CONF[$extKey]['version'];
913 $eInfo['CGLcompliance'] = $EM_CONF[$extKey]['CGLcompliance'];
914 $eInfo['CGLcompliance_note'] = $EM_CONF[$extKey]['CGLcompliance_note'];
915 $eInfo['TYPO3_version'] = $EM_CONF[$extKey]['TYPO3_version'];
916 $filesHash = unserialize($EM_CONF[$extKey]['_md5_values_when_last_written']);
918 if (!is_array($filesHash) ||
count($filesHash)<500) {
920 // Get all files list (may take LOONG time):
921 $extPath = $path.$extKey.'/';
923 $fileArr = $this->removePrefixPathFromList($this->getAllFilesAndFoldersInPath($fileArr,$extPath),$extPath);
925 if (!is_array($fileArr)) {
926 debug(array($fileArr,$extKey,$extPath,$this->getAllFilesAndFoldersInPath(array(),$extPath)),'ERROR');
930 $eInfo['numberfiles'] = count($fileArr);
931 $eInfo['dirtype'] = filetype($path.$extKey);
933 // Most recent modification:
934 $eInfo['mtime_files'] = $this->findMostRecent($fileArr,$extPath);
935 if (count($eInfo['mtime_files'])) $eInfo['mtime'] = max($eInfo['mtime_files']);
936 $eInfo['mtime_hash'] = md5(implode(',',$eInfo['mtime_files']));
938 $eInfo['mtime_hash'] = 'No calculation done, too many files in extension: '.count($filesHash);
941 $eInfo['manual'] = @is_file
($path.$extKey.'/doc/manual.sxw');
944 } else return 'ERROR: No emconf.php file: '.$file;
948 * Recursively gather all files and folders of extension path.
950 * @param array Array of files to which new files are added
951 * @param string Path to look up files in
952 * @param string List of file extensions to include. Blank = all
953 * @param boolean If set, directories are included as well.
954 * @return array $fileArr with new entries added.
956 function getAllFilesAndFoldersInPath($fileArr,$extPath,$extList='',$regDirs=0) {
957 if ($regDirs) $fileArr[] = $extPath;
958 $fileArr = array_merge($fileArr,t3lib_div
::getFilesInDir($extPath,$extList,1,1));
960 $dirs = t3lib_div
::get_dirs($extPath);
961 if (is_array($dirs)) {
962 foreach($dirs as $subdirs) {
963 if ($subdirs && (strcmp($subdirs,'CVS') ||
!$this->noCVS
)) {
964 $fileArr = $this->getAllFilesAndFoldersInPath($fileArr,$extPath.$subdirs.'/',$extList,$regDirs);
972 * Creates an array with modification times of all files in $fileArr
974 * @param array Files in extension (rel path)
975 * @param string Abs path prefix for files.
976 * @return array Array with modification times of files (filenames are keys)
978 function findMostRecent($fileArr,$extPath) {
979 $mtimeArray = array();
980 foreach($fileArr as $fN) {
981 if ($fN!='ext_emconf.php') {
982 $mtime = filemtime($extPath.$fN);
983 $mtimeArray[$fN] = $mtime;
990 * Removes the absolute part of all files/folders in fileArr
992 * @param array File array
993 * @param string Prefix to remove
994 * @return array Modified file array (or error string)
996 function removePrefixPathFromList($fileArr,$extPath) {
998 while(list($k,$absFileRef)=each($fileArr)) {
999 if(t3lib_div
::isFirstPartOfStr($absFileRef,$extPath)) {
1000 $fileArr[$k]=substr($absFileRef,strlen($extPath));
1001 } else return 'ERROR: One or more of the files was NOT prefixed with the prefix-path!';
1021 /******************************
1025 ******************************/
1028 * Shows detailed information for a single installation of TYPO3
1030 * @param string KEY pointing to installation
1031 * @return string HTML content
1033 function singleSite($exp) {
1034 $all = $this->globalSiteInfo
[$exp];
1036 // General information:
1038 <h2>'.htmlspecialchars($all['siteInfo']['sitename'].' (DB: '.$all['siteInfo']['TYPO3_db']).')</h2>
1041 <h3>Main details:</h3>
1043 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>
1046 // Add all information in globalSiteInfo array:
1047 $content.= t3lib_div
::view_array($all);
1051 <h3>Login-Log for last month:</h3>';
1052 $content.= $this->loginLog($all['siteInfo']['TYPO3_db']);
1059 * Get last-login log for database.
1061 * @param string Database
1062 * @return string HTML
1064 function loginLog($DB) {
1066 //1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent
1067 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
1068 'sys_log.*, be_users.username AS username, be_users.admin AS admin',
1070 'be_users.uid=sys_log.userid AND sys_log.type=255 AND sys_log.tstamp > ' . ($GLOBALS['EXEC_TIME'] - (60 * 60 * 24 * 30)),
1072 'sys_log.tstamp DESC'
1074 $res = mysql($DB,$query);
1079 while($row = mysql_fetch_assoc($res)) {
1080 $day = date('d-m-Y',$row['tstamp']);
1081 if ($dayRef!=$day) {
1083 <h4>'.$day.':</h4>';
1086 $theLine = date('H:i',$row['tstamp']).': '.str_pad(substr($row['username'],0,10),10).' '.$this->log_getDetails($row['details'],unserialize($row['log_data']));
1087 $theLine = htmlspecialchars($theLine);
1088 $lines[]= $row['admin'] ?
'<span class="redclass">'.$theLine.'</span>' : $theLine;
1092 return '<pre>'.implode(chr(10),$lines).'</pre>';
1096 * Compile log details into template string
1098 * @param string Log message (template)
1099 * @param array Data array to insert in log message
1100 * @return string Log details.
1102 function log_getDetails($text,$data) {
1103 // $code is used later on to substitute errormessages with language-corrected values...
1104 if (is_array($data)) {
1105 return sprintf($text, $data[0],$data[1],$data[2],$data[3],$data[4]);
1106 } else return $text;
1111 * Removing temp_CACHED files for installation
1113 * @param string KEY pointing to installation
1114 * @return string HTML content
1116 function rmCachedFiles($exp) {
1117 $all = $this->globalSiteInfo
[$exp];
1119 <h2>'.htmlspecialchars($all['siteInfo']['sitename'].' (DB: '.$all['siteInfo']['TYPO3_db']).')</h2>
1121 <h3>typo3conf/temp_CACHED_* files:</h3>';
1123 $path = $all['siteInfo']['SA_PATH'].'/typo3conf/';
1124 if (@is_dir
($path)) {
1125 $filesInDir = t3lib_div
::getFilesInDir($path,'php',1);
1127 foreach($filesInDir as $kk => $vv) {
1128 if (t3lib_div
::isFirstPartOfStr(basename($vv),'temp_CACHED_')) {
1129 if (strstr(basename($vv),'ext_localconf.php') ||
strstr(basename($vv),'ext_tables.php')) {
1130 $content.='REMOVED: '.$vv.'<br />';
1132 if (file_exists($vv)) $content.= $this->error('ERROR: File still exists, so could not be removed anyways!').'<br />';
1137 $content.= $this->error('ERROR: '.$path.' was not a directory!');
1144 * Menu for either update/information, showing links for each installation found
1146 * @param string Action key "update" or "info"
1147 * @return string HTML output.
1149 function menuContent($exp) {
1156 foreach($this->globalSiteInfo
as $k => $all) {
1158 // Setting section header, if needed.
1159 if ($head!=$all['siteInfo']['MAIN_DIR']) {
1161 <h4 style="white-space: nowrap;">'.htmlspecialchars(t3lib_div
::fixed_lgd_cs($all['siteInfo']['MAIN_DIR'],-18)).'</h4>';
1162 $head = $all['siteInfo']['MAIN_DIR']; // Set new head...
1170 $label = $all['siteInfo']['sitename'] ?
$all['siteInfo']['sitename'] : '(DB: '.$all['siteInfo']['TYPO3_db'].')';
1173 <b>'.htmlspecialchars($label).'</b> ('.htmlspecialchars(substr($all['siteInfo']['SA_PATH'],strlen($all['siteInfo']['MAIN_DIR'])+
1)).')<br />';
1175 // To avoid "visited links" display on next hit:
1176 $tempVal='&_someUniqueValue=' . $GLOBALS['EXEC_TIME'];
1178 // Add links for update:
1179 $url = $this->scriptName
.'?type=page&show=rmTempCached&exp='.$k.$tempVal;
1180 $lines[] = '<span style="white-space: nowrap;"><a href="'.htmlspecialchars($url).'" target="TSApage">Remove temp_CACHED files</a></span>';
1182 $url = $all['siteInfo']['INSTALL_URL'].'index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=import|CURRENT_STATIC'."&presetWholeTable=1".$tempVal.'#bottom';
1183 $lines[] = '<span style="white-space: nowrap;"><a href="'.htmlspecialchars($url).'" target="TSApage">CURRENT_STATIC</a></span>';
1185 $url = $all['siteInfo']['INSTALL_URL'].'index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=cmpFile|CURRENT_TABLES'.$tempVal.'#bottom';
1186 $lines[] = '<span style="white-space: nowrap;"><a href="'.htmlspecialchars($url).'" target="TSApage">CURRENT_TABLES</a></span>';
1189 $url = $all['siteInfo']['INSTALL_URL'].'index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=cache|'.
1190 "&PRESET[database_clearcache][cache_pages]=1".
1191 '&PRESET[database_clearcache][cache_pagesection]=1'.
1192 "&PRESET[database_clearcache][cache_hash]=1".
1195 $lines[] = '<span style="white-space: nowrap;"><a href="'.htmlspecialchars($url).'" target="TSApage">Clear cache</a></span>';
1198 $url = $all['siteInfo']['ADMIN_URL'].'index.php';
1199 $lines[] = '<span style="white-space: nowrap;"><a href="'.htmlspecialchars($url).'" target="'.$this->targetWindowAdmin
.'">Admin -></a></span>';
1203 $label = $all['siteInfo']['sitename'] ?
$all['siteInfo']['sitename'] : '(DB: '.$all['siteInfo']['TYPO3_db'].')';
1205 $url = $this->scriptName
.'?type=page&show=info&exp='.$k;
1206 $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>';
1212 return implode('<br />',$lines).'<br />';
1217 * Create list of admin logins.
1219 * @return string HTML table
1221 function makeAdminLogin() {
1227 // Traverse installations found:
1228 foreach($this->globalSiteInfo
as $k => $all) {
1230 // Setting section header, if needed.
1231 if ($head!=$all['siteInfo']['MAIN_DIR']) {
1234 <td colspan="2"><br />
1235 <h4>'.htmlspecialchars($all['siteInfo']['MAIN_DIR']).'</h4>
1238 $head = $all['siteInfo']['MAIN_DIR'];
1242 $label = $all['siteInfo']['sitename'] ?
$all['siteInfo']['sitename'] : '(DB: '.$all['siteInfo']['TYPO3_db'].')';
1243 $unique = md5(microtime());
1248 if (is_array($all['siteInfo']['ADMINS'])) {
1250 foreach($all['siteInfo']['ADMINS'] as $vArr) {
1251 $chalVal = md5($vArr['username'].':'.$vArr['password'].':'.$unique);
1252 $opts[] = '<option value="'.$chalVal.'">'.htmlspecialchars($vArr['username'].($vArr['disable']?
' [DISABLED]':'')).'</option>';
1253 if (!$defUName) { $defUName = $vArr['username']; }
1256 if (count($opts)>1) {
1258 <select name="userident" onchange="document[\''.$k.'\'].username.value=this.options[this.selectedIndex].text;">
1265 ('.$defUName.')<br />
1266 <input type="hidden" name="userident" value="'.$chalVal.'" />';
1270 <form name="'.$k.'" action="'.$all['siteInfo']['ADMIN_URL'].'index.php" target="EXTERnalWindow" method="post">
1271 <input type="submit" name="submit" value="Login" />
1272 <input type="hidden" name="username" value="'.$defUName.'" />
1273 <input type="hidden" name="challenge" value="'.$unique.'" />
1274 <input type="hidden" name="redirect_url" value="" />
1275 <input type="hidden" name="login_status" value="login" />
1276 '.trim($userident).'
1281 <td><strong>'.htmlspecialchars($label).'</strong></td>
1282 <td nowrap="nowrap">'.trim($form).'</td>
1286 // Return login table:
1287 return '<table border="1" cellpadding="5" cellspacing="1">'.implode('',$lines).'</table>';
1291 * For for changing admin passwords
1293 * @return string Form content.
1295 function changeAdminPasswordsForm() {
1298 foreach($this->changeAdminPasswords
as $k => $p) {
1302 foreach($p as $kk => $pp) {
1303 $content.= '<span style="white-space: nowrap;">';
1304 $content.= '<input type="checkbox" name="SETFIELDS[]" value="'.$pp.'" /> '.$pp.' - ';
1305 $content.= htmlspecialchars(implode(' - ',$this->collectAdminPasswords
[$k][$kk]));
1306 $content.= '</span><br />';
1310 $content.='New password: <input type="text" name="NEWPASS" /><br />';
1311 $content.='New password (md5): <input type="text" name="NEWPASS_md5" /><br />
1312 (This overrules any plain password above!)
1315 <form action="'.htmlspecialchars($this->scriptName
.'?type=page&show=admin').'" method="post">
1317 <input type="submit" name="Set" />
1325 * Setting new passwords
1327 * @return string Status
1328 * @see changeAdminPasswordsForm()
1330 function setNewPasswords() {
1331 $whichFields = t3lib_div
::_POST('SETFIELDS');
1332 $pass = trim(t3lib_div
::_POST('NEWPASS'));
1333 $passMD5 = t3lib_div
::_POST('NEWPASS_md5');
1336 if (($pass ||
$passMD5) && is_array($whichFields)) {
1337 $pass = $passMD5 ?
$passMD5 : md5($pass);
1339 foreach($whichFields as $values) {
1340 $parts = explode(':',$values);
1341 if (count($parts)>2) {
1342 $key = $this->mapDBtoKey
[$parts[0]];
1343 if ($key && isset($this->globalSiteInfo
[$key]['siteInfo'])) {
1344 $error = $this->connectToDatabase($this->globalSiteInfo
[$key]['siteInfo']);
1346 $DB = $this->globalSiteInfo
[$key]['siteInfo']['TYPO3_db'];
1347 $content.='<h3>Updating '.$DB.':</h3>';
1349 $query = $GLOBALS['TYPO3_DB']->UPDATEquery(
1351 'uid='.intval($parts[1]).' AND username="'.addslashes($parts[2]).'" AND admin!=0',
1352 array('password' => $pass)
1353 ); // username/admin are added to security. But they are certainly redundant!!
1356 $content.= 'Affected rows: '.mysql_affected_rows().'<br /><hr />';
1364 $this->initProcess();
1369 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_superadmin.php']) {
1370 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_superadmin.php']);