/**
 * Sends notification e-mails to users in two situations:
 *
 *  - Their account is about to expire. This is controlled by the 'expiry'
 *    field of the usr table. Once that time has passed, the user may not
 *    log in.
 *  - They have not logged in for close to a certain amount of time. If that
 *    amount of time has passed, the user may not log in.
 *
 * The actual prevention of users logging in is handled by the authentication
 * code. This cron job sends e-mails to notify users that these events will
 * happen soon.
 */
function auth_handle_account_expiries()
{
    // The 'expiry' flag on the usr table
    $sitename = get_config('sitename');
    $wwwroot = get_config('wwwroot');
    $expire = get_config('defaultaccountinactiveexpire');
    $warn = get_config('defaultaccountinactivewarn');
    $daystoexpire = ceil($warn / 86400) . ' ';
    $daystoexpire .= $daystoexpire == 1 ? get_string('day') : get_string('days');
    // Expiry warning messages
    if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff
        FROM {usr} u
        WHERE ' . db_format_tsfield('u.expiry', false) . ' < ?
        AND expirymailsent = 0 AND deleted = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            _email_or_notify($user, get_string('accountexpirywarning'), get_string('accountexpirywarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('accountexpirywarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr', 'expirymailsent', 1, 'id', $user->id);
        }
    }
    // Actual expired users
    if ($users = get_records_sql_array('SELECT id
        FROM {usr}
        WHERE ' . db_format_tsfield('expiry', false) . ' < ?', array(time()))) {
        // Users have expired!
        foreach ($users as $user) {
            expire_user($user->id);
        }
    }
    if ($expire) {
        // Inactivity (lastlogin is too old)
        // MySQL doesn't want to compare intervals, so when editing the where clauses below, make sure
        // the intervals are always added to datetimes first.
        $dbexpire = db_interval($expire);
        $dbwarn = db_interval($warn);
        $installationtime = get_config('installation_time');
        $lastactive = "COALESCE(u.lastaccess, u.lastlogin, u.ctime, ?)";
        // Actual inactive users
        if ($users = get_records_sql_array("\n            SELECT u.id\n            FROM {usr} u\n            WHERE {$lastactive} + {$dbexpire} < current_timestamp\n                AND (u.expiry IS NULL OR u.expiry > current_timestamp) AND id > 0", array($installationtime))) {
            // Users have become inactive!
            foreach ($users as $user) {
                deactivate_user($user->id);
            }
        }
        // Inactivity warning emails
        if ($users = get_records_sql_array("\n            SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff\n            FROM {usr} u\n            WHERE {$lastactive} + {$dbexpire} < current_timestamp + {$dbwarn}\n                AND (u.expiry IS NULL OR u.expiry > current_timestamp)\n                AND inactivemailsent = 0 AND deleted = 0 AND id > 0", array($installationtime))) {
            foreach ($users as $user) {
                $displayname = display_name($user);
                _email_or_notify($user, get_string('accountinactivewarning'), get_string('accountinactivewarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $sitename), get_string('accountinactivewarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $sitename));
                set_field('usr', 'inactivemailsent', 1, 'id', $user->id);
            }
        }
    }
    // Institution membership expiry
    delete_records_sql('DELETE FROM {usr_institution}
        WHERE ' . db_format_tsfield('expiry', false) . ' < ? AND expirymailsent = 1', array(time()));
    // Institution membership expiry warnings
    if ($users = get_records_sql_array('
        SELECT
            u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff,
            ui.institution, ui.expiry, i.displayname as institutionname
        FROM {usr} u
        INNER JOIN {usr_institution} ui ON u.id = ui.usr
        INNER JOIN {institution} i ON ui.institution = i.name
        WHERE ' . db_format_tsfield('ui.expiry', false) . ' < ?
        AND ui.expirymailsent = 0 AND u.deleted = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            _email_or_notify($user, get_string('institutionmembershipexpirywarning'), get_string('institutionmembershipexpirywarningtext', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('institutionmembershipexpirywarninghtml', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr_institution', 'expirymailsent', 1, 'usr', $user->id, 'institution', $user->institution);
        }
    }
}
Beispiel #2
0
function handle_user_deactivate($user_id, $HTTP_VARS, &$errors)
{
    if ($user_id == get_opendb_session_var('user_id')) {
        $errors[] = array('error' => get_opendb_lang_var('cannot_deactivate_yourself'), 'detail' => '');
        return FALSE;
    } else {
        if (fetch_my_borrowed_item_cnt($user_id) > 0) {
            $errors[] = array('error' => get_opendb_lang_var('user_with_borrows_not_deactivated'), 'detail' => '');
            return FALSE;
        } else {
            if (fetch_owner_borrowed_item_cnt($user_id) > 0) {
                $errors[] = array('error' => get_opendb_lang_var('user_with_owner_borrows_not_deactivated'), 'detail' => '');
                return FALSE;
            } else {
                if ($HTTP_VARS['confirmed'] == 'true') {
                    // Cancel all reservations.
                    $results = fetch_owner_reserved_item_rs($user_id);
                    if ($results) {
                        while ($borrowed_item_r = db_fetch_assoc($results)) {
                            cancel_reserve_item($borrowed_item_r['sequence_number']);
                        }
                        db_free_result($results);
                    }
                    $results = fetch_my_reserved_item_rs($user_id);
                    if ($results) {
                        while ($borrowed_item_r = db_fetch_assoc($results)) {
                            cancel_reserve_item($borrowed_item_r['sequence_number']);
                        }
                        db_free_result($results);
                    }
                    // deactivate user.
                    if (deactivate_user($user_id)) {
                        return TRUE;
                    } else {
                        return FALSE;
                    }
                } else {
                    if ($HTTP_VARS['confirmed'] != 'false') {
                        // confirmation required.
                        return "__CONFIRM__";
                    } else {
                        return "__ABORTED__";
                    }
                }
            }
        }
    }
}
Beispiel #3
0
<?php

//Activate or deactivate user
require_once '../includes/functions.inc.php';
require_once '../includes/admin.inc.php';
if (isset($_POST['uid'])) {
    $uid = $_POST['uid'];
    $user = user_load($uid);
    if ($user['User_Status'] == 0) {
        activate_user($uid);
    } elseif ($user['User_Status'] == 1) {
        deactivate_user($uid);
    }
    header('Location: ' . $_SERVER['HTTP_REFERER'] . '');
}
Beispiel #4
0
function clear_server()
{
    global $conf_base_path, $users, $is_compute_node, $is_control_node;
    if (!$is_control_node && !$is_compute_node) {
        return;
    }
    //print "Čekam 1s...\n";
    sleep(1);
    // Just a compute node
    if (!$is_control_node && $is_compute_node) {
        // This just kills node processes, not very efective...
        foreach ($users as $username => $options) {
            if ($options['status'] == "active") {
                deactivate_user($username);
            }
        }
        write_files();
        exec("killall node");
        exec("killall nodejs");
        exec("killall tmux");
        exec("killall inotifywait");
        exec("killall gdb");
        return;
    }
    if (!$is_control_node && $is_svn_node) {
        foreach ($users as $username => $options) {
            if ($options['status'] == "active") {
                deactivate_user($username);
            }
        }
        write_files();
        exec("killall php");
        exec("killall inotifywait");
        exec("killall gdb");
        return;
    }
    // Kill webidectl processes waiting to login
    $mypid = getmypid();
    foreach (ps_ax("127.0.0.1") as $process) {
        if ($process['pid'] != $mypid && strstr($process['cmd'], "webidectl") && strstr($process['cmd'], "php")) {
            exec("kill " . $process['pid']);
        }
    }
    // Logout all users
    foreach ($users as $username => $options) {
        if ($options['status'] == "active") {
            deactivate_user($username);
        }
    }
    // Force restart, since deactivate will just reload... this kills some hanging connections
    exec("service nginx restart");
    // Again, someone somehow reached the login page and tried to login
    foreach (ps_ax("127.0.0.1") as $process) {
        if ($process['pid'] != $mypid && strstr($process['cmd'], "webidectl") && strstr($process['cmd'], "php")) {
            exec("kill " . $process['pid']);
        }
        if (strstr($process['cmd'], "syncsvn.php")) {
            exec("kill " . $process['pid']);
        }
    }
    exec("killall node");
    exec("killall nodejs");
    exec("killall tmux");
    exec("killall inotifywait");
    exec("killall gdb");
    // Again write files, to nuke someone who managed to login
    write_files();
    // Again, someone cheated the race condition
    exec("service nginx restart");
}
Beispiel #5
0
/**
 * Sends notification e-mails to users in two situations:
 *
 *  - Their account is about to expire. This is controlled by the 'expiry'
 *    field of the usr table. Once that time has passed, the user may not
 *    log in.
 *  - They have not logged in for close to a certain amount of time. If that
 *    amount of time has passed, the user may not log in.
 *
 * The actual prevention of users logging in is handled by the authentication
 * code. This cron job sends e-mails to notify users that these events will
 * happen soon.
 */
function auth_handle_account_expiries()
{
    // The 'expiry' flag on the usr table
    $sitename = get_config('sitename');
    $wwwroot = get_config('wwwroot');
    $expire = get_config('defaultaccountinactiveexpire');
    $warn = get_config('defaultaccountinactivewarn');
    $daystoexpire = ceil($warn / 86400) . ' ';
    $daystoexpire .= $daystoexpire == 1 ? get_string('day') : get_string('days');
    // Expiry warning messages
    if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff
        FROM {usr} u
        WHERE ' . db_format_tsfield('u.expiry', false) . ' < ?
        AND expirymailsent = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            email_user($user, null, get_string('accountexpirywarning'), get_string('accountexpirywarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('accountexpirywarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr', 'expirymailsent', 1, 'id', $user->id);
        }
    }
    // Actual expired users
    if ($users = get_records_sql_array('SELECT id
        FROM {usr}
        WHERE ' . db_format_tsfield('expiry', false) . ' < ?', array(time()))) {
        // Users have expired!
        foreach ($users as $user) {
            expire_user($user->id);
        }
    }
    if ($expire) {
        // Inactivity (lastlogin is too old)
        if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff
            FROM {usr} u
            WHERE (? - ' . db_format_tsfield('u.lastlogin', false) . ') > ' . ($expire - $warn) . '
            AND inactivemailsent = 0', array(time()))) {
            foreach ($users as $user) {
                $displayname = display_name($user);
                email_user($user, null, get_string('accountinactivewarning'), get_string('accountinactivewarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $sitename), get_string('accountinactivewarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $sitename));
                set_field('usr', 'inactivemailsent', 1, 'id', $user->id);
            }
        }
        // Actual inactive users
        if ($users = get_records_sql_array('SELECT u.id
            FROM {usr} u
            WHERE (? - ' . db_format_tsfield('lastlogin', false) . ') > ?', array(time(), $expire))) {
            // Users have become inactive!
            foreach ($users as $user) {
                deactivate_user($user->id);
            }
        }
    }
    // Institution membership expiry
    delete_records_sql('DELETE FROM {usr_institution} 
        WHERE ' . db_format_tsfield('expiry', false) . ' < ? AND expirymailsent = 1', array(time()));
    // Institution membership expiry warnings
    if ($users = get_records_sql_array('
        SELECT
            u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.admin, u.staff,
            ui.institution, ui.expiry, i.displayname as institutionname
        FROM {usr} u
        INNER JOIN {usr_institution} ui ON u.id = ui.usr
        INNER JOIN {institution} i ON ui.institution = i.name
        WHERE ' . db_format_tsfield('ui.expiry', false) . ' < ?
        AND ui.expirymailsent = 0', array(time() + $warn))) {
        foreach ($users as $user) {
            $displayname = display_name($user);
            email_user($user, null, get_string('institutionmembershipexpirywarning'), get_string('institutionmembershipexpirywarningtext', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename), get_string('institutionmembershipexpirywarninghtml', 'mahara', $displayname, $user->institutionname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename));
            set_field('usr_institution', 'expirymailsent', 1, 'usr', $user->id, 'institution', $user->institution);
        }
    }
}
<?php

if (isset($_GET['settings_msg'])) {
    $msg = $_GET['settings_msg'];
    deactivate_user($user_id);
    session_destroy();
    header("Location: index.php?accnt_msg={$msg}");
}
deactivate_user($user_id);
session_destroy();
header("Location: index.php");