فهرست منبع

move action from filter table to filter list in group

rajven 2 سال پیش
والد
کامیت
dff151f896

+ 108 - 26
docs/iptables/sync_iptables.pl

@@ -21,6 +21,7 @@ use IPTables::libiptc;
 use DBI;
 use DBI;
 use utf8;
 use utf8;
 use open ":encoding(utf8)";
 use open ":encoding(utf8)";
+use Net::DNS;
 
 
 #exit;
 #exit;
 
 
@@ -66,50 +67,131 @@ if ($connected_users_only) {
 db_log_verbose($dbh,"Sync user state at router $router_name started.");
 db_log_verbose($dbh,"Sync user state at router $router_name started.");
 
 
 #get userid list
 #get userid list
-my $user_auth_sql="SELECT User_auth.ip, User_auth.filter_group_id
+my $user_auth_sql="SELECT User_auth.ip, User_auth.filter_group_id, User_auth.queue_id, User_auth.id
 FROM User_auth, User_list
 FROM User_auth, User_list
 WHERE User_auth.user_id = User_list.id
 WHERE User_auth.user_id = User_list.id
 AND User_auth.deleted =0
 AND User_auth.deleted =0
 AND User_auth.enabled =1
 AND User_auth.enabled =1
 AND User_auth.blocked =0
 AND User_auth.blocked =0
 AND User_list.blocked =0
 AND User_list.blocked =0
-AND User_auth.user_id <> $hotspot_user_id
+AND User_list.enabled =1
+AND User_auth.ou_id <> $default_hotspot_ou_id
 ORDER BY ip_int";
 ORDER BY ip_int";
 
 
-my %users;
-
 my @authlist_ref = get_records_sql($dbh,$user_auth_sql);
 my @authlist_ref = get_records_sql($dbh,$user_auth_sql);
+my %users;
+my %lists;
+my %found_users;
 
 
-#print Dumper(\@authlist_ref);
 foreach my $row (@authlist_ref) {
 foreach my $row (@authlist_ref) {
-if ($connected_users_only) {
-    next if (!$connected_users->match_string($row->{ip}));
-    }
-$users{'group_'.$row->{filter_group_id}}->{ips}{$row->{ip}}=1;
+if ($connected_users_only) { next if (!$connected_users->match_string($row->{ip})); }
+#skip not office ip's
+next if (!$office_networks->match_string($row->{ip}));
+$found_users{$row->{'id'}}=$row->{ip};
+#filter group acl's
+$users{'group_'.$row->{filter_group_id}}->{$row->{ip}}=1;
+$users{'group_all'}->{$row->{ip}}=1;
+$lists{'group_'.$row->{filter_group_id}}=1;
+#queue acl's
+if ($row->{queue_id}) { $users{'queue_'.$row->{queue_id}}->{$row->{ip}}=1; }
+}
+
+log_debug("Users status:".Dumper(\%users));
+
+#full list
+$lists{'group_all'}=1;
+
+#get queue list
+my @queuelist_ref = get_records_sql($dbh,"SELECT * FROM Queue_list");
+
+my %queues;
+foreach my $row (@queuelist_ref) {
+$lists{'queue_'.$row->{id}}=1;
+next if ((!$row->{Download}) and !($row->{Upload}));
+$queues{'queue_'.$row->{id}}{id}=$row->{id};
+$queues{'queue_'.$row->{id}}{down}=$row->{Download};
+$queues{'queue_'.$row->{id}}{up}=$row->{Upload};
 }
 }
 
 
-#get filters
-my @filter_list = get_records_sql($dbh,"SELECT id,name,proto,dst,dstport,action FROM Filter_list where type=0");
+log_debug("Queues status:".Dumper(\%queues));
+
+my @filterlist_ref = get_records_sql($dbh,"SELECT * FROM Filter_list where type=0");
+
 my %filters;
 my %filters;
-foreach my $row (@filter_list) {
-$filters{$row->{id}}->{id}=$row->{id};
-$filters{$row->{id}}->{proto}=$row->{proto};
-$filters{$row->{id}}->{dst}=$row->{dst};
-$filters{$row->{id}}->{port}=$row->{dstport};
-$filters{$row->{id}}->{action}=$row->{action};
+my %dyn_filters;
+
+my $max_filter_rec = get_record_sql($dbh,"SELECT MAX(id) FROM Filter_list");
+my $max_filter_id = $max_filter_rec->{id};
+
+my $dyn_filters_base = $max_filter_id+1000;
+my $dyn_filters_index = $dyn_filters_base;
+
+foreach my $row (@filterlist_ref) {
+    #if dst - ip address
+    if (is_ip($row->{dst})) {
+        $filters{$row->{id}}->{id}=$row->{id};
+        $filters{$row->{id}}->{proto}=$row->{proto};
+        $filters{$row->{id}}->{dst}=$row->{dst};
+        $filters{$row->{id}}->{dstport}=$row->{dstport};
+        $filters{$row->{id}}->{srcport}=$row->{srcport};
+        #set false for dns dst flag
+        $filters{$row->{id}}->{dns_dst}=0;
+        } else {
+        #if dst not ip - check dns record
+        my @dns_record=ResolveNames($row->{dst},undef);
+        my $resolved_ips = (scalar @dns_record>0);
+        next if (!$resolved_ips);
+        foreach my $resolved_ip (sort @dns_record) {
+                next if (!$resolved_ip);
+                #enable dns dst filters
+                $filters{$row->{id}}->{dns_dst}=1;
+                #add dynamic dns filter
+                $filters{$dyn_filters_index}->{id}=$row->{id};
+                $filters{$dyn_filters_index}->{proto}=$row->{proto};
+                $filters{$dyn_filters_index}->{dst}=$resolved_ip;
+                $filters{$dyn_filters_index}->{dstport}=$row->{dstport};
+                $filters{$dyn_filters_index}->{srcport}=$row->{srcport};
+                $filters{$dyn_filters_index}->{dns_dst}=0;
+                #save new filter dns id for original filter id
+                push(@{$dyn_filters{$row->{id}}},$dyn_filters_index);
+                $dyn_filters_index++;
+            }
+        }
 }
 }
 
 
-#get groups
-my @group_list = get_records_sql($dbh,"SELECT group_id,filter_id,Group_filters.order FROM Group_filters ORDER BY Group_filters.group_id,Group_filters.order" );
+log_debug("Filters status:". Dumper(\%filters));
+log_debug("DNS-filters status:". Dumper(\%dyn_filters));
+
+#clean unused filter records
+do_sql($dbh,"DELETE FROM Group_filters WHERE group_id NOT IN (SELECT id FROM Group_list)");
+do_sql($dbh,"DELETE FROM Group_filters WHERE filter_id NOT IN (SELECT id FROM Filter_list)");
+
+my @grouplist_ref = get_records_sql($dbh,"SELECT `group_id`,`filter_id`,`order`,`action` FROM Group_filters ORDER BY Group_filters.group_id,Group_filters.order");
+
 my %group_filters;
 my %group_filters;
-my %lists;
 my $index=0;
 my $index=0;
-foreach my $row (@group_list) {
-$group_filters{'group_'.$row->{group_id}}->{$index}=$row->{filter_id};
-$lists{'group_'.$row->{group_id}}=1;
-$index++;
+foreach my $row (@grouplist_ref) {
+    #if dst dns filter not found
+    if (!$filters{$row->{filter_id}}->{dns_dst}) {
+        $group_filters{'group_'.$row->{group_id}}->{$index}->{filter_id}=$row->{filter_id};
+        $group_filters{'group_'.$row->{group_id}}->{$index}->{action}=$row->{action};
+        $index++;
+    } else {
+        #if found dns dst filters - add
+	    if (exists $dyn_filters{$row->{filter_id}}) {
+	        my @dyn_ips = @{$dyn_filters{$row->{filter_id}}};
+	        if (scalar @dyn_ips >0) {
+		        for (my $i = 0; $i < scalar @dyn_ips; $i++) {
+        	        $group_filters{'group_'.$row->{group_id}}->{$index}=$dyn_ips[$i];
+        	        $index++;
+        	    }
+	        }
+        }
+    }
 }
 }
 
 
+log_debug("Group filters: ".Dumper(\%group_filters));
+
 my %cur_users;
 my %cur_users;
 
 
 my @new_iptables_users=();
 my @new_iptables_users=();
@@ -169,7 +251,7 @@ next if (!$group_name);
 next if (!exists($group_filters{$group_name}));
 next if (!exists($group_filters{$group_name}));
 push(@{$chain_rules{$group_name}},"-N $group_name");
 push(@{$chain_rules{$group_name}},"-N $group_name");
 foreach my $filter_index (sort keys %{$group_filters{$group_name}}) {
 foreach my $filter_index (sort keys %{$group_filters{$group_name}}) {
-    my $filter_id=$group_filters{$group_name}->{$filter_index};
+    my $filter_id=$group_filters{$group_name}->{$filter_index}->{filter_id};
     next if (!$filters{$filter_id});
     next if (!$filters{$filter_id});
     my $src_rule='-A '.$group_name;
     my $src_rule='-A '.$group_name;
     my $dst_rule='-A '.$group_name;
     my $dst_rule='-A '.$group_name;
@@ -190,7 +272,7 @@ foreach my $filter_index (sort keys %{$group_filters{$group_name}}) {
 	$src_rule=$src_rule.$module." --sport ".trim($filters{$filter_id}->{port});
 	$src_rule=$src_rule.$module." --sport ".trim($filters{$filter_id}->{port});
 	$dst_rule=$dst_rule.$module." --dport ".trim($filters{$filter_id}->{port});
 	$dst_rule=$dst_rule.$module." --dport ".trim($filters{$filter_id}->{port});
 	}
 	}
-    if ($filters{$filter_id}->{action}) {
+    if ($group_filters{$group_name}->{$filter_index}->{action}) {
 	$src_rule=$src_rule." -j ACCEPT";
 	$src_rule=$src_rule." -j ACCEPT";
 	$dst_rule=$dst_rule." -j ACCEPT";
 	$dst_rule=$dst_rule." -j ACCEPT";
 	} else {
 	} else {

+ 208 - 148
html/admin/customers/control-subnets.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 
 
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 
 
 if (isset($_POST["s_remove"])) {
 if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];
     $s_id = $_POST["s_id"];
@@ -10,80 +10,98 @@ if (isset($_POST["s_remove"])) {
             if (isset($val)) {
             if (isset($val)) {
                 LOG_INFO($db_link, "Remove subnet id: $val");
                 LOG_INFO($db_link, "Remove subnet id: $val");
                 delete_record($db_link, "subnets", "id=" . $val);
                 delete_record($db_link, "subnets", "id=" . $val);
-                }
             }
             }
         }
         }
+    }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
     exit;
 }
 }
 
 
 if (isset($_POST['s_save'])) {
 if (isset($_POST['s_save'])) {
     $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
     $len = is_array($_POST['s_save']) ? count($_POST['s_save']) : 0;
-    for ($i = 0; $i < $len; $i ++) {
+    for ($i = 0; $i < $len; $i++) {
         $save_id = intval($_POST['s_save'][$i]);
         $save_id = intval($_POST['s_save'][$i]);
         $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
         $len_all = is_array($_POST['n_id']) ? count($_POST['n_id']) : 0;
-        for ($j = 0; $j < $len_all; $j ++) {
-            if (intval($_POST['n_id'][$j]) != $save_id) { continue; }
+        for ($j = 0; $j < $len_all; $j++) {
+            if (intval($_POST['n_id'][$j]) != $save_id) {
+                continue;
+            }
             $new['subnet'] = trim($_POST['s_subnet'][$j]);
             $new['subnet'] = trim($_POST['s_subnet'][$j]);
-            $new['office'] = $_POST['s_office'][$j]*1;
-            $new['hotspot'] = $_POST['s_hotspot'][$j]*1;
-            $new['vpn'] = $_POST['s_vpn'][$j]*1;
-            $new['free'] = $_POST['s_free'][$j]*1;
-            $new['dhcp'] = $_POST['s_dhcp'][$j]*1;
-            $new['dhcp_lease_time'] = $_POST['s_lease_time'][$j]*1;
-            $new['static'] = $_POST['s_static'][$j]*1;
-            $new['discovery'] = $_POST['s_discovery'][$j]*1;
-            $new['dhcp_update_hostname'] = $_POST['s_dhcp_update'][$j]*1;
+            $new['office'] = $_POST['s_office'][$j] * 1;
+            $new['hotspot'] = $_POST['s_hotspot'][$j] * 1;
+            $new['vpn'] = $_POST['s_vpn'][$j] * 1;
+            $new['free'] = $_POST['s_free'][$j] * 1;
+            $new['dhcp'] = $_POST['s_dhcp'][$j] * 1;
+            $new['dhcp_lease_time'] = $_POST['s_lease_time'][$j] * 1;
+            $new['static'] = $_POST['s_static'][$j] * 1;
+            $new['discovery'] = $_POST['s_discovery'][$j] * 1;
+            $new['dhcp_update_hostname'] = $_POST['s_dhcp_update'][$j] * 1;
             $new['comment'] = trim($_POST['s_comment'][$j]);
             $new['comment'] = trim($_POST['s_comment'][$j]);
             $range = cidrToRange($new['subnet']);
             $range = cidrToRange($new['subnet']);
-	    $first_user_ip = $range[0];
-	    $last_user_ip = $range[1];
+            $first_user_ip = $range[0];
+            $last_user_ip = $range[1];
             $cidr = $range[2][1];
             $cidr = $range[2][1];
-	    if (isset($cidr) and $cidr <= 32) {
-	        $new['subnet'] = $first_user_ip . '/' . $cidr;
-		} else {
-	        $new['subnet'] = '';
-		}
+            if (isset($cidr) and $cidr <= 32) {
+                $new['subnet'] = $first_user_ip . '/' . $cidr;
+            } else {
+                $new['subnet'] = '';
+            }
             $new['ip_int_start'] = ip2long($first_user_ip);
             $new['ip_int_start'] = ip2long($first_user_ip);
-	    $new['ip_int_stop'] = ip2long($last_user_ip);
+            $new['ip_int_stop'] = ip2long($last_user_ip);
             $new['dhcp_start'] = ip2long(trim($_POST['s_dhcp_start'][$j]));
             $new['dhcp_start'] = ip2long(trim($_POST['s_dhcp_start'][$j]));
             $new['dhcp_stop'] = ip2long(trim($_POST['s_dhcp_stop'][$j]));
             $new['dhcp_stop'] = ip2long(trim($_POST['s_dhcp_stop'][$j]));
-            $dhcp_fail=0;
-            if (!isset($new['dhcp_start']) or $new['dhcp_start']==0) { $dhcp_fail=1; }
-            if (!isset($new['dhcp_stop']) or $new['dhcp_stop']==0) { $dhcp_fail=1; }
-            if (!$dhcp_fail and ($new['dhcp_start']-$new['ip_int_stop'] >= 0)) { $dhcp_fail=1; }
-            if (!$dhcp_fail and ($new['dhcp_start']-$new['ip_int_start'] <= 0)) { $dhcp_fail=1; }
-            if (!$dhcp_fail and ($new['dhcp_stop']-$new['ip_int_stop']>=0)) { $dhcp_fail=1; }
-            if (!$dhcp_fail and ($new['dhcp_stop']-$new['ip_int_start']<=0)) { $dhcp_fail=1; }
-            if (!$dhcp_fail and ($new['dhcp_start']-$new['dhcp_stop']>=0)) { $dhcp_fail=1; }
+            $dhcp_fail = 0;
+            if (!isset($new['dhcp_start']) or $new['dhcp_start'] == 0) {
+                $dhcp_fail = 1;
+            }
+            if (!isset($new['dhcp_stop']) or $new['dhcp_stop'] == 0) {
+                $dhcp_fail = 1;
+            }
+            if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_stop'] >= 0)) {
+                $dhcp_fail = 1;
+            }
+            if (!$dhcp_fail and ($new['dhcp_start'] - $new['ip_int_start'] <= 0)) {
+                $dhcp_fail = 1;
+            }
+            if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_stop'] >= 0)) {
+                $dhcp_fail = 1;
+            }
+            if (!$dhcp_fail and ($new['dhcp_stop'] - $new['ip_int_start'] <= 0)) {
+                $dhcp_fail = 1;
+            }
+            if (!$dhcp_fail and ($new['dhcp_start'] - $new['dhcp_stop'] >= 0)) {
+                $dhcp_fail = 1;
+            }
             if ($dhcp_fail) {
             if ($dhcp_fail) {
-        	$new['dhcp_start']=ip2long($range[3]);
-        	$new['dhcp_stop']=ip2long($range[4]);
-        	}
-	    $gateway = ip2long(trim($_POST['s_gateway'][$j]));
-	    if (!isset($gateway)) { $gateway=$range[5]; }
-	    $new['gateway']=$gateway;
-	    if ($new['hotspot']) {
-        	$new['dhcp_update_hostname'] = 0;
-        	$new['discovery'] = 0;
-        	$new['vpn'] = 0;
-		}
-	    if ($new['vpn']) {
-        	$new['discovery'] = 0;
-        	$new['dhcp'] = 0;
-		}
-	    if ($new['office']) {
-        	$new['free'] = 0;
-        	}
+                $new['dhcp_start'] = ip2long($range[3]);
+                $new['dhcp_stop'] = ip2long($range[4]);
+            }
+            $gateway = ip2long(trim($_POST['s_gateway'][$j]));
+            if (!isset($gateway)) {
+                $gateway = $range[5];
+            }
+            $new['gateway'] = $gateway;
+            if ($new['hotspot']) {
+                $new['dhcp_update_hostname'] = 0;
+                $new['discovery'] = 0;
+                $new['vpn'] = 0;
+            }
+            if ($new['vpn']) {
+                $new['discovery'] = 0;
+                $new['dhcp'] = 0;
+            }
+            if ($new['office']) {
+                $new['free'] = 0;
+            }
             if (!$new['office']) {
             if (!$new['office']) {
-        	$new['discovery'] = 0;
-        	$new['dhcp'] = 0;
-        	$new['static'] = 0;
-        	$new['dhcp_update_hostname'] = 0;
-        	$new['gateway'] = 0;
-        	$new['dhcp_start'] = 0;
-        	$new['dhcp_stop'] = 0;
-        	}
+                $new['discovery'] = 0;
+                $new['dhcp'] = 0;
+                $new['static'] = 0;
+                $new['dhcp_update_hostname'] = 0;
+                $new['gateway'] = 0;
+                $new['dhcp_start'] = 0;
+                $new['dhcp_stop'] = 0;
+            }
             update_record($db_link, "subnets", "id='{$save_id}'", $new);
             update_record($db_link, "subnets", "id='{$save_id}'", $new);
         }
         }
     }
     }
