Ver Fonte

mail notifications for changing user records are enabled again

root há 1 ano atrás
pai
commit
4480320b96
3 ficheiros alterados com 55 adições e 42 exclusões
  1. 2 2
      html/admin/users/editauth.php
  2. 2 2
      html/admin/users/edituser.php
  3. 51 38
      html/inc/common.php

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

@@ -104,7 +104,7 @@ if (isset($_POST["editauth"]) and !$old_auth_info['deleted']) {
         if (!$user_enabled) { $new['enabled']=0; }
         if (!$user_enabled) { $new['enabled']=0; }
         $changes = get_diff_rec($db_link, "User_auth", "id='$id'", $new, 0);
         $changes = get_diff_rec($db_link, "User_auth", "id='$id'", $new, 0);
         if (!empty($changes)) {
         if (!empty($changes)) {
-            LOG_INFO($db_link, "Changed record for $ip! Log: " . $changes, $id);
+            LOG_WARNING($db_link, "Changed record for $ip! Log: " . $changes, $id);
             }
             }
         if (is_auth_bind_changed($db_link, $id, $ip, $mac)) {
         if (is_auth_bind_changed($db_link, $id, $ip, $mac)) {
             $new_id = copy_auth($db_link, $id, $new);
             $new_id = copy_auth($db_link, $id, $new);
@@ -130,7 +130,7 @@ if (isset($_POST["moveauth"]) and !$old_auth_info['deleted']) {
     $moved_auth = get_record_sql($db_link,"SELECT comments FROM User_auth WHERE id=".$id);
     $moved_auth = get_record_sql($db_link,"SELECT comments FROM User_auth WHERE id=".$id);
     $changes = apply_auth_rule($db_link, $moved_auth, $new_parent_id);
     $changes = apply_auth_rule($db_link, $moved_auth, $new_parent_id);
     update_record($db_link, "User_auth", "id='$id'", $changes);
     update_record($db_link, "User_auth", "id='$id'", $changes);
-    LOG_INFO($db_link, "IP-address moved to another user! Applyed: " . get_rec_str($changes), $id);
+    LOG_WARNING($db_link, "IP-address moved to another user! Applyed: " . get_rec_str($changes), $id);
     run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$old_auth_info["user_id"]." AND rule='".$old_auth_info["mac"]."' AND type=2");
     run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$old_auth_info["user_id"]." AND rule='".$old_auth_info["mac"]."' AND type=2");
     run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$old_auth_info["user_id"]." AND rule='".$old_auth_info["ip"]."' AND type=1");
     run_sql($db_link,"DELETE FROM auth_rules WHERE user_id=".$old_auth_info["user_id"]." AND rule='".$old_auth_info["ip"]."' AND type=1");
     LOG_INFO($db_link,"Autorules removed for user_id: ".$old_auth_info["user_id"]." login: ".$user_info["login"]." by mac and ip");
     LOG_INFO($db_link,"Autorules removed for user_id: ".$old_auth_info["user_id"]." login: ".$user_info["login"]." by mac and ip");

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

@@ -36,7 +36,7 @@ if (isset($_POST["edituser"])) {
     }
     }
     $changes = get_diff_rec($db_link, "User_list", "id='$id'", $new, 0);
     $changes = get_diff_rec($db_link, "User_list", "id='$id'", $new, 0);
     if (!empty($changes)) {
     if (!empty($changes)) {
-        LOG_INFO($db_link, "Changed user id: $id login: " . $new["login"] . ". \r\nApply: $changes");
+        LOG_WARNING($db_link, "Changed user id: $id login: " . $new["login"] . ". \r\nApply: $changes");
     }
     }
     update_record($db_link, "User_list", "id='$id'", $new);
     update_record($db_link, "User_list", "id='$id'", $new);
     if (!$new["enabled"]) {
     if (!$new["enabled"]) {
@@ -161,7 +161,7 @@ if (isset($_POST["addauth"])) {
                 $new['dhcp'] = $f_dhcp;
                 $new['dhcp'] = $f_dhcp;
                 $new["dhcp_action"] = 'manual';
                 $new["dhcp_action"] = 'manual';
                 update_record($db_link, "User_auth", "id=" . $fid, $new);
                 update_record($db_link, "User_auth", "id=" . $fid, $new);
-                LOG_INFO($db_link, "Add ip for login: " . $user_info["login"] . ": ip => $fip, mac => $fmac", $fid);
+                LOG_WARNING($db_link, "Add ip for login: " . $user_info["login"] . ": ip => $fip, mac => $fmac", $fid);
                 header("Location: /admin/users/editauth.php?id=" . $fid);
                 header("Location: /admin/users/editauth.php?id=" . $fid);
                 exit;
                 exit;
             }
             }

+ 51 - 38
html/inc/common.php

@@ -2210,58 +2210,67 @@ function LOG_DEBUG($db, $msg, $auth_id = 0)
     }
     }
 }
 }
 
 
