Zhe Yang

KVDB第三方面板

简单的kvDB面板 使用basic认证 使用前先要改密码

<?php

$username=”wenfeng”;
$password=”swaen”;

if (isset($_SERVER[‘PHP_AUTH_USER’]) && $_SERVER[‘PHP_AUTH_USER’]== $username && $_SERVER[‘PHP_AUTH_PW’]==$password) {
?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″>

</head>
<body>
<p>用户名:<?=$username?></p>

<?
} else {
header(‘WWW-Authenticate: Basic realm=”Hellotianma Login”‘);
header(‘HTTP/1.1 401 Unauthorized’);
exit();
}
?>

 

<?php
$kv = new SaeKV();
$ret = $kv->init();
echo “KVDB初始化:”.($ret?”成功”:”失败(errno:”.$kv->errno().” errmsg:”.$kv->errmsg().”)”);
echo “<br/>==============================<br/>”;
?>
<form action=”#” method=”post” >
<p>操作:<select name=”m” ><option>list</option><option>add</option><option>set</option><option>get</option><option>replace</option><option>delete</option> </select> key:<input type=”text” name=”k”/>value:<input type=”text” name=”v”/><input type=”submit”/></p>

<?
if(isset($_POST[‘m’])){
$m=$_POST[‘m’];
// 增加key-value
$_key=$_POST[‘k’];
$_val=isset($_POST[‘v’])?$_POST[‘v’]:”;
if($m==’add’){
$ret = $kv->add($_key, $_val);
}
// 更新key-value
if($m==’set’){
$ret = $kv->set($_key, $_val);
}
// 替换key-value
if($m==’replace’){
$ret = $kv->replace($_key, $_val);
}
// 获得key-value
if($m==’get’){
$ret = $kv->get($_key);
echo “<b>$_key:<br/>==============<br/><pre>”;
var_dump($ret);
echo “</pre><br/>==============<br/></b>”;
}
// 删除key-value
if($m==’delete’){
$ret = $kv->delete($_key);
}

$er=$ret?”成功(“.$_key.”:”.$_val.”)”:”失败(errno:”.$kv->errno().” errmsg:”.$kv->errmsg().”)”;
echo “<br/>$m 操作返回:$er <br/> <br/>”;
}
$pk = isset($_POST[‘pk’])?$_POST[‘pk’]:”;
$sk = isset($_POST[‘sk’])?$_POST[‘sk’]:”;

$r=array();
$ret = $kv->pkrget($pk, 100,$sk);
end($ret);
$sk = key($ret);
//$all = isset($_POST[‘all’])?$_POST[‘all’]:false;
// 循环获取所有key-values
/*
if ($all)
{
while (true) {
$r=array_merge($r,$ret);
end($ret);
$start_key = key($ret);
$i = count($ret);
if ($i < 100) break;
$ret = $kv->pkrget($pk, 100, $start_key);
}
}
$r=array_merge($r,$ret);
*/

 

?>
<p>前缀:<input type=”text” name=”pk” value=”<?=$pk?>”/>start_key:<input type=”text” name=”sk” value=”<?=$sk?>”/><input type=”submit” value=”下一页”/></p>

<pre>
<?// 前缀搜索

var_dump($ret);
?>
</pre>
<p><input type=”submit” value=”下一页”/></p>
</form>
</body>
</html>

 

代码二

<?php
@session_start();
$pass = ‘saekv123456’;

function check_login(){
if(!isset($_SESSION[‘admin’])){
echo “<script>window.location.href=’saekv.php?a=index'</script>”;
exit;
}
}
$kv = new SaeKV();
$ret = $kv->init();

$a = isset($_GET[‘a’])?$_GET[‘a’]:’index’;
$k = isset($_REQUEST[‘k’])?$_REQUEST[‘k’]:”;
$v = isset($_POST[‘v’])?$_POST[‘v’]:”;
?>
<title>SAE KVDB Manager – Powered By actphp.com</title>
<div id=”header”>
<h3>SAE KVDB Manager</h3>
<a href=”saekv.php?a=set”>SET</a> | <a href=”saekv.php?a=get”>GET</a> | <a href=”saekv.php?a=del”>DEL</a> | <a href=”saekv.php?a=allkv”>ALL KV</a> | <a href=”saekv.php?a=logout”>Logout</a>
</div>
<?php
if($a == ‘index’){
echo ‘<form action=”?a=login” method=”post”>密码:’.”<input type=’passwd’ name=’passwd’ value=” /><br /><input type=’submit’ name=’submit’ value=’登录’ /><br /></form>”;

}else if($a == ‘login’){
$passwd = isset($_POST[‘passwd’])?$_POST[‘passwd’]:”;
if($passwd == $pass ){
$_SESSION[‘admin’] = 1;
}
echo “<script>window.location.href=’saekv.php?a=allkv'</script>”;
}else if($a == ‘set’){
check_login();
if(!empty($k) && !empty($v) ){
$kv->set($k,$v);
echo “<p>设置成功:{$k} => {$v}</p>”;
}else{
?>
<form action=”saekv.php?a=set” name=”setform” method=”post”>
<p> Key:<input type=”text” name=”k” value=”” /></p>
<p>Value:<input type=”text” name=”v” value=”” /></p>
<p> <input type=”submit” value=”设置” /></p>
</form>
<?php
}
}else if ($a == ‘get’){
check_login();
if(!empty($k)){
if(@file_exists(‘saekv://’.$k)){
echo “<p>取值成功:{$k} => <pre>”;
echo htmlspecialchars(file_get_contents(‘saekv://’.$k));
echo “</pre></p>”;
}else{
$v = $kv->get($k);
if($v !== false){
echo “<p>取值成功:{$k} => <pre>”;
if(is_array($v)){
print_r($v);
}else if(is_string($v)){
echo $v;
}else{
var_dump($v);
}
echo “</pre></p>”;
}else{
echo “<p>{$k}不存在!</p>”;
}
}

}else{
?>
<form action=”saekv.php?a=get” name=”setform” method=”post”>
<p> Key:<input type=”text” name=”k” value=”” /></p>
<p> <input type=”submit” value=”获得” /></p>
</form>

<?php
}
}else if($a == ‘del’){
check_login();
if(!empty($k) ){
$v = $kv->delete($k);
echo “<p>K:{$k}删除成功!</p>”;

}else if(!empty($_GET[‘k’])){
$v = $kv->delete($_GET[‘k’]);
echo “<p>K:{$_GET[‘k’]}删除成功!</p>”;

}
else{
?>
<form action=”saekv.php?a=del” name=”setform” method=”post”>
<p> Key:<input type=”text” name=”k” value=”” /></p>
<p> <input type=”submit” value=”删除” /></p>
</form>

<?php
}
}else if ($a ==’allkv’){
check_login();
$ret = $kv->pkrget(”, 100);
while (true) {
foreach($ret as $k=>$v)
echo “<p>K:{$k} <a href=\”saekv.php?a=get&k={$k}\”>GET</a> | <a href=\”saekv.php?a=del&k={$k}\” onclick=\”return confirm(‘确认删除?’);\” style=’color:red;’>DEL</a></p>”;
end($ret);
$start_key = key($ret);
$i = count($ret);
if ($i < 100) break;
$ret = $kv->pkrget(‘abc’, 100, $start_key);
}

}else if ($a ==’logout’){
@session_destroy();
echo “<script>window.location.href=’saekv.php?a=index'</script>”;
}
?>

码字很辛苦,转载请注明来自Zhe Yang@Shandong University《KVDB第三方面板》

评论