Bläddra i källkod

web: added several interface improvements
nagios: fixed generation of configs for passive devices during snmp polling

root 1 år sedan
förälder
incheckning
1084df5

+ 68 - 0
docs/mysql/nagios.sql

@@ -0,0 +1,68 @@
+-- phpMyAdmin SQL Dump
+-- version 5.1.1
+-- https://www.phpmyadmin.net/
+--
+-- Хост: localhost
+-- Время создания: Фев 03 2025 г., 17:41
+-- Версия сервера: 10.6.18-MariaDB-0ubuntu0.22.04.1-log
+-- Версия PHP: 8.1.2-1ubuntu2.19
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- База данных: `nagios`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Структура таблицы `netdevices`
+--
+
+CREATE TABLE `netdevices` (
+  `id` bigint(20) NOT NULL,
+  `device_id` int(11) NOT NULL DEFAULT 0,
+  `changed` bigint(20) DEFAULT NULL,
+  `data_id` int(11) NOT NULL DEFAULT 0,
+  `data_type` int(11) NOT NULL DEFAULT 0,
+  `data_value1` bigint(20) NOT NULL DEFAULT 0,
+  `data_value2` bigint(20) NOT NULL DEFAULT 0,
+  `data_value3` bigint(20) NOT NULL DEFAULT 0,
+  `data_value4` bigint(20) NOT NULL DEFAULT 0,
+  `ip` bigint(20) NOT NULL DEFAULT 0
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
+
+--
+-- Индексы сохранённых таблиц
+--
+
+--
+-- Индексы таблицы `netdevices`
+--
+ALTER TABLE `netdevices`
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `device_id` (`device_id`,`data_id`,`data_type`),
+  ADD KEY `data_id` (`data_id`,`data_type`,`ip`);
+
+--
+-- AUTO_INCREMENT для сохранённых таблиц
+--
+
+--
+-- AUTO_INCREMENT для таблицы `netdevices`
+--
+ALTER TABLE `netdevices`
+  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

+ 4 - 3
html/admin/customers/devmodels.php

@@ -116,7 +116,7 @@ print_control_submenu($page_url);
 <td><b><?php echo WEB_list_models; ?></b></td>
 <td><?php print_vendor_select($db_link,'vendor_select',$f_vendor_select); ?></td>
 <td><?php print WEB_rows_at_page."&nbsp:";print_row_at_pages('rows',$displayed); ?></td>
-<td><input type="submit" name="OK" value="<?php print WEB_btn_show; ?>"></td>
+<td><input id='apply' name='apply' type="submit" name="OK" value="<?php print WEB_btn_show; ?>"></td>
 </tr>
 </table>
 
@@ -143,8 +143,8 @@ print_navigation($page_url,$page,$displayed,$count_records[0],$total);
 <td><b><?php echo WEB_cell_poe_in; ?></b></td>
 <td><b><?php echo WEB_cell_poe_out; ?></b></td>
 <td><b><?php echo WEB_nagios_template; ?></b></td>
-<td><input type="submit" name='save' value="<?php echo WEB_btn_save; ?>"></td>
-<td><input type="submit" name='remove' value="<?php echo WEB_btn_delete; ?>"></td>
+<td><input id='save' type="submit" name='save' value="<?php echo WEB_btn_save; ?>"></td>
+<td><input id='remove' type="submit" name='remove' value="<?php echo WEB_btn_delete; ?>"></td>
 </tr>
 <?php
 $t_ou = get_records_sql($db_link,'SELECT * FROM device_models '.$v_filter." ORDER BY vendor_id, model_name LIMIT $start,$displayed");
@@ -167,6 +167,7 @@ foreach ($t_ou as $row) {
 <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
 </div>
 </form>
+
 <?php
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
 ?>

+ 21 - 2
html/admin/devices/index.php

@@ -37,7 +37,7 @@ if (!empty($sort_field) and !empty($order)) { $sort_sql = " ORDER BY $sort_field
 <td class="info" colspan=3> <?php  print WEB_device_type_show; print_devtypes_select($db_link, "devtypes", $f_devtype_id, "id<3"); ?>
 <td class="info" colspan=3> <?php  print WEB_models; print_devmodels_select($db_link, "devmodels", $f_devmodel_id); ?>
 <?php print WEB_device_show_location; print_building_select($db_link, "building_id", $f_building_id); ?></td>
-<td class="info"><input type="submit" name="apply" value="<?php echo WEB_btn_show; ?>"></td>
+<td class="info"><input type="submit" id="apply" name="apply" value="<?php echo WEB_btn_show; ?>"></td>
 <td class="info" colspan=2><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove_device" value="<?php echo WEB_btn_delete; ?>"></td>
 </tr>
 <tr align="center">
@@ -90,6 +90,25 @@ foreach ($switches as $row) {
 <td class="up"><?php echo WEB_device_online; ?></td>
 <tr>
 </table>
+
+<script>
+document.getElementById('devtypes').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('apply');
+  buttonApply.click();
+});
+
+document.getElementById('devmodels').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('apply');
+  buttonApply.click();
+});
+
+document.getElementById('building_id').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('apply');
+  buttonApply.click();
+});
+
+</script>
+
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
 ?>

