-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
2206 lines (1866 loc) · 75.7 KB
/
Copy pathinstall.php
File metadata and controls
2206 lines (1866 loc) · 75.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* SlimStorage Installer - One-File Installation & Update System
*
* This standalone script downloads, installs, and configures SlimStorage.
*
* Features:
* - Downloads latest release from GitHub automatically
* - Extracts and installs all files
* - Guides you through configuration
* - Creates .secrets.yml from a web form
* - Tests database connection
* - Initializes database schema
* - Can also be used for updates
*
* Requirements:
* - PHP 8.1+
* - MySQL 5.7+ or MariaDB 10.3+
* - PDO MySQL extension
* - cURL extension
* - ZipArchive extension
*
* Usage:
* 1. Upload ONLY this file to your web server
* 2. Navigate to it in your browser (e.g., https://yourdomain.com/install.php)
* 3. Follow the on-screen instructions
* 4. Delete this file after installation for security
*
* For Updates:
* - Upload this file again and add ?update=1 to the URL
* - It will preserve your .secrets.yml and update all other files
*/
declare(strict_types=1);
// Configuration
const GITHUB_REPO = 'kibotu/slimstorage'; // Change this to your actual GitHub repo
const GITHUB_API_URL = 'https://api.github.com/repos/' . GITHUB_REPO . '/releases/latest';
const INSTALL_DIR = __DIR__;
// .secrets.yml goes ONE FOLDER UP from web root (where config.php expects it: __DIR__ . '/../.secrets.yml')
const SECRETS_FILE = INSTALL_DIR . '/../.secrets.yml';
// schema.sql also goes one folder up (outside web root for security)
const SCHEMA_FILE = INSTALL_DIR . '/../schema.sql';
const PUBLIC_DIR = INSTALL_DIR . '/public';
const TEMP_DIR = INSTALL_DIR . '/temp_install';
const DOWNLOAD_TIMEOUT = 300; // 5 minutes
// Start session early (needed for installation flow tracking)
session_start();
// Detect update mode from GET parameter OR session (session persists across steps)
$isUpdateMode = (isset($_GET['update']) && $_GET['update'] === '1') || ($_SESSION['update_mode'] ?? false);
// Store update mode in session (do this early so it persists)
if ($isUpdateMode) {
$_SESSION['update_mode'] = true;
}
// Check if we're in the middle of an active installation (config was just saved)
$isActiveInstallation = isset($_SESSION['db_connection_ok']) || isset($_SESSION['config']);
$currentStep = $_GET['step'] ?? 'welcome';
// Security: Prevent access after installation is complete (unless updating or in active installation)
// Allow database and complete steps if we're in an active installation session
// Always allow delete step (it just removes the installer file, no security concern)
$allowedStepsWithSecrets = ['database', 'complete'];
$isAllowedStep = in_array($currentStep, $allowedStepsWithSecrets) && $isActiveInstallation;
$isDeleteStep = $currentStep === 'delete';
if (file_exists(SECRETS_FILE) && !isset($_GET['force']) && !$isUpdateMode && !$isAllowedStep && !$isDeleteStep) {
die('⚠️ Installation already complete. Delete .secrets.yml or add ?force=1 to reinstall, or ?update=1 to update.');
}
// Handle different installation steps (use $currentStep from earlier)
$step = $currentStep;
// Early handler for database step - redirect to configure if not ready
if ($step === 'database' && !isset($_SESSION['db_connection_ok'])) {
header('Location: ?step=configure');
exit;
}
// Early handler for configure step - handle update mode redirect before HTML output
if ($step === 'configure') {
$isUpdate = $_SESSION['update_mode'] ?? false;
// If updating and secrets exist, skip configuration and go to database step
if ($isUpdate && file_exists(SECRETS_FILE)) {
// Load existing configuration
$existingConfig = loadExistingSecretsEarly();
$_SESSION['config'] = $existingConfig;
$_SESSION['db_connection_ok'] = true;
// Set up PDO session variables
$dsn = sprintf(
"mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4",
$existingConfig['database']['host'] ?? 'localhost',
$existingConfig['database']['port'] ?? 3306,
$existingConfig['database']['name'] ?? ''
);
$_SESSION['pdo_dsn'] = $dsn;
$_SESSION['pdo_user'] = $existingConfig['database']['user'] ?? '';
$_SESSION['pdo_password'] = $existingConfig['database']['password'] ?? '';
header('Location: ?step=database');
exit;
}
}
// Early handler for process step - must run BEFORE any HTML output (for redirects)
if ($step === 'process' && $_SERVER['REQUEST_METHOD'] === 'POST') {
$result = handleProcessConfiguration();
if ($result['redirect']) {
header('Location: ' . $result['redirect']);
exit;
}
// If there's an error, store it in session and let the HTML page render it
$_SESSION['process_error'] = $result['error'] ?? null;
}
// Early AJAX handler - must run BEFORE any HTML output
if ($step === 'download' && isset($_GET['action'])) {
header('Content-Type: application/json');
try {
$action = $_GET['action'];
$isUpdate = $_SESSION['update_mode'] ?? false;
switch ($action) {
case 'fetch':
$releaseInfo = ajaxFetchLatestRelease();
$_SESSION['release_info'] = $releaseInfo;
echo json_encode(['success' => true, 'version' => $releaseInfo['tag_name']]);
break;
case 'download':
$releaseInfo = $_SESSION['release_info'] ?? null;
if (!$releaseInfo) {
throw new Exception('Release information not found');
}
$size = ajaxDownloadRelease($releaseInfo);
echo json_encode(['success' => true, 'size' => ajaxFormatBytes($size)]);
break;
case 'extract':
$files = ajaxExtractRelease($isUpdate);
echo json_encode(['success' => true, 'files' => $files]);
break;
case 'schema':
if (!$isUpdate) {
ajaxPrepareSchema();
}
echo json_encode(['success' => true]);
break;
default:
throw new Exception('Invalid action');
}
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// Helper functions for early AJAX handler (defined before HTML output)
function ajaxFetchLatestRelease(): array
{
$ch = curl_init(GITHUB_API_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'SlimStorage-Installer');
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
throw new Exception("Failed to fetch release: $error");
}
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("GitHub API returned HTTP $httpCode");
}
$data = json_decode($response, true);
if (!$data || !isset($data['zipball_url'])) {
throw new Exception("Invalid release data from GitHub");
}
return $data;
}
function ajaxDownloadRelease(array $releaseInfo): int
{
// Find the slimstore-{version}.zip asset from the release (curated, smaller)
// Fall back to zipball_url if no release asset found (full repo)
$zipUrl = $releaseInfo['zipball_url'];
$isReleaseAsset = false;
if (!empty($releaseInfo['assets'])) {
foreach ($releaseInfo['assets'] as $asset) {
// Match slimstore-*.zip but not the checksum file
if (preg_match('/^slimstore-.*\.zip$/', $asset['name']) && !str_ends_with($asset['name'], '.sha256')) {
$zipUrl = $asset['browser_download_url'];
$isReleaseAsset = true;
break;
}
}
}
$_SESSION['is_release_asset'] = $isReleaseAsset;
$_SESSION['download_url'] = $zipUrl;
$zipFile = TEMP_DIR . '/release.zip';
// Create temp directory
if (!file_exists(TEMP_DIR)) {
mkdir(TEMP_DIR, 0755, true);
}
// Download with retry logic (GitHub sometimes returns 503)
$maxRetries = 3;
$retryDelay = 2; // seconds
$lastError = '';
$lastHttpCode = 0;
for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {
$ch = curl_init($zipUrl);
$fp = fopen($zipFile, 'w+');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'SlimStorage-Installer/1.0');
curl_setopt($ch, CURLOPT_TIMEOUT, DOWNLOAD_TIMEOUT);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
$result = curl_exec($ch);
$lastHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($result === false) {
$lastError = curl_error($ch);
curl_close($ch);
fclose($fp);
if ($attempt < $maxRetries) {
sleep($retryDelay);
$retryDelay *= 2; // Exponential backoff
continue;
}
throw new Exception("Failed to download release after $maxRetries attempts: $lastError");
}
curl_close($ch);
fclose($fp);
// Success
if ($lastHttpCode === 200) {
break;
}
// Retry on 5xx errors
if ($lastHttpCode >= 500 && $attempt < $maxRetries) {
sleep($retryDelay);
$retryDelay *= 2;
continue;
}
throw new Exception("Failed to download release: HTTP $lastHttpCode (attempt $attempt/$maxRetries). URL: $zipUrl");
}
$_SESSION['zip_file'] = $zipFile;
return filesize($zipFile);
}
function ajaxExtractRelease(bool $isUpdate = false): int
{
$extractLog = [];
$zipFile = $_SESSION['zip_file'] ?? TEMP_DIR . '/release.zip';
$isReleaseAsset = $_SESSION['is_release_asset'] ?? false;
$extractLog[] = "Starting extraction...";
$extractLog[] = "Zip file: $zipFile";
$extractLog[] = "Is release asset: " . ($isReleaseAsset ? 'yes' : 'no');
$extractLog[] = "INSTALL_DIR: " . INSTALL_DIR;
$extractLog[] = "SCHEMA_FILE target: " . SCHEMA_FILE;
$extractLog[] = "SECRETS_FILE target: " . SECRETS_FILE;
// Check if parent directory is writable
$parentDir = dirname(SCHEMA_FILE);
$parentWritable = is_writable($parentDir);
$extractLog[] = "Parent dir: $parentDir";
$extractLog[] = "Parent dir writable: " . ($parentWritable ? 'yes' : 'NO! This may cause problems');
if (!file_exists($zipFile)) {
throw new Exception('Release zip file not found');
}
$zip = new ZipArchive();
if ($zip->open($zipFile) !== true) {
throw new Exception('Failed to open zip file');
}
$extractLog[] = "Zip opened successfully, contains " . $zip->numFiles . " files";
// Find the root folder in the zip (GitHub zipball adds a folder like "repo-version")
// Release assets created by our workflow have no root folder
$rootFolder = '';
if (!$isReleaseAsset) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$name = $zip->getNameIndex($i);
if (strpos($name, '/') !== false) {
$rootFolder = substr($name, 0, strpos($name, '/') + 1);
break;
}
}
}
$fileCount = 0;
$filesToSkip = ['install.php', '.secrets.yml', '.secrets-sample.yml', '.gitignore'];
// Files/folders that should NOT be extracted to web root (except schema.sql which we need)
$nonWebFiles = ['scripts/', 'README.md', '.gitignore', '.secrets-sample.yml'];
// If updating, also skip certain config files
if ($isUpdate) {
$filesToSkip[] = '.secrets.yml';
}
for ($i = 0; $i < $zip->numFiles; $i++) {
$name = $zip->getNameIndex($i);
// Remove root folder prefix
$relativePath = $rootFolder ? substr($name, strlen($rootFolder)) : $name;
// Skip empty paths, root folder, and specific files
if (empty($relativePath) || $relativePath === '/') {
continue;
}
// Skip files we don't want to overwrite
$skipThis = false;
foreach ($filesToSkip as $skipFile) {
if ($relativePath === $skipFile || str_ends_with($relativePath, '/' . $skipFile)) {
$skipThis = true;
break;
}
}
if ($skipThis) {
continue;
}
// Skip non-web files (scripts/, README.md, etc.) - but keep schema.sql
foreach ($nonWebFiles as $nonWebFile) {
if ($relativePath === $nonWebFile || str_starts_with($relativePath, $nonWebFile)) {
$skipThis = true;
break;
}
}
if ($skipThis) {
continue;
}
// Handle public/ folder specially - extract its contents to INSTALL_DIR (flatten it)
if (str_starts_with($relativePath, 'public/')) {
$relativePath = substr($relativePath, 7); // Remove 'public/' prefix
if (empty($relativePath)) {
continue; // Skip the public/ folder itself
}
$targetPath = INSTALL_DIR . '/' . $relativePath;
} elseif ($relativePath === 'schema.sql') {
// schema.sql goes to parent directory (outside web root)
$targetPath = SCHEMA_FILE;
} else {
// Skip any other root-level files/folders
continue;
}
// Create directory if needed
if (str_ends_with($name, '/')) {
if (!file_exists($targetPath)) {
mkdir($targetPath, 0755, true);
}
} else {
// Extract file
$dir = dirname($targetPath);
if (!file_exists($dir)) {
mkdir($dir, 0755, true);
}
$content = $zip->getFromIndex($i);
if ($content !== false) {
$result = file_put_contents($targetPath, $content);
if ($result === false) {
$extractLog[] = "FAILED to write: $targetPath";
} else {
$fileCount++;
// Log important files
if (str_contains($targetPath, 'schema.sql') || str_contains($targetPath, 'index.php') || str_contains($targetPath, 'config.php')) {
$extractLog[] = "Extracted: $targetPath ($result bytes)";
}
}
}
}
}
$zip->close();
$extractLog[] = "Extraction complete. Files extracted: $fileCount";
$extractLog[] = "schema.sql exists after extraction: " . (file_exists(SCHEMA_FILE) ? 'YES at ' . SCHEMA_FILE : 'NO!');
// Store extraction log in session for debugging
$_SESSION['extract_log'] = $extractLog;
// Clean up zip file
unlink($zipFile);
if (is_dir(TEMP_DIR)) {
@rmdir(TEMP_DIR);
}
return $fileCount;
}
function ajaxPrepareSchema(): void
{
// Read the schema file from the extracted files
if (!file_exists(SCHEMA_FILE)) {
throw new Exception('Schema file not found after extraction at: ' . SCHEMA_FILE);
}
$_SESSION['schema_sql'] = file_get_contents(SCHEMA_FILE);
}
function ajaxFormatBytes(int $bytes): string
{
$units = ['B', 'KB', 'MB', 'GB'];
$i = 0;
while ($bytes >= 1024 && $i < count($units) - 1) {
$bytes /= 1024;
$i++;
}
return round($bytes, 2) . ' ' . $units[$i];
}
/**
* Load existing secrets from .secrets.yml (early version for pre-HTML handlers)
*/
function loadExistingSecretsEarly(): array
{
if (!file_exists(SECRETS_FILE)) {
return [];
}
$content = file_get_contents(SECRETS_FILE);
$lines = explode("\n", $content);
$config = [];
$currentSection = null;
foreach ($lines as $line) {
$line = trim($line);
// Skip comments and empty lines
if ($line === '' || str_starts_with($line, '#')) {
continue;
}
// Check for section header
if (!str_starts_with($line, ' ') && str_ends_with($line, ':')) {
$currentSection = rtrim($line, ':');
$config[$currentSection] = [];
continue;
}
// Parse key-value pairs
if (str_contains($line, ':')) {
[$key, $value] = explode(':', $line, 2);
$key = trim($key);
$value = trim($value);
if ($currentSection !== null) {
$config[$currentSection][$key] = $value;
}
}
}
return $config;
}
/**
* Handle configuration processing before HTML output (for redirects)
*/
function handleProcessConfiguration(): array
{
// Validate and sanitize inputs
$config = [
'database' => [
'host' => trim($_POST['db_host'] ?? 'localhost'),
'port' => (int)($_POST['db_port'] ?? 3306),
'name' => trim($_POST['db_name'] ?? ''),
'user' => trim($_POST['db_user'] ?? ''),
'password' => $_POST['db_password'] ?? '',
'prefix' => trim($_POST['db_prefix'] ?? 'slimstore_'),
],
'domain' => [
'name' => trim($_POST['domain_name'] ?? ''),
],
'google_oauth' => [
'client_id' => trim($_POST['google_client_id'] ?? ''),
'client_secret' => trim($_POST['google_client_secret'] ?? ''),
'redirect_uri' => trim($_POST['google_redirect_uri'] ?? ''),
],
'superadmin' => [
'email' => trim($_POST['superadmin_email'] ?? ''),
],
'api' => [
'rate_limit_requests' => (int)($_POST['rate_limit_requests'] ?? 10000),
'rate_limit_window_seconds' => (int)($_POST['rate_limit_window'] ?? 60),
'max_keys_per_user' => (int)($_POST['max_keys_per_user'] ?? 100),
'max_value_size_bytes' => (int)($_POST['max_value_size'] ?? 262144),
'allowed_origins' => trim($_POST['allowed_origins'] ?? ''),
],
];
// Store in session for next step
$_SESSION['config'] = $config;
// Test database connection
try {
$dsn = sprintf(
"mysql:host=%s;port=%d;dbname=%s;charset=utf8mb4",
$config['database']['host'],
$config['database']['port'],
$config['database']['name']
);
$pdo = new PDO($dsn, $config['database']['user'], $config['database']['password'], [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
$_SESSION['db_connection_ok'] = true;
$_SESSION['pdo_dsn'] = $dsn;
$_SESSION['pdo_user'] = $config['database']['user'];
$_SESSION['pdo_password'] = $config['database']['password'];
// Create .secrets.yml file
createSecretsFileEarly($config);
return ['redirect' => '?step=database', 'error' => null];
} catch (PDOException $e) {
return ['redirect' => null, 'error' => $e->getMessage()];
}
}
/**
* Create secrets file (early version for pre-HTML handler)
*/
function createSecretsFileEarly(array $config): void
{
$yaml = "# Secrets Configuration\n";
$yaml .= "# WARNING: This file contains sensitive information.\n";
$yaml .= "# Do NOT commit this file to version control.\n\n";
$yaml .= "# Database Configuration\n";
$yaml .= "database:\n";
$yaml .= " host: {$config['database']['host']}\n";
$yaml .= " port: {$config['database']['port']}\n";
$yaml .= " name: {$config['database']['name']}\n";
$yaml .= " user: {$config['database']['user']}\n";
$yaml .= " password: {$config['database']['password']}\n";
$yaml .= " prefix: {$config['database']['prefix']}\n\n";
$yaml .= "# Domain Configuration\n";
$yaml .= "domain:\n";
$yaml .= " name: {$config['domain']['name']}\n\n";
$yaml .= "# Google OAuth Configuration\n";
$yaml .= "google_oauth:\n";
$yaml .= " client_id: {$config['google_oauth']['client_id']}\n";
$yaml .= " client_secret: {$config['google_oauth']['client_secret']}\n";
$yaml .= " redirect_uri: {$config['google_oauth']['redirect_uri']}\n\n";
$yaml .= "# Superadmin Configuration\n";
$yaml .= "superadmin:\n";
$yaml .= " email: {$config['superadmin']['email']}\n\n";
$yaml .= "# API Configuration\n";
$yaml .= "api:\n";
$yaml .= " rate_limit_requests: {$config['api']['rate_limit_requests']}\n";
$yaml .= " rate_limit_window_seconds: {$config['api']['rate_limit_window_seconds']}\n";
$yaml .= " max_keys_per_user: {$config['api']['max_keys_per_user']}\n";
$yaml .= " max_value_size_bytes: {$config['api']['max_value_size_bytes']}\n";
$yaml .= " allowed_origins: {$config['api']['allowed_origins']}\n";
if (file_put_contents(SECRETS_FILE, $yaml) === false) {
throw new Exception("Failed to create .secrets.yml file");
}
// Set restrictive permissions
chmod(SECRETS_FILE, 0600);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SlimStorage Installer</title>
<style>
/* Inter font import for consistent typography */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
:root {
/* Color Palette - Dark Mode matching main app */
--bg-body: #0f172a;
--bg-body-gradient: radial-gradient(at 0% 0%, rgba(56, 189, 248, 0.15) 0px, transparent 50%),
radial-gradient(at 100% 0%, rgba(236, 72, 153, 0.15) 0px, transparent 50%),
radial-gradient(at 100% 100%, rgba(14, 165, 233, 0.15) 0px, transparent 50%),
radial-gradient(at 0% 100%, rgba(232, 121, 249, 0.15) 0px, transparent 50%);
--bg-card: rgba(30, 41, 59, 0.7);
--bg-card-hover: rgba(30, 41, 59, 0.85);
--bg-input: rgba(15, 23, 42, 0.6);
--border-color: rgba(148, 163, 184, 0.1);
--border-color-hover: rgba(148, 163, 184, 0.2);
--text-primary: #f8fafc;
--text-secondary: #94a3b8;
--text-muted: #64748b;
--primary: #3b82f6;
--primary-hover: #2563eb;
--primary-glow: rgba(59, 130, 246, 0.5);
--success: #10b981;
--success-bg: rgba(16, 185, 129, 0.2);
--warning: #f59e0b;
--warning-bg: rgba(245, 158, 11, 0.2);
--danger: #ef4444;
--danger-hover: #dc2626;
--danger-bg: rgba(239, 68, 68, 0.2);
--radius-sm: 6px;
--radius-md: 12px;
--transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
--font-mono: 'Monaco', 'Courier New', monospace;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: var(--font-sans);
background-color: var(--bg-body);
background-image: var(--bg-body-gradient);
background-attachment: fixed;
color: var(--text-primary);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
.container {
background: var(--bg-card);
border: 1px solid var(--border-color);
border-radius: var(--radius-md);
backdrop-filter: blur(8px);
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
max-width: 800px;
width: 100%;
padding: 3rem;
animation: slideUp 0.5s ease-out;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
h1 {
background: linear-gradient(to right, #38bdf8, #818cf8);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 0.5rem;
font-size: 2.5rem;
font-weight: 800;
text-align: center;
letter-spacing: -0.05em;
}
h3 {
color: var(--text-primary);
font-weight: 600;
}
.subtitle {
text-align: center;
color: var(--text-secondary);
margin-bottom: 2rem;
font-size: 1.1rem;
}
.step-indicator {
display: flex;
justify-content: center;
margin-bottom: 2rem;
gap: 1rem;
}
.step {
width: 40px;
height: 40px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
border: 1px solid var(--border-color);
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: var(--text-muted);
transition: var(--transition);
}
.step.active {
background: var(--primary);
border-color: var(--primary);
color: white;
transform: scale(1.2);
box-shadow: 0 0 20px var(--primary-glow);
}
.step.completed {
background: var(--success);
border-color: var(--success);
color: white;
}
.form-group {
margin-bottom: 1.5rem;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
color: var(--text-primary);
font-size: 0.875rem;
}
.label-description {
font-size: 0.8rem;
color: var(--text-muted);
font-weight: normal;
margin-top: 0.25rem;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea {
width: 100%;
padding: 0.75rem 1rem;
background: var(--bg-input);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
color: var(--text-primary);
font-family: inherit;
font-size: 0.875rem;
transition: var(--transition);
}
input:focus,
textarea:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
background: rgba(15, 23, 42, 0.8);
}
input::placeholder {
color: var(--text-muted);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
background: var(--primary);
color: white;
padding: 0.875rem 2rem;
border: 1px solid transparent;
border-radius: var(--radius-sm);
font-size: 0.875rem;
font-weight: 600;
cursor: pointer;
transition: var(--transition);
text-decoration: none;
box-shadow: 0 0 20px rgba(59, 130, 246, 0.15);
}
.btn:hover {
background: var(--primary-hover);
transform: translateY(-2px);
box-shadow: 0 0 25px rgba(37, 99, 235, 0.4);
color: white;
}
.btn-secondary {
background: rgba(255, 255, 255, 0.05);
color: var(--text-primary);
border-color: var(--border-color);
box-shadow: none;
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.1);
border-color: var(--border-color-hover);
box-shadow: none;
}
.btn-success {
background: var(--success);
}
.btn-success:hover {
background: #059669;
box-shadow: 0 0 25px rgba(16, 185, 129, 0.4);
}
.btn-danger {
background: var(--danger-bg);
color: var(--danger);
border-color: rgba(239, 68, 68, 0.3);
box-shadow: none;
}
.btn-danger:hover {
background: rgba(239, 68, 68, 0.3);
border-color: var(--danger);
color: #fecaca;
}
.btn-group {
display: flex;
gap: 1rem;
margin-top: 2rem;
}
.alert {
padding: 1rem;
border-radius: var(--radius-sm);
margin-bottom: 1.5rem;
border: 1px solid transparent;
}
.alert-success {
background: var(--success-bg);
border-color: rgba(16, 185, 129, 0.3);
color: #6ee7b7;
}
.alert-error {
background: var(--danger-bg);
border-color: rgba(239, 68, 68, 0.3);
color: #fca5a5;
}
.alert-warning {
background: var(--warning-bg);
border-color: rgba(245, 158, 11, 0.3);
color: #fcd34d;
}
.alert-info {
background: rgba(59, 130, 246, 0.1);
border-color: rgba(59, 130, 246, 0.3);
color: #93c5fd;
}
.alert a {
color: #60a5fa;
text-decoration: underline;
}
.requirements {
background: rgba(15, 23, 42, 0.5);
border: 1px solid var(--border-color);
padding: 1.5rem;
border-radius: var(--radius-sm);
margin: 1.5rem 0;
}
.requirement {
display: flex;
align-items: center;
gap: 0.5rem;
margin-bottom: 0.75rem;
color: var(--text-secondary);
}
.requirement-ok {
color: var(--success);
}
.requirement-fail {
color: var(--danger);
}
.code-block {
background: #0f172a;
color: #e2e8f0;
padding: 1.25rem;
border-radius: var(--radius-sm);
font-family: var(--font-mono);
font-size: 0.875rem;
overflow-x: auto;
margin: 1rem 0;
border: 1px solid var(--border-color);
white-space: pre-wrap;
word-break: break-all;
}
.progress-bar {
width: 100%;
height: 8px;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
overflow: hidden;
margin: 1rem 0;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #38bdf8, #818cf8);
transition: width 0.3s;
}
.grid-2 {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
@media (max-width: 768px) {
body {
padding: 1rem;
}
.container {
padding: 1.5rem;
}
h1 {
font-size: 2rem;
}
.grid-2 {
grid-template-columns: 1fr;
}
.btn-group {
flex-direction: column;
}
}
.feature-list {
list-style: none;
margin: 1.5rem 0;
}
.feature-list li {
padding: 0.5rem 0;
padding-left: 2rem;