index.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. declare(strict_types=1);
  3. $baseUrl = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']);
  4. $dataPath = __DIR__ . '/data/webhooks.json';
  5. $maxWebhooks = 100;
  6. // Handle webhook creation
  7. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create') {
  8. $raw = file_get_contents($dataPath);
  9. $data = json_decode($raw, true);
  10. if (count($data['webhooks']) >= $maxWebhooks) {
  11. $error = 'Maximum number of webhooks (' . $maxWebhooks . ') reached.';
  12. } else {
  13. $key = bin2hex(random_bytes(8));
  14. $webhook = [
  15. 'key' => $key,
  16. 'created' => date('c'),
  17. 'requests' => []
  18. ];
  19. $data['webhooks'][] = $webhook;
  20. file_put_contents($dataPath, json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
  21. header('Location: ' . $_SERVER['REQUEST_URI']);
  22. exit;
  23. }
  24. }
  25. // Load webhooks
  26. $raw = file_get_contents($dataPath);
  27. $data = json_decode($raw, true);
  28. $webhooks = $data['webhooks'];
  29. ?>
  30. <!DOCTYPE html>
  31. <html lang="en">
  32. <head>
  33. <meta charset="UTF-8">
  34. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  35. <title>Webhook Debug Tool</title>
  36. <style>
  37. body {
  38. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  39. max-width: 1200px;
  40. margin: 40px auto;
  41. padding: 0 20px;
  42. background: #f5f5f5;
  43. }
  44. h1 { color: #333; }
  45. .info { background: #e3f2fd; padding: 15px; border-radius: 5px; margin-bottom: 20px; }
  46. table { width: 100%; border-collapse: collapse; background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
  47. th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
  48. th { background: #2196F3; color: white; }
  49. tr:hover { background: #f5f5f5; }
  50. .btn {
  51. display: inline-block;
  52. padding: 10px 20px;
  53. background: #2196F3;
  54. color: white;
  55. text-decoration: none;
  56. border-radius: 5px;
  57. border: none;
  58. cursor: pointer;
  59. font-size: 14px;
  60. }
  61. .btn:hover { background: #1976D2; }
  62. .btn-danger { background: #f44336; }
  63. .btn-danger:hover { background: #d32f2f; }
  64. .url-box {
  65. background: #f5f5f5;
  66. padding: 8px;
  67. border-radius: 3px;
  68. font-family: monospace;
  69. font-size: 12px;
  70. word-break: break-all;
  71. }
  72. .empty { text-align: center; color: #999; padding: 40px; }
  73. .error { background: #ffebee; color: #c62828; padding: 10px; border-radius: 5px; margin: 10px 0; }
  74. form { display: inline; }
  75. </style>
  76. </head>
  77. <body>
  78. <h1>🔗 Webhook Debug Tool</h1>
  79. <div class="info">
  80. <strong>How to use:</strong>
  81. <ol>
  82. <li>Click "Create New Webhook" to generate a unique webhook URL</li>
  83. <li>Copy the webhook URL and configure it as the webhook endpoint in your service</li>
  84. <li>Send requests to the webhook URL - all data will be captured</li>
  85. <li>Click "View Requests" to see all captured requests with headers and body</li>
  86. </ol>
  87. </div>
  88. <?php if (isset($error)): ?>
  89. <div class="error"><?= htmlspecialchars($error) ?></div>
  90. <?php endif; ?>
  91. <div style="margin-bottom: 20px;">
  92. <form method="POST" style="display: inline;">
  93. <input type="hidden" name="action" value="create">
  94. <button type="submit" class="btn">➕ Create New Webhook</button>
  95. </form>
  96. <span style="margin-left: 10px; color: #666;">(<?= count($webhooks) ?>/<?= $maxWebhooks ?> webhooks)</span>
  97. </div>
  98. <?php if (empty($webhooks)): ?>
  99. <div class="empty">No webhooks created yet. Click "Create New Webhook" to get started.</div>
  100. <?php else: ?>
  101. <table>
  102. <thead>
  103. <tr>
  104. <th>Key</th>
  105. <th>Created</th>
  106. <th>Requests</th>
  107. <th>Webhook URL</th>
  108. <th>Actions</th>
  109. </tr>
  110. </thead>
  111. <tbody>
  112. <?php foreach (array_reverse($webhooks) as $webhook): ?>
  113. <tr>
  114. <td><code><?= htmlspecialchars($webhook['key']) ?></code></td>
  115. <td><?= htmlspecialchars(date('Y-m-d H:i:s', strtotime($webhook['created']))) ?></td>
  116. <td><?= count($webhook['requests']) ?></td>
  117. <td>
  118. <div class="url-box">
  119. <?= htmlspecialchars($baseUrl . '/webhook.php?key=' . $webhook['key']) ?>
  120. </div>
  121. </td>
  122. <td>
  123. <a href="view.php?key=<?= urlencode($webhook['key']) ?>" class="btn">View Requests</a>
  124. </td>
  125. </tr>
  126. <?php endforeach; ?>
  127. </tbody>
  128. </table>
  129. <?php endif; ?>
  130. </body>
  131. </html>