瀏覽代碼

Added client cipher for active list

root 8 月之前
父節點
當前提交
8339ba5184
共有 3 個文件被更改,包括 47 次插入16 次删除
  1. 2 0
      addons/set_perm.sh
  2. 43 16
      functions.php
  3. 2 0
      get_server_data.php

+ 2 - 0
addons/set_perm.sh

@@ -1,5 +1,7 @@
 #!/bin/bash
 
+chown nobody:www-data /etc/openvpn/server/server1/ccd/*
+chmod 464 /etc/openvpn/server/server1/ccd/*
 chmod 644 /etc/openvpn/server/server1/ipp.txt
 chmod 644 /etc/openvpn/server/server1/rsa/pki/index.txt
 

+ 43 - 16
functions.php

@@ -107,6 +107,7 @@ function getOpenVPNStatus($server) {
             continue;
         }
 
+//CLIENT_LIST,Common Name,Real Address,Virtual Address,Virtual IPv6 Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username,Client ID,Peer ID,Data Channel Cipher
         if ($in_client_list && strpos($line, 'CLIENT_LIST') === 0) {
             $parts = explode(',', $line);
             if (count($parts) >= 9) {
@@ -118,7 +119,8 @@ function getOpenVPNStatus($server) {
                     'bytes_sent' => formatBytes($parts[6]),
                     'connected_since' => $parts[7],
                     'username' => $parts[8] ?? $parts[1],
-                    'banned' => isClientBanned($server, $parts[1])
+                    'cipher' => end($parts),
+                    'banned' => isClientBanned($server, $parts[1]),
                 ];
             }
         }
@@ -132,30 +134,28 @@ function getOpenVPNStatus($server) {
 
 function getAccountList($server) {
     $accounts = [];
-    
+
     // Получаем список из index.txt (неотозванные сертификаты)
     if (!empty($server['cert_index']) && file_exists($server['cert_index'])) {
         $index_content = file_get_contents($server['cert_index']);
         $lines = explode("\n", $index_content);
-        
+
         foreach ($lines as $line) {
             if (empty(trim($line))) continue;
-            
+
             $parts = preg_split('/\s+/', $line);
             if (count($parts) >= 6 && $parts[0] === 'V') { // Только валидные сертификаты
                 $username = $parts[5];
-                $accounts[$username]["username"] = $username;
-                $accounts[$username]["ip"] = $ip;
-                $accounts[$username]["banned"] = false;
-                if (isClientBanned($server,$username)) { 
-                    $accounts[$username]["banned"] = true;
-                    }
+                $accounts[$username] = [
+                    "username" => $username,
+                    "ip" => null,
+                    "banned" => isClientBanned($server, $username)
+                ];
             }
         }
     }
 
     // Получаем список выданных IP из ipp.txt
-    $assigned_ips = [];
     if (!empty($server['ipp_file']) && file_exists($server['ipp_file'])) {
         $ipp_content = file_get_contents($server['ipp_file']);
         $lines = explode("\n", $ipp_content);
@@ -167,12 +167,39 @@ function getAccountList($server) {
             if (count($parts) >= 2) {
                 $username = $parts[0];
                 $ip = $parts[1];
-                $accounts[$username]["username"] = $username;
+                if (!isset($accounts[$username])) {
+                    $accounts[$username] = [
+                        "username" => $username,
+                        "banned" => false
+                    ];
+                }
+                $accounts[$username]["ip"] = $ip;
+                $accounts[$username]["banned"] = isClientBanned($server, $username);
+            }
+        }
+    }
+
+    // Ищем IP-адреса в CCD файлах
+    if (!empty($server['ccd']) && is_dir($server['ccd'])) {
+        $ccd_files = scandir($server['ccd']);
+        foreach ($ccd_files as $file) {
+            if ($file === '.' || $file === '..') continue;
+            
+            $username = $file;
+            $filepath = $server['ccd'] . '/' . $file;
+            $content = file_get_contents($filepath);
+            
+            // Ищем строку ifconfig-push с IP адресом
+            if (preg_match('/ifconfig-push\s+(\d+\.\d+\.\d+\.\d+)/', $content, $matches)) {
+                $ip = $matches[1];
+                if (!isset($accounts[$username])) {
+                    $accounts[$username] = [
+                        "username" => $username,
+                        "banned" => false
+                    ];
+                }
                 $accounts[$username]["ip"] = $ip;
-                $accounts[$username]["banned"] = false;
-                if (isClientBanned($server,$username)) { 
-                    $accounts[$username]["banned"] = true;
-                    }
+                $accounts[$username]["banned"] = isClientBanned($server, $username);
             }
         }
     }

+ 2 - 0
get_server_data.php

@@ -60,6 +60,7 @@ ob_start();
                 <th>Virtual IP</th>
                 <th>Traffic</th>
                 <th>Connected</th>
+                <th>Cipher</th>
                 <th>Status</th>
                 <th>Actions</th>
             </tr>
@@ -76,6 +77,7 @@ ob_start();
                 <td><?= htmlspecialchars($client['virtual_ip']) ?></td>
                 <td>↓<?= $client['bytes_received'] ?> ↑<?= $client['bytes_sent'] ?></td>
                 <td><?= htmlspecialchars($client['connected_since']) ?></td>
+                <td><?= htmlspecialchars($client['cipher']) ?></td>
                 <td>
                     <span class="status-badge <?= $client['banned'] ? 'status-banned' : 'status-active' ?>">
                         <?= $client['banned'] ? 'BANNED' : 'Active' ?>