PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/public_html/lists/admin/index.php

https://github.com/samtuke/phplist
PHP | 608 lines | 500 code | 58 blank | 50 comment | 230 complexity | 4a9b3559b484a7b21a14254efb868799 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. @ob_start();
  3. $er = error_reporting(0);
  4. # check for commandline and cli version
  5. if (!isset($_SERVER["SERVER_NAME"]) && !PHP_SAPI == "cli") {
  6. print "Warning: commandline only works well with the cli version of PHP";
  7. }
  8. if (isset($_REQUEST['_SERVER'])) { exit; }
  9. $cline = array();
  10. $GLOBALS['commandline'] = 0;
  11. require_once dirname(__FILE__) .'/commonlib/lib/unregister_globals.php';
  12. require_once dirname(__FILE__) .'/commonlib/lib/magic_quotes.php';
  13. # setup commandline
  14. if (php_sapi_name() == "cli") {
  15. for ($i=0; $i<$_SERVER['argc']; $i++) {
  16. $my_args = array();
  17. if (preg_match("/(.*)=(.*)/",$_SERVER['argv'][$i], $my_args)) {
  18. $_GET[$my_args[1]] = $my_args[2];
  19. $_REQUEST[$my_args[1]] = $my_args[2];
  20. }
  21. }
  22. $GLOBALS["commandline"] = 1;
  23. $cline = parseCLine();
  24. $dir = dirname($_SERVER["SCRIPT_FILENAME"]);
  25. chdir($dir);
  26. if (!is_file($cline['c'])) {
  27. print "Cannot find config file\n";
  28. exit;
  29. }
  30. } else {
  31. $GLOBALS["commandline"] = 0;
  32. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  33. header("Pragma: no-cache"); // HTTP/1.0
  34. }
  35. $configfile = '';
  36. if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
  37. $configfile = $_SERVER["ConfigFile"];
  38. } elseif (isset($cline["c"]) && is_file($cline["c"])) {
  39. $configfile = $cline["c"];
  40. } elseif (is_file(dirname(__FILE__).'/../config/config.php')) {
  41. $configfile = "../config/config.php";
  42. } else {
  43. $configfile = "../config/config.php";
  44. }
  45. if (is_file($configfile) && filesize($configfile) > 20) {
  46. include $configfile;
  47. } elseif ($GLOBALS["commandline"]) {
  48. print 'Cannot find config file'."\n";
  49. } else {
  50. $GLOBALS['installer'] = 1;
  51. include(dirname(__FILE__).'/install.php');
  52. exit;
  53. }
  54. $ajax = isset($_GET['ajaxed']);
  55. if (!isset($database_host) || !isset($database_user) || !isset($database_password) || !isset($database_name)) {
  56. # print $GLOBALS['I18N']->get('Database details incomplete, please check your config file');
  57. print 'Database details incomplete, please check your config file';
  58. exit;
  59. }
  60. #exit;
  61. # record the start time(usec) of script
  62. $now = gettimeofday();
  63. $GLOBALS["pagestats"] = array();
  64. $GLOBALS["pagestats"]["time_start"] = $now["sec"] * 1000000 + $now["usec"];
  65. $GLOBALS["pagestats"]["number_of_queries"] = 0;
  66. # load all required files
  67. require_once dirname(__FILE__).'/init.php';
  68. require_once dirname(__FILE__).'/'.$GLOBALS["database_module"];
  69. include_once dirname(__FILE__)."/../texts/english.inc";
  70. include_once dirname(__FILE__)."/../texts/".$GLOBALS["language_module"];
  71. include_once dirname(__FILE__)."/languages.php";
  72. require_once dirname(__FILE__)."/defaultconfig.php";
  73. require_once dirname(__FILE__).'/connect.php';
  74. include_once dirname(__FILE__)."/lib.php";
  75. if (INTERFACELIB == 2 && is_file(dirname(__FILE__).'/interfacelib.php')) {
  76. require_once dirname(__FILE__)."/interfacelib.php";
  77. } else {
  78. require_once dirname(__FILE__)."/commonlib/lib/interfacelib.php";
  79. }
  80. if (!empty($_SESSION['hasconf']) || Sql_Table_exists($tables["config"],1)) {
  81. $_SESSION['hasconf'] = true;
  82. ### Activate all plugins
  83. /* already done in pluginlib */
  84. //foreach ($GLOBALS['plugins'] as $plugin) {
  85. //$plugin->activate();
  86. //}
  87. }
  88. if (!empty($_GET['page']) && $_GET['page'] == 'logout') {
  89. foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
  90. $plugin->logout();
  91. }
  92. $_SESSION["adminloggedin"] = "";
  93. $_SESSION["logindetails"] = "";
  94. session_destroy();
  95. Redirect('home');
  96. }
  97. ## send a header for IE
  98. header('X-UA-Compatible: IE=Edge');
  99. ## tell SE's to leave us alone
  100. header('X-Robots-Tag: noindex');
  101. if (!$ajax && !$GLOBALS["commandline"]) {
  102. if (USE_MINIFIED_ASSETS && file_exists(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/pagetop_minified.php')) {
  103. include_once dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/pagetop_minified.php';
  104. } else {
  105. include_once dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/pagetop.php';
  106. }
  107. }
  108. if (isset($GLOBALS['pageheader'])) {
  109. foreach ($GLOBALS['pageheader'] as $sHeaderItem => $sHtml ) {
  110. print '<!--'.$sHeaderItem.'-->'.$sHtml;
  111. print "\n";
  112. }
  113. }
  114. if ($GLOBALS["commandline"]) {
  115. if (!isset($_SERVER["USER"]) && sizeof($GLOBALS["commandline_users"])) {
  116. clineError("USER environment variable is not defined, cannot do access check. Please make sure USER is defined.");
  117. exit;
  118. }
  119. if (is_array($GLOBALS["commandline_users"]) && sizeof($GLOBALS["commandline_users"]) && !in_array($_SERVER["USER"],$GLOBALS["commandline_users"])) {
  120. clineError("Sorry, You (".$_SERVER["USER"].") do not have sufficient permissions to run phplist on commandline");
  121. exit;
  122. }
  123. $GLOBALS["require_login"] = 0;
  124. # getopt is actually useless
  125. #$opt = getopt("p:");
  126. $IsCommandlinePlugin = isset($cline['m']) && in_array($cline['m'],$GLOBALS["commandlinePlugins"]);
  127. if ($cline['p'] && !$IsCommandlinePlugin) {
  128. if (empty($GLOBALS['developer_email']) && isset($cline['p']) && !in_array($cline['p'],$GLOBALS["commandline_pages"])) {
  129. clineError($cline['p']." does not process commandline");
  130. } elseif (isset($cline['p'])) {
  131. $_GET['page'] = $cline['p'];
  132. }
  133. } elseif ($cline['p'] && $IsCommandlinePlugin) {
  134. if (empty($GLOBALS['developer_email']) && isset($cline['p']) && !in_array($cline['p'],$commandlinePluginPages[$cline['m']])) {
  135. clineError($cline['p']." does not process commandline");
  136. } elseif (isset($cline['p'])) {
  137. $_GET['page'] = $cline['p'];
  138. $_GET['pi'] = $cline['m'];
  139. }
  140. } else {
  141. clineUsage(" [other parameters]");
  142. exit;
  143. }
  144. } else {
  145. if (CHECK_REFERRER && isset($_SERVER['HTTP_REFERER'])) {
  146. ## do a crude check on referrer. Won't solve everything, as it can be faked, but shouldn't hurt
  147. $ref = parse_url($_SERVER['HTTP_REFERER']);
  148. if ($ref['host'] != $_SERVER['HTTP_HOST'] && !in_array($ref['host'],$allowed_referrers)) {
  149. print 'Access denied';exit;
  150. }
  151. }
  152. }
  153. if (!isset($_GET['page'])) {
  154. $page = $GLOBALS['homepage'];
  155. } else {
  156. $page = $_GET['page'];
  157. }
  158. if (preg_match("/([\w_]+)/",$page,$regs)) {
  159. $page = $regs[1];
  160. } else {
  161. $page = '';
  162. }
  163. if (!is_file($page.'.php') && !isset($_GET['pi'])) {
  164. $page = $GLOBALS['homepage'];
  165. }
  166. if (!$GLOBALS["admin_auth_module"]) {
  167. # stop login system when no admins exist
  168. if (!Sql_Table_Exists($tables["admin"])) {
  169. $GLOBALS["require_login"] = 0;
  170. } else {
  171. $num = Sql_Query("select * from {$tables["admin"]}");
  172. if (!Sql_Affected_Rows())
  173. $GLOBALS["require_login"] = 0;
  174. }
  175. } elseif (!Sql_Table_exists($GLOBALS['tables']['config'])) {
  176. $GLOBALS['require_login'] = 0;
  177. }
  178. if (!empty($_GET['pi']) && isset($GLOBALS['plugins'][$_GET['pi']])) {
  179. $page_title = $GLOBALS['plugins'][$_GET['pi']]->pageTitle($page);
  180. } else {
  181. $page_title = $GLOBALS['I18N']->pageTitle($page);
  182. }
  183. print "<title>".NAME." :: ";
  184. if (isset($GLOBALS["installation_name"])) {
  185. print $GLOBALS["installation_name"] .' :: ';
  186. }
  187. print "$page_title</title>";
  188. if (isset($GLOBALS["require_login"]) && $GLOBALS["require_login"]) {
  189. if ($GLOBALS["admin_auth_module"] && is_file("auth/".$GLOBALS["admin_auth_module"])) {
  190. require_once "auth/".$GLOBALS["admin_auth_module"];
  191. } elseif ($GLOBALS["admin_auth_module"] && is_file($GLOBALS["admin_auth_module"])) {
  192. require_once $GLOBALS["admin_auth_module"];
  193. } else {
  194. if ($GLOBALS["admin_auth_module"]) {
  195. logEvent("Warning: unable to use ".$GLOBALS["admin_auth_module"]. " for admin authentication, reverting back to phplist authentication");
  196. $GLOBALS["admin_auth_module"] = 'phplist_auth.inc';
  197. }
  198. require_once 'auth/phplist_auth.inc';
  199. }
  200. if (class_exists('admin_auth')) {
  201. $GLOBALS["admin_auth"] = new admin_auth();
  202. } else {
  203. print Fatal_Error($GLOBALS['I18N']->get('Admin Authentication initialisation failure'));
  204. return;
  205. }
  206. if ((!isset($_SESSION["adminloggedin"]) || !$_SESSION["adminloggedin"]) && isset($_REQUEST["login"]) && isset($_REQUEST["password"]) && !empty($_REQUEST["password"])) {
  207. $loginresult = $GLOBALS["admin_auth"]->validateLogin($_REQUEST["login"],$_REQUEST["password"]);
  208. if (!$loginresult[0]) {
  209. $_SESSION["adminloggedin"] = "";
  210. $_SESSION["logindetails"] = "";
  211. $page = "login";
  212. logEvent(sprintf($GLOBALS['I18N']->get('invalid login from %s, tried logging in as %s'),$_SERVER['REMOTE_ADDR'],$_REQUEST["login"]));
  213. $msg = $loginresult[1];
  214. } else {
  215. $_SESSION["adminloggedin"] = $_SERVER["REMOTE_ADDR"];
  216. $_SESSION["logindetails"] = array(
  217. "adminname" => $_REQUEST["login"],
  218. "id" => $loginresult[0],
  219. "superuser" => $admin_auth->isSuperUser($loginresult[0]),
  220. "passhash" => sha1($_REQUEST["password"]),
  221. );
  222. ##16692 - make sure admin permissions apply at first login
  223. $GLOBALS["admin_auth"]->validateAccount($_SESSION["logindetails"]["id"]);
  224. if (!empty($_POST["page"])) {
  225. $page = preg_replace('/\W+/','',$_POST["page"]);
  226. }
  227. }
  228. #If passwords are encrypted and a password recovery request was made, send mail to the admin of the given email address.
  229. } elseif (isset($_REQUEST["forgotpassword"])) {
  230. $adminId = $GLOBALS["admin_auth"]->adminIdForEmail($_REQUEST['forgotpassword']);
  231. if($adminId){
  232. $msg = sendAdminPasswordToken($adminId);
  233. } else {
  234. $msg = $GLOBALS['I18N']->get('Failed sending a change password token');
  235. }
  236. $page = "login";
  237. } elseif (!isset($_SESSION["adminloggedin"]) || !$_SESSION["adminloggedin"]) {
  238. #$msg = 'Not logged in';
  239. $page = "login";
  240. } elseif (CHECK_SESSIONIP && $_SESSION["adminloggedin"] && $_SESSION["adminloggedin"] != $_SERVER["REMOTE_ADDR"]) {
  241. logEvent(sprintf($GLOBALS['I18N']->get('login ip invalid from %s for %s (was %s)'),$_SERVER['REMOTE_ADDR'],$_SESSION["logindetails"]['adminname'],$_SESSION["adminloggedin"]));
  242. $msg = $GLOBALS['I18N']->get('Your IP address has changed. For security reasons, please login again');
  243. $_SESSION["adminloggedin"] = "";
  244. $_SESSION["logindetails"] = "";
  245. $page = "login";
  246. } elseif ($_SESSION["adminloggedin"] && $_SESSION["logindetails"]) {
  247. $validate = $GLOBALS["admin_auth"]->validateAccount($_SESSION["logindetails"]["id"]);
  248. if (!$validate[0]) {
  249. logEvent(sprintf($GLOBALS['I18N']->get('invalidated login from %s for %s (error %s)'),$_SERVER['REMOTE_ADDR'],$_SESSION["logindetails"]['adminname'],$validate[1]));
  250. $_SESSION["adminloggedin"] = "";
  251. $_SESSION["logindetails"] = "";
  252. $page = "login";
  253. $msg = $validate[1];
  254. }
  255. } else {
  256. $page = "login";
  257. }
  258. }
  259. if ($page == 'login') {
  260. unset($_GET['pi']);
  261. }
  262. ## force to login page, if an Ajax call is made without being logged in
  263. if ($ajax && empty($_SESSION['adminloggedin'])) {
  264. $_SESSION['action_result'] = s('Your session timed out, please login again');
  265. print '<script type="text/javascript">top.location = "./?page=home";</script>';
  266. exit;
  267. }
  268. if (LANGUAGE_SWITCH && empty($logoutontop) && !$ajax) {
  269. $languageswitcher = '
  270. <div id="languageswitcher">
  271. <form name="languageswitchform" method="post" action="">';
  272. $languageswitcher .= '
  273. <select name="setlanguage" onchange="document.languageswitchform.submit()">';
  274. $lancount = 0;
  275. foreach ($GLOBALS['LANGUAGES'] as $iso => $rec) {
  276. # if (is_dir(dirname(__FILE__).'/locale/'.$iso)) {
  277. $languageswitcher .= sprintf('
  278. <option value="%s" %s>%s</option>',$iso,$_SESSION['adminlanguage']['iso'] == $iso ? 'selected="selected"':'',$rec[0]);
  279. $lancount++;
  280. # }
  281. }
  282. $languageswitcher .= '
  283. </select>
  284. </form>
  285. </div>';
  286. if ($lancount <= 1) {
  287. $languageswitcher = '';
  288. }
  289. }
  290. require_once dirname(__FILE__).'/setpermissions.php';
  291. $include = '';
  292. if ($page != '' && $page != 'install') {
  293. preg_match("/([\w_]+)/",$page,$regs);
  294. $include = $regs[1];
  295. $include .= ".php";
  296. $include = $page . ".php";
  297. } else {
  298. $include = $GLOBALS['homepage'].".php";
  299. }
  300. $pageinfo = new pageInfo();
  301. $pageinfo->fetchInfoContent($include);
  302. if (is_file('ui/'.$GLOBALS['ui']."/mainmenu.php")) {
  303. include 'ui/'.$GLOBALS['ui']."/mainmenu.php";
  304. }
  305. if (!$ajax) {
  306. if (USE_MINIFIED_ASSETS && file_exists(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/header_minified.inc')) {
  307. include 'ui/'.$GLOBALS['ui']."/header_minified.inc";
  308. } else {
  309. include 'ui/'.$GLOBALS['ui']."/header.inc";
  310. }
  311. }
  312. if (!$ajax) {
  313. print '<h4 class="pagetitle">'.mb_strtolower($page_title).'</h4>';
  314. }
  315. if ($GLOBALS["require_login"] && $page != "login") {
  316. if ($page == 'logout') {
  317. $greeting = $GLOBALS['I18N']->get('goodbye');
  318. } else {
  319. $hr = date("G");
  320. if ($hr > 0 && $hr < 12) {
  321. $greeting = $GLOBALS['I18N']->get('good morning');
  322. } elseif ($hr <= 18) {
  323. $greeting = $GLOBALS['I18N']->get('good afternoon');
  324. } else {
  325. $greeting = $GLOBALS['I18N']->get('good evening');
  326. }
  327. }
  328. if ($page != "logout" && empty($logoutontop) && !$ajax) {
  329. # print '<div class="right">'.PageLink2("logout",$GLOBALS['I18N']->get('logout')).'</div>';
  330. if (!empty($_SESSION['firstinstall']) && $page != 'setup') {
  331. print '<div class="fright">'.PageLinkClass("setup",$GLOBALS['I18N']->get('Continue Configuration'),'','firstinstallbutton').'</div>';
  332. }
  333. }
  334. }
  335. if (!$GLOBALS["commandline"]) {
  336. print '<noscript>';
  337. Info(s('phpList will work without Javascript, but it will be easier to use if you switch it on.'));
  338. print '</noscript>';
  339. }
  340. if (!$ajax && $page != "login") {
  341. if (strpos(VERSION,"dev") && !TEST) {#
  342. if ($GLOBALS["developer_email"]) {
  343. Info("Running DEV version. All emails will be sent to ".$GLOBALS["developer_email"]);
  344. } else {
  345. Info("Running DEV version, but developer email is not set");
  346. }
  347. }
  348. if (TEST) {
  349. print Info($GLOBALS['I18N']->get('Running in testmode, no emails will be sent. Check your config file.'));
  350. }
  351. if (version_compare(PHP_VERSION, '5.1.2', '<') && WARN_ABOUT_PHP_SETTINGS) {
  352. Error($GLOBALS['I18N']->get('phpList requires PHP version 5.1.2 or higher'));
  353. }
  354. if (defined("ENABLE_RSS") && ENABLE_RSS && !function_exists("xml_parse") && WARN_ABOUT_PHP_SETTINGS)
  355. Warn($GLOBALS['I18N']->get('You are trying to use RSS, but XML is not included in your PHP'));
  356. if (ALLOW_ATTACHMENTS && WARN_ABOUT_PHP_SETTINGS && (!is_dir($GLOBALS["attachment_repository"]) || !is_writable ($GLOBALS["attachment_repository"]))) {
  357. if (ini_get("open_basedir")) {
  358. Warn($GLOBALS['I18N']->get('open_basedir restrictions are in effect, which may be the cause of the next warning'));
  359. }
  360. Warn($GLOBALS['I18N']->get('The attachment repository does not exist or is not writable'));
  361. }
  362. if (MANUALLY_PROCESS_QUEUE && isSuperUser() && empty($_GET['pi']) &&
  363. ## hmm, how many more pages to not show this?
  364. (!isset($_GET['page']) ||
  365. ($_GET['page'] != 'processqueue' && $_GET['page'] != 'messages' && $_GET['page'] != 'upgrade'))) {
  366. ## avoid error on uninitialised DB
  367. if (Sql_Table_exists($tables['message'])) {
  368. $queued_count = Sql_Fetch_Row_Query(sprintf('select count(id) from %s where status in ("submitted","inprocess") and embargo < now()',$tables['message']));
  369. if ($queued_count[0]) {
  370. $link = PageLinkButton('processqueue',s('Process the queue'));
  371. $link2 = PageLinkButton('messages&amp;tab=active',s('View the queue'));
  372. if ($link || $link2) {
  373. print Info(sprintf(s('You have %s message(s) waiting to be sent'),$queued_count[0]).'<br/>'.$link.' '.$link2);
  374. }
  375. }
  376. }
  377. }
  378. }
  379. # always allow access to the about page
  380. if (isset($_GET['page']) && $_GET['page'] == 'about') {
  381. $page = 'about';
  382. $include = 'about.php';
  383. }
  384. print $pageinfo->show();
  385. if (!empty($_GET['action']) && $_GET['page'] != 'pageaction') {
  386. $action = basename($_GET['action']);
  387. if (is_file(dirname(__FILE__).'/actions/'.$action.'.php')) {
  388. $status = '';
  389. ## the page action return the result in $status
  390. include dirname(__FILE__).'/actions/'.$action.'.php';
  391. print '<div id="actionresult">'.$status.'</div>';
  392. }
  393. }
  394. /*
  395. if (USEFCK) {
  396. $imgdir = getenv("DOCUMENT_ROOT").$GLOBALS["pageroot"].'/'.FCKIMAGES_DIR.'/';
  397. if (!is_dir($imgdir) || !is_writeable ($imgdir)) {
  398. Warn("The FCK image directory does not exist, or is not writable");
  399. }
  400. }
  401. */
  402. if (!empty($_COOKIE['browsetrail'])) {
  403. if (!isset($_SESSION['browsetrail']) || !is_array($_SESSION['browsetrail'])) {
  404. $_SESSION['browsetrail'] = array();
  405. }
  406. if (!in_array($_COOKIE['browsetrail'],$_SESSION['browsetrail'])) {
  407. $_SESSION['browsetrail'][] = $_COOKIE['browsetrail'];
  408. }
  409. }
  410. if (defined("USE_PDF") && USE_PDF && !defined('FPDF_VERSION')) {
  411. Warn($GLOBALS['I18N']->get('You are trying to use PDF support without having FPDF loaded'));
  412. }
  413. $this_doc = getenv("REQUEST_URI");
  414. if (preg_match("#(.*?)/admin?$#i",$this_doc,$regs)) {
  415. $check_pageroot = $pageroot;
  416. $check_pageroot = preg_replace('#/$#','',$check_pageroot);
  417. if ($check_pageroot != $regs[1] && WARN_ABOUT_PHP_SETTINGS)
  418. Warn($GLOBALS['I18N']->get('The pageroot in your config does not match the current locationCheck your config file.'));
  419. }
  420. clearstatcache();
  421. if (checkAccess($page,"") || $page == 'about') {
  422. if (empty($_GET['pi']) && (is_file($include) || is_link($include))) {
  423. # check whether there is a language file to include
  424. if (is_file("lan/".$_SESSION['adminlanguage']['iso']."/".$include)) {
  425. include "lan/".$_SESSION['adminlanguage']['iso']."/".$include;
  426. }
  427. if (is_file('ui/'.$GLOBALS['ui'].'/pages/'.$include)) {
  428. $include = 'ui/'.$GLOBALS['ui'].'/pages/'.$include;
  429. }
  430. # print "Including $include<br/>";
  431. # hmm, pre-parsing and capturing the error would be nice
  432. #$parses_ok = eval(@file_get_contents($include));
  433. $parses_ok = 1;
  434. if (!$parses_ok) {
  435. print Error("cannot parse $include");
  436. print '<p class="error">Sorry, an error occurred. This is a bug. Please <a href="http://mantis.phplist.com">report the bug to the Bug Tracker</a><br/>Sorry for the inconvenience</a></p>';
  437. } else {
  438. if (!empty($_SESSION['action_result'])) {
  439. print '<div class="actionresult">'.$_SESSION['action_result'].'</div>';
  440. # print '<script>alert("'.$_SESSION['action_result'].'")</script>';
  441. unset($_SESSION['action_result']);
  442. }
  443. if ($GLOBALS['commandline']) {
  444. @ob_end_clean();
  445. @ob_start();
  446. }
  447. if (isset($GLOBALS['developer_email'])) {
  448. include $include;
  449. } else {
  450. @include $include;
  451. }
  452. }
  453. # print "End of inclusion<br/>";
  454. } elseif (!empty($_GET['pi']) && isset($GLOBALS['plugins']) && is_array($GLOBALS['plugins']) && isset($GLOBALS['plugins'][$_GET['pi']]) && is_object($GLOBALS['plugins'][$_GET['pi']])) {
  455. $plugin = $GLOBALS["plugins"][$_GET["pi"]];
  456. $menu = $plugin->adminmenu();
  457. if (is_file($plugin->coderoot . $include)) {
  458. include ($plugin->coderoot . $include);
  459. } elseif ($include == 'main.php' || $_GET['page'] == 'home') {
  460. print '<h3>'.$plugin->name.'</h3><ul>';
  461. foreach ($menu as $page => $desc) {
  462. print '<li>'.PageLink2($page,$desc).'</li>';
  463. }
  464. print '</ul>';
  465. } elseif ($page != 'login') {
  466. print '<br/>'."$page -&gt; ".$I18N->get('Sorry this page was not found in the plugin').'<br/>';#.' '.$plugin->coderoot.$include.'<br/>';
  467. #print $plugin->coderoot . "$include";
  468. }
  469. } else {
  470. if ($GLOBALS["commandline"]) {
  471. clineError(s('Sorry, that module does not exist'));
  472. exit;
  473. }
  474. if (is_file('ui/'.$GLOBALS['ui'].'/pages/'.$include)) {
  475. include ('ui/'.$GLOBALS['ui'].'/pages/'.$include);
  476. } else {
  477. print "$page -&gt; ".$GLOBALS['I18N']->get('Sorry, not implemented yet');
  478. }
  479. }
  480. } else {
  481. Error($GLOBALS['I18N']->get('Access Denied'));
  482. }
  483. # some debugging stuff
  484. $now = gettimeofday();
  485. $finished = $now["sec"] * 1000000 + $now["usec"];
  486. $elapsed = $finished - $GLOBALS["pagestats"]["time_start"];
  487. $elapsed = ($elapsed / 1000000);
  488. print "\n\n".'<!--';
  489. if (!empty($GLOBALS['developer_email'])) {
  490. print '<br clear="all" />';
  491. print $GLOBALS["pagestats"]["number_of_queries"]." db queries in $elapsed seconds";
  492. if (function_exists('memory_get_peak_usage')) {
  493. $memory_usage = 'Peak: ' .memory_get_peak_usage();
  494. } elseif (function_exists("memory_get_usage")) {
  495. $memory_usage = memory_get_usage();
  496. } else {
  497. $memory_usage = 'Cannot determine with this PHP version';
  498. }
  499. print '<br/>Memory usage: '.$memory_usage;
  500. }
  501. if (isset($GLOBALS["statslog"])) {
  502. if ($fp = @fopen($GLOBALS["statslog"],"a")) {
  503. @fwrite($fp,$GLOBALS["pagestats"]["number_of_queries"]."\t$elapsed\t".$_SERVER['REQUEST_URI']."\t".$GLOBALS['installation_name']."\n");
  504. }
  505. }
  506. print '-->';
  507. if ($ajax || !empty($GLOBALS["commandline"])) {
  508. @ob_clean();
  509. exit;
  510. } elseif (!isset($_GET["omitall"])) {
  511. if (!$GLOBALS['compression_used']) {
  512. @ob_end_flush();
  513. }
  514. if (USE_MINIFIED_ASSETS && file_exists(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/footer_minified.inc')) {
  515. include_once 'ui/'.$GLOBALS['ui']."/footer_minified.inc";
  516. } else {
  517. include_once 'ui/'.$GLOBALS['ui']."/footer.inc";
  518. }
  519. }
  520. if (isset($GLOBALS['pagefooter'])) {
  521. foreach ($GLOBALS['pagefooter'] as $sFooterItem => $sHtml ) {
  522. print '<!--'.$sFooterItem.'-->'.$sHtml;
  523. print "\n";
  524. }
  525. }
  526. print '</body></html>';
  527. function parseCline() {
  528. $res = array();
  529. $cur = "";
  530. foreach ($GLOBALS["argv"] as $clinearg) {
  531. if (substr($clinearg,0,1) == "-") {
  532. $par = substr($clinearg,1,1);
  533. $clinearg = substr($clinearg,2,strlen($clinearg));
  534. # $res[$par] = "";
  535. $cur = mb_strtolower($par);
  536. $res[$cur] .= $clinearg;
  537. } elseif ($cur) {
  538. if ($res[$cur])
  539. $res[$cur] .= ' '.$clinearg;
  540. else
  541. $res[$cur] .= $clinearg;
  542. }
  543. }
  544. /* ob_end_clean();
  545. foreach ($res as $key => $val) {
  546. print "$key = $val\n";
  547. }
  548. ob_start();*/
  549. return $res;
  550. }