-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
660 lines (582 loc) · 27.1 KB
/
Copy pathinstall.php
File metadata and controls
660 lines (582 loc) · 27.1 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
<?php
/*
* install.php — Kurulum sihirbazı / Installation wizard
*
* Sunucu gereksinimlerini denetler, veritabanını hazırlar, şemayı
* içe aktarır, yönetici hesabını oluşturur ve config.php dosyasını
* yazar.
*
* GÜVENLİK
* --------
* Kurulum tamamlandığında config/config.php oluşur ve bu dosya
* kendini devre dışı bırakır. Yine de kurulumdan sonra install.php
* dosyasını sunucudan SİLİN.
*/
declare(strict_types=1);
session_start();
const APP_MIN_PHP = '8.1.0';
$root = __DIR__;
$configFile = $root . '/config/config.php';
$schemaFile = $root . '/sql/admin-panel.sql';
/* ══ Dil ═══════════════════════════════════════════════════════ */
$lang = $_GET['lang'] ?? $_SESSION['install_lang'] ?? null;
if (!in_array($lang, ['tr', 'en'], true)) {
$lang = stripos((string)($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? ''), 'tr') !== false ? 'tr' : 'en';
}
$_SESSION['install_lang'] = $lang;
$S = [
'tr' => [
'title' => 'Kurulum Sihirbazı', 'subtitle' => 'Paneli kullanmaya başlamak için birkaç adım kaldı.',
'req' => 'Sunucu Gereksinimleri', 'req_ok' => 'Tüm gereksinimler karşılanıyor.',
'req_fail' => 'Aşağıdaki gereksinimler karşılanmıyor. Kuruluma devam edilemez.',
'db' => 'Veritabanı', 'db_host' => 'Sunucu', 'db_name' => 'Veritabanı adı',
'db_user' => 'Kullanıcı adı', 'db_pass' => 'Şifre',
'db_hint' => 'Veritabanı yoksa oluşturulmaya çalışılır.',
'app' => 'Uygulama', 'app_name' => 'Panel adı',
'admin' => 'Yönetici Hesabı', 'admin_hint' => 'Bu hesap tüm yetkilere sahip Süper Admin olur.',
'username' => 'Kullanıcı adı', 'email' => 'E-posta', 'password' => 'Şifre',
'password2' => 'Şifre (tekrar)',
'submit' => 'Kurulumu Tamamla', 'installing' => 'Kuruluyor…',
'done' => 'Kurulum Tamamlandı', 'done_desc' => 'Panel kullanıma hazır.',
'done_warn' => 'ÖNEMLİ: Güvenlik için install.php dosyasını şimdi sunucudan silin.',
'go' => 'Giriş Sayfasına Git',
'locked' => 'Kurulum Zaten Yapılmış',
'locked_desc' => 'Bu panel daha önce kurulmuş. Yeniden kurmak isterseniz config/config.php dosyasını silin.',
'err_pass_match' => 'Şifreler eşleşmiyor.',
'err_user_empty' => 'Kullanıcı adı boş olamaz.',
'err_user_long' => 'Kullanıcı adı en fazla 50 karakter olabilir.',
'err_email' => 'Geçerli bir e-posta adresi girin.',
'err_dbname' => 'Veritabanı adı boş olamaz.',
'err_appname' => 'Panel adı boş olamaz.',
'err_csrf' => 'Oturum doğrulaması başarısız. Sayfayı yenileyip tekrar deneyin.',
'err_connect' => 'Veritabanına bağlanılamadı: ',
'err_create_db' => 'Veritabanı oluşturulamadı. Kullanıcının CREATE yetkisi olmayabilir: ',
'err_schema' => 'Şema içe aktarılamadı: ',
'err_schema_missing' => 'Şema dosyası bulunamadı: sql/admin-panel.sql',
'err_config_write' => 'config/config.php yazılamadı. config/ dizinine yazma izni verin.',
'err_admin' => 'Yönetici hesabı oluşturulamadı: ',
'err_role_missing' => 'Süper Admin rolü bulunamadı. Şema eksik içe aktarılmış olabilir.',
'ext' => 'PHP eklentisi', 'writable' => 'yazılabilir olmalı', 'php_ver' => 'PHP sürümü',
'pw_err_short' => 'Şifre en az {n} karakter olmalı.',
'pw_err_long' => 'Şifre çok uzun (en fazla 72 karakter).',
'pw_err_case' => 'Şifre hem büyük hem küçük harf içermeli.',
'pw_err_number' => 'Şifre en az bir rakam içermeli.',
'pw_err_symbol' => 'Şifre en az bir sembol içermeli.',
'pw_err_common' => 'Bu şifre çok yaygın kullanılıyor. Lütfen başka bir şifre seçin.',
'pw_hint_min' => 'en az {n} karakter', 'pw_hint_case' => 'büyük + küçük harf',
'pw_hint_number' => 'rakam', 'pw_hint_symbol' => 'sembol',
],
'en' => [
'title' => 'Installation Wizard', 'subtitle' => 'Just a few steps before you can use the panel.',
'req' => 'Server Requirements', 'req_ok' => 'All requirements are met.',
'req_fail' => 'The requirements below are not met. Installation cannot continue.',
'db' => 'Database', 'db_host' => 'Host', 'db_name' => 'Database name',
'db_user' => 'Username', 'db_pass' => 'Password',
'db_hint' => 'The database will be created if it does not exist.',
'app' => 'Application', 'app_name' => 'Panel name',
'admin' => 'Administrator Account', 'admin_hint' => 'This account becomes the all-powerful Super Admin.',
'username' => 'Username', 'email' => 'Email', 'password' => 'Password',
'password2' => 'Password (repeat)',
'submit' => 'Complete Installation', 'installing' => 'Installing…',
'done' => 'Installation Complete', 'done_desc' => 'The panel is ready to use.',
'done_warn' => 'IMPORTANT: Delete install.php from your server now.',
'go' => 'Go to Login',
'locked' => 'Already Installed',
'locked_desc' => 'This panel has already been installed. To reinstall, delete config/config.php.',
'err_pass_match' => 'Passwords do not match.',
'err_user_empty' => 'Username cannot be empty.',
'err_user_long' => 'Username can be at most 50 characters.',
'err_email' => 'Enter a valid email address.',
'err_dbname' => 'Database name cannot be empty.',
'err_appname' => 'Panel name cannot be empty.',
'err_csrf' => 'Session validation failed. Refresh the page and try again.',
'err_connect' => 'Could not connect to the database: ',
'err_create_db' => 'Could not create the database. The user may lack CREATE privileges: ',
'err_schema' => 'Could not import the schema: ',
'err_schema_missing' => 'Schema file not found: sql/admin-panel.sql',
'err_config_write' => 'Could not write config/config.php. Grant write permission to config/.',
'err_admin' => 'Could not create the administrator account: ',
'err_role_missing' => 'Super Admin role not found. The schema may be incompletely imported.',
'ext' => 'PHP extension', 'writable' => 'must be writable', 'php_ver' => 'PHP version',
'pw_err_short' => 'Password must be at least {n} characters.',
'pw_err_long' => 'Password is too long (72 characters maximum).',
'pw_err_case' => 'Password must contain both uppercase and lowercase letters.',
'pw_err_number' => 'Password must contain at least one number.',
'pw_err_symbol' => 'Password must contain at least one symbol.',
'pw_err_common' => 'This password is too common. Please choose a different one.',
'pw_hint_min' => 'at least {n} characters', 'pw_hint_case' => 'upper + lowercase',
'pw_hint_number' => 'number', 'pw_hint_symbol' => 'symbol',
],
][$lang];
/*
* validation.php t() ve config() bekler. Bu iki yardımcıyı burada
* sağlıyoruz ki şifre politikası tek bir yerde tanımlı kalsın —
* kurulum ile panel aynı kuralları uygulasın.
*/
function t(string $key, array $replace = []): string
{
global $S;
$str = $S[$key] ?? $key;
foreach ($replace as $k => $v) {
$str = str_replace('{' . $k . '}', htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'), $str);
}
return $str;
}
/** Kurulum sırasında geçerli olan varsayılan politika. */
function config(string $key, $default = null)
{
static $defaults = [
'password_min_length' => 10,
'password_require_mixed_case' => true,
'password_require_number' => true,
'password_require_symbol' => false,
];
return $defaults[$key] ?? $default;
}
require_once $root . '/includes/validation.php';
/* ══ Zaten kurulu mu? ══════════════════════════════════════════ */
$alreadyInstalled = is_file($configFile);
/* ══ Gereksinim denetimi ═══════════════════════════════════════ */
$requirements = [
['label' => t('php_ver') . ' ≥ ' . APP_MIN_PHP, 'ok' => version_compare(PHP_VERSION, APP_MIN_PHP, '>='), 'note' => PHP_VERSION],
['label' => 'PDO', 'ok' => extension_loaded('pdo'), 'note' => t('ext')],
['label' => 'pdo_mysql', 'ok' => extension_loaded('pdo_mysql'), 'note' => t('ext')],
['label' => 'mbstring', 'ok' => extension_loaded('mbstring'), 'note' => t('ext')],
['label' => 'openssl', 'ok' => extension_loaded('openssl'), 'note' => t('ext')],
['label' => 'config/', 'ok' => is_writable($root . '/config'), 'note' => t('writable')],
];
$requirementsOk = true;
foreach ($requirements as $r) {
if (!$r['ok']) { $requirementsOk = false; }
}
/* ══ Yardımcılar ═══════════════════════════════════════════════ */
/**
* SQL dosyasını tek tek çalıştırılabilir ifadelere böler.
* Tırnak/backtick içindeki noktalı virgülleri ve -- yorumlarını gözetir.
*/
function splitSqlStatements(string $sql): array
{
$statements = [];
$current = '';
$quote = '';
$len = strlen($sql);
for ($i = 0; $i < $len; $i++) {
$ch = $sql[$i];
if ($quote !== '') {
if ($ch === '\\' && $quote !== '`') {
$current .= $ch . ($sql[$i + 1] ?? '');
$i++;
continue;
}
if ($ch === $quote) { $quote = ''; }
$current .= $ch;
continue;
}
if ($ch === "'" || $ch === '"' || $ch === '`') {
$quote = $ch;
$current .= $ch;
continue;
}
/* "--" ile başlayan satır yorumu */
if ($ch === '-' && ($sql[$i + 1] ?? '') === '-') {
while ($i < $len && $sql[$i] !== "\n") { $i++; }
$current .= "\n";
continue;
}
if ($ch === ';') {
$statements[] = trim($current);
$current = '';
continue;
}
$current .= $ch;
}
if (trim($current) !== '') { $statements[] = trim($current); }
return array_values(array_filter($statements, static fn($s) => $s !== ''));
}
/**
* config.php içeriğini üretir. Değerler var_export ile yazılır;
* tırnak veya ters eğik çizgi içeren şifreler bozulmaz.
*/
function buildConfig(array $v): string
{
$e = static fn($x) => var_export($x, true);
return <<<PHP
<?php
/*
* config/config.php — install.php tarafından oluşturuldu
* Generated by install.php on {$v['generated']}
*
* Bu dosya hassas bilgi içerir; web'den erişilemez (config/.htaccess).
* Sürüm kontrolüne EKLEMEYİN.
*/
return [
/* ── Veritabanı ─────────────────────────────────── */
'host' => {$e($v['host'])},
'dbname' => {$e($v['dbname'])},
'user' => {$e($v['user'])},
'pass' => {$e($v['pass'])},
/* ── Uygulama ───────────────────────────────────── */
'app_name' => {$e($v['app_name'])},
/*
* Panelin web yolu. Boş bırakılırsa otomatik tespit edilir.
* Yalnızca otomatik tespitin başarısız olduğu kurulumlarda doldurun.
*/
'base_url' => '',
/* ── Ortam ──────────────────────────────────────── */
/* CANLI SUNUCUDA 'production' OLMALIDIR. */
'env' => 'production',
/* ── Oturum ─────────────────────────────────────── */
'session_idle_timeout' => 1800,
'session_absolute_timeout' => 43200,
/* ── Şifre Politikası ───────────────────────────── */
'password_min_length' => 10,
'password_require_mixed_case' => true,
'password_require_number' => true,
'password_require_symbol' => false,
];
PHP;
}
/**
* .htaccess içindeki ErrorDocument yollarını kurulum dizinine göre günceller.
* Başarısız olursa kurulum durdurulmaz; yalnızca özel hata sayfaları devre dışı kalır.
*/
function updateErrorDocuments(string $root): void
{
$file = $root . '/.htaccess';
if (!is_file($file) || !is_writable($file)) {
return;
}
$docRoot = str_replace('\\', '/', (string)realpath((string)($_SERVER['DOCUMENT_ROOT'] ?? '')));
$appRoot = str_replace('\\', '/', (string)realpath($root));
$base = ($docRoot !== '' && strpos($appRoot, $docRoot) === 0)
? substr($appRoot, strlen($docRoot))
: str_replace('\\', '/', dirname((string)($_SERVER['SCRIPT_NAME'] ?? '')));
$base = rtrim('/' . trim($base, '/'), '/');
$block = "# BEGIN ERROR_DOCUMENTS\n"
. "ErrorDocument 403 $base/errors/403.php\n"
. "ErrorDocument 404 $base/errors/404.php\n"
. "ErrorDocument 500 $base/errors/500.php\n"
. "# END ERROR_DOCUMENTS";
$content = (string)file_get_contents($file);
$updated = preg_replace(
'/# BEGIN ERROR_DOCUMENTS.*?# END ERROR_DOCUMENTS/s',
str_replace('$', '\\$', $block),
$content
);
if ($updated !== null && $updated !== $content) {
@file_put_contents($file, $updated);
}
}
/* ══ Kurulum işlemi ════════════════════════════════════════════ */
if (empty($_SESSION['install_csrf'])) {
$_SESSION['install_csrf'] = bin2hex(random_bytes(32));
}
$errors = [];
$installed = false;
/* Formu yeniden çizerken kullanılacak değerler — şifreler asla geri yazılmaz */
$form = [
'host' => $_POST['host'] ?? 'localhost',
'dbname' => $_POST['dbname'] ?? 'admin_panel',
'dbuser' => $_POST['dbuser'] ?? 'root',
'app_name' => $_POST['app_name'] ?? 'Admin Panel',
'username' => $_POST['username'] ?? '',
'email' => $_POST['email'] ?? '',
];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$alreadyInstalled && $requirementsOk) {
if (!hash_equals($_SESSION['install_csrf'], $_POST['csrf'] ?? '')) {
$errors[] = t('err_csrf');
} else {
$host = trim((string)($_POST['host'] ?? ''));
$dbname = trim((string)($_POST['dbname'] ?? ''));
$dbuser = (string)($_POST['dbuser'] ?? '');
$dbpass = (string)($_POST['dbpass'] ?? '');
$appName = trim((string)($_POST['app_name'] ?? ''));
$username = str_replace(' ', '', trim((string)($_POST['username'] ?? '')));
$email = trim((string)($_POST['email'] ?? ''));
$pass = (string)($_POST['password'] ?? '');
$pass2 = (string)($_POST['password2'] ?? '');
if ($dbname === '') { $errors[] = t('err_dbname'); }
if ($appName === '') { $errors[] = t('err_appname'); }
if ($username === '') { $errors[] = t('err_user_empty'); }
elseif (mb_strlen($username) > 50) { $errors[] = t('err_user_long'); }
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = t('err_email'); }
if ($pass !== $pass2) { $errors[] = t('err_pass_match'); }
else { $errors = array_merge($errors, passwordErrors($pass)); }
if (!is_file($schemaFile)) { $errors[] = t('err_schema_missing'); }
/* ── Veritabanı bağlantısı ve şema ── */
if (!$errors) {
$dsnBase = sprintf('mysql:host=%s;charset=utf8mb4', $host);
$opts = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsnBase, $dbuser, $dbpass, $opts);
} catch (PDOException $e) {
$errors[] = t('err_connect') . $e->getMessage();
}
if (!$errors) {
/* Veritabanını oluştur (yoksa) ve seç */
try {
$quoted = '`' . str_replace('`', '``', $dbname) . '`';
$pdo->exec("CREATE DATABASE IF NOT EXISTS $quoted "
. "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
$pdo->exec("USE $quoted");
} catch (PDOException $e) {
$errors[] = t('err_create_db') . $e->getMessage();
}
}
if (!$errors) {
try {
foreach (splitSqlStatements((string)file_get_contents($schemaFile)) as $sql) {
$pdo->exec($sql);
}
} catch (PDOException $e) {
$errors[] = t('err_schema') . $e->getMessage();
}
}
/* ── Yönetici hesabı ── */
if (!$errors) {
try {
$roleStmt = $pdo->query(
"SELECT role_id FROM roles WHERE deleted_at IS NULL ORDER BY role_level DESC LIMIT 1"
);
$roleId = $roleStmt->fetchColumn();
if ($roleId === false) {
$errors[] = t('err_role_missing');
} else {
$ins = $pdo->prepare(
"INSERT INTO users (username, email, password_hash, role_id, status)
VALUES (?, ?, ?, ?, 1)"
);
$ins->execute([
$username,
$email,
password_hash($pass, PASSWORD_DEFAULT),
(int)$roleId,
]);
}
} catch (PDOException $e) {
$errors[] = t('err_admin') . $e->getMessage();
}
}
/* ── config.php ── */
if (!$errors) {
$content = buildConfig([
'host' => $host,
'dbname' => $dbname,
'user' => $dbuser,
'pass' => $dbpass,
'app_name' => $appName,
'generated' => date('Y-m-d H:i'),
]);
if (@file_put_contents($configFile, $content) === false) {
$errors[] = t('err_config_write');
} else {
@chmod($configFile, 0640);
updateErrorDocuments($root);
/* Kurulum verisi bellekte kalmasın */
unset($_SESSION['install_csrf']);
$installed = true;
}
}
}
}
}
$loginUrl = 'login.php';
?>
<!DOCTYPE html>
<html lang="<?= htmlspecialchars($lang) ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars(t('title')) ?></title>
<link rel="stylesheet" href="assets/fonts/fonts.css">
<style>
:root {
--bg:#f8fafc; --surface:#fff; --border:#e2e8f0; --fg:#0f172a;
--muted:#64748b; --primary:#4f46e5; --primary-dark:#4338ca;
--ok:#16a34a; --ok-bg:#dcfce7; --bad:#dc2626; --bad-bg:#fee2e2;
}
@media (prefers-color-scheme: dark) {
:root {
--bg:#0f172a; --surface:#1e293b; --border:#334155; --fg:#f1f5f9;
--muted:#94a3b8; --primary:#6366f1; --primary-dark:#818cf8;
--ok:#4ade80; --ok-bg:#14532d; --bad:#f87171; --bad-bg:#7f1d1d;
}
}
*,*::before,*::after { box-sizing:border-box; }
body {
font-family:'Inter',system-ui,-apple-system,sans-serif; font-size:14px;
background:var(--bg); color:var(--fg); margin:0; padding:40px 20px;
-webkit-font-smoothing:antialiased;
}
.wrap { max-width:620px; margin:0 auto; }
.logo {
width:48px; height:48px; background:var(--primary); border-radius:12px;
display:flex; align-items:center; justify-content:center; color:#fff;
font-weight:700; font-size:18px; margin:0 auto 18px;
}
h1 { font-size:24px; font-weight:700; text-align:center; margin:0 0 6px; }
.sub { text-align:center; color:var(--muted); margin:0 0 28px; }
.card {
background:var(--surface); border:1px solid var(--border);
border-radius:12px; padding:22px; margin-bottom:18px;
}
.card h2 {
font-size:12px; font-weight:700; text-transform:uppercase;
letter-spacing:.08em; color:var(--muted); margin:0 0 16px;
}
.row { display:flex; justify-content:space-between; align-items:center;
padding:8px 0; border-bottom:1px solid var(--border); gap:12px; }
.row:last-child { border-bottom:0; }
.pill { font-size:11px; font-weight:700; padding:3px 9px; border-radius:99px; white-space:nowrap; }
.pill.ok { background:var(--ok-bg); color:var(--ok); }
.pill.bad { background:var(--bad-bg); color:var(--bad); }
.note { color:var(--muted); font-size:12px; }
label { display:block; font-weight:600; margin:0 0 6px; font-size:13px; }
.hint { font-weight:400; color:var(--muted); font-size:12px; }
input {
width:100%; padding:10px 12px; border:1px solid var(--border);
border-radius:8px; font:inherit; background:var(--bg); color:var(--fg);
}
input:focus { outline:2px solid var(--primary); outline-offset:-1px; border-color:var(--primary); }
.field { margin-bottom:14px; }
.grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
@media (max-width:520px) { .grid { grid-template-columns:1fr; } }
button {
width:100%; padding:12px; background:var(--primary); color:#fff; border:0;
border-radius:8px; font:inherit; font-weight:600; cursor:pointer;
}
button:hover { background:var(--primary-dark); }
button[disabled] { opacity:.5; cursor:not-allowed; }
.alert { border-radius:8px; padding:14px 16px; margin-bottom:18px; font-size:13px; }
.alert.bad { background:var(--bad-bg); color:var(--bad); }
.alert.ok { background:var(--ok-bg); color:var(--ok); }
.alert ul { margin:6px 0 0; padding-left:18px; }
.langs { text-align:center; margin-bottom:18px; font-size:12px; }
.langs a { color:var(--muted); text-decoration:none; padding:0 6px; }
.langs a.on { color:var(--primary); font-weight:700; }
.done { text-align:center; }
.done .big { font-size:44px; margin-bottom:8px; }
a.btn {
display:inline-block; margin-top:16px; padding:12px 24px; background:var(--primary);
color:#fff; text-decoration:none; border-radius:8px; font-weight:600;
}
</style>
</head>
<body>
<div class="wrap">
<div class="logo">AP</div>
<div class="langs">
<a href="?lang=tr" class="<?= $lang === 'tr' ? 'on' : '' ?>">Türkçe</a>|<a
href="?lang=en" class="<?= $lang === 'en' ? 'on' : '' ?>">English</a>
</div>
<?php if ($alreadyInstalled && !$installed): ?>
<h1><?= htmlspecialchars(t('locked')) ?></h1>
<p class="sub"><?= htmlspecialchars(t('locked_desc')) ?></p>
<div class="card done">
<a class="btn" href="<?= htmlspecialchars($loginUrl) ?>"><?= htmlspecialchars(t('go')) ?></a>
</div>
<?php elseif ($installed): ?>
<h1><?= htmlspecialchars(t('done')) ?></h1>
<p class="sub"><?= htmlspecialchars(t('done_desc')) ?></p>
<div class="card done">
<div class="big">✅</div>
<div class="alert bad" style="text-align:left;">
<strong><?= htmlspecialchars(t('done_warn')) ?></strong>
</div>
<a class="btn" href="<?= htmlspecialchars($loginUrl) ?>"><?= htmlspecialchars(t('go')) ?></a>
</div>
<?php else: ?>
<h1><?= htmlspecialchars(t('title')) ?></h1>
<p class="sub"><?= htmlspecialchars(t('subtitle')) ?></p>
<?php if ($errors): ?>
<div class="alert bad">
<ul>
<?php foreach ($errors as $e): ?>
<li><?= htmlspecialchars($e) ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="card">
<h2><?= htmlspecialchars(t('req')) ?></h2>
<?php foreach ($requirements as $r): ?>
<div class="row">
<div>
<?= htmlspecialchars($r['label']) ?>
<div class="note"><?= htmlspecialchars($r['note']) ?></div>
</div>
<span class="pill <?= $r['ok'] ? 'ok' : 'bad' ?>"><?= $r['ok'] ? 'OK' : '✕' ?></span>
</div>
<?php endforeach; ?>
</div>
<?php if (!$requirementsOk): ?>
<div class="alert bad"><?= htmlspecialchars(t('req_fail')) ?></div>
<?php endif; ?>
<form method="post">
<input type="hidden" name="csrf" value="<?= htmlspecialchars($_SESSION['install_csrf']) ?>">
<div class="card">
<h2><?= htmlspecialchars(t('db')) ?></h2>
<div class="grid">
<div class="field">
<label><?= htmlspecialchars(t('db_host')) ?></label>
<input name="host" value="<?= htmlspecialchars($form['host']) ?>" required>
</div>
<div class="field">
<label><?= htmlspecialchars(t('db_name')) ?>
<span class="hint">— <?= htmlspecialchars(t('db_hint')) ?></span>
</label>
<input name="dbname" value="<?= htmlspecialchars($form['dbname']) ?>" required>
</div>
<div class="field">
<label><?= htmlspecialchars(t('db_user')) ?></label>
<input name="dbuser" value="<?= htmlspecialchars($form['dbuser']) ?>" required>
</div>
<div class="field">
<label><?= htmlspecialchars(t('db_pass')) ?></label>
<input type="password" name="dbpass" autocomplete="off">
</div>
</div>
</div>
<div class="card">
<h2><?= htmlspecialchars(t('app')) ?></h2>
<div class="field">
<label><?= htmlspecialchars(t('app_name')) ?></label>
<input name="app_name" value="<?= htmlspecialchars($form['app_name']) ?>" maxlength="60" required>
</div>
</div>
<div class="card">
<h2><?= htmlspecialchars(t('admin')) ?></h2>
<p class="note" style="margin:-8px 0 16px;"><?= htmlspecialchars(t('admin_hint')) ?></p>
<div class="grid">
<div class="field">
<label><?= htmlspecialchars(t('username')) ?></label>
<input name="username" value="<?= htmlspecialchars($form['username']) ?>" maxlength="50" required>
</div>
<div class="field">
<label><?= htmlspecialchars(t('email')) ?></label>
<input type="email" name="email" value="<?= htmlspecialchars($form['email']) ?>" required>
</div>
<div class="field">
<label><?= htmlspecialchars(t('password')) ?>
<span class="hint">— <?= htmlspecialchars(passwordHint()) ?></span>
</label>
<input type="password" name="password" autocomplete="new-password" required>
</div>
<div class="field">
<label><?= htmlspecialchars(t('password2')) ?></label>
<input type="password" name="password2" autocomplete="new-password" required>
</div>
</div>
</div>
<button type="submit" <?= $requirementsOk ? '' : 'disabled' ?>>
<?= htmlspecialchars(t('submit')) ?>
</button>
</form>
<?php endif; ?>
</div>
</body>
</html>