From 91a10dfc36412f3715e6968d3b5619cb74be319a Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 27 May 2013 21:57:48 -0400 Subject: [PATCH] Start porting admin/ to use the hoplite HTTP stack. This rewrites index.php to be an entrypoint, which should eventually be moved up a level. This begins the conversion of the admin section welcome screen. --- admin/home.php | 102 +++++++++++++++++++++++++++++++++++++++++++++ admin/index.php | 104 +++++++++++++++++++++++++--------------------- includes/init.php | 2 +- 3 files changed, 160 insertions(+), 48 deletions(-) create mode 100644 admin/home.php mode change 100755 => 100644 admin/index.php diff --git a/admin/home.php b/admin/home.php new file mode 100644 index 0000000..3b9730e --- /dev/null +++ b/admin/home.php @@ -0,0 +1,102 @@ +body = 'Hello World'; + } +} + +/* +require_once('./global.php'); + +NavLinks::optionsPages(); +$navigator->set_focus('tab', 'options', null); +$navigator->set_focus('link', 'options-pages-home', 'options-pages'); + +$admin->page_start(T('Home')); + +// ################################################################### + +if (!(defined('NO_VERSION_CHECK') AND constant('NO_VERSION_CHECK') == true)) +{ + $check = @file_get_contents('http://www.bluestatic.org/versioncheck.php?prod=bugdar&ver=' . str_replace(' ', '-', $bugsys->options['trackerversion'])); + if (strpos($check, '') !== false) + { + $check = $bugsys->xml->parse($check); + if (isset($check['version-check']['update'])) + { + $admin->page_code('
' . T('Update Avaliable') . ':
' . sprintf(T('Your installation of Bugdar is out-of-date. You are running version %1$s and the latest version is %2$s. You can download the update at Blue Static\'s website. You are strongly encouraged to apply all updates to fix bugs and any security issues (if present).'), $bugsys->options['trackerversion'], $check['version-check']['update']['value']) . '
'); + } + else if (isset($check['version-check']['up-to-date'])) + { + $admin->page_code('
' . T('Up-to-Date') . ':
' . sprintf(T('Your installation of Bugdar is up-to-date. You are running version %1$s.'), $bugsys->options['trackerversion']) . '
'); + } + } +} + +// ################################################################### + +$admin->table_start(); +$admin->table_head(T('Welcome to the Bugdar Admin Panel')); + +// ------------------------------------------------------------------- +$admin->row_span(T('Version Information'), 'thead'); +$admin->row_text(T('Bugdar Version'), $bugsys->options['trackerversion']); +$admin->row_text(T('PHP Version'), phpversion()); + +$mysql = $db->query_first("SELECT VERSION() AS version"); +$admin->row_text(T('MySQL Version'), $mysql['version']); + +$admin->row_text(T('Web Server'), ($_SERVER['SERVER_SOFTWARE'] ? $_SERVER['SERVER_SOFTWARE'] : $SERVER['SERVER_SOFTWARE'])); + +// ------------------------------------------------------------------- +$admin->row_span(T('Server Options'), 'thead'); + +$mysql = $db->query_first("SHOW VARIABLES LIKE 'max_allowed_packet'"); +$admin->row_text(T('MySQL: Maximum Packet Size'), $mysql['Value']); + +$admin->row_text(T('MySQL: Maximum Upload Size'), $funct->fetch_max_attachment_size()); + +$mysql = $db->query_first("SHOW VARIABLES LIKE 'ft_min_word_len'"); +$admin->row_text(T('MySQL: Full-Text Search Minimum Word Length'), $mysql['Value']); + +$admin->row_text(T('PHP: Safe Mode'), ((ini_get('safe_mode') == 1 OR strtolower(ini_get('safe_mode')) == 'on') ? T('Yes') : T('No'))); +$admin->row_text(T('PHP: Register Globals'), ((ini_get('register_globals') == 1 OR strtolower(ini_get('register_globals')) == 'on') ? T('Yes') : T('No'))); +$admin->row_text(T('PHP: Magic Quotes GPC'), ((ini_get('magic_quotes_gpc') == 1 OR strtolower(ini_get('magic_quotes_gpc')) == 'on') ? T('Yes') : T('No'))); +$admin->row_text(T('PHP: Magic Quotes Sybase'), ((ini_get('magic_quotes_sybase') == 1 OR strtolower(ini_get('magic_quotes_sybase')) == 'on') ? T('Yes') : T('No'))); + +// ------------------------------------------------------------------- + +$admin->table_end(); + +$admin->page_end(); + +*/ \ No newline at end of file diff --git a/admin/index.php b/admin/index.php old mode 100755 new mode 100644 index 7382cc3..e34a2cc --- a/admin/index.php +++ b/admin/index.php @@ -2,7 +2,7 @@ /*=====================================================================*\ || ################################################################### || # Bugdar -|| # Copyright (c)2002-2007 Blue Static +|| # Copyright (c)2002-2013 Blue Static || # || # This program is free software; you can redistribute it and/or modify || # it under the terms of the GNU General Public License as published by @@ -19,67 +19,77 @@ || ################################################################### \*=====================================================================*/ -require_once('./global.php'); +namespace bugdar\admin; -NavLinks::optionsPages(); -$navigator->set_focus('tab', 'options', null); -$navigator->set_focus('link', 'options-pages-home', 'options-pages'); +use \bugdar; +use \hoplite\http; -$admin->page_start(T('Home')); +chdir('../'); +require_once './includes/init.php'; -// ################################################################### +require_once HOPLITE_ROOT . '/http/output_filter.php'; +require_once HOPLITE_ROOT . '/http/response_code.php'; +require_once HOPLITE_ROOT . '/http/root_controller.php'; +require_once HOPLITE_ROOT . '/http/url_map.php'; -if (!(defined('NO_VERSION_CHECK') AND constant('NO_VERSION_CHECK') == true)) +/** + * @implements \hoplite\http\RootControllerDelegate + */ +class FrontController { - $check = @file_get_contents('http://www.bluestatic.org/versioncheck.php?prod=bugdar&ver=' . str_replace(' ', '-', $bugsys->options['trackerversion'])); - if (strpos($check, '') !== false) + /** @var \hoplite\http\RootController */ + private $controller = NULL; + + public function __construct(http\RootController $controller) { - $check = $bugsys->xml->parse($check); - if (isset($check['version-check']['update'])) - { - $admin->page_code('
' . T('Update Avaliable') . ':
' . sprintf(T('Your installation of Bugdar is out-of-date. You are running version %1$s and the latest version is %2$s. You can download the update at Blue Static\'s website. You are strongly encouraged to apply all updates to fix bugs and any security issues (if present).'), $bugsys->options['trackerversion'], $check['version-check']['update']['value']) . '
'); - } - else if (isset($check['version-check']['up-to-date'])) - { - $admin->page_code('
' . T('Up-to-Date') . ':
' . sprintf(T('Your installation of Bugdar is up-to-date. You are running version %1$s.'), $bugsys->options['trackerversion']) . '
'); - } + $this->controller = $controller; } -} - -// ################################################################### - -$admin->table_start(); -$admin->table_head(T('Welcome to the Bugdar Admin Panel')); - -// ------------------------------------------------------------------- -$admin->row_span(T('Version Information'), 'thead'); -$admin->row_text(T('Bugdar Version'), $bugsys->options['trackerversion']); -$admin->row_text(T('PHP Version'), phpversion()); -$mysql = $db->query_first("SELECT VERSION() AS version"); -$admin->row_text(T('MySQL Version'), $mysql['version']); + public function WillRouteRequest(http\Request $request, http\Response $response) + { + // TODO(port): Write a new cookie function. + global $funct; -$admin->row_text(T('Web Server'), ($_SERVER['SERVER_SOFTWARE'] ? $_SERVER['SERVER_SOFTWARE'] : $SERVER['SERVER_SOFTWARE'])); + $cookie = COOKIE_PREFIX . 'adminsession'; -// ------------------------------------------------------------------- -$admin->row_span(T('Server Options'), 'thead'); + if (can_perform('canadminpanel')) { + $stmt = bugdar::$db->Prepare("SELECT * FROM ". TABLE_PREFIX . "adminsession WHERE sessionid = ?"); + $stmt->Execute(array(bugdar::$input->InputClean('c', $cookie, http\Input::TYPE_STR))); + $session = $stmt->FetchObject(); -$mysql = $db->query_first("SHOW VARIABLES LIKE 'max_allowed_packet'"); -$admin->row_text(T('MySQL: Maximum Packet Size'), $mysql['Value']); + if ($session && $session->userid == bugdar::$user['userid'] && $session->dateline >= TIMENOW - 3600) { + // Renew the cookie. + $funct->cookie($cookie, $session->sessionid, false); + return; + } + } -$admin->row_text(T('MySQL: Maximum Upload Size'), $funct->fetch_max_attachment_size()); + $funct->cookie($cookie, NULL); + $this->LoginPage(); + } -$mysql = $db->query_first("SHOW VARIABLES LIKE 'ft_min_word_len'"); -$admin->row_text(T('MySQL: Full-Text Search Minimum Word Length'), $mysql['Value']); + public function LoginPage() + { + $this->controller->StopWithCode(http\ResponseCode::FORBIDDEN); + } +} -$admin->row_text(T('PHP: Safe Mode'), ((ini_get('safe_mode') == 1 OR strtolower(ini_get('safe_mode')) == 'on') ? T('Yes') : T('No'))); -$admin->row_text(T('PHP: Register Globals'), ((ini_get('register_globals') == 1 OR strtolower(ini_get('register_globals')) == 'on') ? T('Yes') : T('No'))); -$admin->row_text(T('PHP: Magic Quotes GPC'), ((ini_get('magic_quotes_gpc') == 1 OR strtolower(ini_get('magic_quotes_gpc')) == 'on') ? T('Yes') : T('No'))); -$admin->row_text(T('PHP: Magic Quotes Sybase'), ((ini_get('magic_quotes_sybase') == 1 OR strtolower(ini_get('magic_quotes_sybase')) == 'on') ? T('Yes') : T('No'))); +$controller = new http\RootController($GLOBALS); +$controller->set_delegate(new FrontController($controller)); -// ------------------------------------------------------------------- +$url_map = new http\UrlMap($controller); +$url_map->set_file_loader(function($name, $value) { + require_once BUGDAR_ROOT . '/admin/' . $value; + return 'bugdar\\admin\\' . $name . 'Action'; +}); +$controller->set_url_map($url_map); -$admin->table_end(); +$url_map->set_map(array( + '' => 'home', + 'fields' => 'fields', +)); -$admin->page_end(); +$output_filter = new http\OutputFilter($controller); +$controller->set_output_filter($output_filter); +$controller->Run(); diff --git a/includes/init.php b/includes/init.php index 9627163..d1b9d1f 100755 --- a/includes/init.php +++ b/includes/init.php @@ -91,9 +91,9 @@ class bugdar static $datastore = array(); } +// TODO(port): Define this in index.php instead. define('BUGDAR_ROOT', dirname(dirname(__FILE__))); - // ################################################################### // Initialize Hoplite concurrently with ISSO 2.x. -- 2.43.5