ajax.php 750 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. // Main include
  4. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  5. // Check user
  6. if ($_SESSION["userContext"] != "admin") {
  7. header("Location: /list/user");
  8. exit();
  9. }
  10. if (empty($_POST["period"])) {
  11. $period = "daily";
  12. } else {
  13. if (in_array($_POST["period"], ["day", "week", "month", "year"])) {
  14. $period = $_POST["period"];
  15. } else {
  16. $period = "daily";
  17. }
  18. }
  19. if (empty($_POST["service"])) {
  20. $service = "la";
  21. } else {
  22. $service = $_POST["service"];
  23. }
  24. // Data
  25. exec(
  26. HESTIA_CMD . "v-export-rrd " . quoteshellarg($service) . " " . quoteshellarg($period),
  27. $output,
  28. $return_var,
  29. );
  30. $data = json_decode(implode("", $output), true);
  31. $data["service"] = $service;
  32. echo json_encode($data);