196 lines
No EOL
5.9 KiB
PHP
196 lines
No EOL
5.9 KiB
PHP
<?php
|
|
$acceptParam['log'] = array(
|
|
'suspect',
|
|
'success',
|
|
'other',
|
|
'retry'
|
|
);
|
|
|
|
if (isset($ui['pwd'])) {
|
|
checkAdmin($ui['pwd']);
|
|
}
|
|
|
|
if (isset($ui['log']) && !in_array($ui['log'], $acceptParam['log']) || $_SESSION['login'] !== true) {
|
|
die('Tell me, Mr Anderson, what good is a phone call if you\'re unable to speak ?');
|
|
}
|
|
|
|
if (empty($ui['log'])) {
|
|
$ui['log'] = 'success';
|
|
}
|
|
|
|
function clearLog($log) {
|
|
if (file_exists('cache/logs/'.$log.'.txt') && is_file('cache/logs/'.$log.'.txt')) {
|
|
file_put_contents('cache/logs/'.$log.'.txt', '');
|
|
}
|
|
}
|
|
|
|
function parseSuccessLog() {
|
|
if (file_exists('cache/logs/success.txt')) {
|
|
$file = fopen('cache/logs/success.txt', "r");
|
|
$res = '';
|
|
if (!empty($file)) {
|
|
while (!feof($file)) {
|
|
$currentLine = trim(fgets($file));
|
|
$currentLine = explode(' ', $currentLine);
|
|
$currentLine = str_replace('s', '', $currentLine);
|
|
if (!empty($currentLine[5])) {
|
|
$res['genTime'][] = $currentLine[5];
|
|
}
|
|
}
|
|
} else {
|
|
$res['genTime'] = array();
|
|
}
|
|
fclose($file);
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
function parseFailLog($log) {
|
|
if (empty($log) || ($log !== 'suspect' && $log !== 'retry' && $log !== 'other')) {
|
|
die('Are you sure about this.');
|
|
}
|
|
$res = '';
|
|
$list = glob('cache/logs/'.$log.'/*.log');
|
|
if (!empty($list)) {
|
|
foreach ($list as $value) {
|
|
$line = file_get_contents($value);
|
|
$line = trim($line);
|
|
$line = explode(' --- ', $line);
|
|
if (!empty($line[7])) {
|
|
$res[] = array(
|
|
$line[1],
|
|
$line[2],
|
|
$line[4],
|
|
'Error '.$line[7].' - '
|
|
);
|
|
} else {
|
|
$res[] = array(
|
|
$line[1],
|
|
$line[2],
|
|
$line[4],
|
|
''
|
|
);
|
|
}
|
|
}
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
function manualGen($hash, $log) {
|
|
$line = file_get_contents('cache/logs/'.$log.'/'.$hash.'.log');
|
|
$line = trim($line);
|
|
$line = explode(' --- ', $line);
|
|
$hash = sha1($GLOBALS['config']['salt'].rawurldecode($line[1]));
|
|
file_put_contents('cache/tmp/manual.txt', $line[1]);
|
|
exec('bin/thumb_server.sh manual '.escapeshellarg($hash).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' 0 1', $result);
|
|
if ((int)$result[0] === 1) {
|
|
$res['success'] = 1;
|
|
$res['filePath'] = pathForFile($line[4], $hash).'.png';
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
function delAndRegen($hash, $size) {
|
|
$path = pathForFile($size, $hash);
|
|
if (file_exists($path.'.png')) {
|
|
unlink($path.'.png');
|
|
}
|
|
if (file_exists($path.'_thumb.png')) {
|
|
unlink($path.'_thumb.png');
|
|
}
|
|
}
|
|
|
|
function tryRootDomain($hash, $log) {
|
|
$line = file_get_contents('cache/logs/'.$log.'/'.$hash.'.log');
|
|
$line = trim($line);
|
|
$line = explode(' --- ', $line);
|
|
$hash = sha1($GLOBALS['config']['salt'].rawurldecode($line[1]));
|
|
$parts = parse_url($line[1]);
|
|
$url = $parts['scheme'].'://'.trim($parts['host']);
|
|
file_put_contents('cache/tmp/manual.txt', $url);
|
|
exec('bin/thumb_server.sh manual '.escapeshellarg($hash).' '.escapeshellarg($line[3]).' '.escapeshellarg($line[4]).' 0 1', $result);
|
|
if ((int)$result[0] === 1) {
|
|
$res['success'] = 1;
|
|
$res['filePath'] = pathForFile($line[4], $hash).'.png';
|
|
return $res;
|
|
}
|
|
}
|
|
|
|
function keepThisThumb($hash, $log) {
|
|
unlink('cache/logs/'.$log.'/'.$hash.'.log');
|
|
}
|
|
|
|
if (isset($ui['clear']) && (int)$ui['clear'] === 1) {
|
|
clearLog($ui['log']);
|
|
}
|
|
?>
|
|
<div class="hMenu">
|
|
<ul>
|
|
<li>
|
|
<a href="?p=admin&log=success">Success</a>
|
|
</li>
|
|
<li>
|
|
<a href="?p=admin&log=suspect">Suspect</a>
|
|
</li>
|
|
<li>
|
|
<a href="?p=admin&log=retry">Retry</a>
|
|
</li>
|
|
<li>
|
|
<a href="?p=admin&log=other">Other error</a>
|
|
</li>
|
|
<li>
|
|
<a href="?logout=1">Logout</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div id="log">
|
|
<?php
|
|
if ($ui['log'] === 'success') {
|
|
$logs = parseSuccessLog();
|
|
if (!empty($logs)) {
|
|
$nbThumb = 0;
|
|
$nbThumb = count($logs['genTime']);
|
|
echo 'Total request : ', $nbThumb, '</br>';
|
|
echo 'Moyenne per request : ', round(array_sum($logs['genTime']) / $nbThumb, 2), 's (min (', min($logs['genTime']), 's) max (', max($logs['genTime']), 's))</br>';
|
|
} else {
|
|
echo 'No result';
|
|
}
|
|
echo '<p class="clear" ><a href="?p=admin&log=success&clear=1">Clear success log</a></p>';
|
|
}
|
|
if ($ui['log'] === 'suspect' || $ui['log'] === 'retry' || $ui['log'] === 'other') {
|
|
if (isset($ui['hash']) && !empty($ui['hash'])) {
|
|
$ui['hash'] = validHash($ui['hash']);
|
|
if (isset($ui['root']) && (int)$ui['root'] === 1) {
|
|
$success = tryRootDomain($ui['hash'], $ui['log']);
|
|
}
|
|
if (isset($ui['cache']) && (int)$ui['cache'] === 1) {
|
|
$success['filePath'] = pathForFile($ui['s'], $ui['hash']).'.png';
|
|
}
|
|
if (isset($ui['keep']) && (int)$ui['keep'] === 1) {
|
|
keepThisThumb($ui['hash'], $ui['log']);
|
|
}
|
|
if (isset($ui['mGen']) && (int)$ui['mGen'] === 1)
|
|
$success = manualGen($ui['hash'], $ui['log']);
|
|
}
|
|
$logs = parseFailLog($ui['log']);
|
|
if (!empty($logs)) {
|
|
echo '<ul>';
|
|
foreach ($logs as $value) {
|
|
echo '<li>', htmlentities(strip_tags($value['3'])), htmlentities(strip_tags($value['0'])), '</br><a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&mGen=1">manuel launch</a> <a href="', htmlentities(strip_tags($value['0'])), '">view site</a> <a href="?p=admin&log=', $ui['log'], '&hash=', $value['1'], '&cache=1&s=', $value['2'], '">view image in cache</a></li>';
|
|
}
|
|
echo '</ul>';
|
|
} else {
|
|
echo 'No result';
|
|
}
|
|
}
|
|
echo '</div>';
|
|
|
|
if (!empty($success)) {
|
|
echo '<div id="result">';
|
|
echo '<img src="', $success['filePath'], '?r=', time(), '" style="width:100%;"/>';
|
|
echo '<p><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $success['filePath'], '" onclick="this.select()"/></p>';
|
|
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&root=1">Try with root domain</a> / ';
|
|
echo '<a href="?p=admin&log=', $ui['log'], '&hash=', $ui['hash'], '&keep=1">Keep this thumbshot</a>';
|
|
echo '</div>';
|
|
}
|
|
?>
|