File:  [Paefchen] / FreeBSD / tinderbox / webui / index.php
Revision 1.1.1.1.2.2: download - view: text, annotated - select for diffs - revision graph
Thu Nov 15 15:29:46 2007 UTC (17 years ago) by as
Branches: CH2PHP5
Diff to: branchpoint 1.1.1.1: preferred, unified
add config compat-mod

<?php
#-
# Copyright (c) 2005 Oliver Lehmann <oliver@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# 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 $
#

define('STARTTIME', microtime(true));

if ((int)PHP_VERSION < 5)
	die ("Error: TB-WebUI needs PHP5!\n");

foreach (array('pcre') as $phpmodule)
	if (! extension_loaded($phpmodule))
		die (sprintf("Error: TB-WebUI needs PHP-Module '%s'\n",
			$phpmodule));

if (! is_readable('inc_ds.php'))
	die ("Error: Configuration File not found (inc_ds.php)\n");
require_once 'inc_ds.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);

set_include_path(get_include_path().PATH_SEPARATOR.'module'
    .PATH_SEPARATOR.'core');

function __autoload($class) {
	require_once $class . '.php';
}

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 ) {
	case 'describe_port':		$port_id    = $_REQUEST['id'];
					$display    = $modulePorts->display_describe_port( $port_id );
					break;
	case 'failed_buildports':	$build      = $_REQUEST['build'];
					$maintainer = $_REQUEST['maintainer'];
					$display    = $moduleBuildPorts->display_failed_buildports( $build, $maintainer, null );
					break;
	case 'bad_buildports':		$build      = $_REQUEST['build'];
					$maintainer = $_REQUEST['maintainer'];
					$display    = $moduleBuildPorts->display_failed_buildports( $build, $maintainer, 'foo' );
					break;
	case 'latest_buildports':	$build      = $_REQUEST['build'];
					$display    = $moduleBuildPorts->display_latest_buildports( $build );
					break;
	case 'list_buildports':		$build      = $_REQUEST['build'];
					$sort       = '';
					if (isset($_REQUEST['sort'])) {
						$sort = $_REQUEST['sort'];
					}
					$display    = $moduleBuildPorts->display_list_buildports( $build, $sort );
					break;
	case 'list_tinderd_queue':	$build_id   = $_REQUEST['filter_build_id'];
					$display    = $moduleTinderd->list_tinderd_queue( $build_id );
					break;
	case 'change_tinderd_queue':	$ctinderdq  = $_REQUEST['change_tinderd_queue'];
					$entry_id   = $_REQUEST['entry_id'];
					$build_id   = $_REQUEST['build_id'];
					$priority   = $_REQUEST['priority'];
					$emailoc    = $_REQUEST['email_on_completion'];
					$moduleTinderd->change_tinderd_queue( $ctinderdq, $entry_id, $build_id, $priority, $emailoc );
					$build_id   = $_REQUEST['filter_build_id'];
					$display    = $moduleTinderd->list_tinderd_queue( $build_id );
					break;
	case 'add_tinderd_queue':	$atinderdq  = $_REQUEST['add_tinderd_queue'];
					$build_id   = $_REQUEST['new_build_id'];
					$priority   = $_REQUEST['new_priority'];
					$directory  = $_REQUEST['new_port_directory'];
					$emailoc    = $_REQUEST['new_email_on_completion'];
					$moduleTinderd->add_tinderd_queue( $atinderdq, $build_id, $priority, $directory, $emailoc );
					$build_id   = $_REQUEST['filter_build_id'];
					$display    = $moduleTinderd->list_tinderd_queue( $build_id );
					break;
	case 'display_add_user':	$display    = $moduleUsers->display_add_user( '', '', '', '', array() );
					break;
	case 'add_user':		$user_name  = $_REQUEST['user_name'];
					$user_email = $_REQUEST['user_email'];
					$user_pwd   = $_REQUEST['user_password'];
					$wwwenabled = $_REQUEST['www_enabled'];
					$display    = $moduleUsers->action_user( 'add', '', $user_name, $user_email, $user_pwd, $wwwenabled );
					switch( $display ) {
						case '1':	unset( $display ); header( 'Location: index.php' ); break;
						case '0':	$display = $moduleUsers->display_add_user( $user_name, $user_email, $user_pwd, $wwwenabled ); break;
					}
					break;
	case 'display_modify_user':	$user_id  = $_REQUEST['modify_user_id'];
					$display    = $moduleUsers->display_modify_user( 1, $user_id, '', '', '', '', array() );
					break;
	case 'modify_user':		$actionuser = $_REQUEST['action_user'];
					$user_id    = $_REQUEST['user_id'];
					$user_name  = $_REQUEST['user_name'];
					$user_email = $_REQUEST['user_email'];
					$user_pwd   = $_REQUEST['user_password'];
					$wwwenabled = $_REQUEST['www_enabled'];
					$display    = $moduleUsers->action_user( $actionuser, $user_id, $user_name, $user_email, $user_pwd, $wwwenabled );
					switch( $display ) {
						case '1':	unset( $display ); header( 'Location: index.php' ); break;
						case '0':	$display = $moduleUsers->display_modify_user( 0, $user_id, $user_name, $user_email, $user_pwd, $www_enabled ); break;
					}
					break;
	case 'display_failure_reasons':	$failure_reason_tag  = $_REQUEST['failure_reason_tag'];
					$display    = $modulePortFailureReasons->display_failure_reasons( $failure_reason_tag );
					break;
	case 'config':			$display    = $moduleConfig->display_config();
					break;
	case 'list_builds':
	default:			$display    = $moduleBuilds->display_list_builds();
					break;
}

echo $display;

if (isset($with_timer) && $with_timer) 
	printf('<p style="color:#FF0000;font-size:10px;">elapsed: %03.6f seconds, </p>', microtime(true) - $starttimer);

echo '<p style="font-size:10px;"><b>Note:</b> The Tinderbox web interface requires cookies to be enable.</p>';
?>