+function truncateByWords($string, $length = 100) {
+    if (strlen($string) <= $length) {
+        return $string;
+    }
+    $wrapped = wordwrap($string, $length);
+    $shortened = substr($wrapped, 0, strpos($wrapped, "\n"));
+    return $shortened;
+}
+
 function get_first_line($msg)
 function get_first_line($msg)
 {
 {
-    if (empty($msg)) {
-        return;
-    }
+    if (empty($msg)) { return; }
     preg_match('/(.*)(\n|\<br\>)/', $msg, $matches);
     preg_match('/(.*)(\n|\<br\>)/', $msg, $matches);
     if (!empty($matches[1])) {
     if (!empty($matches[1])) {
         return $matches[1];
         return $matches[1];
     }
     }
-    return;
+    return truncateByWords($msg,80);
 }
 }
 
 
 function email($level, $msg)
 function email($level, $msg)
 {
 {
-    if (!get_const('send_email')) {
-        return;
-    }
-    if (!($level === L_WARNING or $level === L_ERROR)) {
-        return;
-    }
+if (!get_const('send_email')) { return; }
+if (!($level === L_WARNING or $level === L_ERROR)) { return; }
 
 
-    $message  ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'."\r\n";
-    $message .='<html xmlns="http://www.w3.org/1999/xhtml">'."\r\n";
+// Generate a boundary string
+$boundary = md5(time());
 
 
-    $subject = get_first_line($msg);
+// Headers
+$headers = array(
+    'From' => get_const('sender_email'),
+    'Reply-To' => get_const('sender_email'),
+    'X-Mailer' => 'PHP',
+    'MIME-Version' => '1.0',
+    'Content-Type' => 'multipart/mixed; boundary=' . $boundary
+);
 
 
-    if ($level === L_WARNING) {
-        $subject = "WARN: " . $subject . "...";
-        $message .="<head><title>$subject</title></head><body>\r\n";
-        $message .= 'WARNING! Manager: ' . $_SESSION['login'] . ' </br>';
-    }
-    if ($level === L_ERROR) {
-        $subject = "ERROR: " . $subject . "...";
-        $message .="<head><title>$subject</title></head><body>\r\n";
-        $message .= 'ERROR! Manager: ' . $_SESSION['login'] . ' </br>';
-    }
+$subject = get_first_line($msg);
 
 
-    $msg_lines = preg_replace("/\r\n/", "</br>", $msg);
-    $msg_lines = preg_replace("/\n/", "</br>", $msg_lines);
-    $message  .= $msg_lines.'</body></html>';
+if ($level === L_WARNING) {
+    $subject = "WARN: " . $subject . "...";
+    $message = 'WARNING! Manager: ' . $_SESSION['login'] . ' <br>' . $msg .'<br>';
+}
+if ($level === L_ERROR) {
+    $subject = "ERROR: " . $subject . "...";
+    $message = 'ERROR! Manager: ' . $_SESSION['login'] . ' <br>' . $msg .'<br>';
+}
 
 
-    // Base64 encode the message
-    $encoded_message = base64_encode($message);
+// HTML part
+$html_message = "<html><body><h1>$message</h1></body></html>";
+$html_encoded = chunk_split(base64_encode($html_message));
 
 
-    $to        = get_const('admin_email');
-    $headers  = 'From: '. get_const('sender_email') . "\r\n";
-    $headers .= "X-Mailer: PHP\r\n";
-    $headers .= "MIME-Version: 1.0\r\n";
-    $headers .= "Content-Type: text/plain; charset=utf-8\r\n";
-    $headers .= "Content-Transfer-Encoding: base64\r\n";
+// Create the message body
+$message = "";
+$message .= "--" . $boundary . "\r\n";
+$message .= "Content-Type: text/html; charset=UTF-8\r\n";
+$message .= "Content-Transfer-Encoding: base64\r\n\r\n";
+$message .= $html_encoded . "\r\n";
+$message .= "--" . $boundary . "--";
 
 
-    mail($to, $subject, chunk_split($message), $headers);
+// Send email
+mail(get_const('admin_email'), $subject, $message, $headers);
 }
 }
 
 
 function write_log($db, $msg, $level, $auth_id = 0)
 function write_log($db, $msg, $level, $auth_id = 0)
@@ -4576,10 +4585,14 @@ function delete_record($db, $table, $filter)
 
 
     $changed_log = 'record: ';
     $changed_log = 'record: ';
     if (!empty($old)) {
     if (!empty($old)) {
+        asort($old,SORT_STRING);
+        $old = array_reverse($old,1);
         foreach ($old as $key => $value) {
         foreach ($old as $key => $value) {
-            if (!isset($value)) {
-                $value = '';
-            }
+            if (empty($value)) { continue; }
+            if (preg_match('/action/',$key)) { continue; }
+            if (preg_match('/status/',$key)) { continue; }
+            if (preg_match('/time/',$key)) { continue; }
+            if (preg_match('/found/',$key)) { continue; }
             $changed_log = $changed_log . " $key => $value,";
             $changed_log = $changed_log . " $key => $value,";
         }
         }
     }
     }