forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
125 lines (111 loc) · 3.98 KB
/
index.php
File metadata and controls
125 lines (111 loc) · 3.98 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
<?php
define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
if (isset($_POST['user']) || isset($_POST['hash'])) {
// Authentication
if (empty($_POST['hash'])) {
if ($_POST['user'] != 'admin') {
echo 'Error: authentication failed';
exit;
}
$password = $_POST['password'];
$v_ip = escapeshellarg($_SERVER['REMOTE_ADDR']);
$output = '';
exec (HESTIA_CMD."v-get-user-salt admin ".$v_ip." json" , $output, $return_var);
$pam = json_decode(implode('', $output), true);
$salt = $pam['admin']['SALT'];
$method = $pam['admin']['METHOD'];
if ($method == 'md5' ) {
$hash = crypt($password, '$1$'.$salt.'$');
}
if ($method == 'sha-512' ) {
$hash = crypt($password, '$6$rounds=5000$'.$salt.'$');
$hash = str_replace('$rounds=5000','',$hash);
}
if ($method == 'des' ) {
$hash = crypt($password, $salt);
}
// Send hash via tmp file
$v_hash = exec('mktemp -p /tmp');
$fp = fopen($v_hash, "w");
fwrite($fp, $hash."\n");
fclose($fp);
// Check user hash
exec(HESTIA_CMD ."v-check-user-hash admin ".$v_hash." ".$v_ip, $output, $return_var);
unset($output);
// Remove tmp file
unlink($v_hash);
// Check API answer
if ( $return_var > 0 ) {
echo 'Error: authentication failed';
exit;
}
} else {
$key = '/usr/local/hestia/data/keys/' . basename($_POST['hash']);
if (file_exists($key) && is_file($key)) {
exec(HESTIA_CMD ."v-check-api-key ".escapeshellarg($key)." ".$v_ip, $output, $return_var);
unset($output);
// Check API answer
if ( $return_var > 0 ) {
echo 'Error: authentication failed';
exit;
}
} else {
$return_var = 1;
}
}
if ( $return_var > 0 ) {
echo 'Error: authentication failed';
exit;
}
// Prepare arguments
if (isset($_POST['cmd'])) $cmd = escapeshellarg($_POST['cmd']);
if (isset($_POST['arg1'])) $arg1 = escapeshellarg($_POST['arg1']);
if (isset($_POST['arg2'])) $arg2 = escapeshellarg($_POST['arg2']);
if (isset($_POST['arg3'])) $arg3 = escapeshellarg($_POST['arg3']);
if (isset($_POST['arg4'])) $arg4 = escapeshellarg($_POST['arg4']);
if (isset($_POST['arg5'])) $arg5 = escapeshellarg($_POST['arg5']);
if (isset($_POST['arg6'])) $arg6 = escapeshellarg($_POST['arg6']);
if (isset($_POST['arg7'])) $arg7 = escapeshellarg($_POST['arg7']);
if (isset($_POST['arg8'])) $arg8 = escapeshellarg($_POST['arg8']);
if (isset($_POST['arg9'])) $arg9 = escapeshellarg($_POST['arg9']);
// Build query
$cmdquery = HESTIA_CMD.$cmd." ";
if(!empty($arg1)){
$cmdquery = $cmdquery.$arg1." "; }
if(!empty($arg2)){
$cmdquery = $cmdquery.$arg2." "; }
if(!empty($arg3)){
$cmdquery = $cmdquery.$arg3." "; }
if(!empty($arg4)){
$cmdquery = $cmdquery.$arg4." "; }
if(!empty($arg5)){
$cmdquery = $cmdquery.$arg5." "; }
if(!empty($arg6)){
$cmdquery = $cmdquery.$arg6." "; }
if(!empty($arg7)){
$cmdquery = $cmdquery.$arg7." "; }
if(!empty($arg8)){
$cmdquery = $cmdquery.$arg8." "; }
if(!empty($arg9)){
$cmdquery = $cmdquery.$arg9; }
// Check command
if ($cmd == "'v-make-tmp-file'") {
// Used in DNS Cluster
$fp = fopen($_POST['arg2'], 'w');
fwrite($fp, $_POST['arg1']."\n");
fclose($fp);
$return_var = 0;
} else {
// Run normal cmd query
exec ($cmdquery, $output, $return_var);
}
if ((!empty($_POST['returncode'])) && ($_POST['returncode'] == 'yes')) {
echo $return_var;
} else {
if (($return_var == 0) && (empty($output))) {
echo "OK";
} else {
echo implode("\n",$output)."\n";
}
}
}