449232304b04c1a65c6def05adff7a26f58dd15f
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_superadmin.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (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 *
30 *
31 * @author Kasper Skårhøj <kasper@typo3.com>
32 * @package TYPO3
33 * @subpackage t3lib
34 */
35
36
37 // *******************************
38 // Set error reporting
39 // *******************************
40 error_reporting (E_ALL ^ E_NOTICE);
41 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
42
43
44 // Dependency:
45 include_once("./typo3_src/t3lib/class.t3lib_div.php");
46
47 function debug($p1,$p2="") {
48 t3lib_div::debug($p1,$p2);
49 }
50
51 class t3lib_superadmin {
52 var $parentDirs=array();
53 var $globalSiteInfo=array();
54 var $currentUrl="";
55 var $targetWindow="superAdminWindow";
56 var $targetWindowAdmin="superAdminWindowAdmin";
57 var $targetWindowInstall="superAdminWindowInstall";
58 var $mapDBtoKey=array();
59 var $collectAdminPasswords=array();
60 var $changeAdminPasswords=array();
61 var $collectInstallPasswords=array();
62 var $scriptName="superadmin.php";
63
64 // Control:
65 var $full=0; // If set, the full information array per site is printed.
66
67 var $noCVS=0; // See tools/em/index.php....
68
69 function init($parentDirs) {
70 $this->parentDirs = $parentDirs;
71 }
72 function initProcess() {
73 $content="";
74 reset($this->parentDirs);
75 while(list($k,$v)=each($this->parentDirs)) {
76 $dir = ereg_replace("/$","",$v["dir"]);
77 $baseUrl=ereg_replace("/$","",$v["url"]);
78 $content.="<BR><BR><BR>";
79 $content.=$this->headerParentDir($dir);
80 if (@is_dir($dir)) {
81 $in_dirs = t3lib_div::get_dirs($dir);
82 asort($in_dirs);
83 reset($in_dirs);
84 $dirArr=array();
85 while(list($k,$v)=each($in_dirs)) {
86 if (substr($v,0,9)!="typo3_src") {
87 $this->currentUrl=$baseUrl."/".$v;
88 $content.=$this->headerSiteDir($v);
89 $content.=$this->processSiteDir($dir."/".$v,$dir);
90 }
91 }
92 } else {
93 $content.=$this->error("'".$dir."' was not a directory!");
94 }
95 }
96 // debug($this->globalSiteInfo);
97 return $content;
98 }
99 function make() {
100 reset($this->parentDirs);
101 $content = $this->initProcess();
102
103 // Output mode:
104 $mode=t3lib_div::GPvar("show");
105 //debug($GLOBALS["HTTP_GET_VARS"]);
106 switch($mode) {
107 case "menu":
108 $lines=array();
109 $lines[]=$this->setMenuItem("info","INFO");
110 $lines[]=$this->setMenuItem("update","UPDATE");
111 $lines[]='';
112 $lines[]='<A HREF="'.$this->scriptName.'?type=page" target="TSApage">Default</A>';
113 $lines[]='<a HREF="'.$this->scriptName.'?type=page&show=all" target="TSApage">All details</a>';
114 $lines[]='<a HREF="'.$this->scriptName.'?type=page&show=admin" target="TSApage">Admin logins</a>';
115 $lines[]='<a HREF="'.$this->scriptName.'?type=phpinfo" target="TSApage">phpinfo()</a>';
116 $lines[]='<a HREF="'.$this->scriptName.'?type=localext&show=localext" target="TSApage">Local extensions</a>';
117 $lines[]='';
118 $content = '<font>'.implode("<BR>",$lines).'</font>';
119 $content.= '<HR>';
120 $content.=$this->menuContent(t3lib_div::GPvar("exp"));
121 return '<h2><nobr><div align="center">TYPO3<BR>Super Admin</div></nobr></h2>'.$content;
122 break;
123 case "all":
124 return '<h1>All details:</h1><h2>Overview:</h2>'.$this->makeTable()."<BR><HR><BR>".
125 '<h1>Details per site:</h1>'.$content;
126 break;
127 case "admin":
128 $content = $this->setNewPasswords();
129 $this->makeTable();
130 return $content.'<h1>Admin options:</h1><h2>Admin logins:</h2>'.$this->makeAdminLogin()."<BR><HR><BR>".
131 '<h2>TBE Admin Passwords:</h2>'.t3lib_div::view_array($this->collectAdminPasswords)."<BR><HR><BR>".
132 '<h2>Install Tool Passwords:</h2>'.t3lib_div::view_array($this->collectInstallPasswords)."<BR><HR><BR>".
133 '<h2>Change TBE Admin Passwords:</h2>'.$this->changeAdminPasswordsForm()."<BR><HR><BR>";
134 break;
135 case "info":
136 return '<h1>Single site details</h1>'.$this->singleSite(t3lib_div::GPvar("exp"))."<BR>";
137 break;
138 case "rmTempCached":
139 return '<h1>Removing temp_CACHED_*.php files</h1>'.$this->rmCachedFiles(t3lib_div::GPvar("exp"))."<BR>";
140 break;
141 case "localext":
142 return '<h1>Local Extensions Found:</h1>'.$this->localExtensions()."<BR>";
143 break;
144 default:
145 return '<h1>Default info:</h1>'.$content;
146 break;
147 }
148 }
149 function setMenuItem($code,$label) {
150 $out = '<a HREF="'.$this->scriptName.'?type=menu&show=menu&exp='.$code.'" target="TSAmenu">'.$label.'</a>';
151 if ($code==t3lib_div::GPvar("exp")) {
152 $out = '<font color=red>&gt;&gt;</font>'.$out;
153 }
154 return $out;
155 }
156 function error($str) {
157 $out = '<font color=red size=4>'.$str.'</font>';
158 return $out;
159 }
160 function headerParentDir($str) {
161 $out = '<h2>'.$str.'</h2>';
162 return $out;
163 }
164 function headerSiteDir($str) {
165 $out = '<h3>'.$str.'</h3>';
166 return $out;
167 }
168 function processSiteDir($path,$dir) {
169 if (@is_dir($path)) {
170 $localconf = $path."/typo3conf/localconf.php";
171 if (@is_file($localconf)) {
172 $key = md5($localconf);
173 $this->includeLocalconf($localconf);
174
175 $this->mapDBtoKey[$this->globalSiteInfo[$key]["siteInfo"]["TYPO3_db"]]=$key;
176 $this->globalSiteInfo[$key]["siteInfo"]["MAIN_DIR"]=$dir;
177 $this->globalSiteInfo[$key]["siteInfo"]["SA_PATH"]=$path;
178 $this->globalSiteInfo[$key]["siteInfo"]["URL"]=$this->currentUrl."/";
179 $this->globalSiteInfo[$key]["siteInfo"]["ADMIN_URL"]=$this->currentUrl."/".TYPO3_mainDir;
180 $this->globalSiteInfo[$key]["siteInfo"]["INSTALL_URL"]=$this->currentUrl."/".TYPO3_mainDir."install/";
181
182 $conMsg = $this->connectToDatabase($this->globalSiteInfo[$key]["siteInfo"]);
183 if (!$conMsg) {
184 $this->getDBInfo($key);
185 if ($this->full) {
186 $out.=t3lib_div::view_array($this->globalSiteInfo[$key]);
187 } else {
188 $out.=t3lib_div::view_array($this->globalSiteInfo[$key]["siteInfo"]);
189 }
190 } else {$out=$this->error($conMsg);}
191 } else $out=$this->error($localconf." is not a file!");
192 } else $out=$this->error($path." is not a directory!");
193 return $out;
194 }
195 function includeLocalconf($localconf) {
196 include($localconf);
197
198 $siteInfo=array();
199 $siteInfo["sitename"] = $TYPO3_CONF_VARS["SYS"]["sitename"];
200 $siteInfo["TYPO3_db"] = $typo_db;
201 $siteInfo["TYPO3_db_username"] = $typo_db_username;
202 $siteInfo["TYPO3_db_password"] = $typo_db_password;
203 $siteInfo["TYPO3_db_host"] = $typo_db_host;
204 $siteInfo["installToolPassword"] = $TYPO3_CONF_VARS["BE"]["installToolPassword"];
205 $siteInfo["warningEmailAddress"] = $TYPO3_CONF_VARS["BE"]["warning_email_addr"];
206 $siteInfo["warningMode"] = $TYPO3_CONF_VARS["BE"]["warning_mode"];
207
208 $this->globalSiteInfo[md5($localconf)]=array("siteInfo"=>$siteInfo,"TYPO3_CONF_VARS"=>$TYPO3_CONF_VARS);
209 return $siteInfo;
210 }
211 function connectToDatabase($siteInfo) {
212 if (@mysql_pconnect($siteInfo["TYPO3_db_host"], $siteInfo["TYPO3_db_username"], $siteInfo["TYPO3_db_password"])) {
213 if (!$siteInfo["TYPO3_db"]) {
214 return $this->error("No database selected");
215 } elseif (!mysql_select_db($siteInfo["TYPO3_db"])) {
216 return $this->error("Cannot connect to the current database, '".$siteInfo["TYPO3_db"]."'");
217 }
218 } else {
219 return $this->error("The current username, password or host was not accepted when the connection to the database was attempted to be established!");
220 }
221 }
222 function getDBInfo($key) {
223 $DB = $this->globalSiteInfo[$key]["siteInfo"]["TYPO3_db"];
224
225 // Non-admin users
226 $query="SELECT count(*) FROM be_users WHERE admin=0 AND NOT deleted";
227 $res = mysql($DB,$query);
228 $row = mysql_fetch_row($res);
229 $this->globalSiteInfo[$key]["siteInfo"]["BE_USERS_NONADMIN"] = $row[0];
230 // Admin users
231 $query="SELECT count(*) FROM be_users WHERE admin!=0 AND NOT deleted";
232 $res = mysql($DB,$query);
233 $row = mysql_fetch_row($res);
234 $this->globalSiteInfo[$key]["siteInfo"]["BE_USERS_ADMIN"] = $row[0];
235
236 // Select Admin users
237 $query="SELECT uid,username,password,email,realName FROM be_users WHERE admin!=0 AND NOT deleted";
238 $res = mysql($DB,$query);
239 while($row = mysql_fetch_assoc($res)) {
240 // debug($row);
241 $this->globalSiteInfo[$key]["siteInfo"]["ADMINS"][] = $row;
242 }
243 }
244 function makeTable() {
245 // TITLE:
246 $info=array();
247 $info[]="Site:";
248 $info[]="Database:";
249 $info[]="Username";
250 $info[]="Password";
251 $info[]="Host";
252 $info[]="Links (new win)";
253 $info[]="#Users NA/A";
254 $info[]="Admin be_users Info";
255 $info[]="Install Tool Password";
256 $info[]="Warning email address";
257 $info[]="W.mode";
258 $mainArrRows[]="<TR bgcolor=#eeeeee><TD nowrap valign=top>".implode("</TD><TD nowrap valign=top>",$info)."</TD></TR>";
259
260 reset($this->globalSiteInfo);
261 while(list($k,$all)=each($this->globalSiteInfo)) {
262 $info=array();
263 $info[]=$all["siteInfo"]["sitename"];
264 $info[]=$all["siteInfo"]["TYPO3_db"];
265 $info[]=$all["siteInfo"]["TYPO3_db_username"];
266 $info[]=$all["siteInfo"]["TYPO3_db_password"];
267 $info[]=$all["siteInfo"]["TYPO3_db_host"];
268 // URL
269 $info[]='<A HREF="'.$all["siteInfo"]["URL"].'" target="'.$this->targetWindow.'">Site</A> / <A HREF="'.$all["siteInfo"]["ADMIN_URL"].'" target="'.$this->targetWindowAdmin.'">Admin</A> / <A HREF="'.$all["siteInfo"]["INSTALL_URL"].'" target="'.$this->targetWindowInstall.'">Install</A>';
270 $info[]=$all["siteInfo"]["BE_USERS_NONADMIN"]."/".$all["siteInfo"]["BE_USERS_ADMIN"];
271
272 // Admin
273 if (is_array($all["siteInfo"]["ADMINS"])) {
274 reset($all["siteInfo"]["ADMINS"]);
275 $lines=array();
276 while(list(,$vArr)=each($all["siteInfo"]["ADMINS"])) {
277 $lines[]=$vArr["password"]." - ".$vArr["username"]." (".$vArr["realName"].", ".$vArr["email"].")";
278 $this->collectAdminPasswords[$vArr["password"]][] = $all["siteInfo"]["sitename"]." (".$all["siteInfo"]["TYPO3_db"]."), ".$vArr["username"]." (".$vArr["realName"].", ".$vArr["email"].")";
279 $this->changeAdminPasswords[$vArr["password"]][]=$all["siteInfo"]["TYPO3_db"].":".$vArr["uid"].":".$vArr["username"];
280 }
281 $info[]=implode("<BR>",$lines);
282 } else {
283 $info[]='<font color="red">No DB connection!</font>';
284 }
285 // Install
286 $info[]=$all["siteInfo"]["installToolPassword"];
287 $this->collectInstallPasswords[$all["siteInfo"]["installToolPassword"]][] = $all["siteInfo"]["sitename"]." (".$all["siteInfo"]["TYPO3_db"].")";
288
289 $info[]=$all["siteInfo"]["warningEmailAddress"];
290 $info[]=$all["siteInfo"]["warningMode"];
291 // debug($all["siteInfo"]);
292
293
294 // compile
295 $mainArrRows[]="<TR><TD nowrap valign=top>".implode("</TD><TD nowrap valign=top>",$info)."</TD></TR>";
296 }
297 $table = '<TABLE border=1 cellpadding=1 cellspacing=1>'.implode("",$mainArrRows).'</TABLE>';
298 return $table;
299 }
300
301 /**
302 * Based on the globalSiteInfo array, this prints information about local extensions for each site.
303 * In particular version number and most recent mod-time is interesting!
304 */
305 function localExtensions() {
306 $this->extensionInfoArray=array();
307
308 reset($this->globalSiteInfo);
309 while(list($k,$all)=each($this->globalSiteInfo)) {
310 if ($all["siteInfo"]["SA_PATH"]) {
311 $extDir = $all["siteInfo"]["SA_PATH"]."/typo3conf/ext/";
312 if (@is_dir($extDir)) {
313 $this->extensionInfoArray["site"][$k]=array();
314
315 # debug($extDir,1);
316 $extensions=t3lib_div::get_dirs($extDir);
317 if (is_array($extensions)) {
318
319 # debug($extensions);
320 reset($extensions);
321 while(list(,$extKey)=each($extensions)) {
322 $eInfo = $this->getExtensionInfo($extDir,$extKey,$k);
323
324 $this->extensionInfoArray["site"][$k][$extKey]=$eInfo;
325 $this->extensionInfoArray["ext"][$extKey][$k]=$eInfo;
326 }
327 }
328 }
329 }
330 }
331
332 // Display results:
333 $out="";
334
335
336 // PER EXTENSION:
337 if (is_array($this->extensionInfoArray["ext"])) {
338 $extensionKeysCollect=array();
339
340 ksort($this->extensionInfoArray["ext"]);
341 reset($this->extensionInfoArray["ext"]);
342 $rows=array(
343 "reg"=>array(),
344 "user"=>array()
345 );
346 while(list($extKey,$instances)=each($this->extensionInfoArray["ext"])) {
347 $mtimes=array();
348
349 // Find most recent mtime of the options:
350 reset($instances);
351 while(list($k,$eInfo)=each($instances)) {
352 $mtimes[]=$eInfo["mtime"];
353 }
354 // Max mtime:
355 $maxMtime=max($mtimes);
356 $c=0;
357
358 // So, traverse all sites with the extension present:
359 reset($instances);
360 while(list($k,$eInfo)=each($instances)) {
361 // Set background color if mtime matches
362 if ($maxMtime==$eInfo["mtime"]) {
363 $this->extensionInfoArray["site"][$k][$extKey]["_highlight"]=1;
364 $bgCol = ' bgcolor="#eeeeee""';
365 } else {
366 $bgCol = ' style="color: #999999; font-style: italic;"';
367 }
368
369 // Make row:
370 $type = substr($extKey,0,5)!="user_"?"reg":"user";
371 if ($type=="reg") $extensionKeysCollect[]=$extKey;
372 $rows[$type][]='
373 <tr>
374 '.(!$c?'<td rowspan="'.count($instances).'">'.$extKey.'</td>':'').'
375 <td nowrap'.$bgCol.'>'.$this->globalSiteInfo[$k]["siteInfo"]["SA_PATH"].'</td>
376 <td nowrap'.$bgCol.'>'.$eInfo["title"].'</td>
377 <td nowrap'.$bgCol.'>'.$eInfo["version"].'</td>
378 <td nowrap'.$bgCol.'>'.$eInfo["numberfiles"].'</td>
379 <td nowrap'.$bgCol.'>'.($eInfo["manual"]?'M':'-').'</td>
380 <td nowrap'.$bgCol.'>'.($eInfo["mtime"]?date("d-m-y H:i:s",$eInfo["mtime"]):'').'</td>
381 <td nowrap'.$bgCol.'>'.$eInfo["mtime_hash"].'</td>
382 </tr>
383 ';
384 $c++;
385 }
386 }
387
388 $out.='<h3>Registered extensions:</h3><table border=1>'.implode("",$rows["reg"]).'</table>';
389
390 $extensionKeysCollect = array_unique($extensionKeysCollect);
391 asort($extensionKeysCollect);
392 $out.='<form><textarea cols="80" rows="10">'.implode(chr(10),$extensionKeysCollect).'</textarea></form>';
393
394 $out.='<BR><h3>User extensions:</h3><table border=1>'.implode("",$rows["user"]).'</table>';
395 }
396
397 // PER SITE:
398 if (is_array($this->extensionInfoArray["site"])) {
399 reset($this->extensionInfoArray["site"]);
400 $rows=array();
401 while(list($k,$extensions)=each($this->extensionInfoArray["site"])) {
402 // So, traverse all sites with the extension present:
403 $c=0;
404 reset($extensions);
405 while(list($extKey,$eInfo)=each($extensions)) {
406 // Set background color if mtime matches
407 if ($eInfo["_highlight"]) {
408 $bgCol = ' bgcolor="#eeeeee""';
409 } else {
410 $bgCol = ' style="color: #999999; font-style: italic;"';
411 }
412
413 // Make row:
414 $rows[]='
415 <tr>
416 '.(!$c?'<td rowspan="'.count($extensions).'">'.$this->globalSiteInfo[$k]["siteInfo"]["SA_PATH"].'</td>':'').'
417 <td nowrap'.$bgCol.'>'.$extKey.'</td>
418 <td nowrap'.$bgCol.'>'.$eInfo["title"].'</td>
419 <td nowrap'.$bgCol.'>'.$eInfo["version"].'</td>
420 <td nowrap'.$bgCol.'>'.$eInfo["numberfiles"].'</td>
421 <td nowrap'.$bgCol.'>'.($eInfo["mtime"]?date("d-m-y H:i:s",$eInfo["mtime"]):'').'</td>
422 <td nowrap'.$bgCol.'>'.$eInfo["mtime_hash"].'</td>
423 </tr>
424 ';
425 $c++;
426 }
427 }
428 $out.='<BR><h3>Sites:</h3><table border=1>'.implode("",$rows).'</table>';
429 }
430 return $out;
431
432
433 # debug($this->extensionInfoArray);
434 # debug($this->globalSiteInfo);
435 }
436
437 /**
438 * Gets information for an extension, eg. version and most-recently-edited-script
439 */
440 function getExtensionInfo($path,$extKey,$k) {
441 $file = $path.$extKey."/ext_emconf.php";
442 if (@is_file($file)) {
443 $_EXTKEY = $extKey;
444 include($file);
445
446 $eInfo=array();
447 // Info from emconf:
448 $eInfo["title"] = $EM_CONF[$extKey]["title"];
449 $eInfo["version"] = $EM_CONF[$extKey]["version"];
450 $filesHash = unserialize($EM_CONF[$extKey]["_md5_values_when_last_written"]);
451
452 # debug(count($filesHash),1);
453 if (is_array($filesHash) && count($filesHash)<50) {
454 // Get all files list (may take LOONG time):
455 $extPath=$path.$extKey."/";
456 $fileArr = array();
457 $fileArr = $this->removePrefixPathFromList($this->getAllFilesAndFoldersInPath($fileArr,$extPath),$extPath);
458
459 // Number of files:
460 $eInfo["numberfiles"]=count($fileArr);
461
462 // Most recent modification:
463 $eInfo["mtime_files"]=$this->findMostRecent($fileArr,$extPath);
464 if (count($eInfo["mtime_files"])) $eInfo["mtime"]=max($eInfo["mtime_files"]);
465 $eInfo["mtime_hash"] = md5(implode(",",$eInfo["mtime_files"]));
466 }
467
468 $eInfo["manual"] = @is_file($path.$extKey."/doc/manual.sxw");
469
470 return $eInfo;
471 # debug(unserialize($EM_CONF[$extKey]["_md5_values_when_last_written"]));
472 # debug($this->serverExtensionMD5Array($fileArr,$extPath));
473 # debug($fileArr);
474 } else return "ERROR: No emconf.php file: ".$file;
475 }
476
477 /**
478 * Recursively gather all files and folders of extension path.
479 */
480 function getAllFilesAndFoldersInPath($fileArr,$extPath,$extList="",$regDirs=0) {
481 if ($regDirs) $fileArr[]=$extPath;
482 $fileArr=array_merge($fileArr,t3lib_div::getFilesInDir($extPath,$extList,1,1)); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
483
484 $dirs = t3lib_div::get_dirs($extPath);
485 if (is_array($dirs)) {
486 reset($dirs);
487 while(list(,$subdirs)=each($dirs)) {
488 if ($subdirs && (strcmp($subdirs,"CVS") || !$this->noCVS)) {
489 $fileArr = $this->getAllFilesAndFoldersInPath($fileArr,$extPath.$subdirs."/",$extList,$regDirs);
490 }
491 }
492 }
493 return $fileArr;
494 }
495
496 /**
497 * Creates a MD5-hash array over the current files in the extension
498 */
499 function serverExtensionMD5Array($fileArr,$extPath) {
500 reset($fileArr);
501 $md5Array=array();
502 while(list(,$fN)=each($fileArr)) {
503 if ($fN!="ext_emconf.php") {
504 $content_md5 = md5(t3lib_div::getUrl($extPath.$fN));
505 $md5Array[$fN]=substr($content_md5,0,4);
506 }
507 }
508 return $md5Array;
509 }
510
511 /**
512 * Creates a MD5-hash array over the current files in the extension
513 */
514 function findMostRecent($fileArr,$extPath) {
515 reset($fileArr);
516 $mtimeArray=array();
517 while(list(,$fN)=each($fileArr)) {
518 if ($fN!="ext_emconf.php") {
519 $mtime = filemtime($extPath.$fN);
520 $mtimeArray[$fN]=$mtime;
521 }
522 }
523 return $mtimeArray;
524 }
525
526 /**
527 * Removes the absolute part of all files/folders in fileArr
528 */
529 function removePrefixPathFromList($fileArr,$extPath) {
530 reset($fileArr);
531 while(list($k,$absFileRef)=each($fileArr)) {
532 if(t3lib_div::isFirstPartOfStr($absFileRef,$extPath)) {
533 $fileArr[$k]=substr($absFileRef,strlen($extPath));
534 } else return "ERROR: One or more of the files was NOT prefixed with the prefix-path!";
535 }
536 return $fileArr;
537 }
538
539
540
541 function singleSite($exp) {
542 $all = $this->globalSiteInfo[$exp];
543 $content = '<h2>'.$all["siteInfo"]["sitename"].' (DB: '.$all["siteInfo"]["TYPO3_db"].')</h2>';
544 $content.= '<HR>';
545 $content.= '<h3>Main details:</h3>';
546 $content.= '<font>LINKS: <A HREF="'.$all["siteInfo"]["URL"].'" target="'.$this->targetWindow.'">Site</A> / <A HREF="'.$all["siteInfo"]["ADMIN_URL"].'" target="'.$this->targetWindowAdmin.'">Admin</A> / <A HREF="'.$all["siteInfo"]["INSTALL_URL"].'" target="'.$this->targetWindowInstall.'">Install</A></font><BR><BR>';
547 $content.= t3lib_div::view_array($all);
548
549 $content.= '<h3>Login-Log for last month:</h3>';
550 $content.= $this->loginLog($all["siteInfo"]["TYPO3_db"]);
551
552 return $content;
553 }
554 function rmCachedFiles($exp) {
555 $all = $this->globalSiteInfo[$exp];
556 $content = '<h2>'.$all["siteInfo"]["sitename"].' (DB: '.$all["siteInfo"]["TYPO3_db"].')</h2>';
557 $content.= '<HR>';
558 $content.= '<h3>typo3conf/temp_CACHED_* files:</h3>';
559
560 $path = $all["siteInfo"]["SA_PATH"]."/typo3conf/";
561 if (@is_dir($path)) {
562 $filesInDir=t3lib_div::getFilesInDir($path,"php",1);
563 reset($filesInDir);
564 while(list($kk,$vv)=each($filesInDir)) {
565 if (t3lib_div::isFirstPartOfStr(basename($vv),"temp_CACHED_")) {
566 if (strstr(basename($vv),"ext_localconf.php") || strstr(basename($vv),"ext_tables.php")) {
567 $content.="REMOVED: ".$vv."<BR>";
568 unlink($vv);
569 if (file_exists($vv)) $content.="<strong><font color=red>ERROR: File still exists, so could not be removed anyways!</font></strong><BR>";
570 }
571 }
572 }
573 } else {
574 $content.='<strong><font color=red>ERROR: '.$path.' was not a directory!</font></strong>';
575 }
576
577 return $content;
578 }
579 function menuContent($exp) {
580 if ($exp) {
581 reset($this->globalSiteInfo);
582 $lines=array();
583 $head="";
584 while(list($k,$all)=each($this->globalSiteInfo)) {
585 // Setting section header, if needed.
586 if ($head!=$all["siteInfo"]["MAIN_DIR"]) {
587 $lines[]='<h4><nobr>'.t3lib_div::fixed_lgd_pre($all["siteInfo"]["MAIN_DIR"],18).'</nobr></h4>';
588 $head=$all["siteInfo"]["MAIN_DIR"];
589 }
590
591 switch($exp) {
592 case "update":
593 // Label:
594 $label = $all["siteInfo"]["sitename"] ? $all["siteInfo"]["sitename"] : "(DB: ".$all["siteInfo"]["TYPO3_db"].")";
595 $lines[]='<HR><b>'.$label.'</b> ('.substr($all["siteInfo"]["SA_PATH"],strlen($all["siteInfo"]["MAIN_DIR"])+1).')<BR>';
596
597 // Get SQL-files:
598 /* $readPath = $all["siteInfo"]["SA_PATH"]."/typo3/t3lib/stddb/";
599 $fileArr = t3lib_div::getFilesInDir($readPath,"sql",1,"mtime");
600 $file=array();
601 if (is_array($fileArr)) {
602 reset($fileArr);
603 while(list(,$fP)=each($fileArr)) {
604 // if (substr($fP,0,strlen($readPath."static_template"))==$readPath."static_template") {
605 if (substr($fP,0,strlen($readPath."static+"))==$readPath."static+") {
606 $file["static_template.sql"]=$fP;
607 }
608 if (substr($fP,0,strlen($readPath."sys_tabledescr_X"))==$readPath."sys_tabledescr_X") {
609 $file["sys_tabledescr_X.sql"]=$fP;
610 }
611 if (substr($fP,0,strlen($readPath."tables"))==$readPath."tables") {
612 $file["tables.sql"]=$fP;
613 }
614 }
615 }
616 */
617 $tempVal='&_someUniqueValue='.time();
618
619 // $url = $all["siteInfo"]["ADMIN_URL"]."mod/tools/em/index.php";
620 // $lines[]='<nobr><a HREF="'.$url.'" target="TSApage">EM</a></nobr>';
621
622
623
624 $lines[]='<nobr><a HREF="'.$this->scriptName.'?type=page&show=rmTempCached&exp='.$k.$tempVal.'" target="TSApage">Remove temp_CACHED files</a></nobr>';
625
626 $url = $all["siteInfo"]["INSTALL_URL"]."index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=cmpFile|CURRENT_TABLES".$tempVal."#bottom";
627 $lines[]='<nobr><a HREF="'.$url.'" target="TSApage">CURRENT_TABLES</a></nobr>';
628
629 $url = $all["siteInfo"]["INSTALL_URL"]."index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=import|CURRENT_STATIC"."&presetWholeTable=1".$tempVal."#bottom";
630 $lines[]='<nobr><a HREF="'.$url.'" target="TSApage">CURRENT_STATIC</a></nobr>';
631
632 /*
633 // Link to tables:
634 if ($file["tables.sql"]) {
635 $url = $all["siteInfo"]["INSTALL_URL"]."index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=cmpFile|".rawurlencode($file["tables.sql"]).$tempVal."#bottom";
636 $lines[]='<nobr><a HREF="'.$url.'" target="TSApage">'.basename($file["tables.sql"]).'</a></nobr>';
637 }
638 // Link to static_tempalte
639 if ($file["static_template.sql"]) {
640 $url = $all["siteInfo"]["INSTALL_URL"]."index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=import|".rawurlencode($file["static_template.sql"])."&presetWholeTable=1".$tempVal."#bottom";
641 $lines[]='<nobr><a HREF="'.$url.'" target="TSApage">'.basename($file["static_template.sql"]).'</a></nobr>';
642 }
643 // Link to language file
644 if ($file["sys_tabledescr_X.sql"]) {
645 $url = $all["siteInfo"]["INSTALL_URL"]."index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=import|".rawurlencode($file["sys_tabledescr_X.sql"])."&presetWholeTable=1".$tempVal."#bottom";
646 $lines[]='<nobr><a HREF="'.$url.'" target="TSApage">'.basename($file["sys_tabledescr_X.sql"]).'</a></nobr>';
647 }
648 */
649 // Cache
650 $url = $all["siteInfo"]["INSTALL_URL"]."index.php?TYPO3_INSTALL[type]=database&TYPO3_INSTALL[database_type]=cache|".
651 "&PRESET[database_clearcache][cache_pages]=1".
652 "&PRESET[database_clearcache][cache_pagesection]=1".
653 "&PRESET[database_clearcache][cache_hash]=1".
654 $tempVal.
655 "#bottom";
656 $lines[]='<nobr><a HREF="'.$url.'" target="TSApage">Clear cache</a></nobr>';
657
658
659 $lines[]='<nobr><a HREF="'.$all["siteInfo"]["ADMIN_URL"].'index.php" target="'.$this->targetWindowAdmin.'">Admin -></a></nobr>';
660 break;
661 case "info":
662 // item
663 $label = $all["siteInfo"]["sitename"] ? $all["siteInfo"]["sitename"] : "(DB: ".$all["siteInfo"]["TYPO3_db"].")";
664 $lines[]='<nobr><a HREF="'.$this->scriptName.'?type=page&show=info&exp='.$k.'" target="TSApage">'.$label.'</a> ('.substr($all["siteInfo"]["SA_PATH"],strlen($all["siteInfo"]["MAIN_DIR"])+1).'/)</nobr>';
665 break;
666 }
667 }
668 return "<font>".implode("<BR>",$lines)."<BR></font>";
669 }
670 }
671 function makeAdminLogin() {
672 reset($this->globalSiteInfo);
673 $lines=array();
674 $head="";
675 while(list($k,$all)=each($this->globalSiteInfo)) {
676 // Setting section header, if needed.
677 if ($head!=$all["siteInfo"]["MAIN_DIR"]) {
678 $lines[]='<tr><td colspan=2><BR><h4>'.$all["siteInfo"]["MAIN_DIR"].'</h4></td></tr>';
679 $head=$all["siteInfo"]["MAIN_DIR"];
680 }
681
682
683
684 // item
685 $label = $all["siteInfo"]["sitename"] ? $all["siteInfo"]["sitename"] : "(DB: ".$all["siteInfo"]["TYPO3_db"].")";
686 $unique=md5(microtime());
687
688 $opts=array();
689
690 $defUName="";
691 if (is_array($all["siteInfo"]["ADMINS"])) {
692 reset($all["siteInfo"]["ADMINS"]);
693 while(list(,$vArr)=each($all["siteInfo"]["ADMINS"])) {
694 $chalVal = md5($vArr["username"].":".$vArr["password"].":".$unique);
695 $opts[]='<option value="'.$chalVal.'">'.$vArr["username"].'</option>';
696 if (!$defUName) {$defUName=$vArr["username"];}
697 }
698 }
699 if (count($opts)>1) {
700 $userident='
701 <select name="userident" onChange="document[\''.$k.'\'].username.value=this.options[this.selectedIndex].text;">'.implode("",$opts).'</select>
702 ';
703 } else {
704 $userident='('.$defUName.')<BR><input type="Hidden" name="userident" value="'.$chalVal.'">';
705 }
706
707 $form='
708 <form name="'.$k.'" action="'.$all["siteInfo"]["ADMIN_URL"].'index.php" target="EXTERnalWindow" method="post">
709 <input type="submit" name="submit" value="Login">
710 <input type="Hidden" name="username" value="'.$defUName.'">
711 <input type="Hidden" name="challenge" value="'.$unique.'">
712 <input type="Hidden" name="redirect_url" value="">
713 <input type="Hidden" name="login_status" value="login">
714 '.trim($userident).'
715 </form>';
716
717 $lines[]='<tr><td><strong>'.$label.'</strong></td><td nowrap>'.trim($form).'</td></tr>';
718 }
719 return "<table border=1 cellpadding=5 cellspacing=1>".implode("",$lines)."</table>";
720 }
721 function loginLog($DB) {
722 // Non-admin users
723 $query="SELECT sys_log.*, be_users.username AS username, be_users.admin AS admin FROM sys_log,be_users WHERE be_users.uid=sys_log.userid AND sys_log.type=255 AND sys_log.tstamp > ".(time()-(60*60*24*30))." ORDER BY sys_log.tstamp DESC";
724
725 //1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent
726 $res = mysql($DB,$query);
727 echo mysql_error();
728 $dayRef="";
729 $lines=array();
730 while($row = mysql_fetch_assoc($res)) {
731 $day = date("d-m-Y",$row["tstamp"]);
732 if ($dayRef!=$day) {
733 $lines[]='
734 <h4>'.$day.':</h4>';
735 $dayRef=$day;
736 }
737 $theLine = date("H:i",$row["tstamp"]).": ".str_pad(substr($row["username"],0,10),10)." ".$this->log_getDetails($row["details"],unserialize($row["log_data"]));
738 $lines[]= $row["admin"] ? '<span class=redclass>'.$theLine.'</span>' : $theLine;
739
740 // debug($row);
741 }
742 return '<pre>'.implode(chr(10),$lines).'</pre>';
743 }
744 function log_getDetails($text,$data) {
745 // $code is used later on to substitute errormessages with language-corrected values...
746 if (is_array($data)) {
747 return sprintf($text, $data[0],$data[1],$data[2],$data[3],$data[4]);
748 } else return $text;
749 }
750 function changeAdminPasswordsForm() {
751 reset($this->changeAdminPasswords);
752 $content="";
753 while(list($k,$p)=each($this->changeAdminPasswords)) {
754 $content.='<h3>'.$k.'</h3>';
755 reset($p);
756 while(list($kk,$pp)=each($p)) {
757 $content.='<nobr>';
758 $content.='<input type="checkbox" name="SETFIELDS[]" value="'.$pp.'"> '.$pp.' - ';
759 $content.=$this->collectAdminPasswords[$k][$kk];
760 $content.='</nobr><BR>';
761 }
762 }
763
764 $content.='New password: <input type="text" name="NEWPASS"><BR>';
765 $content.='New password (md5): <input type="text" name="NEWPASS_md5"><BR>
766 (This overrules any plain password above!)
767 <br>';
768 $content='
769 <form action="'.$this->scriptName.'?type=page&show=admin" method="post">
770 '.$content.'
771 <input type="submit" name="Set">
772 </form>
773 ';
774
775 return $content;
776 }
777 function setNewPasswords() {
778 $whichFields = t3lib_div::GPvar("SETFIELDS");
779
780 $pass = trim(t3lib_div::GPvar("NEWPASS"));
781 $passMD5 = t3lib_div::GPvar("NEWPASS_md5");
782 $updatedFlag=0;
783 if ($pass || $passMD5) {
784 $pass = $passMD5 ? $passMD5 : md5($pass);
785
786 reset($whichFields);
787 while(list(,$values)=each($whichFields)) {
788 $parts = explode(":",$values);
789 if (count($parts)>2) {
790 $key = $this->mapDBtoKey[$parts[0]];
791 if ($key && isset($this->globalSiteInfo[$key]["siteInfo"])) {
792 $error = $this->connectToDatabase($this->globalSiteInfo[$key]["siteInfo"]);
793 if (!$error) {
794 $DB = $this->globalSiteInfo[$key]["siteInfo"]["TYPO3_db"];
795 $content.='<h3>Updating '.$DB.':</h3>';
796 $query = "UPDATE be_users SET password='".addslashes($pass)."' WHERE uid=".intval($parts[1])." AND username='".addslashes($parts[2])."' AND admin!=0"; // username/admin are added to security. But they are certainly redundant!!
797 $content.='<i>'.htmlspecialchars($query).'</i><BR>';
798 $res = mysql($DB,$query);
799 echo mysql_error();
800 $content.='Affected rows: '.mysql_affected_rows().'<BR><HR>';
801 $updatedFlag="1";
802 }
803 }
804 }
805 }
806 }
807 $this->initProcess();
808 return $content;
809 }
810 function defaultSet() {
811 $style = '
812 <style type="text/css">
813 .redclass {color: red;}
814 P {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px}
815 FONT {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px}
816 H1 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 20px; color: #000066;}
817 H2 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; color: #000066;}
818 H3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; color: #000066;}
819 H4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: maroon;}
820 TD {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px}
821 </style>
822 ';
823
824 switch(t3lib_div::GPvar("type")) {
825 case "phpinfo":
826 phpinfo();
827 break;
828 case "page":
829 ?>
830 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
831 <?php echo $style;?>
832 <html>
833 <head>
834 <title>TYPO3 Super Admin MAIN</title>
835 </head>
836 <body>
837 <br>
838 <?php
839 echo $this->make();
840 ?>
841 </body>
842 </html>
843 <?php
844 break;
845 case "menu":
846 ?>
847 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
848 <?php echo $style;?>
849 <html>
850 <head>
851 <title>TYPO3 Super Admin MENU</title>
852 </head>
853 <body>
854 <?php
855 echo $this->make();
856 ?>
857 </body>
858 </html>
859 <?php
860 break;
861 case "localext":
862 ?>
863 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
864 <?php echo $style;?>
865 <html>
866 <head>
867 <title>TYPO3 Super Admin</title>
868 </head>
869 <body>
870 <?php
871 echo $this->make();
872 ?>
873 </body>
874 </html>
875 <?php
876 break;
877 default:
878 ?>
879 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
880 <html>
881 <head>
882 <title>TYPO3 Super Admin</title>
883 </head>
884 <frameset cols="250,*">
885 <frame name="TSAmenu" src="superadmin.php?type=menu&show=menu" marginwidth="10" marginheight="10" scrolling="auto" frameborder="0">
886 <frame name="TSApage" src="superadmin.php?type=page" marginwidth="10" marginheight="10" scrolling="auto" frameborder="0">
887 </frameset>
888 </html>
889 <?php
890 break;
891 }
892 }
893 }
894
895
896 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_superadmin.php"]) {
897 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["t3lib/class.t3lib_superadmin.php"]);
898 }
899
900 ?>