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

- cosmetic changes in edit device page
- fixed log records for user ip
- garbage old debug records

Dmitriev Roman 4 лет назад
Родитель
Сommit
48e19693b6

+ 37 - 20
html/admin/devices/editdevice.php

@@ -109,10 +109,8 @@ print "</tr>\n";
 print "<tr><td>Расположен</td><td colspan=2>Комментарий</td><td><td>";
 print "</tr><tr>";
 print "<td class=\"data\">"; print_building_select($db_link, 'f_building_id', $device['building_id']); print "</td>\n";
-print "<td class=\"data\" colspan=2><input type=\"text\" size=50 name='f_comment' value='".$device['comment']."'></td>\n";
-print "<td></td><td></td>";
+print "<td class=\"data\" colspan=3><input type=\"text\" size=50 name='f_comment' value='".$device['comment']."'></td>\n";
 print "</tr>";
-
 if ($device['device_type']==2) {
     print "<tr><td>Управление доступом</td><td>DHCP-Server</td><td>Шейперы</td><td>Только connected юзеры</td></tr>";
     print "<tr>";
@@ -124,14 +122,39 @@ if ($device['device_type']==2) {
     print "<tr><td colspan=4>"; print_url("Список интерфейсов","/admin/devices/edit_l3int.php?id=$id"); print "</td></tr>";
     print "<tr><td colspan=4 class=\"data\">"; print get_l3_interfaces($db_link,$device['id']); print "</td></tr>";
     }
-print "</tr><td>Snmp Version</td><td><p title='Некоторые устройства отдают mac-таблицу по индексу порта в snmp, другие - по номеру.'>Mac by snmp</p></td>";
-print "<td>Discovery</td><td>Nagios</td></tr>";
-print "<tr><td class=\"data\">"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
-print "<td class=\"data\">"; print_qa_select('f_fdb_snmp', $device['fdb_snmp_index']); print "</td>\n";
-print "<td class=\"data\">"; print_qa_select('f_discovery', $device['discovery']); print "</td>\n";
-print "<td class=\"data\">"; print_qa_select('f_nagios', $device['nagios']); print "</td>\n";
-print "</tr>";
-if ($device['snmp_version'] ==3) {
+if ($device['device_type']<=2) {
+    print "<tr><td>Snmp Version</td><td><p title='Некоторые устройства отдают mac-таблицу по индексу порта в snmp, другие - по номеру.'>Mac by snmp</p></td>";
+    print "<td>Discovery</td><td>Nagios</td></tr>";
+    print "<tr><td class=\"data\">"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
+    print "<td class=\"data\">"; print_qa_select('f_fdb_snmp', $device['fdb_snmp_index']); print "</td>\n";
+    print "<td class=\"data\">"; print_qa_select('f_discovery', $device['discovery']); print "</td>\n";
+    print "<td class=\"data\">"; print_qa_select('f_nagios', $device['nagios']); print "</td>\n";
+    print "</tr>";
+    if ($device['snmp_version'] ==3) {
+        print "<tr><td>Snmpv3 RO user</td><td>Snmpv3 RW user</td><td>Snmpv3 RO password</td><td>Snmpv3 RW password</td><td></td>";
+	print "</tr><tr>";
+        print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_ro' value=".$device['snmp3_user_ro']."></td>\n";
+	print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_rw' value=".$device['snmp3_user_rw']."></td>\n";
+        print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_ro_password' value=".$device['snmp3_user_ro_password']."></td>\n";
+	print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_rw_password' value=".$device['snmp3_user_rw_password']."></td>\n";
+        print "</tr>\n";
+	}
+    print "<tr><td>Snmp RO Community</td><td>Snmp RW Community</td><td></td><td></td></tr>";
+    print "<tr>\n";
+    print "<td class=\"data\"><input type=\"text\" name='f_community' value=".$device['community']."></td>\n";
+    print "<td class=\"data\"><input type=\"text\" name='f_rw_community' value=".$device['rw_community']."></td>\n";
+    print "<td><button name=\"port_walk\" onclick=\"window.open('mactable.php?id=" . $id . "')\">Mac table</button>";
+    print "<button name=\"port_walk\" onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">Port Walk</button></td>";
+    print "<td></td>";
+    print "</tr>";
+    }
+if ($device['device_type']>2) {
+    print "<tr><td>Snmp Version</td><td>Snmp RO Community</td><td>Snmp RW Community</td><td></td></tr>";
+    print "<tr><td class=\"data\">"; print_snmp_select('f_snmp_version', $device['snmp_version']); print "</td>\n";
+    print "<td class=\"data\"><input type=\"text\" name='f_community' value=".$device['community']."></td>\n";
+    print "<td class=\"data\"><input type=\"text\" name='f_rw_community' value=".$device['rw_community']."></td>\n";
+    print "<dtd></td></tr>";
+    if ($device['snmp_version'] ==3) {
         print "<tr><td>Snmpv3 RO user</td><td>Snmpv3 RW user</td><td>Snmpv3 RO password</td><td>Snmpv3 RW password</td><td></td>";
 	print "</tr><tr>";
         print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_ro' value=".$device['snmp3_user_ro']."></td>\n";
@@ -140,15 +163,9 @@ if ($device['snmp_version'] ==3) {
 	print "<td class=\"data\"><input type=\"text\" name='f_snmp3_user_rw_password' value=".$device['snmp3_user_rw_password']."></td>\n";
         print "<td></td></tr>\n";
 	}
-print "<tr><td>Snmp RO Community</td><td>Snmp RW Community</td><td></td><td></td></tr>";
-print "<tr>\n";
-print "<td class=\"data\"><input type=\"text\" name='f_community' value=".$device['community']."></td>\n";
-print "<td class=\"data\"><input type=\"text\" name='f_rw_community' value=".$device['rw_community']."></td>\n";
-print "<td><button name=\"port_walk\" onclick=\"window.open('mactable.php?id=" . $id . "')\">Mac table</button></td>";
-print "<td><button name=\"port_walk\" onclick=\"window.open('snmpwalk.php?id=" . $id . "')\">Port Walk</button></td>";
-print "</tr>";
-print "<tr><td colspan=4 align=right><input type=\"submit\" name=\"editdevice\" value=\"Сохранить\"></td></tr>";
-print "</table>\n";
+    }
+    print "<tr><td colspan=4 align=right><input type=\"submit\" name=\"editdevice\" value=\"Сохранить\"></td></tr>";
+    print "</table>\n";
 ?>
 </form>
 <?php require_once ($_SERVER['DOCUMENT_ROOT']."/inc/footer.small.php"); ?>

+ 5 - 5
html/admin/users/add_dhcp.php

@@ -33,24 +33,24 @@ if (!empty($_GET["ip"]) and !empty($_GET["mac"])) {
 	$aid = NULL;
 	if (!empty($auth)) {
 	    $aid = $auth['id'];
-	    LOG_VERBOSE($db_link,"Found auth for dhcp id: $aid with ip: $ip mac: $mac");
+	    LOG_VERBOSE($db_link,"Found auth for dhcp id: $aid with ip: $ip mac: $mac",$aid);
 	    }
 
 	if ($action ==='add' and empty($auth)) {
-	    LOG_VERBOSE($db_link,"Add user by dhcp request ip: $ip mac: $mac");
 	    $aid = resurrection_auth($db_link, $ip, $mac, $action, $dhcp_hostname);
+	    LOG_VERBOSE($db_link,"Add user by dhcp request ip: $ip mac: $mac",$aid);
             }
 
 	if ($action ==='del' and !empty($auth)) {
             $last_time = strtotime($auth['dhcp_time']);
-            LOG_VERBOSE($db_link,"Delete action found for ip $ip (id: $aid, userid: ".$auth['user_id']."). Last timestamp = ".strftime('%Y-%m-%d %H-%M-%S',$last_time)." Now = ".strftime('%Y-%m-%d %H-%M-%S',time()));
+            LOG_VERBOSE($db_link,"Delete action found for ip $ip (id: $aid, userid: ".$auth['user_id']."). Last timestamp = ".strftime('%Y-%m-%d %H-%M-%S',$last_time)." Now = ".strftime('%Y-%m-%d %H-%M-%S',time()),$aid);
 	    if ((time() - $last_time>60) and ($auth['ou_id'] == $default_user_ou_id or $auth['ou_id'] == $default_hotspot_ou_id)) {
-                LOG_VERBOSE($db_link,"Remove dynamic user ip (id: $aid) by dhcp request for ip: $ip mac: $mac");
+                LOG_VERBOSE($db_link,"Remove dynamic user ip (id: $aid) by dhcp request for ip: $ip mac: $mac",$aid);
 	        delete_record($db_link,"User_auth","id=".$aid);
 	        $u_count=get_count_records($db_link,'User_auth','deleted=0 and user_id='.$auth['user_id']);
 	        if ($u_count == 0) {
 	    	    delete_record($db_link,"User_list","id=".$auth['user_id']);
-                    LOG_VERBOSE($db_link,"Remove dynamic user id: ".$auth['user_id']." by dhcp request");
+                    LOG_VERBOSE($db_link,"Remove dynamic user id: ".$auth['user_id']." by dhcp request",$aid);
 	    	    }
 	        }
 	    }

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

@@ -81,7 +81,7 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
                 $new['filter_group_id'] = $_POST["f_group_id"] * 1;
             }
         $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
-        if (!empty($changes)) { LOG_WARNING($db_link,"Изменен адрес доступа! Список изменений: $changes"); }
+        if (!empty($changes)) { LOG_WARNING($db_link,"Изменен адрес доступа! Список изменений: $changes",$id); }
         if (is_auth_bind_changed($db_link,$id,$ip,$mac)) {
             $new_id = copy_auth($db_link,$id,$new);
             header("Location: /admin/users/editauth.php?id=".$new_id,TRUE, 302);
@@ -100,7 +100,7 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
 if (isset($_POST["moveauth"])) {
     $new_parent_id = $_POST["f_new_parent"]*1;
     apply_auth_rule($db_link,$id,$new_parent_id);
-    LOG_WARNING($db_link,"Адрес доступа перемещён к другому пользователю! Применено: $changes");
+    LOG_WARNING($db_link,"Адрес доступа перемещён к другому пользователю! Применено: $changes",$id);
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
     }
@@ -175,7 +175,7 @@ if (isset($_POST["recovery"])) {
                 $new['filter_group_id'] = $_POST["f_group_id"] * 1;
             }
         $changes = get_diff_rec($db_link,"User_auth","id='$id'", $new, 0);
-        if (!empty($changes)) { LOG_WARNING($db_link,"Восстановлен адрес доступа! Применено: $changes"); }
+        if (!empty($changes)) { LOG_WARNING($db_link,"Восстановлен адрес доступа! Применено: $changes",$id); }
         update_record($db_link, "User_auth", "id='$id'", $new);
 	apply_auth_rule($db_link,$id,$new['user_id']);
 	} else {

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

@@ -125,7 +125,7 @@ if (isset($_POST["addauth"])) {
                 $new['dhcp']=$f_dhcp;
                 update_record($db_link,"User_auth","id=".$fid,$new);
                 apply_auth_rule($db_link,$fid,$id);
-                LOG_WARNING($db_link,"Создан новый адрес доступа: ip => $fip, mac => $fmac");
+                LOG_WARNING($db_link,"Создан новый адрес доступа: ip => $fip, mac => $fmac",$fid);
                 header("Location: /admin/users/editauth.php?id=".$fid);
                 exit;
                 }
@@ -148,7 +148,7 @@ if (isset($_POST["removeauth"])) {
             run_sql($db_link, 'DELETE FROM User_auth_alias WHERE auth_id='.$val);
             $auth["deleted"] = 1;
             $changes = get_diff_rec($db_link,"User_auth","id='$val'", '', 0);
-            if (!empty($changes)) { LOG_WARNING($db_link,"Удалён адрес доступа: \r\n $changes"); }
+            if (!empty($changes)) { LOG_WARNING($db_link,"Удалён адрес доступа: \r\n $changes",$val); }
             update_record($db_link, "User_auth", "id=" . $val, $auth);
         }
     }

+ 12 - 12
html/inc/common.php

@@ -1592,40 +1592,40 @@ function isRO($db)
     return $f_ro;
 }
 
-function LOG_INFO($db,$msg) {
+function LOG_INFO($db,$msg,$auth_id = 0) {
 global $L_INFO;
 global $log_level;
 if ($log_level < $L_INFO) { return; }
-write_log($db,$msg,$L_INFO);
+write_log($db,$msg,$L_INFO,$auth_id);
 }
 
-function LOG_ERROR($db,$msg) {
+function LOG_ERROR($db,$msg,$auth_id = 0) {
 global $L_ERROR;
 global $log_level;
 if ($log_level < $L_ERROR) { return; }
 email($L_ERROR,$msg);
-write_log($db,$msg,$L_ERROR);
+write_log($db,$msg,$L_ERROR,$auth_id);
 }
 
-function LOG_VERBOSE($db,$msg) {
+function LOG_VERBOSE($db,$msg,$auth_id=0) {
 global $L_VERBOSE;
 global $log_level;
 if ($log_level < $L_VERBOSE) { return; }
-write_log($db,$msg,$L_VERBOSE);
+write_log($db,$msg,$L_VERBOSE,$auth_id);
 }
 
-function LOG_WARNING($db,$msg) {
+function LOG_WARNING($db,$msg,$auth_id=0) {
 global $L_WARNING;
 global $log_level;
 if ($log_level < $L_WARNING) { return; }
 email($L_WARNING,$msg);
-write_log($db,$msg,$L_WARNING);
+write_log($db,$msg,$L_WARNING,$auth_id);
 }
 
-function LOG_DEBUG($db,$msg) {
+function LOG_DEBUG($db,$msg,$auth_id=0) {
 global $debug;
 global $L_DEBUG;
-if (isset($debug) and $debug) { write_log($db,$msg,$L_DEBUG); }
+if (isset($debug) and $debug) { write_log($db,$msg,$L_DEBUG,$auth_id); }
 }
 
 function email ($level,$msg) {
@@ -1656,7 +1656,7 @@ $send = SimpleMail::make()
     ->send();
 }
 
-function write_log($db, $msg, $level)
+function write_log($db, $msg, $level, $auth_id = 0)
 {
     $work_user = 'http';
     if (isset($_SESSION['login'])) {
@@ -1668,7 +1668,7 @@ function write_log($db, $msg, $level)
     global $L_INFO;
     if (!isset($level)) { $level = $L_INFO; }
     $msg = str_replace("'", '', $msg);
-    $sSQL = "insert into syslog(customer,message,level) values('$work_user','$msg',$level)";
+    $sSQL = "insert into syslog(customer,message,level,auth_id) values('$work_user','$msg',$level,$auth_id)";
     mysqli_query($db, $sSQL);
 }
 

+ 6 - 3
scripts/Rstat/mysql.pm

@@ -218,7 +218,8 @@ if ($log_level >= $L_ERROR) {
 sub db_log_info {
 my $db = shift;
 my $msg = shift;
-if ($log_level >= $L_INFO) { write_db_log($db,$msg,$L_INFO); }
+my $id = shift;
+if ($log_level >= $L_INFO) { write_db_log($db,$msg,$L_INFO,$id); }
 }
 
 #---------------------------------------------------------------------------------------------------------------
@@ -226,7 +227,8 @@ if ($log_level >= $L_INFO) { write_db_log($db,$msg,$L_INFO); }
 sub db_log_verbose {
 my $db = shift;
 my $msg = shift;
-if ($log_level >= $L_VERBOSE) { write_db_log($db,$msg,$L_VERBOSE); }
+my $id = shift;
+if ($log_level >= $L_VERBOSE) { write_db_log($db,$msg,$L_VERBOSE,$id); }
 }
 
 #---------------------------------------------------------------------------------------------------------------
@@ -234,9 +236,10 @@ if ($log_level >= $L_VERBOSE) { write_db_log($db,$msg,$L_VERBOSE); }
 sub db_log_warning {
 my $db = shift;
 my $msg = shift;
+my $id = shift;
 if ($log_level >= $L_WARNING) {
     sendEmail("WARN! ".substr($msg,0,30),$msg,1);
-    write_db_log($db,$msg,$L_WARNING);
+    write_db_log($db,$msg,$L_WARNING,$id);
     }
 }
 

+ 6 - 7
scripts/dhcp-log.pl

@@ -106,7 +106,7 @@ if (!$pid) {
         while (my $logline = <DHCP_SOCKET>) {
             next unless defined $logline;
             chomp($logline);
-            log_info("GET CLIENT REQUEST: $logline");
+            log_verbose("GET CLIENT REQUEST: $logline");
             my ($type,$mac,$ip,$hostname,$timestamp,$tags,$sup_hostname,$old_hostname) = split (/\;/, $logline);
             next if (!$type);
             next if ($type!~/(old|add|del)/i);
@@ -158,14 +158,13 @@ if (!$pid) {
             log_debug("UTF8 HOSTNAME: ".$dhcp_record->{hostname_utf8});
             log_debug("END GET");
 
-
             my $auth_record = get_record_sql($hdb,'SELECT * FROM User_auth WHERE ip="'.$dhcp_record->{ip}.'" and mac="'.$mac.'" and deleted=0 ORDER BY last_found DESC');
 	    if (!$auth_record and $type eq 'old' ) { $type='add'; }
 
             if ($type eq 'add') {
                 my $res_id = resurrection_auth($hdb,$dhcp_record->{ip},$mac,$type,$dhcp_record->{hostname_utf8});
                 $auth_record = get_record_sql($hdb,'SELECT * FROM User_auth WHERE id='.$res_id);
-                log_info("Check for new auth. Found id: $res_id");
+                db_log_info($hdb,"Check for new auth. Found id: $res_id",$res_id);
                 } else { $auth_record = get_record_sql($hdb,'SELECT * FROM User_auth WHERE ip="'.$dhcp_record->{ip}.'" and mac="'.$mac.'" and deleted=0 ORDER BY last_found DESC'); }
 
             my $auth_id = $auth_record->{id};
@@ -177,7 +176,7 @@ if (!$pid) {
                 my $auth_rec;
                 $auth_rec->{dhcp_hostname} = $dhcp_record->{hostname_utf8};
                 $auth_rec->{dhcp_time}=$dhcp_event_time;
-                log_info("Add lease by dhcp event for dynamic clients id:$auth_id ip: $dhcp_record->{ip}");
+                db_log_verbose($hdb,"Add lease by dhcp event for dynamic clients id:$auth_id ip: $dhcp_record->{ip}",$auth_id);
                 update_record($hdb,'User_auth',$auth_rec,"id=$auth_id");
                 }
 
@@ -189,7 +188,7 @@ if (!$pid) {
                     my $auth_rec;
                     $auth_rec->{dhcp_action}=$type;
                     $auth_rec->{dhcp_time}=$dhcp_event_time;
-                    log_info("Update lease by dhcp event for dynamic clients id:$auth_id ip: $dhcp_record->{ip}");
+                    db_log_verbose($hdb,"Update lease by dhcp event for dynamic clients id:$auth_id ip: $dhcp_record->{ip}",$auth_id);
                     update_record($hdb,'User_auth',$auth_rec,"id=$auth_id");
                 }
 
@@ -197,7 +196,7 @@ if (!$pid) {
                 if ($auth_record->{dhcp_time} =~ /([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/) {
                     my $d_time = mktime($6,$5,$4,$3,$2-1,$1-1900);
                     if (time()-$d_time>60 and ($auth_ou_id == $default_user_ou_id or $auth_ou_id==$default_hotspot_ou_id)) {
-                        log_info("Remove user ip record by dhcp release event for dynamic clients id:$auth_id ip: $dhcp_record->{ip}");
+                        db_log_info($hdb,"Remove user ip record by dhcp release event for dynamic clients id:$auth_id ip: $dhcp_record->{ip}",$auth_id);
                         my $auth_rec;
                         $auth_rec->{deleted}="1";
                         $auth_rec->{dhcp_action}=$type;
@@ -206,7 +205,7 @@ if (!$pid) {
                         my $u_count=get_count_records($hdb,'User_auth','deleted=0 and user_id='.$auth_record->{'user_id'});
 		        if (!$u_count) {
 				delete_record($hdb,"User_list","id=".$auth_record->{'user_id'});
-	                        log_info("Remove dynamic user id: $auth_record->{'user_id'} by dhcp request");
+	                        db_log_info($hdb,"Remove dynamic user id: $auth_record->{'user_id'} by dhcp request",$auth_id);
 	                        }
                         }
                     }

+ 3 - 3
scripts/fetch_new_arp.pl

@@ -331,7 +331,7 @@ foreach my $mac (keys %mac_address_table) {
             	    $auth_id=$auth_table{oper_table}{$simple_mac};
             	    } else {
                     $auth_id=$auth_table{full_table}{$simple_mac};
-                    db_log_debug($dbh,"Mac not found in oper ARP-table. Use old values auth_id: $auth_id [$simple_mac] at device $dev_name [$port]");
+                    db_log_debug($dbh,"Mac not found in oper ARP-table. Use old values auth_id: $auth_id [$simple_mac] at device $dev_name [$port]",$auth_id);
                     }
 
                 if (exists $connections{$auth_id}) {
@@ -347,7 +347,7 @@ foreach my $mac (keys %mac_address_table) {
                     $connections{$auth_id}{port}=$port_id;
                     $mac_history{$simple_mac}{changed}=1;
                     $mac_history{$simple_mac}{auth_id}=$auth_id;
-                    db_log_info($dbh,"Found auth_id: $auth_id [$mac_splitted] at device $dev_name [$port]. Update connection");
+                    db_log_info($dbh,"Found auth_id: $auth_id [$mac_splitted] at device $dev_name [$port]. Update connection",$auth_id);
                     my $auth_rec;
                     $auth_rec->{last_found}=$now_str;
                     update_record($dbh,'User_auth',$auth_rec,"id=".$auth_id);
@@ -359,7 +359,7 @@ foreach my $mac (keys %mac_address_table) {
                     $mac_history{$simple_mac}{changed}=1;
                     $mac_history{$simple_mac}{auth_id}=$auth_id;
                     $connections{$auth_id}{port}=$port_id;
-                    db_log_info($dbh,"Found auth_id: $auth_id [$mac_splitted] at device $dev_name [$port]. Create connection.");
+                    db_log_info($dbh,"Found auth_id: $auth_id [$mac_splitted] at device $dev_name [$port]. Create connection.",$auth_id);
                     my $auth_rec;
                     $auth_rec->{last_found}=$now_str;
                     update_record($dbh,'User_auth',$auth_rec,"id=".$auth_id);

+ 9 - 1
scripts/garbage.pl

@@ -177,7 +177,15 @@ $clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
 db_log_verbose($dbh,"Clean worklog older that ".$clean_str);
 do_sql($dbh,"DELETE FROM syslog WHERE `timestamp` < $clean_str" );
 
-##### syslog  ######
+#clean debug logs older than 2 days
+$day_dur = DateTime::Duration->new( days => 2 );
+$clean_date = $now - $day_dur;
+$clean_str = $dbh->quote($clean_date->ymd("-")." 00:00:00");
+
+db_log_verbose($dbh,"Clean debug worklog older that ".$clean_str);
+do_sql($dbh,"DELETE FROM syslog WHERE level>3 AND `timestamp` < $clean_str" );
+
+##### remote syslog  ######
 
 $day_dur = DateTime::Duration->new( days => $history_syslog_day );
 $clean_date = $now - $day_dur;