|
84 | 84 | // set this to false to embed logged image links
|
85 | 85 | define('DISCORD_PREVENT_EMBED', true);
|
86 | 86 |
|
| 87 | +// Default protocol to use in URLs |
| 88 | +// Accepted values: auto, http, https |
| 89 | +define('DEFAULT_PROTOCOL', 'auto'); |
| 90 | + |
87 | 91 |
|
88 | 92 | /* DANGEROUS CONSTANTS BELOW THIS LINE */
|
89 | 93 |
|
@@ -224,6 +228,16 @@ function check_constants()
|
224 | 228 | 'Invalid DISCORD_PREVENT_EMBED constant, must be a boolean.');
|
225 | 229 | }
|
226 | 230 |
|
| 231 | + if (!defined('DEFAULT_PROTOCOL')) |
| 232 | + { |
| 233 | + define('DEFAULT_PROTOCOL', 'auto'); |
| 234 | + } |
| 235 | + if (!in_array(DEFAULT_PROTOCOL, ['auto', 'http', 'https'])) |
| 236 | + { |
| 237 | + error_die($data, 500, 'invalid_server_configuration', |
| 238 | + 'Invalid DEFAULT_PROTOCOL constant, must be one of: auto, http, https.'); |
| 239 | + } |
| 240 | + |
227 | 241 | if (!defined('KEYSPACE'))
|
228 | 242 | {
|
229 | 243 | define('KEYSPACE', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
|
@@ -384,6 +398,7 @@ function end_request(&$data, $code = 200, $status = 'success')
|
384 | 398 | function error_die(&$data, $code, $reason = 'unknown_error', $debug = '')
|
385 | 399 | {
|
386 | 400 | $data['error'] = $reason;
|
| 401 | + $data['error_msg'] = ERRORS[$reason]; |
387 | 402 |
|
388 | 403 | if ($debug)
|
389 | 404 | {
|
@@ -462,10 +477,17 @@ function generate_all_urls(&$data, $deletion = true)
|
462 | 477 | {
|
463 | 478 | $protocol = get_parameter('protocol');
|
464 | 479 |
|
465 |
| - if (!$protocol) |
| 480 | + if (!in_array($protocol, ['http', 'https'])) |
466 | 481 | {
|
467 |
| - $https = $_SERVER['HTTPS']; |
468 |
| - $protocol = 'http'.($https?'s':''); |
| 482 | + if (DEFAULT_PROTOCOL === 'auto') |
| 483 | + { |
| 484 | + $https = $_SERVER['HTTPS']; |
| 485 | + $protocol = 'http'.($https?'s':''); |
| 486 | + } |
| 487 | + else |
| 488 | + { |
| 489 | + $protocol = DEFAULT_PROTOCOL; |
| 490 | + } |
469 | 491 | }
|
470 | 492 |
|
471 | 493 | $protocol = $protocol.'://';
|
@@ -761,9 +783,31 @@ function info_endpoint(&$data)
|
761 | 783 | }
|
762 | 784 | }
|
763 | 785 |
|
764 |
| -define('VERSION', '2.3.1'); |
| 786 | +define('VERSION', '2.4.0'); |
765 | 787 | define('SOURCE', 'https://github.com/Xenthys/ShareXen');
|
766 | 788 |
|
| 789 | +define('ERRORS', [ |
| 790 | + 'unknown_error' => 'An unknown error happened, you shouldn\'t ever see this error message.', |
| 791 | + 'invalid_server_configuration' => 'Server configuration is invalid, please tell an administrator.', |
| 792 | + 'invalid_credentials' => 'Your token is invalid, please check it out or ask an administrator.', |
| 793 | + 'unauthenticated_request' => 'You must be authentified in order to use this API endpoint.', |
| 794 | + 'file_already_exists' => 'The specified file name already exists on the server.', |
| 795 | + 'forbidden_filename' => 'The specified file name is forbidden: invalid characters or extension.', |
| 796 | + 'missing_filename' => 'A file name must be specified in order to use this API endpoint.', |
| 797 | + 'file_not_found' => 'The given file name was not found on the server.', |
| 798 | + 'invalid_key' => 'The given file deletion key is invalid.', |
| 799 | + 'missing_permissions' => 'You do not have the permission to perform this operation.', |
| 800 | + 'missing_file' => 'You must send a file in order to use the upload API endpoint.', |
| 801 | + 'invalid_file_extension' => 'The specified file extension is invalid.', |
| 802 | + 'invalid_file_mime_type' => 'The specified file MIME type is invalid.', |
| 803 | + 'cannot_generate_unique_filename' => 'The API was unable to generate a unique file name.', |
| 804 | + 'upload_failed' => 'The API was unable to save your file, please tell and administrator.', |
| 805 | + 'delete_failed' => 'The API was unable to delete your file, please tell and administrator.', |
| 806 | + 'missing_new_name' => 'You must specify the new file name (new_name) to rename a file.', |
| 807 | + 'rename_failed' => 'The API was unable to rename your file, please tell and administrator.', |
| 808 | + 'unknown_endpoint' => 'Unknown API endpoint, must be one of: upload, delete, rename, info.' |
| 809 | +]); |
| 810 | + |
767 | 811 | $data = [
|
768 | 812 | 'api_version' => VERSION,
|
769 | 813 | 'api_source' => SOURCE
|
|
0 commit comments