diff --git a/addhost.php b/addhost.php
index 56e35765c..975880380 100755
--- a/addhost.php
+++ b/addhost.php
@@ -192,7 +192,7 @@ if (!empty($argv[1]))
}
}
-print Console_Color::convert("\n" . $config['project_name_version']." Add Host Tool
+print $console_color->convert("\n" . $config['project_name_version']." Add Host Tool
Usage (SNMPv1/2c): ./addhost.php <%Whostname%n> [community] [v1|v2c] [port] [" . implode("|",$config['snmp']['transports']) . "]
Usage (SNMPv3) : Config Defaults : ./addhost.php <%Whostname%n> any v3 [user] [port] [" . implode("|",$config['snmp']['transports']) . "]
diff --git a/html/api_v0.php b/html/api_v0.php
index cc53e81b7..79c75a5e9 100644
--- a/html/api_v0.php
+++ b/html/api_v0.php
@@ -16,7 +16,6 @@ include_once("../includes/defaults.inc.php");
include_once("../config.php");
include_once("../includes/definitions.inc.php");
include_once("../includes/common.php");
-include_once("../includes/console_colour.php");
include_once("../includes/dbFacile.php");
include_once("../includes/rewrites.php");
include_once("includes/functions.inc.php");
diff --git a/html/graph.php b/html/graph.php
index 8051e01a5..95cf00b21 100755
--- a/html/graph.php
+++ b/html/graph.php
@@ -54,6 +54,8 @@ include_once("includes/authenticate.inc.php");
include("includes/graphs/graph.inc.php");
+$console_color = new Console_Color2();
+
$end = utime(); $run = $end - $start;;
if($debug) { echo("
Runtime ".$run." secs");
diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php
index 2c6aeab54..a8708e7fa 100644
--- a/html/includes/functions.inc.php
+++ b/html/includes/functions.inc.php
@@ -547,7 +547,7 @@ function getlocations()
$ignore_dev_location[$row['device_id']] = 1;
}
# We can do this because of the ORDER BY, "bool" will be handled before "string"
- elseif ($row['attrib_type'] == 'override_sysLocation_string' && $ignore_dev_location[$row['device_id']] == 1)
+ elseif ($row['attrib_type'] == 'override_sysLocation_string' && (isset($ignore_dev_location[$row['device_id']]) && $ignore_dev_location[$row['device_id']] == 1))
{
if (!in_array($row['attrib_value'],$locations)) { $locations[] = $row['attrib_value']; }
}
@@ -564,7 +564,7 @@ function getlocations()
foreach ($rows as $row)
{
# Only add it as a location if it wasn't overridden (and not already there)
- if ($row['location'] != '' && !$ignore_dev_location[$row['device_id']])
+ if ($row['location'] != '' && !isset($ignore_dev_location[$row['device_id']]))
{
if (!in_array($row['location'],$locations)) { $locations[] = $row['location']; }
}
diff --git a/html/includes/hostbox.inc.php b/html/includes/hostbox.inc.php
index 454039adf..8d3115bb6 100644
--- a/html/includes/hostbox.inc.php
+++ b/html/includes/hostbox.inc.php
@@ -1,6 +1,6 @@
");
}
-echo("
Errored ('.$ports['errored'].')');
}
-if ($ports['ignored'])
+if (isset($ports['ignored']))
{
echo('
Ignored ('.$ports['ignored'].')
",errors);
} else { $error_img = ""; }
diff --git a/includes/common.php b/includes/common.php
index bff445574..71da214be 100644
--- a/includes/common.php
+++ b/includes/common.php
@@ -59,9 +59,10 @@ function isCli()
function print_error($text)
{
+ global $console_color;
if (isCli())
{
- print Console_Color::convert("%r".$text."%n\n", false);
+ print $console_color->convert("%r".$text."%n\n", false);
} else {
echo('
'.$text.'
'.$text.'
+ *
* text text background
* ------------------------------------------------
* %k %K %0 black dark grey black
@@ -209,23 +210,22 @@ class Console_Color
* @param string $string String to convert
* @param bool $colored Should the string be colored?
*
- * @access public
* @return string
*/
- function convert($string, $colored = true)
+ public function convert($string, $colored = true)
{
static $conversions = array ( // static so the array doesn't get built
// everytime
// %y - yellow, and so on... {{{
- '%y' => array('color' => 'yellow'),
- '%g' => array('color' => 'green' ),
- '%b' => array('color' => 'blue' ),
- '%r' => array('color' => 'red' ),
- '%p' => array('color' => 'purple'),
- '%m' => array('color' => 'purple'),
- '%c' => array('color' => 'cyan' ),
- '%w' => array('color' => 'grey' ),
- '%k' => array('color' => 'black' ),
+ '%y' => array('color' => 'yellow', 'style' => 'normal'),
+ '%g' => array('color' => 'green', 'style' => 'normal'),
+ '%b' => array('color' => 'blue', 'style' => 'normal'),
+ '%r' => array('color' => 'red', 'style' => 'normal'),
+ '%p' => array('color' => 'purple', 'style' => 'normal'),
+ '%m' => array('color' => 'purple', 'style' => 'normal'),
+ '%c' => array('color' => 'cyan', 'style' => 'normal'),
+ '%w' => array('color' => 'grey', 'style' => 'normal'),
+ '%k' => array('color' => 'black', 'style' => 'normal'),
'%n' => array('color' => 'reset' ),
'%Y' => array('color' => 'yellow', 'style' => 'light'),
'%G' => array('color' => 'green', 'style' => 'light'),
@@ -257,7 +257,7 @@ class Console_Color
if ($colored) {
$string = str_replace('%%', '% ', $string);
foreach ($conversions as $key => $value) {
- $string = str_replace($key, Console_Color::color($value),
+ $string = str_replace($key, $this->color($value),
$string);
}
$string = str_replace('% ', '%', $string);
@@ -271,13 +271,12 @@ class Console_Color
/**
* Escapes % so they don't get interpreted as color codes
- *
+ *
* @param string $string String to escape
*
- * @access public
* @return string
*/
- function escape($string)
+ public function escape($string)
{
return str_replace('%', '%%', $string);
}
@@ -290,10 +289,9 @@ class Console_Color
* @acess public
* @return string
*/
- function strip($string)
+ public function strip($string)
{
return preg_replace('/\033\[[\d;]+m/', '', $string);
}
}
-?>
diff --git a/includes/dbFacile.php b/includes/dbFacile.php
index 42810dcef..9d25c4cad 100644
--- a/includes/dbFacile.php
+++ b/includes/dbFacile.php
@@ -22,16 +22,15 @@ Usage
* Used by the other _query functions.
* */
function dbQuery($sql, $parameters = array()) {
- global $fullSql, $debug, $sql_debug;
+ global $fullSql, $debug, $sql_debug, $console_color;
$fullSql = dbMakeQuery($sql, $parameters);
if($debug) {
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
- print Console_Color::convert("\nSQL[%y".$fullSql."%n] ");
+ print $console_color->convert("\nSQL[%y".$fullSql."%n] ");
} else {
$sql_debug[] = $fullSql;
}
- #echo("\nSQL[".$fullSql."] ");
- }
+ }
/*
if($this->logFile)
diff --git a/includes/functions.php b/includes/functions.php
index c2a8eedd4..161757107 100755
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -30,6 +30,8 @@ include_once($config['install_dir'] . "/includes/services.inc.php");
include_once($config['install_dir'] . "/includes/dbFacile.php");
include_once($config['install_dir'] . "/includes/console_colour.php");
+$console_color = new Console_Color2();
+
if ($config['alerts']['email']['enable'])
{
include_once($config['install_dir'] . "/includes/phpmailer/class.phpmailer.php");
@@ -161,7 +163,7 @@ function getImage($device)
{
$image = '
';
}
- elseif ($config['os'][$device['os']]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$device['os']]['icon'] . ".png"))
+ elseif (isset($config['os'][$device['os']]['icon']) && $config['os'][$device['os']]['icon'] && file_exists($config['html_dir'] . "/images/os/" . $config['os'][$device['os']]['icon'] . ".png"))
{
$image = '
';
} else {
diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php
index c8f197ee0..3b23be7e9 100644
--- a/includes/rrdtool.inc.php
+++ b/includes/rrdtool.inc.php
@@ -148,7 +148,7 @@ function rrdtool_graph($graph_file, $options)
function rrdtool($command, $filename, $options)
{
- global $config, $debug, $rrd_pipes;
+ global $config, $debug, $rrd_pipes, $console_color;
$cmd = "$command $filename $options";
if ($command != "create" && $config['rrdcached'])
@@ -158,7 +158,7 @@ function rrdtool($command, $filename, $options)
if ($config['norrd'])
{
- print Console_Color::convert("[%rRRD Disabled%n]");
+ print $console_color->convert("[%rRRD Disabled%n]");
} else {
fwrite($rrd_pipes[0], $cmd."\n");
}
@@ -166,7 +166,7 @@ function rrdtool($command, $filename, $options)
{
echo stream_get_contents($rrd_pipes[1]);
echo stream_get_contents($rrd_pipes[2]);
- print Console_Color::convert("RRD[%g".$cmd."%n] ");
+ print $console_color->convert("RRD[%g".$cmd."%n] ");
} else {
$tmp = stream_get_contents($rrd_pipes[1]).stream_get_contents($rrd_pipes[2]);
}
@@ -182,15 +182,15 @@ function rrdtool($command, $filename, $options)
function rrdtool_create($filename, $options)
{
- global $config, $debug;
+ global $config, $debug, $console_color;
if ($config['norrd'])
{
- print Console_Color::convert("[%gRRD Disabled%n] ", false);
+ print $console_color->convert("[%gRRD Disabled%n] ", false);
} else {
$command = $config['rrdtool'] . " create $filename $options";
}
- if ($debug) { print Console_Color::convert("RRD[%g".$command."%n] "); }
+ if ($debug) { print $console_color->convert("RRD[%g".$command."%n] "); }
return shell_exec($command);
}
diff --git a/scripts/console-ui.php b/scripts/console-ui.php
index d4325745a..566b94dd4 100755
--- a/scripts/console-ui.php
+++ b/scripts/console-ui.php
@@ -9,6 +9,8 @@ include_once("../includes/definitions.inc.php");
include("../includes/functions.php");
include("../html/includes/functions.inc.php");
+$console_color = new Console_Color2();
+
$long_opts = array('list::','device-stats');
$options = getopt("l:d:",$long_opts);
@@ -36,9 +38,9 @@ while($end == 0)
// Include the required SQL queries to get our data
require('../includes/db/status_count.inc.php');
- $tbl->addRow(array('Devices ('.$devices['count'].')',Console_Color::convert("%g".$devices['up']." Up%n"),Console_Color::convert("%r".$devices['down']." Down%n"),Console_Color::convert("%y".$devices['ignored']." Ignored%n"),Console_Color::convert("%p".$devices['disabled']." Disabled%n")));
- $tbl->addRow(array('Ports ('.$ports['count'].')',Console_Color::convert("%g".$ports['up']." Up%n"),Console_Color::convert("%r".$ports['down']." Down%n"),Console_Color::convert("%y".$ports['ignored']." Ignored%n"),Console_Color::convert("%p".$ports['shutdown']." Shutdown%n")));
- $tbl->addRow(array('Services ('.$services['count'].')',Console_Color::convert("%g".$services['up']." Up%n"),Console_Color::convert("%r".$services['down']." Down%n"),Console_Color::convert("%y".$services['ignored']." Ignored%n"),Console_Color::convert("%p".$services['disabled']." Shutdown%n")));
+ $tbl->addRow(array('Devices ('.$devices['count'].')',print $console_color->convert("%g".$devices['up']." Up%n"),print $console_color->convert("%r".$devices['down']." Down%n"),print $console_color->convert("%y".$devices['ignored']." Ignored%n"),print $console_color->convert("%p".$devices['disabled']." Disabled%n")));
+ $tbl->addRow(array('Ports ('.$ports['count'].')',print $console_color->convert("%g".$ports['up']." Up%n"),print $console_color->convert("%r".$ports['down']." Down%n"),print $console_color->convert("%y".$ports['ignored']." Ignored%n"),print $console_color->convert("%p".$ports['shutdown']." Shutdown%n")));
+ $tbl->addRow(array('Services ('.$services['count'].')',print $console_color->convert("%g".$services['up']." Up%n"),print $console_color->convert("%r".$services['down']." Down%n"),print $console_color->convert("%y".$services['ignored']." Ignored%n"),print $console_color->convert("%p".$services['disabled']." Shutdown%n")));
echo $tbl->getTable();
@@ -129,7 +131,7 @@ while($end == 0)
");
exit;
}
- echo(Console_Color::convert("%rLast update at ". date("Y-m-d h:i:s")."%n\n\n"));
+ echo(print $console_color->convert("%rLast update at ". date("Y-m-d h:i:s")."%n\n\n"));
sleep(5);
}