-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.php
More file actions
executable file
·715 lines (680 loc) · 22.9 KB
/
Copy pathtool.php
File metadata and controls
executable file
·715 lines (680 loc) · 22.9 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
<?php
$secret_key = "vuba1";
$key = isset($_GET['key']) ? $_GET['key'] : '';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Response Viewer</title>
<style>
:root {
--gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
--color-primary: #667eea;
--color-text: #333;
--shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
--shadow-md: 0 4px 20px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.2);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 10px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: var(--gradient-primary);
min-height: 100vh;
}
.dashboard-container {
max-width: 800px;
margin: 20px auto;
padding: 0 10px;
}
.dashboard-header {
background: white;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
text-align: center;
}
.dashboard-header h3 {
margin: 0;
font-size: 20px;
color: #333;
font-weight: 600;
}
.dashboard-header .key-badge {
display: inline-block;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 4px 12px;
border-radius: 20px;
font-size: 14px;
font-weight: 500;
margin-left: 8px;
}
.empty-state {
background: white;
border-radius: 12px;
padding: 40px 20px;
text-align: center;
color: #666;
}
.empty-state-icon {
font-size: 48px;
margin-bottom: 15px;
}
.empty-state-text {
font-size: 16px;
margin: 0;
}
#popup-overlay {
cursor: pointer;
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 9998;
}
#popup {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90%;
max-width: 700px;
max-height: 90vh;
background: white;
border: 1px solid #ccc;
padding: 25px;
box-shadow: 0px 10px 40px rgba(0, 0, 0, 0.2);
overflow-y: auto;
z-index: 9999;
border-radius: 12px;
}
#popup h2 {
margin: 0 0 20px 0;
color: #333;
font-size: 22px;
}
#popup form {
display: flex;
flex-direction: column;
}
#popup form label {
font-weight: bold;
margin-bottom: 8px;
font-size: 14px;
color: #333;
}
#popup form input, #popup form textarea {
margin-bottom: 20px;
padding: 12px;
font-size: 16px;
border: 2px solid #e0e0e0;
border-radius: 8px;
width: 100%;
transition: border-color 0.3s;
}
#popup form input:focus, #popup form textarea:focus {
outline: none;
border-color: #667eea;
}
#popup form textarea {
resize: vertical;
min-height: 300px;
max-height: 500px;
font-family: 'Courier New', monospace;
line-height: 1.5;
}
#popup-buttons {
display: flex;
gap: 10px;
margin-top: 15px;
flex-direction: row;
}
#popup-buttons button {
flex: 1;
padding: 12px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 5px;
background-color: #007BFF;
color: white;
touch-action: manipulation;
}
#popup-buttons button:active {
transform: scale(0.98);
}
#popup-buttons button.save {
background-color: #28a745;
}
#popup-buttons button.save:active {
background-color: #218838;
}
#popup-buttons button.delete {
background-color: #ffc107;
color: #212529;
}
#popup-buttons button.delete:active {
background-color: #e0a800;
}
#popup-buttons button.cancel {
background-color: #dc3545;
}
#popup-buttons button.cancel:active {
background-color: #a71d2a;
}
#api-list {
list-style: none;
padding: 0;
margin: 0;
}
#api-list li {
margin-bottom: 12px;
}
.api-item {
background: white;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
padding: 16px 20px;
display: flex;
align-items: center;
gap: 12px;
transition: transform 0.2s, box-shadow 0.2s;
}
.api-item:hover {
transform: translateY(-2px);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.api-item-icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
flex-shrink: 0;
}
.api-item-content {
flex: 1;
cursor: pointer;
}
.api-item-name {
font-size: 16px;
font-weight: 600;
color: #333;
margin: 0;
}
.api-item-actions {
display: flex;
gap: 8px;
}
.api-item-actions button {
width: 40px;
height: 40px;
border: none;
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 18px;
transition: transform 0.2s, background-color 0.2s;
background-color: #f0f0f0;
}
.api-item-actions button:hover {
transform: scale(1.1);
}
.api-item-actions button:active {
transform: scale(0.95);
}
.api-item-actions .test-btn {
background-color: #e8f0fe;
color: #1a73e8;
}
.api-item-actions .test-btn:hover {
background-color: #d2e3fc;
}
.new-api-btn {
background: white;
color: #667eea;
border: 2px dashed #667eea;
padding: 20px;
border-radius: 12px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
width: 100%;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
transition: all 0.3s ease;
margin-bottom: 20px;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.new-api-btn:hover {
border-color: transparent;
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.new-api-btn:active {
transform: translateY(0);
}
.new-api-btn::before {
content: '✨';
font-size: 20px;
}
/* Toast notifications */
#toast-container {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 9999;
display: flex;
flex-direction: column-reverse;
gap: 0;
}
.toast {
padding: 15px 20px;
color: white;
font-size: 14px;
text-align: center;
animation: slideUp 0.3s ease forwards;
width: 100%;
box-sizing: border-box;
}
.toast.dismissing {
animation: slideDown 0.3s ease forwards;
}
.toast.success {
background-color: #28a745;
}
.toast.error {
background-color: #dc3545;
}
.toast.info {
background-color: #17a2b8;
}
.toast.warning {
background-color: #ffc107;
color: #212529;
}
@keyframes slideUp {
from {
transform: translateY(100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
@keyframes slideDown {
from {
transform: translateY(0);
opacity: 1;
}
to {
transform: translateY(100%);
opacity: 0;
}
}
/* Mobile optimizations */
@media (max-width: 768px) {
body {
padding: 5px;
}
.dashboard-container {
margin: 10px auto;
}
.dashboard-header {
padding: 15px;
}
.dashboard-header h3 {
font-size: 16px;
}
.dashboard-header .key-badge {
display: block;
margin: 8px auto 0;
width: fit-content;
}
#popup {
top: 0 !important;
left: 0 !important;
transform: none !important;
width: 100%;
max-width: 100%;
height: 100%;
max-height: 100%;
border-radius: 0;
padding: 15px;
}
#popup h2 {
font-size: 18px;
}
#popup form textarea {
min-height: 200px;
}
#popup-buttons {
flex-direction: column;
}
#popup-buttons button {
width: 100%;
min-width: auto;
}
.api-item {
padding: 12px 16px;
}
.api-item-icon {
width: 36px;
height: 36px;
font-size: 18px;
}
.api-item-name {
font-size: 15px;
}
.api-item-actions button {
width: 36px;
height: 36px;
font-size: 16px;
}
}
/* Key input form */
.key-form-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
margin: -10px;
}
.key-form-card {
background: white;
padding: 40px;
border-radius: 12px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
max-width: 400px;
width: 100%;
}
.key-form-card h2 {
margin: 0 0 10px 0;
color: #333;
font-size: 24px;
text-align: center;
}
.key-form-card p {
margin: 0 0 30px 0;
color: #666;
font-size: 14px;
text-align: center;
}
.key-form-card form {
display: flex;
flex-direction: column;
}
.key-form-card label {
font-weight: bold;
margin-bottom: 8px;
color: #333;
font-size: 14px;
}
.key-form-card input {
padding: 14px;
font-size: 16px;
border: 2px solid #e0e0e0;
border-radius: 8px;
margin-bottom: 20px;
transition: border-color 0.3s;
}
.key-form-card input:focus {
outline: none;
border-color: #667eea;
}
.key-form-card button {
padding: 14px;
font-size: 16px;
font-weight: bold;
color: white;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
border-radius: 8px;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.key-form-card button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}
.key-form-card button:active {
transform: translateY(0);
}
@media (max-width: 768px) {
.key-form-container {
padding: 20px;
}
.key-form-card {
padding: 30px 20px;
}
}
</style>
</head>
<body>
<?php if (empty($key)): ?>
<div class="key-form-container">
<div class="key-form-card">
<h2>🔐 API Mock Service</h2>
<p>Enter your key to access the API management dashboard</p>
<form method="GET" action="tool.php">
<label for="key">Your Key</label>
<input type="text" id="key" name="key" placeholder="Enter your key" required autofocus>
<button type="submit">Access Dashboard</button>
</form>
</div>
</div>
<?php else:
$folder = "data";
// Include private functions and sample data
require_once 'private.php';
require_once 'sample.php';
// Get existing data from consolidated file
$storageData = getStorageData($key, $secret_key);
// Migration: Check for old individual files and consolidate them
$oldFiles = is_dir($folder) ? glob("$folder/*-$key-$secret_key.bin") : [];
if (!empty($oldFiles) && empty($storageData)) {
foreach ($oldFiles as $file) {
$fileName = basename($file);
// Extract API name from old filename format
$apiName = preg_replace('/-\w+-' . preg_quote($secret_key, '/') . '\.bin$/', '', $fileName);
if ($apiName && $apiName !== $fileName) {
$content = file_get_contents($file);
if ($content !== false) {
$storageData[$apiName] = $content;
}
}
}
// Save migrated data and delete old files
if (!empty($storageData)) {
saveStorageData($key, $secret_key, $storageData);
// Clean up old files
foreach ($oldFiles as $file) {
unlink($file);
}
}
}
// Create sample APIs only if the file doesn't exist (new key)
$file_name = "$folder/$key-$secret_key.bin";
if (!file_exists($file_name)) {
// Get sample data from sample.php
$storageData = getSampleData();
// Save consolidated data
saveStorageData($key, $secret_key, $storageData);
}
?>
<div class="dashboard-container">
<div class="dashboard-header">
<h3>🚀 API Management <span class="key-badge"><?php echo htmlspecialchars($key); ?></span></h3>
</div>
<button class="new-api-btn" onclick="showPopup()">+ New API</button>
<?php if (empty($storageData)): ?>
<div class="empty-state">
<div class="empty-state-icon">📭</div>
<p class="empty-state-text">No APIs yet. Click "+ New API" to create one!</p>
</div>
<?php else: ?>
<ul id="api-list">
<?php foreach ($storageData as $apiName => $content): ?>
<li>
<div class="api-item" onclick="editAPI('<?php echo htmlspecialchars($apiName); ?>')">
<div class="api-item-icon">📝</div>
<div class="api-item-content">
<p class="api-item-name"><?php echo htmlspecialchars($apiName); ?></p>
</div>
<div class="api-item-actions">
<button class="test-btn" onclick="event.stopPropagation(); testAPI('<?php echo htmlspecialchars($apiName); ?>')" title="Test API">
🌐
</button>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<div id="popup-overlay"></div>
<div id="popup">
<h2 id="popup-title">New API</h2>
<form id="popup-form">
<label for="name">API Name:</label>
<input type="text" id="name" name="name" placeholder="Enter API name" required>
<label for="response">Response:</label>
<textarea id="response" name="response" placeholder="Enter the API response" rows="10" required></textarea>
<input type="hidden" id="file-name" name="file-name">
<div id="popup-buttons">
<button type="button" class="save" onclick="saveAPI()">Save</button>
<button type="button" class="delete" onclick="deleteAPI()">Delete</button>
<button type="button" class="cancel" onclick="closePopup()">Cancel</button>
</div>
</form>
</div>
<?php endif; ?>
<script>
// Toast notification function
function showToast(message, type = 'info') {
const container = document.getElementById('toast-container');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.textContent = message;
container.appendChild(toast);
// Dismiss with slide-down animation after 2.7 seconds
setTimeout(() => {
toast.classList.add('dismissing');
// Remove from DOM after animation completes
setTimeout(() => {
toast.remove();
}, 300);
}, 2700);
}
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape') {
closePopup();
}
});
function showPopup() {
document.getElementById('popup-title').textContent = "New API";
document.getElementById('name').value = "";
document.getElementById('response').value = "";
document.getElementById('file-name').value = "";
document.getElementById('popup-overlay').style.display = 'block';
document.getElementById('popup').style.display = 'block';
document.body.style.overflow = 'hidden';
}
function closePopup() {
document.getElementById('popup').style.display = 'none';
document.getElementById('popup-overlay').style.display = 'none';
document.body.style.overflow = '';
}
// Close popup when clicking overlay
document.addEventListener('DOMContentLoaded', function() {
const overlay = document.getElementById('popup-overlay');
if (overlay) {
overlay.addEventListener('click', closePopup);
}
});
function editAPI(apiName) {
fetch(`get.php?name=${encodeURIComponent(apiName)}&key=<?php echo htmlspecialchars($key); ?>&edit=1`)
.then(response => response.json())
.then(data => {
if (data.error_code === 0) {
document.getElementById('popup-title').textContent = "Edit API";
document.getElementById('name').value = apiName;
document.getElementById('response').value = data.content;
document.getElementById('file-name').value = apiName;
document.getElementById('popup-overlay').style.display = 'block';
document.getElementById('popup').style.display = 'block';
document.body.style.overflow = 'hidden';
} else {
showToast(data.error_message, 'error');
}
})
.catch(err => showToast('Error fetching API data.', 'error'));
}
function saveAPI() {
const name = document.getElementById('name').value.trim();
const response = document.getElementById('response').value.trim();
const fileName = document.getElementById('file-name').value;
if (!name || !response) {
showToast("Name and response are required.", 'warning');
return;
}
const formData = new FormData();
formData.append('name', name);
formData.append('response', response);
formData.append('key', '<?php echo htmlspecialchars($key); ?>');
fetch('save.php', {
method: 'POST',
body: formData
})
.then(response => response.text())
.then(data => {
showToast('API saved successfully!', 'success');
setTimeout(() => location.reload(), 1000);
})
.catch(err => showToast('Error saving API.', 'error'));
}
function testAPI(apiName) {
const url = `get.php?name=${encodeURIComponent(apiName)}&key=<?php echo htmlspecialchars($key); ?>`;
window.open(url, '_blank');
}
function deleteAPI() {
const apiName = document.getElementById('file-name').value;
if (!apiName) {
showToast("No API selected for deletion.", 'warning');
return;
}
fetch(`delete.php?name=${encodeURIComponent(apiName)}&key=<?php echo htmlspecialchars($key); ?>`, {
method: 'GET'
})
.then(response => response.text())
.then(data => {
showToast('API deleted successfully!', 'success');
setTimeout(() => location.reload(), 1000);
})
.catch(err => showToast('Error deleting API.', 'error'));
}
</script>
<div id="toast-container"></div>
</body>
</html>