Repository navigation
Expand file tree
/
Copy pathdebug_paste.php
More file actions
150 lines (133 loc) · 6.29 KB
/
Copy pathdebug_paste.php
File metadata and controls
150 lines (133 loc) · 6.29 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
<?php
/**
* 🔍 Lunabin Debug Script - Enhanced
* Checks specific paste and shows database structure
*/
require_once 'inc/config.php';
require_once 'inc/db.php';
require_once 'inc/functions.php';
$searchId = $_GET['id'] ?? '';
echo "<h2>🔍 Lunabin Debug Information</h2>";
echo "<hr>";
try {
$db = getDB();
// 1. Check database structure
echo "<h3>📋 Database Structure:</h3>";
$stmt = $db->query("PRAGMA table_info(pastes)");
$columns = $stmt->fetchAll();
echo "<table border='1' cellpadding='5'>";
echo "<tr><th>Column Name</th><th>Type</th><th>Not Null</th><th>Default</th></tr>";
foreach ($columns as $column) {
echo "<tr>";
echo "<td><strong>" . $column['name'] . "</strong></td>";
echo "<td>" . $column['type'] . "</td>";
echo "<td>" . ($column['notnull'] ? 'Yes' : 'No') . "</td>";
echo "<td>" . ($column['dflt_value'] ?? 'NULL') . "</td>";
echo "</tr>";
}
echo "</table>";
// 2. Display all pastes
echo "<h3>📊 All Pastes in Database:</h3>";
$stmt = $db->query("SELECT id, title, share_code, created_at, expire_at, is_encrypted, iv FROM pastes ORDER BY created_at DESC LIMIT 10");
$allPastes = $stmt->fetchAll();
if (empty($allPastes)) {
echo "<p><strong>❌ No pastes found in database!</strong></p>";
} else {
echo "<table border='1' cellpadding='5'>";
echo "<tr><th>ID</th><th>Title</th><th>Share Code</th><th>Created</th><th>Expires</th><th>Encrypted</th><th>IV</th><th>Test Links</th></tr>";
foreach ($allPastes as $paste) {
$isExpired = $paste['expire_at'] < time();
$rowStyle = $isExpired ? 'style="background-color: #ffcccc;"' : '';
echo "<tr $rowStyle>";
echo "<td><strong>" . htmlspecialchars($paste['id']) . "</strong></td>";
echo "<td>" . htmlspecialchars($paste['title'] ?: 'Untitled') . "</td>";
echo "<td>" . htmlspecialchars($paste['share_code']) . "</td>";
echo "<td>" . date('d.m.Y H:i', $paste['created_at']) . "</td>";
echo "<td>" . date('d.m.Y H:i', $paste['expire_at']) . ($isExpired ? ' <strong>(EXPIRED)</strong>' : '') . "</td>";
echo "<td>" . ($paste['is_encrypted'] ? 'Yes' : 'No') . "</td>";
echo "<td>" . ($paste['iv'] ? '✓' : '❌') . "</td>";
echo "<td>";
echo "<a href='view.php?id=" . htmlspecialchars($paste['id']) . "' target='_blank'>ID Link</a> | ";
echo "<a href='view.php?id=" . htmlspecialchars($paste['share_code']) . "' target='_blank'>Share Code Link</a>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
// 3. Search for specific paste (if ID provided)
if (!empty($searchId)) {
echo "<h3>🔍 Searching for Paste: <code>$searchId</code></h3>";
$stmt = $db->prepare("SELECT * FROM pastes WHERE id = ? OR share_code = ?");
$stmt->execute([$searchId, $searchId]);
$specificPaste = $stmt->fetch();
if ($specificPaste) {
echo "<p><strong>✅ Paste found!</strong></p>";
echo "<table border='1' cellpadding='5'>";
foreach ($specificPaste as $key => $value) {
echo "<tr>";
echo "<td><strong>$key</strong></td>";
echo "<td>" . htmlspecialchars($value ?? 'NULL') . "</td>";
echo "</tr>";
}
echo "</table>";
// Check expiration time
if ($specificPaste['expire_at'] < time()) {
echo "<p><strong>⚠️ This paste has already expired!</strong></p>";
} else {
echo "<p><strong>✅ Paste is still valid.</strong></p>";
// Test share info generation
try {
$shareInfo = getShareInfo($specificPaste['id']);
echo "<h4>📤 Share Info Test:</h4>";
echo "<table border='1' cellpadding='5'>";
foreach ($shareInfo as $key => $value) {
echo "<tr>";
echo "<td><strong>$key</strong></td>";
echo "<td>";
if (strpos($key, 'link') !== false) {
echo "<a href='" . htmlspecialchars($value) . "' target='_blank'>" . htmlspecialchars($value) . "</a>";
} else {
echo htmlspecialchars($value);
}
echo "</td>";
echo "</tr>";
}
echo "</table>";
} catch (Exception $e) {
echo "<p><strong>❌ Error with Share Info: " . htmlspecialchars($e->getMessage()) . "</strong></p>";
}
}
} else {
echo "<p><strong>❌ Paste '$searchId' was not found!</strong></p>";
echo "<p>Possible causes:</p>";
echo "<ul>";
echo "<li>The paste was not created correctly</li>";
echo "<li>The paste has already expired</li>";
echo "<li>Error saving to the database</li>";
echo "<li>The database was reset</li>";
echo "</ul>";
}
}
// 4. Share code generator test
echo "<h3>🎲 Share Code Generator Test:</h3>";
echo "<p>Testing share code generation:</p>";
for ($i = 0; $i < 5; $i++) {
try {
$testCode = generateShareCode();
echo "<span style='font-family: monospace; background: #f0f0f0; padding: 2px 5px; margin: 2px; border: 1px solid #ccc;'>$testCode</span> ";
} catch (Exception $e) {
echo "<span style='color: red;'>ERROR: " . htmlspecialchars($e->getMessage()) . "</span> ";
}
}
echo "<br><br>";
// 5. Display current time
echo "<h3>🕒 Time Information:</h3>";
echo "<p><strong>Current Time:</strong> " . date('d.m.Y H:i:s') . " (Unix: " . time() . ")</p>";
} catch (Exception $e) {
echo "<p><strong>❌ Error:</strong> " . htmlspecialchars($e->getMessage()) . "</p>";
}
echo "<hr>";
echo "<p><a href='index.php'>← Back to Main Page</a></p>";
echo "<p><a href='fix_database.php'>🔧 Repair Database</a></p>";
echo "<p><a href='?'>🔄 Debug without ID</a></p>";
?>