-
Notifications
You must be signed in to change notification settings - Fork 36
/
tools.php
88 lines (80 loc) · 2.44 KB
/
tools.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
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) ? " day" : " days");
}
if ($hours > 0) {
$uptimeString .= (($days > 0) ? ", " : "") . $hours;
$uptimeString .= (($hours == 1) ? " hr" : " hrs");
}
if ($mins > 0) {
$uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins;
$uptimeString .= (($mins == 1) ? " min" : " mins");
}
if ($secs > 0) {
$uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " : "") . $secs;
$uptimeString .= (($secs == 1) ? " s" : " s");
}
return $uptimeString;
}
function startsWith($haystack, $needle) {
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
function searchForKey($field, $needle, $array) {
foreach ($array as $key => $val) {
if ($val[$field] === $needle) {
return $key;
}
}
return null;
}
function getMHZ($freq) {
return substr($freq,0,3) . "." . substr($freq,3,3) . "." . substr($freq,6) . " Mhz";
}
function isProcessRunning($processname) {
exec("pgrep " . $processname, $pids);
if(empty($pids)) {
// process not running!
return false;
} else {
// process running!
return true;
}
}
function createConfigLines() {
$out ="";
foreach($_GET as $key=>$val) {
if($key != "cmd") {
$out .= "define(\"$key\", \"$val\");"."\n";
}
}
return $out;
}
function checkSetup() {
$el = error_reporting();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if (defined("DISTRIBUTION")) {
?>
<div class="alert alert-danger" role="alert"><?php echo _("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") && ! defined("DISABLESETUPWARNING")) {
?>
<div class="alert alert-danger" role="alert"><?php echo _("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);
}
function convertTimezone($timestamp) {
$date = new DateTime($timestamp);
$date->setTimezone(new DateTimeZone(TIMEZONE));
return $date->format('Y-m-d H:i:s');
}
?>