Преглед на файлове

changed log levels for some events

Roman Dmitriev преди 1 година
родител
ревизия
eee5854e29

+ 1 - 1
html/admin/customers/building.php

@@ -6,7 +6,7 @@ if (isset($_POST["remove"])) {
     $fid = $_POST["f_id"];
     foreach ($fid as $key => $val) {
         if (isset($val) and $val > 1) {
-            LOG_INFO($db_link,'Remove building id: '.$val);
+            LOG_INFO($db_link,'Remove building id: '. $val .' '. dump_record($db_link,'building','id='.$val));
             delete_record($db_link, "building", "id=" . $val);
         }
     }

+ 8 - 8
html/admin/customers/control.php

@@ -21,7 +21,7 @@ if (isset($_POST["set_workmode_off"])) {
 if (isset($_POST["recheck_ip"]) and is_option($db_link, 37)) {
     $run_cmd = get_option($db_link, 37);
     $result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." >/dev/null 2>/dev/null &");
-    LOG_INFO($db_link, "Run command: $run_cmd ");
+    LOG_VERBOSE($db_link, "Run command: $run_cmd ");
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
@@ -29,7 +29,7 @@ if (isset($_POST["recheck_ip"]) and is_option($db_link, 37)) {
 if (isset($_POST["refresh_dhcp"]) and is_option($db_link, 38)) {
     $run_cmd = get_option($db_link, 38);
     $result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." >/dev/null 2>/dev/null &");
-    LOG_INFO($db_link, "Run command: $run_cmd ");
+    LOG_VERBOSE($db_link, "Run command: $run_cmd ");
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
@@ -37,7 +37,7 @@ if (isset($_POST["refresh_dhcp"]) and is_option($db_link, 38)) {
 if (isset($_POST["refresh_nagios"]) and is_option($db_link, 40)) {
     $run_cmd = get_option($db_link, 40);
     $result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." >/dev/null 2>/dev/null &");
-    LOG_INFO($db_link, "Run command: $run_cmd ");
+    LOG_VERBOSE($db_link, "Run command: $run_cmd ");
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
@@ -52,7 +52,7 @@ if (isset($_POST["up_nagios"])) {
 if (isset($_POST["refresh_dns"]) and is_option($db_link, 39)) {
     $run_cmd = get_option($db_link, 39);
     $result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." >/dev/null 2>/dev/null &");
-    LOG_INFO($db_link, "Run command: $run_cmd ");
+    LOG_VERBOSE($db_link, "Run command: $run_cmd ");
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
@@ -60,7 +60,7 @@ if (isset($_POST["refresh_dns"]) and is_option($db_link, 39)) {
 if (isset($_POST["discovery"]) and is_option($db_link, 41)) {
     $run_cmd = get_option($db_link, 41);
     $result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." >/dev/null 2>/dev/null &");
-    LOG_INFO($db_link, "Run command: $run_cmd ");
+    LOG_VERBOSE($db_link, "Run command: $run_cmd ");
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
@@ -68,7 +68,7 @@ if (isset($_POST["discovery"]) and is_option($db_link, 41)) {
 if (isset($_POST["discovery2"]) and is_option($db_link, 41)) {
     $run_cmd = get_option($db_link, 41);
     $result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." force >/dev/null 2>/dev/null &");
-    LOG_INFO($db_link, "Run command: $run_cmd force");
+    LOG_VERBOSE($db_link, "Run command: $run_cmd force");
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;
 }
@@ -91,7 +91,7 @@ if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];
     foreach ($s_id as $key => $val) {
         if (isset($val)) {
-            LOG_INFO($db_link, "Remove subnet id: $val");
+            LOG_INFO($db_link, "Remove subnet id: $val ". dump_record($db_link,'subnets','id='.$val));
             delete_record($db_link, "subnets", "id=" . $val);
         }
     }
@@ -100,7 +100,7 @@ if (isset($_POST["s_remove"])) {
 }
 
 if (isset($_POST["clean_cache"])) {
-    LOG_INFO($db_link, "Clean dns cache");
+    LOG_VERBOSE($db_link, "Clean dns cache");
     run_sql($db_link,"DELETE FROM dns_cache");
     header("Location: " . $_SERVER["REQUEST_URI"]);
     exit;

+ 1 - 1
html/admin/customers/index-subnets.php

@@ -8,7 +8,7 @@ if (isset($_POST["s_remove"])) {
         $s_id = $_POST["s_id"];
         foreach ($s_id as $key => $net_id) {
             if (isset($net_id)) {
-                LOG_INFO($db_link, "Remove subnet id: $net_id");
+                LOG_INFO($db_link, "Remove subnet id: $net_id ". dump_record($db_link,'subnets','id='.$val));
                 delete_record($db_link, "subnets", "id=" . $net_id);
             }
         }

+ 2 - 2
html/admin/customers/index.php

@@ -10,7 +10,7 @@ if (isset($_POST["create"])) {
 	$customer = get_record_sql($db_link,"Select * from Customers WHERE LCase(Login)=LCase('$login')");
         if (!empty($customer)) {
             $msg_error = "Login $login already exists!";
-            LOG_INFO($db_link, $msg_error);
+            LOG_ERROR($db_link, $msg_error);
             unset($_POST);
         } else {
             $new['Login'] = $login;
@@ -29,7 +29,7 @@ if (isset($_POST["remove"])) {
     $fid = $_POST["fid"];
     foreach ($fid as $key => $val) {
         if ($val) {
-            LOG_INFO($db_link, "Remove login with id: $val");
+            LOG_INFO($db_link, "Remove login with id: $val ". dump_record($db_link,'Customers','id='.$val));
             delete_record($db_link, "Customers", "id=" . $val);
         }
     }

+ 1 - 1
html/admin/devices/edit_gw_subnets.php

@@ -11,7 +11,7 @@ if (isset($_POST["s_remove"])) {
     $s_id = $_POST["gs_id"];
     foreach ($s_id as $key => $val) {
         if (isset($val)) {
-            LOG_INFO($db_link, "Remove subnet from gateway id: $val");
+            LOG_INFO($db_link, "Remove subnet from gateway id: $val ". dump_record($db_link,'gateway_subnets','id='.$val));
             delete_record($db_link, "gateway_subnets", "id=" . $val);
         }
     }

+ 1 - 1
html/admin/devices/edit_l3int.php

@@ -11,7 +11,7 @@ if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];
     foreach ($s_id as $key => $val) {
         if (isset($val)) {
-            LOG_INFO($db_link, "Remove l3_interface id: $val");
+            LOG_INFO($db_link, "Remove l3_interface id: $val ". dump_record($db_link,'device_l3_interfaces','id='.$val));
             delete_record($db_link, "device_l3_interfaces", "id=" . $val);
         }
     }

+ 1 - 1
html/admin/devices/switchport-conn.php

@@ -9,7 +9,7 @@ if (isset($_POST["remove"])) {
     $fid = $_POST["f_id"];
     foreach ($fid as $key => $val) {
         if (isset($val) and $val != 1) {
-                LOG_INFO($db_link, "Remove connection id: $val");
+                LOG_VERBOSE($db_link, "Remove connection id: $val ".dump_record($db_link,'connections','id='.$val));
                 delete_record($db_link, "connections", "id=" . $val);
             }
         }

+ 1 - 1
html/admin/groups/edit_group.php

@@ -25,7 +25,7 @@ if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];
     foreach ($s_id as $key => $val) {
         if (isset($val)) {
-            LOG_INFO($db_link, "Remove rule id: $val");
+            LOG_INFO($db_link, "Remove rule id: $val ".dump_record($db_link,'auth_rules','id='.$val));
             delete_record($db_link, "auth_rules", "id=" . $val);
         }
     }

+ 23 - 16
html/admin/users/add_dhcp.php

@@ -1,21 +1,28 @@
 <?php
-require_once ($_SERVER['DOCUMENT_ROOT']."/inc/qauth.php");
+require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/qauth.php");
 
 if (!empty($_GET["ip"]) and !empty($_GET["mac"])) {
-    $ip = $_GET["ip"];
-    $mac = mac_dotted(trim($_GET["mac"]));
-    $dhcp_hostname = '';
-    if (!empty($_GET["hostname"])) { $dhcp_hostname = trim($_GET["hostname"]); }
-    $faction = $_GET["action"] * 1;
+  $ip = $_GET["ip"];
+  $mac = mac_dotted(trim($_GET["mac"]));
+  $dhcp_hostname = '';
+  if (!empty($_GET["hostname"])) {
+    $dhcp_hostname = trim($_GET["hostname"]);
+  }
+  $faction = $_GET["action"] * 1;
+  $action = 'add';
+  if ($faction == 1) {
     $action = 'add';
-    if ($faction == 1) { $action = 'add'; }
-    if ($faction == 0) { $action = 'del'; }
-    LOG_VERBOSE($db_link, "external dhcp request for $ip [$mac] $action");
-    if (checkValidIp($ip) and is_our_network($db_link, $ip)) {
-		$run_cmd = "/opt/Eye/scripts/dnsmasq-hook.sh '".$action."' '".$mac."' '".$ip."' '".$dhcp_hostname."'";
-		$result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." >/dev/null 2>/dev/null &");
-		LOG_INFO($db_link, "Run command: $run_cmd ");
-        } else { LOG_ERROR($db_link, "$ip - wrong network!"); }
-	}
+  }
+  if ($faction == 0) {
+    $action = 'del';
+  }
+  LOG_VERBOSE($db_link, "external dhcp request for $ip [$mac] $action");
+  if (checkValidIp($ip) and is_our_network($db_link, $ip)) {
+    $run_cmd = "/opt/Eye/scripts/dnsmasq-hook.sh '" . $action . "' '" . $mac . "' '" . $ip . "' '" . $dhcp_hostname . "'";
+    $result = shell_exec("/usr/bin/sudo " . escapeshellcmd($run_cmd) . " >/dev/null 2>/dev/null &");
+    LOG_VERBOSE($db_link, "Run command: $run_cmd ");
+  } else {
+    LOG_ERROR($db_link, "$ip - wrong network!");
+  }
+}
 unset($_GET);
-?>

+ 1 - 1
html/admin/users/edit_alias.php

@@ -20,7 +20,7 @@ if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];
     foreach ($s_id as $key => $val) {
         if (isset($val)) {
-            LOG_INFO($db_link, "Remove alias id: $val");
+            LOG_INFO($db_link, "Remove alias id: $val ".dump_record($db_link,'User_auth_alias','id='.$val));
             delete_record($db_link, "User_auth_alias", "id=" . $val);
         }
     }

+ 1 - 1
html/admin/users/edit_rules.php

@@ -13,7 +13,7 @@ if (isset($_POST["s_remove"])) {
     $s_id = $_POST["s_id"];
     foreach ($s_id as $key => $val) {
         if (isset($val)) {
-            LOG_INFO($db_link, "Remove rule id: $val");
+            LOG_INFO($db_link, "Remove rule id: $val ".dump_record($db_link,'auth_rules','id='.$val));
             delete_record($db_link, "auth_rules", "id=" . $val);
         }
     }

+ 1 - 1
html/api.php

@@ -71,7 +71,7 @@ if (!empty($action)) {
               if (checkValidIp($ip) and is_our_network($db_link, $ip)) {
                     $run_cmd = "/opt/Eye/scripts/dnsmasq-hook.sh '".$dhcp_action."' '".$mac."' '".$ip."' '".$dhcp_hostname."'";
                     $result = shell_exec("/usr/bin/sudo ".escapeshellcmd($run_cmd)." >/dev/null 2>/dev/null &");
-                    LOG_INFO($db_link, "Run command: $run_cmd ");
+                    LOG_VERBOSE($db_link, "Run command: $run_cmd ");
                     } else { LOG_ERROR($db_link, "$ip - wrong network!"); }
               }
           }

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

@@ -125,14 +125,14 @@ function IsAuthenticated($db)
     }
 
     if (empty($login) or empty($pass)) {
-        LOG_INFO($db, "login [$login] or password [$pass] undefined from $auth_ip: fail!");
+        LOG_ERROR($db, "login [$login] or password [$pass] undefined from $auth_ip: fail!");
         logout();
         return false;
     }
 
     $login = htmlspecialchars(stripslashes($login));
     if (empty($login) or empty($pass)) {
-        LOG_INFO($db, "login [$login] or password [$pass] undefined from $auth_ip: fail!");
+        LOG_ERROR($db, "login [$login] or password [$pass] undefined from $auth_ip: fail!");
         logout();
         return false;
     }
@@ -159,12 +159,12 @@ function IsAuthenticated($db)
             setcookie("Auth", $auth_record['id'] . ":" . $session['session_id'] . ":" . md5($ret_id . ":" . $session['session_key'] . ":" . $_SESSION['IP']), time() + 60 * 60 * 24);
             return true;
         } else {
-            LOG_INFO($db, "login user [$login] from " . $_SESSION['IP'] . ": fail!");
+            LOG_ERROR($db, "login user [$login] from " . $_SESSION['IP'] . ": fail!");
             logout();
             return false;
         }
     }
-    LOG_INFO($db, "login user [$login] from " . $_SESSION['IP'] . ": fail!");
+    LOG_ERROR($db, "login user [$login] from " . $_SESSION['IP'] . ": fail!");
     logout();
     return false;
 }
@@ -201,7 +201,7 @@ function IsSilentAuthenticated($db)
     }
 
     if (empty($login) or empty($pass)) {
-        LOG_INFO($db, "login or password undefined from $auth_ip: fail!");
+        LOG_ERROR($db, "login or password undefined from $auth_ip: fail!");
         logout();
         return false;
     }
@@ -209,7 +209,7 @@ function IsSilentAuthenticated($db)
     $login = htmlspecialchars(stripslashes($login));
 
     if ($login == '' or $pass == '') {
-        LOG_INFO($db, "login or password undefined from $auth_ip: fail!");
+        LOG_ERROR($db, "login or password undefined from $auth_ip: fail!");
         logout();
         return false;
     }
@@ -230,7 +230,7 @@ function IsSilentAuthenticated($db)
         return true;
     }
 
-    LOG_INFO($db, "Api login user $login from " . $_SESSION['IP'] . ": fail!");
+    LOG_ERROR($db, "Api login user $login from " . $_SESSION['IP'] . ": fail!");
     logout();
     return false;
 }

