1
|
|
|
<?php |
2
|
|
|
// This file is part of BOINC. |
3
|
|
|
// https://boinc.berkeley.edu |
4
|
|
|
// Copyright (C) 2024 University of California |
5
|
|
|
// |
6
|
|
|
// BOINC is free software; you can redistribute it and/or modify it |
7
|
|
|
// under the terms of the GNU Lesser General Public License |
8
|
|
|
// as published by the Free Software Foundation, |
9
|
|
|
// either version 3 of the License, or (at your option) any later version. |
10
|
|
|
// |
11
|
|
|
// BOINC is distributed in the hope that it will be useful, |
12
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
14
|
|
|
// See the GNU Lesser General Public License for more details. |
15
|
|
|
// |
16
|
|
|
// You should have received a copy of the GNU Lesser General Public License |
17
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
// web interface for managing BUDA science apps |
20
|
|
|
// |
21
|
|
|
// in the following, 'app' means BUDA science app |
22
|
|
|
// and 'variant' means a variant of one of these (e.g. CPU, GPU) |
23
|
|
|
|
24
|
|
|
require_once('../inc/util.inc'); |
25
|
|
|
require_once('../inc/sandbox.inc'); |
26
|
|
|
require_once('../inc/keywords.inc'); |
27
|
|
|
require_once('../inc/submit_util.inc'); |
28
|
|
|
require_once('../inc/buda.inc'); |
29
|
|
|
|
30
|
|
|
display_errors(); |
31
|
|
|
|
32
|
|
|
$buda_root = "../../buda_apps"; |
33
|
|
|
|
34
|
|
|
// scan BUDA apps and variants, and write a file 'buda_plan_classes' |
35
|
|
|
// in the project dir with list of plan classes |
36
|
|
|
// |
37
|
|
|
function write_plan_class_file() { |
38
|
|
|
$pcs = []; |
39
|
|
|
global $buda_root; |
40
|
|
|
$apps = get_buda_apps(); |
41
|
|
|
foreach ($apps as $app) { |
42
|
|
|
$vars = get_buda_variants($app); |
43
|
|
|
$pcs = array_merge($pcs, $vars); |
44
|
|
|
} |
45
|
|
|
$pcs = array_unique($pcs); |
46
|
|
|
file_put_contents( |
47
|
|
|
"../../buda_plan_classes", |
48
|
|
|
implode("\n", $pcs)."\n" |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// show list of BUDA apps and variants, |
53
|
|
|
// w/ buttons for adding and deleting |
54
|
|
|
// |
55
|
|
|
function app_list($notice=null) { |
56
|
|
|
global $buda_root; |
57
|
|
|
if (!is_dir($buda_root)) { |
58
|
|
|
mkdir($buda_root); |
59
|
|
|
} |
60
|
|
|
page_head('BOINC Universal Docker App (BUDA)'); |
61
|
|
|
if ($notice) { |
62
|
|
|
echo "$notice <p>\n"; |
63
|
|
|
} |
64
|
|
|
text_start(); |
65
|
|
|
echo " |
66
|
|
|
<p>BUDA lets you submit Docker jobs using a web interface. |
67
|
|
|
<a href=https://github.com/BOINC/boinc/wiki/BUDA-overview>Learn more</a>. |
68
|
|
|
<p> |
69
|
|
|
BUDA science apps: |
70
|
|
|
"; |
71
|
|
|
|
72
|
|
|
$apps = get_buda_apps(); |
73
|
|
|
foreach ($apps as $app) { |
74
|
|
|
show_app($app); |
75
|
|
|
} |
76
|
|
|
echo '<hr>'; |
77
|
|
|
show_button_small('buda.php?action=app_form', 'Add science app'); |
78
|
|
|
text_end(); |
79
|
|
|
page_tail(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function show_app($dir) { |
83
|
|
|
global $buda_root; |
84
|
|
|
$desc = null; |
85
|
|
|
$desc_path = "$buda_root/$dir/desc.json"; |
86
|
|
|
$desc = json_decode(file_get_contents($desc_path)); |
87
|
|
|
echo '<hr>'; |
88
|
|
|
echo sprintf('<font size=+3>%s</font> <a href=buda.php?action=app_details&name=%s>details</a>', |
89
|
|
|
$desc->long_name, |
90
|
|
|
$desc->name |
91
|
|
|
); |
92
|
|
|
$vars = get_buda_variants($dir); |
93
|
|
|
if ($vars) { |
94
|
|
|
start_table('table-striped'); |
95
|
|
|
table_header( |
96
|
|
|
'Variant<br><small>click for details</small>', |
97
|
|
|
'Job submission form' |
98
|
|
|
); |
99
|
|
|
foreach ($vars as $var) { |
100
|
|
|
table_row( |
101
|
|
|
"<a href=buda.php?action=variant_view&app=$dir&variant=$var>$var</href>", |
102
|
|
|
button_text( |
103
|
|
|
"buda_submit.php?app=$dir&variant=$var", "Submit jobs" |
104
|
|
|
) |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
end_table(); |
108
|
|
|
} else { |
109
|
|
|
echo '<p>No variants'; |
110
|
|
|
} |
111
|
|
|
echo "<p>"; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
function file_row($app, $variant, $dir, $f) { |
115
|
|
|
[$md5, $size] = parse_info_file("$dir/.md5/$f"); |
116
|
|
|
table_row( |
117
|
|
|
"<a href=buda.php?action=view_file&app=$app&variant=$variant&fname=$f>$f</a>", |
118
|
|
|
$size, |
119
|
|
|
$md5 |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
function variant_view() { |
124
|
|
|
global $buda_root; |
125
|
|
|
$app = get_str('app'); |
126
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
127
|
|
|
$variant = get_str('variant'); |
128
|
|
|
if (!is_valid_filename($variant)) die('bad arg'); |
|
|
|
|
129
|
|
|
page_head("BUDA: variant '$variant' of science app '$app'"); |
130
|
|
|
$dir = "$buda_root/$app/$variant"; |
131
|
|
|
$desc = json_decode(file_get_contents("$dir/variant.json")); |
132
|
|
|
start_table(); |
133
|
|
|
table_header('Dockerfile', 'size', 'md5'); |
134
|
|
|
file_row($app, $variant, $dir, $desc->dockerfile); |
135
|
|
|
table_header('App files', '', ''); |
136
|
|
|
foreach ($desc->app_files as $f) { |
137
|
|
|
file_row($app, $variant, $dir, $f); |
138
|
|
|
} |
139
|
|
|
table_header('Auto-generated files', '', ''); |
140
|
|
|
file_row($app, $variant, $dir, 'template_in'); |
141
|
|
|
file_row($app, $variant, $dir, 'template_out'); |
142
|
|
|
file_row($app, $variant, $dir, 'variant.json'); |
143
|
|
|
end_table(); |
144
|
|
|
|
145
|
|
|
start_table(); |
146
|
|
|
row2( |
147
|
|
|
'Input filenames:', |
148
|
|
|
implode(',', $desc->input_file_names) |
149
|
|
|
); |
150
|
|
|
row2( |
151
|
|
|
'Output filenames:', |
152
|
|
|
implode(',', $desc->output_file_names) |
153
|
|
|
); |
154
|
|
|
if (!empty($desc->max_total)) { |
155
|
|
|
row2('Max total instances per job:', $desc->max_total); |
156
|
|
|
} else { |
157
|
|
|
row2('Max total instances per job:', '1'); |
158
|
|
|
} |
159
|
|
|
if (!empty($desc->min_nsuccess)) { |
160
|
|
|
row2('Target successful instances per job:', $desc->min_nsuccess); |
161
|
|
|
} else { |
162
|
|
|
row2('Target successful instances per job:', '1'); |
163
|
|
|
} |
164
|
|
|
end_table(); |
165
|
|
|
|
166
|
|
|
echo '<p>'; |
167
|
|
|
show_button( |
168
|
|
|
"buda.php?action=variant_delete&app=$app&variant=$variant", |
169
|
|
|
'Delete variant', |
170
|
|
|
null, |
171
|
|
|
'btn btn-xs btn-warning' |
172
|
|
|
); |
173
|
|
|
page_tail(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
// form for creating app variant. |
177
|
|
|
// Currently doesn't support indirect files. |
178
|
|
|
// doing this would require checkboxes for indirect |
179
|
|
|
// |
180
|
|
|
// Could have other stuff like |
181
|
|
|
// - min_quorum, max_total_results |
182
|
|
|
// - rsc_disk_bound, rsc_memory_bound |
183
|
|
|
// or does this belong in job submission? |
184
|
|
|
// |
185
|
|
|
function variant_form($user) { |
186
|
|
|
$sbitems = sandbox_select_items($user); |
187
|
|
|
$app = get_str('app'); |
188
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
189
|
|
|
|
190
|
|
|
page_head_select2("Create a variant of Docker app $app"); |
191
|
|
|
echo " |
192
|
|
|
Details are <a href=https://github.com/BOINC/boinc/wiki/BUDA-job-submission#adding-a-variant>here</a>. |
193
|
|
|
"; |
194
|
|
|
$sb = '<br><small>From your <a href=sandbox.php>file sandbox</a></small>'; |
195
|
|
|
$pc = '<br><small>Specify |
196
|
|
|
<a href=https://github.com/BOINC/boinc/wiki/AppPlan>GPU and other requirements</a>'; |
197
|
|
|
form_start('buda.php'); |
198
|
|
|
form_input_hidden('app', $app); |
199
|
|
|
form_input_hidden('action', 'variant_action'); |
200
|
|
|
form_input_text("Plan class$pc", 'variant'); |
201
|
|
|
form_select("Dockerfile$sb", 'dockerfile', $sbitems); |
202
|
|
|
form_select2_multi("Application files$sb", 'app_files', $sbitems, null); |
203
|
|
|
form_input_text( |
204
|
|
|
'Input file names<br><small>Space-separated</small>', |
205
|
|
|
'input_file_names' |
206
|
|
|
); |
207
|
|
|
form_input_text( |
208
|
|
|
'Output file names<br><small>Space-separated</small>', |
209
|
|
|
'output_file_names' |
210
|
|
|
); |
211
|
|
|
form_input_text( |
212
|
|
|
'Run at most this many total instances of each job', |
213
|
|
|
'max_total', |
214
|
|
|
'1' |
215
|
|
|
); |
216
|
|
|
form_input_text( |
217
|
|
|
'Get this many successful instances of each job |
218
|
|
|
<br><small>(subject to the above limit)</small> |
219
|
|
|
', |
220
|
|
|
'min_nsuccess', |
221
|
|
|
'1' |
222
|
|
|
); |
223
|
|
|
form_submit('OK'); |
224
|
|
|
form_end(); |
225
|
|
|
page_tail(); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
function buda_file_phys_name($app, $variant, $md5) { |
229
|
|
|
return sprintf('buda_%s_%s_%s', $app, $variant, $md5); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
// copy file from sandbox to variant dir, and stage to download hier |
233
|
|
|
// |
234
|
|
|
function copy_and_stage_file($user, $fname, $dir, $app, $variant) { |
235
|
|
|
copy_sandbox_file($user, $fname, $dir); |
236
|
|
|
[$md5, $size] = parse_info_file("$dir/.md5/$fname"); |
237
|
|
|
$phys_name = buda_file_phys_name($app, $variant, $md5); |
238
|
|
|
stage_file_aux("$dir/$fname", $md5, $size, $phys_name); |
239
|
|
|
return $phys_name; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
// create templates and put them in variant dir |
243
|
|
|
// |
244
|
|
|
function create_templates($variant, $variant_desc, $dir) { |
245
|
|
|
// input template |
246
|
|
|
// |
247
|
|
|
$x = "<input_template>\n"; |
248
|
|
|
$ninfiles = 1 + count($variant_desc->input_file_names) + count($variant_desc->app_files); |
249
|
|
|
for ($i=0; $i<$ninfiles; $i++) { |
250
|
|
|
$x .= " <file_info>\n <sticky/>\n <no_delete/>\n <executable/>\n </file_info>\n"; |
251
|
|
|
} |
252
|
|
|
$x .= " <workunit>\n"; |
253
|
|
|
$x .= file_ref_in($variant_desc->dockerfile); |
254
|
|
|
foreach ($variant_desc->app_files as $fname) { |
255
|
|
|
$x .= file_ref_in($fname); |
256
|
|
|
} |
257
|
|
|
foreach ($variant_desc->input_file_names as $fname) { |
258
|
|
|
$x .= file_ref_in($fname); |
259
|
|
|
} |
260
|
|
|
if ($variant == 'cpu') { |
261
|
|
|
$x .= " <plan_class></plan_class>\n"; |
262
|
|
|
} else { |
263
|
|
|
$x .= " <plan_class>$variant</plan_class>\n"; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
// replication params |
267
|
|
|
// |
268
|
|
|
$x .= sprintf(" <target_nresults>%d</target_nresults>\n", |
269
|
|
|
$variant_desc->min_nsuccess |
270
|
|
|
); |
271
|
|
|
$x .= sprintf(" <min_quorum>%d</min_quorum>\n", |
272
|
|
|
$variant_desc->min_nsuccess |
273
|
|
|
); |
274
|
|
|
$x .= sprintf(" <max_total_results>%d</max_total_results>\n", |
275
|
|
|
$variant_desc->max_total |
276
|
|
|
); |
277
|
|
|
|
278
|
|
|
$x .= " </workunit>\n<input_template>\n"; |
279
|
|
|
file_put_contents("$dir/template_in", $x); |
280
|
|
|
|
281
|
|
|
// output template |
282
|
|
|
// |
283
|
|
|
$x = "<output_template>\n"; |
284
|
|
|
$i = 0; |
285
|
|
|
foreach ($variant_desc->output_file_names as $fname) { |
286
|
|
|
$x .= file_info_out($i++); |
287
|
|
|
} |
288
|
|
|
$x .= " <result>\n"; |
289
|
|
|
$i = 0; |
290
|
|
|
foreach ($variant_desc->output_file_names as $fname) { |
291
|
|
|
$x .= file_ref_out($i++, $fname); |
292
|
|
|
} |
293
|
|
|
$x .= " </result>\n</output_template>\n"; |
294
|
|
|
file_put_contents("$dir/template_out", $x); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
// create variant |
298
|
|
|
// |
299
|
|
|
function variant_action($user) { |
300
|
|
|
global $buda_root; |
301
|
|
|
$variant = get_str('variant'); |
302
|
|
|
if (!$variant) $variant = 'cpu'; |
303
|
|
|
if (!is_valid_filename($variant)) { |
304
|
|
|
error_page(filename_rules()); |
305
|
|
|
} |
306
|
|
|
$app = get_str('app'); |
307
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
308
|
|
|
$dockerfile = get_str('dockerfile'); |
309
|
|
|
if (!is_valid_filename($dockerfile)) { |
310
|
|
|
error_page("Invalid dockerfile name: ".filename_rules()); |
311
|
|
|
} |
312
|
|
|
$app_files = get_array('app_files'); |
313
|
|
|
foreach ($app_files as $fname) { |
314
|
|
|
if (!is_valid_filename($fname)) { |
315
|
|
|
error_page("Invalid app file name: ".filename_rules()); |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
$min_nsuccess = get_int('min_nsuccess'); |
319
|
|
|
if ($min_nsuccess <= 0) { |
320
|
|
|
error_page('Must specify a positive number of successful instances.'); |
321
|
|
|
} |
322
|
|
|
$max_total = get_int('max_total'); |
323
|
|
|
if ($max_total <= 0) { |
324
|
|
|
error_page('Must specify a positive max number of instances.'); |
325
|
|
|
} |
326
|
|
|
if ($min_nsuccess > $max_total) { |
327
|
|
|
error_page('Target # of successful instances must be <= max total'); |
328
|
|
|
} |
329
|
|
|
$input_file_names = get_str('input_file_names', true); |
330
|
|
|
$output_file_names = explode(' ', get_str('output_file_names')); |
331
|
|
|
if ($input_file_names) { |
332
|
|
|
$input_file_names = explode(' ', $input_file_names); |
333
|
|
|
foreach ($input_file_names as $fname) { |
334
|
|
|
if (!is_valid_filename($fname)) { |
335
|
|
|
error_page("Invalid input file name: ".filename_rules()); |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
} else { |
339
|
|
|
$input_file_names = []; |
340
|
|
|
} |
341
|
|
|
foreach ($output_file_names as $fname) { |
342
|
|
|
if (!is_valid_filename($fname)) { |
343
|
|
|
error_page("Invalid output file name: ".filename_rules()); |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
if (file_exists("$buda_root/$app/$variant")) { |
348
|
|
|
error_page("Variant '$variant' already exists."); |
349
|
|
|
} |
350
|
|
|
$dir = "$buda_root/$app/$variant"; |
351
|
|
|
mkdir($dir); |
352
|
|
|
mkdir("$dir/.md5"); |
353
|
|
|
|
354
|
|
|
// collect variant params into a struct |
355
|
|
|
// |
356
|
|
|
$desc = new StdClass; |
357
|
|
|
$desc->dockerfile = $dockerfile; |
358
|
|
|
$desc->app_files = $app_files; |
359
|
|
|
$desc->input_file_names = $input_file_names; |
360
|
|
|
$desc->output_file_names = $output_file_names; |
361
|
|
|
$desc->min_nsuccess = $min_nsuccess; |
362
|
|
|
$desc->max_total = $max_total; |
363
|
|
|
|
364
|
|
|
// copy files from sandbox to variant dir |
365
|
|
|
// |
366
|
|
|
$pname = copy_and_stage_file($user, $dockerfile, $dir, $app, $variant); |
367
|
|
|
$desc->dockerfile_phys = $pname; |
368
|
|
|
$desc->app_files_phys = []; |
369
|
|
|
foreach ($app_files as $fname) { |
370
|
|
|
$pname = copy_and_stage_file($user, $fname, $dir, $app, $variant); |
371
|
|
|
$desc->app_files_phys[] = $pname; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
// write variant params to a JSON file |
375
|
|
|
// |
376
|
|
|
file_put_contents( |
377
|
|
|
"$dir/variant.json", |
378
|
|
|
json_encode($desc, JSON_PRETTY_PRINT) |
379
|
|
|
); |
380
|
|
|
|
381
|
|
|
create_templates($variant, $desc, $dir); |
382
|
|
|
|
383
|
|
|
// Note: we don't currently allow indirect file access. |
384
|
|
|
// If we did, we'd need to create job.toml to mount project dir |
385
|
|
|
|
386
|
|
|
app_list("Variant $variant added for app $app."); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
function variant_delete() { |
390
|
|
|
global $buda_root; |
391
|
|
|
$app = get_str('app'); |
392
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
393
|
|
|
$variant = get_str('variant'); |
394
|
|
|
if (!is_valid_filename($variant)) die('bad arg'); |
|
|
|
|
395
|
|
|
$confirmed = get_str('confirmed', true); |
396
|
|
|
if ($confirmed) { |
397
|
|
|
$dir = "$buda_root/$app/$variant"; |
398
|
|
|
if (!file_exists($dir)) error_page('no such variant'); |
399
|
|
|
// delete staged files |
400
|
|
|
// |
401
|
|
|
foreach (scandir("$dir/.md5") as $fname) { |
402
|
|
|
if ($fname[0] == '.') continue; |
403
|
|
|
[$md5, $size] = parse_info_file("$dir/.md5/$fname"); |
404
|
|
|
$phys_name = buda_file_phys_name($app, $variant, $md5); |
405
|
|
|
$phys_path = download_hier_path($phys_name); |
406
|
|
|
unlink($phys_path); |
407
|
|
|
unlink("$phys_path.md5"); |
408
|
|
|
} |
409
|
|
|
system("rm -r $buda_root/$app/$variant", $ret); |
410
|
|
|
if ($ret) { |
411
|
|
|
error_page("delete failed"); |
412
|
|
|
} |
413
|
|
|
$notice = "Variant $variant of app $app removed."; |
414
|
|
|
app_list($notice); |
415
|
|
|
} else { |
416
|
|
|
page_head("Confirm"); |
417
|
|
|
echo "<p>Are you sure you want to delete variant $variant of BUDA app $app? <p>"; |
418
|
|
|
show_button( |
419
|
|
|
"buda.php?action=variant_delete&app=$app&variant=$variant&confirmed=yes", |
420
|
|
|
"Yes" |
421
|
|
|
); |
422
|
|
|
page_tail(); |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
function app_delete() { |
427
|
|
|
global $buda_root; |
428
|
|
|
$app = get_str('app'); |
429
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
430
|
|
|
$confirmed = get_str('confirmed', true); |
431
|
|
|
if ($confirmed) { |
432
|
|
|
$dir = "$buda_root/$app"; |
433
|
|
|
if (!file_exists($dir)) error_page('no such app'); |
434
|
|
|
$vars = get_buda_variants($app); |
435
|
|
|
if ($vars) { |
436
|
|
|
error_page("You must delete all variants first."); |
437
|
|
|
} |
438
|
|
|
system("rm $buda_root/$app/desc.json", $ret); |
439
|
|
|
system("rmdir $buda_root/$app", $ret); |
440
|
|
|
if ($ret) { |
441
|
|
|
error_page('delete failed'); |
442
|
|
|
} |
443
|
|
|
$notice = "App $app removed."; |
444
|
|
|
app_list($notice); |
445
|
|
|
} else { |
446
|
|
|
page_head('Confirm'); |
447
|
|
|
echo "<p>Are you sure you want to delete BUDA science app $app? <p>"; |
448
|
|
|
show_button( |
449
|
|
|
"buda.php?action=app_delete&app=$app&confirmed=yes", |
450
|
|
|
"Yes" |
451
|
|
|
); |
452
|
|
|
page_tail(); |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
function app_form($desc=null) { |
457
|
|
|
page_head_select2($desc?"Edit Docker app $desc->name":'Create Docker app'); |
458
|
|
|
form_start('buda.php'); |
459
|
|
|
form_input_hidden('action', 'app_action'); |
460
|
|
|
if ($desc) { |
461
|
|
|
form_input_hidden('edit_name', $desc->name); |
462
|
|
|
form_input_hidden('user_id', $desc->user_id); |
463
|
|
|
form_input_hidden('create_time', $desc->create_time); |
464
|
|
|
} else { |
465
|
|
|
form_input_text('Internal name<br><small>No spaces</small>', 'name'); |
466
|
|
|
} |
467
|
|
|
form_input_text('User-visible name', 'long_name', |
468
|
|
|
$desc?$desc->long_name:null |
469
|
|
|
); |
470
|
|
|
form_input_textarea( |
471
|
|
|
'Description<br><small>... of what the app does and of the research goals</small>', |
472
|
|
|
'description', |
473
|
|
|
$desc?$desc->description:null |
474
|
|
|
); |
475
|
|
|
form_select2_multi('Science keywords', |
476
|
|
|
'sci_kw', |
477
|
|
|
keyword_select_options(KW_CATEGORY_SCIENCE), |
478
|
|
|
$desc?$desc->sci_kw:null |
479
|
|
|
); |
480
|
|
|
form_input_text( |
481
|
|
|
'URL of web page describing app', |
482
|
|
|
'url', |
483
|
|
|
$desc?$desc->url:'' |
484
|
|
|
); |
485
|
|
|
// don't include location keywords; |
486
|
|
|
// various people may submit jobs to this app |
487
|
|
|
form_submit('OK'); |
488
|
|
|
form_end(); |
489
|
|
|
page_tail(); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
function app_action($user) { |
493
|
|
|
global $buda_root; |
494
|
|
|
$edit_name = get_str('edit_name', true); |
495
|
|
|
$desc = new StdClass; |
496
|
|
|
if ($edit_name) { |
497
|
|
|
$dir = "$buda_root/$edit_name"; |
498
|
|
|
$name = $edit_name; |
499
|
|
|
$desc->user_id = get_int('user_id'); |
500
|
|
|
$desc->create_time = get_int('create_time'); |
501
|
|
|
} else { |
502
|
|
|
$name = get_str('name'); |
503
|
|
|
if (!is_valid_filename($name)) { |
504
|
|
|
error_page(filename_rules()); |
505
|
|
|
} |
506
|
|
|
$dir = "$buda_root/$name"; |
507
|
|
|
if (file_exists($dir)) { |
508
|
|
|
error_page("App $name already exists."); |
509
|
|
|
} |
510
|
|
|
mkdir($dir); |
511
|
|
|
$desc->user_id = $user->id; |
512
|
|
|
$desc->create_time = time(); |
513
|
|
|
} |
514
|
|
|
$desc->name = $name; |
515
|
|
|
$desc->long_name = get_str('long_name'); |
516
|
|
|
$desc->description = get_str('description'); |
517
|
|
|
$desc->sci_kw = array_map('intval', get_array('sci_kw')); |
518
|
|
|
file_put_contents("$dir/desc.json", json_encode($desc, JSON_PRETTY_PRINT)); |
519
|
|
|
header("Location: buda.php"); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
function view_file() { |
523
|
|
|
global $buda_root; |
524
|
|
|
$app = get_str('app'); |
525
|
|
|
if (!is_valid_filename($app)) die('bad arg'); |
|
|
|
|
526
|
|
|
$variant = get_str('variant'); |
527
|
|
|
if (!is_valid_filename($variant)) die('bad arg'); |
|
|
|
|
528
|
|
|
$fname = get_str('fname'); |
529
|
|
|
if (!is_valid_filename($fname)) die('bad arg'); |
|
|
|
|
530
|
|
|
echo "<pre>\n"; |
531
|
|
|
$x = file_get_contents("$buda_root/$app/$variant/$fname"); |
532
|
|
|
echo htmlspecialchars($x); |
533
|
|
|
echo "</pre>\n"; |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
function handle_app_edit() { |
537
|
|
|
global $buda_root; |
538
|
|
|
$name = get_str('name'); |
539
|
|
|
app_form(get_buda_desc($name)); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
function app_details() { |
543
|
|
|
global $buda_root; |
544
|
|
|
$name = get_str('name'); |
545
|
|
|
$desc = get_buda_desc($name); |
546
|
|
|
if (!$desc) error_page("no desc file $path"); |
547
|
|
|
page_head("BUDA app: $desc->long_name"); |
548
|
|
|
start_table(); |
549
|
|
|
row2('Internal name', $desc->name); |
550
|
|
|
$user = BoincUser::lookup_id($desc->user_id); |
551
|
|
|
row2('Creator', |
552
|
|
|
sprintf('<a href=show_user.php?userid=%d>%s</a>', |
553
|
|
|
$user->id, |
554
|
|
|
$user->name |
555
|
|
|
) |
556
|
|
|
); |
557
|
|
|
row2('Created', date_str($desc->create_time)); |
558
|
|
|
row2('Description', $desc->description); |
559
|
|
|
row2('Science keywords', kw_array_to_str($desc->sci_kw)); |
560
|
|
|
row2('', |
561
|
|
|
button_text_small( |
562
|
|
|
sprintf('buda.php?action=%s&name=%s', 'app_edit', $desc->name), |
563
|
|
|
'Edit app info' |
564
|
|
|
) |
565
|
|
|
); |
566
|
|
|
$vars = get_buda_variants($name); |
567
|
|
|
if ($vars) { |
568
|
|
|
$x = []; |
569
|
|
|
foreach ($vars as $var) { |
570
|
|
|
$x[] = sprintf('<a href=buda.php?var_details?var=%s>%s</a>', |
571
|
|
|
$var, $var |
572
|
|
|
); |
573
|
|
|
} |
574
|
|
|
$x[] = button_text_small( |
575
|
|
|
"buda.php?action=variant_form&app=$name", |
576
|
|
|
'Add variant' |
577
|
|
|
); |
578
|
|
|
row2('Variants', implode('<p>', $x)); |
579
|
|
|
} else { |
580
|
|
|
row2('Variants', |
581
|
|
|
button_text_small( |
582
|
|
|
"buda.php?action=variant_form&app=$name", |
583
|
|
|
'Add variant' |
584
|
|
|
) |
585
|
|
|
); |
586
|
|
|
row2('', |
587
|
|
|
button_text( |
588
|
|
|
"buda.php?action=app_delete&app=$name", |
589
|
|
|
"Delete app", |
590
|
|
|
null, |
591
|
|
|
'btn btn-xs btn-warning' |
592
|
|
|
) |
593
|
|
|
); |
594
|
|
|
} |
595
|
|
|
end_table(); |
596
|
|
|
page_tail(); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
// check access. |
600
|
|
|
// Anyone with submit access to BUDA can add/delete apps and variants. |
601
|
|
|
// Might want to refine this at some point |
602
|
|
|
|
603
|
|
|
$user = get_logged_in_user(); |
|
|
|
|
604
|
|
|
$buda_app = BoincApp::lookup("name='buda'"); |
605
|
|
|
if (!$buda_app) error_page('no buda app'); |
606
|
|
|
if (!has_submit_access($user, $buda_app->id)) { |
607
|
|
|
error_page('no access'); |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
$action = get_str('action', true); |
611
|
|
|
switch ($action) { |
612
|
|
|
case 'app_edit': |
613
|
|
|
handle_app_edit(); break; |
614
|
|
|
case 'app_form': |
615
|
|
|
app_form(); break; |
616
|
|
|
case 'app_action': |
617
|
|
|
app_action($user); break; |
618
|
|
|
case 'app_details': |
619
|
|
|
app_details(); break; |
620
|
|
|
case 'app_delete': |
621
|
|
|
app_delete(); break; |
622
|
|
|
case 'variant_view': |
623
|
|
|
variant_view($user); break; |
|
|
|
|
624
|
|
|
case 'variant_form': |
625
|
|
|
variant_form($user); break; |
626
|
|
|
case 'variant_action': |
627
|
|
|
variant_action($user); |
628
|
|
|
write_plan_class_file(); |
629
|
|
|
break; |
630
|
|
|
case 'variant_delete': |
631
|
|
|
variant_delete(); |
632
|
|
|
write_plan_class_file(); |
633
|
|
|
break; |
634
|
|
|
case 'view_file': |
635
|
|
|
view_file(); break; |
636
|
|
|
case null: |
637
|
|
|
app_list(); break; |
638
|
|
|
default: |
|
|
|
|
639
|
|
|
error_page("unknown action"); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
?> |
643
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.