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
55 lines (48 loc) · 1.71 KB
/
index.php
File metadata and controls
55 lines (48 loc) · 1.71 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
<?php
define('VESTA_CMD', '/usr/bin/sudo /usr/local/vesta/bin/');
if (isset($_POST['user']) || isset($_POST['hash'])) {
// Authentication
$auth_code = 1;
if (empty($_POST['hash'])) {
$v_user = escapeshellarg($_POST['user']);
$v_password = escapeshellarg($_POST['password']);
exec(VESTA_CMD ."v-check-user-password ".$v_user." ".$v_password." '".$_SERVER["REMOTE_ADDR"]."'", $output, $auth_code);
} else {
$key = '/usr/local/vesta/data/keys/' . basename($_POST['hash']);
if (file_exists($key)) {
$auth_code = '0';
}
}
if ($auth_code != 0 ) {
echo 'Error: authentication failed';
exit;
}
// Check user permission to use API
if ($_POST['user'] != 'admin') {
echo 'Error: only admin is allowed to use API';
exit;
}
// Prepare arguments
$cmd = escapeshellarg($_POST['cmd']);
$arg1 = escapeshellarg($_POST['arg1']);
$arg2 = escapeshellarg($_POST['arg2']);
$arg3 = escapeshellarg($_POST['arg3']);
$arg4 = escapeshellarg($_POST['arg4']);
$arg5 = escapeshellarg($_POST['arg5']);
$arg6 = escapeshellarg($_POST['arg6']);
$arg7 = escapeshellarg($_POST['arg7']);
$arg8 = escapeshellarg($_POST['arg8']);
$arg9 = escapeshellarg($_POST['arg9']);
// Run query
exec (VESTA_CMD.$cmd." ".$arg1." ".$arg2." ".$arg3." ".$arg4." ".$arg5." ".$arg6." ".$arg7." ".$arg8." ".$arg9, $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";
}
}
}
?>