index.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 (($return_var == 0) && (empty($output))) {
  39. echo 'OK';
  40. } else {
  41. echo implode("\n",$output);
  42. }
  43. }
  44. ?>