0, 'fail' => 0];
$check = function ($name, $ok, $detail = '') use (&$stat) {
if ($ok) {
$stat['pass']++;
echo ' [PASS] ' . $name . PHP_EOL;
} else {
$stat['fail']++;
echo ' [FAIL] ' . $name . ($detail === '' ? '' : ' -> ' . $detail) . PHP_EOL;
}
};
$root = dirname(__DIR__, 2);
$host = $root . '/TinyImg';
$plugin = $root . '/TinyImgUploader';
// 拼接构造,避免测试代码自身成为「旧品牌字面量」的命中项
$forbidden = 'img' . 'url';
/** 递归收集文本文件(跳过第三方 layui 与二进制文件) */
function host_text_files($dir)
{
$out = [];
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS));
foreach ($it as $f) {
$path = str_replace('\\', '/', $f->getPathname());
if (strpos($path, '/static/layui/') !== false) {
continue;
}
$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
if (!in_array($ext, ['php', 'js', 'html', 'htm', 'css', 'txt', 'md', 'json', 'svg', 'htaccess'], true)
&& !in_array(basename($path), ['.htaccess', '.gitignore', 'LICENSE'], true)) {
continue;
}
$out[] = ['path' => $path, 'body' => file_get_contents($path)];
}
return $out;
}
$hostFiles = host_text_files($host);
$pluginFiles = host_text_files($plugin);
echo PHP_EOL . '1. 更名与版本号' . PHP_EOL;
$oldNameHits = 0;
foreach (array_merge($hostFiles, $pluginFiles) as $f) {
$oldNameHits += substr_count(strtolower($f['body']), $forbidden);
}
$check('两个工程源码里旧品牌字样为 0', $oldNameHits === 0, '命中 ' . $oldNameHits . ' 处');
$version = trim(file_get_contents($host . '/functions/version.txt'));
$check('版本号更新为 v2.0.0', strpos($version, 'v2.0.0') === 0, $version);
$check('版本文件带构建日期', (bool) preg_match('/\(\d{8}\)/', $version), $version);
$check('存在统一版本模块 functions/version.php', is_file($host . '/functions/version.php'));
$check('旧的 v1.40 版本号不再出现在版本文件', strpos($version, '1.40') === false);
$check('前台关于页读取统一版本号',
strpos(file_get_contents($host . '/about.php'), 'TINYIMG_VERSION') !== false);
$check('后台关于弹窗读取统一版本号',
strpos(file_get_contents($host . '/admin/about.php'), 'TINYIMG_VERSION') !== false);
$check('站点标题统一为 TinyImg',
strpos(file_get_contents($host . '/index.php'), 'TinyImg') !== false
&& strpos(file_get_contents($host . '/tpl/admin/header.php'), '
TinyImg
') !== false);
echo PHP_EOL . '2. SM.MS 上传通道已屏蔽 / 移除' . PHP_EOL;
$smUploadHits = 0;
foreach ($hostFiles as $f) {
$smUploadHits += substr_count(strtolower($f['body']), 'sm.ms/api');
}
$check('没有任何对 sm.ms 上传 API 的请求', $smUploadHits === 0, '命中 ' . $smUploadHits . ' 处');
$miniup = file_get_contents($host . '/miniup.html');
$check('极简上传页没有 SM.MS 选项卡', strpos($miniup, 'SM.MS') === false);
$check('极简上传页没有 #sm 文件输入', strpos($miniup, 'id="sm"') === false);
$check('极简上传页保留本站拖拽上传', strpos($miniup, 'id="upimg"') !== false);
$embed = file_get_contents($host . '/static/embed.js');
$check('embed.js 没有 smshow / deletesm 函数',
strpos($embed, 'function smshow') === false && strpos($embed, 'function deletesm') === false);
$check('embed.js 保留本站上传逻辑',
strpos($embed, "url: 'functions/upload.php'") !== false);
$left = file_get_contents($host . '/tpl/admin/left.php');
$check('后台左侧菜单没有 SM.MS 入口', strpos($left, 'smadmin.php') === false);
$check('后台左侧菜单新增 Token 设置入口', strpos($left, 'setting.php') !== false);
$check('后台顶部导航新增 Token 设置入口',
strpos(file_get_contents($host . '/tpl/admin/header.php'), './setting.php') !== false);
$check('前台导航没有 SM.MS 入口',
strpos(file_get_contents($host . '/tpl/user/header.php'), 'sm.php') === false);
$smPage = file_get_contents($host . '/sm.php');
$check('sm.php 返回 410 且不提供上传表单',
strpos($smPage, 'http_response_code(410)') !== false && strpos($smPage, 'id="sm"') === false);
$smFunc = file_get_contents($host . '/functions/sm.php');
$check('functions/sm.php fail closed,不写数据库',
strpos($smFunc, 'http_response_code(410)') !== false
&& strpos($smFunc, '$database->insert') === false);
$smAdmin = file_get_contents($host . '/admin/smadmin.php');
$check('admin/smadmin.php 不再查询数据库', strpos($smAdmin, 'querysm') === false);
$check('admin/delete.php 拒绝 type=sm',
strpos(file_get_contents($host . '/admin/delete.php'), "=== 'sm'") !== false);
$adminClass = file_get_contents($host . '/functions/class/class.admin.php');
$check('class.admin.php 已移除 querysm / deletesm',
strpos($adminClass, 'function querysm') === false && strpos($adminClass, 'function deletesm') === false);
$check('upgrade.php 不再创建 sm 表',
strpos(file_get_contents($host . '/upgrade.php'), 'CREATE TABLE') === false);
echo PHP_EOL . '3. Token 设置页与存储' . PHP_EOL;
$check('admin/setting.php 存在', is_file($host . '/admin/setting.php'));
$check('functions/token.php 存在', is_file($host . '/functions/token.php'));
$check('Token 存储文件带 PHP 守卫(不会通过 URL 泄漏)',
strpos(file_get_contents($host . '/functions/token.php'), "