index.php 1.7 KB

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