+ 13 - 4
html/inc/common.php

@@ -2331,9 +2331,9 @@ function apply_device_lock ($db, $device_id, $iteration =0) {
         LOG_DEBUG($db,"The lock is already expired. Set new lock.");
         return set_lock_discovery($db,$device_id);
         }
-    LOG_INFO($db,"Snmp discovery lock for device id: $device_id found! Need wait ".$wait_time." sec.");
+    LOG_VERBOSE($db,"Snmp discovery lock for device id: $device_id found! Need wait ".$wait_time." sec.");
     sleep($wait_time);
-    LOG_INFO($db,"Try set new lock and continue discovery for device id:".$device_id);
+    LOG_VERBOSE($db,"Try set new lock and continue discovery for device id:".$device_id);
     return apply_device_lock($db,$device_id,$iteration);
 }
 
@@ -3749,7 +3749,7 @@ function set_port_for_group($db, $group_id, $place_id, $state)
 {
     $authSQL = 'SELECT User_auth.id,User_auth.dns_name,User_auth.ip FROM User_auth, User_list WHERE User_auth.user_id = User_list.id AND User_auth.deleted=0 and User_list.ou_id=' . $group_id;
     $auth_list = mysqli_query($db, $authSQL);
-    LOG_INFO($db, 'Mass port state change started!');
+    LOG_VERBOSE($db, 'Mass port state change started!');
     // get auth list for group
     while (list($a_id, $a_name, $a_ip) = mysqli_fetch_array($auth_list)) {
         // get device and port for auth
@@ -3775,7 +3775,7 @@ function set_port_for_group($db, $group_id, $place_id, $state)
         set_port_state($d_vendor_id, $d_snmp_index, $d_ip, $d_community, $d_snmp, $state);
         set_port_poe_state($d_vendor_id, $d_port, $d_snmp_index, $d_ip, $d_community, $d_snmp, $state);
     }
-    LOG_INFO($db, 'Mass port state change stopped.');
+    LOG_VERBOSE($db, 'Mass port state change stopped.');
 }
 
 function get_vendor($db, $mac)
