mirror of
https://github.com/Oxbian/SIDPS.git
synced 2025-07-08 04:43:47 +02:00
filtres ok
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
require_once('constants.php');
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//--- dbConnect --------------------------------------------------------------
|
||||
@ -28,14 +31,27 @@
|
||||
// Function to get all alertes
|
||||
// \param db The connected database.
|
||||
// \return The list of alertes.
|
||||
function dbRequestAlerts($db)
|
||||
function dbRequestAlerts($db, $filtres = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = 'SELECT * FROM alertes';
|
||||
$statement = $db->prepare($request);
|
||||
$statement->execute();
|
||||
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
$params = [];
|
||||
|
||||
|
||||
// Si $filtres est non nul et non vide, appliquez les conditions
|
||||
if (isset($filtres)) {
|
||||
$conditions = [];
|
||||
foreach ($filtres as $colonne => $valeur) {
|
||||
$conditions[] = "$colonne = :$colonne";
|
||||
$params[":$colonne"] = $valeur;
|
||||
}
|
||||
$request .= ' WHERE ' . implode(' AND ', $conditions);
|
||||
}
|
||||
|
||||
$statement = $db->prepare($request);
|
||||
$statement->execute($params);
|
||||
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
catch (PDOException $exception)
|
||||
{
|
||||
@ -45,6 +61,29 @@
|
||||
return $result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
//--- dbRequestDevices --------------------------------------------------------
|
||||
//----------------------------------------------------------------------------
|
||||
// Function to get all alertes
|
||||
// \param db The connected database.
|
||||
// \return The list of alertes.
|
||||
function dbRequestDevices($db)
|
||||
{
|
||||
try
|
||||
{
|
||||
$request = 'SELECT device_product FROM alertes GROUP BY device_product;';
|
||||
$statement = $db->prepare($request);
|
||||
$statement->execute();
|
||||
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
catch (PDOException $exception)
|
||||
{
|
||||
error_log('Request error: '.$exception->getMessage());
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
//--- dbAddCTweet ------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -1,46 +1,58 @@
|
||||
<?php
|
||||
require_once('database.php');
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once('database.php');
|
||||
|
||||
// Database connexion.
|
||||
$db = dbConnect();
|
||||
if (!$db)
|
||||
{
|
||||
header ('HTTP/1.1 503 Service Unavailable');
|
||||
exit;
|
||||
// Database connexion.
|
||||
$db = dbConnect();
|
||||
if (!$db) {
|
||||
header('HTTP/1.1 503 Service Unavailable');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check the request.
|
||||
$requestMethod = $_SERVER['REQUEST_METHOD'];
|
||||
$request = $_SERVER['PATH_INFO'];
|
||||
$request = explode('/', $request);
|
||||
|
||||
|
||||
if ($request[1] == 'alertes') {
|
||||
if ($requestMethod == 'GET') {
|
||||
|
||||
$filtresArray = [];
|
||||
if(isset($_GET['device_product']))
|
||||
$filtresArray['device_product'] = $_GET['device_product'];
|
||||
if(isset($_GET['agent_severity']))
|
||||
$filtresArray['agent_severity'] = $_GET['agent_severity'];
|
||||
error_log('filtres array : ' . json_encode($filtresArray));
|
||||
|
||||
if (!empty($filtresArray)) {
|
||||
$data = dbRequestAlerts($db, $filtresArray);
|
||||
} else {
|
||||
$data = dbRequestAlerts($db, null);
|
||||
}
|
||||
}
|
||||
|
||||
// Check the request.
|
||||
$requestMethod = $_SERVER['REQUEST_METHOD'];
|
||||
$request = $_SERVER['PATH_INFO'];
|
||||
$request = explode('/', $request);
|
||||
|
||||
if ($request[1] != 'alertes')
|
||||
{
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($requestMethod == 'GET')
|
||||
{
|
||||
$data = dbRequestAlerts($db);
|
||||
}
|
||||
|
||||
if ($requestMethod == 'PUT')
|
||||
{
|
||||
if ($requestMethod == 'PUT') {
|
||||
parse_str(file_get_contents('php://input'), $_PUT);
|
||||
if($id !=''&&isset($_PUT['login'])&&isset($_PUT['text']))
|
||||
if ($id != '' && isset($_PUT['login']) && isset($_PUT['text']))
|
||||
$data = dbModifyTweet($db, $id, $_PUT['login'], strip_tags($_PUT['text']));
|
||||
}
|
||||
}
|
||||
|
||||
// Send data to the client.
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
if($requestMethod == 'POST')
|
||||
header('HTTP/1.1 201 Created');
|
||||
else
|
||||
header('HTTP/1.1 200 OK');
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
?>
|
||||
if ($request[1] == 'devices') {
|
||||
$data = dbRequestDevices($db);
|
||||
}
|
||||
|
||||
// Send data to the client.
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
if ($requestMethod == 'POST')
|
||||
header('HTTP/1.1 201 Created');
|
||||
else
|
||||
header('HTTP/1.1 200 OK');
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
|
Reference in New Issue
Block a user