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
|
<?php
function init_logview() {
global $S, $request;
$S['title']='Log Viewer';
if (!isset($S['user'])) return 'login';
if (isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build'])) {
$r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"');
if ($r->rowCount()) {
$S['logview']['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC));
if (!owner_or_admin($S['logview']['build']->owner)) return '404'; // TODO permission denied
} else
return '404';
if (isset($request['task']) && is_numeric($request['task'])) {
$r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$request['build'].'" AND `order`='.$request['task']);
if ($r->rowCount()) {
$S['logview']['task']=new sql_task($r->fetch(PDO::FETCH_ASSOC));
} // else return '404'; // Just goes to the build if task is missing
}
}
}
function body_logview() {
global $S, $request, $conf;
if (isset($S['logview']['task'])) {
$task=&$S['logview']['task'];
echo '<div style="font-size: 130%">'.$task->display().'</div>';
echo '<a href="'.url('logs/'.$task->build).'">Back</a><br/>';
$page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1;
$count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN);
$pager='';
if ($count > $conf['logview_max']) {
$pager='<form action="'.url('logs/'.$task->build.'/'.$task->order).'" method="post" onsubmit="window.location.href=\''.url('logs/'.$task->build.'/'.$task->order).'/\'+this.page.value; return false">Page: ';
if ($page > 1) {
$pager.='<input type="button" value="<<" onclick="this.form.page.value='.($page-1).'; this.form.onsubmit()" /> '."\n";
}
$pager.='<select name="page">';
for ($i=1; ($i-1)*$conf['logview_max']<$count; $i++) {
$pager.="<option value=\"$i\"".($i==$page?'selected="selected"':'').">$i</option>\n";
}
$pager.='</select> <input type="submit" value="Go" />';
if ($page*$conf['logview_max']<$count) {
$pager.=' <input type="button" value=">>" onclick="this.form.page.value='.($page+1).'; this.form.onsubmit()" />'."\n";
}
$pager.='</form>';
echo $pager;
}
$r=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']);
if ($r->rowCount()) {
echo '<div style="font-family: monospace">';
$ansi=new ansi_to_html();
while ($entry=$r->fetch(PDO::FETCH_ASSOC)) {
$entry=new sql_buildlog_entry($entry);
// $text=str_replace(array("\n", "\t"), array("<br/>\n", str_repeat(' ', 4)), htmlentities($entry->text));
// echo '<a name="entry_'.$task->order.'_'.$entry->order.'"'.($entry->stream=='stderr'?' style="color: red" ':'').' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' @ '.date('D j M Y @ H:i:s', $entry->timestamp).' UTC">'.$text.'</a>';
echo $ansi->process($entry->text);
// TODO handle tabs properly, move all this into ansi_to_html
}
echo $ansi->reset(); // Clear any leftover <span>s
echo '</div>';
echo $pager;
echo '<a href="'.url('logs/'.$task->build).'">Back</a><br/>';
} else {
if ($count) {
echo print_error("There aren't $page pages. Try an <a href=\"".url('logs/'.$task->build.'/'.$task->order)."\">earlier page</a>.");
} else {
echo print_warning('No output');
}
}
} elseif (isset($S['logview']['build'])) {
$build=&$S['logview']['build'];
echo $build->display();
$r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$request['build'].'" ORDER BY `order` ASC');
if ($r->rowCount() == 0) {
echo '<b>No tasks found.</b>';
}
while ($task=$r->fetch(PDO::FETCH_ASSOC)) {
$task=new sql_task($task);
echo $task->display();
}
} else {
$r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC');
if ($r->rowCount() == 0) {
echo print_warning('No builds found.');
}
while ($build=$r->fetch(PDO::FETCH_ASSOC)) {
$build=new sql_build($build);
echo $build->display();
}
}
}
?>
|