Initial
This commit is contained in:
63
web/list/rrd/ajax.php
Normal file
63
web/list/rrd/ajax.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
use function Hestiacp\quoteshellarg\quoteshellarg;
|
||||
// Main include
|
||||
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
|
||||
|
||||
// Check user
|
||||
if ($_SESSION["userContext"] != "admin") {
|
||||
header("Location: /list/user");
|
||||
exit();
|
||||
}
|
||||
|
||||
$requestPayload = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$allowedPeriods = ["daily", "weekly", "monthly", "yearly", "biennially", "triennially"];
|
||||
|
||||
if (!empty($requestPayload["period"]) && in_array($requestPayload["period"], $allowedPeriods)) {
|
||||
$period = $requestPayload["period"];
|
||||
} else {
|
||||
$period = "daily";
|
||||
}
|
||||
|
||||
if (!empty($requestPayload["service"])) {
|
||||
$service = $requestPayload["service"];
|
||||
} else {
|
||||
$service = "la";
|
||||
}
|
||||
|
||||
// Data
|
||||
exec(
|
||||
HESTIA_CMD . "v-export-rrd " . quoteshellarg($service) . " " . quoteshellarg($period),
|
||||
$output,
|
||||
$return_var,
|
||||
);
|
||||
|
||||
if ($return_var != 0) {
|
||||
http_response_code(500);
|
||||
exit("Error fetching RRD data");
|
||||
}
|
||||
|
||||
$serviceUnits = [
|
||||
"la" => "Points",
|
||||
"mem" => "Mbytes",
|
||||
"apache2" => "Connections",
|
||||
"nginx" => "Connections",
|
||||
"mail" => "Queue Size",
|
||||
"ftp" => "Connections",
|
||||
"ssh" => "Connections",
|
||||
];
|
||||
|
||||
if (preg_match("/^net_/", $service)) {
|
||||
$serviceUnits[$service] = "KBytes";
|
||||
}
|
||||
if (preg_match("/^pgsql_/", $service)) {
|
||||
$serviceUnits[$service] = "Queries";
|
||||
}
|
||||
if (preg_match("/^mysql_/", $service)) {
|
||||
$serviceUnits[$service] = "Queries";
|
||||
}
|
||||
|
||||
$data = json_decode(implode("", $output), true);
|
||||
$data["service"] = $service;
|
||||
$data["unit"] = $serviceUnits[$service] ?? null;
|
||||
echo json_encode($data);
|
||||
18
web/list/rrd/image.php
Normal file
18
web/list/rrd/image.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
session_start();
|
||||
if ($_SESSION["userContext"] != "admin") {
|
||||
exit();
|
||||
}
|
||||
$real_path = realpath($_SERVER["DOCUMENT_ROOT"] . $_SERVER["QUERY_STRING"]);
|
||||
if (empty($real_path)) {
|
||||
exit();
|
||||
}
|
||||
$dir_name = dirname($real_path);
|
||||
$dir_name = dirname($dir_name);
|
||||
if ($dir_name != $_SERVER["DOCUMENT_ROOT"] . "/rrd") {
|
||||
exit();
|
||||
}
|
||||
header("X-Accel-Redirect: " . $_SERVER["QUERY_STRING"]);
|
||||
header("Content-Type: image/png");
|
||||
|
||||
?>
|
||||
49
web/list/rrd/index.php
Normal file
49
web/list/rrd/index.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
$TAB = "RRD";
|
||||
|
||||
// Main include
|
||||
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
|
||||
|
||||
// Check user
|
||||
if ($_SESSION["userContext"] != "admin") {
|
||||
header("Location: /list/user");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Data
|
||||
exec(HESTIA_CMD . "v-list-sys-rrd json", $output, $return_var);
|
||||
$data = json_decode(implode("", $output), true);
|
||||
unset($output);
|
||||
|
||||
/*
|
||||
if (empty($_GET["period"])) {
|
||||
$period = "day";
|
||||
} elseif (!in_array($_GET["period"], ["day", "week", "month", "year"])) {
|
||||
$period = "day";
|
||||
} else {
|
||||
$period = $_GET["period"];
|
||||
}
|
||||
*/
|
||||
if (empty($_GET["period"])) {
|
||||
$period = "daily";
|
||||
} elseif (
|
||||
!in_array($_GET["period"], [
|
||||
"daily",
|
||||
"weekly",
|
||||
"monthly",
|
||||
"yearly",
|
||||
"biennially",
|
||||
"triennially",
|
||||
])
|
||||
) {
|
||||
$period = "daily";
|
||||
} else {
|
||||
$period = $_GET["period"];
|
||||
}
|
||||
|
||||
// Render page
|
||||
render_page($user, $TAB, "list_rrd");
|
||||
|
||||
// Back uri
|
||||
$_SESSION["back"] = $_SERVER["REQUEST_URI"];
|
||||
Reference in New Issue
Block a user