Просмотр исходного кода

create bind ip autorule in user list & all ip's pages

Roman Dmitriev 2 лет назад
Родитель
Сommit
9048922a11

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

@@ -78,6 +78,7 @@ print_ip_submenu($page_url);
 	<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_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_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>
 	<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>
+    <tr><td><input type=checkbox class="putField" name="e_bind_ip" value='1'></td><td><?php print WEB_user_bind_ip."&nbsp";print_qa_select('a_bind_ip', 1);?></td></tr>
 	</table>
 	</table>
 	<input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
 	<input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
     </form>
     </form>

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

@@ -75,6 +75,7 @@ if ($msg_error) {
         <tr><td><input type=checkbox class="putField" name="e_month_q" value='1'></td><td><?php print WEB_cell_permonth."&nbsp"; ?><input type="text" name="a_month_q" value="0" size=5></td></tr>
         <tr><td><input type=checkbox class="putField" name="e_month_q" value='1'></td><td><?php print WEB_cell_permonth."&nbsp"; ?><input type="text" name="a_month_q" value="0" size=5></td></tr>
         <tr><td><input type=checkbox class="putField" name="e_new_ou" value='1'></td><td><?php print WEB_cell_ou."&nbsp";print_ou_select($db_link, 'a_new_ou', $rou); ?></td></tr>
         <tr><td><input type=checkbox class="putField" name="e_new_ou" value='1'></td><td><?php print WEB_cell_ou."&nbsp";print_ou_select($db_link, 'a_new_ou', $rou); ?></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>
         <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>
+        <tr><td><input type=checkbox class="putField" name="e_bind_ip" value='1'></td><td><?php print WEB_user_bind_ip."&nbsp";print_qa_select('a_bind_ip', 1);?></td></tr>
         </table>
         </table>
         <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
         <input type="submit" name="submit" class="btn" value="<?php echo WEB_btn_apply; ?>">
     </form>
     </form>

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

@@ -457,6 +457,8 @@ 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_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_bind_mac","Bind mac for login");
 define("WEB_user_unbind_mac","Unbind mac for login");
 define("WEB_user_unbind_mac","Unbind mac for login");
+define("WEB_user_bind_ip","Bind ip-address for login");
+define("WEB_user_unbind_ip","Unbind ip-address for login");
 
 
 /* public */
 /* public */
 define("WEB_msg_access_login","Internet for login");
 define("WEB_msg_access_login","Internet for login");

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

@@ -457,6 +457,8 @@ define("WEB_new_user","Новый юзер");
 define("WEB_user_deleted","принадлежит несуществующему юзеру. Вероятно запись удалена");
 define("WEB_user_deleted","принадлежит несуществующему юзеру. Вероятно запись удалена");
 define("WEB_user_bind_mac","Привязать мак к юзеру");
 define("WEB_user_bind_mac","Привязать мак к юзеру");
 define("WEB_user_unbind_mac","Отвязать мак от юзера");
 define("WEB_user_unbind_mac","Отвязать мак от юзера");
+define("WEB_user_bind_ip","Привязать IP-адрес к юзеру");
+define("WEB_user_unbind_ip","Отвязать IP-адрес от юзера");
 
 
 /* public */
 /* public */
 define("WEB_msg_access_login","Интернет (логин)");
 define("WEB_msg_access_login","Интернет (логин)");

+ 31 - 0
html/utils/auth_apply.php

@@ -35,6 +35,10 @@ if (isset($_POST["ApplyForAll"])) {
         $_POST["a_bind_mac"] = 0;
         $_POST["a_bind_mac"] = 0;
     }
     }
 
 
+    if (empty($_POST["a_bind_ip"])) {
+        $_POST["a_bind_ip"] = 0;
+    }
+
     $a_enabled  = $_POST["a_enabled"] * 1;
     $a_enabled  = $_POST["a_enabled"] * 1;
     $a_dhcp     = $_POST["a_dhcp"] * 1;
     $a_dhcp     = $_POST["a_dhcp"] * 1;
     $a_dhcp_acl = $_POST["a_dhcp_acl"];
     $a_dhcp_acl = $_POST["a_dhcp_acl"];
@@ -43,6 +47,7 @@ if (isset($_POST["ApplyForAll"])) {
     $a_traf     = $_POST["a_traf"] * 1;
     $a_traf     = $_POST["a_traf"] * 1;
 
 
     $a_bind_mac = $_POST["a_bind_mac"]*1;
     $a_bind_mac = $_POST["a_bind_mac"]*1;
+    $a_bind_ip  = $_POST["a_bind_ip"]*1;
 
 
     $n_enabled = $_POST["n_enabled"] * 1;
     $n_enabled = $_POST["n_enabled"] * 1;
     $n_link    = $_POST["n_link"] * 1;
     $n_link    = $_POST["n_link"] * 1;
@@ -123,6 +128,32 @@ if (isset($_POST["ApplyForAll"])) {
                         LOG_ERROR($db_link,"Auto rule for user_id: ".$first_auth['user_id']." not created. Record not found or empty mac.");
                         LOG_ERROR($db_link,"Auto rule for user_id: ".$first_auth['user_id']." not created. Record not found or empty mac.");
                     }
                     }
             }
             }