@@ -106,9 +124,9 @@ if (isset($_POST["s_create"])) {
         }
         }
         $new['ip_int_start'] = ip2long($first_user_ip);
         $new['ip_int_start'] = ip2long($first_user_ip);
         $new['ip_int_stop'] = ip2long($last_user_ip);
         $new['ip_int_stop'] = ip2long($last_user_ip);
-    	$new['dhcp_start'] = ip2long($range[3]);
-    	$new['dhcp_stop'] = ip2long($range[4]);
-    	$new['gateway'] = ip2long($range[5]);
+        $new['dhcp_start'] = ip2long($range[3]);
+        $new['dhcp_stop'] = ip2long($range[4]);
+        $new['gateway'] = ip2long($range[5]);
         LOG_INFO($db_link, "Create new subnet $new_subnet");
         LOG_INFO($db_link, "Create new subnet $new_subnet");
         insert_record($db_link, "subnets", $new);
         insert_record($db_link, "subnets", $new);
     }
     }
@@ -120,96 +138,138 @@ unset($_POST);
 
 
 fix_auth_rules($db_link);
 fix_auth_rules($db_link);
 
 
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
 
 
 print_control_submenu($page_url);
 print_control_submenu($page_url);
 
 
 ?>
 ?>
 <div id="cont">
 <div id="cont">
