<?php
require_once __DIR__ '/lib.php';

// Source disclosure (limited)
$allowed = ['index.php''lib.php''upload.php'];
if (isset(
$_GET['src'])) {
    
$src basename($_GET['src']);
    if (
in_array($src$allowedtrue)) {
        
highlight_file(__DIR__ '/' $src);
        exit;
    } else {
        
http_response_code(403);
        echo 
'Not allowed';
        exit;
    }
}

$dataFile __DIR__ '/data.json';
if (!
file_exists($dataFile)) {
    
file_put_contents($dataFilejson_encode(['avatar' => 'uploads/default.jpg']));
}

$data json_decode(@file_get_contents($dataFile), true);
$avatar = isset($data['avatar']) ? $data['avatar'] : 'uploads/default.jpg';

// Allow avatar override from URL parameter
if (isset($_GET['avatar'])) {
    
$candidate $_GET['avatar'];
    
// Allow uploads/ paths and phar:// protocol for intended PHAR deserialization
    
if (preg_match('/uploads\//'$candidate)) {
        
$avatar $candidate;
    }
}

// Get image dimensions for display
$dimensions = @getimagesize($avatar);

?><!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Avatar Display Service</title>
  <style>body{font-family:system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial; margin:2rem;} .card{max-width:820px}</style>
  </head>
<body>
  <div class="card">
    <h1>Avatar Display Service</h1>
    <p>Upload an avatar image and view this page to see its dimensions.</p>
    <ul>
      <li><a href="/upload.php">Upload avatar</a></li>
      <li>View source: <a href="/?src=index.php">index.php</a>, <a href="/?src=upload.php">upload.php</a>, <a href="/?src=lib.php">lib.php</a></li>
    </ul>
    <hr/>
    <p>Current avatar path: <code><?php echo htmlspecialchars($avatarENT_QUOTES'UTF-8'); ?></code></p>
    <p>Dimensions: <code><?php echo $dimensions ? ($dimensions[0] . 'x' $dimensions[1]) : 'Unknown'?></code></p>
  </div>
</body>
</html>