/** * Test checking domains against a list of allowed domains. * * @param bool $expected Expected result * @param string $domain domain address * @dataProvider data_domain_addresses */ public function test_check_domain_against_allowed_domains($expected, $domain) { $alloweddomains = ['example.com', '*.moodle.com', '*.per.this.penny-arcade.com', 'bad.*.url.com', ' trouble.com.au']; $this->assertEquals($expected, \core\ip_utils::is_domain_in_allowed_list($domain, $alloweddomains)); }
/** * Check to see if a user's real email address should be used for the "From" field. * * @param object $from The user object for the user we are sending the email from. * @param object $user The user object that we are sending the email to. * @param array $alloweddomains An array of allowed domains that we can send email from. * @return bool Returns true if we can use the from user's email adress in the "From" field. */ function can_send_from_real_email_address($from, $user, $alloweddomains) { // Email is in the list of allowed domains for sending email, // and the senders email setting is either displayed to everyone, or display to only other users that are enrolled // in a course with the sender. if (\core\ip_utils::is_domain_in_allowed_list(substr($from->email, strpos($from->email, '@') + 1), $alloweddomains) && ($from->maildisplay == core_user::MAILDISPLAY_EVERYONE || $from->maildisplay == core_user::MAILDISPLAY_COURSE_MEMBERS_ONLY && enrol_get_shared_courses($user, $from, false, true))) { return true; } return false; }
/** * Checks whether the input hostname is blocked by any of the domain/wildcard rules. * * @param string $host the hostname to check * @return bool true if the host is covered by an entry in the blacklist, false otherwise. */ protected function host_explicitly_blocked($host) { $blockedhosts = $this->get_blacklisted_hosts_by_category(); $domainhostsblocked = array_merge($blockedhosts['domain'], $blockedhosts['domainwildcard']); return ip_utils::is_domain_in_allowed_list($host, $domainhostsblocked); }