@@ -4649,6 +4649,15 @@ function insert_record($db, $table, $newvalue)
     return $last_id;
 }
 
+function dump_record($db,$table,$filter)
+{
+    $result = '';
+    $old = get_record($db,$table,$filter);
+    if (empty($old)) { return $result; } 
+    $result = 'record: '. get_rec_str($old);
+    return $result;
+}
+
 function get_rec_str($array)
 {
     $result = '';

+ 2 - 2
html/utils/user_remove.php

@@ -13,7 +13,7 @@ if (isset($_POST["RemoveUser"]) and (isset($_POST["f_deleted"]))) {
 				$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");
+					LOG_INFO($db_link, "Delete device for user id: $val ".dump_record($db_link,'devices','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']);
@@ -24,7 +24,7 @@ if (isset($_POST["RemoveUser"]) and (isset($_POST["f_deleted"]))) {
 				run_sql($db_link, "DELETE FROM auth_rules WHERE user_id=$val");
 				run_sql($db_link, "UPDATE User_auth SET deleted=1, changed=1, dhcp_changed=1 WHERE user_id=$val");
 				delete_record($db_link, "User_list", "id=$val");
-				LOG_WARNING($db_link, "Deleted user id: $val login: " . $login['login']);
+				LOG_WARNING($db_link, "Deleted user id: $val ".dump_record($db_link,'User_list','id='.$val));
 			}
 		}
 		if ($all_ok) {

+ 2 - 2
scripts/dhcp-log.pl

@@ -355,8 +355,8 @@ if (!$pid) {
                         $auth_rec->{dhcp_time}=$dhcp_event_time;
                         update_record($hdb,'User_auth',$auth_rec,"id=$auth_id");
                         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'});
+                        if (!$u_count) {
+                                delete_record($hdb,"User_list","id=".$auth_record->{'user_id'});
                                 db_log_info($hdb,"Remove dynamic user id: $auth_record->{'user_id'} by dhcp request",$auth_id);
                                 }
                         }