1
0

index.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
  3. define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
  4. exit;
  5. if (isset($_POST['user']) || isset($_POST['hash'])) {
  6. // Authentication
  7. if (empty($_POST['hash'])) {
  8. if ($_POST['user'] != 'admin') {
  9. echo 'Error: authentication failed';
  10. exit;
  11. }
  12. $password = $_POST['password'];
  13. $v_ip = escapeshellarg($_SERVER['REMOTE_ADDR']);
  14. $output = '';
  15. exec (HESTIA_CMD."v-get-user-salt admin ".$v_ip." json" , $output, $return_var);
  16. $pam = json_decode(implode('', $output), true);
  17. $salt = $pam['admin']['SALT'];
  18. $method = $pam['admin']['METHOD'];
  19. if ($method == 'md5' ) {
  20. $hash = crypt($password, '$1$'.$salt.'$');
  21. }
  22. if ($method == 'sha-512' ) {
  23. $hash = crypt($password, '$6$rounds=5000$'.$salt.'$');
  24. $hash = str_replace('$rounds=5000','',$hash);
  25. }
  26. if ($method == 'des' ) {
  27. $hash = crypt($password, $salt);
  28. }
  29. // Send hash via tmp file
  30. $v_hash = exec('mktemp -p /tmp');
  31. $fp = fopen($v_hash, "w");
  32. fwrite($fp, $hash."\n");
  33. fclose($fp);
  34. // Check user hash
  35. exec(HESTIA_CMD ."v-check-user-hash admin ".$v_hash." ".$v_ip, $output, $return_var);
  36. unset($output);
  37. // Remove tmp file
  38. unlink($v_hash);
  39. // Check API answer
  40. if ( $return_var > 0 ) {
  41. echo 'Error: authentication failed';
  42. exit;
  43. }
  44. } else {
  45. $key = '/usr/local/hestia/data/keys/' . basename($_POST['hash']);
  46. if (file_exists($key) && is_file($key)) {
  47. exec(HESTIA_CMD ."v-check-api-key ".escapeshellarg($key)." ".$v_ip, $output, $return_var);
  48. unset($output);
  49. // Check API answer
  50. if ( $return_var > 0 ) {
  51. echo 'Error: authentication failed';
  52. exit;
  53. }
  54. } else {
  55. $return_var = 1;
  56. }
  57. }
  58. if ( $return_var > 0 ) {
  59. echo 'Error: authentication failed';
  60. exit;
  61. }
  62. // Prepare arguments
  63. if (isset($_POST['cmd'])) $cmd = escapeshellarg($_POST['cmd']);
  64. if (isset($_POST['arg1'])) $arg1 = escapeshellarg($_POST['arg1']);
  65. if (isset($_POST['arg2'])) $arg2 = escapeshellarg($_POST['arg2']);
  66. if (isset($_POST['arg3'])) $arg3 = escapeshellarg($_POST['arg3']);
  67. if (isset($_POST['arg4'])) $arg4 = escapeshellarg($_POST['arg4']);
  68. if (isset($_POST['arg5'])) $arg5 = escapeshellarg($_POST['arg5']);
  69. if (isset($_POST['arg6'])) $arg6 = escapeshellarg($_POST['arg6']);
  70. if (isset($_POST['arg7'])) $arg7 = escapeshellarg($_POST['arg7']);
  71. if (isset($_POST['arg8'])) $arg8 = escapeshellarg($_POST['arg8']);
  72. if (isset($_POST['arg9'])) $arg9 = escapeshellarg($_POST['arg9']);
  73. // Build query
  74. $cmdquery = HESTIA_CMD.$cmd." ";
  75. if(!empty($arg1)){
  76. $cmdquery = $cmdquery.$arg1." "; }
  77. if(!empty($arg2)){
  78. $cmdquery = $cmdquery.$arg2." "; }
  79. if(!empty($arg3)){
  80. $cmdquery = $cmdquery.$arg3." "; }
  81. if(!empty($arg4)){
  82. $cmdquery = $cmdquery.$arg4." "; }
  83. if(!empty($arg5)){
  84. $cmdquery = $cmdquery.$arg5." "; }
  85. if(!empty($arg6)){
  86. $cmdquery = $cmdquery.$arg6." "; }
  87. if(!empty($arg7)){
  88. $cmdquery = $cmdquery.$arg7." "; }
  89. if(!empty($arg8)){
  90. $cmdquery = $cmdquery.$arg8." "; }
  91. if(!empty($arg9)){
  92. $cmdquery = $cmdquery.$arg9; }
  93. // Check command
  94. if ($cmd == "'v-make-tmp-file'") {
  95. // Used in DNS Cluster
  96. $fp = fopen($_POST['arg2'], 'w');
  97. fwrite($fp, $_POST['arg1']."\n");
  98. fclose($fp);
  99. $return_var = 0;
  100. } else {
  101. // Run normal cmd query
  102. exec ($cmdquery, $output, $return_var);
  103. }
  104. if ((!empty($_POST['returncode'])) && ($_POST['returncode'] == 'yes')) {
  105. echo $return_var;
  106. } else {
  107. if (($return_var == 0) && (empty($output))) {
  108. echo "OK";
  109. } else {
  110. echo implode("\n",$output)."\n";
  111. }
  112. }
  113. }