/home/techb158/balacoffee.com/wp-content/plugins/updraftplus/addons
Edit: /home/techb158/balacoffee.com/wp-content/plugins/updraftplus/addons/lockadmin.php (11168B)
opts['session_length'];
if (!$session_length) $session_length = 86400;
// A lock has been set. Has the user passed the test?
if (empty($_COOKIE['updraft_unlockadmin'])) return false;
// Cookie in correct format?
if (!preg_match('/^(\d+):(.*)$/', $_COOKIE['updraft_unlockadmin'], $matches)) return false;
$cookie_time = $matches[1]; // The time when the session began
$cookie_hash = $matches[2];
$time_now = time();
// Cookie is older than session length
if ($time_now > $cookie_time + $session_length) return false;
$cookie_session_began = $cookie_time - ($cookie_time % $session_length);
$user = wp_get_current_user();
if (!is_a($user, 'WP_User')) return false;
// The cookie relies on the user ID, password and session time. So, someone stealing the cookie can't use it forever. They need the password to generate valid cookies.
$correct_hash = hash('sha256', $user->ID.'-'.$password.'-'.$cookie_session_began);
if ($correct_hash != $cookie_hash) return false;
return true;
}
public function return_opts() {
$this->get_opts();
return $this->opts;
}
private function get_opts() {
$this->opts = UpdraftPlus_Options::get_updraft_option('updraft_adminlocking');
if (!is_array($this->opts)) $this->opts = array();
if (!isset($this->opts['password'])) $this->opts['password'] = '';
if (!isset($this->opts['session_length'])) $this->opts['session_length'] = 3600;
if (!isset($this->opts['support_url'])) $this->opts['support_url'] = '';
}
/**
* Runs upon the WP action admin_init, but only if there's appropriate data in $_POST
*/
public function admin_init() {
if ((empty($_POST['updraft_unlockadmin_session_length']) && empty($_POST['updraft_unlockadmin_password'])) || empty($_POST['nonce'])) return;
if (!wp_verify_nonce($_POST['nonce'], 'updraftplus-unlockadmin-nonce')) return;
$user = wp_get_current_user();
if (!is_a($user, 'WP_User')) return;
$this->get_opts();
if (!empty($_POST['updraft_unlockadmin_session_length']) && isset($_POST['updraft_unlockadmin_oldpassword']) && $_POST['updraft_unlockadmin_oldpassword'] == $this->opts['password']) {
$this->old_password = $this->opts['password'];
$this->opts['password'] = $_POST['updraft_unlockadmin_password'];
$this->opts['support_url'] = $_POST['updraft_unlockadmin_support_url'];
$this->opts['session_length'] = (int) $_POST['updraft_unlockadmin_session_length'];
UpdraftPlus_Options::update_updraft_option('updraft_adminlocking', $this->opts);
$this->password_length = strlen($this->opts['password']);
add_action('all_admin_notices', array($this, 'show_admin_warning_passwordset'));
}
// Note: this code also fires when the user sets a new password (because we don't want to immediately lock them)
$password = $this->opts['password'];
if ($password === (string) $_POST['updraft_unlockadmin_password']) {
$session_length = (int) $this->opts['session_length'];
if ($session_length<1) $session_length = 86400;
// The cookie relies on the user ID, password and session time. So, someone stealing the cookie can't use it forever. They need the password to generate valid cookies.
$time_now = time();
$expire = $time_now + $session_length;
$cookie_session_began = $time_now - ($time_now % $session_length);
$correct_hash = hash('sha256', $user->ID.'-'.$password.'-'.$cookie_session_began);
$secure = apply_filters('secure_auth_cookie', is_ssl(), $user->ID);
setcookie('updraft_unlockadmin', $cookie_session_began.':'.$correct_hash, $expire, ADMIN_COOKIE_PATH, COOKIE_DOMAIN, $secure, true);
$this->correct_password_supplied = true;
} else {
$this->correct_password_supplied = false;
}
}
public function show_admin_warning_passwordset() {
$msg = '
';
if (strlen($this->old_password) >0 && 0 == $this->password_length) {
$msg .= __('The admin password has now been removed.', 'updraftplus');
} elseif (strlen($this->old_password) == 0 && $this->password_length > 0) {
$msg .= __('An admin password has been set.', 'updraftplus');
} elseif ($this->old_password !== $this->opts['password']) {
$msg .= __('The admin password has been changed.', 'updraftplus');
} else {
$msg .= __('Settings saved.');
}
$msg .= '';
global $updraftplus_admin;
$updraftplus_admin->show_admin_warning($msg);
}
public function settings_page_render($go) {
if (!$go) return $go;
if ($this->correct_password_supplied) return true;
$this->get_opts();
$password = $this->opts['password'];
if ($this->check_user_cookie($password)) return $go;
return false;
}
/**
* Runs upon the WP action updraftplus_debugtools_dashboard
*/
public function debugtools_dashboard() {
global $updraftplus_admin;
$this->get_opts();
?>
settings_header();
?>
';
}
}