|
| 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 | + * DNS Email Noreply check. |
| 18 | + * |
| 19 | + * @package tool_emailutils |
| 20 | + * @author Benjamin Walker <[email protected]> |
| 21 | + * @copyright Catalyst IT 2024 |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +namespace tool_emailutils\check; |
| 27 | +use core\check\check; |
| 28 | +use core\check\result; |
| 29 | +use tool_emailutils\dns_util; |
| 30 | + |
| 31 | +/** |
| 32 | + * DNS Email Noreply check. |
| 33 | + * |
| 34 | + * @package tool_emailutils |
| 35 | + * @author Benjamin Walker <[email protected]> |
| 36 | + * @copyright Catalyst IT 2024 |
| 37 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 38 | + */ |
| 39 | +class dnsnoreply extends check { |
| 40 | + |
| 41 | + /** |
| 42 | + * A link to a place to action this |
| 43 | + * |
| 44 | + * @return \action_link|null |
| 45 | + */ |
| 46 | + public function get_action_link(): ?\action_link { |
| 47 | + return new \action_link( |
| 48 | + new \moodle_url('/admin/settings.php?section=outgoingmailconfig'), |
| 49 | + get_string('outgoingmailconfig', 'core_admin')); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Get Result. |
| 54 | + * |
| 55 | + * @return result |
| 56 | + */ |
| 57 | + public function get_result() : result { |
| 58 | + global $DB, $CFG; |
| 59 | + |
| 60 | + $url = new \moodle_url($CFG->wwwroot); |
| 61 | + $domain = $url->get_host(); |
| 62 | + |
| 63 | + $details = ''; |
| 64 | + $status = result::INFO; |
| 65 | + $summary = ''; |
| 66 | + |
| 67 | + $dns = new dns_util(); |
| 68 | + |
| 69 | + $noreply = $dns->get_noreply(); |
| 70 | + $details .= "<p>No reply email: <code>$noreply</code></p>"; |
| 71 | + |
| 72 | + $noreplydomain = $dns->get_noreply_domain(); |
| 73 | + $details .= "<p>No reply domain: <code>$noreplydomain</code></p>"; |
| 74 | + |
| 75 | + $details .= "<p>LMS domain: <code>$domain</code></p>"; |
| 76 | + |
| 77 | + $primarydomain = $dns->get_primary_domain($domain); |
| 78 | + |
| 79 | + if ($noreplydomain == $domain) { |
| 80 | + $status = result::OK; |
| 81 | + $summary = "LMS is same as noreply domain"; |
| 82 | + } else if (str_contains($domain, '.' . $noreplydomain)) { |
| 83 | + $status = result::OK; |
| 84 | + $summary = "LMS is a subdomain of noreply domain"; |
| 85 | + } else if (str_contains($noreplydomain, '.' . $primarydomain)) { |
| 86 | + $summary = "LMS and noreply domain have a shared domain"; |
| 87 | + } else { |
| 88 | + $summary = "LMS and noreply domain have nothing in common"; |
| 89 | + } |
| 90 | + |
| 91 | + return new result($status, $summary, $details); |
| 92 | + } |
| 93 | +} |
0 commit comments