|
| 1 | +<?php |
| 2 | +define('VESTA_CMD', '/usr/bin/sudo /usr/local/vesta/bin/'); |
| 3 | + |
| 4 | +if (isset($_POST['user']) || isset($_POST['hash'])) { |
| 5 | + |
| 6 | + // Authentication |
| 7 | + $auth_code = 1; |
| 8 | + if (empty($_POST['hash'])) { |
| 9 | + $v_user = escapeshellarg($_POST['user']); |
| 10 | + $v_password = escapeshellarg($_POST['password']); |
| 11 | + exec(VESTA_CMD ."v-check-user-password ".$v_user." ".$v_password." '".$_SERVER["REMOTE_ADDR"]."'", $output, $auth_code); |
| 12 | + } else { |
| 13 | + $key = '/usr/local/vesta/data/keys/' . basename($_POST['hash']); |
| 14 | + if (file_exists($key)) { |
| 15 | + $auth_code = '0'; |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + if ($auth_code != 0 ) { |
| 20 | + echo 'Error: authentication failed'; |
| 21 | + exit; |
| 22 | + } |
| 23 | + |
| 24 | + // Check user permission to use API |
| 25 | + if ($_POST['user'] != 'admin') { |
| 26 | + echo 'Error: only admin is allowed to use API'; |
| 27 | + exit; |
| 28 | + } |
| 29 | + |
| 30 | + // Prepare arguments |
| 31 | + $cmd = escapeshellarg($_POST['cmd']); |
| 32 | + $arg1 = escapeshellarg($_POST['arg1']); |
| 33 | + $arg2 = escapeshellarg($_POST['arg2']); |
| 34 | + $arg3 = escapeshellarg($_POST['arg3']); |
| 35 | + $arg4 = escapeshellarg($_POST['arg4']); |
| 36 | + $arg5 = escapeshellarg($_POST['arg5']); |
| 37 | + $arg6 = escapeshellarg($_POST['arg6']); |
| 38 | + $arg7 = escapeshellarg($_POST['arg7']); |
| 39 | + $arg8 = escapeshellarg($_POST['arg8']); |
| 40 | + $arg9 = escapeshellarg($_POST['arg9']); |
| 41 | + |
| 42 | + // Run query |
| 43 | + exec (VESTA_CMD.$cmd." ".$arg1." ".$arg2." ".$arg3." ".$arg4." ".$arg5." ".$arg6." ".$arg7." ".$arg8." ".$arg9, $output, $return_var); |
| 44 | + if (($return_var == 0) && (empty($output))) { |
| 45 | + echo 'OK'; |
| 46 | + } else { |
| 47 | + echo implode("\n",$output); |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +?> |
0 commit comments