From 9a00e39e42faa4440257896e4257d7a642f98fa5 Mon Sep 17 00:00:00 2001 From: printempw Date: Sun, 14 Feb 2016 16:23:19 +0800 Subject: [PATCH] return 404 if no texture is uploaded or user is not registered --- get.php | 7 +++++-- includes/User.class.php | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/get.php b/get.php index 1b18d6a8..5a26adf7 100644 --- a/get.php +++ b/get.php @@ -3,7 +3,7 @@ * @Author: prpr * @Date: 2016-02-02 20:56:42 * @Last Modified by: prpr - * @Last Modified time: 2016-02-10 14:06:10 + * @Last Modified time: 2016-02-14 16:18:03 * * All textures requests of legacy link will be handle here. */ @@ -13,7 +13,10 @@ require "$dir/includes/autoload.inc.php"; if (isset($_GET['type']) && isset($_GET['uname'])) { $user = new User($_GET['uname']); - if (!$user->is_registered) Utils::raise(1, 'Non-existent user.'); + if (!$user->is_registered) { + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); + Utils::raise(1, 'Non-existent user.'); + } // Cache friendly $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : null; diff --git a/includes/User.class.php b/includes/User.class.php index 25ba8812..4cf2e9e8 100644 --- a/includes/User.class.php +++ b/includes/User.class.php @@ -3,7 +3,7 @@ * @Author: printempw * @Date: 2016-01-16 23:01:33 * @Last Modified by: prpr - * @Last Modified time: 2016-02-10 21:04:32 + * @Last Modified time: 2016-02-14 16:21:53 */ class User @@ -104,16 +104,21 @@ class User } public function getBinaryTexture($type) { - $filename = "./textures/".$this->getTexture($type); - if (file_exists($filename)) { - header('Content-Type: image/png'); - // Cache friendly - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->getLastModified()).' GMT'); - header('Content-Length: '.filesize($filename)); - return Utils::fread($filename); + if ($this->getTexture($type) != "") { + $filename = "./textures/".$this->getTexture($type); + if (file_exists($filename)) { + header('Content-Type: image/png'); + // Cache friendly + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->getLastModified()).' GMT'); + header('Content-Length: '.filesize($filename)); + return Utils::fread($filename); + } else { + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); + Utils::raise(-1, 'Texture no longer exists.'); + } } else { header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); - Utils::raise(-1, 'Texture no longer exists.'); + Utils::raise(-1, 'No available textures.'); } } @@ -165,6 +170,7 @@ class User Utils::raise(-1, '配置文件错误:不支持的 API_TYPE。'); } } else { + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); $json['errno'] = 1; $json['msg'] = "Non-existent user."; }