CMXX - Firmware improvement
This commit is contained in:
66
api/v2/get/products_software.php
Normal file
66
api/v2/get/products_software.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
defined($security_key) or exit;
|
||||
|
||||
//------------------------------------------
|
||||
// Products_software
|
||||
//------------------------------------------
|
||||
|
||||
//NEW ARRAY
|
||||
$criterias = [];
|
||||
$clause = '';
|
||||
|
||||
//Check for $_GET variables and build up clause
|
||||
if(isset($get_content) && $get_content!=''){
|
||||
//GET VARIABLES FROM URL
|
||||
$requests = explode("&", $get_content);
|
||||
//Check for keys and values
|
||||
foreach ($requests as $y){
|
||||
$v = explode("=", $y);
|
||||
//INCLUDE VARIABLES IN ARRAY
|
||||
$criterias[$v[0]] = $v[1];
|
||||
}
|
||||
}
|
||||
|
||||
//check if productcode and product_version are send
|
||||
if (isset($criterias['productcode']) && $criterias['productcode'] != '' && isset($criterias['version'])){
|
||||
|
||||
|
||||
//Connect to DB
|
||||
$pdo = dbConnect($dbname);
|
||||
|
||||
//SQL for Paging
|
||||
$sql = 'SELECT * FROM products_versions pv JOIN products p ON pv.productrowid = p.rowID WHERE p.productcode = ? AND pv.version = ? AND pv.status = "1"';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
//Excute Query
|
||||
$stmt->execute([$criterias['productcode'],$criterias['version']]);
|
||||
//Get results
|
||||
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($messages as $message){
|
||||
|
||||
//CHECK IF FIRMWARE FILE IS AVAILABLE
|
||||
$software_file = dirname(__FILE__,4)."/firmware/".$message['software'].'.HEX';
|
||||
if (file_exists($software_file)){
|
||||
//GET SOURCE CODE
|
||||
$file_contents = file_get_contents($software_file);
|
||||
} else {
|
||||
$file_contents = '';
|
||||
}
|
||||
|
||||
$output = array("hw_version"=> $message['version'], "HEX_FW"=> $message['software'], "Firmware" => $file_contents);
|
||||
|
||||
//------------------------------------------
|
||||
//JSON_ENCODE
|
||||
//------------------------------------------
|
||||
$output = json_encode($output, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
//Send results
|
||||
echo $output;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
http_response_code(404);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user