Dmitriev Roman 5 лет назад
Родитель
Сommit
dd79900fe4

+ 2 - 2
docs/mysql/stat_table_vendors.sql

@@ -46,8 +46,8 @@ INSERT INTO `vendors` (`id`, `name`) VALUES
 (30, 'HW-group'),
 (30, 'HW-group'),
 (31, 'Netping'),
 (31, 'Netping'),
 (32, 'Trassir'),
 (32, 'Trassir'),
-(33, 'QSC');
-
+(33, 'QSC'),
+(34, 'Projectiondesign');
 --
 --
 ALTER TABLE `vendors`
 ALTER TABLE `vendors`
   ADD PRIMARY KEY (`id`);
   ADD PRIMARY KEY (`id`);

+ 1 - 1
html/admin/devices/deleted.php

@@ -28,7 +28,7 @@ foreach ($switches as $row) {
     print "<td class=\"$cl\"><input type=hidden name=\"id\" value=".$row['id'].">".$row['id']."</td>\n";
     print "<td class=\"$cl\"><input type=hidden name=\"id\" value=".$row['id'].">".$row['id']."</td>\n";
     print "<td class=\"$cl\" align=left><a href=editdevice.php?id=".$row['id'].">" . $row['device_name'] . "</a></td>\n";
     print "<td class=\"$cl\" align=left><a href=editdevice.php?id=".$row['id'].">" . $row['device_name'] . "</a></td>\n";
     print "<td class=\"$cl\">".$row['ip']."</td>\n";
     print "<td class=\"$cl\">".$row['ip']."</td>\n";
-    print "<td class=\"$cl\">" . get_vendor_name($db_link, $row['vendor_id']) . " " . $row['device_model'] . "</td>\n";
+    print "<td class=\"$cl\">" . get_vendor_name($db_link, $row['vendor_id']) . " " . get_device_model($db_link,$row['device_model_id']) . "</td>\n";
     print "<td class=\"$cl\">" . get_building($db_link, $row['building_id']) . "(" . $row['comment'] . ")</td>\n";
     print "<td class=\"$cl\">" . get_building($db_link, $row['building_id']) . "(" . $row['comment'] . ")</td>\n";
 }
 }
 ?>
 ?>

+ 4 - 6
html/admin/devices/editdevice.php

@@ -39,7 +39,7 @@ if (isset($_POST["editdevice"]) and isset($id)) {
     }
     }
     unset($new);
     unset($new);
     if (isset($_POST["f_device_name"])) { $new['device_name'] = substr($_POST["f_device_name"], 0, 50); }
     if (isset($_POST["f_device_name"])) { $new['device_name'] = substr($_POST["f_device_name"], 0, 50); }
-    if (isset($_POST["f_device_model"])) { $new['device_model'] = substr($_POST["f_device_model"], 0, 50); }
+    if (isset($_POST["f_device_model_id"])) { $new['device_model_id'] = $_POST["f_device_model_id"]*1; }
     if (isset($_POST["f_devtype_id"])) { $new['device_type'] = $_POST["f_devtype_id"]*1; }
     if (isset($_POST["f_devtype_id"])) { $new['device_type'] = $_POST["f_devtype_id"]*1; }
     if (isset($_POST["f_comment"])) { $new['comment'] = $_POST["f_comment"]; }
     if (isset($_POST["f_comment"])) { $new['comment'] = $_POST["f_comment"]; }
     if (isset($_POST["f_SN"])) { $new['SN'] = $_POST["f_SN"]; }
     if (isset($_POST["f_SN"])) { $new['SN'] = $_POST["f_SN"]; }
