<?php
header("Access-Control-Allow-Origin: *");

if($_GET["opr"] == "scan"){
	echo shell_exec('./smartctl_i386 --scan -j');
	//echo file_get_contents("scan.txt");
}else if($_GET["opr"] == "info"){
	//smartctl -H /dev/sdb -j
	//echo shell_exec('sudo ./smartctl_i386 -i '.$_GET["drive"].' -j -A');
	$DiskData = [];
    $DiskData["model_name"] = "Unknown";
    $DiskData["user_capacity"]["bytes"] = "0";
    $DiskData["temperature"]["current"] = "0";
    $DiskData["model_family"] = "Unknown";
    $DiskData["device"]["info_name"] = "Unknown";
    $DiskData["firmware_version"] = "0.0.0";
    $DiskData["serial_number"] = "Unknown";
    $DiskData["power_on_time"]["hours"] = 0;
    $DiskData["sata_version"]["string"] = "Unknown";
    $DiskData["interface_speed"]["current"]["string"] = "Unknown";
    $DiskData["rotation_rate"] = 0;
    $DiskData["device"]["protocol"] = "Unknown";
	
	$execResult = json_decode(shell_exec('sudo ./smartctl_i386 -i '.$_GET["drive"].' -j -A'),true);
	//$execResult = json_decode(file_get_contents(explode("/",$_GET["drive"])[2].".txt"),true);
	if($execResult == null){
		die("");
	}
    $DiskData = array_merge($DiskData,$execResult);
    echo json_encode($DiskData);
}
?>