2019-02-07 16:24:49 +01:00
< ? php
/**
* Extension to self monitor Pandora FMS Console
*
* @ category Console Class
* @ package Pandora FMS
* @ subpackage Supervisor
* @ version 1.0 . 0
* @ license See below
*
* ______ ___ _______ _______ ________
* | __ \ .-----.--.--.--| |.-----.----.-----. | ___ | | | __ |
* | __ /| _ | | _ || _ | _ | _ | | ___ | | __ |
* | ___ | | ___ . _ | __ | __ | _____ || _____ | __ | | ___ . _ | | ___ | | __ | _ | __ | _______ |
*
* ============================================================================
2020-11-27 13:52:35 +01:00
* Copyright ( c ) 2005 - 2021 Artica Soluciones Tecnologicas
2019-02-07 16:24:49 +01:00
* Please see http :// pandorafms . org for full contribution list
* 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 for version 2.
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* ============================================================================
*/
global $config ;
2019-02-07 18:00:51 +01:00
require_once $config [ 'homedir' ] . '/include/functions_db.php' ;
2019-02-07 16:24:49 +01:00
require_once $config [ 'homedir' ] . '/include/functions_io.php' ;
require_once $config [ 'homedir' ] . '/include/functions_notifications.php' ;
require_once $config [ 'homedir' ] . '/include/functions_servers.php' ;
2021-06-14 13:56:42 +02:00
require_once $config [ 'homedir' ] . '/godmode/um_client/vendor/autoload.php' ;
2019-02-07 16:24:49 +01:00
// Enterprise includes.
enterprise_include_once ( 'include/functions_metaconsole.php' );
enterprise_include_once ( 'include/functions_license.php' );
2019-03-27 11:06:57 +01:00
enterprise_include_once ( 'include/functions_cron.php' );
2019-02-07 16:24:49 +01:00
/**
* Base class to run scheduled tasks in cron extension
*/
class ConsoleSupervisor
{
2021-01-11 18:32:44 +01:00
/**
* Minimum modules to check performance .
*/
public const MIN_PERFORMANCE_MODULES = 100 ;
2019-02-07 16:24:49 +01:00
/**
* Show if console supervisor is enabled or not .
*
* @ var boolean
*/
public $enabled ;
/**
* Value of 'id' from tnotification_source
* where description is 'System status'
*
* @ var integer
*/
public $sourceId ;
/**
* Target groups to be notified .
*
* @ var array
*/
public $targetGroups ;
/**
* Target users to be notified .
*
* @ var array
*/
public $targetUsers ;
/**
* Targets up to date .
*
* @ var boolean
*/
public $targetUpdated ;
/**
* Show messages or not .
*
* @ var boolean
*/
2020-11-26 11:28:31 +01:00
public $interactive ;
2019-02-07 16:24:49 +01:00
/**
* Constructor .
*
2020-11-26 11:28:31 +01:00
* @ param boolean $interactive Show output while executing or not .
2019-02-07 16:24:49 +01:00
*
* @ return class This object
*/
2020-11-26 11:28:31 +01:00
public function __construct ( bool $interactive = true )
2019-02-07 16:24:49 +01:00
{
$source = db_get_row (
'tnotification_source' ,
'description' ,
io_safe_input ( 'System status' )
);
2020-11-26 11:28:31 +01:00
$this -> interactive = $interactive ;
2019-02-07 16:24:49 +01:00
if ( $source === false ) {
$this -> enabled = false ;
$this -> sourceId = null ;
$this -> targetGroups = null ;
$this -> targetUsers = null ;
} else {
$this -> enabled = ( bool ) $source [ 'enabled' ];
$this -> sourceId = $source [ 'id' ];
}
return $this ;
}
/**
* Warn a message .
*
* @ param string $msg Message .
*
* @ return void
*/
public function warn ( string $msg )
{
if ( $this -> verbose === true ) {
echo date ( 'M j G:i:s' ) . ' ConsoleSupervisor: ' . $msg . " \n " ;
}
}
2019-02-22 18:12:01 +01:00
/**
* Manage scheduled tasks ( basic ) .
*
* @ return void
*/
public function runBasic ()
{
2021-01-27 19:23:31 +01:00
// Ensure functions are installed and up to date.
enterprise_hook ( 'cron_extension_install_functions' );
2019-02-22 18:12:01 +01:00
2019-02-23 00:01:59 +01:00
/*
* PHP configuration warnings :
2020-11-17 11:44:52 +01:00
* NOTIF . PHP . SAFE_MODE
* NOTIF . PHP . INPUT_TIME
* NOTIF . PHP . EXECUTION_TIME
* NOTIF . PHP . UPLOAD_MAX_FILESIZE
* NOTIF . PHP . MEMORY_LIMIT
* NOTIF . PHP . DISABLE_FUNCTIONS
* NOTIF . PHP . PHANTOMJS
* NOTIF . PHP . VERSION
2019-02-23 00:01:59 +01:00
*/
$this -> checkPHPSettings ();
2019-02-22 18:12:01 +01:00
/*
* Check license .
2020-11-17 11:44:52 +01:00
* NOTIF . LICENSE . EXPIRATION
2019-02-22 18:12:01 +01:00
*/
$this -> checkLicense ();
/*
* Check component statuses ( servers down - frozen ) .
2020-11-17 11:44:52 +01:00
* NOTIF . SERVER . STATUS . ID_SERVER
2019-02-22 18:12:01 +01:00
*/
$this -> checkPandoraServers ();
/*
* Check at least 1 server running in master mode .
2020-11-17 11:44:52 +01:00
* NOTIF . SERVER . MASTER
2019-02-22 18:12:01 +01:00
*/
$this -> checkPandoraServerMasterAvailable ();
/*
* Check if CRON is running .
2020-11-17 11:44:52 +01:00
* NOTIF . CRON . CONFIGURED
2019-02-22 18:12:01 +01:00
*/
if ( enterprise_installed ()) {
$this -> checkCronRunning ();
}
2019-05-14 17:15:28 +02:00
/*
* Check if instance is registered .
2020-11-17 11:44:52 +01:00
* NOTIF . UPDATEMANAGER . REGISTRATION
2019-05-14 17:15:28 +02:00
*/
$this -> checkUpdateManagerRegistration ();
/*
* Check if there ' re new messages in UM .
2020-11-17 11:44:52 +01:00
* NOTIF . UPDATEMANAGER . MESSAGES
2019-05-14 17:15:28 +02:00
*/
2019-05-14 23:49:01 +02:00
$this -> getUMMessages ();
2019-05-14 17:15:28 +02:00
2019-09-30 12:48:46 +02:00
/*
* Check if the Server and Console has
* the same versions .
2020-11-17 11:44:52 +01:00
* NOTIF . SERVER . MISALIGNED
2019-09-30 12:48:46 +02:00
*/
2020-10-07 18:48:17 +02:00
2019-09-30 12:48:46 +02:00
$this -> checkConsoleServerVersions ();
2020-04-07 18:40:47 +02:00
/*
* Check if AllowOverride is None or All .
* NOTIF . ALLOWOVERIDE . MESSAGE
*/
2020-10-07 18:48:17 +02:00
2020-04-07 18:40:47 +02:00
$this -> checkAllowOverrideEnabled ();
2020-06-08 10:48:48 +02:00
/*
* Check if the Pandora Console log
* file remains in old location .
2020-11-17 11:44:52 +01:00
* NOTIF . PANDORACONSOLE . LOG . OLD
2020-06-08 10:48:48 +02:00
*/
2020-10-07 18:48:17 +02:00
2020-06-08 10:48:48 +02:00
$this -> checkPandoraConsoleLogOldLocation ();
/*
* Check if the audit log file
* remains in old location .
2020-11-17 11:44:52 +01:00
* NOTIF . AUDIT . LOG . OLD
2020-06-08 10:48:48 +02:00
*/
2020-10-07 18:48:17 +02:00
2020-06-08 10:48:48 +02:00
$this -> checkAuditLogOldLocation ();
2019-02-22 18:12:01 +01:00
}
2019-02-07 16:24:49 +01:00
/**
* Manage scheduled tasks .
*
* @ return void
*/
public function run ()
{
global $config ;
2020-10-13 18:24:10 +02:00
$this -> maintenanceOperations ();
2019-02-07 16:24:49 +01:00
if ( $this -> enabled === false ) {
2020-10-13 18:24:10 +02:00
// Notifications not enabled.
2019-02-07 16:24:49 +01:00
return ;
}
if ( $this -> sourceId === null ) {
// Source not detected.
return ;
}
if ( $this -> verbose === true ) {
if ( enterprise_hook ( 'cron_supervisor_lock' ) === false ) {
// Cannot continue. Locked.
exit ;
}
}
// Enterprise support.
if ( file_exists ( $config [ 'homedir' ] . '/' . ENTERPRISE_DIR . '/load_enterprise.php' )) {
include_once $config [ 'homedir' ] . '/' . ENTERPRISE_DIR . '/load_enterprise.php' ;
}
// Automatic checks launched by supervisor.
$this -> warn ( 'running.' );
/*
* Check license .
2020-11-17 11:44:52 +01:00
* NOTIF . LICENSE . EXPIRATION
* NOTIF . LICENSE . LIMITED
2019-02-07 16:24:49 +01:00
*/
$this -> checkLicense ();
/*
* Check number of files in attachment :
2020-11-17 11:44:52 +01:00
* NOTIF . FILES . ATTACHMENT
2019-02-07 16:24:49 +01:00
*/
$this -> checkAttachment ();
/*
* Files in data_in :
2020-11-17 11:44:52 +01:00
* NOTIF . FILES . DATAIN ( > 1000 )
* NOTIF . FILES . DATAIN . BADXML ( > 150 )
2019-02-07 16:24:49 +01:00
*/
$this -> checkDataIn ();
/*
* Check module queues not growing :
2020-11-17 11:44:52 +01:00
* NOTIF . SERVER . QUEUE . ID_SERVER
2019-02-07 16:24:49 +01:00
*/
$this -> checkServers ();
/*
* Check component statuses ( servers down - frozen ) .
2020-11-17 11:44:52 +01:00
* NOTIF . SERVER . STATUS . ID_SERVER
2019-02-07 16:24:49 +01:00
*/
$this -> checkPandoraServers ();
/*
* Check at least 1 server running in master mode .
2020-11-17 11:44:52 +01:00
* NOTIF . SERVER . MASTER
2019-02-07 16:24:49 +01:00
*/
$this -> checkPandoraServerMasterAvailable ();
/*
* PHP configuration warnings :
2020-11-17 11:44:52 +01:00
* NOTIF . PHP . SAFE_MODE
* NOTIF . PHP . INPUT_TIME
* NOTIF . PHP . EXECUTION_TIME
* NOTIF . PHP . UPLOAD_MAX_FILESIZE
* NOTIF . PHP . MEMORY_LIMIT
* NOTIF . PHP . DISABLE_FUNCTIONS
* NOTIF . PHP . PHANTOMJS
* NOTIF . PHP . VERSION
2019-02-07 16:24:49 +01:00
*/
$this -> checkPHPSettings ();
/*
* Check connection with historical DB ( if enabled ) .
2020-11-17 11:44:52 +01:00
* NOTIF . HISTORYDB
2019-02-07 16:24:49 +01:00
*/
$this -> checkPandoraHistoryDB ();
/*
* Check pandoradb running in main DB .
* Check pandoradb running in historical DB .
2020-11-17 11:44:52 +01:00
* NOTIF . PANDORADB
* NOTIF . PANDORADB . HISTORICAL
2019-02-07 16:24:49 +01:00
*/
$this -> checkPandoraDBMaintenance ();
/*
* Check historical DB MR version .
2020-11-17 11:44:52 +01:00
* NOTIF . HISTORYDB . MR
2019-02-07 16:24:49 +01:00
*/
$this -> checkPandoraHistoryDBMR ();
/*
* Check external components .
2020-11-17 11:44:52 +01:00
* NOTIF . EXT . ELASTICSEARCH
* NOTIF . EXT . LOGSTASH
2019-02-07 16:24:49 +01:00
*
*/
$this -> checkExternalComponents ();
/*
* Check Metaconsole synchronization issues .
2020-11-17 11:44:52 +01:00
* NOTIF . METACONSOLE . DB_CONNECTION
2019-02-07 16:24:49 +01:00
*/
$this -> checkMetaconsole ();
/*
* Check incoming scheduled downtimes ( < 15 d ) .
2020-11-17 11:44:52 +01:00
* NOTIF . DOWNTIME
2019-02-07 16:24:49 +01:00
*/
$this -> checkDowntimes ();
/*
* Check if instance is registered .
2020-11-17 11:44:52 +01:00
* NOTIF . UPDATEMANAGER . REGISTRATION
2019-02-07 16:24:49 +01:00
*/
$this -> checkUpdateManagerRegistration ();
/*
* Check if event storm protection is activated .
2020-11-17 11:44:52 +01:00
* NOTIF . MISC . EVENTSTORMPROTECTION
2019-02-07 16:24:49 +01:00
*/
$this -> checkEventStormProtection ();
/*
* Check if develop_bypass is enabled .
2020-11-17 11:44:52 +01:00
* NOTIF . MISC . DEVELOPBYPASS
2019-02-07 16:24:49 +01:00
*/
$this -> checkDevelopBypass ();
/*
* Check if fontpath exists .
2020-11-17 11:44:52 +01:00
* NOTIF . MISC . FONTPATH
2019-02-07 16:24:49 +01:00
*/
$this -> checkFont ();
/*
* Check if default user and password exists .
2020-11-17 11:44:52 +01:00
* NOTIF . SECURITY . DEFAULT_PASSWORD
2019-02-07 16:24:49 +01:00
*/
$this -> checkDefaultPassword ();
/*
* Check if there ' re new updates .
2020-11-17 11:44:52 +01:00
* NOTIF . UPDATEMANAGER . OPENSETUP
* NOTIF . UPDATEMANAGER . UPDATE
2019-02-07 16:24:49 +01:00
*/
$this -> checkUpdates ();
2019-02-07 18:00:51 +01:00
/*
* Check if there ' re new minor updates available .
2020-11-17 11:44:52 +01:00
* NOTIF . UPDATEMANAGER . MINOR
2019-02-07 18:00:51 +01:00
*/
$this -> checkMinorRelease ();
2020-11-17 11:44:52 +01:00
if (( bool ) enterprise_installed () === true ) {
2019-02-07 16:24:49 +01:00
// Release the lock.
enterprise_hook ( 'cron_supervisor_release_lock' );
}
2019-02-19 14:36:16 +01:00
/*
* Check if CRON is running .
2020-11-17 11:44:52 +01:00
* NOTIF . CRON . CONFIGURED
2019-02-19 14:36:16 +01:00
*/
2019-02-22 18:12:01 +01:00
2019-02-19 14:36:16 +01:00
if ( enterprise_installed ()) {
$this -> checkCronRunning ();
}
2019-05-14 18:09:34 +02:00
/*
* Check if instance is registered .
2020-11-17 11:44:52 +01:00
* NOTIF . UPDATEMANAGER . REGISTRATION
2019-05-14 18:09:34 +02:00
*/
$this -> checkUpdateManagerRegistration ();
/*
* Check if there ' re new messages in UM .
2020-11-17 11:44:52 +01:00
* NOTIF . UPDATEMANAGER . MESSAGES
2019-05-14 18:09:34 +02:00
*/
2019-05-14 23:49:01 +02:00
$this -> getUMMessages ();
2019-09-30 12:48:46 +02:00
/*
* Check if the Server and Console has
* the same versions .
2020-11-17 11:44:52 +01:00
* NOTIF . SERVER . MISALIGNED
2019-09-30 12:48:46 +02:00
*/
2020-10-07 18:48:17 +02:00
2019-09-30 12:48:46 +02:00
$this -> checkConsoleServerVersions ();
2020-04-07 18:40:47 +02:00
/*
* Check if AllowOverride is None or All .
2020-11-17 11:44:52 +01:00
* NOTIF . ALLOWOVERRIDE . MESSAGE
2020-04-07 18:40:47 +02:00
*/
$this -> checkAllowOverrideEnabled ();
2020-10-07 18:48:17 +02:00
/*
* Check if HA status .
*/
2020-11-17 11:44:52 +01:00
if (( bool ) enterprise_installed () === true ) {
2020-06-02 13:55:01 +02:00
$this -> checkHaStatus ();
}
2020-05-25 17:49:23 +02:00
2020-06-08 10:48:48 +02:00
/*
* Check if the audit log file
* remains in old location .
*/
2020-10-07 18:48:17 +02:00
2020-06-08 10:48:48 +02:00
$this -> checkAuditLogOldLocation ();
2019-02-07 16:24:49 +01:00
}
2020-06-08 10:48:48 +02:00
2020-10-13 18:24:10 +02:00
/**
* Executes console maintenance operations . Executed ALWAYS through CRON .
*
* @ return void
*/
public function maintenanceOperations ()
{
2020-06-08 10:48:48 +02:00
/*
2020-10-13 18:24:10 +02:00
* Process cache clean if needed .
2020-10-07 18:48:17 +02:00
*/
2020-10-13 18:24:10 +02:00
$this -> checkCleanPhantomCache ();
2019-02-07 16:24:49 +01:00
}
/**
* Update targets for given notification using object targets .
*
2019-02-07 18:00:51 +01:00
* @ param array $notification Current notification .
2020-11-26 11:28:31 +01:00
* @ param boolean $send_mails Only update db targets , no email .
2019-02-07 16:24:49 +01:00
*
* @ return void
*/
2019-02-07 18:00:51 +01:00
public function updateTargets (
array $notification ,
2020-11-26 11:28:31 +01:00
bool $send_mails = true
2019-02-07 18:00:51 +01:00
) {
$notification_id = $notification [ 'id_mensaje' ];
2019-02-07 18:29:20 +01:00
$blacklist = [];
2019-02-07 18:00:51 +01:00
2019-02-07 16:24:49 +01:00
if ( is_array ( $this -> targetUsers ) === true
&& count ( $this -> targetUsers ) > 0
) {
// Process user targets.
$insertion_string = '' ;
$users_sql = 'INSERT INTO tnotification_user(id_mensaje,id_user)' ;
foreach ( $this -> targetUsers as $user ) {
$insertion_string .= sprintf (
'(%d,"%s")' ,
$notification_id ,
$user [ 'id_user' ]
);
$insertion_string .= ',' ;
2020-11-26 11:28:31 +01:00
if ( $send_mails === true ) {
2019-02-07 18:00:51 +01:00
// Send mail.
if ( isset ( $user [ 'also_mail' ]) && $user [ 'also_mail' ] == 1 ) {
enterprise_hook (
'send_email_user' ,
[
$user [ 'id_user' ],
2019-03-05 16:48:27 +01:00
io_safe_output ( $notification [ 'mensaje' ]) . '<br><hl><br>' . $notification [ 'url' ],
2019-02-07 18:00:51 +01:00
io_safe_output ( $notification [ 'subject' ]),
]
);
2019-02-07 18:29:20 +01:00
array_push ( $blacklist , $user [ 'id_user' ]);
2019-02-07 18:00:51 +01:00
}
2019-02-07 16:24:49 +01:00
}
}
$insertion_string = substr ( $insertion_string , 0 , - 1 );
db_process_sql ( $users_sql . ' VALUES ' . $insertion_string );
}
if ( is_array ( $this -> targetGroups ) === true
&& count ( $this -> targetGroups ) > 0
) {
// Process group targets.
$insertion_string = '' ;
$groups_sql = 'INSERT INTO tnotification_group(id_mensaje,id_group)' ;
foreach ( $this -> targetGroups as $group ) {
$insertion_string .= sprintf (
'(%d,"%s")' ,
$notification_id ,
$group [ 'id_group' ]
);
$insertion_string .= ',' ;
2020-11-26 11:28:31 +01:00
if ( $send_mails === true ) {
2019-02-07 18:00:51 +01:00
// Send mail.
if ( isset ( $group [ 'also_mail' ]) && $group [ 'also_mail' ] == 1 ) {
enterprise_hook (
'send_email_group' ,
[
$group [ 'id_group' ],
2019-03-05 16:48:27 +01:00
io_safe_output ( $notification [ 'mensaje' ]) . '<br><hl><br>' . $notification [ 'url' ],
2019-02-07 18:00:51 +01:00
io_safe_output ( $notification [ 'subject' ]),
2019-02-07 18:29:20 +01:00
null ,
$blacklist ,
2019-02-07 18:00:51 +01:00
]
);
}
2019-02-07 16:24:49 +01:00
}
}
$insertion_string = substr ( $insertion_string , 0 , - 1 );
db_process_sql ( $groups_sql . ' VALUES ' . $insertion_string );
}
}
/**
* Generates notifications for target users and groups .
*
* @ param array $data Message to be delivered :
* - boolean status ( false : notify , true : do not notify )
* - string title
* - string message
* - string url .
* @ param integer $source_id Target source_id , by default $this -> sourceId .
* @ param integer $max_age Maximum age for generated notification .
*
* @ return void
*/
public function notify (
array $data ,
int $source_id = 0 ,
2020-10-07 18:48:17 +02:00
int $max_age = SECONDS_1DAY
2019-02-07 16:24:49 +01:00
) {
// Uses 'check failed' logic.
if ( is_array ( $data ) === false ) {
// Skip.
return ;
}
if ( $source_id === 0 ) {
$source_id = $this -> sourceId ;
2021-02-19 13:36:29 +01:00
}
static $_cache_targets ;
$key = $source_id . '|' . $data [ 'type' ];
if ( $_cache_targets === null ) {
$_cache_targets = [];
}
if ( $_cache_targets [ $key ] !== null ) {
$targets = $_cache_targets [ $key ];
} else {
$targets = get_notification_source_targets (
$source_id ,
$data [ 'type' ]
);
2019-02-07 16:24:49 +01:00
$this -> targetGroups = $targets [ 'groups' ];
$this -> targetUsers = $targets [ 'users' ];
2021-02-19 13:36:29 +01:00
$_cache_targets [ $key ] = $targets ;
2019-02-07 16:24:49 +01:00
}
switch ( $data [ 'type' ]) {
2019-03-26 11:53:03 +01:00
case 'NOTIF.LICENSE.LIMITED' :
$max_age = 0 ;
2019-03-27 11:59:25 +01:00
break ;
2019-02-07 16:24:49 +01:00
case 'NOTIF.LICENSE.EXPIRATION' :
case 'NOTIF.FILES.ATTACHMENT' :
case 'NOTIF.FILES.DATAIN' :
case 'NOTIF.FILES.DATAIN.BADXML' :
case 'NOTIF.PHP.SAFE_MODE' :
case 'NOTIF.PHP.INPUT_TIME' :
case 'NOTIF.PHP.EXECUTION_TIME' :
case 'NOTIF.PHP.UPLOAD_MAX_FILESIZE' :
case 'NOTIF.PHP.MEMORY_LIMIT' :
case 'NOTIF.PHP.DISABLE_FUNCTIONS' :
case 'NOTIF.PHP.PHANTOMJS' :
case 'NOTIF.PHP.VERSION' :
case 'NOTIF.HISTORYDB' :
case 'NOTIF.PANDORADB' :
case 'NOTIF.PANDORADB.HISTORICAL' :
case 'NOTIF.HISTORYDB.MR' :
case 'NOTIF.EXT.ELASTICSEARCH' :
case 'NOTIF.METACONSOLE.DB_CONNECTION' :
case 'NOTIF.DOWNTIME' :
case 'NOTIF.UPDATEMANAGER.REGISTRATION' :
case 'NOTIF.MISC.EVENTSTORMPROTECTION' :
case 'NOTIF.MISC.DEVELOPBYPASS' :
case 'NOTIF.MISC.FONTPATH' :
case 'NOTIF.SECURITY.DEFAULT_PASSWORD' :
case 'NOTIF.UPDATEMANAGER.OPENSETUP' :
case 'NOTIF.UPDATEMANAGER.UPDATE' :
2019-02-07 18:00:51 +01:00
case 'NOTIF.UPDATEMANAGER.MINOR' :
2019-05-14 17:15:28 +02:00
case 'NOTIF.UPDATEMANAGER.MESSAGES' :
2019-02-19 11:13:07 +01:00
case 'NOTIF.CRON.CONFIGURED' :
2020-04-07 18:40:47 +02:00
case 'NOTIF.ALLOWOVERRIDE.MESSAGE' :
2020-05-25 17:49:23 +02:00
case 'NOTIF.HAMASTER.MESSAGE' :
2019-02-07 16:24:49 +01:00
default :
// NOTIF.SERVER.STATUS.
// NOTIF.SERVER.STATUS.ID_SERVER.
// NOTIF.SERVER.QUEUE.ID_SERVER.
// NOTIF.SERVER.MASTER.
// NOTIF.SERVER.STATUS.ID_SERVER.
if ( preg_match ( '/^NOTIF.SERVER/' , $data [ 'type' ]) === true ) {
2020-10-07 18:48:17 +02:00
// Send notification once a day.
$max_age = SECONDS_1DAY ;
2019-02-07 16:24:49 +01:00
}
// Else ignored.
break ;
}
// Get previous notification.
$prev = db_get_row (
'tmensajes' ,
'subtype' ,
2020-11-26 11:28:31 +01:00
$data [ 'type' ],
false ,
false
2019-02-07 16:24:49 +01:00
);
if ( $prev !== false
&& ( time () - $prev [ 'timestamp' ]) > $max_age
) {
// Clean previous notification.
$this -> cleanNotifications ( $data [ 'type' ]);
} else if ( $prev !== false ) {
// Avoid creation. Previous notification is still valid.
// Update message with latest information.
$r = db_process_sql_update (
'tmensajes' ,
[
'mensaje' => io_safe_input ( $data [ 'message' ]),
'subject' => io_safe_input ( $data [ 'title' ]),
],
[ 'id_mensaje' => $prev [ 'id_mensaje' ]]
);
2020-11-26 11:28:31 +01:00
$this -> updateTargets ( $prev , false );
2019-02-07 16:24:49 +01:00
return ;
}
if ( isset ( $data [ 'type' ]) === false ) {
$data [ 'type' ] = '' ;
}
// Create notification.
$notification = [];
$notification [ 'timestamp' ] = time ();
$notification [ 'id_source' ] = $source_id ;
$notification [ 'mensaje' ] = io_safe_input ( $data [ 'message' ]);
$notification [ 'subject' ] = io_safe_input ( $data [ 'title' ]);
$notification [ 'subtype' ] = $data [ 'type' ];
$notification [ 'url' ] = io_safe_input ( $data [ 'url' ]);
$id = db_process_sql_insert ( 'tmensajes' , $notification );
if ( $id === false ) {
// Failed to generate notification.
$this -> warn ( 'Failed to generate notification' );
return ;
}
2019-02-07 18:07:52 +01:00
// Update reference to update targets.
$notification [ 'id_mensaje' ] = $id ;
2019-02-07 18:00:51 +01:00
$this -> updateTargets ( $notification );
2019-02-07 16:24:49 +01:00
}
/**
* Deletes useless notifications .
*
* @ param string $subtype Subtype to be deleted .
*
* @ return mixed False in case of error or invalid values passed .
* Affected rows otherwise
*/
public function cleanNotifications ( string $subtype )
{
$not_count = db_get_value_sql (
sprintf (
' SELECT count ( * ) as n
FROM tmensajes
WHERE subtype like " %s " ' ,
$subtype
)
);
if ( $not_count > 0 ) {
return db_process_sql_delete (
'tmensajes' ,
sprintf ( 'subtype like "%s"' , $subtype )
);
}
return true ;
}
/**
* Check license status and validity .
*
* @ return boolean Return true if license is valid , false if not .
*/
public function checkLicense ()
{
global $config ;
$license = enterprise_hook ( 'license_get_info' );
if ( $license === ENTERPRISE_NOT_HOOK ) {
return false ;
}
$days_to_expiry = (( strtotime ( $license [ 'expiry_date' ]) - time ()) / ( 60 * 60 * 24 ));
2019-03-27 11:59:25 +01:00
// Limited mode.
2019-03-26 11:53:03 +01:00
if ( isset ( $config [ 'limited_mode' ])) {
// Warn user if license is going to expire in 15 days or less.
$this -> notify (
[
'type' => 'NOTIF.LICENSE.LIMITED' ,
'title' => __ ( 'Limited mode.' ),
'message' => io_safe_output ( $config [ 'limited_mode' ]),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/setup/license' ),
2019-03-26 11:53:03 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.LICENSE.LIMITED' );
}
2019-03-27 11:59:25 +01:00
// Expiry.
2019-02-07 16:24:49 +01:00
if (( $days_to_expiry <= 15 ) && ( $days_to_expiry > 0 )) {
2020-05-12 12:54:20 +02:00
if ( $config [ 'license_mode' ] == 1 ) {
$title = __ ( 'License is about to expire' );
$msg = 'Your license will expire in %d days. Please, contact our sales department.' ;
} else {
$title = __ ( 'Support is about to expire' );
$msg = 'Your support license will expire in %d days. Please, contact our sales department.' ;
}
2019-02-07 16:24:49 +01:00
// Warn user if license is going to expire in 15 days or less.
$this -> notify (
[
2019-03-26 11:53:03 +01:00
'type' => 'NOTIF.LICENSE.EXPIRATION' ,
2020-05-12 12:54:20 +02:00
'title' => $title ,
2019-02-07 16:24:49 +01:00
'message' => __ (
2020-05-12 12:54:20 +02:00
$msg ,
2019-02-07 16:24:49 +01:00
$days_to_expiry
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/setup/license' ),
2019-02-07 16:24:49 +01:00
]
);
} else if ( $days_to_expiry < 0 ) {
2020-05-12 12:54:20 +02:00
if ( $config [ 'license_mode' ] == 1 ) {
$title = __ ( 'Expired license' );
$msg = __ ( 'Your license has expired. Please, contact our sales department.' );
} else {
$title = __ ( 'Support expired' );
$msg = __ ( 'This license is outside of support. Please, contact our sales department.' );
}
2019-02-07 16:24:49 +01:00
// Warn user, license has expired.
$this -> notify (
[
'type' => 'NOTIF.LICENSE.EXPIRATION' ,
2020-05-12 12:54:20 +02:00
'title' => $title ,
'message' => $msg ,
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/setup/license' ),
2019-02-07 16:24:49 +01:00
]
);
return false ;
} else {
$this -> cleanNotifications ( 'NOTIF.LICENSE.EXPIRATION' );
}
return true ;
}
/**
* Count files in target path .
*
* @ param string $path Path to be checked .
* @ param string $regex Regular expression to find files .
* @ param integer $max_files Maximum number of files to find .
*
* @ return integer Number of files in target path .
*/
public function countFiles (
string $path = '' ,
string $regex = '' ,
int $max_files = 500
) {
if ( empty ( $path ) === true ) {
return - 1 ;
}
$nitems = 0 ;
// Count files up to max_files.
$dir = opendir ( $path );
if ( $dir !== false ) {
// Used instead of glob to avoid check directories with
// more than 1M files.
while ( false !== ( $file = readdir ( $dir )) && $nitems <= $max_files ) {
if ( $file != '.' && $file != '..' ) {
if ( empty ( $regex ) === false ) {
2019-02-21 14:16:17 +01:00
if ( preg_match ( $regex , $file ) === 1 ) {
2019-02-07 16:24:49 +01:00
$nitems ++ ;
continue ;
}
2019-02-21 14:18:33 +01:00
} else {
$nitems ++ ;
2019-02-07 16:24:49 +01:00
}
}
}
closedir ( $dir );
}
return $nitems ;
}
/**
* Check excesive files in attachment directory .
*
* @ return void
*/
public function checkAttachment ()
{
global $config ;
if ( is_writable ( $config [ 'attachment_store' ]) !== true ) {
$this -> notify (
[
'type' => 'NOTIF.WRITABLE.ATTACHMENT' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Attachment directory is not writable' ),
2019-02-07 16:24:49 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'Directory %s is not writable. Please, configure corresponding permissions.' ,
2019-02-07 16:24:49 +01:00
$config [ 'attachment_store' ]
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=general' ),
2019-02-07 16:24:49 +01:00
]
);
return ;
} else {
$this -> cleanNotifications ( 'NOTIF.WRITABLE.ATTACHMENT' );
}
$filecount = $this -> countFiles (
$config [ 'attachment_store' ],
'' ,
$config [ 'num_files_attachment' ]
);
if ( $filecount > $config [ 'num_files_attachment' ]) {
$this -> notify (
[
'type' => 'NOTIF.FILES.ATTACHMENT' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'There are too many files in attachment directory' ),
2019-02-07 16:24:49 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'There are more than %d files in attachment, consider cleaning up attachment directory manually.' ,
2019-02-07 16:24:49 +01:00
$config [ 'num_files_attachment' ]
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=perf' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.FILES.ATTACHMENT' );
}
}
/**
* Check excesive files in data_in directory .
*
* @ return void
*/
public function checkDataIn ()
{
global $config ;
2020-10-07 18:48:17 +02:00
$remote_config_dir = ( string ) io_safe_output ( $config [ 'remote_config' ]);
2019-09-24 19:07:55 +02:00
2019-02-07 16:24:49 +01:00
if ( enterprise_installed ()
&& isset ( $config [ 'license_nms' ])
&& $config [ 'license_nms' ] != 1
) {
2019-09-24 19:07:55 +02:00
if ( is_readable ( $remote_config_dir ) !== true ) {
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Remote configuration directory is not readable' ),
2019-02-07 16:24:49 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'Remote configuration directory %s is not readable. Please, adjust configuration.' ,
2019-09-24 19:07:55 +02:00
$remote_config_dir
2019-02-07 16:24:49 +01:00
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=general' ),
2019-02-07 16:24:49 +01:00
]
);
return ;
} else {
$this -> cleanNotifications (
'NOTIF.PERMISSIONS.REMOTE_CONFIG'
);
}
2019-09-24 19:07:55 +02:00
if ( is_writable ( $remote_config_dir . '/conf' ) !== true ) {
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG.CONF' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Remote configuration directory is not writable' ),
2019-02-07 16:24:49 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'Remote configuration directory %s is not writable. Please, adjust configuration.' ,
2019-09-24 19:07:55 +02:00
$remote_config_dir . '/conf'
2019-02-07 16:24:49 +01:00
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=general' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications (
'NOTIF.PERMISSIONS.REMOTE_CONFIG.CONF'
);
}
2019-09-24 19:07:55 +02:00
if ( is_writable ( $remote_config_dir . '/collections' ) !== true ) {
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG.COLLECTIONS' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Remote collections directory is not writable' ),
2019-02-07 16:24:49 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'Collections directory %s is not writable. Please, adjust configuration.' ,
2019-09-24 19:07:55 +02:00
$remote_config_dir . '/collections'
2019-02-07 16:24:49 +01:00
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=general' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications (
'NOTIF.PERMISSIONS.REMOTE_CONFIG.COLLECTIONS'
);
}
2019-09-24 19:07:55 +02:00
if ( is_writable ( $remote_config_dir . '/md5' ) !== true ) {
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PERMISSIONS.REMOTE_CONFIG.MD5' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Remote md5 directory is not writable' ),
2019-02-07 16:24:49 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'MD5 directory %s is not writable. Please, adjust configuration.' ,
2019-09-24 19:07:55 +02:00
$remote_config_dir . '/md5'
2019-02-07 16:24:49 +01:00
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=general' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications (
'NOTIF.PERMISSIONS.REMOTE_CONFIG.MD5'
);
}
} else {
$this -> cleanNotifications ( 'NOTIF.PERMISSIONS.REMOTE_CONF%' );
}
$MAX_FILES_DATA_IN = 1000 ;
$MAX_BADXML_FILES_DATA_IN = 150 ;
$filecount = $this -> countFiles (
2019-09-24 19:07:55 +02:00
$remote_config_dir ,
2019-02-07 16:24:49 +01:00
'' ,
$MAX_FILES_DATA_IN
);
// If cannot open directory, count is '-1', skip.
if ( $filecount > $MAX_FILES_DATA_IN ) {
$this -> notify (
[
'type' => 'NOTIF.FILES.DATAIN' ,
'title' => __ ( 'There are too much files in spool' ) . '.' ,
'message' => __ (
2019-03-05 16:48:27 +01:00
'There are more than %d files in %s. Consider checking DataServer performance' ,
2019-02-07 16:24:49 +01:00
$MAX_FILES_DATA_IN ,
2019-09-24 19:07:55 +02:00
$remote_config_dir
2019-02-07 16:24:49 +01:00
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=perf' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.FILES.DATAIN' );
}
$filecount = $this -> countFiles (
2019-09-24 19:07:55 +02:00
$remote_config_dir ,
2019-02-21 14:16:17 +01:00
'/^.*BADXML$/' ,
2019-02-07 16:24:49 +01:00
$MAX_BADXML_FILES_DATA_IN
);
// If cannot open directory, count is '-1', skip.
if ( $filecount > $MAX_BADXML_FILES_DATA_IN ) {
$this -> notify (
[
'type' => 'NOTIF.FILES.DATAIN.BADXML' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'There are too many BADXML files in spool' ),
2019-02-07 16:24:49 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'There are more than %d files in %s. Consider checking software agents.' ,
2019-02-07 16:24:49 +01:00
$MAX_BADXML_FILES_DATA_IN ,
2019-09-24 19:07:55 +02:00
$remote_config_dir
2019-02-07 16:24:49 +01:00
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=perf' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.FILES.DATAIN.BADXML' );
}
}
/**
* Check growing queues in servers .
*
* @ return void
*/
public function checkServers ()
{
global $config ;
2019-03-06 19:39:07 +01:00
include_once $config [ 'homedir' ] . '/include/functions_servers.php' ;
2019-02-07 16:24:49 +01:00
$idx_file = $config [ 'attachment_store' ] . '/.cron.supervisor.servers.idx' ;
$MAX_QUEUE = 1500 ;
2019-03-06 19:39:07 +01:00
$total_modules = servers_get_total_modules ();
2019-02-07 16:24:49 +01:00
$queue_state = [];
$previous = [];
$new = [];
if ( file_exists ( $idx_file ) === true ) {
// Read previous values from file.
$previous = json_decode ( file_get_contents ( $idx_file ), true );
}
// DataServer queue status.
$queue_state = db_get_all_rows_sql (
' SELECT id_server , name , server_type , queued_modules , status
FROM tserver ORDER BY 1 '
);
$time = time ();
2019-02-13 14:56:10 +01:00
if ( is_array ( $queue_state ) === true ) {
foreach ( $queue_state as $queue ) {
$key = $queue [ 'id_server' ];
$type = $queue [ 'server_type' ];
$new_data [ $key ] = $queue [ 'queued_modules' ];
2019-03-06 19:39:07 +01:00
$max_grown = 0 ;
if ( is_array ( $total_modules )
&& isset ( $total_modules [ $queue [ 'server_type' ]])
) {
$max_grown = ( $total_modules [ $queue [ 'server_type' ]] * 0.40 );
}
2019-02-13 14:56:10 +01:00
2021-01-11 18:32:44 +01:00
if ( $total_modules [ $queue [ 'server_type' ]] < self :: MIN_PERFORMANCE_MODULES ) {
$this -> cleanNotifications ( 'NOTIF.SERVER.QUEUE.' . $key );
// Skip.
continue ;
}
2019-02-13 14:56:10 +01:00
// Compare queue increments in a not over 900 seconds.
if ( empty ( $previous [ $key ][ 'modules' ])
|| ( $time - $previous [ $key ][ 'utime' ]) > 900
) {
$previous [ $key ][ 'modules' ] = 0 ;
}
2019-02-07 16:24:49 +01:00
2019-02-13 14:56:10 +01:00
$modules_queued = ( $queue [ 'queued_modules' ] - $previous [ $key ][ 'modules' ]);
2019-02-07 16:24:49 +01:00
2019-03-06 19:39:07 +01:00
// 40% Modules queued since last check. If any.
if ( $max_grown > 0
&& $modules_queued > $max_grown
2019-02-13 14:56:10 +01:00
) {
$msg = 'Queue has grown %d modules. Total %d' ;
if ( $modules_queued <= 0 ) {
$msg = 'Queue is decreasing in %d modules. But there are %d queued.' ;
$modules_queued *= - 1 ;
}
$this -> notify (
[
'type' => 'NOTIF.SERVER.QUEUE.' . $key ,
'title' => __ (
2019-03-05 16:48:27 +01:00
'%s (%s) is lacking performance.' ,
2019-02-13 14:56:10 +01:00
servers_get_server_string_name ( $type ),
$queue [ 'name' ]
),
'message' => __ (
$msg ,
$modules_queued ,
$queue [ 'queued_modules' ]
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=60' ),
2019-02-13 14:56:10 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.SERVER.QUEUE.' . $key );
2019-02-07 16:24:49 +01:00
}
2019-02-13 14:56:10 +01:00
$new [ $key ][ 'modules' ] = $queue [ 'queued_modules' ];
$new [ $key ][ 'utime' ] = $time ;
2019-02-07 16:24:49 +01:00
}
2019-02-13 14:56:10 +01:00
// Update file content.
file_put_contents ( $idx_file , json_encode ( $new ));
} else {
// No queue data, ignore.
unlink ( $idx_file );
2019-02-07 16:24:49 +01:00
2019-02-13 14:56:10 +01:00
// Clean notifications.
$this -> cleanNotifications ( 'NOTIF.SERVER.QUEUE.%' );
}
2019-02-07 16:24:49 +01:00
}
/**
* Check Pandora component statuses .
*
* @ return void
*/
public function checkPandoraServers ()
{
2020-10-07 18:48:17 +02:00
global $config ;
2019-02-07 16:24:49 +01:00
$servers = db_get_all_rows_sql (
' SELECT
id_server ,
name ,
server_type ,
2019-03-11 18:04:23 +01:00
server_keepalive ,
2019-02-07 16:24:49 +01:00
status ,
unix_timestamp () - unix_timestamp ( keepalive ) as downtime
FROM tserver
WHERE
unix_timestamp () - unix_timestamp ( keepalive ) > server_keepalive
OR status = 0 '
);
if ( $servers === false ) {
$nservers = db_get_value_sql (
' SELECT count ( * ) as nservers
FROM tserver '
);
if ( $nservers == 0 ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/en/documentation/02_installation/04_configuration' ;
2019-02-07 16:24:49 +01:00
if ( $config [ 'language' ] == 'es' ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/es/documentation/02_installation/04_configuration' ;
2019-02-07 16:24:49 +01:00
}
$this -> notify (
[
'type' => 'NOTIF.SERVER.STATUS' ,
'title' => __ ( 'No servers available.' ),
2019-03-05 16:48:27 +01:00
'message' => __ ( 'There are no servers registered in this console. Please, check installation guide.' ),
2019-02-07 16:24:49 +01:00
'url' => $url ,
]
);
}
// At this point there's no servers with issues.
$this -> cleanNotifications ( 'NOTIF.SERVER.STATUS%' );
return ;
2020-07-06 17:01:52 +02:00
} else {
2020-11-26 11:28:31 +01:00
// Clean notifications. Only show notif for down servers
// ONLY FOR RECOVERED ONES.
$servers_working = db_get_all_rows_sql (
' SELECT
id_server ,
name ,
server_type ,
server_keepalive ,
status ,
unix_timestamp () - unix_timestamp ( keepalive ) as downtime
FROM tserver
WHERE
unix_timestamp () - unix_timestamp ( keepalive ) <= server_keepalive
OR status != 0 '
);
if ( is_array ( $servers_working ) === true ) {
foreach ( $servers_working as $server ) {
$this -> cleanNotifications (
'NOTIF.SERVER.STATUS' . $server [ 'id_server' ]
);
}
}
2019-02-07 16:24:49 +01:00
}
foreach ( $servers as $server ) {
2019-03-11 18:04:23 +01:00
if ( $server [ 'server_type' ] == SERVER_TYPE_ENTERPRISE_SATELLITE ) {
if ( $server [ 'downtime' ] < ( $server [ 'server_keepalive' ] * 2 )) {
2019-03-07 11:57:31 +01:00
// Satellite uses different keepalive mode.
continue ;
}
}
2019-02-07 16:24:49 +01:00
if ( $server [ 'status' ] == 1 ) {
// Fatal error. Component has die.
$msg = __ (
2019-03-05 16:48:27 +01:00
'%s (%s) has crashed.' ,
2019-02-07 16:24:49 +01:00
servers_get_server_string_name ( $server [ 'server_type' ]),
$server [ 'name' ]
);
$description = __ (
2019-03-05 16:48:27 +01:00
'%s (%s) has crashed, please check log files.' ,
2019-02-07 16:24:49 +01:00
servers_get_server_string_name ( $server [ 'server_type' ]),
$server [ 'name' ]
);
} else {
// Non-fatal error. Controlated exit. Component is not running.
$msg = __ (
2019-03-05 16:48:27 +01:00
'%s (%s) is not running.' ,
2019-02-07 16:24:49 +01:00
servers_get_server_string_name ( $server [ 'server_type' ]),
$server [ 'name' ]
);
$description = __ (
2019-03-05 16:48:27 +01:00
'%s (%s) is not running. Please, check configuration file or remove this server from server list.' ,
2019-02-07 16:24:49 +01:00
servers_get_server_string_name ( $server [ 'server_type' ]),
$server [ 'name' ]
);
}
$this -> notify (
[
'type' => 'NOTIF.SERVER.STATUS.' . $server [ 'id_server' ],
'title' => $msg ,
'message' => $description ,
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=60' ),
2019-02-07 16:24:49 +01:00
]
);
}
}
/**
* Checks if there ' s at last one server running in master mode .
*
* @ return void
*/
public function checkPandoraServerMasterAvailable ()
{
2020-10-07 18:48:17 +02:00
global $config ;
2019-02-07 16:24:49 +01:00
$n_masters = db_get_value_sql (
' SELECT
count ( * ) as n
FROM tserver
WHERE
unix_timestamp () - unix_timestamp ( keepalive ) <= server_keepalive
AND master > 0
AND status = 1 '
);
if ( $n_masters === false ) {
// Failed to retrieve server list.
return ;
}
if ( $n_masters <= 0 ) {
// No server running in master.
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/en/documentation/02_installation/04_configuration#master' ;
2019-02-07 16:24:49 +01:00
if ( $config [ 'language' ] == 'es' ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/es/documentation/02_installation/04_configuration#master' ;
2019-02-07 16:24:49 +01:00
}
$this -> notify (
[
'type' => 'NOTIF.SERVER.MASTER' ,
'title' => __ ( 'No master servers found.' ),
2019-03-05 16:48:27 +01:00
'message' => __ ( 'At least one server must be defined to run as master. Please, check documentation.' ),
2019-02-07 16:24:49 +01:00
'url' => $url ,
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.SERVER.MASTER%' );
}
}
/**
* Checks PHP settings to be correct . Generates system notifications if not .
*
* @ return void
*/
public function checkPHPSettings ()
{
global $config ;
$PHPupload_max_filesize = config_return_in_bytes (
ini_get ( 'upload_max_filesize' )
);
// PHP configuration.
$PHPmax_input_time = ini_get ( 'max_input_time' );
$PHPmemory_limit = config_return_in_bytes ( ini_get ( 'memory_limit' ));
$PHPmax_execution_time = ini_get ( 'max_execution_time' );
$PHPsafe_mode = ini_get ( 'safe_mode' );
$PHPdisable_functions = ini_get ( 'disable_functions' );
$PHPupload_max_filesize_min = config_return_in_bytes ( '800M' );
2021-06-14 13:56:42 +02:00
$PHPmemory_limit_min = config_return_in_bytes ( '800M' );
2019-05-17 18:29:38 +02:00
$PHPSerialize_precision = ini_get ( 'serialize_precision' );
2019-02-07 16:24:49 +01:00
// PhantomJS status.
2019-09-24 19:07:55 +02:00
$phantomjs_dir = io_safe_output ( $config [ 'phantomjs_bin' ]);
$result_ejecution = exec ( $phantomjs_dir . '/phantomjs --version' );
2019-02-07 16:24:49 +01:00
// PHP version checks.
$php_version = phpversion ();
$php_version_array = explode ( '.' , $php_version );
if ( $PHPsafe_mode === '1' ) {
2019-03-06 18:28:00 +01:00
$url = 'http://php.net/manual/en/features.safe-mode.php' ;
if ( $config [ 'language' ] == 'es' ) {
$url = 'http://php.net/manual/es/features.safe-mode.php' ;
}
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PHP.SAFE_MODE' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'PHP safe mode is enabled. Some features may not work properly' ),
'message' => __ ( 'To disable it, go to your PHP configuration file (php.ini) and put safe_mode = Off (Do not forget to restart apache process after changes)' ),
2019-03-06 18:28:00 +01:00
'url' => $url ,
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.SAFE_MODE' );
}
if ( $PHPmax_input_time !== '-1' ) {
2019-03-06 18:28:00 +01:00
$url = 'http://php.net/manual/en/info.configuration.php#ini.max-input-time' ;
if ( $config [ 'language' ] == 'es' ) {
$url = 'http://php.net/manual/es/info.configuration.php#ini.max-input-time' ;
}
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PHP.INPUT_TIME' ,
'title' => sprintf (
2019-03-05 16:48:27 +01:00
__ ( " '%s' value in PHP configuration is not recommended " ),
2019-02-07 16:24:49 +01:00
'max_input_time'
),
'message' => sprintf (
__ ( 'Recommended value is %s' ),
'-1 (' . __ ( 'Unlimited' ) . ')'
2019-03-05 16:48:27 +01:00
) . '<br><br>' . __ ( 'Please, change it on your PHP configuration file (php.ini) or contact with administrator (Do not forget to restart Apache process after)' ),
2019-03-06 18:28:00 +01:00
'url' => $url ,
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.INPUT_TIME' );
}
2020-05-25 18:49:28 +02:00
if (( int ) $PHPmax_execution_time !== 0 ) {
2019-03-06 18:28:00 +01:00
$url = 'http://php.net/manual/en/info.configuration.php#ini.max-execution-time' ;
if ( $config [ 'language' ] == 'es' ) {
$url = 'http://php.net/manual/es/info.configuration.php#ini.max-execution-time' ;
}
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PHP.EXECUTION_TIME' ,
'title' => sprintf (
__ ( " Not recommended '%s' value in PHP configuration " ),
'max_execution_time'
),
'message' => sprintf (
__ ( 'Recommended value is: %s' ),
'0 (' . __ ( 'Unlimited' ) . ')'
) . '<br><br>' . __ ( 'Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)' ),
2019-03-06 18:28:00 +01:00
'url' => $url ,
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.EXECUTION_TIME' );
}
if ( $PHPupload_max_filesize < $PHPupload_max_filesize_min ) {
2019-03-06 18:28:00 +01:00
$url = 'http://php.net/manual/en/ini.core.php#ini.upload-max-filesize' ;
if ( $config [ 'language' ] == 'es' ) {
$url = 'http://php.net/manual/es/ini.core.php#ini.upload-max-filesize' ;
}
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PHP.UPLOAD_MAX_FILESIZE' ,
'title' => sprintf (
__ ( " Not recommended '%s' value in PHP configuration " ),
'upload_max_filesize'
),
'message' => sprintf (
__ ( 'Recommended value is: %s' ),
sprintf ( __ ( '%s or greater' ), '800M' )
) . '<br><br>' . __ ( 'Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)' ),
2019-03-06 18:28:00 +01:00
'url' => $url ,
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.UPLOAD_MAX_FILESIZE' );
}
if ( $PHPmemory_limit < $PHPmemory_limit_min && $PHPmemory_limit !== '-1' ) {
2019-03-06 18:28:00 +01:00
$url = 'http://php.net/manual/en/ini.core.php#ini.memory-limit' ;
if ( $config [ 'language' ] == 'es' ) {
$url = 'http://php.net/manual/es/ini.core.php#ini.memory-limit' ;
}
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PHP.MEMORY_LIMIT' ,
'title' => sprintf (
__ ( " Not recommended '%s' value in PHP configuration " ),
'memory_limit'
),
'message' => sprintf (
__ ( 'Recommended value is: %s' ),
2021-06-14 13:56:42 +02:00
sprintf ( __ ( '%s or greater' ), '800M' )
2019-02-07 16:24:49 +01:00
) . '<br><br>' . __ ( 'Please, change it on your PHP configuration file (php.ini) or contact with administrator' ),
2019-03-06 18:28:00 +01:00
'url' => $url ,
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.MEMORY_LIMIT' );
}
if ( preg_match ( '/system/' , $PHPdisable_functions ) || preg_match ( '/exec/' , $PHPdisable_functions )) {
2019-03-06 18:28:00 +01:00
$url = 'http://php.net/manual/en/ini.core.php#ini.disable-functions' ;
if ( $config [ 'language' ] == 'es' ) {
$url = 'http://php.net/manual/es/ini.core.php#ini.disable-functions' ;
}
2019-02-07 16:24:49 +01:00
$this -> notify (
[
'type' => 'NOTIF.PHP.DISABLE_FUNCTIONS' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Problems with disable_functions in php.ini' ),
'message' => __ ( 'The variable disable_functions contains functions system() or exec() in PHP configuration file (php.ini)' ) . '<br /><br />' . __ ( 'Please, change it on your PHP configuration file (php.ini) or contact with administrator (Dont forget restart apache process after changes)' ),
2019-03-06 18:28:00 +01:00
'url' => $url ,
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.DISABLE_FUNCTIONS' );
}
if ( ! isset ( $result_ejecution ) || $result_ejecution == '' ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/en/documentation/02_installation/04_configuration#Phantomjs' ;
2019-02-07 16:24:49 +01:00
if ( $config [ 'language' ] == 'es' ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/es/documentation/02_installation/04_configuration#Phantomjs' ;
2019-02-07 16:24:49 +01:00
}
$this -> notify (
[
'type' => 'NOTIF.PHP.PHANTOMJS' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'PhantomJS is not installed' ),
'message' => __ ( 'To be able to create images of the graphs for PDFs, please install the PhantomJS extension. For that, it is necessary to follow these steps:' ),
2019-02-07 16:24:49 +01:00
'url' => $url ,
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.PHANTOMJS' );
}
if ( $php_version_array [ 0 ] < 7 ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/en/documentation/07_technical_annexes/14_php_7' ;
2019-02-07 16:24:49 +01:00
if ( $config [ 'language' ] == 'es' ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/es/documentation/07_technical_annexes/14_php_7' ;
2019-02-07 16:24:49 +01:00
}
$this -> notify (
[
'type' => 'NOTIF.PHP.VERSION' ,
'title' => __ ( 'PHP UPDATE REQUIRED' ),
2021-03-11 15:40:23 +01:00
'message' => __ ( 'For a correct operation of PandoraFMS, PHP must be updated to version 7.0 or higher.' ) . '<br>' . __ ( 'Otherwise, functionalities will be lost.' ) . '<br>' . " <ol><li class='color_67'> " . __ ( 'Report download in PDF format' ) . '</li>' . " <li class='color_67'> " . __ ( 'Emails Sending' ) . '</li><li class="color_67">' . __ ( 'Metaconsole Collections' ) . '</li><li class="color_67">...</li></ol>' ,
2019-02-07 16:24:49 +01:00
'url' => $url ,
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PHP.VERSION' );
}
2019-05-17 18:29:38 +02:00
if ( $PHPSerialize_precision != - 1 ) {
$url = 'https://www.php.net/manual/en/ini.core.php#ini.serialize-precision' ;
if ( $config [ 'language' ] == 'es' ) {
$url = 'https://www.php.net/manual/es/ini.core.php#ini.serialize-precision' ;
}
$this -> notify (
[
'type' => 'NOTIF.PHP.SERIALIZE_PRECISION' ,
'title' => sprintf (
__ ( " Not recommended '%s' value in PHP configuration " ),
2019-09-24 19:07:55 +02:00
'serialize_precision'
),
'message' => sprintf (
2019-05-17 18:29:38 +02:00
__ ( 'Recommended value is: %s' ),
sprintf ( '-1' )
) . '<br><br>' . __ ( 'Please, change it on your PHP configuration file (php.ini) or contact with administrator' ),
'url' => $url ,
]
);
} else {
2019-07-15 17:46:59 +02:00
$this -> cleanNotifications ( 'NOTIF.PHP.SERIALIZE_PRECISION' );
2019-05-17 18:29:38 +02:00
}
2019-02-07 16:24:49 +01:00
}
/**
* Checks if history DB is available .
*
* @ return void
*/
public function checkPandoraHistoryDB ()
{
global $config ;
if ( isset ( $config [ 'history_db_enabled' ])
&& $config [ 'history_db_enabled' ] == 1
) {
if ( ! isset ( $config [ 'history_db_connection' ])
|| $config [ 'history_db_connection' ] === false
) {
ob_start ();
$config [ 'history_db_connection' ] = db_connect (
$config [ 'history_db_host' ],
$config [ 'history_db_name' ],
$config [ 'history_db_user' ],
io_output_password ( $config [ 'history_db_pass' ]),
$config [ 'history_db_port' ],
false
);
ob_get_clean ();
}
if ( $config [ 'history_db_connection' ] === false ) {
$this -> notify (
[
'type' => 'NOTIF.HISTORYDB' ,
'title' => __ ( 'Historical database not available' ),
2019-03-05 16:48:27 +01:00
'message' => __ ( 'Historical database is enabled, though not accessible with the current configuration.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=hist_db' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.HISTORYDB' );
}
} else {
$this -> cleanNotifications ( 'NOTIF.HISTORYDB' );
}
}
/**
* Check if pandora_db is running in all available DB instances .
* Generating notifications .
*
* @ return void
*/
public function checkPandoraDBMaintenance ()
{
global $config ;
// Main DB db_maintenance value.
$db_maintance = db_get_value (
'value' ,
'tconfig' ,
'token' ,
'db_maintance'
);
// If never was executed, it means we are in the first Pandora FMS execution. Set current timestamp.
if ( empty ( $db_maintance )) {
config_update_value ( 'db_maintance' , date ( 'U' ));
}
$last_maintance = ( date ( 'U' ) - $db_maintance );
// Limit 48h.
if ( $last_maintance > 172800 ) {
$this -> notify (
[
'type' => 'NOTIF.PANDORADB' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Database maintenance problem' ),
2019-02-19 11:13:07 +01:00
'message' => __ (
2019-03-05 16:48:27 +01:00
'Your database hasn\'t been through maintenance for 48hrs. Please, check documentation on how to perform this maintenance process on %s and enable it as soon as possible.' ,
2019-02-19 11:13:07 +01:00
io_safe_output ( get_product_name ())
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=perf' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PANDORADB' );
}
if ( isset ( $config [ 'history_db_enabled' ])
&& $config [ 'history_db_enabled' ] == 1
) {
// History DB db_maintenance value.
$db_maintenance = db_get_value (
'value' ,
'tconfig' ,
'token' ,
'db_maintenance' ,
true
);
// History db connection is supossed to be enabled since we use
// db_get_value, wich initializes target db connection.
if ( empty ( $db_maintance )) {
$sql = sprintf (
'UPDATE tconfig SET `value`=%d WHERE `token`="%s"' ,
date ( 'U' ),
'db_maintenance'
);
$affected_rows = db_process_sql (
$sql ,
$rettype = 'affected_rows' ,
$dbconnection = $config [ 'history_db_connection' ]
);
if ( $affected_rows == 0 ) {
// Failed to update. Maybe the row does not exist?
$sql = sprintf (
'INSERT INTO tconfig(`token`,`value`) VALUES("%s",%d)' ,
'db_maintenance' ,
date ( 'U' )
);
$affected_rows = db_process_sql (
$sql ,
$rettype = 'affected_rows' ,
$dbconnection = $config [ 'history_db_connection' ]
);
}
}
$last_maintance = ( date ( 'U' ) - $db_maintance );
// Limit 48h.
if ( $last_maintance > 172800 ) {
$this -> notify (
[
'type' => 'NOTIF.PANDORADB.HISTORY' ,
'title' => __ (
2019-03-05 16:48:27 +01:00
'Historical database maintenance problem.'
2019-02-07 16:24:49 +01:00
),
2019-03-05 16:48:27 +01:00
'message' => __ ( 'Your historical database hasn\'t been through maintenance for 48hrs. Please, check documentation on how to perform this maintenance process on %s and enable it as soon as possible.' , get_product_name ()),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=perf' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
// Historical db working fine.
$this -> cleanNotifications ( 'NOTIF.PANDORADB.HISTORY' );
}
} else {
// Disabled historical db.
$this -> cleanNotifications ( 'NOTIF.PANDORADB.HISTORY' );
}
}
/**
* Check MR package applied in historical DB
*
* @ return void
*/
public function checkPandoraHistoryDBMR ()
{
global $config ;
if ( isset ( $config [ 'history_db_enabled' ])
&& $config [ 'history_db_enabled' ] == 1
) {
$mrh_version = db_get_value (
'value' ,
'tconfig' ,
'token' ,
'MR' ,
true
);
if ( $mrh_version != $config [ 'MR' ]) {
$this -> notify (
[
'type' => 'NOTIF.HISTORYDB.MR' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Historical database MR mismatch' ),
'message' => __ ( 'Your historical database is not using the same schema as the main DB. This could produce anomalies while storing historical data.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=hist_db' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
// MR version OK.
$this -> cleanNotifications ( 'NOTIF.HISTORYDB.MR' );
}
} else {
// Disabled historical db.
$this -> cleanNotifications ( 'NOTIF.HISTORYDB.MR' );
}
}
/**
* Check if elasticsearch is available .
*
* @ return void
*/
public function checkExternalComponents ()
{
global $config ;
// Cannot check selenium, configuration is only available from server.
if ( isset ( $config [ 'log_collector' ])
&& $config [ 'log_collector' ] == 1
) {
$elasticsearch = @ fsockopen (
$config [ 'elasticsearch_ip' ],
$config [ 'elasticsearch_port' ],
$errno ,
$errstr ,
5
);
if ( $elasticsearch === false ) {
$this -> notify (
[
'type' => 'NOTIF.EXT.ELASTICSEARCH' ,
'title' => __ ( 'Log collector cannot connect to ElasticSearch' ),
2019-03-05 16:48:27 +01:00
'message' => __ ( 'ElasticSearch is not available using current configuration.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=log' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
fclose ( $elasticsearch );
$this -> cleanNotifications ( 'NOTIF.EXT.ELASTICSEARCH' );
}
} else {
$this -> cleanNotifications ( 'NOTIF.EXT.ELASTICSEARCH' );
}
}
/**
* Checks if metaconsole DB connection is ready .
*
* @ return void
*/
public function checkMetaconsole ()
{
global $config ;
$check_ok = true ;
if ( license_free ()
&& is_metaconsole () === false
&& isset ( $config [ 'node_metaconsole' ])
&& $config [ 'node_metaconsole' ] == 1
) {
// Check if node is successfully registered in MC.
$server_name = db_get_value (
'distinct(name)' ,
'tserver' ,
'server_type' ,
1
);
$mc_db_conn = enterprise_hook (
'metaconsole_load_external_db' ,
[
[
'dbhost' => $config [ 'replication_dbhost' ],
'dbuser' => $config [ 'replication_dbuser' ],
'dbpass' => io_output_password (
$config [ 'replication_dbpass' ]
),
'dbname' => $config [ 'replication_dbname' ],
],
]
);
if ( $mc_db_conn === NOERR ) {
$check_ok = true ;
} else {
$check_ok = false ;
}
// Restore the default connection.
enterprise_hook ( 'metaconsole_restore_db' );
}
if ( $check_ok === true ) {
$this -> cleanNotifications ( 'NOTIF.METACONSOLE.DB_CONNECTION' );
} else {
$this -> notify (
[
'type' => 'NOTIF.METACONSOLE.DB_CONNECTION' ,
'title' => __ ( 'Metaconsole DB is not available.' ),
2019-03-05 16:48:27 +01:00
'message' => __ ( 'Cannot connect with Metaconsole DB using current configuration.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=general&sec2=godmode/setup/setup§ion=enterprise' ),
2019-02-07 16:24:49 +01:00
]
);
}
}
/**
* Check if there are any incoming scheduled downtime in less than 15 d .
*
* @ return void
*/
public function checkDowntimes ()
{
// 15 Days.
$THRESHOLD_SECONDS = ( 15 * 3600 * 24 );
// Check first if any planned runtime is running.
$currently_running = ( int ) db_get_value_sql (
' SELECT count ( * ) as " n " FROM tplanned_downtime
WHERE executed = 1 '
);
if ( $currently_running > 0 ) {
$this -> notify (
[
'type' => 'NOTIF.DOWNTIME' ,
'title' => __ ( 'Scheduled downtime running.' ),
2019-03-05 16:48:27 +01:00
'message' => __ ( 'A scheduled downtime is running. Some monitoring data won\'t be available while downtime is taking place.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list' ),
2019-02-07 16:24:49 +01:00
]
);
return ;
} else {
// Retrieve downtimes.
$downtimes = db_get_all_rows_sql (
' SELECT * FROM tplanned_downtime
WHERE
( type_execution = " once " AND date_from > now ())
OR type_execution != " once " ORDER BY `id` DESC '
);
// Initialize searchers.
$next_downtime_begin = PHP_INT_MAX ;
$now = time ();
if ( $downtimes === false ) {
$this -> cleanNotifications ( 'NOTIF.DOWNTIME' );
return ;
}
$weekdays = [
'monday' ,
'tuesday' ,
'wednesday' ,
'thursday' ,
'friday' ,
'saturday' ,
'sunday' ,
];
foreach ( $downtimes as $dt ) {
if ( $dt [ 'type_execution' ] == 'once'
&& ( $dt [ 'date_from' ] - $now ) < $THRESHOLD_SECONDS
) {
if ( $next_downtime_begin > $dt [ 'date_from' ]) {
// Store datetime for next downtime.
$next_downtime_begin = $dt [ 'date_from' ];
$next_downtime_end = $dt [ 'date_to' ];
}
} else if ( $dt [ 'type_periodicity' ] == 'monthly' ) {
$schd_time_begin = explode (
':' ,
$dt [ 'periodically_time_from' ]
);
$schd_time_end = explode (
':' ,
$dt [ 'periodically_time_to' ]
);
$begin = mktime (
// Hour.
$schd_time_begin [ 0 ],
// Minute.
$schd_time_begin [ 1 ],
// Second.
$schd_time_begin [ 2 ],
// Month.
date ( 'n' , $now ),
// Day.
$dt [ 'periodically_day_from' ],
// Year.
date ( 'Y' , $now )
);
$end = mktime (
// Hour.
$schd_time_end [ 0 ],
// Minute.
$schd_time_end [ 1 ],
// Second.
$schd_time_end [ 2 ],
// Month.
date ( 'n' , $now ),
// Day.
$dt [ 'periodically_day_to' ],
// Year.
date ( 'Y' , $now )
);
if ( $next_downtime_begin > $begin ) {
$next_downtime_begin = $begin ;
$next_downtime_end = $end ;
}
} else if ( $dt [ 'type_periodicity' ] == 'weekly' ) {
// Always applies.
$current_week_day = date ( 'N' , $now );
$schd_time_begin = explode (
':' ,
$dt [ 'periodically_time_from' ]
);
$schd_time_end = explode (
':' ,
$dt [ 'periodically_time_to' ]
);
$i = 0 ;
$max = 7 ;
while ( $dt [ $weekdays [(( $current_week_day + $i ) % 7 )]] != 1
&& $max -- >= 0
) {
// Calculate day of the week matching downtime
// definition.
$i ++ ;
}
if ( $max < 0 ) {
// No days set.
continue ;
}
// Calculate utimestamp.
$begin = mktime (
// Hour.
$schd_time_begin [ 0 ],
// Minute.
$schd_time_begin [ 1 ],
// Second.
$schd_time_begin [ 2 ],
// Month.
date ( 'n' , $now ),
// Day.
( date ( 'j' , $now ) + $i + 1 ),
// Year.
date ( 'Y' , $now )
);
$end = mktime (
// Hour.
$schd_time_end [ 0 ],
// Minute.
$schd_time_end [ 1 ],
// Second.
$schd_time_end [ 2 ],
// Month.
date ( 'n' , $now ),
// Day.
( date ( 'j' , $now ) + $i + 1 ),
// Year.
date ( 'Y' , $now )
);
if ( $next_downtime_begin > $begin ) {
$next_downtime_begin = $begin ;
$next_downtime_end = $end ;
}
}
}
if ( $next_downtime_begin != PHP_INT_MAX ) {
$this -> notify (
[
'type' => 'NOTIF.DOWNTIME' ,
'title' => __ ( 'Downtime scheduled soon.' ),
'message' => __ (
2019-03-05 16:48:27 +01:00
'A scheduled downtime is going to be executed from %s to %s. Some monitoring data won\'t be available while downtime is taking place.' ,
2019-02-07 16:24:49 +01:00
date ( 'M j, G:i:s ' , $next_downtime_begin ),
date ( 'M j, G:i:s ' , $next_downtime_end )
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gagente&sec2=godmode/agentes/planned_downtime.list' ),
2019-02-07 16:24:49 +01:00
]
);
return ;
} else {
$this -> cleanNotifications ( 'NOTIF.DOWNTIME' );
}
}
}
/**
* Check if current instance of Pandora FMS is registered in Update Manager .
*
* @ return void
*/
public function checkUpdateManagerRegistration ()
{
global $config ;
2019-06-13 12:30:09 +02:00
include_once $config [ 'homedir' ] . '/include/functions_update_manager.php' ;
2019-02-07 16:24:49 +01:00
$login = get_parameter ( 'login' , false );
2019-05-14 17:15:28 +02:00
if ( update_manager_verify_registration () === false ) {
$this -> notify (
[
'type' => 'NOTIF.UPDATEMANAGER.REGISTRATION' ,
'title' => __ ( 'This instance is not registered in the Update manager section' ),
2021-03-11 15:40:23 +01:00
'message' => __ ( 'Click <a class="bolder underline" href="javascript: force_run_register();"> here</a> to start the registration process' ),
2019-05-14 17:15:28 +02:00
'url' => 'javascript: force_run_register();' ,
]
);
2019-02-07 16:24:49 +01:00
} else {
$this -> cleanNotifications ( 'NOTIF.UPDATEMANAGER.REGISTRATION' );
}
}
/**
* Check if user 'admin' is enabled and using default password .
*
* @ return void
*/
public function checkDefaultPassword ()
{
global $config ;
// Check default password for "admin".
$admin_with_default_pass = db_get_value_sql (
' SELECT count ( * ) FROM tusuario
WHERE
id_user = " admin "
AND password = " 1da7ee7d45b96d0e1f45ee4ee23da560 "
AND is_admin = 1
and disabled != 1 '
);
if ( $admin_with_default_pass > 0 ) {
$this -> notify (
[
'type' => 'NOTIF.SECURITY.DEFAULT_PASSWORD' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Default password for "Admin" user has not been changed' ),
'message' => __ ( 'Please, change the default password since it is a commonly reported vulnerability.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gusuarios&sec2=godmode/users/user_list' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.SECURITY.DEFAULT_PASSWORD' );
}
}
/**
* Undocumented function
*
* @ return void
*/
public function checkFont ()
{
global $config ;
2019-09-24 19:07:55 +02:00
$fontpath = io_safe_output ( $config [ 'fontpath' ]);
2020-10-07 16:03:52 +02:00
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
// Windows.
$fontpath = $config [ 'homedir' ] . '\include\fonts\\' . $fontpath ;
} else {
$home = str_replace ( '\\' , '/' , $config [ 'homedir' ]);
$fontpath = $home . '/include/fonts/' . $fontpath ;
}
2019-09-24 19:07:55 +02:00
if (( $fontpath == '' )
|| ( file_exists ( $fontpath ) === false )
2019-02-07 16:24:49 +01:00
) {
$this -> notify (
[
'type' => 'NOTIF.MISC.FONTPATH' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Default font doesn\'t exist' ),
'message' => __ ( 'Your defined font doesn\'t exist or is not defined. Please, check font parameters in your config' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/setup/setup§ion=vis' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.MISC.FONTPATH' );
}
}
/**
* Checks if develop_bypass is enabbled .
*
* @ return void
*/
public function checkDevelopBypass ()
{
global $develop_bypass ;
if ( $develop_bypass == 1 ) {
$this -> notify (
[
'type' => 'NOTIF.MISC.DEVELOPBYPASS' ,
'title' => __ ( 'Developer mode is enabled' ),
'message' => __ (
2019-03-05 16:48:27 +01:00
'Your %s has the "develop_bypass" mode enabled. This is a developer mode and should be disabled in a production environment. This value is located in the main index.php file' ,
2019-02-07 16:24:49 +01:00
get_product_name ()
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.MISC.DEVELOPBYPASS' );
}
}
/**
* Check if event storm protection is enabled .
*
* @ return void
*/
public function checkEventStormProtection ()
{
global $config ;
if ( $config [ 'event_storm_protection' ]) {
$this -> notify (
[
'type' => 'NOTIF.MISC.EVENTSTORMPROTECTION' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Event storm protection is enabled.' ),
'message' => __ ( 'Some events may get lost while this mode is enabled. The server must be restarted after altering this setting.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/setup/setup§ion=general' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.MISC.EVENTSTORMPROTECTION' );
}
}
/**
* Check if there ' re new updates available .
*
* @ return void
*/
public function checkUpdates ()
{
global $config ;
if ( isset ( $_SESSION [ 'new_update' ])) {
if ( ! empty ( $_SESSION [ 'return_installation_open' ])) {
if ( ! $_SESSION [ 'return_installation_open' ][ 'return' ]) {
foreach ( $_SESSION [ 'return_installation_open' ][ 'text' ] as $message ) {
$this -> notify (
[
'type' => 'NOTIF.UPDATEMANAGER.OPENSETUP' ,
2019-03-05 16:48:27 +01:00
'title' => __ ( 'Failed to retrieve updates, please configure utility' ),
2019-02-07 16:24:49 +01:00
'message' => $message ,
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/setup/setup§ion=general' ),
2019-02-07 16:24:49 +01:00
]
);
}
} else {
$this -> cleanNotifications ( 'NOTIF.UPDATEMANAGER.OPENSETUP' );
}
} else {
$this -> cleanNotifications ( 'NOTIF.UPDATEMANAGER.OPENSETUP' );
}
if ( $_SESSION [ 'new_update' ] == 'new' ) {
$this -> notify (
[
'type' => 'NOTIF.UPDATEMANAGER.UPDATE' ,
'title' => __ (
'New %s Console update' ,
get_product_name ()
),
2021-03-11 15:40:23 +01:00
'message' => __ ( 'There is a new update available. Please<a class="bolder" href="' . ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=online' ) . '"> go to Administration:Setup:Update Manager</a> for more details.' ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gsetup&sec2=godmode/update_manager/update_manager&tab=online' ),
2019-02-07 16:24:49 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.UPDATEMANAGER.UPDATE' );
}
} else {
$this -> cleanNotifications ( 'NOTIF.UPDATEMANAGER.OPENSETUP' );
$this -> cleanNotifications ( 'NOTIF.UPDATEMANAGER.UPDATE' );
}
}
2019-02-07 18:00:51 +01:00
/**
* Check if there ' re minor updates available .
*
* @ return void
*/
public function checkMinorRelease ()
{
global $config ;
$check_minor_release_available = db_check_minor_relase_available ();
if ( $check_minor_release_available ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/es/documentation/02_installation/02_anexo_upgrade#version_70ng_rolling_release' ;
2019-02-07 18:00:51 +01:00
if ( $config [ 'language' ] == 'es' ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/en/documentation/02_installation/02_anexo_upgrade#version_70ng_rolling_release' ;
2019-02-07 18:00:51 +01:00
}
$this -> notify (
[
'type' => 'NOTIF.UPDATEMANAGER.MINOR' ,
'title' => __ ( 'Minor release/s available' ),
'message' => __ (
2021-03-11 15:40:23 +01:00
'There is one or more minor releases available. <a id="aviable_updates" target="blank" href="%s">.About minor release update</a>.' ,
2019-02-07 18:00:51 +01:00
$url
),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=online' ),
2019-02-07 18:00:51 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.UPDATEMANAGER.MINOR' );
}
}
2019-02-19 11:13:07 +01:00
/**
* Check if CRON utility has been configured .
*
* @ return void
*/
public function checkCronRunning ()
{
global $config ;
// Check if DiscoveryCronTasks is running. Warn user if not.
if ( $config [ 'cron_last_run' ] == 0
|| ( get_system_time () - $config [ 'cron_last_run' ]) > 3600
) {
2019-03-05 16:48:27 +01:00
$message_conf_cron = __ ( 'DiscoveryConsoleTasks is not running properly' );
2019-02-19 11:13:07 +01:00
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) != 'WIN' ) {
2019-03-05 16:48:27 +01:00
$message_conf_cron .= __ ( 'Discovery relies on an appropriate cron setup.' );
2019-02-19 20:27:05 +01:00
$message_conf_cron .= '. ' . __ ( 'Please, add the following line to your crontab file:' );
2021-03-11 15:40:23 +01:00
$message_conf_cron .= '<b><pre class=""ui-dialog>* * * * * <user> wget -q -O - --no-check-certificate ' ;
2019-02-19 11:13:07 +01:00
$message_conf_cron .= str_replace (
ENTERPRISE_DIR . '/meta/' ,
'' ,
ui_get_full_url ( false )
);
$message_conf_cron .= ENTERPRISE_DIR . '/' . EXTENSIONS_DIR ;
2020-06-08 10:48:48 +02:00
$message_conf_cron .= '/cron/cron.php >> </pre>' ;
2020-06-12 09:40:12 +02:00
$message_conf_cron .= $config [ 'homedir' ] . '/log/cron.log</pre>' ;
2019-02-19 11:13:07 +01:00
}
if ( isset ( $config [ 'cron_last_run' ]) === true ) {
$message_conf_cron .= __ ( 'Last execution' ) . ': ' ;
$message_conf_cron .= date ( 'Y/m/d H:i:s' , $config [ 'cron_last_run' ]);
2019-03-05 16:48:27 +01:00
$message_conf_cron .= __ ( 'Please, make sure process is not locked.' );
2019-02-19 11:13:07 +01:00
}
$this -> notify (
[
'type' => 'NOTIF.CRON.CONFIGURED' ,
'title' => __ ( 'DiscoveryConsoleTasks is not configured.' ),
'message' => __ ( $message_conf_cron ),
2019-09-04 14:12:38 +02:00
'url' => ui_get_full_url ( 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist' ),
2019-02-19 11:13:07 +01:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.CRON.CONFIGURED' );
}
}
2019-05-14 17:15:28 +02:00
/**
* Search for messages .
*
* @ return void
*/
public function getUMMessages ()
{
global $config ;
2019-06-13 12:30:09 +02:00
include_once $config [ 'homedir' ] . '/include/functions_update_manager.php' ;
2019-05-14 17:15:28 +02:00
2019-05-14 23:49:01 +02:00
if ( update_manager_verify_registration () === false ) {
// Console not subscribed.
return ;
}
// Avoid contact for messages too much often.
2021-06-14 13:56:42 +02:00
if ( isset ( $config [ 'last_um_check' ]) === true
2019-05-14 23:49:01 +02:00
&& time () < $config [ 'last_um_check' ]
) {
return ;
}
2021-06-14 13:56:42 +02:00
$messages = update_manager_get_messages ();
if ( is_array ( $messages ) === true ) {
2019-05-14 17:15:28 +02:00
$source_id = get_notification_source_id (
'Official communication'
);
2021-06-14 13:56:42 +02:00
2019-05-14 17:15:28 +02:00
foreach ( $messages as $message ) {
2021-06-14 13:56:42 +02:00
if ( isset ( $message [ 'url' ]) === false ) {
2019-05-14 23:49:01 +02:00
$message [ 'url' ] = '#' ;
2019-05-14 17:15:28 +02:00
}
$this -> notify (
[
2019-05-14 23:49:01 +02:00
'type' => 'NOTIF.UPDATEMANAGER.MESSAGES.' . $message [ 'id' ],
2019-05-14 17:15:28 +02:00
'title' => $message [ 'subject' ],
'message' => base64_decode ( $message [ 'message_html' ]),
'url' => $message [ 'url' ],
],
$source_id
);
}
}
}
2019-09-30 12:48:46 +02:00
/**
2019-09-30 15:40:40 +02:00
* Check if all servers and console versions are the same
2019-09-30 12:48:46 +02:00
*
* @ return void
*/
public function checkConsoleServerVersions ()
{
2019-09-30 15:40:40 +02:00
global $config ;
2019-10-21 17:36:26 +02:00
// List all servers except satellite server.
2019-09-30 15:40:40 +02:00
$server_version_list = db_get_all_rows_sql (
2019-10-21 17:36:26 +02:00
sprintf (
' SELECT `name` , `version`
FROM tserver
2020-05-25 17:49:23 +02:00
WHERE server_type != % d
2019-10-21 17:36:26 +02:00
GROUP BY `version` ' ,
2020-05-25 17:49:23 +02:00
SERVER_TYPE_ENTERPRISE_SATELLITE
2019-10-21 17:36:26 +02:00
)
2019-09-30 12:48:46 +02:00
);
2019-10-21 17:36:26 +02:00
$missed = 0 ;
2019-09-30 12:48:46 +02:00
2019-10-21 17:36:26 +02:00
if ( is_array ( $server_version_list ) === true ) {
foreach ( $server_version_list as $server ) {
if ( strpos (
$server [ 'version' ],
2021-06-14 13:56:42 +02:00
$config [ 'current_package' ]
2019-10-21 17:36:26 +02:00
) === false
) {
$missed ++ ;
$title_ver_misaligned = __ (
'%s version misaligned with Console' ,
$server [ 'name' ]
);
$message_ver_misaligned = __ (
'Server %s and this console have different versions. This might cause several malfunctions. Please, update this server.' ,
$server [ 'name' ]
);
$this -> notify (
[
'type' => 'NOTIF.SERVER.MISALIGNED' ,
'title' => __ ( $title_ver_misaligned ),
'message' => __ ( $message_ver_misaligned ),
'url' => ui_get_full_url ( 'index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=online' ),
]
);
}
2019-09-30 15:40:40 +02:00
}
2019-09-30 12:48:46 +02:00
}
2019-10-21 17:36:26 +02:00
// Cleanup notifications if exception is recovered.
if ( $missed == 0 ) {
$this -> cleanNotifications ( 'NOTIF.SERVER.MISALIGNED' );
}
2019-09-30 12:48:46 +02:00
}
2020-04-07 18:40:47 +02:00
/**
* Check if AllowOveride is None or All .
*
* @ return void
*/
public function checkAllowOverrideEnabled ()
{
global $config ;
$message = 'If AllowOverride is disabled, .htaccess will not works.' ;
2020-05-11 12:24:18 +02:00
$message .= '<pre>Please check /etc/httpd/conf/httpd.conf to resolve this problem.' ;
2020-04-07 18:49:01 +02:00
// Get content file.
2020-04-07 18:40:47 +02:00
$file = file_get_contents ( '/etc/httpd/conf/httpd.conf' );
$file_lines = preg_split ( " # \r ? \n # " , $file , - 1 , PREG_SPLIT_NO_EMPTY );
$is_none = false ;
2020-04-07 18:49:01 +02:00
2020-04-08 10:36:40 +02:00
$i = 0 ;
2020-04-07 18:40:47 +02:00
foreach ( $file_lines as $line ) {
2020-04-08 10:36:40 +02:00
$i ++ ;
// Check Line and content.
if ( preg_match ( '/ AllowOverride/' , $line ) && $i === 311 ) {
2020-04-07 18:40:47 +02:00
$result = explode ( ' ' , $line );
2020-04-08 10:36:40 +02:00
if ( $result [ 5 ] == 'None' ) {
2020-04-07 18:40:47 +02:00
$is_none = true ;
$this -> notify (
[
'type' => 'NOTIF.ALLOWOVERRIDE.MESSAGE' ,
'title' => __ ( 'AllowOverride is disabled' ),
'message' => __ ( $message ),
2020-04-08 09:45:18 +02:00
'url' => ui_get_full_url ( 'index.php' ),
2020-04-07 18:40:47 +02:00
]
);
}
}
}
2020-04-07 18:49:01 +02:00
// Cleanup notifications if AllowOverride is All.
2020-04-07 18:40:47 +02:00
if ( ! $is_none ) {
$this -> cleanNotifications ( 'NOTIF.ALLOWOVERRIDE.MESSAGE' );
}
}
2020-05-25 17:49:23 +02:00
/**
* Check if AllowOveride is None or All .
*
* @ return void
*/
public function checkHaStatus ()
{
global $config ;
2020-05-26 11:00:22 +02:00
enterprise_include_once ( 'include/class/DatabaseHA.class.php' );
2020-05-27 13:07:59 +02:00
2020-05-26 11:00:22 +02:00
$cluster = new DatabaseHA ();
$nodes = $cluster -> getNodes ();
foreach ( $nodes as $node ) {
2020-09-24 13:05:17 +02:00
if ( $node [ 'status' ] == HA_DISABLED ) {
continue ;
}
2020-05-28 13:38:53 +02:00
$cluster_master = $cluster -> isClusterMaster ( $node );
$db_master = $cluster -> isDBMaster ( $node );
2020-05-27 13:07:59 +02:00
2020-05-28 13:38:53 +02:00
$message = '<pre>The roles played by node ' . $node [ 'host' ] . ' are out of sync :
Role in the cluster : Master
Role in the database : Slave Desynchronized operation in the node ' ;
2020-05-27 13:07:59 +02:00
2020-05-28 13:38:53 +02:00
if (( int ) $db_master !== ( int ) $cluster_master ) {
2020-05-26 11:00:22 +02:00
$this -> notify (
[
'type' => 'NOTIF.HAMASTER.MESSAGE' ,
'title' => __ ( 'Desynchronized operation on the node ' . $node [ 'host' ]),
'message' => __ ( $message ),
'url' => ui_get_full_url ( 'index.php?sec=gservers&sec2=enterprise/godmode/servers/HA_cluster' ),
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.HAMASTER.MESSAGE' );
}
}
2020-05-25 17:49:23 +02:00
}
2020-10-07 18:48:17 +02:00
/**
2020-06-08 10:48:48 +02:00
* Check if Pandora console log file remains in old location .
*
* @ return void
*/
public function checkPandoraConsoleLogOldLocation ()
{
global $config ;
if ( file_exists ( $config [ 'homedir' ] . '/pandora_console.log' )) {
$title_pandoraconsole_old_log = __ (
'Pandora FMS console log file changed location' ,
$config [ 'homedir' ]
);
$message_pandoraconsole_old_log = __ (
2020-06-11 10:00:53 +02:00
'Pandora FMS console log file has been moved to new location %s/log. Currently you have an outdated and inoperative version of this file at %s. Please, consider deleting it.' ,
2020-06-08 10:48:48 +02:00
$config [ 'homedir' ],
$config [ 'homedir' ]
);
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com/manual/en/quickguides/general_quick_guide#solving_problems_where_to_look_and_who_to_ask' ;
2020-06-11 10:00:53 +02:00
if ( $config [ 'language' ] == 'es' ) {
2021-06-24 14:31:15 +02:00
$url = 'https://pandorafms.com//manual/es/quickguides/general_quick_guide#solucion_de_problemas_donde_mirar_a_quien_preguntar' ;
2020-06-11 10:00:53 +02:00
}
2020-06-08 10:48:48 +02:00
$this -> notify (
[
'type' => 'NOTIF.PANDORACONSOLE.LOG.OLD' ,
'title' => __ ( $title_pandoraconsole_old_log ),
'message' => __ ( $message_pandoraconsole_old_log ),
2020-06-11 10:00:53 +02:00
'url' => $url ,
2020-06-08 10:48:48 +02:00
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.PANDORACONSOLE.LOG.OLD' );
}
}
/**
* Check if audit log file remains in old location .
*
* @ return void
*/
public function checkAuditLogOldLocation ()
{
global $config ;
if ( file_exists ( $config [ 'homedir' ] . '/audit.log' )) {
$title_audit_old_log = __ (
'Pandora FMS audit log file changed location' ,
$config [ 'homedir' ]
);
$message_audit_old_log = __ (
2020-06-11 10:00:53 +02:00
'Pandora FMS audit log file has been moved to new location %s/log. Currently you have an outdated and inoperative version of this file at %s. Please, consider deleting it.' ,
2020-06-08 10:48:48 +02:00
$config [ 'homedir' ],
$config [ 'homedir' ]
);
$this -> notify (
[
'type' => 'NOTIF.AUDIT.LOG.OLD' ,
'title' => __ ( $title_audit_old_log ),
'message' => __ ( $message_audit_old_log ),
'url' => '#' ,
]
);
} else {
$this -> cleanNotifications ( 'NOTIF.AUDIT.LOG.OLD' );
}
}
2020-10-13 18:24:10 +02:00
/**
* Clean Phantom cache if needed .
*
* @ return void
*/
public function checkCleanPhantomCache ()
{
global $config ;
if (( int ) $config [ 'clean_phantomjs_cache' ] !== 1 ) {
return ;
}
$cache_dir = $config [ 'homedir' ] . '/attachment/cache' ;
if ( is_dir ( $cache_dir ) === true ) {
rrmdir ( $cache_dir );
}
// Clean process has ended.
config_update_value (
'clean_phantomjs_cache' ,
0
);
}
2019-02-07 16:24:49 +01:00
}