增加Token有效期

This commit is contained in:
= 2022-02-24 18:36:49 +01:00
parent 2e9764f1b4
commit 8be373cd8b
9 changed files with 197 additions and 56 deletions

View File

@ -105,6 +105,7 @@ $HTTP["url"] =~ "^/(i|public)/" {
* 2022-2-21 v2.5.4 Developing
- 增加回收图片
- 增加Token有效期
- 修复广场标题
* 2022-2-21 v2.5.3

View File

@ -38,6 +38,55 @@ if (isset($_POST['update'])) {
';
header("refresh:1;");
}
// 添加token
if (isset($_POST['add_token_id'])) {
// $_POST['add_token'] 生成的Token
// $_POST['add_token_id'] Token的ID
// $_POST['add_token_expired'] 过期时间
$postArr = array(
$_POST['add_token'] => array(
'id' => $_POST['add_token_id'], 'expired' => $_POST['add_token_expired'] * 86400 + time(), 'add_time' => time()
)
);
$new_config = array_replace($tokenList, $postArr);
$config_file = APP_ROOT . '/config/api_key.php';
cache_write($config_file, $new_config, 'tokenList');
echo '
<script>
new $.zui.Messager("上传用户添加成功!", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
</script>
';
header("refresh:1;");
}
// 禁用Token
if (isset($_GET['stop_token'])) {
// unset($tokenList[$_GET['delete_token']]);
$stop_token = $_GET['stop_token'];
$postArr = array(
$stop_token => array(
'id' => 0, 'expired' => time()
)
);
$new_config = array_replace($tokenList, $postArr);
$config_file = APP_ROOT . '/config/api_key.php';
cache_write($config_file, $new_config, 'tokenList');
echo '
<script>
new $.zui.Messager("禁用Token成功!", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
</script>
';
header("refresh:2;url=" . $config['domain'] . "/admin/admin.inc.php");
}
// 删除guset.config.php数组对
if (isset($_GET['delete_guest'])) {
unset($guestConfig[$_GET['delete_guest']]);
@ -88,16 +137,7 @@ if (isset($_POST['delDir'])) {
header("refresh:1;"); // 1s后刷新当前页面
}
}
// 查找用户ID或者Token
if (isset($_POST['radio'])) {
if ($_POST['radio'] == 'id') {
$radio_value = '用户token: ' . getIDToken($_POST['radio-value']);
} elseif ($_POST['radio'] == 'token') {
$radio_value = '用户ID: ' . getID($_POST['radio-value']);
} else {
$radio_value = null;
}
}
// 恢复图片
if (isset($_GET['reimg'])) {
$name = $_GET['reimg'];
@ -451,7 +491,7 @@ if (isset($_GET['reimg'])) {
</form>
</div>
<div class="tab-pane fade " id="Content5">
<h5>外部KEY | 请根据需要申请并填写</h5>
<h5>外部KEY</h5>
<form class="form-condensed" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" style="margin-bottom: 10px;">
<div class="form-group">
<label for="TinyPng" data-toggle="tooltip" title="申请网址"><a href="https://tinypng.com/developers" target="_blank">TinyPng Key &nbsp;</a></label>
@ -469,31 +509,30 @@ if (isset($_GET['reimg'])) {
<input type="hidden" class="form-control" name="update" value="<?php echo date("Y-m-d H:i:s"); ?>" placeholder="隐藏的保存">
<button type="submit" class="btn btn-mini btn-primary">保存</button>
</form>
<b data-toggle="tooltip" title="新Token需按要求填入/config/api_key.php才生效">生成新的API upload Token</b>
<form class="form-condensed" action="<?php $_SERVER['SCRIPT_NAME']; ?>" method="post">
<div class="input-group">
<span class="input-group-addon">New Token</span>
<input type="text" class="form-control" id="exampleInputMoney1" value="<?php echo privateToken(); ?>">
<hr>
<h5>上传Token</h5>
<div id="myDataGrid" class="datagrid">
<div class="input-control search-box search-box-circle has-icon-left has-icon-right" id="searchboxExample2" style="margin-bottom: 10px; max-width: 300px">
<input id="inputSearchExample2" type="search" class="form-control search-input input-sm" placeholder="搜索Token">
<label for="inputSearchExample2" class="input-control-icon-left search-icon"><i class="icon icon-search"></i></label>
<a href="#" class="input-control-icon-right search-clear-btn"><i class="icon icon-remove"></i></a>
</div>
</form>
<table class="table table-hover table-bordered table-condensed table-responsive" style="margin-top: 10px;">
<thead>
<tr>
<th>当前可用Token列表: </th>
</tr>
</thead>
<tbody>
<?php foreach ($tokenList as $value) echo '<tr><td>' . $value . '</td></tr>'; ?>
</tbody>
</table>
<form class="form-condensed" action="<?php $_SERVER['SCRIPT_NAME']; ?>" method="post">
<div class="datagrid-container"></div>
</div>
<form class="form-inline" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" style="margin-top: 10px;">
<div class="form-group">
<label for="exampleInputAccount6">根据ID/Token查找用户</label>
<input type="text" name="radio-value" id="exampleInputAccount6" class="form-control" placeholder="输入信息" value="<?php echo @$radio_value; ?>">
<div class="radio-primary"><input type="radio" name="radio" value="id" id="primaryradio1" checked="checked"><label for="primaryradio1">根据ID查找用户Token</label></div>
<div class="radio-primary"><input type="radio" name="radio" value="token" id="primaryradio2"><label for="primaryradio2">根据Token查找用户ID</label></div>
<button type="submit" class="btn btn-mini btn-primary">查找</button>
<label for="exampleInputEmail3">Token: </label>
<input type="text" class="form-control input-sm" id="exampleInputEmail3" name="add_token" value="<?php echo privateToken(); ?>">
</div>
<div class="form-group">
<label for="exampleInputInviteCode3">有效期: </label>
<input type="number" class="form-control input-sm" id="exampleInputInviteCode3" name="add_token_expired" value="30">
<label for="exampleInputInviteCode3"></label>
</div>
<input type="hidden" class="form-control" name="add_token_id" value="<?php echo count($tokenList); ?>" placeholder="隐藏的保存">
<button type="submit" class="btn btn-sm btn-primary">添加</button>
</form>
</div>
<div class="tab-pane fade" id="Content6">
@ -841,7 +880,7 @@ if (isset($_GET['reimg'])) {
<tr>
<td><?php echo $key; ?></td>
<td><?php echo $value; ?></td>
<td><a class='btn btn-mini btn-danger' href='admin.inc.php?delete_guest=$key'>删除</a></td>
<td><a class='btn btn-mini btn-danger' href='admin.inc.php?delete_guest=<?php echo $key; ?>'>删除</a></td>
</tr>
<?php endforeach; ?>
</tbody>
@ -855,7 +894,11 @@ if (isset($_GET['reimg'])) {
<link href="<?php static_cdn(); ?>/public/static/zui/lib/datetimepicker/datetimepicker.min.css" rel="stylesheet">
<script src="<?php static_cdn(); ?>/public/static/zui/lib/datetimepicker/datetimepicker.min.js"></script>
<script src="<?php static_cdn(); ?>/public/static/md5/md5.min.js"></script>
<link href="<?php static_cdn(); ?>/public/static/zui/lib/datagrid/zui.datagrid.min.css" rel="stylesheet">
<script src="<?php static_cdn(); ?>/public/static/zui/lib/datagrid/zui.datagrid.min.js"></script>
<?php /** 引入设置页面检测文件 */ if ($config['checkEnv']) require_once APP_ROOT . '/application/check_admin.inc.php'; ?>
<script>
// 使用本地存储记录当前tab页面
$('[data-tab]').on('shown.zui.tab', function(e) {
@ -928,6 +971,68 @@ if (isset($_GET['reimg'])) {
endDate: new Date() // 只能选当前日期之前
});
// Token 数据表格
$('#myDataGrid').datagrid({
dataSource: {
cols: [{
name: 'id',
label: 'ID',
width: 0.1
},
{
name: 'list',
label: '列表',
width: 0.4
},
{
name: 'add_time',
label: '添加时间',
html: true,
width: 0.2
},
{
name: 'expired',
label: '有效期至',
html: true,
width: 0.2
},
{
name: 'delete',
label: '删除',
html: true,
width: 0.1
},
],
array: [
<? foreach ($tokenList as $key => $value) :
if ($value['expired'] < time()) {
$expired = '<p class="text-gray">已过期</p>';
} else {
$expired = '<p class="text-green">' . date('Y年m月d日 H:i:s', $value['expired']) . '</p>';
}
?> {
id: '<?php echo $value['id']; ?>',
list: '<?php echo $key; ?>',
add_time: '<?php echo date('Y年m月d日 H:i:s', $value['add_time']); ?>',
expired: '<?php echo $expired; ?>',
delete: "<a class='btn btn-mini btn-danger' href='admin.inc.php?stop_token=<?php echo $key; ?>'>禁用</a>"
},
<?php endforeach; ?>
]
},
sortable: true,
hoverCell: true,
showRowIndex: false,
responsive: true,
// ... 其他初始化选项
});
// 获取数据表格实例
var myDataGrid = $('#myDataGrid').data('zui.datagrid');
// 按照 `name` 列降序排序
myDataGrid.sortBy('expired', 'desc');
// 更改网页标题
document.title = "图床设置 - <?php echo $config['title']; ?>"
</script>

View File

@ -58,8 +58,8 @@ function check_api($token)
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
}
if (!in_array($token, $tokenList)) {
// Token错误 Token错误
if (!in_array($tokenList[$token], $tokenList)) {
// Token 是否存在
$reJson = array(
"result" => 'failed',
'code' => 202,
@ -67,4 +67,14 @@ function check_api($token)
);
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
}
if ($tokenList[$token]['expired'] < time()) {
// Token 是否过期
$reJson = array(
"result" => 'failed',
'code' => 203,
'message' => 'Token Expired',
);
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
}
}

View File

@ -28,7 +28,7 @@ if ($handle->uploaded) {
// 允许上传的mime类型
$handle->allowed = array('image/*');
// 文件命名
$handle->file_new_name_body = imgName($handle->file_src_name_body) . '_' . getID($token);
$handle->file_new_name_body = imgName($handle->file_src_name_body) . '_' . $tokenList[$token]['id'];
// 最大上传限制
$handle->file_max_sizes = $config['maxSize'];
// 最大宽度

View File

@ -123,7 +123,7 @@
<div class="bottom-bar">
<a href="' . $imgUrl . '" target="_blank"><i class="icon icon-picture" data-toggle="tooltip" title="原图" style="margin-left:10px;"></i></a>
<a href="#" class="copy" data-clipboard-text="' . $imgUrl . '" data-toggle="tooltip" title="复制" style="margin-left:10px;"><i class="icon icon-copy"></i></a>
<a href="/application/info.php?img=' . $imgUrl . '" data-toggle="tooltip" title="详细信息" target="_blank" style="margin-left:10px;"><i class="icon icon-info-sign"></i></a>
<a href="/application/info.php?img=' . $imgUrl . '" data-toggle="tooltip" title="信息" target="_blank" style="margin-left:10px;"><i class="icon icon-info-sign"></i></a>
<a href="' . $config['domain'] . '/application/del.php?recycle_url=' . $imgUrl . '" target="_blank" data-toggle="tooltip" title="回收" style="margin-left:10px;"><i class="icon icon-undo"></i></a>
<a href="' . $config['domain'] . '/application/del.php?url=' . $imgUrl . '" target="_blank" data-toggle="tooltip" title="删除" style="margin-left:10px;"><i class="icon icon-trash"></i></a>
<label style="margin-left:10px;" class="text-primary"><input type="checkbox" style="margin: left 200px;" id="url" name="checkbox" value="' . $imgUrl . '"> 选择</label>

View File

@ -1,17 +1,22 @@
<?php
/**
* 此文件用来存放API Key
* 2021-11-6 14:36:35
*/
/*
* Token list 请在此填写需要配置Token的用户 前边编号有助于识别上传者ID
* 格式: ID数字需要从0开始,顺序添加)=> Token注意后边',')
*/
$tokenList = array(
0 => '8337effca0ddfcd9c5899f3509b23657',
1 => '1c17b11693cb5ec63859b091c5b9c1b2',
);
$tokenList=Array
(
'8337effca0ddfcd9c5899f3509b23657'=>Array
(
'id'=>0,
'expired'=>3373722730,
'add_time'=>1645722730
),
'1c17b11693cb5ec63859b091c5b9c1b2'=>Array
(
'id'=>1,
'expired'=>2509722743,
'add_time'=>1645722743
),
'3e2246984b5047c25dcf08dc41c367b8'=>Array
(
'id'=>2,
'expired'=>1645636354,
'add_time'=>1645722754
)
);

View File

@ -12,7 +12,7 @@ $config=Array
'user'=>'admin',
'password'=>'e6e061838856bf47e1de730719fb2609',
'mustLogin'=>0,
'apiStatus'=>0,
'apiStatus'=>1,
'path'=>'/i/',
'imgName'=>'default',
'maxSize'=>10485760,
@ -97,7 +97,7 @@ var _hmt = _hmt || [];
),
'language'=>0,
'version'=>'2.5.3',
'update'=>'2022-02-24 00:42:23',
'update'=>'2022-02-25 00:25:27',
'terms'=>'<div class="container">
<div class="row">
<div class="col-xs-3">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long