nagiosql/admin/delconfig.php

192 lines
8.2 KiB
PHP
Raw Permalink Normal View History

2017-05-22 11:24:21 +02:00
<?php
///////////////////////////////////////////////////////////////////////////////
//
// NagiosQL
//
///////////////////////////////////////////////////////////////////////////////
//
2019-04-17 11:40:50 +02:00
// (c) 2005-2018 by Martin Willisegger
2017-05-22 11:24:21 +02:00
//
// Project : NagiosQL
// Component : Admin file deletion
2019-04-17 11:40:50 +02:00
// Website : https://sourceforge.net/projects/nagiosql/
// Version : 3.4.0
// GIT Repo : https://gitlab.com/wizonet/NagiosQL
2017-05-22 11:24:21 +02:00
//
///////////////////////////////////////////////////////////////////////////////
//
2019-04-17 11:40:50 +02:00
// Path settings
// ===================
$strPattern = '(admin/[^/]*.php)';
$preRelPath = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING));
$preBasePath = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'SCRIPT_FILENAME', FILTER_SANITIZE_STRING));
//
2017-05-22 11:24:21 +02:00
// Define common variables
// =======================
2019-04-17 11:40:50 +02:00
$prePageId = 27;
$preContent = 'admin/delbackup.htm.tpl';
$preAccess = 1;
$preFieldvars = 1;
2017-05-22 11:24:21 +02:00
//
// Include preprocessing files
// ===========================
2019-04-17 11:40:50 +02:00
require $preBasePath.'functions/prepend_adm.php';
require $preBasePath.'functions/prepend_content.php';
2017-05-22 11:24:21 +02:00
//
// Get configuration set ID
// ========================
2019-04-17 11:40:50 +02:00
$myConfigClass->getConfigTargets($arrConfigSet);
2017-05-22 11:24:21 +02:00
$intConfigId = $arrConfigSet[0];
2019-04-17 11:40:50 +02:00
$myConfigClass->getConfigValues($intConfigId, 'method', $intMethod);
$myConfigClass->getConfigValues($intConfigId, 'basedir', $strBaseDir);
$myConfigClass->getConfigValues($intConfigId, 'hostconfig', $strHostDir);
$myConfigClass->getConfigValues($intConfigId, 'serviceconfig', $strServiceDir);
2017-05-22 11:24:21 +02:00
//
// Process form inputs
// ===================
2019-04-17 11:40:50 +02:00
/** @var array $chkMselValue1 */
if (($chkMselValue1[0] != '') && ($chkStatus == 1)) {
foreach ($chkMselValue1 as $elem) {
$intCheck = $myConfigClass->removeFile(trim($elem), $intConfigId);
$strFileTmp1 = str_replace($strServiceDir, '', $elem);
$strFileTmp2 = str_replace($strHostDir, '', $strFileTmp1);
$strFile = str_replace($strBaseDir, '', $strFileTmp2);
if ($intCheck == 0) {
$myDataClass->writeLog(translate('File deleted'). ': ' .trim($strFile));
$myVisClass->processMessage($strFile. ' ' .translate('successfully deleted'). '!', $strInfoMessage);
} else {
$myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage);
}
}
2017-05-22 11:24:21 +02:00
}
//
// Include content
// ===============
2019-04-17 11:40:50 +02:00
$conttp->setVariable('TITLE', translate('Delete config files'));
$conttp->parse('header');
$conttp->show('header');
$conttp->setVariable('LANG_SEARCH_STRING', translate('Filter string'));
$conttp->setVariable('LANG_SEARCH', translate('Search'));
$conttp->setVariable('LANG_DELETE', translate('Delete'));
$conttp->setVariable('LANG_DELETE_SEARCH', translate('Reset filter'));
$conttp->setVariable('DAT_SEARCH', $chkTfSearch);
$conttp->setVariable('BACKUPFILE', translate('Configuration file'));
$conttp->setVariable('LANG_REQUIRED', translate('required'));
$conttp->setVariable('MAKE', translate('Delete'));
$conttp->setVariable('ABORT', translate('Abort'));
$conttp->setVariable('CTRL_INFO', translate('Hold CTRL to select<br>more than one entry'));
$conttp->setVariable('IMAGE_PATH', $_SESSION['SETS']['path']['base_url']. 'images/');
$conttp->setVariable('ACTION_INSERT', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING));
2017-05-22 11:24:21 +02:00
// Build a local file list
if ($intMethod == 1) {
2019-04-17 11:40:50 +02:00
$output = array();
$myConfigClass->storeDirToArray($strBaseDir, "\.cfg", '\.cfg_old', $output, $strErrorMessage);
if (is_array($output) && (count($output) != 0)) {
foreach ($output as $elem2) {
if (($chkTfSearch == '') || (substr_count($elem2, $chkTfSearch) != 0)) {
$conttp->setVariable('DAT_BACKUPFILE', $elem2);
$conttp->parse('filelist');
}
}
}
} elseif ($intMethod == 2) {
// Open ftp connection
if ($myConfigClass->getFTPConnection($intConfigId) == '0') {
$arrFiles = array();
$arrFiles1 = ftp_nlist($myConfigClass->resConnectId, $strBaseDir);
if (is_array($arrFiles1)) {
$arrFiles = array_merge($arrFiles, $arrFiles1);
}
$arrFiles2 = ftp_nlist($myConfigClass->resConnectId, $strHostDir);
if (is_array($arrFiles2)) {
$arrFiles = array_merge($arrFiles, $arrFiles2);
}
$arrFiles3 = ftp_nlist($myConfigClass->resConnectId, $strServiceDir);
if (is_array($arrFiles3)) {
$arrFiles = array_merge($arrFiles, $arrFiles3);
}
if (is_array($arrFiles) && (count($arrFiles) != 0)) {
foreach ($arrFiles as $elem) {
if (!substr_count($elem, 'cfg')) {
continue;
}
if (($chkTfSearch == '') || (substr_count($elem, $chkTfSearch) != 0)) {
$conttp->setVariable('DAT_BACKUPFILE', str_replace('//', '/', $elem));
$conttp->parse('filelist');
}
}
}
ftp_close($myConfigClass->resConnectId);
} else {
$myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage);
}
} elseif ($intMethod == 3) {
// Open ssh connection
if ($myConfigClass->getSSHConnection($intConfigId) == '0') {
$intReturn = $myConfigClass->sendSSHCommand('ls '.$strBaseDir, $arrFiles1);
if (($intReturn == 0) && is_array($arrFiles1) && (count($arrFiles1) != 0)) {
foreach ($arrFiles1 as $elem) {
if (!substr_count($elem, 'cfg')) {
continue;
}
if (substr_count($elem, 'cgi.cfg') != 0) {
continue;
}
if (substr_count($elem, 'nagios.cfg') != 0) {
continue;
}
if (($chkTfSearch == '') || (substr_count($elem, $chkTfSearch) != 0)) {
$conttp->setVariable('DAT_BACKUPFILE', str_replace('//', '/', $strBaseDir. '/' .$elem));
$conttp->setVariable('DAT_BACKUPFILE_FULL', str_replace('//', '/', $strBaseDir. '/' .$elem));
$conttp->parse('filelist');
}
}
}
$intReturn = $myConfigClass->sendSSHCommand('ls '.$strHostDir, $arrFiles2);
if (($intReturn == 0) && is_array($arrFiles2) && (count($arrFiles2) != 0)) {
foreach ($arrFiles2 as $elem) {
if (!substr_count($elem, 'cfg')) {
continue;
}
if (($chkTfSearch == '') || (substr_count($elem, $chkTfSearch) != 0)) {
$conttp->setVariable('DAT_BACKUPFILE', str_replace('//', '/', $strHostDir. '/' .$elem));
$conttp->setVariable('DAT_BACKUPFILE_FULL', str_replace('//', '/', $strHostDir. '/' .$elem));
$conttp->parse('filelist');
}
}
}
$intReturn = $myConfigClass->sendSSHCommand('ls '.$strServiceDir, $arrFiles3);
if (($intReturn == 0) && is_array($arrFiles3) && (count($arrFiles3) != 0)) {
foreach ($arrFiles3 as $elem) {
if (!substr_count($elem, 'cfg')) {
continue;
}
if (($chkTfSearch == '') || (substr_count($elem, $chkTfSearch) != 0)) {
$conttp->setVariable('DAT_BACKUPFILE', str_replace('//', '/', $strServiceDir. '/' .$elem));
$conttp->setVariable('DAT_BACKUPFILE_FULL', str_replace('//', '/', $strServiceDir. '/' .$elem));
$conttp->parse('filelist');
}
}
}
} else {
$myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage);
}
2017-05-22 11:24:21 +02:00
}
2019-04-17 11:40:50 +02:00
if ($strErrorMessage != '') {
$conttp->setVariable('ERRORMESSAGE', $strErrorMessage);
}
$conttp->setVariable('INFOMESSAGE', $strInfoMessage);
2017-05-22 11:24:21 +02:00
// Check access rights for adding new objects
2019-04-17 11:40:50 +02:00
if ($myVisClass->checkAccountGroup($prePageKey, 'write') != 0) {
$conttp->setVariable('ADD_CONTROL', 'disabled="disabled"');
}
$conttp->parse('main');
$conttp->show('main');
2017-05-22 11:24:21 +02:00
//
// Footer ausgeben
// ===============
2019-04-17 11:40:50 +02:00
$maintp->setVariable('VERSION_INFO', "<a href='https://sourceforge.net/projects/nagiosql/' "
. "target='_blank'>NagiosQL</a> $setFileVersion");
$maintp->parse('footer');
$maintp->show('footer');