time_bg.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. include '../../../auth.php';
  3. ?>
  4. <?php
  5. $result = [];
  6. if(isset($_GET["opr"]) == false){
  7. $result["return"] = "500";
  8. echo json_encode($result);
  9. die();
  10. }
  11. if($_GET["opr"] == "query"){
  12. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  13. $result["timezone"] = exec("tzutil /g");
  14. $result["fulltime"] = exec('getTime.exe');
  15. $result["time"] = explode(" ",exec('getTime.exe'))[1]." ".explode(" ",exec('getTime.exe'))[2];
  16. } else {
  17. $result["timezone"] = exec("cat /etc/timezone");
  18. $result["fulltime"] = exec('date +"%a %Y-%m-%d %T %Z %z"');
  19. $result["time"] = exec('date +"%Y-%m-%d %T"');
  20. }
  21. }else if($_GET["opr"] == "edit"){
  22. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  23. $tz_win = '';
  24. $tz = json_decode(file_get_contents('data/wintz.json'));
  25. foreach($tz->{"supplementalData"}->{"windowsZones"}->{"mapTimezones"}->{"mapZone"} as $item){
  26. if($item->{"_type"} == $_GET["timezone"]){
  27. $tz_win = $item->{"_other"};
  28. };
  29. }
  30. $result["newtimezone"] = $tz_win;
  31. exec('tzutil /s "'.$tz_win.'"');
  32. $result["return"] = "200";
  33. } else {
  34. exec("sudo timedatectl set-timezone '".$_GET["timezone"]."'");
  35. $result["return"] = "200";
  36. }
  37. }
  38. echo json_encode($result);
  39. ?>