Source for file Common.php
Documentation is available at Common.php
* LICENSE: This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation.
* @author Hector Ortiz (FreeNAC Core Team)
* @copyright 2007 FreeNAC
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License Version 2
* @link http://www.freenac.net
* Define this common parent class to ensure consistent logging and access to configuration settings.
* This class can be extended with 'common' code to simplify derived classes and ensure consistency.
public $conf, $logger, $db_conn; // allow access outside derived classes, ideally would be read-only
* Get the current instance of our Settings and Logger classes
* Connect to database via mysqli
global $dbhost, $dbuser, $dbpass, $dbname;
$this->db_conn =
new mysqli($dbhost, $dbuser, $dbpass, $dbname);
//$this->logger->debug( get_class($this). " getConnection() to {$dbname} on $dbhost.", 3);
if ($in_db_conn ===
NULL and isset
($conn))
* htmlescape: escape date before outputting to a Browser
#return htmlentities($in_string, ENT_QUOTES, 'UTF-8');
* sqlescape: call real_escape_string1 with DB connection
public function sqlescape ($in_string, $in_removePct=
FALSE)
$conn=
$this->getConnection(); // make sure we have a DB connection
* Escape possibly dangerous characters, to prevent SQL injection
* Trim leading/trailing spaces too
$this->logger->debug("real_escape_string1: in_string=$in_string,", 3);
// mysqli: prepends backslashes to: \x00, \n, \r, \, ', " and \x1a
$str =
$in_conn->real_escape_string($str);
if ($in_removePct) // escape %
$this->logger->debug("real_escape_string1: ret=$str", 3);
* Write key events to naclog which is visible from the GUI
* To view recent entries:
* select * from naclog ORDER BY datetime DESC LIMIT 5;
* @param mixed $level Level of severity of the message
* @param mixed $msg Message to log
function log2db($level=
'info', $msg=
'')
$conn=
$this->getConnection(); // make sure we have a DB connection
if (isset
($_SERVER['HOSTNAME']))
$host=
$_SERVER['HOSTNAME'];
else if (isset
($_ENV['HOSTNAME']))
$q=
"insert into naclog set what='" .
sqlescape($msg)
.
"', host='$host', priority='$level'";
Documentation generated on Mon, 17 Nov 2008 01:10:27 +0100 by phpDocumentor 1.4.0