remove parameter from FroxorLogger class and migrated it to PDO database class, refs #1287
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -26,35 +26,24 @@ class FroxlorLogger
|
||||
* Userinfo
|
||||
* @var array
|
||||
*/
|
||||
|
||||
private $userinfo = array();
|
||||
|
||||
/**
|
||||
* Database handler
|
||||
* @var db
|
||||
*/
|
||||
|
||||
private $db = false;
|
||||
|
||||
/**
|
||||
* Settings array
|
||||
* @var settings
|
||||
*/
|
||||
|
||||
private $settings = array();
|
||||
|
||||
/**
|
||||
* LogTypes Array
|
||||
* @var logtypes
|
||||
*/
|
||||
|
||||
static private $logtypes = null;
|
||||
|
||||
/**
|
||||
* Logger-Object-Array
|
||||
* @var loggers
|
||||
*/
|
||||
|
||||
static private $loggers = null;
|
||||
|
||||
/**
|
||||
@@ -63,31 +52,24 @@ class FroxlorLogger
|
||||
* @param array userinfo
|
||||
* @param array settings
|
||||
*/
|
||||
|
||||
protected function __construct($userinfo, $db, $settings)
|
||||
{
|
||||
protected function __construct($userinfo, $settings) {
|
||||
$this->userinfo = $userinfo;
|
||||
$this->db = $db;
|
||||
$this->settings = $settings;
|
||||
self::$logtypes = array();
|
||||
|
||||
if(!isset($this->settings['logger']['logtypes'])
|
||||
if (!isset($this->settings['logger']['logtypes'])
|
||||
&& (!isset($this->settings['logger']['logtypes']) || $this->settings['logger']['logtypes'] == '')
|
||||
&& isset($this->settings['logger']['enabled'])
|
||||
&& $this->settings['logger']['enabled'])
|
||||
{
|
||||
&& $this->settings['logger']['enabled']
|
||||
) {
|
||||
self::$logtypes[0] = 'syslog';
|
||||
self::$logtypes[1] = 'mysql';
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isset($this->settings['logger']['logtypes'])
|
||||
&& $this->settings['logger']['logtypes'] != '')
|
||||
{
|
||||
} else {
|
||||
if (isset($this->settings['logger']['logtypes'])
|
||||
&& $this->settings['logger']['logtypes'] != ''
|
||||
) {
|
||||
self::$logtypes = explode(',', $this->settings['logger']['logtypes']);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
self::$logtypes = null;
|
||||
}
|
||||
}
|
||||
@@ -97,40 +79,37 @@ class FroxlorLogger
|
||||
* Singleton ftw ;-)
|
||||
*
|
||||
*/
|
||||
|
||||
static public function getInstanceOf($_usernfo, $_db, $_settings)
|
||||
static public function getInstanceOf($_usernfo, $_settings)
|
||||
{
|
||||
if(!isset($_usernfo)
|
||||
|| $_usernfo == null)
|
||||
{
|
||||
if (!isset($_usernfo)
|
||||
|| $_usernfo == null
|
||||
) {
|
||||
$_usernfo = array();
|
||||
$_usernfo['loginname'] = 'unknown';
|
||||
}
|
||||
|
||||
if(!isset(self::$loggers[$_usernfo['loginname']]))
|
||||
{
|
||||
self::$loggers[$_usernfo['loginname']] = new FroxlorLogger($_usernfo, $_db, $_settings);
|
||||
if (!isset(self::$loggers[$_usernfo['loginname']])) {
|
||||
self::$loggers[$_usernfo['loginname']] = new FroxlorLogger($_usernfo, $_settings);
|
||||
}
|
||||
|
||||
return self::$loggers[$_usernfo['loginname']];
|
||||
}
|
||||
|
||||
public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null)
|
||||
{
|
||||
if(self::$logtypes == null)
|
||||
{
|
||||
public function logAction ($action = USR_ACTION, $type = LOG_NOTICE, $text = null) {
|
||||
|
||||
if (self::$logtypes == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->settings['logger']['log_cron'] == '0'
|
||||
&& $action == CRON_ACTION)
|
||||
{
|
||||
if ($this->settings['logger']['log_cron'] == '0'
|
||||
&& $action == CRON_ACTION
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(self::$logtypes as $logger)
|
||||
{
|
||||
switch($logger)
|
||||
foreach (self::$logtypes as $logger) {
|
||||
|
||||
switch ($logger)
|
||||
{
|
||||
case 'syslog':
|
||||
$_log = SysLogger::getInstanceOf($this->userinfo, $this->settings);
|
||||
@@ -140,43 +119,30 @@ class FroxlorLogger
|
||||
{
|
||||
$_log = FileLogger::getInstanceOf($this->userinfo, $this->settings);
|
||||
}
|
||||
|
||||
catch(Exception $e)
|
||||
{
|
||||
if($action != CRON_ACTION)
|
||||
{
|
||||
if ($action != CRON_ACTION) {
|
||||
standard_error('logerror', $e->getMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
echo "Log-Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'mysql':
|
||||
$_log = MysqlLogger::getInstanceOf($this->userinfo, $this->settings, $this->db);
|
||||
$_log = MysqlLogger::getInstanceOf($this->userinfo, $this->settings);
|
||||
break;
|
||||
default:
|
||||
$_log = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if($_log != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ($_log != null) {
|
||||
try {
|
||||
$_log->logAction($action, $type, $text);
|
||||
}
|
||||
|
||||
catch(Exception $e)
|
||||
{
|
||||
if($action != CRON_ACTION)
|
||||
{
|
||||
} catch(Exception $e) {
|
||||
if ($action != CRON_ACTION) {
|
||||
standard_error('logerror', $e->getMessage());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
echo "Log-Error: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
@@ -184,20 +150,22 @@ class FroxlorLogger
|
||||
}
|
||||
}
|
||||
|
||||
public function setCronLog($_cronlog = 0)
|
||||
{
|
||||
public function setCronLog($_cronlog = 0) {
|
||||
|
||||
$_cronlog = (int)$_cronlog;
|
||||
|
||||
if($_cronlog != 0
|
||||
&& $_cronlog != 1)
|
||||
{
|
||||
if ($_cronlog != 0
|
||||
&& $_cronlog != 1
|
||||
) {
|
||||
$_cronlog = 0;
|
||||
}
|
||||
|
||||
$this->db->query("UPDATE `" . TABLE_PANEL_SETTINGS . "`
|
||||
SET `value`='" . $this->db->escape($_cronlog) . "'
|
||||
WHERE `settinggroup`='logger'
|
||||
AND `varname`='log_cron'");
|
||||
$stmt = Database::prepare("
|
||||
UPDATE `" . TABLE_PANEL_SETTINGS . "` SET
|
||||
`value` = :value
|
||||
WHERE `settinggroup`='logger' AND `varname`='log_cron'"
|
||||
);
|
||||
Database::pexecute($stmt, array('value' => $_cronlog));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,27 +20,18 @@
|
||||
* Logger - MySQL-Logger-Class
|
||||
*/
|
||||
|
||||
class MysqlLogger extends AbstractLogger
|
||||
{
|
||||
class MysqlLogger extends AbstractLogger {
|
||||
|
||||
/**
|
||||
* Userinfo
|
||||
* @var array
|
||||
*/
|
||||
|
||||
private $userinfo = array();
|
||||
|
||||
/**
|
||||
* Database handler
|
||||
* @var db
|
||||
*/
|
||||
|
||||
private $db = false;
|
||||
|
||||
/**
|
||||
* Syslogger Objects Array
|
||||
* @var loggers
|
||||
*/
|
||||
|
||||
static private $loggers = array();
|
||||
|
||||
/**
|
||||
@@ -48,66 +39,69 @@ class MysqlLogger extends AbstractLogger
|
||||
*
|
||||
* @param array userinfo
|
||||
* @param array settings
|
||||
* @param resource database
|
||||
*/
|
||||
|
||||
protected function __construct($userinfo, $settings, $db)
|
||||
{
|
||||
protected function __construct($userinfo, $settings) {
|
||||
parent::setupLogger($settings);
|
||||
$this->userinfo = $userinfo;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton ftw ;-)
|
||||
*
|
||||
*/
|
||||
static public function getInstanceOf($_usernfo, $_settings) {
|
||||
|
||||
static public function getInstanceOf($_usernfo, $_settings, $_db)
|
||||
{
|
||||
if(!isset(self::$loggers[$_usernfo['loginname']]))
|
||||
{
|
||||
self::$loggers[$_usernfo['loginname']] = new MysqlLogger($_usernfo, $_settings, $_db);
|
||||
if (!isset(self::$loggers[$_usernfo['loginname']])) {
|
||||
self::$loggers[$_usernfo['loginname']] = new MysqlLogger($_usernfo, $_settings);
|
||||
}
|
||||
|
||||
return self::$loggers[$_usernfo['loginname']];
|
||||
}
|
||||
|
||||
public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null)
|
||||
{
|
||||
if(parent::isEnabled())
|
||||
{
|
||||
if(parent::getSeverity() <= 1
|
||||
&& $type == LOG_NOTICE)
|
||||
{
|
||||
public function logAction($action = USR_ACTION, $type = LOG_NOTICE, $text = null) {
|
||||
|
||||
if (parent::isEnabled()) {
|
||||
|
||||
if (parent::getSeverity() <= 1
|
||||
&& $type == LOG_NOTICE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!isset($this->userinfo['loginname'])
|
||||
|| $this->userinfo['loginname'] == '')
|
||||
{
|
||||
if (!isset($this->userinfo['loginname'])
|
||||
|| $this->userinfo['loginname'] == ''
|
||||
) {
|
||||
$name = 'unknown';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$name = " (" . $this->userinfo['loginname'] . ")";
|
||||
}
|
||||
|
||||
$now = time();
|
||||
|
||||
if($text != null
|
||||
&& $text != '')
|
||||
{
|
||||
$this->db->query("INSERT INTO `panel_syslog` (`type`, `date`, `action`, `user`, `text`)
|
||||
VALUES ('" . (int)$type . "', '" . $now . "', '" . (int)$action . "', '" . $this->db->escape($name) . "', '" . $this->db->escape($text) . "')");
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query("INSERT INTO `panel_syslog` (`type`, `date`, `action`, `userid`, `text`)
|
||||
VALUES ('" . (int)$type . "', '" . $now . "', '" . (int)$action . "', '" . $this->db->escape($name) . "', 'No text given!!! Check scripts!')");
|
||||
$stmt = Database::prepare("
|
||||
INSERT INTO `panel_syslog` SET
|
||||
`type` = :type,
|
||||
`date` = :now,
|
||||
`action` = :action,
|
||||
`user` = :user,
|
||||
`text` = :text"
|
||||
);
|
||||
|
||||
$ins_data = array(
|
||||
'type' => $type,
|
||||
'now' => $now,
|
||||
'action' => $action,
|
||||
'user' => $name
|
||||
);
|
||||
|
||||
if ($text != null
|
||||
&& $text != ''
|
||||
) {
|
||||
$ins_data['text'] = $text;
|
||||
Database::pexecute($stmt, $ins_data);
|
||||
} else {
|
||||
$ins_data['text'] = 'No text given!!! Check scripts!';
|
||||
Database::pexecute($stmt, $ins_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user