]> jfr.im git - uguu.git/commitdiff
Merge branch 'master' of https://github.com/nokonoko/Uguu v.1.8.4
authorGo Johansson (neku) <redacted>
Sun, 31 Dec 2023 15:11:33 +0000 (16:11 +0100)
committerGo Johansson (neku) <redacted>
Sun, 31 Dec 2023 15:11:33 +0000 (16:11 +0100)
13 files changed:
.gitignore
package.json
src/Classes/Connector.php
src/Classes/CuteGrills.php
src/Classes/Database.php
src/Classes/GrillLoader.php
src/Classes/Response.php
src/Classes/Upload.php
src/Classes/expireChecker.php
src/config.json
src/static/php/checkExpire.php
src/static/php/grill.php
src/static/php/upload.php

index c6438a2861c2acda048fb43df229f8276fcd0464..8b1543ca7ade529f7ceaaf43ec6ae09167756294 100644 (file)
@@ -12,3 +12,4 @@ composer.phar
 composer.lock
 docker/uguuForDocker.tar.gz
 !/.php-cs-fixer.cache
+test.php
index ead3ba4897b5b226cb931def88e53a03a7976e69..fb48f9bce8724060ab869b38c1dc0155f09f441c 100755 (executable)
@@ -1,6 +1,6 @@
 {
   "name": "uguu",
-  "version": "1.8.3",
+  "version": "1.8.4",
   "description": "Uguu is a simple lightweight temporary file host with support for drop, paste, click and API uploading.",
   "homepage": "https://uguu.se",
   "repository": {
index 71fe0cdc0d1981a795b07f3bdd273a661921a1ec..b22e9937bd8567b19253b119c1a3778601964ea7 100755 (executable)
@@ -1,8 +1,18 @@
 <?php
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
@@ -71,7 +81,7 @@
             $this->DB = new PDO(
                $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
                $this->CONFIG['DB_USER'],
-               $this->CONFIG['DB_PASS']
+               $this->CONFIG['DB_PASS'],
             );
         }
     }
\ No newline at end of file
index 75ec018449d078163cba4163d9088753c88a2382..42ec149b867f696e2344c117792adea77a0189c7 100755 (executable)
@@ -1,8 +1,18 @@
 <?php
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
index d174838c49eeae16a04968e6e900f59032c50206..482ab672092ae4fbefecee878bcfd014ba8040d2 100755 (executable)
@@ -1,8 +1,18 @@
 <?php
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
             }
             return false;
         }
-
     }
