-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
executable file
·1307 lines (1152 loc) · 54.2 KB
/
Copy pathinstall.php
File metadata and controls
executable file
·1307 lines (1152 loc) · 54.2 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
/**
* IT资产管理系统 - 安装程序
* 版本: 1.0
* 日期: 2025-08-23
*/
// 设置错误报告
error_reporting(E_ALL);
ini_set('display_errors', 1);
// 设置执行时间限制
set_time_limit(300);
// 辅助函数定义
function createDatabaseConnection($config) {
// MySQL 8.4.5 兼容性配置
$dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['dbname']};charset=utf8mb4";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci, sql_mode = ''"
];
$pdo = new PDO($dsn, $config['username'], $config['password'], $options);
return $pdo;
}
function checkStorageWritable() {
$dir = './storage';
if (!is_dir($dir)) {
return @mkdir($dir, 0755, true);
}
return is_writable($dir);
}
function checkConfigWritable() {
$dir = './src/config';
if (!is_dir($dir)) {
return @mkdir($dir, 0755, true);
}
return is_writable($dir);
}
function return_bytes($val) {
$val = trim($val);
$last = strtolower($val[strlen($val)-1]);
$val = (int)$val;
switch($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
function checkCommandExists($command) {
// 检查exec函数是否被禁用
if (in_array('exec', explode(',', ini_get('disable_functions')))) {
return false;
}
// 检查命令是否存在
$output = null;
$return_var = null;
// 根据操作系统使用不同的命令检测方式
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// Windows系统
exec("where $command 2>nul", $output, $return_var);
} else {
// Unix/Linux/macOS系统
exec("which $command 2>/dev/null", $output, $return_var);
}
return $return_var === 0 && !empty($output);
}
function checkExecFunction() {
// 检查exec函数是否可用
if (in_array('exec', explode(',', ini_get('disable_functions')))) {
return false;
}
// 尝试执行一个简单的命令
$output = null;
$return_var = null;
try {
exec('echo "test" 2>/dev/null', $output, $return_var);
return $return_var === 0;
} catch (Exception $e) {
return false;
}
}
// 处理AJAX请求 - 必须在任何输出之前
if (isset($_GET['action']) && $_GET['action'] === 'test_db') {
header('Content-Type: application/json');
try {
$config = [
'host' => $_POST['db_host'] ?? '',
'port' => $_POST['db_port'] ?? '3306',
'dbname' => $_POST['db_name'] ?? '',
'username' => $_POST['db_user'] ?? '',
'password' => $_POST['db_pass'] ?? ''
];
// 验证必填字段
if (empty($config['host']) || empty($config['dbname']) || empty($config['username'])) {
throw new Exception('请填写完整的数据库连接信息');
}
$pdo = createDatabaseConnection($config);
// 获取MySQL版本信息
$version = $pdo->query('SELECT VERSION()')->fetchColumn();
preg_match('/^(\d+)\.(\d+)\.(\d+)/', $version, $matches);
$majorVersion = (int)$matches[1];
$minorVersion = (int)$matches[2];
// 检查版本兼容性
$isCompatible = ($majorVersion > 5) || ($majorVersion == 5 && $minorVersion >= 7);
if (!$isCompatible) {
throw new Exception("MySQL版本过低 ({$version}),要求 MySQL 5.7+ 或 MySQL 8.0+");
}
// 检查数据库权限
$requiredPrivileges = ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'CREATE', 'ALTER', 'INDEX', 'DROP'];
$stmt = $pdo->query("SHOW GRANTS FOR CURRENT_USER()");
$grants = $stmt->fetchAll(PDO::FETCH_COLUMN);
$hasAllPrivileges = false;
foreach ($grants as $grant) {
if (strpos($grant, 'ALL PRIVILEGES') !== false ||
strpos($grant, 'GRANT ALL') !== false) {
$hasAllPrivileges = true;
break;
}
}
// 检查字符集支持
$stmt = $pdo->query("SHOW CHARACTER SET LIKE 'utf8mb4'");
$utf8mb4Support = $stmt->fetch() !== false;
// 检查存储引擎
$stmt = $pdo->query("SHOW ENGINES WHERE Engine = 'InnoDB' AND Support IN ('YES', 'DEFAULT')");
$innodbSupport = $stmt->fetch() !== false;
$warnings = [];
if (!$utf8mb4Support) {
$warnings[] = "数据库不支持 UTF8MB4 字符集";
}
if (!$innodbSupport) {
$warnings[] = "InnoDB 存储引擎不可用";
}
if (!$hasAllPrivileges) {
// 检查具体权限
$missingPrivileges = [];
foreach ($requiredPrivileges as $privilege) {
$found = false;
foreach ($grants as $grant) {
if (strpos(strtoupper($grant), strtoupper($privilege)) !== false) {
$found = true;
break;
}
}
if (!$found) {
$missingPrivileges[] = $privilege;
}
}
if (!empty($missingPrivileges)) {
$warnings[] = "可能缺少权限: " . implode(', ', $missingPrivileges);
}
}
$message = "数据库连接成功!\\n";
$message .= "MySQL版本: {$version}\\n";
$message .= "字符集支持: " . ($utf8mb4Support ? "✓ UTF8MB4" : "⚠ 有限") . "\\n";
$message .= "存储引擎: " . ($innodbSupport ? "✓ InnoDB" : "⚠ 有限") . "\\n";
if (!empty($warnings)) {
$message .= "\\n注意事项:\\n" . implode("\\n", array_map(function($w) { return "• " . $w; }, $warnings));
}
echo json_encode([
'success' => true,
'message' => $message,
'version' => $version,
'warnings' => $warnings
], JSON_UNESCAPED_UNICODE);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'message' => $e->getMessage()
], JSON_UNESCAPED_UNICODE);
}
exit;
}
// 检查是否已经安装
if (file_exists('./install.lock')) {
die('系统已经安装完成!如需重新安装,请删除 install.lock 文件。');
}
// 安装步骤
$step = isset($_GET['step']) ? (int)$_GET['step'] : 1;
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IT资产管理系统 - 安装向导</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Microsoft YaHei', Arial, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; margin: 0; }
.installer { background: white; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); width: 100%; max-width: 1400px; overflow: hidden; margin: 0 auto; }
.header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; text-align: center; }
.header h1 { font-size: 24px; margin-bottom: 5px; }
.header p { opacity: 0.9; font-size: 14px; }
.content { padding: 40px; max-width: none; }
.step-indicator { display: flex; justify-content: center; margin-bottom: 40px; }
.step { width: 30px; height: 30px; border-radius: 50%; background: #ddd; color: #666; display: flex; align-items: center; justify-content: center; margin: 0 10px; font-weight: bold; }
.step.active { background: #667eea; color: white; }
.step.completed { background: #28a745; color: white; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; color: #333; font-size: 15px; }
.form-group input, .form-group select { width: 100%; padding: 12px 16px; border: 1px solid #ddd; border-radius: 6px; font-size: 15px; transition: border-color 0.3s ease; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1); }
.btn { background: #667eea; color: white; padding: 12px 30px; border: none; border-radius: 5px; cursor: pointer; font-size: 14px; transition: background 0.3s; display: inline-block; text-decoration: none; }
.btn:hover { background: #5a6fd8; }
.btn:disabled { background: #ccc; cursor: not-allowed; }
.btn-group { text-align: center; margin-top: 30px; }
.alert { padding: 15px; margin-bottom: 20px; border-radius: 5px; }
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
.requirements { list-style: none; }
.requirements li {
padding: 12px 0;
border-bottom: 1px solid #eee;
display: flex;
justify-content: space-between;
align-items: flex-start;
line-height: 1.5;
}
.requirements li:last-child { border-bottom: none; }
.requirements h3 { margin: 30px 0 15px 0; padding: 12px 0; border-bottom: 2px solid #667eea; color: #667eea; font-size: 18px; font-weight: 600; }
.status { font-weight: bold; }
.status.ok { color: #28a745; }
.status.error { color: #dc3545; }
.status.warning { color: #ffc107; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }
.progress { background: #f0f0f0; border-radius: 10px; height: 20px; margin: 20px 0; overflow: hidden; }
.progress-bar { background: #667eea; height: 100%; transition: width 0.3s; }
pre { background: #f8f9fa; padding: 15px; border-radius: 5px; font-size: 12px; white-space: pre-wrap; max-height: 300px; overflow-y: auto; }
.form-group small { display: block; margin-top: 5px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.requirements h3:first-of-type { margin-top: 0; }
.requirements li small { color: #666; font-size: 11px; margin-top: 2px; }
.grid-info { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.grid-info h4 { margin: 0 0 12px 0; font-size: 15px; font-weight: 600; }
/* 环境检测结果的多列布局 */
.requirements-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
gap: 25px;
margin-top: 20px;
}
.requirements-section {
background: #fafafa;
padding: 20px;
border-radius: 8px;
border: 1px solid #e0e0e0;
}
.requirements-section h3 {
margin-top: 0;
margin-bottom: 15px;
padding-bottom: 8px;
border-bottom: 2px solid #667eea;
color: #667eea;
font-size: 16px;
font-weight: 600;
}
/* 数据库配置表单的网格布局 */
.form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 20px;
}
.form-grid .form-group {
margin-bottom: 0;
}
/* 超大屏幕优化 */
@media (min-width: 1600px) {
.installer { max-width: 1500px; }
.content { padding: 50px 60px; }
.requirements-grid {
grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
gap: 35px;
}
.form-grid { gap: 30px; }
.grid-info { gap: 40px; }
}
@media (max-width: 1200px) {
.installer { max-width: 95vw; }
.content { padding: 35px; }
}
@media (max-width: 1024px) {
.installer { max-width: 98vw; }
.content { padding: 30px; }
.requirements-grid { grid-template-columns: 1fr; gap: 20px; }
.form-grid { grid-template-columns: 1fr; gap: 15px; }
}
@media (max-width: 768px) {
.grid-info { grid-template-columns: 1fr; gap: 20px; }
.content { padding: 25px; }
.installer { width: 100%; }
.requirements li { flex-direction: column; align-items: flex-start; gap: 5px; }
.requirements-grid { gap: 15px; }
}
@media (max-width: 600px) {
body { padding: 8px; }
.content { padding: 20px; }
.installer { width: 100%; border-radius: 8px; }
.header { padding: 15px; }
.header h1 { font-size: 20px; }
.requirements-section { padding: 15px; }
.form-group label { font-size: 14px; }
.form-group input, .form-group select { padding: 10px 12px; font-size: 14px; }
}
@media (max-width: 480px) {
body { padding: 5px; }
.content { padding: 15px; }
.header { padding: 12px; }
.header h1 { font-size: 18px; }
.header p { font-size: 13px; }
.step { width: 26px; height: 26px; font-size: 13px; }
.requirements-section { padding: 12px; }
.requirements-section h3 { font-size: 15px; }
}
</style>
</head>
<body>
<div class="installer">
<div class="header">
<h1>IT资产管理系统</h1>
<p>安装向导 - 步骤 <?php echo $step; ?> / 4</p>
</div>
<div class="content">
<div class="step-indicator">
<div class="step <?php echo $step >= 1 ? ($step > 1 ? 'completed' : 'active') : ''; ?>">1</div>
<div class="step <?php echo $step >= 2 ? ($step > 2 ? 'completed' : 'active') : ''; ?>">2</div>
<div class="step <?php echo $step >= 3 ? ($step > 3 ? 'completed' : 'active') : ''; ?>">3</div>
<div class="step <?php echo $step >= 4 ? 'active' : ''; ?>">4</div>
</div>
<?php
switch ($step) {
case 1:
showWelcome();
break;
case 2:
showRequirements();
break;
case 3:
showDatabaseConfig();
break;
case 4:
performInstallation();
break;
}
?>
</div>
</div>
<script>
function nextStep() {
const currentStep = <?php echo $step; ?>;
window.location.href = 'install.php?step=' + (currentStep + 1);
}
function recheckEnvironment() {
const btn = event.target;
btn.disabled = true;
btn.innerHTML = '🔄 重新检测中...';
setTimeout(() => {
location.reload();
}, 1000);
}
function testDatabase() {
const formData = new FormData(document.getElementById('dbForm'));
const resultDiv = document.getElementById('db-test-result');
const testBtn = document.querySelector('button[onclick="testDatabase()"]');
const installBtn = document.getElementById('installBtn');
// 禁用按钮并显示测试中状态
testBtn.disabled = true;
testBtn.innerHTML = '🔄 正在测试...';
installBtn.disabled = true;
resultDiv.innerHTML = '<div class="alert alert-info">🔍 正在测试数据库连接,请稍候...</div>';
fetch('install.php?action=test_db', {
method: 'POST',
body: formData
})
.then(response => {
// 检查响应是否为JSON
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
throw new Error('服务器返回了非JSON格式的响应,请检查PHP错误日志');
}
return response.json();
})
.then(data => {
testBtn.disabled = false;
testBtn.innerHTML = '🔍 测试数据库连接';
if (data.success) {
let alertClass = 'alert-success';
let icon = '✅';
let title = '数据库连接测试成功!';
if (data.warnings && data.warnings.length > 0) {
alertClass = 'alert-warning';
icon = '⚠️';
title = '数据库连接成功,但有注意事项';
}
let messageHtml = data.message.replace(/\\n/g, '<br>');
resultDiv.innerHTML = `
<div class="alert ${alertClass}">
<strong>${icon} ${title}</strong><br>
<div style="margin-top: 10px; font-family: monospace; font-size: 13px; white-space: pre-line;">${messageHtml}</div>
</div>
`;
installBtn.disabled = false;
installBtn.style.background = '#28a745';
installBtn.innerHTML = '✅ 开始安装 →';
} else {
resultDiv.innerHTML = `
<div class="alert alert-error">
<strong>❌ 数据库连接失败</strong><br>
<div style="margin-top: 10px;">${data.message || '未知错误'}</div>
<div style="margin-top: 15px; padding: 10px; background: #f8f9fa; border-radius: 4px; font-size: 13px;">
<strong>常见解决方案:</strong><br>
• 检查数据库服务是否启动<br>
• 验证主机名和端口号<br>
• 确认用户名和密码正确<br>
• 检查数据库是否存在<br>
• 确认网络连接正常
</div>
</div>
`;
installBtn.disabled = true;
installBtn.style.background = '#6c757d';
installBtn.innerHTML = '开始安装 →';
}
})
.catch(error => {
console.error('Database test error:', error);
testBtn.disabled = false;
testBtn.innerHTML = '🔍 测试数据库连接';
resultDiv.innerHTML = `
<div class="alert alert-error">
<strong>❌ 测试过程发生错误</strong><br>
<div style="margin-top: 10px;">${error.message}</div>
<div style="margin-top: 15px; padding: 10px; background: #f8f9fa; border-radius: 4px; font-size: 13px;">
请检查:<br>
• PHP错误日志<br>
• 服务器网络连接<br>
• PHP PDO扩展是否正常<br>
• 防火墙设置
</div>
</div>
`;
installBtn.disabled = true;
installBtn.style.background = '#6c757d';
installBtn.innerHTML = '开始安装 →';
});
}
</script>
</body>
</html>
<?php
function showWelcome() {
?>
<h2>欢迎使用 IT资产管理系统</h2>
<div class="alert alert-info">
<strong>安装前请确保:</strong>
<ul style="margin-top: 10px; padding-left: 20px;">
<li>已准备好MySQL 5.7+ 或 MySQL 8.0+ 数据库</li>
<li>PHP版本 >= 7.4 (推荐 PHP 8.0+)</li>
<li>已开启必需的PHP扩展 (PDO, MySQL, JSON, cURL等)</li>
<li>Web服务器已正确配置 (Apache/Nginx)</li>
<li>具有目录写入权限</li>
</ul>
</div>
<div class="grid-info">
<div>
<h3>系统功能特性</h3>
<ul style="margin: 15px 0; padding-left: 20px; line-height: 1.8;">
<li>🖥️ 笔记本电脑资产管理</li>
<li>📺 显示器设备管理</li>
<li>🖨️ 打印机设备管理</li>
<li>🖥️ 主机设备管理</li>
<li>🏢 服务器资产管理</li>
<li>📦 耗材库存管理</li>
<li>🌐 IP地址段管理</li>
<li>👥 多角色权限管理</li>
<li>📊 资产统计分析</li>
<li>📝 操作日志记录</li>
</ul>
</div>
<div>
<h3>最低系统要求</h3>
<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; margin: 15px 0;">
<div style="margin-bottom: 20px;">
<h4 style="color: #667eea; margin-bottom: 12px; font-size: 15px; font-weight: 600;">服务器环境</h4>
<ul style="margin: 0; padding-left: 20px; font-size: 13px; line-height: 1.6;">
<li>PHP 7.4+ (推荐 8.0+)</li>
<li>MySQL 5.7+ / MySQL 8.0+</li>
<li>Apache 2.4+ / Nginx 1.18+</li>
<li>128MB+ PHP内存限制</li>
<li>启用exec系统函数</li>
</ul>
</div>
<div style="margin-bottom: 20px;">
<h4 style="color: #667eea; margin-bottom: 12px; font-size: 15px; font-weight: 600;">系统工具</h4>
<ul style="margin: 0; padding-left: 20px; font-size: 13px; line-height: 1.6;">
<li>ping (网络连通测试)</li>
<li>fping (批量ping工具)</li>
<li>nmap (端口扫描)</li>
<li>arp (ARP表查看)</li>
</ul>
</div>
<div>
<h4 style="color: #667eea; margin-bottom: 12px; font-size: 15px; font-weight: 600;">PHP扩展要求</h4>
<div style="font-size: 13px; color: #666; line-height: 1.6;">
PDO, PDO-MySQL, JSON, cURL, OpenSSL, MBString, Hash扩展
</div>
</div>
</div>
</div>
</div>
<div class="alert alert-warning">
<strong>重要提示:</strong>
<p style="margin: 5px 0;">安装过程将自动检测系统环境,只有通过所有必需检测项才能继续安装。如有问题,请联系系统管理员解决。</p>
<p style="margin: 5px 0; font-size: 13px;"><strong>系统工具说明:</strong>本系统需要ping、fping等网络工具来实现IP段扫描和设备发现功能。如果缺少这些工具,部分功能将无法正常使用。</p>
</div>
<div class="btn-group">
<button class="btn" onclick="nextStep()" style="font-size: 16px; padding: 15px 40px;">开始环境检测</button>
</div>
<style>
@media (max-width: 768px) {
[style*="grid-template-columns: 1fr 1fr"] {
grid-template-columns: 1fr !important;
gap: 25px !important;
}
}
</style>
<?php
}
function showRequirements() {
?>
<h2>环境检测</h2>
<p style="font-size: 16px; color: #666; margin-bottom: 25px;">正在检查系统环境是否满足安装要求,请确保所有必需项目都通过检测...</p>
<div class="alert alert-info">
<strong>系统要求:</strong>
<ul style="margin-top: 10px; padding-left: 20px;">
<li>PHP 7.4+ (推荐 PHP 8.0+)</li>
<li>MySQL 5.7+ 或 MySQL 8.0+</li>
<li>Web服务器 (Apache/Nginx)</li>
<li>至少 128MB PHP 内存限制</li>
<li>文件上传大小至少 16MB</li>
<li>启用exec函数用于系统命令执行</li>
<li>系统工具:ping、fping、nmap、arp等</li>
</ul>
</div>
<div class="requirements-grid">
<!-- PHP环境检测 -->
<div class="requirements-section">
<h3>PHP环境检测</h3>
<ul class="requirements">
<?php
// PHP版本检测
$phpVersion = PHP_VERSION;
$phpVersionOk = version_compare($phpVersion, '7.4.0', '>=');
$phpRecommended = version_compare($phpVersion, '8.0.0', '>=');
echo '<li><span>PHP版本 (当前: ' . $phpVersion . ')</span> <span class="status ' .
($phpVersionOk ? ($phpRecommended ? 'ok' : 'warning') : 'error') . '">' .
($phpVersionOk ? ($phpRecommended ? '✓ 优秀' : '⚠ 可用') : '✗ 版本过低') . '</span></li>';
// PHP扩展检测
$requiredExtensions = [
'PDO' => 'pdo',
'PDO MySQL' => 'pdo_mysql',
'JSON' => 'json',
'cURL' => 'curl',
'OpenSSL' => 'openssl',
'MBString' => 'mbstring',
'Hash' => 'hash',
];
$allExtensionsLoaded = true;
foreach ($requiredExtensions as $name => $ext) {
$loaded = extension_loaded($ext);
if (!$loaded) $allExtensionsLoaded = false;
$statusClass = $loaded ? 'ok' : 'error';
$statusText = $loaded ? '✓ 已加载' : '✗ 未安装';
echo "<li><span>{$name}扩展</span> <span class=\"status $statusClass\">$statusText</span></li>";
}
?>
</ul>
</div>
<!-- PHP配置检测 -->
<div class="requirements-section">
<h3>PHP配置检测</h3>
<ul class="requirements">
<?php
// PHP配置检测
$memoryLimit = ini_get('memory_limit');
$memoryLimitBytes = return_bytes($memoryLimit);
$memoryOk = $memoryLimitBytes >= 128 * 1024 * 1024; // 128MB
echo '<li><span>内存限制 (当前: ' . $memoryLimit . ')</span> <span class="status ' .
($memoryOk ? 'ok' : 'warning') . '">' .
($memoryOk ? '✓ 充足' : '⚠ 建议≥128M') . '</span></li>';
$uploadMaxFilesize = ini_get('upload_max_filesize');
$uploadBytes = return_bytes($uploadMaxFilesize);
$uploadOk = $uploadBytes >= 16 * 1024 * 1024; // 16MB
echo '<li><span>文件上传限制 (当前: ' . $uploadMaxFilesize . ')</span> <span class="status ' .
($uploadOk ? 'ok' : 'warning') . '">' .
($uploadOk ? '✓ 充足' : '⚠ 建议≥16M') . '</span></li>';
$maxExecutionTime = ini_get('max_execution_time');
$executionOk = $maxExecutionTime == 0 || $maxExecutionTime >= 60;
echo '<li><span>脚本执行时间 (当前: ' . ($maxExecutionTime == 0 ? '无限制' : $maxExecutionTime . 's') . ')</span> <span class="status ' .
($executionOk ? 'ok' : 'warning') . '">' .
($executionOk ? '✓ 充足' : '⚠ 建议≥60s') . '</span></li>';
?>
</ul>
</div>
<!-- 系统函数检测 -->
<div class="requirements-section">
<h3>系统函数检测</h3>
<ul class="requirements">
<?php
// 系统函数检测
$execEnabled = checkExecFunction();
echo '<li><span>exec函数</span> <span class="status ' .
($execEnabled ? 'ok' : 'error') . '">' .
($execEnabled ? '✓ 可用' : '✗ 被禁用') . '</span></li>';
// 检查其他可能被禁用的危险函数
$systemFunctions = [
'shell_exec' => function_exists('shell_exec') && !in_array('shell_exec', explode(',', ini_get('disable_functions'))),
'system' => function_exists('system') && !in_array('system', explode(',', ini_get('disable_functions'))),
'passthru' => function_exists('passthru') && !in_array('passthru', explode(',', ini_get('disable_functions'))),
];
$systemFunctionAvailable = false;
foreach ($systemFunctions as $func => $available) {
if ($available) {
$systemFunctionAvailable = true;
break;
}
}
echo '<li><span>系统执行函数</span> <span class="status ' .
($systemFunctionAvailable ? 'ok' : 'warning') . '">' .
($systemFunctionAvailable ? '✓ 可用' : '⚠ 受限') . '</span></li>';
?>
</ul>
</div>
<!-- 系统工具检测 -->
<div class="requirements-section">
<h3>系统工具检测</h3>
<ul class="requirements">
<?php
// 系统工具检测
$requiredTools = [
'ping' => [
'name' => 'ping命令',
'description' => '网络连通性测试',
'required' => true,
'windows_alt' => 'ping'
],
'fping' => [
'name' => 'fping命令',
'description' => '快速批量ping工具',
'required' => false,
'install_hint' => 'yum install fping 或 apt-get install fping'
],
'nmap' => [
'name' => 'nmap命令',
'description' => '网络端口扫描工具',
'required' => false,
'install_hint' => 'yum install nmap 或 apt-get install nmap'
],
'arp' => [
'name' => 'arp命令',
'description' => 'ARP表查看工具',
'required' => true,
'windows_alt' => 'arp'
]
];
$allRequiredToolsAvailable = true;
$toolsAvailable = 0;
$totalTools = count($requiredTools);
foreach ($requiredTools as $tool => $config) {
$available = false;
if ($execEnabled) {
$available = checkCommandExists($tool);
// Windows系统的特殊处理
if (!$available && !empty($config['windows_alt']) && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$available = checkCommandExists($config['windows_alt']);
}
}
if ($available) {
$toolsAvailable++;
}
if ($config['required'] && !$available) {
$allRequiredToolsAvailable = false;
}
$statusClass = $available ? 'ok' : ($config['required'] ? 'error' : 'warning');
$statusText = $available ? '✓ 可用' : ($config['required'] ? '✗ 缺失' : '⚠ 建议安装');
$toolInfo = '<span>' . $config['name'] . '<br><small style="color: #666; font-size: 12px;">' . $config['description'] . '</small>';
if (!$available && !empty($config['install_hint'])) {
$toolInfo .= '<br><small style="color: #ff6b35; font-size: 11px;">' . $config['install_hint'] . '</small>';
}
$toolInfo .= '</span>';
echo "<li>$toolInfo <span class=\"status $statusClass\">$statusText</span></li>";
}
// 显示工具可用性统计
echo '<li><span><strong>工具可用性统计</strong></span> <span class="status ' .
($toolsAvailable >= ($totalTools * 0.75) ? 'ok' : 'warning') . '">' .
"可用 {$toolsAvailable}/{$totalTools} 个工具" . '</span></li>';
?>
</ul>
</div>
<!-- 目录权限检测 -->
<div class="requirements-section">
<h3>目录权限检测</h3>
<ul class="requirements">
<?php
// 目录权限检测
$permissionChecks = [
'根目录写入权限' => is_writable('.'),
'storage目录' => checkStorageWritable(),
'src/config目录' => checkConfigWritable(),
];
$allPermissionsOk = true;
foreach ($permissionChecks as $item => $status) {
if (!$status) $allPermissionsOk = false;
$statusClass = $status ? 'ok' : 'error';
$statusText = $status ? '✓ 可写' : '✗ 无权限';
echo "<li><span>$item</span> <span class=\"status $statusClass\">$statusText</span></li>";
}
?>
</ul>
</div>
<!-- 必需文件检测 -->
<div class="requirements-section">
<h3>必需文件检测</h3>
<ul class="requirements">
<?php
// 文件检测
$requiredFiles = [
'SQL文件目录' => is_dir('./sql'),
'accounts.sql' => file_exists('./sql/accounts.sql'),
'server.sql' => file_exists('./sql/server.sql'),
'src目录结构' => is_dir('./src') && is_dir('./src/controllers') && is_dir('./src/models'),
];
$allFilesExist = true;
foreach ($requiredFiles as $item => $status) {
if (!$status) $allFilesExist = false;
$statusClass = $status ? 'ok' : 'error';
$statusText = $status ? '✓ 存在' : '✗ 缺失';
echo "<li><span>$item</span> <span class=\"status $statusClass\">$statusText</span></li>";
}
?>
</ul>
</div>
</div>
<?php
// 综合评估
$allPassed = $phpVersionOk && $allExtensionsLoaded && $allPermissionsOk && $allFilesExist && $execEnabled && $allRequiredToolsAvailable;
$hasWarnings = !$phpRecommended || !$memoryOk || !$uploadOk || !$executionOk || !$systemFunctionAvailable || ($toolsAvailable < $totalTools);
?>
<?php if ($allPassed): ?>
<?php if ($hasWarnings): ?>
<div class="alert alert-warning">
<strong>环境检测通过,但有建议优化项!</strong>
<p>系统可以正常安装,但建议优化标记为"⚠"的配置项以获得更好的性能。</p>
</div>
<?php else: ?>
<div class="alert alert-success">
<strong>恭喜!</strong> 系统环境检测全部通过,配置优秀,可以继续安装。
</div>
<?php endif; ?>
<div class="btn-group">
<button class="btn" onclick="nextStep()">下一步 - 数据库配置</button>
</div>
<?php else: ?>
<div class="alert alert-error">
<strong>环境检测失败!</strong>
<p>发现以下严重问题,必须解决后才能继续安装:</p>
<ul style="margin-top: 10px; padding-left: 20px;">
<?php if (!$phpVersionOk): ?>
<li>PHP版本过低,请升级到7.4或更高版本</li>
<?php endif; ?>
<?php if (!$allExtensionsLoaded): ?>
<li>缺少必需的PHP扩展,请安装标记为"✗"的扩展</li>
<?php endif; ?>
<?php if (!$allPermissionsOk): ?>
<li>目录权限不足,请设置相关目录的写入权限</li>
<?php endif; ?>
<?php if (!$allFilesExist): ?>
<li>缺少必需文件,请检查安装包完整性</li>
<?php endif; ?>
<?php if (!$execEnabled): ?>
<li>exec函数被禁用,请修改PHP配置启用exec函数</li>
<?php endif; ?>
<?php if (!$allRequiredToolsAvailable): ?>
<li>缺少必需的系统工具,请安装标记为"✗"的工具</li>
<?php endif; ?>
</ul>
<p><strong>解决方案:</strong></p>
<ol style="margin-top: 10px; padding-left: 20px;">
<li>联系服务器管理员解决环境问题</li>
<li>检查PHP配置和扩展安装</li>
<li>设置正确的目录权限 (chmod 755)</li>
<li>确保安装包文件完整</li>
<li>启用exec函数:从php.ini的disable_functions中移除exec</li>
<li>安装系统工具:使用包管理器安装ping、fping、nmap等工具</li>
<li>确保系统PATH环境变量包含工具路径</li>
</ol>
</div>
<div class="btn-group">
<button class="btn" onclick="recheckEnvironment()" style="background:#17a2b8;">🔄 重新检测环境</button>
<button class="btn" onclick="window.location.href='install.php?step=1'" style="background:#6c757d;">← 返回首页</button>
</div>
<?php endif; ?>
<?php
}
function showDatabaseConfig() {
?>
<h2>数据库配置</h2>
<p style="font-size: 16px; color: #666; margin-bottom: 25px;">请填写数据库连接信息。系统将测试连接并检查数据库权限:</p>
<div class="alert alert-info">
<strong>数据库要求:</strong>
<ul style="margin-top: 10px; padding-left: 20px;">
<li>MySQL 5.7+ 或 MySQL 8.0+ 数据库</li>
<li>数据库用户具有 CREATE, ALTER, INSERT, SELECT, UPDATE, DELETE 权限</li>
<li>推荐使用独立的数据库,避免与其他应用混用</li>
<li>确保数据库字符集支持 UTF8MB4</li>
</ul>
</div>
<form id="dbForm" method="post" action="install.php?step=4">
<div class="form-grid">
<div class="form-group">
<label for="db_host">数据库主机</label>
<input type="text" id="db_host" name="db_host" value="localhost" required placeholder="localhost 或 IP地址">
</div>
<div class="form-group">
<label for="db_port">端口号</label>
<input type="number" id="db_port" name="db_port" value="3306" required placeholder="默认: 3306">
</div>
</div>
<div class="form-group">
<label for="db_name">数据库名</label>
<input type="text" id="db_name" name="db_name" value="it_asset_management" required placeholder="数据库名称">
<small style="color: #666; font-size: 13px; margin-top: 5px; display: block;">建议使用独立的数据库,系统将创建多个数据表</small>
</div>
<div class="form-grid">
<div class="form-group">
<label for="db_user">用户名</label>
<input type="text" id="db_user" name="db_user" value="root" required placeholder="数据库用户名">
</div>
<div class="form-group">
<label for="db_pass">密码</label>
<input type="password" id="db_pass" name="db_pass" placeholder="数据库密码">
</div>
</div>
<div id="db-test-result" style="margin: 25px 0;"></div>
<div class="btn-group">
<button type="button" class="btn" onclick="testDatabase()" style="background: #17a2b8; margin-right: 15px;">🔍 测试数据库连接</button>
<button type="submit" class="btn" id="installBtn" disabled>开始安装 →</button>
</div>
</form>
<div class="alert alert-warning" style="margin-top: 30px;">
<strong>安全提示:</strong>
<ul style="margin-top: 10px; padding-left: 20px;">
<li>生产环境请不要使用 root 用户</li>
<li>建议创建专用数据库用户并设置强密码</li>
<li>定期备份数据库数据</li>
<li>安装完成后请妥善保管数据库配置信息</li>
</ul>
</div>
<style>
@media (max-width: 768px) {
.form-group:has(#db_host),
.form-group:has(#db_port),
.form-group:has(#db_user),
.form-group:has(#db_pass) {
grid-column: 1 / -1;
}
[style*="grid-template-columns: 1fr 1fr"] {
grid-template-columns: 1fr !important;
gap: 20px !important;
}
}
</style>
<?php
}
function performInstallation() {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$config = [
'host' => $_POST['db_host'],
'port' => $_POST['db_port'],
'dbname' => $_POST['db_name'],
'username' => $_POST['db_user'],
'password' => $_POST['db_pass']
];
echo '<h2>正在安装系统...</h2>';
echo '<div class="progress"><div class="progress-bar" id="progressBar" style="width: 0%"></div></div>';
echo '<div id="installLog"><pre id="logContent"></pre></div>';
echo '<script>
let progress = 0;
let logContent = document.getElementById("logContent");
let progressBar = document.getElementById("progressBar");