opr.php 1.9 KB

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