opr.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. header("Access-Control-Allow-Origin: *");
  3. // for linux user, you might need chmod 0777 smartctl_x86_64 && chmod 0777 smartctl_armv6
  4. // you need smartctl 7.0.0 above to support JSON output
  5. $ok = false;
  6. preg_match('/smartmontools release ([0-9])\.([0-9])/', shell_exec(' sudo smartctl --version | grep "release"'), $filter);
  7. if(isset($filter[1])){
  8. if($filter[1] > 6){
  9. $binary = "smartctl";
  10. $ok = true;
  11. }
  12. }
  13. if($ok == false){
  14. if(strcasecmp(substr(PHP_OS, 0, 3), 'WIN') == 0){
  15. $binary = "./bin/smartctl";
  16. }else{
  17. if(strpos(exec('uname -m'), 'arm') !== false){
  18. $binary = "sudo ./smartctl_armv6";
  19. }else{
  20. $binary = "sudo ./smartctl_x86_64";
  21. }
  22. }
  23. }
  24. if($_GET["opr"] == "scan"){
  25. echo shell_exec($binary.' --scan -j');
  26. //echo file_get_contents("scan.txt");
  27. }else if($_GET["opr"] == "info"){
  28. //smartctl -H /dev/sdb -j
  29. //echo shell_exec('sudo ./smartctl_i386 -i '.$_GET["drive"].' -j -A');
  30. $DiskData = [];
  31. $DiskData["model_name"] = "Unknown";
  32. $DiskData["user_capacity"]["bytes"] = 0;
  33. $DiskData["temperature"]["current"] = 0;
  34. $DiskData["model_family"] = "Unknown";
  35. $DiskData["device"]["info_name"] = "Unknown";
  36. $DiskData["firmware_version"] = "0.0.0";
  37. $DiskData["serial_number"] = "Unknown";
  38. $DiskData["power_on_time"]["hours"] = 0;
  39. $DiskData["power_cycle_count"] = 0;
  40. $DiskData["sata_version"]["string"] = "Unknown";
  41. $DiskData["interface_speed"]["current"]["string"] = "Unknown";
  42. $DiskData["interface_speed"]["max"]["string"] = "Unknown";
  43. $DiskData["ata_version"]["string"] = "Unknown";
  44. $DiskData["rotation_rate"] = 0;
  45. $DiskData["device"]["protocol"] = "Unknown";
  46. $DiskData["ata_smart_attributes"]["table"] = [];
  47. $execResult = json_decode(shell_exec($binary.' -i '.$_GET["drive"].' -j -A'),true);
  48. //$execResult = json_decode(file_get_contents(explode("/",$_GET["drive"])[2].".txt"),true);
  49. if($execResult == null){
  50. die("");
  51. }
  52. $DiskData = array_merge($DiskData,$execResult);
  53. echo json_encode($DiskData);
  54. }
  55. ?>