diff --git a/README.md b/README.md index 6ffbd1f..67c0b9d 100755 --- a/README.md +++ b/README.md @@ -66,6 +66,9 @@ RewriteRule config/(.*).(php)$ – [F]
点击查看2.0版更新日志 +* 2021-11-14 v2.4.2 +- 增加上传日志 + * 2021-11-12 v2.4.1 - 增加缓存周期配置 - 增加上传统计 diff --git a/admin/admin.inc.php b/admin/admin.inc.php index 436a480..d5ee4c1 100755 --- a/admin/admin.inc.php +++ b/admin/admin.inc.php @@ -303,13 +303,6 @@ if (isset($_POST['form'])) { -
-
- - > - -
-
@@ -332,7 +325,24 @@ if (isset($_POST['form'])) {
-

当前软件版本:

+
+ + > + +
+
+
+
+ + title="日志每月保存一个文件;经过测试每月二十万条数据并不影响速度!"> + +
+
+
+

+ 当前版本: + Github: +

diff --git a/admin/logs/verson/verson.json b/admin/logs/verson/verson.json new file mode 100755 index 0000000..a11e839 --- /dev/null +++ b/admin/logs/verson/verson.json @@ -0,0 +1,41 @@ +{ + "url": "https://api.github.com/repos/icret/EasyImages2.0/releases/53294083", + "assets_url": "https://api.github.com/repos/icret/EasyImages2.0/releases/53294083/assets", + "upload_url": "https://uploads.github.com/repos/icret/EasyImages2.0/releases/53294083/assets{?name,label}", + "html_url": "https://github.com/icret/EasyImages2.0/releases/tag/2.4.1", + "id": 53294083, + "author": { + "login": "icret", + "id": 16373024, + "node_id": "MDQ6VXNlcjE2MzczMDI0", + "avatar_url": "https://avatars.githubusercontent.com/u/16373024?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/icret", + "html_url": "https://github.com/icret", + "followers_url": "https://api.github.com/users/icret/followers", + "following_url": "https://api.github.com/users/icret/following{/other_user}", + "gists_url": "https://api.github.com/users/icret/gists{/gist_id}", + "starred_url": "https://api.github.com/users/icret/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/icret/subscriptions", + "organizations_url": "https://api.github.com/users/icret/orgs", + "repos_url": "https://api.github.com/users/icret/repos", + "events_url": "https://api.github.com/users/icret/events{/privacy}", + "received_events_url": "https://api.github.com/users/icret/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOCzgjBc4DLTQD", + "tag_name": "2.4.1", + "target_commitish": "master", + "name": "EasyImage2.0 简单图床 ver:2.4.1", + "draft": false, + "prerelease": false, + "created_at": "2021-11-13T10:56:59Z", + "published_at": "2021-11-13T14:18:47Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/icret/EasyImages2.0/tarball/2.4.1", + "zipball_url": "https://api.github.com/repos/icret/EasyImages2.0/zipball/2.4.1", + "body": "- 2021-11-12 v2.4.1\r\n- 增加缓存周期配置\r\n- 增加上传统计\r\n- 增加viewjs\r\n- 更新依赖件\r\n- 修复统计错误" +} diff --git a/application/chart.php b/application/chart.php index f750cae..fa5b152 100755 --- a/application/chart.php +++ b/application/chart.php @@ -31,7 +31,7 @@ function getLatelyTime($type = '') $total_contents = APP_ROOT . $config['path']; // 获取用户自定义的上传目录 $chart_total_file_md5 = strval(md5_file(APP_ROOT . '/config/config.php')); // 以config.php文件的md5命名 -$chart_total_file = $total_contents . "cache/chart-$chart_total_file_md5.php"; // 文件绝对目录 +$chart_total_file = APP_ROOT . "/admin/logs/counts/chart-$chart_total_file_md5.php"; // 文件绝对目录 function write_chart_total() { @@ -54,7 +54,7 @@ function write_chart_total() // 统计每日占用空间 $count_contents['chart_disk'][] = [$count_day[$i] => getDirectorySize($total_contents . $count_day[$i])]; } - + $count_contents = json_encode($count_contents, true); // serialize存储文件 file_put_contents($chart_total_file, $count_contents); // 存储文件 } diff --git a/application/class.version.php b/application/class.version.php index 3d8e696..3723285 100755 --- a/application/class.version.php +++ b/application/class.version.php @@ -16,9 +16,9 @@ class getVerson public function readJson() { - if (file_exists(__DIR__ . '/../i/cache/verson.json')) { - $file = fopen(__DIR__ . '/../i/cache/verson.json', 'r'); - $test = fread($file, filesize(__DIR__ . '/../i/cache/verson.json')); + if (file_exists(__DIR__ . '/../admin/logs/verson/verson.json')) { + $file = fopen(__DIR__ . '/../admin/logs/verson/verson.json', 'r'); + $test = fread($file, filesize(__DIR__ . '/../admin/logs/verson/verson.json')); $verson = json_decode($test, true); return $verson['tag_name']; fclose($file); @@ -32,7 +32,7 @@ class getVerson $verson = $this->geturl($this->url); $verson = json_decode($verson, true); - $file = fopen(__DIR__ . '/../i/cache/verson.json', 'w+'); + $file = fopen(__DIR__ . '/../admin/logs/verson/verson.json', 'w+'); fwrite($file, $verson); fclose($file); } diff --git a/application/total_files.php b/application/total_files.php index 2f1c59c..5e235bc 100755 --- a/application/total_files.php +++ b/application/total_files.php @@ -34,8 +34,7 @@ function total_files($file) $total_file_path = APP_ROOT . $config['path']; // 获取用户自定义的上传目录 $totalJsonMD5 = strval(md5_file(APP_ROOT . '/config/config.php')); // 以config.php文件的md5命名 -$totalJsonName = $total_file_path . "cache/total-files-$totalJsonMD5.php"; // 文件绝对目录 - +$totalJsonName = APP_ROOT . "/admin/logs/counts/total-files-$totalJsonMD5.php"; // 文件绝对目录 function creat_json() // 创建json文件 { diff --git a/application/write-log.php b/application/write-log.php new file mode 100755 index 0000000..8f638ac --- /dev/null +++ b/application/write-log.php @@ -0,0 +1,85 @@ +来源:ecshop + *
$_SERVER和getenv的区别,getenv不支持IIS的isapi方式运行的php + * @access public + * @return string + */ +function real_ip() +{ + static $realip = NULL; + if ($realip !== NULL) { + return $realip; + } + if (isset($_SERVER)) { + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */ + foreach ($arr as $ip) { + $ip = trim($ip); + + if ($ip != 'unknown') { + $realip = $ip; + + break; + } + } + } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { + $realip = $_SERVER['HTTP_CLIENT_IP']; + } else { + if (isset($_SERVER['REMOTE_ADDR'])) { + $realip = $_SERVER['REMOTE_ADDR']; + } else { + $realip = '0.0.0.0'; + } + } + } else { + if (getenv('HTTP_X_FORWARDED_FOR')) { + $realip = getenv('HTTP_X_FORWARDED_FOR'); + } elseif (getenv('HTTP_CLIENT_IP')) { + $realip = getenv('HTTP_CLIENT_IP'); + } else { + $realip = getenv('REMOTE_ADDR'); + } + } + // 使用正则验证IP地址的有效性,防止伪造IP地址进行SQL注入攻击 + preg_match("/[\d\.]{7,15}/", $realip, $onlineip); + $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0'; + return $realip; +} + +/** + * 写日志 + * 日志格式:图片名称->上传时间(北京时间)->IP地址->浏览器信息->文件相对路径->cache文件相对路径 + */ +function write_log($file, $cacheFile = null) +{ + global $config; + $name = trim(basename($file), " \t\n\r\0\x0B"); // 图片名称 + $log = array($name => array( + 'date' => date('Y-m-d H:i:s'), // 上传日期 + 'ip' => real_ip(), // 上传ip + 'user_agent' => $_SERVER['HTTP_USER_AGENT'], //浏览器信息 + 'path' => $file, // 文件相对路径 + 'cache' => $cacheFile, // 文件缓存相对位置 + )); + + $logFileName = APP_ROOT . '/admin/logs/upload/' . date('Y-m') . '.php'; + + // 写入禁止浏览器直接访问 + if (is_file($logFileName) == false) { + $php_code = ''; + file_put_contents($logFileName, $php_code); + } + + $log = json_encode($log, true); + file_put_contents($logFileName, PHP_EOL . $log, FILE_APPEND | LOCK_EX); +} +/* +for ($i = 0; $i < 100000; $i++) { + write_log('/i/2021/11/13/12der8s.jpg', '/i/cache/2021_11_13_12der8s.jpg'); +} +*/ \ No newline at end of file diff --git a/config/config.php b/config/config.php index db3e909..6c56fe2 100755 --- a/config/config.php +++ b/config/config.php @@ -45,7 +45,7 @@ $config=Array
', - 'showSwitch'=>0, + 'showSwitch'=>1, 'listNumber'=>20, 'customize'=>'