index.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // Not Declaring arguments may cause Notifies on the response on an API Call when the Directive Dysplay errors is enabled
  26. // you may initialize argument arg1, arg2,... arg9 to = '' here
  27. // Or post the unused args to =''
  28. // Prepare arguments
  29. if (isset($_POST['cmd'])) $cmd = escapeshellarg($_POST['cmd']);
  30. if (isset($_POST['arg1'])) $arg1 = escapeshellarg($_POST['arg1']);
  31. if (isset($_POST['arg2'])) $arg2 = escapeshellarg($_POST['arg2']);
  32. if (isset($_POST['arg3'])) $arg3 = escapeshellarg($_POST['arg3']);
  33. if (isset($_POST['arg4'])) $arg4 = escapeshellarg($_POST['arg4']);
  34. if (isset($_POST['arg5'])) $arg5 = escapeshellarg($_POST['arg5']);
  35. if (isset($_POST['arg6'])) $arg6 = escapeshellarg($_POST['arg6']);
  36. if (isset($_POST['arg7'])) $arg7 = escapeshellarg($_POST['arg7']);
  37. if (isset($_POST['arg8'])) $arg8 = escapeshellarg($_POST['arg8']);
  38. if (isset($_POST['arg9'])) $arg9 = escapeshellarg($_POST['arg9']);
  39. // Run query
  40. exec (VESTA_CMD.$cmd." ".$arg1." ".$arg2." ".$arg3." ".$arg4." ".$arg5." ".$arg6." ".$arg7." ".$arg8." ".$arg9, $output, $return_var);
  41. if ((!empty($_POST['returncode'])) && ($_POST['returncode'] == 'yes')) {
  42. echo $return_var;
  43. } else {
  44. if (($return_var == 0) && (empty($output))) {
  45. echo "OK";
  46. } else {
  47. echo implode("\n",$output)."\n";
  48. }
  49. }
  50. }
  51. ?>