Annotation of FreeBSD/tinderbox/webui/index.php, revision 1.1.1.1.2.3
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.3! as 27: # $Paefchen: FreeBSD/tinderbox/webui/index.php,v 1.1.1.1.2.2 2007/11/15 15:29:46 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:
1.1.1.1.2.3! as 70: foreach (array('WWWROOT', 'TBROOT', 'TEMPLATESDIR') as $dir)
! 71: if (! is_dir(constant($dir)))
! 72: die(sprintf("Error => config: dir %s not found (%s)\n",
! 73: constant($dir), $dir));
! 74:
1.1.1.1.2.2 as 75: set_include_path(get_include_path().PATH_SEPARATOR.'module'
76: .PATH_SEPARATOR.'core');
1.1.1.1.2.1 as 77:
78: function __autoload($class) {
1.1.1.1.2.3! as 79: require_once $class.'.php';
1.1.1.1.2.1 as 80: }
81:
1.1.1.1.2.2 as 82: function module_list() {
83: return preg_split('/[,; ]+/', MODULES);
84: }
85:
86: function module_instance($module) {
87: static $instances;
88: if (! isset($instances))
89: $instances = array();
90: }
91:
92:
93: foreach (module_list() as $moduleName) {
94: $className = 'module' . $moduleName;
95:
96: if (! is_readable('module/'.$className.'.php'))
97: die (sprintf("Error: Module not found (%s)\n",
98: $moduleName));
99:
100: define('MODULE_'.strtoupper($moduleName), $className);
101: /* as xxx */
1.1.1.1.2.1 as 102: $$className = new $className;
103: }
1.1 as 104:
1.1.1.1.2.2 as 105: require_once TEMPLATESDIR.'/messages.inc';
106:
107: if (defined('MODULE_USERS')) {
108: $moduleUsers->start();
1.1 as 109:
1.1.1.1.2.2 as 110: if (isset($_POST['do_login'])) {
111: $moduleUsers->do_login( $_POST['User_Name'], $_POST['User_Password']);
112: }
113: else if(isset($_POST['do_logout'])
114: || ($moduleUsers->is_logged_in() && ! $moduleUsers->get_www_enabled())) {
115: $moduleUsers->do_logout();
116: header('Location: index.php');
117: exit;
118: }
1.1 as 119: }
120:
1.1.1.1.2.2 as 121: /* as xxx */
122: #$display_login = $moduleUsers->display_login();
1.1 as 123:
124: $action = $_REQUEST['action'];
125:
126: switch( $action ) {
127: case 'describe_port': $port_id = $_REQUEST['id'];
128: $display = $modulePorts->display_describe_port( $port_id );
129: break;
130: case 'failed_buildports': $build = $_REQUEST['build'];
131: $maintainer = $_REQUEST['maintainer'];
132: $display = $moduleBuildPorts->display_failed_buildports( $build, $maintainer, null );
133: break;
134: case 'bad_buildports': $build = $_REQUEST['build'];
135: $maintainer = $_REQUEST['maintainer'];
136: $display = $moduleBuildPorts->display_failed_buildports( $build, $maintainer, 'foo' );
137: break;
138: case 'latest_buildports': $build = $_REQUEST['build'];
139: $display = $moduleBuildPorts->display_latest_buildports( $build );
140: break;
141: case 'list_buildports': $build = $_REQUEST['build'];
142: $sort = '';
143: if (isset($_REQUEST['sort'])) {
144: $sort = $_REQUEST['sort'];
145: }
146: $display = $moduleBuildPorts->display_list_buildports( $build, $sort );
147: break;
148: case 'list_tinderd_queue': $build_id = $_REQUEST['filter_build_id'];
149: $display = $moduleTinderd->list_tinderd_queue( $build_id );
150: break;
151: case 'change_tinderd_queue': $ctinderdq = $_REQUEST['change_tinderd_queue'];
152: $entry_id = $_REQUEST['entry_id'];
153: $build_id = $_REQUEST['build_id'];
154: $priority = $_REQUEST['priority'];
155: $emailoc = $_REQUEST['email_on_completion'];
156: $moduleTinderd->change_tinderd_queue( $ctinderdq, $entry_id, $build_id, $priority, $emailoc );
157: $build_id = $_REQUEST['filter_build_id'];
158: $display = $moduleTinderd->list_tinderd_queue( $build_id );
159: break;
160: case 'add_tinderd_queue': $atinderdq = $_REQUEST['add_tinderd_queue'];
161: $build_id = $_REQUEST['new_build_id'];
162: $priority = $_REQUEST['new_priority'];
163: $directory = $_REQUEST['new_port_directory'];
164: $emailoc = $_REQUEST['new_email_on_completion'];
165: $moduleTinderd->add_tinderd_queue( $atinderdq, $build_id, $priority, $directory, $emailoc );
166: $build_id = $_REQUEST['filter_build_id'];
167: $display = $moduleTinderd->list_tinderd_queue( $build_id );
168: break;
169: case 'display_add_user': $display = $moduleUsers->display_add_user( '', '', '', '', array() );
170: break;
171: case 'add_user': $user_name = $_REQUEST['user_name'];
172: $user_email = $_REQUEST['user_email'];
173: $user_pwd = $_REQUEST['user_password'];
174: $wwwenabled = $_REQUEST['www_enabled'];
175: $display = $moduleUsers->action_user( 'add', '', $user_name, $user_email, $user_pwd, $wwwenabled );
176: switch( $display ) {
177: case '1': unset( $display ); header( 'Location: index.php' ); break;
178: case '0': $display = $moduleUsers->display_add_user( $user_name, $user_email, $user_pwd, $wwwenabled ); break;
179: }
180: break;
181: case 'display_modify_user': $user_id = $_REQUEST['modify_user_id'];
182: $display = $moduleUsers->display_modify_user( 1, $user_id, '', '', '', '', array() );
183: break;
184: case 'modify_user': $actionuser = $_REQUEST['action_user'];
185: $user_id = $_REQUEST['user_id'];
186: $user_name = $_REQUEST['user_name'];
187: $user_email = $_REQUEST['user_email'];
188: $user_pwd = $_REQUEST['user_password'];
189: $wwwenabled = $_REQUEST['www_enabled'];
190: $display = $moduleUsers->action_user( $actionuser, $user_id, $user_name, $user_email, $user_pwd, $wwwenabled );
191: switch( $display ) {
192: case '1': unset( $display ); header( 'Location: index.php' ); break;
193: case '0': $display = $moduleUsers->display_modify_user( 0, $user_id, $user_name, $user_email, $user_pwd, $www_enabled ); break;
194: }
195: break;
196: case 'display_failure_reasons': $failure_reason_tag = $_REQUEST['failure_reason_tag'];
197: $display = $modulePortFailureReasons->display_failure_reasons( $failure_reason_tag );
198: break;
199: case 'config': $display = $moduleConfig->display_config();
200: break;
201: case 'list_builds':
202: default: $display = $moduleBuilds->display_list_builds();
203: break;
204: }
205:
206: echo $display;
207:
1.1.1.1.2.1 as 208: if (isset($with_timer) && $with_timer)
209: printf('<p style="color:#FF0000;font-size:10px;">elapsed: %03.6f seconds, </p>', microtime(true) - $starttimer);
210:
1.1 as 211: echo '<p style="font-size:10px;"><b>Note:</b> The Tinderbox web interface requires cookies to be enable.</p>';
212: ?>