function _errorlog_sendEmailAlert()
{
    if (!$GLOBALS['SETTINGS']['advanced']['phpEmailErrors']) {
        return;
    }
    // once run function once per page-view
    static $alreadySent = false;
    if ($alreadySent) {
        return;
    }
    $alreadySent = true;
    // check if email sent in last hour
    $sentInLastHour = mysql_count('_error_log', " `dateLogged` > (NOW() - INTERVAL 1 HOUR) AND email_sent = 1");
    // send hourly alert
    if (!$sentInLastHour) {
        // send email
        $secondsAgo = time() - $GLOBALS['SETTINGS']['bgtasks_lastEmail'];
        if ($secondsAgo >= 60 * 60) {
            // don't email more than once an hour
            // get date format
            if ($GLOBALS['SETTINGS']['dateFormat'] == 'dmy') {
                $dateFormat = "jS M, Y - h:i:s A";
            } elseif ($GLOBALS['SETTINGS']['dateFormat'] == 'mdy') {
                $dateFormat = "M jS, Y - h:i:s A";
            } else {
                $dateFormat = "M jS, Y - h:i:s A";
            }
            // load latest error list
            $latestErrors = mysql_select('_error_log', "`dateLogged` > (NOW() - INTERVAL 1 HOUR) ORDER BY `dateLogged` DESC LIMIT 25");
            $latestErrorsList = '';
            foreach ($latestErrors as $thisError) {
                $latestErrorsList .= date($dateFormat, strtotime($thisError['dateLogged'])) . "\n";
                $latestErrorsList .= $thisError['error'] . "\n";
                $latestErrorsList .= $thisError['filepath'] . " (line " . $thisError['line_num'] . ")\n";
                $latestErrorsList .= $thisError['url'] . "\n\n";
            }
            // set email_sent flag for ALL records
            mysql_update('_error_log', null, 'TRUE', array('email_sent' => 1));
            // send email message
            $placeholders = array('error.hostname' => parse_url($GLOBALS['SETTINGS']['adminUrl'], PHP_URL_HOST), 'error.latestErrorsList' => nl2br(htmlencode($latestErrorsList)), 'error.errorLogUrl' => realUrl("?menu=_error_log", $GLOBALS['SETTINGS']['adminUrl']));
            $errors = sendMessage(emailTemplate_loadFromDB(array('template_id' => 'CMS-ERRORLOG-ALERT', 'placeholders' => $placeholders)));
            // log/display email sending errors
            if ($errors) {
                trigger_error("Unable to send error notification email from " . __FUNCTION__ . ": {$errors}", E_USER_NOTICE);
                die(__FUNCTION__ . ": {$errors}");
            }
        }
    }
}
function forgotPassword()
{
    global $SETTINGS, $TABLE_PREFIX, $PROGRAM_DIR;
    $GLOBALS['sentEmail'] = false;
    // Lookup username or email
    if (@$_REQUEST['usernameOrEmail']) {
        security_dieUnlessPostForm();
        security_dieUnlessInternalReferer();
        security_dieOnInvalidCsrfToken();
        disableInDemoMode('', 'forgotPassword.php', false);
        // send emails
        $escapedNameOrEmail = mysql_escape($_REQUEST['usernameOrEmail']);
        $matchingUsers = mysql_select('accounts', "'{$escapedNameOrEmail}' IN(`username`,`email`)");
        foreach ($matchingUsers as $user) {
            // get reset url
            $resetBaseUrl = array_value(explode('?', thisPageUrl()), 0);
            $resetCode = _generatePasswordResetCode($user['num']);
            $resetUrl = "{$resetBaseUrl}?menu=resetPassword&userNum=" . $user['num'] . "&resetCode={$resetCode}";
            // send message - v2.50 switched to emailTemplate_loadFromDB()
            $emailHeaders = emailTemplate_loadFromDB(array('template_id' => 'CMS-PASSWORD-RESET', 'placeholders' => array('user.num' => $user['num'], 'user.email' => $user['email'], 'resetUrl' => $resetUrl)));
            $errors = sendMessage($emailHeaders);
            if ($errors) {
                alert("Mail Error: " . nl2br($errors));
            }
            //
            $GLOBALS['sentEmail'] = true;
        }
    }
    // display errors
    if (array_key_exists('usernameOrEmail', $_REQUEST) && @$_REQUEST['usernameOrEmail'] == '') {
        alert(t("No username or email specified!"));
    }
    if (@$_REQUEST['usernameOrEmail'] && !$GLOBALS['sentEmail']) {
        alert(t("No matching username or email was found!"));
    }
    //
    showInterface('forgotPassword.php', false);
    exit;
}
Example #3
0
function cron_logErrorsOnDieOrExit()
{
    if (!@$GLOBALS['CRON_JOB_LOG_NUM']) {
        return;
    }
    $summary = t("Returned errors");
    $output = ob_get_clean();
    $runtime = sprintf("%0.2f", microtime(true) - $GLOBALS['CRON_JOB_START']);
    // update job log entry
    mysql_update('_cron_log', $GLOBALS['CRON_JOB_LOG_NUM'], null, array('summary' => $summary, 'output' => $output, 'runtime' => $runtime));
    // send email
    $secondsAgo = time() - $GLOBALS['SETTINGS']['bgtasks_lastEmail'];
    if ($secondsAgo >= 60 * 60) {
        // don't email more than once an hour
        // get email placeholders
        $cronLog = mysql_get('_cron_log', $GLOBALS['CRON_JOB_LOG_NUM']);
        $placeholders = array('bgtask.date' => $cronLog['createdDate'], 'bgtask.activity' => $cronLog['activity'], 'bgtask.summary' => nl2br(htmlencode($cronLog['summary'])), 'bgtask.completed' => $cronLog['completed'], 'bgtask.function' => $cronLog['function'], 'bgtask.output' => nl2br(htmlencode($cronLog['output'])), 'bgtask.runtime' => $cronLog['runtime'], 'bgtask.function' => $cronLog['function'], 'bgtasks.logsUrl' => realUrl("?menu=_cron_log", $GLOBALS['SETTINGS']['adminUrl']), 'bgtasks.settingsUrl' => realUrl("?menu=admin&action=general#background-tasks", $GLOBALS['SETTINGS']['adminUrl']));
        // send message
        $errors = sendMessage(emailTemplate_loadFromDB(array('template_id' => 'CMS-BGTASK-ERROR', 'placeholders' => $placeholders)));
        if ($errors) {
            die("Mail Error: {$errors}");
        }
        // update last emailed time
        $GLOBALS['SETTINGS']['bgtasks_lastEmail'] = time();
        saveSettings();
    }
}