1
0
Эх сурвалжийг харах

next changes.first draft release

Dmitriev Roman 3 сар өмнө
parent
commit
20d1390c91

+ 3 - 0
docs/databases/postgres/ru/create_db.sql

@@ -554,6 +554,9 @@ auth_id BIGINT NOT NULL DEFAULT 0,
 ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
 byte_in BIGINT NOT NULL DEFAULT 0,
 byte_out BIGINT NOT NULL DEFAULT 0
+pkt_in INTEGER,
+pkt_out INTEGER,
+step SMALLINT NOT NULL DEFAULT 3600
 );
 COMMENT ON TABLE user_stats IS 'Статистика трафика пользователей (агрегированная)';
 

+ 12 - 9
html/admin/devices/editport.php

@@ -3,18 +3,21 @@ require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
 require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
 
-if (isset($_POST["editport"])) {
-    $new['snmp_index'] = $_POST["f_snmp"] * 1;
-    $new['uplink'] = $_POST["f_uplink"] * 1;
-    $new['nagios'] = $_POST["f_nagios"] * 1;
-    $new['skip'] = $_POST["f_skip"] * 1;
-    $new['description'] = $_POST["f_description"];
-    update_record($db_link, "device_ports", "id=?", $new, [ $id ]);
+if (getPOST("editport") !== null) {
+    $new = [
+        'snmp_index'  => (int)getPOST("f_snmp", null, 0),
+        'uplink'      => (int)getPOST("f_uplink", null, 0),
+        'nagios'      => (int)getPOST("f_nagios", null, 0),
+        'skip'        => (int)getPOST("f_skip", null, 0),
+        'description' => trim(getPOST("f_description", null, ''))
+    ];
 
-    $target_id = $_POST["f_target_port"];
+    update_record($db_link, "device_ports", "id = ?", $new, [$id]);
+
+    $target_id = (int)getPOST("f_target_port", null, 0);
     bind_ports($db_link, $id, $target_id);
 
-    header("location: editport.php?id=$id");
+    header("Location: editport.php?id=$id");
     exit;
 }
 

+ 12 - 5
html/admin/devices/index.php

@@ -8,14 +8,21 @@ $default_sort='device_name';
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/sortfilter.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
 
-if (isset($_POST["remove_device"])) {
-    $dev_ids = $_POST["fid"];
-    foreach ($dev_ids as $key => $val) {
-        if ($val) { delete_device($db_link,$val); }
+if (getPOST("remove_device") !== null) {
+    $dev_ids = getPOST("fid", null, []);
+    
+    if (!empty($dev_ids) && is_array($dev_ids)) {
+        foreach ($dev_ids as $val) {
+            $val = trim($val);
+            if ($val !== '') {
+                delete_device($db_link, (int)$val);
+            }
         }
+    }
+    
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
-    }
+}
 
 print_device_submenu($page_url);
 

+ 11 - 8
html/admin/devices/switchport-conn.php

@@ -5,17 +5,20 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
 $device=get_record($db_link,'devices',"id=?", [ $id ]);
 
-if (isset($_POST["remove"])) {
-    $fid = $_POST["f_id"];
-    foreach ($fid as $key => $val) {
-        if (isset($val) and $val != 1) {
-                LOG_VERBOSE($db_link, "Remove connection id: $val ".dump_record($db_link,'connections','id=?', [$val]));
-                delete_record($db_link, "connections", "id=?", [$val]);
+if (getPOST("remove") !== null) {
+    $fid = getPOST("f_id", null, []);
+    if (!empty($fid) && is_array($fid)) {
+        foreach ($fid as $val) {
+            $val = trim($val);
+            if ($val !== '' && $val != 1) {
+                LOG_VERBOSE($db_link, "Remove connection id: $val " . dump_record($db_link, 'connections', 'id = ?', [$val]));
+                delete_record($db_link, "connections", "id = ?", [(int)$val]);
             }
         }
-        header("Location: " . $_SERVER["REQUEST_URI"]);
-        exit;
     }
+    header("Location: " . $_SERVER["REQUEST_URI"]);
+    exit;
+}
 
 unset($_POST);
 

+ 30 - 38
html/admin/devices/switchport.php

@@ -3,55 +3,47 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
 
-if (isset($_POST["regensnmp"])) {
-    $snmp_index = $_POST["f_snmp_start"] * 1;
-    $sSQL = "SELECT id,port from device_ports WHERE device_ports.device_id=? ORDER BY id";
-    $flist = get_records_sql($db_link, $sSQL, [ $id ]);
+// Перегенерация SNMP-индексов
+if (getPOST("regensnmp") !== null) {
+    $snmp_index = (int)getPOST("f_snmp_start", null, 1);
+    $sSQL = "SELECT id, port FROM device_ports WHERE device_ports.device_id = ? ORDER BY id";
+    $flist = get_records_sql($db_link, $sSQL, [$id]);
     LOG_DEBUG($db_link, "Recalc snmp_index for device id: $id with start $snmp_index");
     foreach ($flist as $row) {
         $snmp = $row['port'] + $snmp_index - 1;
-        $new['snmp_index'] = $snmp;
-        update_record($db_link, "device_ports", "id=?", $new, [$row['id']]);
+        update_record($db_link, "device_ports", "id = ?", ['snmp_index' => $snmp], [$row['id']]);
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
 
-if (isset($_POST['save'])) {
-    $saved = array();
-    //button save
-    $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
-    for ($i = 0; $i < $len; $i ++) {
-        $save_id = intval($_POST['save'][$i]);
-        if ($save_id == 0) { continue;  }
-        array_push($saved,$save_id);
-        }
-    //select box
-    $len = is_array($_POST['f_id']) ? count($_POST['f_id']) : 0;
-    if ($len>0) {
-        for ($i = 0; $i < $len; $i ++) {
-            $save_id = intval($_POST['f_id'][$i]);
-            if ($save_id == 0) { continue; }
-            if (!in_array($save_id, $saved)) { array_push($saved,$save_id); }
-            }
-        }
-    //save changes
-    $len = is_array($saved) ? count($saved) : 0;
-    for ($i = 0; $i < $len; $i ++) {
-        $save_id = intval($saved[$i]);
-        if ($save_id == 0) { continue;  }
-        $len_all = is_array($_POST['p_id']) ? count($_POST['p_id']) : 0;
-        for ($j = 0; $j < $len_all; $j ++) {
-            if (intval($_POST['p_id'][$j]) != $save_id) { continue; }
-            $new['port_name'] = $_POST['f_name'][$j];
-            $new['snmp_index'] = $_POST['f_snmp_index'][$j]*1;
-            update_record($db_link, "device_ports", "id=?", $new, [ $save_id ]);
-            }
+// Сохранение ОТМЕЧЕННЫХ портов
+if (getPOST("save") !== null) {
+    $selected_ids = getPOST("f_id", null, []);      // отмеченные чекбоксы
+    $all_ids      = getPOST("p_id", null, []);      // все ID
+    $port_names   = getPOST("f_name", null, []);
+    $snmp_indices = getPOST("f_snmp_index", null, []);
+    
+    if (!empty($selected_ids) && is_array($selected_ids)) {
+        $selected_ids = array_map('intval', $selected_ids);
+        $selected_set = array_flip($selected_ids);
+        
+        foreach ($all_ids as $i => $id) {
+            $id = (int)$id;
+            if ($id <= 0 || !isset($selected_set[$id])) continue;
+            
+            $new = [
+                'port_name'   => trim($port_names[$i] ?? ''),
+                'snmp_index'  => (int)($snmp_indices[$i] ?? 0)
+            ];
+            
+            update_record($db_link, "device_ports", "id = ?", $new, [$id]);
         }
+    }
+    
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
-    }
-
+}
 
 unset($_POST);
 

+ 77 - 52
html/admin/devices/switchstatus.php

@@ -3,67 +3,92 @@ require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
 require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
 
-$device = get_record($db_link, 'devices', "id=?", [ $id ]);
+$device = get_record($db_link, 'devices', "id = ?", [$id]);
 $snmp = getSnmpAccess($device);
-$device_model = get_record($db_link, 'device_models', "id=?", [ $device['device_model_id'] ]);
+$device_model = get_record($db_link, 'device_models', "id = ?", [$device['device_model_id']]);
 
-if (isset($_POST["regensnmp"])) {
-    $snmp_index = $_POST["f_snmp_start"] * 1;
-    $sSQL = "SELECT id,port from device_ports WHERE device_ports.device_id=? ORDER BY id";
-    $flist = get_records_sql($db_link, $sSQL, [ $id ]);
+// Перегенерация SNMP-индексов
+if (getPOST("regensnmp") !== null) {
+    $snmp_index = (int)getPOST("f_snmp_start", null, 1);
+    $sSQL = "SELECT id, port FROM device_ports WHERE device_ports.device_id = ? ORDER BY id";
+    $flist = get_records_sql($db_link, $sSQL, [$id]);
     LOG_DEBUG($db_link, "Recalc snmp_index for device id: $id with start $snmp_index");
     foreach ($flist as $row) {
-        $snmp = $row['port'] + $snmp_index - 1;
-        $new['snmp_index'] = $snmp;
-        update_record($db_link, "device_ports", "id=?", $new, [$row['id']]);
+        $snmp_val = $row['port'] + $snmp_index - 1;
+        update_record($db_link, "device_ports", "id = ?", ['snmp_index' => $snmp_val], [$row['id']]);
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
 
-if (isset($_POST['poe_on']) and $device['snmp_version'] > 0) {
-    $len = is_array($_POST['poe_on']) ? count($_POST['poe_on']) : 0;
-    for ($i = 0; $i < $len; $i++) {
-        $port_index = intval($_POST['poe_on'][$i]);
-        $sSQL = "SELECT port from device_ports WHERE device_id=? and snmp_index=?";
-        $port = get_record_sql($db_link, $sSQL, [ $id , $port_index ]);
-        LOG_DEBUG($db_link, "Device id: " . $id . " enable poe at port " . $port['port'] . " snmp index " . $port_index);
-        set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $snmp, 1);
+// Включение PoE
+if (getPOST("poe_on") !== null && $device['snmp_version'] > 0) {
+    $poe_on = getPOST("poe_on", null, []);
+    if (!empty($poe_on) && is_array($poe_on)) {
+        foreach ($poe_on as $port_index) {
+            $port_index = (int)$port_index;
+            if ($port_index <= 0) continue;
+            $port = get_record_sql($db_link, 
+                "SELECT port FROM device_ports WHERE device_id = ? AND snmp_index = ?", 
+                [$id, $port_index]
+            );
+            if (!empty($port)) {
+                LOG_DEBUG($db_link, "Device id: $id enable poe at port {$port['port']} snmp index $port_index");
+                set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $snmp, 1);
+            }
+        }
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
 
-if (isset($_POST['poe_off']) and $device['snmp_version'] > 0) {
-    $len = is_array($_POST['poe_off']) ? count($_POST['poe_off']) : 0;
-    for ($i = 0; $i < $len; $i++) {
-        $port_index = intval($_POST['poe_off'][$i]);
-        $sSQL = "SELECT port from device_ports WHERE device_id=? and snmp_index=?";
-        $port = get_record_sql($db_link, $sSQL, [ $id , $port_index ]);
-        LOG_DEBUG($db_link, "Device id: " . $id . " disable poe at port " . $port['port'] . " snmp index " . $port_index);
-        set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $snmp, 0);
+// Отключение PoE
+if (getPOST("poe_off") !== null && $device['snmp_version'] > 0) {
+    $poe_off = getPOST("poe_off", null, []);
+    if (!empty($poe_off) && is_array($poe_off)) {
+        foreach ($poe_off as $port_index) {
+            $port_index = (int)$port_index;
+            if ($port_index <= 0) continue;
+            $port = get_record_sql($db_link, 
+                "SELECT port FROM device_ports WHERE device_id = ? AND snmp_index = ?", 
+                [$id, $port_index]
+            );
+            if (!empty($port)) {
+                LOG_DEBUG($db_link, "Device id: $id disable poe at port {$port['port']} snmp index $port_index");
+                set_port_poe_state($device['vendor_id'], $port['port'], $port_index, $device['ip'], $snmp, 0);
+            }
+        }
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
 
-if (isset($_POST['port_on']) and $device['snmp_version'] > 0) {
-    $len = is_array($_POST['port_on']) ? count($_POST['port_on']) : 0;
-    for ($i = 0; $i < $len; $i++) {
-        $port_index = intval($_POST['port_on'][$i]);
-        LOG_DEBUG($db_link, "Device id: $id enable port with snmp index $port_index");
-        set_port_state($device['vendor_id'], $port_index, $device['ip'], $snmp, 1);
+// Включение портов
+if (getPOST("port_on") !== null && $device['snmp_version'] > 0) {
+    $port_on = getPOST("port_on", null, []);
+    
+    if (!empty($port_on) && is_array($port_on)) {
+        foreach ($port_on as $port_index) {
+            $port_index = (int)$port_index;
+            if ($port_index <= 0) continue;
+            LOG_DEBUG($db_link, "Device id: $id enable port with snmp index $port_index");
+            set_port_state($device['vendor_id'], $port_index, $device['ip'], $snmp, 1);
+        }
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
 
-if (isset($_POST['port_off']) and $device['snmp_version'] > 0) {
-    $len = is_array($_POST['port_off']) ? count($_POST['port_off']) : 0;
-    for ($i = 0; $i < $len; $i++) {
-        $port_index = intval($_POST['port_off'][$i]);
-        LOG_DEBUG($db_link, "Device id: $id disable port with snmp index $port_index");
-        set_port_state($device['vendor_id'], $port_index, $device['ip'], $snmp, 0);
+// Отключение портов
+if (getPOST("port_off") !== null && $device['snmp_version'] > 0) {
+    $port_off = getPOST("port_off", null, []);
+    if (!empty($port_off) && is_array($port_off)) {
+        foreach ($port_off as $port_index) {
+            $port_index = (int)$port_index;
+            if ($port_index <= 0) continue;
+            LOG_DEBUG($db_link, "Device id: $id disable port with snmp index $port_index");
+            set_port_state($device['vendor_id'], $port_index, $device['ip'], $snmp, 0);
+        }
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
@@ -409,18 +434,18 @@ print_editdevice_submenu($page_url, $id, $device['device_type'], $user_info['log
             <input type='submit' name='regensnmp' value='<?php echo WEB_device_recalc_snmp_port ?>'>
         </div>
 
-        <?php
-        print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
-        print "<tr><td>" . WEB_port_status . "</td></tr>\n";
-        print "<tr><td class=\"down\">" . WEB_port_oper_down . "</td>";
-        print "<td class=\"up\">" . WEB_port_oper_up . "</td>";
-        print "<td class=\"shutdown\">" . WEB_port_admin_shutdown . "</td><tr>\n";
-        print "</table>\n";
-        print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
-        print "<tr><td>" . WEB_port_speed . "</td></tr>\n";
-        print "<tr><td class=\"speed10M\">" . WEB_port_speed_10 . "</td><td class=\"speed100M\">" . WEB_port_speed_100 . "</td><td class=\"speed1G\">" . WEB_port_speed_1G . "</td><td class=\"speed10G\">" . WEB_port_speed_10G . "</td><tr>\n";
-        print "</table>\n";
-        print "</form>";
-        unset_lock_discovery($db_link, $id);
-        require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.simple.php");
-        ?>
+<?php
+print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
+print "<tr><td>" . WEB_port_status . "</td></tr>\n";
+print "<tr><td class=\"down\">" . WEB_port_oper_down . "</td>";
+print "<td class=\"up\">" . WEB_port_oper_up . "</td>";
+print "<td class=\"shutdown\">" . WEB_port_admin_shutdown . "</td><tr>\n";
+print "</table>\n";
+print "<table class=\"data\" cellspacing=\"1\" cellpadding=\"4\">\n";
+print "<tr><td>" . WEB_port_speed . "</td></tr>\n";
+print "<tr><td class=\"speed10M\">" . WEB_port_speed_10 . "</td><td class=\"speed100M\">" . WEB_port_speed_100 . "</td><td class=\"speed1G\">" . WEB_port_speed_1G . "</td><td class=\"speed10G\">" . WEB_port_speed_10G . "</td><tr>\n";
+print "</table>\n";
+print "</form>";
+unset_lock_discovery($db_link, $id);
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.simple.php");
+?>

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 441 - 233
html/inc/common.php


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно