1
0

get_server_data.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. session_start();
  3. // 1. Проверяем AJAX-запрос
  4. if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest') {
  5. dieAjaxError('Direct access not allowed');
  6. }
  7. // 2. Проверяем CSRF-токен
  8. //if (empty($_GET['csrf']) || $_GET['csrf'] !== $_SESSION['csrf_token']) {
  9. // dieAjaxError('Invalid CSRF token');
  10. //}
  11. // Если все проверки пройдены, выполняем основной код
  12. function dieAjaxError($message) {
  13. header('HTTP/1.0 403 Forbidden');
  14. header('Content-Type: application/json');
  15. die(json_encode(['error' => $message]));
  16. }
  17. define("CONFIG", 1);
  18. require_once 'functions.php';
  19. $config_file = __DIR__ . '/config.php';
  20. if (!file_exists($config_file)) {
  21. die("Configuration file not found: $config_file");
  22. }
  23. $servers = require_once $config_file;
  24. $server_name = $_GET['server'] ?? '';
  25. $action = $_GET['action'] ?? '';
  26. $username = $_GET['username'] ?? '';
  27. if (!isset($servers[$server_name])) {
  28. die("Invalid server name");
  29. }
  30. $server = $servers[$server_name];
  31. $clients = getOpenVPNStatus($server);
  32. $banned_clients = getBannedClients($server, $clients);
  33. $accounts = getAccountList($server);
  34. // Генерируем HTML для этого сервера
  35. ob_start();
  36. ?>
  37. <h2><?= htmlspecialchars($server['title']) ?></h2>
  38. <div class="section">
  39. <h3>Active Connections</h3>
  40. <?php if (!empty($clients)): ?>
  41. <table>
  42. <thead>
  43. <tr>
  44. <th>Client</th>
  45. <th>Real IP</th>
  46. <th>Virtual IP</th>
  47. <th>Traffic</th>
  48. <th>Connected</th>
  49. <th>Cipher</th>
  50. <th>Status</th>
  51. <th>Actions</th>
  52. </tr>
  53. </thead>
  54. <tbody>
  55. <?php foreach ($clients as $client): ?>
  56. <tr class="<?= $client['banned'] ? 'banned' : '' ?>">
  57. <td>
  58. <a href="#" onclick="return generateConfig('<?= $server_name ?>', '<?= htmlspecialchars($client['name']) ?>', event)">
  59. <?= htmlspecialchars($client['name']) ?>
  60. </a>
  61. </td>
  62. <td><?= htmlspecialchars($client['real_ip']) ?></td>
  63. <td><?= htmlspecialchars($client['virtual_ip']) ?></td>
  64. <td>↓<?= $client['bytes_received'] ?> ↑<?= $client['bytes_sent'] ?></td>
  65. <td><?= htmlspecialchars($client['connected_since']) ?></td>
  66. <td><?= htmlspecialchars($client['cipher']) ?></td>
  67. <td>
  68. <span class="status-badge <?= $client['banned'] ? 'status-banned' : 'status-active' ?>">
  69. <?= $client['banned'] ? 'BANNED' : 'Active' ?>
  70. </span>
  71. </td>
  72. <td class="actions">
  73. <?php if ($client['banned']): ?>
  74. <button onclick="handleAction('<?= $server_name ?>', 'unban', '<?= htmlspecialchars($client['name']) ?>')"
  75. class="btn unban-btn">Unban</button>
  76. <?php else: ?>
  77. <button onclick="handleAction('<?= $server_name ?>', 'ban', '<?= htmlspecialchars($client['name']) ?>')"
  78. class="btn ban-btn">Ban</button>
  79. <?php endif; ?>
  80. </td>
  81. </tr>
  82. <?php endforeach; ?>
  83. </tbody>
  84. </table>
  85. <?php else: ?>
  86. <p>No active connections</p>
  87. <?php endif; ?>
  88. </div>
  89. <div class="section">
  90. <div class="spoiler">
  91. <div class="spoiler-title collapsed" onclick="toggleSpoiler(this)">
  92. Configured Account List (<?= count($accounts) ?>)
  93. </div>
  94. <div class="spoiler-content">
  95. <table>
  96. <thead>
  97. <tr>
  98. <th>Account</th>
  99. <th>Assigned IP</th>
  100. <th>Status</th>
  101. <th>Actions</th>
  102. </tr>
  103. </thead>
  104. <tbody>
  105. <?php foreach ($accounts as $account):
  106. if (isClientActive($clients,$account["username"])) { continue; }
  107. ?>
  108. <tr>
  109. <td>
  110. <a href="#" onclick="return generateConfig('<?= $server_name ?>', '<?= htmlspecialchars($account['username']) ?>', event)">
  111. <?= htmlspecialchars($account['username']) ?>
  112. </a>
  113. </td>
  114. <td><?= htmlspecialchars($account['ip'] ?? 'N/A') ?></td>
  115. <td>
  116. <span class="status-badge <?= $account['banned'] ? 'status-banned' : 'status-active' ?>">
  117. <?= $account['banned'] ? 'BANNED' : 'ENABLED' ?>
  118. </span>
  119. </td>
  120. <td class="actions">
  121. <?php if ($account['banned']): ?>
  122. <button onclick="handleAction('<?= $server_name ?>', 'unban', '<?= htmlspecialchars($account['username']) ?>')"
  123. class="btn unban-btn">Unban</button>
  124. <?php else: ?>
  125. <button onclick="handleAction('<?= $server_name ?>', 'ban', '<?= htmlspecialchars($account['username']) ?>')"
  126. class="btn ban-btn">Ban</button>
  127. <?php endif; ?>
  128. </td>
  129. </tr>
  130. <?php endforeach; ?>
  131. </tbody>
  132. </table>
  133. </div>
  134. </div>
  135. </div>
  136. <div class="last-update">
  137. Last update: <?= date('Y-m-d H:i:s') ?>
  138. </div>
  139. <?php
  140. echo ob_get_clean();