pull/18/head
icret 2022-02-01 03:51:02 +08:00
parent a035e68be2
commit 317d055781
6 changed files with 210 additions and 64 deletions

View File

@ -96,12 +96,42 @@ $HTTP["url"] =~ "^/(i|public)/" {
```
- 或者参考:[https://blog.png.cm/996.html](https://blog.png.cm/996.html)
<details><summary><mark><font color=darkred>点击查看2.0版更新日志</font></mark></summary>
## 更新日志
<details><summary><mark>点击查看2.0版更新日志</mark></summary>
* 2022-1-28 v2.4.8 dev
- 修复无可疑图片时显示错误
- 修复开启登录上传后无法上传的bug
- 增加安装时检测.user.ini
- 增加 [nsfwjs](https://github.com/infinitered/nsfwjs) 接口方式检测违规图片
- 作者测试时用的`docker`搭建 `docker`地址:[zengdawei/nsfw_restful_api
](https://hub.docker.com/r/zengdawei/nsfw_restful_api)
- 使用注意 程序希望的nsfwjs返回json 并且如下格式:
```json
[
{
"className": "Drawing",
"probability": 0.824431836605072
},
{
"className": "Hentai",
"probability": 0.16360442340373993
},
{
"className": "Neutral",
"probability": 0.007620695047080517
},
{
"className": "Porn",
"probability": 0.004154415801167488
},
{
"className": "Sexy",
"probability": 0.00018858206749428064
}
]
```
- 增加WordPress上大名鼎鼎的实时缩略图生成TimThumb
- TimeThumb为本图床修改版,会缓存到缓存文件夹方便下次调用
@ -117,7 +147,6 @@ $HTTP["url"] =~ "^/(i|public)/" {
- 更换验证码库并不再区分大小写
- 修复一处有概率暴露图片绝对路径的bug
* 2022-1-22 v2.4.6
- 视图优化
- 删除重复内容
@ -317,7 +346,7 @@ RewriteRule config/(.*).(php)$ [F]
- ~~支持删除自定义删除图片(仅管理员)~~
</details>
<details><summary><mark><font color=darkred>与1.6.4版本差别</font></mark></summary>
<details><summary><mark>与1.6.4版本差别</mark></summary>
##### 不建议再使用 [EasyImage 1.6.4版本](https://github.com/icret/easyImages)
@ -353,7 +382,6 @@ RewriteRule config/(.*).(php)$ [F]
- 最低`PHP 5.6`,推荐`PHP 7.0`及以上版本需要PHP支持`Fileinfo,iconv,zip,mbstring,openssl`扩展,如果缺失会导致无法上传/删除图片
- 文件上传视图提供文件列表管理和文件批量上传功能,允许拖拽(需要`HTML5`支持)来添加上传文件,支持上传大图片,优先使用`HTML5`旧得浏览器自动使用`Flash和Silverlight`的方式兼容
## 鸣谢
- [verot](https://github.com/verot/class.upload.php "verot" )
@ -363,3 +391,7 @@ RewriteRule config/(.*).(php)$ [F]
- [GPL-2.0](https://github.com/icret/EasyImages2.0/blob/master/LICENSE)
- Copyright © 2018 EasyImage dev By [Icret](https://github.com/icret)
* have fun!
[![Stargazers over time](https://starchart.cc/icret/EasyImages2.0.svg)](https://github.com/icret/EasyImages2.0/stargazers)

View File

@ -101,7 +101,25 @@ if (isset($_POST['radio'])) {
// 恢复图片
if (isset($_GET['reimg'])) {
$name = $_GET['reimg'];
re_checkImg($name);
if (re_checkImg($name)) {
echo "
<script>
new $.zui.Messager('恢复成功', {
type: 'success', // 定义颜色主题
icon: 'ok'
}).show();
</script>
";
} else {
echo "
<script>
new $.zui.Messager('文件不存在!', {
type: 'danger', // 定义颜色主题
icon: 'warning-sign'
}).show();
</script>
";
}
}
?>
@ -183,7 +201,7 @@ if (isset($_GET['reimg'])) {
<input type="radio" name="thumbnail" value="0" <?php if ($config['thumbnail'] === 0) echo 'checked="checked"'; ?> id="thumbnail0"><label for="thumbnail0" data-toggle="tooltip" title="直接输出上传图片,会导致流量增加"> 关闭</label>
</div>
<div class="radio-primary">
<input type="radio" name="thumbnail" value="1" <?php if ($config['thumbnail'] === 1) echo 'checked="checked"'; ?> id="thumbnail1"><label for="thumbnail1" data-toggle="tooltip" title="利用TimThumb生成 | 优点: 带缓存周期 缺点:无法生成webp动图"> 实时生成 | 推荐</label>
<input type="radio" name="thumbnail" value="1" <?php if ($config['thumbnail'] === 1) echo 'checked="checked"'; ?> id="thumbnail1"><label for="thumbnail1" data-toggle="tooltip" title="利用TimThumb生成 | 优点: 带缓存周期 缺点:无法生成webp动图,无法被cdn缓存"> 实时生成 | 推荐</label>
</div>
<div class="radio-primary">
<input type="radio" name="thumbnail" value="2" <?php if ($config['thumbnail'] === 2) echo 'checked="checked"'; ?> id="thumbnail2"><label for="thumbnail2" data-toggle="tooltip" title="优点: 缩略图直链 | 缺点: 无缓存周期, 每日首张缩略图会使广场页面代码布局异常 [ 刷新即可 ]"> 实时生成 | 缩略图直链</label>
@ -439,8 +457,8 @@ if (isset($_GET['reimg'])) {
<b>外部KEY | 请根据需要申请并填写</b>
<form class="form-inline" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" style="margin-bottom: 10px;">
<div class="form-group">
<label for="TinyPng" title="申请地址:https://tinypng.com/developers"><a href="https://tinypng.com/developers" target="_blank">TinyPng Key</a></label>
<input type="text" class="form-control input-sm" id="TinyPng" name="TinyPng_key" value="<?php echo $config['TinyPng_key']; ?>" placeholder="填入压缩图片Key" title="开启后会受服务器到https://tinypng.com 速度影响,国内不建议开启!" onkeyup="this.value=this.value.replace(/\s/g,'')">
<label for="TinyPng" data-toggle="tooltip" title="申请网址"><a href="https://tinypng.com/developers" target="_blank">TinyPng Key</a></label>
<input type="text" class="form-control input-sm" id="TinyPng" name="TinyPng_key" value="<?php echo $config['TinyPng_key']; ?>" placeholder="填入压缩图片Key" data-toggle="tooltip" title="开启后会受服务器到https://tinypng.com 速度影响,国内不建议开启!" onkeyup="this.value=this.value.replace(/\s/g,'')">
<input type="hidden" class="form-control" name="form" value="<?php echo date("Y-m-d H:i:s"); ?>" placeholder="隐藏的保存">
</div>
<input type="hidden" class="form-control" name="form" value="<?php echo date("Y-m-d H:i:s"); ?>" placeholder="隐藏的保存">
@ -448,16 +466,24 @@ if (isset($_GET['reimg'])) {
</form>
<form class="form-inline" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" style="margin-bottom: 10px;">
<div class="form-group">
<label for="moderatecontent_key" title="申请地址:https://client.moderatecontent.com"><a href="https://client.moderatecontent.com" target="_blank">Moderate Key</a></label>
<input type="text" class="form-control input-sm" name="moderatecontent_key" id="moderatecontent_key" value="<?php echo $config['moderatecontent_key']; ?>" placeholder="填入图片监黄Key" title="开启后会受服务器到https://moderatecontent.com 速度影响,国内不建议开启! " onkeyup="this.value=this.value.replace(/\s/g,'')">
<label for="moderatecontent_key" data-toggle="tooltip" title="申请网址"><a href="https://client.moderatecontent.com" target="_blank">Moderate Key</a></label>
<input type="text" class="form-control input-sm" name="moderatecontent_key" id="moderatecontent_key" value="<?php echo $config['moderatecontent_key']; ?>" placeholder="填入图片鉴黄Key" data-toggle="tooltip" title="开启后会受服务器到https://moderatecontent.com 速度影响,国内不建议开启! " onkeyup="this.value=this.value.replace(/\s/g,'')">
</div>
<input type="hidden" class="form-control" name="form" value="<?php echo date("Y-m-d H:i:s"); ?>" placeholder="隐藏的保存">
<button type="submit" class="btn btn-mini btn-primary">保存</button>
</form>
<b>生成API Token | 新Token需按要求填入<code>/config/api_key.php</code>才生效</b>
<form class="form-inline" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" style="margin-bottom: 10px;">
<div class="form-group">
<label for="nsfwjs_url" data-toggle="tooltip" title="nsfwjs github"><a href="https://github.com/infinitered/nsfwjs" target="_blank">nsfwjs url</a></label>
<input type="url" class="form-control input-sm" name="nsfwjs_url" id="nsfwjs_url" value="<?php echo $config['nsfwjs_url']; ?>" placeholder="http://IP:99/nsfw?url=" data-toggle="tooltip" title="自行搭建nsfwjs服务的网站地址" onkeyup="this.value=this.value.replace(/\s/g,'')">
</div>
<input type="hidden" class="form-control" name="form" 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">Generate token</span>
<span class="input-group-addon">New Token</span>
<input type="text" class="form-control" id="exampleInputMoney1" value="<?php echo privateToken(); ?>">
</div>
</form>
@ -486,11 +512,12 @@ if (isset($_GET['reimg'])) {
<div class="tab-pane fade" id="Content6">
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<div class="form-group">
<div class="switch switch-inline">
<input type="hidden" name="checkImg" value="0">
<input type="checkbox" name="checkImg" value="1" <?php if ($config['checkImg']) echo 'checked="checked"'; ?> title="开启后会受服务器到https://moderatecontent.com速度影响国内不建议开启! ">
<label style="font-weight: bold">开启图片监黄 | 申请key后填入API 设置的Moderate Key中</label>
</div>
<label data-toggle="tooltip" title="根据鉴黄方式在API 设置中填入Token或者url">图片鉴黄方式</label>
<select class="chosen-select form-control" name="checkImg">
<option value="0" <?php if ($config['checkImg'] == 0) echo 'selected'; ?>>关闭</option>
<option value="1" <?php if ($config['checkImg'] == 1) echo 'selected'; ?>>使用 moderatecontent</option>
<option value="2" <?php if ($config['checkImg'] == 2) echo 'selected'; ?>>使用 nsfwjs (据说准确率93%)</option>
</select>
</div>
<div class="form-group">
<label>图片违规判断准确率 | 当前: </label>
@ -538,7 +565,7 @@ if (isset($_GET['reimg'])) {
</form>
</div>
<div class="tab-pane fade" id="Content7">
<p>为了访问速度仅显示最近20张图片监黄需要在安全设置->开启图片监黄。</p>
<p>为了访问速度仅显示最近20张图片鉴黄需要在安全设置->开启图片鉴黄。</p>
<p>key申请地址: <a href="https://client.moderatecontent.com/" target="_blank">https://client.moderatecontent.com/</a></p>
<p>获得key后打开->API 设置->Moderate Key->填入 </p>
<div class="table-responsive">
@ -568,7 +595,7 @@ if (isset($_GET['reimg'])) {
echo '
<tr>
<td>' . $i . '</td>
<td><img data-toggle="lightbox" src="' . get_online_thumbnail($file_path) . '" data-image="' . $file_path . '" class="img-thumbnail" ></td>
<td><img data-toggle="lightbox" src="' . get_online_thumbnail($file_path) . '" data-image="' . $url . '" class="img-thumbnail" ></td>
<td>' . $filen_name . '</td>
<td>' . $file_size . '</td>
<td>

View File

@ -613,16 +613,107 @@ function moderatecontent_json($img, $url = null)
}
/**
* 检查图片是否违规
* @param $imageUrl string 图片url
* 使用curl方式实现get或post请求
* @param $url 请求的url地址
* @param $data 发送的post数据 如果为空则为get方式请求
* return 请求后获取到的数据
*/
function checkImg($imageUrl)
function nsfwjs_json($url, $data = '')
{
global $config;
if (empty($config['nsfwjs_url'])) {
exit;
}
$ch = curl_init();
$params[CURLOPT_URL] = $config['nsfwjs_url'] . $url; //请求url地址
$params[CURLOPT_HEADER] = false; //是否返回响应头信息
$params[CURLOPT_RETURNTRANSFER] = true; //是否将结果返回
$params[CURLOPT_FOLLOWLOCATION] = true; //是否重定向
$params[CURLOPT_TIMEOUT] = 30; //超时时间
if (!empty($data)) {
$params[CURLOPT_POST] = true;
$params[CURLOPT_POSTFIELDS] = $data;
}
$params[CURLOPT_SSL_VERIFYPEER] = false; //请求https时设置,还有其他解决方案
$params[CURLOPT_SSL_VERIFYHOST] = false; //请求https时,其他方案查看其他博文
curl_setopt_array($ch, $params); //传入curl参数
$content = curl_exec($ch); //执行
curl_close($ch); //关闭连接
$content = json_decode($content, true);
return $content;
}
/**
* 检查图片是否违规
* @param $imageUrl string 图片url
*/
function checkImg($imageUrl, $type = 1)
{
global $config;
/** # 使用moderatecontent */
if ($type == 1) {
$response = moderatecontent_json($imageUrl);
if ($response['rating_index'] == 3 or $response['predictions']['adult'] > $config['checkImg_value']) { // (1 = everyone, 2 = teen, 3 = adult)
//$old_path = APP_ROOT . parse_url($imageUrl)['path']; // 提交网址中的文件路径 /i/2021/10/29/p8vypd.png
$bad_pic = true;
}
}
/** # 使用nsfwjs */
if ($type == 2) {
/**
* probability概率
* className类型
*
* 上传图片后,总共会返回 5 个维度的数值来鉴别该图片的尺度:
*
* 绘画Drawing—— 无害的艺术,或艺术绘画;
* 变态Hentai—— 色情艺术,不适合大多数工作环境;
* 中立Neutral—— 一般,无害的内容;
* 色情Porn—— 不雅的内容和行为,通常涉及生殖器;
* 性感Sexy—— 不合时宜的挑衅内容。
*
* 当porn评分超过>=0.6左右,就几乎是一张带有色情性质的图片了。
*/
$file = nsfwjs_json($imageUrl);
// 将获取的值删除className后组建数组
for ($i = 0; $i <= count($file); $i++) {
if ($file[$i]['className'] == 'Drawing') {
$res['Drawing'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Hentai') {
$res['Hentai'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Neutral') {
$res['Neutral'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Porn') {
$res['Porn'] = $file[$i]['probability'];
}
if ($file[$i]['className'] == 'Sexy') {
$res['Sexy'] = $file[$i]['probability'];
}
}
// 测试数组是否正确
// foreach ($file as $k => $v) {
// foreach ($v as $k1 => $v1) {
// echo $k1 . '=>' . $v1 . '<br/>';
// }
// }
if ($res['Sexy'] * 100 > $config['checkImg_value'] or $res['Porn'] * 100 > $config['checkImg_value']) {
$bad_pic = true;
}
}
/** # 如果违规则移动图片到违规文件夹 */
if ($bad_pic == true) {
$old_path = APP_ROOT . str_replace($config['imgurl'], '', $imageUrl); // 提交网址中的文件路径 /i/2021/10/29/p8vypd.png
$name = date('Y_m_d') . '_' . basename($imageUrl); // 文件名 2021_10_30_p8vypd.png
$new_path = APP_ROOT . $config['path'] . 'suspic/' . $name; // 新路径含文件名
@ -650,15 +741,7 @@ function re_checkImg($name)
if (is_file($now_path_file)) {
$to_file = APP_ROOT . $config['path'] . $fileToPath; // 要还原图片的绝对位置 */i/2021/10/30/p8vypd.png
rename($now_path_file, $to_file); // 移动文件
} else {
echo "
<script>
new $.zui.Messager('文件不存在!', {
type: 'danger', // 定义颜色主题
icon: 'warning-sign'
}).show();
</script>
";
return true;
}
}

View File

@ -20,9 +20,12 @@ function process($filePath, $absolutePath)
}
// 图片违规检查
if ($config['checkImg']) {
require_once APP_ROOT . '/config/api_key.php';
@checkImg($config['imgurl'] . $filePath);
if ($config['checkImg'] == 1) {
@checkImg($config['imgurl'] . $filePath, 1);
}
if ($config['checkImg'] == 2) {
@checkImg($config['imgurl'] . $filePath, 2);
}
}

View File

@ -43,7 +43,10 @@ $config=Array
'theme'=>'default',
'static_cdn_url'=>'https://cdn.jsdelivr.net/gh/icret/EasyImages2.0',
'TinyPng_key'=>'',
'checkImg'=>0,
'checkImg_value'=>50,
'moderatecontent_key'=>'',
'nsfwjs_url'=>'http://172.17.0.2:3307/api/nsfw/classify?url=',
'footer'=>'<a href="/admin/terms.php" target="_blank">请勿上传违反中国政策的图片</a>
<script>
var _hmt = _hmt || [];
@ -69,8 +72,6 @@ var _hmt = _hmt || [];
'listNumber'=>20,
'customize'=>'',
'checkEnv'=>1,
'checkImg'=>0,
'checkImg_value'=>50,
'upload_logs'=>1,
'cache_freq'=>2,
'upload_first_show'=>1,
@ -80,6 +81,6 @@ var _hmt = _hmt || [];
'check_ip'=>0,
'check_ip_model'=>0,
'check_ip_list'=>'',
'version'=>'2.4.7',
'form'=>'2022-01-30 06:34:23'
'version'=>'2.4.8',
'form'=>'2022-02-01 03:21:02'
);