summaryrefslogtreecommitdiff
path: root/static/upload.php
AgeCommit message (Collapse)Author
2016-06-17Rename all functions to camelCase as set by psr2Eliot Whalan
2016-06-16Revert most ofddccf5f1c26517bf58cd45e3d92096fc760d9db6Eliot Whalan
2016-06-14Revert "upload.php: Deprecate all named functions"Eliot Whalan
This reverts commit cae3cb012812c2d7e1995301e85c8954567a499d.
2016-05-29upload.php: Deprecate all named functionsJuuso Lapinlampi
Deprecates diverse_array(), generate_name(), refiles() and upload_file(). These pollute the global namespace and do not follow the PSR-2 naming convention. The plan is to create a new file with a new class to share this common code, leaving upload.php only with the last lines of code that it really needs to do (calling other class functions). Acked-by: Eliot Whalan <ewhal@pantsu.cat>
2016-05-29upload.php: Don't unlink() tempfiles in upload_file()Juuso Lapinlampi
We don't need to care about garbage collection and explicitly unlinking temporary files: PHP will handle that for us automatically. In other words, this is "dead" code. Less code the better. Updates the comment before it to reflect this. Tested on PHP 5.6.22 and PHP 7.0.7 on Debian stretch/sid GNU/Linux. Tested-by: Juuso Lapinlampi <wub@partyvan.eu> See: https://secure.php.net/manual/en/function.tmpfile.php
2016-05-25upload.php: Deprecate ob_start (output buffering)Juuso Lapinlampi
None of us can find a reason why we would need to buffer our output in a PHP application. My best guess is this may be a relic from Pomf 1.0.0 or Moe panel. Unless someone finds a better reason to keep this, this feature is useless and has negligible benefit and will be removed. In respect for SemVer, deprecating this feature happens first in a minor version before removal in a next major version. Acked-by: Eliot Whalan <ewhal@pantsu.cat>
2016-05-25upload.php: Clarify what Exception $code 500 isJuuso Lapinlampi
Add comments explaining how the number 500 after Exception means HTTP status code "500 Internal Server Error". This may not be so obvious to the reader without consulting the PHP manual. Compliments commit 4606553f38909b483bc06674f9558ede1a9ff1f6. Reviewed-by: Eliot Whalan <ewhal@pantsu.cat>
2016-05-24Extend and improve PHP code comments (PHPDoc)Juuso Lapinlampi
Add file summaries, @copyright tags and other comments. Covers majority of the PHP code base now. I have avoided being too verbose and omitted some potential tags. Most visibly to the user, this comments every user configurable setting and clarifies what some of the options do. POMF_DB_USER and POMF_DB_PASS are not rendered perfectly in phpDocumentor version 2.8.5. This is a sacrifice I made in attempt for not being too verbose and obvious. Response class gets a @todo for being a god object.
2016-05-23Replace include_once statements with require_onceAustin Gillmann
Normally in include_once if a script does not load PHP will treat it as such as an E_WARNING, while require_once fail the script with a E_COMPILE_ERROR if the script does not load. Since we require all of these scripts to properly function it will be better to classify them as required in PHP. Reported-by: Juuso Lapinlampi <wub@partyvan.eu> Reviewed-by: Juuso Lapinlampi <wub@partyvan.eu>
2016-05-23upload.php: Add Pantsu.cat copyright year 2016Juuso Lapinlampi
Previous two commits in this topic branch introduced substantial changes.
2016-05-23upload.php: Apply DRY to POMF_FILES_ROOT.$newnameJuuso Lapinlampi
Don't repeat yourself with multiple POMF_FILES_ROOT.$newname for full file path. Use a variable pointer $uploadFile. Improves code readability and robustness.
2016-05-23upload.php: Unnest upload_file() if-else expressionsJuuso Lapinlampi
As phpmd (PHP Mess Detector) linter says: "An if expression with an else branch is never necessary." Well, at least almost never necessary. Improves readability and resolves phpmd cleancode lint errors.
2016-05-07Deprecate file expiration support in Pomf 2.1.0Juuso Lapinlampi
File expiration support has never been properly implemented in Pomf core or moe panel. It serves as legacy baggage before nekunekus got an idea to create nokonoko/Uguu for temporary uploads. In current plans, this non-feature will be removed in the 3.0.0 release which is the next SemVer major version that allows to remove this. Reviewed-by: Austin Gillmann <alucard@cuntflaps.me>
2015-11-16Fix generate_name() imaginary column "pomf" to "files"Juuso Lapinlampi
(Partially reverts commit e0bb4e0.) Actually fix generate_name() COUNT query this time. It still had an imaginary table "pomf" from e0bb4e0. Change it to "files" like in the schema. For code consistency, :filename is reverted back to :name as it was before commit e0bb4e0. That commit is bogus and doesn't fix the issue due to skipping the code review process. The problem with this COUNT query in first place was that it checked imaginary columns (name) from an imaginary table (pomf) in the database. This led to the "same filename" check not working at all, and the other code only relying on checking the same hash (currently SHA-1) for returning the filename before generate_name(). By luck, generated filenames could collide and another file of the same generated filename would be returned, discarding the new upload. I discovered this bug about a month ago myself, but back then there was no reliable way to reproduce it and no good description of the bug. This bug was introduced in commit 5b77a4e. Reported-by: Vhum Vhum <vhumvhum1@gmail.com> Suggested-by: Luminarys <luminarys@fuwa.se> OK ewhal@, luminarys@
2015-11-16Change SQL query from name to filename to resolve duplicate entries in the ↵Eliot Whalan
database
2015-09-27Merge branch 'remove-moe-code-in-core' of WubTheCaptain/pomfJuuso Lapinlampi
OK ewhal@
2015-09-27Remove session_start(); from upload.phpJuuso Lapinlampi
Moe panel uses PHP sessions to keep the user logged in. We don't need it anymore, it's not required for core functionality.
2015-09-27Merge branch 'php-strict-comparison'Juuso Lapinlampi
OK ewhal@
2015-09-24Remove code that requires moe panelEliot Whalan
2015-09-23static/upload.php: Use strict comparison for $triesJuuso Lapinlampi
2015-09-23Add Expat copyright headers to PHP filesJuuso Lapinlampi
Interestingly, static/classes/UploadedFile.class.php is not licensed under Expat license. Because it was posted in PHP.net comments, I believe it's under the PHP license.
2015-09-18Revert ShareX / URL change commitsWubTheCaptain
These commits are ShareX issues, not Pomf issues. Allowing these commits to be in the source reduces maintainability. This reverts commits bbcffe8d745937677352edf25e6a250ca8fd507b, 943e7e62a8ca814d47168bcebf2cc92dbce9a45a and partially 1411bce1dc13bf6fea66b5899ba29d50d5c53bb0.
2015-09-17Add html response classpantsucat
2015-09-17Fix to work with sharexpantsucat
2015-09-16Indent and format project to PSR-2 styleWubTheCaptain
PSR-2 [1] is a highly regarded style guide in the PHP community according to Stack Overflow [2]. The indentation was out of place in the source code. I've seen a combination of 1 space tabs, 3 space tabs, 4 space tabs and 5 space tabs. Some closing braces on the same line and a lot of the code (especially moe code) had reached the point of losing readability. Converted with php-cs-fixer and some hand adjustment. [1]: http://www.php-fig.org/psr/psr-2/ [2]: https://stackoverflow.com/questions/3638083/list-of-highly-regarded -php-style-guides
2015-09-15Rework generate_name() logicWubTheCaptain
Adds a new config option POMF_FILES_LENGTH. This will allow the user to adjust the length of filenames. Defaults to 6. The filename generator never used character z in new filenames. There are 27 characters in a-z, but the old code uses a magic number of 26 characters. This bug was introduced in commit 5b77a4eaab418836820b2a0bad7c88f0b88136a0. Instead of relying on magic numbers like with mt_rand(), conveniently use arrays with array_rand() instead. More characters can be added with array_merge() in future if desired.
2015-08-15Update upload.phpEric Johansson (neku)
2015-06-24pass full urlKieran Harkin
2015-06-24pass full url back to clientKieran Harkin
2015-02-03Minor code refactoring and updatescenci0
DATABASE UPDATE: `orginalname` renamed to `originalname` (run update.sql to update `files` table). Run `update.sql` to update your database, no data will be lost (if you don't update it, pomf won't work properly). `schema.sql` - `id`s are now unsigned to double the maximum number of supported indexes - `size` and `user` columns are unsigned too (we can't have a negative file size or a negative user id) `static/classes/Response.class.php` New class to manage responses and errors. Using a class for responses makes the code cleaner and easier to add new response type handlers in the future. - The response type is declared while a new variable is initialized and the `error` and `send` methods will print a proper output according to it - The header for the response is also set accordingly to the response type (`text/plain` for `csv`/`gyazo` output, `application/json` for `json` output) `static/classes/UploadException.class.php` `Exception` class extension to manage errors that may have occurred while uploading files to the server. This way every error is reported in detail. `static/includes/settings.inc.php` - `POMF_URL`: add an option to set the domain of the url to prepend to the newly generated filename (before it was hardcoded and it was `http://a.pomf.se/`) [this option is currently used only when the output is set to `gyazo`] `upload.php` - Add functions calls at the beginning to enable the output compression if possible (gzipped output) - Include new classes - `generate_name ()` --- The new name generation algorithm is basically the same of the old one, but it's easier to add/remove characters if needed (eg. lower-case letters isn't enough and you need to add capital-case letters or digits) --- Check directly the database instead of the filesystem to see if a generated filename is already in use - `upload_file ()` --- File errors generate a `UploadException` instead of a normal `Exception` --- Move common code outside the `if` to avoid useless code repetition (only the query is now inside the condition) --- Change file permissions of a file after moving it to the new directory (if the user didn't set a mask previouly these files wouldn't be world readable, we make sure they are) - `diverse_array ()` --- Function to reorder initial `$_FILES` array (easier to handle for `refiles`) - `refiles ()` --- Use a `foreach` cicle instead of a `for` one, easier to understand - Create a new response object and set its response type (`csv`, `gyazo` or default to `json`) - Edit response handling according to the new response class
2014-12-20removed disgusting "Eric Johansson (neku)
2014-12-20Update upload.phpEric Johansson (neku)
2014-12-20Update upload.phpEric Johansson (neku)
2014-12-20Update upload.phpEric Johansson (neku)
2014-12-20Update upload.phpEric Johansson (neku)
2014-12-20Update upload.phpMichael
2014-12-19Update upload.phpEric Johansson (neku)
2014-12-19Update upload.phpEric Johansson (neku)
2014-10-02not even used, shitty, removedNeku
2014-08-24fixed vuln + other ghetto updatesNeku
2014-02-22Update upload.phpNeku
2014-02-22Update upload.phpbenwaffle
database.inc.php already includes settings.inc.php
2014-01-18Add double-dot handling. Fixes #1Peter Lejeck
2014-01-18Fix indentation in upload.phpPeter Lejeck
Please, neku, learn to use tabs, okay?
2014-01-15or notneku nekus
2014-01-15accounts?neku nekus
2014-01-15accounts?neku nekus
2014-01-04fix?Neku
2014-01-04fixed some shitNeku
2013-12-16maybe one more, we need new algoNeku