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
|
<?php
/**
* Mageia build-system quick status report script.
* List log files related to $_GET['k'] build path.
*
* @copyright Copyright (C) 2012 Mageia.Org
*
* @author Romain d'Alverny
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License aspublished by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
$key = isset($_GET['k']) ? trim(strip_tags(html_entity_decode($_GET['k']))) : null;
if (is_null($key)) {
die('.');
}
require 'conf.php';
// FIXME this expects to remove /uploads from $key. Could be different in the future.
$key = substr($key, 8);
$path = realpath($upload_dir . $key);
$job = explode('/', $key);
$job = end($job);
if (false !== strpos($key, 'rejected')) {
$valid = file_exists($path);
$type = 'rejected';
$job = str_replace('.youri', '', $job);
$path = str_replace('.youri', '', $path);
} else {
$valid = is_dir($path);
$type = 'regular';
}
if (!$valid) {
header('Status: 404 Not Found');
header('HTTP/1.0 404 Not Found');
die('Sorry, not found');
}
$list = array();
if ($type == 'rejected') {
$list = glob($path . '*');
} else {
$list = glob_recursive_tree($path . '/*');
$others = array(
'.youri',
'_i586.done',
'_x86_64.done'
'_armv7hl.done'
'_aarch64.done'
);
foreach ($others as $suffix) {
$f = $path . $suffix;
if (file_exists($f)) {
$list[] = $f;
}
}
}
echo sprintf('<h4>%s</h4>', $job),
print_list($list);
// lib code below.
/**
* Format size in human-readable format.
*
* @param integer $a_bytes size in bytes
*
* @return string
*
* @author yatsynych
* @link http://www.php.net/manual/fr/function.filesize.php#106935
*/
function _format_bytes($a_bytes)
{
if ($a_bytes < 1024) {
return $a_bytes .' B';
} elseif ($a_bytes < 1048576) {
return round($a_bytes / 1024, 2) .' KiB';
} elseif ($a_bytes < 1073741824) {
return round($a_bytes / 1048576, 2) . ' MiB';
} elseif ($a_bytes < 1099511627776) {
return round($a_bytes / 1073741824, 2) . ' GiB';
} elseif ($a_bytes < 1125899906842624) {
return round($a_bytes / 1099511627776, 2) .' TiB';
} elseif ($a_bytes < 1152921504606846976) {
return round($a_bytes / 1125899906842624, 2) .' PiB';
} elseif ($a_bytes < 1180591620717411303424) {
return round($a_bytes / 1152921504606846976, 2) .' EiB';
} elseif ($a_bytes < 1208925819614629174706176) {
return round($a_bytes / 1180591620717411303424, 2) .' ZiB';
} else {
return round($a_bytes / 1208925819614629174706176, 2) .' YiB';
}
}
/**
* @param string $pattern
* @param integer $flags
*
* @return array
*
* @author Mike
* @link http://www.php.net/manual/fr/function.glob.php#106595
*
* Does not support flag GLOB_BRACE
*
*/
function glob_recursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
function glob_recursive_tree($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$dirtop = explode('/', $dir);
$files[end($dirtop)] = glob_recursive_tree($dir . '/' . basename($pattern), $flags);
}
return $files;
}
function print_list($list)
{
global $upload_dir, $path;
$l = array();
foreach ($list as $f) {
if (!is_string($f)) {
continue;
}
if (is_dir($f)) {
$top = basename($f);
$l[] = sprintf('<li><span class="dir">%s</span>%s</li>', $top, print_list($list[$top]));
} elseif (file_exists($f)) {
$l[] = sprintf('<li><a href="%s" rel="nofollow" class="view-inline">%s</a> <span class="filesize">(%s)</span></li>',
'uploads' . str_replace($upload_dir, '', $f),
basename($f),
_format_bytes(filesize($f))
);
}
}
return sprintf('<ul>%s</ul>', implode($l));
}
|