forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
138 lines (127 loc) · 4 KB
/
main.php
File metadata and controls
138 lines (127 loc) · 4 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
// Check user session
if (!isset($_SESSION['user'])) {
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
header("Location: /login/");
exit;
}
if (isset($_SESSION['look']) && ( $_SESSION['look'] != 'admin' )) {
$user = $_SESSION['look'];
} else {
$user = $_SESSION['user'];
}
define('VESTA_CMD', '/usr/bin/sudo /usr/local/vesta/bin/');
$i = 0;
// Define functions
function check_error($return_var){
if ( $return_var > 0 ) {
header("Location: /error/");
exit;
}
}
function top_panel($user, $TAB) {
global $panel;
$command = VESTA_CMD."v-list-user '".$user."' 'json'";
exec ($command, $output, $return_var);
if ( $return_var > 0 ) {
header("Location: /error/");
exit;
}
$panel = json_decode(implode('', $output), true);
unset($output);
if ( $user == 'admin' ) {
include($_SERVER['DOCUMENT_ROOT'].'/templates/admin/panel.html');
} else {
include($_SERVER['DOCUMENT_ROOT'].'/templates/user/panel.html');
}
}
function humanize_time($usage) {
if ( $usage > 60 ) {
$usage = $usage / 60;
$usage = number_format($usage, 2);
$usage = $usage." Hour.";
} else {
$usage = $usage." Min.";
}
return $usage;
}
function humanize_usage($usage) {
if ( $usage > 1000 ) {
$usage = $usage / 1000;
if ( $usage > 1000 ) {
$usage = $usage / 1000 ;
if ( $usage > 1000 ) {
$usage = $usage / 1000 ;
$usage = number_format($usage, 2);
$usage = $usage." pb";
} else {
$usage = number_format($usage, 2);
$usage = $usage." tb";
}
} else {
$usage = number_format($usage, 2);
$usage = $usage." gb";
}
} else {
$usage = $usage." mb";
}
return $usage;
}
function get_percentage($used,$total) {
if (!isset($total)) $total = 0;
if (!isset($used)) $used = 0;
if ( $total == 0 ) {
$percent = 0;
} else {
$percent = $used / $total;
$percent = $percent * 100;
$percent = number_format($percent, 0, '', '');
if ( $percent > 100 ) {
$percent = 100;
}
if ( $percent < 0 ) {
$percent = 0;
}
}
return $percent;
}
function send_email($to,$subject,$mailtext,$from) {
$charset = "utf-8";
$to = '<'.$to.'>';
$boundary = '--' . md5( uniqid("myboundary") );
$priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
$priority = $priorities[2];
$ctencoding = "8bit";
$sep = chr(13) . chr(10);
$disposition = "inline";
$subject = "=?$charset?B?".base64_encode($subject)."?=";
$header = "From: $from \nX-Priority: $priority\nCC:\n";
$header .= "Mime-Version: 1.0\nContent-Type: text/plain; charset=$charset \n";
$header .= "Content-Transfer-Encoding: $ctencoding\nX-Mailer: Php/libMailv1.3\n";
$message = $mailtext;
mail($to, $subject, $message, $header);
}
function display_error_block() {
if (!empty($_SESSION['error_msg'])) {
echo '
<script type="text/javascript">
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
<div id="dialog-message" title="Error">
<p>';
echo $_SESSION['error_msg'];
echo "</p>\n </div>\n";
unset($_SESSION['error_msg']);
}
}
?>