134 lines
4.0 KiB
PHP
134 lines
4.0 KiB
PHP
<?php
|
|
require_once('../config.lib.php');
|
|
require_https();
|
|
require_once("../session.lib.php");
|
|
$denied = NULL;
|
|
$wait_minutes = 0;
|
|
$captcha_failed = FALSE;
|
|
$is_admin = NULL;
|
|
$login_name = is_string($_POST['username'] ?? NULL) ? $_POST['username'] : '';
|
|
if (isset($_SESSION['editor'])) {
|
|
session_write_close();
|
|
header("Location: /publish/edit");
|
|
return;
|
|
} else if (isset($_POST['login']) && !csrf_valid()) {
|
|
$denied = TRUE;
|
|
} else if (isset($_POST['login']) && ($wait = login_blocked_for($login_name)) > 0) {
|
|
$denied = TRUE;
|
|
$wait_minutes = (int)ceil($wait / 60);
|
|
} else if (isset($_POST['login']) && !captcha_verify_response()) {
|
|
$denied = TRUE;
|
|
$captcha_failed = TRUE;
|
|
} else if (isset($_POST['login'])) {
|
|
include_once('../open_db.lib.php');
|
|
$table = "editors";
|
|
open_db('open');
|
|
|
|
$username = $login_name;
|
|
$query = "SELECT * FROM $table WHERE username = ? LIMIT 1";
|
|
$getid = $db->execute_query($query, array($username)) or db_fail();
|
|
$row = $getid->fetch_assoc();
|
|
|
|
$stored_password = '';
|
|
if (isset($row))
|
|
$stored_password = $row['password'];
|
|
else $denied = TRUE;
|
|
$getid->close();
|
|
$compare_password = is_string($_POST['password'] ?? NULL) ? $_POST['password'] : '';
|
|
// password_verify() also accepts hashes made by the old crypt() call
|
|
if (!password_verify($compare_password, $stored_password)) {
|
|
$denied = TRUE;
|
|
record_login_failure($username);
|
|
open_db('close');
|
|
} else {
|
|
// Move an old hash to the current algorithm while we have the password
|
|
rehash_password($username, $compare_password, $stored_password);
|
|
open_db('close');
|
|
login_editor($username);
|
|
clear_login_failures($username);
|
|
// Keep user logged in with cookie, if they request it
|
|
if (isset($_POST['remember'])) {
|
|
create_persistent_login($username);
|
|
}
|
|
$referrer = (string)($_SESSION['referrer'] ?? '');
|
|
unset($_SESSION['referrer']);
|
|
session_write_close();
|
|
if (is_local_path($referrer))
|
|
header('Location: ' . $referrer);
|
|
else
|
|
header("Location: /publish/edit");
|
|
return;
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>x.x.x [login]</title>
|
|
<link rel="icon" href="favicon.png" />
|
|
<link rel="shortcut icon" href="favicon.png" />
|
|
<link rel="stylesheet" type="text/css" href="../style.css" />
|
|
<link rel='stylesheet' type='text/css' href='../publish/style.css' />
|
|
<script type="text/javascript" src="../utilities.js"></script>
|
|
<link rel="alternate" type="application/rss+xml" title="xxx.org.za RSS feed" href="/feed" />
|
|
<?= captcha_script() ?>
|
|
</head>
|
|
<?php flush(); ?>
|
|
<body>
|
|
<div id="container">
|
|
<?php include_once("../sidebar.inc.php"); ?>
|
|
<main id="main">
|
|
<div id="maintext">
|
|
|
|
<H1>editor login</H1>
|
|
|
|
<?php
|
|
if ($wait_minutes)
|
|
echo "<p><strong>Too many failed logins. Please try again in $wait_minutes minute".($wait_minutes == 1 ? "" : "s").".</strong></p>\n";
|
|
else if ($captcha_failed)
|
|
echo "<p><strong>Please complete the captcha.</strong></p>\n";
|
|
else if ($denied)
|
|
echo "<p><strong>Access denied. Please try again.</strong></p>\n";
|
|
?>
|
|
|
|
<form action="" method="post">
|
|
<?= csrf_field() ?>
|
|
<div class="grid">
|
|
|
|
<label for="username">Username: </label>
|
|
<div class="rightcolumn">
|
|
<input type="text" id="username" name="username" />
|
|
</div>
|
|
|
|
<label for="password">Password: </label>
|
|
<div class="rightcolumn">
|
|
<input type="password" id="password" name="password" />
|
|
</div>
|
|
|
|
<label for="remember">Remember me:</label>
|
|
<div class="rightcolumn">
|
|
<input type="checkbox" id="remember" name="remember" checked />
|
|
</div>
|
|
|
|
<?= captcha_widget() ?>
|
|
|
|
<div class="leftcolumn"></div>
|
|
<div class="submission">
|
|
<button type="submit" id="login" name="login" value="1">Login</button>
|
|
</div>
|
|
|
|
</div><!-- .grid -->
|
|
</form>
|
|
|
|
</div> <!-- .maintext -->
|
|
</main> <!-- .main -->
|
|
</div> <!-- .container -->
|
|
<?php include_once("../bottombar.inc.php"); ?>
|
|
|
|
</body>
|
|
</html>
|
|
|