CMXX - Updated products_software

This commit is contained in:
“VeLiTi”
2024-11-08 13:52:14 +01:00
parent c6a1c61eb1
commit 3ed27eb5ff
3 changed files with 88 additions and 58 deletions

View File

@@ -24,7 +24,6 @@ if(isset($get_content) && $get_content!=''){
//check if productcode and product_version are send //check if productcode and product_version are send
if (isset($criterias['productcode']) && $criterias['productcode'] != '' && isset($criterias['version'])){ if (isset($criterias['productcode']) && $criterias['productcode'] != '' && isset($criterias['version'])){
//Connect to DB //Connect to DB
$pdo = dbConnect($dbname); $pdo = dbConnect($dbname);
@@ -39,14 +38,21 @@ $messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($messages as $message){ foreach ($messages as $message){
//CHECK IF FIRMWARE FILE IS AVAILABLE //CHECK IF FIRMWARE FILE IS AVAILABLE
$software_file = dirname(__FILE__,4)."/firmware/".$message['software'].'.HEX'; $software_file = dirname(__FILE__,4)."/firmware/".$message['software'];
if (file_exists($software_file)){ $file = glob($software_file, GLOB_BRACE);
if (!empty($file)){
//GET FILE EXTENTION
$ext = strtolower(pathinfo($file[0], PATHINFO_EXTENSION));
if ($ext == 'hex'){
//GET SOURCE CODE //GET SOURCE CODE
$file_contents = file_get_contents($software_file); $file_contents = file_get_contents($software_file);
//REMOVE RETURN \R //REMOVE RETURN \R
$file_contents = str_replace("\r", '',$file_contents); $file_contents = str_replace("\r", '',$file_contents);
} else { }
$file_contents = ''; else {
//PROVIDE URL TO FILE
$file_contents = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$message['software'];
} }
$output = array("hw_version"=> $message['version'], "HEX_FW"=> $message['software'], "Firmware" => $file_contents); $output = array("hw_version"=> $message['version'], "HEX_FW"=> $message['software'], "Firmware" => $file_contents);
@@ -59,7 +65,7 @@ foreach ($messages as $message){
//Send results //Send results
echo $output; echo $output;
} }
}
} }
else { else {
http_response_code(404); http_response_code(404);

View File

@@ -44,16 +44,28 @@ if (isset($_GET['rowID'])) {
//CHECK FOR FIRMWARE FILE //CHECK FOR FIRMWARE FILE
$firmware_file = $_FILES["fileToUpload"]["name"] ?? ''; $firmware_file = $_FILES["fileToUpload"]["name"] ?? '';
if($firmware_file !='' || !empty($firmware_file)){ if($firmware_file !='' || !empty($firmware_file)){
$extension = strtolower(pathinfo($firmware_file, PATHINFO_EXTENSION));
$target_dir = dirname(__FILE__)."/firmware/";
if ($extension == 'hex'){
//READ FILE //READ FILE
$contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]); $contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
//firmwarename //firmwarename
$firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME); $firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME);
//Filename //Filename
$target_dir = dirname(__FILE__)."/firmware/";
$input_file = $target_dir . $firmware_name.'.HEX'; $input_file = $target_dir . $firmware_name.'.HEX';
//store firmware file //store firmware file
file_put_contents($input_file, $contents); file_put_contents($input_file, $contents);
} else {
$target_file = $target_dir . $firmware_file;
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$firmware_name = $firmware_file;
}
//Use firmwarefile name as software version //Use firmwarefile name as software version
$_POST['software'] = $firmware_name; $_POST['software'] = $firmware_name;
} }
@@ -99,19 +111,31 @@ if (isset($_GET['rowID'])) {
//CHECK FOR FIRMWARE FILE //CHECK FOR FIRMWARE FILE
$firmware_file = $_FILES["fileToUpload"]["name"] ?? ''; $firmware_file = $_FILES["fileToUpload"]["name"] ?? '';
//FIRMWARE FILE UPLOADED
if($firmware_file !='' || !empty($firmware_file)){ if($firmware_file !='' || !empty($firmware_file)){
$extension = strtolower(pathinfo($firmware_file, PATHINFO_EXTENSION));
$target_dir = dirname(__FILE__)."/firmware/";
if ($extension == 'hex'){
//READ FILE //READ FILE
$contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]); $contents = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
//firmwarename //firmwarename
$firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME); $firmware_name = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_FILENAME);
//Filename //Filename
$target_dir = dirname(__FILE__)."/firmware/";
$input_file = $target_dir . $firmware_name.'.HEX'; $input_file = $target_dir . $firmware_name.'.HEX';
//store firmware file //store firmware file
file_put_contents($input_file, $contents); file_put_contents($input_file, $contents);
$firmware_name = $firmware_name.'.HEX';
} else {
$target_file = $target_dir . $firmware_file;
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
$firmware_name = $firmware_file;
}
//Use firmwarefile name as software version //Use firmwarefile name as software version
$_POST['software'] = $firmware_name.'.HEX'; $_POST['software'] = $firmware_name;
} }
//GET ALL POST DATA //GET ALL POST DATA
@@ -165,10 +189,10 @@ $view .= '<div class="content-block tab-content active">
<input id="name" type="text" name="version" placeholder="'.$product_version_version.'" value="'.$products_versions['version'].'" required> <input id="name" type="text" name="version" placeholder="'.$product_version_version.'" value="'.$products_versions['version'].'" required>
<label for=""><i class="required">*</i>'.$product_version_software.'</label> <label for=""><i class="required">*</i>'.$product_version_software.'</label>
<input id="name" type="text" name="software" placeholder="'.$product_version_software.'" value="'.$products_versions['software'].'" required> <input id="name" type="text" name="software" placeholder="'.$product_version_software.'" value="'.$products_versions['software'].'">
<label for=""></label> <label for=""></label>
<input type="file" name="fileToUpload" id="fileToUpload" accept=".hex, .HEX" style="width: 30%;padding: 50px 0 0 0;height: 10px;"> <input type="file" name="fileToUpload" id="fileToUpload" accept=".hex, .HEX, .bin,.BIN,.exe,.EXE" style="width: 30%;padding: 50px 0 0 0;height: 10px;">
'; ';

View File

@@ -7,11 +7,11 @@ error_reporting(E_ALL);
//================================================================= //=================================================================
$service_tool_current_version = '877a739'; $service_tool_current_version = '877a739';
$service_tool_current_filename = 'EmergencyFlasherSetup.exe'; $service_tool_current_filename = 'EmergencyPlugTestKitSetup_RO-TEST.exe';
$software_download_url = 'https://'.$_SERVER['SERVER_NAME'].'/downloads'.'/'; $software_download_url = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/';
//getSoftware (legacy) //getSoftware (legacy)
$software_url = 'https://'.$_SERVER['SERVER_NAME'].'/downloads'.'/'.$service_tool_current_filename; $software_url = 'https://'.$_SERVER['SERVER_NAME'].'/firmware'.'/'.$service_tool_current_filename;
//================================================================= //=================================================================
//SERVICE Tool initialize =================================== //SERVICE Tool initialize ===================================