Upload via GUI (32 Dateien)
This commit is contained in:
@@ -1,35 +1,59 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/lib.php';
|
||||
|
||||
function site_headers(): void
|
||||
{
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('X-Frame-Options: DENY');
|
||||
header('Referrer-Policy: same-origin');
|
||||
header("Content-Security-Policy: default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'");
|
||||
}
|
||||
|
||||
function site_header(string $title, string $active = ''): void
|
||||
{
|
||||
site_headers();
|
||||
$name = site_config()['site_name'];
|
||||
?><!doctype html>
|
||||
<html lang="de"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?= site_h($title) ?> · <?= site_h($name) ?></title><link rel="stylesheet" href="assets/style.css"></head>
|
||||
<body>
|
||||
<header class="top"><div class="wrap">
|
||||
<a class="brand" href="index.php"><?= site_h($name) ?></a>
|
||||
<nav><a href="admin.php" class="on">Verwaltung</a></nav>
|
||||
</div></header>
|
||||
<main class="wrap">
|
||||
<?php
|
||||
}
|
||||
|
||||
function site_footer(): void
|
||||
{
|
||||
?></main>
|
||||
<footer class="wrap foot">Fremder Code läuft mit allen Rechten auf eurem Server. Installiert nur Pakete, deren Herkunft ihr prüfen könnt, am besten signierte.</footer>
|
||||
</body></html>
|
||||
<?php
|
||||
}
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/lib.php';
|
||||
|
||||
function site_headers(): void
|
||||
{
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('X-Frame-Options: DENY');
|
||||
header('Referrer-Policy: same-origin');
|
||||
header("Content-Security-Policy: default-src 'self'; img-src 'self' data:; style-src 'self'; script-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'");
|
||||
}
|
||||
|
||||
/** Navigation der Verwaltung: Kennung => [Beschriftung, Symbol]. */
|
||||
function site_tabs(): array
|
||||
{
|
||||
return [
|
||||
'overview' => ['Übersicht', '◧'],
|
||||
'packages' => ['Pakete', '▣'],
|
||||
'apps' => ['Apps', '⬇'],
|
||||
'push' => ['Push-Dienst', '🔔'],
|
||||
'settings' => ['Einstellungen', '⚙'],
|
||||
];
|
||||
}
|
||||
|
||||
function site_header(string $title, string $active = '', bool $nav = false): void
|
||||
{
|
||||
site_headers();
|
||||
$name = site_config()['site_name'];
|
||||
?><!doctype html>
|
||||
<html lang="de"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#0f6f6a">
|
||||
<title><?= site_h($title) ?> · <?= site_h($name) ?></title>
|
||||
<link rel="icon" href="assets/favicon.svg" type="image/svg+xml">
|
||||
<link rel="icon" href="assets/favicon-32.png" sizes="32x32" type="image/png">
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
<link rel="apple-touch-icon" href="assets/apple-touch-icon.png">
|
||||
<link rel="stylesheet" href="assets/style.css"></head>
|
||||
<body>
|
||||
<header class="top"><div class="wrap">
|
||||
<a class="brand" href="index.php"><img src="assets/favicon.svg" alt="" width="30" height="30"><span><?= site_h($name) ?></span></a>
|
||||
<?php if ($nav): ?>
|
||||
<nav class="tabs" aria-label="Bereiche">
|
||||
<?php foreach (site_tabs() as $key => [$label, $icon]): ?>
|
||||
<a href="admin.php?tab=<?= site_h($key) ?>"<?= $key === $active ? ' class="on" aria-current="page"' : '' ?>><span class="ico" aria-hidden="true"><?= $icon ?></span><?= site_h($label) ?></a>
|
||||
<?php endforeach; ?>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
</div></header>
|
||||
<main class="wrap">
|
||||
<?php
|
||||
}
|
||||
|
||||
function site_footer(): void
|
||||
{
|
||||
?></main>
|
||||
<footer class="wrap foot">Fremder Code läuft mit allen Rechten auf eurem Server. Installiert nur Pakete, deren Herkunft ihr prüfen könnt, am besten signierte.</footer>
|
||||
</body></html>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
|
||||
const SITE_MAX_PACKAGE_BYTES = 10 * 1024 * 1024;
|
||||
const SITE_MAX_APP_BYTES = 300 * 1024 * 1024;
|
||||
const SITE_MAX_PREVIEW_BYTES = 1024 * 1024;
|
||||
const SITE_PLUGIN_EXTENSIONS = ['php', 'json', 'sql', 'js', 'css', 'png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'md', 'txt', 'html'];
|
||||
const SITE_THEME_EXTENSIONS = ['css', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'woff', 'woff2'];
|
||||
@@ -95,6 +96,10 @@ function site_db(): PDO
|
||||
signature TEXT NOT NULL DEFAULT '', size INTEGER NOT NULL, requires TEXT NOT NULL DEFAULT '', permissions TEXT NOT NULL DEFAULT '',
|
||||
downloads INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL, UNIQUE (item_id, version),
|
||||
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE)");
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS app_releases (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, platform TEXT NOT NULL, version TEXT NOT NULL, file TEXT NOT NULL,
|
||||
sha256 TEXT NOT NULL, size INTEGER NOT NULL, notes TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL,
|
||||
UNIQUE(platform, version))");
|
||||
// Empfehlung (nachträglich ergänzt, damit bestehende Datenbanken ohne Handarbeit weiterlaufen)
|
||||
$cols = array_column($pdo->query('PRAGMA table_info(items)')->fetchAll(), 'name');
|
||||
if (!in_array('featured', $cols, true)) $pdo->exec('ALTER TABLE items ADD COLUMN featured INTEGER NOT NULL DEFAULT 0');
|
||||
@@ -102,6 +107,50 @@ function site_db(): PDO
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
/** Latest published app release per platform: the HIGHEST version, not the one uploaded last. */
|
||||
function site_app_release(string $platform): ?array
|
||||
{
|
||||
if (!in_array($platform, ['android', 'windows', 'minecraft'], true)) return null;
|
||||
$stmt = site_db()->prepare('SELECT * FROM app_releases WHERE platform = ?');
|
||||
$stmt->execute([$platform]);
|
||||
$rows = $stmt->fetchAll();
|
||||
if (!$rows) return null;
|
||||
usort($rows, fn($a, $b) => version_compare($b['version'], $a['version']) ?: ((int) $b['id'] <=> (int) $a['id']));
|
||||
return $rows[0];
|
||||
}
|
||||
|
||||
function site_app_releases(): array
|
||||
{
|
||||
$rows = site_db()->query('SELECT * FROM app_releases')->fetchAll();
|
||||
usort($rows, fn($a, $b) => strcmp($a['platform'], $b['platform']) ?: (version_compare($b['version'], $a['version']) ?: ((int) $b['id'] <=> (int) $a['id'])));
|
||||
return $rows;
|
||||
}
|
||||
|
||||
function site_publish_app(string $platform, string $tmp, string $version, string $notes): array
|
||||
{
|
||||
$types = ['android' => ['apk', "PK"], 'windows' => ['exe', "MZ"], 'minecraft' => ['jar', "PK"]];
|
||||
if (!isset($types[$platform])) return ['ok' => false, 'error' => 'Unbekannte Plattform.'];
|
||||
if (!preg_match('/^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)?$/', $version)) return ['ok' => false, 'error' => 'Bitte eine Versionsnummer wie 3.4.0 eingeben.'];
|
||||
if (!is_uploaded_file($tmp)) return ['ok' => false, 'error' => 'Die hochgeladene Datei wurde nicht gefunden.'];
|
||||
$size = (int) filesize($tmp);
|
||||
if ($size < 1024 || $size > SITE_MAX_APP_BYTES) return ['ok' => false, 'error' => 'Die Datei muss zwischen 1 KB und 300 MB groß sein.'];
|
||||
$head = (string) file_get_contents($tmp, false, null, 0, 2);
|
||||
if ($head !== $types[$platform][1]) return ['ok' => false, 'error' => 'Dateityp passt nicht zur gewählten Plattform.'];
|
||||
$dir = site_storage() . '/apps/' . $platform;
|
||||
if (!is_dir($dir) && !@mkdir($dir, 0755, true)) return ['ok' => false, 'error' => 'App-Speicher konnte nicht angelegt werden.'];
|
||||
$file = bin2hex(random_bytes(24)) . '.' . $types[$platform][0];
|
||||
if (!move_uploaded_file($tmp, $dir . '/' . $file)) return ['ok' => false, 'error' => 'App-Datei konnte nicht gespeichert werden.'];
|
||||
$sha = hash_file('sha256', $dir . '/' . $file);
|
||||
try {
|
||||
$stmt = site_db()->prepare('INSERT INTO app_releases(platform,version,file,sha256,size,notes,created_at) VALUES(?,?,?,?,?,?,?)');
|
||||
$stmt->execute([$platform, $version, $file, $sha, $size, substr(trim($notes), 0, 2000), date('Y-m-d H:i:s')]);
|
||||
} catch (PDOException $e) {
|
||||
@unlink($dir . '/' . $file);
|
||||
return ['ok' => false, 'error' => str_contains(strtolower($e->getMessage()), 'unique') ? 'Diese Version ist für diese Plattform bereits vorhanden.' : 'Release konnte nicht gespeichert werden.'];
|
||||
}
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
/** Plugin bzw. Theme als „Empfohlen“ markieren oder die Markierung entfernen. */
|
||||
function site_set_featured(int $itemId, bool $featured): bool
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user