@@ -64,7 +64,7 @@ if (isset($_POST["editdevice"]) and isset($id)) {
     if (!isset($new['user_id']) or empty($new['user_id'])) { $new['user_id']=0; }
     if (!isset($new['user_id']) or empty($new['user_id'])) { $new['user_id']=0; }
     if (isset($_POST["f_nagios"])) { $new['nagios'] = $_POST["f_nagios"] * 1; }
     if (isset($_POST["f_nagios"])) { $new['nagios'] = $_POST["f_nagios"] * 1; }
     if (empty($new['nagios'])) { $new['nagios_status'] = 'UP'; }
     if (empty($new['nagios'])) { $new['nagios_status'] = 'UP'; }
-    if (isset($_POST["f_vendor_id"])) { $new['vendor_id'] = $_POST["f_vendor_id"] * 1; }
+    $new['vendor_id'] = get_device_model_vendor($db_link,$new['device_model_id']);
     if (isset($_POST["f_port_count"])) { $new['port_count'] = $sw_ports; }
     if (isset($_POST["f_port_count"])) { $new['port_count'] = $sw_ports; }
     update_record($db_link, "devices", "id='$id'", $new);
     update_record($db_link, "devices", "id='$id'", $new);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     header("Location: " . $_SERVER["REQUEST_URI"]);
@@ -104,14 +104,12 @@ print "<td class=\"data\"><input type=\"text\" name='f_port_count' value='".$dev
 print "</tr>\n";
 print "</tr>\n";
 ?>
 ?>
 </tr>
 </tr>
-<td>Вендор</td>
-<td>Модель</td>
+<td colspan=2>Модель</td>
 <td colspan=2>SN</td>
 <td colspan=2>SN</td>
 
 
 <?php
 <?php
 print "<tr>\n";
 print "<tr>\n";
-print "<td class=\"data\">"; print_vendor_select($db_link, 'f_vendor_id', $device['vendor_id']); print "</td>\n";
-print "<td class=\"data\"><input type=\"text\" name='f_device_model' value='".$device['device_model']."'></td>\n";
+print "<td class=\"data\" colspan=2>"; print_device_model_select($db_link,'f_device_model_id',$device['device_model_id']); print "</td>\n";
 print "<td class=\"data\" colspan=2><input type=\"text\" size=50 name='f_SN' value='".$device['SN']."'></td>\n";
 print "<td class=\"data\" colspan=2><input type=\"text\" size=50 name='f_SN' value='".$device['SN']."'></td>\n";
 print "</tr>\n";
 print "</tr>\n";
 
 

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

@@ -60,7 +60,7 @@ if (!empty($sort_field) and !empty($order)) { $sort_sql = " ORDER BY $sort_field
 <td><b><a href=index.php?sort=device_type&order=<?php print $new_order; ?>>Тип</a></b></td>
 <td><b><a href=index.php?sort=device_type&order=<?php print $new_order; ?>>Тип</a></b></td>
 <td><b><a href=index.php?sort=device_name&order=<?php print $new_order; ?>>Название</a></b></td>
 <td><b><a href=index.php?sort=device_name&order=<?php print $new_order; ?>>Название</a></b></td>
 <td><b><a href=index.php?sort=ip&order=<?php print $new_order; ?>>IP</a></b></td>
 <td><b><a href=index.php?sort=ip&order=<?php print $new_order; ?>>IP</a></b></td>
-<td><b><a href=index.php?sort=device_model&order=<?php print $new_order; ?>>Модель</a></b></td>
+<td><b><a href=index.php?sort=device_model_id&order=<?php print $new_order; ?>>Модель</a></b></td>
 <td><b><a href=index.php?sort=building_id&order=<?php print $new_order; ?>>Расположен</a></b></td>
 <td><b><a href=index.php?sort=building_id&order=<?php print $new_order; ?>>Расположен</a></b></td>
 <td><b>Портов</b></td>
 <td><b>Портов</b></td>
 <td><b>Nagios</b></td>
 <td><b>Nagios</b></td>
@@ -89,7 +89,7 @@ foreach ($switches as $row) {
         } else {
         } else {
         print "<td class=\"$cl\">".$row['ip']."</td>\n";
         print "<td class=\"$cl\">".$row['ip']."</td>\n";
         }
         }
-    print "<td class=\"$cl\">" . get_vendor_name($db_link, $row['vendor_id']) . " " . $row['device_model'] . "</td>\n";
+    print "<td class=\"$cl\">" . get_vendor_name($db_link, $row['vendor_id']) . " " . get_device_model($db_link,$row['device_model_id']) . "</td>\n";
     print "<td class=\"$cl\">" . get_building($db_link, $row['building_id']) . "(" . $row['comment'] . ")</td>\n";
     print "<td class=\"$cl\">" . get_building($db_link, $row['building_id']) . "(" . $row['comment'] . ")</td>\n";
     print "<td class=\"$cl\">".$row['port_count']."</td>\n";
     print "<td class=\"$cl\">".$row['port_count']."</td>\n";
     print "<td class=\"$cl\">" . get_qa($row['nagios']) . "</td>\n";
     print "<td class=\"$cl\">" . get_qa($row['nagios']) . "</td>\n";

+ 28 - 3
html/admin/groups/index.php

@@ -15,17 +15,36 @@ if (isset($_POST["remove"])) {
     }
     }
 
 
 if (isset($_POST['save'])) {
 if (isset($_POST['save'])) {
-    $len = is_array($_POST['id']) ? count($_POST['id']) : 0;
+    $saved = array();
+    //button save
+    $len = is_array($_POST['save']) ? count($_POST['save']) : 0;
     for ($i = 0; $i < $len; $i ++) {
     for ($i = 0; $i < $len; $i ++) {
         $save_id = intval($_POST['save'][$i]);
         $save_id = intval($_POST['save'][$i]);
-        if ($save_id == 0) {
-            continue;
+        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>1) {
+        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['id']) ? count($_POST['id']) : 0;
         $len_all = is_array($_POST['id']) ? count($_POST['id']) : 0;
         for ($j = 0; $j < $len_all; $j ++) {
         for ($j = 0; $j < $len_all; $j ++) {
             if (intval($_POST['id'][$j]) != $save_id) { continue; }
             if (intval($_POST['id'][$j]) != $save_id) { continue; }
             $new['ou_name'] = $_POST['f_group_name'][$j];
             $new['ou_name'] = $_POST['f_group_name'][$j];
             $new['nagios_dir'] = $_POST['f_nagios'][$j];
             $new['nagios_dir'] = $_POST['f_nagios'][$j];
+            $new['nagios_host_use'] = $_POST['f_nagios_host'][$j];
+            $new['nagios_ping'] = $_POST['f_nagios_ping'][$j];
+            $new['nagios_default_service'] = $_POST['f_nagios_service'][$j];
             update_record($db_link, "OU", "id='{$save_id}'", $new);
             update_record($db_link, "OU", "id='{$save_id}'", $new);
             }
             }
         }
         }
@@ -55,6 +74,9 @@ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
 <td><b>Id</b></td>
 <td><b>Id</b></td>
 <td><b>Название</b></td>
 <td><b>Название</b></td>
 <td><b>Nagios directory</b></td>
 <td><b>Nagios directory</b></td>
+<td><b>Host template</b></td>
+<td><b>Ping</b></td>
+<td><b>Host service</b></td>
 <td><input type="submit" name="remove" value="Удалить"></td>
 <td><input type="submit" name="remove" value="Удалить"></td>
 </tr>
 </tr>
 <?
 <?
@@ -65,6 +87,9 @@ foreach ($t_ou as $row) {
     print "<td class=\"data\"><input type=\"hidden\" name='id[]' value='{$row['id']}'>{$row['id']}</td>\n";
     print "<td class=\"data\"><input type=\"hidden\" name='id[]' value='{$row['id']}'>{$row['id']}</td>\n";
     print "<td class=\"data\"><input type=\"text\" name='f_group_name[]' value='{$row['ou_name']}'></td>\n";
     print "<td class=\"data\"><input type=\"text\" name='f_group_name[]' value='{$row['ou_name']}'></td>\n";
     print "<td class=\"data\"><input type=\"text\" name='f_nagios[]' value='{$row['nagios_dir']}'></td>\n";
     print "<td class=\"data\"><input type=\"text\" name='f_nagios[]' value='{$row['nagios_dir']}'></td>\n";
+    print "<td class=\"data\"><input type=\"text\" name='f_nagios_host[]' value='{$row['nagios_host_use']}'></td>\n";
+    print "<td class=\"data\">"; print_qa_select("f_nagios_ping[]",$row['nagios_ping']); print "</td>\n";
+    print "<td class=\"data\"><input type=\"text\" name='f_nagios_service[]' value='{$row['nagios_default_service']}'></td>\n";
     print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>Сохранить</button></td>\n";
     print "<td class=\"data\"><button name='save[]' value='{$row['id']}'>Сохранить</button></td>\n";
     print "</tr>\n";
     print "</tr>\n";
 }
 }

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

@@ -53,7 +53,7 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
             $f_dnsname=trim($_POST["f_dns_name"]);
             $f_dnsname=trim($_POST["f_dns_name"]);
             if (!empty($f_dnsname) and checkValidHostname($f_dnsname) and checkUniqHostname($db_link,$id,$f_dnsname)) { $new['dns_name'] = $f_dnsname; }
             if (!empty($f_dnsname) and checkValidHostname($f_dnsname) and checkUniqHostname($db_link,$id,$f_dnsname)) { $new['dns_name'] = $f_dnsname; }
             if (empty($f_dnsname)) { $new['dns_name'] = ''; }
             if (empty($f_dnsname)) { $new['dns_name'] = ''; }
-            $new['host_model'] = $_POST["f_host_model"];
+            $new['device_model_id'] = $_POST["f_device_model_id"]*1;
             $new['save_traf'] = $_POST["f_save_traf"] * 1;
             $new['save_traf'] = $_POST["f_save_traf"] * 1;
             $new['dhcp_acl'] = trim($_POST["f_acl"]);
             $new['dhcp_acl'] = trim($_POST["f_acl"]);
             if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
             if ($default_user_id == $parent_id or $hotspot_user_id == $parent_id) {
@@ -214,7 +214,7 @@ print "<b> Адрес доступа пользователя <a href=/admin/use
 <td><?php print $cell_traf; ?></td>
 <td><?php print $cell_traf; ?></td>
 <td></td>
 <td></td>
 <tr>
 <tr>
-<td><input type="text" name="f_host_model" value="<? echo $auth_info['host_model']; ?>"></td>
+<td><?php print_device_model_select($db_link,'f_device_model_id',$auth_info['device_model_id']); ?></td>
 <td><input type="text" name="f_handler"	value="<? echo $auth_info['nagios_handler']; ?>"></td>
 <td><input type="text" name="f_handler"	value="<? echo $auth_info['nagios_handler']; ?>"></td>
 <td><input type="text" name="f_acl" value="<? echo $auth_info['dhcp_acl']; ?>"></td>
 <td><input type="text" name="f_acl" value="<? echo $auth_info['dhcp_acl']; ?>"></td>
 <td><?php print_qa_select('f_nagios', $auth_info['nagios']); ?></td>
 <td><?php print_qa_select('f_nagios', $auth_info['nagios']); ?></td>

+ 26 - 0
html/inc/common.php

@@ -567,6 +567,22 @@ function get_ou($db, $ou_value)
     return $ou_name['ou_name'];
     return $ou_name['ou_name'];
 }
 }
 
 
