You are not allowed to delete log entries. (insufficient permissions)
';
}else{
$id=htmlspecialchars($_GET["delete"]);
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
create_log_backup($conn);
$sql = "DELETE FROM log WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
// Execute the statement
$stmt->execute();
$stmt->close();
$conn->close();
echo '
Log entry deleted.
';
log_action("LOG::ENTRY::DELETE::SUCCESS","User ".$_SESSION["username"]." deleted a log entry.",$_SESSION["id"]);
}
}
if(isset($_GET["delete_all"])){
if($perms[3]!=="1"){
log_action("LOG::ENTRY::DELETE::FAILURE","User ".$_SESSION["username"]." tried to delete the full log but not succeeded because of insufficient permissions.",$_SESSION["id"]);
echo '
You are not allowed to delete log entries. (insufficient permissions)
';
}else{
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
create_log_backup($conn);
$sql = "DELETE FROM log";
$stmt = $conn->prepare($sql);
// Execute the statement
$stmt->execute();
$stmt->close();
$conn->close();
echo '
Log deleted.
';
log_action("LOG::ENTRY::DELETE::SUCCESS","User ".$_SESSION["username"]." deleted the full log.",$_SESSION["id"]);
}
}
// Define page size and current page
$page_size = 50;
$current_page = htmlspecialchars(isset($_GET['page']) ? intval($_GET['page']) : 1);
$offset = ($current_page - 1) * $page_size;
// Get total number of log entries based on filters
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT count(log.id) AS log_count FROM machines,log WHERE machine_name=machine_id AND machine_location LIKE ? AND loglevel LIKE ? AND logtext LIKE ? AND machine_id LIKE ? AND time LIKE ?";
$stmt = $conn->prepare($sql);
$loglevel = "%" . $loglevel . "%";
$logtext = "%" . $logtext . "%";
$machine_id = "%" . $machine_id . "%";
$machine_location = "%" . $machine_location . "%";
$time = "%" . $time . "%";
$stmt->bind_param("sssss",$machine_location, $loglevel, $logtext, $machine_id, $time);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$total_entries = $row["log_count"];
// Calculate total pages
$total_pages = ceil(($total_entries) / $page_size);
// Query log entries for the current page with filters
$sql = "SELECT * FROM machines,log WHERE machine_location LIKE ? AND loglevel LIKE ? AND logtext LIKE ? AND machine_id LIKE ? AND time LIKE ? AND machine_name=machine_id ORDER BY log.id DESC LIMIT ?, ?";
$stmt = $conn->prepare($sql);
$loglevel = "%" . $loglevel . "%";
$logtext = "%" . $logtext . "%";
$machine_id = "%" . $machine_id . "%";
$machine_location = "%" . $machine_location . "%";
$time = "%" . $time . "%";
$stmt->bind_param("sssssii", $machine_location, $loglevel, $logtext, $machine_id, $time, $offset, $page_size);
$stmt->execute();
$result = $stmt->get_result();
if($current_page==1){
echo("
");
//echo("
");
}
// Display log entries
echo '
';
$conn->close();
// Display pagination links with filter query
echo '