فهرست منبع

add mass create auto rules

Roman Dmitriev 2 سال پیش
والد
کامیت
a499180d8f
4فایلهای تغییر یافته به همراه36 افزوده شده و 1 حذف شده
  1. 1 0
      html/admin/iplist/index.php
  2. 2 0
      html/inc/languages/english.php
  3. 2 1
      html/inc/languages/russian.php
  4. 31 0
      html/utils/auth_apply.php

+ 1 - 0
html/admin/iplist/index.php

@@ -77,6 +77,7 @@ print_ip_submenu($page_url);
 	<tr><td><input type=checkbox class="putField" name="e_dhcp" value='1'></td><td><?php print "Dhcp&nbsp"; print_qa_select('a_dhcp', 1);?></td></tr>
 	<tr><td><input type=checkbox class="putField" name="e_dhcp_acl" value='1'></td><td><?php print "Dhcp-acl&nbsp";print_dhcp_acl_select('a_dhcp_acl','');?></td></tr>
 	<tr><td><input type=checkbox class="putField" name="e_traf" value='1'></td><td><?php print "Save traffic&nbsp"; print_qa_select('a_traf',1);?></td></tr>
+	<tr><td><input type=checkbox class="putField" name="e_bind_mac" value='1'></td><td><?php print WEB_user_bind_mac."&nbsp";print_qa_select('a_bind_mac', 1);?></td></tr>
 	</table>
 	<input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
     </form>

+ 2 - 0
html/inc/languages/english.php

@@ -455,6 +455,8 @@ define("WEB_user_add_mac","Mac (optional)");
 define("WEB_user_list_apply","Apply to list");
 define("WEB_new_user","New user");
 define("WEB_user_deleted","belongs to a non-existent user. Probably the record has been deleted");
+define("WEB_user_bind_mac","Bind mac for login");
+define("WEB_user_unbind_mac","Unbind mac for login");
 
 /* public */
 define("WEB_msg_access_login","Internet for login");

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

@@ -435,7 +435,6 @@ define("WEB_log_dhcp_add","Аренда адреса");
 define("WEB_log_dhcp_del","Освобождение адреса");
 define("WEB_log_dhcp_old","Обновление аренды");
 
-
 /* reports */
 define("WEB_report_user_traffic","Трафик пользователя");
 define("WEB_report_traffic_for_ip","для адреса");
@@ -456,6 +455,8 @@ define("WEB_user_add_mac","Mac (необязательно)");
 define("WEB_user_list_apply","Применить к списку");
 define("WEB_new_user","Новый юзер");
 define("WEB_user_deleted","принадлежит несуществующему юзеру. Вероятно запись удалена");
+define("WEB_user_bind_mac","Привязать мак в юзеру");
+define("WEB_user_unbind_mac","Отвязать мак от юзера");
 
 /* public */
 define("WEB_msg_access_login","Интернет (логин)");

+ 31 - 0
html/utils/auth_apply.php

@@ -31,6 +31,10 @@ if (isset($_POST["ApplyForAll"])) {
         $_POST["n_link"] = 0;
     }
 
+    if (empty($_POST["a_bind_mac"])) {
+        $_POST["a_bind_mac"] = 0;
+    }
+
     $a_enabled  = $_POST["a_enabled"] * 1;
     $a_dhcp     = $_POST["a_dhcp"] * 1;
     $a_dhcp_acl = $_POST["a_dhcp_acl"];
@@ -38,6 +42,8 @@ if (isset($_POST["ApplyForAll"])) {
     $a_group    = $_POST["a_group_id"] * 1;
     $a_traf     = $_POST["a_traf"] * 1;
 
+    $a_bind_mac = $_POST["a_bind_mac"]*1;
+
     $n_enabled = $_POST["n_enabled"] * 1;
     $n_link    = $_POST["n_link"] * 1;
     $n_handler = $_POST["n_handler"];
@@ -93,6 +99,31 @@ if (isset($_POST["ApplyForAll"])) {
                 if (!$ret) {
                     $all_ok = 0;
                 }
+
+            //bind mac rule
+            if (isset($_POST["e_bind_mac"])) {
+                $first_auth = get_record_sql($db_link,"SELECT user_id,mac FROM User_auth WHERE id=".$val);
+                if ($a_bind_mac) {
+                    if (!empty($first_auth) and !empty($first_auth['mac'])) {
+                        $auth_rules = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=2 AND rule='".$first_auth['mac']."'");
+                        if (empty($auth_rules)) {
+                                $new['user_id']=$first_auth['user_id'];
+                                $new['type']=2;
+                                $new['rule']=$first_auth['mac'];
+                                insert_record($db_link,"auth_rules",$new);
+                                LOG_INFO($db_link,"Created auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']);
+                            } else {
+                                LOG_INFO($db_link,"Auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']." already exists");
+                            }
+                        }
+                    } else {
+                        run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=2");
+                        LOG_INFO($db_link,"Remove auto rule for user_id: ".$first_auth['user_id']." and mac ".$first_auth['mac']);
+                    }
+                header("Location: " . $_SERVER["REQUEST_URI"]);
+                exit;
+                }
+
             }
         }
     }