+function get_device_model($db, $model_value)
+{
+    if (!isset($model_value)) { return; }
+    $model_name = get_record_sql($db, "SELECT model_name FROM device_models WHERE id=$model_value");
+    if (empty($model_name)) { return; }
+    return $model_name['model_name'];
+}
+
+function get_device_model_vendor($db, $model_value)
+{
+    if (!isset($model_value)) { return; }
+    $model_name = get_record_sql($db, "SELECT vendor_id FROM device_models WHERE id=$model_value");
+    if (empty($model_name)) { return; }
+    return $model_name['vendor_id'];
+}
+
 function get_building($db, $building_value)
 function get_building($db, $building_value)
 {
 {
     if (!isset($building_value)) { return; }
     if (!isset($building_value)) { return; }
@@ -575,6 +591,16 @@ function get_building($db, $building_value)
     return $building_name['name'];
     return $building_name['name'];
 }
 }
 
 
+function print_device_model_select($db, $device_model_name, $device_model_value)
+{
+    print "<select name=\"$device_model_name\" class=\"js-select-single\" style=\"width: 100%\">\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);
+    }
+    print "</select>\n";
+}
+
 function print_group_select($db, $group_name, $group_value)
 function print_group_select($db, $group_name, $group_value)
 {
 {
     print "<select name=\"$group_name\">\n";
     print "<select name=\"$group_name\">\n";

+ 5 - 2
updates/20210330/db-patch-mysql-ou.sql

@@ -1,7 +1,8 @@
 ALTER TABLE `devices` ADD `device_model_id` INT NULL DEFAULT NULL AFTER `device_type`;
 ALTER TABLE `devices` ADD `device_model_id` INT NULL DEFAULT NULL AFTER `device_type`;
 ALTER TABLE `User_auth` ADD `device_model_id` INT NULL DEFAULT NULL AFTER `month_quota`;
 ALTER TABLE `User_auth` ADD `device_model_id` INT NULL DEFAULT NULL AFTER `month_quota`;
-ALTER TABLE `OU` ADD `nagios_template` VARCHAR(50) NULL DEFAULT NULL AFTER `nagios_dir`, ADD `nagios_ping` BOOLEAN NOT NULL DEFAULT TRUE AFTER `nagios_template`;
-ALTER TABLE `OU` ADD `nagios_default_service` VARCHAR(100) NOT NULL DEFAULT 'local-service' AFTER `nagios_ping`;
+ALTER TABLE `OU` ADD `nagios_host_use` VARCHAR(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;
+ALTER TABLE `OU` ADD `nagios_ping` BOOLEAN NOT NULL DEFAULT TRUE AFTER `nagios_host_use`;
+ALTER TABLE `OU` ADD `nagios_default_service` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL AFTER `nagios_ping`;
 UPDATE `OU` SET `ou_name` = '!Всё' WHERE `OU`.`id` = 0;
 UPDATE `OU` SET `ou_name` = '!Всё' WHERE `OU`.`id` = 0;
 UPDATE `OU` SET `nagios_template` = 'voip' WHERE `OU`.`id` = 4;
 UPDATE `OU` SET `nagios_template` = 'voip' WHERE `OU`.`id` = 4;
 UPDATE `OU` SET `nagios_template` = 'generic-host' WHERE `OU`.`id` = 0;
 UPDATE `OU` SET `nagios_template` = 'generic-host' WHERE `OU`.`id` = 0;
@@ -17,3 +18,5 @@ UPDATE `OU` SET `nagios_template` = 'ap' WHERE `OU`.`id` = 12;
 INSERT INTO `vendors` (`id`, `name`) VALUES (33, 'QSC');
 INSERT INTO `vendors` (`id`, `name`) VALUES (33, 'QSC');
 ALTER TABLE `devices` CHANGE `device_model_id` `device_model_id` INT NULL DEFAULT '89';
 ALTER TABLE `devices` CHANGE `device_model_id` `device_model_id` INT NULL DEFAULT '89';
 ALTER TABLE `User_auth` CHANGE `device_model_id` `device_model_id` INT(11) NULL DEFAULT '87';
 ALTER TABLE `User_auth` CHANGE `device_model_id` `device_model_id` INT(11) NULL DEFAULT '87';
+INSERT INTO `vendors` (`id`, `name`) VALUES ('34', 'Projectiondesign');
+INSERT INTO `vendors` (`id`, `name`) VALUES ('35', 'Lenovo');

+ 2 - 1
updates/20210330/stat_table_device_models.sql

@@ -103,7 +103,8 @@ INSERT INTO `device_models` (`id`, `model_name`, `vendor_id`, `nagios_template`)
 (86, 'HWg-STE', 30, NULL),
 (86, 'HWg-STE', 30, NULL),
 (87, 'Computer', 1, NULL),
 (87, 'Computer', 1, NULL),
 (88, 'Mobile Phone', 1, NULL),
 (88, 'Mobile Phone', 1, NULL),
-(89, 'Switch', 1, NULL);
+(89, 'Switch', 1, NULL),
+(90, 'Projectiondesign F22',34,NULL);
 
 
 --
 --
 -- Индексы сохранённых таблиц
 -- Индексы сохранённых таблиц