Repository navigation
Expand file tree
/
Copy pathinstall.php
More file actions
1457 lines (1370 loc) · 50.7 KB
/
Copy pathinstall.php
File metadata and controls
1457 lines (1370 loc) · 50.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
declare(strict_types=1);
$phpVersionId = defined('PHP_VERSION_ID') ? (int) PHP_VERSION_ID : 0;
if ($phpVersionId < 80300) {
$current = defined('PHP_VERSION') ? PHP_VERSION : 'unknown';
if (PHP_SAPI === 'cli') {
fwrite(STDERR, 'HCMS requires PHP 8.3+, this CLI runs ' . $current . '.' . PHP_EOL);
exit(1);
}
http_response_code(500);
header('Content-Type: text/html; charset=utf-8');
echo '<!doctype html><html lang="en"><head><meta charset="utf-8"/>'
. '<meta name="viewport" content="width=device-width, initial-scale=1"/>'
. '<title>HCMS — PHP version</title><style>'
. 'body{margin:0;min-height:100vh;display:flex;align-items:center;justify-content:center;'
. 'font-family:system-ui,sans-serif;background:linear-gradient(160deg,#e8eef2 0%,#d5ebe6 45%,#e2e8f0 100%);'
. 'color:#0f172a;padding:24px;box-sizing:border-box}'
. '.box{max-width:420px;background:#fff;border:1px solid #cbd5e1;border-radius:16px;padding:28px 24px;'
. 'box-shadow:0 12px 40px rgba(15,23,42,.08)}'
. 'h1{font-size:28px;margin:0 0 4px;letter-spacing:-.02em}'
. '.sub{color:#64748b;font-size:14px;margin:0 0 20px}'
. 'p{margin:0 0 12px;line-height:1.5;font-size:15px}'
. 'code{background:#f1f5f9;padding:2px 6px;border-radius:6px;font-size:13px}'
. '.hint{color:#0d9488;font-size:13px;margin-top:16px}'
. '</style></head><body><div class="box">'
. '<h1>HCMS</h1><p class="sub">Installer</p>'
. '<p><strong>HCMS requires PHP 8.3+</strong></p>'
. '<p>This server is running <code>' . htmlspecialchars($current, ENT_QUOTES, 'UTF-8') . '</code>.</p>'
. '<p class="hint">Update PHP in your hosting panel or switch the site to PHP 8.3+, then reload this page.</p>'
. '</div></body></html>';
exit(1);
}
const CMS_GITHUB_REPO = 'lnked/hcms';
const CMS_MIN_PHP = '8.3.0';
$root = __DIR__;
$lock = $root . '/storage/installed.lock';
// src/autoload.php resolves Cms\* without vendor/; only a pre-download tree
// (src/ not fetched yet) has to fall back to the Composer autoloader.
$autoload = is_file($root . '/src/autoload.php')
? $root . '/src/autoload.php'
: $root . '/vendor/autoload.php';
// `php install.php` on a bare box: the wizard is web-only, so boot PHP's
// built-in server instead of dumping HTML into the terminal. The child process
// re-enters this file as the router, hence the cli-server branch below.
if (PHP_SAPI === 'cli') {
$cliArgs = isset($_SERVER['argv']) && is_array($_SERVER['argv']) ? $_SERVER['argv'] : [];
cms_install_cli_serve(array_map('strval', array_slice(array_values($cliArgs), 1)));
}
if (PHP_SAPI === 'cli-server') {
$requestPath = parse_url((string) ($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH);
$requestPath = is_string($requestPath) && !str_contains($requestPath, '..') ? $requestPath : '/';
if ($requestPath !== '/install.php' && is_file($root . $requestPath)) {
return false; // static file — the built-in server streams it itself
}
// Installed already: hand /admin and /api to the CMS front controller so the
// link the wizard prints at the end actually resolves on this server.
if ($requestPath !== '/install.php' && is_file($lock) && is_file($root . '/index.php')) {
cms_install_cli_front($root . '/index.php');
}
cms_install_cli_authorize();
}
$action = $_GET['action'] ?? null;
/** @var array<string, mixed>|null $requestBody */
$requestBody = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$decoded = json_decode((string) file_get_contents('php://input'), true);
if (is_array($decoded)) {
$requestBody = $decoded;
if (isset($decoded['action']) && is_string($decoded['action'])) {
$action = $decoded['action'];
}
}
}
$wantsJson = $action !== null
|| (isset($_SERVER['HTTP_ACCEPT']) && str_contains((string) $_SERVER['HTTP_ACCEPT'], 'application/json') && $_SERVER['REQUEST_METHOD'] === 'POST');
if (is_file($lock) && $wantsJson && $action !== 'status') {
cms_install_send(403, ['error' => ['code' => 'INSTALLED', 'message' => 'CMS is already installed']]);
}
if ($wantsJson) {
cms_install_api($root, $autoload, $lock, is_string($action) ? $action : 'status', $requestBody);
}
if (is_file($lock)) {
header('Content-Type: text/html; charset=utf-8');
echo '<!doctype html><html><body><p>CMS already installed. <a href="/admin">Open Admin Panel</a></p></body></html>';
exit;
}
header('Content-Type: text/html; charset=utf-8');
echo cms_install_html();
exit;
/**
* @param array<string, mixed> $payload
*
* @return never
*/
function cms_install_send(int $status, array $payload)
{
http_response_code($status);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
exit;
}
/**
* @param array<string, mixed>|null $requestBody
*
* @return never
*/
function cms_install_api(string $root, string $autoload, string $lock, string $action, ?array $requestBody = null)
{
try {
$force = is_array($requestBody) && !empty($requestBody['force']);
if (is_file($autoload)) {
require $autoload;
if (!class_exists(Cms\Core\Paths::class)) {
cms_install_send(500, ['error' => [
'code' => 'BROKEN_INSTALL',
'message' => 'src/ is incomplete — run php scripts/restore.php diagnose',
]]);
}
$paths = new Cms\Core\Paths($root);
$installer = new Cms\Install\Installer($paths);
$downloader = new Cms\Install\ReleaseDownloader($paths);
if ($action === 'status') {
cms_install_send(200, $installer->status());
}
if ($action === 'latest') {
cms_install_send(200, ['data' => $downloader->srcReady() ? ['skipped' => true] : $downloader->latestManifest()]);
}
if ($action === 'download') {
cms_install_send(200, $downloader->download($force));
}
if ($action === 'test-connection') {
$db = is_array($requestBody) && isset($requestBody['database']) && is_array($requestBody['database'])
? $requestBody['database']
: [];
$result = $installer->testConnection($db);
cms_install_send($result['ok'] ? 200 : 400, $result);
}
if ($action === 'complete') {
if (is_file($lock)) {
cms_install_send(403, ['error' => ['code' => 'INSTALLED', 'message' => 'CMS is already installed']]);
}
$adminUrl = $installer->complete(is_array($requestBody) ? $requestBody : []);
cms_install_send(200, ['ok' => true, 'adminUrl' => $adminUrl]);
}
cms_install_send(400, ['error' => ['code' => 'BAD_REQUEST', 'message' => 'Unknown action']]);
}
if ($action === 'status') {
cms_install_send(200, [
'installed' => is_file($lock),
'srcReady' => is_file($root . '/src/bootstrap.php'),
'version' => is_file($root . '/VERSION') ? trim((string) file_get_contents($root . '/VERSION')) : '0.0.0',
'requirements' => cms_install_requirements($root),
]);
}
if ($action === 'download') {
cms_install_inline_download($root, $force);
}
cms_install_send(409, [
'error' => [
'code' => 'FILES_MISSING',
'message' => 'Download CMS files first or run composer install',
],
]);
} catch (Cms\Install\ValidationException $e) {
cms_install_send(422, [
'error' => [
'code' => 'VALIDATION_ERROR',
'message' => $e->getMessage(),
'fields' => $e->fields(),
],
]);
} catch (Throwable $e) {
cms_install_send(400, ['error' => ['code' => 'INSTALL_ERROR', 'message' => $e->getMessage()]]);
}
}
/**
* @return array<string, mixed>
*/
function cms_install_requirements(string $root): array
{
$checks = [
'php' => version_compare(PHP_VERSION, CMS_MIN_PHP, '>='),
'pdo_mysql' => extension_loaded('pdo_mysql'),
'json' => extension_loaded('json'),
'mbstring' => extension_loaded('mbstring'),
'zip' => class_exists(ZipArchive::class),
'http' => function_exists('curl_init') || (bool) ini_get('allow_url_fopen'),
'writable' => is_writable($root),
];
return ['ok' => !in_array(false, $checks, true), 'phpVersion' => PHP_VERSION, 'checks' => $checks];
}
/** @return never */
function cms_install_inline_download(string $root, bool $force = false)
{
if (!$force && is_file($root . '/src/bootstrap.php')) {
cms_install_send(200, ['skipped' => true, 'reason' => 'src_present']);
}
$base = 'https://github.com/' . CMS_GITHUB_REPO . '/releases/latest/download/';
$manifestRaw = cms_install_http($base . 'latest.json');
$manifest = json_decode($manifestRaw, true);
if (!is_array($manifest) || !isset($manifest['version']) || !is_string($manifest['version'])) {
throw new RuntimeException('Invalid release manifest');
}
$version = $manifest['version'];
$zipUrl = isset($manifest['zip']) && is_string($manifest['zip']) ? $manifest['zip'] : $base . 'cms-' . $version . '.zip';
$expected = isset($manifest['sha256']) && is_string($manifest['sha256'])
? strtolower($manifest['sha256'])
: strtolower(trim((string) preg_replace('/\s.*/', '', cms_install_http($base . 'cms-' . $version . '.zip.sha256'))));
$storage = $root . '/storage';
if (!is_dir($storage) && !mkdir($storage, 0775, true) && !is_dir($storage)) {
throw new RuntimeException('Cannot create storage');
}
$tmp = $storage . '/cms-' . $version . '.zip';
file_put_contents($tmp, cms_install_http($zipUrl));
$actual = hash_file('sha256', $tmp);
if ($actual === false || $expected === '' || !hash_equals($expected, $actual)) {
@unlink($tmp);
throw new RuntimeException('Release checksum mismatch');
}
$zip = new ZipArchive();
if ($zip->open($tmp) !== true) {
@unlink($tmp);
throw new RuntimeException('Unable to open archive');
}
$zip->extractTo($root);
$zip->close();
@unlink($tmp);
cms_install_send(200, [
'skipped' => false,
'version' => $version,
'changelog' => $manifest['changelog'] ?? [],
]);
}
function cms_install_http(string $url): string
{
$headers = ['User-Agent: hcms-installer'];
$token = getenv('CMS_GITHUB_TOKEN') ?: getenv('GITHUB_TOKEN') ?: '';
if ($token !== '') {
$headers[] = 'Authorization: Bearer ' . $token;
$headers[] = 'Accept: application/octet-stream';
}
if (function_exists('curl_init')) {
$ch = curl_init($url);
if ($ch === false) {
throw new RuntimeException('curl_init failed');
}
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTPHEADER => $headers,
]);
$body = curl_exec($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (!is_string($body) || $code >= 400) {
throw new RuntimeException(
'Download failed: ' . $url
. ($code === 404
? ' — repo private or release missing. Make lnked/hcms public, or set CMS_GITHUB_TOKEN.'
: ''),
);
}
return $body;
}
$context = stream_context_create([
'http' => [
'timeout' => 60,
'header' => implode("\r\n", $headers) . "\r\n",
],
]);
$body = @file_get_contents($url, false, $context);
if (!is_string($body)) {
throw new RuntimeException('Download failed: ' . $url);
}
return $body;
}
function cms_install_html(): string
{
return <<<'HTML'
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Install HCMS</title>
<link rel="preconnect" href="https://fonts.googleapis.com"/>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@500;600;700&family=Source+Sans+3:wght@400;500;600&display=swap" rel="stylesheet"/>
<style>
:root {
--ink: #0f172a;
--ink-soft: #334155;
--muted: #64748b;
--line: #cbd5e1;
--panel: rgba(255, 255, 255, 0.92);
--teal: #0d9488;
--teal-deep: #0f766e;
--ok: #15803d;
--err: #b91c1c;
--fair: #d97706;
--good: #0d9488;
--strong: #0f766e;
--weak: #dc2626;
--radius: 16px;
--font-ui: "Source Sans 3", system-ui, sans-serif;
--font-display: Outfit, system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
font-family: var(--font-ui);
color: var(--ink);
background:
radial-gradient(900px 480px at 12% -10%, rgba(13, 148, 136, 0.22), transparent 55%),
radial-gradient(700px 420px at 92% 8%, rgba(51, 65, 85, 0.14), transparent 50%),
linear-gradient(165deg, #e8eef2 0%, #d9ebe7 42%, #e2e8f0 100%);
padding: 40px 16px 64px;
}
.wrap { max-width: 560px; margin: 0 auto; }
.brand {
margin-bottom: 28px;
animation: fadeUp 0.45s ease both;
}
.brand h1 {
font-family: var(--font-display);
font-size: clamp(2.4rem, 8vw, 3.25rem);
font-weight: 700;
letter-spacing: -0.04em;
line-height: 1;
margin: 0;
}
.brand p {
margin: 8px 0 0;
color: var(--muted);
font-size: 1.05rem;
}
.rail {
display: flex;
gap: 6px;
margin-bottom: 18px;
animation: fadeUp 0.5s ease 0.05s both;
}
.rail-item {
flex: 1;
text-align: center;
padding: 10px 4px;
border-radius: 12px;
background: rgba(255,255,255,0.45);
border: 1px solid transparent;
color: var(--muted);
font-size: 12px;
font-weight: 600;
transition: border-color 0.2s, color 0.2s, background 0.2s, box-shadow 0.2s;
}
.rail-item .n {
display: block;
font-family: var(--font-display);
font-size: 13px;
margin-bottom: 2px;
}
.rail-item.done { color: var(--teal-deep); background: rgba(13,148,136,0.1); }
.rail-item.active {
color: var(--ink);
background: var(--panel);
border-color: rgba(13,148,136,0.35);
box-shadow: 0 0 0 3px rgba(13,148,136,0.12);
animation: pulseSoft 1.8s ease infinite;
}
.panel {
background: var(--panel);
border: 1px solid rgba(148,163,184,0.45);
border-radius: var(--radius);
padding: 22px 20px 20px;
backdrop-filter: blur(10px);
box-shadow: 0 18px 50px rgba(15,23,42,0.08);
animation: fadeUp 0.55s ease 0.1s both;
}
.step { display: none; }
.step.active { display: block; animation: fadeIn 0.28s ease; }
h2 {
font-family: var(--font-display);
font-size: 1.2rem;
font-weight: 600;
margin: 0 0 14px;
letter-spacing: -0.02em;
}
.checks { display: grid; gap: 8px; margin-bottom: 18px; }
.check {
display: flex;
align-items: center;
gap: 10px;
font-size: 14px;
color: var(--ink-soft);
}
.check .dot {
width: 18px; height: 18px; border-radius: 50%;
display: grid; place-items: center;
font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.check.ok .dot { background: var(--ok); }
.check.fail .dot { background: var(--err); }
.check.fail { color: var(--err); }
label {
display: block;
font-size: 13px;
font-weight: 600;
color: var(--ink-soft);
margin: 12px 0 5px;
}
input {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
font: inherit;
font-size: 15px;
color: var(--ink);
background: #fff;
transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
outline: none;
border-color: var(--teal);
box-shadow: 0 0 0 3px rgba(13,148,136,0.18);
}
.lang-select {
position: relative;
}
.lang-select select {
width: 100%;
appearance: none;
-webkit-appearance: none;
padding: 10px 44px 10px 12px;
border: 1px solid var(--line);
border-radius: 10px;
font: inherit;
font-size: 15px;
font-weight: 500;
color: var(--ink);
background: #fff;
cursor: pointer;
transition: border-color 0.15s, box-shadow 0.15s;
}
.lang-select select:hover {
border-color: #94a3b8;
}
.lang-select select:focus {
outline: none;
border-color: var(--teal);
box-shadow: 0 0 0 3px rgba(13,148,136,0.18);
}
.lang-select::after {
content: "";
position: absolute;
top: 50%;
right: 14px;
width: 10px;
height: 10px;
pointer-events: none;
transform: translateY(-60%) rotate(45deg);
border-right: 2px solid var(--muted);
border-bottom: 2px solid var(--muted);
}
.lang-select:focus-within::after {
border-color: var(--teal-deep);
}
input.invalid, select.invalid {
border-color: var(--err);
}
input.invalid:focus, select.invalid:focus {
border-color: var(--err);
box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.15);
}
.field-error {
margin: 4px 0 0;
font-size: 12px;
font-weight: 600;
color: var(--err);
}
.field-error:empty { display: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
button {
font: inherit;
font-weight: 600;
font-size: 14px;
border: 0;
border-radius: 10px;
padding: 11px 16px;
cursor: pointer;
background: var(--ink);
color: #fff;
transition: transform 0.12s, opacity 0.15s, background 0.15s;
}
button:hover:not(:disabled) { background: #1e293b; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.secondary {
background: #fff;
color: var(--ink);
border: 1px solid var(--line);
}
button.secondary:hover:not(:disabled) { background: #f8fafc; }
.input-with-actions {
position: relative;
}
.input-with-actions input {
padding-right: 76px;
}
.input-actions {
position: absolute;
top: 50%;
right: 8px;
transform: translateY(-50%);
display: flex;
align-items: center;
gap: 2px;
}
button.icon-btn {
display: grid;
place-items: center;
width: 28px;
height: 28px;
padding: 0;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--muted);
box-shadow: none;
}
button.icon-btn:hover:not(:disabled) {
background: rgba(13, 148, 136, 0.1);
color: var(--teal-deep);
}
button.icon-btn:active:not(:disabled) { transform: none; }
button.icon-btn svg {
width: 16px;
height: 16px;
display: block;
}
.progress-wrap {
display: none;
margin-top: 16px;
}
.progress-wrap.on { display: block; }
.progress-track {
height: 8px;
border-radius: 999px;
background: #e2e8f0;
overflow: hidden;
}
.progress-fill {
height: 100%;
width: 0%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), var(--teal-deep));
transition: width 0.35s ease;
}
.progress-fill.indeterminate {
width: 40% !important;
animation: indeterminate 1.1s ease-in-out infinite;
}
.progress-label {
margin: 8px 0 0;
font-size: 13px;
color: var(--muted);
}
.status { margin-top: 12px; font-size: 14px; min-height: 1.2em; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }
.status.muted { color: var(--muted); }
.strength { margin-top: 8px; }
.strength-track {
height: 6px;
border-radius: 999px;
background: #e2e8f0;
overflow: hidden;
}
.strength-fill {
height: 100%;
width: 0%;
border-radius: inherit;
transition: width 0.25s ease, background 0.25s ease;
}
.strength-fill.weak { width: 25%; background: var(--weak); }
.strength-fill.fair { width: 50%; background: var(--fair); }
.strength-fill.good { width: 75%; background: var(--good); }
.strength-fill.strong { width: 100%; background: var(--strong); }
.strength-label {
margin: 6px 0 0;
font-size: 12px;
font-weight: 600;
color: var(--muted);
}
.strength-label.weak { color: var(--weak); }
.strength-label.fair { color: var(--fair); }
.strength-label.good { color: var(--good); }
.strength-label.strong { color: var(--strong); }
.toast {
position: fixed;
bottom: 24px;
left: 50%;
transform: translateX(-50%) translateY(12px);
background: var(--ink);
color: #fff;
padding: 10px 16px;
border-radius: 10px;
font-size: 13px;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s, transform 0.2s;
z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.check-opt {
display: flex;
align-items: flex-start;
gap: 10px;
margin: 16px 0 4px;
font-size: 13px;
font-weight: 500;
color: var(--ink);
cursor: pointer;
line-height: 1.4;
}
.check-opt input {
width: auto;
margin: 2px 0 0;
accent-color: var(--teal);
flex-shrink: 0;
}
.hint-inline { color: var(--muted); font-weight: 400; }
.done-panel { text-align: center; padding: 12px 0 4px; }
.done-panel h2 { color: var(--ok); font-size: 1.45rem; }
.done-panel a {
display: inline-block;
margin-top: 12px;
color: #fff;
background: var(--ink);
text-decoration: none;
padding: 11px 18px;
border-radius: 10px;
font-weight: 600;
}
@keyframes fadeUp {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: none; }
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes pulseSoft {
0%, 100% { box-shadow: 0 0 0 3px rgba(13,148,136,0.12); }
50% { box-shadow: 0 0 0 5px rgba(13,148,136,0.18); }
}
@keyframes indeterminate {
0% { transform: translateX(-120%); }
100% { transform: translateX(280%); }
}
@media (max-width: 480px) {
.rail-item .lbl { display: none; }
.rail-item { padding: 10px 2px; }
body { padding-top: 28px; }
}
</style>
</head>
<body>
<div class="wrap">
<header class="brand">
<h1>HCMS</h1>
<p>Install</p>
</header>
<nav class="rail" id="rail" aria-label="Install steps">
<div class="rail-item active" data-step="0"><span class="n">1</span><span class="lbl">Files</span></div>
<div class="rail-item" data-step="1"><span class="n">2</span><span class="lbl">Database</span></div>
<div class="rail-item" data-step="2"><span class="n">3</span><span class="lbl">App</span></div>
<div class="rail-item" data-step="3"><span class="n">4</span><span class="lbl">Admin</span></div>
</nav>
<div class="panel">
<div id="s0" class="step active">
<h2>System check</h2>
<div id="req" class="checks"></div>
<div class="row-actions">
<button type="button" id="btnDownload">Download latest / continue</button>
<button type="button" id="btnForceDl" class="secondary" style="display:none">Re-download files</button>
</div>
<div id="dlProgress" class="progress-wrap">
<div class="progress-track"><div id="dlFill" class="progress-fill"></div></div>
<p id="dlLabel" class="progress-label"></p>
</div>
<p id="dlLog" class="status muted"></p>
<div class="row-actions" id="dlRetryWrap" style="display:none">
<button type="button" id="btnRetry" class="secondary">Retry download</button>
</div>
</div>
<div id="s1" class="step">
<h2>Database</h2>
<label for="dbHost">Host</label><input id="dbHost" value="127.0.0.1"/>
<p class="field-error" id="errDbHost"></p>
<label for="dbPort">Port</label><input id="dbPort" value="3306"/>
<p class="field-error" id="errDbPort"></p>
<label for="dbName">Name</label><input id="dbName" value="hcms"/>
<p class="field-error" id="errDbName"></p>
<label for="dbUser">User</label><input id="dbUser" value="root"/>
<p class="field-error" id="errDbUser"></p>
<label for="dbPass">Password</label><input id="dbPass" type="password"/>
<label for="dbCharset">Charset</label><input id="dbCharset" value="utf8mb4"/>
<div class="row-actions">
<button type="button" id="btnTest" class="secondary">Test connection</button>
<button type="button" id="btnDb">Continue</button>
</div>
<p id="dbMsg" class="status"></p>
</div>
<div id="s2" class="step">
<h2>Application</h2>
<label for="appName">Name</label><input id="appName" value="HCMS"/>
<p class="field-error" id="errAppName"></p>
<label for="appUrl">URL</label><input id="appUrl"/>
<p class="field-error" id="errAppUrl"></p>
<label for="appTz">Timezone</label><input id="appTz" value="UTC"/>
<p class="field-error" id="errAppTz"></p>
<label for="appLang">Language</label>
<div class="lang-select">
<select id="appLang" aria-label="Language">
<option value="en" selected>English</option>
<option value="ru">Русский</option>
</select>
</div>
<label for="appPublicDir">Web root folder</label>
<input id="appPublicDir" list="publicDirList" value="public" placeholder="public"/>
<p class="field-error" id="errAppPublicDir"></p>
<datalist id="publicDirList">
<option value="public"></option>
<option value="public_html"></option>
<option value="www"></option>
<option value="htdocs"></option>
</datalist>
<p class="hint">Hosting document root must point to this folder. Admin URL = <code>/admin</code>.</p>
<div class="row-actions">
<button type="button" id="btnApp">Continue</button>
</div>
</div>
<div id="s3" class="step">
<h2>Administrator</h2>
<label for="admName">Name</label><input id="admName"/>
<p class="field-error" id="errAdmName"></p>
<label for="admEmail">Email</label><input id="admEmail" type="email"/>
<p class="field-error" id="errAdmEmail"></p>
<label for="admPass">Password</label>
<div class="input-with-actions">
<input id="admPass" type="password" autocomplete="new-password"/>
<div class="input-actions">
<button type="button" id="btnGenPass" class="icon-btn" title="Generate" aria-label="Generate password">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M21 12a9 9 0 1 1-2.64-6.36"/>
<polyline points="21 3 21 9 15 9"/>
</svg>
</button>
<button type="button" id="btnCopyPass" class="icon-btn" title="Copy" aria-label="Copy password">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<rect x="9" y="9" width="13" height="13" rx="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
</button>
</div>
</div>
<p class="field-error" id="errAdmPass"></p>
<div class="strength" id="strengthBox" hidden>
<div class="strength-track"><div id="strengthFill" class="strength-fill"></div></div>
<p id="strengthLabel" class="strength-label"></p>
</div>
<label for="admPass2">Confirm</label><input id="admPass2" type="password" autocomplete="new-password"/>
<p class="field-error" id="errAdmPass2"></p>
<label class="check-opt" for="optTelemetry">
<input type="checkbox" id="optTelemetry" checked/>
<span>Share anonymous install stats <span class="hint-inline">(version, PHP, OS — no personal data)</span></span>
</label>
<div class="row-actions">
<button type="button" id="btnInstall">Install</button>
</div>
<div id="instProgress" class="progress-wrap">
<div class="progress-track"><div id="instFill" class="progress-fill"></div></div>
<p id="instLabel" class="progress-label"></p>
</div>
<p id="instMsg" class="status"></p>
</div>
<div id="s4" class="step">
<div class="done-panel">
<h2>Installation completed</h2>
<p class="status muted">CMS is ready.</p>
<a id="openAdmin" href="/admin" onclick="try{sessionStorage.removeItem('hcms_token')}catch(e){}">Open Admin Panel</a>
</div>
</div>
</div>
</div>
<div id="toast" class="toast" role="status">Copied</div>
<script>
const $ = (id) => document.getElementById(id);
const reqLabels = {
php: 'PHP 8.3+',
pdo_mysql: 'PDO MySQL',
json: 'JSON',
mbstring: 'mbstring',
zip: 'ZipArchive',
http: 'HTTP downloads',
writable: 'Writable directory'
};
let wizardStep = 0;
let reqOk = false;
let progressTimer = null;
function setWizardStep(n) {
wizardStep = n;
document.querySelectorAll('.step').forEach((el, i) => {
el.classList.toggle('active', i === n);
});
document.querySelectorAll('.rail-item').forEach((el) => {
const s = Number(el.dataset.step);
el.classList.toggle('active', s === Math.min(n, 3));
el.classList.toggle('done', s < n || n === 4);
if (n === 4) el.classList.remove('active');
});
}
function toast(msg) {
const t = $('toast');
t.textContent = msg;
t.classList.add('show');
setTimeout(() => t.classList.remove('show'), 1600);
}
function setProgress(wrapId, fillId, labelId, pct, label, indeterminate) {
const wrap = $(wrapId);
const fill = $(fillId);
wrap.classList.add('on');
fill.classList.toggle('indeterminate', !!indeterminate);
if (!indeterminate) fill.style.width = Math.max(0, Math.min(100, pct)) + '%';
$(labelId).textContent = label || '';
}
function resetProgress(wrapId, fillId, labelId) {
clearInterval(progressTimer);
progressTimer = null;
const wrap = $(wrapId);
const fill = $(fillId);
wrap.classList.remove('on');
fill.classList.remove('indeterminate');
fill.style.width = '0%';
$(labelId).textContent = '';
}
function runPhasedProgress(wrapId, fillId, labelId, phases) {
let i = 0;
clearInterval(progressTimer);
const tick = () => {
const p = phases[Math.min(i, phases.length - 1)];
setProgress(wrapId, fillId, labelId, p.pct, p.label, !!p.indeterminate);
if (i < phases.length - 1) i += 1;
};
tick();
progressTimer = setInterval(tick, 900);
}
async function api(action, body = {}) {
const res = await fetch('install.php?action=' + encodeURIComponent(action), {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
body: JSON.stringify({ action, ...body })
});
let data = {};
try { data = await res.json(); } catch (_) {}
if (!res.ok) {
const msg = data.error?.message || data.error || 'Request failed';
const err = new Error(typeof msg === 'string' ? msg : 'Request failed');
err.code = data.error?.code || '';
err.fields = data.error?.fields && typeof data.error.fields === 'object' ? data.error.fields : {};
throw err;
}
return data;
}
const fieldErrorMap = {
dbHost: 'errDbHost',
dbPort: 'errDbPort',
dbName: 'errDbName',
dbUser: 'errDbUser',
appName: 'errAppName',
appUrl: 'errAppUrl',
appTz: 'errAppTz',
appPublicDir: 'errAppPublicDir',
admName: 'errAdmName',
admEmail: 'errAdmEmail',
admPass: 'errAdmPass',
admPass2: 'errAdmPass2'
};
const adminApiFields = {
name: 'admName',
email: 'admEmail',
password: 'admPass',
passwordConfirm: 'admPass2'
};
function firstFieldMessage(value) {
if (Array.isArray(value)) return value[0] || '';
return typeof value === 'string' ? value : '';
}
function clearFieldErrors(ids) {
ids.forEach((id) => {
const input = $(id);
if (input) input.classList.remove('invalid');
const errId = fieldErrorMap[id];
if (errId && $(errId)) $(errId).textContent = '';
});
}
function setFieldErrors(errors) {
Object.entries(errors).forEach(([key, value]) => {
const msg = firstFieldMessage(value);
if (!msg) return;
const inputId = adminApiFields[key] || key;
const errId = fieldErrorMap[inputId];
if ($(inputId)) $(inputId).classList.add('invalid');
if (errId && $(errId)) $(errId).textContent = msg;
});
}
function validateDatabase() {
const ids = ['dbHost', 'dbPort', 'dbName', 'dbUser'];
clearFieldErrors(ids);
const errors = {};
if (!$('dbHost').value.trim()) errors.dbHost = 'Host is required';
const port = Number($('dbPort').value);
if (!$('dbPort').value.trim() || !Number.isFinite(port) || port < 1 || port > 65535) {
errors.dbPort = 'Enter a valid port (1–65535)';
}
if (!$('dbName').value.trim()) errors.dbName = 'Database name is required';
if (!$('dbUser').value.trim()) errors.dbUser = 'User is required';
setFieldErrors(errors);
return Object.keys(errors).length === 0;
}
function validateApplication() {
const ids = ['appName', 'appUrl', 'appTz', 'appPublicDir'];
clearFieldErrors(ids);
const errors = {};
if (!$('appName').value.trim()) errors.appName = 'Name is required';
const url = $('appUrl').value.trim();
if (!url) {
errors.appUrl = 'URL is required';
} else {
try {
const parsed = new URL(url);
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
errors.appUrl = 'URL must start with http:// or https://';
}
} catch (_) {
errors.appUrl = 'Enter a valid URL';
}
}
if (!$('appTz').value.trim()) errors.appTz = 'Timezone is required';
if (!$('appPublicDir').value.trim()) errors.appPublicDir = 'Web root folder is required';