-<br>
-<form name="def" action="control-subnets.php" method="post">
-<b><?php echo WEB_network_org_title; ?></b> <br>
-<table class="data">
-<tr align="center">
-	<td></td>
-	<td width=30><b>id</b></td>
-	<td><b><?php echo WEB_network_subnet; ?></b></td>
-	<td><b><?php echo WEB_network_gateway; ?></b></td>
-	<td><b><?php echo WEB_network_use_dhcp; ?></b></td>
-	<td><b><?php echo WEB_network_static; ?></b></td>
-	<td><b><?php echo WEB_network_dhcp_first; ?></b></td>
-	<td><b><?php echo WEB_network_dhcp_last; ?></b></td>
-	<td><b><?php echo WEB_network_dhcp_leasetime; ?></b></td>
-	<td><b><?php echo WEB_network_office_subnet; ?></b></td>
-	<td><b><?php echo WEB_network_hotspot; ?></b></td>
-	<td><b><?php echo WEB_network_vpn; ?></b></td>
-	<td><b><?php echo WEB_network_free; ?></b></td>
-	<td><b><?php echo WEB_network_dyndns; ?></b></td>
-	<td><b><?php echo WEB_network_discovery; ?></b></td>
-	<td><b><?php echo WEB_cell_comment; ?></b></td>
-	<td><input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="s_remove" value="<?php print WEB_btn_remove; ?>"></td>
-</tr>
-<?php
-$t_subnets = get_records($db_link,'subnets','True ORDER BY ip_int_start');
-foreach ( $t_subnets as $row ) {
-    print "<tr align=center>\n";
-    $cl="data";
-    print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
-    print "<td class=\"$cl\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
-    print "<td class=\"$cl\"><input type=\"text\" name='s_subnet[]' value='{$row['subnet']}' size='18'></td>\n";
-    $cell_disabled='';
-    if ($row['office'] and !$row['vpn']) {
-	$default_range=cidrToRange($row['subnet']);
-        if (!isset($row['dhcp_start']) or !($row['dhcp_start']>0)) { $row['dhcp_start']=ip2long($default_range[3]); }
-        if (!isset($row['dhcp_stop']) or !($row['dhcp_stop']>0)) { $row['dhcp_stop']=ip2long($default_range[4]); }
-	} else {
-	$cell_disabled='readonly=true';
-	$cl='down';
-	}
-    print "<td class=\"$cl\"><input type=\"text\" name='s_gateway[]' value='".long2ip($row['gateway'])."'  size='15' $cell_disabled></td>\n";
-    if ($row['dhcp']) { $cl = 'up'; } else { $cl = 'data'; }
-    print "<td class=\"$cl\">"; print_qa_select("s_dhcp[]",$row['dhcp']); print "</td>\n";
-    if ($row['static']) { $cl = 'up'; } else { $cl = 'data'; }
-    print "<td class=\"$cl\">"; print_qa_select("s_static[]",$row['static']); print "</td>\n";
-    $cl = 'data';
-    print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_start[]' value='".long2ip($row['dhcp_start'])."' size='15' $cell_disabled></td>\n";
-    print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_stop[]' value='".long2ip($row['dhcp_stop'])."' size='15' $cell_disabled></td>\n";
-    print "<td class=\"$cl\"><input type=\"text\" name='s_lease_time[]' value='".$row['dhcp_lease_time']."'size='3' $cell_disabled></td>\n";
-    $row_cl = 'data';
-    if (!$row['office']) { $row_cl='down'; }
-    if ($row['office']) { $cl = 'up'; } else { $cl = 'data'; }
-    print "<td class=\"$cl\">";
-    print_qa_select("s_office[]",$row['office']);
-    print "</td>\n";
-    if ($row_cl ==='data' and $row['hotspot']) { $cl = 'up'; } else { $cl = $row_cl; }
-    print "<td class=\"$cl\">";
-    print_qa_select_ext("s_hotspot[]",$row['hotspot'],!$row['office']);
-    print "</td>\n";
-    if ($row_cl ==='data' and $row['vpn']) { $cl = 'up'; } else { $cl = $row_cl; }
-    print "<td class=\"$cl\">";
-    print_qa_select_ext("s_vpn[]",$row['vpn'],!$row['office']);
-    print "</td>\n";
-    if ($row['free']) { $cl = 'up'; } else { $cl = $row_cl; }
-    print "<td class=\"$cl\">";
-    print_qa_select("s_free[]",$row['free']);
-    print "</td>\n";
-    if ($row_cl ==='data' and $row['dhcp_update_hostname']) { $cl = 'up'; } else { $cl = $row_cl; }
-    print "<td class=\"$cl\">";
-    print_qa_select_ext("s_dhcp_update[]",$row['dhcp_update_hostname'],!$row['office']);
-    print "</td>\n";
-    if ($row_cl ==='data' and $row['discovery']) { $cl = 'up'; } else { $cl = $row_cl; }
-    print "<td class=\"$cl\">";
-    print_qa_select_ext("s_discovery[]",$row['discovery'],!$row['office']);
-    print "</td>\n";
-    print "<td class=\"data\"><input type=\"text\" name='s_comment[]' value='{$row['comment']}'></td>\n";
-    print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>".WEB_btn_save."</button></td>\n";
-    print "</tr>\n";
-}
-?>
-<tr>
-<td colspan=6><?php print WEB_network_create."&nbsp:<input type=\"text\" name='s_create_subnet' value=''>"; ?></td>
-<td><input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>"></td>
-</tr>
-</table>
-</form>
-<?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php"); ?>
+    <br>
+    <form name="def" action="control-subnets.php" method="post">
+        <b><?php echo WEB_network_org_title; ?></b> <br>
+        <table class="data">
+            <tr align="center">
+                <td></td>
+                <td width=30><b>id</b></td>
+                <td><b><?php echo WEB_network_subnet; ?></b></td>
+                <td><b><?php echo WEB_network_gateway; ?></b></td>
+                <td><b><?php echo WEB_network_use_dhcp; ?></b></td>
+                <td><b><?php echo WEB_network_static; ?></b></td>
+                <td><b><?php echo WEB_network_dhcp_first; ?></b></td>
+                <td><b><?php echo WEB_network_dhcp_last; ?></b></td>
+                <td><b><?php echo WEB_network_dhcp_leasetime; ?></b></td>
+                <td><b><?php echo WEB_network_office_subnet; ?></b></td>
+                <td><b><?php echo WEB_network_hotspot; ?></b></td>
+                <td><b><?php echo WEB_network_vpn; ?></b></td>
+                <td><b><?php echo WEB_network_free; ?></b></td>
+                <td><b><?php echo WEB_network_dyndns; ?></b></td>
+                <td><b><?php echo WEB_network_discovery; ?></b></td>
+                <td><b><?php echo WEB_cell_comment; ?></b></td>
+                <td><input type="submit" onclick="return confirm('<?php print WEB_btn_delete; ?>?')" name="s_remove" value="<?php print WEB_btn_remove; ?>"></td>
+            </tr>
+            <?php
+            $t_subnets = get_records($db_link, 'subnets', 'True ORDER BY ip_int_start');
+            foreach ($t_subnets as $row) {
+                print "<tr align=center>\n";
+                $cl = "data";
+                print "<td class=\"$cl\" style='padding:0'><input type=checkbox name=s_id[] value='{$row['id']}'></td>\n";
+                print "<td class=\"$cl\"><input type=\"hidden\" name='n_id[]' value='{$row['id']}'>{$row['id']}</td>\n";
+                print "<td class=\"$cl\"><input type=\"text\" name='s_subnet[]' value='{$row['subnet']}' size='18'></td>\n";
+                $cell_disabled = '';
+                if ($row['office'] and !$row['vpn']) {
+                    $default_range = cidrToRange($row['subnet']);
+                    if (!isset($row['dhcp_start']) or !($row['dhcp_start'] > 0)) {
+                        $row['dhcp_start'] = ip2long($default_range[3]);
+                    }
+                    if (!isset($row['dhcp_stop']) or !($row['dhcp_stop'] > 0)) {
+                        $row['dhcp_stop'] = ip2long($default_range[4]);
+                    }
+                } else {
+                    $cell_disabled = 'readonly=true';
+                    $cl = 'down';
+                }
+                print "<td class=\"$cl\"><input type=\"text\" name='s_gateway[]' value='" . long2ip($row['gateway']) . "'  size='15' $cell_disabled></td>\n";
+                if ($row['dhcp']) {
+                    $cl = 'up';
+                } else {
+                    $cl = 'data';
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select("s_dhcp[]", $row['dhcp']);
+                print "</td>\n";
+                if ($row['static']) {
+                    $cl = 'up';
+                } else {
+                    $cl = 'data';
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select("s_static[]", $row['static']);
+                print "</td>\n";
+                $cl = 'data';
+                print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_start[]' value='" . long2ip($row['dhcp_start']) . "' size='15' $cell_disabled></td>\n";
+                print "<td class=\"$cl\"><input type=\"text\" name='s_dhcp_stop[]' value='" . long2ip($row['dhcp_stop']) . "' size='15' $cell_disabled></td>\n";
+                print "<td class=\"$cl\"><input type=\"text\" name='s_lease_time[]' value='" . $row['dhcp_lease_time'] . "'size='3' $cell_disabled></td>\n";
+                $row_cl = 'data';
+                if (!$row['office']) {
+                    $row_cl = 'down';
+                }
+                if ($row['office']) {
+                    $cl = 'up';
+                } else {
+                    $cl = 'data';
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select("s_office[]", $row['office']);
+                print "</td>\n";
+                if ($row_cl === 'data' and $row['hotspot']) {
+                    $cl = 'up';
+                } else {
+                    $cl = $row_cl;
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select_ext("s_hotspot[]", $row['hotspot'], !$row['office']);
+                print "</td>\n";
+                if ($row_cl === 'data' and $row['vpn']) {
+                    $cl = 'up';
+                } else {
+                    $cl = $row_cl;
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select_ext("s_vpn[]", $row['vpn'], !$row['office']);
+                print "</td>\n";
+                if ($row['free']) {
+                    $cl = 'up';
+                } else {
+                    $cl = $row_cl;
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select("s_free[]", $row['free']);
+                print "</td>\n";
+                if ($row_cl === 'data' and $row['dhcp_update_hostname']) {
+                    $cl = 'up';
+                } else {
+                    $cl = $row_cl;
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select_ext("s_dhcp_update[]", $row['dhcp_update_hostname'], !$row['office']);
+                print "</td>\n";
+                if ($row_cl === 'data' and $row['discovery']) {
+                    $cl = 'up';
+                } else {
+                    $cl = $row_cl;
+                }
+                print "<td class=\"$cl\">";
+                print_qa_select_ext("s_discovery[]", $row['discovery'], !$row['office']);
+                print "</td>\n";
+                print "<td class=\"data\"><input type=\"text\" name='s_comment[]' value='{$row['comment']}'></td>\n";
+                print "<td class=\"data\"><button name='s_save[]' value='{$row['id']}'>" . WEB_btn_save . "</button></td>\n";
+                print "</tr>\n";
+            }
+            ?>
+            <tr>
+                <td colspan=6><?php print WEB_network_create . "&nbsp:<input type=\"text\" name='s_create_subnet' value=''>"; ?></td>
+                <td><input type="submit" name="s_create" value="<?php echo WEB_btn_add; ?>"></td>
+            </tr>
+        </table>
+    </form>
+    <?php require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php"); ?>

+ 3 - 16
html/admin/filters/editfilter.php

@@ -9,7 +9,6 @@ if (isset($_POST["editfilter"])) {
     $new['proto'] = $_POST["f_proto"];
     $new['proto'] = $_POST["f_proto"];
     $new['dstport'] = str_replace(':', '-', $_POST["f_dstport"]);
     $new['dstport'] = str_replace(':', '-', $_POST["f_dstport"]);
     $new['srcport'] = str_replace(':', '-', $_POST["f_srcport"]);
     $new['srcport'] = str_replace(':', '-', $_POST["f_srcport"]);
-    $new['action'] = $_POST["f_action"] * 1;
     $new['comment'] = $_POST["f_comment"];
     $new['comment'] = $_POST["f_comment"];
     update_record($db_link, "Filter_list", "id='$id'", $new);
     update_record($db_link, "Filter_list", "id='$id'", $new);
     unset($_POST);
     unset($_POST);
@@ -35,15 +34,11 @@ print "<input type=hidden name=id value=$id>";
 if (isset($filter['type']) and $filter['type'] == 0) {
 if (isset($filter['type']) and $filter['type'] == 0) {
     print "<table class=\"data\" cellspacing=\"0\" cellpadding=\"4\">";
     print "<table class=\"data\" cellspacing=\"0\" cellpadding=\"4\">";
     print "<tr><td><b>".WEB_cell_forename."</b></td>";
     print "<tr><td><b>".WEB_cell_forename."</b></td>";
-    print "<td ><b>".WEB_cell_comment."</b></td>";
-    print "<td ><b>".WEB_traffic_action."</b></td>";
+    print "<td colspan=2><b>".WEB_cell_comment."</b></td>";
     print "</tr>";
     print "</tr>";
     print "<tr>";
     print "<tr>";
     print "<td align=left><input type=text name=f_name value='".$filter['name']."'></td>";
     print "<td align=left><input type=text name=f_name value='".$filter['name']."'></td>";
-    print "<td ><input type=text name=f_comment value='".$filter['comment']."'></td>";
-    print "<td>";
-    print_action_select('f_action', $filter['action']);
-    print "</td>";
+    print "<td colspan=2><input type=text name=f_comment value='".$filter['comment']."'></td>";
     print "<td><input type=submit name=editfilter value='".WEB_btn_save."'></td>";
     print "<td><input type=submit name=editfilter value='".WEB_btn_save."'></td>";
     print "</tr>";
     print "</tr>";
     print "<tr>";
     print "<tr>";
@@ -62,23 +57,15 @@ if (isset($filter['type']) and $filter['type'] == 0) {
 } else {
 } else {
     print "<table class=\"data\" cellspacing=\"0\" cellpadding=\"4\">";
     print "<table class=\"data\" cellspacing=\"0\" cellpadding=\"4\">";
     print "<tr><td><b>".WEB_cell_forename."</b></td>";
     print "<tr><td><b>".WEB_cell_forename."</b></td>";
-    print "<td ><b>".WEB_cell_comment."</b></td>";
-    print "<td ><b>".WEB_traffic_action."</b></td>";
+    print "<td><b>".WEB_cell_comment."</b></td>";
     print "<td><input type=submit name=editfilter value=".WEB_btn_save."></td>";
     print "<td><input type=submit name=editfilter value=".WEB_btn_save."></td>";
     print "</tr>";
     print "</tr>";
     print "<tr>";
     print "<tr>";
     print "<td align=left><input type=text name=f_name value='".$filter['name']."'></td>";
     print "<td align=left><input type=text name=f_name value='".$filter['name']."'></td>";
     print "<td ><input type=text name=f_comment value='".$filter['comment']."'></td>";
     print "<td ><input type=text name=f_comment value='".$filter['comment']."'></td>";
-    print "<td>";
-    print_action_select('f_action', $filter['action']);
-    print "</td>";
     print "<td ><input type=text name=f_dst value='".$filter['dst']."'></td>";
     print "<td ><input type=text name=f_dst value='".$filter['dst']."'></td>";
-    print "</td>";
-    print_action_select('f_action', $filter['action']);
-    print "</td>";
     print "</tr>";
     print "</tr>";
     print "</table>";
     print "</table>";
 }
 }
 print "</form>";
 print "</form>";
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
 require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
-?>

+ 92 - 62
html/admin/filters/editgroup.php

@@ -1,7 +1,7 @@
 <?php
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/idfilter.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/idfilter.php");
 
 
 if (isset($_POST["editgroup"])) {
 if (isset($_POST["editgroup"])) {
     $new['group_name'] = $_POST["f_group_name"];
     $new['group_name'] = $_POST["f_group_name"];
@@ -13,33 +13,52 @@ if (isset($_POST["editgroup"])) {
 
 
 if (isset($_POST["addfilter"])) {
 if (isset($_POST["addfilter"])) {
     $filter_id = $_POST["newfilter"] * 1;
     $filter_id = $_POST["newfilter"] * 1;
-    list ($forder) = mysqli_fetch_array(mysqli_query($db_link, "SELECT MAX(GF.order) FROM Group_filters GF where group_id='$id'"));
-    $forder ++;
+    $max_record = get_record_sql($db_link, "SELECT MAX(G.order) as morder FROM Group_filters as G where G.group_id='$id'");
+    if (empty($max_record)) {
+        $forder = 1;
+    } else {
+        $forder = $max_record["morder"] * 1 + 1;
+    }
     $new['group_id'] = $id;
     $new['group_id'] = $id;
     $new['filter_id'] = $filter_id;
     $new['filter_id'] = $filter_id;
     $new['order'] = $forder;
     $new['order'] = $forder;
+    $new['action'] = 1;
     insert_record($db_link, "Group_filters", $new);
     insert_record($db_link, "Group_filters", $new);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
     exit;
 }
 }
 
 
 if (isset($_POST["removefilter"])) {
 if (isset($_POST["removefilter"])) {
-    $fgid = $_POST["fgid"];
-    foreach ($fgid as $key => $val) {
-        if (!empty($val)) { delete_record($db_link, "Group_filters", "id=" . $val * 1); }
+    $f_group_filter = $_POST["f_group_filter"];
+    foreach ($f_group_filter as $key => $val) {
+        if (!empty($val)) {
+            delete_record($db_link, "Group_filters", "id=" . $val * 1);
+        }
     }
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
     exit;
 }
 }
-if (isset($_POST["saveorder"])) {
-    if ((isset($_POST["fgid"])) and (isset($_POST["ford"]))) {
-        $fgid = $_POST["fgid"];
-        $ford = $_POST["ford"];
-        LOG_DEBUG($db_link, "Resort filter rules for group id: $id");
-        foreach ($ford as $key => $val) {
-            $gid = $fgid[$key];
-            $new['order'] = $val;
-            update_record($db_link, "Group_filters", "id=" . $gid, $new);
+
+if (isset($_POST["updateFilters"])) {
+    var_dump($_POST);
+    if (!empty($_POST["f_group_filter"])) {
+        $f_group_filter = $_POST["f_group_filter"];
+        LOG_DEBUG($db_link, "Update filters for group id: " . $id);
+        for ($i = 0; $i < count($f_group_filter); ++$i) {
+            $group_filter_id = $f_group_filter[$i];
+            if (empty($_POST["f_ord"][$group_filter_id])) {
+                $new['order'] = $i;
+            } else {
+                $new['order'] = $_POST["f_ord"][$group_filter_id] * 1;
+            }
+            if (empty($_POST["f_action"][$group_filter_id])) {
+                $new['action'] = 0;
+            } else {
+                $new['action'] = $_POST["f_action"][$group_filter_id] * 1;
+            }
+            if (!empty($new)) {
+                update_record($db_link, "Group_filters", "id=" . $group_filter_id, $new);
+            }
         }
         }
     }
     }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     header("Location: " . $_SERVER["REQUEST_URI"]);
@@ -48,55 +67,66 @@ if (isset($_POST["saveorder"])) {
 
 
 unset($_POST);
 unset($_POST);
 
 
-$group = get_record_sql($db_link, "SELECT * FROM Group_list WHERE id=".$id);
+$group = get_record_sql($db_link, "SELECT * FROM Group_list WHERE id=" . $id);
 
 
 print_filters_submenu($page_url);
 print_filters_submenu($page_url);
 
 
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
 ?>
 ?>
 <div id="cont">
 <div id="cont">
-<br> <b><?php echo WEB_title_group; ?></b> <br>
+    <br> <b><?php echo WEB_title_group; ?></b> <br>
 
 
-<form name="def" action="editgroup.php?id=<?php echo $id; ?>" method="post">
-<input type="hidden" name="id" value=<?php echo $id; ?>>
-<table class="data">
-<tr>
-<td><?php echo WEB_cell_name; ?></td>
-<td><input type="text" name="f_group_name" value="<?php echo $group['group_name']; ?>"></td>
-<td><?php echo WEB_cell_comment; ?></td>
-<td><input type="text" name="f_group_comment" value="<?php echo $group['comment']; ?>"></td>
-</tr>
-<tr>
-<td colspan=2><input type="submit" name="editgroup"	value="<?php echo WEB_btn_save; ?>"></td>
-</tr>
-</table>
-<br> <b><?php echo WEB_groups_filter_list; ?></b><br>
-<table class="data">
-<tr>
-<td><input type="checkbox" onClick="checkAll(this.checked);"></td>
-<td><?php echo WEB_group_filter_order; ?></td>
-<td><?php echo WEB_group_filter_name; ?></td>
-<td align="right"><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete_filter; ?>?')" name="removefilter" value="<?php echo WEB_btn_delete; ?>"></td>
-</tr>
+    <form name="def" action="editgroup.php?id=<?php echo $id; ?>" method="post">
+        <input type="hidden" name="id" value=<?php echo $id; ?>>
+        <table class="data">
+            <tr>
+                <td><?php echo WEB_cell_name; ?></td>
+                <td class='data'><input type="text" name="f_group_name" value="<?php echo $group['group_name']; ?>"></td>
+                <td class='data' align=right><input type="submit" name="editgroup" value="<?php echo WEB_btn_save; ?>"></td>
+            </tr>
+            <tr>
+                <td><?php echo WEB_cell_comment; ?></td>
+                <td class='data'><input type="text" name="f_group_comment" value="<?php echo $group['comment']; ?>"></td>
+                <td class='data'></td>
+            </tr>
+        </table>
+        <br> <b><?php echo WEB_groups_filter_list; ?></b><br>
+        <table class="data">
+            <tr>
+                <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
+                <td><?php echo WEB_group_filter_order; ?></td>
+                <td><?php echo WEB_group_filter_name; ?></td>
+                <td><?php echo WEB_traffic_action; ?></td>
+                <td class='up'><input type="submit" name="updateFilters" value="<?php echo WEB_btn_save_filters; ?>"></td>
+                <td class='warn'><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete_filter; ?>?')" name="removefilter" value="<?php echo WEB_btn_delete; ?>"></td>
+            </tr>
 
 
-<?php
-$sSQL = "SELECT G.id, G.filter_id, F.name, G.order, F.comment FROM Group_filters G, Filter_list F WHERE F.id=G.filter_id and group_id=$id Order by G.order";
-$flist = get_records_sql($db_link,$sSQL);
-foreach ($flist as $row) {
-    print "<tr align=center>\n";
-    print "<td class=\"data\" style='padding:0'><input type=checkbox name=fgid[] value=".$row['id']."></td>\n";
-    print "<td class=\"data\" align=left><input type=text name=ford[] value=".$row['order']." size=4 ></td>\n";
-    print "<td class=\"data\" align=left><a href=editfilter.php?id=".$row['filter_id'].">" . $row['name'] . "</a></td>\n";
-    print "<td class=\"data\" align=left>" . $row['comment'] . "</a></td>\n";
-    print "</tr>";
-}
-?>
-</table>
-<div>
-<input type="submit" name="addfilter" value="<?php echo WEB_msg_add_filter; ?>"> <?php print_filter_select($db_link, 'newfilter', $id); ?>
-<input type="submit" name="saveorder" value="<?php echo WEB_btn_reorder; ?>">
-</div>
-</form>
-<?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
-?>
+            <?php
+            $sSQL = "SELECT G.id, G.filter_id, F.name, G.order, G.action, F.comment FROM Group_filters G, Filter_list F WHERE F.id=G.filter_id and group_id=$id Order by G.order";
+            $flist = get_records_sql($db_link, $sSQL);
+            foreach ($flist as $row) {
+                print "<tr align=center>\n";
+                print "<td class=\"data\" style='padding:0'><input type=checkbox name=f_group_filter[] value=" . $row['id'] . "></td>\n";
+                print "<td class=\"data\" align=left><input type=text name=f_ord[" . $row['id'] . "] value=" . $row['order'] . " size=4 ></td>\n";
+                print "<td class=\"data\" align=left><a href=editfilter.php?id=" . $row['filter_id'] . ">" . $row['name'] . "</a></td>\n";
+                $cl = "data";
+                if ($row['action']) {
+                    $cl = "up";
+                } else {
+                    $cl = "warn";
+                }
+                print "<td class=" . $cl . ">";
+                print_action_select('f_action[' . $row['id'] . ']', $row['action']);
+                print "</td>";
+                print "<td colspan=2 class=\"data\" align=left>" . $row['comment'] . "</a></td>\n";
+                print "</tr>";
+            }
+            ?>
+        </table>
+        <div>
+            <input type="submit" name="addfilter" value="<?php echo WEB_msg_add_filter; ?>"> <?php print_filter_select($db_link, 'newfilter', $id); ?>
+        </div>
+    </form>
+    <?php
+    require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php");
+    ?>

+ 38 - 35
html/admin/filters/groups.php

@@ -1,12 +1,12 @@
 <?php
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 
 
 if (isset($_POST["create"])) {
 if (isset($_POST["create"])) {
     $fname = $_POST["newgroup"];
     $fname = $_POST["newgroup"];
     if ($fname) {
     if ($fname) {
         $new['group_name'] = $fname;
         $new['group_name'] = $fname;
-        $new_id=insert_record($db_link, "Group_list", $new);
+        $new_id = insert_record($db_link, "Group_list", $new);
         header("location: editgroup.php?id=$new_id");
         header("location: editgroup.php?id=$new_id");
         exit;
         exit;
     }
     }
@@ -17,44 +17,47 @@ if (isset($_POST["create"])) {
 if (isset($_POST["remove"])) {
 if (isset($_POST["remove"])) {
     $fgid = $_POST["fid"];
     $fgid = $_POST["fid"];
     foreach ($fgid as $key => $val) {
     foreach ($fgid as $key => $val) {
-        if (!empty($val)) { delete_record($db_link, "Group_list", "id=" . $val * 1); }
+        if (!empty($val)) {
+            run_sql($db_link, "DELETE FROM Group_filters WHERE group_id=" . $val * 1);
+            delete_record($db_link, "Group_list", "id=" . $val * 1);
         }
         }
+    }
     header("Location: " . $_SERVER["REQUEST_URI"]);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
     exit;
-    }
+}
 
 
 unset($_POST);
 unset($_POST);
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
 
 
 print_filters_submenu($page_url);
 print_filters_submenu($page_url);
 ?>
 ?>
 <div id="cont">
 <div id="cont">
-<form name="def" action="groups.php" method="post">
-<table class="data">
-<tr align="center">
-	<td><input type="checkbox" onClick="checkAll(this.checked);"></td>
-	<td><b>Id</b></td>
-	<td width=200><b><?php echo WEB_cell_name; ?></b></td>
-	<td width=200><b><?php echo WEB_cell_comment; ?></b></td>
-    <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
-</tr>
-<?php
-$groups = get_records_sql($db_link,'SELECT * FROM Group_list ORDER BY id');
-foreach ($groups as $row) {
-    print "<tr align=center>\n";
-    print "<td class=\"data\" style='padding:0'><input type=checkbox name=fid[] value=".$row["id"]."></td>\n";
-    print "<td class=\"data\" ><input type=\"hidden\" name=\"".$row["id"]."\" value=".$row["id"].">".$row["id"]."</td>\n";
-    print "<td class=\"data\"><a href=editgroup.php?id=".$row["id"].">" . $row["group_name"] . "</a></td>\n";
-    print "<td class=\"data\">" . $row["comment"] . "</td>\n";
-    print "<td></td></tr>";
-}
-?>
-</table>
-<div>
-<?php echo WEB_cell_name; ?><input type=text name=newgroup value="Unknown">
-<input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
-</div>
-</form>
-<?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
-?>
+    <form name="def" action="groups.php" method="post">
+        <table class="data">
+            <tr align="center">
+                <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
+                <td><b>Id</b></td>
+                <td width=200><b><?php echo WEB_cell_name; ?></b></td>
+                <td width=200><b><?php echo WEB_cell_comment; ?></b></td>
+                <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
+            </tr>
+            <?php
+            $groups = get_records_sql($db_link, 'SELECT * FROM Group_list ORDER BY id');
+            foreach ($groups as $row) {
+                print "<tr align=center>\n";
+                print "<td class=\"data\" style='padding:0'><input type=checkbox name=fid[] value=" . $row["id"] . "></td>\n";
+                print "<td class=\"data\" ><input type=\"hidden\" name=\"" . $row["id"] . "\" value=" . $row["id"] . ">" . $row["id"] . "</td>\n";
+                print "<td class=\"data\"><a href=editgroup.php?id=" . $row["id"] . ">" . $row["group_name"] . "</a></td>\n";
+                print "<td class=\"data\">" . $row["comment"] . "</td>\n";
+                print "<td></td></tr>";
+            }
+            ?>
+        </table>
+        <div>
+            <?php echo WEB_cell_name; ?><input type=text name=newgroup value="Unknown">
+            <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
+        </div>
+    </form>
+    <?php
+    require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php");
+    ?>

+ 75 - 68
html/admin/filters/index.php

@@ -1,27 +1,27 @@
 <?php
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 
 
 if (isset($_POST["create"])) {
 if (isset($_POST["create"])) {
     $fname = $_POST["newfilter"];
     $fname = $_POST["newfilter"];
     $ftype = 0;
     $ftype = 0;
     if (isset($_POST['filter_type'])) {
     if (isset($_POST['filter_type'])) {
         $ftype = $_POST["filter_type"] * 1;
         $ftype = $_POST["filter_type"] * 1;
-	}
+    }
     if (isset($fname)) {
     if (isset($fname)) {
         $new['name'] = $fname;
         $new['name'] = $fname;
         $new['type'] = $ftype;
         $new['type'] = $ftype;
-        $new_id=insert_record($db_link, "Filter_list", $new);
+        $new_id = insert_record($db_link, "Filter_list", $new);
         header("Location: editfilter.php?id=$new_id");
         header("Location: editfilter.php?id=$new_id");
         exit;
         exit;
-	}
     }
     }
+}
 
 
 if (isset($_POST["remove"])) {
 if (isset($_POST["remove"])) {
     $fid = $_POST["fid"];
     $fid = $_POST["fid"];
     foreach ($fid as $key => $val) {
     foreach ($fid as $key => $val) {
         if ($val) {
         if ($val) {
-            run_sql($db_link, "DELETE FROM Group_filters WHERE filter_id=".$val);
+            run_sql($db_link, "DELETE FROM Group_filters WHERE filter_id=" . $val);
             delete_record($db_link, "Filter_list", "id=$val");
             delete_record($db_link, "Filter_list", "id=$val");
         }
         }
     }
     }
@@ -29,68 +29,75 @@ if (isset($_POST["remove"])) {
     exit;
     exit;
 }
 }
 unset($_POST);
 unset($_POST);
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/header.php");
 print_filters_submenu($page_url);
 print_filters_submenu($page_url);
 ?>
 ?>
 <div id="cont">
 <div id="cont">
-<form name="def" action="index.php" method="post">
-	<table class="data">
-	<tr align="center">
-		<td><input type="checkbox" onClick="checkAll(this.checked);"></td>
-		<td><b>id</b></td>
-		<td><b><?php echo WEB_cell_forename; ?></b></td>
-		<td><b><?php echo WEB_cell_type; ?></b></td>
-		<td><b><?php echo WEB_traffic_proto; ?></b></td>
-		<td><b><?php echo WEB_traffic_dest_address; ?></b></td>
-		<td><b><?php echo WEB_traffic_dst_port; ?></b></td>
-		<td><b><?php echo WEB_traffic_src_port; ?></b></td>
-		<td><b><?php echo WEB_traffic_action; ?></b></td>
-		<td><b><?php echo WEB_cell_comment; ?></b></td>
-        <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
-	</tr>
-<?php
-$filters = get_records_sql($db_link,'SELECT * FROM Filter_list ORDER BY name');
-foreach ($filters as $row) {
-    print "<tr align=center>\n";
-    print "<td class=\"data\" style='padding:0'><input type=checkbox name=fid[] value=".$row['id']."></td>\n";
-    print "<td class=\"data\" ><input type=hidden name=\"id\" value=".$row['id'].">".$row['id']."</td>\n";
-    print "<td class=\"data\" align=left><a href=editfilter.php?id=".$row['id'].">" . $row['name'] . "</a></td>\n";
-    if (empty($row['comment'])) { $row['comment']=''; }
-    if (empty($row['proto'])) { $row['proto']=''; }
-    if (empty($row['dst'])) { $row['dst']=''; }
-    if (empty($row['dstport'])) { $row['dstport']=''; }
-    if (empty($row['srcport'])) { $row['srcport']=''; }
-    if ($row['type'] == 0) {
-        print "<td class=\"data\">IP фильтр</td>\n";
-        print "<td class=\"data\">".$row['proto']."</td>\n";
-        print "<td class=\"data\">".$row['dst']."</td>\n";
-        print "<td class=\"data\">".$row['dstport']."</td>\n";
-        print "<td class=\"data\">".$row['srcport']."</td>\n";
-        print "<td class=\"data\">" . get_action($row['action']) . "</td>\n";
-        print "<td class=\"data\">".$row['comment']."</td>\n";
-    } else {
-        print "<td class=\"data\">Name фильтр</td>\n";
-        print "<td class=\"data\"></td>\n";
-        print "<td class=\"data\">".$row['dst']."</td>\n";
-        print "<td class=\"data\"></td>\n";
-        print "<td class=\"data\"></td>\n";
-        print "<td class=\"data\">" . get_action($row['action']) . "</td>\n";
-        print "<td class=\"data\">".$row['comment']."</td>\n";
-    }
-    print "<td></td></tr>";
-}
-?>
-</table>
-<div>
-<?php echo WEB_cell_name; ?>
-<input type=text name=newfilter value="Unknown">
-<?php echo Web_filter_type; ?>
-<select name="filter_type" disabled=true>
-	<option value=0 selected>IP фильтр</option>
-	<option value=1>Name фильтр</option>
-</select>
-<input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
-</form>
-<?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
-?>
+    <form name="def" action="index.php" method="post">
+        <table class="data">
+            <tr align="center">
+                <td><input type="checkbox" onClick="checkAll(this.checked);"></td>
+                <td><b>id</b></td>
+                <td><b><?php echo WEB_cell_forename; ?></b></td>
+                <td><b><?php echo WEB_cell_type; ?></b></td>
+                <td><b><?php echo WEB_traffic_proto; ?></b></td>
+                <td><b><?php echo WEB_traffic_dest_address; ?></b></td>
+                <td><b><?php echo WEB_traffic_dst_port; ?></b></td>
+                <td><b><?php echo WEB_traffic_src_port; ?></b></td>
+                <td><b><?php echo WEB_cell_comment; ?></b></td>
+                <td><input type="submit" onclick="return confirm('<?php echo WEB_msg_delete; ?>?')" name="remove" value="<?php echo WEB_btn_delete; ?>"></td>
+            </tr>
+            <?php
+            $filters = get_records_sql($db_link, 'SELECT * FROM Filter_list ORDER BY name');
+            foreach ($filters as $row) {
+                print "<tr align=center>\n";
+                print "<td class=\"data\" style='padding:0'><input type=checkbox name=fid[] value=" . $row['id'] . "></td>\n";
+                print "<td class=\"data\" ><input type=hidden name=\"id\" value=" . $row['id'] . ">" . $row['id'] . "</td>\n";
+                print "<td class=\"data\" align=left><a href=editfilter.php?id=" . $row['id'] . ">" . $row['name'] . "</a></td>\n";
+                if (empty($row['comment'])) {
+                    $row['comment'] = '';
+                }
+                if (empty($row['proto'])) {
+                    $row['proto'] = '';
+                }
+                if (empty($row['dst'])) {
+                    $row['dst'] = '';
+                }
+                if (empty($row['dstport'])) {
+                    $row['dstport'] = '';
+                }
+                if (empty($row['srcport'])) {
+                    $row['srcport'] = '';
+                }
+                if ($row['type'] == 0) {
+                    print "<td class=\"data\">IP фильтр</td>\n";
+                    print "<td class=\"data\">" . $row['proto'] . "</td>\n";
+                    print "<td class=\"data\">" . $row['dst'] . "</td>\n";
+                    print "<td class=\"data\">" . $row['dstport'] . "</td>\n";
+                    print "<td class=\"data\">" . $row['srcport'] . "</td>\n";
+                    print "<td class=\"data\">" . $row['comment'] . "</td>\n";
+                } else {
+                    print "<td class=\"data\">Name фильтр</td>\n";
+                    print "<td class=\"data\"></td>\n";
+                    print "<td class=\"data\">" . $row['dst'] . "</td>\n";
+                    print "<td class=\"data\"></td>\n";
+                    print "<td class=\"data\"></td>\n";
+                    print "<td class=\"data\">" . $row['comment'] . "</td>\n";
+                }
+                print "<td></td></tr>";
+            }
+            ?>
+        </table>
+        <div>
+            <?php echo WEB_cell_name; ?>
+            <input type=text name=newfilter value="Unknown">
+            <?php echo Web_filter_type; ?>
+            <select name="filter_type" disabled=true>
+                <option value=0 selected>IP фильтр</option>
+                <option value=1>Name фильтр</option>
+            </select>
+            <input type="submit" name="create" value="<?php echo WEB_btn_add; ?>">
+    </form>
+    <?php
+    require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/footer.php");
+    ?>

+ 4 - 4
html/inc/auth.utils.php

@@ -17,8 +17,8 @@ function logout()
     if (session_id()) {
     if (session_id()) {
         // Если есть активная сессия, удаляем куки сессии
         // Если есть активная сессия, удаляем куки сессии
         setcookie(session_name(), session_id(), time() - 60 * 60 * 24);
         setcookie(session_name(), session_id(), time() - 60 * 60 * 24);
-        if (isset($_COOKIE["Auth"])) { 
-            unset($_COOKIE["Auth"]); 
+        if (isset($_COOKIE["Auth"])) {
+            unset($_COOKIE["Auth"]);
             setcookie("Auth", null, -1);
             setcookie("Auth", null, -1);
         }
         }
         session_unset();
         session_unset();
@@ -35,8 +35,8 @@ function qlogout()
     if (session_id()) {
     if (session_id()) {
         // Если есть активная сессия, удаляем куки сессии
         // Если есть активная сессия, удаляем куки сессии
         setcookie(session_name(), session_id(), time() - 60 * 60 * 24);
         setcookie(session_name(), session_id(), time() - 60 * 60 * 24);
-        if (isset($_COOKIE["Auth"])) { 
-            unset($_COOKIE["Auth"]); 
+        if (isset($_COOKIE["Auth"])) {
+            unset($_COOKIE["Auth"]);
             setcookie("Auth", null, -1);
             setcookie("Auth", null, -1);
         }
         }
         session_unset();
         session_unset();

+ 4 - 4
html/inc/common.php

@@ -2968,7 +2968,7 @@ function update_record($db, $table, $filter, $newvalue)
     LOG_DEBUG($db, "Run sql: $new_sql");
     LOG_DEBUG($db, "Run sql: $new_sql");
     $sql_result = mysqli_query($db, $new_sql) or LOG_ERROR($db, "SQL: $new_sql :".mysqli_error($db));
     $sql_result = mysqli_query($db, $new_sql) or LOG_ERROR($db, "SQL: $new_sql :".mysqli_error($db));
     if (!$sql_result) { LOG_ERROR($db, "UPDATE Request: $new_sql :".mysqli_error($db)); return; }
     if (!$sql_result) { LOG_ERROR($db, "UPDATE Request: $new_sql :".mysqli_error($db)); return; }
-    LOG_VERBOSE($db, "Change table $table WHERE $filter set $changed_log");
+    if ( $table !== "sessions" ) { LOG_VERBOSE($db, "Change table $table WHERE $filter set $changed_log"); }
 }
 }
 
 
 function delete_record($db, $table, $filter)
 function delete_record($db, $table, $filter)
@@ -3012,7 +3012,7 @@ function delete_record($db, $table, $filter)
         $sql_result = mysqli_query($db, $new_sql) or LOG_ERROR($db, "SQL: $new_sql :".mysqli_error($db));
         $sql_result = mysqli_query($db, $new_sql) or LOG_ERROR($db, "SQL: $new_sql :".mysqli_error($db));
         if (!$sql_result) { LOG_ERROR($db, "DELETE Request: $new_sql : ".mysqli_error($db)); return; }
         if (!$sql_result) { LOG_ERROR($db, "DELETE Request: $new_sql : ".mysqli_error($db)); return; }
         }
         }
-    LOG_VERBOSE($db, "Delete FROM table $table WHERE $filter $changed_log");
+    if ( $table !== "sessions" ) { LOG_VERBOSE($db, "Delete FROM table $table WHERE $filter $changed_log"); }
     return $changed_log;
     return $changed_log;
 }
 }
 
 
@@ -3052,8 +3052,8 @@ function insert_record($db, $table, $newvalue)
     $sql_result = mysqli_query($db, $new_sql) or LOG_ERROR($db, "SQL: $new_sql :".mysqli_error($db));
     $sql_result = mysqli_query($db, $new_sql) or LOG_ERROR($db, "SQL: $new_sql :".mysqli_error($db));
     if (!$sql_result) { LOG_ERROR($db, "INSERT Request:".mysqli_error($db)); return; }
     if (!$sql_result) { LOG_ERROR($db, "INSERT Request:".mysqli_error($db)); return; }
     $last_id = mysqli_insert_id($db);
     $last_id = mysqli_insert_id($db);
-    LOG_VERBOSE($db, "Create record in table $table: $changed_log with id: $last_id");
-    if ($table === 'User_auth') { run_sql($db,"UPDATE User_auth SET changed=1 WHERE id=".$last_id); }
+    if ( $table !== "sessions" ) { LOG_VERBOSE($db, "Create record in table $table: $changed_log with id: $last_id"); }
+    if ( $table === 'User_auth') { run_sql($db,"UPDATE User_auth SET changed=1 WHERE id=".$last_id); }
     return $last_id;
     return $last_id;
 }
 }
 
 

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

@@ -238,6 +238,7 @@ define("WEB_btn_recover","Restore");
 define("WEB_btn_transfom","Transform");
 define("WEB_btn_transfom","Transform");
 define("WEB_btn_login","Enter");
 define("WEB_btn_login","Enter");
 define("WEB_btn_apply_selected","Apply for selected");
 define("WEB_btn_apply_selected","Apply for selected");
+define("WEB_btn_save_filters","Save filters");
 
 
 /* control options */
 /* control options */
 define("WEB_config_remove_option","Parameter removed");
 define("WEB_config_remove_option","Parameter removed");

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

@@ -238,6 +238,7 @@ define("WEB_btn_recover","Восстановить");
 define("WEB_btn_transfom","Преобразовать");
 define("WEB_btn_transfom","Преобразовать");
 define("WEB_btn_login","Войти");
 define("WEB_btn_login","Войти");
 define("WEB_btn_apply_selected","Поменять у выделения");
 define("WEB_btn_apply_selected","Поменять у выделения");
+define("WEB_btn_save_filters","Сохранить фильтры");
 
 
 /* control options */
 /* control options */
 define("WEB_config_remove_option","Удалён параметр");
 define("WEB_config_remove_option","Удалён параметр");

+ 77 - 29
html/utils/auth_apply.php

@@ -1,21 +1,35 @@
 <?php
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 
 
-if (! defined("CONFIG")) die("Not defined");
+if (!defined("CONFIG")) die("Not defined");
 
 
 if (isset($_POST["ApplyForAll"])) {
 if (isset($_POST["ApplyForAll"])) {
 
 
     $auth_id = $_POST["fid"];
     $auth_id = $_POST["fid"];
 
 
-    if (empty($_POST["a_enabled"])) { $_POST["a_enabled"]=0; }
-    if (empty($_POST["a_dhcp"])) { $_POST["a_dhcp"]=0; }
-    if (empty($_POST["a_queue_id"])) { $_POST["a_queue_id"]=0; }
-    if (empty($_POST["a_group_id"])) { $_POST["a_group_id"]=0; }
-    if (empty($_POST["a_traf"])) { $_POST["a_traf"]=0; }
+    if (empty($_POST["a_enabled"])) {
+        $_POST["a_enabled"] = 0;
+    }
+    if (empty($_POST["a_dhcp"])) {
+        $_POST["a_dhcp"] = 1;
+    }
+    if (empty($_POST["a_queue_id"])) {
+        $_POST["a_queue_id"] = 0;
+    }
+    if (empty($_POST["a_group_id"])) {
+        $_POST["a_group_id"] = 0;
+    }
+    if (empty($_POST["a_traf"])) {
+        $_POST["a_traf"] = 1;
+    }
 
 
-    if (empty($_POST["n_enabled"])) { $_POST["n_enabled"]=0; }
-    if (empty($_POST["n_link"])) { $_POST["n_link"]=0; }
+    if (empty($_POST["n_enabled"])) {
+        $_POST["n_enabled"] = 0;
+    }
+    if (empty($_POST["n_link"])) {
+        $_POST["n_link"] = 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;
@@ -28,29 +42,63 @@ if (isset($_POST["ApplyForAll"])) {
     $n_link    = $_POST["n_link"] * 1;
     $n_link    = $_POST["n_link"] * 1;
     $n_handler = $_POST["n_handler"];
     $n_handler = $_POST["n_handler"];
 
 
-    $msg="Massive User change!";
-    LOG_WARNING($db_link,$msg);
+    $msg = "Massive User change!";
+    LOG_WARNING($db_link, $msg);
 
 
-    $all_ok=1;
+    $all_ok = 1;
     foreach ($auth_id as $key => $val) {
     foreach ($auth_id as $key => $val) {
         if ($val) {
         if ($val) {
             unset($auth);
             unset($auth);
-	    if (isset($_POST["e_enabled"]))    { $auth['enabled'] = $a_enabled; }
-	    if (isset($_POST["e_group_id"]))   { $auth['filter_group_id'] = $a_group; }
-	    if (isset($_POST["e_queue_id"]))   { $auth['queue_id'] = $a_queue; }
-	    if (isset($_POST["e_dhcp"]))       { $auth['dhcp'] = $a_dhcp; }
-	    if (isset($_POST["e_dhcp_acl"]))   { $auth['dhcp_acl'] = $a_dhcp_acl; }
-	    if (isset($_POST["e_traf"]))       { $auth['save_traf'] = $a_traf; }
-//nagios
-	    if (isset($_POST["e_nag_enabled"])){ $auth['nagios'] = $n_enabled; }
-	    if (isset($_POST["e_nag_link"]))   { $auth['link_check'] = $n_link; }
-	    if (isset($_POST["e_nag_handler"])){ $auth['nagios_handler'] = $n_handler; }
-
-	    if (!empty($auth)) {
-        	$ret = update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
-		if (!$ret) { $all_ok = 0; }
-		}
+            if (isset($_POST["e_enabled"])) {
+                //check user state
+                if ($a_enabled) {
+                    $cur_auth = get_record_sql($db_link, "User_auth", "id=" . $val);
+                    if (!empty($cur_auth)) {
+                        $user_info = get_record_sql($db_link, "User_list", 'id=' . $cur_auth["user_id"]);
+                        if (!empty($user_info)) {
+                            $a_enabled = $user_info["enabled"];
+                        }
+                    }
+                }
+                $auth['enabled'] = $a_enabled;
+            }
+            if (isset($_POST["e_group_id"])) {
+                $auth['filter_group_id'] = $a_group;
+            }
+            if (isset($_POST["e_queue_id"])) {
+                $auth['queue_id'] = $a_queue;
+            }
+            if (isset($_POST["e_dhcp"])) {
+                $auth['dhcp'] = $a_dhcp;
+            }
+            if (isset($_POST["e_dhcp_acl"])) {
+                $auth['dhcp_acl'] = $a_dhcp_acl;
+            }
+            if (isset($_POST["e_traf"])) {
+                $auth['save_traf'] = $a_traf;
+            }
+            //nagios
+            if (isset($_POST["e_nag_enabled"])) {
+                $auth['nagios'] = $n_enabled;
+            }
+            if (isset($_POST["e_nag_link"])) {
+                $auth['link_check'] = $n_link;
+            }
+            if (isset($_POST["e_nag_handler"])) {
+                $auth['nagios_handler'] = $n_handler;
+            }
+
+            if (!empty($auth)) {
+                $ret = update_record($db_link, "User_auth", "id='" . $val . "'", $auth);
+                if (!$ret) {
+                    $all_ok = 0;
+                }
             }
             }
         }
         }
-    if ($all_ok) { print "Success!"; } else { print "Fail!"; }
     }
     }
+    if ($all_ok) {
+        print "Success!";
+    } else {
+        print "Fail!";
+    }
+}

+ 21 - 13
html/utils/auth_remove.php

@@ -1,21 +1,29 @@
 <?php
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 
 
-if (! defined("CONFIG")) die("Not defined");
+if (!defined("CONFIG")) die("Not defined");
 
 
 if (isset($_POST["RemoveAuth"]) and (isset($_POST["f_deleted"]))) {
 if (isset($_POST["RemoveAuth"]) and (isset($_POST["f_deleted"]))) {
-    if ($_POST["f_deleted"]*1) {
+    if ($_POST["f_deleted"] * 1) {
         $auth_id = $_POST["fid"];
         $auth_id = $_POST["fid"];
-	$all_ok = 1;
-	foreach ($auth_id as $key => $val) {
-    	    if ($val) {
-                run_sql($db_link, 'DELETE FROM connections WHERE auth_id='.$val);
-                run_sql($db_link, 'DELETE FROM User_auth_alias WHERE auth_id='.$val);
-                $changes=delete_record($db_link, "User_auth", "id=" . $val);
-                if (!empty($changes)) { LOG_WARNING($db_link,"Remove user ip: $changes"); } else { $all_ok =1; }
+        $all_ok = 1;
+        foreach ($auth_id as $key => $val) {
+            if ($val) {
+                run_sql($db_link, 'DELETE FROM connections WHERE auth_id=' . $val);
+                run_sql($db_link, 'DELETE FROM User_auth_alias WHERE auth_id=' . $val);
+                $changes = delete_record($db_link, "User_auth", "id=" . $val);
+                if (!empty($changes)) {
+                    LOG_WARNING($db_link, "Remove user ip: $changes");
+                } else {
+                    $all_ok = 1;
                 }
                 }
             }
             }
-	if ($all_ok) { print "Success!"; } else { print "Fail!"; }
-	}
+        }
+        if ($all_ok) {
+            print "Success!";
+        } else {
+            print "Fail!";
+        }
     }
     }
+}

+ 82 - 36
html/utils/user_apply.php

@@ -1,22 +1,38 @@
 <?php
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 
 
-if (! defined("CONFIG")) die("Not defined");
+if (!defined("CONFIG")) die("Not defined");
 
 
 if (isset($_POST["ApplyForAll"])) {
 if (isset($_POST["ApplyForAll"])) {
 
 
     $auth_id = $_POST["fid"];
     $auth_id = $_POST["fid"];
 
 
-    if (empty($_POST["a_enabled"]))  { $_POST["a_enabled"]=0; }
-    if (empty($_POST["a_dhcp"]))     { $_POST["a_dhcp"]=0; }
-    if (empty($_POST["a_queue_id"])) { $_POST["a_queue_id"]=0; }
-    if (empty($_POST["a_group_id"])) { $_POST["a_group_id"]=0; }
-    if (empty($_POST["a_traf"]))     { $_POST["a_traf"]=0; }
+    if (empty($_POST["a_enabled"])) {
+        $_POST["a_enabled"] = 0;
+    }
+    if (empty($_POST["a_dhcp"])) {
+        $_POST["a_dhcp"] = 0;
+    }
+    if (empty($_POST["a_queue_id"])) {
+        $_POST["a_queue_id"] = 0;
+    }
+    if (empty($_POST["a_group_id"])) {
+        $_POST["a_group_id"] = 0;
+    }
+    if (empty($_POST["a_traf"])) {
+        $_POST["a_traf"] = 0;
+    }
 
 
-    if (empty($_POST["a_day_q"]))    { $_POST["a_day_q"]=0; }
-    if (empty($_POST["a_month_q"]))  { $_POST["a_month_q"]=0; }
-    if (empty($_POST["a_new_ou"]))   { $_POST["a_new_ou"]=0; }
+    if (empty($_POST["a_day_q"])) {
+        $_POST["a_day_q"] = 0;
+    }
+    if (empty($_POST["a_month_q"])) {
+        $_POST["a_month_q"] = 0;
+    }
+    if (empty($_POST["a_new_ou"])) {
+        $_POST["a_new_ou"] = 0;
+    }
 
 
 
 
     $a_enabled  = $_POST["a_enabled"] * 1;
     $a_enabled  = $_POST["a_enabled"] * 1;
@@ -29,39 +45,69 @@ if (isset($_POST["ApplyForAll"])) {
     $a_month    = $_POST["a_month_q"] * 1;
     $a_month    = $_POST["a_month_q"] * 1;
     $a_ou_id    = $_POST["a_new_ou"] * 1;
     $a_ou_id    = $_POST["a_new_ou"] * 1;
 
 
-    $msg="Massive User change!";
-    LOG_WARNING($db_link,$msg);
+    $msg = "Massive User change!";
+    LOG_WARNING($db_link, $msg);
 
 
-    $all_ok=1;
+    $all_ok = 1;
     foreach ($auth_id as $key => $val) {
     foreach ($auth_id as $key => $val) {
         if ($val) {
         if ($val) {
             unset($auth);
             unset($auth);
             unset($user);
             unset($user);
-	    if (isset($_POST["e_enabled"]))    { $auth['enabled'] = $a_enabled; $user['enabled'] = $a_enabled; }
-	    if (isset($_POST["e_group_id"]))   { $auth['filter_group_id'] = $a_group; }
-	    if (isset($_POST["e_queue_id"]))   { $auth['queue_id'] = $a_queue; }
-	    if (isset($_POST["e_dhcp"]))       { $auth['dhcp'] = $a_dhcp; }
-	    if (isset($_POST["e_dhcp_acl"]))   { $auth['dhcp_acl'] = $a_dhcp_acl; }
-	    if (isset($_POST["e_traf"]))       { $auth['save_traf'] = $a_traf; }
-	    if (isset($_POST["e_day_q"]))      { $user['day_quota'] = $a_day; }
-	    if (isset($_POST["e_month_q"]))    { $user['month_quota'] = $a_month; }
-	    if (isset($_POST["e_new_ou"]))     { $user['ou_id'] = $a_ou_id; $auth['ou_id'] = $a_ou_id; }
+            if (isset($_POST["e_enabled"])) {
+                $auth['enabled'] = $a_enabled;
+                $user['enabled'] = $a_enabled;
+            }
+            if (isset($_POST["e_group_id"])) {
+                $auth['filter_group_id'] = $a_group;
+            }
+            if (isset($_POST["e_queue_id"])) {
+                $auth['queue_id'] = $a_queue;
+            }
+            if (isset($_POST["e_dhcp"])) {
+                $auth['dhcp'] = $a_dhcp;
+            }
+            if (isset($_POST["e_dhcp_acl"])) {
+                $auth['dhcp_acl'] = $a_dhcp_acl;
+            }
+            if (isset($_POST["e_traf"])) {
+                $auth['save_traf'] = $a_traf;
+            }
+            if (isset($_POST["e_day_q"])) {
+                $user['day_quota'] = $a_day;
+            }
+            if (isset($_POST["e_month_q"])) {
+                $user['month_quota'] = $a_month;
+            }
+            if (isset($_POST["e_new_ou"])) {
+                $user['ou_id'] = $a_ou_id;
+                $auth['ou_id'] = $a_ou_id;
+            }
 
 
-            $login = get_record($db_link,"User_list","id='$val'");
-            $msg.=" For all ip user id: ".$val." login: ".$login['login']." set: ";
-            $msg.= get_diff_rec($db_link,"User_list","id='$val'", $user, 1);
+            $login = get_record($db_link, "User_list", "id='$val'");
+            $msg .= " For all ip user id: " . $val . " login: " . $login['login'] . " set: ";
+            $msg .= get_diff_rec($db_link, "User_list", "id='$val'", $user, 1);
             $ret = update_record($db_link, "User_list", "id='" . $val . "'", $user);
             $ret = update_record($db_link, "User_list", "id='" . $val . "'", $user);
-	    if (!$ret) { $all_ok = 0; }
+            if (!$ret) {
+                $all_ok = 0;
+            }
 
 
-	    $auth_list = get_records_sql($db_link,"SELECT id FROM User_auth WHERE deleted=0 AND user_id=".$val);
-	    if (!empty($auth)) {
-		foreach ($auth_list as $row) {
-		    if (empty($row)) { continue; }
-        	    $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $auth);
-		    if (!$ret) { $all_ok = 0; }
-		    }
-		}
+            $auth_list = get_records_sql($db_link, "SELECT id FROM User_auth WHERE deleted=0 AND user_id=" . $val);
+            if (!empty($auth)) {
+                foreach ($auth_list as $row) {
+                    if (empty($row)) {
+                        continue;
+                    }
+                    $ret = update_record($db_link, "User_auth", "id='" . $row["id"] . "'", $auth);
+                    if (!$ret) {
+                        $all_ok = 0;
+                    }
+                }
             }
             }
         }
         }
-    if ($all_ok) { print "Success!"; } else { print "Fail!"; }
     }
     }
+    if ($all_ok) {
+        print "Success!";
+    } else {
+        print "Fail!";
+    }
+}

+ 30 - 26
html/utils/user_remove.php

@@ -1,31 +1,35 @@
 <?php
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/auth.php");
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/languages/" . HTML_LANG . ".php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/auth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/languages/" . HTML_LANG . ".php");
 
 
-if (! defined("CONFIG")) die("Not defined");
+if (!defined("CONFIG")) die("Not defined");
 
 
 if (isset($_POST["RemoveUser"]) and (isset($_POST["f_deleted"]))) {
 if (isset($_POST["RemoveUser"]) and (isset($_POST["f_deleted"]))) {
-    if ($_POST["f_deleted"]*1) {
-        $fid = $_POST["fid"];
-	$all_ok = 1;
-        foreach ($fid as $key => $val) {
-	    if ($val) {
-    	        $login = get_record($db_link,"User_list","id='$val'");
-        	$device= get_record($db_link,"devices","user_id='$val'");
-                if (!empty($device)) {
-            	    LOG_INFO($db_link, "Delete device for user id: $val");
-            	    unbind_ports($db_link, $device['id']);
-                    run_sql($db_link, "DELETE FROM connections WHERE device_id=".$device['id']);
-            	    run_sql($db_link, "DELETE FROM device_l3_interfaces WHERE device_id=".$device['id']);
-                    run_sql($db_link, "DELETE FROM device_ports WHERE device_id=".$device['id']);
-            	    delete_record($db_link, "devices", "id=".$device['id']);
-                    }
-        	run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=$val");
-        	run_sql($db_link,"UPDATE User_auth SET deleted=1 WHERE user_id=$val");
-        	delete_record($db_link, "User_list", "id=$val");
-        	LOG_WARNING($db_link,"Deleted user id: $val login: ".$login['login']."\r\n");
-            }
-        }
-	if ($all_ok) { print "Success!"; } else { print "Fail!"; }
+	if ($_POST["f_deleted"] * 1) {
+		$fid = $_POST["fid"];
+		$all_ok = 1;
+		foreach ($fid as $key => $val) {
+			if ($val) {
+				$login = get_record($db_link, "User_list", "id='$val'");
+				$device = get_record($db_link, "devices", "user_id='$val'");
+				if (!empty($device)) {
+					LOG_INFO($db_link, "Delete device for user id: $val");
+					unbind_ports($db_link, $device['id']);
+					run_sql($db_link, "DELETE FROM connections WHERE device_id=" . $device['id']);
+					run_sql($db_link, "DELETE FROM device_l3_interfaces WHERE device_id=" . $device['id']);
+					run_sql($db_link, "DELETE FROM device_ports WHERE device_id=" . $device['id']);
+					delete_record($db_link, "devices", "id=" . $device['id']);
+				}
+				run_sql($db_link, "DELETE FROM auth_rules WHERE user_id=$val");
+				run_sql($db_link, "UPDATE User_auth SET deleted=1 WHERE user_id=$val");
+				delete_record($db_link, "User_list", "id=$val");
+				LOG_WARNING($db_link, "Deleted user id: $val login: " . $login['login'] . "\r\n");
+			}
+		}
+		if ($all_ok) {
+			print "Success!";
+		} else {
+			print "Fail!";
+		}
 	}
 	}
-    }
+}

+ 5 - 6
scripts/sync_mikrotik.pl

@@ -368,7 +368,6 @@ foreach my $row (@filterlist_ref) {
         $filters{$row->{id}}->{dst}=$row->{dst};
         $filters{$row->{id}}->{dst}=$row->{dst};
         $filters{$row->{id}}->{dstport}=$row->{dstport};
         $filters{$row->{id}}->{dstport}=$row->{dstport};
         $filters{$row->{id}}->{srcport}=$row->{srcport};
         $filters{$row->{id}}->{srcport}=$row->{srcport};
-        $filters{$row->{id}}->{action}=$row->{action};
         #set false for dns dst flag
         #set false for dns dst flag
         $filters{$row->{id}}->{dns_dst}=0;
         $filters{$row->{id}}->{dns_dst}=0;
         } else {
         } else {
@@ -386,7 +385,6 @@ foreach my $row (@filterlist_ref) {
                 $filters{$dyn_filters_index}->{dst}=$resolved_ip;
                 $filters{$dyn_filters_index}->{dst}=$resolved_ip;
                 $filters{$dyn_filters_index}->{dstport}=$row->{dstport};
                 $filters{$dyn_filters_index}->{dstport}=$row->{dstport};
                 $filters{$dyn_filters_index}->{srcport}=$row->{srcport};
                 $filters{$dyn_filters_index}->{srcport}=$row->{srcport};
-                $filters{$dyn_filters_index}->{action}=$row->{action};
                 $filters{$dyn_filters_index}->{dns_dst}=0;
                 $filters{$dyn_filters_index}->{dns_dst}=0;
                 #save new filter dns id for original filter id
                 #save new filter dns id for original filter id
                 push(@{$dyn_filters{$row->{id}}},$dyn_filters_index);
                 push(@{$dyn_filters{$row->{id}}},$dyn_filters_index);
@@ -402,14 +400,15 @@ log_debug("DNS-filters status:". Dumper(\%dyn_filters));
 do_sql($dbh,"DELETE FROM Group_filters WHERE group_id NOT IN (SELECT id FROM Group_list)");
 do_sql($dbh,"DELETE FROM Group_filters WHERE group_id NOT IN (SELECT id FROM Group_list)");
 do_sql($dbh,"DELETE FROM Group_filters WHERE filter_id NOT IN (SELECT id FROM Filter_list)");
 do_sql($dbh,"DELETE FROM Group_filters WHERE filter_id NOT IN (SELECT id FROM Filter_list)");
 
 
-my @grouplist_ref = get_records_sql($dbh,"SELECT group_id,filter_id,Group_filters.order FROM Group_filters order by Group_filters.group_id,Group_filters.order");
+my @grouplist_ref = get_records_sql($dbh,"SELECT `group_id`,`filter_id`,`order`,`action` FROM Group_filters ORDER BY Group_filters.group_id,Group_filters.order");
 
 
 my %group_filters;
 my %group_filters;
 my $index=0;
 my $index=0;
 foreach my $row (@grouplist_ref) {
 foreach my $row (@grouplist_ref) {
     #if dst dns filter not found
     #if dst dns filter not found
     if (!$filters{$row->{filter_id}}->{dns_dst}) {
     if (!$filters{$row->{filter_id}}->{dns_dst}) {
-        $group_filters{'group_'.$row->{group_id}}->{$index}=$row->{filter_id};
+        $group_filters{'group_'.$row->{group_id}}->{$index}->{filter_id}=$row->{filter_id};
+        $group_filters{'group_'.$row->{group_id}}->{$index}->{action}=$row->{action};
         $index++;
         $index++;
     } else {
     } else {
         #if found dns dst filters - add
         #if found dns dst filters - add
@@ -508,14 +507,14 @@ foreach my $group_name (keys %group_filters) {
 next if (!$group_name);
 next if (!$group_name);
 next if (!exists($group_filters{$group_name}));
 next if (!exists($group_filters{$group_name}));
 foreach my $filter_index (sort keys %{$group_filters{$group_name}}) {
 foreach my $filter_index (sort keys %{$group_filters{$group_name}}) {
-    my $filter_id=$group_filters{$group_name}->{$filter_index};
+    my $filter_id=$group_filters{$group_name}->{$filter_index}->{filter_id};
     next if (!$filters{$filter_id});
     next if (!$filters{$filter_id});
     next if ($filters{$filter_id}->{dns_dst});
     next if ($filters{$filter_id}->{dns_dst});
 
 
     my $src_rule='chain='.$group_name;
     my $src_rule='chain='.$group_name;
     my $dst_rule='chain='.$group_name;
     my $dst_rule='chain='.$group_name;
 
 
-    if ($filters{$filter_id}->{action}) {
+    if ($group_filters{$group_name}->{$filter_index}->{action}) {
 	$src_rule=$src_rule." action=accept";
 	$src_rule=$src_rule." action=accept";
 	$dst_rule=$dst_rule." action=accept";
 	$dst_rule=$dst_rule." action=accept";
 	} else {
 	} else {

+ 3 - 0
updates/2-4-11/filter-uprades.sql

@@ -0,0 +1,3 @@
+ALTER TABLE `Group_filters` ADD `action` BOOLEAN NOT NULL DEFAULT FALSE AFTER `order`;
+UPDATE `Group_filters` as G set action = (SELECT action FROM Filter_list WHERE G.filter_id = id);
+ALTER TABLE `Filter_list` DROP `action`;

+ 1 - 0
version

@@ -0,0 +1 @@
+2.4.11