Skip to content

Commit

Permalink
Merge branch 'MDL-32985' of git://github.com/merrill-oakland/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 5, 2012
2 parents d291dfd + 192a8e1 commit 4baa746
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/cronlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ function cron_run() {

// Send login failures notification - brute force protection in moodle is weak,
// we should at least send notices early in each cron execution
if (!empty($CFG->notifyloginfailures)) {
notify_login_failures();
mtrace(' Notified login failured');
if (notify_login_failures()) {
mtrace(' Notified login failures');
}


Expand Down Expand Up @@ -603,12 +602,23 @@ function cron_bc_hack_plugin_functions($plugintype, $plugins) {
* Note that this function must be only executed from the cron script
* It uses the cache_flags system to store temporary records, deleting them
* by name before finishing
*
* @return bool True if executed, false if not
*/
function notify_login_failures() {
global $CFG, $DB, $OUTPUT;

if (empty($CFG->notifyloginfailures)) {
return false;
}

$recip = get_users_from_config($CFG->notifyloginfailures, 'moodle/site:config');

// If it has been less than an hour, or if there are no recipients, don't execute.
if (((time() - HOURSECS) < $CFG->lastnotifyfailure) || !is_array($recip) || count($recip) <= 0) {
return false;
}

if (empty($CFG->lastnotifyfailure)) {
$CFG->lastnotifyfailure=0;
}
Expand Down Expand Up @@ -685,10 +695,8 @@ function notify_login_failures() {
}
$rs->close();

// If we haven't run in the last hour and
// we have something useful to report and we
// are actually supposed to be reporting to somebody
if ((time() - HOURSECS) > $CFG->lastnotifyfailure && $count > 0 && is_array($recip) && count($recip) > 0) {
// If we have something useful to report.
if ($count > 0) {
$site = get_site();
$subject = get_string('notifyloginfailuressubject', '', format_string($site->fullname));
// Calculate the complete body of notification (start + messages + end)
Expand All @@ -710,4 +718,6 @@ function notify_login_failures() {

// Finally, delete all the temp records we have created in cache_flags
$DB->delete_records_select('cache_flags', "flagtype IN ('login_failure_by_ip', 'login_failure_by_info')");

return true;
}

0 comments on commit 4baa746

Please sign in to comment.