diff --git a/README.md b/README.md index 940cd61..e6c9386 100755 --- a/README.md +++ b/README.md @@ -96,14 +96,44 @@ $HTTP["url"] =~ "^/(i|public)/" { ``` - 或者参考:[https://blog.png.cm/996.html](https://blog.png.cm/996.html) -
点击查看2.0版更新日志 +## 更新日志 + +
点击查看2.0版更新日志 * 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为本图床修改版,会缓存到缓存文件夹方便下次调用 + - TimeThumb为本图床修改版,会缓存到缓存文件夹方便下次调用 * 2022-1-27 v2.4.7 - 优化页面排版 @@ -117,7 +147,6 @@ $HTTP["url"] =~ "^/(i|public)/" { - 更换验证码库并不再区分大小写 - 修复一处有概率暴露图片绝对路径的bug - * 2022-1-22 v2.4.6 - 视图优化 - 删除重复内容 @@ -317,7 +346,7 @@ RewriteRule config/(.*).(php)$ – [F] - ~~支持删除自定义删除图片(仅管理员)~~
-
与1.6.4版本差别 +
与1.6.4版本差别 ##### 不建议再使用 [EasyImage 1.6.4版本](https://github.com/icret/easyImages) @@ -352,7 +381,6 @@ RewriteRule config/(.*).(php)$ – [F] ## 兼容 - 最低`PHP 5.6`,推荐`PHP 7.0`及以上版本,需要PHP支持`Fileinfo,iconv,zip,mbstring,openssl`扩展,如果缺失会导致无法上传/删除图片 - 文件上传视图提供文件列表管理和文件批量上传功能,允许拖拽(需要`HTML5`支持)来添加上传文件,支持上传大图片,优先使用`HTML5`旧得浏览器自动使用`Flash和Silverlight`的方式兼容 - ## 鸣谢 @@ -362,4 +390,8 @@ 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) \ No newline at end of file + - 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) diff --git a/admin/admin.inc.php b/admin/admin.inc.php index e85bfbf..3a2e102 100755 --- a/admin/admin.inc.php +++ b/admin/admin.inc.php @@ -101,7 +101,25 @@ if (isset($_POST['radio'])) { // 恢复图片 if (isset($_GET['reimg'])) { $name = $_GET['reimg']; - re_checkImg($name); + if (re_checkImg($name)) { + echo " + + "; + } else { + echo " + + "; + } } ?> @@ -183,10 +201,10 @@ if (isset($_GET['reimg'])) { id="thumbnail0">
- id="thumbnail1"> + id="thumbnail1">
- id="thumbnail2"> + id="thumbnail2">
@@ -439,8 +457,8 @@ if (isset($_GET['reimg'])) { 外部KEY | 请根据需要申请并填写
- - + + " placeholder="隐藏的保存">
" placeholder="隐藏的保存"> @@ -448,16 +466,24 @@ if (isset($_GET['reimg'])) {
" placeholder="隐藏的保存">
- 生成API Token | 新Token需按要求填入/config/api_key.php才生效 +
+
+ + +
+ " placeholder="隐藏的保存"> + +
+ 生成API upload Token
- Generate token + New Token
@@ -486,11 +512,12 @@ if (isset($_GET['reimg'])) {
-
- - title="开启后会受服务器到https://moderatecontent.com速度影响,国内不建议开启! "> - -
+ +
@@ -538,7 +565,7 @@ if (isset($_GET['reimg'])) {
-

为了访问速度,仅显示最近20张图片;监黄需要在安全设置->开启图片监黄。

+

为了访问速度,仅显示最近20张图片;鉴黄需要在安全设置->开启图片鉴黄。

key申请地址: https://client.moderatecontent.com/

获得key后打开->API 设置->Moderate Key->填入

@@ -568,7 +595,7 @@ if (isset($_GET['reimg'])) { echo ' ' . $i . ' - + ' . $filen_name . ' ' . $file_size . ' @@ -577,7 +604,7 @@ if (isset($_GET['reimg'])) { 删除 - '; + '; } ?> diff --git a/application/function.php b/application/function.php index 5c75d86..4c269fc 100755 --- a/application/function.php +++ b/application/function.php @@ -93,7 +93,7 @@ function config_path($path = null) if (!is_writable($img_path)) { @chmod($img_path, 0755); } - + return $img_path; } @@ -613,22 +613,113 @@ 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; - $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 - $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; // 新路径含文件名 - $cache_dir = APP_ROOT . $config['path'] . 'suspic/'; // suspic路径 + if (empty($config['nsfwjs_url'])) { + exit; + } - if (is_dir($cache_dir)) { // 创建suspic目录并移动 + $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) + $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 . '
'; + // } + // } + + 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; // 新路径含文件名 + $cache_dir = APP_ROOT . $config['path'] . 'suspic/'; // suspic路径 + + if (is_dir($cache_dir)) { // 创建suspic目录并移动 rename($old_path, $new_path); } else { mkdir($cache_dir, 0777, true); @@ -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 " - - "; + return true; } } diff --git a/application/process.php b/application/process.php index 6fcd8f2..8392589 100755 --- a/application/process.php +++ b/application/process.php @@ -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); } } diff --git a/application/total_files.php b/application/total_files.php index bdc9e11..48842f0 100755 --- a/application/total_files.php +++ b/application/total_files.php @@ -51,7 +51,7 @@ function creat_json() // 创建json文件 $yestUpload = getFileNumber(APP_ROOT . $config['path'] . date("Y/m/d/", strtotime("-1 day"))); // 昨日上传数量 $totalJsonInfo = [ - 'filename' => $totalJsonMD5, // 统计文件名称 + 'filename' => $totalJsonMD5, // 统计文件名称 'date' => date('YmdH'), // 识别日期格式 'total_time' => date('Y-m-d H:i:s'), // 统计时间 'dirnum' => $dirn, // 文件夹数量 diff --git a/config/config.php b/config/config.php index 969e403..ece76b3 100755 --- a/config/config.php +++ b/config/config.php @@ -4,8 +4,8 @@ $config=Array 'title'=>'简单图床 - EasyImage', 'keywords'=>'简单图床,easyimage,无数据库图床,PHP多图长传程序,自适应页面,HTML5,markdown,bbscode,一键复制', 'description'=>'简单图床EasyImage是一款支持多文件上传的无数据库图床,可以完美替代PHP多图上传程序,最新html5自适应页面兼容手机电脑,上传后返回图片直链,markdown图片,论坛贴图bbscode链接,简单方便支持一键复制,支持多域名,api上传。', - 'tips'=>'
  • 单文件≤10M,单次上传≤30张
  • - 简单图床是一款开源图床, 支持多文件上传无数据库 + 'tips'=>'
  • 单文件≤10M,单次上传≤30张
  • + 简单图床是一款开源图床, 支持多文件上传无数据库 如果你喜欢这种图床风格就下载喔 (๑•̀ㅂ•́)و✧', 'domain'=>'http://127.0.0.1', 'imgurl'=>'http://127.0.0.1', @@ -43,17 +43,20 @@ $config=Array 'theme'=>'default', 'static_cdn_url'=>'https://cdn.jsdelivr.net/gh/icret/EasyImages2.0', 'TinyPng_key'=>'', + 'checkImg'=>0, + 'checkImg_value'=>50, 'moderatecontent_key'=>'', - 'footer'=>'请勿上传违反中国政策的图片 - + 'nsfwjs_url'=>'http://172.17.0.2:3307/api/nsfw/classify?url=', + 'footer'=>'请勿上传违反中国政策的图片 + ', 'ad_top'=>0, 'ad_top_info'=>' @@ -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' ); \ No newline at end of file