Explorar el Código

- add default option for user to Group info

Dmitriev Roman hace 4 años
padre
commit
c56742b3ea

+ 21 - 8
html/admin/groups/edit_group.php

@@ -13,6 +13,9 @@ if (isset($_POST['save'])) {
         $new['nagios_host_use'] = $_POST['f_nagios_host'];
         $new['nagios_ping'] = $_POST['f_nagios_ping'];
         $new['nagios_default_service'] = $_POST['f_nagios_service'];
+        $new['queue_id']= $_POST['f_queue_id']*1;
+        $new['filter_group_id']= $_POST['f_filter_group_id']*1;
+        $new['enabled']= $_POST['f_enabled']*1;
         if ($new['default_users'] == TRUE) { run_sql($db_link,"UPDATE OU set default_users=0 WHERE id!='{$id}'"); }
         if ($new['default_hotspot'] == TRUE) { run_sql($db_link,"UPDATE OU set default_hotspot=0 WHERE id!='{$id}'"); }
         update_record($db_link, "OU", "id='{$id}'", $new);
@@ -71,29 +74,39 @@ fix_auth_rules($db_link);
 <form name="def" action="edit_group.php" method="post">
 <table class="data">
 <tr align="center">
-<td><b>Название</b></td>
+<td colspan=2><b>Название</b></td>
 <td><b>Default</b></td>
 <td><b>Hotspot</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>
 </tr>
 <?php
 $ou_info = get_record_sql($db_link,'SELECT * FROM OU WHERE id='.$id);
 print "<tr align=center>\n";
-print "<td class=\"data\"><input type=\"text\" name='f_group_name' value='{$ou_info['ou_name']}'></td>\n";
+print "<td colspan=2 class=\"data\"><input type=\"text\" name='f_group_name' value='{$ou_info['ou_name']}' style=\"width:95%;\"></td>\n";
 if ($ou_info['default_users']) { $cl = "up"; } else { $cl="data"; }
 print "<td class=\"$cl\">";  print_qa_select("f_default",$ou_info['default_users']); print "</td>\n";
 if ($ou_info['default_hotspot']) { $cl = "up"; } else { $cl="data"; }
 print "<td class=\"$cl\">";  print_qa_select("f_default_hotspot",$ou_info['default_hotspot']); print "</td>\n";
+?>
+<tr>
+<td><b>Nagios directory</b></td>
+<td><b>Host template</b></td>
+<td><b>Ping</b></td>
+<td><b>Host service</b></td>
+</tr>
+<?php
 print "<td class=\"data\"><input type=\"text\" name='f_nagios' value='{$ou_info['nagios_dir']}'></td>\n";
 print "<td class=\"data\"><input type=\"text\" name='f_nagios_host' value='{$ou_info['nagios_host_use']}'></td>\n";
 print "<td class=\"data\">"; print_qa_select("f_nagios_ping",$ou_info['nagios_ping']); print "</td>\n";
 print "<td class=\"data\"><input type=\"text\" name='f_nagios_service' value='{$ou_info['nagios_default_service']}'></td>\n";
-print "<td class=\"data\"><button name='save' value='{$ou_info['id']}'>Сохранить</button></td>\n";
-print "</tr>\n";
 ?>
+</tr>
+<tr><td colspan=4>Правила для автоназначенных клиентов</td></tr>
+<tr>
+<td class="data">Фильтр&nbsp<?php print_group_select($db_link, 'f_filter_group_id', $ou_info['filter_group_id']); ?></td>
+<td class="data">Шейпер&nbsp<?php print_queue_select($db_link, 'f_queue_id', $ou_info['queue_id']); ?></td>
+<td class="data">Включен&nbsp<?php print_qa_select('f_enabled', $ou_info['enabled']); ?></td>
+<?php print "<td align=right class=\"data\"><button name='save' value='{$ou_info['id']}'>Сохранить</button></td>\n"; ?>
+</tr>
 </table>
 <br>
 <b>Правила автоназначения адресов в <?php print_url($auth_info['login'],"/admin/users/edituser.php?id=$id"); ?></b>

+ 8 - 1
html/inc/common.php

@@ -1351,6 +1351,7 @@ $set_auth['filter_group_id']=$user_rec['filter_group_id'];
 $set_auth['queue_id']= $user_rec['queue_id'];
 $set_auth['enabled'] = $user_rec['enabled'];
 update_record($db, "User_auth", "id=$auth_id", $set_auth);
+return $set_auth;
 }
 
 function fix_auth_rules($db) {
@@ -1380,6 +1381,12 @@ if ($user_info['dhcp_hostname']) {
     $user['fio']=$user_info['ip'];
     }
 $user['ou_id'] = $user_info['ou_id'];
+$ou_info = get_record_sql($db,"SELECT * FROM OU WHERE id=".$user_info['ou_id']);
+if (!empty($ou_info)) {
+    $user['enabled'] = $ou_info['enabled'];
+    $user['queue_id'] = $ou_info['queue_id'];
+    $user['filter_group_id'] = $ou_info['filter_group_id'];
+    }
 $result = insert_record($db,"User_list",$user);
 if (!empty($result) and $auto_mac_rule and $user_info['mac']) {
     $auth_rule['user_id'] = $result;
@@ -1509,7 +1516,7 @@ function resurrection_auth($db, $ip, $mac, $action, $dhcp_hostname)
     }
     //check rules, update filter and state for new record
     if (!empty($resurrection_id)) {
-            apply_auth_rule($db,$resurrection_id,$new_user_id);
+            $user_rec=apply_auth_rule($db,$resurrection_id,$new_user_id);
 	    $msg.="filter: ".$user_rec['filter_group_id']."\r\n queue_id: ".$user_rec['queue_id']."\r\n enabled: ".$user_rec['enabled']."\r\nid: $resurrection_id";
 	    if (!is_hotspot($db,$ip) and !empty($msg)) { LOG_WARNING($db, $msg); }
 	    if (is_hotspot($db,$ip) and !empty($msg)) { LOG_INFO($db, $msg); }

+ 6 - 0
scripts/Rstat/mysql.pm

@@ -723,6 +723,12 @@ if ($user_info->{dhcp_hostname}) {
     $user->{fio}=$user_info->{ip};
     }
 $user->{ou_id} = $user_info->{ou_id};
+my $ou_info = get_record_sql($db,"SELECT * FROM OU WHERE id=".$user_info->{'ou_id'});
+if ($ou_info) {
+    $user->{'enabled'} = $ou_info->{'enabled'};
+    $user->{'queue_id'} = $ou_info->{'queue_id'};
+    $user->{'filter_group_id'} = $ou_info->{'filter_group_id'};
+    }
 my $result = insert_record($db,"User_list",$user);
 if ($result and $config_ref{auto_mac_rule} and $user_info->{mac}) {
     my $auth_rule;

+ 1 - 0
updates/20211129/mysql-patch-to-2.4.sql

@@ -8,3 +8,4 @@ UPDATE `config_options` SET `min_value` = '22' WHERE `config_options`.`id` = 30;
 UPDATE `config_options` SET `default_value` = '22' WHERE `config_options`.`id` = 30;
 UPDATE `config_options` SET `description` = 'Порт ssh маршрутизатора' WHERE `config_options`.`id` = 30;
 INSERT INTO `config_options` (`id`, `option_name`, `description`, `uniq`, `type`, `default_value`, `min_value`, `max_value`) VALUES ('64', 'auto_mac_rule', 'Создавать автоматическую привязку мак-адреса к юзеру. Т.е. все ip-адреса для найденного мака будут привязываться к одном и тому же юзеру.', '1', 'bool', '0', '0', '1');
+ALTER TABLE `OU` ADD `enabled` INT NOT NULL DEFAULT '0' AFTER `nagios_default_service`, ADD `filter_group_id` INT NOT NULL DEFAULT '0' AFTER `enabled`, ADD `queue_id` INT NOT NULL DEFAULT '0' AFTER `filter_group_id`;