LuminaWebsite/armory_icon.php

47 lines
1.5 KiB
PHP

<?php
/**
* Icons aus Aion 2 (Gegenstaende, Daevanion-Boards, Begleiter) fuer die Live-Daten der Profilseiten:
* ?f=<Dateiname>. Laedt das Icon beim ersten Mal von NCSoft (nur ARMORY_ICON_BASE), legt es unter
* assets/uploads/armory/ ab und liefert es aus - danach verweist die Seite direkt auf die Datei.
* So sieht NCSoft nie die Besucher der Website.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/armory.php';
if (!current_user() || !user_has_permission('members.view')) {
http_response_code(403);
exit;
}
$file = (string) ($_GET['f'] ?? '');
if (!preg_match('/^[A-Za-z0-9_\-]{1,100}\.png$/', $file)) {
http_response_code(404);
exit;
}
session_write_close();
$path = ARMORY_ICON_DIR . $file;
if (!is_file($path)) {
try {
$bytes = armory_download(ARMORY_ICON_BASE . $file, 512 * 1024);
} catch (RuntimeException $e) {
http_response_code(404);
exit;
}
if (armory_image_ext($bytes) !== 'png') {
http_response_code(404);
exit;
}
// Erst unter anderem Namen schreiben, damit niemand eine halbe Datei bekommt
$tmp = $path . '.' . bin2hex(random_bytes(4)) . '.tmp';
if (@file_put_contents($tmp, $bytes) === false || !@rename($tmp, $path)) {
@unlink($tmp);
header('Content-Type: image/png');
header('Cache-Control: private, max-age=3600');
echo $bytes;
exit;
}
}
header('Content-Type: image/png');
header('Cache-Control: private, max-age=604800');
header('X-Content-Type-Options: nosniff');
readfile($path);