\ No newline at end of file
index 18d6f888e5ba4b1c430e36b1d5ee0d065de3af13..d5588b68c693ac98b2881f1f29302a783e7f60c4 100755 (executable)
@@ -1,8 +1,18 @@
 <?php
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
index 18c743d04a52d1009be3f62fe2ae359086337de2..c9e231bcbd39c231c2fd8086959d7ffde3c5d168 100755 (executable)
@@ -1,8 +1,18 @@
 <?php
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
index 2a3100ef964ddf4fbb40e8df34365c39406d2839..a01cef592a7b89ef70c24ffe365dc4ef180337eb 100755 (executable)
@@ -1,8 +1,19 @@
 <?php
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     * @links
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
         private mixed $Connector;
         
         /**
-         * Takes an array of files, and returns an array of arrays containing the file's temporary name,
-         * name, size, XXH3 hash, extension, and MIME type
+         * Resolves and processes an array of files, performing various checks and operations on each file.
+         *
+         * Check if the file is a dupe (if enabled).
+         * Generate a new name (if not a dupe).
+         * Generate hash of the file.
+         * Get the extension of the file.
+         * Get the MIME of the file.
+         * Get the size of the file.
          *
-         * @param $files array The files array from the $_FILES superglobal.
+         * @param array $files An array of file data. Each element should be an associative array
+         *                     *             with the following keys:
+         *                     *             - 'tmp_name' : The temporary name of the uploaded file.
+         *                     *             - 'name'     : The original name of the file.
+         *                     *             - 'size'     : The size of the file in bytes.
          *
-         * @return array An array of arrays.
+         * @return array An array containing information about each uploaded file. Each element of the array
+         * *             is an associative array with the following keys:
+         * *             - 'temp_name' : The temporary name of the uploaded file.
+         * *             - 'name'      : The processed name of the file after checking for length and removing tags.
+         * *             - 'size'      : The size of the uploaded file in bytes.
+         * *             - 'xxh'       : The xxhash of the uploaded file.
+         * *             - 'extension' : The file extension.
+         * *             - 'mime'      : The MIME type of the file.
+         * *             - 'dupe'      : Indicates if the uploaded file is a duplicate.
+         * *             - 'filename'  : The final filename of the uploaded file.
          */
         public function reFiles(array $files):array
         {
@@ -44,7 +74,7 @@
                    'TEMP_NAME' => $file['tmp_name'],
                    'NAME'      => strip_tags($this->checkNameLength($file['name'])),
                    'SIZE'      => $file['size'],
-                   'XXH'      => hash_file('xxh3', $file['tmp_name']),
+                   'XXH'       => hash_file('xxh3', $file['tmp_name']),
                    'EXTENSION' => $this->fileExtension($file),
                    'MIME'      => $this->fileMIME($file),
                    'DUPE'      => false,
         }
         
         /**
-         * Takes an array of arrays and returns an array of arrays with the keys and values swapped
-         *
-         * @param $files array an array of arrays
-         *
-         * @return array ```
-         * array:2 [▼
-         *   0 => array:2 [▼
-         *     'TEMP_NAME' => 'example'
-         *     'NAME' => 'example'
-         *     'SIZE' => 'example'
-         *     'XXH' => 'example'
-         *     'EXTENSION' => 'example'
-         *     'MIME' => 'example'
-         *
-         *   ]
-         *   1 => array:2 [▼
-         *     'TEMP_NAME' => 'example'
-         *     'NAME' => 'example'
-         *     'SIZE' => 'example'
-         *     'XXH' => 'example'
-         *     'EXTENSION' => 'example'
-         *     'MIME' => 'example'
-         *   ]
-         * ]
-         * ```
+         * Rearranges a multidimensional array by exchanging the keys of the first and second level.
+         *
+         * @param array $files The multidimensional array to be rearranged.
+         *
+         * @return array The rearranged array with exchanged keys of the first and second level.
          */
         public function diverseArray(array $files):array
         {
         }
         
         /**
-         * Takes a file, checks if it's blacklisted, moves it to the file storage, and then logs it to the database
+         * Performs various checks (if enabled), insert info into database, moves file to storage
+         * location, then returns an array of file information.
+         *
+         * If a check is triggered or another error occurs it will return an error stating why
+         * the file was unable to be uploaded.
          *
-         * @return array An array containing the hash, name, url, and size of the file.
+         * @return array An array containing the following information:
+         *               - hash     : The hash value of the uploaded file
+         *               - name     : The name of the uploaded file
+         *               - filename : The filename of the uploaded file
+         *               - url      : The URL of the uploaded file
+         *               - size     : The size of the uploaded file
+         *               - dupe     : Boolean indicating whether the file is a duplicate
          */
         public function uploadFile():array
         {
-            switch (true) {
-                case $this->Connector->CONFIG['RATE_LIMIT']:
-                    if (
-                       $this->Connector->checkRateLimit(
-                          $this->fingerPrintInfo,
-                          $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'],
-                          $this->Connector->CONFIG['RATE_LIMIT_FILES'],
-                       )
-                    ) {
-                        $this->Connector->response->error(
-                           500,
-                           'Rate limit, please wait ' . $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'] .
-                           ' seconds before uploading again.',
-                        );
-                    }
-                // Continue
-                case $this->Connector->CONFIG['BLACKLIST_DB']:
-                    $this->Connector->checkFileBlacklist($this->FILE_INFO['XXH']);
-                // Continue
-                case $this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION']):
-                    $this->checkMimeBlacklist();
-                // Continue
-                case $this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION']):
-                    $this->checkMimeBlacklist();
-                    $this->checkExtensionBlacklist();
-                // Continue
+            if ($this->Connector->CONFIG['RATE_LIMIT']) {
+                if (
+                   $this->Connector->checkRateLimit(
+                      $this->fingerPrintInfo,
+                      $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'],
+                      $this->Connector->CONFIG['RATE_LIMIT_FILES'],
+                   )
+                ) {
+                    $this->Connector->response->error(
+                       500,
+                       'Rate limit, please wait ' . $this->Connector->CONFIG['RATE_LIMIT_TIMEOUT'] .
+                       ' seconds before uploading again.',
+                    );
+                }
+            }
+            if ($this->Connector->CONFIG['BLACKLIST_DB']) {
+                $this->Connector->checkFileBlacklist($this->FILE_INFO['XXH']);
+            }
+            if ($this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION'])) {
+                $this->checkMimeBlacklist();
+            }
+            if ($this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION'])) {
+                $this->checkMimeBlacklist();
+                $this->checkExtensionBlacklist();
+            }
+            if (!$this->Connector->CONFIG['FILTER_MODE'] && empty($this->FILE_INFO['EXTENSION'])) {
+                $this->checkMimeWhitelist();
+            }
+            if (!$this->Connector->CONFIG['FILTER_MODE'] && !empty($this->FILE_INFO['EXTENSION'])) {
+                $this->checkMimeWhitelist();
+                $this->checkExtensionWhitelist();
             }
             // If its not a dupe then skip checking if file can be written and
             // skip inserting it into the DB.
         
         /**
          * Takes the amount of files that are being uploaded, and creates a fingerprint of the user's IP address,
-         * user agent, and the amount of files being
-         * uploaded
+         * user agent, and the amount of files being uploaded.
          *
          * @param $files_amount int The amount of files that are being uploaded.
          *
         }
         
         /**
-         * It takes an array of strings, and returns the last two strings joined by a dot,
-         * unless the last two strings are in the array of strings in the
-         * `DOUBLE_DOTS_EXTENSIONS` config variable, in which case it returns the last string
+         * Determines the double dot file extension from the given file.
          *
-         * @param $extension array The extension of the file.
+         * If the last two elements of the array contain double dots, those will be extracted and concatenated.
+         * If the resulting double-dot extension is present in the whitelist, it will be returned.
+         * Otherwise, the last element of the array will be returned.
          *
-         * @return string The last two elements of the array are joined together and returned.
+         * @param array $extension An array of strings representing file extensions.
+         *
+         * @return string The extracted extension.
          */
         public function doubleDotExtension(array $extension):string
         {
         }
         
         /**
-         * Takes a file and returns the file extension
+         * Determines the file extension from the given file.
+         *
+         * The method checks if the file name contains a dot (.). If it does, the file name is split
+         * using the dot as the delimiter to extract the extension. The number of dots in the file name
+         * is also counted to handle special cases.
+         *
+         * If the file name contains exactly two dots, the method calls the doubleDotExtension() function
+         * to handle the special case. Otherwise, the method returns the last element of the exploded
+         * file name array, which represents the extension.
          *
-         * @param $file array The file you want to get the extension from.
+         * @param array $file The file array containing the name of the file.
          *
-         * @return string | bool The file extension of the file.
+         * @return string|bool The file extension if it exists, or false if the file name does not contain a dot.
          */
-        public function fileExtension(array $file):string | bool
+        public function fileExtension(array $file):string|bool
         {
-            if(str_contains($file['name'], '.')){
-            $extension = explode('.', $file['name']);
-            $dotCount = substr_count($file['name'], '.');    
-            return match ($dotCount) {
-                2 => $this->doubleDotExtension($extension),
-                default => end($extension)
-            };
+            if (str_contains($file['name'], '.')) {
+                $extension = explode('.', $file['name']);
+                $dotCount = substr_count($file['name'], '.');
+                return match ($dotCount) {
+                    2 => $this->doubleDotExtension($extension),
+                    default => end($extension)
+                };
             }
             return false;
         }
         
         /**
-         * > Check if the file's MIME type is in the blacklist
+         * Checks if the MIME type of the uploaded file is in the blacklist.
+         *
+         * If the MIME is in the blacklist, an error is returned indicating that the filetype
+         * is not allowed.
          *
          */
         public function checkMimeBlacklist():void
         {
-            if (in_array($this->FILE_INFO['MIME'], $this->Connector->CONFIG['BLOCKED_MIME'])) {
+            if (in_array($this->FILE_INFO['MIME'], $this->Connector->CONFIG['FILTER_MIME'])) {
                 $this->Connector->response->error(415, 'Filetype not allowed');
             }
         }
         
         /**
-         * > Check if the file extension is in the blacklist
+         * Checks if the MIME type of the uploaded file is in the whitelist.
+         *
+         * If the MIME type is not in the whitelist, an error is returned indicating that the filetype
+         * is not allowed.
+         *
+         */
+        public function checkMimeWhitelist():void
+        {
+            if (!in_array($this->FILE_INFO['MIME'], $this->Connector->CONFIG['FILTER_MIME'])) {
+                $this->Connector->response->error(415, 'Filetype not allowed');
+            }
+        }
+        
+        /**
+         * Checks if the extension of the uploaded file is in the blacklist.
+         *
+         * If the extension is in the blacklist, an error is returned indicating that the filetype
+         * is not allowed.
          *
          */
         public function checkExtensionBlacklist():void
         {
-            if (in_array($this->FILE_INFO['EXTENSION'], $this->Connector->CONFIG['BLOCKED_EXTENSIONS'])) {
+            if (in_array($this->FILE_INFO['EXTENSION'], $this->Connector->CONFIG['FILTER_EXTENSIONS'])) {
                 $this->Connector->response->error(415, 'Filetype not allowed');
             }
         }
         
+        /**
+         * Checks if the extension of the uploaded file is in the whitelist.
+         *
+         * If the extension is not in the whitelist, an error is returned indicating that the filetype
+         * is not allowed.
+         *
+         */
+        public function checkExtensionWhitelist():void
+        {
+            if (!in_array($this->FILE_INFO['EXTENSION'], $this->Connector->CONFIG['FILTER_EXTENSIONS'])) {
+                $this->Connector->response->error(415, 'Filetype not allowed');
+            }
+        }
+        
+        /**
+         * Checks if the length of the given filename exceeds 250 characters.
+         *
+         * If the length of the filename exceeds 250 characters, it is truncated to a maximum of 250 characters.
+         * Otherwise, the filename remains unchanged.
+         *
+         * @param string $fileName The filename to check the length for.
+         *
+         * @return string The filename, either unchanged or truncated if its length exceeds 250 characters.
+         */
         public function checkNameLength(string $fileName):string
         {
             if (strlen($fileName) > 250) {
         }
         
         /**
-         * Generates a random string of characters, checks if it exists in the database,
-         * and if it does, it generates another one
+         * Generates a unique name for a file.
+         *
+         * This method generates a random name for a file by selecting characters from the ID_CHARSET
+         * defined in the Connector's CONFIG. If an extension is provided, it appends the extension
+         * to the generated name. The method then checks if the generated name already exists in the
+         * database using the dbCheckNameExists() function. If the generated name
+         * already exists, it generates a new name until a unique one is found. If the maximum number
+         * of retries is reached, an error is returned.
          *
-         * @param $extension string The file extension.
+         * @param string $extension The extension of the file.
          *
-         * @return string A string
+         * @return string The generated unique name for the file.
          */
         public function generateName(string $extension):string
         {
index a66e2fd1e5f09cb8f86a033c6e0df410e0384dce..635067887e7327e6459db7e2b0ecb8aa84a43136 100755 (executable)
 <?php
-
-namespace Pomf\Uguu\Classes;
-use PDO;
-class expireChecker
-{
-    public PDO $DB;
-    public string $dbType;
-    public array $CONFIG;
-    public string $timeUnit;
-
-    public function checkDB(): bool | array {
-        if(is_int($this->CONFIG['expireTime'])) {
-            $this->timeUnit = strtoupper($this->CONFIG['expireTimeUnit']);
-            if(!in_array($this->timeUnit, ['SECONDS', 'MINUTES', 'HOURS', 'DAYS', 'WEEKS', 'MONTHS', 'YEARS'])){
-                $this->timeUnit = "HOURS";
+    /*
+     * Uguu
+     *
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
+     *
+     * This program is free software: you can redistribute it and/or modify
+     * it under the terms of the GNU General Public License as published by
+     * the Free Software Foundation, either version 3 of the License, or
+     * (at your option) any later version.
+     *
+     * This program is distributed in the hope that it will be useful,
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     * GNU General Public License for more details.
+     *
+     * You should have received a copy of the GNU General Public License
+     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+     */
+    
+    namespace Pomf\Uguu\Classes;
+    
+    use PDO;
+    
+    class expireChecker
+    {
+        public PDO $DB;
+        public string $dbType;
+        public array $CONFIG;
+        public string $timeUnit;
+        
+        public function checkDB():bool|array
+        {
+            if (is_int($this->CONFIG['expireTime'])) {
+                $this->timeUnit = strtoupper($this->CONFIG['expireTimeUnit']);
+                if (!in_array($this->timeUnit, ['SECONDS', 'MINUTES', 'HOURS', 'DAYS', 'WEEKS', 'MONTHS', 'YEARS'])) {
+                    $this->timeUnit = "HOURS";
+                }
+                $query = match ($this->dbType) {
+                    'pgsql' => 'SELECT id, filename FROM files WHERE date < EXTRACT(epoch from NOW() - INTERVAL \'' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\')',
+                    default => 'SELECT id, filename FROM files WHERE date <= strftime(\'%s\', datetime(\'now\', \'-' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\'));'
+                };
+                $q = $this->DB->prepare($query);
+                $q->execute();
+                $result = $q->fetchAll(PDO::FETCH_ASSOC);
+                $q->closeCursor();
+                $returnArray = [
+                   'ids'       => [],
+                   'filenames' => [],
+                ];
+                foreach ($result as $array) {
+                    $returnArray['ids'][] = $array['id'];
+                    $returnArray['filenames'][] = $array['filename'];
+                }
+                return $returnArray;
+            } else {
+                return false;
             }
+        }
+        
+        public function cleanRateLimitDB():void
+        {
             $query = match ($this->dbType) {
-                'pgsql' => 'SELECT id, filename FROM files WHERE date < EXTRACT(epoch from NOW() - INTERVAL \'' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\')',
-                default => 'SELECT id, filename FROM files WHERE date <= strftime(\'%s\', datetime(\'now\', \'-' . $this->CONFIG['expireTime'] . ' ' . $this->timeUnit . '\'));'
+                'pgsql' => 'DELETE FROM ratelimit WHERE time < EXTRACT(epoch from NOW() - INTERVAL \'24 HOURS\')',
+                default => 'DELETE FROM ratelimit WHERE time <= strftime(\'%s\', datetime(\'now\', \'-24 HOURS\'));'
             };
             $q = $this->DB->prepare($query);
             $q->execute();
-            $result = $q->fetchAll(PDO::FETCH_ASSOC);
             $q->closeCursor();
-            $returnArray = [
-                'ids' => [],
-                'filenames' => []
-            ];
-            foreach ($result as $array){
-                $returnArray['ids'][] = $array['id'];
-                $returnArray['filenames'][] = $array['filename'];
-            }
-            return $returnArray;
-        } else {
-            return false;
         }
-    }
-
-    public function cleanRateLimitDB(): void {
-        $query = match ($this->dbType) {
-            'pgsql' => 'DELETE FROM ratelimit WHERE time < EXTRACT(epoch from NOW() - INTERVAL \'24 HOURS\')',
-            default => 'DELETE FROM ratelimit WHERE time <= strftime(\'%s\', datetime(\'now\', \'-24 HOURS\'));'
-        };
-        $q = $this->DB->prepare($query);
-        $q->execute();
-        $q->closeCursor();
-    }
-    public function deleteFiles(array $filenames): void {
-        foreach ($filenames as $filename) {
-            unlink($this->CONFIG['FILES_ROOT'] . $filename);
+        
+        public function deleteFiles(array $filenames):void
+        {
+            foreach ($filenames as $filename) {
+                unlink($this->CONFIG['FILES_ROOT'] . $filename);
+            }
         }
-    }
-
-    public function deleteFromDB(array $ids): void {
-        foreach ($ids as $id) {
-            $query = match ($this->dbType) {
-                'pgsql' => 'DELETE FROM files WHERE id = (:id)',
-                default => 'DELETE FROM files WHERE id = (:id)'
-            };
-            $q = $this->DB->prepare($query);
-            $q->bindValue(':id', $id);
-            $q->execute();
-            $q->closeCursor();
+        
+        public function deleteFromDB(array $ids):void
+        {
+            foreach ($ids as $id) {
+                $query = match ($this->dbType) {
+                    'pgsql' => 'DELETE FROM files WHERE id = (:id)',
+                    default => 'DELETE FROM files WHERE id = (:id)'
+                };
+                $q = $this->DB->prepare($query);
+                $q->bindValue(':id', $id);
+                $q->execute();
+                $q->closeCursor();
+            }
         }
-    }
-
-    /**
-     * Reads the config.json file and populates the CONFIG property with the settings
-     * Also assembles the PDO DB connection and registers error handlers.
-     *
-     */
-    public function __construct()
-    {
-        $this->response = new Response('json');
-        if (!file_exists(__DIR__ . '/../config.json')) {
-            $this->response->error(500, 'Cant read settings file.');
+        
+        /**
+         * Reads the config.json file and populates the CONFIG property with the settings
+         * Also assembles the PDO DB connection and registers error handlers.
+         *
+         */
+        public function __construct()
+        {
+            $this->response = new Response('json');
+            if (!file_exists(__DIR__ . '/../config.json')) {
+                $this->response->error(500, 'Cant read settings file.');
+            }
+            $this->CONFIG = json_decode(
+               file_get_contents(__DIR__ . '/../config.json'),
+               true,
+            );
+            ini_set('display_errors', 0);
+            $this->dbType = $this->CONFIG['DB_MODE'];
+            $this->DB = new PDO(
+               $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
+               $this->CONFIG['DB_USER'],
+               $this->CONFIG['DB_PASS'],
+            );
         }
-        $this->CONFIG = json_decode(
-            file_get_contents(__DIR__ . '/../config.json'),
-            true,
-        );
-        ini_set('display_errors', 0);
-        $this->dbType = $this->CONFIG['DB_MODE'];
-        $this->DB = new PDO(
-            $this->CONFIG['DB_MODE'] . ':' . $this->CONFIG['DB_PATH'],
-            $this->CONFIG['DB_USER'],
-            $this->CONFIG['DB_PASS']
-        );
     }
-}
 
 
 
index 18eec163a977a5a15ef70eb888cd742daf39f358..c744c279ad781b5f6a3748362a8490b039ee8aa0 100755 (executable)
@@ -1,6 +1,6 @@
 {
   "dest": "dist",
-  "pkgVersion": "1.8.3",
+  "pkgVersion": "1.8.4",
   "pages": [
     "index.ejs",
     "faq.ejs",
@@ -48,7 +48,7 @@
     "min.js",
     "conf.bak"
   ],
-  "BLOCKED_EXTENSIONS": [
+  "FILTER_EXTENSIONS": [
     "exe",
     "scr",
     "com",
@@ -63,7 +63,7 @@
     "phtml",
     "svg"
   ],
-  "BLOCKED_MIME": [
+  "FILTER_MIME": [
     "application/msword",
     "text/html",
     "application/x-dosexec",
index 819995787c24744630f0b557752e52a8fe345a21..eb8e4bcc6ec274a2f1c9497f0e68bbe3f4867ae9 100755 (executable)
@@ -1,33 +1,43 @@
 <?php
-
-/**
- * Uguu
- *
- * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-require_once __DIR__ . '/vendor/autoload.php';
-
-use Pomf\Uguu\Classes\expireChecker;
-
-$check = new expireChecker();
-$dbResult = $check->checkDB();
-$check->cleanRateLimitDB();
-if(empty($dbResult['ids'])){
-    echo "No file(s) expired, nothing to do.";
-} else {
-    $check->deleteFromDB($dbResult['ids']);
-    $check->deleteFiles($dbResult['filenames']);
-}
\ No newline at end of file
+    /*
+     * Uguu
+     *
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
+     *
+     * This program is free software: you can redistribute it and/or modify
+     * it under the terms of the GNU General Public License as published by
+     * the Free Software Foundation, either version 3 of the License, or
+     * (at your option) any later version.
+     *
+     * This program is distributed in the hope that it will be useful,
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     * GNU General Public License for more details.
+     *
+     * You should have received a copy of the GNU General Public License
+     * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+     */
+    
+    require_once __DIR__ . '/vendor/autoload.php';
+    
+    use Pomf\Uguu\Classes\expireChecker;
+    
+    $check = new expireChecker();
+    $dbResult = $check->checkDB();
+    $check->cleanRateLimitDB();
+    if (empty($dbResult['ids'])) {
+        echo "No file(s) expired, nothing to do.";
+    } else {
+        $check->deleteFromDB($dbResult['ids']);
+        $check->deleteFiles($dbResult['filenames']);
+    }
\ No newline at end of file
index eb6acd08115ef6af7897ac10f41fea44da1ceeb9..92eac59d05147678f7a4ad84c9b4be55f9853a4d 100755 (executable)
@@ -1,9 +1,18 @@
 <?php
-    
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
@@ -18,6 +27,7 @@
      * You should have received a copy of the GNU General Public License
      * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      */
+    
     require_once __DIR__ . '/../vendor/autoload.php';
     
     use Pomf\Uguu\Classes\GrillLoader;
index 550355f01909f23658272740110287a2b09c292d..ee4d5c3536f1f40becf6a0d5095ca1b88595d92f 100755 (executable)
@@ -1,9 +1,18 @@
 <?php
-    
-    /**
+    /*
      * Uguu
      *
-     * @copyright Copyright (c) 2022-2023 Go Johansson (nokonoko) <neku@pomf.se>
+     * @copyright Copyright (c) 2022-2024 Go Johansson (nokonoko) <neku@pomf.se>
+     *
+     * Note that this was previously distributed under the MIT license 2015-2022.
+     *
+     * If you are a company that wants to use Uguu I urge you to contact me to
+     * solve any potential license issues rather then using pre-2022 code.
+     *
+     * A special thanks goes out to the open source community around the world
+     * for supporting and being the backbone of projects like Uguu.
+     *
+     * This project can be found at <https://github.com/nokonoko/Uguu>.
      *
      * This program is free software: you can redistribute it and/or modify
      * it under the terms of the GNU General Public License as published by
@@ -18,6 +27,7 @@
      * You should have received a copy of the GNU General Public License
      * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      */
+    
     require_once __DIR__ . '/../vendor/autoload.php';
     
     use Pomf\Uguu\Classes\Upload;
@@ -39,6 +49,7 @@
             $upload->send($res);
         }
     }
+    
     $resType = (isset($_GET['output']) and !empty($_GET['output'])) ? strtolower(preg_replace('/[^a-zA-Z]/', '', $_GET['output'])) : 'json';
     $response = new Response($resType);
     if (!isset($_FILES['files']) or empty($_FILES['files'])) {