1<?php 2/////////////////////////////////////////////////////////////////////////////// 3// 4// NagiosQL 5// 6/////////////////////////////////////////////////////////////////////////////// 7// 8// (c) 2005-2020 by Martin Willisegger 9// 10// Project : NagiosQL 11// Component : Support page 12// Website : https://sourceforge.net/projects/nagiosql/ 13// Version : 3.4.1 14// GIT Repo : https://gitlab.com/wizonet/NagiosQL 15// 16/////////////////////////////////////////////////////////////////////////////// 17// 18// Path settings 19// =================== 20$strPattern = '(admin/[^/]*.php)'; 21$preRelPath = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING)); 22$preBasePath = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'SCRIPT_FILENAME', FILTER_SANITIZE_STRING)); 23// 24// Define common variables 25// ======================= 26$prePageId = 40; 27$preContent = 'admin/support.htm.tpl'; 28$preAccess = 1; 29$preFieldvars = 1; 30$setSaveLangId = 'private'; 31// 32// Include preprocessing files 33// =========================== 34require $preBasePath.'functions/prepend_adm.php'; 35require $preBasePath.'functions/prepend_content.php'; 36// 37// Start content 38// ============= 39$conttp->setVariable('TITLE', translate('NagiosQL support page')); 40$conttp->parse('header'); 41$conttp->show('header'); 42// 43// Single data form 44// ================ 45$conttp->setVariable('MAINSITE', $_SESSION['SETS']['path']['base_url']. 'admin.php'); 46foreach ($arrDescription as $elem) { 47 $conttp->setVariable($elem['name'], $elem['string']); 48} 49$conttp->setVariable('SUBTITLE_1', translate('Support contact information')); 50$conttp->setVariable('SUPPORT_TEXT_1', translate('For questions, the online support forum or contact information ' 51 . 'visit our website:')); 52$conttp->setVariable('WEBSITE_LINK', translate('NagiosQL on sourceforge')); 53// 54// Donation 55// ======== 56$conttp->setVariable('SUBTITLE_2', translate('Donate to support NagiosQL')); 57$conttp->setVariable('SUPPORT_TEXT_2', translate('If you like NagiosQL and it simplifies your daily work, then you ' 58 . 'may want to support the project by making a donation. This helps us to keep NagiosQL alive and to cover ' 59 . 'our costs. Thank you for your donation!')); 60$conttp->setVariable('DONATE_LINK', translate('Donate for NagiosQL on sourceforge')); 61// 62// Translations 63// ============ 64$conttp->setVariable('SUBTITLE_3', translate('Translation services')); 65$conttp->setVariable('SUPPORT_TEXT_3', translate('NagiosQL was translated into various languages. Since some ' 66 . 'translators are no longer available in later versions, there may be untranslated words or phrases. If ' 67 . 'you want to help us complete the translation, correct them or introduce a new language, then sign up ' 68 . 'with us now! The translations are simply feasible online - we use an open translation service where ' 69 . 'you can register for free at any time:')); 70$conttp->setVariable('TRANSLATION_LINK', translate('Transifex translation service')); 71// 72// GIT repository 73// ============== 74$conttp->setVariable('SUBTITLE_8', translate('GIT software repository')); 75$conttp->setVariable('SUPPORT_TEXT_5', translate('The NagiosQL sources are available on GitLab. There you will ' 76 .'always find the latest bugfixes and changes as well as older branches.')); 77$conttp->setVariable('GIT_LINK', translate('GitLab')); 78// 79// Online version check 80// ==================== 81$conttp->setVariable('SUBTITLE_4', translate('Version check')); 82if (!isset($SETS['common']['updcheck']) || ($SETS['common']['updcheck'] == '0')) { 83 $conttp->setVariable('SUPPORT_TEXT_4', translate('The online version check is not enabled. You can enable it ' 84 . 'on the settings page.')); 85} elseif (isset($SETS['common']['updcheck']) && ($SETS['common']['updcheck'] == '1')) { 86 $conttp->setVariable('SUPPORT_TEXT_4', translate('The online version check connects the NagiosQL page to find ' 87 . 'out, if your version is still up to date.')); 88 $conttp->setVariable('LOADER_IMAGE', $_SESSION['SETS']['path']['base_url']. 'images/loader.gif'); 89 $conttp->setVariable('VERSION_IF_SRC', $_SESSION['SETS']['path']['base_url']. 'admin/versioncheck.php?show=0'); 90 $conttp->parse('versioncheck_frame'); 91 $conttp->setVariable('VERSION_IF_SRC_RELOAD', $_SESSION['SETS']['path']['base_url']. 92 'admin/versioncheck.php?show=1'); 93 $conttp->parse('versioncheck_js'); 94} 95$conttp->setVariable('GIT_TITLE', translate('GIT code version')); 96$conttp->setVariable('GIT_VERSION', $setFileVersion.'-'.$setGITVersion); 97// 98// Environment check 99// ================= 100$conttp->setVariable('SUBTITLE_5', translate('Environment check')); 101// Javascript check 102$conttp->setVariable('FAILED', translate('failed')); 103$conttp->setVariable('OK', translate('ok')); 104// PHP version check 105$conttp->setVariable('PHP_VERSION', translate('PHP version')); 106if (PHP_VERSION_ID >= 50500) { 107 $conttp->setVariable('PHP_CLASS', 'checkgreen'); 108 $conttp->setVariable('PHP_RESULT', translate('ok'). ' (' .PHP_VERSION. ')'); 109} else { 110 $conttp->setVariable('PHP_CLASS', 'checkred'); 111 $conttp->setVariable('PHP_RESULT', translate('failed'). ' (' .PHP_VERSION. ' - ' 112 .translate('Required:'). ' 5.5.0)'); 113} 114// PHP modules / extensions 115$strExtPath = ini_get('extension_dir'); 116$strPrefix = (PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : ''; 117$conttp->setVariable('PHP_SESSION_MODULE', translate('PHP module:'). ' session'); 118if (extension_loaded('session')) { 119 $conttp->setVariable('PHP_SESSION_CLASS', 'checkgreen'); 120 $conttp->setVariable('PHP_SESSION_RESULT', translate('ok')); 121} else { 122 $conttp->setVariable('PHP_SESSION_CLASS', 'checkred'); 123 $conttp->setVariable('PHP_SESSION_RESULT', translate('failed')); 124} 125$conttp->setVariable('PHP_GETTEXT_MODULE', translate('PHP module:'). ' gettext'); 126if (extension_loaded('gettext')) { 127 $conttp->setVariable('PHP_GETTEXT_CLASS', 'checkgreen'); 128 $conttp->setVariable('PHP_GETTEXT_RESULT', translate('ok')); 129} else { 130 $conttp->setVariable('PHP_GETTEXT_CLASS', 'checkred'); 131 $conttp->setVariable('PHP_GETTEXT_RESULT', translate('failed')); 132} 133$conttp->setVariable('PHP_FTP_MODULE', translate('PHP module:'). ' ftp'); 134if (extension_loaded('ftp')) { 135 $conttp->setVariable('PHP_FTP_CLASS', 'checkgreen'); 136 $conttp->setVariable('PHP_FTP_RESULT', translate('ok')); 137 $intFTP_ok = 1; 138} else { 139 $conttp->setVariable('PHP_FTP_CLASS', 'checkorange'); 140 $conttp->setVariable('PHP_FTP_RESULT', translate('failed')); 141 $intFTP_ok = 0; 142} 143$conttp->setVariable('PHP_SSH2_MODULE', translate('PHP module:'). ' ssh'); 144if (extension_loaded('ssh2')) { 145 $conttp->setVariable('PHP_SSH2_CLASS', 'checkgreen'); 146 $conttp->setVariable('PHP_SSH2_RESULT', translate('ok')); 147 $intSSH_ok = 1; 148} else { 149 $conttp->setVariable('PHP_SSH2_CLASS', 'checkorange'); 150 $conttp->setVariable('PHP_SSH2_RESULT', translate('failed')); 151 $intSSH_ok = 0; 152} 153// Datenbankversion 154if ($SETS['db']['type'] == 'mysql') { 155 $conttp->setVariable('DB_VERSION', translate('MySQL version')); 156 $strSQL = "SHOW VARIABLES LIKE 'version'"; 157 $booReturn = $myDBClass->hasSingleDataset($strSQL, $arrDataset); 158 if ($booReturn && (count($arrDataset) != 0)) { 159 $strDBVersion = $arrDataset['Value']; 160 if (version_compare($strDBVersion, '5.0.0', '>=')) { 161 $conttp->setVariable('DB_CLASS', 'checkgreen'); 162 $conttp->setVariable('DB_RESULT', translate('ok'). ' (' .$strDBVersion. ')'); 163 } else { 164 $conttp->setVariable('DB_CLASS', 'checkorange'); 165 $conttp->setVariable('DB_RESULT', translate('failed'). ' (' .$strDBVersion. ' - ' .translate('Required:'). 166 ' 5.0.0)'); 167 } 168 } 169} 170// INI settings 171$conttp->setVariable('INI_FILE_UPLOADS', translate('PHP ini settings:'). ' file_uploads'); 172$strStatus1 = ini_get('file_uploads'); 173if (empty($strStatus1) || ($strStatus1 == 1)) { 174 $conttp->setVariable('INI_FILE_UPLOADS_CLASS', 'checkgreen'); 175 $conttp->setVariable('INI_FILE_UPLOADS_RESULT', translate('ok')); 176} else { 177 $conttp->setVariable('INI_FILE_UPLOADS_CLASS', 'checkred'); 178 $conttp->setVariable('INI_FILE_UPLOADS_RESULT', translate('failed')); 179} 180$conttp->setVariable('INI_AUTO_START', translate('PHP ini settings:'). ' session.auto_start'); 181$strStatus2 = ini_get('session.auto_start'); 182if (empty($strStatus2) || ($strStatus2 == 0)) { 183 $conttp->setVariable('INI_AUTO_START_CLASS', 'checkgreen'); 184 $conttp->setVariable('INI_AUTO_START_RESULT', translate('ok')); 185} else { 186 $conttp->setVariable('INI_AUTO_START_CLASS', 'checkred'); 187 $conttp->setVariable('INI_AUTO_START_RESULT', translate('failed')); 188} 189$conttp->setVariable('INI_SUHO_SESS_ENC', translate('PHP ini settings:'). ' suhosin.session.encrypt'); 190$strStatus3 = ini_get('suhosin.session.encrypt'); 191if (empty($strStatus3) || ($strStatus3 == 0)) { 192 $conttp->setVariable('INI_SUHO_SESS_ENC_CLASS', 'checkgreen'); 193 $conttp->setVariable('INI_SUHO_SESS_ENC_RESULT', translate('ok')); 194} else { 195 $conttp->setVariable('INI_SUHO_SESS_ENC_CLASS', 'checkred'); 196 $conttp->setVariable('INI_SUHO_SESS_ENC_RESULT', translate('failed')); 197} 198$conttp->setVariable('INI_DATE_TIMEZONE', translate('PHP ini settings:'). ' date.timezone'); 199$strStatus4 = ini_get('date.timezone'); 200if (!empty($strStatus4)) { 201 $conttp->setVariable('INI_DATE_TIMEZONE_CLASS', 'checkgreen'); 202 $conttp->setVariable('INI_DATE_TIMEZONE_RESULT', translate('ok'). ' (' .$strStatus4. ')'); 203} else { 204 $conttp->setVariable('INI_DATE_TIMEZONE_CLASS', 'checkred'); 205 $conttp->setVariable('INI_DATE_TIMEZONE_RESULT', translate('failed')); 206} 207// File access checks 208$conttp->setVariable('RW_CONFIG', translate('Read/Write access:'). ' settings.php'); 209$strConfigFile = '../config/settings.php'; 210if (file_exists($strConfigFile) && is_readable($strConfigFile) && is_writable($strConfigFile)) { 211 $conttp->setVariable('RW_CONFIG_CLASS', 'checkgreen'); 212 $conttp->setVariable('RW_CONFIG_RESULT', translate('ok')); 213} else { 214 $conttp->setVariable('RW_CONFIG_CLASS', 'checkred'); 215 $conttp->setVariable('RW_CONFIG_RESULT', translate('failed')); 216} 217// 218// Domain checks 219// ============= 220$myConfigClass->getConfigTargets($arrConfigSet); 221$intConfigId = $arrConfigSet[0]; 222$myConfigClass->getConfigValues($intConfigId, 'method', $intMethod); 223if ($intConfigId != 0) { 224 $conttp->setVariable('SUBTITLE_6', translate('Config domain checks')); 225 $conttp->setVariable('SUPPORT_TEXT_6', translate('The checks below are based on your data domain and config ' 226 . 'domain settings. To change the data domain, use the pull down menu in the upper right corner. Repeat ' 227 . 'this check for any data domain you have configured. To change the config domain, use the data domain ' 228 . 'menu and select a different config domain value.')); 229 $myConfigClass->getConfigValues($intConfigId, 'conffile', $strConffile); 230 $myConfigClass->getConfigValues($intConfigId, 'target', $strConfName); 231 $conttp->setVariable('DOMAIN_NAME', translate('Config domain name')); 232 $conttp->setVariable('DOMAIN_NAME_VALUE', $strConfName); 233 $conttp->setVariable('CONNECT_TYPE', translate('Connection type')); 234 if ($intMethod == 1) { 235 $conttp->setVariable('CONNECT_TYPE_CLASS', 'checkgreen'); 236 $conttp->setVariable('CONNECT_TYPE_RESULT', 'Fileaccess'); 237 } elseif ($intMethod == 2) { 238 if ($intFTP_ok == 1) { 239 $conttp->setVariable('CONNECT_TYPE_CLASS', 'checkgreen'); 240 $conttp->setVariable('CONNECT_TYPE_RESULT', 'FTP'); 241 } else { 242 $conttp->setVariable('CONNECT_TYPE_CLASS', 'checkred'); 243 $conttp->setVariable('CONNECT_TYPE_RESULT', 'FTP (no FTP module)'); 244 } 245 } elseif ($intMethod == 3) { 246 if ($intSSH_ok == 1) { 247 $conttp->setVariable('CONNECT_TYPE_CLASS', 'checkgreen'); 248 $conttp->setVariable('CONNECT_TYPE_RESULT', 'SSH/SFTP'); 249 } else { 250 $conttp->setVariable('CONNECT_TYPE_CLASS', 'checkred'); 251 $conttp->setVariable('CONNECT_TYPE_RESULT', 'SSH/SFTP (no SSH2 module)'); 252 } 253 } 254 $conttp->setVariable('CONNECT_CHECK', translate('Connection check')); 255 if ($intMethod == 1) { 256 $conttp->setVariable('CONNECT_CHECK_CLASS', 'checkgreen'); 257 $conttp->setVariable('CONNECT_CHECK_RESULT', translate('ok')); 258 } elseif ($intMethod == 2) { 259 $booReturn = 0; 260 if (empty($myConfigClass->resConnectId) || !is_resource($myConfigClass->resConnectId)) { 261 $booReturn = $myConfigClass->getFTPConnection($intConfigId); 262 } 263 if ($booReturn == 1) { 264 $conttp->setVariable('CONNECT_CHECK_CLASS', 'checkred'); 265 $conttp->setVariable('CONNECT_CHECK_RESULT', translate('failed')); 266 $myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage); 267 $intConnectCheck = 0; 268 } else { 269 $conttp->setVariable('CONNECT_CHECK_CLASS', 'checkgreen'); 270 $conttp->setVariable('CONNECT_CHECK_RESULT', translate('ok')); 271 $intConnectCheck = 1; 272 } 273 } elseif ($intMethod == 3) { 274 $booReturn = 0; 275 if (empty($myConfigClass->resConnectId) || !is_resource($myConfigClass->resConnectId)) { 276 $booReturn = $myConfigClass->getSSHConnection($intConfigId); 277 } 278 if ($booReturn == 1) { 279 $conttp->setVariable('CONNECT_CHECK_CLASS', 'checkred'); 280 $conttp->setVariable('CONNECT_CHECK_RESULT', translate('failed')); 281 $myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage); 282 $intConnectCheck = 0; 283 } else { 284 $conttp->setVariable('CONNECT_CHECK_CLASS', 'checkgreen'); 285 $conttp->setVariable('CONNECT_CHECK_RESULT', translate('ok')); 286 $intConnectCheck = 1; 287 } 288 } 289 $conttp->setVariable('RW_NAG_CONF', translate('Nagios config file')); 290 if ($intMethod == 1) { 291 if (file_exists($strConffile) && is_readable($strConffile)) { 292 if (is_writable($strConffile)) { 293 $conttp->setVariable('RW_NAG_CONF_CLASS', 'checkgreen'); 294 $conttp->setVariable('RW_NAG_CONF_RESULT', translate('ok')); 295 } else { 296 $conttp->setVariable('RW_NAG_CONF_CLASS', 'checkorange'); 297 $conttp->setVariable('RW_NAG_CONF_RESULT', translate('ok'). ' (' .translate('readonly'). ')'); 298 } 299 } else { 300 $conttp->setVariable('RW_NAG_CONF_CLASS', 'checkred'); 301 $conttp->setVariable('RW_NAG_CONF_RESULT', translate('failed')); 302 } 303 } elseif (($intMethod == 2) || ($intMethod == 3)) { 304 // Write file to temporary 305 $strFileName = tempnam($SETS['path']['tempdir'], 'nagiosql_conf'); 306 // Copy configuration from remote system 307 $intReturn = $myConfigClass->remoteFileCopy($strConffile, $intConfigId, $strFileName, 0); 308 if ($intReturn == 0) { 309 $intCheck = 0; 310 } else { 311 $intCheck = 1; 312 $myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage); 313 if (file_exists($strFileName)) { 314 unlink($strFileName); 315 } 316 } 317 // Copy configuration to remote system 318 if ($intCheck == 0) { 319 $intReturn = $myConfigClass->remoteFileCopy($strConffile, $intConfigId, $strFileName, 1); 320 if ($intReturn == 0) { 321 $intCheck = 0; 322 if (file_exists($strFileName)) { 323 unlink($strFileName); 324 } 325 } else { 326 $myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage); 327 $intCheck = 2; 328 if (file_exists($strFileName)) { 329 unlink($strFileName); 330 } 331 } 332 } 333 // Write Results 334 if ($intCheck == 0) { 335 $conttp->setVariable('RW_NAG_CONF_CLASS', 'checkgreen'); 336 $conttp->setVariable('RW_NAG_CONF_RESULT', translate('ok')); 337 } elseif ($intCheck == 1) { 338 $conttp->setVariable('RW_NAG_CONF_CLASS', 'checkred'); 339 $conttp->setVariable('RW_NAG_CONF_RESULT', translate('failed')); 340 } elseif ($intCheck == 2) { 341 $conttp->setVariable('RW_NAG_CONF_CLASS', 'checkorange'); 342 $conttp->setVariable('RW_NAG_CONF_RESULT', translate('ok'). ' (' .translate('readonly'). ')'); 343 } 344 } 345 $myConfigClass->getConfigValues($intConfigId, 'pidfile', $strPidfile); 346 $myConfigClass->getConfigValues($intConfigId, 'binaryfile', $strBinary); 347 $myConfigClass->getConfigValues($intConfigId, 'commandfile', $strCommandfile); 348 $conttp->setVariable('CHECK_NAG_LOCK', translate('Nagios process file')); 349 if ($intMethod == 1) { 350 if (substr_count(PHP_OS, 'Linux') != 0) { 351 exec('ps -ef | grep '.basename($strBinary).' | grep -v grep', $arrExec); 352 } else { 353 $arrExec[0] = 1; 354 } 355 if (isset($arrExec[0])) { 356 if (file_exists($strPidfile)) { 357 $conttp->setVariable('CHECK_NAG_LOCK_CLASS', 'checkgreen'); 358 $conttp->setVariable('CHECK_NAG_LOCK_RESULT', translate('ok')); 359 $intDemonOk = 0; 360 } else { 361 $conttp->setVariable('CHECK_NAG_LOCK_CLASS', 'checkred'); 362 $conttp->setVariable('CHECK_NAG_LOCK_RESULT', translate('failed') . ' (' 363 . translate('file is missed') . ')'); 364 $intDemonOk = 1; 365 } 366 } else { 367 $conttp->setVariable('CHECK_NAG_LOCK_CLASS', 'checkred'); 368 $conttp->setVariable('CHECK_NAG_LOCK_RESULT', translate('failed')); 369 $myVisClass->processMessage(translate('Nagios daemon is not running'), $strErrorMessage); 370 $intDemonOk = 1; 371 } 372 } elseif ($intMethod == 2) { 373 $conttp->setVariable('CHECK_NAG_LOCK_CLASS', 'checkorange'); 374 $conttp->setVariable('CHECK_NAG_LOCK_RESULT', translate('ok'). ' (' .translate('not used with FTP'). ')'); 375 $intDemonOk = 1; 376 } elseif ($intMethod == 3) { 377 $arrResultBinary = array(); 378 $arrResultPid = array(); 379 $intBinary = 1; 380 $intPid = 1; 381 if ($strBinary != '') { 382 $intBinary = $myConfigClass->sendSSHCommand('ps -ef | grep '.basename($strBinary).' | grep '. 383 basename($strConffile).' | grep -v grep', $arrResultBinary); 384 } 385 if ($strPidfile != '') { 386 $intPid = $myConfigClass->sendSSHCommand('ls ' . $strPidfile, $arrResult2); 387 } 388 if (($intBinary == 0) && ($intPid == 0)) { 389 $conttp->setVariable('CHECK_NAG_LOCK_CLASS', 'checkgreen'); 390 $conttp->setVariable('CHECK_NAG_LOCK_RESULT', translate('ok')); 391 $intDemonOk = 0; 392 } elseif (($intBinary == 0) && ($intPid == 1)) { 393 $conttp->setVariable('CHECK_NAG_LOCK_CLASS', 'checkred'); 394 $conttp->setVariable('CHECK_NAG_LOCK_RESULT', translate('failed'). ' (' .translate('file is missed'). ')'); 395 $intDemonOk = 1; 396 } else { 397 $conttp->setVariable('CHECK_NAG_LOCK_CLASS', 'checkred'); 398 $conttp->setVariable('CHECK_NAG_LOCK_RESULT', translate('failed'). ' (' .translate('demon dead'). ')'); 399 $myVisClass->processMessage(translate('Nagios daemon is not running'), $strErrorMessage); 400 $intDemonOk = 1; 401 } 402 } 403 // Command file 404 $conttp->setVariable('RW_NAG_COMMAND', translate('Nagios command file')); 405 if ($intMethod == 1) { 406 if (file_exists($strCommandfile) && is_readable($strCommandfile) && is_writable($strCommandfile)) { 407 if ($intDemonOk == 0) { 408 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkgreen'); 409 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('ok')); 410 } else { 411 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkorange'); 412 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('ok'). ' (' .translate('demon dead'). '?)'); 413 } 414 } 415 if (!file_exists($strCommandfile)) { 416 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkred'); 417 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('failed'). ' (' .translate('file is missed'). ')'); 418 } elseif (!is_writable($strCommandfile)) { 419 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkred'); 420 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('failed'). ' (' .translate('readonly'). ')'); 421 } elseif (!is_readable($strCommandfile)) { 422 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkred'); 423 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('failed')); 424 } 425 } elseif ($intMethod == 2) { 426 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkorange'); 427 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('ok'). ' (' .translate('not used with FTP'). ')'); 428 } elseif ($intMethod == 3) { 429 if ($strCommandfile != '') { 430 if ($intDemonOk == 0) { 431 $myConfigClass->sendSSHCommand('echo "TEST" >>' . $strCommandfile . '; echo $?; echo ""', $arrTemp); 432 if ($arrTemp[0] == 0) { 433 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkgreen'); 434 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('ok')); 435 } else { 436 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkred'); 437 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('failed'). ' (' 438 .translate('readonly'). ')'); 439 } 440 } elseif ($intDemonOk == 1) { 441 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkred'); 442 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('failed'). ' (' .translate('demon dead'). ')'); 443 } else { 444 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkred'); 445 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('failed'). ' (' 446 .translate('file is missed'). ')'); 447 } 448 } else { 449 $conttp->setVariable('RW_NAG_COMMAND_CLASS', 'checkred'); 450 $conttp->setVariable('RW_NAG_COMMAND_RESULT', translate('failed'). ' (' .translate('file is missed'). ')'); 451 } 452 } 453 // Binary file 454 $conttp->setVariable('EXE_NAG_BINARY', translate('Nagios binary file')); 455 if ($intMethod == 1) { 456 if (file_exists($strBinary)) { 457 if (is_executable($strBinary)) { 458 $conttp->setVariable('EXE_NAG_BINARY_CLASS', 'checkgreen'); 459 $conttp->setVariable('EXE_NAG_BINARY_RESULT', translate('ok')); 460 } else { 461 $conttp->setVariable('EXE_NAG_BINARY_CLASS', 'checkred'); 462 $conttp->setVariable('EXE_NAG_BINARY_RESULT', translate('failed'). ' (' 463 .translate('not executable'). ')'); 464 } 465 } else { 466 $conttp->setVariable('EXE_NAG_BINARY_CLASS', 'checkred'); 467 $conttp->setVariable('EXE_NAG_BINARY_RESULT', translate('failed'). ' (' .translate('file is missed'). ')'); 468 } 469 } elseif ($intMethod == 2) { 470 $conttp->setVariable('EXE_NAG_BINARY_CLASS', 'checkorange'); 471 $conttp->setVariable('EXE_NAG_BINARY_RESULT', translate('ok'). ' (' .translate('not used with FTP'). ')'); 472 } elseif ($intMethod == 3) { 473 $booReturn = 0; 474 /** @noinspection IsEmptyFunctionUsageInspection */ 475 if (empty($myConfigClass->resConnectId) || !is_resource($myConfigClass->resConnectId)) { 476 $booReturn = $myConfigClass->getSSHConnection($intConfigId); 477 } 478 if ($booReturn == 1) { 479 $myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage); 480 } else { 481 if (($strBinary != '') && ($strConffile != '') && 482 ($myConfigClass->sendSSHCommand('ls '.$strBinary, $arrTemp) == 0)) { 483 $myConfigClass->sendSSHCommand($strBinary.' -V', $arrResult); 484 if (!is_array($arrResult) || ($arrResult == false)) { 485 $conttp->setVariable('EXE_NAG_BINARY_CLASS', 'checkred'); 486 $conttp->setVariable('EXE_NAG_BINARY_RESULT', translate('failed'). ' (' . 487 translate('not executable'). ')'); 488 } else { 489 $conttp->setVariable('EXE_NAG_BINARY_CLASS', 'checkgreen'); 490 $conttp->setVariable('EXE_NAG_BINARY_RESULT', translate('ok')); 491 } 492 } else { 493 $conttp->setVariable('EXE_NAG_BINARY_CLASS', 'checkred'); 494 $conttp->setVariable('EXE_NAG_BINARY_RESULT', translate('failed'). ' (' . 495 translate('file is missed'). ')'); 496 } 497 } 498 } 499 // Check config files 500 $myConfigClass->getConfigValues($intConfigId, 'basedir', $strBasedir); 501 $myConfigClass->getConfigValues($intConfigId, 'hostconfig', $strHostdir); 502 $myConfigClass->getConfigValues($intConfigId, 'serviceconfig', $strServicedir); 503 $conttp->setVariable('SUBTITLE_7', translate('Verify configuration files and demon configuration')); 504 $conttp->setVariable('CONFIGURATION_NAME', translate('Configuration name')); 505 $conttp->setVariable('USED', translate('Used in data domain')); 506 $conttp->setVariable('DEMON_CONFIG', translate('Included in demon configuration'). ' (' 507 .basename($strConffile). ')'); 508 $arrConfig = array(); 509 $arrConfigFiles = array( 510 'Hosts' => array( 'table' => 'tbl_host', 'file' => 'directory'), 511 'Services' => array( 'table' => 'tbl_service', 'file' => 'directory'), 512 'Hostgroups' => array( 'table' => 'tbl_hostgroup', 'file' => 'hostgroups.cfg'), 513 'Servicegroups' => array( 'table' => 'tbl_servicegroup', 'file' => 'servicegroups.cfg'), 514 'Hosttemplates' => array( 'table' => 'tbl_hosttemplate', 'file' => 'hosttemplates.cfg'), 515 'servicetemplates' => array( 'table' => 'tbl_servicetemplate', 'file' => 'servicetemplates.cfg'), 516 'Contacts' => array( 'table' => 'tbl_contact', 'file' => 'contacts.cfg'), 517 'Contactgroups' => array( 'table' => 'tbl_contactgroup', 'file' => 'contactgroups.cfg'), 518 'Timeperiods' => array( 'table' => 'tbl_timeperiod', 'file' => 'timeperiods.cfg'), 519 'Contacttemplates' => array( 'table' => 'tbl_contacttemplate', 'file' => 'contacttemplates.cfg'), 520 'Commands' => array( 'table' => 'tbl_command', 'file' => 'commands.cfg'), 521 'Hostdependencies' => array( 'table' => 'tbl_hostdependency', 'file' => 'hostdependencies.cfg'), 522 'Hostescalations' => array( 'table' => 'tbl_hostescalation', 'file' => 'hostescalations.cfg'), 523 'Hostextinfo' => array( 'table' => 'tbl_hostextinfo', 'file' => 'hostextinfo.cfg'), 524 'Servicedependencies' => array( 'table' => 'tbl_servicedependency', 'file' => 'servicedependencies.cfg'), 525 'Serviceescalations' => array( 'table' => 'tbl_serviceescalation', 'file' => 'serviceescalations.cfg'), 526 'Serviceextinfo' => array( 'table' => 'tbl_serviceextinfo', 'file' => 'serviceextinfo.cfg')); 527 if ($intMethod == 1) { 528 $intCheck = 1; 529 if (file_exists($strConffile) && is_readable($strConffile)) { 530 $resFile = fopen($strConffile, 'rb'); 531 while (!feof($resFile)) { 532 $strLine = trim(fgets($resFile)); 533 if ((0 === strpos($strLine, 'c')) && ((substr_count($strLine, 'cfg_dir') != 0) || 534 (substr_count($strLine, 'cfg_file') != 0))) { 535 $arrConfig[] = $strLine; 536 } 537 } 538 $intCheck = 0; 539 fclose($resFile); 540 } 541 } elseif (($intMethod == 2) || ($intMethod == 3)) { 542 $intCheck = 1; 543 // Write file to temporary 544 $strFileName = tempnam($SETS['path']['tempdir'], 'nagiosql_conf'); 545 // Copy configuration from remote system 546 $intReturn = $myConfigClass->remoteFileCopy($strConffile, $intConfigId, $strFileName, 0); 547 if ($intReturn == 0) { 548 $intCheck = 0; 549 if (file_exists($strFileName) && is_readable($strFileName)) { 550 $resFile = fopen($strFileName, 'rb'); 551 while (!feof($resFile)) { 552 $strLine = trim(fgets($resFile)); 553 if ((0 === strpos($strLine, 'c')) && ((substr_count($strLine, 'cfg_dir') != 0) || 554 (substr_count($strLine, 'cfg_file') != 0))) { 555 $arrConfig[] = $strLine; 556 } 557 } 558 fclose($resFile); 559 $intCheck = 0; 560 } 561 } else { 562 $intCheck = 1; 563 $myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage); 564 if (file_exists($strFileName)) { 565 unlink($strFileName); 566 } 567 } 568 } 569 $i = 0; 570 foreach ($arrConfigFiles as $key => $elem) { 571 // Line colours 572 $strClassL = 'tdlb'; 573 $strClassM = 'tdmb'; 574 if ($i%2 == 1) { 575 $strClassL = 'tdld'; 576 $strClassM = 'tdmd'; 577 } 578 $conttp->setVariable('CLASS_L', $strClassL); 579 $conttp->setVariable('CLASS_M', $strClassM); 580 // Write configuiration name 581 $conttp->setVariable('CONFIG_NAME', $key); 582 // Count active datasets 583 $strSQL = 'SELECT * FROM `' .$elem['table']."` WHERE `active`='1' AND `config_id`=$chkDomainId"; 584 $booReturn = $myDBClass->hasDataArray($strSQL, $arrDataLines, $intDataCount); 585 if ($booReturn && ($intDataCount != 0)) { 586 $conttp->setVariable('ACTIVE_CONFIG_COUNT', '<span class="checkgreen">' .translate('ok'). ' (' . 587 $intDataCount. ')</span>'); 588 } elseif ($intDataCount == 0) { 589 $conttp->setVariable('ACTIVE_CONFIG_COUNT', '<span class="checkgreen">' .translate('not used'). '</span>'); 590 } else { 591 $conttp->setVariable('ACTIVE_CONFIG_COUNT', '<span class="checkred">' .translate('failed'). '</span>'); 592 $myVisClass->processMessage($myDBClass->strErrorMessage, $strErrorMessage); 593 } 594 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkred">' .translate('failed'). '</span> (' . 595 translate('cfg definition missed'). ')'); 596 if (($intCheck == 0) && is_array($arrConfig) && (count($arrConfig) != 0)) { 597 foreach ($arrConfig as $line) { 598 if ($elem['file'] != 'directory') { 599 if ((substr_count($line, 'cfg_dir=' .$strBasedir) != 0) && (substr_count($line, 'cfg_dir=' . 600 substr($strHostdir, 0, -1)) == 0) && (substr_count($line, 'cfg_dir=' . 601 substr($strServicedir, 0, -1)) == 0)) { 602 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkgreen">' .translate('ok'). 603 '</span> (' .$line. ')'); 604 break; 605 } 606 if (substr_count($line, $strBasedir.$elem['file']) != 0) { 607 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkgreen">' .translate('ok'). 608 '</span> (' .$line. ')'); 609 break; 610 } 611 if ($intDataCount == 0) { 612 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkorange">' .translate('ok'). 613 '</span> (' .translate('cfg definition missed, but actually not used'). ')'); 614 } elseif (substr_count($line, $elem['file']) != 0) { 615 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkred">' .translate('failed'). 616 '</span> (' .translate('wrong base path:'). ' ' .$line. ')'); 617 break; 618 } 619 } elseif ($elem['table'] == 'tbl_host') { 620 if (substr_count($line, 'cfg_dir=' .substr($strHostdir, 0, -1)) != 0) { 621 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkgreen">' .translate('ok'). 622 '</span> (' .$line. ')'); 623 break; 624 } 625 if ($intDataCount == 0) { 626 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkorange">' .translate('ok'). 627 '</span> (' .translate('cfg definition missed, but actually not used'). ')'); 628 break; 629 } 630 } elseif ($elem['table'] == 'tbl_service') { 631 if (substr_count($line, 'cfg_dir=' .substr($strServicedir, 0, -1)) != 0) { 632 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkgreen">' .translate('ok'). 633 '</span> (' .$line. ')'); 634 break; 635 } 636 if ($intDataCount == 0) { 637 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkorange">' .translate('ok'). 638 '</span> (' .translate('cfg definition missed, but actually not used'). ')'); 639 break; 640 } 641 } 642 } 643 } else { 644 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkred">' .translate('failed'). 645 '</span> (' .translate('cfg file not readable'). ')'); 646 } 647 $conttp->parse('configfileline'); 648 $i++; 649 } 650 // Check for unused config 651 if (($intCheck == 0) && is_array($arrConfig) && (count($arrConfig) != 0)) { 652 foreach ($arrConfig as $line) { 653 $intTest=0; 654 foreach ($arrConfigFiles as $elem) { 655 if (substr_count($line, $elem['file']) != 0) { 656 $intTest = 1; 657 } 658 } 659 if ($intTest == 0) { 660 if (substr_count($line, substr('cfg_dir=' .$strHostdir, 0, -1)) != 0) { 661 $intTest = 1; 662 } 663 if (substr_count($line, substr('cfg_dir=' .$strServicedir, 0, -1)) != 0) { 664 $intTest = 1; 665 } 666 //if (substr_count($line,substr("cfg_dir=".$strBasedir,0,-1)) != 0) $intTest = 1; 667 } 668 if ($intTest == 0) { 669 // Line colours 670 $strClassL = 'tdlb'; 671 $strClassM = 'tdmb'; 672 if ($i%2 == 1) { 673 $strClassL = 'tdld'; 674 $strClassM = 'tdmd'; 675 } 676 $conttp->setVariable('CLASS_L', $strClassL); 677 $conttp->setVariable('CLASS_M', $strClassM); 678 $conttp->setVariable('CONFIG_NAME', translate('Not used')); 679 $conttp->setVariable('ACTIVE_CONFIG_COUNT', '<span class="checkred">' .translate('failed'). '</span>'); 680 $conttp->setVariable('DEMON_CFG_OK', '<span class="checkred">' .translate('unused - please delete!'). 681 '</span> (' .$line. ')'); 682 $conttp->parse('configfileline'); 683 $i++; 684 } 685 } 686 } 687 $conttp->parse('configdomain'); 688} 689 690// Messages 691if ($strErrorMessage != '') { 692 $conttp->setVariable('ERRORMESSAGE', $strErrorMessage); 693} 694if ($strInfoMessage != '') { 695 $conttp->setVariable('INFOMESSAGE', $strInfoMessage); 696} 697// Check access rights for adding new objects 698if ($myVisClass->checkAccountGroup($prePageKey, 'write') != 0) { 699 $conttp->setVariable('ADD_CONTROL', 'disabled="disabled"'); 700} 701$conttp->parse('support'); 702$conttp->show('support'); 703// 704// Process footer 705// ============== 706$maintp->setVariable('VERSION_INFO', "<a href='https://sourceforge.net/projects/nagiosql/' " 707 . "target='_blank'>NagiosQL</a> $setFileVersion"); 708$maintp->parse('footer'); 709$maintp->show('footer'); 710