Fix #7809 - sort out logging
authorAlan <alan@roojs.com>
Wed, 6 Sep 2023 05:06:28 +0000 (13:06 +0800)
committerAlan <alan@roojs.com>
Wed, 6 Sep 2023 05:06:28 +0000 (13:06 +0800)
Pman.php
Pman/Login.php

index 0fa0a67..6cbb587 100644 (file)
--- a/Pman.php
+++ b/Pman.php
@@ -516,7 +516,9 @@ class Pman extends HTML_FlexyFramework_Page
             if(!empty($errors)){
                 DB_DataObject::factory('Events')->writeEventLogExtra($errors);
             }
-            if (!preg_match('/^(ERROR|NOTICE)/', $type )) {
+            // various codes that are acceptable.
+            // 
+            if (!preg_match('/^(ERROR|NOTICE|LOG)/', $type )) {
                 $type = 'ERROR-' . $type;
             }
             
index e309cdc..44a1a41 100644 (file)
@@ -27,7 +27,7 @@ class Pman_Login extends Pman
     
     var $ip_management = false;
        
-       var $event_prefix = '';
+       var $event_suffix = '';
        
     
     function getAuth() // everyone allowed in here..
@@ -98,7 +98,7 @@ class Pman_Login extends Pman
         //print_r($u);
         if ($u) {
             
-            $this->addEvent($this->event_prefix . 'LOGOUT');
+            $this->addEvent('LOGOUT'. $this->event_suffix);
             $e = DB_DataObject::factory('Events');
           
             
@@ -220,7 +220,7 @@ class Pman_Login extends Pman
         }
         $u->login();
             // we might need this later..
-        $this->addEvent($this->event_prefix . "SWITCH-USER", false, $au->name . ' TO ' . $u->name);
+        $this->addEvent("LOGIN-SWITCH-USER". $this->event_suffix, false, $au->name . ' TO ' . $u->name);
         $this->jok("SWITCH");
         
     }
@@ -314,11 +314,11 @@ class Pman_Login extends Pman
         if (!empty($ip)) {
             //DB_DataObject::DebugLevel(1);
             $e = DB_DataObject::Factory('Events');
-            $e->action = $this->event_prefix . 'LOGIN-BAD';
+            $e->action = 'LOGIN-BAD'. $this->event_suffix;
             $e->ipaddr = $ip;
             $e->whereAdd('event_when > NOW() - INTERVAL 10 MINUTE');
             if ($e->count() > 5) {
-                $this->jerror($this->event_prefix . 'LOGIN-RATE', "Login failures are rate limited - please try later");
+                $this->jerror('LOGIN-RATE'. $this->event_suffix, "Login failures are rate limited - please try later");
             }
         }
         
@@ -329,23 +329,23 @@ class Pman_Login extends Pman
         // empty username = not really a hacking attempt.
         
         if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
-            $this->jerror($this->event_prefix . 'LOGIN-EMPTY', 'You typed the wrong Username or Password (0)');
+            $this->jerror('LOGIN-EMPTY'. $this->event_suffix, 'You typed the wrong Username or Password (0)');
             exit;
         }
         
         $u->authUserName($_REQUEST['username']);
         
         if ($u->count() > 1 || !$u->find(true)) {
-            $this->jerror($this->event_prefix . 'LOGIN-BAD','You typed the wrong Username or Password  (1)');
+            $this->jerror('LOGIN-BAD'. $this->event_suffix,'You typed the wrong Username or Password  (1)');
             exit;
         }
         
         if (!$u->active()) { 
-            $this->jerror($this->event_prefix . 'LOGIN-BAD','Account disabled');
+            $this->jerror('LOGIN-BAD'. $this->event_suffix,'Account disabled');
         }
         
         if(!empty($u->oath_key) && empty($_REQUEST['oath_password'])){
-            $this->jerror($this->event_prefix . 'LOGIN-2FA','Your account requires Two-Factor Authentication');
+            $this->jerror('LOGIN-2FA'. $this->event_suffix,'Your account requires Two-Factor Authentication');
         }
         
         // check if config allows non-owner passwords.
@@ -354,14 +354,14 @@ class Pman_Login extends Pman
         $ff= HTML_FlexyFramework::get();
         if (!empty($ff->Pman['auth_comptype']) && $ff->Pman['auth_comptype'] != $u->company()->comptype) {
             //print_r($u->company());
-            $this->jerror($this->event_prefix . 'LOGIN-BADUSER', "Login not permited to outside companies"); // serious failure
+            $this->jerror('LOGIN-BADUSER'. $this->event_suffix, "Login not permited to outside companies"); // serious failure
         }
         
         
         // note we trim \x10 -- line break - as it was injected the front end
         // may have an old bug on safari/chrome that added that character in certian wierd scenarios..
         if (!$u->checkPassword(trim($_REQUEST['password'],"\x10"))) {
-            $this->jerror($this->event_prefix . 'LOGIN-BAD', 'You typed the wrong Username or Password  (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
+            $this->jerror('LOGIN-BAD'. $this->event_suffix, 'You typed the wrong Username or Password  (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
             exit;
         }
         
@@ -372,7 +372,7 @@ class Pman_Login extends Pman
                !$u->checkTwoFactorAuthentication($_REQUEST['oath_password'])
            )
         ) {
-            $this->jerror($this->event_prefix . 'LOGIN-BAD', 'You typed the wrong Username or Password  (3)');
+            $this->jerror('LOGIN-BAD'. $this->event_suffix, 'You typed the wrong Username or Password  (3)');
             exit;
         }
         
@@ -380,7 +380,7 @@ class Pman_Login extends Pman
         
         $u->login();
         // we might need this later..
-        $this->addEvent($this->event_prefix . "LOGIN", false, session_id());
+        $this->addEvent("LOGIN". $this->event_suffix, false, session_id());
                
                
                
@@ -479,7 +479,7 @@ class Pman_Login extends Pman
                        $this->jerr($sent->getMessage());
         }
        
-        $this->addEvent($this->event_prefix . 'PASSREQ',$u, $u->email);
+        $this->addEvent('LOGIN-PASSREQ'. $this->event_suffix,$u, $u->email);
         $uu = clone($u);
         $uu->no_reset_sent++;
         $uu->update($u);
@@ -529,7 +529,7 @@ class Pman_Login extends Pman
                        $u->setPassword($newpass);
                }
         $u->update($uu);
-               $this->addEvent($this->event_prefix . "CHANGEPASS", $u);
+               $this->addEvent("LOGIN-CHANGEPASS". $this->event_suffix, $u);
 
         $this->jok("Password has been Updated");
     }
@@ -544,7 +544,7 @@ class Pman_Login extends Pman
                $uu = clone($au);
                $au->setPassword($r['passwd1']);
                $au->update($uu);
-               $this->addEvent($this->event_prefix . "CHANGEPASS", $au);
+               $this->addEvent("LOGIN-CHANGEPASS". $this->event_suffix, $au);
                $this->jok($au);
                         
     }