program, nvl({$query_mod2},'CPU') wait_class, user_id, count(*) n, sum(count(*)) over () total, sum(count(*)) over (partition by session_id || ',' || session_serial#) total_by_sid FROM v\$active_session_history WHERE sample_time > to_date('{$_POST['startDate']}', 'DD.MM.YYYY HH24:MI:SS') AND sample_time < to_date('{$_POST['endDate']}', 'DD.MM.YYYY HH24:MI:SS') {$query_mod1} GROUP BY session_id || ',' || session_serial#, program, nvl({$query_mod2},'CPU'), user_id ORDER BY 7 desc, 1)) h, dba_users u WHERE h.user_id = u.user_id and rank <= 10 ORDER BY rank SQL; } $start_time = microtime(true); $query = removeEmptyLines($query); $statement = oci_parse($connect, $query); oci_execute($statement); oci_fetch_all($statement, $results); if (sizeof($results["N"]) <= 0) { exit; } $sum_activity = $results["TOTAL"][0]; if ($_POST['type'] === 'top-sql' && $_POST['data'] === 'awr') { $sqlid_list = ''; foreach ($results['SQL_ID'] as $key => $val) { if (!strpos($sqlid_list, $val)) { $sqlid_list .= "'" . $val . "',"; } } if ($sqlid_list === '') {
function writeConfiguration($file, $key, $value) { $fileContent = ''; if (is_file($file)) { $fileContent = file_get_contents($file); $fileContent = removeEmptyLines($fileContent); } if ($fileContent != '') { // Replace $wasReplaced = false; $resultBuffer = ''; $lines = explode(PHP_EOL, $fileContent); $count = count($lines); for ($i = 0; $i < $count; $i++) { $line = trim($lines[$i]); if (preg_match('/' . $key . '/i', $line)) { $line = $key . '=' . $value; $wasReplaced = true; } if ($resultBuffer != '') { $resultBuffer .= PHP_EOL; } $resultBuffer .= $line; } if (!$wasReplaced) { if ($resultBuffer != '') { $resultBuffer .= PHP_EOL; } $resultBuffer .= $key . '=' . $value; } $fileContent = $resultBuffer; } else { $fileContent = $key . '=' . $value; } // store config file if (!file_put_contents($file, $fileContent, LOCK_EX)) { logMessage("Failed to write config file: {$file}"); return false; } logMessage("Wrote config file: " . $file); return true; }
function inserisci_conf($findme, $valore, $verbose = FALSE) { $file = 'Util/config.php'; // Apro il file di configurazione $fileT = 'Util/configTEMP.php'; //Testing purpose only $fr = fopen($file, 'r+'); // In lettura + scrittura, con il puntatore all'inizio del file $frT = fopen($fileT, 'r+'); //Testing purpose only $my_file = file_get_contents($file); // E lo leggo $lenght = strlen($findme); // quanto è lunga $pos = strpos($my_file, $findme); //cerco la cosa da cancellare if ($pos === false) { echo "The string '{$findme}' was not found in the string Util/config.php"; } else { echo $verbose ? "The string '{$findme}' was found in the string Util/config.php" : ""; echo $verbose ? " and exists at position {$pos} <br>" : ""; fseek($fr, $pos - $lenght, SEEK_SET); $PPP = PHP_EOL; $newfile = substr_replace($my_file, "{$valore}{$PPP}", $pos, 0); ftruncate($fr, 0); rewind($fr); $newfile = removeEmptyLines($newfile); fwrite($fr, $newfile); fclose($fr); fclose($frT); } }
<?php $fileStr = file_get_contents('rb.php'); $newStr = ''; function removeEmptyLines($string) { return preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $string); } $commentTokens = array(T_COMMENT); if (defined('T_DOC_COMMENT')) { $commentTokens[] = T_DOC_COMMENT; } // PHP 5 if (defined('T_ML_COMMENT')) { $commentTokens[] = T_ML_COMMENT; } // PHP 4 $tokens = token_get_all($fileStr); foreach ($tokens as $token) { if (is_array($token)) { if (in_array($token[0], $commentTokens)) { continue; } $token = $token[1]; } $newStr .= $token; } $newStr = removeEmptyLines($newStr); $newStr = str_replace("<" . "?php", "", $newStr); $newStr = "<" . "?php\n//Written by Gabor de Mooij and the RedBeanPHP Community, copyright 2009-2013\n//Licensed New BSD/GPLV2 - see license.txt\n" . $newStr; file_put_contents('rbnc.php', $newStr);