--- FreeBSD/tinderbox/webui/index.php 2007/11/02 20:55:00 1.1 +++ FreeBSD/tinderbox/webui/index.php 2007/11/16 22:52:43 1.1.1.1.2.3 @@ -24,41 +24,103 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # +# $Paefchen: FreeBSD/tinderbox/webui/index.php,v 1.1.1.1.2.2 2007/11/15 15:29:46 as Exp $ # $MCom: portstools/tinderbox/webui/index.php,v 1.22 2007/10/13 02:28:47 ade Exp $ # -$starttimer = explode( ' ', microtime() ); +define('STARTTIME', microtime(true)); -require_once 'module/moduleBuilds.php'; -require_once 'module/moduleBuildPorts.php'; -require_once 'module/moduleConfig.php'; -require_once 'module/modulePorts.php'; -require_once 'module/modulePortFailureReasons.php'; -require_once 'module/moduleSession.php'; -require_once 'module/moduleTinderd.php'; -require_once 'module/moduleUsers.php'; +if ((int)PHP_VERSION < 5) + die ("Error: TB-WebUI needs PHP5!\n"); -require_once $templatesdir.'/messages.inc'; +foreach (array('pcre') as $phpmodule) + if (! extension_loaded($phpmodule)) + die (sprintf("Error: TB-WebUI needs PHP-Module '%s'\n", + $phpmodule)); -$moduleBuilds = new moduleBuilds(); -$moduleBuildPorts = new moduleBuildPorts(); -$moduleConfig = new moduleConfig(); -$modulePorts = new modulePorts(); -$modulePortFailureReasons = new modulePortFailureReasons(); -$moduleSession = new moduleSession(); -$moduleTinderd = new moduleTinderd(); -$moduleUsers = new moduleUsers(); +if (! is_readable('inc_ds.php')) + die ("Error: Configuration File not found (inc_ds.php)\n"); +require_once 'inc_ds.php'; -$moduleSession->start(); -if( isset($_POST['do_login']) ) { - $moduleUsers->do_login( $_POST['User_Name'], $_POST['User_Password'] ); -} elseif( isset($_POST['do_logout']) || ( $moduleUsers->is_logged_in() && !$moduleUsers->get_www_enabled() ) ) { - $moduleUsers->do_logout(); - header( 'Location: index.php' ); +if (is_readable('inc_tinderbox.php')) + require_once 'inc_tinderbox.php'; + +/* ...defaults && compat... */ +if (! defined('MODULES')) define('MODULES', 'Builds, BuildPorts, Config, Ports, PortFailureReasons, Tinderd, Users'); +if (! defined('TB_NAME')) define('TB_NAME', isset($tinderbox_name) ? $tinderbox_name : 'Example Tinderbox'); +if (! defined('TB_TITLE')) define('TB_TITLE', isset($tinderbox_title) ? $tinderbox_title : 'Example Tinderbox'); +if (! defined('WWWROOT')) define('WWWROOT', isset($wwwrooturi) ? $wwwrooturi : dirname(__FILE__)); +if (! defined('TBROOT')) define('TBROOT', isset($rootdir) ? $rootdir : realpath(WWWROOT.'/../..')); +if (! defined('TEMPLATE')) define('TEMPLATE', isset($template_dir) ? $template_dir : 'default'); +if (! defined('URLROOT')) define('URLROOT', dirname($_SERVER['SCRIPT_NAME'])); +if (! defined('PROTOCOL')) define('PROTOCOL', isset($_SERVER['HTTPS'])?'https':'http'); +if (! defined('HOSTNAME')) define('HOSTNAME', $_SERVER['SERVER_NAME']); +if (! defined('PORT')) define('PORT', $_SERVER['SERVER_PORT']); +if (! defined('URL')) define('URL', PROTOCOL.'://'.HOSTNAME.(PORT!=80?':80':'').URLROOT); +if (! defined('PKGURL')) define('PKGURL', isset($pkguri) ? $pkguri : URL.'/packages'); +if (! defined('PKGDIR')) define('PKGDIR', isset($pkgdir) ? $pkgdir : TBROOT.'/packages'); +if (! defined('LOGURL')) define('LOGURL', isset($loguri) ? $loguri : URL.'/logs'); +if (! defined('LOGDIR')) define('LOGDIR', isset($lodir) ? $logdir : TBROOT.'/logs'); +if (! defined('ERRORLOGURL')) define('ERRORLOGURL', isset($errorloguri) ? $errorloguri : URL.'/errors'); +if (! defined('ERRORLOGDIR')) define('ERRORLOGDIR', isset($errorlogdir) ? $errorlogdir : TBROOT.'/errors'); +if (! defined('TEMPLATESURL')) define('TEMPLATESURL', isset($templatesuri) ? $templatesuri : URL.'/templates/'.TEMPLATE); +if (! defined('TEMPLATESDIR')) define('TEMPLATESDIR', isset($templatesdir) ? $templatesdir : WWWROOT.'/templates/'.TEMPLATE); +if (! defined('SHOWTIMER')) define('SHOWTIMER', false); + +foreach (array('WWWROOT', 'TBROOT', 'TEMPLATESDIR') as $dir) + if (! is_dir(constant($dir))) + die(sprintf("Error => config: dir %s not found (%s)\n", + constant($dir), $dir)); + +set_include_path(get_include_path().PATH_SEPARATOR.'module' + .PATH_SEPARATOR.'core'); + +function __autoload($class) { + require_once $class.'.php'; } -$display_login = $moduleUsers->display_login(); +function module_list() { + return preg_split('/[,; ]+/', MODULES); +} +function module_instance($module) { + static $instances; + if (! isset($instances)) + $instances = array(); +} + + +foreach (module_list() as $moduleName) { + $className = 'module' . $moduleName; + + if (! is_readable('module/'.$className.'.php')) + die (sprintf("Error: Module not found (%s)\n", + $moduleName)); + + define('MODULE_'.strtoupper($moduleName), $className); + /* as xxx */ + $$className = new $className; +} + +require_once TEMPLATESDIR.'/messages.inc'; + +if (defined('MODULE_USERS')) { + $moduleUsers->start(); + + if (isset($_POST['do_login'])) { + $moduleUsers->do_login( $_POST['User_Name'], $_POST['User_Password']); + } + else if(isset($_POST['do_logout']) + || ($moduleUsers->is_logged_in() && ! $moduleUsers->get_www_enabled())) { + $moduleUsers->do_logout(); + header('Location: index.php'); + exit; + } +} + +/* as xxx */ +#$display_login = $moduleUsers->display_login(); + $action = $_REQUEST['action']; switch( $action ) { @@ -143,10 +205,8 @@ switch( $action ) { echo $display; -if( isset( $with_timer ) && $with_timer == 1 ) { - $endtimer = explode( ' ', microtime() ); - $timer = ( $endtimer[1]-$starttimer[1] )+( $endtimer[0]-$starttimer[0] ); - printf( '

elapsed: %03.6f seconds, %s', $timer, '

' ); -} +if (isset($with_timer) && $with_timer) + printf('

elapsed: %03.6f seconds,

', microtime(true) - $starttimer); + echo '

Note: The Tinderbox web interface requires cookies to be enable.

'; ?>