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

+ 33 - 11
docs/mysql/stat_table_User_auth.sql

@@ -1,6 +1,4 @@
 
--- --------------------------------------------------------
-
 --
 -- Структура таблицы `User_auth`
 --
@@ -13,28 +11,52 @@ CREATE TABLE `User_auth` (
   `save_traf` tinyint(1) NOT NULL DEFAULT 0,
   `enabled` tinyint(1) NOT NULL DEFAULT 0,
   `dhcp` tinyint(1) NOT NULL DEFAULT 1,
+  `timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
+  `clientid` varchar(50) NOT NULL DEFAULT '',
+  `nagios` tinyint(1) NOT NULL DEFAULT 0,
+  `nagios_status` varchar(10) NOT NULL DEFAULT 'UP',
   `filter_group_id` tinyint(1) NOT NULL DEFAULT 0,
   `deleted` tinyint(4) NOT NULL DEFAULT 0,
   `comments` text DEFAULT NULL,
   `dns_name` varchar(60) NOT NULL DEFAULT '',
-  `WikiName` VARCHAR(250) DEFAULT NULL;
+  `WikiName` varchar(250) DEFAULT NULL,
   `dhcp_acl` text DEFAULT NULL,
   `queue_id` int(11) NOT NULL DEFAULT 0,
   `mac` varchar(20) NOT NULL DEFAULT '',
-  `dhcp_action` varchar(10) NOT NULL DEFAULT '',
+  `dhcp_action` varchar(10) DEFAULT '',
   `dhcp_time` datetime NOT NULL DEFAULT current_timestamp(),
   `dhcp_hostname` varchar(60) DEFAULT NULL,
-  `last_found` datetime NOT NULL DEFAULT current_timestamp(),
+  `last_found` datetime DEFAULT current_timestamp(),
   `blocked` tinyint(1) NOT NULL DEFAULT 0,
   `day_quota` int(11) NOT NULL DEFAULT 0,
   `month_quota` int(11) NOT NULL DEFAULT 0,
-  `timestamp` timestamp NOT NULL DEFAULT current_timestamp(),
-  `clientid` varchar(50) NOT NULL DEFAULT '',
-  `nagios` tinyint(1) NOT NULL DEFAULT 0,
-  `nagios_status` varchar(10) NOT NULL DEFAULT '',
-  `host_model` varchar(50) NOT NULL DEFAULT '',
-  `nagios_handler` varchar(50) NOT NULL DEFAULT '',
+  `device_model_id` int(11) DEFAULT 87,
+  `host_model` varchar(50) DEFAULT '',
+  `nagios_handler` varchar(50) DEFAULT '',
   `link_check` tinyint(1) NOT NULL DEFAULT 0,
   `changed` tinyint(1) NOT NULL DEFAULT 0,
   `changed_time` datetime NOT NULL DEFAULT current_timestamp()
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+--
+-- Индексы сохранённых таблиц
+--
+
+--
+-- Индексы таблицы `User_auth`
+--
+ALTER TABLE `User_auth`
+  ADD PRIMARY KEY (`id`),
+  ADD KEY `auth_index` (`id`,`user_id`,`ip_int`,`mac`,`ip`,`deleted`) USING BTREE,
+  ADD KEY `deleted` (`deleted`);
+
+--
+-- AUTO_INCREMENT для сохранённых таблиц
+--
+
+--
+-- AUTO_INCREMENT для таблицы `User_auth`
+--
+ALTER TABLE `User_auth`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;

+ 96 - 1
docs/mysql/stat_table_device_models.sql

@@ -10,6 +10,101 @@ CREATE TABLE `device_models` (
   `nagios_template` varchar(200) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+--
+-- Дамп данных таблицы `device_models`
+--
+
+INSERT INTO `device_models` (`id`, `model_name`, `vendor_id`, `nagios_template`) VALUES
+(1, '2011LS', 9, NULL),
+(2, '2011UAS-2HnD', 9, NULL),
+(3, 'AT-8000S', 8, NULL),
+(4, 'AT-8100S/48POE', 8, NULL),
+(5, 'AT-9000/28', 8, NULL),
+(6, 'AT-GS950/24', 8, NULL),
+(7, 'CCR1009-7G-1C-1S+', 9, NULL),
+(8, 'CCR1036-8G-2S+', 9, NULL),
+(9, 'CCR1036-8G-2S+', 9, NULL),
+(10, 'CRS317-1G-16S+', 9, NULL),
+(11, 'CRS326-24S+2Q+', 9, NULL),
+(12, 'CRS328-24P-4S+', 9, NULL),
+(13, 'CRS328-24P-4S+', 9, NULL),
+(14, 'CRS328-4C-20S-4S+', 9, NULL),
+(15, 'DGS-3120-48TC', 7, NULL),
+(16, 'ES-2024', 4, NULL),
+(17, 'ES-2024A', 4, NULL),
+(18, 'ES-2108', 4, NULL),
+(19, 'ES-2108-G', 4, NULL),
+(20, 'ES-3124-4F', 4, NULL),
+(21, 'GS110TP', 10, NULL),
+(22, 'GS-4024', 4, NULL),
+(23, 'HP 1910', 15, NULL),
+(24, 'ISCOM2110A-MA', 5, NULL),
+(25, 'ISCOM2110EA-MA', 5, NULL),
+(26, 'ISCOM2126EA-MA', 5, NULL),
+(27, 'ISCOM2128EA-MA', 5, NULL),
+(28, 'Linux server', 1, NULL),
+(29, 'MES2124F', 2, NULL),
+(30, 'MES2124MB', 2, NULL),
+(31, 'MES5248', 2, NULL),
+(32, 'RB2011UAS', 9, NULL),
+(33, 'RB3011UiAS', 9, NULL),
+(34, 'RB960PGS', 9, NULL),
+(35, 'RBD52G-5HacD2HnD', 9, NULL),
+(36, 'S2940-8G-v2', 6, NULL),
+(37, 'S2980G-24T', 6, NULL),
+(38, 'S3750G-24S-E', 6, NULL),
+(39, 'S5300-52P-LI-AC', 3, NULL),
+(40, 'S5320-52X-PWR-SI-AC', 3, NULL),
+(41, 'S5321-28X-SI-AC', 3, NULL),
+(42, 'S5321-52X-SI-AC', 3, NULL),
+(43, 'S6320-54C-EI-48S-AC', 3, NULL),
+(44, 'SNR-S2980G-24T', 6, NULL),
+(45, 'V1910-16G', 15, NULL),
+(46, 'V1910-24G-PoE', 15, NULL),
+(47, 'Windows server', 1, NULL),
+(48, 'WS-C2960G-24TC-L', 16, NULL),
+(49, 'WS-C3560G-24TS-S', 16, NULL),
+(50, 'x210-16GT', 8, NULL),
+(51, 'x210-24GT', 8, NULL),
+(52, 'x610-24Ts/X', 8, NULL),
+(53, 'x610-48Ts', 8, NULL),
+(54, 'XGS-4728', 4, NULL),
+(55, 'ZyWall 310', 4, NULL),
+(56, 'APC Smart-UPS_3000', 20, 'ups.cfg'),
+(57, 'APC Smart-UPS_5000', 20, 'ups.cfg'),
+(58, 'Schneider Smart-UPS_3000', 27, 'ups.cfg'),
+(59, 'SMG-1016M', 2, NULL),
+(60, 'EATON 9PX 1500i RT 2U', 24, 'ups.cfg'),
+(61, 'EATON 9PX3000i_RT_2U', 24, 'ups.cfg'),
+(62, 'EATON 9PX_6000i', 24, 'ups.cfg'),
+(63, 'EATON PW9130_3000', 24, 'ups.cfg'),
+(64, 'EATON PW9130_3000VA-R', 24, 'ups.cfg'),
+(65, 'Epson WF-5620 Series', 26, 'epson.cfg'),
+(66, 'Epson WF-8590 Series', 26, 'epson.cfg'),
+(67, 'HP Officejet-7000', 15, 'hp.cfg'),
+(68, 'OKI C610', 22, 'oki.cfg'),
+(69, 'OKI MB472', 22, 'oki.cfg'),
+(70, 'OKI MB491', 22, 'oki.cfg'),
+(71, 'OKI MC562', 22, 'oki.cfg'),
+(72, 'OKI MC573', 22, 'oki.cfg'),
+(73, 'OKI MC861', 22, 'oki.cfg'),
+(74, 'Panasonic KX-MB2000RU', 21, 'panasonic.cfg'),
+(75, 'PT-MZ10KE', 21, NULL),
+(76, 'PT-VX41', 21, NULL),
+(77, 'Rave 522AA', 33, NULL),
+(78, 'DZ570E', 21, NULL),
+(79, 'DZ6700', 21, NULL),
+(80, 'Rcq80', 21, NULL),
+(81, 'RZ12K', 21, NULL),
+(82, 'RZ660', 21, NULL),
+(83, 'RZ770', 21, NULL),
+(84, 'RZ970', 21, NULL),
+(85, 'XVR-5216', 32, NULL),
+(86, 'HWg-STE', 30, NULL),
+(87, 'Computer', 1, NULL),
+(88, 'Mobile Phone', 1, NULL),
+(89, 'Switch', 1, NULL);
+
 --
 -- Индексы сохранённых таблиц
 --
@@ -28,4 +123,4 @@ ALTER TABLE `device_models`
 -- AUTO_INCREMENT для таблицы `device_models`
 --
 ALTER TABLE `device_models`
-  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=89;

+ 32 - 10
docs/mysql/stat_table_devices.sql

@@ -1,20 +1,19 @@
-
--- --------------------------------------------------------
-
 --
 -- Структура таблицы `devices`
 --
 
 CREATE TABLE `devices` (
   `id` int(11) NOT NULL,
-  `device_model` varchar(50) DEFAULT NULL,
+  `device_model` varchar(50) DEFAULT '',
   `device_type` int(11) NOT NULL DEFAULT 1,
+  `device_model_id` int(11) DEFAULT 89,
   `vendor_id` int(11) NOT NULL DEFAULT 1,
-  `device_name` varchar(50) DEFAULT NULL,
+  `device_name` varchar(50) DEFAULT '',
   `building_id` int(11) NOT NULL DEFAULT 1,
-  `ip` varchar(15) DEFAULT NULL,
+  `ip` varchar(15) DEFAULT '',
   `port_count` int(11) NOT NULL DEFAULT 0,
   `SN` varchar(80) DEFAULT NULL,
+  `dhcp` tinyint(1) NOT NULL DEFAULT 0,
   `comment` text DEFAULT NULL,
   `snmp_version` tinyint(4) NOT NULL DEFAULT 0,
   `snmp3_user_rw` varchar(20) DEFAULT NULL,
@@ -26,12 +25,35 @@ CREATE TABLE `devices` (
   `fdb_snmp_index` tinyint(1) NOT NULL DEFAULT 0,
   `discovery` tinyint(1) NOT NULL DEFAULT 1,
   `user_acl` tinyint(1) NOT NULL DEFAULT 0,
-  `dhcp` tinyint(1) NOT NULL DEFAULT 0,
   `nagios` tinyint(1) NOT NULL DEFAULT 0,
+  `deleted` tinyint(1) NOT NULL DEFAULT 0,
   `active` tinyint(1) NOT NULL DEFAULT 1,
   `nagios_status` varchar(10) NOT NULL DEFAULT 'UP',
   `queue_enabled` tinyint(1) NOT NULL DEFAULT 0,
-  `connected_user_only` tinyint(1) NOT NULL DEFAULT 1,
-  `user_id` int(11) DEFAULT NULL,
-  `deleted` tinyint(1) NOT NULL DEFAULT 0
+  `connected_user_only` tinyint(1) NOT NULL DEFAULT 0,
+  `user_id` int(11) DEFAULT 0
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+--
+-- Индексы сохранённых таблиц
+--
+
+--
+-- Индексы таблицы `devices`
+--
+ALTER TABLE `devices`
+  ADD PRIMARY KEY (`id`),
+  ADD UNIQUE KEY `id` (`id`),
+  ADD KEY `device_model_id` (`device_model`),
+  ADD KEY `ip` (`ip`),
+  ADD KEY `device_type` (`device_type`);
+
+--
+-- AUTO_INCREMENT для сохранённых таблиц
+--
+
+--
+-- AUTO_INCREMENT для таблицы `devices`
+--
+ALTER TABLE `devices`
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;

+ 2 - 1
docs/mysql/stat_table_vendors.sql

@@ -45,7 +45,8 @@ INSERT INTO `vendors` (`id`, `name`) VALUES
 (29, 'Hikvision'),
 (30, 'HW-group'),
 (31, 'Netping'),
-(32, 'Trassir');
+(32, 'Trassir'),
+(33, 'QSC');
 
 --
 ALTER TABLE `vendors`

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

@@ -60,7 +60,8 @@ if (isset($_POST["editdevice"]) and isset($id)) {
     if (isset($_POST["f_wan"])) { $new['wan_int'] = $_POST["f_wan"]; }
     if (isset($_POST["f_lan"])) { $new['lan_int'] = $_POST["f_lan"]; }
     if (isset($_POST["f_building_id"])) { $new['building_id'] = $_POST["f_building_id"] * 1; }
-    if (isset($_POST["f_user_id"])) { $new['user_id'] = $_POST["f_user_id"] * 1; }
+    $new['user_id'] = get_user_by_ip($db_link,$new['ip']);
+    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 (empty($new['nagios'])) { $new['nagios_status'] = 'UP'; }
     if (isset($_POST["f_vendor_id"])) { $new['vendor_id'] = $_POST["f_vendor_id"] * 1; }
@@ -115,11 +116,11 @@ print "<td class=\"data\" colspan=2><input type=\"text\" size=50 name='f_SN' val
 print "</tr>\n";
 
 print "<tr><td>Расположен</td><td colspan=2>Комментарий</td>";
-if (isset($device['user_id']) and $device['user_id']>0) { print "<td align=right><a href=/admin/users/edituser.php?id=".$device['user_id'].">Auth user</a><td>\n"; } else { print "<td>Auth user<td>"; }
+print "<td align=right>Auth user<td>";
 print "</tr><tr>";
 print "<td class=\"data\">"; print_building_select($db_link, 'f_building_id', $device['building_id']); print "</td>\n";
 print "<td class=\"data\" colspan=2><input type=\"text\" size=50 name='f_comment' value='".$device['comment']."'></td>\n";
-print "<td class=\"data\">"; print_login_select($db_link,'f_user_id', $device['user_id']); print "</td>\n";
+if (isset($device['user_id']) and $device['user_id']>0) { print "<td align=right><a href=/admin/users/edituser.php?id=".$device['user_id'].">".get_login($db_link,$device['user_id'])."</a><td>\n"; } else { print "<td>Unknown<td>"; }
 print "</tr>";
 
 if ($device['device_type']==2) {

+ 8 - 0
html/inc/common.php

@@ -989,6 +989,14 @@ function get_auth_by_ip($db, $ip)
     return $f_auth_id;
 }
 
+function get_user_by_ip($db, $ip)
+{
+    $d_sql = "SELECT user_id FROM User_auth WHERE ip='$ip' and deleted=0";
+    $auth_q = mysqli_query($db, $d_sql);
+    list ($f_auth_id) = mysqli_fetch_array($auth_q);
+    return $f_auth_id;
+}
+
 function print_auth_port($db, $port_id)
 {
     $d_sql = "SELECT A.ip,A.ip_int,A.mac,A.id,A.dns_name FROM User_auth as A, connections as C WHERE C.port_id=$port_id and A.id=C.auth_id and A.deleted=0 order by A.ip_int";

+ 3 - 0
updates/20210330/db-patch-mysql-ou.sql

@@ -14,3 +14,6 @@ UPDATE `OU` SET `nagios_template` = 'ups' WHERE `OU`.`id` = 8;
 UPDATE `OU` SET `nagios_template` = 'security' WHERE `OU`.`id` = 9;
 UPDATE `OU` SET `nagios_template` = 'routers' WHERE `OU`.`id` = 10;
 UPDATE `OU` SET `nagios_template` = 'ap' WHERE `OU`.`id` = 12;
+INSERT INTO `vendors` (`id`, `name`) VALUES (33, 'QSC');
+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';

+ 97 - 2
updates/20210330/stat_table_device_models.sql

@@ -6,10 +6,105 @@
 CREATE TABLE `device_models` (
   `id` int(11) NOT NULL,
   `model_name` varchar(200) DEFAULT NULL,
-  `vendor_id` int(11) DEFAULT NULL,
+  `vendor_id` int(11) DEFAULT 1,
   `nagios_template` varchar(200) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
+--
+-- Дамп данных таблицы `device_models`
+--
+
+INSERT INTO `device_models` (`id`, `model_name`, `vendor_id`, `nagios_template`) VALUES
+(1, '2011LS', 9, NULL),
+(2, '2011UAS-2HnD', 9, NULL),
+(3, 'AT-8000S', 8, NULL),
+(4, 'AT-8100S/48POE', 8, NULL),
+(5, 'AT-9000/28', 8, NULL),
+(6, 'AT-GS950/24', 8, NULL),
+(7, 'CCR1009-7G-1C-1S+', 9, NULL),
+(8, 'CCR1036-8G-2S+', 9, NULL),
+(9, 'CCR1036-8G-2S+', 9, NULL),
+(10, 'CRS317-1G-16S+', 9, NULL),
+(11, 'CRS326-24S+2Q+', 9, NULL),
+(12, 'CRS328-24P-4S+', 9, NULL),
+(13, 'CRS328-24P-4S+', 9, NULL),
+(14, 'CRS328-4C-20S-4S+', 9, NULL),
+(15, 'DGS-3120-48TC', 7, NULL),
+(16, 'ES-2024', 4, NULL),
+(17, 'ES-2024A', 4, NULL),
+(18, 'ES-2108', 4, NULL),
+(19, 'ES-2108-G', 4, NULL),
+(20, 'ES-3124-4F', 4, NULL),
+(21, 'GS110TP', 10, NULL),
+(22, 'GS-4024', 4, NULL),
+(23, 'HP 1910', 15, NULL),
+(24, 'ISCOM2110A-MA', 5, NULL),
+(25, 'ISCOM2110EA-MA', 5, NULL),
+(26, 'ISCOM2126EA-MA', 5, NULL),
+(27, 'ISCOM2128EA-MA', 5, NULL),
+(28, 'Linux server', 1, NULL),
+(29, 'MES2124F', 2, NULL),
+(30, 'MES2124MB', 2, NULL),
+(31, 'MES5248', 2, NULL),
+(32, 'RB2011UAS', 9, NULL),
+(33, 'RB3011UiAS', 9, NULL),
+(34, 'RB960PGS', 9, NULL),
+(35, 'RBD52G-5HacD2HnD', 9, NULL),
+(36, 'S2940-8G-v2', 6, NULL),
+(37, 'S2980G-24T', 6, NULL),
+(38, 'S3750G-24S-E', 6, NULL),
+(39, 'S5300-52P-LI-AC', 3, NULL),
+(40, 'S5320-52X-PWR-SI-AC', 3, NULL),
+(41, 'S5321-28X-SI-AC', 3, NULL),
+(42, 'S5321-52X-SI-AC', 3, NULL),
+(43, 'S6320-54C-EI-48S-AC', 3, NULL),
+(44, 'SNR-S2980G-24T', 6, NULL),
+(45, 'V1910-16G', 15, NULL),
+(46, 'V1910-24G-PoE', 15, NULL),
+(47, 'Windows server', 1, NULL),
+(48, 'WS-C2960G-24TC-L', 16, NULL),
+(49, 'WS-C3560G-24TS-S', 16, NULL),
+(50, 'x210-16GT', 8, NULL),
+(51, 'x210-24GT', 8, NULL),
+(52, 'x610-24Ts/X', 8, NULL),
+(53, 'x610-48Ts', 8, NULL),
+(54, 'XGS-4728', 4, NULL),
+(55, 'ZyWall 310', 4, NULL),
+(56, 'APC Smart-UPS_3000', 20, 'ups.cfg'),
+(57, 'APC Smart-UPS_5000', 20, 'ups.cfg'),
+(58, 'Schneider Smart-UPS_3000', 27, 'ups.cfg'),
+(59, 'SMG-1016M', 2, NULL),
+(60, 'EATON 9PX 1500i RT 2U', 24, 'ups.cfg'),
+(61, 'EATON 9PX3000i_RT_2U', 24, 'ups.cfg'),
+(62, 'EATON 9PX_6000i', 24, 'ups.cfg'),
+(63, 'EATON PW9130_3000', 24, 'ups.cfg'),
+(64, 'EATON PW9130_3000VA-R', 24, 'ups.cfg'),
+(65, 'Epson WF-5620 Series', 26, 'epson.cfg'),
+(66, 'Epson WF-8590 Series', 26, 'epson.cfg'),
+(67, 'HP Officejet-7000', 15, 'hp.cfg'),
+(68, 'OKI C610', 22, 'oki.cfg'),
+(69, 'OKI MB472', 22, 'oki.cfg'),
+(70, 'OKI MB491', 22, 'oki.cfg'),
+(71, 'OKI MC562', 22, 'oki.cfg'),
+(72, 'OKI MC573', 22, 'oki.cfg'),
+(73, 'OKI MC861', 22, 'oki.cfg'),
+(74, 'Panasonic KX-MB2000RU', 21, 'panasonic.cfg'),
+(75, 'PT-MZ10KE', 21, NULL),
+(76, 'PT-VX41', 21, NULL),
+(77, 'Rave 522AA', 33, NULL),
+(78, 'DZ570E', 21, NULL),
+(79, 'DZ6700', 21, NULL),
+(80, 'Rcq80', 21, NULL),
+(81, 'RZ12K', 21, NULL),
+(82, 'RZ660', 21, NULL),
+(83, 'RZ770', 21, NULL),
+(84, 'RZ970', 21, NULL),
+(85, 'XVR-5216', 32, NULL),
+(86, 'HWg-STE', 30, NULL),
+(87, 'Computer', 1, NULL),
+(88, 'Mobile Phone', 1, NULL),
+(89, 'Switch', 1, NULL);
+
 --
 -- Индексы сохранённых таблиц
 --
@@ -28,4 +123,4 @@ ALTER TABLE `device_models`
 -- AUTO_INCREMENT для таблицы `device_models`
 --
 ALTER TABLE `device_models`
-  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
+  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=89;