|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - http://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +namespace tool_objectfs\check; |
| 18 | +use core\check\check; |
| 19 | +use core\check\result; |
| 20 | + |
| 21 | +/** |
| 22 | + * Status check for objectFS proxied range requests. |
| 23 | + * |
| 24 | + * @package tool_objectfs |
| 25 | + * @author Peter Burnett <peterburnett@catalyst-au.net> |
| 26 | + * @copyright Catalyst IT |
| 27 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 28 | + */ |
| 29 | +class proxy_range_request extends check { |
| 30 | + /** |
| 31 | + * Link to ObjectFS settings page. |
| 32 | + * |
| 33 | + * @return \action_link|null |
| 34 | + */ |
| 35 | + public function get_action_link(): ?\action_link { |
| 36 | + $url = new \moodle_url('/admin/category.php', ['category' => 'tool_objectfs']); |
| 37 | + return new \action_link($url, get_string('pluginname', 'tool_objectfs')); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Check for the success of a proxied range request, if the setting is enabled. |
| 42 | + * |
| 43 | + * @return result |
| 44 | + */ |
| 45 | + public function get_result(): result { |
| 46 | + $config = \tool_objectfs\local\manager::get_objectfs_config(); |
| 47 | + $client = \tool_objectfs\local\manager::get_client($config); |
| 48 | + |
| 49 | + $signingsupport = false; |
| 50 | + if (!empty($config->filesystem)) { |
| 51 | + $signingsupport = (new $config->filesystem())->supports_presigned_urls(); |
| 52 | + } |
| 53 | + |
| 54 | + $testconn = $client->test_connection(); |
| 55 | + $connstatus = $testconn->success; |
| 56 | + |
| 57 | + if ($connstatus && $signingsupport) { |
| 58 | + $range = $client->test_range_request(new $config->filesystem()); |
| 59 | + |
| 60 | + if ($range->result) { |
| 61 | + return new result(result::OK, get_string('settings:presignedurl:testrangeok', 'tool_objectfs')); |
| 62 | + } else { |
| 63 | + return new result(result::WARNING, get_string('settings:presignedurl:testrangeerror', 'tool_objectfs')); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + return new result(result::UNKNOWN, get_string('check:proxyrangerequestsdisabled', 'tool_objectfs')); |
| 68 | + } |
| 69 | +} |
0 commit comments