Files
xxx/publish/addeditor.php
T
tim c85f54116c Use bound parameters for every query that takes user data.
The queue image query took $id without quotes or a check, which allowed
SQL injection.
2026-09-25 21:29:09 +02:00

87 lines
2.5 KiB
PHP

<?php
if ( ! isset($_SERVER['HTTPS'])) {
header('Location: https://' . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI']);
}
require_once("../session.lib.php");
$added = FALSE;
if (!isset($_SESSION['editor'])) {
header("Location: https://xxx.org.za/publish/login");
return;
} else if (isset($_POST['adduser'])) {
require_once('../open_db.lib.php');
open_db('open');
$table = "editors";
$username = (string)($_POST['username'] ?? '');
$password = password_hash((string)($_POST['password'] ?? ''), PASSWORD_DEFAULT);
$email = (string)($_POST['email'] ?? '');
$query = "INSERT INTO $table SET `username` = ?, `password` = ?, `email` = ?";
if ($result = $db->execute_query($query, array($username, $password, $email))) {
$added = TRUE;
$is_admin = TRUE;
}
open_db('close');
}
?>
<!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 [add editor]</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" />
</head>
<?php flush(); ?>
<body>
<div id="container">
<?php include_once("../sidebar.inc.php"); ?>
<main id="main">
<div id="maintext">
<H1>add editor</H1>
<?php if ($added) { ?>
<p>Added editor <?= $username ?></p>
<?php } else { ?>
<form action="https://xxx.org.za<?= $_SERVER['REQUEST_URI'] ?>" method="post">
<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="email">Email: </label>
<div class="rightcolumn">
<input type="text" id="email" name="email" />
</div>
<div class="leftcolumn"></div>
<div class="submission">
<button type="submit" id="adduser" name="adduser" value="1">Add editor</button>
</div>
</div><!-- .grid -->
</form>
<?php } ?>
</div> <!-- .maintext -->
</main> <!-- .main -->
</div> <!-- .container -->
<?php include_once("../bottombar.inc.php"); ?>
</body>
</html>