Module: nagvis
Branch: master
Commit: 37f07ded207c4a9c6798e1f31799bad12a17d341
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=37f07ded207c4a9c6798e1f31799bad12a17d341

Author: LaMi <[email protected]>
Date:   Tue Apr  6 20:18:57 2010 +0200

#242 Implemented new class CoreLog to create a log file. Initially using it for 
authentication

---

 share/server/core/classes/CoreAuthHandler.php   |   20 +++++++++++-
 share/server/core/classes/CoreAuthModSQLite.php |    4 --
 share/server/core/classes/CoreLog.php           |   39 +++++++++++++++++++++++
 3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/share/server/core/classes/CoreAuthHandler.php 
b/share/server/core/classes/CoreAuthHandler.php
index 3bbbe1e..c69485e 100644
--- a/share/server/core/classes/CoreAuthHandler.php
+++ b/share/server/core/classes/CoreAuthHandler.php
@@ -137,10 +137,17 @@ class CoreAuthHandler {
        public function isAuthenticated($bTrustUsername = 
AUTH_NOT_TRUST_USERNAME) {
                // Don't do these things twice
                if($this->bIsAuthenticated === null) {
+                       $ALOG = new 
CoreLog($this->CORE->getMainCfg()->getValue('paths', 'var').'nagvis-audit.log',
+                                           
$this->CORE->getMainCfg()->getValue('global', 'dateformat'));
+                       
                        // When the user authenticated in trust mode read it 
here and override
-                       // the value handed over with the function call
+                       // the value handed over with the function call.
+                       // The isAuthentication() function will then only check 
if the user exists.
                        if($this->SESS->isSetAndNotEmpty('authTrusted')) {
+                               $bAlreadyAuthed = true;
                                $bTrustUsername = AUTH_TRUST_USERNAME;
+                       } else {
+                               $bAlreadyAuthed = false;        
                        }
                        
                        // Ask the module
@@ -154,6 +161,13 @@ class CoreAuthHandler {
                                if($bTrustUsername === AUTH_TRUST_USERNAME) {
                                        $this->SESS->set('authTrusted', 
AUTH_TRUST_USERNAME);
                                }
+
+                               if(!$bAlreadyAuthed)
+                                       $ALOG->l('User logged in 
('.$this->getUser().' / '.$this->getUserId().'): '.$this->sModuleName);
+                       }
+
+                       if($this->bIsAuthenticated === false) {
+                               $ALOG->l('User login failed 
('.$this->getUser().' / '.$this->getUserId().'): '.$this->sModuleName);
                        }
                        
                        // Remove some maybe old data when not authenticated
@@ -172,6 +186,10 @@ class CoreAuthHandler {
        
        public function logout() {
                if($this->logoutSupported()) {
+                       $ALOG = new 
CoreLog($this->CORE->getMainCfg()->getValue('paths', 'var').'nagvis-audit.log',
+                                           
$this->CORE->getMainCfg()->getValue('global', 'dateformat'));
+                       $ALOG->l('User logged out ('.$this->getUser().' / 
'.$this->getUserId().'): '.$this->sModuleName);
+                       
                        // Remove the login information
                        $this->SESS->set('authCredentials', false);
                        $this->SESS->set('userPermissions', false);
diff --git a/share/server/core/classes/CoreAuthModSQLite.php 
b/share/server/core/classes/CoreAuthModSQLite.php
index 88b3005..d788dea 100644
--- a/share/server/core/classes/CoreAuthModSQLite.php
+++ b/share/server/core/classes/CoreAuthModSQLite.php
@@ -176,7 +176,6 @@ class CoreAuthModSQLite extends CoreAuthModule {
                        
                        $bReturn = true;
                } else {
-                       //FIXME: Logging? Invalid user
                        $bReturn = false;
                }
                
@@ -202,14 +201,11 @@ class CoreAuthModSQLite extends CoreAuthModule {
                        $userId = $this->checkUserAuth($bTrustUsername);
                        if($userId > 0) {
                                $this->iUserId = $userId;
-                               //FIXME: Logging? Successfull authentication
                                $bReturn = true;
                        } else {
-                               //FIXME: Logging? Invalid password
                                $bReturn = false;
                        }
                } else {
-                       //FIXME: Logging? Invalid user
                        $bReturn = false;
                }
                
diff --git a/share/server/core/classes/CoreLog.php 
b/share/server/core/classes/CoreLog.php
new file mode 100644
index 0000000..53c5b91
--- /dev/null
+++ b/share/server/core/classes/CoreLog.php
@@ -0,0 +1,39 @@
+<?php
+
+
+class CoreLog {
+       private $path = null;
+       private $FILE = null;
+       private $dateFormat = null;
+
+       public function __construct($file, $dateFormat) {
+               $this->path = $file;
+    $this->dateFormat = $dateFormat;
+       }
+
+       public function __destruct() {
+               $this->closeFile();
+       }
+
+       private function openFile() {
+               $this->FILE = fopen($this->path, 'a');
+       }
+
+       private function closeFile() {
+               if($this->FILE !== null)
+                       fclose($this->FILE);
+       }
+       
+       /**
+        * Writes the debug output to the debug file
+        *
+        * @param   String    Debug message
+        * @author  Lars Michelsen <[email protected]>
+        */
+       public function l($msg) {
+               if($this->FILE === null)
+                       $this->openFile();
+               
+         fwrite($this->FILE, date($this->dateFormat).' '.$msg."\n");
+       }
+}


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to