Skip to content

Commit d194596

Browse files
committed
wip
1 parent 02c76cc commit d194596

5 files changed

Lines changed: 94 additions & 17 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ temp_install/
3535
# Generated version file (created by installer)
3636
public/VERSION
3737

38+
# Version cache (for update check)
39+
public/.version-cache
40+

install.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@
5757

5858
// Security: Prevent access after installation is complete (unless updating or in active installation)
5959
// Allow database and complete steps if we're in an active installation session
60-
$allowedStepsWithSecrets = ['database', 'complete', 'delete'];
60+
// Always allow delete step (it just removes the installer file, no security concern)
61+
$allowedStepsWithSecrets = ['database', 'complete'];
6162
$isAllowedStep = in_array($currentStep, $allowedStepsWithSecrets) && $isActiveInstallation;
63+
$isDeleteStep = $currentStep === 'delete';
6264

63-
if (file_exists(SECRETS_FILE) && !isset($_GET['force']) && !$isUpdateMode && !$isAllowedStep) {
65+
if (file_exists(SECRETS_FILE) && !isset($_GET['force']) && !$isUpdateMode && !$isAllowedStep && !$isDeleteStep) {
6466
die('⚠️ Installation already complete. Delete .secrets.yml or add ?force=1 to reinstall, or ?update=1 to update.');
6567
}
6668

public/admin/index.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5340,14 +5340,38 @@ function goToLogPage(page) {
53405340
$versionFile = __DIR__ . '/../VERSION';
53415341
$version = file_exists($versionFile) ? trim(file_get_contents($versionFile)) : null;
53425342
if ($version):
5343+
// Check for newer version (cached, checks GitHub API once per hour)
5344+
$latestVersion = null;
5345+
$cacheFile = __DIR__ . '/../.version-cache';
5346+
$cacheMaxAge = 3600; // 1 hour
5347+
5348+
if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheMaxAge) {
5349+
$latestVersion = trim(file_get_contents($cacheFile));
5350+
} else {
5351+
// Fetch latest version from GitHub API
5352+
$ch = curl_init('https://api.github.com/repos/kibotu/SlimStorage/releases/latest');
5353+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
5354+
curl_setopt($ch, CURLOPT_USERAGENT, 'SlimStorage');
5355+
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
5356+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
5357+
$response = curl_exec($ch);
5358+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
5359+
curl_close($ch);
5360+
5361+
if ($httpCode === 200 && $response) {
5362+
$data = json_decode($response, true);
5363+
if (!empty($data['tag_name'])) {
5364+
$latestVersion = $data['tag_name'];
5365+
@file_put_contents($cacheFile, $latestVersion);
5366+
}
5367+
}
5368+
}
5369+
5370+
$hasUpdate = $latestVersion && version_compare(ltrim($latestVersion, 'v'), ltrim($version, 'v'), '>');
53435371
?>
5344-
<span class="version"><?= htmlspecialchars($version) ?></span>
5372+
<span class="version"><?= htmlspecialchars($version) ?><?php if ($hasUpdate): ?> <a href="https://github.com/kibotu/SlimStorage/releases/latest" target="_blank" rel="noopener" style="color: #10b981;">(<?= htmlspecialchars($latestVersion) ?> available)</a><?php endif; ?></span>
53455373
<?php endif; ?>
53465374
<span class="separator">•</span>
5347-
<a href="https://github.com/kibotu/SlimStorage" target="_blank" rel="noopener">
5348-
GitHub
5349-
</a>
5350-
<span class="separator">•</span>
53515375
<a href="https://github.com/kibotu/SlimStorage/issues" target="_blank" rel="noopener">
53525376
Report Issue
53535377
</a>

public/admin/superadmin.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,14 +1648,38 @@ function showSection(sectionId) {
16481648
$versionFile = __DIR__ . '/../VERSION';
16491649
$version = file_exists($versionFile) ? trim(file_get_contents($versionFile)) : null;
16501650
if ($version):
1651+
// Check for newer version (cached, checks GitHub API once per hour)
1652+
$latestVersion = null;
1653+
$cacheFile = __DIR__ . '/../.version-cache';
1654+
$cacheMaxAge = 3600; // 1 hour
1655+
1656+
if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheMaxAge) {
1657+
$latestVersion = trim(file_get_contents($cacheFile));
1658+
} else {
1659+
// Fetch latest version from GitHub API
1660+
$ch = curl_init('https://api.github.com/repos/kibotu/SlimStorage/releases/latest');
1661+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1662+
curl_setopt($ch, CURLOPT_USERAGENT, 'SlimStorage');
1663+
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
1664+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
1665+
$response = curl_exec($ch);
1666+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
1667+
curl_close($ch);
1668+
1669+
if ($httpCode === 200 && $response) {
1670+
$data = json_decode($response, true);
1671+
if (!empty($data['tag_name'])) {
1672+
$latestVersion = $data['tag_name'];
1673+
@file_put_contents($cacheFile, $latestVersion);
1674+
}
1675+
}
1676+
}
1677+
1678+
$hasUpdate = $latestVersion && version_compare(ltrim($latestVersion, 'v'), ltrim($version, 'v'), '>');
16511679
?>
1652-
<span class="version"><?= htmlspecialchars($version) ?></span>
1680+
<span class="version"><?= htmlspecialchars($version) ?><?php if ($hasUpdate): ?> <a href="https://github.com/kibotu/SlimStorage/releases/latest" target="_blank" rel="noopener" style="color: #10b981;">(<?= htmlspecialchars($latestVersion) ?> available)</a><?php endif; ?></span>
16531681
<?php endif; ?>
16541682
<span class="separator">•</span>
1655-
<a href="https://github.com/kibotu/SlimStorage" target="_blank" rel="noopener">
1656-
GitHub
1657-
</a>
1658-
<span class="separator">•</span>
16591683
<a href="https://github.com/kibotu/SlimStorage/issues" target="_blank" rel="noopener">
16601684
Report Issue
16611685
</a>

public/index.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,38 @@
326326
$versionFile = __DIR__ . '/VERSION';
327327
$version = file_exists($versionFile) ? trim(file_get_contents($versionFile)) : null;
328328
if ($version):
329+
// Check for newer version (cached, checks GitHub API once per hour)
330+
$latestVersion = null;
331+
$cacheFile = __DIR__ . '/.version-cache';
332+
$cacheMaxAge = 3600; // 1 hour
333+
334+
if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheMaxAge) {
335+
$latestVersion = trim(file_get_contents($cacheFile));
336+
} else {
337+
// Fetch latest version from GitHub API
338+
$ch = curl_init('https://api.github.com/repos/kibotu/SlimStorage/releases/latest');
339+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
340+
curl_setopt($ch, CURLOPT_USERAGENT, 'SlimStorage');
341+
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
342+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
343+
$response = curl_exec($ch);
344+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
345+
curl_close($ch);
346+
347+
if ($httpCode === 200 && $response) {
348+
$data = json_decode($response, true);
349+
if (!empty($data['tag_name'])) {
350+
$latestVersion = $data['tag_name'];
351+
@file_put_contents($cacheFile, $latestVersion);
352+
}
353+
}
354+
}
355+
356+
$hasUpdate = $latestVersion && version_compare(ltrim($latestVersion, 'v'), ltrim($version, 'v'), '>');
329357
?>
330-
<span class="version"><?= htmlspecialchars($version) ?></span>
358+
<span class="version"><?= htmlspecialchars($version) ?><?php if ($hasUpdate): ?> <a href="https://github.com/kibotu/SlimStorage/releases/latest" target="_blank" rel="noopener" style="color: #10b981;">(<?= htmlspecialchars($latestVersion) ?> available)</a><?php endif; ?></span>
331359
<?php endif; ?>
332360
<span class="separator">•</span>
333-
<a href="https://github.com/kibotu/SlimStorage" target="_blank" rel="noopener">
334-
GitHub
335-
</a>
336-
<span class="separator">•</span>
337361
<a href="https://github.com/kibotu/SlimStorage/issues" target="_blank" rel="noopener">
338362
Report Issue
339363
</a>

0 commit comments

Comments
 (0)