1<?php 2/////////////////////////////////////////////////////////////////////////////// 3// 4// NagiosQL 5// 6/////////////////////////////////////////////////////////////////////////////// 7// 8// (c) 2005-2020 by Martin Willisegger 9// 10// Project : NagiosQL 11// Component : Variable definition list 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$preAccess = 1; 27$preNoMain = 1; 28// 29// Include preprocessing file 30// ========================== 31require $preBasePath.'functions/prepend_adm.php'; 32// 33// Process post parameters 34// ======================= 35$chkDataId = filter_input(INPUT_GET, 'dataId', FILTER_VALIDATE_INT, array('options' => array('default' => 0))); 36$chkMode = filter_input(INPUT_GET, 'mode', FILTER_SANITIZE_STRING); 37$chkDef = filter_input(INPUT_GET, 'def', FILTER_SANITIZE_STRING); 38$chkRange = filter_input(INPUT_GET, 'range', FILTER_SANITIZE_STRING); 39$chkLinkTab = filter_input(INPUT_GET, 'linktab', FILTER_SANITIZE_STRING); 40if (get_magic_quotes_gpc() == 0) { 41 $chkDef = addslashes($chkDef); 42 $chkRange = addslashes($chkRange); 43} 44// 45// Get data 46// ======== 47if ($chkLinkTab != '') { 48 $strSQL = 'SELECT * FROM `tbl_variabledefinition` LEFT JOIN `' .$chkLinkTab. '` ON `id`=`idSlave` ' . 49 "WHERE `idMaster`=$chkDataId ORDER BY `name`"; 50 $booReturn = $myDBClass->hasDataArray($strSQL, $arrDataLines, $intDataCount); 51 // 52 // Store data to session 53 // ============================ 54 if ($chkMode == '') { 55 $arrTemp = array(); 56 $_SESSION['variabledefinition'] = array(); 57 if ($booReturn && ($intDataCount != 0)) { 58 foreach ($arrDataLines as $elem) { 59 $arrTemp['id'] = $elem['id']; 60 $arrTemp['definition'] = addslashes($elem['name']); 61 $arrTemp['range'] = addslashes($elem['value']); 62 $arrTemp['status'] = 0; 63 $_SESSION['variabledefinition'][] = $arrTemp; 64 } 65 } 66 } 67} 68// 69// Add mode 70// ======== 71if ($chkMode == 'add') { 72 $arrTemp = array(); 73 if (isset($_SESSION['variabledefinition']) && is_array($_SESSION['variabledefinition'])) { 74 $intCheck = 0; 75 foreach ($_SESSION['variabledefinition'] as $key => $elem) { 76 if (($elem['definition'] == $chkDef) && ($elem['status'] == 0)) { 77 $_SESSION['variabledefinition'][$key]['definition'] = $chkDef; 78 $_SESSION['variabledefinition'][$key]['range'] = $chkRange; 79 $intCheck = 1; 80 } 81 } 82 if ($intCheck == 0) { 83 $arrTemp['id'] = 0; 84 $arrTemp['definition'] = $chkDef; 85 $arrTemp['range'] = $chkRange; 86 $arrTemp['status'] = 0; 87 $_SESSION['variabledefinition'][] = $arrTemp; 88 } 89 } else { 90 $arrTemp['id'] = 0; 91 $arrTemp['definition'] = $chkDef; 92 $arrTemp['range'] = $chkRange; 93 $arrTemp['status'] = 0; 94 $_SESSION['variabledefinition'][] = $arrTemp; 95 } 96} 97// 98// Deletion mode 99// ============= 100if ($chkMode == 'del' && isset($_SESSION['variabledefinition']) && is_array($_SESSION['variabledefinition'])) { 101 foreach ($_SESSION['variabledefinition'] as $key => $elem) { 102 if (($elem['definition'] == $chkDef) && ($elem['status'] == 0)) { 103 $_SESSION['variabledefinition'][$key]['status'] = 1; 104 } 105 } 106} 107?> 108<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 109<html> 110<head> 111 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 112 <title>None</title> 113 <link href="<?php echo $_SESSION['SETS']['path']['base_url']; ?>config/main.css" rel="stylesheet" type="text/css"> 114 <!--suppress JSUnresolvedVariable --> 115 <script type="text/javascript"> 116 function b64DecodeUnicode(str){ 117 return decodeURIComponent(atob(str).split('').map(function(c) { 118 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); 119 }).join('')); 120 } 121 function decodeHtml(html) { 122 let txt = document.createElement("textarea"); 123 txt.innerHTML = html; 124 return txt.value; 125 } 126 function doEdit(key,range) { 127 parent.document.frmDetail.txtVariablename.value = decodeURIComponent(key); 128 parent.document.frmDetail.txtVariablevalue.value = decodeHtml(b64DecodeUnicode(range)); 129 } 130 function doDel(key) { 131 let link; 132 link = '<?php echo $_SESSION['SETS']['path']['base_url']; ?>'; 133 link = link+'admin/variabledefinitions.php?dataId=<?php echo $chkDataId; ?>&mode=del&def='+key; 134 document.location.href = link; 135 } 136 </script> 137</head> 138<body style="margin:0"> 139 <table cellpadding="0" cellspacing="0" border="0" width="100%"> 140<?php 141if (isset($_SESSION['variabledefinition']) && is_array($_SESSION['variabledefinition']) && 142 (count($_SESSION['variabledefinition']) != 0)) { 143 foreach ($_SESSION['variabledefinition'] as $elem) { 144 if ($elem['status'] == 0) { 145?> 146 <tr> 147 <td class="tablerow" style="padding-bottom:2px; width:260px"><?php 148 echo htmlentities(stripslashes($elem['definition']), ENT_COMPAT, 'UTF-8'); ?></td> 149 <td class="tablerow" style="padding-bottom:2px; width:260px"><?php 150 echo $elem['range']; ?></td> 151 <td class="tablerow" style="width:50px" align="right"><img src="<?php 152 echo $_SESSION['SETS']['path']['base_url']; ?>images/edit.gif" width="18" height="18" alt="<?php 153 echo translate('Modify'); ?>" title="<?php echo translate('Modify'); ?>" onClick="doEdit('<?php 154 echo rawurlencode(stripslashes($elem['definition'])); ?>','<?php 155 echo base64_encode($elem['range']); ?>')" style="cursor:pointer"> <img src="<?php 156 echo $_SESSION['SETS']['path']['base_url']; ?>images/delete.gif" width="18" height="18" alt="<?php 157 echo translate('Delete'); ?>" title="<?php echo translate('Delete'); ?>" onClick="doDel('<?php 158 echo rawurlencode(stripslashes($elem['definition'])); ?>')" style="cursor:pointer"></td> 159 </tr> 160<?php 161 } 162 } 163} else { 164?> 165 <tr> 166 <td class="tablerow"><?php echo translate('No data'); ?></td> 167 <td class="tablerow"> </td> 168 <td class="tablerow" align="right"> </td> 169 </tr> 170<?php 171} 172?> 173 </table> 174</body> 175</html>