1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
|
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/bossa_db.inc");
require_once("../inc/bolt_db.inc");
require_once("../inc/util_ops.inc");
function job_state_string($s) {
switch ($s) {
case 0: return "Embargoed";
case 1: return "In progress";
case 2: return "Completed";
}
}
function include_app_file($app_id) {
$app = BossaApp::lookup_id($app_id);
$file = "../inc/$app->short_name.inc";
require_once($file);
}
function show_bossa_app($app, $i) {
$j = $i%2;
echo "<tr class=row$j>
<td>Name: $app->name<br>
Short name: $app->short_name<br>
Description: $app->description<br>
Created: ".date_str($app->create_time)."
</td>
<td>
";
if ($app->hidden) {
show_button("bossa_admin.php?action=unhide&app_id=$app->id", "Unhide", "Unhide this app");
} else {
show_button("bossa_admin.php?action=hide&app_id=$app->id", "Hide", "Hide this app");
}
echo "<br>";
show_button("bossa_admin.php?action=show_batches&app_id=$app->id", "Show batches", "Show batches");
}
function show_bossa_apps() {
$apps = BossaApp::enum();
start_table();
row1("Existing apps", 2);
table_header("Name/description", "");
$i = 0;
foreach ($apps as $app) {
show_bossa_app($app, $i++);
}
end_table();
}
function add_app_form() {
echo "
<form action=bossa_admin.php method=get>
<input type=hidden name=action value=add_app>
";
start_table();
row1("Add app");
row2(
"Name<br><p class=\"text-muted\">Visible to users</p>",
"<input name=app_name>"
);
row2(
"Short name<br><p class=\"text-muted\">Used in file and function names - no spaces or special characters</p>",
"<input name=short_name>"
);
row2(
"Description<br><p class=\"text-muted\">Visible to users</p>",
"<textarea name=description cols=60></textarea>"
);
row2("Average time per job", "<input name=time_estimate> seconds");
row2("Time limit per job", "<input name=time_limit> seconds");
row2("Fraction of calibration jobs", "<input name=calibration_frac>");
row2("Name of Bolt training course", "<input name=training_course>");
row2("", "<input class=\"btn btn-default\" type=submit submit value=\"Create app\">");
end_table();
echo "</form>";
}
function user_settings() {
global $user;
$flags = $user->bossa->flags;
echo "<form action=bossa_admin.php method=get>
<input type=hidden name=action value=update_user>
";
start_table();
row1("User settings");
$x = ($flags&BOLT_FLAGS_SHOW_ALL)?"checked":"";
row2("Show hidden apps?", "<input type=checkbox name=show_all $x>");
$x = ($flags&BOLT_FLAGS_DEBUG)?"checked":"";
row2("Show debugging output?", "<input type=checkbox name=debug $x>");
row2("", "<input class=\"btn btn-default\" type=submit value=\"Update user\">");
end_table();
echo "</form>";
}
function show_all() {
admin_page_head("Bossa administration");
show_bossa_apps();
echo "<p>";
add_app_form();
echo "<p>";
user_settings();
admin_page_tail();
}
function job_duration($inst) {
if ($inst->finish_time) {
$d = $inst->finish_time - $inst->create_time;
$d /= 60;
$d = number_format($d, 2);
$d = "$d min.";
} else {
$d = "---";
}
return $d;
}
function job_show_instances($job) {
$insts = BossaJobInst::enum("job_id=$job->id");
if (!count($insts)) {
echo "---";
return;
}
start_table();
table_header("User", "Start", "Duration", "Result");
foreach ($insts as $inst) {
$user = BoincUser::lookup_id($inst->user_id);
$t = time_str($inst->create_time);
$d = job_duration($inst);
echo "<tr>
<td><a href=bossa_admin.php?action=show_user&app_id=$job->app_id&user_id=$user->id>$user->name</a></td>
<td>$t</td>
<td>$d</td>
<td>
";
echo instance_summary($inst->get_opaque_data());
echo "
</td>
</tr>
";
}
end_table();
}
function show_batch($batch_id) {
$batch = BossaBatch::lookup_id($batch_id);
if (!$batch) error_page("No such batch");
include_app_file($batch->app_id);
admin_page_head("Jobs for batch $batch->name");
$jobs = BossaJob::enum("batch_id=$batch_id");
start_table();
table_header("ID", "Created", "State", "Instances");
$i = 0;
foreach ($jobs as $job) {
$t = time_str($job->create_time);
$s = job_state_string($job->state);
$j = $i++ % 2;
echo "<tr class=row$j>
<td>
$job->id <a href=bossa_admin.php?action=job_show_insts&job_id=$job->id>(details)</a><br>
";
echo job_summary($job);
echo "
</td>
<td>$t</td>
<td>$s</td>
<td>
";
job_show_instances($job);
echo "
</td>
</tr>
";
}
end_table();
admin_page_tail();
}
function show_batches($app_id) {
$batches = BossaBatch::enum("app_id = $app_id");
$app = BossaApp::lookup_id($app_id);
admin_page_head("Batches ($app->name)");
start_table();
table_header("ID", "Name", "Calibration?", "Created", "Jobs", "Completed");
foreach ($batches as $batch) {
table_row(
"$batch->id | <a href=bossa_admin.php?action=show_batch&batch_id=$batch->id>show jobs</a> | <a href=bossa_admin.php?action=clear_batch_confirm&batch_id=$batch->id>delete instances</a>",
"$batch->name",
$batch->calibration?"yes":"no",
time_str($batch->create_time),
BossaJob::count("batch_id=$batch->id"),
BossaJob::count("batch_id=$batch->id and state=2")
);
}
end_table();
admin_page_tail();
}
function job_show_insts($job_id) {
$job = BossaJob::lookup_id($job_id);
include_app_file($job->app_id);
admin_page_head("Instances of job $job_id");
job_show_instances($job);
admin_page_tail();
}
function calibration_job_string($inst, $job) {
if ($inst->calibration) {
$i = $job->get_opaque_data();
return "yes: ".instance_summary($i->answer);
} else {
return "no";
}
}
function show_bossa_user() {
$user_id = get_int('user_id');
$app_id = get_int('app_id');
$user = BoincUser::lookup_id("$user_id");
BossaUser::lookup($user);
$app = BossaApp::lookup_id($app_id);
include_app_file($app_id);
admin_page_head("$user->name ($app->name)");
$x = user_summary($user);
if ($x) {
echo "User info: $x<br>";
}
$insts = BossaJobInst::enum("user_id=$user_id");
start_table();
table_header("Job", "Calibration?", "Start", "Duration", "Response");
foreach ($insts as $inst) {
$job = BossaJob::lookup_id($inst->job_id);
table_row(
"$inst->job_id <a href=bossa_admin.php?action=job_show_insts&job_id=$inst->job_id>(details)</a><br>".job_summary($job),
calibration_job_string($inst, $job),
time_str($inst->create_time),
job_duration($inst),
instance_summary($inst->get_opaque_data())
);
}
end_table();
admin_page_tail();
}
function clear_batch_confirm($batch_id) {
admin_page_head("Confirm delete instances");
echo "
This will permanently delete all results from this batch.
<p>
Are you sure you want to do this?
<p>
<a href=bossa_admin.php?action=clear_batch&batch_id=$batch_id>Yes</a>
";
admin_page_tail();
}
function clear_batch($batch_id) {
admin_page_head("Deleting instances");
if (BossaJobInst::delete_aux("batch_id=$batch_id")) {
echo "Job instances deleted.";
$jobs = BossaJob::enum("batch_id=$batch_id");
foreach ($jobs as $job) {
$job->update("priority_0=1");
}
} else {
echo "Database error.";
}
$jobs = BossaJob::enum("batch_id=$batch_id");
foreach ($jobs as $job) {
$job->update("state=1");
}
admin_page_tail();
}
$user = get_logged_in_user();
$db = BossaDb::get();
if (!$db) error_page("Can't connect to database server");
if (!$db->table_exists('bossa_app')) {
admin_page_head("Create Bossa database");
$db_name = $db->db_name;
echo "
The database tables for Bossa don't seem to exist.
To create them, go to ~/boinc/db and type
<pre>
mysql $db_name < bossa_schema.sql
mysql $db_name < bossa_constraints.sql
</pre>
Then <a href=bossa_admin.php>reload this page</a>.
";
admin_page_tail();
exit;
}
BossaUser::lookup($user);
$action = get_str('action', true);
switch ($action) {
case 'add_app':
$name = BossaDb::escape_string(get_str('app_name'));
$short_name = get_str('short_name');
$description = BossaDb::escape_string(get_str('description'));
$training_course = get_str('training_course', true);
if (strlen($training_course)) {
$course = BoltCourse::lookup_name($training_course);
if (!$course) {
error_page("No course named $training_course");
}
$courseid = $course->id;
} else {
$courseid = 0;
}
$time_estimate = get_str('time_estimate');
if (!$time_estimate) $time_estimate = 60;
$time_limit = get_str('time_limit');
if (!$time_limit) $time_limit = 3600;
$calibration_frac = get_str('calibration_frac' , true);
if (!$calibration_frac) $calibration_frac = 0;
$now = time();
$app_id = BossaApp::insert("(create_time, name, short_name, description, bolt_course_id, time_estimate, time_limit, calibration_frac) values ($now, '$name', '$short_name', '$description', $courseid, $time_estimate, $time_limit, $calibration_frac)");
if ($courseid) {
$course->update("bossa_app_id=$app_id");
}
Header('Location: bossa_admin.php');
exit;
case 'update_user':
$flags = 0;
if (get_str('show_all', true)) $flags |= BOLT_FLAGS_SHOW_ALL;
if (get_str('debug', true)) $flags |= BOLT_FLAGS_DEBUG;
$user->bossa->update("flags=$flags");
$user->bossa->flags = $flags;
Header('Location: bossa_admin.php');
exit;
case 'show_user':
show_bossa_user();
exit;
case 'show_batches':
$app_id = get_int('app_id');
show_batches($app_id);
exit;
case 'show_batch':
$batch_id = get_int('batch_id');
show_batch($batch_id);
exit;
case 'job_show_insts':
$job_id = get_int('job_id');
job_show_insts($job_id);
exit;
case 'hide':
$app_id = get_int('app_id');
$app = BossaApp::lookup_id($app_id);
if (!$app) error_page("no such app");
$app->update("hidden=1");
break;
case 'unhide':
$app_id = get_int('app_id');
$app = BossaApp::lookup_id($app_id);
if (!$app) error_page("no such app");
$app->update("hidden=0");
break;
case 'clear_batch_confirm':
$batch_id = get_int('batch_id');
clear_batch_confirm($batch_id);
exit;
case 'clear_batch':
$batch_id = get_int('batch_id');
clear_batch($batch_id);
exit;
case '':
show_all();
exit;
default:
error_page("unknown action $action");
}
Header('Location: bossa_admin.php');
?>
|