Procházet zdrojové kódy

- html: add btn ip rule for user

root před 4 roky
rodič
revize
0d1de0e3aa

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

@@ -98,7 +98,7 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
     exit;
     }
 
-if (isset($_POST["moveauth"])) {
+if (isset($_POST["moveauth"]) and !$old_auth_info['deleted']) {
     $new_parent_id = $_POST["f_new_parent"]*1;
     apply_auth_rule($db_link,$id,$new_parent_id);
     LOG_WARNING($db_link,"Адрес доступа перемещён к другому пользователю! Применено: $changes",$id);
@@ -106,7 +106,7 @@ if (isset($_POST["moveauth"])) {
     exit;
     }
 
-if (isset($_POST["recovery"])) {
+if (isset($_POST["recovery"]) and $old_auth_info['deleted']) {
     $ip = trim($_POST["f_ip"]);
     if (checkValidIp($ip)) {
         $ip_aton = ip2long($ip);

+ 32 - 3
html/admin/users/edituser.php

@@ -61,6 +61,27 @@ if (isset($_POST["delMacRule"])) {
     exit;
 }
 
+if (isset($_POST["addIPRule"])) {
+    unset($new);
+    $first_auth = get_record_sql($db_link,"SELECT ip FROM User_auth WHERE user_id=".$id." AND deleted=0 AND LENGTH(ip)>0 ORDER BY id");
+    if (!empty($first_auth) and !empty($first_auth['ip'])) {
+        $new['user_id']=$id;
+        $new['type']=1;
+        $new['rule']=$first_auth['ip'];
+	insert_record($db_link,"auth_rules",$new);
+	LOG_INFO($db_link,"Создано правило атоназначения юзеру id: ".$id." для IP ".$first_auth['IP']);
+	}
+    header("Location: " . $_SERVER["REQUEST_URI"]);
+    exit;
+}
+
+if (isset($_POST["delIPRule"])) {
+    run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$id." AND type=1");
+    LOG_INFO($db_link,"Удалены все правила атоназначения юзеру id: $id по ip");
+    header("Location: " . $_SERVER["REQUEST_URI"]);
+    exit;
+}
+
 if (isset($_POST["showDevice"])) {
     $device = get_record_sql($db_link,"SELECT * FROM devices WHERE user_id=".$id);
     $auth = get_record_sql($db_link,"SELECT * FROM User_auth WHERE user_id=".$id);
@@ -210,18 +231,26 @@ if (!empty($_SESSION[$page_url]['msg'])) {
 <?php
 print "<td>"; print_url("Список правил","/admin/users/edit_rules.php?id=$id"); print "</td>";
 $rule_count = get_count_records($db_link,"auth_rules","user_id=".$id);
-if ($rule_count>0) { print "<td > Count: ".$rule_count."</td>"; } else { print "<td></td>"; }
+print "<td > Count: ".$rule_count."</td>";
 $first_auth = get_record_sql($db_link,"SELECT id FROM User_auth WHERE user_id=".$id." AND deleted=0 ORDER BY id");
 if (!empty($first_auth)) {
+    //mac
     $mac_rule_count = get_count_records($db_link,"auth_rules","user_id=".$id." AND type=2");
     if (!empty($mac_rule_count)) { 
 	print "<td><input type=\"submit\" name=\"delMacRule\" value=".$btn_mac_del." ></td>";
 	} else {
 	print "<td><input type=\"submit\" name=\"addMacRule\" value=".$btn_mac_add." ></td>";
 	}
-    } else { print "<td></td>"; }
+    //ip
+    $ip_rule_count = get_count_records($db_link,"auth_rules","user_id=".$id." AND type=1");
+    if (!empty($ip_rule_count)) { 
+	print "<td><input type=\"submit\" name=\"delIPRule\" value=".$btn_ip_del." ></td>";
+	} else {
+	print "<td><input type=\"submit\" name=\"addIPRule\" value=".$btn_ip_add." ></td>";
+	}
+    } else { print "<td colspan=2></td>"; }
 ?>
-<td colspan=3 align=right>Created: <?php print $user_info["timestamp"]; ?></td>
+<td colspan=2 align=right>Created: <?php print $user_info["timestamp"]; ?></td>
 </tr>
 <tr>
 <?php print "<td colspan=2>"; print_url("Трафик за день","/admin/reports/userday.php?id=$id"); ?></td>

+ 4 - 2
html/inc/languages/russian.php

@@ -81,8 +81,10 @@ $btn_save = "Сохранить";
 $btn_move = "Переместить";
 $btn_apply = "Применить конфигурацию";
 $btn_device = "+Устройство";
-$btn_mac_add = "Привязать";
-$btn_mac_del = "Отвязать";
+$btn_mac_add = "+MAC";
+$btn_mac_del = "-MAC";
+$btn_ip_add = "+IP";
+$btn_ip_del = "-IP";
 
 /* error messages */
 $msg_exists = "уже существует!";