+ 22 - 4
html/admin/groups/edit_group.php

@@ -111,9 +111,9 @@ print "<td class=\"data\"></td>\n";
 <td class="data"><?php print WEB_cell_enabled."&nbsp"; print_qa_select('f_enabled', $ou_info['enabled']); ?></td>
 <td class="data"><?php print WEB_cell_filter."&nbsp"; print_group_select($db_link, 'f_filter_group_id', $ou_info['filter_group_id']); ?></td>
 <td class="data"><?php print WEB_cell_shaper."&nbsp"; print_queue_select($db_link, 'f_queue_id', $ou_info['queue_id']); ?></td>
-<td class="data" align=right><?php print WEB_cell_life_hours."&nbsp"; print "<input  type=\"number\" min=1 name='f_life_duration' value='{$ou_info['life_duration']}'";
+<td class="data" align=right><?php print WEB_cell_life_hours."&nbsp"; print "<input  type=\"number\" min=1 id='f_life_duration' name='f_life_duration' value='{$ou_info['life_duration']}'";
 if (!$ou_info['dynamic']) { print "disabled"; }; print " style=\"width:35%;\" ></td>\n"; ?>
-<?php print "<td align=right class=\"data\"><button name='save' value='{$ou_info['id']}'>".WEB_btn_save."</button></td>\n"; ?>
+<?php print "<td align=right class=\"data\"><button id='save' name='save' value='{$ou_info['id']}'>".WEB_btn_save."</button></td>\n"; ?>
 </tr>
 </table>
 <br>
@@ -139,7 +139,7 @@ foreach ( $t_auth_rules as $row ) {
     print "<td class=\"data\">"; print_qa_rule_select("s_type[]","{$row['type']}"); print "</td>\n";
     print "<td class=\"data\"><input type=\"text\" name='s_rule[]' value='{$row['rule']}'></td>\n";
     print "<td class=\"data\"><input type=\"text\" name='s_comment[]' value='{$row['comment']}'></td>\n";
-    print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
+    print "<td class=\"data\"><button id='s_save' name='s_save' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
     print "</tr>\n";
 }
 ?>
@@ -150,4 +150,22 @@ print "<input type=\"text\" name='s_new_rule' value=''>"; ?>
 <input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>">
 </div>
 </form>
-<?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>
+
+<script>
+document.getElementById('f_dynamic').addEventListener('change', function(event) {
+  const selectValue = this.value;
+  const inputField = document.getElementById('f_life_duration');
+  if (selectValue === '1') {
+    inputField.disabled = false;
+    inputField.value=24;
+  } else {
+    inputField.disabled = true;
+  }
+});
+
+</script>
+
+<?php
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
+?>
+

+ 30 - 1
html/admin/iplist/index.php

@@ -224,6 +224,35 @@ print_navigation($page_url,$page,$displayed,$count_records[0],$total);
 <script src="/js/remodal/remodal.min.js"></script>
 <script src="/js/remodal-auth.js"></script>
 
+<script>
+document.getElementById('ou').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('cidr').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('enabled').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('ip_type').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('rows').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+
+</script>
+
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
 ?>

+ 25 - 1
html/admin/iplist/nagios.php

@@ -164,6 +164,30 @@ print_navigation($page_url,$page,$displayed,$count_records[0],$total);
 <script src="/js/remodal/remodal.min.js"></script>
 <script src="/js/remodal-auth.js"></script>
 
+<script>
+document.getElementById('ou').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('subnet').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('enabled').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('rows').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+
+</script>
+
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
 ?>

+ 23 - 2
html/admin/reports/index-full.php

@@ -21,7 +21,7 @@ print_reports_submenu($page_url);
 <?php echo WEB_log_stop_date; ?>:&nbsp<input type="date" name="date_stop" value="<?php echo $date2; ?>" />
 <?php echo WEB_cell_gateway; ?>:&nbsp<?php print_gateway_select($db_link, 'gateway', $rgateway); ?>
 <?php print WEB_rows_at_page."&nbsp"; print_row_at_pages('rows',$displayed); ?>
