mirror of
https://github.com/nokonoko/Uguu.git
synced 2024-01-06 13:35:15 +00:00
Anti-dupe and filter bugs fixed
This commit is contained in:
parent
45bc029d8e
commit
0a3934c24a
@ -327,7 +327,7 @@ namespace Core {
|
||||
$q->execute();
|
||||
$result = $q->fetch();
|
||||
if ($result['count'] > 0) {
|
||||
Upload::$NEW_NAME_FULL = $result['filename'];
|
||||
return $result['filename'];
|
||||
}
|
||||
} catch (Exception) {
|
||||
throw new Exception('Cant check for dupes in DB.', 500);
|
||||
@ -359,4 +359,3 @@ namespace Core {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -72,13 +72,29 @@ class Upload
|
||||
public function uploadFile(): array
|
||||
{
|
||||
(new Settings())->loadConfig();
|
||||
(new Upload())->fileInfo();
|
||||
|
||||
if (Settings::$ANTI_DUPE) {
|
||||
(new Database())->antiDupe();
|
||||
if (Settings::$BLACKLIST_DB) {
|
||||
(new Database())->checkFileBlacklist();
|
||||
}
|
||||
|
||||
(new Upload())->generateName();
|
||||
if (Settings::$FILTER_MODE) {
|
||||
self::checkMimeBlacklist();
|
||||
self::checkExtensionBlacklist();
|
||||
}
|
||||
|
||||
if (Settings::$ANTI_DUPE) {
|
||||
$result = (new Database())->antiDupe();
|
||||
if (isset($result)) {
|
||||
self::$NEW_NAME_FULL = $result;
|
||||
} else {
|
||||
(new Upload())->generateName();
|
||||
}
|
||||
}
|
||||
|
||||
if (!Settings::$ANTI_DUPE) {
|
||||
(new Upload())->generateName();
|
||||
}
|
||||
|
||||
if (!is_dir(Settings::$FILES_ROOT)) {
|
||||
throw new Exception('File storage path not accessible.', 500);
|
||||
@ -107,12 +123,13 @@ class Upload
|
||||
'size' => self::$FILE_SIZE
|
||||
];
|
||||
}
|
||||
|
||||
public function fileInfo()
|
||||
{
|
||||
if (isset($_FILES['files'])) {
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
self::$FILE_MIME = finfo_file($finfo, self::$TEMP_FILE);
|
||||
$extension = explode('.',self::$FILE_NAME,2);
|
||||
$extension = explode('.', self::$FILE_NAME, 2);
|
||||
self::$FILE_EXTENSION = $extension['1'];
|
||||
finfo_close($finfo);
|
||||
|
||||
@ -123,40 +140,6 @@ class Upload
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generateName(): string
|
||||
{
|
||||
(new Upload())->fileInfo();
|
||||
|
||||
do {
|
||||
if (Settings::$FILES_RETRIES === 0) {
|
||||
throw new Exception('Gave up trying to find an unused name!', 500);
|
||||
}
|
||||
|
||||
self::$NEW_NAME = '';
|
||||
for ($i = 0; $i < Settings::$NAME_LENGTH; ++$i) {
|
||||
self::$NEW_NAME .= Settings::$ID_CHARSET[mt_rand(0, strlen(Settings::$ID_CHARSET))];
|
||||
}
|
||||
|
||||
if(isset(self::$FILE_EXTENSION)){
|
||||
self::$NEW_NAME_FULL = self::$NEW_NAME;
|
||||
self::$NEW_NAME_FULL .= '.'.self::$FILE_EXTENSION;
|
||||
}
|
||||
|
||||
if (Settings::$BLACKLIST_DB) {
|
||||
(new Database())->checkFileBlacklist();
|
||||
}
|
||||
|
||||
if (Settings::$FILTER_MODE) {
|
||||
self::checkMimeBlacklist();
|
||||
self::checkExtensionBlacklist();
|
||||
}
|
||||
} while ((new Database())->dbCheckNameExists() > 0);
|
||||
|
||||
return self::$NEW_NAME_FULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
@ -177,4 +160,28 @@ class Upload
|
||||
throw new Exception('Filetype not allowed.', 415);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function generateName(): string
|
||||
{
|
||||
do {
|
||||
if (Settings::$FILES_RETRIES === 0) {
|
||||
throw new Exception('Gave up trying to find an unused name!', 500);
|
||||
}
|
||||
|
||||
self::$NEW_NAME = '';
|
||||
for ($i = 0; $i < Settings::$NAME_LENGTH; ++$i) {
|
||||
self::$NEW_NAME .= Settings::$ID_CHARSET[mt_rand(0, strlen(Settings::$ID_CHARSET))];
|
||||
}
|
||||
|
||||
if (isset(self::$FILE_EXTENSION)) {
|
||||
self::$NEW_NAME_FULL = self::$NEW_NAME;
|
||||
self::$NEW_NAME_FULL .= '.' . self::$FILE_EXTENSION;
|
||||
}
|
||||
} while ((new Database())->dbCheckNameExists() > 0);
|
||||
|
||||
return self::$NEW_NAME_FULL;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user