瀏覽代碼

api: added the get_dhcp_all function, which returns all entries for the configuration of the dhcp server.
html: added fractional number support for the lifetime of dynamic records

root 11 月之前
父節點
當前提交
a374ed357d

+ 1 - 1
docs/mysql/2-8-0/mysql.sql

@@ -724,7 +724,7 @@ CREATE TABLE `OU` (
   `filter_group_id` int(11) NOT NULL DEFAULT 0,
   `queue_id` int(11) NOT NULL DEFAULT 0,
   `dynamic` tinyint(1) NOT NULL DEFAULT 0,
-  `life_duration` int(11) NOT NULL DEFAULT 24
+  `life_duration` DECIMAL(10,2) NOT NULL DEFAULT '24'
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 --

+ 1 - 0
html/admin/customers/index-subnets.php

@@ -10,6 +10,7 @@ if (isset($_POST["s_remove"])) {
             if (isset($net_id)) {
                 LOG_INFO($db_link, "Remove subnet id: $net_id ". dump_record($db_link,'subnets','id='.$val));
                 delete_record($db_link, "subnets", "id=" . $net_id);
+                delete_record($db_link, "gateway_subnets", "subnet_id=" . $net_id);
             }
         }
     }

+ 2 - 2
html/admin/groups/edit_group.php

@@ -82,7 +82,6 @@ fix_auth_rules($db_link);
 </tr>
 <?php
 $ou_info = get_record_sql($db_link,'SELECT * FROM OU WHERE id='.$id);
-if ($ou_info['life_duration']<1) { $ou_info['life_duration']=1; }
 print "<tr align=center>\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"; }
@@ -111,7 +110,8 @@ 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 id='f_life_duration' 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' step='0.01' min='0.01' id='f_life_duration' name='f_life_duration' value='" . htmlspecialchars($ou_info['life_duration'])."'";
 if (!$ou_info['dynamic']) { print "disabled"; }; print " style=\"width:35%;\" ></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>

+ 27 - 0
html/api.php

@@ -43,6 +43,7 @@ if (!empty($action)) {
                   LOG_VERBOSE($db_link,"API: Record found.");
                   try {
                     $json = json_encode($result, JSON_THROW_ON_ERROR);
+                    header('Content-Type: application/json');
                     echo $json;
                     }
                   catch (JsonException $exception) {
@@ -57,6 +58,32 @@ if (!empty($action)) {
              }
           }
 
+      //return user auth record
+      if ($action ==='get_dhcp_all') {
+            $result=[];
+            LOG_VERBOSE($db_link,"API: Get all dhcp records");
+            $sql = "SELECT id, ip, ip_int, mac, comments, dns_name, dhcp_option_set, dhcp_acl, ou_id 
+                    FROM User_auth 
+                    WHERE dhcp=1 AND deleted=0 
+                    ORDER BY ip_int";
+            $result = get_records_sql($db_link, $sql);
+
+            if (!empty($result)) {
+                    LOG_VERBOSE($db_link, "API: " . count($result) . " records found.");
+                    try {
+                        header('Content-Type: application/json');
+                        echo json_encode($result, JSON_THROW_ON_ERROR);
+                    } catch (JsonException $exception) {
+                        LOG_ERROR($db_link, "API: JSON encoding error: " . $exception->getMessage());
+                        exit("JSON error");
+                        }
+                    } else {
+                        LOG_VERBOSE($db_link, "API: No records found.");
+                        header('Content-Type: application/json');
+                        echo json_encode([]);
+                    }
+            }
+
       //add dhcp log record
       if ($action ==='send_dhcp') {
           if (!empty($ip) and !empty($mac)) {

+ 13 - 6
scripts/eyelib/database.pm

@@ -1746,12 +1746,19 @@ if ($cur_auth_id) {
     if ($user_record) {
 	    my $ou_info = get_record_sql($db,'SELECT * FROM OU WHERE id='.$user_record->{ou_id});
 	    if ($ou_info and $ou_info->{'dynamic'}) {
-	            if (!$ou_info->{'life_duration'}) { $ou_info->{'life_duration'} = 24; }
-	            my $now = DateTime->now(time_zone=>'local');
-	            my $hours_dur = DateTime::Duration->new( hours => $ou_info->{'life_duration'} );
-	            my $eof = $now + $hours_dur;
-		    $new_record->{'dynamic'} = 1;
-	            $new_record->{'eof'}=$eof->strftime('%Y-%m-%d %H:%M:%S');
+                    # Устанавливаем значение по умолчанию, если не задано
+                    if (!$ou_info->{'life_duration'}) { 
+                            $ou_info->{'life_duration'} = 24.0;  # Явно указываем дробное число
+                            }
+                    my $now = DateTime->now(time_zone => 'local');
+                    # Разбиваем life_duration на часы и минуты (для дробного значения)
+                    my $hours = int($ou_info->{'life_duration'});  # Целая часть (часы)
+                    my $minutes = ($ou_info->{'life_duration'} - $hours) * 60;  # Дробная часть → минуты
+                    # Создаём продолжительность с учётом дробных часов (в виде часов + минут)
+                    my $duration = DateTime::Duration->new( hours   => $hours, minutes => $minutes);
+                    my $eof = $now + $duration;
+                    $new_record->{'dynamic'} = 1;
+                    $new_record->{'eof'} = $eof->strftime('%Y-%m-%d %H:%M:%S');
 		    }
 	    $new_record->{ou_id}=$user_record->{ou_id};
 	    $new_record->{comments}=$user_record->{fio};

+ 1 - 0
scripts/updates/2-8-0/OU.sql

@@ -0,0 +1 @@
+ALTER TABLE `OU` CHANGE `life_duration` `life_duration` DECIMAL(10,2) NOT NULL DEFAULT '24';