952 days continuous production uptime, 40k+ tp/s single node. Original corpo Bitbucket history not included — clean archive commit.
299 lines
13 KiB
PHP
299 lines
13 KiB
PHP
<?php
|
|
/**
|
|
* cachejefe.php -- the 21st-Century Namaste Cache Manager!
|
|
*
|
|
* This program uses the Material-Design Bootstrap framework which is licensed to Micheal Shallop, personally, but can
|
|
* can be distributed as a web-app under the developer license. (See the licensing files in ./html for more info)
|
|
*
|
|
* This program is a replacement for the old cache-manager program which has a stunning UI reminiscent of 2004. This
|
|
* app could be a lot more ajax-y but I'm about as far as it gets from being a f/e dev so you gets what you gets.
|
|
*
|
|
*
|
|
* @author mike@givingassistant.org
|
|
* @version 1.0
|
|
*
|
|
* HISTORY:
|
|
* ========
|
|
* 03-05-18 mks CORE-781: original coding
|
|
* 08-29-18 mks DB-50: replaced boots with sneakers
|
|
* 01-17-20 mks DB-150: squelching sneakerstrap stdout/stderr
|
|
*
|
|
*/
|
|
|
|
// initialization
|
|
ob_start();
|
|
require_once(dirname(__DIR__) . '/config/sneakerstrap.inc');
|
|
ob_end_clean();
|
|
ini_set('xdebug.var_display_max_depth', 10);
|
|
ini_set('xdebug.var_display_max_children', 256);
|
|
ini_set('xdebug.var_display_max_data', 1024);
|
|
$data = (isset($_REQUEST['data'])) ? $_REQUEST['data'] : STRING_CACHE_HOME;
|
|
$errorMessage = '';
|
|
$cRecord = null;
|
|
if (strlen($_REQUEST[STRING_CACHE_SEARCH])) {
|
|
// search all the keys for the submitted search string
|
|
$searchKey = htmlspecialchars($_REQUEST[STRING_CACHE_SEARCH]);
|
|
$cKeys = gasCache::getAllKeys();
|
|
$foundKeys = [];
|
|
foreach($cKeys as $key) {
|
|
if (stripos($key, $searchKey) !== false and (!in_array($key, $foundKeys))) {
|
|
$foundKeys[] = $key;
|
|
$tmp = "<a href='?data=delete&ckey=$key'><i class='fa fa-trash red-text'></i></a> ";
|
|
$tmp .= "<a href='?data=fetch&ckey=$key'><i class='fa fa-eye'></i> </a> " . $key . "<br>";
|
|
$keyData[] = $tmp;
|
|
}
|
|
}
|
|
$keyCount = count($foundKeys);
|
|
$data = STRING_CACHE_SEARCH;
|
|
} else {
|
|
// otherwise, they clicked on a nav-bar option
|
|
switch ($data) {
|
|
case STRING_CACHE_FETCH :
|
|
$cRecord = gasCache::sysGet($_REQUEST[STRING_CACHE_CKEY]);
|
|
if (!empty($cRecord) and !is_array($cRecord)) {
|
|
$extractedData = json_decode(gzuncompress($cRecord), true);
|
|
if (!is_null($extractedData))
|
|
$cRecord = $extractedData;
|
|
} elseif (empty($cRecord)) {
|
|
$errorMessage = 'Data referenced by key no longer exists in-cache; the key may have expired.';
|
|
}
|
|
break;
|
|
|
|
case STRING_CACHE_FLUSH :
|
|
$res = gasCache::flush_cache();
|
|
$cRecord = 'Cache was ' . ((!$res) ? '<span class="red-text">NOT</span> ' : '') . 'flushed successfully!';
|
|
break;
|
|
|
|
case STRING_CACHE_STATS :
|
|
$cData = gasCache::get_stats();
|
|
break;
|
|
|
|
case STRING_CACHE_DELETE :
|
|
gasCache::sysDel($_REQUEST[STRING_CACHE_CKEY]);
|
|
$delMsg = 'Key ' . $_REQUEST[STRING_CACHE_CKEY] . ' was deleted.';
|
|
break;
|
|
|
|
case STRING_CACHE_KEYS :
|
|
// get a list of all keys in cache
|
|
$keyList = gasCache::getAllKeys();
|
|
sort($keyList);
|
|
$foundKeys = [];
|
|
$counter = 1;
|
|
$keyData = [];
|
|
|
|
if (is_array($keyList)) {
|
|
foreach ($keyList as $cKey) {
|
|
if (!in_array($cKey, $foundKeys)) {
|
|
$foundKeys[] = $cKey;
|
|
$tmp = "<a href='?data=delete&ckey=$cKey'><i class='fa fa-trash red-text'></i></a> ";
|
|
$tmp .= "<a href='?data=fetch&ckey=$cKey'><i class='fa fa-eye'></i> </a> " . $cKey . "<br>";
|
|
$keyData[] = $tmp;
|
|
}
|
|
}
|
|
$keyCount = count($foundKeys);
|
|
}
|
|
break;
|
|
|
|
case STRING_CACHE_HOME :
|
|
; // do nothing
|
|
break;
|
|
}
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<title>Namaste Tools: Cache Jefe</title>
|
|
<!-- Font Awesome -->
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
|
<!-- Bootstrap core CSS -->
|
|
<link href="../html/css/bootstrap.min.css" rel="stylesheet">
|
|
<!-- Material Design Bootstrap -->
|
|
<link href="../html/css/mdb.min.css" rel="stylesheet">
|
|
<!-- Your custom styles (optional) -->
|
|
<link href="../html/css/style.css" rel="stylesheet">
|
|
</head>
|
|
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg justify-content-between navbar-dark blue-gradient">
|
|
<a class="navbar-brand" href="#">
|
|
<!--suppress CheckImageSize -->
|
|
<img src="../html/img/namaste.png" height="50" alt="">
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false"
|
|
aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="cachejefeNav">
|
|
<form method="post" action="">
|
|
<ul class="navbar-nav">
|
|
<li class="nav-item <?php if ($data == STRING_CACHE_HOME) echo 'active'; ?>">
|
|
<a class="nav-link" href="?data=home">Home <span class="sr-only">(current)</span></a>
|
|
</li>
|
|
<li class="nav-item <?php if ($data == STRING_CACHE_KEYS) echo 'active'; ?>">
|
|
<a class="nav-link" href="?data=keys">Keys </a>
|
|
</li>
|
|
<li class="nav-item <?php if ($data == STRING_CACHE_STATS) echo 'active'; ?>">
|
|
<a class="nav-link" href="?data=stats">Stats </a>
|
|
</li>
|
|
<li class="nav-item <?php if ($data == STRING_CACHE_FLUSH) echo 'active'; ?>">
|
|
<a class="nav-link" href="?data=flush">Flush </a>
|
|
</li>
|
|
</ul>
|
|
</form>
|
|
</div>
|
|
<!-- search box -->
|
|
<form method="post" action="" class="form-inline my-0">
|
|
<div class="md-form form-sm mt-0">
|
|
<input class="form-control form-control-sm mr-sm-2 mb-0" name="keyHash" type="text" maxlength="100" placeholder="Search (partials accepted)" aria-label="Search">
|
|
</div>
|
|
<button class="btn btn-outline-white btn-sm my-0" type="submit">Search</button>
|
|
</form>
|
|
</nav>
|
|
<?php
|
|
switch ($data) {
|
|
case STRING_CACHE_HOME :
|
|
echo
|
|
'<div style="height: 50vh">
|
|
<div class="flex-center flex-column">
|
|
<h1 class="animated fadeIn mb-4">Namaste Cache Jefe</h1>
|
|
<h5 class="animated fadeIn mb-3">Diagnostic and Debugging Tool</h5>
|
|
<p class="animated fadeIn text-muted">Making cache your bitch since 2011!</p>
|
|
|
|
<div class="text-left flex-column">
|
|
<br><br>
|
|
<p><strong>Home </strong>displays this page</p>
|
|
<p><strong>Keys </strong>lists all of the available keys currently stored in cache</p>
|
|
<p><strong>Stats </strong>displays cache stats output which as some useful information</p>
|
|
<p><strong>Flush </strong>flushes cache and <strong class="red-text">deletes </strong>ALL keys</p>
|
|
<p><strong>Search </strong>allows you to search by all or part of a cache key</p>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
break;
|
|
case STRING_CACHE_FETCH :
|
|
case STRING_CACHE_FLUSH :
|
|
echo
|
|
'<div class="container-fluid">
|
|
<div class="card">
|
|
<h4 class="card-body">
|
|
<div class="card-title"><strong>';
|
|
if ($data == STRING_CACHE_FETCH)
|
|
echo 'Cached Content for ' . $_REQUEST[STRING_CACHE_CKEY];
|
|
else
|
|
echo 'Cache Flush Request';
|
|
echo '</strong>
|
|
</div>
|
|
</h4>
|
|
<div class="card-text" style="margin-left:10px;">';
|
|
|
|
if (!is_null($cRecord) and is_array($cRecord))
|
|
var_dump($cRecord);
|
|
elseif (false !== $cRecord and is_scalar($cRecord))
|
|
echo $cRecord . '<br><br>';
|
|
elseif (!empty($errorMessage))
|
|
echo "<div class='text-danger'>" . $errorMessage . "</div>";
|
|
else
|
|
echo "<div class='text-danger'>" . ERROR_UNKNOWN_EVENT . $data . "</div>";
|
|
echo '</div></div></div>';
|
|
|
|
break;
|
|
case STRING_CACHE_STATS :
|
|
echo
|
|
'<br><div class="container-fluid">
|
|
<div class="flex-center flex-column">
|
|
<div class="card">
|
|
<h4 class="card-body ">
|
|
<strong>
|
|
<div class="card-title">Cache Stats</div>
|
|
</strong>
|
|
<span class="card-text">';
|
|
if (is_array($cData)) {
|
|
var_dump($cData);
|
|
} else {
|
|
echo "Could not retrieve cache stats";
|
|
}
|
|
echo '
|
|
</span>
|
|
</h4>
|
|
</div>
|
|
</div>
|
|
</div>';
|
|
break;
|
|
case STRING_CACHE_SEARCH :
|
|
case STRING_CACHE_KEYS :
|
|
case STRING_CACHE_DELETE :
|
|
?>
|
|
<br><br>
|
|
<div class="container-fluid">
|
|
<div class="row justify-content-md-center">
|
|
<div class="col">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<?php
|
|
if ($data == STRING_CACHE_KEYS) {
|
|
echo '<h5 class="card-title">Current Cached Key Count:' . $keyCount . '</h5>';
|
|
} elseif ($data == STRING_CACHE_DELETE) {
|
|
echo '<h5 class="card-title">' . $delMsg . '</h5>';
|
|
} else {
|
|
echo '<h5 class="card-title">Cached Key Search Results Count: ' . $keyCount . '</h5>';
|
|
}
|
|
?>
|
|
<span class="card-text">
|
|
<?php
|
|
if ($data != STRING_CACHE_DELETE) {
|
|
if ($keyCount) {
|
|
echo "Click the <i class='fa fa-trash red-text'></i> to delete a cached record. ";
|
|
echo "Click the <i class='fa fa-eye blue-text'></i> to view the cached record.";
|
|
} else {
|
|
if ($data == STRING_CACHE_KEYS) {
|
|
echo 'There are no records currently stored in the cache system.';
|
|
} else {
|
|
echo 'Search request: "' . $searchKey . '", returned no data.';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<br><br>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<br>
|
|
<?php
|
|
for ($index = 0; $index < $keyCount; $index+=3) {
|
|
echo '<div class="row">' . $eos;
|
|
if (!empty($keyData[$index]))
|
|
echo '<div class="col">' . $keyData[$index] . '</div>' . $eos;
|
|
if (!empty($keyData[($index + 1)]))
|
|
echo '<div class="col">' . $keyData[$index+1] . '</div>' . $eos;
|
|
if (!empty($keyData[($index + 2)]))
|
|
echo '<div class="col">' . $keyData[$index+2] . '</div>' . $eos;
|
|
echo '</div>' . $eos;
|
|
}
|
|
?>
|
|
</div>
|
|
<?php
|
|
break;
|
|
}
|
|
?>
|
|
|
|
<!-- SCRIPTS -->
|
|
<!-- JQuery -->
|
|
<script type="text/javascript" src="../html/js/jquery-3.2.1.min.js"></script>
|
|
<!-- Bootstrap tooltips -->
|
|
<script type="text/javascript" src="../html/js/popper.min.js"></script>
|
|
<!-- Bootstrap core JavaScript -->
|
|
<script type="text/javascript" src="../html/js/bootstrap.js"></script>
|
|
<!-- MDB core JavaScript -->
|
|
<script type="text/javascript" src="../html/js/mdb.min.js"></script>
|
|
</body>
|
|
|
|
</html>
|