This commit is contained in:
2026-07-19 18:27:27 +08:00
parent fe4b286ce1
commit 0febcf69f4
170 changed files with 19490 additions and 11878 deletions
+60 -96
View File
@@ -1,73 +1,39 @@
<?php
/**
* Small utility helpers used across the mmdvmhost partials and
* functions.php. Procedural, no class wrapping — just standalone
* functions included via `include_once` from many sites.
*
* Inventory:
* - format_time() Pretty-print a duration in seconds as a
* "Xd, Yhr, Zmin, Ws" string with HTML
* non-breaking spaces (intended for the
* dashboard table cells).
* - startsWith() Substring "starts-with" check used by
* getConfigItem() and the log parsers in
* functions.php.
* - getMHZ() Convert a 9-digit Hz integer (as written
* into /etc/mmdvmhost) into "fff.ffffff MHz"
* for display.
* - isProcessRunning() Cheap pgrep-like check via `ps -eo args` /
* `ps -eo comm`. Cached on first call so
* subsequent calls in the same request hit
* the cached process list. Pass refresh=true
* to force a re-scan in long-running scripts.
* - createConfigLines() Build PHP `define()` strings from $_GET
* query-string parameters. Legacy helper;
* not currently called from active code.
* - getSize() Convert a byte count to a B/KB/MB/GB/...
* friendly string.
* - checkSetup() Diagnostic helper that flags an old config
* format. Called from legacy install paths.
*/
function format_time($seconds) {
$secs = intval($seconds % 60);
$mins = intval($seconds / 60 % 60);
$hours = intval($seconds / 3600 % 24);
$days = intval($seconds / 86400);
$uptimeString = "";
function format_time($seconds)
{
$secs = intval($seconds % 60);
$mins = intval($seconds / 60 % 60);
$hours = intval($seconds / 3600 % 24);
$days = intval($seconds / 86400);
$uptimeString = "";
if ($days > 0) {
$uptimeString .= $days;
$uptimeString .= (($days == 1) ? "&nbsp;day" : "&nbsp;days");
}
if ($hours > 0) {
$uptimeString .= (($days > 0) ? ", " : "") . $hours;
$uptimeString .= (($hours == 1) ? "&nbsp;hr" : "&nbsp;hrs");
}
if ($mins > 0) {
$uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins;
$uptimeString .= (($mins == 1) ? "&nbsp;min" : "&nbsp;mins");
}
if ($secs > 0) {
$uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " : "") . $secs;
$uptimeString .= (($secs == 1) ? "&nbsp;s" : "&nbsp;s");
}
return $uptimeString;
if ($days > 0) {
$uptimeString .= $days;
$uptimeString .= (($days == 1) ? "&nbsp;day" : "&nbsp;days");
}
if ($hours > 0) {
$uptimeString .= (($days > 0) ? ", " : "") . $hours;
$uptimeString .= (($hours == 1) ? "&nbsp;hr" : "&nbsp;hrs");
}
if ($mins > 0) {
$uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins;
$uptimeString .= (($mins == 1) ? "&nbsp;min" : "&nbsp;mins");
}
if ($secs > 0) {
$uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " : "") . $secs;
$uptimeString .= (($secs == 1) ? "&nbsp;s" : "&nbsp;s");
}
return $uptimeString;
}
function startsWith($haystack, $needle)
{
function startsWith($haystack, $needle) {
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
function getMHZ($freq)
{
return substr($freq,0,3) . "." . substr($freq,3,6) . " MHz";
function getMHZ($freq) {
return substr($freq,0,3) . "." . substr($freq,3,6) . " MHz";
}
function isProcessRunning($processName, $full = false, $refresh = false)
{
function isProcessRunning($processName, $full = false, $refresh = false) {
if ($full) {
static $processes_full = array();
if ($refresh) $processes_full = array();
@@ -86,44 +52,42 @@ function isProcessRunning($processName, $full = false, $refresh = false)
return false;
}
function createConfigLines()
{
$out ="";
foreach($_GET as $key=>$val) {
if($key != "cmd") {
$out .= "define(\"$key\", \"$val\");"."\n";
}
}
return $out;
function createConfigLines() {
$out ="";
foreach($_GET as $key=>$val) {
if($key != "cmd") {
$out .= "define(\"$key\", \"$val\");"."\n";
}
}
return $out;
}
function getSize($filesize, $precision = 2) {
$units = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y');
foreach ($units as $idUnit => $unit) {
if ($filesize > 1024)
$filesize /= 1024;
else
break;
}
return round($filesize, $precision).' '.$units[$idUnit].'B';
}
function getSize($filesize, $precision = 2)
{
$units = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y');
foreach ($units as $idUnit => $unit) {
if ($filesize > 1024)
$filesize /= 1024;
else
break;
}
return round($filesize, $precision).' '.$units[$idUnit].'B';
}
function checkSetup()
{
$el = error_reporting();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (defined(DISTRIBUTION)) {
function checkSetup() {
$el = error_reporting();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (defined(DISTRIBUTION)) {
?>
<div class="alert alert-danger" role="alert">You are using an old config.php. Please configure your Dashboard by calling <a href="setup.php">setup.php</a>!</div>
<?php
} else {
if (file_exists ("setup.php")) {
?>
<div class="alert alert-danger" role="alert">You forgot to remove setup.php in root-directory of your dashboard or you forgot to configure it! Please delete the file or configure your Dashboard by calling <a href="setup.php">setup.php</a>!</div>
<?php
}
}
error_reporting($el);
} else {
if (file_exists ("setup.php")) {
?>
<div class="alert alert-danger" role="alert">You forgot to remove setup.php in root-directory of your dashboard or you forgot to configure it! Please delete the file or configure your Dashboard by calling <a href="setup.php">setup.php</a>!</div>
<?php
}
}
error_reporting($el);
}
?>