+
+            //bind ip rule
+            if (isset($_POST["e_bind_ip"])) {
+                $first_auth = get_record_sql($db_link,"SELECT user_id,ip FROM User_auth WHERE id=".$val);
+                if (!empty($first_auth) and !empty($first_auth['ip'])) {
+                    if ($a_bind_ip) {
+                            $auth_rules_user = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=1");
+                            $auth_rules_ip = get_record_sql($db_link,"SELECT * FROM auth_rules WHERE rule='".$first_auth['ip']."' AND type=1");
+                            if (empty($auth_rules_user) and empty($auth_rules_ip)) {
+                                $new['user_id']=$first_auth['user_id'];
+                                $new['type']=1;
+                                $new['rule']=$first_auth['ip'];
+                                insert_record($db_link,"auth_rules",$new);
+                                LOG_INFO($db_link,"Created auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']);
+                                } else {
+                                LOG_INFO($db_link,"Auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']." already exists");
+                                }
+                            } else {
+                                run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$first_auth['user_id']." AND type=1");
+                                LOG_INFO($db_link,"Remove auto rule for user_id: ".$first_auth['user_id']." and ip ".$first_auth['ip']);
+                            }
+                    } else {
+                        LOG_ERROR($db_link,"Auto rule for user_id: ".$first_auth['user_id']." not created. Record not found or empty ip.");
+                    }
+            }
+
         }
         }
     }
     }
     if ($all_ok) {
     if ($all_ok) {

+ 32 - 1
html/utils/user_apply.php

@@ -38,6 +38,10 @@ if (isset($_POST["ApplyForAll"])) {
         $_POST["a_bind_mac"] = 0;
         $_POST["a_bind_mac"] = 0;
     }
     }
 
 
+    if (empty($_POST["a_bind_ip"])) {
+        $_POST["a_bind_ip"] = 0;
+    }
+
     $a_enabled  = $_POST["a_enabled"] * 1;
     $a_enabled  = $_POST["a_enabled"] * 1;
     $a_dhcp     = $_POST["a_dhcp"] * 1;
     $a_dhcp     = $_POST["a_dhcp"] * 1;
     $a_dhcp_acl = $_POST["a_dhcp_acl"];
     $a_dhcp_acl = $_POST["a_dhcp_acl"];
@@ -49,6 +53,7 @@ if (isset($_POST["ApplyForAll"])) {
     $a_ou_id    = $_POST["a_new_ou"] * 1;
     $a_ou_id    = $_POST["a_new_ou"] * 1;
 
 
     $a_bind_mac = $_POST["a_bind_mac"] * 1;
     $a_bind_mac = $_POST["a_bind_mac"] * 1;
+    $a_bind_ip  = $_POST["a_bind_ip"] * 1;
 
 
     $msg = "Massive User change!";
     $msg = "Massive User change!";
     LOG_WARNING($db_link, $msg);
     LOG_WARNING($db_link, $msg);
@@ -96,8 +101,9 @@ if (isset($_POST["ApplyForAll"])) {
                 $all_ok = 0;
                 $all_ok = 0;
             }
             }
 
 
-            $auth_list = get_records_sql($db_link, "SELECT id, mac FROM User_auth WHERE deleted=0 AND user_id=" . $val);
+            $auth_list = get_records_sql($db_link, "SELECT id, mac, ip FROM User_auth WHERE deleted=0 AND user_id=" . $val);
             $b_mac = '';
             $b_mac = '';
+            $b_ip = '';
             if (!empty($auth_list)) {
             if (!empty($auth_list)) {
                 foreach ($auth_list as $row) {
                 foreach ($auth_list as $row) {
                     if (empty($row)) {
                     if (empty($row)) {
@@ -106,6 +112,9 @@ if (isset($_POST["ApplyForAll"])) {
                     if (empty($b_mac) and !empty($row["mac"])) {
                     if (empty($b_mac) and !empty($row["mac"])) {
                         $b_mac = $row["mac"];
                         $b_mac = $row["mac"];
                     }
                     }
+                    if (empty($b_ip) and !empty($row["ip"])) {
+                        $b_ip = $row["ip"];
+                    }
                     $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $auth);
                     $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $auth);
                     if (!$ret) {
                     if (!$ret) {
                         $all_ok = 0;
                         $all_ok = 0;
@@ -134,6 +143,28 @@ if (isset($_POST["ApplyForAll"])) {
                         LOG_INFO($db_link, "Remove auto rule for user_id: " . $val . " and mac " . $b_mac);
                         LOG_INFO($db_link, "Remove auto rule for user_id: " . $val . " and mac " . $b_mac);
                 }
                 }
             }
             }
+
+            //bind ip rule
+            if (isset($_POST["e_bind_ip"])) {
+                if ($a_bind_ip) {
+                    if (!empty($b_ip)) {
+                        $auth_rules_user = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE user_id=" . $val . " AND type=1");
+                        $auth_rules_ip = get_record_sql($db_link, "SELECT * FROM auth_rules WHERE rule='" . $b_ip . "' AND type=1");
+                        if (empty($auth_rules_user) and empty($auth_rules_ip)) {
+                                $new['user_id'] = $val;
+                                $new['type'] = 1;
+                                $new['rule'] = $b_ip;
+                                insert_record($db_link, "auth_rules", $new);
+                                LOG_INFO($db_link, "Created auto rule for user_id: " . $val . " and ip " . $b_ip);
+                            } else {
+                                LOG_INFO($db_link, "Auto rule for user_id: " . $val . " and ip " . $ip . " already exists");
+                            }
+                        }
+                    } else {
+                        run_sql($db_link, "DELETE FROM auth_rules WHERE user_id=" . $val . " AND type=1");
+                        LOG_INFO($db_link, "Remove auto rule for user_id: " . $val . " and ip " . $b_ip);
+                }
+            }
         }
         }
     }
     }
     if ($all_ok) {
     if ($all_ok) {