-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscript.js
More file actions
1491 lines (1296 loc) · 49 KB
/
script.js
File metadata and controls
1491 lines (1296 loc) · 49 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
// 全局变量
let commandHistory = [];
let customTemplates = [];
let currentLanguage = 'zh-CN';
let isDarkMode = false;
// 语言配置
const languages = {
'zh-CN': {
title: 'SQLMap命令生成器',
description: '快速生成SQLMap命令,支持多种注入方式和高级选项',
// ... 其他翻译
},
'en-US': {
title: 'SQLMap Command Generator',
description: 'Quickly generate SQLMap commands with multiple injection methods and advanced options',
// ... 其他翻译
}
};
// 预设模板
const presetTemplates = {
'basic': {
name: '基本扫描',
description: '基本的SQL注入扫描配置',
options: {
'level': '--level 2',
'risk': '--risk 1',
'threads': '--threads 1',
'batch': true,
'random-agent': true
}
},
'waf-bypass': {
name: 'WAF绕过',
description: '针对WAF的绕过配置',
options: {
'tamper': '--tamper=space2comment,between,charencode',
'waf': true,
'identify-waf': true,
'random-agent': true,
'delay': '--delay 2',
'timeout': '--timeout 30'
}
},
'shell': {
name: '获取Shell',
description: '尝试获取操作系统Shell的配置',
options: {
'os-shell': true,
'os-pwn': true,
'level': '--level 5',
'risk': '--risk 3',
'threads': '--threads 1'
}
},
'dump': {
name: '数据导出',
description: '导出数据库数据的配置',
options: {
'dump': true,
'dump-all': true,
'batch': true,
'threads': '--threads 4'
}
},
'enum': {
name: '信息枚举',
description: '枚举数据库信息的配置',
options: {
'dbs': true,
'tables': true,
'columns': true,
'batch': true,
'threads': '--threads 2'
}
},
'fast-scan': {
name: '高速扫描',
description: '快速扫描多个可能的注入点',
options: {
'level': '--level 1',
'risk': '--risk 1',
'threads': '--threads 10',
'batch': true,
'smart': true,
'random-agent': true
}
},
'time-based': {
name: '时间盲注',
description: '针对时间延迟盲注的专用配置',
options: {
'technique': '--technique=T',
'time-sec': '--time-sec=2',
'timeout': '--timeout 30',
'level': '--level 3',
'risk': '--risk 2'
}
},
'boolean-based': {
name: '布尔盲注',
description: '针对布尔型盲注的专用配置',
options: {
'technique': '--technique=B',
'level': '--level 3',
'risk': '--risk 2'
}
},
'error-based': {
name: '报错注入',
description: '利用数据库错误信息的注入配置',
options: {
'technique': '--technique=E',
'level': '--level 3',
'risk': '--risk 3'
}
},
'union-based': {
name: '联合查询',
description: '针对联合查询注入的专用配置',
options: {
'technique': '--technique=U',
'union-cols': '--union-cols=8-12',
'level': '--level 3',
'risk': '--risk 2'
}
},
'mysql': {
name: 'MySQL专用',
description: '针对MySQL数据库的优化配置',
options: {
'dbms': '--dbms=mysql',
'no-cast': true,
'technique': '--technique=BEUSTQ',
'level': '--level 3',
'risk': '--risk 2'
}
},
'mssql': {
name: 'MSSQL专用',
description: '针对Microsoft SQL Server的优化配置',
options: {
'dbms': '--dbms=mssql',
'technique': '--technique=BEUSTQ',
'level': '--level 3',
'risk': '--risk 2'
}
},
'oracle': {
name: 'Oracle专用',
description: '针对Oracle数据库的优化配置',
options: {
'dbms': '--dbms=oracle',
'technique': '--technique=BEUSTQ',
'level': '--level 3',
'risk': '--risk 2'
}
},
'postgresql': {
name: 'PostgreSQL专用',
description: '针对PostgreSQL数据库的优化配置',
options: {
'dbms': '--dbms=postgresql',
'technique': '--technique=BEUSTQ',
'level': '--level 3',
'risk': '--risk 2'
}
},
'cloudflare': {
name: 'Cloudflare绕过',
description: '针对Cloudflare WAF的绕过配置',
options: {
'tamper': '--tamper=cloudflare,space2comment,randomcase',
'random-agent': true,
'delay': '--delay 3',
'timeout': '--timeout 35',
'identify-waf': true,
'waf': true
}
},
'modsecurity': {
name: 'ModSecurity绕过',
description: '针对ModSecurity WAF的绕过配置',
options: {
'tamper': '--tamper=modsecurityversioned,space2comment,space2dash',
'random-agent': true,
'delay': '--delay 2',
'identify-waf': true,
'waf': true
}
},
'mobile-app': {
name: '移动应用',
description: '针对移动应用API的测试配置',
options: {
'mobile': true,
'random-agent': true,
'level': '--level 3',
'risk': '--risk 2',
'technique': '--technique=BEUSTQ'
}
},
'fingerprint': {
name: '数据库指纹',
description: '仅用于识别后端数据库类型',
options: {
'fingerprint': true,
'batch': true,
'random-agent': true,
'level': '--level 1',
'risk': '--risk 1'
}
},
'safe-scan': {
name: '安全扫描',
description: '低风险、低侵入性的扫描配置',
options: {
'level': '--level 1',
'risk': '--risk 1',
'batch': true,
'technique': '--technique=B',
'threads': '--threads 1',
'time-sec': '--time-sec=1',
'text-only': true
}
}
};
// 参数依赖关系
const parameterDependencies = {
'os-shell': ['level', 'risk'],
'os-pwn': ['os-shell'],
'dump-all': ['dump'],
'tables': ['dbs'],
'columns': ['tables'],
'check-tor': ['tor']
};
// 初始化
document.addEventListener('DOMContentLoaded', () => {
try {
console.log('初始化应用...');
initializeEventListeners();
loadCustomTemplates();
loadCommandHistory();
initializeDarkMode();
initializeLanguage();
initializeValidation();
// 初始化手风琴面板的内容高度
const activeAccordions = document.querySelectorAll('.accordion.active');
activeAccordions.forEach(accordion => {
const content = accordion.querySelector('.accordion-content');
if (content) {
content.style.maxHeight = content.scrollHeight + 'px';
}
});
// 初始化历史记录列表
updateHistoryList();
console.log('初始化完成');
} catch (err) {
console.error('初始化失败:', err);
}
});
// 事件监听器初始化
function initializeEventListeners() {
// 按钮事件
document.getElementById('generate-button').addEventListener('click', generateCommand);
document.getElementById('reset-button').addEventListener('click', resetOptions);
document.getElementById('copy-button').addEventListener('click', copyCommand);
document.getElementById('toggle-checkboxes').addEventListener('click', toggleCheckboxes);
document.getElementById('toggle-all').addEventListener('click', toggleAllAccordions);
document.getElementById('load-template').addEventListener('click', openTemplateModal);
document.getElementById('save-template').addEventListener('click', saveCurrentTemplate);
// 添加清除历史记录按钮事件监听
const clearHistoryButton = document.getElementById('clear-history');
if (clearHistoryButton) {
clearHistoryButton.addEventListener('click', clearCommandHistory);
}
// 模板模态框事件
const closeModalBtn = document.querySelector('.close-modal');
if (closeModalBtn) {
closeModalBtn.addEventListener('click', closeTemplateModal);
}
document.querySelectorAll('.template-tab').forEach(tab => {
tab.addEventListener('click', () => switchTemplateTab(tab));
});
document.querySelectorAll('.template-item').forEach(item => {
item.addEventListener('click', () => loadTemplate(item.dataset.template));
});
// 保存自定义模板按钮
const saveCustomTemplateBtn = document.getElementById('save-custom-template');
if (saveCustomTemplateBtn) {
saveCustomTemplateBtn.addEventListener('click', saveCurrentTemplate);
}
// 初始化手风琴菜单
initializeAccordions();
// 参数依赖关系事件
Object.keys(parameterDependencies).forEach(param => {
const element = document.getElementById(param);
if (element) {
element.addEventListener('change', () => handleParameterDependency(param));
}
});
// 输入验证事件
document.querySelectorAll('input, select').forEach(element => {
element.addEventListener('input', () => validateInput(element));
});
// 添加复选框状态变化事件监听,更新全选按钮状态
document.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
checkbox.addEventListener('change', updateToggleCheckboxesButton);
});
// 初始化更新全选按钮状态
updateToggleCheckboxesButton();
}
// 生成命令
function generateCommand() {
// 获取当前激活的输出元素
const outputElement = document.getElementById('output-command');
// 添加加载指示
outputElement.classList.add('loading');
outputElement.value = '生成命令中...';
// 延迟一点以显示加载动画
setTimeout(() => {
// 实际生成命令
const command = buildCommand();
// 动画效果展示命令
if (command) {
// 先淡入淡出
outputElement.style.opacity = '0';
setTimeout(() => {
outputElement.value = command;
outputElement.style.opacity = '1';
outputElement.classList.remove('loading');
validateCommand(command);
}, 300);
} else {
outputElement.value = '';
outputElement.classList.remove('loading');
showWarning('请提供目标URL或其他必要参数');
}
}, 300);
}
// 构建命令
function buildCommand() {
let command = 'python sqlmap.py';
// 目标选项
const targetUrl = document.getElementById('target-url').value;
const targetFile = document.getElementById('target-file').value;
const requestFile = document.getElementById('request-file').value;
if (targetUrl) command += ` -u "${targetUrl}"`;
if (targetFile) command += ` -m "${targetFile}"`;
if (requestFile) command += ` -r "${requestFile}"`;
// 请求选项
const method = document.getElementById('method').value;
const data = document.getElementById('data').value;
const cookie = document.getElementById('cookie').value;
const userAgent = document.getElementById('user-agent').value;
const randomAgent = document.getElementById('random-agent').checked;
if (method) command += ` ${method}`;
if (data) command += ` --data="${data}"`;
if (cookie) command += ` --cookie="${cookie}"`;
if (userAgent) command += ` --user-agent="${userAgent}"`;
if (randomAgent) command += ' --random-agent';
// 注入选项
const param = document.getElementById('param').value;
const dbms = document.getElementById('dbms').value;
const technique = document.getElementById('technique').value;
const inlineQuery = document.getElementById('inline-query').value;
const prefix = document.getElementById('prefix').value;
const suffix = document.getElementById('suffix').value;
const code = document.getElementById('code').checked;
const osShell = document.getElementById('os-shell').checked;
const osPwn = document.getElementById('os-pwn').checked;
if (param) command += ` -p "${param}"`;
if (dbms) command += ` ${dbms}`;
if (technique) command += ` ${technique}`;
if (inlineQuery) command += ` --sql-query="${inlineQuery}"`;
if (prefix) command += ` --prefix="${prefix}"`;
if (suffix) command += ` --suffix="${suffix}"`;
if (code) command += ' --code-exec';
if (osShell) command += ' --os-shell';
if (osPwn) command += ' --os-pwn';
// 探测选项
const level = document.querySelector('input[name="level"]:checked').value;
const risk = document.querySelector('input[name="risk"]:checked').value;
if (level) command += ` ${level}`;
if (risk) command += ` ${risk}`;
// 枚举选项
const dbs = document.getElementById('dbs').checked;
const tables = document.getElementById('tables').checked;
const columns = document.getElementById('columns').checked;
const dump = document.getElementById('dump').checked;
const dumpAll = document.getElementById('dump-all').checked;
const dbName = document.getElementById('db-name').value;
const tableName = document.getElementById('table-name').value;
if (dbs) command += ' --dbs';
if (tables) command += ' --tables';
if (columns) command += ' --columns';
if (dump) command += ' --dump';
if (dumpAll) command += ' --dump-all';
if (dbName) command += ` -D "${dbName}"`;
if (tableName) command += ` -T "${tableName}"`;
// 高级选项
const threads = document.getElementById('threads').value;
const verbose = document.querySelector('input[name="verbose"]:checked').value;
const batch = document.getElementById('batch').checked;
const tor = document.getElementById('tor').checked;
const checkTor = document.getElementById('check-tor').checked;
const proxy = document.getElementById('proxy').value;
const delay = document.getElementById('delay').value;
const timeout = document.getElementById('timeout').value;
const retries = document.getElementById('retries').value;
const timeSec = document.getElementById('time-sec').value;
const unionCols = document.getElementById('union-cols').value;
const fingerprint = document.getElementById('fingerprint').checked;
if (threads) command += ` --threads ${threads}`;
if (verbose) command += ` ${verbose}`;
if (batch) command += ' --batch';
if (tor) command += ' --tor';
if (checkTor) command += ' --check-tor';
if (proxy) command += ` --proxy="${proxy}"`;
if (delay) command += ` --delay ${delay}`;
if (timeout) command += ` --timeout ${timeout}`;
if (retries) command += ` --retries ${retries}`;
if (timeSec) command += ` --time-sec ${timeSec}`;
if (unionCols) command += ` --union-cols ${unionCols}`;
if (fingerprint) command += ' --fingerprint';
// 绕过选项
const tamper = document.getElementById('tamper').value;
const tamperMultiple = document.getElementById('tamper-multiple').value;
const waf = document.getElementById('waf').checked;
const identifyWaf = document.getElementById('identify-waf').checked;
const mobile = document.getElementById('mobile').checked;
const smart = document.getElementById('smart').checked;
const textOnly = document.getElementById('text-only').checked;
const noCast = document.getElementById('no-cast').checked;
const noEscape = document.getElementById('no-escape').checked;
if (tamper) command += ` ${tamper}`;
if (tamperMultiple) command += ` --tamper="${tamperMultiple}"`;
if (waf) command += ' --waf';
if (identifyWaf) command += ' --identify-waf';
if (mobile) command += ' --mobile';
if (smart) command += ' --smart';
if (textOnly) command += ' --text-only';
if (noCast) command += ' --no-cast';
if (noEscape) command += ' --no-escape';
// 其他选项
const customOptions = document.getElementById('custom-options').value;
if (customOptions) command += ` ${customOptions}`;
return command;
}
// 重置选项
function resetOptions() {
document.querySelectorAll('input[type="text"]').forEach(input => input.value = '');
document.querySelectorAll('input[type="number"]').forEach(input => input.value = input.defaultValue);
document.querySelectorAll('select').forEach(select => select.selectedIndex = 0);
document.querySelectorAll('input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
document.querySelectorAll('input[type="radio"]').forEach(radio => {
if (radio.value.includes('1')) radio.checked = true;
else radio.checked = false;
});
document.getElementById('output-command').value = '';
// 更新全选按钮状态
updateToggleCheckboxesButton();
}
// 复制命令
function copyCommand() {
const commandText = document.getElementById('output-command').value;
if (!commandText.trim()) {
showWarning('没有可复制的命令');
return;
}
navigator.clipboard.writeText(commandText).then(() => {
const copyButton = document.getElementById('copy-button');
copyButton.classList.add('copied');
copyButton.innerHTML = '<i class="fas fa-check"></i> 已复制';
// 添加脉冲动画
copyButton.style.animation = 'pulse 0.3s ease-in-out';
setTimeout(() => {
copyButton.classList.remove('copied');
copyButton.innerHTML = '<i class="fas fa-copy"></i> 复制命令';
copyButton.style.animation = '';
}, 2000);
addToHistory(commandText);
showSuccess('命令已复制到剪贴板');
}).catch(err => {
console.error('复制失败:', err);
showError('复制失败,请手动复制');
});
}
// 切换复选框状态
function toggleCheckboxes() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
const allChecked = Array.from(checkboxes).every(checkbox => checkbox.checked);
checkboxes.forEach(checkbox => {
checkbox.checked = !allChecked;
});
// 更新全选按钮状态
updateToggleCheckboxesButton();
}
// 更新全选按钮状态
function updateToggleCheckboxesButton() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
const allChecked = checkboxes.length > 0 && Array.from(checkboxes).every(checkbox => checkbox.checked);
const toggleButton = document.getElementById('toggle-checkboxes');
if (toggleButton) {
if (allChecked) {
toggleButton.innerHTML = '<i class="fas fa-check-square"></i> 取消全选';
toggleButton.classList.add('all-checked');
} else {
toggleButton.innerHTML = '<i class="fas fa-square"></i> 全选';
toggleButton.classList.remove('all-checked');
}
}
}
// 切换手风琴菜单
function toggleAccordion(accordion) {
const content = accordion.querySelector('.accordion-content');
if (accordion.classList.contains('active')) {
// 折叠动画
content.style.maxHeight = content.scrollHeight + 'px';
setTimeout(() => {
content.style.maxHeight = '0px';
setTimeout(() => {
accordion.classList.remove('active');
}, 300);
}, 10);
} else {
// 展开动画
accordion.classList.add('active');
content.style.maxHeight = content.scrollHeight + 'px';
}
}
// 切换所有手风琴菜单
function toggleAllAccordions() {
const accordions = document.querySelectorAll('.accordion');
const isAnyCollapsed = Array.from(accordions).some(accordion => !accordion.classList.contains('active'));
accordions.forEach(accordion => {
const content = accordion.querySelector('.accordion-content');
if (isAnyCollapsed) {
// 全部展开
accordion.classList.add('active');
content.style.maxHeight = content.scrollHeight + 'px';
} else {
// 全部折叠
content.style.maxHeight = content.scrollHeight + 'px';
setTimeout(() => {
content.style.maxHeight = '0px';
setTimeout(() => {
accordion.classList.remove('active');
}, 300);
}, 10);
}
});
// 更新按钮图标
const toggleIcon = document.querySelector('#toggle-all i');
toggleIcon.className = isAnyCollapsed ? 'fas fa-chevron-up' : 'fas fa-chevron-down';
}
// 打开模板模态框
function openTemplateModal() {
const modal = document.getElementById('template-modal');
if (!modal) {
console.error('找不到模板模态框元素');
return;
}
modal.style.display = 'flex';
// 添加动画效果
setTimeout(() => {
modal.classList.add('active');
document.body.style.overflow = 'hidden'; // 阻止背景滚动
// 加载模板列表
updateCustomTemplateList();
// 默认激活预设模板选项卡
const defaultTab = document.querySelector('.template-tab[data-tab="preset"]');
if (defaultTab) {
// 确保所有选项卡内容都正确初始化
document.querySelectorAll('.template-content').forEach(content => {
content.style.opacity = '0';
content.style.transform = 'translateY(10px)';
content.classList.remove('active');
});
// 重置所有选项卡状态
document.querySelectorAll('.template-tab').forEach(tab => {
tab.classList.remove('active');
});
// 激活默认选项卡
defaultTab.classList.add('active');
// 激活默认内容
const defaultContent = document.getElementById('preset-templates');
if (defaultContent) {
defaultContent.classList.add('active');
// 使用requestAnimationFrame确保DOM更新后再应用动画
requestAnimationFrame(() => {
setTimeout(() => {
defaultContent.style.opacity = '1';
defaultContent.style.transform = 'translateY(0)';
// 初始化选项卡指示器
updateTabIndicator(defaultTab);
}, 50);
});
}
}
}, 50);
}
// 关闭模板模态框
function closeTemplateModal() {
const modal = document.getElementById('template-modal');
// 添加关闭动画
modal.classList.remove('active');
// 延迟隐藏模态框,等待动画完成
setTimeout(() => {
modal.style.display = 'none';
document.body.style.overflow = ''; // 恢复背景滚动
}, 300);
}
// 切换模板选项卡
function switchTemplateTab(tab) {
if (!tab) return;
// 获取所有选项卡和内容
const tabs = document.querySelectorAll('.template-tab');
const contents = document.querySelectorAll('.template-content');
// 获取目标内容
const target = tab.getAttribute('data-tab');
const targetContent = document.getElementById(`${target}-templates`);
if (!targetContent) {
console.error(`找不到模板内容元素: ${target}-templates`);
return;
}
// 检查是否已经是激活状态
if (tab.classList.contains('active')) return;
// 获取当前激活的内容
const activeContent = document.querySelector('.template-content.active');
// 计算动画方向(左右)
let direction = 1; // 默认向右切换
if (activeContent) {
const activeTabId = activeContent.id.replace('-templates', '');
const activeTab = document.querySelector(`.template-tab[data-tab="${activeTabId}"]`);
if (activeTab) {
// 找出当前激活选项卡的索引和目标选项卡的索引
const activeIndex = Array.from(tabs).indexOf(activeTab);
const targetIndex = Array.from(tabs).indexOf(tab);
direction = targetIndex > activeIndex ? 1 : -1;
}
}
// 设置内容区域动画方向
if (activeContent) {
// 淡出当前内容
activeContent.style.opacity = '0';
activeContent.style.transform = `translateY(${10 * direction}px)`;
}
// 更新选项卡样式
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// 更新选项卡下的滑动指示器
updateTabIndicator(tab);
// 延迟一点后切换内容,让淡出动画有时间执行
setTimeout(() => {
// 移除所有内容的激活状态
contents.forEach(c => c.classList.remove('active'));
// 预设目标内容的起始状态
targetContent.style.opacity = '0';
targetContent.style.transform = `translateY(${-10 * direction}px)`;
targetContent.classList.add('active');
// 强制重绘
void targetContent.offsetWidth;
// 应用动画效果
requestAnimationFrame(() => {
targetContent.style.opacity = '1';
targetContent.style.transform = 'translateY(0)';
});
}, 150);
}
// 更新选项卡指示器
function updateTabIndicator(activeTab) {
const tabsContainer = document.querySelector('.template-tabs');
if (!tabsContainer) return;
const indicator = tabsContainer.querySelector('.tab-indicator') ||
createTabIndicator(tabsContainer);
// 根据激活的选项卡更新指示器位置和宽度
const tabRect = activeTab.getBoundingClientRect();
const containerRect = tabsContainer.getBoundingClientRect();
indicator.style.left = `${tabRect.left - containerRect.left}px`;
indicator.style.width = `${tabRect.width}px`;
}
// 创建选项卡指示器
function createTabIndicator(tabsContainer) {
const indicator = document.createElement('div');
indicator.className = 'tab-indicator';
indicator.style.position = 'absolute';
indicator.style.bottom = '0';
indicator.style.height = '3px';
indicator.style.backgroundColor = 'var(--primary-color)';
indicator.style.transition = 'left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1)';
indicator.style.pointerEvents = 'none';
indicator.style.zIndex = '2';
tabsContainer.appendChild(indicator);
return indicator;
}
// 加载模板
function loadTemplate(templateId) {
let template;
// 检查是否是自定义模板(格式为 'custom-X')
if (templateId && templateId.startsWith('custom-')) {
const index = parseInt(templateId.split('-')[1]);
if (!isNaN(index) && index >= 0 && index < customTemplates.length) {
template = customTemplates[index];
}
} else {
// 否则是预设模板
template = presetTemplates[templateId];
}
if (!template) {
console.error(`找不到模板: ${templateId}`);
return;
}
console.log(`加载模板: ${template.name}`);
// 应用模板选项
Object.entries(template.options).forEach(([key, value]) => {
const element = document.getElementById(key);
if (element) {
if (element.type === 'checkbox') {
element.checked = value;
} else if (element.type === 'radio') {
const radio = document.querySelector(`input[name="${key}"][value="${value}"]`);
if (radio) {
radio.checked = true;
}
} else {
element.value = value;
}
}
});
closeTemplateModal();
generateCommand();
// 更新全选按钮状态,确保与当前复选框状态同步
updateToggleCheckboxesButton();
showMessage(`已应用模板: ${template.name}`, 'success');
}
// 保存当前模板
function saveCurrentTemplate() {
const templateNameInput = document.getElementById('template-name');
const templateDescInput = document.getElementById('template-description');
if (!templateNameInput || !templateDescInput) {
showMessage('找不到模板名称或描述输入框', 'error');
return;
}
const name = templateNameInput.value;
const description = templateDescInput.value;
if (!name || !description) {
showMessage('请填写模板名称和描述', 'warning');
return;
}
const template = {
id: `custom-${Date.now()}`,
name,
description,
options: getCurrentOptions()
};
customTemplates.push(template);
saveCustomTemplates();
updateCustomTemplateList();
templateNameInput.value = '';
templateDescInput.value = '';
// 切换到自定义模板选项卡显示新添加的模板
const customTab = document.querySelector('.template-tab[data-tab="custom"]');
if (customTab) {
switchTemplateTab(customTab);
}
showMessage('模板保存成功', 'success');
}
// 获取当前选项
function getCurrentOptions() {
const options = {};
document.querySelectorAll('input[type="checkbox"]').forEach(element => {
if (element.id) {
options[element.id] = element.checked;
}
});
document.querySelectorAll('input[type="radio"]:checked').forEach(element => {
if (element.name) {
options[element.name] = element.value;
}
});
document.querySelectorAll('input[type="text"], input[type="number"], select').forEach(element => {
if (element.id && element.value.trim()) {
options[element.id] = element.value;
}
});
return options;
}
// 加载自定义模板
function loadCustomTemplates() {
const saved = localStorage.getItem('customTemplates');
if (saved) {
customTemplates = JSON.parse(saved);
updateCustomTemplateList();
}
}
// 保存自定义模板
function saveCustomTemplates() {
localStorage.setItem('customTemplates', JSON.stringify(customTemplates));
}
// 更新自定义模板列表
function updateCustomTemplateList() {
const customTemplateList = document.querySelector('.custom-template-list');
if (!customTemplateList) {
console.error('找不到自定义模板列表元素');
return;
}
customTemplateList.innerHTML = '';
if (customTemplates.length === 0) {
const emptyMsg = document.createElement('div');
emptyMsg.className = 'empty-templates';
emptyMsg.textContent = '没有保存的自定义模板';
customTemplateList.appendChild(emptyMsg);
return;
}
customTemplates.forEach((template, index) => {
const templateItem = document.createElement('div');
templateItem.className = 'template-item';
templateItem.setAttribute('data-template', `custom-${index}`);
templateItem.innerHTML = `
<div class="template-info">
<h4>${template.name}</h4>
<p>${template.description || '无描述'}</p>
</div>
<div class="template-actions">
<button class="use-template" onclick="loadTemplate('custom-${index}')">
<i class="fas fa-check"></i> 使用
</button>
<button class="delete-template" onclick="deleteTemplate(${index})">
<i class="fas fa-trash"></i>
</button>
</div>
`;
// 添加点击事件,整个模板项也可以点击加载
templateItem.addEventListener('click', (e) => {
// 避免点击按钮时重复触发
if (!e.target.closest('.use-template') && !e.target.closest('.delete-template')) {
loadTemplate(`custom-${index}`);
}
});
// 添加进入动画
templateItem.style.opacity = '0';
templateItem.style.transform = 'translateY(10px)';
customTemplateList.appendChild(templateItem);
// 错开显示时间,创建瀑布流效果
setTimeout(() => {
templateItem.style.opacity = '1';
templateItem.style.transform = 'translateY(0)';
}, 50 * index);
});
}
// 删除模板
function deleteTemplate(index) {
if (!confirm('确定要删除这个模板吗?')) {
return;
}
customTemplates.splice(index, 1);
saveCustomTemplates();
updateCustomTemplateList();
showMessage('模板已删除', 'success');
}
// 加载命令历史
function loadCommandHistory() {
try {
const savedHistory = localStorage.getItem('sqlmapCommandHistory');
if (savedHistory) {
commandHistory = JSON.parse(savedHistory);
updateHistoryList();
}
} catch (err) {
console.error('加载历史记录失败:', err);
showMessage('加载历史记录失败', 'error');
// 如果加载失败,重置为空数组
commandHistory = [];
}