|
|
|
@@ -26,23 +26,12 @@ if(isset($_POST['new_website'], $_POST['new_username'], $_POST['new_password'])
|
|
|
|
|
$new_username = trim($_POST["new_username"]);
|
|
|
|
|
$new_password = trim($_POST["new_password"]);
|
|
|
|
|
|
|
|
|
|
// Insert new web site using a prepared statement to prevent SQL injection.
|
|
|
|
|
$sql_query = "INSERT INTO websites (login_user_id, web_url, web_username, web_password) VALUES " .
|
|
|
|
|
"((SELECT id FROM login_users WHERE username = ?), ?, ?, ?)";
|
|
|
|
|
|
|
|
|
|
$stmt = $conn->prepare($sql_query);
|
|
|
|
|
if ($stmt === false) {
|
|
|
|
|
$conn->close();
|
|
|
|
|
die("Prepare failed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$stmt->bind_param("ssss", $username, $new_website, $new_username, $new_password);
|
|
|
|
|
// Insert new web site
|
|
|
|
|
$sql_query = "INSERT INTO websites (login_user_id,web_url,web_username,web_password) VALUES " .
|
|
|
|
|
"((SELECT id FROM login_users WHERE username='{$username}'),'{$new_website}','{$new_username}','{$new_password}');";
|
|
|
|
|
//echo $sql_query;
|
|
|
|
|
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
$conn->close();
|
|
|
|
|
|
|
|
|
|
$result = $conn->query($sql_query);
|
|
|
|
|
$conn -> close();
|
|
|
|
|
|
|
|
|
|
// After processing, redirect to the same page to clear the form
|
|
|
|
|
unset($_POST['new_website']);
|
|
|
|
@@ -56,25 +45,11 @@ if(isset($_POST['new_website'], $_POST['new_username'], $_POST['new_password'])
|
|
|
|
|
if(isset($_POST['delete_website']) && trim($_POST["websiteid"] != '')) {
|
|
|
|
|
$webid = trim($_POST["websiteid"]);
|
|
|
|
|
|
|
|
|
|
// Cast to int to avoid unexpected input and use a prepared statement to prevent SQL injection.
|
|
|
|
|
$webid = (int)trim($_POST["websiteid"]);
|
|
|
|
|
|
|
|
|
|
// Delete selected web site
|
|
|
|
|
$sql_query = "DELETE FROM websites WHERE webid = ?";
|
|
|
|
|
|
|
|
|
|
$stmt = $conn->prepare($sql_query);
|
|
|
|
|
if ($stmt === false) {
|
|
|
|
|
$conn->close();
|
|
|
|
|
die("Prepare failed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$stmt->bind_param("i", $webid);
|
|
|
|
|
$sql_query = "DELETE FROM websites WHERE webid='{$webid}';";
|
|
|
|
|
//echo $sql_query;
|
|
|
|
|
|
|
|
|
|
$result = $stmt->execute();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
$conn->close();
|
|
|
|
|
|
|
|
|
|
$result = $conn->query($sql_query);
|
|
|
|
|
$conn -> close();
|
|
|
|
|
|
|
|
|
|
// After processing, redirect to the same page to clear the form
|
|
|
|
|
unset($_POST['websiteid']);
|
|
|
|
@@ -82,40 +57,22 @@ if(isset($_POST['delete_website']) && trim($_POST["websiteid"] != '')) {
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Display list of user's web sites using a prepared statement to prevent SQL injection.
|
|
|
|
|
$sql_query = "SELECT * FROM websites INNER JOIN login_users ON websites.login_user_id=login_users.id WHERE login_users.username = ?";
|
|
|
|
|
// Display list of user's web sites
|
|
|
|
|
$sql_query = "SELECT * FROM websites INNER JOIN login_users ON websites.login_user_id=login_users.id WHERE login_users.username='{$username}';";
|
|
|
|
|
//echo $sql_query;
|
|
|
|
|
|
|
|
|
|
$stmt = $conn->prepare($sql_query);
|
|
|
|
|
if ($stmt === false) {
|
|
|
|
|
$conn->close();
|
|
|
|
|
die("Prepare failed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$stmt->bind_param("s", $username);
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$result = $stmt->get_result();
|
|
|
|
|
$stmt->close();
|
|
|
|
|
|
|
|
|
|
$result = $conn->query($sql_query);
|
|
|
|
|
|
|
|
|
|
//echo htmlspecialchars($username);
|
|
|
|
|
$safe_username = htmlspecialchars($username, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8");
|
|
|
|
|
echo "<h3>Entries of " . $safe_username . "</h3>";
|
|
|
|
|
echo "<h3>Entries of " . $username . "</h3>";
|
|
|
|
|
|
|
|
|
|
if (!empty($result) && $result->num_rows >= 1) {
|
|
|
|
|
while ($row = $result -> fetch_assoc()) {
|
|
|
|
|
// Escape output to prevent stored XSS (DB content must be treated as untrusted).
|
|
|
|
|
$safe_url = htmlspecialchars($row["web_url"], ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8");
|
|
|
|
|
$safe_user = htmlspecialchars($row["web_username"], ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8");
|
|
|
|
|
$safe_pass = htmlspecialchars($row["web_password"], ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8");
|
|
|
|
|
$webid_safe = (int)$row["webid"];
|
|
|
|
|
|
|
|
|
|
echo "<table border=0>";
|
|
|
|
|
echo "<tr style='background-color: #f4f4f4;'><td colspan=2>" . $safe_url . "</td></tr>" .
|
|
|
|
|
"<tr><td>Username: " . $safe_user . "</td><td>Password: " . $safe_pass . "</td></tr>";
|
|
|
|
|
echo "<tr style='background-color: #f4f4f4;'><td colspan=2>" . $row["web_url"] . "</td></tr>" .
|
|
|
|
|
"<tr><td>Username: " . $row["web_username"] . "</td><td>Password: " . $row["web_password"] . "</td></tr>";
|
|
|
|
|
|
|
|
|
|
echo "<tr><td><form method='POST' style='height: 3px'>" .
|
|
|
|
|
"<input type='hidden' name='websiteid' value='" . $webid_safe . "'>" .
|
|
|
|
|
"<input type='hidden' name='websiteid' value='" . $row["webid"] . "'>" .
|
|
|
|
|
"<button type='submit' name='delete_website'>Delete</button></form></td></tr>";
|
|
|
|
|
|
|
|
|
|
echo "<tr><td colspan=2 style=height: 20px;></td></tr>";
|
|
|
|
|