101 lines
2.9 KiB
PHP
101 lines
2.9 KiB
PHP
<?php
|
|
/*
|
|
login.php
|
|
OpenLog Online Logbook
|
|
Copyright (C) 2026 Rod Wright
|
|
|
|
SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
include("functions.php");
|
|
|
|
$print = $_REQUEST['print'];
|
|
$tech = $_REQUEST['tech'];
|
|
$pass = $_REQUEST['pass'];
|
|
$login = $_REQUEST['login'];
|
|
$cancel = $_REQUEST['cancel'];
|
|
|
|
if ($cancel) {
|
|
session_destroy();
|
|
}
|
|
|
|
$techalpha = TECH_ALPHA;
|
|
$logname = LOG_NAME;
|
|
|
|
if ($print) {
|
|
$sbcolor = P_SIDEBAR_COLOR;
|
|
$mbgcolor = P_MENUBG_COLOR;
|
|
} else {
|
|
$sbcolor = SIDEBAR_COLOR;
|
|
$mbgcolor = MENUBG_COLOR;
|
|
}
|
|
|
|
|
|
framework("begin", "$logname", "Login Page", $print);
|
|
|
|
pagetable("begin");
|
|
if (!$print) {
|
|
pageblock("left", "begin");
|
|
sidemenu("no print");
|
|
pageblock("left", "end");
|
|
}
|
|
pageblock("right", "begin");
|
|
if ($login) {
|
|
// log me in
|
|
$pwhash = mysqli_fetch_row(mysqli_query($db, "select techpass from techs where techid=\"$tech\""))[0];
|
|
if (password_verify($pass, $pwhash)) {
|
|
$_SESSION['login'] = $tech;
|
|
$techname = dblookup($db, "techs", "techid", "techname", $tech);
|
|
echo "
|
|
Welcome $techname. Please select a menu option at the left to continue.
|
|
";
|
|
} else {
|
|
$adminqry = mysqli_query($db, "select techname from techs where admin=1 and status=1");
|
|
echo "
|
|
Incorrect password. Please <a href=\"login.php\">try again</a>.<br><br>
|
|
Forgot your password? Contact an administrator:<br><br>
|
|
";
|
|
while ($admintech = mysqli_fetch_row($adminqry)[0]) {
|
|
echo "$admintech <br>";
|
|
}
|
|
}
|
|
} else if ($cancel) {
|
|
echo "
|
|
You are logged out. Please select a menu option at the left to continue.<br><hr>
|
|
";
|
|
} else {
|
|
if (!isset($_SESSION['login'])) {
|
|
// show the login form
|
|
echo "
|
|
<form method=\"post\" action=\"login.php\">
|
|
<b>Tech: </b>
|
|
<select name=\"tech\">
|
|
";
|
|
if ($techalpha) $torder = "techname";
|
|
else $torder = "techid";
|
|
$techrow = mysqli_query($db, "select * from techs order by $torder asc");
|
|
while ($techitem = mysqli_fetch_assoc($techrow)) {
|
|
if ($techitem["status"] == 1) {
|
|
printf("<option value=\"%s\">%s</option>", $techitem["techid"], $techitem["techname"]);
|
|
}
|
|
}
|
|
echo "</select><br><br>
|
|
Password: <input type=\"password\" name=\"pass\" size=\"40\"><br><br>
|
|
<input type=\"submit\" name=\"login\" value=\"Log In\">
|
|
<input type=\"submit\" name=\"cancel\" value=\"Cancel\"><br>
|
|
</form>
|
|
<br><hr>
|
|
";
|
|
} else {
|
|
$loginid = $_SESSION['login'];
|
|
$loggedinas = mysqli_fetch_row(mysqli_query($db, "select techname from techs where techid=\"$loginid\""))[0];
|
|
echo "
|
|
You are already logged in as $loggedinas. Please select a menu option at the left to continue.<br><hr>
|
|
";
|
|
}
|
|
}
|
|
pageblock("right", "end");
|
|
pagetable("end");
|
|
|
|
framework("end", "", "", $print);
|