Annotation of FreeBSD/tinderbox/webui/index.php, revision 1.1.1.1.2.2
1.1 as 1: <?php
2: #-
3: # Copyright (c) 2005 Oliver Lehmann <oliver@FreeBSD.org>
4: # All rights reserved.
5: #
6: # Redistribution and use in source and binary forms, with or without
7: # modification, are permitted provided that the following conditions
8: # are met:
9: # 1. Redistributions of source code must retain the above copyright
10: # notice, this list of conditions and the following disclaimer
11: # 2. Redistributions in binary form must reproduce the above copyright
12: # notice, this list of conditions and the following disclaimer in the
13: # documentation and/or other materials provided with the distribution.
14: #
15: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25: # SUCH DAMAGE.
26: #
1.1.1.1.2.2! as 27: # $Paefchen: FreeBSD/tinderbox/webui/index.php,v 1.1.1.1.2.1 2007/11/13 07:39:25 as Exp $
1.1 as 28: # $MCom: portstools/tinderbox/webui/index.php,v 1.22 2007/10/13 02:28:47 ade Exp $
29: #
30:
1.1.1.1.2.2! as 31: define('STARTTIME', microtime(true));
1.1 as 32:
1.1.1.1.2.2! as 33: if ((int)PHP_VERSION < 5)
! 34: die ("Error: TB-WebUI needs PHP5!\n");
1.1 as 35:
1.1.1.1.2.2! as 36: foreach (array('pcre') as $phpmodule)
! 37: if (! extension_loaded($phpmodule))
! 38: die (sprintf("Error: TB-WebUI needs PHP-Module '%s'\n",
! 39: $phpmodule));
! 40:
! 41: if (! is_readable('inc_ds.php'))
! 42: die ("Error: Configuration File not found (inc_ds.php)\n");
! 43: require_once 'inc_ds.php';
! 44:
! 45: if (is_readable('inc_tinderbox.php'))
! 46: require_once 'inc_tinderbox.php';
! 47:
! 48: /* ...defaults && compat... */
! 49: if (! defined('MODULES')) define('MODULES', 'Builds, BuildPorts, Config, Ports, PortFailureReasons, Tinderd, Users');
! 50: if (! defined('TB_NAME')) define('TB_NAME', isset($tinderbox_name) ? $tinderbox_name : 'Example Tinderbox');
! 51: if (! defined('TB_TITLE')) define('TB_TITLE', isset($tinderbox_title) ? $tinderbox_title : 'Example Tinderbox');
! 52: if (! defined('WWWROOT')) define('WWWROOT', isset($wwwrooturi) ? $wwwrooturi : dirname(__FILE__));
! 53: if (! defined('TBROOT')) define('TBROOT', isset($rootdir) ? $rootdir : realpath(WWWROOT.'/../..'));
! 54: if (! defined('TEMPLATE')) define('TEMPLATE', isset($template_dir) ? $template_dir : 'default');
! 55: if (! defined('URLROOT')) define('URLROOT', dirname($_SERVER['SCRIPT_NAME']));
! 56: if (! defined('PROTOCOL')) define('PROTOCOL', isset($_SERVER['HTTPS'])?'https':'http');
! 57: if (! defined('HOSTNAME')) define('HOSTNAME', $_SERVER['SERVER_NAME']);
! 58: if (! defined('PORT')) define('PORT', $_SERVER['SERVER_PORT']);
! 59: if (! defined('URL')) define('URL', PROTOCOL.'://'.HOSTNAME.(PORT!=80?':80':'').URLROOT);
! 60: if (! defined('PKGURL')) define('PKGURL', isset($pkguri) ? $pkguri : URL.'/packages');
! 61: if (! defined('PKGDIR')) define('PKGDIR', isset($pkgdir) ? $pkgdir : TBROOT.'/packages');
! 62: if (! defined('LOGURL')) define('LOGURL', isset($loguri) ? $loguri : URL.'/logs');
! 63: if (! defined('LOGDIR')) define('LOGDIR', isset($lodir) ? $logdir : TBROOT.'/logs');
! 64: if (! defined('ERRORLOGURL')) define('ERRORLOGURL', isset($errorloguri) ? $errorloguri : URL.'/errors');
! 65: if (! defined('ERRORLOGDIR')) define('ERRORLOGDIR', isset($errorlogdir) ? $errorlogdir : TBROOT.'/errors');
! 66: if (! defined('TEMPLATESURL')) define('TEMPLATESURL', isset($templatesuri) ? $templatesuri : URL.'/templates/'.TEMPLATE);
! 67: if (! defined('TEMPLATESDIR')) define('TEMPLATESDIR', isset($templatesdir) ? $templatesdir : WWWROOT.'/templates/'.TEMPLATE);
! 68: if (! defined('SHOWTIMER')) define('SHOWTIMER', false);
! 69:
! 70: set_include_path(get_include_path().PATH_SEPARATOR.'module'
! 71: .PATH_SEPARATOR.'core');
1.1.1.1.2.1 as 72:
73: function __autoload($class) {
74: require_once $class . '.php';
75: }
76:
1.1.1.1.2.2! as 77: function module_list() {
! 78: return preg_split('/[,; ]+/', MODULES);
! 79: }
! 80:
! 81: function module_instance($module) {
! 82: static $instances;
! 83: if (! isset($instances))
! 84: $instances = array();
! 85: }
! 86:
! 87:
! 88: foreach (module_list() as $moduleName) {
! 89: $className = 'module' . $moduleName;
! 90:
! 91: if (! is_readable('module/'.$className.'.php'))
! 92: die (sprintf("Error: Module not found (%s)\n",
! 93: $moduleName));
! 94:
! 95: define('MODULE_'.strtoupper($moduleName), $className);
! 96: /* as xxx */
1.1.1.1.2.1 as 97: $$className = new $className;
98: }
1.1 as 99:
1.1.1.1.2.2! as 100: require_once TEMPLATESDIR.'/messages.inc';
! 101:
! 102: if (defined('MODULE_USERS')) {
! 103: $moduleUsers->start();
1.1 as 104:
1.1.1.1.2.2! as 105: if (isset($_POST['do_login'])) {
! 106: $moduleUsers->do_login( $_POST['User_Name'], $_POST['User_Password']);
! 107: }
! 108: else if(isset($_POST['do_logout'])
! 109: || ($moduleUsers->is_logged_in() && ! $moduleUsers->get_www_enabled())) {
! 110: $moduleUsers->do_logout();
! 111: header('Location: index.php');
! 112: exit;
! 113: }
1.1 as 114: }
115:
1.1.1.1.2.2! as 116: /* as xxx */
! 117: #$display_login = $moduleUsers->display_login();
1.1 as 118:
119: $action = $_REQUEST['action'];
120:
121: switch( $action ) {
122: case 'describe_port': $port_id = $_REQUEST['id'];
123: $display = $modulePorts->display_describe_port( $port_id );
124: break;
125: case 'failed_buildports': $build = $_REQUEST['build'];
126: $maintainer = $_REQUEST['maintainer'];
127: $display = $moduleBuildPorts->display_failed_buildports( $build, $maintainer, null );
128: break;
129: case 'bad_buildports': $build = $_REQUEST['build'];
130: $maintainer = $_REQUEST['maintainer'];
131: $display = $moduleBuildPorts->display_failed_buildports( $build, $maintainer, 'foo' );
132: break;
133: case 'latest_buildports': $build = $_REQUEST['build'];
134: $display = $moduleBuildPorts->display_latest_buildports( $build );
135: break;
136: case 'list_buildports': $build = $_REQUEST['build'];
137: $sort = '';
138: if (isset($_REQUEST['sort'])) {
139: $sort = $_REQUEST['sort'];
140: }
141: $display = $moduleBuildPorts->display_list_buildports( $build, $sort );
142: break;
143: case 'list_tinderd_queue': $build_id = $_REQUEST['filter_build_id'];
144: $display = $moduleTinderd->list_tinderd_queue( $build_id );
145: break;
146: case 'change_tinderd_queue': $ctinderdq = $_REQUEST['change_tinderd_queue'];
147: $entry_id = $_REQUEST['entry_id'];
148: $build_id = $_REQUEST['build_id'];
149: $priority = $_REQUEST['priority'];
150: $emailoc = $_REQUEST['email_on_completion'];
151: $moduleTinderd->change_tinderd_queue( $ctinderdq, $entry_id, $build_id, $priority, $emailoc );
152: $build_id = $_REQUEST['filter_build_id'];
153: $display = $moduleTinderd->list_tinderd_queue( $build_id );
154: break;
155: case 'add_tinderd_queue': $atinderdq = $_REQUEST['add_tinderd_queue'];
156: $build_id = $_REQUEST['new_build_id'];
157: $priority = $_REQUEST['new_priority'];
158: $directory = $_REQUEST['new_port_directory'];
159: $emailoc = $_REQUEST['new_email_on_completion'];
160: $moduleTinderd->add_tinderd_queue( $atinderdq, $build_id, $priority, $directory, $emailoc );
161: $build_id = $_REQUEST['filter_build_id'];
162: $display = $moduleTinderd->list_tinderd_queue( $build_id );
163: break;
164: case 'display_add_user': $display = $moduleUsers->display_add_user( '', '', '', '', array() );
165: break;
166: case 'add_user': $user_name = $_REQUEST['user_name'];
167: $user_email = $_REQUEST['user_email'];
168: $user_pwd = $_REQUEST['user_password'];
169: $wwwenabled = $_REQUEST['www_enabled'];
170: $display = $moduleUsers->action_user( 'add', '', $user_name, $user_email, $user_pwd, $wwwenabled );
171: switch( $display ) {
172: case '1': unset( $display ); header( 'Location: index.php' ); break;
173: case '0': $display = $moduleUsers->display_add_user( $user_name, $user_email, $user_pwd, $wwwenabled ); break;
174: }
175: break;
176: case 'display_modify_user': $user_id = $_REQUEST['modify_user_id'];
177: $display = $moduleUsers->display_modify_user( 1, $user_id, '', '', '', '', array() );
178: break;
179: case 'modify_user': $actionuser = $_REQUEST['action_user'];
180: $user_id = $_REQUEST['user_id'];
181: $user_name = $_REQUEST['user_name'];
182: $user_email = $_REQUEST['user_email'];
183: $user_pwd = $_REQUEST['user_password'];
184: $wwwenabled = $_REQUEST['www_enabled'];
185: $display = $moduleUsers->action_user( $actionuser, $user_id, $user_name, $user_email, $user_pwd, $wwwenabled );
186: switch( $display ) {
187: case '1': unset( $display ); header( 'Location: index.php' ); break;
188: case '0': $display = $moduleUsers->display_modify_user( 0, $user_id, $user_name, $user_email, $user_pwd, $www_enabled ); break;
189: }
190: break;
191: case 'display_failure_reasons': $failure_reason_tag = $_REQUEST['failure_reason_tag'];
192: $display = $modulePortFailureReasons->display_failure_reasons( $failure_reason_tag );
193: break;
194: case 'config': $display = $moduleConfig->display_config();
195: break;
196: case 'list_builds':
197: default: $display = $moduleBuilds->display_list_builds();
198: break;
199: }
200:
201: echo $display;
202:
1.1.1.1.2.1 as 203: if (isset($with_timer) && $with_timer)
204: printf('<p style="color:#FF0000;font-size:10px;">elapsed: %03.6f seconds, </p>', microtime(true) - $starttimer);
205:
1.1 as 206: echo '<p style="font-size:10px;"><b>Note:</b> The Tinderbox web interface requires cookies to be enable.</p>';
207: ?>