New upstream version 0.6.27

This commit is contained in:
geos_one
2025-08-06 18:11:51 +02:00
parent a6b4158f1f
commit 56a986c0ba
563 changed files with 45811 additions and 35282 deletions

View File

@@ -1,154 +1,185 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
<?php
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
// phpcs:disable PSR1.Files.SideEffects
defined('SYSPATH') or die('No direct access allowed.');
// phpcs:enable PSR1.Files.SideEffects
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
/**
* Retrieves the PNP config files
* Retrieves the PNP config files
*/
class Auth_Model extends System_Model {
public $SOCKET = NULL;
public $socketPath = NULL;
public $socketDOMAIN = NULL;
public $socketTYPE = NULL;
public $socketHOST = NULL;
public $socketPORT = 0;
public $socketPROTO = NULL;
class Auth_Model extends System_Model
{
public $SOCKET = null;
public $ERR_TXT = "";
public $AUTH_ENABLED = FALSE;
public $REMOTE_USER = NULL;
public $socketPath = null;
public function __construct() {
$this->config = new Config_Model;
public $socketDOMAIN = null;
public $socketTYPE = null;
public $socketHOST = null;
public $socketPORT = 0;
public $socketPROTO = null;
public $ERR_TXT = '';
public $AUTH_ENABLED = false;
public $REMOTE_USER = null;
public $config = '';
public function __construct()
{
$this->config = new Config_Model();
$this->config->read_config();
if($this->config->conf['auth_enabled'] == 1){
$this->AUTH_ENABLED = TRUE;
$this->socketPath = $this->config->conf['livestatus_socket'];
if ($this->config->conf['auth_enabled'] == 1) {
$this->AUTH_ENABLED = true;
$this->socketPath = $this->config->conf['livestatus_socket'];
}
// Try to get the login of the user
if(isset($_SERVER['REMOTE_USER'])){
if (isset($_SERVER['REMOTE_USER'])) {
$this->REMOTE_USER = $_SERVER['REMOTE_USER'];
}
if($this->REMOTE_USER === NULL && $this->config->conf['auth_multisite_enabled'] == 1) {
$MSAUTH = new Auth_Multisite_Model($this->config->conf['auth_multisite_htpasswd'],
$this->config->conf['auth_multisite_serials'],
$this->config->conf['auth_multisite_secret'],
$this->config->conf['auth_multisite_login_url']);
if ($this->REMOTE_USER === null && $this->config->conf['auth_multisite_enabled'] == 1) {
$MSAUTH = new Auth_Multisite_Model(
$this->config->conf['auth_multisite_htpasswd'],
$this->config->conf['auth_multisite_serials'],
$this->config->conf['auth_multisite_secret'],
$this->config->conf['auth_multisite_login_url']
);
$this->REMOTE_USER = $MSAUTH->check();
if($this->REMOTE_USER !== null)
if ($this->REMOTE_USER !== null) {
return;
}
}
if($this->AUTH_ENABLED === TRUE && $this->REMOTE_USER === NULL){
throw new Kohana_exception("error.remote_user_missing");
if ($this->AUTH_ENABLED === true && $this->REMOTE_USER === null) {
throw new Kohana_exception('error.remote_user_missing');
}
}
//end __construct()
public function __destruct() {
if($this->SOCKET !== NULL) {
public function __destruct()
{
if ($this->SOCKET !== null) {
socket_close($this->SOCKET);
$this->SOCKET = NULL;
$this->SOCKET = null;
}
}
//end __destruct()
public function connect(){
$this->getSocketDetails($this->socketPath);
public function connect()
{
$this->getSocketDetails($this->socketPath);
$this->SOCKET = socket_create($this->socketDOMAIN, $this->socketTYPE, $this->socketPROTO);
if($this->SOCKET === FALSE) {
throw new Kohana_exception("error.livestatus_socket_error", socket_strerror(socket_last_error($this->SOCKET)), $this->socketPath);
if ($this->SOCKET === false) {
throw new Kohana_exception('error.livestatus_socket_error', socket_strerror(socket_last_error($this->SOCKET)), $this->socketPath);
}
if($this->socketDOMAIN === AF_UNIX){
$result = @socket_connect($this->SOCKET, $this->socketPATH);
}else{
$result = @socket_connect($this->SOCKET, $this->socketHOST, $this->socketPORT);
}
if(!$result) {
throw new Kohana_exception("error.livestatus_socket_error", socket_strerror(socket_last_error($this->SOCKET)), $this->socketPath);
if ($this->socketDOMAIN === AF_UNIX) {
$result = @socket_connect($this->SOCKET, $this->socketPATH);
} else {
$result = @socket_connect($this->SOCKET, $this->socketHOST, $this->socketPORT);
}
if (!$result) {
throw new Kohana_exception('error.livestatus_socket_error', socket_strerror(socket_last_error($this->SOCKET)), $this->socketPath);
}
}
//end connect()
private function queryLivestatus($query) {
if($this->SOCKET === NULL) {
private function queryLivestatus($query)
{
if ($this->SOCKET === null) {
$this->connect();
}
@socket_write($this->SOCKET, $query."\nOutputFormat: json\n\n");
@socket_write($this->SOCKET, $query . "\nOutputFormat: json\n\n");
// Read 16 bytes to get the status code and body size
$read = @socket_read($this->SOCKET,2048);
if(!$read) {
throw new Kohana_exception("error.livestatus_socket_error", socket_strerror(socket_last_error($this->SOCKET)));
$read = @socket_read($this->SOCKET, 2048);
if (!$read) {
throw new Kohana_exception('error.livestatus_socket_error', socket_strerror(socket_last_error($this->SOCKET)));
}
# print Kohana::debug("read ". $read);
// print Kohana::debug("read ". $read);
// Catch problem while reading
if($read === false) {
throw new Kohana_exception("error.livestatus_socket_error", socket_strerror(socket_last_error($this->SOCKET)));
if ($read === false) {
throw new Kohana_exception('error.livestatus_socket_error', socket_strerror(socket_last_error($this->SOCKET)));
}
// Decode the json response
$obj = json_decode(utf8_encode($read));
socket_close($this->SOCKET);
$this->SOCKET = NULL;
$this->SOCKET = null;
return $obj;
}
//end queryLivestatus()
public function is_authorized($host = FALSE, $service = NULL){
if($this->AUTH_ENABLED === FALSE){
return TRUE;
public function is_authorized($host = false, $service = null)
{
if ($this->AUTH_ENABLED === false) {
return true;
}
if($host == "pnp-internal"){
return TRUE;
if ($host == 'pnp-internal') {
return true;
}
if($service === NULL || $service == "_HOST_" || $service == "Host Perfdata"){
$users = explode(",", $this->config->conf['allowed_for_all_hosts']);
if ($service === null || $service == '_HOST_' || $service == 'Host Perfdata') {
$users = explode(',', $this->config->conf['allowed_for_all_hosts']);
if (in_array($this->REMOTE_USER, $users)) {
return TRUE;
return true;
}
$query = "GET hosts\nColumns: name\nFilter: name = $host\nAuthUser: ".$this->REMOTE_USER;
$query = "GET hosts\nColumns: name\nFilter: name = $host\nAuthUser: " . $this->REMOTE_USER;
$result = $this->queryLivestatus($query);
}else{
$users = explode(",", $this->config->conf['allowed_for_all_services']);
} else {
$users = explode(',', $this->config->conf['allowed_for_all_services']);
if (in_array($this->REMOTE_USER, $users)) {
return TRUE;
return true;
}
$query = "GET services\nColumns: host_name description\nFilter: host_name = $host\nFilter: description = $service\nAuthUser: ".$this->REMOTE_USER;
$query = "GET services\nColumns: host_name description\nFilter: host_name = $host\nFilter: description = $service\nAuthUser: " . $this->REMOTE_USER;
$result = $this->queryLivestatus($query);
}
if(sizeof($result) > 0){
return TRUE;
}else{
return FALSE;
}
return (!empty($result));
}
//end is_authorized()
public function getSocketDetails($string=FALSE){
if(preg_match('/^unix:(.*)$/',$string,$match) ){
$this->socketDOMAIN = AF_UNIX;
$this->socketTYPE = SOCK_STREAM;
$this->socketPATH = $match[1];
$this->socketPROTO = 0;
return;
}
if(preg_match('/^tcp:([a-zA-Z0-9-\.]+):([0-9]+)$/',$string,$match) ){
$this->socketDOMAIN = AF_INET;
$this->socketTYPE = SOCK_STREAM;
$this->socketHOST = $match[1];
$this->socketPORT = $match[2];
$this->socketPROTO = SOL_TCP;
return;
}
# Fallback
if(preg_match('/^\/.*$/',$string,$match) ){
$this->socketDOMAIN = AF_UNIX;
$this->socketTYPE = SOCK_STREAM;
$this->socketPATH = $string;
$this->socketPROTO = 0;
return;
}
return FALSE;
}
public function getSocketDetails($string = false)
{
if (preg_match('/^unix:(.*)$/', $string, $match)) {
$this->socketDOMAIN = AF_UNIX;
$this->socketTYPE = SOCK_STREAM;
$this->socketPATH = $match[1];
$this->socketPROTO = 0;
return;
}
if (preg_match('/^tcp:([a-zA-Z0-9-\.]+):([0-9]+)$/', $string, $match)) {
$this->socketDOMAIN = AF_INET;
$this->socketTYPE = SOCK_STREAM;
$this->socketHOST = $match[1];
$this->socketPORT = $match[2];
$this->socketPROTO = SOL_TCP;
return;
}
// Fallback
if (preg_match('/^\/.*$/', $string, $match)) {
$this->socketDOMAIN = AF_UNIX;
$this->socketTYPE = SOCK_STREAM;
$this->socketPATH = $string;
$this->socketPROTO = 0;
return;
}
return false;
}
//end getSocketDetails()
}
//end class

View File

@@ -1,13 +1,24 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
<?php
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
// phpcs:disable PSR1.Files.SideEffects
defined('SYSPATH') or die('No direct access allowed.');
// phpcs:enable PSR1.Files.SideEffects
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
class Auth_Multisite_Model {
class Auth_Multisite_Model
{
private $htpasswdPath;
private $serialsPath;
private $secretPath;
private $authFile;
public function __construct($htpasswdPath, $serialsPath, $secretPath, $loginUrl) {
public function __construct($htpasswdPath, $serialsPath, $secretPath, $loginUrl)
{
$this->htpasswdPath = $htpasswdPath;
$this->serialsPath = $serialsPath;
$this->secretPath = $secretPath;
@@ -16,96 +27,120 @@ class Auth_Multisite_Model {
// When the auth.serial file exists, use this instead of the htpasswd
// for validating the cookie. The structure of the file is equal, so
// the same code can be used.
if(file_exists($this->serialsPath)) {
if (file_exists($this->serialsPath)) {
$this->authFile = 'serial';
} elseif(file_exists($this->htpasswdPath)) {
} elseif (file_exists($this->htpasswdPath)) {
$this->authFile = 'htpasswd';
} else {
throw new Kohana_exception("error.auth_multisite_missing_htpasswd");
throw new Kohana_exception('error.auth_multisite_missing_htpasswd');
}
if(!file_exists($this->secretPath)) {
if (!file_exists($this->secretPath)) {
$this->redirectToLogin();
}
}
//end __construct()
private function loadAuthFile($path) {
$creds = array();
foreach(file($path) AS $line) {
if(strpos($line, ':') !== false) {
private function loadAuthFile($path)
{
$creds = [];
foreach (file($path) as $line) {
if (strpos($line, ':') !== false) {
list($username, $secret) = explode(':', $line, 2);
$creds[$username] = rtrim($secret);
$creds[$username] = rtrim($secret);
}
}
return $creds;
}
//end loadAuthFile()
private function loadSecret() {
private function loadSecret()
{
return trim(file_get_contents($this->secretPath));
}
//end loadSecret()
private function generateHash($username, $now, $user_secret) {
private function generateHash($username, $now, $user_secret)
{
$secret = $this->loadSecret();
return md5($username . $now . $user_secret . $secret);
}
//end generateHash()
private function checkAuthCookie($cookieName) {
if(!isset($_COOKIE[$cookieName]) || $_COOKIE[$cookieName] == '') {
private function checkAuthCookie($cookieName)
{
if (!isset($_COOKIE[$cookieName]) || $_COOKIE[$cookieName] == '') {
throw new Exception();
}
list($username, $issueTime, $cookieHash) = explode(':', $_COOKIE[$cookieName], 3);
$cookie = $_COOKIE[$cookieName];
if ($cookie[0] == '"') {
$cookie = trim($cookie, '"');
}
list($username, $issueTime, $cookieHash) = explode(':', $cookie, 3);
if($this->authFile == 'htpasswd')
if ($this->authFile == 'htpasswd') {
$users = $this->loadAuthFile($this->htpasswdPath);
else
} else {
$users = $this->loadAuthFile($this->serialsPath);
}
if(!isset($users[$username])) {
if (!isset($users[$username])) {
throw new Exception();
}
$user_secret = $users[$username];
// Validate the hash
if($cookieHash != $this->generateHash($username, $issueTime, $user_secret)) {
if ($cookieHash != $this->generateHash($username, $issueTime, $user_secret)) {
throw new Exception();
}
// FIXME: Maybe renew the cookie here too
return $username;
}
//end checkAuthCookie()
private function checkAuth() {
private function checkAuth()
{
// Loop all cookies trying to fetch a valid authentication
// cookie for this installation
foreach(array_keys($_COOKIE) AS $cookieName) {
if(substr($cookieName, 0, 5) != 'auth_') {
foreach (array_keys($_COOKIE) as $cookieName) {
if (substr($cookieName, 0, 5) != 'auth_') {
continue;
}
try {
$name = $this->checkAuthCookie($cookieName);
return $name;
} catch(Exception $e) {}
} catch (Exception $e) {
}
}
return '';
}
//end checkAuth()
private function redirectToLogin() {
private function redirectToLogin()
{
header('Location:' . $this->loginUrl . '?_origtarget=' . $_SERVER['REQUEST_URI']);
}
//end redirectToLogin()
public function check() {
public function check()
{
$username = $this->checkAuth();
if($username === '') {
if ($username === '') {
$this->redirectToLogin();
exit(0);
}
return $username;
}
//end check()
}
?>
//end class

View File

@@ -1,7 +1,13 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
<?php
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
// phpcs:disable PSR1.Files.SideEffects
defined('SYSPATH') or die('No direct access allowed.');
// phpcs:enable PSR1.Files.SideEffects
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
/**
* Retrieves the PNP config files
* Retrieves the PNP config files
*/
class Config_Model extends System_Model
{
@@ -9,17 +15,19 @@ class Config_Model extends System_Model
public $views = array();
public $scheme = array();
public function read_config(){
if(getenv('PNP_CONFIG_FILE') != ""){
public function read_config()
{
if (getenv('PNP_CONFIG_FILE') != "") {
$config = getenv('PNP_CONFIG_FILE');
}elseif(OMD){
$config = OMD_SITE_ROOT.'/etc/pnp4nagios/config';
}else{
$config = Kohana::config('core.pnp_etc_path')."/config";
} elseif (OMD) {
$config = OMD_SITE_ROOT . '/etc/pnp4nagios/config';
} else {
$config = Kohana::config('core.pnp_etc_path') . "/config";
}
# Default Values
$conf['doc_language'] = Kohana::config('core.doc_language');
$conf['fontconfig_cache'] = Kohana::config('core.fontconfig_cache');
$conf['graph_width'] = Kohana::config('core.graph_width');
$conf['graph_height'] = Kohana::config('core.graph_height');
$conf['zgraph_width'] = Kohana::config('core.zgraph_width');
@@ -37,15 +45,15 @@ class Config_Model extends System_Model
$conf['auth_multisite_htpasswd'] = Kohana::config('core.auth_multisite_htpasswd');
$conf['auth_multisite_secret'] = Kohana::config('core.auth_multisite_secret');
$conf['auth_multisite_login_url'] = Kohana::config('core.auth_multisite_login_url');
$scheme['Reds'] = array ('#FEE0D2','#FCBBA1','#FC9272','#FB6A4A','#EF3B2C','#CB181D','#A50F15','#67000D');
$scheme['Reds'] = array ('#FEE0D2','#FCBBA1','#FC9272','#FB6A4A','#EF3B2C','#CB181D','#A50F15','#67000D');
$views = Kohana::config('core.views');
if (is_readable($config . ".php")) {
include ($config . ".php");
}else {
throw new Kohana_Exception('error.config-not-found', $config.'.php');
include($config . ".php");
} else {
throw new Kohana_Exception('error.config-not-found', $config . '.php');
}
// Load optional config files
@@ -56,19 +64,19 @@ class Config_Model extends System_Model
$dh = opendir($config . ".d");
while (($file = readdir($dh)) !== false) {
if ($file[0] != '.' && substr($file, -4) == '.php') {
$custom_configs[] = $config . ".d/" .$file;
$custom_configs[] = $config . ".d/" . $file;
}
}
closedir($dh);
}
foreach($custom_configs AS $config_file) {
foreach ($custom_configs as $config_file) {
if (is_readable($config_file)) {
$array_a = $views;
$views = array();
include ($config_file);
include($config_file);
$array_b = $views;
if(sizeof($views) == 0 ){
if (empty($views)) {
$views = $array_a;
}
}
@@ -77,10 +85,18 @@ class Config_Model extends System_Model
// Use graph_height & graph_width from URL if present
// Hint: In Kohana 3 Input class is removed
$input = Input::instance();
if($input->get('h') != "" ) $conf['graph_height'] = intval($input->get('h'));
if($input->get('w') != "" ) $conf['graph_width'] = intval($input->get('w'));
if($input->get('graph_height') != "" ) $conf['graph_height'] = intval($input->get('graph_height'));
if($input->get('graph_width') != "" ) $conf['graph_width'] = intval($input->get('graph_width'));
if ($input->get('h') != "") {
$conf['graph_height'] = intval($input->get('h'));
}
if ($input->get('w') != "") {
$conf['graph_width'] = intval($input->get('w'));
}
if ($input->get('graph_height') != "") {
$conf['graph_height'] = intval($input->get('graph_height'));
}
if ($input->get('graph_width') != "") {
$conf['graph_width'] = intval($input->get('graph_width'));
}
$this->conf = $conf;
$this->views = $views;
$this->scheme = $scheme;

File diff suppressed because it is too large Load Diff

View File

@@ -1,229 +1,287 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
<?php
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
// phpcs:disable PSR1.Files.SideEffects
defined('SYSPATH') or die('No direct access allowed.');
// phpcs:enable PSR1.Files.SideEffects
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
/**
* Retrieves and manipulates current status of hosts (and services?)
*/
class Rrdtool_Model extends System_Model
{
private $RRD_CMD = false;
private $RRD_CMD = FALSE;
/*
*
*
*/
public function __construct(){
public $config = '';
public function __construct()
{
$this->config = new Config_Model();
$this->config->read_config();
#print Kohana::debug($this->config->views);
// print Kohana::debug($this->config->views);
}
//end __construct()
private function rrdtool_execute() {
$descriptorspec = array (
0 => array ("pipe","r"), // stdin is a pipe that the child will read from
1 => array ("pipe","w"), // stdout is a pipe that the child will write to
2 => array ("pipe","w") // stderr is a pipe that the child will write to
);
if(!isset($this->config->conf['rrdtool']) )
return FALSE;
private function rrdtool_execute()
{
$descriptorspec = [
0 => [
'pipe',
'r',
],
// stdin is a pipe that the child will read from
1 => [
'pipe',
'w',
],
// stdout is a pipe that the child will write to
2 => [
'pipe',
'w',
],
// stderr is a pipe that the child will write to
];
if ( !is_executable($this->config->conf['rrdtool']) ) {
$data = "ERROR: ".$this->config->conf['rrdtool']." is not executable by PHP\n\n";
if (!isset($this->config->conf['rrdtool'])) {
return false;
}
if (!is_executable($this->config->conf['rrdtool'])) {
$data = 'ERROR: ' . $this->config->conf['rrdtool'] . " is not executable by PHP\n\n";
return $data;
}
$rrdtool = $this->config->conf['rrdtool'] . " - ";
$rrdtool = $this->config->conf['rrdtool'] . ' - ';
/*
this is needed by Fontconfig, used by pango, used by rrdtool graph
** it's automatically set up for 'interactive' sessions, but web servers
** don't have it (usually?). If there are 'red screens' instead of graphs,
** there's a good chance this is why */
$fc_cache = $this->config->conf['fontconfig_cache'];
putenv('XDG_CACHE_HOME=' . $fc_cache);
$xdg_cache = getenv('XDG_CACHE_HOME');
if (!$xdg_cache) {
$data = 'ERROR: environment var XDG_CACHE_HOME not defined (should be writable cache dir)';
return $data;
}
if (!is_dir($xdg_cache) || !is_writeable($xdg_cache)) {
$data = 'ERROR: env XDG_CACHE_HOME (' . $xdg_cache . ') is not writable directory';
return $data;
}
$command = $this->RRD_CMD;
$process = proc_open($rrdtool, $descriptorspec, $pipes);
$debug = Array();
$data = "";
$debug = [];
$data = '';
if (is_resource($process)) {
fwrite($pipes[0], $command);
fclose($pipes[0]);
stream_set_timeout($pipes[1],1);
$data = stream_get_contents($pipes[1]);
stream_set_timeout($pipes[2],1);
$stderr = stream_get_contents($pipes[2]);
stream_set_timeout($pipes[1], 1);
$data = stream_get_contents($pipes[1]);
stream_set_timeout($pipes[2], 1);
$stderr = stream_get_contents($pipes[2]);
$stdout_meta = stream_get_meta_data($pipes[1]);
if($stdout_meta['timed_out'] == 1){
if ($stdout_meta['timed_out'] == 1) {
$data = "ERROR: Timeout while reading rrdtool data.\n\n";
}
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
// Catch STDERR
if($stderr && strlen($stderr) >= 0 ){
$data = "ERROR: STDERR => ".$stderr."\n\n";
if ($stderr && strlen($stderr) >= 0) {
$data = 'ERROR: STDERR => ' . $stderr . "\n\n";
return $data;
}
// Catch STDOUT < 50 Characters
if($data && strlen($data) < 50 ){
$data = "ERROR: STDOUT => ".$data."\n\n";
if ($data && strlen($data) < 50) {
$data = 'ERROR: STDOUT => ' . $data . "\n\n";
return $data;
}
}else{
$data = "ERROR: proc_open(".$rrdtool." ... failed";
} else {
$data = 'ERROR: proc_open(' . $rrdtool . ' ... failed';
}
//end if
return $data;
}
//end rrdtool_execute()
public function doImage($RRD_CMD, $out='STDOUT') {
public function doImage($RRD_CMD, $out = 'STDOUT')
{
$conf = $this->config->conf;
# construct $command to rrdtool
if(isset($conf['RRD_DAEMON_OPTS']) && $conf['RRD_DAEMON_OPTS'] != '' ){
$command = " graph --daemon=" . $conf['RRD_DAEMON_OPTS'] . " - ";
}else{
$command = " graph - ";
// construct $command to rrdtool
if (isset($conf['RRD_DAEMON_OPTS']) && $conf['RRD_DAEMON_OPTS'] != '') {
$command = ' graph --daemon=' . $conf['RRD_DAEMON_OPTS'] . ' - ';
} else {
$command = ' graph - ';
}
$width = 0;
$width = 0;
$height = 0;
if ($out == 'PDF'){
if($conf['pdf_graph_opt']){
if ($out == 'PDF') {
if ($conf['pdf_graph_opt']) {
$command .= $conf['pdf_graph_opt'];
}
if (isset($conf['pdf_width']) && is_numeric($conf['pdf_width'])){
if (isset($conf['pdf_width']) && is_numeric($conf['pdf_width'])) {
$width = abs($conf['pdf_width']);
}
if (isset($conf['pdf_height']) && is_numeric($conf['pdf_height'])){
if (isset($conf['pdf_height']) && is_numeric($conf['pdf_height'])) {
$height = abs($conf['pdf_height']);
}
}else{
if($conf['graph_opt']){
} else {
if ($conf['graph_opt']) {
$command .= $conf['graph_opt'];
}
if(is_numeric($conf['graph_width'])){
if (is_numeric($conf['graph_width'])) {
$width = abs($conf['graph_width']);
}
if(is_numeric($conf['graph_height'])){
if (is_numeric($conf['graph_height'])) {
$height = abs($conf['graph_height']);
}
}
//end if
if ($width > 0){
if ($width > 0) {
$command .= " --width=$width";
}
if ($height > 0){
if ($height > 0) {
$command .= " --height=$height";
}
if ($height < 81 || (isset($conf['graph_only']) && $conf['graph_only'])){
$command .= " --only-graph";
}
elseif (isset($conf['no_legend']) && $conf['no_legend']){
$command .= " --no-legend";
if ($height < 81 || (isset($conf['graph_only']) && $conf['graph_only'])) {
$command .= ' --only-graph';
} elseif (isset($conf['no_legend']) && $conf['no_legend']) {
$command .= ' --no-legend';
}
$command .= $RRD_CMD;
# Force empty vertical label
if( ! preg_match_all('/(-l|--vertical-label)/i',$command,$match)){
// Force empty vertical label
if (! preg_match_all('/(-l|--vertical-label)/i', $command, $match)) {
$command .= " --vertical-label=' ' ";
}
$this->RRD_CMD = $command;
$data = $this->rrdtool_execute();
if($data){
$data = $this->rrdtool_execute();
if ($data) {
return $data;
}else{
return FALSE;
} else {
return false;
}
}
//end doImage()
/*
*
*/
public function doXport($RRD_CMD){
public function doXport($RRD_CMD)
{
$conf = $this->config->conf;
if(isset($conf['RRD_DAEMON_OPTS']) && $conf['RRD_DAEMON_OPTS'] != '' ){
$command = " xport --daemon=" . $conf['RRD_DAEMON_OPTS'];
}else{
$command = " xport ";
if (isset($conf['RRD_DAEMON_OPTS']) && $conf['RRD_DAEMON_OPTS'] != '') {
$command = ' xport --daemon=' . $conf['RRD_DAEMON_OPTS'];
} else {
$command = ' xport ';
}
$command .= $RRD_CMD;
$command .= $RRD_CMD;
$this->RRD_CMD = $command;
$data = $this->rrdtool_execute();
$data = preg_replace('/OK.*/','',$data);
if($data){
$data = $this->rrdtool_execute();
$data = preg_replace('/OK.*/', '', $data);
if ($data) {
return $data;
}else{
return FALSE;
} else {
return false;
}
}
//end doXport()
public function streamImage($data = FALSE){
if ( $data === FALSE ){
header("Content-type: image/png");
echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A
public function streamImage($data = false)
{
if ($data === false) {
header('Content-type: image/png');
echo base64_decode(
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A
/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9kCCAoDKSKZ0rEAAAAZdEVYdENv
bW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADUlEQVQI12NgYGBgAAAABQABXvMqOgAAAABJ
RU5ErkJggg==');
return;
RU5ErkJggg=='
);
return;
}
if (preg_match('/^ERROR/', $data)) {
if(preg_match('/NOT_AUTHORIZED/', $data)){
if (preg_match('/NOT_AUTHORIZED/', $data)) {
// TODO: i18n
$data .= "\n\nYou are not authorized to view this Image";
// Set font size
$font_size = 3;
}else{
$data .= $this->format_rrd_debug( $this->config->conf['rrdtool'] . $this->RRD_CMD) ;
} else {
$data .= $this->format_rrd_debug($this->config->conf['rrdtool'] . $this->RRD_CMD);
// Set font size
$font_size = 1.5;
$font_size = 2;
}
$ts=explode("\n",$data);
$width=0;
foreach ($ts as $k=>$string) {
$width=max($width,strlen($string));
$ts = explode("\n", $data);
$width = 0;
foreach ($ts as $k => $string) {
$width = max($width, strlen($string));
}
$width = imagefontwidth($font_size)*$width;
if($width <= $this->config->conf['graph_width']+100){
$width = $this->config->conf['graph_width']+100;
$width = imagefontwidth($font_size) * $width;
if ($width <= ($this->config->conf['graph_width'] + 100)) {
$width = ($this->config->conf['graph_width'] + 100);
}
$height = imagefontheight($font_size)*count($ts);
if($height <= $this->config->conf['graph_height']+60){
$height = $this->config->conf['graph_height']+60;
$height = imagefontheight($font_size) * count($ts);
if ($height <= ($this->config->conf['graph_height'] + 60)) {
$height = ($this->config->conf['graph_height'] + 60);
}
$el=imagefontheight($font_size);
$em=imagefontwidth($font_size);
$el = imagefontheight($font_size);
$em = imagefontwidth($font_size);
// Create the image pallette
$img = imagecreatetruecolor($width,$height);
$img = imagecreatetruecolor($width, $height);
// Dark red background
$bg = imagecolorallocate($img, 0xAA, 0x00, 0x00);
imagefilledrectangle($img, 0, 0,$width ,$height , $bg);
imagefilledrectangle($img, 0, 0, $width, $height, $bg);
// White font color
$color = imagecolorallocate($img, 255, 255, 255);
foreach ($ts as $k=>$string) {
foreach ($ts as $k => $string) {
// Length of the string
$len = strlen($string);
// Y-coordinate of character, X changes, Y is static
$ypos_offset = 5;
$xpos_offset = 5;
// Loop through the string
for($i=0;$i<$len;$i++){
for ($i = 0; $i < $len; $i++) {
// Position of the character horizontally
$xpos = $i * $em + $ypos_offset;
$ypos = $k * $el + $xpos_offset;
$xpos = ($i * $em + $ypos_offset);
$ypos = ($k * $el + $xpos_offset);
// Draw character
imagechar($img, $font_size, $xpos, $ypos, $string, $color);
// Remove character from string
$string = substr($string, 1);
$string = substr($string, 1);
}
}
header("Content-type: image/png");
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
}else{
header("Content-type: image/png");
} else {
header('Content-type: image/png');
echo $data;
}
//end if
}
//end streamImage()
public function saveImage($data = FALSE){
$img = array();
$img['file'] = tempnam($this->config->conf['temp'],"PNP");
if(!$fh = fopen($img['file'],'w') ){
public function saveImage($data = false)
{
$img = [];
$img['file'] = tempnam($this->config->conf['temp'], 'PNP');
if (!$fh = fopen($img['file'], 'w')) {
throw new Kohana_Exception('save-rrd-image', $img['file']);
}
fwrite($fh, $data);
@@ -232,15 +290,19 @@ class Rrdtool_Model extends System_Model
$image = imagecreatefrompng($img['file']);
imagepng($image, $img['file']);
list ($img['width'], $img['height'], $img['type'], $img['attr']) = getimagesize($img['file']);
}else{
} else {
throw new Kohana_Exception('error.gd-missing');
}
return $img;
}
//end saveImage()
private function format_rrd_debug($data) {
$data = preg_replace('/(HRULE|VDEF|DEF|CDEF|GPRINT|LINE|AREA|COMMENT)/',"\n\${1}", $data);
private function format_rrd_debug($data)
{
$data = preg_replace('/(HRULE|VDEF|DEF|CDEF|GPRINT|LINE|AREA|COMMENT)/', "\n\${1}", $data);
return $data;
}
}
//end format_rrd_debug()
}
//end class

View File

@@ -1,14 +1,19 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
<?php
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
// phpcs:disable PSR1.Files.SideEffects
defined('SYSPATH') or die('No direct access allowed.');
// phpcs:enable PSR1.Files.SideEffects
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
/**
* Retrieves the PNP config files
* Retrieves the PNP config files
*/
class System_Model extends Model {
public $ERROR = NULL;
public function __construct() {
class System_Model extends Model
{
public $ERROR = null;
public function __construct()
{
}
}