| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- declare(strict_types=1);
- $baseUrl = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']);
- $dataPath = __DIR__ . '/data/webhooks.json';
- $maxWebhooks = 100;
- // Handle webhook creation
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create') {
- $raw = file_get_contents($dataPath);
- $data = json_decode($raw, true);
-
- if (count($data['webhooks']) >= $maxWebhooks) {
- $error = 'Maximum number of webhooks (' . $maxWebhooks . ') reached.';
- } else {
- $key = bin2hex(random_bytes(8));
- $webhook = [
- 'key' => $key,
- 'created' => date('c'),
- 'requests' => []
- ];
- $data['webhooks'][] = $webhook;
- file_put_contents($dataPath, json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
- header('Location: ' . $_SERVER['REQUEST_URI']);
- exit;
- }
- }
- // Load webhooks
- $raw = file_get_contents($dataPath);
- $data = json_decode($raw, true);
- $webhooks = $data['webhooks'];
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Webhook Debug Tool</title>
- <style>
- body {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
- max-width: 1200px;
- margin: 40px auto;
- padding: 0 20px;
- background: #f5f5f5;
- }
- h1 { color: #333; }
- .info { background: #e3f2fd; padding: 15px; border-radius: 5px; margin-bottom: 20px; }
- table { width: 100%; border-collapse: collapse; background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
- th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
- th { background: #2196F3; color: white; }
- tr:hover { background: #f5f5f5; }
- .btn {
- display: inline-block;
- padding: 10px 20px;
- background: #2196F3;
- color: white;
- text-decoration: none;
- border-radius: 5px;
- border: none;
- cursor: pointer;
- font-size: 14px;
- }
- .btn:hover { background: #1976D2; }
- .btn-danger { background: #f44336; }
- .btn-danger:hover { background: #d32f2f; }
- .url-box {
- background: #f5f5f5;
- padding: 8px;
- border-radius: 3px;
- font-family: monospace;
- font-size: 12px;
- word-break: break-all;
- }
- .empty { text-align: center; color: #999; padding: 40px; }
- .error { background: #ffebee; color: #c62828; padding: 10px; border-radius: 5px; margin: 10px 0; }
- form { display: inline; }
- </style>
- </head>
- <body>
- <h1>🔗 Webhook Debug Tool</h1>
-
- <div class="info">
- <strong>How to use:</strong>
- <ol>
- <li>Click "Create New Webhook" to generate a unique webhook URL</li>
- <li>Copy the webhook URL and configure it as the webhook endpoint in your service</li>
- <li>Send requests to the webhook URL - all data will be captured</li>
- <li>Click "View Requests" to see all captured requests with headers and body</li>
- </ol>
- </div>
- <?php if (isset($error)): ?>
- <div class="error"><?= htmlspecialchars($error) ?></div>
- <?php endif; ?>
- <div style="margin-bottom: 20px;">
- <form method="POST" style="display: inline;">
- <input type="hidden" name="action" value="create">
- <button type="submit" class="btn">➕ Create New Webhook</button>
- </form>
- <span style="margin-left: 10px; color: #666;">(<?= count($webhooks) ?>/<?= $maxWebhooks ?> webhooks)</span>
- </div>
- <?php if (empty($webhooks)): ?>
- <div class="empty">No webhooks created yet. Click "Create New Webhook" to get started.</div>
- <?php else: ?>
- <table>
- <thead>
- <tr>
- <th>Key</th>
- <th>Created</th>
- <th>Requests</th>
- <th>Webhook URL</th>
- <th>Actions</th>
- </tr>
- </thead>
- <tbody>
- <?php foreach (array_reverse($webhooks) as $webhook): ?>
- <tr>
- <td><code><?= htmlspecialchars($webhook['key']) ?></code></td>
- <td><?= htmlspecialchars(date('Y-m-d H:i:s', strtotime($webhook['created']))) ?></td>
- <td><?= count($webhook['requests']) ?></td>
- <td>
- <div class="url-box">
- <?= htmlspecialchars($baseUrl . '/webhook.php?key=' . $webhook['key']) ?>
- </div>
- </td>
- <td>
- <a href="view.php?key=<?= urlencode($webhook['key']) ?>" class="btn">View Requests</a>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php endif; ?>
- </body>
- </html>
|