-<input type="submit" value="<?php echo WEB_btn_show; ?>">
+<input id='btn_filter' name='btn_filter' type="submit" value="<?php echo WEB_btn_show; ?>">
 </form>
 
 <?php
@@ -112,5 +112,26 @@ print "</tr>\n";
 
 <?php
 print_navigation($page_url,$page,$displayed,$count_records[0],$total);
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
+?>
+
+<script>
+document.getElementById('ou').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('rows').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('gateway').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+</script>
+
+<?php
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
 ?>

+ 2 - 1
html/admin/users/editauth.php

@@ -425,8 +425,9 @@ if (empty($auth_info['eof']) or $auth_info['eof'] == '0000-00-00 00:00:00') {
 </form>
 <br>
 
+
 <script>
-document.getElementById('f_dynamic').addEventListener('change', function() {
+document.getElementById('f_dynamic').addEventListener('change', function(event) {
   const selectValue = this.value;
   const inputField = document.getElementById('f_eof');
   if (selectValue === '1') {

+ 14 - 1
html/admin/users/index.php

@@ -190,6 +190,19 @@ print_navigation($page_url,$page,$displayed,$count_records[0],$total);
 <script src="/js/remodal/remodal.min.js"></script>
 <script src="/js/remodal-user.js"></script>
 
+<script>
+document.getElementById('ou').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+document.getElementById('rows').addEventListener('change', function(event) {
+  const buttonApply = document.getElementById('btn_filter');
+  buttonApply.click();
+});
+
+</script>
+
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
+require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.simple.php");
 ?>

+ 48 - 48
html/inc/common.php

@@ -486,7 +486,7 @@ function decrypt_string($crypted_string)
 
 function print_ou_select($db, $ou_name, $ou_value)
 {
-    print "<select name=\"$ou_name\" >\n";
+    print "<select id=\"$ou_name\" name=\"$ou_name\" >\n";
     $t_ou = mysqli_query($db, "SELECT id,ou_name FROM OU ORDER BY ou_name");
     while (list($f_ou_id, $f_ou_name) = mysqli_fetch_array($t_ou)) {
         print_select_item($f_ou_name, $f_ou_id, $ou_value);
@@ -509,7 +509,7 @@ function get_subnet_description($db, $subnet_id)
 
 function print_add_gw_subnets($db, $device_id, $gs_name)
 {
-    print "<select name=\"$gs_name\" >\n";
+    print "<select id=\"$gs_name\" name=\"$gs_name\" >\n";
     $t_gs = mysqli_query($db, "SELECT id,subnet,comment FROM subnets WHERE subnets.free=0 AND subnets.id NOT IN (SELECT subnet_id FROM gateway_subnets WHERE gateway_subnets.device_id=" . $device_id . ") ORDER BY subnet");
     while (list($f_gs_id, $f_gs_name, $f_gs_comment) = mysqli_fetch_array($t_gs)) {
         print_select_item($f_gs_name . '(' . $f_gs_comment . ')', $f_gs_id, 0);
@@ -519,7 +519,7 @@ function print_add_gw_subnets($db, $device_id, $gs_name)
 
 function print_add_dev_interface($db, $device_id, $int_list, $int_name)
 {
-    print "&nbsp<select name=\"$int_name\" >\n";
+    print "&nbsp<select id=\"$int_name\" name=\"$int_name\" >\n";
     $t_int = get_records_sql($db, "SELECT * FROM device_l3_interfaces WHERE device_id=" . $device_id);
     $int_exists = [];
     foreach ($t_int as $interface) {
@@ -544,7 +544,7 @@ function print_add_dev_interface($db, $device_id, $int_list, $int_name)
 
 function print_ou_set($db, $ou_name, $ou_value)
 {
-    print "<select name=\"$ou_name\">\n";
+    print "<select id=\"$ou_name\" name=\"$ou_name\">\n";
     $t_ou = mysqli_query($db, "SELECT id,ou_name FROM OU WHERE id>=1 ORDER BY ou_name");
     while (list($f_ou_id, $f_ou_name) = mysqli_fetch_array($t_ou)) {
         print_select_item($f_ou_name, $f_ou_id, $ou_value);
@@ -554,7 +554,7 @@ function print_ou_set($db, $ou_name, $ou_value)
 
 function print_subnet_select($db, $subnet_name, $subnet_value)
 {
-    print "<select name=\"$subnet_name\" >\n";
+    print "<select id=\"$subnet_name\" name=\"$subnet_name\" >\n";
     $t_subnet = mysqli_query($db, "SELECT id,subnet FROM subnets ORDER BY ip_int_start");
     print_select_item(WEB_select_item_all_ips, 0, $subnet_value);
     while (list($f_subnet_id, $f_subnet_name) = mysqli_fetch_array($t_subnet)) {
@@ -565,7 +565,7 @@ function print_subnet_select($db, $subnet_name, $subnet_value)
 
 function print_acl_select($db, $acl_name, $acl_value)
 {
-    print "<select name=\"$acl_name\" >\n";
+    print "<select id=\"$acl_name\" name=\"$acl_name\" >\n";
     $t_acl = mysqli_query($db, "SELECT id,name FROM acl ORDER BY id");
     while (list($f_acl_id, $f_acl_name) = mysqli_fetch_array($t_acl)) {
         print_select_item($f_acl_name, $f_acl_id, $acl_value);
@@ -575,7 +575,7 @@ function print_acl_select($db, $acl_name, $acl_value)
 
 function print_device_ip_select($db, $ip_name, $ip, $user_id)
 {
-    print "<select name=\"$ip_name\">\n";
+    print "<select id=\"$ip_name\" name=\"$ip_name\">\n";
     $auth_list = get_records_sql($db, "SELECT ip FROM User_auth WHERE user_id=$user_id AND deleted=0 ORDER BY ip_int");
     foreach ($auth_list as $row) {
         print_select_item($row['ip'], $row['ip'], $ip);
@@ -585,7 +585,7 @@ function print_device_ip_select($db, $ip_name, $ip, $user_id)
 
 function print_subnet_select_office($db, $subnet_name, $subnet_value)
 {
-    print "<select name=\"$subnet_name\" >\n";
+    print "<select id=\"$subnet_name\" name=\"$subnet_name\" >\n";
     $t_subnet = mysqli_query($db, "SELECT id,subnet FROM subnets WHERE office=1 ORDER BY ip_int_start");
     print_select_item(WEB_select_item_all_ips, 0, $subnet_value);
     while (list($f_subnet_id, $f_subnet_name) = mysqli_fetch_array($t_subnet)) {
@@ -596,7 +596,7 @@ function print_subnet_select_office($db, $subnet_name, $subnet_value)
 
 function print_subnet_select_office_splitted($db, $subnet_name, $subnet_value)
 {
-    print "<select name=\"$subnet_name\" >\n";
+    print "<select id=\"$subnet_name\" name=\"$subnet_name\" >\n";
     $t_subnet = mysqli_query($db, "SELECT id,subnet,ip_int_start,ip_int_stop FROM subnets WHERE office=1 ORDER BY ip_int_start");
     print_select_item(WEB_select_item_all_ips, 0, $subnet_value);
     while (list($f_subnet_id, $f_subnet_name, $f_start_ip, $f_stop_ip) = mysqli_fetch_array($t_subnet)) {
@@ -614,7 +614,7 @@ function print_subnet_select_office_splitted($db, $subnet_name, $subnet_value)
 
 function print_loglevel_select($item_name, $value)
 {
-    print "<select name=\"$item_name\">\n";
+    print "<select id=\"$item_name\" name=\"$item_name\">\n";
     print_select_item('Error', L_ERROR, $value);
     print_select_item('Warning', L_WARNING, $value);
     print_select_item('Info', L_INFO, $value);
@@ -865,7 +865,7 @@ function get_building($db, $building_value)
 
 function print_device_model_select($db, $device_model_name, $device_model_value)
 {
-    print "<select name=\"$device_model_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$device_model_name\" name=\"$device_model_name\" class=\"js-select-single\">\n";
     $t_device_model = mysqli_query($db, "SELECT M.id,M.model_name,V.name FROM device_models M,vendors V WHERE M.vendor_id = V.id ORDER BY V.name,M.model_name");
     while (list($f_device_model_id, $f_device_model_name, $f_vendor_name) = mysqli_fetch_array($t_device_model)) {
         print_select_item($f_vendor_name . " " . $f_device_model_name, $f_device_model_id, $device_model_value);
@@ -875,7 +875,7 @@ function print_device_model_select($db, $device_model_name, $device_model_value)
 
 function print_group_select($db, $group_name, $group_value)
 {
-    print "<select name=\"$group_name\">\n";
+    print "<select id=\"$group_name\" name=\"$group_name\">\n";
     $t_group = mysqli_query($db, "SELECT id,group_name FROM Group_list Order by group_name");
     while (list($f_group_id, $f_group_name) = mysqli_fetch_array($t_group)) {
         print_select_item($f_group_name, $f_group_id, $group_value);
@@ -885,7 +885,7 @@ function print_group_select($db, $group_name, $group_value)
 
 function print_building_select($db, $building_name, $building_value)
 {
-    print "<select name=\"$building_name\">\n";
+    print "<select id=\"$building_name\" name=\"$building_name\">\n";
     print_select_item(WEB_select_item_all, 0, $building_value);
     $t_building = mysqli_query($db, "SELECT id,name FROM building Order by name");
     while (list($f_building_id, $f_building_name) = mysqli_fetch_array($t_building)) {
@@ -896,7 +896,7 @@ function print_building_select($db, $building_name, $building_value)
 
 function print_devmodels_select($db, $devmodel_name, $devmodel_value, $dev_filter = 'device_type<=2')
 {
-    print "<select name=\"$devmodel_name\">\n";
+    print "<select id=\"$devmodel_name\" name=\"$devmodel_name\">\n";
     print_select_item(WEB_select_item_all, -1, $devmodel_value);
     $t_devmodel = mysqli_query($db, "SELECT M.id,V.name,M.model_name FROM device_models M,vendors V WHERE M.vendor_id = V.id and M.id in (SELECT device_model_id FROM devices WHERE $dev_filter) ORDER BY V.name,M.model_name");
     while (list($f_devmodel_id, $f_devmodel_vendor, $f_devmodel_name) = mysqli_fetch_array($t_devmodel)) {
@@ -907,7 +907,7 @@ function print_devmodels_select($db, $devmodel_name, $devmodel_value, $dev_filte
 
 function print_devtypes_select($db, $devtype_name, $devtype_value, $mode)
 {
-    print "<select name=\"$devtype_name\">\n";
+    print "<select id=\"$devtype_name\" name=\"$devtype_name\">\n";
     print_select_item(WEB_select_item_all, -1, $devtype_value);
     $filter = '';
     if (!empty($mode)) {
@@ -922,7 +922,7 @@ function print_devtypes_select($db, $devtype_name, $devtype_value, $mode)
 
 function print_devtype_select($db, $devtype_name, $devtype_value)
 {
-    print "<select name=\"$devtype_name\">\n";
+    print "<select id=\"$devtype_name\" name=\"$devtype_name\">\n";
     $t_devtype = mysqli_query($db, "SELECT id,`name." . HTML_LANG . "` FROM device_types ORDER BY `name." . HTML_LANG . "`");
     while (list($f_devtype_id, $f_devtype_name) = mysqli_fetch_array($t_devtype)) {
         print_select_item($f_devtype_name, $f_devtype_id, $devtype_value);
@@ -1000,7 +1000,7 @@ function get_gw_subnets($db, $device_id)
 
 function print_queue_select($db, $queue_name, $queue_value)
 {
-    print "<select name=\"$queue_name\">\n";
+    print "<select id=\"$queue_name\" name=\"$queue_name\">\n";
     $t_queue = mysqli_query($db, "SELECT id,queue_name FROM Queue_list Order by queue_name");
     while (list($f_queue_id, $f_queue_name) = mysqli_fetch_array($t_queue)) {
         print_select_item($f_queue_name, $f_queue_id, $queue_value);
@@ -1016,7 +1016,7 @@ function get_queue($db, $queue_value)
 
 function print_qa_l3int_select($qa_name, $qa_value = 0)
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     print_select_item(WEB_select_item_lan, 0, $qa_value);
     print_select_item(WEB_select_item_wan, 1, $qa_value);
     print "</select>\n";
@@ -1024,7 +1024,7 @@ function print_qa_l3int_select($qa_name, $qa_value = 0)
 
 function print_qa_rule_select($qa_name, $qa_value = 1)
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     print_select_item('Subnet', 1, $qa_value);
     print_select_item('Mac', 2, $qa_value);
     print_select_item('Hostname', 3, $qa_value);
@@ -1033,7 +1033,7 @@ function print_qa_rule_select($qa_name, $qa_value = 1)
 
 function print_snmp_auth_proto_select($qa_name, $qa_value = 'sha512')
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     print_select_item('sha512', 'sha512', $qa_value);
     print_select_item('sha256', 'sha256', $qa_value);
     print_select_item('sha', 'sha', $qa_value);
@@ -1043,7 +1043,7 @@ function print_snmp_auth_proto_select($qa_name, $qa_value = 'sha512')
 
 function print_snmp_priv_proto_select($qa_name, $qa_value = 'aes128')
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     print_select_item('aes128', 'aes128', $qa_value);
     print_select_item('aes', 'aes', $qa_value);
     print_select_item('des', 'des', $qa_value);
@@ -1075,7 +1075,7 @@ function print_qa_select($qa_name, $qa_value = 0)
 
 function print_list_select($qa_name, $qa_value, $list)
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     if (empty($qa_value)) {
         $qa_value = '';
     }
@@ -1091,7 +1091,7 @@ function print_qa_select_ext($qa_name, $qa_value = 0, $readonly = 1)
     if ($readonly) {
         $state = 'disabled=true';
     }
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     print_select_item_ext(WEB_select_item_yes, 1, $qa_value, $readonly);
     print_select_item_ext(WEB_select_item_no, 0, $qa_value, $readonly);
     print "</select>\n";
@@ -1136,7 +1136,7 @@ function print_control_proto_select($qa_name, $qa_value = -1)
 
 function print_snmp_select($qa_name, $qa_value = 0)
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     print_select_item('Disabled', 0, $qa_value);
     print_select_item('v1', 1, $qa_value);
     print_select_item('v2', 2, $qa_value);
@@ -1146,7 +1146,7 @@ function print_snmp_select($qa_name, $qa_value = 0)
 
 function print_dhcp_select($qa_name, $qa_value = 0)
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     if (!isset($qa_value) or strlen($qa_value) == 0) {
         $qa_value = 'all';
     }
@@ -1175,7 +1175,7 @@ function print_dhcp_acl_select($qa_name)
 
 function print_enabled_select($qa_name, $qa_value)
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     if (!isset($qa_value) or strlen($qa_value) == 0) {
         $qa_value = 0;
     }
@@ -1187,7 +1187,7 @@ function print_enabled_select($qa_name, $qa_value)
 
 function print_ip_type_select($qa_name, $qa_value)
 {
-    print "<select name=\"$qa_name\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\">\n";
     if (!isset($qa_value) or strlen($qa_value) == 0) {
         $qa_value = 0;
     }
@@ -1200,7 +1200,7 @@ function print_ip_type_select($qa_name, $qa_value)
 
 function print_vendor_select($db, $qa_name, $qa_value)
 {
-    print "<select name=\"$qa_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\"  style=\"width: 100%\">\n";
     $sSQL = "SELECT id,`name` FROM `vendors` order by `name`";
     $vendors = mysqli_query($db, $sSQL);
     print_select_item(WEB_select_item_all, 0, $qa_value);
@@ -1212,7 +1212,7 @@ function print_vendor_select($db, $qa_name, $qa_value)
 
 function print_vendor_set($db, $qa_name, $qa_value)
 {
-    print "<select name=\"$qa_name\" class=\"js-select-single\" style=\"width: 100%\">\n";
+    print "<select id=\"$qa_name\" name=\"$qa_name\" style=\"width: 100%\">\n";
     $sSQL = "SELECT id,`name` FROM `vendors` order by `name`";
     $vendors = mysqli_query($db, $sSQL);
     while (list($v_id, $v_name) = mysqli_fetch_array($vendors)) {
@@ -1240,7 +1240,7 @@ function get_qa($qa_value)
 
 function print_action_select($action_name, $action_value)
 {
-    print "<select name=\"$action_name\">\n";
+    print "<select id=\"$action_name\" name=\"$action_name\">\n";
     print_select_item(WEB_select_item_allow, 1, $action_value);
     print_select_item(WEB_select_item_forbidden, 0, $action_value);
     print "</select>\n";
@@ -1256,7 +1256,7 @@ function get_action($action_value)
 
 function print_filter_select($db, $filter_name, $group_id)
 {
-    print "<select name=\"$filter_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$filter_name\" name=\"$filter_name\" class=\"js-select-single\">\n";
     if (isset($group_id)) {
         $sSQL = "SELECT id,name FROM Filter_list WHERE Filter_list.id not in (Select filter_id FROM Group_filters WHERE group_id=$group_id)";
     } else {
@@ -1290,7 +1290,7 @@ function get_auth_count($db, $user_id)
 
 function print_login_select($db, $login_name, $current_login)
 {
-    print "<select name=\"$login_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$login_name\" name=\"$login_name\" class=\"js-select-single\">\n";
     $t_login = mysqli_query($db, "SELECT id,login FROM User_list Order by Login");
     print_select_item('None', 0, $current_login);
     while (list($f_user_id, $f_login) = mysqli_fetch_array($t_login)) {
@@ -1301,7 +1301,7 @@ function print_login_select($db, $login_name, $current_login)
 
 function print_auth_select($db, $login_name, $current_auth)
 {
-    print "<select name=\"$login_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$login_name\" name=\"$login_name\" class=\"js-select-single\">\n";
     $t_login = mysqli_query($db, "SELECT U.login,U.fio,A.ip,A.id FROM User_list as U, User_auth as A WHERE A.user_id=U.id and A.deleted=0 and (A.id not in (select device_ports.auth_id FROM device_ports) or A.id=$current_auth) order by U.login,U.fio,A.ip");
     print_select_item('Empty', 0, $current_auth);
     while (list($f_login, $f_fio, $f_ip, $f_auth_id) = mysqli_fetch_array($t_login)) {
@@ -1312,7 +1312,7 @@ function print_auth_select($db, $login_name, $current_auth)
 
 function print_auth_select_mac($db, $login_name, $current_auth)
 {
-    print "<select name=\"$login_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$login_name\" name=\"$login_name\" class=\"js-select-single\">\n";
     $t_login = mysqli_query($db, "SELECT U.login,U.fio,A.ip,A.mac,A.id FROM User_list as U, User_auth as A WHERE A.user_id=U.id and A.deleted=0 and (A.id not in (select device_ports.auth_id FROM device_ports) or A.id=$current_auth) order by U.login,U.fio,A.ip");
 
     print_select_item('Empty', 0, $current_auth);
@@ -1333,7 +1333,7 @@ function compact_port_name($port)
 
 function print_device_port_select($db, $field_name, $device_id, $target_id)
 {
-    print "<select name=\"$field_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$field_name\" name=\"$field_name\" class=\"js-select-single\">\n";
     if (empty($target_id)) {
         $target_id = 0;
     }
@@ -1354,7 +1354,7 @@ function print_device_port_select($db, $field_name, $device_id, $target_id)
 
 function print_device_select($db, $field_name, $device_id)
 {
-    print "<select name=\"$field_name\" class=\"js-select-single\" >\n";
+    print "<select id=\"$field_name\" name=\"$field_name\" class=\"js-select-single\" >\n";
     $d_sql = "SELECT D.device_name, D.id FROM devices AS D Where D.deleted=0 order by D.device_name ASC";
     $t_device = mysqli_query($db, $d_sql);
     print_select_item(WEB_select_item_every, 0, $device_id);
@@ -1366,7 +1366,7 @@ function print_device_select($db, $field_name, $device_id)
 
 function print_netdevice_select($db, $field_name, $device_id)
 {
-    print "<select name=\"$field_name\" class=\"js-select-single\" >\n";
+    print "<select id=\"$field_name\" name=\"$field_name\" class=\"js-select-single\" >\n";
     $d_sql = "SELECT D.device_name, D.id FROM devices AS D Where D.deleted=0 and D.device_type<=2 order by D.device_name ASC";
     $t_device = mysqli_query($db, $d_sql);
     print_select_item(WEB_select_item_every, 0, $device_id);
@@ -1378,7 +1378,7 @@ function print_netdevice_select($db, $field_name, $device_id)
 
 function print_vlan_select($db, $field_name, $vlan)
 {
-    print "<select name=\"$field_name\" class=\"js-select-single\">\n";
+    print "<select id=\"$field_name\" name=\"$field_name\" class=\"js-select-single\">\n";
     $d_sql = "SELECT DISTINCT vlan FROM device_ports ORDER BY vlan DESC";
     $v_device = mysqli_query($db, $d_sql);
     if (!isset($vlan) or empty($vlan)) {
@@ -1396,7 +1396,7 @@ function print_vlan_select($db, $field_name, $vlan)
 
 function print_device_select_ip($db, $field_name, $device_ip)
 {
-    print "<select name=\"$field_name\" class=\"js-select-single\" >\n";
+    print "<select id=\"$field_name\" name=\"$field_name\" class=\"js-select-single\" >\n";
     $d_sql = "SELECT D.device_name, D.ip FROM devices AS D Where D.deleted=0 order by D.device_name ASC";
     $t_device = mysqli_query($db, $d_sql);
     print_select_item(WEB_select_item_every, '', $device_ip);
@@ -1408,7 +1408,7 @@ function print_device_select_ip($db, $field_name, $device_ip)
 
 function print_syslog_device_select($db, $field_name, $syslog_filter, $device_ip)
 {
-    print "<select name=\"$field_name\" class=\"js-select-single\" >\n";
+    print "<select id=\"$field_name\" name=\"$field_name\" class=\"js-select-single\" >\n";
     $d_sql = "SELECT R.ip, D.device_name FROM (SELECT DISTINCT ip FROM remote_syslog WHERE $syslog_filter) AS R LEFT JOIN (SELECT ip, device_name FROM devices WHERE deleted=0) AS D ON R.ip=D.ip ORDER BY R.ip ASC";
     $t_device = mysqli_query($db, $d_sql);
     print_select_item(WEB_select_item_every, '', $device_ip);
@@ -1423,7 +1423,7 @@ function print_syslog_device_select($db, $field_name, $syslog_filter, $device_ip
 
 function print_gateway_select($db, $field_name, $device_id)
 {
-    print "<select name=\"$field_name\" >\n";
+    print "<select id=\"$field_name\" name=\"$field_name\" >\n";
     $d_sql = "SELECT D.device_name, D.id FROM devices AS D Where D.deleted=0 and D.device_type=2 order by D.device_name ASC";
     $t_device = mysqli_query($db, $d_sql);
     print_select_item(WEB_select_item_every, 0, $device_id);
@@ -1671,7 +1671,7 @@ function get_port($db, $port_id)
 
 function print_option_select($db, $option_name)
 {
-    print "<select name=\"$option_name\">\n";
+    print "<select id=\"$option_name\" name=\"$option_name\">\n";
     $t_option = mysqli_query($db, "SELECT id,option_name FROM config_options WHERE uniq=0 AND draft=0 order by option_name");
     while (list($f_id, $f_name) = mysqli_fetch_array($t_option)) {
         print "<option value=$f_id>$f_name</option>";
@@ -2429,7 +2429,7 @@ function write_log($db, $msg, $level, $auth_id = 0)
 
 function print_year_select($year_name, $year)
 {
-    print "<select name=\"$year_name\" >\n";
+    print "<select id=\"$year_name\" name=\"$year_name\" >\n";
     for ($i = $year - 10; $i <= $year + 10; $i++) {
         print_select_item($i, $i, $year);
     }
@@ -2440,7 +2440,7 @@ function print_date_select($dd, $mm, $yy)
 {
     if ($dd >= 1) {
         print "<b>День</b>\n";
-        print "<select name=\"day\" >\n";
+        print "<select id=\"day\" name=\"day\" >\n";
         for ($i = 1; $i <= 31; $i++) {
             print_select_item($i, $i, $dd);
         }
@@ -2449,7 +2449,7 @@ function print_date_select($dd, $mm, $yy)
 
     if ($mm >= 1) {
         print "<b>Месяц</b>\n";
-        print "<select name=\"month\" >\n";
+        print "<select id=\"month\"  name=\"month\" >\n";
         for ($i = 1; $i <= 12; $i++) {
             $tmp_date = DateTimeImmutable::createFromFormat('U', strtotime("$i/01/$yy"));
             $month_name = $tmp_date->format('F');
@@ -2466,7 +2466,7 @@ function print_date_select2($dd, $mm, $yy)
 {
     if ($dd >= 1) {
         print "<b>День</b>\n";
-        print "<select name=\"day2\" >\n";
+        print "<select id=\"day2\" name=\"day2\" >\n";
         for ($i = 1; $i <= 31; $i++) {
             print_select_item($i, $i, $dd);
         }
@@ -2475,7 +2475,7 @@ function print_date_select2($dd, $mm, $yy)
 
     if ($mm >= 1) {
         print "<b>Месяц</b>\n";
-        print "<select name=\"month2\" >\n";
+        print "<select id=\"month2\" name=\"month2\" >\n";
         for ($i = 1; $i <= 12; $i++) {
             $tmp_date = DateTimeImmutable::createFromFormat('U', strtotime("$i/01/$yy"));
             $month_name = $tmp_date->format('F');
@@ -3502,7 +3502,7 @@ function print_select_item_ext($description, $value, $current, $disabled)
 
 function print_row_at_pages($name, $value)
 {
-    print "<select name='" . $name . "'>\n";
+    print "<select id='" . $name . "' name='" . $name . "'>\n";
     print_select_item(WEB_select_item_more, pow(10, 10), $value);
     print_select_item('25', 25, $value);
     print_select_item('50', 50, $value);

+ 5 - 1
scripts/eyelib/nagios.pm

@@ -12,9 +12,9 @@ use vars qw(@EXPORT @ISA);
 use eyelib::config;
 use eyelib::main;
 use eyelib::database;
+use eyelib::snmp;
 use Time::Local;
 use Data::Dumper;
-use eyelib::mfi;
 
 @ISA = qw(Exporter);
 @EXPORT = qw(
@@ -80,6 +80,10 @@ sub read_host_template {
 my $device = shift;
 my $template_file = shift;
 my $result;
+
+if (!exists $device->{parent_snmp} and !$device->{snmp}) { setCommunity($device); }
+if (exists $device->{parent_snmp} and !$device->{snmp}) { $device->{snmp} = $device->{parent_snmp}; }
+
 my @custom_cfg=();
 if (-e $template_file) { @custom_cfg = read_file($template_file); } else { return; }
 if (@custom_cfg and scalar(@custom_cfg)) {